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