ql4_os.c 283 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <linux/blkdev.h>
  10. #include <linux/iscsi_boot_sysfs.h>
  11. #include <linux/inet.h>
  12. #include <scsi/scsi_tcq.h>
  13. #include <scsi/scsicam.h>
  14. #include "ql4_def.h"
  15. #include "ql4_version.h"
  16. #include "ql4_glbl.h"
  17. #include "ql4_dbg.h"
  18. #include "ql4_inline.h"
  19. #include "ql4_83xx.h"
  20. /*
  21. * Driver version
  22. */
  23. static char qla4xxx_version_str[40];
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * Module parameter information and variables
  30. */
  31. static int ql4xdisablesysfsboot = 1;
  32. module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
  33. MODULE_PARM_DESC(ql4xdisablesysfsboot,
  34. " Set to disable exporting boot targets to sysfs.\n"
  35. "\t\t 0 - Export boot targets\n"
  36. "\t\t 1 - Do not export boot targets (Default)");
  37. int ql4xdontresethba;
  38. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  39. MODULE_PARM_DESC(ql4xdontresethba,
  40. " Don't reset the HBA for driver recovery.\n"
  41. "\t\t 0 - It will reset HBA (Default)\n"
  42. "\t\t 1 - It will NOT reset HBA");
  43. int ql4xextended_error_logging;
  44. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  45. MODULE_PARM_DESC(ql4xextended_error_logging,
  46. " Option to enable extended error logging.\n"
  47. "\t\t 0 - no logging (Default)\n"
  48. "\t\t 2 - debug logging");
  49. int ql4xenablemsix = 1;
  50. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  51. MODULE_PARM_DESC(ql4xenablemsix,
  52. " Set to enable MSI or MSI-X interrupt mechanism.\n"
  53. "\t\t 0 = enable INTx interrupt mechanism.\n"
  54. "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
  55. "\t\t 2 = enable MSI interrupt mechanism.");
  56. #define QL4_DEF_QDEPTH 32
  57. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  58. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  59. MODULE_PARM_DESC(ql4xmaxqdepth,
  60. " Maximum queue depth to report for target devices.\n"
  61. "\t\t Default: 32.");
  62. static int ql4xqfulltracking = 1;
  63. module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
  64. MODULE_PARM_DESC(ql4xqfulltracking,
  65. " Enable or disable dynamic tracking and adjustment of\n"
  66. "\t\t scsi device queue depth.\n"
  67. "\t\t 0 - Disable.\n"
  68. "\t\t 1 - Enable. (Default)");
  69. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  70. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  71. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  72. " Target Session Recovery Timeout.\n"
  73. "\t\t Default: 120 sec.");
  74. int ql4xmdcapmask = 0;
  75. module_param(ql4xmdcapmask, int, S_IRUGO);
  76. MODULE_PARM_DESC(ql4xmdcapmask,
  77. " Set the Minidump driver capture mask level.\n"
  78. "\t\t Default is 0 (firmware default capture mask)\n"
  79. "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
  80. int ql4xenablemd = 1;
  81. module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
  82. MODULE_PARM_DESC(ql4xenablemd,
  83. " Set to enable minidump.\n"
  84. "\t\t 0 - disable minidump\n"
  85. "\t\t 1 - enable minidump (Default)");
  86. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  87. /*
  88. * SCSI host template entry points
  89. */
  90. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  91. /*
  92. * iSCSI template entry points
  93. */
  94. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  95. enum iscsi_param param, char *buf);
  96. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  97. enum iscsi_param param, char *buf);
  98. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  99. enum iscsi_host_param param, char *buf);
  100. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
  101. uint32_t len);
  102. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  103. enum iscsi_param_type param_type,
  104. int param, char *buf);
  105. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  106. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  107. struct sockaddr *dst_addr,
  108. int non_blocking);
  109. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  110. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  111. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  112. enum iscsi_param param, char *buf);
  113. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  114. static struct iscsi_cls_conn *
  115. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  116. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  117. struct iscsi_cls_conn *cls_conn,
  118. uint64_t transport_fd, int is_leading);
  119. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  120. static struct iscsi_cls_session *
  121. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  122. uint16_t qdepth, uint32_t initial_cmdsn);
  123. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  124. static void qla4xxx_task_work(struct work_struct *wdata);
  125. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  126. static int qla4xxx_task_xmit(struct iscsi_task *);
  127. static void qla4xxx_task_cleanup(struct iscsi_task *);
  128. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  129. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  130. struct iscsi_stats *stats);
  131. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  132. uint32_t iface_type, uint32_t payload_size,
  133. uint32_t pid, struct sockaddr *dst_addr);
  134. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  135. uint32_t *num_entries, char *buf);
  136. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
  137. static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
  138. int len);
  139. static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
  140. /*
  141. * SCSI host template entry points
  142. */
  143. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  144. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  145. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  146. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  147. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  148. static int qla4xxx_slave_alloc(struct scsi_device *device);
  149. static int qla4xxx_slave_configure(struct scsi_device *device);
  150. static umode_t qla4_attr_is_visible(int param_type, int param);
  151. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  152. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  153. int reason);
  154. /*
  155. * iSCSI Flash DDB sysfs entry points
  156. */
  157. static int
  158. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  159. struct iscsi_bus_flash_conn *fnode_conn,
  160. void *data, int len);
  161. static int
  162. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  163. int param, char *buf);
  164. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  165. int len);
  166. static int
  167. qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
  168. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  169. struct iscsi_bus_flash_conn *fnode_conn);
  170. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  171. struct iscsi_bus_flash_conn *fnode_conn);
  172. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
  173. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  174. QLA82XX_LEGACY_INTR_CONFIG;
  175. static struct scsi_host_template qla4xxx_driver_template = {
  176. .module = THIS_MODULE,
  177. .name = DRIVER_NAME,
  178. .proc_name = DRIVER_NAME,
  179. .queuecommand = qla4xxx_queuecommand,
  180. .eh_abort_handler = qla4xxx_eh_abort,
  181. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  182. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  183. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  184. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  185. .slave_configure = qla4xxx_slave_configure,
  186. .slave_alloc = qla4xxx_slave_alloc,
  187. .change_queue_depth = qla4xxx_change_queue_depth,
  188. .this_id = -1,
  189. .cmd_per_lun = 3,
  190. .use_clustering = ENABLE_CLUSTERING,
  191. .sg_tablesize = SG_ALL,
  192. .max_sectors = 0xFFFF,
  193. .shost_attrs = qla4xxx_host_attrs,
  194. .host_reset = qla4xxx_host_reset,
  195. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  196. .use_blk_tags = 1,
  197. };
  198. static struct iscsi_transport qla4xxx_iscsi_transport = {
  199. .owner = THIS_MODULE,
  200. .name = DRIVER_NAME,
  201. .caps = CAP_TEXT_NEGO |
  202. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  203. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  204. CAP_MULTI_R2T,
  205. .attr_is_visible = qla4_attr_is_visible,
  206. .create_session = qla4xxx_session_create,
  207. .destroy_session = qla4xxx_session_destroy,
  208. .start_conn = qla4xxx_conn_start,
  209. .create_conn = qla4xxx_conn_create,
  210. .bind_conn = qla4xxx_conn_bind,
  211. .stop_conn = iscsi_conn_stop,
  212. .destroy_conn = qla4xxx_conn_destroy,
  213. .set_param = iscsi_set_param,
  214. .get_conn_param = qla4xxx_conn_get_param,
  215. .get_session_param = qla4xxx_session_get_param,
  216. .get_ep_param = qla4xxx_get_ep_param,
  217. .ep_connect = qla4xxx_ep_connect,
  218. .ep_poll = qla4xxx_ep_poll,
  219. .ep_disconnect = qla4xxx_ep_disconnect,
  220. .get_stats = qla4xxx_conn_get_stats,
  221. .send_pdu = iscsi_conn_send_pdu,
  222. .xmit_task = qla4xxx_task_xmit,
  223. .cleanup_task = qla4xxx_task_cleanup,
  224. .alloc_pdu = qla4xxx_alloc_pdu,
  225. .get_host_param = qla4xxx_host_get_param,
  226. .set_iface_param = qla4xxx_iface_set_param,
  227. .get_iface_param = qla4xxx_get_iface_param,
  228. .bsg_request = qla4xxx_bsg_request,
  229. .send_ping = qla4xxx_send_ping,
  230. .get_chap = qla4xxx_get_chap_list,
  231. .delete_chap = qla4xxx_delete_chap,
  232. .set_chap = qla4xxx_set_chap_entry,
  233. .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
  234. .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
  235. .new_flashnode = qla4xxx_sysfs_ddb_add,
  236. .del_flashnode = qla4xxx_sysfs_ddb_delete,
  237. .login_flashnode = qla4xxx_sysfs_ddb_login,
  238. .logout_flashnode = qla4xxx_sysfs_ddb_logout,
  239. .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
  240. .get_host_stats = qla4xxx_get_host_stats,
  241. };
  242. static struct scsi_transport_template *qla4xxx_scsi_transport;
  243. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  244. uint32_t iface_type, uint32_t payload_size,
  245. uint32_t pid, struct sockaddr *dst_addr)
  246. {
  247. struct scsi_qla_host *ha = to_qla_host(shost);
  248. struct sockaddr_in *addr;
  249. struct sockaddr_in6 *addr6;
  250. uint32_t options = 0;
  251. uint8_t ipaddr[IPv6_ADDR_LEN];
  252. int rval;
  253. memset(ipaddr, 0, IPv6_ADDR_LEN);
  254. /* IPv4 to IPv4 */
  255. if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
  256. (dst_addr->sa_family == AF_INET)) {
  257. addr = (struct sockaddr_in *)dst_addr;
  258. memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
  259. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
  260. "dest: %pI4\n", __func__,
  261. &ha->ip_config.ip_address, ipaddr));
  262. rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
  263. ipaddr);
  264. if (rval)
  265. rval = -EINVAL;
  266. } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
  267. (dst_addr->sa_family == AF_INET6)) {
  268. /* IPv6 to IPv6 */
  269. addr6 = (struct sockaddr_in6 *)dst_addr;
  270. memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
  271. options |= PING_IPV6_PROTOCOL_ENABLE;
  272. /* Ping using LinkLocal address */
  273. if ((iface_num == 0) || (iface_num == 1)) {
  274. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
  275. "src: %pI6 dest: %pI6\n", __func__,
  276. &ha->ip_config.ipv6_link_local_addr,
  277. ipaddr));
  278. options |= PING_IPV6_LINKLOCAL_ADDR;
  279. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  280. pid, ipaddr);
  281. } else {
  282. ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
  283. "not supported\n", __func__, iface_num);
  284. rval = -ENOSYS;
  285. goto exit_send_ping;
  286. }
  287. /*
  288. * If ping using LinkLocal address fails, try ping using
  289. * IPv6 address
  290. */
  291. if (rval != QLA_SUCCESS) {
  292. options &= ~PING_IPV6_LINKLOCAL_ADDR;
  293. if (iface_num == 0) {
  294. options |= PING_IPV6_ADDR0;
  295. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  296. "Ping src: %pI6 "
  297. "dest: %pI6\n", __func__,
  298. &ha->ip_config.ipv6_addr0,
  299. ipaddr));
  300. } else if (iface_num == 1) {
  301. options |= PING_IPV6_ADDR1;
  302. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  303. "Ping src: %pI6 "
  304. "dest: %pI6\n", __func__,
  305. &ha->ip_config.ipv6_addr1,
  306. ipaddr));
  307. }
  308. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  309. pid, ipaddr);
  310. if (rval)
  311. rval = -EINVAL;
  312. }
  313. } else
  314. rval = -ENOSYS;
  315. exit_send_ping:
  316. return rval;
  317. }
  318. static umode_t qla4_attr_is_visible(int param_type, int param)
  319. {
  320. switch (param_type) {
  321. case ISCSI_HOST_PARAM:
  322. switch (param) {
  323. case ISCSI_HOST_PARAM_HWADDRESS:
  324. case ISCSI_HOST_PARAM_IPADDRESS:
  325. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  326. case ISCSI_HOST_PARAM_PORT_STATE:
  327. case ISCSI_HOST_PARAM_PORT_SPEED:
  328. return S_IRUGO;
  329. default:
  330. return 0;
  331. }
  332. case ISCSI_PARAM:
  333. switch (param) {
  334. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  335. case ISCSI_PARAM_PERSISTENT_PORT:
  336. case ISCSI_PARAM_CONN_ADDRESS:
  337. case ISCSI_PARAM_CONN_PORT:
  338. case ISCSI_PARAM_TARGET_NAME:
  339. case ISCSI_PARAM_TPGT:
  340. case ISCSI_PARAM_TARGET_ALIAS:
  341. case ISCSI_PARAM_MAX_BURST:
  342. case ISCSI_PARAM_MAX_R2T:
  343. case ISCSI_PARAM_FIRST_BURST:
  344. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  345. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  346. case ISCSI_PARAM_IFACE_NAME:
  347. case ISCSI_PARAM_CHAP_OUT_IDX:
  348. case ISCSI_PARAM_CHAP_IN_IDX:
  349. case ISCSI_PARAM_USERNAME:
  350. case ISCSI_PARAM_PASSWORD:
  351. case ISCSI_PARAM_USERNAME_IN:
  352. case ISCSI_PARAM_PASSWORD_IN:
  353. case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
  354. case ISCSI_PARAM_DISCOVERY_SESS:
  355. case ISCSI_PARAM_PORTAL_TYPE:
  356. case ISCSI_PARAM_CHAP_AUTH_EN:
  357. case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
  358. case ISCSI_PARAM_BIDI_CHAP_EN:
  359. case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
  360. case ISCSI_PARAM_DEF_TIME2WAIT:
  361. case ISCSI_PARAM_DEF_TIME2RETAIN:
  362. case ISCSI_PARAM_HDRDGST_EN:
  363. case ISCSI_PARAM_DATADGST_EN:
  364. case ISCSI_PARAM_INITIAL_R2T_EN:
  365. case ISCSI_PARAM_IMM_DATA_EN:
  366. case ISCSI_PARAM_PDU_INORDER_EN:
  367. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  368. case ISCSI_PARAM_MAX_SEGMENT_SIZE:
  369. case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
  370. case ISCSI_PARAM_TCP_WSF_DISABLE:
  371. case ISCSI_PARAM_TCP_NAGLE_DISABLE:
  372. case ISCSI_PARAM_TCP_TIMER_SCALE:
  373. case ISCSI_PARAM_TCP_TIMESTAMP_EN:
  374. case ISCSI_PARAM_TCP_XMIT_WSF:
  375. case ISCSI_PARAM_TCP_RECV_WSF:
  376. case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
  377. case ISCSI_PARAM_IPV4_TOS:
  378. case ISCSI_PARAM_IPV6_TC:
  379. case ISCSI_PARAM_IPV6_FLOW_LABEL:
  380. case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
  381. case ISCSI_PARAM_KEEPALIVE_TMO:
  382. case ISCSI_PARAM_LOCAL_PORT:
  383. case ISCSI_PARAM_ISID:
  384. case ISCSI_PARAM_TSID:
  385. case ISCSI_PARAM_DEF_TASKMGMT_TMO:
  386. case ISCSI_PARAM_ERL:
  387. case ISCSI_PARAM_STATSN:
  388. case ISCSI_PARAM_EXP_STATSN:
  389. case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
  390. case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
  391. case ISCSI_PARAM_LOCAL_IPADDR:
  392. return S_IRUGO;
  393. default:
  394. return 0;
  395. }
  396. case ISCSI_NET_PARAM:
  397. switch (param) {
  398. case ISCSI_NET_PARAM_IPV4_ADDR:
  399. case ISCSI_NET_PARAM_IPV4_SUBNET:
  400. case ISCSI_NET_PARAM_IPV4_GW:
  401. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  402. case ISCSI_NET_PARAM_IFACE_ENABLE:
  403. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  404. case ISCSI_NET_PARAM_IPV6_ADDR:
  405. case ISCSI_NET_PARAM_IPV6_ROUTER:
  406. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  407. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  408. case ISCSI_NET_PARAM_VLAN_ID:
  409. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  410. case ISCSI_NET_PARAM_VLAN_ENABLED:
  411. case ISCSI_NET_PARAM_MTU:
  412. case ISCSI_NET_PARAM_PORT:
  413. case ISCSI_NET_PARAM_IPADDR_STATE:
  414. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
  415. case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
  416. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  417. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  418. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  419. case ISCSI_NET_PARAM_TCP_WSF:
  420. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  421. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  422. case ISCSI_NET_PARAM_CACHE_ID:
  423. case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
  424. case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
  425. case ISCSI_NET_PARAM_IPV4_TOS_EN:
  426. case ISCSI_NET_PARAM_IPV4_TOS:
  427. case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
  428. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
  429. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
  430. case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
  431. case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
  432. case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
  433. case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
  434. case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
  435. case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
  436. case ISCSI_NET_PARAM_REDIRECT_EN:
  437. case ISCSI_NET_PARAM_IPV4_TTL:
  438. case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
  439. case ISCSI_NET_PARAM_IPV6_MLD_EN:
  440. case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
  441. case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
  442. case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
  443. case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
  444. case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
  445. case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
  446. case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
  447. case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
  448. return S_IRUGO;
  449. default:
  450. return 0;
  451. }
  452. case ISCSI_IFACE_PARAM:
  453. switch (param) {
  454. case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
  455. case ISCSI_IFACE_PARAM_HDRDGST_EN:
  456. case ISCSI_IFACE_PARAM_DATADGST_EN:
  457. case ISCSI_IFACE_PARAM_IMM_DATA_EN:
  458. case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
  459. case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
  460. case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
  461. case ISCSI_IFACE_PARAM_ERL:
  462. case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
  463. case ISCSI_IFACE_PARAM_FIRST_BURST:
  464. case ISCSI_IFACE_PARAM_MAX_R2T:
  465. case ISCSI_IFACE_PARAM_MAX_BURST:
  466. case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
  467. case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
  468. case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
  469. case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
  470. case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
  471. case ISCSI_IFACE_PARAM_INITIATOR_NAME:
  472. return S_IRUGO;
  473. default:
  474. return 0;
  475. }
  476. case ISCSI_FLASHNODE_PARAM:
  477. switch (param) {
  478. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  479. case ISCSI_FLASHNODE_PORTAL_TYPE:
  480. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  481. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  482. case ISCSI_FLASHNODE_ENTRY_EN:
  483. case ISCSI_FLASHNODE_HDR_DGST_EN:
  484. case ISCSI_FLASHNODE_DATA_DGST_EN:
  485. case ISCSI_FLASHNODE_IMM_DATA_EN:
  486. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  487. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  488. case ISCSI_FLASHNODE_PDU_INORDER:
  489. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  490. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  491. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  492. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  493. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  494. case ISCSI_FLASHNODE_ERL:
  495. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  496. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  497. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  498. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  499. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  500. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  501. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  502. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  503. case ISCSI_FLASHNODE_FIRST_BURST:
  504. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  505. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  506. case ISCSI_FLASHNODE_MAX_R2T:
  507. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  508. case ISCSI_FLASHNODE_ISID:
  509. case ISCSI_FLASHNODE_TSID:
  510. case ISCSI_FLASHNODE_PORT:
  511. case ISCSI_FLASHNODE_MAX_BURST:
  512. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  513. case ISCSI_FLASHNODE_IPADDR:
  514. case ISCSI_FLASHNODE_ALIAS:
  515. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  516. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  517. case ISCSI_FLASHNODE_LOCAL_PORT:
  518. case ISCSI_FLASHNODE_IPV4_TOS:
  519. case ISCSI_FLASHNODE_IPV6_TC:
  520. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  521. case ISCSI_FLASHNODE_NAME:
  522. case ISCSI_FLASHNODE_TPGT:
  523. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  524. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  525. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  526. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  527. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  528. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  529. case ISCSI_FLASHNODE_USERNAME:
  530. case ISCSI_FLASHNODE_PASSWORD:
  531. case ISCSI_FLASHNODE_STATSN:
  532. case ISCSI_FLASHNODE_EXP_STATSN:
  533. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  534. return S_IRUGO;
  535. default:
  536. return 0;
  537. }
  538. }
  539. return 0;
  540. }
  541. /**
  542. * qla4xxx_create chap_list - Create CHAP list from FLASH
  543. * @ha: pointer to adapter structure
  544. *
  545. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  546. * is received, it will be checked in this list. If entry exist then the CHAP
  547. * entry index is set in the DDB. If CHAP entry does not exist in this list
  548. * then a new entry is added in FLASH in CHAP table and the index obtained is
  549. * used in the DDB.
  550. **/
  551. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  552. {
  553. int rval = 0;
  554. uint8_t *chap_flash_data = NULL;
  555. uint32_t offset;
  556. dma_addr_t chap_dma;
  557. uint32_t chap_size = 0;
  558. if (is_qla40XX(ha))
  559. chap_size = MAX_CHAP_ENTRIES_40XX *
  560. sizeof(struct ql4_chap_table);
  561. else /* Single region contains CHAP info for both
  562. * ports which is divided into half for each port.
  563. */
  564. chap_size = ha->hw.flt_chap_size / 2;
  565. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  566. &chap_dma, GFP_KERNEL);
  567. if (!chap_flash_data) {
  568. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  569. return;
  570. }
  571. if (is_qla40XX(ha)) {
  572. offset = FLASH_CHAP_OFFSET;
  573. } else {
  574. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  575. if (ha->port_num == 1)
  576. offset += chap_size;
  577. }
  578. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  579. if (rval != QLA_SUCCESS)
  580. goto exit_chap_list;
  581. if (ha->chap_list == NULL)
  582. ha->chap_list = vmalloc(chap_size);
  583. if (ha->chap_list == NULL) {
  584. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  585. goto exit_chap_list;
  586. }
  587. memset(ha->chap_list, 0, chap_size);
  588. memcpy(ha->chap_list, chap_flash_data, chap_size);
  589. exit_chap_list:
  590. dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
  591. }
  592. static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
  593. int16_t chap_index,
  594. struct ql4_chap_table **chap_entry)
  595. {
  596. int rval = QLA_ERROR;
  597. int max_chap_entries;
  598. if (!ha->chap_list) {
  599. ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
  600. rval = QLA_ERROR;
  601. goto exit_get_chap;
  602. }
  603. if (is_qla80XX(ha))
  604. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  605. sizeof(struct ql4_chap_table);
  606. else
  607. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  608. if (chap_index > max_chap_entries) {
  609. ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
  610. rval = QLA_ERROR;
  611. goto exit_get_chap;
  612. }
  613. *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
  614. if ((*chap_entry)->cookie !=
  615. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  616. rval = QLA_ERROR;
  617. *chap_entry = NULL;
  618. } else {
  619. rval = QLA_SUCCESS;
  620. }
  621. exit_get_chap:
  622. return rval;
  623. }
  624. /**
  625. * qla4xxx_find_free_chap_index - Find the first free chap index
  626. * @ha: pointer to adapter structure
  627. * @chap_index: CHAP index to be returned
  628. *
  629. * Find the first free chap index available in the chap table
  630. *
  631. * Note: Caller should acquire the chap lock before getting here.
  632. **/
  633. static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
  634. uint16_t *chap_index)
  635. {
  636. int i, rval;
  637. int free_index = -1;
  638. int max_chap_entries = 0;
  639. struct ql4_chap_table *chap_table;
  640. if (is_qla80XX(ha))
  641. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  642. sizeof(struct ql4_chap_table);
  643. else
  644. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  645. if (!ha->chap_list) {
  646. ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
  647. rval = QLA_ERROR;
  648. goto exit_find_chap;
  649. }
  650. for (i = 0; i < max_chap_entries; i++) {
  651. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  652. if ((chap_table->cookie !=
  653. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
  654. (i > MAX_RESRV_CHAP_IDX)) {
  655. free_index = i;
  656. break;
  657. }
  658. }
  659. if (free_index != -1) {
  660. *chap_index = free_index;
  661. rval = QLA_SUCCESS;
  662. } else {
  663. rval = QLA_ERROR;
  664. }
  665. exit_find_chap:
  666. return rval;
  667. }
  668. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  669. uint32_t *num_entries, char *buf)
  670. {
  671. struct scsi_qla_host *ha = to_qla_host(shost);
  672. struct ql4_chap_table *chap_table;
  673. struct iscsi_chap_rec *chap_rec;
  674. int max_chap_entries = 0;
  675. int valid_chap_entries = 0;
  676. int ret = 0, i;
  677. if (is_qla80XX(ha))
  678. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  679. sizeof(struct ql4_chap_table);
  680. else
  681. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  682. ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
  683. __func__, *num_entries, chap_tbl_idx);
  684. if (!buf) {
  685. ret = -ENOMEM;
  686. goto exit_get_chap_list;
  687. }
  688. qla4xxx_create_chap_list(ha);
  689. chap_rec = (struct iscsi_chap_rec *) buf;
  690. mutex_lock(&ha->chap_sem);
  691. for (i = chap_tbl_idx; i < max_chap_entries; i++) {
  692. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  693. if (chap_table->cookie !=
  694. __constant_cpu_to_le16(CHAP_VALID_COOKIE))
  695. continue;
  696. chap_rec->chap_tbl_idx = i;
  697. strlcpy(chap_rec->username, chap_table->name,
  698. ISCSI_CHAP_AUTH_NAME_MAX_LEN);
  699. strlcpy(chap_rec->password, chap_table->secret,
  700. QL4_CHAP_MAX_SECRET_LEN);
  701. chap_rec->password_length = chap_table->secret_len;
  702. if (chap_table->flags & BIT_7) /* local */
  703. chap_rec->chap_type = CHAP_TYPE_OUT;
  704. if (chap_table->flags & BIT_6) /* peer */
  705. chap_rec->chap_type = CHAP_TYPE_IN;
  706. chap_rec++;
  707. valid_chap_entries++;
  708. if (valid_chap_entries == *num_entries)
  709. break;
  710. else
  711. continue;
  712. }
  713. mutex_unlock(&ha->chap_sem);
  714. exit_get_chap_list:
  715. ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
  716. __func__, valid_chap_entries);
  717. *num_entries = valid_chap_entries;
  718. return ret;
  719. }
  720. static int __qla4xxx_is_chap_active(struct device *dev, void *data)
  721. {
  722. int ret = 0;
  723. uint16_t *chap_tbl_idx = (uint16_t *) data;
  724. struct iscsi_cls_session *cls_session;
  725. struct iscsi_session *sess;
  726. struct ddb_entry *ddb_entry;
  727. if (!iscsi_is_session_dev(dev))
  728. goto exit_is_chap_active;
  729. cls_session = iscsi_dev_to_session(dev);
  730. sess = cls_session->dd_data;
  731. ddb_entry = sess->dd_data;
  732. if (iscsi_session_chkready(cls_session))
  733. goto exit_is_chap_active;
  734. if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
  735. ret = 1;
  736. exit_is_chap_active:
  737. return ret;
  738. }
  739. static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
  740. uint16_t chap_tbl_idx)
  741. {
  742. int ret = 0;
  743. ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
  744. __qla4xxx_is_chap_active);
  745. return ret;
  746. }
  747. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
  748. {
  749. struct scsi_qla_host *ha = to_qla_host(shost);
  750. struct ql4_chap_table *chap_table;
  751. dma_addr_t chap_dma;
  752. int max_chap_entries = 0;
  753. uint32_t offset = 0;
  754. uint32_t chap_size;
  755. int ret = 0;
  756. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  757. if (chap_table == NULL)
  758. return -ENOMEM;
  759. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  760. if (is_qla80XX(ha))
  761. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  762. sizeof(struct ql4_chap_table);
  763. else
  764. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  765. if (chap_tbl_idx > max_chap_entries) {
  766. ret = -EINVAL;
  767. goto exit_delete_chap;
  768. }
  769. /* Check if chap index is in use.
  770. * If chap is in use don't delet chap entry */
  771. ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
  772. if (ret) {
  773. ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
  774. "delete from flash\n", chap_tbl_idx);
  775. ret = -EBUSY;
  776. goto exit_delete_chap;
  777. }
  778. chap_size = sizeof(struct ql4_chap_table);
  779. if (is_qla40XX(ha))
  780. offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
  781. else {
  782. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  783. /* flt_chap_size is CHAP table size for both ports
  784. * so divide it by 2 to calculate the offset for second port
  785. */
  786. if (ha->port_num == 1)
  787. offset += (ha->hw.flt_chap_size / 2);
  788. offset += (chap_tbl_idx * chap_size);
  789. }
  790. ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  791. if (ret != QLA_SUCCESS) {
  792. ret = -EINVAL;
  793. goto exit_delete_chap;
  794. }
  795. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  796. __le16_to_cpu(chap_table->cookie)));
  797. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  798. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  799. goto exit_delete_chap;
  800. }
  801. chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
  802. offset = FLASH_CHAP_OFFSET |
  803. (chap_tbl_idx * sizeof(struct ql4_chap_table));
  804. ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
  805. FLASH_OPT_RMW_COMMIT);
  806. if (ret == QLA_SUCCESS && ha->chap_list) {
  807. mutex_lock(&ha->chap_sem);
  808. /* Update ha chap_list cache */
  809. memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
  810. chap_table, sizeof(struct ql4_chap_table));
  811. mutex_unlock(&ha->chap_sem);
  812. }
  813. if (ret != QLA_SUCCESS)
  814. ret = -EINVAL;
  815. exit_delete_chap:
  816. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  817. return ret;
  818. }
  819. /**
  820. * qla4xxx_set_chap_entry - Make chap entry with given information
  821. * @shost: pointer to host
  822. * @data: chap info - credentials, index and type to make chap entry
  823. * @len: length of data
  824. *
  825. * Add or update chap entry with the given information
  826. **/
  827. static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
  828. {
  829. struct scsi_qla_host *ha = to_qla_host(shost);
  830. struct iscsi_chap_rec chap_rec;
  831. struct ql4_chap_table *chap_entry = NULL;
  832. struct iscsi_param_info *param_info;
  833. struct nlattr *attr;
  834. int max_chap_entries = 0;
  835. int type;
  836. int rem = len;
  837. int rc = 0;
  838. int size;
  839. memset(&chap_rec, 0, sizeof(chap_rec));
  840. nla_for_each_attr(attr, data, len, rem) {
  841. param_info = nla_data(attr);
  842. switch (param_info->param) {
  843. case ISCSI_CHAP_PARAM_INDEX:
  844. chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
  845. break;
  846. case ISCSI_CHAP_PARAM_CHAP_TYPE:
  847. chap_rec.chap_type = param_info->value[0];
  848. break;
  849. case ISCSI_CHAP_PARAM_USERNAME:
  850. size = min_t(size_t, sizeof(chap_rec.username),
  851. param_info->len);
  852. memcpy(chap_rec.username, param_info->value, size);
  853. break;
  854. case ISCSI_CHAP_PARAM_PASSWORD:
  855. size = min_t(size_t, sizeof(chap_rec.password),
  856. param_info->len);
  857. memcpy(chap_rec.password, param_info->value, size);
  858. break;
  859. case ISCSI_CHAP_PARAM_PASSWORD_LEN:
  860. chap_rec.password_length = param_info->value[0];
  861. break;
  862. default:
  863. ql4_printk(KERN_ERR, ha,
  864. "%s: No such sysfs attribute\n", __func__);
  865. rc = -ENOSYS;
  866. goto exit_set_chap;
  867. };
  868. }
  869. if (chap_rec.chap_type == CHAP_TYPE_IN)
  870. type = BIDI_CHAP;
  871. else
  872. type = LOCAL_CHAP;
  873. if (is_qla80XX(ha))
  874. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  875. sizeof(struct ql4_chap_table);
  876. else
  877. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  878. mutex_lock(&ha->chap_sem);
  879. if (chap_rec.chap_tbl_idx < max_chap_entries) {
  880. rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
  881. &chap_entry);
  882. if (!rc) {
  883. if (!(type == qla4xxx_get_chap_type(chap_entry))) {
  884. ql4_printk(KERN_INFO, ha,
  885. "Type mismatch for CHAP entry %d\n",
  886. chap_rec.chap_tbl_idx);
  887. rc = -EINVAL;
  888. goto exit_unlock_chap;
  889. }
  890. /* If chap index is in use then don't modify it */
  891. rc = qla4xxx_is_chap_active(shost,
  892. chap_rec.chap_tbl_idx);
  893. if (rc) {
  894. ql4_printk(KERN_INFO, ha,
  895. "CHAP entry %d is in use\n",
  896. chap_rec.chap_tbl_idx);
  897. rc = -EBUSY;
  898. goto exit_unlock_chap;
  899. }
  900. }
  901. } else {
  902. rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
  903. if (rc) {
  904. ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
  905. rc = -EBUSY;
  906. goto exit_unlock_chap;
  907. }
  908. }
  909. rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
  910. chap_rec.chap_tbl_idx, type);
  911. exit_unlock_chap:
  912. mutex_unlock(&ha->chap_sem);
  913. exit_set_chap:
  914. return rc;
  915. }
  916. static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
  917. {
  918. struct scsi_qla_host *ha = to_qla_host(shost);
  919. struct iscsi_offload_host_stats *host_stats = NULL;
  920. int host_stats_size;
  921. int ret = 0;
  922. int ddb_idx = 0;
  923. struct ql_iscsi_stats *ql_iscsi_stats = NULL;
  924. int stats_size;
  925. dma_addr_t iscsi_stats_dma;
  926. DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
  927. host_stats_size = sizeof(struct iscsi_offload_host_stats);
  928. if (host_stats_size != len) {
  929. ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
  930. __func__, len, host_stats_size);
  931. ret = -EINVAL;
  932. goto exit_host_stats;
  933. }
  934. host_stats = (struct iscsi_offload_host_stats *)buf;
  935. if (!buf) {
  936. ret = -ENOMEM;
  937. goto exit_host_stats;
  938. }
  939. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  940. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  941. &iscsi_stats_dma, GFP_KERNEL);
  942. if (!ql_iscsi_stats) {
  943. ql4_printk(KERN_ERR, ha,
  944. "Unable to allocate memory for iscsi stats\n");
  945. ret = -ENOMEM;
  946. goto exit_host_stats;
  947. }
  948. ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
  949. iscsi_stats_dma);
  950. if (ret != QLA_SUCCESS) {
  951. ql4_printk(KERN_ERR, ha,
  952. "Unable to retrieve iscsi stats\n");
  953. ret = -EIO;
  954. goto exit_host_stats;
  955. }
  956. host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
  957. host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
  958. host_stats->mactx_multicast_frames =
  959. le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
  960. host_stats->mactx_broadcast_frames =
  961. le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
  962. host_stats->mactx_pause_frames =
  963. le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
  964. host_stats->mactx_control_frames =
  965. le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
  966. host_stats->mactx_deferral =
  967. le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
  968. host_stats->mactx_excess_deferral =
  969. le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
  970. host_stats->mactx_late_collision =
  971. le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
  972. host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
  973. host_stats->mactx_single_collision =
  974. le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
  975. host_stats->mactx_multiple_collision =
  976. le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
  977. host_stats->mactx_collision =
  978. le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
  979. host_stats->mactx_frames_dropped =
  980. le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
  981. host_stats->mactx_jumbo_frames =
  982. le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
  983. host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
  984. host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
  985. host_stats->macrx_unknown_control_frames =
  986. le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
  987. host_stats->macrx_pause_frames =
  988. le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
  989. host_stats->macrx_control_frames =
  990. le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
  991. host_stats->macrx_dribble =
  992. le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
  993. host_stats->macrx_frame_length_error =
  994. le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
  995. host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
  996. host_stats->macrx_carrier_sense_error =
  997. le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
  998. host_stats->macrx_frame_discarded =
  999. le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
  1000. host_stats->macrx_frames_dropped =
  1001. le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
  1002. host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
  1003. host_stats->mac_encoding_error =
  1004. le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
  1005. host_stats->macrx_length_error_large =
  1006. le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
  1007. host_stats->macrx_length_error_small =
  1008. le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
  1009. host_stats->macrx_multicast_frames =
  1010. le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
  1011. host_stats->macrx_broadcast_frames =
  1012. le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
  1013. host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
  1014. host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
  1015. host_stats->iptx_fragments =
  1016. le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
  1017. host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
  1018. host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
  1019. host_stats->iprx_fragments =
  1020. le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
  1021. host_stats->ip_datagram_reassembly =
  1022. le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
  1023. host_stats->ip_invalid_address_error =
  1024. le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
  1025. host_stats->ip_error_packets =
  1026. le64_to_cpu(ql_iscsi_stats->ip_error_packets);
  1027. host_stats->ip_fragrx_overlap =
  1028. le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
  1029. host_stats->ip_fragrx_outoforder =
  1030. le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
  1031. host_stats->ip_datagram_reassembly_timeout =
  1032. le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
  1033. host_stats->ipv6tx_packets =
  1034. le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
  1035. host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
  1036. host_stats->ipv6tx_fragments =
  1037. le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
  1038. host_stats->ipv6rx_packets =
  1039. le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
  1040. host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
  1041. host_stats->ipv6rx_fragments =
  1042. le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
  1043. host_stats->ipv6_datagram_reassembly =
  1044. le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
  1045. host_stats->ipv6_invalid_address_error =
  1046. le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
  1047. host_stats->ipv6_error_packets =
  1048. le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
  1049. host_stats->ipv6_fragrx_overlap =
  1050. le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
  1051. host_stats->ipv6_fragrx_outoforder =
  1052. le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
  1053. host_stats->ipv6_datagram_reassembly_timeout =
  1054. le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
  1055. host_stats->tcptx_segments =
  1056. le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
  1057. host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
  1058. host_stats->tcprx_segments =
  1059. le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
  1060. host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
  1061. host_stats->tcp_duplicate_ack_retx =
  1062. le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
  1063. host_stats->tcp_retx_timer_expired =
  1064. le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
  1065. host_stats->tcprx_duplicate_ack =
  1066. le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
  1067. host_stats->tcprx_pure_ackr =
  1068. le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
  1069. host_stats->tcptx_delayed_ack =
  1070. le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
  1071. host_stats->tcptx_pure_ack =
  1072. le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
  1073. host_stats->tcprx_segment_error =
  1074. le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
  1075. host_stats->tcprx_segment_outoforder =
  1076. le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
  1077. host_stats->tcprx_window_probe =
  1078. le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
  1079. host_stats->tcprx_window_update =
  1080. le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
  1081. host_stats->tcptx_window_probe_persist =
  1082. le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
  1083. host_stats->ecc_error_correction =
  1084. le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
  1085. host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
  1086. host_stats->iscsi_data_bytes_tx =
  1087. le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
  1088. host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
  1089. host_stats->iscsi_data_bytes_rx =
  1090. le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
  1091. host_stats->iscsi_io_completed =
  1092. le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
  1093. host_stats->iscsi_unexpected_io_rx =
  1094. le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
  1095. host_stats->iscsi_format_error =
  1096. le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
  1097. host_stats->iscsi_hdr_digest_error =
  1098. le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
  1099. host_stats->iscsi_data_digest_error =
  1100. le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
  1101. host_stats->iscsi_sequence_error =
  1102. le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
  1103. exit_host_stats:
  1104. if (ql_iscsi_stats)
  1105. dma_free_coherent(&ha->pdev->dev, host_stats_size,
  1106. ql_iscsi_stats, iscsi_stats_dma);
  1107. ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
  1108. __func__);
  1109. return ret;
  1110. }
  1111. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  1112. enum iscsi_param_type param_type,
  1113. int param, char *buf)
  1114. {
  1115. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  1116. struct scsi_qla_host *ha = to_qla_host(shost);
  1117. int ival;
  1118. char *pval = NULL;
  1119. int len = -ENOSYS;
  1120. if (param_type == ISCSI_NET_PARAM) {
  1121. switch (param) {
  1122. case ISCSI_NET_PARAM_IPV4_ADDR:
  1123. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  1124. break;
  1125. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1126. len = sprintf(buf, "%pI4\n",
  1127. &ha->ip_config.subnet_mask);
  1128. break;
  1129. case ISCSI_NET_PARAM_IPV4_GW:
  1130. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  1131. break;
  1132. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1133. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1134. OP_STATE(ha->ip_config.ipv4_options,
  1135. IPOPT_IPV4_PROTOCOL_ENABLE, pval);
  1136. } else {
  1137. OP_STATE(ha->ip_config.ipv6_options,
  1138. IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
  1139. }
  1140. len = sprintf(buf, "%s\n", pval);
  1141. break;
  1142. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1143. len = sprintf(buf, "%s\n",
  1144. (ha->ip_config.tcp_options &
  1145. TCPOPT_DHCP_ENABLE) ?
  1146. "dhcp" : "static");
  1147. break;
  1148. case ISCSI_NET_PARAM_IPV6_ADDR:
  1149. if (iface->iface_num == 0)
  1150. len = sprintf(buf, "%pI6\n",
  1151. &ha->ip_config.ipv6_addr0);
  1152. if (iface->iface_num == 1)
  1153. len = sprintf(buf, "%pI6\n",
  1154. &ha->ip_config.ipv6_addr1);
  1155. break;
  1156. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  1157. len = sprintf(buf, "%pI6\n",
  1158. &ha->ip_config.ipv6_link_local_addr);
  1159. break;
  1160. case ISCSI_NET_PARAM_IPV6_ROUTER:
  1161. len = sprintf(buf, "%pI6\n",
  1162. &ha->ip_config.ipv6_default_router_addr);
  1163. break;
  1164. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  1165. pval = (ha->ip_config.ipv6_addl_options &
  1166. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  1167. "nd" : "static";
  1168. len = sprintf(buf, "%s\n", pval);
  1169. break;
  1170. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  1171. pval = (ha->ip_config.ipv6_addl_options &
  1172. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  1173. "auto" : "static";
  1174. len = sprintf(buf, "%s\n", pval);
  1175. break;
  1176. case ISCSI_NET_PARAM_VLAN_ID:
  1177. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1178. ival = ha->ip_config.ipv4_vlan_tag &
  1179. ISCSI_MAX_VLAN_ID;
  1180. else
  1181. ival = ha->ip_config.ipv6_vlan_tag &
  1182. ISCSI_MAX_VLAN_ID;
  1183. len = sprintf(buf, "%d\n", ival);
  1184. break;
  1185. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  1186. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1187. ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
  1188. ISCSI_MAX_VLAN_PRIORITY;
  1189. else
  1190. ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
  1191. ISCSI_MAX_VLAN_PRIORITY;
  1192. len = sprintf(buf, "%d\n", ival);
  1193. break;
  1194. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1195. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1196. OP_STATE(ha->ip_config.ipv4_options,
  1197. IPOPT_VLAN_TAGGING_ENABLE, pval);
  1198. } else {
  1199. OP_STATE(ha->ip_config.ipv6_options,
  1200. IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
  1201. }
  1202. len = sprintf(buf, "%s\n", pval);
  1203. break;
  1204. case ISCSI_NET_PARAM_MTU:
  1205. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  1206. break;
  1207. case ISCSI_NET_PARAM_PORT:
  1208. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1209. len = sprintf(buf, "%d\n",
  1210. ha->ip_config.ipv4_port);
  1211. else
  1212. len = sprintf(buf, "%d\n",
  1213. ha->ip_config.ipv6_port);
  1214. break;
  1215. case ISCSI_NET_PARAM_IPADDR_STATE:
  1216. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1217. pval = iscsi_get_ipaddress_state_name(
  1218. ha->ip_config.ipv4_addr_state);
  1219. } else {
  1220. if (iface->iface_num == 0)
  1221. pval = iscsi_get_ipaddress_state_name(
  1222. ha->ip_config.ipv6_addr0_state);
  1223. else if (iface->iface_num == 1)
  1224. pval = iscsi_get_ipaddress_state_name(
  1225. ha->ip_config.ipv6_addr1_state);
  1226. }
  1227. len = sprintf(buf, "%s\n", pval);
  1228. break;
  1229. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
  1230. pval = iscsi_get_ipaddress_state_name(
  1231. ha->ip_config.ipv6_link_local_state);
  1232. len = sprintf(buf, "%s\n", pval);
  1233. break;
  1234. case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
  1235. pval = iscsi_get_router_state_name(
  1236. ha->ip_config.ipv6_default_router_state);
  1237. len = sprintf(buf, "%s\n", pval);
  1238. break;
  1239. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  1240. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1241. OP_STATE(~ha->ip_config.tcp_options,
  1242. TCPOPT_DELAYED_ACK_DISABLE, pval);
  1243. } else {
  1244. OP_STATE(~ha->ip_config.ipv6_tcp_options,
  1245. IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
  1246. }
  1247. len = sprintf(buf, "%s\n", pval);
  1248. break;
  1249. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  1250. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1251. OP_STATE(~ha->ip_config.tcp_options,
  1252. TCPOPT_NAGLE_ALGO_DISABLE, pval);
  1253. } else {
  1254. OP_STATE(~ha->ip_config.ipv6_tcp_options,
  1255. IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
  1256. }
  1257. len = sprintf(buf, "%s\n", pval);
  1258. break;
  1259. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  1260. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1261. OP_STATE(~ha->ip_config.tcp_options,
  1262. TCPOPT_WINDOW_SCALE_DISABLE, pval);
  1263. } else {
  1264. OP_STATE(~ha->ip_config.ipv6_tcp_options,
  1265. IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
  1266. pval);
  1267. }
  1268. len = sprintf(buf, "%s\n", pval);
  1269. break;
  1270. case ISCSI_NET_PARAM_TCP_WSF:
  1271. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1272. len = sprintf(buf, "%d\n",
  1273. ha->ip_config.tcp_wsf);
  1274. else
  1275. len = sprintf(buf, "%d\n",
  1276. ha->ip_config.ipv6_tcp_wsf);
  1277. break;
  1278. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  1279. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1280. ival = (ha->ip_config.tcp_options &
  1281. TCPOPT_TIMER_SCALE) >> 1;
  1282. else
  1283. ival = (ha->ip_config.ipv6_tcp_options &
  1284. IPV6_TCPOPT_TIMER_SCALE) >> 1;
  1285. len = sprintf(buf, "%d\n", ival);
  1286. break;
  1287. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  1288. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1289. OP_STATE(ha->ip_config.tcp_options,
  1290. TCPOPT_TIMESTAMP_ENABLE, pval);
  1291. } else {
  1292. OP_STATE(ha->ip_config.ipv6_tcp_options,
  1293. IPV6_TCPOPT_TIMESTAMP_EN, pval);
  1294. }
  1295. len = sprintf(buf, "%s\n", pval);
  1296. break;
  1297. case ISCSI_NET_PARAM_CACHE_ID:
  1298. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1299. len = sprintf(buf, "%d\n",
  1300. ha->ip_config.ipv4_cache_id);
  1301. else
  1302. len = sprintf(buf, "%d\n",
  1303. ha->ip_config.ipv6_cache_id);
  1304. break;
  1305. case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
  1306. OP_STATE(ha->ip_config.tcp_options,
  1307. TCPOPT_DNS_SERVER_IP_EN, pval);
  1308. len = sprintf(buf, "%s\n", pval);
  1309. break;
  1310. case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
  1311. OP_STATE(ha->ip_config.tcp_options,
  1312. TCPOPT_SLP_DA_INFO_EN, pval);
  1313. len = sprintf(buf, "%s\n", pval);
  1314. break;
  1315. case ISCSI_NET_PARAM_IPV4_TOS_EN:
  1316. OP_STATE(ha->ip_config.ipv4_options,
  1317. IPOPT_IPV4_TOS_EN, pval);
  1318. len = sprintf(buf, "%s\n", pval);
  1319. break;
  1320. case ISCSI_NET_PARAM_IPV4_TOS:
  1321. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
  1322. break;
  1323. case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
  1324. OP_STATE(ha->ip_config.ipv4_options,
  1325. IPOPT_GRAT_ARP_EN, pval);
  1326. len = sprintf(buf, "%s\n", pval);
  1327. break;
  1328. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
  1329. OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
  1330. pval);
  1331. len = sprintf(buf, "%s\n", pval);
  1332. break;
  1333. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
  1334. pval = (ha->ip_config.ipv4_alt_cid_len) ?
  1335. (char *)ha->ip_config.ipv4_alt_cid : "";
  1336. len = sprintf(buf, "%s\n", pval);
  1337. break;
  1338. case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
  1339. OP_STATE(ha->ip_config.ipv4_options,
  1340. IPOPT_REQ_VID_EN, pval);
  1341. len = sprintf(buf, "%s\n", pval);
  1342. break;
  1343. case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
  1344. OP_STATE(ha->ip_config.ipv4_options,
  1345. IPOPT_USE_VID_EN, pval);
  1346. len = sprintf(buf, "%s\n", pval);
  1347. break;
  1348. case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
  1349. pval = (ha->ip_config.ipv4_vid_len) ?
  1350. (char *)ha->ip_config.ipv4_vid : "";
  1351. len = sprintf(buf, "%s\n", pval);
  1352. break;
  1353. case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
  1354. OP_STATE(ha->ip_config.ipv4_options,
  1355. IPOPT_LEARN_IQN_EN, pval);
  1356. len = sprintf(buf, "%s\n", pval);
  1357. break;
  1358. case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
  1359. OP_STATE(~ha->ip_config.ipv4_options,
  1360. IPOPT_FRAGMENTATION_DISABLE, pval);
  1361. len = sprintf(buf, "%s\n", pval);
  1362. break;
  1363. case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
  1364. OP_STATE(ha->ip_config.ipv4_options,
  1365. IPOPT_IN_FORWARD_EN, pval);
  1366. len = sprintf(buf, "%s\n", pval);
  1367. break;
  1368. case ISCSI_NET_PARAM_REDIRECT_EN:
  1369. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1370. OP_STATE(ha->ip_config.ipv4_options,
  1371. IPOPT_ARP_REDIRECT_EN, pval);
  1372. } else {
  1373. OP_STATE(ha->ip_config.ipv6_options,
  1374. IPV6_OPT_REDIRECT_EN, pval);
  1375. }
  1376. len = sprintf(buf, "%s\n", pval);
  1377. break;
  1378. case ISCSI_NET_PARAM_IPV4_TTL:
  1379. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
  1380. break;
  1381. case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
  1382. OP_STATE(ha->ip_config.ipv6_options,
  1383. IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
  1384. len = sprintf(buf, "%s\n", pval);
  1385. break;
  1386. case ISCSI_NET_PARAM_IPV6_MLD_EN:
  1387. OP_STATE(ha->ip_config.ipv6_addl_options,
  1388. IPV6_ADDOPT_MLD_EN, pval);
  1389. len = sprintf(buf, "%s\n", pval);
  1390. break;
  1391. case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
  1392. len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
  1393. break;
  1394. case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
  1395. len = sprintf(buf, "%d\n",
  1396. ha->ip_config.ipv6_traffic_class);
  1397. break;
  1398. case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
  1399. len = sprintf(buf, "%d\n",
  1400. ha->ip_config.ipv6_hop_limit);
  1401. break;
  1402. case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
  1403. len = sprintf(buf, "%d\n",
  1404. ha->ip_config.ipv6_nd_reach_time);
  1405. break;
  1406. case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
  1407. len = sprintf(buf, "%d\n",
  1408. ha->ip_config.ipv6_nd_rexmit_timer);
  1409. break;
  1410. case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
  1411. len = sprintf(buf, "%d\n",
  1412. ha->ip_config.ipv6_nd_stale_timeout);
  1413. break;
  1414. case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
  1415. len = sprintf(buf, "%d\n",
  1416. ha->ip_config.ipv6_dup_addr_detect_count);
  1417. break;
  1418. case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
  1419. len = sprintf(buf, "%d\n",
  1420. ha->ip_config.ipv6_gw_advrt_mtu);
  1421. break;
  1422. default:
  1423. len = -ENOSYS;
  1424. }
  1425. } else if (param_type == ISCSI_IFACE_PARAM) {
  1426. switch (param) {
  1427. case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
  1428. len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
  1429. break;
  1430. case ISCSI_IFACE_PARAM_HDRDGST_EN:
  1431. OP_STATE(ha->ip_config.iscsi_options,
  1432. ISCSIOPTS_HEADER_DIGEST_EN, pval);
  1433. len = sprintf(buf, "%s\n", pval);
  1434. break;
  1435. case ISCSI_IFACE_PARAM_DATADGST_EN:
  1436. OP_STATE(ha->ip_config.iscsi_options,
  1437. ISCSIOPTS_DATA_DIGEST_EN, pval);
  1438. len = sprintf(buf, "%s\n", pval);
  1439. break;
  1440. case ISCSI_IFACE_PARAM_IMM_DATA_EN:
  1441. OP_STATE(ha->ip_config.iscsi_options,
  1442. ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
  1443. len = sprintf(buf, "%s\n", pval);
  1444. break;
  1445. case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
  1446. OP_STATE(ha->ip_config.iscsi_options,
  1447. ISCSIOPTS_INITIAL_R2T_EN, pval);
  1448. len = sprintf(buf, "%s\n", pval);
  1449. break;
  1450. case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
  1451. OP_STATE(ha->ip_config.iscsi_options,
  1452. ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
  1453. len = sprintf(buf, "%s\n", pval);
  1454. break;
  1455. case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
  1456. OP_STATE(ha->ip_config.iscsi_options,
  1457. ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
  1458. len = sprintf(buf, "%s\n", pval);
  1459. break;
  1460. case ISCSI_IFACE_PARAM_ERL:
  1461. len = sprintf(buf, "%d\n",
  1462. (ha->ip_config.iscsi_options &
  1463. ISCSIOPTS_ERL));
  1464. break;
  1465. case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
  1466. len = sprintf(buf, "%u\n",
  1467. ha->ip_config.iscsi_max_pdu_size *
  1468. BYTE_UNITS);
  1469. break;
  1470. case ISCSI_IFACE_PARAM_FIRST_BURST:
  1471. len = sprintf(buf, "%u\n",
  1472. ha->ip_config.iscsi_first_burst_len *
  1473. BYTE_UNITS);
  1474. break;
  1475. case ISCSI_IFACE_PARAM_MAX_R2T:
  1476. len = sprintf(buf, "%d\n",
  1477. ha->ip_config.iscsi_max_outstnd_r2t);
  1478. break;
  1479. case ISCSI_IFACE_PARAM_MAX_BURST:
  1480. len = sprintf(buf, "%u\n",
  1481. ha->ip_config.iscsi_max_burst_len *
  1482. BYTE_UNITS);
  1483. break;
  1484. case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
  1485. OP_STATE(ha->ip_config.iscsi_options,
  1486. ISCSIOPTS_CHAP_AUTH_EN, pval);
  1487. len = sprintf(buf, "%s\n", pval);
  1488. break;
  1489. case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
  1490. OP_STATE(ha->ip_config.iscsi_options,
  1491. ISCSIOPTS_BIDI_CHAP_EN, pval);
  1492. len = sprintf(buf, "%s\n", pval);
  1493. break;
  1494. case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
  1495. OP_STATE(ha->ip_config.iscsi_options,
  1496. ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
  1497. len = sprintf(buf, "%s\n", pval);
  1498. break;
  1499. case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
  1500. OP_STATE(ha->ip_config.iscsi_options,
  1501. ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
  1502. len = sprintf(buf, "%s\n", pval);
  1503. break;
  1504. case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
  1505. OP_STATE(ha->ip_config.iscsi_options,
  1506. ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
  1507. len = sprintf(buf, "%s\n", pval);
  1508. break;
  1509. case ISCSI_IFACE_PARAM_INITIATOR_NAME:
  1510. len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
  1511. break;
  1512. default:
  1513. len = -ENOSYS;
  1514. }
  1515. }
  1516. return len;
  1517. }
  1518. static struct iscsi_endpoint *
  1519. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  1520. int non_blocking)
  1521. {
  1522. int ret;
  1523. struct iscsi_endpoint *ep;
  1524. struct qla_endpoint *qla_ep;
  1525. struct scsi_qla_host *ha;
  1526. struct sockaddr_in *addr;
  1527. struct sockaddr_in6 *addr6;
  1528. if (!shost) {
  1529. ret = -ENXIO;
  1530. pr_err("%s: shost is NULL\n", __func__);
  1531. return ERR_PTR(ret);
  1532. }
  1533. ha = iscsi_host_priv(shost);
  1534. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  1535. if (!ep) {
  1536. ret = -ENOMEM;
  1537. return ERR_PTR(ret);
  1538. }
  1539. qla_ep = ep->dd_data;
  1540. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  1541. if (dst_addr->sa_family == AF_INET) {
  1542. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  1543. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  1544. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  1545. (char *)&addr->sin_addr));
  1546. } else if (dst_addr->sa_family == AF_INET6) {
  1547. memcpy(&qla_ep->dst_addr, dst_addr,
  1548. sizeof(struct sockaddr_in6));
  1549. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  1550. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  1551. (char *)&addr6->sin6_addr));
  1552. } else {
  1553. ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
  1554. __func__);
  1555. }
  1556. qla_ep->host = shost;
  1557. return ep;
  1558. }
  1559. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  1560. {
  1561. struct qla_endpoint *qla_ep;
  1562. struct scsi_qla_host *ha;
  1563. int ret = 0;
  1564. qla_ep = ep->dd_data;
  1565. ha = to_qla_host(qla_ep->host);
  1566. DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
  1567. if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
  1568. ret = 1;
  1569. return ret;
  1570. }
  1571. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  1572. {
  1573. struct qla_endpoint *qla_ep;
  1574. struct scsi_qla_host *ha;
  1575. qla_ep = ep->dd_data;
  1576. ha = to_qla_host(qla_ep->host);
  1577. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  1578. ha->host_no));
  1579. iscsi_destroy_endpoint(ep);
  1580. }
  1581. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  1582. enum iscsi_param param,
  1583. char *buf)
  1584. {
  1585. struct qla_endpoint *qla_ep = ep->dd_data;
  1586. struct sockaddr *dst_addr;
  1587. struct scsi_qla_host *ha;
  1588. if (!qla_ep)
  1589. return -ENOTCONN;
  1590. ha = to_qla_host(qla_ep->host);
  1591. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  1592. ha->host_no));
  1593. switch (param) {
  1594. case ISCSI_PARAM_CONN_PORT:
  1595. case ISCSI_PARAM_CONN_ADDRESS:
  1596. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  1597. if (!dst_addr)
  1598. return -ENOTCONN;
  1599. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  1600. &qla_ep->dst_addr, param, buf);
  1601. default:
  1602. return -ENOSYS;
  1603. }
  1604. }
  1605. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  1606. struct iscsi_stats *stats)
  1607. {
  1608. struct iscsi_session *sess;
  1609. struct iscsi_cls_session *cls_sess;
  1610. struct ddb_entry *ddb_entry;
  1611. struct scsi_qla_host *ha;
  1612. struct ql_iscsi_stats *ql_iscsi_stats;
  1613. int stats_size;
  1614. int ret;
  1615. dma_addr_t iscsi_stats_dma;
  1616. cls_sess = iscsi_conn_to_session(cls_conn);
  1617. sess = cls_sess->dd_data;
  1618. ddb_entry = sess->dd_data;
  1619. ha = ddb_entry->ha;
  1620. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  1621. ha->host_no));
  1622. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  1623. /* Allocate memory */
  1624. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  1625. &iscsi_stats_dma, GFP_KERNEL);
  1626. if (!ql_iscsi_stats) {
  1627. ql4_printk(KERN_ERR, ha,
  1628. "Unable to allocate memory for iscsi stats\n");
  1629. goto exit_get_stats;
  1630. }
  1631. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  1632. iscsi_stats_dma);
  1633. if (ret != QLA_SUCCESS) {
  1634. ql4_printk(KERN_ERR, ha,
  1635. "Unable to retrieve iscsi stats\n");
  1636. goto free_stats;
  1637. }
  1638. /* octets */
  1639. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  1640. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  1641. /* xmit pdus */
  1642. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  1643. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  1644. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  1645. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  1646. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  1647. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  1648. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  1649. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  1650. /* recv pdus */
  1651. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  1652. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  1653. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  1654. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  1655. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  1656. stats->logoutrsp_pdus =
  1657. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  1658. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  1659. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  1660. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  1661. free_stats:
  1662. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  1663. iscsi_stats_dma);
  1664. exit_get_stats:
  1665. return;
  1666. }
  1667. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  1668. {
  1669. struct iscsi_cls_session *session;
  1670. struct iscsi_session *sess;
  1671. unsigned long flags;
  1672. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  1673. session = starget_to_session(scsi_target(sc->device));
  1674. sess = session->dd_data;
  1675. spin_lock_irqsave(&session->lock, flags);
  1676. if (session->state == ISCSI_SESSION_FAILED)
  1677. ret = BLK_EH_RESET_TIMER;
  1678. spin_unlock_irqrestore(&session->lock, flags);
  1679. return ret;
  1680. }
  1681. static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
  1682. {
  1683. struct scsi_qla_host *ha = to_qla_host(shost);
  1684. struct iscsi_cls_host *ihost = shost->shost_data;
  1685. uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
  1686. qla4xxx_get_firmware_state(ha);
  1687. switch (ha->addl_fw_state & 0x0F00) {
  1688. case FW_ADDSTATE_LINK_SPEED_10MBPS:
  1689. speed = ISCSI_PORT_SPEED_10MBPS;
  1690. break;
  1691. case FW_ADDSTATE_LINK_SPEED_100MBPS:
  1692. speed = ISCSI_PORT_SPEED_100MBPS;
  1693. break;
  1694. case FW_ADDSTATE_LINK_SPEED_1GBPS:
  1695. speed = ISCSI_PORT_SPEED_1GBPS;
  1696. break;
  1697. case FW_ADDSTATE_LINK_SPEED_10GBPS:
  1698. speed = ISCSI_PORT_SPEED_10GBPS;
  1699. break;
  1700. }
  1701. ihost->port_speed = speed;
  1702. }
  1703. static void qla4xxx_set_port_state(struct Scsi_Host *shost)
  1704. {
  1705. struct scsi_qla_host *ha = to_qla_host(shost);
  1706. struct iscsi_cls_host *ihost = shost->shost_data;
  1707. uint32_t state = ISCSI_PORT_STATE_DOWN;
  1708. if (test_bit(AF_LINK_UP, &ha->flags))
  1709. state = ISCSI_PORT_STATE_UP;
  1710. ihost->port_state = state;
  1711. }
  1712. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  1713. enum iscsi_host_param param, char *buf)
  1714. {
  1715. struct scsi_qla_host *ha = to_qla_host(shost);
  1716. int len;
  1717. switch (param) {
  1718. case ISCSI_HOST_PARAM_HWADDRESS:
  1719. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  1720. break;
  1721. case ISCSI_HOST_PARAM_IPADDRESS:
  1722. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  1723. break;
  1724. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  1725. len = sprintf(buf, "%s\n", ha->name_string);
  1726. break;
  1727. case ISCSI_HOST_PARAM_PORT_STATE:
  1728. qla4xxx_set_port_state(shost);
  1729. len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  1730. break;
  1731. case ISCSI_HOST_PARAM_PORT_SPEED:
  1732. qla4xxx_set_port_speed(shost);
  1733. len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  1734. break;
  1735. default:
  1736. return -ENOSYS;
  1737. }
  1738. return len;
  1739. }
  1740. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  1741. {
  1742. if (ha->iface_ipv4)
  1743. return;
  1744. /* IPv4 */
  1745. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  1746. &qla4xxx_iscsi_transport,
  1747. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  1748. if (!ha->iface_ipv4)
  1749. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  1750. "iface0.\n");
  1751. }
  1752. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  1753. {
  1754. if (!ha->iface_ipv6_0)
  1755. /* IPv6 iface-0 */
  1756. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  1757. &qla4xxx_iscsi_transport,
  1758. ISCSI_IFACE_TYPE_IPV6, 0,
  1759. 0);
  1760. if (!ha->iface_ipv6_0)
  1761. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  1762. "iface0.\n");
  1763. if (!ha->iface_ipv6_1)
  1764. /* IPv6 iface-1 */
  1765. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  1766. &qla4xxx_iscsi_transport,
  1767. ISCSI_IFACE_TYPE_IPV6, 1,
  1768. 0);
  1769. if (!ha->iface_ipv6_1)
  1770. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  1771. "iface1.\n");
  1772. }
  1773. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  1774. {
  1775. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  1776. qla4xxx_create_ipv4_iface(ha);
  1777. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  1778. qla4xxx_create_ipv6_iface(ha);
  1779. }
  1780. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  1781. {
  1782. if (ha->iface_ipv4) {
  1783. iscsi_destroy_iface(ha->iface_ipv4);
  1784. ha->iface_ipv4 = NULL;
  1785. }
  1786. }
  1787. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  1788. {
  1789. if (ha->iface_ipv6_0) {
  1790. iscsi_destroy_iface(ha->iface_ipv6_0);
  1791. ha->iface_ipv6_0 = NULL;
  1792. }
  1793. if (ha->iface_ipv6_1) {
  1794. iscsi_destroy_iface(ha->iface_ipv6_1);
  1795. ha->iface_ipv6_1 = NULL;
  1796. }
  1797. }
  1798. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  1799. {
  1800. qla4xxx_destroy_ipv4_iface(ha);
  1801. qla4xxx_destroy_ipv6_iface(ha);
  1802. }
  1803. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  1804. struct iscsi_iface_param_info *iface_param,
  1805. struct addr_ctrl_blk *init_fw_cb)
  1806. {
  1807. /*
  1808. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  1809. * iface_num 1 is valid only for IPv6 Addr.
  1810. */
  1811. switch (iface_param->param) {
  1812. case ISCSI_NET_PARAM_IPV6_ADDR:
  1813. if (iface_param->iface_num & 0x1)
  1814. /* IPv6 Addr 1 */
  1815. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  1816. sizeof(init_fw_cb->ipv6_addr1));
  1817. else
  1818. /* IPv6 Addr 0 */
  1819. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  1820. sizeof(init_fw_cb->ipv6_addr0));
  1821. break;
  1822. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  1823. if (iface_param->iface_num & 0x1)
  1824. break;
  1825. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  1826. sizeof(init_fw_cb->ipv6_if_id));
  1827. break;
  1828. case ISCSI_NET_PARAM_IPV6_ROUTER:
  1829. if (iface_param->iface_num & 0x1)
  1830. break;
  1831. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  1832. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1833. break;
  1834. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  1835. /* Autocfg applies to even interface */
  1836. if (iface_param->iface_num & 0x1)
  1837. break;
  1838. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  1839. init_fw_cb->ipv6_addtl_opts &=
  1840. cpu_to_le16(
  1841. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1842. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  1843. init_fw_cb->ipv6_addtl_opts |=
  1844. cpu_to_le16(
  1845. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1846. else
  1847. ql4_printk(KERN_ERR, ha,
  1848. "Invalid autocfg setting for IPv6 addr\n");
  1849. break;
  1850. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  1851. /* Autocfg applies to even interface */
  1852. if (iface_param->iface_num & 0x1)
  1853. break;
  1854. if (iface_param->value[0] ==
  1855. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  1856. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  1857. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1858. else if (iface_param->value[0] ==
  1859. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  1860. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  1861. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1862. else
  1863. ql4_printk(KERN_ERR, ha,
  1864. "Invalid autocfg setting for IPv6 linklocal addr\n");
  1865. break;
  1866. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  1867. /* Autocfg applies to even interface */
  1868. if (iface_param->iface_num & 0x1)
  1869. break;
  1870. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  1871. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  1872. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1873. break;
  1874. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1875. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1876. init_fw_cb->ipv6_opts |=
  1877. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  1878. qla4xxx_create_ipv6_iface(ha);
  1879. } else {
  1880. init_fw_cb->ipv6_opts &=
  1881. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  1882. 0xFFFF);
  1883. qla4xxx_destroy_ipv6_iface(ha);
  1884. }
  1885. break;
  1886. case ISCSI_NET_PARAM_VLAN_TAG:
  1887. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  1888. break;
  1889. init_fw_cb->ipv6_vlan_tag =
  1890. cpu_to_be16(*(uint16_t *)iface_param->value);
  1891. break;
  1892. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1893. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1894. init_fw_cb->ipv6_opts |=
  1895. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  1896. else
  1897. init_fw_cb->ipv6_opts &=
  1898. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  1899. break;
  1900. case ISCSI_NET_PARAM_MTU:
  1901. init_fw_cb->eth_mtu_size =
  1902. cpu_to_le16(*(uint16_t *)iface_param->value);
  1903. break;
  1904. case ISCSI_NET_PARAM_PORT:
  1905. /* Autocfg applies to even interface */
  1906. if (iface_param->iface_num & 0x1)
  1907. break;
  1908. init_fw_cb->ipv6_port =
  1909. cpu_to_le16(*(uint16_t *)iface_param->value);
  1910. break;
  1911. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  1912. if (iface_param->iface_num & 0x1)
  1913. break;
  1914. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  1915. init_fw_cb->ipv6_tcp_opts |=
  1916. cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
  1917. else
  1918. init_fw_cb->ipv6_tcp_opts &=
  1919. cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
  1920. 0xFFFF);
  1921. break;
  1922. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  1923. if (iface_param->iface_num & 0x1)
  1924. break;
  1925. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  1926. init_fw_cb->ipv6_tcp_opts |=
  1927. cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
  1928. else
  1929. init_fw_cb->ipv6_tcp_opts &=
  1930. cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
  1931. break;
  1932. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  1933. if (iface_param->iface_num & 0x1)
  1934. break;
  1935. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  1936. init_fw_cb->ipv6_tcp_opts |=
  1937. cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
  1938. else
  1939. init_fw_cb->ipv6_tcp_opts &=
  1940. cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
  1941. break;
  1942. case ISCSI_NET_PARAM_TCP_WSF:
  1943. if (iface_param->iface_num & 0x1)
  1944. break;
  1945. init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
  1946. break;
  1947. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  1948. if (iface_param->iface_num & 0x1)
  1949. break;
  1950. init_fw_cb->ipv6_tcp_opts &=
  1951. cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
  1952. init_fw_cb->ipv6_tcp_opts |=
  1953. cpu_to_le16((iface_param->value[0] << 1) &
  1954. IPV6_TCPOPT_TIMER_SCALE);
  1955. break;
  1956. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  1957. if (iface_param->iface_num & 0x1)
  1958. break;
  1959. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1960. init_fw_cb->ipv6_tcp_opts |=
  1961. cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
  1962. else
  1963. init_fw_cb->ipv6_tcp_opts &=
  1964. cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
  1965. break;
  1966. case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
  1967. if (iface_param->iface_num & 0x1)
  1968. break;
  1969. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1970. init_fw_cb->ipv6_opts |=
  1971. cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
  1972. else
  1973. init_fw_cb->ipv6_opts &=
  1974. cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
  1975. break;
  1976. case ISCSI_NET_PARAM_REDIRECT_EN:
  1977. if (iface_param->iface_num & 0x1)
  1978. break;
  1979. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1980. init_fw_cb->ipv6_opts |=
  1981. cpu_to_le16(IPV6_OPT_REDIRECT_EN);
  1982. else
  1983. init_fw_cb->ipv6_opts &=
  1984. cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
  1985. break;
  1986. case ISCSI_NET_PARAM_IPV6_MLD_EN:
  1987. if (iface_param->iface_num & 0x1)
  1988. break;
  1989. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1990. init_fw_cb->ipv6_addtl_opts |=
  1991. cpu_to_le16(IPV6_ADDOPT_MLD_EN);
  1992. else
  1993. init_fw_cb->ipv6_addtl_opts &=
  1994. cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
  1995. break;
  1996. case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
  1997. if (iface_param->iface_num & 0x1)
  1998. break;
  1999. init_fw_cb->ipv6_flow_lbl =
  2000. cpu_to_le16(*(uint16_t *)iface_param->value);
  2001. break;
  2002. case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
  2003. if (iface_param->iface_num & 0x1)
  2004. break;
  2005. init_fw_cb->ipv6_traffic_class = iface_param->value[0];
  2006. break;
  2007. case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
  2008. if (iface_param->iface_num & 0x1)
  2009. break;
  2010. init_fw_cb->ipv6_hop_limit = iface_param->value[0];
  2011. break;
  2012. case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
  2013. if (iface_param->iface_num & 0x1)
  2014. break;
  2015. init_fw_cb->ipv6_nd_reach_time =
  2016. cpu_to_le32(*(uint32_t *)iface_param->value);
  2017. break;
  2018. case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
  2019. if (iface_param->iface_num & 0x1)
  2020. break;
  2021. init_fw_cb->ipv6_nd_rexmit_timer =
  2022. cpu_to_le32(*(uint32_t *)iface_param->value);
  2023. break;
  2024. case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
  2025. if (iface_param->iface_num & 0x1)
  2026. break;
  2027. init_fw_cb->ipv6_nd_stale_timeout =
  2028. cpu_to_le32(*(uint32_t *)iface_param->value);
  2029. break;
  2030. case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
  2031. if (iface_param->iface_num & 0x1)
  2032. break;
  2033. init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
  2034. break;
  2035. case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
  2036. if (iface_param->iface_num & 0x1)
  2037. break;
  2038. init_fw_cb->ipv6_gw_advrt_mtu =
  2039. cpu_to_le32(*(uint32_t *)iface_param->value);
  2040. break;
  2041. default:
  2042. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  2043. iface_param->param);
  2044. break;
  2045. }
  2046. }
  2047. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  2048. struct iscsi_iface_param_info *iface_param,
  2049. struct addr_ctrl_blk *init_fw_cb)
  2050. {
  2051. switch (iface_param->param) {
  2052. case ISCSI_NET_PARAM_IPV4_ADDR:
  2053. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  2054. sizeof(init_fw_cb->ipv4_addr));
  2055. break;
  2056. case ISCSI_NET_PARAM_IPV4_SUBNET:
  2057. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  2058. sizeof(init_fw_cb->ipv4_subnet));
  2059. break;
  2060. case ISCSI_NET_PARAM_IPV4_GW:
  2061. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  2062. sizeof(init_fw_cb->ipv4_gw_addr));
  2063. break;
  2064. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  2065. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  2066. init_fw_cb->ipv4_tcp_opts |=
  2067. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  2068. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  2069. init_fw_cb->ipv4_tcp_opts &=
  2070. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  2071. else
  2072. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  2073. break;
  2074. case ISCSI_NET_PARAM_IFACE_ENABLE:
  2075. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  2076. init_fw_cb->ipv4_ip_opts |=
  2077. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  2078. qla4xxx_create_ipv4_iface(ha);
  2079. } else {
  2080. init_fw_cb->ipv4_ip_opts &=
  2081. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  2082. 0xFFFF);
  2083. qla4xxx_destroy_ipv4_iface(ha);
  2084. }
  2085. break;
  2086. case ISCSI_NET_PARAM_VLAN_TAG:
  2087. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  2088. break;
  2089. init_fw_cb->ipv4_vlan_tag =
  2090. cpu_to_be16(*(uint16_t *)iface_param->value);
  2091. break;
  2092. case ISCSI_NET_PARAM_VLAN_ENABLED:
  2093. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  2094. init_fw_cb->ipv4_ip_opts |=
  2095. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  2096. else
  2097. init_fw_cb->ipv4_ip_opts &=
  2098. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  2099. break;
  2100. case ISCSI_NET_PARAM_MTU:
  2101. init_fw_cb->eth_mtu_size =
  2102. cpu_to_le16(*(uint16_t *)iface_param->value);
  2103. break;
  2104. case ISCSI_NET_PARAM_PORT:
  2105. init_fw_cb->ipv4_port =
  2106. cpu_to_le16(*(uint16_t *)iface_param->value);
  2107. break;
  2108. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  2109. if (iface_param->iface_num & 0x1)
  2110. break;
  2111. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2112. init_fw_cb->ipv4_tcp_opts |=
  2113. cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
  2114. else
  2115. init_fw_cb->ipv4_tcp_opts &=
  2116. cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
  2117. 0xFFFF);
  2118. break;
  2119. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  2120. if (iface_param->iface_num & 0x1)
  2121. break;
  2122. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2123. init_fw_cb->ipv4_tcp_opts |=
  2124. cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
  2125. else
  2126. init_fw_cb->ipv4_tcp_opts &=
  2127. cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
  2128. break;
  2129. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  2130. if (iface_param->iface_num & 0x1)
  2131. break;
  2132. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2133. init_fw_cb->ipv4_tcp_opts |=
  2134. cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
  2135. else
  2136. init_fw_cb->ipv4_tcp_opts &=
  2137. cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
  2138. break;
  2139. case ISCSI_NET_PARAM_TCP_WSF:
  2140. if (iface_param->iface_num & 0x1)
  2141. break;
  2142. init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
  2143. break;
  2144. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  2145. if (iface_param->iface_num & 0x1)
  2146. break;
  2147. init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
  2148. init_fw_cb->ipv4_tcp_opts |=
  2149. cpu_to_le16((iface_param->value[0] << 1) &
  2150. TCPOPT_TIMER_SCALE);
  2151. break;
  2152. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  2153. if (iface_param->iface_num & 0x1)
  2154. break;
  2155. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2156. init_fw_cb->ipv4_tcp_opts |=
  2157. cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
  2158. else
  2159. init_fw_cb->ipv4_tcp_opts &=
  2160. cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
  2161. break;
  2162. case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
  2163. if (iface_param->iface_num & 0x1)
  2164. break;
  2165. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2166. init_fw_cb->ipv4_tcp_opts |=
  2167. cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
  2168. else
  2169. init_fw_cb->ipv4_tcp_opts &=
  2170. cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
  2171. break;
  2172. case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
  2173. if (iface_param->iface_num & 0x1)
  2174. break;
  2175. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2176. init_fw_cb->ipv4_tcp_opts |=
  2177. cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
  2178. else
  2179. init_fw_cb->ipv4_tcp_opts &=
  2180. cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
  2181. break;
  2182. case ISCSI_NET_PARAM_IPV4_TOS_EN:
  2183. if (iface_param->iface_num & 0x1)
  2184. break;
  2185. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2186. init_fw_cb->ipv4_ip_opts |=
  2187. cpu_to_le16(IPOPT_IPV4_TOS_EN);
  2188. else
  2189. init_fw_cb->ipv4_ip_opts &=
  2190. cpu_to_le16(~IPOPT_IPV4_TOS_EN);
  2191. break;
  2192. case ISCSI_NET_PARAM_IPV4_TOS:
  2193. if (iface_param->iface_num & 0x1)
  2194. break;
  2195. init_fw_cb->ipv4_tos = iface_param->value[0];
  2196. break;
  2197. case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
  2198. if (iface_param->iface_num & 0x1)
  2199. break;
  2200. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2201. init_fw_cb->ipv4_ip_opts |=
  2202. cpu_to_le16(IPOPT_GRAT_ARP_EN);
  2203. else
  2204. init_fw_cb->ipv4_ip_opts &=
  2205. cpu_to_le16(~IPOPT_GRAT_ARP_EN);
  2206. break;
  2207. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
  2208. if (iface_param->iface_num & 0x1)
  2209. break;
  2210. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2211. init_fw_cb->ipv4_ip_opts |=
  2212. cpu_to_le16(IPOPT_ALT_CID_EN);
  2213. else
  2214. init_fw_cb->ipv4_ip_opts &=
  2215. cpu_to_le16(~IPOPT_ALT_CID_EN);
  2216. break;
  2217. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
  2218. if (iface_param->iface_num & 0x1)
  2219. break;
  2220. memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
  2221. (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
  2222. init_fw_cb->ipv4_dhcp_alt_cid_len =
  2223. strlen(init_fw_cb->ipv4_dhcp_alt_cid);
  2224. break;
  2225. case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
  2226. if (iface_param->iface_num & 0x1)
  2227. break;
  2228. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2229. init_fw_cb->ipv4_ip_opts |=
  2230. cpu_to_le16(IPOPT_REQ_VID_EN);
  2231. else
  2232. init_fw_cb->ipv4_ip_opts &=
  2233. cpu_to_le16(~IPOPT_REQ_VID_EN);
  2234. break;
  2235. case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
  2236. if (iface_param->iface_num & 0x1)
  2237. break;
  2238. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2239. init_fw_cb->ipv4_ip_opts |=
  2240. cpu_to_le16(IPOPT_USE_VID_EN);
  2241. else
  2242. init_fw_cb->ipv4_ip_opts &=
  2243. cpu_to_le16(~IPOPT_USE_VID_EN);
  2244. break;
  2245. case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
  2246. if (iface_param->iface_num & 0x1)
  2247. break;
  2248. memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
  2249. (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
  2250. init_fw_cb->ipv4_dhcp_vid_len =
  2251. strlen(init_fw_cb->ipv4_dhcp_vid);
  2252. break;
  2253. case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
  2254. if (iface_param->iface_num & 0x1)
  2255. break;
  2256. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2257. init_fw_cb->ipv4_ip_opts |=
  2258. cpu_to_le16(IPOPT_LEARN_IQN_EN);
  2259. else
  2260. init_fw_cb->ipv4_ip_opts &=
  2261. cpu_to_le16(~IPOPT_LEARN_IQN_EN);
  2262. break;
  2263. case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
  2264. if (iface_param->iface_num & 0x1)
  2265. break;
  2266. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2267. init_fw_cb->ipv4_ip_opts |=
  2268. cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
  2269. else
  2270. init_fw_cb->ipv4_ip_opts &=
  2271. cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
  2272. break;
  2273. case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
  2274. if (iface_param->iface_num & 0x1)
  2275. break;
  2276. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2277. init_fw_cb->ipv4_ip_opts |=
  2278. cpu_to_le16(IPOPT_IN_FORWARD_EN);
  2279. else
  2280. init_fw_cb->ipv4_ip_opts &=
  2281. cpu_to_le16(~IPOPT_IN_FORWARD_EN);
  2282. break;
  2283. case ISCSI_NET_PARAM_REDIRECT_EN:
  2284. if (iface_param->iface_num & 0x1)
  2285. break;
  2286. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2287. init_fw_cb->ipv4_ip_opts |=
  2288. cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
  2289. else
  2290. init_fw_cb->ipv4_ip_opts &=
  2291. cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
  2292. break;
  2293. case ISCSI_NET_PARAM_IPV4_TTL:
  2294. if (iface_param->iface_num & 0x1)
  2295. break;
  2296. init_fw_cb->ipv4_ttl = iface_param->value[0];
  2297. break;
  2298. default:
  2299. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  2300. iface_param->param);
  2301. break;
  2302. }
  2303. }
  2304. static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
  2305. struct iscsi_iface_param_info *iface_param,
  2306. struct addr_ctrl_blk *init_fw_cb)
  2307. {
  2308. switch (iface_param->param) {
  2309. case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
  2310. if (iface_param->iface_num & 0x1)
  2311. break;
  2312. init_fw_cb->def_timeout =
  2313. cpu_to_le16(*(uint16_t *)iface_param->value);
  2314. break;
  2315. case ISCSI_IFACE_PARAM_HDRDGST_EN:
  2316. if (iface_param->iface_num & 0x1)
  2317. break;
  2318. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2319. init_fw_cb->iscsi_opts |=
  2320. cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
  2321. else
  2322. init_fw_cb->iscsi_opts &=
  2323. cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
  2324. break;
  2325. case ISCSI_IFACE_PARAM_DATADGST_EN:
  2326. if (iface_param->iface_num & 0x1)
  2327. break;
  2328. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2329. init_fw_cb->iscsi_opts |=
  2330. cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
  2331. else
  2332. init_fw_cb->iscsi_opts &=
  2333. cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
  2334. break;
  2335. case ISCSI_IFACE_PARAM_IMM_DATA_EN:
  2336. if (iface_param->iface_num & 0x1)
  2337. break;
  2338. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2339. init_fw_cb->iscsi_opts |=
  2340. cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
  2341. else
  2342. init_fw_cb->iscsi_opts &=
  2343. cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
  2344. break;
  2345. case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
  2346. if (iface_param->iface_num & 0x1)
  2347. break;
  2348. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2349. init_fw_cb->iscsi_opts |=
  2350. cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
  2351. else
  2352. init_fw_cb->iscsi_opts &=
  2353. cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
  2354. break;
  2355. case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
  2356. if (iface_param->iface_num & 0x1)
  2357. break;
  2358. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2359. init_fw_cb->iscsi_opts |=
  2360. cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
  2361. else
  2362. init_fw_cb->iscsi_opts &=
  2363. cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
  2364. break;
  2365. case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
  2366. if (iface_param->iface_num & 0x1)
  2367. break;
  2368. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2369. init_fw_cb->iscsi_opts |=
  2370. cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
  2371. else
  2372. init_fw_cb->iscsi_opts &=
  2373. cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
  2374. break;
  2375. case ISCSI_IFACE_PARAM_ERL:
  2376. if (iface_param->iface_num & 0x1)
  2377. break;
  2378. init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
  2379. init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
  2380. ISCSIOPTS_ERL);
  2381. break;
  2382. case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
  2383. if (iface_param->iface_num & 0x1)
  2384. break;
  2385. init_fw_cb->iscsi_max_pdu_size =
  2386. cpu_to_le32(*(uint32_t *)iface_param->value) /
  2387. BYTE_UNITS;
  2388. break;
  2389. case ISCSI_IFACE_PARAM_FIRST_BURST:
  2390. if (iface_param->iface_num & 0x1)
  2391. break;
  2392. init_fw_cb->iscsi_fburst_len =
  2393. cpu_to_le32(*(uint32_t *)iface_param->value) /
  2394. BYTE_UNITS;
  2395. break;
  2396. case ISCSI_IFACE_PARAM_MAX_R2T:
  2397. if (iface_param->iface_num & 0x1)
  2398. break;
  2399. init_fw_cb->iscsi_max_outstnd_r2t =
  2400. cpu_to_le16(*(uint16_t *)iface_param->value);
  2401. break;
  2402. case ISCSI_IFACE_PARAM_MAX_BURST:
  2403. if (iface_param->iface_num & 0x1)
  2404. break;
  2405. init_fw_cb->iscsi_max_burst_len =
  2406. cpu_to_le32(*(uint32_t *)iface_param->value) /
  2407. BYTE_UNITS;
  2408. break;
  2409. case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
  2410. if (iface_param->iface_num & 0x1)
  2411. break;
  2412. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2413. init_fw_cb->iscsi_opts |=
  2414. cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
  2415. else
  2416. init_fw_cb->iscsi_opts &=
  2417. cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
  2418. break;
  2419. case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
  2420. if (iface_param->iface_num & 0x1)
  2421. break;
  2422. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2423. init_fw_cb->iscsi_opts |=
  2424. cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
  2425. else
  2426. init_fw_cb->iscsi_opts &=
  2427. cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
  2428. break;
  2429. case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
  2430. if (iface_param->iface_num & 0x1)
  2431. break;
  2432. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2433. init_fw_cb->iscsi_opts |=
  2434. cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
  2435. else
  2436. init_fw_cb->iscsi_opts &=
  2437. cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
  2438. break;
  2439. case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
  2440. if (iface_param->iface_num & 0x1)
  2441. break;
  2442. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2443. init_fw_cb->iscsi_opts |=
  2444. cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
  2445. else
  2446. init_fw_cb->iscsi_opts &=
  2447. cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
  2448. break;
  2449. case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
  2450. if (iface_param->iface_num & 0x1)
  2451. break;
  2452. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2453. init_fw_cb->iscsi_opts |=
  2454. cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
  2455. else
  2456. init_fw_cb->iscsi_opts &=
  2457. cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
  2458. break;
  2459. default:
  2460. ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
  2461. iface_param->param);
  2462. break;
  2463. }
  2464. }
  2465. static void
  2466. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  2467. {
  2468. struct addr_ctrl_blk_def *acb;
  2469. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  2470. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  2471. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  2472. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  2473. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  2474. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  2475. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  2476. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  2477. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  2478. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  2479. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  2480. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  2481. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  2482. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  2483. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  2484. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  2485. }
  2486. static int
  2487. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  2488. {
  2489. struct scsi_qla_host *ha = to_qla_host(shost);
  2490. int rval = 0;
  2491. struct iscsi_iface_param_info *iface_param = NULL;
  2492. struct addr_ctrl_blk *init_fw_cb = NULL;
  2493. dma_addr_t init_fw_cb_dma;
  2494. uint32_t mbox_cmd[MBOX_REG_COUNT];
  2495. uint32_t mbox_sts[MBOX_REG_COUNT];
  2496. uint32_t rem = len;
  2497. struct nlattr *attr;
  2498. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  2499. sizeof(struct addr_ctrl_blk),
  2500. &init_fw_cb_dma, GFP_KERNEL);
  2501. if (!init_fw_cb) {
  2502. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  2503. __func__);
  2504. return -ENOMEM;
  2505. }
  2506. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  2507. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  2508. memset(&mbox_sts, 0, sizeof(mbox_sts));
  2509. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  2510. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  2511. rval = -EIO;
  2512. goto exit_init_fw_cb;
  2513. }
  2514. nla_for_each_attr(attr, data, len, rem) {
  2515. iface_param = nla_data(attr);
  2516. if (iface_param->param_type == ISCSI_NET_PARAM) {
  2517. switch (iface_param->iface_type) {
  2518. case ISCSI_IFACE_TYPE_IPV4:
  2519. switch (iface_param->iface_num) {
  2520. case 0:
  2521. qla4xxx_set_ipv4(ha, iface_param,
  2522. init_fw_cb);
  2523. break;
  2524. default:
  2525. /* Cannot have more than one IPv4 interface */
  2526. ql4_printk(KERN_ERR, ha,
  2527. "Invalid IPv4 iface number = %d\n",
  2528. iface_param->iface_num);
  2529. break;
  2530. }
  2531. break;
  2532. case ISCSI_IFACE_TYPE_IPV6:
  2533. switch (iface_param->iface_num) {
  2534. case 0:
  2535. case 1:
  2536. qla4xxx_set_ipv6(ha, iface_param,
  2537. init_fw_cb);
  2538. break;
  2539. default:
  2540. /* Cannot have more than two IPv6 interface */
  2541. ql4_printk(KERN_ERR, ha,
  2542. "Invalid IPv6 iface number = %d\n",
  2543. iface_param->iface_num);
  2544. break;
  2545. }
  2546. break;
  2547. default:
  2548. ql4_printk(KERN_ERR, ha,
  2549. "Invalid iface type\n");
  2550. break;
  2551. }
  2552. } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
  2553. qla4xxx_set_iscsi_param(ha, iface_param,
  2554. init_fw_cb);
  2555. } else {
  2556. continue;
  2557. }
  2558. }
  2559. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  2560. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  2561. sizeof(struct addr_ctrl_blk),
  2562. FLASH_OPT_RMW_COMMIT);
  2563. if (rval != QLA_SUCCESS) {
  2564. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  2565. __func__);
  2566. rval = -EIO;
  2567. goto exit_init_fw_cb;
  2568. }
  2569. rval = qla4xxx_disable_acb(ha);
  2570. if (rval != QLA_SUCCESS) {
  2571. ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
  2572. __func__);
  2573. rval = -EIO;
  2574. goto exit_init_fw_cb;
  2575. }
  2576. wait_for_completion_timeout(&ha->disable_acb_comp,
  2577. DISABLE_ACB_TOV * HZ);
  2578. qla4xxx_initcb_to_acb(init_fw_cb);
  2579. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  2580. if (rval != QLA_SUCCESS) {
  2581. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  2582. __func__);
  2583. rval = -EIO;
  2584. goto exit_init_fw_cb;
  2585. }
  2586. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  2587. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  2588. init_fw_cb_dma);
  2589. exit_init_fw_cb:
  2590. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  2591. init_fw_cb, init_fw_cb_dma);
  2592. return rval;
  2593. }
  2594. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  2595. enum iscsi_param param, char *buf)
  2596. {
  2597. struct iscsi_session *sess = cls_sess->dd_data;
  2598. struct ddb_entry *ddb_entry = sess->dd_data;
  2599. struct scsi_qla_host *ha = ddb_entry->ha;
  2600. struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
  2601. struct ql4_chap_table chap_tbl;
  2602. int rval, len;
  2603. uint16_t idx;
  2604. memset(&chap_tbl, 0, sizeof(chap_tbl));
  2605. switch (param) {
  2606. case ISCSI_PARAM_CHAP_IN_IDX:
  2607. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  2608. sess->password_in, BIDI_CHAP,
  2609. &idx);
  2610. if (rval)
  2611. len = sprintf(buf, "\n");
  2612. else
  2613. len = sprintf(buf, "%hu\n", idx);
  2614. break;
  2615. case ISCSI_PARAM_CHAP_OUT_IDX:
  2616. if (ddb_entry->ddb_type == FLASH_DDB) {
  2617. if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
  2618. idx = ddb_entry->chap_tbl_idx;
  2619. rval = QLA_SUCCESS;
  2620. } else {
  2621. rval = QLA_ERROR;
  2622. }
  2623. } else {
  2624. rval = qla4xxx_get_chap_index(ha, sess->username,
  2625. sess->password,
  2626. LOCAL_CHAP, &idx);
  2627. }
  2628. if (rval)
  2629. len = sprintf(buf, "\n");
  2630. else
  2631. len = sprintf(buf, "%hu\n", idx);
  2632. break;
  2633. case ISCSI_PARAM_USERNAME:
  2634. case ISCSI_PARAM_PASSWORD:
  2635. /* First, populate session username and password for FLASH DDB,
  2636. * if not already done. This happens when session login fails
  2637. * for a FLASH DDB.
  2638. */
  2639. if (ddb_entry->ddb_type == FLASH_DDB &&
  2640. ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
  2641. !sess->username && !sess->password) {
  2642. idx = ddb_entry->chap_tbl_idx;
  2643. rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
  2644. chap_tbl.secret,
  2645. idx);
  2646. if (!rval) {
  2647. iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
  2648. (char *)chap_tbl.name,
  2649. strlen((char *)chap_tbl.name));
  2650. iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
  2651. (char *)chap_tbl.secret,
  2652. chap_tbl.secret_len);
  2653. }
  2654. }
  2655. /* allow fall-through */
  2656. default:
  2657. return iscsi_session_get_param(cls_sess, param, buf);
  2658. }
  2659. return len;
  2660. }
  2661. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  2662. enum iscsi_param param, char *buf)
  2663. {
  2664. struct iscsi_conn *conn;
  2665. struct qla_conn *qla_conn;
  2666. struct sockaddr *dst_addr;
  2667. conn = cls_conn->dd_data;
  2668. qla_conn = conn->dd_data;
  2669. dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
  2670. switch (param) {
  2671. case ISCSI_PARAM_CONN_PORT:
  2672. case ISCSI_PARAM_CONN_ADDRESS:
  2673. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  2674. dst_addr, param, buf);
  2675. default:
  2676. return iscsi_conn_get_param(cls_conn, param, buf);
  2677. }
  2678. }
  2679. int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
  2680. {
  2681. uint32_t mbx_sts = 0;
  2682. uint16_t tmp_ddb_index;
  2683. int ret;
  2684. get_ddb_index:
  2685. tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  2686. if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
  2687. DEBUG2(ql4_printk(KERN_INFO, ha,
  2688. "Free DDB index not available\n"));
  2689. ret = QLA_ERROR;
  2690. goto exit_get_ddb_index;
  2691. }
  2692. if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
  2693. goto get_ddb_index;
  2694. DEBUG2(ql4_printk(KERN_INFO, ha,
  2695. "Found a free DDB index at %d\n", tmp_ddb_index));
  2696. ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
  2697. if (ret == QLA_ERROR) {
  2698. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  2699. ql4_printk(KERN_INFO, ha,
  2700. "DDB index = %d not available trying next\n",
  2701. tmp_ddb_index);
  2702. goto get_ddb_index;
  2703. }
  2704. DEBUG2(ql4_printk(KERN_INFO, ha,
  2705. "Free FW DDB not available\n"));
  2706. }
  2707. *ddb_index = tmp_ddb_index;
  2708. exit_get_ddb_index:
  2709. return ret;
  2710. }
  2711. static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
  2712. struct ddb_entry *ddb_entry,
  2713. char *existing_ipaddr,
  2714. char *user_ipaddr)
  2715. {
  2716. uint8_t dst_ipaddr[IPv6_ADDR_LEN];
  2717. char formatted_ipaddr[DDB_IPADDR_LEN];
  2718. int status = QLA_SUCCESS, ret = 0;
  2719. if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
  2720. ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  2721. '\0', NULL);
  2722. if (ret == 0) {
  2723. status = QLA_ERROR;
  2724. goto out_match;
  2725. }
  2726. ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
  2727. } else {
  2728. ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  2729. '\0', NULL);
  2730. if (ret == 0) {
  2731. status = QLA_ERROR;
  2732. goto out_match;
  2733. }
  2734. ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
  2735. }
  2736. if (strcmp(existing_ipaddr, formatted_ipaddr))
  2737. status = QLA_ERROR;
  2738. out_match:
  2739. return status;
  2740. }
  2741. static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
  2742. struct iscsi_cls_conn *cls_conn)
  2743. {
  2744. int idx = 0, max_ddbs, rval;
  2745. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  2746. struct iscsi_session *sess, *existing_sess;
  2747. struct iscsi_conn *conn, *existing_conn;
  2748. struct ddb_entry *ddb_entry;
  2749. sess = cls_sess->dd_data;
  2750. conn = cls_conn->dd_data;
  2751. if (sess->targetname == NULL ||
  2752. conn->persistent_address == NULL ||
  2753. conn->persistent_port == 0)
  2754. return QLA_ERROR;
  2755. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  2756. MAX_DEV_DB_ENTRIES;
  2757. for (idx = 0; idx < max_ddbs; idx++) {
  2758. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  2759. if (ddb_entry == NULL)
  2760. continue;
  2761. if (ddb_entry->ddb_type != FLASH_DDB)
  2762. continue;
  2763. existing_sess = ddb_entry->sess->dd_data;
  2764. existing_conn = ddb_entry->conn->dd_data;
  2765. if (existing_sess->targetname == NULL ||
  2766. existing_conn->persistent_address == NULL ||
  2767. existing_conn->persistent_port == 0)
  2768. continue;
  2769. DEBUG2(ql4_printk(KERN_INFO, ha,
  2770. "IQN = %s User IQN = %s\n",
  2771. existing_sess->targetname,
  2772. sess->targetname));
  2773. DEBUG2(ql4_printk(KERN_INFO, ha,
  2774. "IP = %s User IP = %s\n",
  2775. existing_conn->persistent_address,
  2776. conn->persistent_address));
  2777. DEBUG2(ql4_printk(KERN_INFO, ha,
  2778. "Port = %d User Port = %d\n",
  2779. existing_conn->persistent_port,
  2780. conn->persistent_port));
  2781. if (strcmp(existing_sess->targetname, sess->targetname))
  2782. continue;
  2783. rval = qla4xxx_match_ipaddress(ha, ddb_entry,
  2784. existing_conn->persistent_address,
  2785. conn->persistent_address);
  2786. if (rval == QLA_ERROR)
  2787. continue;
  2788. if (existing_conn->persistent_port != conn->persistent_port)
  2789. continue;
  2790. break;
  2791. }
  2792. if (idx == max_ddbs)
  2793. return QLA_ERROR;
  2794. DEBUG2(ql4_printk(KERN_INFO, ha,
  2795. "Match found in fwdb sessions\n"));
  2796. return QLA_SUCCESS;
  2797. }
  2798. static struct iscsi_cls_session *
  2799. qla4xxx_session_create(struct iscsi_endpoint *ep,
  2800. uint16_t cmds_max, uint16_t qdepth,
  2801. uint32_t initial_cmdsn)
  2802. {
  2803. struct iscsi_cls_session *cls_sess;
  2804. struct scsi_qla_host *ha;
  2805. struct qla_endpoint *qla_ep;
  2806. struct ddb_entry *ddb_entry;
  2807. uint16_t ddb_index;
  2808. struct iscsi_session *sess;
  2809. struct sockaddr *dst_addr;
  2810. int ret;
  2811. if (!ep) {
  2812. printk(KERN_ERR "qla4xxx: missing ep.\n");
  2813. return NULL;
  2814. }
  2815. qla_ep = ep->dd_data;
  2816. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  2817. ha = to_qla_host(qla_ep->host);
  2818. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  2819. ha->host_no));
  2820. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  2821. if (ret == QLA_ERROR)
  2822. return NULL;
  2823. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  2824. cmds_max, sizeof(struct ddb_entry),
  2825. sizeof(struct ql4_task_data),
  2826. initial_cmdsn, ddb_index);
  2827. if (!cls_sess)
  2828. return NULL;
  2829. sess = cls_sess->dd_data;
  2830. ddb_entry = sess->dd_data;
  2831. ddb_entry->fw_ddb_index = ddb_index;
  2832. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  2833. ddb_entry->ha = ha;
  2834. ddb_entry->sess = cls_sess;
  2835. ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
  2836. ddb_entry->ddb_change = qla4xxx_ddb_change;
  2837. clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
  2838. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  2839. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  2840. ha->tot_ddbs++;
  2841. return cls_sess;
  2842. }
  2843. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  2844. {
  2845. struct iscsi_session *sess;
  2846. struct ddb_entry *ddb_entry;
  2847. struct scsi_qla_host *ha;
  2848. unsigned long flags, wtime;
  2849. struct dev_db_entry *fw_ddb_entry = NULL;
  2850. dma_addr_t fw_ddb_entry_dma;
  2851. uint32_t ddb_state;
  2852. int ret;
  2853. sess = cls_sess->dd_data;
  2854. ddb_entry = sess->dd_data;
  2855. ha = ddb_entry->ha;
  2856. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  2857. ha->host_no));
  2858. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2859. &fw_ddb_entry_dma, GFP_KERNEL);
  2860. if (!fw_ddb_entry) {
  2861. ql4_printk(KERN_ERR, ha,
  2862. "%s: Unable to allocate dma buffer\n", __func__);
  2863. goto destroy_session;
  2864. }
  2865. wtime = jiffies + (HZ * LOGOUT_TOV);
  2866. do {
  2867. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  2868. fw_ddb_entry, fw_ddb_entry_dma,
  2869. NULL, NULL, &ddb_state, NULL,
  2870. NULL, NULL);
  2871. if (ret == QLA_ERROR)
  2872. goto destroy_session;
  2873. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  2874. (ddb_state == DDB_DS_SESSION_FAILED))
  2875. goto destroy_session;
  2876. schedule_timeout_uninterruptible(HZ);
  2877. } while ((time_after(wtime, jiffies)));
  2878. destroy_session:
  2879. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  2880. if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
  2881. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  2882. spin_lock_irqsave(&ha->hardware_lock, flags);
  2883. qla4xxx_free_ddb(ha, ddb_entry);
  2884. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2885. iscsi_session_teardown(cls_sess);
  2886. if (fw_ddb_entry)
  2887. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2888. fw_ddb_entry, fw_ddb_entry_dma);
  2889. }
  2890. static struct iscsi_cls_conn *
  2891. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  2892. {
  2893. struct iscsi_cls_conn *cls_conn;
  2894. struct iscsi_session *sess;
  2895. struct ddb_entry *ddb_entry;
  2896. struct scsi_qla_host *ha;
  2897. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  2898. conn_idx);
  2899. if (!cls_conn) {
  2900. pr_info("%s: Can not create connection for conn_idx = %u\n",
  2901. __func__, conn_idx);
  2902. return NULL;
  2903. }
  2904. sess = cls_sess->dd_data;
  2905. ddb_entry = sess->dd_data;
  2906. ddb_entry->conn = cls_conn;
  2907. ha = ddb_entry->ha;
  2908. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
  2909. conn_idx));
  2910. return cls_conn;
  2911. }
  2912. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  2913. struct iscsi_cls_conn *cls_conn,
  2914. uint64_t transport_fd, int is_leading)
  2915. {
  2916. struct iscsi_conn *conn;
  2917. struct qla_conn *qla_conn;
  2918. struct iscsi_endpoint *ep;
  2919. struct ddb_entry *ddb_entry;
  2920. struct scsi_qla_host *ha;
  2921. struct iscsi_session *sess;
  2922. sess = cls_session->dd_data;
  2923. ddb_entry = sess->dd_data;
  2924. ha = ddb_entry->ha;
  2925. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
  2926. cls_session->sid, cls_conn->cid));
  2927. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  2928. return -EINVAL;
  2929. ep = iscsi_lookup_endpoint(transport_fd);
  2930. conn = cls_conn->dd_data;
  2931. qla_conn = conn->dd_data;
  2932. qla_conn->qla_ep = ep->dd_data;
  2933. return 0;
  2934. }
  2935. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  2936. {
  2937. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  2938. struct iscsi_session *sess;
  2939. struct ddb_entry *ddb_entry;
  2940. struct scsi_qla_host *ha;
  2941. struct dev_db_entry *fw_ddb_entry = NULL;
  2942. dma_addr_t fw_ddb_entry_dma;
  2943. uint32_t mbx_sts = 0;
  2944. int ret = 0;
  2945. int status = QLA_SUCCESS;
  2946. sess = cls_sess->dd_data;
  2947. ddb_entry = sess->dd_data;
  2948. ha = ddb_entry->ha;
  2949. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
  2950. cls_sess->sid, cls_conn->cid));
  2951. /* Check if we have matching FW DDB, if yes then do not
  2952. * login to this target. This could cause target to logout previous
  2953. * connection
  2954. */
  2955. ret = qla4xxx_match_fwdb_session(ha, cls_conn);
  2956. if (ret == QLA_SUCCESS) {
  2957. ql4_printk(KERN_INFO, ha,
  2958. "Session already exist in FW.\n");
  2959. ret = -EEXIST;
  2960. goto exit_conn_start;
  2961. }
  2962. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2963. &fw_ddb_entry_dma, GFP_KERNEL);
  2964. if (!fw_ddb_entry) {
  2965. ql4_printk(KERN_ERR, ha,
  2966. "%s: Unable to allocate dma buffer\n", __func__);
  2967. ret = -ENOMEM;
  2968. goto exit_conn_start;
  2969. }
  2970. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  2971. if (ret) {
  2972. /* If iscsid is stopped and started then no need to do
  2973. * set param again since ddb state will be already
  2974. * active and FW does not allow set ddb to an
  2975. * active session.
  2976. */
  2977. if (mbx_sts)
  2978. if (ddb_entry->fw_ddb_device_state ==
  2979. DDB_DS_SESSION_ACTIVE) {
  2980. ddb_entry->unblock_sess(ddb_entry->sess);
  2981. goto exit_set_param;
  2982. }
  2983. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  2984. __func__, ddb_entry->fw_ddb_index);
  2985. goto exit_conn_start;
  2986. }
  2987. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  2988. if (status == QLA_ERROR) {
  2989. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  2990. sess->targetname);
  2991. ret = -EINVAL;
  2992. goto exit_conn_start;
  2993. }
  2994. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  2995. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  2996. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  2997. ddb_entry->fw_ddb_device_state));
  2998. exit_set_param:
  2999. ret = 0;
  3000. exit_conn_start:
  3001. if (fw_ddb_entry)
  3002. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3003. fw_ddb_entry, fw_ddb_entry_dma);
  3004. return ret;
  3005. }
  3006. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  3007. {
  3008. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  3009. struct iscsi_session *sess;
  3010. struct scsi_qla_host *ha;
  3011. struct ddb_entry *ddb_entry;
  3012. int options;
  3013. sess = cls_sess->dd_data;
  3014. ddb_entry = sess->dd_data;
  3015. ha = ddb_entry->ha;
  3016. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
  3017. cls_conn->cid));
  3018. options = LOGOUT_OPTION_CLOSE_SESSION;
  3019. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  3020. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  3021. }
  3022. static void qla4xxx_task_work(struct work_struct *wdata)
  3023. {
  3024. struct ql4_task_data *task_data;
  3025. struct scsi_qla_host *ha;
  3026. struct passthru_status *sts;
  3027. struct iscsi_task *task;
  3028. struct iscsi_hdr *hdr;
  3029. uint8_t *data;
  3030. uint32_t data_len;
  3031. struct iscsi_conn *conn;
  3032. int hdr_len;
  3033. itt_t itt;
  3034. task_data = container_of(wdata, struct ql4_task_data, task_work);
  3035. ha = task_data->ha;
  3036. task = task_data->task;
  3037. sts = &task_data->sts;
  3038. hdr_len = sizeof(struct iscsi_hdr);
  3039. DEBUG3(printk(KERN_INFO "Status returned\n"));
  3040. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  3041. DEBUG3(printk(KERN_INFO "Response buffer"));
  3042. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  3043. conn = task->conn;
  3044. switch (sts->completionStatus) {
  3045. case PASSTHRU_STATUS_COMPLETE:
  3046. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  3047. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  3048. itt = sts->handle;
  3049. hdr->itt = itt;
  3050. data = task_data->resp_buffer + hdr_len;
  3051. data_len = task_data->resp_len - hdr_len;
  3052. iscsi_complete_pdu(conn, hdr, data, data_len);
  3053. break;
  3054. default:
  3055. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  3056. sts->completionStatus);
  3057. break;
  3058. }
  3059. return;
  3060. }
  3061. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  3062. {
  3063. struct ql4_task_data *task_data;
  3064. struct iscsi_session *sess;
  3065. struct ddb_entry *ddb_entry;
  3066. struct scsi_qla_host *ha;
  3067. int hdr_len;
  3068. sess = task->conn->session;
  3069. ddb_entry = sess->dd_data;
  3070. ha = ddb_entry->ha;
  3071. task_data = task->dd_data;
  3072. memset(task_data, 0, sizeof(struct ql4_task_data));
  3073. if (task->sc) {
  3074. ql4_printk(KERN_INFO, ha,
  3075. "%s: SCSI Commands not implemented\n", __func__);
  3076. return -EINVAL;
  3077. }
  3078. hdr_len = sizeof(struct iscsi_hdr);
  3079. task_data->ha = ha;
  3080. task_data->task = task;
  3081. if (task->data_count) {
  3082. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  3083. task->data_count,
  3084. PCI_DMA_TODEVICE);
  3085. }
  3086. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  3087. __func__, task->conn->max_recv_dlength, hdr_len));
  3088. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  3089. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  3090. task_data->resp_len,
  3091. &task_data->resp_dma,
  3092. GFP_ATOMIC);
  3093. if (!task_data->resp_buffer)
  3094. goto exit_alloc_pdu;
  3095. task_data->req_len = task->data_count + hdr_len;
  3096. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  3097. task_data->req_len,
  3098. &task_data->req_dma,
  3099. GFP_ATOMIC);
  3100. if (!task_data->req_buffer)
  3101. goto exit_alloc_pdu;
  3102. task->hdr = task_data->req_buffer;
  3103. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  3104. return 0;
  3105. exit_alloc_pdu:
  3106. if (task_data->resp_buffer)
  3107. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  3108. task_data->resp_buffer, task_data->resp_dma);
  3109. if (task_data->req_buffer)
  3110. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  3111. task_data->req_buffer, task_data->req_dma);
  3112. return -ENOMEM;
  3113. }
  3114. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  3115. {
  3116. struct ql4_task_data *task_data;
  3117. struct iscsi_session *sess;
  3118. struct ddb_entry *ddb_entry;
  3119. struct scsi_qla_host *ha;
  3120. int hdr_len;
  3121. hdr_len = sizeof(struct iscsi_hdr);
  3122. sess = task->conn->session;
  3123. ddb_entry = sess->dd_data;
  3124. ha = ddb_entry->ha;
  3125. task_data = task->dd_data;
  3126. if (task->data_count) {
  3127. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  3128. task->data_count, PCI_DMA_TODEVICE);
  3129. }
  3130. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  3131. __func__, task->conn->max_recv_dlength, hdr_len));
  3132. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  3133. task_data->resp_buffer, task_data->resp_dma);
  3134. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  3135. task_data->req_buffer, task_data->req_dma);
  3136. return;
  3137. }
  3138. static int qla4xxx_task_xmit(struct iscsi_task *task)
  3139. {
  3140. struct scsi_cmnd *sc = task->sc;
  3141. struct iscsi_session *sess = task->conn->session;
  3142. struct ddb_entry *ddb_entry = sess->dd_data;
  3143. struct scsi_qla_host *ha = ddb_entry->ha;
  3144. if (!sc)
  3145. return qla4xxx_send_passthru0(task);
  3146. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  3147. __func__);
  3148. return -ENOSYS;
  3149. }
  3150. static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
  3151. struct iscsi_bus_flash_conn *conn,
  3152. struct dev_db_entry *fw_ddb_entry)
  3153. {
  3154. unsigned long options = 0;
  3155. int rc = 0;
  3156. options = le16_to_cpu(fw_ddb_entry->options);
  3157. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  3158. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  3159. rc = iscsi_switch_str_param(&sess->portal_type,
  3160. PORTAL_TYPE_IPV6);
  3161. if (rc)
  3162. goto exit_copy;
  3163. } else {
  3164. rc = iscsi_switch_str_param(&sess->portal_type,
  3165. PORTAL_TYPE_IPV4);
  3166. if (rc)
  3167. goto exit_copy;
  3168. }
  3169. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  3170. &options);
  3171. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  3172. sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
  3173. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  3174. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  3175. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  3176. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  3177. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  3178. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  3179. &options);
  3180. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  3181. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  3182. conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
  3183. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  3184. &options);
  3185. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  3186. sess->discovery_auth_optional =
  3187. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  3188. if (test_bit(ISCSIOPT_ERL1, &options))
  3189. sess->erl |= BIT_1;
  3190. if (test_bit(ISCSIOPT_ERL0, &options))
  3191. sess->erl |= BIT_0;
  3192. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  3193. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  3194. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  3195. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  3196. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  3197. conn->tcp_timer_scale |= BIT_3;
  3198. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  3199. conn->tcp_timer_scale |= BIT_2;
  3200. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  3201. conn->tcp_timer_scale |= BIT_1;
  3202. conn->tcp_timer_scale >>= 1;
  3203. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  3204. options = le16_to_cpu(fw_ddb_entry->ip_options);
  3205. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  3206. conn->max_recv_dlength = BYTE_UNITS *
  3207. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  3208. conn->max_xmit_dlength = BYTE_UNITS *
  3209. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  3210. sess->first_burst = BYTE_UNITS *
  3211. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  3212. sess->max_burst = BYTE_UNITS *
  3213. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  3214. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  3215. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  3216. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  3217. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  3218. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  3219. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  3220. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  3221. conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
  3222. conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
  3223. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  3224. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  3225. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  3226. sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
  3227. sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
  3228. sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3229. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  3230. sess->default_taskmgmt_timeout =
  3231. le16_to_cpu(fw_ddb_entry->def_timeout);
  3232. conn->port = le16_to_cpu(fw_ddb_entry->port);
  3233. options = le16_to_cpu(fw_ddb_entry->options);
  3234. conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  3235. if (!conn->ipaddress) {
  3236. rc = -ENOMEM;
  3237. goto exit_copy;
  3238. }
  3239. conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  3240. if (!conn->redirect_ipaddr) {
  3241. rc = -ENOMEM;
  3242. goto exit_copy;
  3243. }
  3244. memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  3245. memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
  3246. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  3247. conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
  3248. conn->link_local_ipv6_addr = kmemdup(
  3249. fw_ddb_entry->link_local_ipv6_addr,
  3250. IPv6_ADDR_LEN, GFP_KERNEL);
  3251. if (!conn->link_local_ipv6_addr) {
  3252. rc = -ENOMEM;
  3253. goto exit_copy;
  3254. }
  3255. } else {
  3256. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  3257. }
  3258. if (fw_ddb_entry->iscsi_name[0]) {
  3259. rc = iscsi_switch_str_param(&sess->targetname,
  3260. (char *)fw_ddb_entry->iscsi_name);
  3261. if (rc)
  3262. goto exit_copy;
  3263. }
  3264. if (fw_ddb_entry->iscsi_alias[0]) {
  3265. rc = iscsi_switch_str_param(&sess->targetalias,
  3266. (char *)fw_ddb_entry->iscsi_alias);
  3267. if (rc)
  3268. goto exit_copy;
  3269. }
  3270. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  3271. exit_copy:
  3272. return rc;
  3273. }
  3274. static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
  3275. struct iscsi_bus_flash_conn *conn,
  3276. struct dev_db_entry *fw_ddb_entry)
  3277. {
  3278. uint16_t options;
  3279. int rc = 0;
  3280. options = le16_to_cpu(fw_ddb_entry->options);
  3281. SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
  3282. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  3283. options |= BIT_8;
  3284. else
  3285. options &= ~BIT_8;
  3286. SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
  3287. SET_BITVAL(sess->discovery_sess, options, BIT_4);
  3288. SET_BITVAL(sess->entry_state, options, BIT_3);
  3289. fw_ddb_entry->options = cpu_to_le16(options);
  3290. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  3291. SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
  3292. SET_BITVAL(conn->datadgst_en, options, BIT_12);
  3293. SET_BITVAL(sess->imm_data_en, options, BIT_11);
  3294. SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
  3295. SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
  3296. SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
  3297. SET_BITVAL(sess->chap_auth_en, options, BIT_7);
  3298. SET_BITVAL(conn->snack_req_en, options, BIT_6);
  3299. SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
  3300. SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
  3301. SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
  3302. SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
  3303. SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
  3304. fw_ddb_entry->iscsi_options = cpu_to_le16(options);
  3305. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  3306. SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
  3307. SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
  3308. SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
  3309. SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
  3310. SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
  3311. SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
  3312. SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
  3313. fw_ddb_entry->tcp_options = cpu_to_le16(options);
  3314. options = le16_to_cpu(fw_ddb_entry->ip_options);
  3315. SET_BITVAL(conn->fragment_disable, options, BIT_4);
  3316. fw_ddb_entry->ip_options = cpu_to_le16(options);
  3317. fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
  3318. fw_ddb_entry->iscsi_max_rcv_data_seg_len =
  3319. cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
  3320. fw_ddb_entry->iscsi_max_snd_data_seg_len =
  3321. cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
  3322. fw_ddb_entry->iscsi_first_burst_len =
  3323. cpu_to_le16(sess->first_burst / BYTE_UNITS);
  3324. fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
  3325. BYTE_UNITS);
  3326. fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
  3327. fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
  3328. fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
  3329. fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
  3330. fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
  3331. fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
  3332. fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
  3333. fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
  3334. fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
  3335. fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
  3336. fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
  3337. fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
  3338. fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
  3339. fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
  3340. fw_ddb_entry->port = cpu_to_le16(conn->port);
  3341. fw_ddb_entry->def_timeout =
  3342. cpu_to_le16(sess->default_taskmgmt_timeout);
  3343. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  3344. fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
  3345. else
  3346. fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
  3347. if (conn->ipaddress)
  3348. memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
  3349. sizeof(fw_ddb_entry->ip_addr));
  3350. if (conn->redirect_ipaddr)
  3351. memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
  3352. sizeof(fw_ddb_entry->tgt_addr));
  3353. if (conn->link_local_ipv6_addr)
  3354. memcpy(fw_ddb_entry->link_local_ipv6_addr,
  3355. conn->link_local_ipv6_addr,
  3356. sizeof(fw_ddb_entry->link_local_ipv6_addr));
  3357. if (sess->targetname)
  3358. memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
  3359. sizeof(fw_ddb_entry->iscsi_name));
  3360. if (sess->targetalias)
  3361. memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
  3362. sizeof(fw_ddb_entry->iscsi_alias));
  3363. COPY_ISID(fw_ddb_entry->isid, sess->isid);
  3364. return rc;
  3365. }
  3366. static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
  3367. struct iscsi_session *sess,
  3368. struct dev_db_entry *fw_ddb_entry)
  3369. {
  3370. unsigned long options = 0;
  3371. uint16_t ddb_link;
  3372. uint16_t disc_parent;
  3373. char ip_addr[DDB_IPADDR_LEN];
  3374. options = le16_to_cpu(fw_ddb_entry->options);
  3375. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  3376. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  3377. &options);
  3378. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  3379. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  3380. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  3381. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  3382. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  3383. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  3384. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  3385. &options);
  3386. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  3387. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  3388. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  3389. &options);
  3390. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  3391. sess->discovery_auth_optional =
  3392. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  3393. if (test_bit(ISCSIOPT_ERL1, &options))
  3394. sess->erl |= BIT_1;
  3395. if (test_bit(ISCSIOPT_ERL0, &options))
  3396. sess->erl |= BIT_0;
  3397. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  3398. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  3399. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  3400. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  3401. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  3402. conn->tcp_timer_scale |= BIT_3;
  3403. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  3404. conn->tcp_timer_scale |= BIT_2;
  3405. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  3406. conn->tcp_timer_scale |= BIT_1;
  3407. conn->tcp_timer_scale >>= 1;
  3408. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  3409. options = le16_to_cpu(fw_ddb_entry->ip_options);
  3410. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  3411. conn->max_recv_dlength = BYTE_UNITS *
  3412. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  3413. conn->max_xmit_dlength = BYTE_UNITS *
  3414. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  3415. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  3416. sess->first_burst = BYTE_UNITS *
  3417. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  3418. sess->max_burst = BYTE_UNITS *
  3419. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  3420. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  3421. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  3422. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  3423. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  3424. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  3425. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  3426. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  3427. conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
  3428. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  3429. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  3430. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  3431. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  3432. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  3433. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  3434. if (ddb_link == DDB_ISNS)
  3435. disc_parent = ISCSI_DISC_PARENT_ISNS;
  3436. else if (ddb_link == DDB_NO_LINK)
  3437. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  3438. else if (ddb_link < MAX_DDB_ENTRIES)
  3439. disc_parent = ISCSI_DISC_PARENT_SENDTGT;
  3440. else
  3441. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  3442. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
  3443. iscsi_get_discovery_parent_name(disc_parent), 0);
  3444. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  3445. (char *)fw_ddb_entry->iscsi_alias, 0);
  3446. options = le16_to_cpu(fw_ddb_entry->options);
  3447. if (options & DDB_OPT_IPV6_DEVICE) {
  3448. memset(ip_addr, 0, sizeof(ip_addr));
  3449. sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
  3450. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
  3451. (char *)ip_addr, 0);
  3452. }
  3453. }
  3454. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  3455. struct dev_db_entry *fw_ddb_entry,
  3456. struct iscsi_cls_session *cls_sess,
  3457. struct iscsi_cls_conn *cls_conn)
  3458. {
  3459. int buflen = 0;
  3460. struct iscsi_session *sess;
  3461. struct ddb_entry *ddb_entry;
  3462. struct ql4_chap_table chap_tbl;
  3463. struct iscsi_conn *conn;
  3464. char ip_addr[DDB_IPADDR_LEN];
  3465. uint16_t options = 0;
  3466. sess = cls_sess->dd_data;
  3467. ddb_entry = sess->dd_data;
  3468. conn = cls_conn->dd_data;
  3469. memset(&chap_tbl, 0, sizeof(chap_tbl));
  3470. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3471. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  3472. sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
  3473. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  3474. memset(ip_addr, 0, sizeof(ip_addr));
  3475. options = le16_to_cpu(fw_ddb_entry->options);
  3476. if (options & DDB_OPT_IPV6_DEVICE) {
  3477. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
  3478. memset(ip_addr, 0, sizeof(ip_addr));
  3479. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  3480. } else {
  3481. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
  3482. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  3483. }
  3484. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  3485. (char *)ip_addr, buflen);
  3486. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  3487. (char *)fw_ddb_entry->iscsi_name, buflen);
  3488. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  3489. (char *)ha->name_string, buflen);
  3490. if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
  3491. if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
  3492. chap_tbl.secret,
  3493. ddb_entry->chap_tbl_idx)) {
  3494. iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
  3495. (char *)chap_tbl.name,
  3496. strlen((char *)chap_tbl.name));
  3497. iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
  3498. (char *)chap_tbl.secret,
  3499. chap_tbl.secret_len);
  3500. }
  3501. }
  3502. }
  3503. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  3504. struct ddb_entry *ddb_entry)
  3505. {
  3506. struct iscsi_cls_session *cls_sess;
  3507. struct iscsi_cls_conn *cls_conn;
  3508. uint32_t ddb_state;
  3509. dma_addr_t fw_ddb_entry_dma;
  3510. struct dev_db_entry *fw_ddb_entry;
  3511. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3512. &fw_ddb_entry_dma, GFP_KERNEL);
  3513. if (!fw_ddb_entry) {
  3514. ql4_printk(KERN_ERR, ha,
  3515. "%s: Unable to allocate dma buffer\n", __func__);
  3516. goto exit_session_conn_fwddb_param;
  3517. }
  3518. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  3519. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  3520. NULL, NULL, NULL) == QLA_ERROR) {
  3521. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  3522. "get_ddb_entry for fw_ddb_index %d\n",
  3523. ha->host_no, __func__,
  3524. ddb_entry->fw_ddb_index));
  3525. goto exit_session_conn_fwddb_param;
  3526. }
  3527. cls_sess = ddb_entry->sess;
  3528. cls_conn = ddb_entry->conn;
  3529. /* Update params */
  3530. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  3531. exit_session_conn_fwddb_param:
  3532. if (fw_ddb_entry)
  3533. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3534. fw_ddb_entry, fw_ddb_entry_dma);
  3535. }
  3536. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  3537. struct ddb_entry *ddb_entry)
  3538. {
  3539. struct iscsi_cls_session *cls_sess;
  3540. struct iscsi_cls_conn *cls_conn;
  3541. struct iscsi_session *sess;
  3542. struct iscsi_conn *conn;
  3543. uint32_t ddb_state;
  3544. dma_addr_t fw_ddb_entry_dma;
  3545. struct dev_db_entry *fw_ddb_entry;
  3546. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3547. &fw_ddb_entry_dma, GFP_KERNEL);
  3548. if (!fw_ddb_entry) {
  3549. ql4_printk(KERN_ERR, ha,
  3550. "%s: Unable to allocate dma buffer\n", __func__);
  3551. goto exit_session_conn_param;
  3552. }
  3553. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  3554. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  3555. NULL, NULL, NULL) == QLA_ERROR) {
  3556. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  3557. "get_ddb_entry for fw_ddb_index %d\n",
  3558. ha->host_no, __func__,
  3559. ddb_entry->fw_ddb_index));
  3560. goto exit_session_conn_param;
  3561. }
  3562. cls_sess = ddb_entry->sess;
  3563. sess = cls_sess->dd_data;
  3564. cls_conn = ddb_entry->conn;
  3565. conn = cls_conn->dd_data;
  3566. /* Update timers after login */
  3567. ddb_entry->default_relogin_timeout =
  3568. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  3569. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  3570. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  3571. ddb_entry->default_time2wait =
  3572. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  3573. /* Update params */
  3574. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3575. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  3576. memcpy(sess->initiatorname, ha->name_string,
  3577. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  3578. exit_session_conn_param:
  3579. if (fw_ddb_entry)
  3580. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3581. fw_ddb_entry, fw_ddb_entry_dma);
  3582. }
  3583. /*
  3584. * Timer routines
  3585. */
  3586. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  3587. unsigned long interval)
  3588. {
  3589. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  3590. __func__, ha->host->host_no));
  3591. init_timer(&ha->timer);
  3592. ha->timer.expires = jiffies + interval * HZ;
  3593. ha->timer.data = (unsigned long)ha;
  3594. ha->timer.function = (void (*)(unsigned long))func;
  3595. add_timer(&ha->timer);
  3596. ha->timer_active = 1;
  3597. }
  3598. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  3599. {
  3600. del_timer_sync(&ha->timer);
  3601. ha->timer_active = 0;
  3602. }
  3603. /***
  3604. * qla4xxx_mark_device_missing - blocks the session
  3605. * @cls_session: Pointer to the session to be blocked
  3606. * @ddb_entry: Pointer to device database entry
  3607. *
  3608. * This routine marks a device missing and close connection.
  3609. **/
  3610. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  3611. {
  3612. iscsi_block_session(cls_session);
  3613. }
  3614. /**
  3615. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  3616. * @ha: Pointer to host adapter structure.
  3617. *
  3618. * This routine marks a device missing and resets the relogin retry count.
  3619. **/
  3620. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  3621. {
  3622. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  3623. }
  3624. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  3625. struct ddb_entry *ddb_entry,
  3626. struct scsi_cmnd *cmd)
  3627. {
  3628. struct srb *srb;
  3629. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  3630. if (!srb)
  3631. return srb;
  3632. kref_init(&srb->srb_ref);
  3633. srb->ha = ha;
  3634. srb->ddb = ddb_entry;
  3635. srb->cmd = cmd;
  3636. srb->flags = 0;
  3637. CMD_SP(cmd) = (void *)srb;
  3638. return srb;
  3639. }
  3640. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  3641. {
  3642. struct scsi_cmnd *cmd = srb->cmd;
  3643. if (srb->flags & SRB_DMA_VALID) {
  3644. scsi_dma_unmap(cmd);
  3645. srb->flags &= ~SRB_DMA_VALID;
  3646. }
  3647. CMD_SP(cmd) = NULL;
  3648. }
  3649. void qla4xxx_srb_compl(struct kref *ref)
  3650. {
  3651. struct srb *srb = container_of(ref, struct srb, srb_ref);
  3652. struct scsi_cmnd *cmd = srb->cmd;
  3653. struct scsi_qla_host *ha = srb->ha;
  3654. qla4xxx_srb_free_dma(ha, srb);
  3655. mempool_free(srb, ha->srb_mempool);
  3656. cmd->scsi_done(cmd);
  3657. }
  3658. /**
  3659. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  3660. * @host: scsi host
  3661. * @cmd: Pointer to Linux's SCSI command structure
  3662. *
  3663. * Remarks:
  3664. * This routine is invoked by Linux to send a SCSI command to the driver.
  3665. * The mid-level driver tries to ensure that queuecommand never gets
  3666. * invoked concurrently with itself or the interrupt handler (although
  3667. * the interrupt handler may call this routine as part of request-
  3668. * completion handling). Unfortunely, it sometimes calls the scheduler
  3669. * in interrupt context which is a big NO! NO!.
  3670. **/
  3671. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  3672. {
  3673. struct scsi_qla_host *ha = to_qla_host(host);
  3674. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  3675. struct iscsi_cls_session *sess = ddb_entry->sess;
  3676. struct srb *srb;
  3677. int rval;
  3678. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  3679. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  3680. cmd->result = DID_NO_CONNECT << 16;
  3681. else
  3682. cmd->result = DID_REQUEUE << 16;
  3683. goto qc_fail_command;
  3684. }
  3685. if (!sess) {
  3686. cmd->result = DID_IMM_RETRY << 16;
  3687. goto qc_fail_command;
  3688. }
  3689. rval = iscsi_session_chkready(sess);
  3690. if (rval) {
  3691. cmd->result = rval;
  3692. goto qc_fail_command;
  3693. }
  3694. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  3695. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  3696. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3697. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  3698. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  3699. !test_bit(AF_ONLINE, &ha->flags) ||
  3700. !test_bit(AF_LINK_UP, &ha->flags) ||
  3701. test_bit(AF_LOOPBACK, &ha->flags) ||
  3702. test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
  3703. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
  3704. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  3705. goto qc_host_busy;
  3706. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  3707. if (!srb)
  3708. goto qc_host_busy;
  3709. rval = qla4xxx_send_command_to_isp(ha, srb);
  3710. if (rval != QLA_SUCCESS)
  3711. goto qc_host_busy_free_sp;
  3712. return 0;
  3713. qc_host_busy_free_sp:
  3714. qla4xxx_srb_free_dma(ha, srb);
  3715. mempool_free(srb, ha->srb_mempool);
  3716. qc_host_busy:
  3717. return SCSI_MLQUEUE_HOST_BUSY;
  3718. qc_fail_command:
  3719. cmd->scsi_done(cmd);
  3720. return 0;
  3721. }
  3722. /**
  3723. * qla4xxx_mem_free - frees memory allocated to adapter
  3724. * @ha: Pointer to host adapter structure.
  3725. *
  3726. * Frees memory previously allocated by qla4xxx_mem_alloc
  3727. **/
  3728. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  3729. {
  3730. if (ha->queues)
  3731. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  3732. ha->queues_dma);
  3733. if (ha->fw_dump)
  3734. vfree(ha->fw_dump);
  3735. ha->queues_len = 0;
  3736. ha->queues = NULL;
  3737. ha->queues_dma = 0;
  3738. ha->request_ring = NULL;
  3739. ha->request_dma = 0;
  3740. ha->response_ring = NULL;
  3741. ha->response_dma = 0;
  3742. ha->shadow_regs = NULL;
  3743. ha->shadow_regs_dma = 0;
  3744. ha->fw_dump = NULL;
  3745. ha->fw_dump_size = 0;
  3746. /* Free srb pool. */
  3747. if (ha->srb_mempool)
  3748. mempool_destroy(ha->srb_mempool);
  3749. ha->srb_mempool = NULL;
  3750. if (ha->chap_dma_pool)
  3751. dma_pool_destroy(ha->chap_dma_pool);
  3752. if (ha->chap_list)
  3753. vfree(ha->chap_list);
  3754. ha->chap_list = NULL;
  3755. if (ha->fw_ddb_dma_pool)
  3756. dma_pool_destroy(ha->fw_ddb_dma_pool);
  3757. /* release io space registers */
  3758. if (is_qla8022(ha)) {
  3759. if (ha->nx_pcibase)
  3760. iounmap(
  3761. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  3762. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3763. if (ha->nx_pcibase)
  3764. iounmap(
  3765. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  3766. } else if (ha->reg) {
  3767. iounmap(ha->reg);
  3768. }
  3769. if (ha->reset_tmplt.buff)
  3770. vfree(ha->reset_tmplt.buff);
  3771. pci_release_regions(ha->pdev);
  3772. }
  3773. /**
  3774. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  3775. * @ha: Pointer to host adapter structure
  3776. *
  3777. * Allocates DMA memory for request and response queues. Also allocates memory
  3778. * for srbs.
  3779. **/
  3780. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  3781. {
  3782. unsigned long align;
  3783. /* Allocate contiguous block of DMA memory for queues. */
  3784. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  3785. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  3786. sizeof(struct shadow_regs) +
  3787. MEM_ALIGN_VALUE +
  3788. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  3789. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  3790. &ha->queues_dma, GFP_KERNEL);
  3791. if (ha->queues == NULL) {
  3792. ql4_printk(KERN_WARNING, ha,
  3793. "Memory Allocation failed - queues.\n");
  3794. goto mem_alloc_error_exit;
  3795. }
  3796. memset(ha->queues, 0, ha->queues_len);
  3797. /*
  3798. * As per RISC alignment requirements -- the bus-address must be a
  3799. * multiple of the request-ring size (in bytes).
  3800. */
  3801. align = 0;
  3802. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  3803. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  3804. (MEM_ALIGN_VALUE - 1));
  3805. /* Update request and response queue pointers. */
  3806. ha->request_dma = ha->queues_dma + align;
  3807. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  3808. ha->response_dma = ha->queues_dma + align +
  3809. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  3810. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  3811. (REQUEST_QUEUE_DEPTH *
  3812. QUEUE_SIZE));
  3813. ha->shadow_regs_dma = ha->queues_dma + align +
  3814. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  3815. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  3816. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  3817. (REQUEST_QUEUE_DEPTH *
  3818. QUEUE_SIZE) +
  3819. (RESPONSE_QUEUE_DEPTH *
  3820. QUEUE_SIZE));
  3821. /* Allocate memory for srb pool. */
  3822. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  3823. mempool_free_slab, srb_cachep);
  3824. if (ha->srb_mempool == NULL) {
  3825. ql4_printk(KERN_WARNING, ha,
  3826. "Memory Allocation failed - SRB Pool.\n");
  3827. goto mem_alloc_error_exit;
  3828. }
  3829. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  3830. CHAP_DMA_BLOCK_SIZE, 8, 0);
  3831. if (ha->chap_dma_pool == NULL) {
  3832. ql4_printk(KERN_WARNING, ha,
  3833. "%s: chap_dma_pool allocation failed..\n", __func__);
  3834. goto mem_alloc_error_exit;
  3835. }
  3836. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  3837. DDB_DMA_BLOCK_SIZE, 8, 0);
  3838. if (ha->fw_ddb_dma_pool == NULL) {
  3839. ql4_printk(KERN_WARNING, ha,
  3840. "%s: fw_ddb_dma_pool allocation failed..\n",
  3841. __func__);
  3842. goto mem_alloc_error_exit;
  3843. }
  3844. return QLA_SUCCESS;
  3845. mem_alloc_error_exit:
  3846. qla4xxx_mem_free(ha);
  3847. return QLA_ERROR;
  3848. }
  3849. /**
  3850. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  3851. * @ha: adapter block pointer.
  3852. *
  3853. * Note: The caller should not hold the idc lock.
  3854. **/
  3855. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  3856. {
  3857. uint32_t temp, temp_state, temp_val;
  3858. int status = QLA_SUCCESS;
  3859. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  3860. temp_state = qla82xx_get_temp_state(temp);
  3861. temp_val = qla82xx_get_temp_val(temp);
  3862. if (temp_state == QLA82XX_TEMP_PANIC) {
  3863. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  3864. " exceeds maximum allowed. Hardware has been shut"
  3865. " down.\n", temp_val);
  3866. status = QLA_ERROR;
  3867. } else if (temp_state == QLA82XX_TEMP_WARN) {
  3868. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  3869. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  3870. " degrees C exceeds operating range."
  3871. " Immediate action needed.\n", temp_val);
  3872. } else {
  3873. if (ha->temperature == QLA82XX_TEMP_WARN)
  3874. ql4_printk(KERN_INFO, ha, "Device temperature is"
  3875. " now %d degrees C in normal range.\n",
  3876. temp_val);
  3877. }
  3878. ha->temperature = temp_state;
  3879. return status;
  3880. }
  3881. /**
  3882. * qla4_8xxx_check_fw_alive - Check firmware health
  3883. * @ha: Pointer to host adapter structure.
  3884. *
  3885. * Context: Interrupt
  3886. **/
  3887. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  3888. {
  3889. uint32_t fw_heartbeat_counter;
  3890. int status = QLA_SUCCESS;
  3891. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  3892. QLA8XXX_PEG_ALIVE_COUNTER);
  3893. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  3894. if (fw_heartbeat_counter == 0xffffffff) {
  3895. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  3896. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  3897. ha->host_no, __func__));
  3898. return status;
  3899. }
  3900. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  3901. ha->seconds_since_last_heartbeat++;
  3902. /* FW not alive after 2 seconds */
  3903. if (ha->seconds_since_last_heartbeat == 2) {
  3904. ha->seconds_since_last_heartbeat = 0;
  3905. qla4_8xxx_dump_peg_reg(ha);
  3906. status = QLA_ERROR;
  3907. }
  3908. } else
  3909. ha->seconds_since_last_heartbeat = 0;
  3910. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  3911. return status;
  3912. }
  3913. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  3914. {
  3915. uint32_t halt_status;
  3916. int halt_status_unrecoverable = 0;
  3917. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  3918. if (is_qla8022(ha)) {
  3919. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  3920. __func__);
  3921. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  3922. CRB_NIU_XG_PAUSE_CTL_P0 |
  3923. CRB_NIU_XG_PAUSE_CTL_P1);
  3924. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  3925. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  3926. __func__);
  3927. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  3928. halt_status_unrecoverable = 1;
  3929. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3930. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  3931. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  3932. __func__);
  3933. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  3934. halt_status_unrecoverable = 1;
  3935. }
  3936. /*
  3937. * Since we cannot change dev_state in interrupt context,
  3938. * set appropriate DPC flag then wakeup DPC
  3939. */
  3940. if (halt_status_unrecoverable) {
  3941. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  3942. } else {
  3943. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  3944. __func__);
  3945. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3946. }
  3947. qla4xxx_mailbox_premature_completion(ha);
  3948. qla4xxx_wake_dpc(ha);
  3949. }
  3950. /**
  3951. * qla4_8xxx_watchdog - Poll dev state
  3952. * @ha: Pointer to host adapter structure.
  3953. *
  3954. * Context: Interrupt
  3955. **/
  3956. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  3957. {
  3958. uint32_t dev_state;
  3959. uint32_t idc_ctrl;
  3960. if (is_qla8032(ha) &&
  3961. (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
  3962. WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
  3963. __func__, ha->func_num);
  3964. /* don't poll if reset is going on */
  3965. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  3966. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3967. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  3968. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  3969. if (qla4_8xxx_check_temp(ha)) {
  3970. if (is_qla8022(ha)) {
  3971. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  3972. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  3973. CRB_NIU_XG_PAUSE_CTL_P0 |
  3974. CRB_NIU_XG_PAUSE_CTL_P1);
  3975. }
  3976. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  3977. qla4xxx_wake_dpc(ha);
  3978. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  3979. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  3980. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
  3981. __func__);
  3982. if (is_qla8032(ha) || is_qla8042(ha)) {
  3983. idc_ctrl = qla4_83xx_rd_reg(ha,
  3984. QLA83XX_IDC_DRV_CTRL);
  3985. if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
  3986. ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
  3987. __func__);
  3988. qla4xxx_mailbox_premature_completion(
  3989. ha);
  3990. }
  3991. }
  3992. if ((is_qla8032(ha) || is_qla8042(ha)) ||
  3993. (is_qla8022(ha) && !ql4xdontresethba)) {
  3994. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3995. qla4xxx_wake_dpc(ha);
  3996. }
  3997. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  3998. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  3999. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  4000. __func__);
  4001. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  4002. qla4xxx_wake_dpc(ha);
  4003. } else {
  4004. /* Check firmware health */
  4005. if (qla4_8xxx_check_fw_alive(ha))
  4006. qla4_8xxx_process_fw_error(ha);
  4007. }
  4008. }
  4009. }
  4010. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  4011. {
  4012. struct iscsi_session *sess;
  4013. struct ddb_entry *ddb_entry;
  4014. struct scsi_qla_host *ha;
  4015. sess = cls_sess->dd_data;
  4016. ddb_entry = sess->dd_data;
  4017. ha = ddb_entry->ha;
  4018. if (!(ddb_entry->ddb_type == FLASH_DDB))
  4019. return;
  4020. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  4021. !iscsi_is_session_online(cls_sess)) {
  4022. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  4023. INVALID_ENTRY) {
  4024. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  4025. 0) {
  4026. atomic_set(&ddb_entry->retry_relogin_timer,
  4027. INVALID_ENTRY);
  4028. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4029. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4030. DEBUG2(ql4_printk(KERN_INFO, ha,
  4031. "%s: index [%d] login device\n",
  4032. __func__, ddb_entry->fw_ddb_index));
  4033. } else
  4034. atomic_dec(&ddb_entry->retry_relogin_timer);
  4035. }
  4036. }
  4037. /* Wait for relogin to timeout */
  4038. if (atomic_read(&ddb_entry->relogin_timer) &&
  4039. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  4040. /*
  4041. * If the relogin times out and the device is
  4042. * still NOT ONLINE then try and relogin again.
  4043. */
  4044. if (!iscsi_is_session_online(cls_sess)) {
  4045. /* Reset retry relogin timer */
  4046. atomic_inc(&ddb_entry->relogin_retry_count);
  4047. DEBUG2(ql4_printk(KERN_INFO, ha,
  4048. "%s: index[%d] relogin timed out-retrying"
  4049. " relogin (%d), retry (%d)\n", __func__,
  4050. ddb_entry->fw_ddb_index,
  4051. atomic_read(&ddb_entry->relogin_retry_count),
  4052. ddb_entry->default_time2wait + 4));
  4053. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4054. atomic_set(&ddb_entry->retry_relogin_timer,
  4055. ddb_entry->default_time2wait + 4);
  4056. }
  4057. }
  4058. }
  4059. /**
  4060. * qla4xxx_timer - checks every second for work to do.
  4061. * @ha: Pointer to host adapter structure.
  4062. **/
  4063. static void qla4xxx_timer(struct scsi_qla_host *ha)
  4064. {
  4065. int start_dpc = 0;
  4066. uint16_t w;
  4067. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  4068. /* If we are in the middle of AER/EEH processing
  4069. * skip any processing and reschedule the timer
  4070. */
  4071. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  4072. mod_timer(&ha->timer, jiffies + HZ);
  4073. return;
  4074. }
  4075. /* Hardware read to trigger an EEH error during mailbox waits. */
  4076. if (!pci_channel_offline(ha->pdev))
  4077. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  4078. if (is_qla80XX(ha))
  4079. qla4_8xxx_watchdog(ha);
  4080. if (is_qla40XX(ha)) {
  4081. /* Check for heartbeat interval. */
  4082. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  4083. ha->heartbeat_interval != 0) {
  4084. ha->seconds_since_last_heartbeat++;
  4085. if (ha->seconds_since_last_heartbeat >
  4086. ha->heartbeat_interval + 2)
  4087. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  4088. }
  4089. }
  4090. /* Process any deferred work. */
  4091. if (!list_empty(&ha->work_list))
  4092. start_dpc++;
  4093. /* Wakeup the dpc routine for this adapter, if needed. */
  4094. if (start_dpc ||
  4095. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  4096. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  4097. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  4098. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  4099. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  4100. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  4101. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  4102. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  4103. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  4104. test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
  4105. test_bit(DPC_AEN, &ha->dpc_flags)) {
  4106. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  4107. " - dpc flags = 0x%lx\n",
  4108. ha->host_no, __func__, ha->dpc_flags));
  4109. qla4xxx_wake_dpc(ha);
  4110. }
  4111. /* Reschedule timer thread to call us back in one second */
  4112. mod_timer(&ha->timer, jiffies + HZ);
  4113. DEBUG2(ha->seconds_since_last_intr++);
  4114. }
  4115. /**
  4116. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  4117. * @ha: Pointer to host adapter structure.
  4118. *
  4119. * This routine stalls the driver until all outstanding commands are returned.
  4120. * Caller must release the Hardware Lock prior to calling this routine.
  4121. **/
  4122. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  4123. {
  4124. uint32_t index = 0;
  4125. unsigned long flags;
  4126. struct scsi_cmnd *cmd;
  4127. unsigned long wtime;
  4128. uint32_t wtmo;
  4129. if (is_qla40XX(ha))
  4130. wtmo = WAIT_CMD_TOV;
  4131. else
  4132. wtmo = ha->nx_reset_timeout / 2;
  4133. wtime = jiffies + (wtmo * HZ);
  4134. DEBUG2(ql4_printk(KERN_INFO, ha,
  4135. "Wait up to %u seconds for cmds to complete\n",
  4136. wtmo));
  4137. while (!time_after_eq(jiffies, wtime)) {
  4138. spin_lock_irqsave(&ha->hardware_lock, flags);
  4139. /* Find a command that hasn't completed. */
  4140. for (index = 0; index < ha->host->can_queue; index++) {
  4141. cmd = scsi_host_find_tag(ha->host, index);
  4142. /*
  4143. * We cannot just check if the index is valid,
  4144. * becase if we are run from the scsi eh, then
  4145. * the scsi/block layer is going to prevent
  4146. * the tag from being released.
  4147. */
  4148. if (cmd != NULL && CMD_SP(cmd))
  4149. break;
  4150. }
  4151. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4152. /* If No Commands are pending, wait is complete */
  4153. if (index == ha->host->can_queue)
  4154. return QLA_SUCCESS;
  4155. msleep(1000);
  4156. }
  4157. /* If we timed out on waiting for commands to come back
  4158. * return ERROR. */
  4159. return QLA_ERROR;
  4160. }
  4161. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  4162. {
  4163. uint32_t ctrl_status;
  4164. unsigned long flags = 0;
  4165. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  4166. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  4167. return QLA_ERROR;
  4168. spin_lock_irqsave(&ha->hardware_lock, flags);
  4169. /*
  4170. * If the SCSI Reset Interrupt bit is set, clear it.
  4171. * Otherwise, the Soft Reset won't work.
  4172. */
  4173. ctrl_status = readw(&ha->reg->ctrl_status);
  4174. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  4175. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  4176. /* Issue Soft Reset */
  4177. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  4178. readl(&ha->reg->ctrl_status);
  4179. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4180. return QLA_SUCCESS;
  4181. }
  4182. /**
  4183. * qla4xxx_soft_reset - performs soft reset.
  4184. * @ha: Pointer to host adapter structure.
  4185. **/
  4186. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  4187. {
  4188. uint32_t max_wait_time;
  4189. unsigned long flags = 0;
  4190. int status;
  4191. uint32_t ctrl_status;
  4192. status = qla4xxx_hw_reset(ha);
  4193. if (status != QLA_SUCCESS)
  4194. return status;
  4195. status = QLA_ERROR;
  4196. /* Wait until the Network Reset Intr bit is cleared */
  4197. max_wait_time = RESET_INTR_TOV;
  4198. do {
  4199. spin_lock_irqsave(&ha->hardware_lock, flags);
  4200. ctrl_status = readw(&ha->reg->ctrl_status);
  4201. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4202. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  4203. break;
  4204. msleep(1000);
  4205. } while ((--max_wait_time));
  4206. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  4207. DEBUG2(printk(KERN_WARNING
  4208. "scsi%ld: Network Reset Intr not cleared by "
  4209. "Network function, clearing it now!\n",
  4210. ha->host_no));
  4211. spin_lock_irqsave(&ha->hardware_lock, flags);
  4212. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  4213. readl(&ha->reg->ctrl_status);
  4214. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4215. }
  4216. /* Wait until the firmware tells us the Soft Reset is done */
  4217. max_wait_time = SOFT_RESET_TOV;
  4218. do {
  4219. spin_lock_irqsave(&ha->hardware_lock, flags);
  4220. ctrl_status = readw(&ha->reg->ctrl_status);
  4221. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4222. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  4223. status = QLA_SUCCESS;
  4224. break;
  4225. }
  4226. msleep(1000);
  4227. } while ((--max_wait_time));
  4228. /*
  4229. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  4230. * after the soft reset has taken place.
  4231. */
  4232. spin_lock_irqsave(&ha->hardware_lock, flags);
  4233. ctrl_status = readw(&ha->reg->ctrl_status);
  4234. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  4235. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  4236. readl(&ha->reg->ctrl_status);
  4237. }
  4238. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4239. /* If soft reset fails then most probably the bios on other
  4240. * function is also enabled.
  4241. * Since the initialization is sequential the other fn
  4242. * wont be able to acknowledge the soft reset.
  4243. * Issue a force soft reset to workaround this scenario.
  4244. */
  4245. if (max_wait_time == 0) {
  4246. /* Issue Force Soft Reset */
  4247. spin_lock_irqsave(&ha->hardware_lock, flags);
  4248. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  4249. readl(&ha->reg->ctrl_status);
  4250. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4251. /* Wait until the firmware tells us the Soft Reset is done */
  4252. max_wait_time = SOFT_RESET_TOV;
  4253. do {
  4254. spin_lock_irqsave(&ha->hardware_lock, flags);
  4255. ctrl_status = readw(&ha->reg->ctrl_status);
  4256. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4257. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  4258. status = QLA_SUCCESS;
  4259. break;
  4260. }
  4261. msleep(1000);
  4262. } while ((--max_wait_time));
  4263. }
  4264. return status;
  4265. }
  4266. /**
  4267. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  4268. * @ha: Pointer to host adapter structure.
  4269. * @res: returned scsi status
  4270. *
  4271. * This routine is called just prior to a HARD RESET to return all
  4272. * outstanding commands back to the Operating System.
  4273. * Caller should make sure that the following locks are released
  4274. * before this calling routine: Hardware lock, and io_request_lock.
  4275. **/
  4276. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  4277. {
  4278. struct srb *srb;
  4279. int i;
  4280. unsigned long flags;
  4281. spin_lock_irqsave(&ha->hardware_lock, flags);
  4282. for (i = 0; i < ha->host->can_queue; i++) {
  4283. srb = qla4xxx_del_from_active_array(ha, i);
  4284. if (srb != NULL) {
  4285. srb->cmd->result = res;
  4286. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  4287. }
  4288. }
  4289. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4290. }
  4291. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  4292. {
  4293. clear_bit(AF_ONLINE, &ha->flags);
  4294. /* Disable the board */
  4295. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  4296. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  4297. qla4xxx_mark_all_devices_missing(ha);
  4298. clear_bit(AF_INIT_DONE, &ha->flags);
  4299. }
  4300. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  4301. {
  4302. struct iscsi_session *sess;
  4303. struct ddb_entry *ddb_entry;
  4304. sess = cls_session->dd_data;
  4305. ddb_entry = sess->dd_data;
  4306. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  4307. if (ddb_entry->ddb_type == FLASH_DDB)
  4308. iscsi_block_session(ddb_entry->sess);
  4309. else
  4310. iscsi_session_failure(cls_session->dd_data,
  4311. ISCSI_ERR_CONN_FAILED);
  4312. }
  4313. /**
  4314. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  4315. * @ha: Pointer to host adapter structure.
  4316. **/
  4317. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  4318. {
  4319. int status = QLA_ERROR;
  4320. uint8_t reset_chip = 0;
  4321. uint32_t dev_state;
  4322. unsigned long wait;
  4323. /* Stall incoming I/O until we are done */
  4324. scsi_block_requests(ha->host);
  4325. clear_bit(AF_ONLINE, &ha->flags);
  4326. clear_bit(AF_LINK_UP, &ha->flags);
  4327. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  4328. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  4329. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  4330. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  4331. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  4332. __func__);
  4333. /* disable pause frame for ISP83xx */
  4334. qla4_83xx_disable_pause(ha);
  4335. }
  4336. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  4337. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  4338. reset_chip = 1;
  4339. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  4340. * do not reset adapter, jump to initialize_adapter */
  4341. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  4342. status = QLA_SUCCESS;
  4343. goto recover_ha_init_adapter;
  4344. }
  4345. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  4346. * from eh_host_reset or ioctl module */
  4347. if (is_qla80XX(ha) && !reset_chip &&
  4348. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  4349. DEBUG2(ql4_printk(KERN_INFO, ha,
  4350. "scsi%ld: %s - Performing stop_firmware...\n",
  4351. ha->host_no, __func__));
  4352. status = ha->isp_ops->reset_firmware(ha);
  4353. if (status == QLA_SUCCESS) {
  4354. ha->isp_ops->disable_intrs(ha);
  4355. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4356. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  4357. } else {
  4358. /* If the stop_firmware fails then
  4359. * reset the entire chip */
  4360. reset_chip = 1;
  4361. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  4362. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  4363. }
  4364. }
  4365. /* Issue full chip reset if recovering from a catastrophic error,
  4366. * or if stop_firmware fails for ISP-8xxx.
  4367. * This is the default case for ISP-4xxx */
  4368. if (is_qla40XX(ha) || reset_chip) {
  4369. if (is_qla40XX(ha))
  4370. goto chip_reset;
  4371. /* Check if 8XXX firmware is alive or not
  4372. * We may have arrived here from NEED_RESET
  4373. * detection only */
  4374. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  4375. goto chip_reset;
  4376. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  4377. while (time_before(jiffies, wait)) {
  4378. if (qla4_8xxx_check_fw_alive(ha)) {
  4379. qla4xxx_mailbox_premature_completion(ha);
  4380. break;
  4381. }
  4382. set_current_state(TASK_UNINTERRUPTIBLE);
  4383. schedule_timeout(HZ);
  4384. }
  4385. chip_reset:
  4386. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  4387. qla4xxx_cmd_wait(ha);
  4388. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4389. DEBUG2(ql4_printk(KERN_INFO, ha,
  4390. "scsi%ld: %s - Performing chip reset..\n",
  4391. ha->host_no, __func__));
  4392. status = ha->isp_ops->reset_chip(ha);
  4393. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  4394. }
  4395. /* Flush any pending ddb changed AENs */
  4396. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4397. recover_ha_init_adapter:
  4398. /* Upon successful firmware/chip reset, re-initialize the adapter */
  4399. if (status == QLA_SUCCESS) {
  4400. /* For ISP-4xxx, force function 1 to always initialize
  4401. * before function 3 to prevent both funcions from
  4402. * stepping on top of the other */
  4403. if (is_qla40XX(ha) && (ha->mac_index == 3))
  4404. ssleep(6);
  4405. /* NOTE: AF_ONLINE flag set upon successful completion of
  4406. * qla4xxx_initialize_adapter */
  4407. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  4408. if (is_qla80XX(ha) && (status == QLA_ERROR)) {
  4409. status = qla4_8xxx_check_init_adapter_retry(ha);
  4410. if (status == QLA_ERROR) {
  4411. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
  4412. ha->host_no, __func__);
  4413. qla4xxx_dead_adapter_cleanup(ha);
  4414. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4415. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4416. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  4417. &ha->dpc_flags);
  4418. goto exit_recover;
  4419. }
  4420. }
  4421. }
  4422. /* Retry failed adapter initialization, if necessary
  4423. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  4424. * case to prevent ping-pong resets between functions */
  4425. if (!test_bit(AF_ONLINE, &ha->flags) &&
  4426. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  4427. /* Adapter initialization failed, see if we can retry
  4428. * resetting the ha.
  4429. * Since we don't want to block the DPC for too long
  4430. * with multiple resets in the same thread,
  4431. * utilize DPC to retry */
  4432. if (is_qla80XX(ha)) {
  4433. ha->isp_ops->idc_lock(ha);
  4434. dev_state = qla4_8xxx_rd_direct(ha,
  4435. QLA8XXX_CRB_DEV_STATE);
  4436. ha->isp_ops->idc_unlock(ha);
  4437. if (dev_state == QLA8XXX_DEV_FAILED) {
  4438. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  4439. "recover adapter. H/W is in Failed "
  4440. "state\n", __func__);
  4441. qla4xxx_dead_adapter_cleanup(ha);
  4442. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4443. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4444. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  4445. &ha->dpc_flags);
  4446. status = QLA_ERROR;
  4447. goto exit_recover;
  4448. }
  4449. }
  4450. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  4451. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  4452. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  4453. "(%d) more times\n", ha->host_no,
  4454. ha->retry_reset_ha_cnt));
  4455. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4456. status = QLA_ERROR;
  4457. } else {
  4458. if (ha->retry_reset_ha_cnt > 0) {
  4459. /* Schedule another Reset HA--DPC will retry */
  4460. ha->retry_reset_ha_cnt--;
  4461. DEBUG2(printk("scsi%ld: recover adapter - "
  4462. "retry remaining %d\n",
  4463. ha->host_no,
  4464. ha->retry_reset_ha_cnt));
  4465. status = QLA_ERROR;
  4466. }
  4467. if (ha->retry_reset_ha_cnt == 0) {
  4468. /* Recover adapter retries have been exhausted.
  4469. * Adapter DEAD */
  4470. DEBUG2(printk("scsi%ld: recover adapter "
  4471. "failed - board disabled\n",
  4472. ha->host_no));
  4473. qla4xxx_dead_adapter_cleanup(ha);
  4474. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4475. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4476. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  4477. &ha->dpc_flags);
  4478. status = QLA_ERROR;
  4479. }
  4480. }
  4481. } else {
  4482. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4483. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  4484. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4485. }
  4486. exit_recover:
  4487. ha->adapter_error_count++;
  4488. if (test_bit(AF_ONLINE, &ha->flags))
  4489. ha->isp_ops->enable_intrs(ha);
  4490. scsi_unblock_requests(ha->host);
  4491. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  4492. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  4493. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  4494. return status;
  4495. }
  4496. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  4497. {
  4498. struct iscsi_session *sess;
  4499. struct ddb_entry *ddb_entry;
  4500. struct scsi_qla_host *ha;
  4501. sess = cls_session->dd_data;
  4502. ddb_entry = sess->dd_data;
  4503. ha = ddb_entry->ha;
  4504. if (!iscsi_is_session_online(cls_session)) {
  4505. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  4506. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4507. " unblock session\n", ha->host_no, __func__,
  4508. ddb_entry->fw_ddb_index);
  4509. iscsi_unblock_session(ddb_entry->sess);
  4510. } else {
  4511. /* Trigger relogin */
  4512. if (ddb_entry->ddb_type == FLASH_DDB) {
  4513. if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
  4514. test_bit(DF_DISABLE_RELOGIN,
  4515. &ddb_entry->flags)))
  4516. qla4xxx_arm_relogin_timer(ddb_entry);
  4517. } else
  4518. iscsi_session_failure(cls_session->dd_data,
  4519. ISCSI_ERR_CONN_FAILED);
  4520. }
  4521. }
  4522. }
  4523. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  4524. {
  4525. struct iscsi_session *sess;
  4526. struct ddb_entry *ddb_entry;
  4527. struct scsi_qla_host *ha;
  4528. sess = cls_session->dd_data;
  4529. ddb_entry = sess->dd_data;
  4530. ha = ddb_entry->ha;
  4531. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4532. " unblock session\n", ha->host_no, __func__,
  4533. ddb_entry->fw_ddb_index);
  4534. iscsi_unblock_session(ddb_entry->sess);
  4535. /* Start scan target */
  4536. if (test_bit(AF_ONLINE, &ha->flags)) {
  4537. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4538. " start scan\n", ha->host_no, __func__,
  4539. ddb_entry->fw_ddb_index);
  4540. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  4541. }
  4542. return QLA_SUCCESS;
  4543. }
  4544. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  4545. {
  4546. struct iscsi_session *sess;
  4547. struct ddb_entry *ddb_entry;
  4548. struct scsi_qla_host *ha;
  4549. int status = QLA_SUCCESS;
  4550. sess = cls_session->dd_data;
  4551. ddb_entry = sess->dd_data;
  4552. ha = ddb_entry->ha;
  4553. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4554. " unblock user space session\n", ha->host_no, __func__,
  4555. ddb_entry->fw_ddb_index);
  4556. if (!iscsi_is_session_online(cls_session)) {
  4557. iscsi_conn_start(ddb_entry->conn);
  4558. iscsi_conn_login_event(ddb_entry->conn,
  4559. ISCSI_CONN_STATE_LOGGED_IN);
  4560. } else {
  4561. ql4_printk(KERN_INFO, ha,
  4562. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  4563. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  4564. cls_session->sid);
  4565. status = QLA_ERROR;
  4566. }
  4567. return status;
  4568. }
  4569. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  4570. {
  4571. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  4572. }
  4573. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  4574. {
  4575. uint16_t relogin_timer;
  4576. struct iscsi_session *sess;
  4577. struct ddb_entry *ddb_entry;
  4578. struct scsi_qla_host *ha;
  4579. sess = cls_sess->dd_data;
  4580. ddb_entry = sess->dd_data;
  4581. ha = ddb_entry->ha;
  4582. relogin_timer = max(ddb_entry->default_relogin_timeout,
  4583. (uint16_t)RELOGIN_TOV);
  4584. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  4585. DEBUG2(ql4_printk(KERN_INFO, ha,
  4586. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  4587. ddb_entry->fw_ddb_index, relogin_timer));
  4588. qla4xxx_login_flash_ddb(cls_sess);
  4589. }
  4590. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  4591. {
  4592. struct iscsi_session *sess;
  4593. struct ddb_entry *ddb_entry;
  4594. struct scsi_qla_host *ha;
  4595. sess = cls_sess->dd_data;
  4596. ddb_entry = sess->dd_data;
  4597. ha = ddb_entry->ha;
  4598. if (!(ddb_entry->ddb_type == FLASH_DDB))
  4599. return;
  4600. if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  4601. return;
  4602. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  4603. !iscsi_is_session_online(cls_sess)) {
  4604. DEBUG2(ql4_printk(KERN_INFO, ha,
  4605. "relogin issued\n"));
  4606. qla4xxx_relogin_flash_ddb(cls_sess);
  4607. }
  4608. }
  4609. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  4610. {
  4611. if (ha->dpc_thread)
  4612. queue_work(ha->dpc_thread, &ha->dpc_work);
  4613. }
  4614. static struct qla4_work_evt *
  4615. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  4616. enum qla4_work_type type)
  4617. {
  4618. struct qla4_work_evt *e;
  4619. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  4620. e = kzalloc(size, GFP_ATOMIC);
  4621. if (!e)
  4622. return NULL;
  4623. INIT_LIST_HEAD(&e->list);
  4624. e->type = type;
  4625. return e;
  4626. }
  4627. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  4628. struct qla4_work_evt *e)
  4629. {
  4630. unsigned long flags;
  4631. spin_lock_irqsave(&ha->work_lock, flags);
  4632. list_add_tail(&e->list, &ha->work_list);
  4633. spin_unlock_irqrestore(&ha->work_lock, flags);
  4634. qla4xxx_wake_dpc(ha);
  4635. }
  4636. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  4637. enum iscsi_host_event_code aen_code,
  4638. uint32_t data_size, uint8_t *data)
  4639. {
  4640. struct qla4_work_evt *e;
  4641. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  4642. if (!e)
  4643. return QLA_ERROR;
  4644. e->u.aen.code = aen_code;
  4645. e->u.aen.data_size = data_size;
  4646. memcpy(e->u.aen.data, data, data_size);
  4647. qla4xxx_post_work(ha, e);
  4648. return QLA_SUCCESS;
  4649. }
  4650. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  4651. uint32_t status, uint32_t pid,
  4652. uint32_t data_size, uint8_t *data)
  4653. {
  4654. struct qla4_work_evt *e;
  4655. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  4656. if (!e)
  4657. return QLA_ERROR;
  4658. e->u.ping.status = status;
  4659. e->u.ping.pid = pid;
  4660. e->u.ping.data_size = data_size;
  4661. memcpy(e->u.ping.data, data, data_size);
  4662. qla4xxx_post_work(ha, e);
  4663. return QLA_SUCCESS;
  4664. }
  4665. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  4666. {
  4667. struct qla4_work_evt *e, *tmp;
  4668. unsigned long flags;
  4669. LIST_HEAD(work);
  4670. spin_lock_irqsave(&ha->work_lock, flags);
  4671. list_splice_init(&ha->work_list, &work);
  4672. spin_unlock_irqrestore(&ha->work_lock, flags);
  4673. list_for_each_entry_safe(e, tmp, &work, list) {
  4674. list_del_init(&e->list);
  4675. switch (e->type) {
  4676. case QLA4_EVENT_AEN:
  4677. iscsi_post_host_event(ha->host_no,
  4678. &qla4xxx_iscsi_transport,
  4679. e->u.aen.code,
  4680. e->u.aen.data_size,
  4681. e->u.aen.data);
  4682. break;
  4683. case QLA4_EVENT_PING_STATUS:
  4684. iscsi_ping_comp_event(ha->host_no,
  4685. &qla4xxx_iscsi_transport,
  4686. e->u.ping.status,
  4687. e->u.ping.pid,
  4688. e->u.ping.data_size,
  4689. e->u.ping.data);
  4690. break;
  4691. default:
  4692. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  4693. "supported", e->type);
  4694. }
  4695. kfree(e);
  4696. }
  4697. }
  4698. /**
  4699. * qla4xxx_do_dpc - dpc routine
  4700. * @data: in our case pointer to adapter structure
  4701. *
  4702. * This routine is a task that is schedule by the interrupt handler
  4703. * to perform the background processing for interrupts. We put it
  4704. * on a task queue that is consumed whenever the scheduler runs; that's
  4705. * so you can do anything (i.e. put the process to sleep etc). In fact,
  4706. * the mid-level tries to sleep when it reaches the driver threshold
  4707. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  4708. **/
  4709. static void qla4xxx_do_dpc(struct work_struct *work)
  4710. {
  4711. struct scsi_qla_host *ha =
  4712. container_of(work, struct scsi_qla_host, dpc_work);
  4713. int status = QLA_ERROR;
  4714. DEBUG2(ql4_printk(KERN_INFO, ha,
  4715. "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  4716. ha->host_no, __func__, ha->flags, ha->dpc_flags));
  4717. /* Initialization not yet finished. Don't do anything yet. */
  4718. if (!test_bit(AF_INIT_DONE, &ha->flags))
  4719. return;
  4720. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  4721. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  4722. ha->host_no, __func__, ha->flags));
  4723. return;
  4724. }
  4725. /* post events to application */
  4726. qla4xxx_do_work(ha);
  4727. if (is_qla80XX(ha)) {
  4728. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  4729. if (is_qla8032(ha) || is_qla8042(ha)) {
  4730. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  4731. __func__);
  4732. /* disable pause frame for ISP83xx */
  4733. qla4_83xx_disable_pause(ha);
  4734. }
  4735. ha->isp_ops->idc_lock(ha);
  4736. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  4737. QLA8XXX_DEV_FAILED);
  4738. ha->isp_ops->idc_unlock(ha);
  4739. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  4740. qla4_8xxx_device_state_handler(ha);
  4741. }
  4742. if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
  4743. if (is_qla8042(ha)) {
  4744. if (ha->idc_info.info2 &
  4745. ENABLE_INTERNAL_LOOPBACK) {
  4746. ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
  4747. __func__);
  4748. status = qla4_84xx_config_acb(ha,
  4749. ACB_CONFIG_DISABLE);
  4750. if (status != QLA_SUCCESS) {
  4751. ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
  4752. __func__);
  4753. }
  4754. }
  4755. }
  4756. qla4_83xx_post_idc_ack(ha);
  4757. clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
  4758. }
  4759. if (is_qla8042(ha) &&
  4760. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
  4761. ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
  4762. __func__);
  4763. if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
  4764. QLA_SUCCESS) {
  4765. ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
  4766. __func__);
  4767. }
  4768. clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
  4769. }
  4770. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  4771. qla4_8xxx_need_qsnt_handler(ha);
  4772. }
  4773. }
  4774. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  4775. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  4776. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  4777. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  4778. if ((is_qla8022(ha) && ql4xdontresethba) ||
  4779. ((is_qla8032(ha) || is_qla8042(ha)) &&
  4780. qla4_83xx_idc_dontreset(ha))) {
  4781. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  4782. ha->host_no, __func__));
  4783. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4784. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  4785. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  4786. goto dpc_post_reset_ha;
  4787. }
  4788. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  4789. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  4790. qla4xxx_recover_adapter(ha);
  4791. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  4792. uint8_t wait_time = RESET_INTR_TOV;
  4793. while ((readw(&ha->reg->ctrl_status) &
  4794. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  4795. if (--wait_time == 0)
  4796. break;
  4797. msleep(1000);
  4798. }
  4799. if (wait_time == 0)
  4800. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  4801. "bit not cleared-- resetting\n",
  4802. ha->host_no, __func__));
  4803. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  4804. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  4805. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4806. status = qla4xxx_recover_adapter(ha);
  4807. }
  4808. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  4809. if (status == QLA_SUCCESS)
  4810. ha->isp_ops->enable_intrs(ha);
  4811. }
  4812. }
  4813. dpc_post_reset_ha:
  4814. /* ---- process AEN? --- */
  4815. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  4816. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  4817. /* ---- Get DHCP IP Address? --- */
  4818. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  4819. qla4xxx_get_dhcp_ip_address(ha);
  4820. /* ---- relogin device? --- */
  4821. if (adapter_up(ha) &&
  4822. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  4823. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  4824. }
  4825. /* ---- link change? --- */
  4826. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  4827. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  4828. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  4829. /* ---- link down? --- */
  4830. qla4xxx_mark_all_devices_missing(ha);
  4831. } else {
  4832. /* ---- link up? --- *
  4833. * F/W will auto login to all devices ONLY ONCE after
  4834. * link up during driver initialization and runtime
  4835. * fatal error recovery. Therefore, the driver must
  4836. * manually relogin to devices when recovering from
  4837. * connection failures, logouts, expired KATO, etc. */
  4838. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  4839. qla4xxx_build_ddb_list(ha, ha->is_reset);
  4840. iscsi_host_for_each_session(ha->host,
  4841. qla4xxx_login_flash_ddb);
  4842. } else
  4843. qla4xxx_relogin_all_devices(ha);
  4844. }
  4845. }
  4846. if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
  4847. if (qla4xxx_sysfs_ddb_export(ha))
  4848. ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
  4849. __func__);
  4850. }
  4851. }
  4852. /**
  4853. * qla4xxx_free_adapter - release the adapter
  4854. * @ha: pointer to adapter structure
  4855. **/
  4856. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  4857. {
  4858. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  4859. /* Turn-off interrupts on the card. */
  4860. ha->isp_ops->disable_intrs(ha);
  4861. if (is_qla40XX(ha)) {
  4862. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  4863. &ha->reg->ctrl_status);
  4864. readl(&ha->reg->ctrl_status);
  4865. } else if (is_qla8022(ha)) {
  4866. writel(0, &ha->qla4_82xx_reg->host_int);
  4867. readl(&ha->qla4_82xx_reg->host_int);
  4868. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  4869. writel(0, &ha->qla4_83xx_reg->risc_intr);
  4870. readl(&ha->qla4_83xx_reg->risc_intr);
  4871. }
  4872. /* Remove timer thread, if present */
  4873. if (ha->timer_active)
  4874. qla4xxx_stop_timer(ha);
  4875. /* Kill the kernel thread for this host */
  4876. if (ha->dpc_thread)
  4877. destroy_workqueue(ha->dpc_thread);
  4878. /* Kill the kernel thread for this host */
  4879. if (ha->task_wq)
  4880. destroy_workqueue(ha->task_wq);
  4881. /* Put firmware in known state */
  4882. ha->isp_ops->reset_firmware(ha);
  4883. if (is_qla80XX(ha)) {
  4884. ha->isp_ops->idc_lock(ha);
  4885. qla4_8xxx_clear_drv_active(ha);
  4886. ha->isp_ops->idc_unlock(ha);
  4887. }
  4888. /* Detach interrupts */
  4889. qla4xxx_free_irqs(ha);
  4890. /* free extra memory */
  4891. qla4xxx_mem_free(ha);
  4892. }
  4893. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  4894. {
  4895. int status = 0;
  4896. unsigned long mem_base, mem_len, db_base, db_len;
  4897. struct pci_dev *pdev = ha->pdev;
  4898. status = pci_request_regions(pdev, DRIVER_NAME);
  4899. if (status) {
  4900. printk(KERN_WARNING
  4901. "scsi(%ld) Failed to reserve PIO regions (%s) "
  4902. "status=%d\n", ha->host_no, pci_name(pdev), status);
  4903. goto iospace_error_exit;
  4904. }
  4905. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  4906. __func__, pdev->revision));
  4907. ha->revision_id = pdev->revision;
  4908. /* remap phys address */
  4909. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  4910. mem_len = pci_resource_len(pdev, 0);
  4911. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  4912. __func__, mem_base, mem_len));
  4913. /* mapping of pcibase pointer */
  4914. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  4915. if (!ha->nx_pcibase) {
  4916. printk(KERN_ERR
  4917. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  4918. pci_release_regions(ha->pdev);
  4919. goto iospace_error_exit;
  4920. }
  4921. /* Mapping of IO base pointer, door bell read and write pointer */
  4922. /* mapping of IO base pointer */
  4923. if (is_qla8022(ha)) {
  4924. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  4925. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  4926. (ha->pdev->devfn << 11));
  4927. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  4928. QLA82XX_CAM_RAM_DB2);
  4929. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  4930. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  4931. ((uint8_t *)ha->nx_pcibase);
  4932. }
  4933. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  4934. db_len = pci_resource_len(pdev, 4);
  4935. return 0;
  4936. iospace_error_exit:
  4937. return -ENOMEM;
  4938. }
  4939. /***
  4940. * qla4xxx_iospace_config - maps registers
  4941. * @ha: pointer to adapter structure
  4942. *
  4943. * This routines maps HBA's registers from the pci address space
  4944. * into the kernel virtual address space for memory mapped i/o.
  4945. **/
  4946. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  4947. {
  4948. unsigned long pio, pio_len, pio_flags;
  4949. unsigned long mmio, mmio_len, mmio_flags;
  4950. pio = pci_resource_start(ha->pdev, 0);
  4951. pio_len = pci_resource_len(ha->pdev, 0);
  4952. pio_flags = pci_resource_flags(ha->pdev, 0);
  4953. if (pio_flags & IORESOURCE_IO) {
  4954. if (pio_len < MIN_IOBASE_LEN) {
  4955. ql4_printk(KERN_WARNING, ha,
  4956. "Invalid PCI I/O region size\n");
  4957. pio = 0;
  4958. }
  4959. } else {
  4960. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  4961. pio = 0;
  4962. }
  4963. /* Use MMIO operations for all accesses. */
  4964. mmio = pci_resource_start(ha->pdev, 1);
  4965. mmio_len = pci_resource_len(ha->pdev, 1);
  4966. mmio_flags = pci_resource_flags(ha->pdev, 1);
  4967. if (!(mmio_flags & IORESOURCE_MEM)) {
  4968. ql4_printk(KERN_ERR, ha,
  4969. "region #0 not an MMIO resource, aborting\n");
  4970. goto iospace_error_exit;
  4971. }
  4972. if (mmio_len < MIN_IOBASE_LEN) {
  4973. ql4_printk(KERN_ERR, ha,
  4974. "Invalid PCI mem region size, aborting\n");
  4975. goto iospace_error_exit;
  4976. }
  4977. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  4978. ql4_printk(KERN_WARNING, ha,
  4979. "Failed to reserve PIO/MMIO regions\n");
  4980. goto iospace_error_exit;
  4981. }
  4982. ha->pio_address = pio;
  4983. ha->pio_length = pio_len;
  4984. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  4985. if (!ha->reg) {
  4986. ql4_printk(KERN_ERR, ha,
  4987. "cannot remap MMIO, aborting\n");
  4988. goto iospace_error_exit;
  4989. }
  4990. return 0;
  4991. iospace_error_exit:
  4992. return -ENOMEM;
  4993. }
  4994. static struct isp_operations qla4xxx_isp_ops = {
  4995. .iospace_config = qla4xxx_iospace_config,
  4996. .pci_config = qla4xxx_pci_config,
  4997. .disable_intrs = qla4xxx_disable_intrs,
  4998. .enable_intrs = qla4xxx_enable_intrs,
  4999. .start_firmware = qla4xxx_start_firmware,
  5000. .intr_handler = qla4xxx_intr_handler,
  5001. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  5002. .reset_chip = qla4xxx_soft_reset,
  5003. .reset_firmware = qla4xxx_hw_reset,
  5004. .queue_iocb = qla4xxx_queue_iocb,
  5005. .complete_iocb = qla4xxx_complete_iocb,
  5006. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  5007. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  5008. .get_sys_info = qla4xxx_get_sys_info,
  5009. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  5010. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  5011. };
  5012. static struct isp_operations qla4_82xx_isp_ops = {
  5013. .iospace_config = qla4_8xxx_iospace_config,
  5014. .pci_config = qla4_8xxx_pci_config,
  5015. .disable_intrs = qla4_82xx_disable_intrs,
  5016. .enable_intrs = qla4_82xx_enable_intrs,
  5017. .start_firmware = qla4_8xxx_load_risc,
  5018. .restart_firmware = qla4_82xx_try_start_fw,
  5019. .intr_handler = qla4_82xx_intr_handler,
  5020. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  5021. .need_reset = qla4_8xxx_need_reset,
  5022. .reset_chip = qla4_82xx_isp_reset,
  5023. .reset_firmware = qla4_8xxx_stop_firmware,
  5024. .queue_iocb = qla4_82xx_queue_iocb,
  5025. .complete_iocb = qla4_82xx_complete_iocb,
  5026. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  5027. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  5028. .get_sys_info = qla4_8xxx_get_sys_info,
  5029. .rd_reg_direct = qla4_82xx_rd_32,
  5030. .wr_reg_direct = qla4_82xx_wr_32,
  5031. .rd_reg_indirect = qla4_82xx_md_rd_32,
  5032. .wr_reg_indirect = qla4_82xx_md_wr_32,
  5033. .idc_lock = qla4_82xx_idc_lock,
  5034. .idc_unlock = qla4_82xx_idc_unlock,
  5035. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  5036. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  5037. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  5038. };
  5039. static struct isp_operations qla4_83xx_isp_ops = {
  5040. .iospace_config = qla4_8xxx_iospace_config,
  5041. .pci_config = qla4_8xxx_pci_config,
  5042. .disable_intrs = qla4_83xx_disable_intrs,
  5043. .enable_intrs = qla4_83xx_enable_intrs,
  5044. .start_firmware = qla4_8xxx_load_risc,
  5045. .restart_firmware = qla4_83xx_start_firmware,
  5046. .intr_handler = qla4_83xx_intr_handler,
  5047. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  5048. .need_reset = qla4_8xxx_need_reset,
  5049. .reset_chip = qla4_83xx_isp_reset,
  5050. .reset_firmware = qla4_8xxx_stop_firmware,
  5051. .queue_iocb = qla4_83xx_queue_iocb,
  5052. .complete_iocb = qla4_83xx_complete_iocb,
  5053. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  5054. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  5055. .get_sys_info = qla4_8xxx_get_sys_info,
  5056. .rd_reg_direct = qla4_83xx_rd_reg,
  5057. .wr_reg_direct = qla4_83xx_wr_reg,
  5058. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  5059. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  5060. .idc_lock = qla4_83xx_drv_lock,
  5061. .idc_unlock = qla4_83xx_drv_unlock,
  5062. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  5063. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  5064. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  5065. };
  5066. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  5067. {
  5068. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  5069. }
  5070. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  5071. {
  5072. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  5073. }
  5074. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  5075. {
  5076. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  5077. }
  5078. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  5079. {
  5080. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  5081. }
  5082. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  5083. {
  5084. struct scsi_qla_host *ha = data;
  5085. char *str = buf;
  5086. int rc;
  5087. switch (type) {
  5088. case ISCSI_BOOT_ETH_FLAGS:
  5089. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  5090. break;
  5091. case ISCSI_BOOT_ETH_INDEX:
  5092. rc = sprintf(str, "0\n");
  5093. break;
  5094. case ISCSI_BOOT_ETH_MAC:
  5095. rc = sysfs_format_mac(str, ha->my_mac,
  5096. MAC_ADDR_LEN);
  5097. break;
  5098. default:
  5099. rc = -ENOSYS;
  5100. break;
  5101. }
  5102. return rc;
  5103. }
  5104. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  5105. {
  5106. int rc;
  5107. switch (type) {
  5108. case ISCSI_BOOT_ETH_FLAGS:
  5109. case ISCSI_BOOT_ETH_MAC:
  5110. case ISCSI_BOOT_ETH_INDEX:
  5111. rc = S_IRUGO;
  5112. break;
  5113. default:
  5114. rc = 0;
  5115. break;
  5116. }
  5117. return rc;
  5118. }
  5119. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  5120. {
  5121. struct scsi_qla_host *ha = data;
  5122. char *str = buf;
  5123. int rc;
  5124. switch (type) {
  5125. case ISCSI_BOOT_INI_INITIATOR_NAME:
  5126. rc = sprintf(str, "%s\n", ha->name_string);
  5127. break;
  5128. default:
  5129. rc = -ENOSYS;
  5130. break;
  5131. }
  5132. return rc;
  5133. }
  5134. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  5135. {
  5136. int rc;
  5137. switch (type) {
  5138. case ISCSI_BOOT_INI_INITIATOR_NAME:
  5139. rc = S_IRUGO;
  5140. break;
  5141. default:
  5142. rc = 0;
  5143. break;
  5144. }
  5145. return rc;
  5146. }
  5147. static ssize_t
  5148. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  5149. char *buf)
  5150. {
  5151. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  5152. char *str = buf;
  5153. int rc;
  5154. switch (type) {
  5155. case ISCSI_BOOT_TGT_NAME:
  5156. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  5157. break;
  5158. case ISCSI_BOOT_TGT_IP_ADDR:
  5159. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  5160. rc = sprintf(buf, "%pI4\n",
  5161. &boot_conn->dest_ipaddr.ip_address);
  5162. else
  5163. rc = sprintf(str, "%pI6\n",
  5164. &boot_conn->dest_ipaddr.ip_address);
  5165. break;
  5166. case ISCSI_BOOT_TGT_PORT:
  5167. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  5168. break;
  5169. case ISCSI_BOOT_TGT_CHAP_NAME:
  5170. rc = sprintf(str, "%.*s\n",
  5171. boot_conn->chap.target_chap_name_length,
  5172. (char *)&boot_conn->chap.target_chap_name);
  5173. break;
  5174. case ISCSI_BOOT_TGT_CHAP_SECRET:
  5175. rc = sprintf(str, "%.*s\n",
  5176. boot_conn->chap.target_secret_length,
  5177. (char *)&boot_conn->chap.target_secret);
  5178. break;
  5179. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  5180. rc = sprintf(str, "%.*s\n",
  5181. boot_conn->chap.intr_chap_name_length,
  5182. (char *)&boot_conn->chap.intr_chap_name);
  5183. break;
  5184. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  5185. rc = sprintf(str, "%.*s\n",
  5186. boot_conn->chap.intr_secret_length,
  5187. (char *)&boot_conn->chap.intr_secret);
  5188. break;
  5189. case ISCSI_BOOT_TGT_FLAGS:
  5190. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  5191. break;
  5192. case ISCSI_BOOT_TGT_NIC_ASSOC:
  5193. rc = sprintf(str, "0\n");
  5194. break;
  5195. default:
  5196. rc = -ENOSYS;
  5197. break;
  5198. }
  5199. return rc;
  5200. }
  5201. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  5202. {
  5203. struct scsi_qla_host *ha = data;
  5204. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  5205. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  5206. }
  5207. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  5208. {
  5209. struct scsi_qla_host *ha = data;
  5210. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  5211. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  5212. }
  5213. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  5214. {
  5215. int rc;
  5216. switch (type) {
  5217. case ISCSI_BOOT_TGT_NAME:
  5218. case ISCSI_BOOT_TGT_IP_ADDR:
  5219. case ISCSI_BOOT_TGT_PORT:
  5220. case ISCSI_BOOT_TGT_CHAP_NAME:
  5221. case ISCSI_BOOT_TGT_CHAP_SECRET:
  5222. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  5223. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  5224. case ISCSI_BOOT_TGT_NIC_ASSOC:
  5225. case ISCSI_BOOT_TGT_FLAGS:
  5226. rc = S_IRUGO;
  5227. break;
  5228. default:
  5229. rc = 0;
  5230. break;
  5231. }
  5232. return rc;
  5233. }
  5234. static void qla4xxx_boot_release(void *data)
  5235. {
  5236. struct scsi_qla_host *ha = data;
  5237. scsi_host_put(ha->host);
  5238. }
  5239. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  5240. {
  5241. dma_addr_t buf_dma;
  5242. uint32_t addr, pri_addr, sec_addr;
  5243. uint32_t offset;
  5244. uint16_t func_num;
  5245. uint8_t val;
  5246. uint8_t *buf = NULL;
  5247. size_t size = 13 * sizeof(uint8_t);
  5248. int ret = QLA_SUCCESS;
  5249. func_num = PCI_FUNC(ha->pdev->devfn);
  5250. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  5251. __func__, ha->pdev->device, func_num);
  5252. if (is_qla40XX(ha)) {
  5253. if (func_num == 1) {
  5254. addr = NVRAM_PORT0_BOOT_MODE;
  5255. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  5256. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  5257. } else if (func_num == 3) {
  5258. addr = NVRAM_PORT1_BOOT_MODE;
  5259. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  5260. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  5261. } else {
  5262. ret = QLA_ERROR;
  5263. goto exit_boot_info;
  5264. }
  5265. /* Check Boot Mode */
  5266. val = rd_nvram_byte(ha, addr);
  5267. if (!(val & 0x07)) {
  5268. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  5269. "options : 0x%x\n", __func__, val));
  5270. ret = QLA_ERROR;
  5271. goto exit_boot_info;
  5272. }
  5273. /* get primary valid target index */
  5274. val = rd_nvram_byte(ha, pri_addr);
  5275. if (val & BIT_7)
  5276. ddb_index[0] = (val & 0x7f);
  5277. /* get secondary valid target index */
  5278. val = rd_nvram_byte(ha, sec_addr);
  5279. if (val & BIT_7)
  5280. ddb_index[1] = (val & 0x7f);
  5281. } else if (is_qla80XX(ha)) {
  5282. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  5283. &buf_dma, GFP_KERNEL);
  5284. if (!buf) {
  5285. DEBUG2(ql4_printk(KERN_ERR, ha,
  5286. "%s: Unable to allocate dma buffer\n",
  5287. __func__));
  5288. ret = QLA_ERROR;
  5289. goto exit_boot_info;
  5290. }
  5291. if (ha->port_num == 0)
  5292. offset = BOOT_PARAM_OFFSET_PORT0;
  5293. else if (ha->port_num == 1)
  5294. offset = BOOT_PARAM_OFFSET_PORT1;
  5295. else {
  5296. ret = QLA_ERROR;
  5297. goto exit_boot_info_free;
  5298. }
  5299. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  5300. offset;
  5301. if (qla4xxx_get_flash(ha, buf_dma, addr,
  5302. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  5303. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  5304. " failed\n", ha->host_no, __func__));
  5305. ret = QLA_ERROR;
  5306. goto exit_boot_info_free;
  5307. }
  5308. /* Check Boot Mode */
  5309. if (!(buf[1] & 0x07)) {
  5310. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  5311. " : 0x%x\n", buf[1]));
  5312. ret = QLA_ERROR;
  5313. goto exit_boot_info_free;
  5314. }
  5315. /* get primary valid target index */
  5316. if (buf[2] & BIT_7)
  5317. ddb_index[0] = buf[2] & 0x7f;
  5318. /* get secondary valid target index */
  5319. if (buf[11] & BIT_7)
  5320. ddb_index[1] = buf[11] & 0x7f;
  5321. } else {
  5322. ret = QLA_ERROR;
  5323. goto exit_boot_info;
  5324. }
  5325. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  5326. " target ID %d\n", __func__, ddb_index[0],
  5327. ddb_index[1]));
  5328. exit_boot_info_free:
  5329. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  5330. exit_boot_info:
  5331. ha->pri_ddb_idx = ddb_index[0];
  5332. ha->sec_ddb_idx = ddb_index[1];
  5333. return ret;
  5334. }
  5335. /**
  5336. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  5337. * @ha: pointer to adapter structure
  5338. * @username: CHAP username to be returned
  5339. * @password: CHAP password to be returned
  5340. *
  5341. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  5342. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  5343. * So from the CHAP cache find the first BIDI CHAP entry and set it
  5344. * to the boot record in sysfs.
  5345. **/
  5346. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  5347. char *password)
  5348. {
  5349. int i, ret = -EINVAL;
  5350. int max_chap_entries = 0;
  5351. struct ql4_chap_table *chap_table;
  5352. if (is_qla80XX(ha))
  5353. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  5354. sizeof(struct ql4_chap_table);
  5355. else
  5356. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  5357. if (!ha->chap_list) {
  5358. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  5359. return ret;
  5360. }
  5361. mutex_lock(&ha->chap_sem);
  5362. for (i = 0; i < max_chap_entries; i++) {
  5363. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  5364. if (chap_table->cookie !=
  5365. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  5366. continue;
  5367. }
  5368. if (chap_table->flags & BIT_7) /* local */
  5369. continue;
  5370. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  5371. continue;
  5372. strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  5373. strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  5374. ret = 0;
  5375. break;
  5376. }
  5377. mutex_unlock(&ha->chap_sem);
  5378. return ret;
  5379. }
  5380. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  5381. struct ql4_boot_session_info *boot_sess,
  5382. uint16_t ddb_index)
  5383. {
  5384. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  5385. struct dev_db_entry *fw_ddb_entry;
  5386. dma_addr_t fw_ddb_entry_dma;
  5387. uint16_t idx;
  5388. uint16_t options;
  5389. int ret = QLA_SUCCESS;
  5390. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5391. &fw_ddb_entry_dma, GFP_KERNEL);
  5392. if (!fw_ddb_entry) {
  5393. DEBUG2(ql4_printk(KERN_ERR, ha,
  5394. "%s: Unable to allocate dma buffer.\n",
  5395. __func__));
  5396. ret = QLA_ERROR;
  5397. return ret;
  5398. }
  5399. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  5400. fw_ddb_entry_dma, ddb_index)) {
  5401. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  5402. "index [%d]\n", __func__, ddb_index));
  5403. ret = QLA_ERROR;
  5404. goto exit_boot_target;
  5405. }
  5406. /* Update target name and IP from DDB */
  5407. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  5408. min(sizeof(boot_sess->target_name),
  5409. sizeof(fw_ddb_entry->iscsi_name)));
  5410. options = le16_to_cpu(fw_ddb_entry->options);
  5411. if (options & DDB_OPT_IPV6_DEVICE) {
  5412. memcpy(&boot_conn->dest_ipaddr.ip_address,
  5413. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  5414. } else {
  5415. boot_conn->dest_ipaddr.ip_type = 0x1;
  5416. memcpy(&boot_conn->dest_ipaddr.ip_address,
  5417. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  5418. }
  5419. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  5420. /* update chap information */
  5421. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  5422. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  5423. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  5424. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  5425. target_chap_name,
  5426. (char *)&boot_conn->chap.target_secret,
  5427. idx);
  5428. if (ret) {
  5429. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  5430. ret = QLA_ERROR;
  5431. goto exit_boot_target;
  5432. }
  5433. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  5434. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  5435. }
  5436. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  5437. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  5438. ret = qla4xxx_get_bidi_chap(ha,
  5439. (char *)&boot_conn->chap.intr_chap_name,
  5440. (char *)&boot_conn->chap.intr_secret);
  5441. if (ret) {
  5442. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  5443. ret = QLA_ERROR;
  5444. goto exit_boot_target;
  5445. }
  5446. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  5447. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  5448. }
  5449. exit_boot_target:
  5450. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5451. fw_ddb_entry, fw_ddb_entry_dma);
  5452. return ret;
  5453. }
  5454. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  5455. {
  5456. uint16_t ddb_index[2];
  5457. int ret = QLA_ERROR;
  5458. int rval;
  5459. memset(ddb_index, 0, sizeof(ddb_index));
  5460. ddb_index[0] = 0xffff;
  5461. ddb_index[1] = 0xffff;
  5462. ret = get_fw_boot_info(ha, ddb_index);
  5463. if (ret != QLA_SUCCESS) {
  5464. DEBUG2(ql4_printk(KERN_INFO, ha,
  5465. "%s: No boot target configured.\n", __func__));
  5466. return ret;
  5467. }
  5468. if (ql4xdisablesysfsboot)
  5469. return QLA_SUCCESS;
  5470. if (ddb_index[0] == 0xffff)
  5471. goto sec_target;
  5472. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  5473. ddb_index[0]);
  5474. if (rval != QLA_SUCCESS) {
  5475. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  5476. "configured\n", __func__));
  5477. } else
  5478. ret = QLA_SUCCESS;
  5479. sec_target:
  5480. if (ddb_index[1] == 0xffff)
  5481. goto exit_get_boot_info;
  5482. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  5483. ddb_index[1]);
  5484. if (rval != QLA_SUCCESS) {
  5485. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  5486. " configured\n", __func__));
  5487. } else
  5488. ret = QLA_SUCCESS;
  5489. exit_get_boot_info:
  5490. return ret;
  5491. }
  5492. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  5493. {
  5494. struct iscsi_boot_kobj *boot_kobj;
  5495. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  5496. return QLA_ERROR;
  5497. if (ql4xdisablesysfsboot) {
  5498. ql4_printk(KERN_INFO, ha,
  5499. "%s: syfsboot disabled - driver will trigger login "
  5500. "and publish session for discovery .\n", __func__);
  5501. return QLA_SUCCESS;
  5502. }
  5503. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  5504. if (!ha->boot_kset)
  5505. goto kset_free;
  5506. if (!scsi_host_get(ha->host))
  5507. goto kset_free;
  5508. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  5509. qla4xxx_show_boot_tgt_pri_info,
  5510. qla4xxx_tgt_get_attr_visibility,
  5511. qla4xxx_boot_release);
  5512. if (!boot_kobj)
  5513. goto put_host;
  5514. if (!scsi_host_get(ha->host))
  5515. goto kset_free;
  5516. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  5517. qla4xxx_show_boot_tgt_sec_info,
  5518. qla4xxx_tgt_get_attr_visibility,
  5519. qla4xxx_boot_release);
  5520. if (!boot_kobj)
  5521. goto put_host;
  5522. if (!scsi_host_get(ha->host))
  5523. goto kset_free;
  5524. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  5525. qla4xxx_show_boot_ini_info,
  5526. qla4xxx_ini_get_attr_visibility,
  5527. qla4xxx_boot_release);
  5528. if (!boot_kobj)
  5529. goto put_host;
  5530. if (!scsi_host_get(ha->host))
  5531. goto kset_free;
  5532. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  5533. qla4xxx_show_boot_eth_info,
  5534. qla4xxx_eth_get_attr_visibility,
  5535. qla4xxx_boot_release);
  5536. if (!boot_kobj)
  5537. goto put_host;
  5538. return QLA_SUCCESS;
  5539. put_host:
  5540. scsi_host_put(ha->host);
  5541. kset_free:
  5542. iscsi_boot_destroy_kset(ha->boot_kset);
  5543. return -ENOMEM;
  5544. }
  5545. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  5546. struct ql4_tuple_ddb *tddb)
  5547. {
  5548. struct scsi_qla_host *ha;
  5549. struct iscsi_cls_session *cls_sess;
  5550. struct iscsi_cls_conn *cls_conn;
  5551. struct iscsi_session *sess;
  5552. struct iscsi_conn *conn;
  5553. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  5554. ha = ddb_entry->ha;
  5555. cls_sess = ddb_entry->sess;
  5556. sess = cls_sess->dd_data;
  5557. cls_conn = ddb_entry->conn;
  5558. conn = cls_conn->dd_data;
  5559. tddb->tpgt = sess->tpgt;
  5560. tddb->port = conn->persistent_port;
  5561. strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  5562. strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  5563. }
  5564. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  5565. struct ql4_tuple_ddb *tddb,
  5566. uint8_t *flash_isid)
  5567. {
  5568. uint16_t options = 0;
  5569. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  5570. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  5571. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  5572. options = le16_to_cpu(fw_ddb_entry->options);
  5573. if (options & DDB_OPT_IPV6_DEVICE)
  5574. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  5575. else
  5576. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  5577. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  5578. if (flash_isid == NULL)
  5579. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  5580. sizeof(tddb->isid));
  5581. else
  5582. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  5583. }
  5584. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  5585. struct ql4_tuple_ddb *old_tddb,
  5586. struct ql4_tuple_ddb *new_tddb,
  5587. uint8_t is_isid_compare)
  5588. {
  5589. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  5590. return QLA_ERROR;
  5591. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  5592. return QLA_ERROR;
  5593. if (old_tddb->port != new_tddb->port)
  5594. return QLA_ERROR;
  5595. /* For multi sessions, driver generates the ISID, so do not compare
  5596. * ISID in reset path since it would be a comparison between the
  5597. * driver generated ISID and firmware generated ISID. This could
  5598. * lead to adding duplicated DDBs in the list as driver generated
  5599. * ISID would not match firmware generated ISID.
  5600. */
  5601. if (is_isid_compare) {
  5602. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  5603. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  5604. __func__, old_tddb->isid[5], old_tddb->isid[4],
  5605. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  5606. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  5607. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  5608. new_tddb->isid[0]));
  5609. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  5610. sizeof(old_tddb->isid)))
  5611. return QLA_ERROR;
  5612. }
  5613. DEBUG2(ql4_printk(KERN_INFO, ha,
  5614. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  5615. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  5616. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  5617. new_tddb->ip_addr, new_tddb->iscsi_name));
  5618. return QLA_SUCCESS;
  5619. }
  5620. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  5621. struct dev_db_entry *fw_ddb_entry,
  5622. uint32_t *index)
  5623. {
  5624. struct ddb_entry *ddb_entry;
  5625. struct ql4_tuple_ddb *fw_tddb = NULL;
  5626. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5627. int idx;
  5628. int ret = QLA_ERROR;
  5629. fw_tddb = vzalloc(sizeof(*fw_tddb));
  5630. if (!fw_tddb) {
  5631. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5632. "Memory Allocation failed.\n"));
  5633. ret = QLA_SUCCESS;
  5634. goto exit_check;
  5635. }
  5636. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5637. if (!tmp_tddb) {
  5638. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5639. "Memory Allocation failed.\n"));
  5640. ret = QLA_SUCCESS;
  5641. goto exit_check;
  5642. }
  5643. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  5644. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  5645. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  5646. if (ddb_entry == NULL)
  5647. continue;
  5648. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  5649. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  5650. ret = QLA_SUCCESS; /* found */
  5651. if (index != NULL)
  5652. *index = idx;
  5653. goto exit_check;
  5654. }
  5655. }
  5656. exit_check:
  5657. if (fw_tddb)
  5658. vfree(fw_tddb);
  5659. if (tmp_tddb)
  5660. vfree(tmp_tddb);
  5661. return ret;
  5662. }
  5663. /**
  5664. * qla4xxx_check_existing_isid - check if target with same isid exist
  5665. * in target list
  5666. * @list_nt: list of target
  5667. * @isid: isid to check
  5668. *
  5669. * This routine return QLA_SUCCESS if target with same isid exist
  5670. **/
  5671. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  5672. {
  5673. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  5674. struct dev_db_entry *fw_ddb_entry;
  5675. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5676. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  5677. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  5678. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  5679. return QLA_SUCCESS;
  5680. }
  5681. }
  5682. return QLA_ERROR;
  5683. }
  5684. /**
  5685. * qla4xxx_update_isid - compare ddbs and updated isid
  5686. * @ha: Pointer to host adapter structure.
  5687. * @list_nt: list of nt target
  5688. * @fw_ddb_entry: firmware ddb entry
  5689. *
  5690. * This routine update isid if ddbs have same iqn, same isid and
  5691. * different IP addr.
  5692. * Return QLA_SUCCESS if isid is updated.
  5693. **/
  5694. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  5695. struct list_head *list_nt,
  5696. struct dev_db_entry *fw_ddb_entry)
  5697. {
  5698. uint8_t base_value, i;
  5699. base_value = fw_ddb_entry->isid[1] & 0x1f;
  5700. for (i = 0; i < 8; i++) {
  5701. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  5702. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  5703. break;
  5704. }
  5705. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  5706. return QLA_ERROR;
  5707. return QLA_SUCCESS;
  5708. }
  5709. /**
  5710. * qla4xxx_should_update_isid - check if isid need to update
  5711. * @ha: Pointer to host adapter structure.
  5712. * @old_tddb: ddb tuple
  5713. * @new_tddb: ddb tuple
  5714. *
  5715. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  5716. * same isid
  5717. **/
  5718. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  5719. struct ql4_tuple_ddb *old_tddb,
  5720. struct ql4_tuple_ddb *new_tddb)
  5721. {
  5722. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  5723. /* Same ip */
  5724. if (old_tddb->port == new_tddb->port)
  5725. return QLA_ERROR;
  5726. }
  5727. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  5728. /* different iqn */
  5729. return QLA_ERROR;
  5730. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  5731. sizeof(old_tddb->isid)))
  5732. /* different isid */
  5733. return QLA_ERROR;
  5734. return QLA_SUCCESS;
  5735. }
  5736. /**
  5737. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  5738. * @ha: Pointer to host adapter structure.
  5739. * @list_nt: list of nt target.
  5740. * @fw_ddb_entry: firmware ddb entry.
  5741. *
  5742. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  5743. * duplicate ddb in list_nt.
  5744. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  5745. * Note: This function also update isid of DDB if required.
  5746. **/
  5747. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  5748. struct list_head *list_nt,
  5749. struct dev_db_entry *fw_ddb_entry)
  5750. {
  5751. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  5752. struct ql4_tuple_ddb *fw_tddb = NULL;
  5753. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5754. int rval, ret = QLA_ERROR;
  5755. fw_tddb = vzalloc(sizeof(*fw_tddb));
  5756. if (!fw_tddb) {
  5757. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5758. "Memory Allocation failed.\n"));
  5759. ret = QLA_SUCCESS;
  5760. goto exit_check;
  5761. }
  5762. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5763. if (!tmp_tddb) {
  5764. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5765. "Memory Allocation failed.\n"));
  5766. ret = QLA_SUCCESS;
  5767. goto exit_check;
  5768. }
  5769. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  5770. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5771. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  5772. nt_ddb_idx->flash_isid);
  5773. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  5774. /* found duplicate ddb */
  5775. if (ret == QLA_SUCCESS)
  5776. goto exit_check;
  5777. }
  5778. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5779. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  5780. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  5781. if (ret == QLA_SUCCESS) {
  5782. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  5783. if (rval == QLA_SUCCESS)
  5784. ret = QLA_ERROR;
  5785. else
  5786. ret = QLA_SUCCESS;
  5787. goto exit_check;
  5788. }
  5789. }
  5790. exit_check:
  5791. if (fw_tddb)
  5792. vfree(fw_tddb);
  5793. if (tmp_tddb)
  5794. vfree(tmp_tddb);
  5795. return ret;
  5796. }
  5797. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  5798. {
  5799. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  5800. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  5801. list_del_init(&ddb_idx->list);
  5802. vfree(ddb_idx);
  5803. }
  5804. }
  5805. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  5806. struct dev_db_entry *fw_ddb_entry)
  5807. {
  5808. struct iscsi_endpoint *ep;
  5809. struct sockaddr_in *addr;
  5810. struct sockaddr_in6 *addr6;
  5811. struct sockaddr *t_addr;
  5812. struct sockaddr_storage *dst_addr;
  5813. char *ip;
  5814. /* TODO: need to destroy on unload iscsi_endpoint*/
  5815. dst_addr = vmalloc(sizeof(*dst_addr));
  5816. if (!dst_addr)
  5817. return NULL;
  5818. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  5819. t_addr = (struct sockaddr *)dst_addr;
  5820. t_addr->sa_family = AF_INET6;
  5821. addr6 = (struct sockaddr_in6 *)dst_addr;
  5822. ip = (char *)&addr6->sin6_addr;
  5823. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  5824. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  5825. } else {
  5826. t_addr = (struct sockaddr *)dst_addr;
  5827. t_addr->sa_family = AF_INET;
  5828. addr = (struct sockaddr_in *)dst_addr;
  5829. ip = (char *)&addr->sin_addr;
  5830. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  5831. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  5832. }
  5833. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  5834. vfree(dst_addr);
  5835. return ep;
  5836. }
  5837. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  5838. {
  5839. if (ql4xdisablesysfsboot)
  5840. return QLA_SUCCESS;
  5841. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  5842. return QLA_ERROR;
  5843. return QLA_SUCCESS;
  5844. }
  5845. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  5846. struct ddb_entry *ddb_entry,
  5847. uint16_t idx)
  5848. {
  5849. uint16_t def_timeout;
  5850. ddb_entry->ddb_type = FLASH_DDB;
  5851. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  5852. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  5853. ddb_entry->ha = ha;
  5854. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  5855. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  5856. ddb_entry->chap_tbl_idx = INVALID_ENTRY;
  5857. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  5858. atomic_set(&ddb_entry->relogin_timer, 0);
  5859. atomic_set(&ddb_entry->relogin_retry_count, 0);
  5860. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  5861. ddb_entry->default_relogin_timeout =
  5862. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  5863. def_timeout : LOGIN_TOV;
  5864. ddb_entry->default_time2wait =
  5865. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  5866. if (ql4xdisablesysfsboot &&
  5867. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  5868. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  5869. }
  5870. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  5871. {
  5872. uint32_t idx = 0;
  5873. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  5874. uint32_t sts[MBOX_REG_COUNT];
  5875. uint32_t ip_state;
  5876. unsigned long wtime;
  5877. int ret;
  5878. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  5879. do {
  5880. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  5881. if (ip_idx[idx] == -1)
  5882. continue;
  5883. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  5884. if (ret == QLA_ERROR) {
  5885. ip_idx[idx] = -1;
  5886. continue;
  5887. }
  5888. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  5889. DEBUG2(ql4_printk(KERN_INFO, ha,
  5890. "Waiting for IP state for idx = %d, state = 0x%x\n",
  5891. ip_idx[idx], ip_state));
  5892. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  5893. ip_state == IP_ADDRSTATE_INVALID ||
  5894. ip_state == IP_ADDRSTATE_PREFERRED ||
  5895. ip_state == IP_ADDRSTATE_DEPRICATED ||
  5896. ip_state == IP_ADDRSTATE_DISABLING)
  5897. ip_idx[idx] = -1;
  5898. }
  5899. /* Break if all IP states checked */
  5900. if ((ip_idx[0] == -1) &&
  5901. (ip_idx[1] == -1) &&
  5902. (ip_idx[2] == -1) &&
  5903. (ip_idx[3] == -1))
  5904. break;
  5905. schedule_timeout_uninterruptible(HZ);
  5906. } while (time_after(wtime, jiffies));
  5907. }
  5908. static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
  5909. struct dev_db_entry *flash_ddb_entry)
  5910. {
  5911. uint16_t options = 0;
  5912. size_t ip_len = IP_ADDR_LEN;
  5913. options = le16_to_cpu(fw_ddb_entry->options);
  5914. if (options & DDB_OPT_IPV6_DEVICE)
  5915. ip_len = IPv6_ADDR_LEN;
  5916. if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
  5917. return QLA_ERROR;
  5918. if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
  5919. sizeof(fw_ddb_entry->isid)))
  5920. return QLA_ERROR;
  5921. if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
  5922. sizeof(fw_ddb_entry->port)))
  5923. return QLA_ERROR;
  5924. return QLA_SUCCESS;
  5925. }
  5926. static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
  5927. struct dev_db_entry *fw_ddb_entry,
  5928. uint32_t fw_idx, uint32_t *flash_index)
  5929. {
  5930. struct dev_db_entry *flash_ddb_entry;
  5931. dma_addr_t flash_ddb_entry_dma;
  5932. uint32_t idx = 0;
  5933. int max_ddbs;
  5934. int ret = QLA_ERROR, status;
  5935. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  5936. MAX_DEV_DB_ENTRIES;
  5937. flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5938. &flash_ddb_entry_dma);
  5939. if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
  5940. ql4_printk(KERN_ERR, ha, "Out of memory\n");
  5941. goto exit_find_st_idx;
  5942. }
  5943. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  5944. flash_ddb_entry_dma, fw_idx);
  5945. if (status == QLA_SUCCESS) {
  5946. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  5947. if (status == QLA_SUCCESS) {
  5948. *flash_index = fw_idx;
  5949. ret = QLA_SUCCESS;
  5950. goto exit_find_st_idx;
  5951. }
  5952. }
  5953. for (idx = 0; idx < max_ddbs; idx++) {
  5954. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  5955. flash_ddb_entry_dma, idx);
  5956. if (status == QLA_ERROR)
  5957. continue;
  5958. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  5959. if (status == QLA_SUCCESS) {
  5960. *flash_index = idx;
  5961. ret = QLA_SUCCESS;
  5962. goto exit_find_st_idx;
  5963. }
  5964. }
  5965. if (idx == max_ddbs)
  5966. ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
  5967. fw_idx);
  5968. exit_find_st_idx:
  5969. if (flash_ddb_entry)
  5970. dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
  5971. flash_ddb_entry_dma);
  5972. return ret;
  5973. }
  5974. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  5975. struct list_head *list_st)
  5976. {
  5977. struct qla_ddb_index *st_ddb_idx;
  5978. int max_ddbs;
  5979. int fw_idx_size;
  5980. struct dev_db_entry *fw_ddb_entry;
  5981. dma_addr_t fw_ddb_dma;
  5982. int ret;
  5983. uint32_t idx = 0, next_idx = 0;
  5984. uint32_t state = 0, conn_err = 0;
  5985. uint32_t flash_index = -1;
  5986. uint16_t conn_id = 0;
  5987. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5988. &fw_ddb_dma);
  5989. if (fw_ddb_entry == NULL) {
  5990. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  5991. goto exit_st_list;
  5992. }
  5993. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  5994. MAX_DEV_DB_ENTRIES;
  5995. fw_idx_size = sizeof(struct qla_ddb_index);
  5996. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  5997. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  5998. NULL, &next_idx, &state,
  5999. &conn_err, NULL, &conn_id);
  6000. if (ret == QLA_ERROR)
  6001. break;
  6002. /* Ignore DDB if invalid state (unassigned) */
  6003. if (state == DDB_DS_UNASSIGNED)
  6004. goto continue_next_st;
  6005. /* Check if ST, add to the list_st */
  6006. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  6007. goto continue_next_st;
  6008. st_ddb_idx = vzalloc(fw_idx_size);
  6009. if (!st_ddb_idx)
  6010. break;
  6011. ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
  6012. &flash_index);
  6013. if (ret == QLA_ERROR) {
  6014. ql4_printk(KERN_ERR, ha,
  6015. "No flash entry for ST at idx [%d]\n", idx);
  6016. st_ddb_idx->flash_ddb_idx = idx;
  6017. } else {
  6018. ql4_printk(KERN_INFO, ha,
  6019. "ST at idx [%d] is stored at flash [%d]\n",
  6020. idx, flash_index);
  6021. st_ddb_idx->flash_ddb_idx = flash_index;
  6022. }
  6023. st_ddb_idx->fw_ddb_idx = idx;
  6024. list_add_tail(&st_ddb_idx->list, list_st);
  6025. continue_next_st:
  6026. if (next_idx == 0)
  6027. break;
  6028. }
  6029. exit_st_list:
  6030. if (fw_ddb_entry)
  6031. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6032. }
  6033. /**
  6034. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  6035. * @ha: pointer to adapter structure
  6036. * @list_ddb: List from which failed ddb to be removed
  6037. *
  6038. * Iterate over the list of DDBs and find and remove DDBs that are either in
  6039. * no connection active state or failed state
  6040. **/
  6041. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  6042. struct list_head *list_ddb)
  6043. {
  6044. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6045. uint32_t next_idx = 0;
  6046. uint32_t state = 0, conn_err = 0;
  6047. int ret;
  6048. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  6049. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  6050. NULL, 0, NULL, &next_idx, &state,
  6051. &conn_err, NULL, NULL);
  6052. if (ret == QLA_ERROR)
  6053. continue;
  6054. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6055. state == DDB_DS_SESSION_FAILED) {
  6056. list_del_init(&ddb_idx->list);
  6057. vfree(ddb_idx);
  6058. }
  6059. }
  6060. }
  6061. static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
  6062. struct ddb_entry *ddb_entry,
  6063. struct dev_db_entry *fw_ddb_entry)
  6064. {
  6065. struct iscsi_cls_session *cls_sess;
  6066. struct iscsi_session *sess;
  6067. uint32_t max_ddbs = 0;
  6068. uint16_t ddb_link = -1;
  6069. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6070. MAX_DEV_DB_ENTRIES;
  6071. cls_sess = ddb_entry->sess;
  6072. sess = cls_sess->dd_data;
  6073. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6074. if (ddb_link < max_ddbs)
  6075. sess->discovery_parent_idx = ddb_link;
  6076. else
  6077. sess->discovery_parent_idx = DDB_NO_LINK;
  6078. }
  6079. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  6080. struct dev_db_entry *fw_ddb_entry,
  6081. int is_reset, uint16_t idx)
  6082. {
  6083. struct iscsi_cls_session *cls_sess;
  6084. struct iscsi_session *sess;
  6085. struct iscsi_cls_conn *cls_conn;
  6086. struct iscsi_endpoint *ep;
  6087. uint16_t cmds_max = 32;
  6088. uint16_t conn_id = 0;
  6089. uint32_t initial_cmdsn = 0;
  6090. int ret = QLA_SUCCESS;
  6091. struct ddb_entry *ddb_entry = NULL;
  6092. /* Create session object, with INVALID_ENTRY,
  6093. * the targer_id would get set when we issue the login
  6094. */
  6095. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  6096. cmds_max, sizeof(struct ddb_entry),
  6097. sizeof(struct ql4_task_data),
  6098. initial_cmdsn, INVALID_ENTRY);
  6099. if (!cls_sess) {
  6100. ret = QLA_ERROR;
  6101. goto exit_setup;
  6102. }
  6103. /*
  6104. * so calling module_put function to decrement the
  6105. * reference count.
  6106. **/
  6107. module_put(qla4xxx_iscsi_transport.owner);
  6108. sess = cls_sess->dd_data;
  6109. ddb_entry = sess->dd_data;
  6110. ddb_entry->sess = cls_sess;
  6111. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  6112. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  6113. sizeof(struct dev_db_entry));
  6114. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  6115. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  6116. if (!cls_conn) {
  6117. ret = QLA_ERROR;
  6118. goto exit_setup;
  6119. }
  6120. ddb_entry->conn = cls_conn;
  6121. /* Setup ep, for displaying attributes in sysfs */
  6122. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  6123. if (ep) {
  6124. ep->conn = cls_conn;
  6125. cls_conn->ep = ep;
  6126. } else {
  6127. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  6128. ret = QLA_ERROR;
  6129. goto exit_setup;
  6130. }
  6131. /* Update sess/conn params */
  6132. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  6133. qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
  6134. if (is_reset == RESET_ADAPTER) {
  6135. iscsi_block_session(cls_sess);
  6136. /* Use the relogin path to discover new devices
  6137. * by short-circuting the logic of setting
  6138. * timer to relogin - instead set the flags
  6139. * to initiate login right away.
  6140. */
  6141. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  6142. set_bit(DF_RELOGIN, &ddb_entry->flags);
  6143. }
  6144. exit_setup:
  6145. return ret;
  6146. }
  6147. static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
  6148. struct list_head *list_ddb,
  6149. struct dev_db_entry *fw_ddb_entry)
  6150. {
  6151. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6152. uint16_t ddb_link;
  6153. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6154. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  6155. if (ddb_idx->fw_ddb_idx == ddb_link) {
  6156. DEBUG2(ql4_printk(KERN_INFO, ha,
  6157. "Updating NT parent idx from [%d] to [%d]\n",
  6158. ddb_link, ddb_idx->flash_ddb_idx));
  6159. fw_ddb_entry->ddb_link =
  6160. cpu_to_le16(ddb_idx->flash_ddb_idx);
  6161. return;
  6162. }
  6163. }
  6164. }
  6165. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  6166. struct list_head *list_nt,
  6167. struct list_head *list_st,
  6168. int is_reset)
  6169. {
  6170. struct dev_db_entry *fw_ddb_entry;
  6171. struct ddb_entry *ddb_entry = NULL;
  6172. dma_addr_t fw_ddb_dma;
  6173. int max_ddbs;
  6174. int fw_idx_size;
  6175. int ret;
  6176. uint32_t idx = 0, next_idx = 0;
  6177. uint32_t state = 0, conn_err = 0;
  6178. uint32_t ddb_idx = -1;
  6179. uint16_t conn_id = 0;
  6180. uint16_t ddb_link = -1;
  6181. struct qla_ddb_index *nt_ddb_idx;
  6182. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6183. &fw_ddb_dma);
  6184. if (fw_ddb_entry == NULL) {
  6185. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  6186. goto exit_nt_list;
  6187. }
  6188. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6189. MAX_DEV_DB_ENTRIES;
  6190. fw_idx_size = sizeof(struct qla_ddb_index);
  6191. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  6192. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  6193. NULL, &next_idx, &state,
  6194. &conn_err, NULL, &conn_id);
  6195. if (ret == QLA_ERROR)
  6196. break;
  6197. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  6198. goto continue_next_nt;
  6199. /* Check if NT, then add to list it */
  6200. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  6201. goto continue_next_nt;
  6202. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6203. if (ddb_link < max_ddbs)
  6204. qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
  6205. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6206. state == DDB_DS_SESSION_FAILED) &&
  6207. (is_reset == INIT_ADAPTER))
  6208. goto continue_next_nt;
  6209. DEBUG2(ql4_printk(KERN_INFO, ha,
  6210. "Adding DDB to session = 0x%x\n", idx));
  6211. if (is_reset == INIT_ADAPTER) {
  6212. nt_ddb_idx = vmalloc(fw_idx_size);
  6213. if (!nt_ddb_idx)
  6214. break;
  6215. nt_ddb_idx->fw_ddb_idx = idx;
  6216. /* Copy original isid as it may get updated in function
  6217. * qla4xxx_update_isid(). We need original isid in
  6218. * function qla4xxx_compare_tuple_ddb to find duplicate
  6219. * target */
  6220. memcpy(&nt_ddb_idx->flash_isid[0],
  6221. &fw_ddb_entry->isid[0],
  6222. sizeof(nt_ddb_idx->flash_isid));
  6223. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  6224. fw_ddb_entry);
  6225. if (ret == QLA_SUCCESS) {
  6226. /* free nt_ddb_idx and do not add to list_nt */
  6227. vfree(nt_ddb_idx);
  6228. goto continue_next_nt;
  6229. }
  6230. /* Copy updated isid */
  6231. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  6232. sizeof(struct dev_db_entry));
  6233. list_add_tail(&nt_ddb_idx->list, list_nt);
  6234. } else if (is_reset == RESET_ADAPTER) {
  6235. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
  6236. &ddb_idx);
  6237. if (ret == QLA_SUCCESS) {
  6238. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
  6239. ddb_idx);
  6240. if (ddb_entry != NULL)
  6241. qla4xxx_update_sess_disc_idx(ha,
  6242. ddb_entry,
  6243. fw_ddb_entry);
  6244. goto continue_next_nt;
  6245. }
  6246. }
  6247. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  6248. if (ret == QLA_ERROR)
  6249. goto exit_nt_list;
  6250. continue_next_nt:
  6251. if (next_idx == 0)
  6252. break;
  6253. }
  6254. exit_nt_list:
  6255. if (fw_ddb_entry)
  6256. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6257. }
  6258. static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  6259. struct list_head *list_nt,
  6260. uint16_t target_id)
  6261. {
  6262. struct dev_db_entry *fw_ddb_entry;
  6263. dma_addr_t fw_ddb_dma;
  6264. int max_ddbs;
  6265. int fw_idx_size;
  6266. int ret;
  6267. uint32_t idx = 0, next_idx = 0;
  6268. uint32_t state = 0, conn_err = 0;
  6269. uint16_t conn_id = 0;
  6270. struct qla_ddb_index *nt_ddb_idx;
  6271. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6272. &fw_ddb_dma);
  6273. if (fw_ddb_entry == NULL) {
  6274. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  6275. goto exit_new_nt_list;
  6276. }
  6277. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6278. MAX_DEV_DB_ENTRIES;
  6279. fw_idx_size = sizeof(struct qla_ddb_index);
  6280. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  6281. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  6282. NULL, &next_idx, &state,
  6283. &conn_err, NULL, &conn_id);
  6284. if (ret == QLA_ERROR)
  6285. break;
  6286. /* Check if NT, then add it to list */
  6287. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  6288. goto continue_next_new_nt;
  6289. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
  6290. goto continue_next_new_nt;
  6291. DEBUG2(ql4_printk(KERN_INFO, ha,
  6292. "Adding DDB to session = 0x%x\n", idx));
  6293. nt_ddb_idx = vmalloc(fw_idx_size);
  6294. if (!nt_ddb_idx)
  6295. break;
  6296. nt_ddb_idx->fw_ddb_idx = idx;
  6297. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  6298. if (ret == QLA_SUCCESS) {
  6299. /* free nt_ddb_idx and do not add to list_nt */
  6300. vfree(nt_ddb_idx);
  6301. goto continue_next_new_nt;
  6302. }
  6303. if (target_id < max_ddbs)
  6304. fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
  6305. list_add_tail(&nt_ddb_idx->list, list_nt);
  6306. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  6307. idx);
  6308. if (ret == QLA_ERROR)
  6309. goto exit_new_nt_list;
  6310. continue_next_new_nt:
  6311. if (next_idx == 0)
  6312. break;
  6313. }
  6314. exit_new_nt_list:
  6315. if (fw_ddb_entry)
  6316. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6317. }
  6318. /**
  6319. * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
  6320. * @dev: dev associated with the sysfs entry
  6321. * @data: pointer to flashnode session object
  6322. *
  6323. * Returns:
  6324. * 1: if flashnode entry is non-persistent
  6325. * 0: if flashnode entry is persistent
  6326. **/
  6327. static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
  6328. {
  6329. struct iscsi_bus_flash_session *fnode_sess;
  6330. if (!iscsi_flashnode_bus_match(dev, NULL))
  6331. return 0;
  6332. fnode_sess = iscsi_dev_to_flash_session(dev);
  6333. return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
  6334. }
  6335. /**
  6336. * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
  6337. * @ha: pointer to host
  6338. * @fw_ddb_entry: flash ddb data
  6339. * @idx: target index
  6340. * @user: if set then this call is made from userland else from kernel
  6341. *
  6342. * Returns:
  6343. * On sucess: QLA_SUCCESS
  6344. * On failure: QLA_ERROR
  6345. *
  6346. * This create separate sysfs entries for session and connection attributes of
  6347. * the given fw ddb entry.
  6348. * If this is invoked as a result of a userspace call then the entry is marked
  6349. * as nonpersistent using flash_state field.
  6350. **/
  6351. static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
  6352. struct dev_db_entry *fw_ddb_entry,
  6353. uint16_t *idx, int user)
  6354. {
  6355. struct iscsi_bus_flash_session *fnode_sess = NULL;
  6356. struct iscsi_bus_flash_conn *fnode_conn = NULL;
  6357. int rc = QLA_ERROR;
  6358. fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
  6359. &qla4xxx_iscsi_transport, 0);
  6360. if (!fnode_sess) {
  6361. ql4_printk(KERN_ERR, ha,
  6362. "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
  6363. __func__, *idx, ha->host_no);
  6364. goto exit_tgt_create;
  6365. }
  6366. fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
  6367. &qla4xxx_iscsi_transport, 0);
  6368. if (!fnode_conn) {
  6369. ql4_printk(KERN_ERR, ha,
  6370. "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
  6371. __func__, *idx, ha->host_no);
  6372. goto free_sess;
  6373. }
  6374. if (user) {
  6375. fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
  6376. } else {
  6377. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  6378. if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
  6379. fnode_sess->is_boot_target = 1;
  6380. else
  6381. fnode_sess->is_boot_target = 0;
  6382. }
  6383. rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
  6384. fw_ddb_entry);
  6385. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  6386. __func__, fnode_sess->dev.kobj.name);
  6387. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  6388. __func__, fnode_conn->dev.kobj.name);
  6389. return QLA_SUCCESS;
  6390. free_sess:
  6391. iscsi_destroy_flashnode_sess(fnode_sess);
  6392. exit_tgt_create:
  6393. return QLA_ERROR;
  6394. }
  6395. /**
  6396. * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
  6397. * @shost: pointer to host
  6398. * @buf: type of ddb entry (ipv4/ipv6)
  6399. * @len: length of buf
  6400. *
  6401. * This creates new ddb entry in the flash by finding first free index and
  6402. * storing default ddb there. And then create sysfs entry for the new ddb entry.
  6403. **/
  6404. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  6405. int len)
  6406. {
  6407. struct scsi_qla_host *ha = to_qla_host(shost);
  6408. struct dev_db_entry *fw_ddb_entry = NULL;
  6409. dma_addr_t fw_ddb_entry_dma;
  6410. struct device *dev;
  6411. uint16_t idx = 0;
  6412. uint16_t max_ddbs = 0;
  6413. uint32_t options = 0;
  6414. uint32_t rval = QLA_ERROR;
  6415. if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
  6416. strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
  6417. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
  6418. __func__));
  6419. goto exit_ddb_add;
  6420. }
  6421. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  6422. MAX_DEV_DB_ENTRIES;
  6423. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6424. &fw_ddb_entry_dma, GFP_KERNEL);
  6425. if (!fw_ddb_entry) {
  6426. DEBUG2(ql4_printk(KERN_ERR, ha,
  6427. "%s: Unable to allocate dma buffer\n",
  6428. __func__));
  6429. goto exit_ddb_add;
  6430. }
  6431. dev = iscsi_find_flashnode_sess(ha->host, NULL,
  6432. qla4xxx_sysfs_ddb_is_non_persistent);
  6433. if (dev) {
  6434. ql4_printk(KERN_ERR, ha,
  6435. "%s: A non-persistent entry %s found\n",
  6436. __func__, dev->kobj.name);
  6437. put_device(dev);
  6438. goto exit_ddb_add;
  6439. }
  6440. /* Index 0 and 1 are reserved for boot target entries */
  6441. for (idx = 2; idx < max_ddbs; idx++) {
  6442. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
  6443. fw_ddb_entry_dma, idx))
  6444. break;
  6445. }
  6446. if (idx == max_ddbs)
  6447. goto exit_ddb_add;
  6448. if (!strncasecmp("ipv6", buf, 4))
  6449. options |= IPV6_DEFAULT_DDB_ENTRY;
  6450. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6451. if (rval == QLA_ERROR)
  6452. goto exit_ddb_add;
  6453. rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
  6454. exit_ddb_add:
  6455. if (fw_ddb_entry)
  6456. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6457. fw_ddb_entry, fw_ddb_entry_dma);
  6458. if (rval == QLA_SUCCESS)
  6459. return idx;
  6460. else
  6461. return -EIO;
  6462. }
  6463. /**
  6464. * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
  6465. * @fnode_sess: pointer to session attrs of flash ddb entry
  6466. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6467. *
  6468. * This writes the contents of target ddb buffer to Flash with a valid cookie
  6469. * value in order to make the ddb entry persistent.
  6470. **/
  6471. static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
  6472. struct iscsi_bus_flash_conn *fnode_conn)
  6473. {
  6474. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6475. struct scsi_qla_host *ha = to_qla_host(shost);
  6476. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  6477. struct dev_db_entry *fw_ddb_entry = NULL;
  6478. dma_addr_t fw_ddb_entry_dma;
  6479. uint32_t options = 0;
  6480. int rval = 0;
  6481. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6482. &fw_ddb_entry_dma, GFP_KERNEL);
  6483. if (!fw_ddb_entry) {
  6484. DEBUG2(ql4_printk(KERN_ERR, ha,
  6485. "%s: Unable to allocate dma buffer\n",
  6486. __func__));
  6487. rval = -ENOMEM;
  6488. goto exit_ddb_apply;
  6489. }
  6490. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6491. options |= IPV6_DEFAULT_DDB_ENTRY;
  6492. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6493. if (rval == QLA_ERROR)
  6494. goto exit_ddb_apply;
  6495. dev_db_start_offset += (fnode_sess->target_id *
  6496. sizeof(*fw_ddb_entry));
  6497. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  6498. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  6499. rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  6500. sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
  6501. if (rval == QLA_SUCCESS) {
  6502. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  6503. ql4_printk(KERN_INFO, ha,
  6504. "%s: flash node %u of host %lu written to flash\n",
  6505. __func__, fnode_sess->target_id, ha->host_no);
  6506. } else {
  6507. rval = -EIO;
  6508. ql4_printk(KERN_ERR, ha,
  6509. "%s: Error while writing flash node %u of host %lu to flash\n",
  6510. __func__, fnode_sess->target_id, ha->host_no);
  6511. }
  6512. exit_ddb_apply:
  6513. if (fw_ddb_entry)
  6514. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6515. fw_ddb_entry, fw_ddb_entry_dma);
  6516. return rval;
  6517. }
  6518. static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
  6519. struct dev_db_entry *fw_ddb_entry,
  6520. uint16_t idx)
  6521. {
  6522. struct dev_db_entry *ddb_entry = NULL;
  6523. dma_addr_t ddb_entry_dma;
  6524. unsigned long wtime;
  6525. uint32_t mbx_sts = 0;
  6526. uint32_t state = 0, conn_err = 0;
  6527. uint16_t tmo = 0;
  6528. int ret = 0;
  6529. ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  6530. &ddb_entry_dma, GFP_KERNEL);
  6531. if (!ddb_entry) {
  6532. DEBUG2(ql4_printk(KERN_ERR, ha,
  6533. "%s: Unable to allocate dma buffer\n",
  6534. __func__));
  6535. return QLA_ERROR;
  6536. }
  6537. memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
  6538. ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
  6539. if (ret != QLA_SUCCESS) {
  6540. DEBUG2(ql4_printk(KERN_ERR, ha,
  6541. "%s: Unable to set ddb entry for index %d\n",
  6542. __func__, idx));
  6543. goto exit_ddb_conn_open;
  6544. }
  6545. qla4xxx_conn_open(ha, idx);
  6546. /* To ensure that sendtargets is done, wait for at least 12 secs */
  6547. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  6548. (ha->def_timeout < LOGIN_TOV * 10) ?
  6549. ha->def_timeout : LOGIN_TOV);
  6550. DEBUG2(ql4_printk(KERN_INFO, ha,
  6551. "Default time to wait for login to ddb %d\n", tmo));
  6552. wtime = jiffies + (HZ * tmo);
  6553. do {
  6554. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  6555. NULL, &state, &conn_err, NULL,
  6556. NULL);
  6557. if (ret == QLA_ERROR)
  6558. continue;
  6559. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6560. state == DDB_DS_SESSION_FAILED)
  6561. break;
  6562. schedule_timeout_uninterruptible(HZ / 10);
  6563. } while (time_after(wtime, jiffies));
  6564. exit_ddb_conn_open:
  6565. if (ddb_entry)
  6566. dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  6567. ddb_entry, ddb_entry_dma);
  6568. return ret;
  6569. }
  6570. static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
  6571. struct dev_db_entry *fw_ddb_entry,
  6572. uint16_t target_id)
  6573. {
  6574. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6575. struct list_head list_nt;
  6576. uint16_t ddb_index;
  6577. int ret = 0;
  6578. if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
  6579. ql4_printk(KERN_WARNING, ha,
  6580. "%s: A discovery already in progress!\n", __func__);
  6581. return QLA_ERROR;
  6582. }
  6583. INIT_LIST_HEAD(&list_nt);
  6584. set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  6585. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  6586. if (ret == QLA_ERROR)
  6587. goto exit_login_st_clr_bit;
  6588. ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
  6589. if (ret == QLA_ERROR)
  6590. goto exit_login_st;
  6591. qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
  6592. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
  6593. list_del_init(&ddb_idx->list);
  6594. qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
  6595. vfree(ddb_idx);
  6596. }
  6597. exit_login_st:
  6598. if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
  6599. ql4_printk(KERN_ERR, ha,
  6600. "Unable to clear DDB index = 0x%x\n", ddb_index);
  6601. }
  6602. clear_bit(ddb_index, ha->ddb_idx_map);
  6603. exit_login_st_clr_bit:
  6604. clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  6605. return ret;
  6606. }
  6607. static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
  6608. struct dev_db_entry *fw_ddb_entry,
  6609. uint16_t idx)
  6610. {
  6611. int ret = QLA_ERROR;
  6612. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  6613. if (ret != QLA_SUCCESS)
  6614. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  6615. idx);
  6616. else
  6617. ret = -EPERM;
  6618. return ret;
  6619. }
  6620. /**
  6621. * qla4xxx_sysfs_ddb_login - Login to the specified target
  6622. * @fnode_sess: pointer to session attrs of flash ddb entry
  6623. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6624. *
  6625. * This logs in to the specified target
  6626. **/
  6627. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  6628. struct iscsi_bus_flash_conn *fnode_conn)
  6629. {
  6630. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6631. struct scsi_qla_host *ha = to_qla_host(shost);
  6632. struct dev_db_entry *fw_ddb_entry = NULL;
  6633. dma_addr_t fw_ddb_entry_dma;
  6634. uint32_t options = 0;
  6635. int ret = 0;
  6636. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
  6637. ql4_printk(KERN_ERR, ha,
  6638. "%s: Target info is not persistent\n", __func__);
  6639. ret = -EIO;
  6640. goto exit_ddb_login;
  6641. }
  6642. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6643. &fw_ddb_entry_dma, GFP_KERNEL);
  6644. if (!fw_ddb_entry) {
  6645. DEBUG2(ql4_printk(KERN_ERR, ha,
  6646. "%s: Unable to allocate dma buffer\n",
  6647. __func__));
  6648. ret = -ENOMEM;
  6649. goto exit_ddb_login;
  6650. }
  6651. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6652. options |= IPV6_DEFAULT_DDB_ENTRY;
  6653. ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6654. if (ret == QLA_ERROR)
  6655. goto exit_ddb_login;
  6656. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  6657. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  6658. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  6659. ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
  6660. fnode_sess->target_id);
  6661. else
  6662. ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
  6663. fnode_sess->target_id);
  6664. if (ret > 0)
  6665. ret = -EIO;
  6666. exit_ddb_login:
  6667. if (fw_ddb_entry)
  6668. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6669. fw_ddb_entry, fw_ddb_entry_dma);
  6670. return ret;
  6671. }
  6672. /**
  6673. * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
  6674. * @cls_sess: pointer to session to be logged out
  6675. *
  6676. * This performs session log out from the specified target
  6677. **/
  6678. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
  6679. {
  6680. struct iscsi_session *sess;
  6681. struct ddb_entry *ddb_entry = NULL;
  6682. struct scsi_qla_host *ha;
  6683. struct dev_db_entry *fw_ddb_entry = NULL;
  6684. dma_addr_t fw_ddb_entry_dma;
  6685. unsigned long flags;
  6686. unsigned long wtime;
  6687. uint32_t ddb_state;
  6688. int options;
  6689. int ret = 0;
  6690. sess = cls_sess->dd_data;
  6691. ddb_entry = sess->dd_data;
  6692. ha = ddb_entry->ha;
  6693. if (ddb_entry->ddb_type != FLASH_DDB) {
  6694. ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
  6695. __func__);
  6696. ret = -ENXIO;
  6697. goto exit_ddb_logout;
  6698. }
  6699. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  6700. ql4_printk(KERN_ERR, ha,
  6701. "%s: Logout from boot target entry is not permitted.\n",
  6702. __func__);
  6703. ret = -EPERM;
  6704. goto exit_ddb_logout;
  6705. }
  6706. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6707. &fw_ddb_entry_dma, GFP_KERNEL);
  6708. if (!fw_ddb_entry) {
  6709. ql4_printk(KERN_ERR, ha,
  6710. "%s: Unable to allocate dma buffer\n", __func__);
  6711. ret = -ENOMEM;
  6712. goto exit_ddb_logout;
  6713. }
  6714. if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  6715. goto ddb_logout_init;
  6716. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  6717. fw_ddb_entry, fw_ddb_entry_dma,
  6718. NULL, NULL, &ddb_state, NULL,
  6719. NULL, NULL);
  6720. if (ret == QLA_ERROR)
  6721. goto ddb_logout_init;
  6722. if (ddb_state == DDB_DS_SESSION_ACTIVE)
  6723. goto ddb_logout_init;
  6724. /* wait until next relogin is triggered using DF_RELOGIN and
  6725. * clear DF_RELOGIN to avoid invocation of further relogin
  6726. */
  6727. wtime = jiffies + (HZ * RELOGIN_TOV);
  6728. do {
  6729. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
  6730. goto ddb_logout_init;
  6731. schedule_timeout_uninterruptible(HZ);
  6732. } while ((time_after(wtime, jiffies)));
  6733. ddb_logout_init:
  6734. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  6735. atomic_set(&ddb_entry->relogin_timer, 0);
  6736. options = LOGOUT_OPTION_CLOSE_SESSION;
  6737. qla4xxx_session_logout_ddb(ha, ddb_entry, options);
  6738. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  6739. wtime = jiffies + (HZ * LOGOUT_TOV);
  6740. do {
  6741. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  6742. fw_ddb_entry, fw_ddb_entry_dma,
  6743. NULL, NULL, &ddb_state, NULL,
  6744. NULL, NULL);
  6745. if (ret == QLA_ERROR)
  6746. goto ddb_logout_clr_sess;
  6747. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  6748. (ddb_state == DDB_DS_SESSION_FAILED))
  6749. goto ddb_logout_clr_sess;
  6750. schedule_timeout_uninterruptible(HZ);
  6751. } while ((time_after(wtime, jiffies)));
  6752. ddb_logout_clr_sess:
  6753. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  6754. /*
  6755. * we have decremented the reference count of the driver
  6756. * when we setup the session to have the driver unload
  6757. * to be seamless without actually destroying the
  6758. * session
  6759. **/
  6760. try_module_get(qla4xxx_iscsi_transport.owner);
  6761. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  6762. spin_lock_irqsave(&ha->hardware_lock, flags);
  6763. qla4xxx_free_ddb(ha, ddb_entry);
  6764. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  6765. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6766. iscsi_session_teardown(ddb_entry->sess);
  6767. clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
  6768. ret = QLA_SUCCESS;
  6769. exit_ddb_logout:
  6770. if (fw_ddb_entry)
  6771. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6772. fw_ddb_entry, fw_ddb_entry_dma);
  6773. return ret;
  6774. }
  6775. /**
  6776. * qla4xxx_sysfs_ddb_logout - Logout from the specified target
  6777. * @fnode_sess: pointer to session attrs of flash ddb entry
  6778. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6779. *
  6780. * This performs log out from the specified target
  6781. **/
  6782. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  6783. struct iscsi_bus_flash_conn *fnode_conn)
  6784. {
  6785. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6786. struct scsi_qla_host *ha = to_qla_host(shost);
  6787. struct ql4_tuple_ddb *flash_tddb = NULL;
  6788. struct ql4_tuple_ddb *tmp_tddb = NULL;
  6789. struct dev_db_entry *fw_ddb_entry = NULL;
  6790. struct ddb_entry *ddb_entry = NULL;
  6791. dma_addr_t fw_ddb_dma;
  6792. uint32_t next_idx = 0;
  6793. uint32_t state = 0, conn_err = 0;
  6794. uint16_t conn_id = 0;
  6795. int idx, index;
  6796. int status, ret = 0;
  6797. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6798. &fw_ddb_dma);
  6799. if (fw_ddb_entry == NULL) {
  6800. ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
  6801. ret = -ENOMEM;
  6802. goto exit_ddb_logout;
  6803. }
  6804. flash_tddb = vzalloc(sizeof(*flash_tddb));
  6805. if (!flash_tddb) {
  6806. ql4_printk(KERN_WARNING, ha,
  6807. "%s:Memory Allocation failed.\n", __func__);
  6808. ret = -ENOMEM;
  6809. goto exit_ddb_logout;
  6810. }
  6811. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  6812. if (!tmp_tddb) {
  6813. ql4_printk(KERN_WARNING, ha,
  6814. "%s:Memory Allocation failed.\n", __func__);
  6815. ret = -ENOMEM;
  6816. goto exit_ddb_logout;
  6817. }
  6818. if (!fnode_sess->targetname) {
  6819. ql4_printk(KERN_ERR, ha,
  6820. "%s:Cannot logout from SendTarget entry\n",
  6821. __func__);
  6822. ret = -EPERM;
  6823. goto exit_ddb_logout;
  6824. }
  6825. if (fnode_sess->is_boot_target) {
  6826. ql4_printk(KERN_ERR, ha,
  6827. "%s: Logout from boot target entry is not permitted.\n",
  6828. __func__);
  6829. ret = -EPERM;
  6830. goto exit_ddb_logout;
  6831. }
  6832. strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
  6833. ISCSI_NAME_SIZE);
  6834. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6835. sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
  6836. else
  6837. sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
  6838. flash_tddb->tpgt = fnode_sess->tpgt;
  6839. flash_tddb->port = fnode_conn->port;
  6840. COPY_ISID(flash_tddb->isid, fnode_sess->isid);
  6841. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  6842. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6843. if (ddb_entry == NULL)
  6844. continue;
  6845. if (ddb_entry->ddb_type != FLASH_DDB)
  6846. continue;
  6847. index = ddb_entry->sess->target_id;
  6848. status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
  6849. fw_ddb_dma, NULL, &next_idx,
  6850. &state, &conn_err, NULL,
  6851. &conn_id);
  6852. if (status == QLA_ERROR) {
  6853. ret = -ENOMEM;
  6854. break;
  6855. }
  6856. qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
  6857. status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
  6858. true);
  6859. if (status == QLA_SUCCESS) {
  6860. ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
  6861. break;
  6862. }
  6863. }
  6864. if (idx == MAX_DDB_ENTRIES)
  6865. ret = -ESRCH;
  6866. exit_ddb_logout:
  6867. if (flash_tddb)
  6868. vfree(flash_tddb);
  6869. if (tmp_tddb)
  6870. vfree(tmp_tddb);
  6871. if (fw_ddb_entry)
  6872. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6873. return ret;
  6874. }
  6875. static int
  6876. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  6877. int param, char *buf)
  6878. {
  6879. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6880. struct scsi_qla_host *ha = to_qla_host(shost);
  6881. struct iscsi_bus_flash_conn *fnode_conn;
  6882. struct ql4_chap_table chap_tbl;
  6883. struct device *dev;
  6884. int parent_type;
  6885. int rc = 0;
  6886. dev = iscsi_find_flashnode_conn(fnode_sess);
  6887. if (!dev)
  6888. return -EIO;
  6889. fnode_conn = iscsi_dev_to_flash_conn(dev);
  6890. switch (param) {
  6891. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  6892. rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
  6893. break;
  6894. case ISCSI_FLASHNODE_PORTAL_TYPE:
  6895. rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
  6896. break;
  6897. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  6898. rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
  6899. break;
  6900. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  6901. rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
  6902. break;
  6903. case ISCSI_FLASHNODE_ENTRY_EN:
  6904. rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
  6905. break;
  6906. case ISCSI_FLASHNODE_HDR_DGST_EN:
  6907. rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
  6908. break;
  6909. case ISCSI_FLASHNODE_DATA_DGST_EN:
  6910. rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
  6911. break;
  6912. case ISCSI_FLASHNODE_IMM_DATA_EN:
  6913. rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
  6914. break;
  6915. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  6916. rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
  6917. break;
  6918. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  6919. rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
  6920. break;
  6921. case ISCSI_FLASHNODE_PDU_INORDER:
  6922. rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
  6923. break;
  6924. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  6925. rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
  6926. break;
  6927. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  6928. rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
  6929. break;
  6930. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  6931. rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
  6932. break;
  6933. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  6934. rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
  6935. break;
  6936. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  6937. rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
  6938. break;
  6939. case ISCSI_FLASHNODE_ERL:
  6940. rc = sprintf(buf, "%u\n", fnode_sess->erl);
  6941. break;
  6942. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  6943. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
  6944. break;
  6945. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  6946. rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
  6947. break;
  6948. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  6949. rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
  6950. break;
  6951. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  6952. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
  6953. break;
  6954. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  6955. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
  6956. break;
  6957. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  6958. rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
  6959. break;
  6960. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  6961. rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
  6962. break;
  6963. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  6964. rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
  6965. break;
  6966. case ISCSI_FLASHNODE_FIRST_BURST:
  6967. rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
  6968. break;
  6969. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  6970. rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
  6971. break;
  6972. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  6973. rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
  6974. break;
  6975. case ISCSI_FLASHNODE_MAX_R2T:
  6976. rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
  6977. break;
  6978. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  6979. rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
  6980. break;
  6981. case ISCSI_FLASHNODE_ISID:
  6982. rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
  6983. fnode_sess->isid[0], fnode_sess->isid[1],
  6984. fnode_sess->isid[2], fnode_sess->isid[3],
  6985. fnode_sess->isid[4], fnode_sess->isid[5]);
  6986. break;
  6987. case ISCSI_FLASHNODE_TSID:
  6988. rc = sprintf(buf, "%u\n", fnode_sess->tsid);
  6989. break;
  6990. case ISCSI_FLASHNODE_PORT:
  6991. rc = sprintf(buf, "%d\n", fnode_conn->port);
  6992. break;
  6993. case ISCSI_FLASHNODE_MAX_BURST:
  6994. rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
  6995. break;
  6996. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  6997. rc = sprintf(buf, "%u\n",
  6998. fnode_sess->default_taskmgmt_timeout);
  6999. break;
  7000. case ISCSI_FLASHNODE_IPADDR:
  7001. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7002. rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
  7003. else
  7004. rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
  7005. break;
  7006. case ISCSI_FLASHNODE_ALIAS:
  7007. if (fnode_sess->targetalias)
  7008. rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
  7009. else
  7010. rc = sprintf(buf, "\n");
  7011. break;
  7012. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  7013. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7014. rc = sprintf(buf, "%pI6\n",
  7015. fnode_conn->redirect_ipaddr);
  7016. else
  7017. rc = sprintf(buf, "%pI4\n",
  7018. fnode_conn->redirect_ipaddr);
  7019. break;
  7020. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  7021. rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
  7022. break;
  7023. case ISCSI_FLASHNODE_LOCAL_PORT:
  7024. rc = sprintf(buf, "%u\n", fnode_conn->local_port);
  7025. break;
  7026. case ISCSI_FLASHNODE_IPV4_TOS:
  7027. rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
  7028. break;
  7029. case ISCSI_FLASHNODE_IPV6_TC:
  7030. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7031. rc = sprintf(buf, "%u\n",
  7032. fnode_conn->ipv6_traffic_class);
  7033. else
  7034. rc = sprintf(buf, "\n");
  7035. break;
  7036. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  7037. rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
  7038. break;
  7039. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  7040. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7041. rc = sprintf(buf, "%pI6\n",
  7042. fnode_conn->link_local_ipv6_addr);
  7043. else
  7044. rc = sprintf(buf, "\n");
  7045. break;
  7046. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  7047. rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
  7048. break;
  7049. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  7050. if (fnode_sess->discovery_parent_type == DDB_ISNS)
  7051. parent_type = ISCSI_DISC_PARENT_ISNS;
  7052. else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
  7053. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  7054. else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
  7055. parent_type = ISCSI_DISC_PARENT_SENDTGT;
  7056. else
  7057. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  7058. rc = sprintf(buf, "%s\n",
  7059. iscsi_get_discovery_parent_name(parent_type));
  7060. break;
  7061. case ISCSI_FLASHNODE_NAME:
  7062. if (fnode_sess->targetname)
  7063. rc = sprintf(buf, "%s\n", fnode_sess->targetname);
  7064. else
  7065. rc = sprintf(buf, "\n");
  7066. break;
  7067. case ISCSI_FLASHNODE_TPGT:
  7068. rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
  7069. break;
  7070. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  7071. rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
  7072. break;
  7073. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  7074. rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
  7075. break;
  7076. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  7077. rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
  7078. break;
  7079. case ISCSI_FLASHNODE_USERNAME:
  7080. if (fnode_sess->chap_auth_en) {
  7081. qla4xxx_get_uni_chap_at_index(ha,
  7082. chap_tbl.name,
  7083. chap_tbl.secret,
  7084. fnode_sess->chap_out_idx);
  7085. rc = sprintf(buf, "%s\n", chap_tbl.name);
  7086. } else {
  7087. rc = sprintf(buf, "\n");
  7088. }
  7089. break;
  7090. case ISCSI_FLASHNODE_PASSWORD:
  7091. if (fnode_sess->chap_auth_en) {
  7092. qla4xxx_get_uni_chap_at_index(ha,
  7093. chap_tbl.name,
  7094. chap_tbl.secret,
  7095. fnode_sess->chap_out_idx);
  7096. rc = sprintf(buf, "%s\n", chap_tbl.secret);
  7097. } else {
  7098. rc = sprintf(buf, "\n");
  7099. }
  7100. break;
  7101. case ISCSI_FLASHNODE_STATSN:
  7102. rc = sprintf(buf, "%u\n", fnode_conn->statsn);
  7103. break;
  7104. case ISCSI_FLASHNODE_EXP_STATSN:
  7105. rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
  7106. break;
  7107. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  7108. rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
  7109. break;
  7110. default:
  7111. rc = -ENOSYS;
  7112. break;
  7113. }
  7114. put_device(dev);
  7115. return rc;
  7116. }
  7117. /**
  7118. * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
  7119. * @fnode_sess: pointer to session attrs of flash ddb entry
  7120. * @fnode_conn: pointer to connection attrs of flash ddb entry
  7121. * @data: Parameters and their values to update
  7122. * @len: len of data
  7123. *
  7124. * This sets the parameter of flash ddb entry and writes them to flash
  7125. **/
  7126. static int
  7127. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  7128. struct iscsi_bus_flash_conn *fnode_conn,
  7129. void *data, int len)
  7130. {
  7131. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  7132. struct scsi_qla_host *ha = to_qla_host(shost);
  7133. struct iscsi_flashnode_param_info *fnode_param;
  7134. struct ql4_chap_table chap_tbl;
  7135. struct nlattr *attr;
  7136. uint16_t chap_out_idx = INVALID_ENTRY;
  7137. int rc = QLA_ERROR;
  7138. uint32_t rem = len;
  7139. memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
  7140. nla_for_each_attr(attr, data, len, rem) {
  7141. fnode_param = nla_data(attr);
  7142. switch (fnode_param->param) {
  7143. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  7144. fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
  7145. break;
  7146. case ISCSI_FLASHNODE_PORTAL_TYPE:
  7147. memcpy(fnode_sess->portal_type, fnode_param->value,
  7148. strlen(fnode_sess->portal_type));
  7149. break;
  7150. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  7151. fnode_sess->auto_snd_tgt_disable =
  7152. fnode_param->value[0];
  7153. break;
  7154. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  7155. fnode_sess->discovery_sess = fnode_param->value[0];
  7156. break;
  7157. case ISCSI_FLASHNODE_ENTRY_EN:
  7158. fnode_sess->entry_state = fnode_param->value[0];
  7159. break;
  7160. case ISCSI_FLASHNODE_HDR_DGST_EN:
  7161. fnode_conn->hdrdgst_en = fnode_param->value[0];
  7162. break;
  7163. case ISCSI_FLASHNODE_DATA_DGST_EN:
  7164. fnode_conn->datadgst_en = fnode_param->value[0];
  7165. break;
  7166. case ISCSI_FLASHNODE_IMM_DATA_EN:
  7167. fnode_sess->imm_data_en = fnode_param->value[0];
  7168. break;
  7169. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  7170. fnode_sess->initial_r2t_en = fnode_param->value[0];
  7171. break;
  7172. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  7173. fnode_sess->dataseq_inorder_en = fnode_param->value[0];
  7174. break;
  7175. case ISCSI_FLASHNODE_PDU_INORDER:
  7176. fnode_sess->pdu_inorder_en = fnode_param->value[0];
  7177. break;
  7178. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  7179. fnode_sess->chap_auth_en = fnode_param->value[0];
  7180. /* Invalidate chap index if chap auth is disabled */
  7181. if (!fnode_sess->chap_auth_en)
  7182. fnode_sess->chap_out_idx = INVALID_ENTRY;
  7183. break;
  7184. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  7185. fnode_conn->snack_req_en = fnode_param->value[0];
  7186. break;
  7187. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  7188. fnode_sess->discovery_logout_en = fnode_param->value[0];
  7189. break;
  7190. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  7191. fnode_sess->bidi_chap_en = fnode_param->value[0];
  7192. break;
  7193. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  7194. fnode_sess->discovery_auth_optional =
  7195. fnode_param->value[0];
  7196. break;
  7197. case ISCSI_FLASHNODE_ERL:
  7198. fnode_sess->erl = fnode_param->value[0];
  7199. break;
  7200. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  7201. fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
  7202. break;
  7203. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  7204. fnode_conn->tcp_nagle_disable = fnode_param->value[0];
  7205. break;
  7206. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  7207. fnode_conn->tcp_wsf_disable = fnode_param->value[0];
  7208. break;
  7209. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  7210. fnode_conn->tcp_timer_scale = fnode_param->value[0];
  7211. break;
  7212. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  7213. fnode_conn->tcp_timestamp_en = fnode_param->value[0];
  7214. break;
  7215. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  7216. fnode_conn->fragment_disable = fnode_param->value[0];
  7217. break;
  7218. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  7219. fnode_conn->max_recv_dlength =
  7220. *(unsigned *)fnode_param->value;
  7221. break;
  7222. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  7223. fnode_conn->max_xmit_dlength =
  7224. *(unsigned *)fnode_param->value;
  7225. break;
  7226. case ISCSI_FLASHNODE_FIRST_BURST:
  7227. fnode_sess->first_burst =
  7228. *(unsigned *)fnode_param->value;
  7229. break;
  7230. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  7231. fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
  7232. break;
  7233. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  7234. fnode_sess->time2retain =
  7235. *(uint16_t *)fnode_param->value;
  7236. break;
  7237. case ISCSI_FLASHNODE_MAX_R2T:
  7238. fnode_sess->max_r2t =
  7239. *(uint16_t *)fnode_param->value;
  7240. break;
  7241. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  7242. fnode_conn->keepalive_timeout =
  7243. *(uint16_t *)fnode_param->value;
  7244. break;
  7245. case ISCSI_FLASHNODE_ISID:
  7246. memcpy(fnode_sess->isid, fnode_param->value,
  7247. sizeof(fnode_sess->isid));
  7248. break;
  7249. case ISCSI_FLASHNODE_TSID:
  7250. fnode_sess->tsid = *(uint16_t *)fnode_param->value;
  7251. break;
  7252. case ISCSI_FLASHNODE_PORT:
  7253. fnode_conn->port = *(uint16_t *)fnode_param->value;
  7254. break;
  7255. case ISCSI_FLASHNODE_MAX_BURST:
  7256. fnode_sess->max_burst = *(unsigned *)fnode_param->value;
  7257. break;
  7258. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  7259. fnode_sess->default_taskmgmt_timeout =
  7260. *(uint16_t *)fnode_param->value;
  7261. break;
  7262. case ISCSI_FLASHNODE_IPADDR:
  7263. memcpy(fnode_conn->ipaddress, fnode_param->value,
  7264. IPv6_ADDR_LEN);
  7265. break;
  7266. case ISCSI_FLASHNODE_ALIAS:
  7267. rc = iscsi_switch_str_param(&fnode_sess->targetalias,
  7268. (char *)fnode_param->value);
  7269. break;
  7270. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  7271. memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
  7272. IPv6_ADDR_LEN);
  7273. break;
  7274. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  7275. fnode_conn->max_segment_size =
  7276. *(unsigned *)fnode_param->value;
  7277. break;
  7278. case ISCSI_FLASHNODE_LOCAL_PORT:
  7279. fnode_conn->local_port =
  7280. *(uint16_t *)fnode_param->value;
  7281. break;
  7282. case ISCSI_FLASHNODE_IPV4_TOS:
  7283. fnode_conn->ipv4_tos = fnode_param->value[0];
  7284. break;
  7285. case ISCSI_FLASHNODE_IPV6_TC:
  7286. fnode_conn->ipv6_traffic_class = fnode_param->value[0];
  7287. break;
  7288. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  7289. fnode_conn->ipv6_flow_label = fnode_param->value[0];
  7290. break;
  7291. case ISCSI_FLASHNODE_NAME:
  7292. rc = iscsi_switch_str_param(&fnode_sess->targetname,
  7293. (char *)fnode_param->value);
  7294. break;
  7295. case ISCSI_FLASHNODE_TPGT:
  7296. fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
  7297. break;
  7298. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  7299. memcpy(fnode_conn->link_local_ipv6_addr,
  7300. fnode_param->value, IPv6_ADDR_LEN);
  7301. break;
  7302. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  7303. fnode_sess->discovery_parent_idx =
  7304. *(uint16_t *)fnode_param->value;
  7305. break;
  7306. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  7307. fnode_conn->tcp_xmit_wsf =
  7308. *(uint8_t *)fnode_param->value;
  7309. break;
  7310. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  7311. fnode_conn->tcp_recv_wsf =
  7312. *(uint8_t *)fnode_param->value;
  7313. break;
  7314. case ISCSI_FLASHNODE_STATSN:
  7315. fnode_conn->statsn = *(uint32_t *)fnode_param->value;
  7316. break;
  7317. case ISCSI_FLASHNODE_EXP_STATSN:
  7318. fnode_conn->exp_statsn =
  7319. *(uint32_t *)fnode_param->value;
  7320. break;
  7321. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  7322. chap_out_idx = *(uint16_t *)fnode_param->value;
  7323. if (!qla4xxx_get_uni_chap_at_index(ha,
  7324. chap_tbl.name,
  7325. chap_tbl.secret,
  7326. chap_out_idx)) {
  7327. fnode_sess->chap_out_idx = chap_out_idx;
  7328. /* Enable chap auth if chap index is valid */
  7329. fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
  7330. }
  7331. break;
  7332. default:
  7333. ql4_printk(KERN_ERR, ha,
  7334. "%s: No such sysfs attribute\n", __func__);
  7335. rc = -ENOSYS;
  7336. goto exit_set_param;
  7337. }
  7338. }
  7339. rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
  7340. exit_set_param:
  7341. return rc;
  7342. }
  7343. /**
  7344. * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
  7345. * @fnode_sess: pointer to session attrs of flash ddb entry
  7346. *
  7347. * This invalidates the flash ddb entry at the given index
  7348. **/
  7349. static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
  7350. {
  7351. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  7352. struct scsi_qla_host *ha = to_qla_host(shost);
  7353. uint32_t dev_db_start_offset;
  7354. uint32_t dev_db_end_offset;
  7355. struct dev_db_entry *fw_ddb_entry = NULL;
  7356. dma_addr_t fw_ddb_entry_dma;
  7357. uint16_t *ddb_cookie = NULL;
  7358. size_t ddb_size = 0;
  7359. void *pddb = NULL;
  7360. int target_id;
  7361. int rc = 0;
  7362. if (fnode_sess->is_boot_target) {
  7363. rc = -EPERM;
  7364. DEBUG2(ql4_printk(KERN_ERR, ha,
  7365. "%s: Deletion of boot target entry is not permitted.\n",
  7366. __func__));
  7367. goto exit_ddb_del;
  7368. }
  7369. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
  7370. goto sysfs_ddb_del;
  7371. if (is_qla40XX(ha)) {
  7372. dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  7373. dev_db_end_offset = FLASH_OFFSET_DB_END;
  7374. dev_db_start_offset += (fnode_sess->target_id *
  7375. sizeof(*fw_ddb_entry));
  7376. ddb_size = sizeof(*fw_ddb_entry);
  7377. } else {
  7378. dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
  7379. (ha->hw.flt_region_ddb << 2);
  7380. /* flt_ddb_size is DDB table size for both ports
  7381. * so divide it by 2 to calculate the offset for second port
  7382. */
  7383. if (ha->port_num == 1)
  7384. dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
  7385. dev_db_end_offset = dev_db_start_offset +
  7386. (ha->hw.flt_ddb_size / 2);
  7387. dev_db_start_offset += (fnode_sess->target_id *
  7388. sizeof(*fw_ddb_entry));
  7389. dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
  7390. ddb_size = sizeof(*ddb_cookie);
  7391. }
  7392. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
  7393. __func__, dev_db_start_offset, dev_db_end_offset));
  7394. if (dev_db_start_offset > dev_db_end_offset) {
  7395. rc = -EIO;
  7396. DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
  7397. __func__, fnode_sess->target_id));
  7398. goto exit_ddb_del;
  7399. }
  7400. pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
  7401. &fw_ddb_entry_dma, GFP_KERNEL);
  7402. if (!pddb) {
  7403. rc = -ENOMEM;
  7404. DEBUG2(ql4_printk(KERN_ERR, ha,
  7405. "%s: Unable to allocate dma buffer\n",
  7406. __func__));
  7407. goto exit_ddb_del;
  7408. }
  7409. if (is_qla40XX(ha)) {
  7410. fw_ddb_entry = pddb;
  7411. memset(fw_ddb_entry, 0, ddb_size);
  7412. ddb_cookie = &fw_ddb_entry->cookie;
  7413. } else {
  7414. ddb_cookie = pddb;
  7415. }
  7416. /* invalidate the cookie */
  7417. *ddb_cookie = 0xFFEE;
  7418. qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  7419. ddb_size, FLASH_OPT_RMW_COMMIT);
  7420. sysfs_ddb_del:
  7421. target_id = fnode_sess->target_id;
  7422. iscsi_destroy_flashnode_sess(fnode_sess);
  7423. ql4_printk(KERN_INFO, ha,
  7424. "%s: session and conn entries for flashnode %u of host %lu deleted\n",
  7425. __func__, target_id, ha->host_no);
  7426. exit_ddb_del:
  7427. if (pddb)
  7428. dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
  7429. fw_ddb_entry_dma);
  7430. return rc;
  7431. }
  7432. /**
  7433. * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
  7434. * @ha: pointer to adapter structure
  7435. *
  7436. * Export the firmware DDB for all send targets and normal targets to sysfs.
  7437. **/
  7438. int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
  7439. {
  7440. struct dev_db_entry *fw_ddb_entry = NULL;
  7441. dma_addr_t fw_ddb_entry_dma;
  7442. uint16_t max_ddbs;
  7443. uint16_t idx = 0;
  7444. int ret = QLA_SUCCESS;
  7445. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  7446. sizeof(*fw_ddb_entry),
  7447. &fw_ddb_entry_dma, GFP_KERNEL);
  7448. if (!fw_ddb_entry) {
  7449. DEBUG2(ql4_printk(KERN_ERR, ha,
  7450. "%s: Unable to allocate dma buffer\n",
  7451. __func__));
  7452. return -ENOMEM;
  7453. }
  7454. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  7455. MAX_DEV_DB_ENTRIES;
  7456. for (idx = 0; idx < max_ddbs; idx++) {
  7457. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
  7458. idx))
  7459. continue;
  7460. ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
  7461. if (ret) {
  7462. ret = -EIO;
  7463. break;
  7464. }
  7465. }
  7466. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
  7467. fw_ddb_entry_dma);
  7468. return ret;
  7469. }
  7470. static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
  7471. {
  7472. iscsi_destroy_all_flashnode(ha->host);
  7473. }
  7474. /**
  7475. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  7476. * @ha: pointer to adapter structure
  7477. * @is_reset: Is this init path or reset path
  7478. *
  7479. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  7480. * using connection open, then create the list of normal targets (nt)
  7481. * from firmware DDBs. Based on the list of nt setup session and connection
  7482. * objects.
  7483. **/
  7484. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  7485. {
  7486. uint16_t tmo = 0;
  7487. struct list_head list_st, list_nt;
  7488. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  7489. unsigned long wtime;
  7490. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  7491. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  7492. ha->is_reset = is_reset;
  7493. return;
  7494. }
  7495. INIT_LIST_HEAD(&list_st);
  7496. INIT_LIST_HEAD(&list_nt);
  7497. qla4xxx_build_st_list(ha, &list_st);
  7498. /* Before issuing conn open mbox, ensure all IPs states are configured
  7499. * Note, conn open fails if IPs are not configured
  7500. */
  7501. qla4xxx_wait_for_ip_configuration(ha);
  7502. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  7503. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  7504. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  7505. }
  7506. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  7507. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  7508. (ha->def_timeout < LOGIN_TOV * 10) ?
  7509. ha->def_timeout : LOGIN_TOV);
  7510. DEBUG2(ql4_printk(KERN_INFO, ha,
  7511. "Default time to wait for build ddb %d\n", tmo));
  7512. wtime = jiffies + (HZ * tmo);
  7513. do {
  7514. if (list_empty(&list_st))
  7515. break;
  7516. qla4xxx_remove_failed_ddb(ha, &list_st);
  7517. schedule_timeout_uninterruptible(HZ / 10);
  7518. } while (time_after(wtime, jiffies));
  7519. qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
  7520. qla4xxx_free_ddb_list(&list_st);
  7521. qla4xxx_free_ddb_list(&list_nt);
  7522. qla4xxx_free_ddb_index(ha);
  7523. }
  7524. /**
  7525. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  7526. * response.
  7527. * @ha: pointer to adapter structure
  7528. *
  7529. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  7530. * set in DDB and we will wait for login response of boot targets during
  7531. * probe.
  7532. **/
  7533. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  7534. {
  7535. struct ddb_entry *ddb_entry;
  7536. struct dev_db_entry *fw_ddb_entry = NULL;
  7537. dma_addr_t fw_ddb_entry_dma;
  7538. unsigned long wtime;
  7539. uint32_t ddb_state;
  7540. int max_ddbs, idx, ret;
  7541. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  7542. MAX_DEV_DB_ENTRIES;
  7543. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7544. &fw_ddb_entry_dma, GFP_KERNEL);
  7545. if (!fw_ddb_entry) {
  7546. ql4_printk(KERN_ERR, ha,
  7547. "%s: Unable to allocate dma buffer\n", __func__);
  7548. goto exit_login_resp;
  7549. }
  7550. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  7551. for (idx = 0; idx < max_ddbs; idx++) {
  7552. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  7553. if (ddb_entry == NULL)
  7554. continue;
  7555. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  7556. DEBUG2(ql4_printk(KERN_INFO, ha,
  7557. "%s: DDB index [%d]\n", __func__,
  7558. ddb_entry->fw_ddb_index));
  7559. do {
  7560. ret = qla4xxx_get_fwddb_entry(ha,
  7561. ddb_entry->fw_ddb_index,
  7562. fw_ddb_entry, fw_ddb_entry_dma,
  7563. NULL, NULL, &ddb_state, NULL,
  7564. NULL, NULL);
  7565. if (ret == QLA_ERROR)
  7566. goto exit_login_resp;
  7567. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  7568. (ddb_state == DDB_DS_SESSION_FAILED))
  7569. break;
  7570. schedule_timeout_uninterruptible(HZ);
  7571. } while ((time_after(wtime, jiffies)));
  7572. if (!time_after(wtime, jiffies)) {
  7573. DEBUG2(ql4_printk(KERN_INFO, ha,
  7574. "%s: Login response wait timer expired\n",
  7575. __func__));
  7576. goto exit_login_resp;
  7577. }
  7578. }
  7579. }
  7580. exit_login_resp:
  7581. if (fw_ddb_entry)
  7582. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7583. fw_ddb_entry, fw_ddb_entry_dma);
  7584. }
  7585. /**
  7586. * qla4xxx_probe_adapter - callback function to probe HBA
  7587. * @pdev: pointer to pci_dev structure
  7588. * @pci_device_id: pointer to pci_device entry
  7589. *
  7590. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  7591. * It returns zero if successful. It also initializes all data necessary for
  7592. * the driver.
  7593. **/
  7594. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  7595. const struct pci_device_id *ent)
  7596. {
  7597. int ret = -ENODEV, status;
  7598. struct Scsi_Host *host;
  7599. struct scsi_qla_host *ha;
  7600. uint8_t init_retry_count = 0;
  7601. char buf[34];
  7602. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  7603. uint32_t dev_state;
  7604. if (pci_enable_device(pdev))
  7605. return -1;
  7606. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  7607. if (host == NULL) {
  7608. printk(KERN_WARNING
  7609. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  7610. goto probe_disable_device;
  7611. }
  7612. /* Clear our data area */
  7613. ha = to_qla_host(host);
  7614. memset(ha, 0, sizeof(*ha));
  7615. /* Save the information from PCI BIOS. */
  7616. ha->pdev = pdev;
  7617. ha->host = host;
  7618. ha->host_no = host->host_no;
  7619. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  7620. pci_enable_pcie_error_reporting(pdev);
  7621. /* Setup Runtime configurable options */
  7622. if (is_qla8022(ha)) {
  7623. ha->isp_ops = &qla4_82xx_isp_ops;
  7624. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  7625. ha->qdr_sn_window = -1;
  7626. ha->ddr_mn_window = -1;
  7627. ha->curr_window = 255;
  7628. nx_legacy_intr = &legacy_intr[ha->func_num];
  7629. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  7630. ha->nx_legacy_intr.tgt_status_reg =
  7631. nx_legacy_intr->tgt_status_reg;
  7632. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  7633. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  7634. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  7635. ha->isp_ops = &qla4_83xx_isp_ops;
  7636. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  7637. } else {
  7638. ha->isp_ops = &qla4xxx_isp_ops;
  7639. }
  7640. if (is_qla80XX(ha)) {
  7641. rwlock_init(&ha->hw_lock);
  7642. ha->pf_bit = ha->func_num << 16;
  7643. /* Set EEH reset type to fundamental if required by hba */
  7644. pdev->needs_freset = 1;
  7645. }
  7646. /* Configure PCI I/O space. */
  7647. ret = ha->isp_ops->iospace_config(ha);
  7648. if (ret)
  7649. goto probe_failed_ioconfig;
  7650. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  7651. pdev->device, pdev->irq, ha->reg);
  7652. qla4xxx_config_dma_addressing(ha);
  7653. /* Initialize lists and spinlocks. */
  7654. INIT_LIST_HEAD(&ha->free_srb_q);
  7655. mutex_init(&ha->mbox_sem);
  7656. mutex_init(&ha->chap_sem);
  7657. init_completion(&ha->mbx_intr_comp);
  7658. init_completion(&ha->disable_acb_comp);
  7659. init_completion(&ha->idc_comp);
  7660. init_completion(&ha->link_up_comp);
  7661. init_completion(&ha->disable_acb_comp);
  7662. spin_lock_init(&ha->hardware_lock);
  7663. spin_lock_init(&ha->work_lock);
  7664. /* Initialize work list */
  7665. INIT_LIST_HEAD(&ha->work_list);
  7666. /* Allocate dma buffers */
  7667. if (qla4xxx_mem_alloc(ha)) {
  7668. ql4_printk(KERN_WARNING, ha,
  7669. "[ERROR] Failed to allocate memory for adapter\n");
  7670. ret = -ENOMEM;
  7671. goto probe_failed;
  7672. }
  7673. host->cmd_per_lun = 3;
  7674. host->max_channel = 0;
  7675. host->max_lun = MAX_LUNS - 1;
  7676. host->max_id = MAX_TARGETS;
  7677. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  7678. host->can_queue = MAX_SRBS ;
  7679. host->transportt = qla4xxx_scsi_transport;
  7680. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  7681. if (ret) {
  7682. ql4_printk(KERN_WARNING, ha,
  7683. "%s: scsi_init_shared_tag_map failed\n", __func__);
  7684. goto probe_failed;
  7685. }
  7686. pci_set_drvdata(pdev, ha);
  7687. ret = scsi_add_host(host, &pdev->dev);
  7688. if (ret)
  7689. goto probe_failed;
  7690. if (is_qla80XX(ha))
  7691. qla4_8xxx_get_flash_info(ha);
  7692. if (is_qla8032(ha) || is_qla8042(ha)) {
  7693. qla4_83xx_read_reset_template(ha);
  7694. /*
  7695. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  7696. * If DONRESET_BIT0 is set, drivers should not set dev_state
  7697. * to NEED_RESET. But if NEED_RESET is set, drivers should
  7698. * should honor the reset.
  7699. */
  7700. if (ql4xdontresethba == 1)
  7701. qla4_83xx_set_idc_dontreset(ha);
  7702. }
  7703. /*
  7704. * Initialize the Host adapter request/response queues and
  7705. * firmware
  7706. * NOTE: interrupts enabled upon successful completion
  7707. */
  7708. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  7709. /* Dont retry adapter initialization if IRQ allocation failed */
  7710. if (is_qla80XX(ha) && (status == QLA_ERROR))
  7711. goto skip_retry_init;
  7712. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  7713. init_retry_count++ < MAX_INIT_RETRIES) {
  7714. if (is_qla80XX(ha)) {
  7715. ha->isp_ops->idc_lock(ha);
  7716. dev_state = qla4_8xxx_rd_direct(ha,
  7717. QLA8XXX_CRB_DEV_STATE);
  7718. ha->isp_ops->idc_unlock(ha);
  7719. if (dev_state == QLA8XXX_DEV_FAILED) {
  7720. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  7721. "initialize adapter. H/W is in failed state\n",
  7722. __func__);
  7723. break;
  7724. }
  7725. }
  7726. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  7727. "(%d)\n", __func__, init_retry_count));
  7728. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  7729. continue;
  7730. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  7731. if (is_qla80XX(ha) && (status == QLA_ERROR)) {
  7732. if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
  7733. goto skip_retry_init;
  7734. }
  7735. }
  7736. skip_retry_init:
  7737. if (!test_bit(AF_ONLINE, &ha->flags)) {
  7738. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  7739. if ((is_qla8022(ha) && ql4xdontresethba) ||
  7740. ((is_qla8032(ha) || is_qla8042(ha)) &&
  7741. qla4_83xx_idc_dontreset(ha))) {
  7742. /* Put the device in failed state. */
  7743. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  7744. ha->isp_ops->idc_lock(ha);
  7745. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7746. QLA8XXX_DEV_FAILED);
  7747. ha->isp_ops->idc_unlock(ha);
  7748. }
  7749. ret = -ENODEV;
  7750. goto remove_host;
  7751. }
  7752. /* Startup the kernel thread for this host adapter. */
  7753. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  7754. "qla4xxx_dpc\n", __func__));
  7755. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  7756. ha->dpc_thread = create_singlethread_workqueue(buf);
  7757. if (!ha->dpc_thread) {
  7758. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  7759. ret = -ENODEV;
  7760. goto remove_host;
  7761. }
  7762. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  7763. ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
  7764. ha->host_no);
  7765. if (!ha->task_wq) {
  7766. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  7767. ret = -ENODEV;
  7768. goto remove_host;
  7769. }
  7770. /*
  7771. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  7772. * (which is called indirectly by qla4xxx_initialize_adapter),
  7773. * so that irqs will be registered after crbinit but before
  7774. * mbx_intr_enable.
  7775. */
  7776. if (is_qla40XX(ha)) {
  7777. ret = qla4xxx_request_irqs(ha);
  7778. if (ret) {
  7779. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  7780. "interrupt %d already in use.\n", pdev->irq);
  7781. goto remove_host;
  7782. }
  7783. }
  7784. pci_save_state(ha->pdev);
  7785. ha->isp_ops->enable_intrs(ha);
  7786. /* Start timer thread. */
  7787. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  7788. set_bit(AF_INIT_DONE, &ha->flags);
  7789. qla4_8xxx_alloc_sysfs_attr(ha);
  7790. printk(KERN_INFO
  7791. " QLogic iSCSI HBA Driver version: %s\n"
  7792. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  7793. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  7794. ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
  7795. ha->fw_info.fw_patch, ha->fw_info.fw_build);
  7796. /* Set the driver version */
  7797. if (is_qla80XX(ha))
  7798. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  7799. if (qla4xxx_setup_boot_info(ha))
  7800. ql4_printk(KERN_ERR, ha,
  7801. "%s: No iSCSI boot target configured\n", __func__);
  7802. set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
  7803. /* Perform the build ddb list and login to each */
  7804. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  7805. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  7806. qla4xxx_wait_login_resp_boot_tgt(ha);
  7807. qla4xxx_create_chap_list(ha);
  7808. qla4xxx_create_ifaces(ha);
  7809. return 0;
  7810. remove_host:
  7811. scsi_remove_host(ha->host);
  7812. probe_failed:
  7813. qla4xxx_free_adapter(ha);
  7814. probe_failed_ioconfig:
  7815. pci_disable_pcie_error_reporting(pdev);
  7816. scsi_host_put(ha->host);
  7817. probe_disable_device:
  7818. pci_disable_device(pdev);
  7819. return ret;
  7820. }
  7821. /**
  7822. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  7823. * @ha: pointer to adapter structure
  7824. *
  7825. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  7826. * so that the other port will not re-initialize while in the process of
  7827. * removing the ha due to driver unload or hba hotplug.
  7828. **/
  7829. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  7830. {
  7831. struct scsi_qla_host *other_ha = NULL;
  7832. struct pci_dev *other_pdev = NULL;
  7833. int fn = ISP4XXX_PCI_FN_2;
  7834. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  7835. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  7836. fn = ISP4XXX_PCI_FN_1;
  7837. other_pdev =
  7838. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  7839. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  7840. fn));
  7841. /* Get other_ha if other_pdev is valid and state is enable*/
  7842. if (other_pdev) {
  7843. if (atomic_read(&other_pdev->enable_cnt)) {
  7844. other_ha = pci_get_drvdata(other_pdev);
  7845. if (other_ha) {
  7846. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  7847. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  7848. "Prevent %s reinit\n", __func__,
  7849. dev_name(&other_ha->pdev->dev)));
  7850. }
  7851. }
  7852. pci_dev_put(other_pdev);
  7853. }
  7854. }
  7855. static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
  7856. struct ddb_entry *ddb_entry)
  7857. {
  7858. struct dev_db_entry *fw_ddb_entry = NULL;
  7859. dma_addr_t fw_ddb_entry_dma;
  7860. unsigned long wtime;
  7861. uint32_t ddb_state;
  7862. int options;
  7863. int status;
  7864. options = LOGOUT_OPTION_CLOSE_SESSION;
  7865. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
  7866. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  7867. goto clear_ddb;
  7868. }
  7869. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7870. &fw_ddb_entry_dma, GFP_KERNEL);
  7871. if (!fw_ddb_entry) {
  7872. ql4_printk(KERN_ERR, ha,
  7873. "%s: Unable to allocate dma buffer\n", __func__);
  7874. goto clear_ddb;
  7875. }
  7876. wtime = jiffies + (HZ * LOGOUT_TOV);
  7877. do {
  7878. status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  7879. fw_ddb_entry, fw_ddb_entry_dma,
  7880. NULL, NULL, &ddb_state, NULL,
  7881. NULL, NULL);
  7882. if (status == QLA_ERROR)
  7883. goto free_ddb;
  7884. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  7885. (ddb_state == DDB_DS_SESSION_FAILED))
  7886. goto free_ddb;
  7887. schedule_timeout_uninterruptible(HZ);
  7888. } while ((time_after(wtime, jiffies)));
  7889. free_ddb:
  7890. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7891. fw_ddb_entry, fw_ddb_entry_dma);
  7892. clear_ddb:
  7893. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  7894. }
  7895. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  7896. {
  7897. struct ddb_entry *ddb_entry;
  7898. int idx;
  7899. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  7900. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  7901. if ((ddb_entry != NULL) &&
  7902. (ddb_entry->ddb_type == FLASH_DDB)) {
  7903. qla4xxx_destroy_ddb(ha, ddb_entry);
  7904. /*
  7905. * we have decremented the reference count of the driver
  7906. * when we setup the session to have the driver unload
  7907. * to be seamless without actually destroying the
  7908. * session
  7909. **/
  7910. try_module_get(qla4xxx_iscsi_transport.owner);
  7911. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  7912. qla4xxx_free_ddb(ha, ddb_entry);
  7913. iscsi_session_teardown(ddb_entry->sess);
  7914. }
  7915. }
  7916. }
  7917. /**
  7918. * qla4xxx_remove_adapter - callback function to remove adapter.
  7919. * @pci_dev: PCI device pointer
  7920. **/
  7921. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  7922. {
  7923. struct scsi_qla_host *ha;
  7924. /*
  7925. * If the PCI device is disabled then it means probe_adapter had
  7926. * failed and resources already cleaned up on probe_adapter exit.
  7927. */
  7928. if (!pci_is_enabled(pdev))
  7929. return;
  7930. ha = pci_get_drvdata(pdev);
  7931. if (is_qla40XX(ha))
  7932. qla4xxx_prevent_other_port_reinit(ha);
  7933. /* destroy iface from sysfs */
  7934. qla4xxx_destroy_ifaces(ha);
  7935. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  7936. iscsi_boot_destroy_kset(ha->boot_kset);
  7937. qla4xxx_destroy_fw_ddb_session(ha);
  7938. qla4_8xxx_free_sysfs_attr(ha);
  7939. qla4xxx_sysfs_ddb_remove(ha);
  7940. scsi_remove_host(ha->host);
  7941. qla4xxx_free_adapter(ha);
  7942. scsi_host_put(ha->host);
  7943. pci_disable_pcie_error_reporting(pdev);
  7944. pci_disable_device(pdev);
  7945. }
  7946. /**
  7947. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  7948. * @ha: HA context
  7949. *
  7950. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  7951. * supported addressing method.
  7952. */
  7953. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  7954. {
  7955. int retval;
  7956. /* Update our PCI device dma_mask for full 64 bit mask */
  7957. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  7958. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  7959. dev_dbg(&ha->pdev->dev,
  7960. "Failed to set 64 bit PCI consistent mask; "
  7961. "using 32 bit.\n");
  7962. retval = pci_set_consistent_dma_mask(ha->pdev,
  7963. DMA_BIT_MASK(32));
  7964. }
  7965. } else
  7966. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  7967. }
  7968. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  7969. {
  7970. struct iscsi_cls_session *cls_sess;
  7971. struct iscsi_session *sess;
  7972. struct ddb_entry *ddb;
  7973. int queue_depth = QL4_DEF_QDEPTH;
  7974. cls_sess = starget_to_session(sdev->sdev_target);
  7975. sess = cls_sess->dd_data;
  7976. ddb = sess->dd_data;
  7977. sdev->hostdata = ddb;
  7978. sdev->tagged_supported = 1;
  7979. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  7980. queue_depth = ql4xmaxqdepth;
  7981. scsi_adjust_queue_depth(sdev, queue_depth);
  7982. return 0;
  7983. }
  7984. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  7985. {
  7986. sdev->tagged_supported = 1;
  7987. return 0;
  7988. }
  7989. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  7990. int reason)
  7991. {
  7992. if (!ql4xqfulltracking)
  7993. return -EOPNOTSUPP;
  7994. return iscsi_change_queue_depth(sdev, qdepth, reason);
  7995. }
  7996. /**
  7997. * qla4xxx_del_from_active_array - returns an active srb
  7998. * @ha: Pointer to host adapter structure.
  7999. * @index: index into the active_array
  8000. *
  8001. * This routine removes and returns the srb at the specified index
  8002. **/
  8003. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  8004. uint32_t index)
  8005. {
  8006. struct srb *srb = NULL;
  8007. struct scsi_cmnd *cmd = NULL;
  8008. cmd = scsi_host_find_tag(ha->host, index);
  8009. if (!cmd)
  8010. return srb;
  8011. srb = (struct srb *)CMD_SP(cmd);
  8012. if (!srb)
  8013. return srb;
  8014. /* update counters */
  8015. if (srb->flags & SRB_DMA_VALID) {
  8016. ha->iocb_cnt -= srb->iocb_cnt;
  8017. if (srb->cmd)
  8018. srb->cmd->host_scribble =
  8019. (unsigned char *)(unsigned long) MAX_SRBS;
  8020. }
  8021. return srb;
  8022. }
  8023. /**
  8024. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  8025. * @ha: Pointer to host adapter structure.
  8026. * @cmd: Scsi Command to wait on.
  8027. *
  8028. * This routine waits for the command to be returned by the Firmware
  8029. * for some max time.
  8030. **/
  8031. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  8032. struct scsi_cmnd *cmd)
  8033. {
  8034. int done = 0;
  8035. struct srb *rp;
  8036. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  8037. int ret = SUCCESS;
  8038. /* Dont wait on command if PCI error is being handled
  8039. * by PCI AER driver
  8040. */
  8041. if (unlikely(pci_channel_offline(ha->pdev)) ||
  8042. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  8043. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  8044. ha->host_no, __func__);
  8045. return ret;
  8046. }
  8047. do {
  8048. /* Checking to see if its returned to OS */
  8049. rp = (struct srb *) CMD_SP(cmd);
  8050. if (rp == NULL) {
  8051. done++;
  8052. break;
  8053. }
  8054. msleep(2000);
  8055. } while (max_wait_time--);
  8056. return done;
  8057. }
  8058. /**
  8059. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  8060. * @ha: Pointer to host adapter structure
  8061. **/
  8062. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  8063. {
  8064. unsigned long wait_online;
  8065. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  8066. while (time_before(jiffies, wait_online)) {
  8067. if (adapter_up(ha))
  8068. return QLA_SUCCESS;
  8069. msleep(2000);
  8070. }
  8071. return QLA_ERROR;
  8072. }
  8073. /**
  8074. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  8075. * @ha: pointer to HBA
  8076. * @t: target id
  8077. * @l: lun id
  8078. *
  8079. * This function waits for all outstanding commands to a lun to complete. It
  8080. * returns 0 if all pending commands are returned and 1 otherwise.
  8081. **/
  8082. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  8083. struct scsi_target *stgt,
  8084. struct scsi_device *sdev)
  8085. {
  8086. int cnt;
  8087. int status = 0;
  8088. struct scsi_cmnd *cmd;
  8089. /*
  8090. * Waiting for all commands for the designated target or dev
  8091. * in the active array
  8092. */
  8093. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  8094. cmd = scsi_host_find_tag(ha->host, cnt);
  8095. if (cmd && stgt == scsi_target(cmd->device) &&
  8096. (!sdev || sdev == cmd->device)) {
  8097. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  8098. status++;
  8099. break;
  8100. }
  8101. }
  8102. }
  8103. return status;
  8104. }
  8105. /**
  8106. * qla4xxx_eh_abort - callback for abort task.
  8107. * @cmd: Pointer to Linux's SCSI command structure
  8108. *
  8109. * This routine is called by the Linux OS to abort the specified
  8110. * command.
  8111. **/
  8112. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  8113. {
  8114. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8115. unsigned int id = cmd->device->id;
  8116. uint64_t lun = cmd->device->lun;
  8117. unsigned long flags;
  8118. struct srb *srb = NULL;
  8119. int ret = SUCCESS;
  8120. int wait = 0;
  8121. ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
  8122. ha->host_no, id, lun, cmd, cmd->cmnd[0]);
  8123. spin_lock_irqsave(&ha->hardware_lock, flags);
  8124. srb = (struct srb *) CMD_SP(cmd);
  8125. if (!srb) {
  8126. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  8127. ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
  8128. ha->host_no, id, lun);
  8129. return SUCCESS;
  8130. }
  8131. kref_get(&srb->srb_ref);
  8132. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  8133. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  8134. DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
  8135. ha->host_no, id, lun));
  8136. ret = FAILED;
  8137. } else {
  8138. DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
  8139. ha->host_no, id, lun));
  8140. wait = 1;
  8141. }
  8142. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  8143. /* Wait for command to complete */
  8144. if (wait) {
  8145. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  8146. DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
  8147. ha->host_no, id, lun));
  8148. ret = FAILED;
  8149. }
  8150. }
  8151. ql4_printk(KERN_INFO, ha,
  8152. "scsi%ld:%d:%llu: Abort command - %s\n",
  8153. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  8154. return ret;
  8155. }
  8156. /**
  8157. * qla4xxx_eh_device_reset - callback for target reset.
  8158. * @cmd: Pointer to Linux's SCSI command structure
  8159. *
  8160. * This routine is called by the Linux OS to reset all luns on the
  8161. * specified target.
  8162. **/
  8163. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  8164. {
  8165. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8166. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  8167. int ret = FAILED, stat;
  8168. if (!ddb_entry)
  8169. return ret;
  8170. ret = iscsi_block_scsi_eh(cmd);
  8171. if (ret)
  8172. return ret;
  8173. ret = FAILED;
  8174. ql4_printk(KERN_INFO, ha,
  8175. "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
  8176. cmd->device->channel, cmd->device->id, cmd->device->lun);
  8177. DEBUG2(printk(KERN_INFO
  8178. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  8179. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  8180. cmd, jiffies, cmd->request->timeout / HZ,
  8181. ha->dpc_flags, cmd->result, cmd->allowed));
  8182. /* FIXME: wait for hba to go online */
  8183. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  8184. if (stat != QLA_SUCCESS) {
  8185. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  8186. goto eh_dev_reset_done;
  8187. }
  8188. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  8189. cmd->device)) {
  8190. ql4_printk(KERN_INFO, ha,
  8191. "DEVICE RESET FAILED - waiting for "
  8192. "commands.\n");
  8193. goto eh_dev_reset_done;
  8194. }
  8195. /* Send marker. */
  8196. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  8197. MM_LUN_RESET) != QLA_SUCCESS)
  8198. goto eh_dev_reset_done;
  8199. ql4_printk(KERN_INFO, ha,
  8200. "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
  8201. ha->host_no, cmd->device->channel, cmd->device->id,
  8202. cmd->device->lun);
  8203. ret = SUCCESS;
  8204. eh_dev_reset_done:
  8205. return ret;
  8206. }
  8207. /**
  8208. * qla4xxx_eh_target_reset - callback for target reset.
  8209. * @cmd: Pointer to Linux's SCSI command structure
  8210. *
  8211. * This routine is called by the Linux OS to reset the target.
  8212. **/
  8213. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  8214. {
  8215. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8216. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  8217. int stat, ret;
  8218. if (!ddb_entry)
  8219. return FAILED;
  8220. ret = iscsi_block_scsi_eh(cmd);
  8221. if (ret)
  8222. return ret;
  8223. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8224. "WARM TARGET RESET ISSUED.\n");
  8225. DEBUG2(printk(KERN_INFO
  8226. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  8227. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  8228. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  8229. ha->dpc_flags, cmd->result, cmd->allowed));
  8230. stat = qla4xxx_reset_target(ha, ddb_entry);
  8231. if (stat != QLA_SUCCESS) {
  8232. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8233. "WARM TARGET RESET FAILED.\n");
  8234. return FAILED;
  8235. }
  8236. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  8237. NULL)) {
  8238. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8239. "WARM TARGET DEVICE RESET FAILED - "
  8240. "waiting for commands.\n");
  8241. return FAILED;
  8242. }
  8243. /* Send marker. */
  8244. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  8245. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  8246. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8247. "WARM TARGET DEVICE RESET FAILED - "
  8248. "marker iocb failed.\n");
  8249. return FAILED;
  8250. }
  8251. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8252. "WARM TARGET RESET SUCCEEDED.\n");
  8253. return SUCCESS;
  8254. }
  8255. /**
  8256. * qla4xxx_is_eh_active - check if error handler is running
  8257. * @shost: Pointer to SCSI Host struct
  8258. *
  8259. * This routine finds that if reset host is called in EH
  8260. * scenario or from some application like sg_reset
  8261. **/
  8262. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  8263. {
  8264. if (shost->shost_state == SHOST_RECOVERY)
  8265. return 1;
  8266. return 0;
  8267. }
  8268. /**
  8269. * qla4xxx_eh_host_reset - kernel callback
  8270. * @cmd: Pointer to Linux's SCSI command structure
  8271. *
  8272. * This routine is invoked by the Linux kernel to perform fatal error
  8273. * recovery on the specified adapter.
  8274. **/
  8275. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  8276. {
  8277. int return_status = FAILED;
  8278. struct scsi_qla_host *ha;
  8279. ha = to_qla_host(cmd->device->host);
  8280. if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
  8281. qla4_83xx_set_idc_dontreset(ha);
  8282. /*
  8283. * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
  8284. * protocol drivers, we should not set device_state to NEED_RESET
  8285. */
  8286. if (ql4xdontresethba ||
  8287. ((is_qla8032(ha) || is_qla8042(ha)) &&
  8288. qla4_83xx_idc_dontreset(ha))) {
  8289. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  8290. ha->host_no, __func__));
  8291. /* Clear outstanding srb in queues */
  8292. if (qla4xxx_is_eh_active(cmd->device->host))
  8293. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  8294. return FAILED;
  8295. }
  8296. ql4_printk(KERN_INFO, ha,
  8297. "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
  8298. cmd->device->channel, cmd->device->id, cmd->device->lun);
  8299. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  8300. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  8301. "DEAD.\n", ha->host_no, cmd->device->channel,
  8302. __func__));
  8303. return FAILED;
  8304. }
  8305. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8306. if (is_qla80XX(ha))
  8307. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  8308. else
  8309. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  8310. }
  8311. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  8312. return_status = SUCCESS;
  8313. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  8314. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  8315. return return_status;
  8316. }
  8317. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  8318. {
  8319. uint32_t mbox_cmd[MBOX_REG_COUNT];
  8320. uint32_t mbox_sts[MBOX_REG_COUNT];
  8321. struct addr_ctrl_blk_def *acb = NULL;
  8322. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  8323. int rval = QLA_SUCCESS;
  8324. dma_addr_t acb_dma;
  8325. acb = dma_alloc_coherent(&ha->pdev->dev,
  8326. sizeof(struct addr_ctrl_blk_def),
  8327. &acb_dma, GFP_KERNEL);
  8328. if (!acb) {
  8329. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  8330. __func__);
  8331. rval = -ENOMEM;
  8332. goto exit_port_reset;
  8333. }
  8334. memset(acb, 0, acb_len);
  8335. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  8336. if (rval != QLA_SUCCESS) {
  8337. rval = -EIO;
  8338. goto exit_free_acb;
  8339. }
  8340. rval = qla4xxx_disable_acb(ha);
  8341. if (rval != QLA_SUCCESS) {
  8342. rval = -EIO;
  8343. goto exit_free_acb;
  8344. }
  8345. wait_for_completion_timeout(&ha->disable_acb_comp,
  8346. DISABLE_ACB_TOV * HZ);
  8347. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  8348. if (rval != QLA_SUCCESS) {
  8349. rval = -EIO;
  8350. goto exit_free_acb;
  8351. }
  8352. exit_free_acb:
  8353. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  8354. acb, acb_dma);
  8355. exit_port_reset:
  8356. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  8357. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  8358. return rval;
  8359. }
  8360. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  8361. {
  8362. struct scsi_qla_host *ha = to_qla_host(shost);
  8363. int rval = QLA_SUCCESS;
  8364. uint32_t idc_ctrl;
  8365. if (ql4xdontresethba) {
  8366. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  8367. __func__));
  8368. rval = -EPERM;
  8369. goto exit_host_reset;
  8370. }
  8371. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  8372. goto recover_adapter;
  8373. switch (reset_type) {
  8374. case SCSI_ADAPTER_RESET:
  8375. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  8376. break;
  8377. case SCSI_FIRMWARE_RESET:
  8378. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8379. if (is_qla80XX(ha))
  8380. /* set firmware context reset */
  8381. set_bit(DPC_RESET_HA_FW_CONTEXT,
  8382. &ha->dpc_flags);
  8383. else {
  8384. rval = qla4xxx_context_reset(ha);
  8385. goto exit_host_reset;
  8386. }
  8387. }
  8388. break;
  8389. }
  8390. recover_adapter:
  8391. /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
  8392. * reset is issued by application */
  8393. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  8394. test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8395. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  8396. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  8397. (idc_ctrl | GRACEFUL_RESET_BIT1));
  8398. }
  8399. rval = qla4xxx_recover_adapter(ha);
  8400. if (rval != QLA_SUCCESS) {
  8401. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  8402. __func__));
  8403. rval = -EIO;
  8404. }
  8405. exit_host_reset:
  8406. return rval;
  8407. }
  8408. /* PCI AER driver recovers from all correctable errors w/o
  8409. * driver intervention. For uncorrectable errors PCI AER
  8410. * driver calls the following device driver's callbacks
  8411. *
  8412. * - Fatal Errors - link_reset
  8413. * - Non-Fatal Errors - driver's pci_error_detected() which
  8414. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  8415. *
  8416. * PCI AER driver calls
  8417. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  8418. * returns RECOVERED or NEED_RESET if fw_hung
  8419. * NEED_RESET - driver's slot_reset()
  8420. * DISCONNECT - device is dead & cannot recover
  8421. * RECOVERED - driver's pci_resume()
  8422. */
  8423. static pci_ers_result_t
  8424. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  8425. {
  8426. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8427. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  8428. ha->host_no, __func__, state);
  8429. if (!is_aer_supported(ha))
  8430. return PCI_ERS_RESULT_NONE;
  8431. switch (state) {
  8432. case pci_channel_io_normal:
  8433. clear_bit(AF_EEH_BUSY, &ha->flags);
  8434. return PCI_ERS_RESULT_CAN_RECOVER;
  8435. case pci_channel_io_frozen:
  8436. set_bit(AF_EEH_BUSY, &ha->flags);
  8437. qla4xxx_mailbox_premature_completion(ha);
  8438. qla4xxx_free_irqs(ha);
  8439. pci_disable_device(pdev);
  8440. /* Return back all IOs */
  8441. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  8442. return PCI_ERS_RESULT_NEED_RESET;
  8443. case pci_channel_io_perm_failure:
  8444. set_bit(AF_EEH_BUSY, &ha->flags);
  8445. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  8446. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  8447. return PCI_ERS_RESULT_DISCONNECT;
  8448. }
  8449. return PCI_ERS_RESULT_NEED_RESET;
  8450. }
  8451. /**
  8452. * qla4xxx_pci_mmio_enabled() gets called if
  8453. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  8454. * and read/write to the device still works.
  8455. **/
  8456. static pci_ers_result_t
  8457. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  8458. {
  8459. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8460. if (!is_aer_supported(ha))
  8461. return PCI_ERS_RESULT_NONE;
  8462. return PCI_ERS_RESULT_RECOVERED;
  8463. }
  8464. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  8465. {
  8466. uint32_t rval = QLA_ERROR;
  8467. int fn;
  8468. struct pci_dev *other_pdev = NULL;
  8469. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  8470. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  8471. if (test_bit(AF_ONLINE, &ha->flags)) {
  8472. clear_bit(AF_ONLINE, &ha->flags);
  8473. clear_bit(AF_LINK_UP, &ha->flags);
  8474. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  8475. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  8476. }
  8477. fn = PCI_FUNC(ha->pdev->devfn);
  8478. if (is_qla8022(ha)) {
  8479. while (fn > 0) {
  8480. fn--;
  8481. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
  8482. ha->host_no, __func__, fn);
  8483. /* Get the pci device given the domain, bus,
  8484. * slot/function number */
  8485. other_pdev = pci_get_domain_bus_and_slot(
  8486. pci_domain_nr(ha->pdev->bus),
  8487. ha->pdev->bus->number,
  8488. PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  8489. fn));
  8490. if (!other_pdev)
  8491. continue;
  8492. if (atomic_read(&other_pdev->enable_cnt)) {
  8493. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
  8494. ha->host_no, __func__, fn);
  8495. pci_dev_put(other_pdev);
  8496. break;
  8497. }
  8498. pci_dev_put(other_pdev);
  8499. }
  8500. } else {
  8501. /* this case is meant for ISP83xx/ISP84xx only */
  8502. if (qla4_83xx_can_perform_reset(ha)) {
  8503. /* reset fn as iSCSI is going to perform the reset */
  8504. fn = 0;
  8505. }
  8506. }
  8507. /* The first function on the card, the reset owner will
  8508. * start & initialize the firmware. The other functions
  8509. * on the card will reset the firmware context
  8510. */
  8511. if (!fn) {
  8512. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  8513. "0x%x is the owner\n", ha->host_no, __func__,
  8514. ha->pdev->devfn);
  8515. ha->isp_ops->idc_lock(ha);
  8516. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8517. QLA8XXX_DEV_COLD);
  8518. ha->isp_ops->idc_unlock(ha);
  8519. rval = qla4_8xxx_update_idc_reg(ha);
  8520. if (rval == QLA_ERROR) {
  8521. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  8522. ha->host_no, __func__);
  8523. ha->isp_ops->idc_lock(ha);
  8524. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8525. QLA8XXX_DEV_FAILED);
  8526. ha->isp_ops->idc_unlock(ha);
  8527. goto exit_error_recovery;
  8528. }
  8529. clear_bit(AF_FW_RECOVERY, &ha->flags);
  8530. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  8531. if (rval != QLA_SUCCESS) {
  8532. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  8533. "FAILED\n", ha->host_no, __func__);
  8534. qla4xxx_free_irqs(ha);
  8535. ha->isp_ops->idc_lock(ha);
  8536. qla4_8xxx_clear_drv_active(ha);
  8537. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8538. QLA8XXX_DEV_FAILED);
  8539. ha->isp_ops->idc_unlock(ha);
  8540. } else {
  8541. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  8542. "READY\n", ha->host_no, __func__);
  8543. ha->isp_ops->idc_lock(ha);
  8544. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8545. QLA8XXX_DEV_READY);
  8546. /* Clear driver state register */
  8547. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  8548. qla4_8xxx_set_drv_active(ha);
  8549. ha->isp_ops->idc_unlock(ha);
  8550. ha->isp_ops->enable_intrs(ha);
  8551. }
  8552. } else {
  8553. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  8554. "the reset owner\n", ha->host_no, __func__,
  8555. ha->pdev->devfn);
  8556. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  8557. QLA8XXX_DEV_READY)) {
  8558. clear_bit(AF_FW_RECOVERY, &ha->flags);
  8559. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  8560. if (rval == QLA_SUCCESS)
  8561. ha->isp_ops->enable_intrs(ha);
  8562. else
  8563. qla4xxx_free_irqs(ha);
  8564. ha->isp_ops->idc_lock(ha);
  8565. qla4_8xxx_set_drv_active(ha);
  8566. ha->isp_ops->idc_unlock(ha);
  8567. }
  8568. }
  8569. exit_error_recovery:
  8570. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  8571. return rval;
  8572. }
  8573. static pci_ers_result_t
  8574. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  8575. {
  8576. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  8577. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8578. int rc;
  8579. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  8580. ha->host_no, __func__);
  8581. if (!is_aer_supported(ha))
  8582. return PCI_ERS_RESULT_NONE;
  8583. /* Restore the saved state of PCIe device -
  8584. * BAR registers, PCI Config space, PCIX, MSI,
  8585. * IOV states
  8586. */
  8587. pci_restore_state(pdev);
  8588. /* pci_restore_state() clears the saved_state flag of the device
  8589. * save restored state which resets saved_state flag
  8590. */
  8591. pci_save_state(pdev);
  8592. /* Initialize device or resume if in suspended state */
  8593. rc = pci_enable_device(pdev);
  8594. if (rc) {
  8595. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  8596. "device after reset\n", ha->host_no, __func__);
  8597. goto exit_slot_reset;
  8598. }
  8599. ha->isp_ops->disable_intrs(ha);
  8600. if (is_qla80XX(ha)) {
  8601. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  8602. ret = PCI_ERS_RESULT_RECOVERED;
  8603. goto exit_slot_reset;
  8604. } else
  8605. goto exit_slot_reset;
  8606. }
  8607. exit_slot_reset:
  8608. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  8609. "device after reset\n", ha->host_no, __func__, ret);
  8610. return ret;
  8611. }
  8612. static void
  8613. qla4xxx_pci_resume(struct pci_dev *pdev)
  8614. {
  8615. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8616. int ret;
  8617. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  8618. ha->host_no, __func__);
  8619. ret = qla4xxx_wait_for_hba_online(ha);
  8620. if (ret != QLA_SUCCESS) {
  8621. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  8622. "resume I/O from slot/link_reset\n", ha->host_no,
  8623. __func__);
  8624. }
  8625. pci_cleanup_aer_uncorrect_error_status(pdev);
  8626. clear_bit(AF_EEH_BUSY, &ha->flags);
  8627. }
  8628. static const struct pci_error_handlers qla4xxx_err_handler = {
  8629. .error_detected = qla4xxx_pci_error_detected,
  8630. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  8631. .slot_reset = qla4xxx_pci_slot_reset,
  8632. .resume = qla4xxx_pci_resume,
  8633. };
  8634. static struct pci_device_id qla4xxx_pci_tbl[] = {
  8635. {
  8636. .vendor = PCI_VENDOR_ID_QLOGIC,
  8637. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  8638. .subvendor = PCI_ANY_ID,
  8639. .subdevice = PCI_ANY_ID,
  8640. },
  8641. {
  8642. .vendor = PCI_VENDOR_ID_QLOGIC,
  8643. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  8644. .subvendor = PCI_ANY_ID,
  8645. .subdevice = PCI_ANY_ID,
  8646. },
  8647. {
  8648. .vendor = PCI_VENDOR_ID_QLOGIC,
  8649. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  8650. .subvendor = PCI_ANY_ID,
  8651. .subdevice = PCI_ANY_ID,
  8652. },
  8653. {
  8654. .vendor = PCI_VENDOR_ID_QLOGIC,
  8655. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  8656. .subvendor = PCI_ANY_ID,
  8657. .subdevice = PCI_ANY_ID,
  8658. },
  8659. {
  8660. .vendor = PCI_VENDOR_ID_QLOGIC,
  8661. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  8662. .subvendor = PCI_ANY_ID,
  8663. .subdevice = PCI_ANY_ID,
  8664. },
  8665. {
  8666. .vendor = PCI_VENDOR_ID_QLOGIC,
  8667. .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
  8668. .subvendor = PCI_ANY_ID,
  8669. .subdevice = PCI_ANY_ID,
  8670. },
  8671. {0, 0},
  8672. };
  8673. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  8674. static struct pci_driver qla4xxx_pci_driver = {
  8675. .name = DRIVER_NAME,
  8676. .id_table = qla4xxx_pci_tbl,
  8677. .probe = qla4xxx_probe_adapter,
  8678. .remove = qla4xxx_remove_adapter,
  8679. .err_handler = &qla4xxx_err_handler,
  8680. };
  8681. static int __init qla4xxx_module_init(void)
  8682. {
  8683. int ret;
  8684. /* Allocate cache for SRBs. */
  8685. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  8686. SLAB_HWCACHE_ALIGN, NULL);
  8687. if (srb_cachep == NULL) {
  8688. printk(KERN_ERR
  8689. "%s: Unable to allocate SRB cache..."
  8690. "Failing load!\n", DRIVER_NAME);
  8691. ret = -ENOMEM;
  8692. goto no_srp_cache;
  8693. }
  8694. /* Derive version string. */
  8695. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  8696. if (ql4xextended_error_logging)
  8697. strcat(qla4xxx_version_str, "-debug");
  8698. qla4xxx_scsi_transport =
  8699. iscsi_register_transport(&qla4xxx_iscsi_transport);
  8700. if (!qla4xxx_scsi_transport){
  8701. ret = -ENODEV;
  8702. goto release_srb_cache;
  8703. }
  8704. ret = pci_register_driver(&qla4xxx_pci_driver);
  8705. if (ret)
  8706. goto unregister_transport;
  8707. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  8708. return 0;
  8709. unregister_transport:
  8710. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  8711. release_srb_cache:
  8712. kmem_cache_destroy(srb_cachep);
  8713. no_srp_cache:
  8714. return ret;
  8715. }
  8716. static void __exit qla4xxx_module_exit(void)
  8717. {
  8718. pci_unregister_driver(&qla4xxx_pci_driver);
  8719. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  8720. kmem_cache_destroy(srb_cachep);
  8721. }
  8722. module_init(qla4xxx_module_init);
  8723. module_exit(qla4xxx_module_exit);
  8724. MODULE_AUTHOR("QLogic Corporation");
  8725. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  8726. MODULE_LICENSE("GPL");
  8727. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);