ql4_os.c 228 KB

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