ql4_os.c 284 KB

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