ql4_os.c 284 KB

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