ql4_os.c 171 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 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. /*
  20. * Driver version
  21. */
  22. static char qla4xxx_version_str[40];
  23. /*
  24. * SRB allocation cache
  25. */
  26. static struct kmem_cache *srb_cachep;
  27. /*
  28. * Module parameter information and variables
  29. */
  30. static int ql4xdisablesysfsboot = 1;
  31. module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
  32. MODULE_PARM_DESC(ql4xdisablesysfsboot,
  33. " Set to disable exporting boot targets to sysfs.\n"
  34. "\t\t 0 - Export boot targets\n"
  35. "\t\t 1 - Do not export boot targets (Default)");
  36. int ql4xdontresethba;
  37. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  38. MODULE_PARM_DESC(ql4xdontresethba,
  39. " Don't reset the HBA for driver recovery.\n"
  40. "\t\t 0 - It will reset HBA (Default)\n"
  41. "\t\t 1 - It will NOT reset HBA");
  42. int ql4xextended_error_logging;
  43. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  44. MODULE_PARM_DESC(ql4xextended_error_logging,
  45. " Option to enable extended error logging.\n"
  46. "\t\t 0 - no logging (Default)\n"
  47. "\t\t 2 - debug logging");
  48. int ql4xenablemsix = 1;
  49. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  50. MODULE_PARM_DESC(ql4xenablemsix,
  51. " Set to enable MSI or MSI-X interrupt mechanism.\n"
  52. "\t\t 0 = enable INTx interrupt mechanism.\n"
  53. "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
  54. "\t\t 2 = enable MSI interrupt mechanism.");
  55. #define QL4_DEF_QDEPTH 32
  56. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  57. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  58. MODULE_PARM_DESC(ql4xmaxqdepth,
  59. " Maximum queue depth to report for target devices.\n"
  60. "\t\t Default: 32.");
  61. static int ql4xqfulltracking = 1;
  62. module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
  63. MODULE_PARM_DESC(ql4xqfulltracking,
  64. " Enable or disable dynamic tracking and adjustment of\n"
  65. "\t\t scsi device queue depth.\n"
  66. "\t\t 0 - Disable.\n"
  67. "\t\t 1 - Enable. (Default)");
  68. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  69. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  70. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  71. " Target Session Recovery Timeout.\n"
  72. "\t\t Default: 120 sec.");
  73. int ql4xmdcapmask = 0x1F;
  74. module_param(ql4xmdcapmask, int, S_IRUGO);
  75. MODULE_PARM_DESC(ql4xmdcapmask,
  76. " Set the Minidump driver capture mask level.\n"
  77. "\t\t Default is 0x1F.\n"
  78. "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
  79. int ql4xenablemd = 1;
  80. module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
  81. MODULE_PARM_DESC(ql4xenablemd,
  82. " Set to enable minidump.\n"
  83. "\t\t 0 - disable minidump\n"
  84. "\t\t 1 - enable minidump (Default)");
  85. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  86. /*
  87. * SCSI host template entry points
  88. */
  89. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  90. /*
  91. * iSCSI template entry points
  92. */
  93. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  94. enum iscsi_param param, char *buf);
  95. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  96. enum iscsi_param param, char *buf);
  97. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  98. enum iscsi_host_param param, char *buf);
  99. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
  100. uint32_t len);
  101. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  102. enum iscsi_param_type param_type,
  103. int param, char *buf);
  104. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  105. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  106. struct sockaddr *dst_addr,
  107. int non_blocking);
  108. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  109. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  110. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  111. enum iscsi_param param, char *buf);
  112. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  113. static struct iscsi_cls_conn *
  114. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  115. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  116. struct iscsi_cls_conn *cls_conn,
  117. uint64_t transport_fd, int is_leading);
  118. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  119. static struct iscsi_cls_session *
  120. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  121. uint16_t qdepth, uint32_t initial_cmdsn);
  122. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  123. static void qla4xxx_task_work(struct work_struct *wdata);
  124. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  125. static int qla4xxx_task_xmit(struct iscsi_task *);
  126. static void qla4xxx_task_cleanup(struct iscsi_task *);
  127. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  128. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  129. struct iscsi_stats *stats);
  130. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  131. uint32_t iface_type, uint32_t payload_size,
  132. uint32_t pid, struct sockaddr *dst_addr);
  133. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  134. uint32_t *num_entries, char *buf);
  135. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
  136. /*
  137. * SCSI host template entry points
  138. */
  139. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  140. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  141. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  142. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  143. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  144. static int qla4xxx_slave_alloc(struct scsi_device *device);
  145. static int qla4xxx_slave_configure(struct scsi_device *device);
  146. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  147. static umode_t ql4_attr_is_visible(int param_type, int param);
  148. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  149. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  150. int reason);
  151. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  152. QLA82XX_LEGACY_INTR_CONFIG;
  153. static struct scsi_host_template qla4xxx_driver_template = {
  154. .module = THIS_MODULE,
  155. .name = DRIVER_NAME,
  156. .proc_name = DRIVER_NAME,
  157. .queuecommand = qla4xxx_queuecommand,
  158. .eh_abort_handler = qla4xxx_eh_abort,
  159. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  160. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  161. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  162. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  163. .slave_configure = qla4xxx_slave_configure,
  164. .slave_alloc = qla4xxx_slave_alloc,
  165. .slave_destroy = qla4xxx_slave_destroy,
  166. .change_queue_depth = qla4xxx_change_queue_depth,
  167. .this_id = -1,
  168. .cmd_per_lun = 3,
  169. .use_clustering = ENABLE_CLUSTERING,
  170. .sg_tablesize = SG_ALL,
  171. .max_sectors = 0xFFFF,
  172. .shost_attrs = qla4xxx_host_attrs,
  173. .host_reset = qla4xxx_host_reset,
  174. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  175. };
  176. static struct iscsi_transport qla4xxx_iscsi_transport = {
  177. .owner = THIS_MODULE,
  178. .name = DRIVER_NAME,
  179. .caps = CAP_TEXT_NEGO |
  180. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  181. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  182. CAP_MULTI_R2T,
  183. .attr_is_visible = ql4_attr_is_visible,
  184. .create_session = qla4xxx_session_create,
  185. .destroy_session = qla4xxx_session_destroy,
  186. .start_conn = qla4xxx_conn_start,
  187. .create_conn = qla4xxx_conn_create,
  188. .bind_conn = qla4xxx_conn_bind,
  189. .stop_conn = iscsi_conn_stop,
  190. .destroy_conn = qla4xxx_conn_destroy,
  191. .set_param = iscsi_set_param,
  192. .get_conn_param = qla4xxx_conn_get_param,
  193. .get_session_param = qla4xxx_session_get_param,
  194. .get_ep_param = qla4xxx_get_ep_param,
  195. .ep_connect = qla4xxx_ep_connect,
  196. .ep_poll = qla4xxx_ep_poll,
  197. .ep_disconnect = qla4xxx_ep_disconnect,
  198. .get_stats = qla4xxx_conn_get_stats,
  199. .send_pdu = iscsi_conn_send_pdu,
  200. .xmit_task = qla4xxx_task_xmit,
  201. .cleanup_task = qla4xxx_task_cleanup,
  202. .alloc_pdu = qla4xxx_alloc_pdu,
  203. .get_host_param = qla4xxx_host_get_param,
  204. .set_iface_param = qla4xxx_iface_set_param,
  205. .get_iface_param = qla4xxx_get_iface_param,
  206. .bsg_request = qla4xxx_bsg_request,
  207. .send_ping = qla4xxx_send_ping,
  208. .get_chap = qla4xxx_get_chap_list,
  209. .delete_chap = qla4xxx_delete_chap,
  210. };
  211. static struct scsi_transport_template *qla4xxx_scsi_transport;
  212. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  213. uint32_t iface_type, uint32_t payload_size,
  214. uint32_t pid, struct sockaddr *dst_addr)
  215. {
  216. struct scsi_qla_host *ha = to_qla_host(shost);
  217. struct sockaddr_in *addr;
  218. struct sockaddr_in6 *addr6;
  219. uint32_t options = 0;
  220. uint8_t ipaddr[IPv6_ADDR_LEN];
  221. int rval;
  222. memset(ipaddr, 0, IPv6_ADDR_LEN);
  223. /* IPv4 to IPv4 */
  224. if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
  225. (dst_addr->sa_family == AF_INET)) {
  226. addr = (struct sockaddr_in *)dst_addr;
  227. memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
  228. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
  229. "dest: %pI4\n", __func__,
  230. &ha->ip_config.ip_address, ipaddr));
  231. rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
  232. ipaddr);
  233. if (rval)
  234. rval = -EINVAL;
  235. } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
  236. (dst_addr->sa_family == AF_INET6)) {
  237. /* IPv6 to IPv6 */
  238. addr6 = (struct sockaddr_in6 *)dst_addr;
  239. memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
  240. options |= PING_IPV6_PROTOCOL_ENABLE;
  241. /* Ping using LinkLocal address */
  242. if ((iface_num == 0) || (iface_num == 1)) {
  243. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
  244. "src: %pI6 dest: %pI6\n", __func__,
  245. &ha->ip_config.ipv6_link_local_addr,
  246. ipaddr));
  247. options |= PING_IPV6_LINKLOCAL_ADDR;
  248. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  249. pid, ipaddr);
  250. } else {
  251. ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
  252. "not supported\n", __func__, iface_num);
  253. rval = -ENOSYS;
  254. goto exit_send_ping;
  255. }
  256. /*
  257. * If ping using LinkLocal address fails, try ping using
  258. * IPv6 address
  259. */
  260. if (rval != QLA_SUCCESS) {
  261. options &= ~PING_IPV6_LINKLOCAL_ADDR;
  262. if (iface_num == 0) {
  263. options |= PING_IPV6_ADDR0;
  264. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  265. "Ping src: %pI6 "
  266. "dest: %pI6\n", __func__,
  267. &ha->ip_config.ipv6_addr0,
  268. ipaddr));
  269. } else if (iface_num == 1) {
  270. options |= PING_IPV6_ADDR1;
  271. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  272. "Ping src: %pI6 "
  273. "dest: %pI6\n", __func__,
  274. &ha->ip_config.ipv6_addr1,
  275. ipaddr));
  276. }
  277. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  278. pid, ipaddr);
  279. if (rval)
  280. rval = -EINVAL;
  281. }
  282. } else
  283. rval = -ENOSYS;
  284. exit_send_ping:
  285. return rval;
  286. }
  287. static umode_t ql4_attr_is_visible(int param_type, int param)
  288. {
  289. switch (param_type) {
  290. case ISCSI_HOST_PARAM:
  291. switch (param) {
  292. case ISCSI_HOST_PARAM_HWADDRESS:
  293. case ISCSI_HOST_PARAM_IPADDRESS:
  294. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  295. case ISCSI_HOST_PARAM_PORT_STATE:
  296. case ISCSI_HOST_PARAM_PORT_SPEED:
  297. return S_IRUGO;
  298. default:
  299. return 0;
  300. }
  301. case ISCSI_PARAM:
  302. switch (param) {
  303. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  304. case ISCSI_PARAM_PERSISTENT_PORT:
  305. case ISCSI_PARAM_CONN_ADDRESS:
  306. case ISCSI_PARAM_CONN_PORT:
  307. case ISCSI_PARAM_TARGET_NAME:
  308. case ISCSI_PARAM_TPGT:
  309. case ISCSI_PARAM_TARGET_ALIAS:
  310. case ISCSI_PARAM_MAX_BURST:
  311. case ISCSI_PARAM_MAX_R2T:
  312. case ISCSI_PARAM_FIRST_BURST:
  313. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  314. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  315. case ISCSI_PARAM_IFACE_NAME:
  316. case ISCSI_PARAM_CHAP_OUT_IDX:
  317. case ISCSI_PARAM_CHAP_IN_IDX:
  318. case ISCSI_PARAM_USERNAME:
  319. case ISCSI_PARAM_PASSWORD:
  320. case ISCSI_PARAM_USERNAME_IN:
  321. case ISCSI_PARAM_PASSWORD_IN:
  322. return S_IRUGO;
  323. default:
  324. return 0;
  325. }
  326. case ISCSI_NET_PARAM:
  327. switch (param) {
  328. case ISCSI_NET_PARAM_IPV4_ADDR:
  329. case ISCSI_NET_PARAM_IPV4_SUBNET:
  330. case ISCSI_NET_PARAM_IPV4_GW:
  331. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  332. case ISCSI_NET_PARAM_IFACE_ENABLE:
  333. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  334. case ISCSI_NET_PARAM_IPV6_ADDR:
  335. case ISCSI_NET_PARAM_IPV6_ROUTER:
  336. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  337. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  338. case ISCSI_NET_PARAM_VLAN_ID:
  339. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  340. case ISCSI_NET_PARAM_VLAN_ENABLED:
  341. case ISCSI_NET_PARAM_MTU:
  342. case ISCSI_NET_PARAM_PORT:
  343. return S_IRUGO;
  344. default:
  345. return 0;
  346. }
  347. }
  348. return 0;
  349. }
  350. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  351. uint32_t *num_entries, char *buf)
  352. {
  353. struct scsi_qla_host *ha = to_qla_host(shost);
  354. struct ql4_chap_table *chap_table;
  355. struct iscsi_chap_rec *chap_rec;
  356. int max_chap_entries = 0;
  357. int valid_chap_entries = 0;
  358. int ret = 0, i;
  359. if (is_qla8022(ha))
  360. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  361. sizeof(struct ql4_chap_table);
  362. else
  363. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  364. ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
  365. __func__, *num_entries, chap_tbl_idx);
  366. if (!buf) {
  367. ret = -ENOMEM;
  368. goto exit_get_chap_list;
  369. }
  370. chap_rec = (struct iscsi_chap_rec *) buf;
  371. mutex_lock(&ha->chap_sem);
  372. for (i = chap_tbl_idx; i < max_chap_entries; i++) {
  373. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  374. if (chap_table->cookie !=
  375. __constant_cpu_to_le16(CHAP_VALID_COOKIE))
  376. continue;
  377. chap_rec->chap_tbl_idx = i;
  378. strncpy(chap_rec->username, chap_table->name,
  379. ISCSI_CHAP_AUTH_NAME_MAX_LEN);
  380. strncpy(chap_rec->password, chap_table->secret,
  381. QL4_CHAP_MAX_SECRET_LEN);
  382. chap_rec->password_length = chap_table->secret_len;
  383. if (chap_table->flags & BIT_7) /* local */
  384. chap_rec->chap_type = CHAP_TYPE_OUT;
  385. if (chap_table->flags & BIT_6) /* peer */
  386. chap_rec->chap_type = CHAP_TYPE_IN;
  387. chap_rec++;
  388. valid_chap_entries++;
  389. if (valid_chap_entries == *num_entries)
  390. break;
  391. else
  392. continue;
  393. }
  394. mutex_unlock(&ha->chap_sem);
  395. exit_get_chap_list:
  396. ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
  397. __func__, valid_chap_entries);
  398. *num_entries = valid_chap_entries;
  399. return ret;
  400. }
  401. static int __qla4xxx_is_chap_active(struct device *dev, void *data)
  402. {
  403. int ret = 0;
  404. uint16_t *chap_tbl_idx = (uint16_t *) data;
  405. struct iscsi_cls_session *cls_session;
  406. struct iscsi_session *sess;
  407. struct ddb_entry *ddb_entry;
  408. if (!iscsi_is_session_dev(dev))
  409. goto exit_is_chap_active;
  410. cls_session = iscsi_dev_to_session(dev);
  411. sess = cls_session->dd_data;
  412. ddb_entry = sess->dd_data;
  413. if (iscsi_session_chkready(cls_session))
  414. goto exit_is_chap_active;
  415. if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
  416. ret = 1;
  417. exit_is_chap_active:
  418. return ret;
  419. }
  420. static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
  421. uint16_t chap_tbl_idx)
  422. {
  423. int ret = 0;
  424. ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
  425. __qla4xxx_is_chap_active);
  426. return ret;
  427. }
  428. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
  429. {
  430. struct scsi_qla_host *ha = to_qla_host(shost);
  431. struct ql4_chap_table *chap_table;
  432. dma_addr_t chap_dma;
  433. int max_chap_entries = 0;
  434. uint32_t offset = 0;
  435. uint32_t chap_size;
  436. int ret = 0;
  437. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  438. if (chap_table == NULL)
  439. return -ENOMEM;
  440. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  441. if (is_qla8022(ha))
  442. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  443. sizeof(struct ql4_chap_table);
  444. else
  445. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  446. if (chap_tbl_idx > max_chap_entries) {
  447. ret = -EINVAL;
  448. goto exit_delete_chap;
  449. }
  450. /* Check if chap index is in use.
  451. * If chap is in use don't delet chap entry */
  452. ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
  453. if (ret) {
  454. ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
  455. "delete from flash\n", chap_tbl_idx);
  456. ret = -EBUSY;
  457. goto exit_delete_chap;
  458. }
  459. chap_size = sizeof(struct ql4_chap_table);
  460. if (is_qla40XX(ha))
  461. offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
  462. else {
  463. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  464. /* flt_chap_size is CHAP table size for both ports
  465. * so divide it by 2 to calculate the offset for second port
  466. */
  467. if (ha->port_num == 1)
  468. offset += (ha->hw.flt_chap_size / 2);
  469. offset += (chap_tbl_idx * chap_size);
  470. }
  471. ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  472. if (ret != QLA_SUCCESS) {
  473. ret = -EINVAL;
  474. goto exit_delete_chap;
  475. }
  476. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  477. __le16_to_cpu(chap_table->cookie)));
  478. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  479. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  480. goto exit_delete_chap;
  481. }
  482. chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
  483. offset = FLASH_CHAP_OFFSET |
  484. (chap_tbl_idx * sizeof(struct ql4_chap_table));
  485. ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
  486. FLASH_OPT_RMW_COMMIT);
  487. if (ret == QLA_SUCCESS && ha->chap_list) {
  488. mutex_lock(&ha->chap_sem);
  489. /* Update ha chap_list cache */
  490. memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
  491. chap_table, sizeof(struct ql4_chap_table));
  492. mutex_unlock(&ha->chap_sem);
  493. }
  494. if (ret != QLA_SUCCESS)
  495. ret = -EINVAL;
  496. exit_delete_chap:
  497. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  498. return ret;
  499. }
  500. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  501. enum iscsi_param_type param_type,
  502. int param, char *buf)
  503. {
  504. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  505. struct scsi_qla_host *ha = to_qla_host(shost);
  506. int len = -ENOSYS;
  507. if (param_type != ISCSI_NET_PARAM)
  508. return -ENOSYS;
  509. switch (param) {
  510. case ISCSI_NET_PARAM_IPV4_ADDR:
  511. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  512. break;
  513. case ISCSI_NET_PARAM_IPV4_SUBNET:
  514. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  515. break;
  516. case ISCSI_NET_PARAM_IPV4_GW:
  517. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  518. break;
  519. case ISCSI_NET_PARAM_IFACE_ENABLE:
  520. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  521. len = sprintf(buf, "%s\n",
  522. (ha->ip_config.ipv4_options &
  523. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  524. "enabled" : "disabled");
  525. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  526. len = sprintf(buf, "%s\n",
  527. (ha->ip_config.ipv6_options &
  528. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  529. "enabled" : "disabled");
  530. break;
  531. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  532. len = sprintf(buf, "%s\n",
  533. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  534. "dhcp" : "static");
  535. break;
  536. case ISCSI_NET_PARAM_IPV6_ADDR:
  537. if (iface->iface_num == 0)
  538. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  539. if (iface->iface_num == 1)
  540. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  541. break;
  542. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  543. len = sprintf(buf, "%pI6\n",
  544. &ha->ip_config.ipv6_link_local_addr);
  545. break;
  546. case ISCSI_NET_PARAM_IPV6_ROUTER:
  547. len = sprintf(buf, "%pI6\n",
  548. &ha->ip_config.ipv6_default_router_addr);
  549. break;
  550. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  551. len = sprintf(buf, "%s\n",
  552. (ha->ip_config.ipv6_addl_options &
  553. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  554. "nd" : "static");
  555. break;
  556. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  557. len = sprintf(buf, "%s\n",
  558. (ha->ip_config.ipv6_addl_options &
  559. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  560. "auto" : "static");
  561. break;
  562. case ISCSI_NET_PARAM_VLAN_ID:
  563. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  564. len = sprintf(buf, "%d\n",
  565. (ha->ip_config.ipv4_vlan_tag &
  566. ISCSI_MAX_VLAN_ID));
  567. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  568. len = sprintf(buf, "%d\n",
  569. (ha->ip_config.ipv6_vlan_tag &
  570. ISCSI_MAX_VLAN_ID));
  571. break;
  572. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  573. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  574. len = sprintf(buf, "%d\n",
  575. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  576. ISCSI_MAX_VLAN_PRIORITY));
  577. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  578. len = sprintf(buf, "%d\n",
  579. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  580. ISCSI_MAX_VLAN_PRIORITY));
  581. break;
  582. case ISCSI_NET_PARAM_VLAN_ENABLED:
  583. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  584. len = sprintf(buf, "%s\n",
  585. (ha->ip_config.ipv4_options &
  586. IPOPT_VLAN_TAGGING_ENABLE) ?
  587. "enabled" : "disabled");
  588. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  589. len = sprintf(buf, "%s\n",
  590. (ha->ip_config.ipv6_options &
  591. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  592. "enabled" : "disabled");
  593. break;
  594. case ISCSI_NET_PARAM_MTU:
  595. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  596. break;
  597. case ISCSI_NET_PARAM_PORT:
  598. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  599. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
  600. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  601. len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
  602. break;
  603. default:
  604. len = -ENOSYS;
  605. }
  606. return len;
  607. }
  608. static struct iscsi_endpoint *
  609. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  610. int non_blocking)
  611. {
  612. int ret;
  613. struct iscsi_endpoint *ep;
  614. struct qla_endpoint *qla_ep;
  615. struct scsi_qla_host *ha;
  616. struct sockaddr_in *addr;
  617. struct sockaddr_in6 *addr6;
  618. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  619. if (!shost) {
  620. ret = -ENXIO;
  621. printk(KERN_ERR "%s: shost is NULL\n",
  622. __func__);
  623. return ERR_PTR(ret);
  624. }
  625. ha = iscsi_host_priv(shost);
  626. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  627. if (!ep) {
  628. ret = -ENOMEM;
  629. return ERR_PTR(ret);
  630. }
  631. qla_ep = ep->dd_data;
  632. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  633. if (dst_addr->sa_family == AF_INET) {
  634. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  635. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  636. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  637. (char *)&addr->sin_addr));
  638. } else if (dst_addr->sa_family == AF_INET6) {
  639. memcpy(&qla_ep->dst_addr, dst_addr,
  640. sizeof(struct sockaddr_in6));
  641. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  642. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  643. (char *)&addr6->sin6_addr));
  644. }
  645. qla_ep->host = shost;
  646. return ep;
  647. }
  648. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  649. {
  650. struct qla_endpoint *qla_ep;
  651. struct scsi_qla_host *ha;
  652. int ret = 0;
  653. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  654. qla_ep = ep->dd_data;
  655. ha = to_qla_host(qla_ep->host);
  656. if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
  657. ret = 1;
  658. return ret;
  659. }
  660. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  661. {
  662. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  663. iscsi_destroy_endpoint(ep);
  664. }
  665. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  666. enum iscsi_param param,
  667. char *buf)
  668. {
  669. struct qla_endpoint *qla_ep = ep->dd_data;
  670. struct sockaddr *dst_addr;
  671. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  672. switch (param) {
  673. case ISCSI_PARAM_CONN_PORT:
  674. case ISCSI_PARAM_CONN_ADDRESS:
  675. if (!qla_ep)
  676. return -ENOTCONN;
  677. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  678. if (!dst_addr)
  679. return -ENOTCONN;
  680. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  681. &qla_ep->dst_addr, param, buf);
  682. default:
  683. return -ENOSYS;
  684. }
  685. }
  686. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  687. struct iscsi_stats *stats)
  688. {
  689. struct iscsi_session *sess;
  690. struct iscsi_cls_session *cls_sess;
  691. struct ddb_entry *ddb_entry;
  692. struct scsi_qla_host *ha;
  693. struct ql_iscsi_stats *ql_iscsi_stats;
  694. int stats_size;
  695. int ret;
  696. dma_addr_t iscsi_stats_dma;
  697. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  698. cls_sess = iscsi_conn_to_session(cls_conn);
  699. sess = cls_sess->dd_data;
  700. ddb_entry = sess->dd_data;
  701. ha = ddb_entry->ha;
  702. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  703. /* Allocate memory */
  704. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  705. &iscsi_stats_dma, GFP_KERNEL);
  706. if (!ql_iscsi_stats) {
  707. ql4_printk(KERN_ERR, ha,
  708. "Unable to allocate memory for iscsi stats\n");
  709. goto exit_get_stats;
  710. }
  711. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  712. iscsi_stats_dma);
  713. if (ret != QLA_SUCCESS) {
  714. ql4_printk(KERN_ERR, ha,
  715. "Unable to retreive iscsi stats\n");
  716. goto free_stats;
  717. }
  718. /* octets */
  719. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  720. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  721. /* xmit pdus */
  722. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  723. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  724. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  725. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  726. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  727. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  728. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  729. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  730. /* recv pdus */
  731. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  732. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  733. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  734. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  735. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  736. stats->logoutrsp_pdus =
  737. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  738. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  739. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  740. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  741. free_stats:
  742. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  743. iscsi_stats_dma);
  744. exit_get_stats:
  745. return;
  746. }
  747. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  748. {
  749. struct iscsi_cls_session *session;
  750. struct iscsi_session *sess;
  751. unsigned long flags;
  752. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  753. session = starget_to_session(scsi_target(sc->device));
  754. sess = session->dd_data;
  755. spin_lock_irqsave(&session->lock, flags);
  756. if (session->state == ISCSI_SESSION_FAILED)
  757. ret = BLK_EH_RESET_TIMER;
  758. spin_unlock_irqrestore(&session->lock, flags);
  759. return ret;
  760. }
  761. static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
  762. {
  763. struct scsi_qla_host *ha = to_qla_host(shost);
  764. struct iscsi_cls_host *ihost = shost->shost_data;
  765. uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
  766. qla4xxx_get_firmware_state(ha);
  767. switch (ha->addl_fw_state & 0x0F00) {
  768. case FW_ADDSTATE_LINK_SPEED_10MBPS:
  769. speed = ISCSI_PORT_SPEED_10MBPS;
  770. break;
  771. case FW_ADDSTATE_LINK_SPEED_100MBPS:
  772. speed = ISCSI_PORT_SPEED_100MBPS;
  773. break;
  774. case FW_ADDSTATE_LINK_SPEED_1GBPS:
  775. speed = ISCSI_PORT_SPEED_1GBPS;
  776. break;
  777. case FW_ADDSTATE_LINK_SPEED_10GBPS:
  778. speed = ISCSI_PORT_SPEED_10GBPS;
  779. break;
  780. }
  781. ihost->port_speed = speed;
  782. }
  783. static void qla4xxx_set_port_state(struct Scsi_Host *shost)
  784. {
  785. struct scsi_qla_host *ha = to_qla_host(shost);
  786. struct iscsi_cls_host *ihost = shost->shost_data;
  787. uint32_t state = ISCSI_PORT_STATE_DOWN;
  788. if (test_bit(AF_LINK_UP, &ha->flags))
  789. state = ISCSI_PORT_STATE_UP;
  790. ihost->port_state = state;
  791. }
  792. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  793. enum iscsi_host_param param, char *buf)
  794. {
  795. struct scsi_qla_host *ha = to_qla_host(shost);
  796. int len;
  797. switch (param) {
  798. case ISCSI_HOST_PARAM_HWADDRESS:
  799. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  800. break;
  801. case ISCSI_HOST_PARAM_IPADDRESS:
  802. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  803. break;
  804. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  805. len = sprintf(buf, "%s\n", ha->name_string);
  806. break;
  807. case ISCSI_HOST_PARAM_PORT_STATE:
  808. qla4xxx_set_port_state(shost);
  809. len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  810. break;
  811. case ISCSI_HOST_PARAM_PORT_SPEED:
  812. qla4xxx_set_port_speed(shost);
  813. len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  814. break;
  815. default:
  816. return -ENOSYS;
  817. }
  818. return len;
  819. }
  820. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  821. {
  822. if (ha->iface_ipv4)
  823. return;
  824. /* IPv4 */
  825. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  826. &qla4xxx_iscsi_transport,
  827. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  828. if (!ha->iface_ipv4)
  829. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  830. "iface0.\n");
  831. }
  832. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  833. {
  834. if (!ha->iface_ipv6_0)
  835. /* IPv6 iface-0 */
  836. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  837. &qla4xxx_iscsi_transport,
  838. ISCSI_IFACE_TYPE_IPV6, 0,
  839. 0);
  840. if (!ha->iface_ipv6_0)
  841. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  842. "iface0.\n");
  843. if (!ha->iface_ipv6_1)
  844. /* IPv6 iface-1 */
  845. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  846. &qla4xxx_iscsi_transport,
  847. ISCSI_IFACE_TYPE_IPV6, 1,
  848. 0);
  849. if (!ha->iface_ipv6_1)
  850. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  851. "iface1.\n");
  852. }
  853. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  854. {
  855. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  856. qla4xxx_create_ipv4_iface(ha);
  857. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  858. qla4xxx_create_ipv6_iface(ha);
  859. }
  860. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  861. {
  862. if (ha->iface_ipv4) {
  863. iscsi_destroy_iface(ha->iface_ipv4);
  864. ha->iface_ipv4 = NULL;
  865. }
  866. }
  867. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  868. {
  869. if (ha->iface_ipv6_0) {
  870. iscsi_destroy_iface(ha->iface_ipv6_0);
  871. ha->iface_ipv6_0 = NULL;
  872. }
  873. if (ha->iface_ipv6_1) {
  874. iscsi_destroy_iface(ha->iface_ipv6_1);
  875. ha->iface_ipv6_1 = NULL;
  876. }
  877. }
  878. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  879. {
  880. qla4xxx_destroy_ipv4_iface(ha);
  881. qla4xxx_destroy_ipv6_iface(ha);
  882. }
  883. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  884. struct iscsi_iface_param_info *iface_param,
  885. struct addr_ctrl_blk *init_fw_cb)
  886. {
  887. /*
  888. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  889. * iface_num 1 is valid only for IPv6 Addr.
  890. */
  891. switch (iface_param->param) {
  892. case ISCSI_NET_PARAM_IPV6_ADDR:
  893. if (iface_param->iface_num & 0x1)
  894. /* IPv6 Addr 1 */
  895. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  896. sizeof(init_fw_cb->ipv6_addr1));
  897. else
  898. /* IPv6 Addr 0 */
  899. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  900. sizeof(init_fw_cb->ipv6_addr0));
  901. break;
  902. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  903. if (iface_param->iface_num & 0x1)
  904. break;
  905. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  906. sizeof(init_fw_cb->ipv6_if_id));
  907. break;
  908. case ISCSI_NET_PARAM_IPV6_ROUTER:
  909. if (iface_param->iface_num & 0x1)
  910. break;
  911. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  912. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  913. break;
  914. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  915. /* Autocfg applies to even interface */
  916. if (iface_param->iface_num & 0x1)
  917. break;
  918. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  919. init_fw_cb->ipv6_addtl_opts &=
  920. cpu_to_le16(
  921. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  922. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  923. init_fw_cb->ipv6_addtl_opts |=
  924. cpu_to_le16(
  925. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  926. else
  927. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  928. "IPv6 addr\n");
  929. break;
  930. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  931. /* Autocfg applies to even interface */
  932. if (iface_param->iface_num & 0x1)
  933. break;
  934. if (iface_param->value[0] ==
  935. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  936. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  937. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  938. else if (iface_param->value[0] ==
  939. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  940. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  941. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  942. else
  943. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  944. "IPv6 linklocal addr\n");
  945. break;
  946. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  947. /* Autocfg applies to even interface */
  948. if (iface_param->iface_num & 0x1)
  949. break;
  950. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  951. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  952. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  953. break;
  954. case ISCSI_NET_PARAM_IFACE_ENABLE:
  955. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  956. init_fw_cb->ipv6_opts |=
  957. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  958. qla4xxx_create_ipv6_iface(ha);
  959. } else {
  960. init_fw_cb->ipv6_opts &=
  961. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  962. 0xFFFF);
  963. qla4xxx_destroy_ipv6_iface(ha);
  964. }
  965. break;
  966. case ISCSI_NET_PARAM_VLAN_TAG:
  967. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  968. break;
  969. init_fw_cb->ipv6_vlan_tag =
  970. cpu_to_be16(*(uint16_t *)iface_param->value);
  971. break;
  972. case ISCSI_NET_PARAM_VLAN_ENABLED:
  973. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  974. init_fw_cb->ipv6_opts |=
  975. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  976. else
  977. init_fw_cb->ipv6_opts &=
  978. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  979. break;
  980. case ISCSI_NET_PARAM_MTU:
  981. init_fw_cb->eth_mtu_size =
  982. cpu_to_le16(*(uint16_t *)iface_param->value);
  983. break;
  984. case ISCSI_NET_PARAM_PORT:
  985. /* Autocfg applies to even interface */
  986. if (iface_param->iface_num & 0x1)
  987. break;
  988. init_fw_cb->ipv6_port =
  989. cpu_to_le16(*(uint16_t *)iface_param->value);
  990. break;
  991. default:
  992. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  993. iface_param->param);
  994. break;
  995. }
  996. }
  997. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  998. struct iscsi_iface_param_info *iface_param,
  999. struct addr_ctrl_blk *init_fw_cb)
  1000. {
  1001. switch (iface_param->param) {
  1002. case ISCSI_NET_PARAM_IPV4_ADDR:
  1003. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  1004. sizeof(init_fw_cb->ipv4_addr));
  1005. break;
  1006. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1007. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  1008. sizeof(init_fw_cb->ipv4_subnet));
  1009. break;
  1010. case ISCSI_NET_PARAM_IPV4_GW:
  1011. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  1012. sizeof(init_fw_cb->ipv4_gw_addr));
  1013. break;
  1014. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1015. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  1016. init_fw_cb->ipv4_tcp_opts |=
  1017. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  1018. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  1019. init_fw_cb->ipv4_tcp_opts &=
  1020. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  1021. else
  1022. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  1023. break;
  1024. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1025. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1026. init_fw_cb->ipv4_ip_opts |=
  1027. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  1028. qla4xxx_create_ipv4_iface(ha);
  1029. } else {
  1030. init_fw_cb->ipv4_ip_opts &=
  1031. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  1032. 0xFFFF);
  1033. qla4xxx_destroy_ipv4_iface(ha);
  1034. }
  1035. break;
  1036. case ISCSI_NET_PARAM_VLAN_TAG:
  1037. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  1038. break;
  1039. init_fw_cb->ipv4_vlan_tag =
  1040. cpu_to_be16(*(uint16_t *)iface_param->value);
  1041. break;
  1042. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1043. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1044. init_fw_cb->ipv4_ip_opts |=
  1045. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  1046. else
  1047. init_fw_cb->ipv4_ip_opts &=
  1048. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  1049. break;
  1050. case ISCSI_NET_PARAM_MTU:
  1051. init_fw_cb->eth_mtu_size =
  1052. cpu_to_le16(*(uint16_t *)iface_param->value);
  1053. break;
  1054. case ISCSI_NET_PARAM_PORT:
  1055. init_fw_cb->ipv4_port =
  1056. cpu_to_le16(*(uint16_t *)iface_param->value);
  1057. break;
  1058. default:
  1059. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  1060. iface_param->param);
  1061. break;
  1062. }
  1063. }
  1064. static void
  1065. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  1066. {
  1067. struct addr_ctrl_blk_def *acb;
  1068. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  1069. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  1070. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  1071. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  1072. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  1073. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  1074. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  1075. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  1076. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  1077. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  1078. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  1079. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  1080. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  1081. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  1082. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  1083. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  1084. }
  1085. static int
  1086. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  1087. {
  1088. struct scsi_qla_host *ha = to_qla_host(shost);
  1089. int rval = 0;
  1090. struct iscsi_iface_param_info *iface_param = NULL;
  1091. struct addr_ctrl_blk *init_fw_cb = NULL;
  1092. dma_addr_t init_fw_cb_dma;
  1093. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1094. uint32_t mbox_sts[MBOX_REG_COUNT];
  1095. uint32_t rem = len;
  1096. struct nlattr *attr;
  1097. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  1098. sizeof(struct addr_ctrl_blk),
  1099. &init_fw_cb_dma, GFP_KERNEL);
  1100. if (!init_fw_cb) {
  1101. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  1102. __func__);
  1103. return -ENOMEM;
  1104. }
  1105. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1106. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1107. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1108. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  1109. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  1110. rval = -EIO;
  1111. goto exit_init_fw_cb;
  1112. }
  1113. nla_for_each_attr(attr, data, len, rem) {
  1114. iface_param = nla_data(attr);
  1115. if (iface_param->param_type != ISCSI_NET_PARAM)
  1116. continue;
  1117. switch (iface_param->iface_type) {
  1118. case ISCSI_IFACE_TYPE_IPV4:
  1119. switch (iface_param->iface_num) {
  1120. case 0:
  1121. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  1122. break;
  1123. default:
  1124. /* Cannot have more than one IPv4 interface */
  1125. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  1126. "number = %d\n",
  1127. iface_param->iface_num);
  1128. break;
  1129. }
  1130. break;
  1131. case ISCSI_IFACE_TYPE_IPV6:
  1132. switch (iface_param->iface_num) {
  1133. case 0:
  1134. case 1:
  1135. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  1136. break;
  1137. default:
  1138. /* Cannot have more than two IPv6 interface */
  1139. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  1140. "number = %d\n",
  1141. iface_param->iface_num);
  1142. break;
  1143. }
  1144. break;
  1145. default:
  1146. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  1147. break;
  1148. }
  1149. }
  1150. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  1151. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  1152. sizeof(struct addr_ctrl_blk),
  1153. FLASH_OPT_RMW_COMMIT);
  1154. if (rval != QLA_SUCCESS) {
  1155. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  1156. __func__);
  1157. rval = -EIO;
  1158. goto exit_init_fw_cb;
  1159. }
  1160. rval = qla4xxx_disable_acb(ha);
  1161. if (rval != QLA_SUCCESS) {
  1162. ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
  1163. __func__);
  1164. rval = -EIO;
  1165. goto exit_init_fw_cb;
  1166. }
  1167. wait_for_completion_timeout(&ha->disable_acb_comp,
  1168. DISABLE_ACB_TOV * HZ);
  1169. qla4xxx_initcb_to_acb(init_fw_cb);
  1170. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  1171. if (rval != QLA_SUCCESS) {
  1172. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  1173. __func__);
  1174. rval = -EIO;
  1175. goto exit_init_fw_cb;
  1176. }
  1177. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1178. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  1179. init_fw_cb_dma);
  1180. exit_init_fw_cb:
  1181. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  1182. init_fw_cb, init_fw_cb_dma);
  1183. return rval;
  1184. }
  1185. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  1186. enum iscsi_param param, char *buf)
  1187. {
  1188. struct iscsi_session *sess = cls_sess->dd_data;
  1189. struct ddb_entry *ddb_entry = sess->dd_data;
  1190. struct scsi_qla_host *ha = ddb_entry->ha;
  1191. int rval, len;
  1192. uint16_t idx;
  1193. switch (param) {
  1194. case ISCSI_PARAM_CHAP_IN_IDX:
  1195. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  1196. sess->password_in, BIDI_CHAP,
  1197. &idx);
  1198. if (rval)
  1199. return -EINVAL;
  1200. len = sprintf(buf, "%hu\n", idx);
  1201. break;
  1202. case ISCSI_PARAM_CHAP_OUT_IDX:
  1203. rval = qla4xxx_get_chap_index(ha, sess->username,
  1204. sess->password, LOCAL_CHAP,
  1205. &idx);
  1206. if (rval)
  1207. return -EINVAL;
  1208. len = sprintf(buf, "%hu\n", idx);
  1209. break;
  1210. default:
  1211. return iscsi_session_get_param(cls_sess, param, buf);
  1212. }
  1213. return len;
  1214. }
  1215. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  1216. enum iscsi_param param, char *buf)
  1217. {
  1218. struct iscsi_conn *conn;
  1219. struct qla_conn *qla_conn;
  1220. struct sockaddr *dst_addr;
  1221. int len = 0;
  1222. conn = cls_conn->dd_data;
  1223. qla_conn = conn->dd_data;
  1224. dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
  1225. switch (param) {
  1226. case ISCSI_PARAM_CONN_PORT:
  1227. case ISCSI_PARAM_CONN_ADDRESS:
  1228. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  1229. dst_addr, param, buf);
  1230. default:
  1231. return iscsi_conn_get_param(cls_conn, param, buf);
  1232. }
  1233. return len;
  1234. }
  1235. int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
  1236. {
  1237. uint32_t mbx_sts = 0;
  1238. uint16_t tmp_ddb_index;
  1239. int ret;
  1240. get_ddb_index:
  1241. tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  1242. if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
  1243. DEBUG2(ql4_printk(KERN_INFO, ha,
  1244. "Free DDB index not available\n"));
  1245. ret = QLA_ERROR;
  1246. goto exit_get_ddb_index;
  1247. }
  1248. if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
  1249. goto get_ddb_index;
  1250. DEBUG2(ql4_printk(KERN_INFO, ha,
  1251. "Found a free DDB index at %d\n", tmp_ddb_index));
  1252. ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
  1253. if (ret == QLA_ERROR) {
  1254. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  1255. ql4_printk(KERN_INFO, ha,
  1256. "DDB index = %d not available trying next\n",
  1257. tmp_ddb_index);
  1258. goto get_ddb_index;
  1259. }
  1260. DEBUG2(ql4_printk(KERN_INFO, ha,
  1261. "Free FW DDB not available\n"));
  1262. }
  1263. *ddb_index = tmp_ddb_index;
  1264. exit_get_ddb_index:
  1265. return ret;
  1266. }
  1267. static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
  1268. struct ddb_entry *ddb_entry,
  1269. char *existing_ipaddr,
  1270. char *user_ipaddr)
  1271. {
  1272. uint8_t dst_ipaddr[IPv6_ADDR_LEN];
  1273. char formatted_ipaddr[DDB_IPADDR_LEN];
  1274. int status = QLA_SUCCESS, ret = 0;
  1275. if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
  1276. ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1277. '\0', NULL);
  1278. if (ret == 0) {
  1279. status = QLA_ERROR;
  1280. goto out_match;
  1281. }
  1282. ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
  1283. } else {
  1284. ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1285. '\0', NULL);
  1286. if (ret == 0) {
  1287. status = QLA_ERROR;
  1288. goto out_match;
  1289. }
  1290. ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
  1291. }
  1292. if (strcmp(existing_ipaddr, formatted_ipaddr))
  1293. status = QLA_ERROR;
  1294. out_match:
  1295. return status;
  1296. }
  1297. static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
  1298. struct iscsi_cls_conn *cls_conn)
  1299. {
  1300. int idx = 0, max_ddbs, rval;
  1301. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1302. struct iscsi_session *sess, *existing_sess;
  1303. struct iscsi_conn *conn, *existing_conn;
  1304. struct ddb_entry *ddb_entry;
  1305. sess = cls_sess->dd_data;
  1306. conn = cls_conn->dd_data;
  1307. if (sess->targetname == NULL ||
  1308. conn->persistent_address == NULL ||
  1309. conn->persistent_port == 0)
  1310. return QLA_ERROR;
  1311. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  1312. MAX_DEV_DB_ENTRIES;
  1313. for (idx = 0; idx < max_ddbs; idx++) {
  1314. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  1315. if (ddb_entry == NULL)
  1316. continue;
  1317. if (ddb_entry->ddb_type != FLASH_DDB)
  1318. continue;
  1319. existing_sess = ddb_entry->sess->dd_data;
  1320. existing_conn = ddb_entry->conn->dd_data;
  1321. if (existing_sess->targetname == NULL ||
  1322. existing_conn->persistent_address == NULL ||
  1323. existing_conn->persistent_port == 0)
  1324. continue;
  1325. DEBUG2(ql4_printk(KERN_INFO, ha,
  1326. "IQN = %s User IQN = %s\n",
  1327. existing_sess->targetname,
  1328. sess->targetname));
  1329. DEBUG2(ql4_printk(KERN_INFO, ha,
  1330. "IP = %s User IP = %s\n",
  1331. existing_conn->persistent_address,
  1332. conn->persistent_address));
  1333. DEBUG2(ql4_printk(KERN_INFO, ha,
  1334. "Port = %d User Port = %d\n",
  1335. existing_conn->persistent_port,
  1336. conn->persistent_port));
  1337. if (strcmp(existing_sess->targetname, sess->targetname))
  1338. continue;
  1339. rval = qla4xxx_match_ipaddress(ha, ddb_entry,
  1340. existing_conn->persistent_address,
  1341. conn->persistent_address);
  1342. if (rval == QLA_ERROR)
  1343. continue;
  1344. if (existing_conn->persistent_port != conn->persistent_port)
  1345. continue;
  1346. break;
  1347. }
  1348. if (idx == max_ddbs)
  1349. return QLA_ERROR;
  1350. DEBUG2(ql4_printk(KERN_INFO, ha,
  1351. "Match found in fwdb sessions\n"));
  1352. return QLA_SUCCESS;
  1353. }
  1354. static struct iscsi_cls_session *
  1355. qla4xxx_session_create(struct iscsi_endpoint *ep,
  1356. uint16_t cmds_max, uint16_t qdepth,
  1357. uint32_t initial_cmdsn)
  1358. {
  1359. struct iscsi_cls_session *cls_sess;
  1360. struct scsi_qla_host *ha;
  1361. struct qla_endpoint *qla_ep;
  1362. struct ddb_entry *ddb_entry;
  1363. uint16_t ddb_index;
  1364. struct iscsi_session *sess;
  1365. struct sockaddr *dst_addr;
  1366. int ret;
  1367. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1368. if (!ep) {
  1369. printk(KERN_ERR "qla4xxx: missing ep.\n");
  1370. return NULL;
  1371. }
  1372. qla_ep = ep->dd_data;
  1373. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  1374. ha = to_qla_host(qla_ep->host);
  1375. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  1376. if (ret == QLA_ERROR)
  1377. return NULL;
  1378. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  1379. cmds_max, sizeof(struct ddb_entry),
  1380. sizeof(struct ql4_task_data),
  1381. initial_cmdsn, ddb_index);
  1382. if (!cls_sess)
  1383. return NULL;
  1384. sess = cls_sess->dd_data;
  1385. ddb_entry = sess->dd_data;
  1386. ddb_entry->fw_ddb_index = ddb_index;
  1387. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  1388. ddb_entry->ha = ha;
  1389. ddb_entry->sess = cls_sess;
  1390. ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
  1391. ddb_entry->ddb_change = qla4xxx_ddb_change;
  1392. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  1393. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  1394. ha->tot_ddbs++;
  1395. return cls_sess;
  1396. }
  1397. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  1398. {
  1399. struct iscsi_session *sess;
  1400. struct ddb_entry *ddb_entry;
  1401. struct scsi_qla_host *ha;
  1402. unsigned long flags, wtime;
  1403. struct dev_db_entry *fw_ddb_entry = NULL;
  1404. dma_addr_t fw_ddb_entry_dma;
  1405. uint32_t ddb_state;
  1406. int ret;
  1407. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1408. sess = cls_sess->dd_data;
  1409. ddb_entry = sess->dd_data;
  1410. ha = ddb_entry->ha;
  1411. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1412. &fw_ddb_entry_dma, GFP_KERNEL);
  1413. if (!fw_ddb_entry) {
  1414. ql4_printk(KERN_ERR, ha,
  1415. "%s: Unable to allocate dma buffer\n", __func__);
  1416. goto destroy_session;
  1417. }
  1418. wtime = jiffies + (HZ * LOGOUT_TOV);
  1419. do {
  1420. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  1421. fw_ddb_entry, fw_ddb_entry_dma,
  1422. NULL, NULL, &ddb_state, NULL,
  1423. NULL, NULL);
  1424. if (ret == QLA_ERROR)
  1425. goto destroy_session;
  1426. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  1427. (ddb_state == DDB_DS_SESSION_FAILED))
  1428. goto destroy_session;
  1429. schedule_timeout_uninterruptible(HZ);
  1430. } while ((time_after(wtime, jiffies)));
  1431. destroy_session:
  1432. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  1433. spin_lock_irqsave(&ha->hardware_lock, flags);
  1434. qla4xxx_free_ddb(ha, ddb_entry);
  1435. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1436. iscsi_session_teardown(cls_sess);
  1437. if (fw_ddb_entry)
  1438. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1439. fw_ddb_entry, fw_ddb_entry_dma);
  1440. }
  1441. static struct iscsi_cls_conn *
  1442. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  1443. {
  1444. struct iscsi_cls_conn *cls_conn;
  1445. struct iscsi_session *sess;
  1446. struct ddb_entry *ddb_entry;
  1447. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1448. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  1449. conn_idx);
  1450. if (!cls_conn)
  1451. return NULL;
  1452. sess = cls_sess->dd_data;
  1453. ddb_entry = sess->dd_data;
  1454. ddb_entry->conn = cls_conn;
  1455. return cls_conn;
  1456. }
  1457. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  1458. struct iscsi_cls_conn *cls_conn,
  1459. uint64_t transport_fd, int is_leading)
  1460. {
  1461. struct iscsi_conn *conn;
  1462. struct qla_conn *qla_conn;
  1463. struct iscsi_endpoint *ep;
  1464. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1465. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  1466. return -EINVAL;
  1467. ep = iscsi_lookup_endpoint(transport_fd);
  1468. conn = cls_conn->dd_data;
  1469. qla_conn = conn->dd_data;
  1470. qla_conn->qla_ep = ep->dd_data;
  1471. return 0;
  1472. }
  1473. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  1474. {
  1475. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1476. struct iscsi_session *sess;
  1477. struct ddb_entry *ddb_entry;
  1478. struct scsi_qla_host *ha;
  1479. struct dev_db_entry *fw_ddb_entry = NULL;
  1480. dma_addr_t fw_ddb_entry_dma;
  1481. uint32_t mbx_sts = 0;
  1482. int ret = 0;
  1483. int status = QLA_SUCCESS;
  1484. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1485. sess = cls_sess->dd_data;
  1486. ddb_entry = sess->dd_data;
  1487. ha = ddb_entry->ha;
  1488. /* Check if we have matching FW DDB, if yes then do not
  1489. * login to this target. This could cause target to logout previous
  1490. * connection
  1491. */
  1492. ret = qla4xxx_match_fwdb_session(ha, cls_conn);
  1493. if (ret == QLA_SUCCESS) {
  1494. ql4_printk(KERN_INFO, ha,
  1495. "Session already exist in FW.\n");
  1496. ret = -EEXIST;
  1497. goto exit_conn_start;
  1498. }
  1499. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1500. &fw_ddb_entry_dma, GFP_KERNEL);
  1501. if (!fw_ddb_entry) {
  1502. ql4_printk(KERN_ERR, ha,
  1503. "%s: Unable to allocate dma buffer\n", __func__);
  1504. ret = -ENOMEM;
  1505. goto exit_conn_start;
  1506. }
  1507. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  1508. if (ret) {
  1509. /* If iscsid is stopped and started then no need to do
  1510. * set param again since ddb state will be already
  1511. * active and FW does not allow set ddb to an
  1512. * active session.
  1513. */
  1514. if (mbx_sts)
  1515. if (ddb_entry->fw_ddb_device_state ==
  1516. DDB_DS_SESSION_ACTIVE) {
  1517. ddb_entry->unblock_sess(ddb_entry->sess);
  1518. goto exit_set_param;
  1519. }
  1520. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  1521. __func__, ddb_entry->fw_ddb_index);
  1522. goto exit_conn_start;
  1523. }
  1524. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  1525. if (status == QLA_ERROR) {
  1526. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  1527. sess->targetname);
  1528. ret = -EINVAL;
  1529. goto exit_conn_start;
  1530. }
  1531. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  1532. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  1533. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  1534. ddb_entry->fw_ddb_device_state));
  1535. exit_set_param:
  1536. ret = 0;
  1537. exit_conn_start:
  1538. if (fw_ddb_entry)
  1539. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1540. fw_ddb_entry, fw_ddb_entry_dma);
  1541. return ret;
  1542. }
  1543. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1544. {
  1545. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1546. struct iscsi_session *sess;
  1547. struct scsi_qla_host *ha;
  1548. struct ddb_entry *ddb_entry;
  1549. int options;
  1550. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1551. sess = cls_sess->dd_data;
  1552. ddb_entry = sess->dd_data;
  1553. ha = ddb_entry->ha;
  1554. options = LOGOUT_OPTION_CLOSE_SESSION;
  1555. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  1556. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  1557. }
  1558. static void qla4xxx_task_work(struct work_struct *wdata)
  1559. {
  1560. struct ql4_task_data *task_data;
  1561. struct scsi_qla_host *ha;
  1562. struct passthru_status *sts;
  1563. struct iscsi_task *task;
  1564. struct iscsi_hdr *hdr;
  1565. uint8_t *data;
  1566. uint32_t data_len;
  1567. struct iscsi_conn *conn;
  1568. int hdr_len;
  1569. itt_t itt;
  1570. task_data = container_of(wdata, struct ql4_task_data, task_work);
  1571. ha = task_data->ha;
  1572. task = task_data->task;
  1573. sts = &task_data->sts;
  1574. hdr_len = sizeof(struct iscsi_hdr);
  1575. DEBUG3(printk(KERN_INFO "Status returned\n"));
  1576. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  1577. DEBUG3(printk(KERN_INFO "Response buffer"));
  1578. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  1579. conn = task->conn;
  1580. switch (sts->completionStatus) {
  1581. case PASSTHRU_STATUS_COMPLETE:
  1582. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  1583. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  1584. itt = sts->handle;
  1585. hdr->itt = itt;
  1586. data = task_data->resp_buffer + hdr_len;
  1587. data_len = task_data->resp_len - hdr_len;
  1588. iscsi_complete_pdu(conn, hdr, data, data_len);
  1589. break;
  1590. default:
  1591. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  1592. sts->completionStatus);
  1593. break;
  1594. }
  1595. return;
  1596. }
  1597. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  1598. {
  1599. struct ql4_task_data *task_data;
  1600. struct iscsi_session *sess;
  1601. struct ddb_entry *ddb_entry;
  1602. struct scsi_qla_host *ha;
  1603. int hdr_len;
  1604. sess = task->conn->session;
  1605. ddb_entry = sess->dd_data;
  1606. ha = ddb_entry->ha;
  1607. task_data = task->dd_data;
  1608. memset(task_data, 0, sizeof(struct ql4_task_data));
  1609. if (task->sc) {
  1610. ql4_printk(KERN_INFO, ha,
  1611. "%s: SCSI Commands not implemented\n", __func__);
  1612. return -EINVAL;
  1613. }
  1614. hdr_len = sizeof(struct iscsi_hdr);
  1615. task_data->ha = ha;
  1616. task_data->task = task;
  1617. if (task->data_count) {
  1618. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  1619. task->data_count,
  1620. PCI_DMA_TODEVICE);
  1621. }
  1622. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1623. __func__, task->conn->max_recv_dlength, hdr_len));
  1624. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  1625. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1626. task_data->resp_len,
  1627. &task_data->resp_dma,
  1628. GFP_ATOMIC);
  1629. if (!task_data->resp_buffer)
  1630. goto exit_alloc_pdu;
  1631. task_data->req_len = task->data_count + hdr_len;
  1632. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1633. task_data->req_len,
  1634. &task_data->req_dma,
  1635. GFP_ATOMIC);
  1636. if (!task_data->req_buffer)
  1637. goto exit_alloc_pdu;
  1638. task->hdr = task_data->req_buffer;
  1639. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  1640. return 0;
  1641. exit_alloc_pdu:
  1642. if (task_data->resp_buffer)
  1643. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1644. task_data->resp_buffer, task_data->resp_dma);
  1645. if (task_data->req_buffer)
  1646. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1647. task_data->req_buffer, task_data->req_dma);
  1648. return -ENOMEM;
  1649. }
  1650. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  1651. {
  1652. struct ql4_task_data *task_data;
  1653. struct iscsi_session *sess;
  1654. struct ddb_entry *ddb_entry;
  1655. struct scsi_qla_host *ha;
  1656. int hdr_len;
  1657. hdr_len = sizeof(struct iscsi_hdr);
  1658. sess = task->conn->session;
  1659. ddb_entry = sess->dd_data;
  1660. ha = ddb_entry->ha;
  1661. task_data = task->dd_data;
  1662. if (task->data_count) {
  1663. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  1664. task->data_count, PCI_DMA_TODEVICE);
  1665. }
  1666. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1667. __func__, task->conn->max_recv_dlength, hdr_len));
  1668. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1669. task_data->resp_buffer, task_data->resp_dma);
  1670. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1671. task_data->req_buffer, task_data->req_dma);
  1672. return;
  1673. }
  1674. static int qla4xxx_task_xmit(struct iscsi_task *task)
  1675. {
  1676. struct scsi_cmnd *sc = task->sc;
  1677. struct iscsi_session *sess = task->conn->session;
  1678. struct ddb_entry *ddb_entry = sess->dd_data;
  1679. struct scsi_qla_host *ha = ddb_entry->ha;
  1680. if (!sc)
  1681. return qla4xxx_send_passthru0(task);
  1682. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  1683. __func__);
  1684. return -ENOSYS;
  1685. }
  1686. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  1687. struct dev_db_entry *fw_ddb_entry,
  1688. struct iscsi_cls_session *cls_sess,
  1689. struct iscsi_cls_conn *cls_conn)
  1690. {
  1691. int buflen = 0;
  1692. struct iscsi_session *sess;
  1693. struct ddb_entry *ddb_entry;
  1694. struct iscsi_conn *conn;
  1695. char ip_addr[DDB_IPADDR_LEN];
  1696. uint16_t options = 0;
  1697. sess = cls_sess->dd_data;
  1698. ddb_entry = sess->dd_data;
  1699. conn = cls_conn->dd_data;
  1700. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1701. conn->max_recv_dlength = BYTE_UNITS *
  1702. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1703. conn->max_xmit_dlength = BYTE_UNITS *
  1704. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1705. sess->initial_r2t_en =
  1706. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1707. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1708. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1709. sess->first_burst = BYTE_UNITS *
  1710. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1711. sess->max_burst = BYTE_UNITS *
  1712. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1713. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1714. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1715. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  1716. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1717. options = le16_to_cpu(fw_ddb_entry->options);
  1718. if (options & DDB_OPT_IPV6_DEVICE)
  1719. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  1720. else
  1721. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  1722. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  1723. (char *)fw_ddb_entry->iscsi_name, buflen);
  1724. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  1725. (char *)ha->name_string, buflen);
  1726. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  1727. (char *)ip_addr, buflen);
  1728. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  1729. (char *)fw_ddb_entry->iscsi_alias, buflen);
  1730. }
  1731. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  1732. struct ddb_entry *ddb_entry)
  1733. {
  1734. struct iscsi_cls_session *cls_sess;
  1735. struct iscsi_cls_conn *cls_conn;
  1736. uint32_t ddb_state;
  1737. dma_addr_t fw_ddb_entry_dma;
  1738. struct dev_db_entry *fw_ddb_entry;
  1739. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1740. &fw_ddb_entry_dma, GFP_KERNEL);
  1741. if (!fw_ddb_entry) {
  1742. ql4_printk(KERN_ERR, ha,
  1743. "%s: Unable to allocate dma buffer\n", __func__);
  1744. goto exit_session_conn_fwddb_param;
  1745. }
  1746. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1747. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1748. NULL, NULL, NULL) == QLA_ERROR) {
  1749. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1750. "get_ddb_entry for fw_ddb_index %d\n",
  1751. ha->host_no, __func__,
  1752. ddb_entry->fw_ddb_index));
  1753. goto exit_session_conn_fwddb_param;
  1754. }
  1755. cls_sess = ddb_entry->sess;
  1756. cls_conn = ddb_entry->conn;
  1757. /* Update params */
  1758. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  1759. exit_session_conn_fwddb_param:
  1760. if (fw_ddb_entry)
  1761. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1762. fw_ddb_entry, fw_ddb_entry_dma);
  1763. }
  1764. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  1765. struct ddb_entry *ddb_entry)
  1766. {
  1767. struct iscsi_cls_session *cls_sess;
  1768. struct iscsi_cls_conn *cls_conn;
  1769. struct iscsi_session *sess;
  1770. struct iscsi_conn *conn;
  1771. uint32_t ddb_state;
  1772. dma_addr_t fw_ddb_entry_dma;
  1773. struct dev_db_entry *fw_ddb_entry;
  1774. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1775. &fw_ddb_entry_dma, GFP_KERNEL);
  1776. if (!fw_ddb_entry) {
  1777. ql4_printk(KERN_ERR, ha,
  1778. "%s: Unable to allocate dma buffer\n", __func__);
  1779. goto exit_session_conn_param;
  1780. }
  1781. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1782. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1783. NULL, NULL, NULL) == QLA_ERROR) {
  1784. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1785. "get_ddb_entry for fw_ddb_index %d\n",
  1786. ha->host_no, __func__,
  1787. ddb_entry->fw_ddb_index));
  1788. goto exit_session_conn_param;
  1789. }
  1790. cls_sess = ddb_entry->sess;
  1791. sess = cls_sess->dd_data;
  1792. cls_conn = ddb_entry->conn;
  1793. conn = cls_conn->dd_data;
  1794. /* Update timers after login */
  1795. ddb_entry->default_relogin_timeout =
  1796. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  1797. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  1798. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  1799. ddb_entry->default_time2wait =
  1800. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1801. /* Update params */
  1802. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1803. conn->max_recv_dlength = BYTE_UNITS *
  1804. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1805. conn->max_xmit_dlength = BYTE_UNITS *
  1806. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1807. sess->initial_r2t_en =
  1808. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1809. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1810. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1811. sess->first_burst = BYTE_UNITS *
  1812. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1813. sess->max_burst = BYTE_UNITS *
  1814. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1815. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1816. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1817. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1818. memcpy(sess->initiatorname, ha->name_string,
  1819. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  1820. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  1821. (char *)fw_ddb_entry->iscsi_alias, 0);
  1822. exit_session_conn_param:
  1823. if (fw_ddb_entry)
  1824. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1825. fw_ddb_entry, fw_ddb_entry_dma);
  1826. }
  1827. /*
  1828. * Timer routines
  1829. */
  1830. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  1831. unsigned long interval)
  1832. {
  1833. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  1834. __func__, ha->host->host_no));
  1835. init_timer(&ha->timer);
  1836. ha->timer.expires = jiffies + interval * HZ;
  1837. ha->timer.data = (unsigned long)ha;
  1838. ha->timer.function = (void (*)(unsigned long))func;
  1839. add_timer(&ha->timer);
  1840. ha->timer_active = 1;
  1841. }
  1842. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  1843. {
  1844. del_timer_sync(&ha->timer);
  1845. ha->timer_active = 0;
  1846. }
  1847. /***
  1848. * qla4xxx_mark_device_missing - blocks the session
  1849. * @cls_session: Pointer to the session to be blocked
  1850. * @ddb_entry: Pointer to device database entry
  1851. *
  1852. * This routine marks a device missing and close connection.
  1853. **/
  1854. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  1855. {
  1856. iscsi_block_session(cls_session);
  1857. }
  1858. /**
  1859. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  1860. * @ha: Pointer to host adapter structure.
  1861. *
  1862. * This routine marks a device missing and resets the relogin retry count.
  1863. **/
  1864. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  1865. {
  1866. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  1867. }
  1868. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  1869. struct ddb_entry *ddb_entry,
  1870. struct scsi_cmnd *cmd)
  1871. {
  1872. struct srb *srb;
  1873. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  1874. if (!srb)
  1875. return srb;
  1876. kref_init(&srb->srb_ref);
  1877. srb->ha = ha;
  1878. srb->ddb = ddb_entry;
  1879. srb->cmd = cmd;
  1880. srb->flags = 0;
  1881. CMD_SP(cmd) = (void *)srb;
  1882. return srb;
  1883. }
  1884. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  1885. {
  1886. struct scsi_cmnd *cmd = srb->cmd;
  1887. if (srb->flags & SRB_DMA_VALID) {
  1888. scsi_dma_unmap(cmd);
  1889. srb->flags &= ~SRB_DMA_VALID;
  1890. }
  1891. CMD_SP(cmd) = NULL;
  1892. }
  1893. void qla4xxx_srb_compl(struct kref *ref)
  1894. {
  1895. struct srb *srb = container_of(ref, struct srb, srb_ref);
  1896. struct scsi_cmnd *cmd = srb->cmd;
  1897. struct scsi_qla_host *ha = srb->ha;
  1898. qla4xxx_srb_free_dma(ha, srb);
  1899. mempool_free(srb, ha->srb_mempool);
  1900. cmd->scsi_done(cmd);
  1901. }
  1902. /**
  1903. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  1904. * @host: scsi host
  1905. * @cmd: Pointer to Linux's SCSI command structure
  1906. *
  1907. * Remarks:
  1908. * This routine is invoked by Linux to send a SCSI command to the driver.
  1909. * The mid-level driver tries to ensure that queuecommand never gets
  1910. * invoked concurrently with itself or the interrupt handler (although
  1911. * the interrupt handler may call this routine as part of request-
  1912. * completion handling). Unfortunely, it sometimes calls the scheduler
  1913. * in interrupt context which is a big NO! NO!.
  1914. **/
  1915. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  1916. {
  1917. struct scsi_qla_host *ha = to_qla_host(host);
  1918. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1919. struct iscsi_cls_session *sess = ddb_entry->sess;
  1920. struct srb *srb;
  1921. int rval;
  1922. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1923. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  1924. cmd->result = DID_NO_CONNECT << 16;
  1925. else
  1926. cmd->result = DID_REQUEUE << 16;
  1927. goto qc_fail_command;
  1928. }
  1929. if (!sess) {
  1930. cmd->result = DID_IMM_RETRY << 16;
  1931. goto qc_fail_command;
  1932. }
  1933. rval = iscsi_session_chkready(sess);
  1934. if (rval) {
  1935. cmd->result = rval;
  1936. goto qc_fail_command;
  1937. }
  1938. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1939. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1940. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1941. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1942. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1943. !test_bit(AF_ONLINE, &ha->flags) ||
  1944. !test_bit(AF_LINK_UP, &ha->flags) ||
  1945. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  1946. goto qc_host_busy;
  1947. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  1948. if (!srb)
  1949. goto qc_host_busy;
  1950. rval = qla4xxx_send_command_to_isp(ha, srb);
  1951. if (rval != QLA_SUCCESS)
  1952. goto qc_host_busy_free_sp;
  1953. return 0;
  1954. qc_host_busy_free_sp:
  1955. qla4xxx_srb_free_dma(ha, srb);
  1956. mempool_free(srb, ha->srb_mempool);
  1957. qc_host_busy:
  1958. return SCSI_MLQUEUE_HOST_BUSY;
  1959. qc_fail_command:
  1960. cmd->scsi_done(cmd);
  1961. return 0;
  1962. }
  1963. /**
  1964. * qla4xxx_mem_free - frees memory allocated to adapter
  1965. * @ha: Pointer to host adapter structure.
  1966. *
  1967. * Frees memory previously allocated by qla4xxx_mem_alloc
  1968. **/
  1969. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  1970. {
  1971. if (ha->queues)
  1972. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  1973. ha->queues_dma);
  1974. if (ha->fw_dump)
  1975. vfree(ha->fw_dump);
  1976. ha->queues_len = 0;
  1977. ha->queues = NULL;
  1978. ha->queues_dma = 0;
  1979. ha->request_ring = NULL;
  1980. ha->request_dma = 0;
  1981. ha->response_ring = NULL;
  1982. ha->response_dma = 0;
  1983. ha->shadow_regs = NULL;
  1984. ha->shadow_regs_dma = 0;
  1985. ha->fw_dump = NULL;
  1986. ha->fw_dump_size = 0;
  1987. /* Free srb pool. */
  1988. if (ha->srb_mempool)
  1989. mempool_destroy(ha->srb_mempool);
  1990. ha->srb_mempool = NULL;
  1991. if (ha->chap_dma_pool)
  1992. dma_pool_destroy(ha->chap_dma_pool);
  1993. if (ha->chap_list)
  1994. vfree(ha->chap_list);
  1995. ha->chap_list = NULL;
  1996. if (ha->fw_ddb_dma_pool)
  1997. dma_pool_destroy(ha->fw_ddb_dma_pool);
  1998. /* release io space registers */
  1999. if (is_qla8022(ha)) {
  2000. if (ha->nx_pcibase)
  2001. iounmap(
  2002. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  2003. } else if (ha->reg)
  2004. iounmap(ha->reg);
  2005. pci_release_regions(ha->pdev);
  2006. }
  2007. /**
  2008. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  2009. * @ha: Pointer to host adapter structure
  2010. *
  2011. * Allocates DMA memory for request and response queues. Also allocates memory
  2012. * for srbs.
  2013. **/
  2014. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  2015. {
  2016. unsigned long align;
  2017. /* Allocate contiguous block of DMA memory for queues. */
  2018. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2019. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  2020. sizeof(struct shadow_regs) +
  2021. MEM_ALIGN_VALUE +
  2022. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  2023. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  2024. &ha->queues_dma, GFP_KERNEL);
  2025. if (ha->queues == NULL) {
  2026. ql4_printk(KERN_WARNING, ha,
  2027. "Memory Allocation failed - queues.\n");
  2028. goto mem_alloc_error_exit;
  2029. }
  2030. memset(ha->queues, 0, ha->queues_len);
  2031. /*
  2032. * As per RISC alignment requirements -- the bus-address must be a
  2033. * multiple of the request-ring size (in bytes).
  2034. */
  2035. align = 0;
  2036. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  2037. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  2038. (MEM_ALIGN_VALUE - 1));
  2039. /* Update request and response queue pointers. */
  2040. ha->request_dma = ha->queues_dma + align;
  2041. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  2042. ha->response_dma = ha->queues_dma + align +
  2043. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  2044. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  2045. (REQUEST_QUEUE_DEPTH *
  2046. QUEUE_SIZE));
  2047. ha->shadow_regs_dma = ha->queues_dma + align +
  2048. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2049. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  2050. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  2051. (REQUEST_QUEUE_DEPTH *
  2052. QUEUE_SIZE) +
  2053. (RESPONSE_QUEUE_DEPTH *
  2054. QUEUE_SIZE));
  2055. /* Allocate memory for srb pool. */
  2056. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  2057. mempool_free_slab, srb_cachep);
  2058. if (ha->srb_mempool == NULL) {
  2059. ql4_printk(KERN_WARNING, ha,
  2060. "Memory Allocation failed - SRB Pool.\n");
  2061. goto mem_alloc_error_exit;
  2062. }
  2063. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  2064. CHAP_DMA_BLOCK_SIZE, 8, 0);
  2065. if (ha->chap_dma_pool == NULL) {
  2066. ql4_printk(KERN_WARNING, ha,
  2067. "%s: chap_dma_pool allocation failed..\n", __func__);
  2068. goto mem_alloc_error_exit;
  2069. }
  2070. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  2071. DDB_DMA_BLOCK_SIZE, 8, 0);
  2072. if (ha->fw_ddb_dma_pool == NULL) {
  2073. ql4_printk(KERN_WARNING, ha,
  2074. "%s: fw_ddb_dma_pool allocation failed..\n",
  2075. __func__);
  2076. goto mem_alloc_error_exit;
  2077. }
  2078. return QLA_SUCCESS;
  2079. mem_alloc_error_exit:
  2080. qla4xxx_mem_free(ha);
  2081. return QLA_ERROR;
  2082. }
  2083. /**
  2084. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  2085. * @ha: adapter block pointer.
  2086. *
  2087. * Note: The caller should not hold the idc lock.
  2088. **/
  2089. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  2090. {
  2091. uint32_t temp, temp_state, temp_val;
  2092. int status = QLA_SUCCESS;
  2093. temp = qla4_8xxx_rd_32(ha, CRB_TEMP_STATE);
  2094. temp_state = qla82xx_get_temp_state(temp);
  2095. temp_val = qla82xx_get_temp_val(temp);
  2096. if (temp_state == QLA82XX_TEMP_PANIC) {
  2097. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  2098. " exceeds maximum allowed. Hardware has been shut"
  2099. " down.\n", temp_val);
  2100. status = QLA_ERROR;
  2101. } else if (temp_state == QLA82XX_TEMP_WARN) {
  2102. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  2103. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  2104. " degrees C exceeds operating range."
  2105. " Immediate action needed.\n", temp_val);
  2106. } else {
  2107. if (ha->temperature == QLA82XX_TEMP_WARN)
  2108. ql4_printk(KERN_INFO, ha, "Device temperature is"
  2109. " now %d degrees C in normal range.\n",
  2110. temp_val);
  2111. }
  2112. ha->temperature = temp_state;
  2113. return status;
  2114. }
  2115. /**
  2116. * qla4_8xxx_check_fw_alive - Check firmware health
  2117. * @ha: Pointer to host adapter structure.
  2118. *
  2119. * Context: Interrupt
  2120. **/
  2121. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  2122. {
  2123. uint32_t fw_heartbeat_counter;
  2124. int status = QLA_SUCCESS;
  2125. fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
  2126. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  2127. if (fw_heartbeat_counter == 0xffffffff) {
  2128. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  2129. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  2130. ha->host_no, __func__));
  2131. return status;
  2132. }
  2133. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  2134. ha->seconds_since_last_heartbeat++;
  2135. /* FW not alive after 2 seconds */
  2136. if (ha->seconds_since_last_heartbeat == 2) {
  2137. ha->seconds_since_last_heartbeat = 0;
  2138. ql4_printk(KERN_INFO, ha,
  2139. "scsi(%ld): %s, Dumping hw/fw registers:\n "
  2140. " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
  2141. " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
  2142. " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
  2143. " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
  2144. ha->host_no, __func__,
  2145. qla4_8xxx_rd_32(ha,
  2146. QLA82XX_PEG_HALT_STATUS1),
  2147. qla4_8xxx_rd_32(ha,
  2148. QLA82XX_PEG_HALT_STATUS2),
  2149. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
  2150. 0x3c),
  2151. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
  2152. 0x3c),
  2153. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
  2154. 0x3c),
  2155. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
  2156. 0x3c),
  2157. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
  2158. 0x3c));
  2159. status = QLA_ERROR;
  2160. }
  2161. } else
  2162. ha->seconds_since_last_heartbeat = 0;
  2163. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  2164. return status;
  2165. }
  2166. /**
  2167. * qla4_8xxx_watchdog - Poll dev state
  2168. * @ha: Pointer to host adapter structure.
  2169. *
  2170. * Context: Interrupt
  2171. **/
  2172. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  2173. {
  2174. uint32_t dev_state, halt_status;
  2175. /* don't poll if reset is going on */
  2176. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2177. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2178. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  2179. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  2180. if (qla4_8xxx_check_temp(ha)) {
  2181. ql4_printk(KERN_INFO, ha, "disabling pause"
  2182. " transmit on port 0 & 1.\n");
  2183. qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2184. CRB_NIU_XG_PAUSE_CTL_P0 |
  2185. CRB_NIU_XG_PAUSE_CTL_P1);
  2186. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2187. qla4xxx_wake_dpc(ha);
  2188. } else if (dev_state == QLA82XX_DEV_NEED_RESET &&
  2189. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2190. if (!ql4xdontresethba) {
  2191. ql4_printk(KERN_INFO, ha, "%s: HW State: "
  2192. "NEED RESET!\n", __func__);
  2193. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2194. qla4xxx_wake_dpc(ha);
  2195. }
  2196. } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
  2197. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2198. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  2199. __func__);
  2200. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  2201. qla4xxx_wake_dpc(ha);
  2202. } else {
  2203. /* Check firmware health */
  2204. if (qla4_8xxx_check_fw_alive(ha)) {
  2205. ql4_printk(KERN_INFO, ha, "disabling pause"
  2206. " transmit on port 0 & 1.\n");
  2207. qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2208. CRB_NIU_XG_PAUSE_CTL_P0 |
  2209. CRB_NIU_XG_PAUSE_CTL_P1);
  2210. halt_status = qla4_8xxx_rd_32(ha,
  2211. QLA82XX_PEG_HALT_STATUS1);
  2212. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  2213. ql4_printk(KERN_ERR, ha, "%s:"
  2214. " Firmware aborted with"
  2215. " error code 0x00006700."
  2216. " Device is being reset\n",
  2217. __func__);
  2218. /* Since we cannot change dev_state in interrupt
  2219. * context, set appropriate DPC flag then wakeup
  2220. * DPC */
  2221. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  2222. set_bit(DPC_HA_UNRECOVERABLE,
  2223. &ha->dpc_flags);
  2224. else {
  2225. ql4_printk(KERN_INFO, ha, "%s: detect "
  2226. "abort needed!\n", __func__);
  2227. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2228. }
  2229. qla4xxx_mailbox_premature_completion(ha);
  2230. qla4xxx_wake_dpc(ha);
  2231. }
  2232. }
  2233. }
  2234. }
  2235. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2236. {
  2237. struct iscsi_session *sess;
  2238. struct ddb_entry *ddb_entry;
  2239. struct scsi_qla_host *ha;
  2240. sess = cls_sess->dd_data;
  2241. ddb_entry = sess->dd_data;
  2242. ha = ddb_entry->ha;
  2243. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2244. return;
  2245. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2246. !iscsi_is_session_online(cls_sess)) {
  2247. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  2248. INVALID_ENTRY) {
  2249. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  2250. 0) {
  2251. atomic_set(&ddb_entry->retry_relogin_timer,
  2252. INVALID_ENTRY);
  2253. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2254. set_bit(DF_RELOGIN, &ddb_entry->flags);
  2255. DEBUG2(ql4_printk(KERN_INFO, ha,
  2256. "%s: index [%d] login device\n",
  2257. __func__, ddb_entry->fw_ddb_index));
  2258. } else
  2259. atomic_dec(&ddb_entry->retry_relogin_timer);
  2260. }
  2261. }
  2262. /* Wait for relogin to timeout */
  2263. if (atomic_read(&ddb_entry->relogin_timer) &&
  2264. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  2265. /*
  2266. * If the relogin times out and the device is
  2267. * still NOT ONLINE then try and relogin again.
  2268. */
  2269. if (!iscsi_is_session_online(cls_sess)) {
  2270. /* Reset retry relogin timer */
  2271. atomic_inc(&ddb_entry->relogin_retry_count);
  2272. DEBUG2(ql4_printk(KERN_INFO, ha,
  2273. "%s: index[%d] relogin timed out-retrying"
  2274. " relogin (%d), retry (%d)\n", __func__,
  2275. ddb_entry->fw_ddb_index,
  2276. atomic_read(&ddb_entry->relogin_retry_count),
  2277. ddb_entry->default_time2wait + 4));
  2278. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2279. atomic_set(&ddb_entry->retry_relogin_timer,
  2280. ddb_entry->default_time2wait + 4);
  2281. }
  2282. }
  2283. }
  2284. /**
  2285. * qla4xxx_timer - checks every second for work to do.
  2286. * @ha: Pointer to host adapter structure.
  2287. **/
  2288. static void qla4xxx_timer(struct scsi_qla_host *ha)
  2289. {
  2290. int start_dpc = 0;
  2291. uint16_t w;
  2292. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  2293. /* If we are in the middle of AER/EEH processing
  2294. * skip any processing and reschedule the timer
  2295. */
  2296. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2297. mod_timer(&ha->timer, jiffies + HZ);
  2298. return;
  2299. }
  2300. /* Hardware read to trigger an EEH error during mailbox waits. */
  2301. if (!pci_channel_offline(ha->pdev))
  2302. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2303. if (is_qla8022(ha)) {
  2304. qla4_8xxx_watchdog(ha);
  2305. }
  2306. if (!is_qla8022(ha)) {
  2307. /* Check for heartbeat interval. */
  2308. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  2309. ha->heartbeat_interval != 0) {
  2310. ha->seconds_since_last_heartbeat++;
  2311. if (ha->seconds_since_last_heartbeat >
  2312. ha->heartbeat_interval + 2)
  2313. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2314. }
  2315. }
  2316. /* Process any deferred work. */
  2317. if (!list_empty(&ha->work_list))
  2318. start_dpc++;
  2319. /* Wakeup the dpc routine for this adapter, if needed. */
  2320. if (start_dpc ||
  2321. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2322. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  2323. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  2324. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2325. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2326. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  2327. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  2328. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2329. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2330. test_bit(DPC_AEN, &ha->dpc_flags)) {
  2331. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  2332. " - dpc flags = 0x%lx\n",
  2333. ha->host_no, __func__, ha->dpc_flags));
  2334. qla4xxx_wake_dpc(ha);
  2335. }
  2336. /* Reschedule timer thread to call us back in one second */
  2337. mod_timer(&ha->timer, jiffies + HZ);
  2338. DEBUG2(ha->seconds_since_last_intr++);
  2339. }
  2340. /**
  2341. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  2342. * @ha: Pointer to host adapter structure.
  2343. *
  2344. * This routine stalls the driver until all outstanding commands are returned.
  2345. * Caller must release the Hardware Lock prior to calling this routine.
  2346. **/
  2347. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  2348. {
  2349. uint32_t index = 0;
  2350. unsigned long flags;
  2351. struct scsi_cmnd *cmd;
  2352. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  2353. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  2354. "complete\n", WAIT_CMD_TOV));
  2355. while (!time_after_eq(jiffies, wtime)) {
  2356. spin_lock_irqsave(&ha->hardware_lock, flags);
  2357. /* Find a command that hasn't completed. */
  2358. for (index = 0; index < ha->host->can_queue; index++) {
  2359. cmd = scsi_host_find_tag(ha->host, index);
  2360. /*
  2361. * We cannot just check if the index is valid,
  2362. * becase if we are run from the scsi eh, then
  2363. * the scsi/block layer is going to prevent
  2364. * the tag from being released.
  2365. */
  2366. if (cmd != NULL && CMD_SP(cmd))
  2367. break;
  2368. }
  2369. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2370. /* If No Commands are pending, wait is complete */
  2371. if (index == ha->host->can_queue)
  2372. return QLA_SUCCESS;
  2373. msleep(1000);
  2374. }
  2375. /* If we timed out on waiting for commands to come back
  2376. * return ERROR. */
  2377. return QLA_ERROR;
  2378. }
  2379. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  2380. {
  2381. uint32_t ctrl_status;
  2382. unsigned long flags = 0;
  2383. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  2384. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  2385. return QLA_ERROR;
  2386. spin_lock_irqsave(&ha->hardware_lock, flags);
  2387. /*
  2388. * If the SCSI Reset Interrupt bit is set, clear it.
  2389. * Otherwise, the Soft Reset won't work.
  2390. */
  2391. ctrl_status = readw(&ha->reg->ctrl_status);
  2392. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  2393. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2394. /* Issue Soft Reset */
  2395. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  2396. readl(&ha->reg->ctrl_status);
  2397. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2398. return QLA_SUCCESS;
  2399. }
  2400. /**
  2401. * qla4xxx_soft_reset - performs soft reset.
  2402. * @ha: Pointer to host adapter structure.
  2403. **/
  2404. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  2405. {
  2406. uint32_t max_wait_time;
  2407. unsigned long flags = 0;
  2408. int status;
  2409. uint32_t ctrl_status;
  2410. status = qla4xxx_hw_reset(ha);
  2411. if (status != QLA_SUCCESS)
  2412. return status;
  2413. status = QLA_ERROR;
  2414. /* Wait until the Network Reset Intr bit is cleared */
  2415. max_wait_time = RESET_INTR_TOV;
  2416. do {
  2417. spin_lock_irqsave(&ha->hardware_lock, flags);
  2418. ctrl_status = readw(&ha->reg->ctrl_status);
  2419. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2420. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  2421. break;
  2422. msleep(1000);
  2423. } while ((--max_wait_time));
  2424. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  2425. DEBUG2(printk(KERN_WARNING
  2426. "scsi%ld: Network Reset Intr not cleared by "
  2427. "Network function, clearing it now!\n",
  2428. ha->host_no));
  2429. spin_lock_irqsave(&ha->hardware_lock, flags);
  2430. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  2431. readl(&ha->reg->ctrl_status);
  2432. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2433. }
  2434. /* Wait until the firmware tells us the Soft Reset is done */
  2435. max_wait_time = SOFT_RESET_TOV;
  2436. do {
  2437. spin_lock_irqsave(&ha->hardware_lock, flags);
  2438. ctrl_status = readw(&ha->reg->ctrl_status);
  2439. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2440. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  2441. status = QLA_SUCCESS;
  2442. break;
  2443. }
  2444. msleep(1000);
  2445. } while ((--max_wait_time));
  2446. /*
  2447. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  2448. * after the soft reset has taken place.
  2449. */
  2450. spin_lock_irqsave(&ha->hardware_lock, flags);
  2451. ctrl_status = readw(&ha->reg->ctrl_status);
  2452. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  2453. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2454. readl(&ha->reg->ctrl_status);
  2455. }
  2456. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2457. /* If soft reset fails then most probably the bios on other
  2458. * function is also enabled.
  2459. * Since the initialization is sequential the other fn
  2460. * wont be able to acknowledge the soft reset.
  2461. * Issue a force soft reset to workaround this scenario.
  2462. */
  2463. if (max_wait_time == 0) {
  2464. /* Issue Force Soft Reset */
  2465. spin_lock_irqsave(&ha->hardware_lock, flags);
  2466. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  2467. readl(&ha->reg->ctrl_status);
  2468. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2469. /* Wait until the firmware tells us the Soft Reset is done */
  2470. max_wait_time = SOFT_RESET_TOV;
  2471. do {
  2472. spin_lock_irqsave(&ha->hardware_lock, flags);
  2473. ctrl_status = readw(&ha->reg->ctrl_status);
  2474. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2475. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  2476. status = QLA_SUCCESS;
  2477. break;
  2478. }
  2479. msleep(1000);
  2480. } while ((--max_wait_time));
  2481. }
  2482. return status;
  2483. }
  2484. /**
  2485. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  2486. * @ha: Pointer to host adapter structure.
  2487. * @res: returned scsi status
  2488. *
  2489. * This routine is called just prior to a HARD RESET to return all
  2490. * outstanding commands back to the Operating System.
  2491. * Caller should make sure that the following locks are released
  2492. * before this calling routine: Hardware lock, and io_request_lock.
  2493. **/
  2494. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  2495. {
  2496. struct srb *srb;
  2497. int i;
  2498. unsigned long flags;
  2499. spin_lock_irqsave(&ha->hardware_lock, flags);
  2500. for (i = 0; i < ha->host->can_queue; i++) {
  2501. srb = qla4xxx_del_from_active_array(ha, i);
  2502. if (srb != NULL) {
  2503. srb->cmd->result = res;
  2504. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2505. }
  2506. }
  2507. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2508. }
  2509. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  2510. {
  2511. clear_bit(AF_ONLINE, &ha->flags);
  2512. /* Disable the board */
  2513. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  2514. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2515. qla4xxx_mark_all_devices_missing(ha);
  2516. clear_bit(AF_INIT_DONE, &ha->flags);
  2517. }
  2518. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  2519. {
  2520. struct iscsi_session *sess;
  2521. struct ddb_entry *ddb_entry;
  2522. sess = cls_session->dd_data;
  2523. ddb_entry = sess->dd_data;
  2524. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  2525. if (ddb_entry->ddb_type == FLASH_DDB)
  2526. iscsi_block_session(ddb_entry->sess);
  2527. else
  2528. iscsi_session_failure(cls_session->dd_data,
  2529. ISCSI_ERR_CONN_FAILED);
  2530. }
  2531. /**
  2532. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  2533. * @ha: Pointer to host adapter structure.
  2534. **/
  2535. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  2536. {
  2537. int status = QLA_ERROR;
  2538. uint8_t reset_chip = 0;
  2539. uint32_t dev_state;
  2540. unsigned long wait;
  2541. /* Stall incoming I/O until we are done */
  2542. scsi_block_requests(ha->host);
  2543. clear_bit(AF_ONLINE, &ha->flags);
  2544. clear_bit(AF_LINK_UP, &ha->flags);
  2545. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  2546. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2547. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  2548. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2549. reset_chip = 1;
  2550. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  2551. * do not reset adapter, jump to initialize_adapter */
  2552. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2553. status = QLA_SUCCESS;
  2554. goto recover_ha_init_adapter;
  2555. }
  2556. /* For the ISP-82xx adapter, issue a stop_firmware if invoked
  2557. * from eh_host_reset or ioctl module */
  2558. if (is_qla8022(ha) && !reset_chip &&
  2559. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2560. DEBUG2(ql4_printk(KERN_INFO, ha,
  2561. "scsi%ld: %s - Performing stop_firmware...\n",
  2562. ha->host_no, __func__));
  2563. status = ha->isp_ops->reset_firmware(ha);
  2564. if (status == QLA_SUCCESS) {
  2565. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2566. qla4xxx_cmd_wait(ha);
  2567. ha->isp_ops->disable_intrs(ha);
  2568. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2569. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2570. } else {
  2571. /* If the stop_firmware fails then
  2572. * reset the entire chip */
  2573. reset_chip = 1;
  2574. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2575. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2576. }
  2577. }
  2578. /* Issue full chip reset if recovering from a catastrophic error,
  2579. * or if stop_firmware fails for ISP-82xx.
  2580. * This is the default case for ISP-4xxx */
  2581. if (!is_qla8022(ha) || reset_chip) {
  2582. if (!is_qla8022(ha))
  2583. goto chip_reset;
  2584. /* Check if 82XX firmware is alive or not
  2585. * We may have arrived here from NEED_RESET
  2586. * detection only */
  2587. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  2588. goto chip_reset;
  2589. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  2590. while (time_before(jiffies, wait)) {
  2591. if (qla4_8xxx_check_fw_alive(ha)) {
  2592. qla4xxx_mailbox_premature_completion(ha);
  2593. break;
  2594. }
  2595. set_current_state(TASK_UNINTERRUPTIBLE);
  2596. schedule_timeout(HZ);
  2597. }
  2598. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2599. qla4xxx_cmd_wait(ha);
  2600. chip_reset:
  2601. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2602. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2603. DEBUG2(ql4_printk(KERN_INFO, ha,
  2604. "scsi%ld: %s - Performing chip reset..\n",
  2605. ha->host_no, __func__));
  2606. status = ha->isp_ops->reset_chip(ha);
  2607. }
  2608. /* Flush any pending ddb changed AENs */
  2609. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2610. recover_ha_init_adapter:
  2611. /* Upon successful firmware/chip reset, re-initialize the adapter */
  2612. if (status == QLA_SUCCESS) {
  2613. /* For ISP-4xxx, force function 1 to always initialize
  2614. * before function 3 to prevent both funcions from
  2615. * stepping on top of the other */
  2616. if (!is_qla8022(ha) && (ha->mac_index == 3))
  2617. ssleep(6);
  2618. /* NOTE: AF_ONLINE flag set upon successful completion of
  2619. * qla4xxx_initialize_adapter */
  2620. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  2621. }
  2622. /* Retry failed adapter initialization, if necessary
  2623. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  2624. * case to prevent ping-pong resets between functions */
  2625. if (!test_bit(AF_ONLINE, &ha->flags) &&
  2626. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2627. /* Adapter initialization failed, see if we can retry
  2628. * resetting the ha.
  2629. * Since we don't want to block the DPC for too long
  2630. * with multiple resets in the same thread,
  2631. * utilize DPC to retry */
  2632. if (is_qla8022(ha)) {
  2633. qla4_8xxx_idc_lock(ha);
  2634. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  2635. qla4_8xxx_idc_unlock(ha);
  2636. if (dev_state == QLA82XX_DEV_FAILED) {
  2637. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  2638. "recover adapter. H/W is in Failed "
  2639. "state\n", __func__);
  2640. qla4xxx_dead_adapter_cleanup(ha);
  2641. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2642. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2643. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  2644. &ha->dpc_flags);
  2645. status = QLA_ERROR;
  2646. goto exit_recover;
  2647. }
  2648. }
  2649. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  2650. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  2651. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  2652. "(%d) more times\n", ha->host_no,
  2653. ha->retry_reset_ha_cnt));
  2654. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2655. status = QLA_ERROR;
  2656. } else {
  2657. if (ha->retry_reset_ha_cnt > 0) {
  2658. /* Schedule another Reset HA--DPC will retry */
  2659. ha->retry_reset_ha_cnt--;
  2660. DEBUG2(printk("scsi%ld: recover adapter - "
  2661. "retry remaining %d\n",
  2662. ha->host_no,
  2663. ha->retry_reset_ha_cnt));
  2664. status = QLA_ERROR;
  2665. }
  2666. if (ha->retry_reset_ha_cnt == 0) {
  2667. /* Recover adapter retries have been exhausted.
  2668. * Adapter DEAD */
  2669. DEBUG2(printk("scsi%ld: recover adapter "
  2670. "failed - board disabled\n",
  2671. ha->host_no));
  2672. qla4xxx_dead_adapter_cleanup(ha);
  2673. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2674. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2675. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  2676. &ha->dpc_flags);
  2677. status = QLA_ERROR;
  2678. }
  2679. }
  2680. } else {
  2681. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2682. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2683. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2684. }
  2685. exit_recover:
  2686. ha->adapter_error_count++;
  2687. if (test_bit(AF_ONLINE, &ha->flags))
  2688. ha->isp_ops->enable_intrs(ha);
  2689. scsi_unblock_requests(ha->host);
  2690. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2691. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  2692. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  2693. return status;
  2694. }
  2695. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  2696. {
  2697. struct iscsi_session *sess;
  2698. struct ddb_entry *ddb_entry;
  2699. struct scsi_qla_host *ha;
  2700. sess = cls_session->dd_data;
  2701. ddb_entry = sess->dd_data;
  2702. ha = ddb_entry->ha;
  2703. if (!iscsi_is_session_online(cls_session)) {
  2704. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  2705. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2706. " unblock session\n", ha->host_no, __func__,
  2707. ddb_entry->fw_ddb_index);
  2708. iscsi_unblock_session(ddb_entry->sess);
  2709. } else {
  2710. /* Trigger relogin */
  2711. if (ddb_entry->ddb_type == FLASH_DDB) {
  2712. if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
  2713. qla4xxx_arm_relogin_timer(ddb_entry);
  2714. } else
  2715. iscsi_session_failure(cls_session->dd_data,
  2716. ISCSI_ERR_CONN_FAILED);
  2717. }
  2718. }
  2719. }
  2720. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  2721. {
  2722. struct iscsi_session *sess;
  2723. struct ddb_entry *ddb_entry;
  2724. struct scsi_qla_host *ha;
  2725. sess = cls_session->dd_data;
  2726. ddb_entry = sess->dd_data;
  2727. ha = ddb_entry->ha;
  2728. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2729. " unblock session\n", ha->host_no, __func__,
  2730. ddb_entry->fw_ddb_index);
  2731. iscsi_unblock_session(ddb_entry->sess);
  2732. /* Start scan target */
  2733. if (test_bit(AF_ONLINE, &ha->flags)) {
  2734. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2735. " start scan\n", ha->host_no, __func__,
  2736. ddb_entry->fw_ddb_index);
  2737. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  2738. }
  2739. return QLA_SUCCESS;
  2740. }
  2741. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  2742. {
  2743. struct iscsi_session *sess;
  2744. struct ddb_entry *ddb_entry;
  2745. struct scsi_qla_host *ha;
  2746. int status = QLA_SUCCESS;
  2747. sess = cls_session->dd_data;
  2748. ddb_entry = sess->dd_data;
  2749. ha = ddb_entry->ha;
  2750. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2751. " unblock user space session\n", ha->host_no, __func__,
  2752. ddb_entry->fw_ddb_index);
  2753. if (!iscsi_is_session_online(cls_session)) {
  2754. iscsi_conn_start(ddb_entry->conn);
  2755. iscsi_conn_login_event(ddb_entry->conn,
  2756. ISCSI_CONN_STATE_LOGGED_IN);
  2757. } else {
  2758. ql4_printk(KERN_INFO, ha,
  2759. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  2760. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  2761. cls_session->sid);
  2762. status = QLA_ERROR;
  2763. }
  2764. return status;
  2765. }
  2766. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  2767. {
  2768. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  2769. }
  2770. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2771. {
  2772. uint16_t relogin_timer;
  2773. struct iscsi_session *sess;
  2774. struct ddb_entry *ddb_entry;
  2775. struct scsi_qla_host *ha;
  2776. sess = cls_sess->dd_data;
  2777. ddb_entry = sess->dd_data;
  2778. ha = ddb_entry->ha;
  2779. relogin_timer = max(ddb_entry->default_relogin_timeout,
  2780. (uint16_t)RELOGIN_TOV);
  2781. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  2782. DEBUG2(ql4_printk(KERN_INFO, ha,
  2783. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  2784. ddb_entry->fw_ddb_index, relogin_timer));
  2785. qla4xxx_login_flash_ddb(cls_sess);
  2786. }
  2787. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  2788. {
  2789. struct iscsi_session *sess;
  2790. struct ddb_entry *ddb_entry;
  2791. struct scsi_qla_host *ha;
  2792. sess = cls_sess->dd_data;
  2793. ddb_entry = sess->dd_data;
  2794. ha = ddb_entry->ha;
  2795. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2796. return;
  2797. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2798. !iscsi_is_session_online(cls_sess)) {
  2799. DEBUG2(ql4_printk(KERN_INFO, ha,
  2800. "relogin issued\n"));
  2801. qla4xxx_relogin_flash_ddb(cls_sess);
  2802. }
  2803. }
  2804. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  2805. {
  2806. if (ha->dpc_thread)
  2807. queue_work(ha->dpc_thread, &ha->dpc_work);
  2808. }
  2809. static struct qla4_work_evt *
  2810. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  2811. enum qla4_work_type type)
  2812. {
  2813. struct qla4_work_evt *e;
  2814. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  2815. e = kzalloc(size, GFP_ATOMIC);
  2816. if (!e)
  2817. return NULL;
  2818. INIT_LIST_HEAD(&e->list);
  2819. e->type = type;
  2820. return e;
  2821. }
  2822. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  2823. struct qla4_work_evt *e)
  2824. {
  2825. unsigned long flags;
  2826. spin_lock_irqsave(&ha->work_lock, flags);
  2827. list_add_tail(&e->list, &ha->work_list);
  2828. spin_unlock_irqrestore(&ha->work_lock, flags);
  2829. qla4xxx_wake_dpc(ha);
  2830. }
  2831. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  2832. enum iscsi_host_event_code aen_code,
  2833. uint32_t data_size, uint8_t *data)
  2834. {
  2835. struct qla4_work_evt *e;
  2836. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  2837. if (!e)
  2838. return QLA_ERROR;
  2839. e->u.aen.code = aen_code;
  2840. e->u.aen.data_size = data_size;
  2841. memcpy(e->u.aen.data, data, data_size);
  2842. qla4xxx_post_work(ha, e);
  2843. return QLA_SUCCESS;
  2844. }
  2845. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  2846. uint32_t status, uint32_t pid,
  2847. uint32_t data_size, uint8_t *data)
  2848. {
  2849. struct qla4_work_evt *e;
  2850. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  2851. if (!e)
  2852. return QLA_ERROR;
  2853. e->u.ping.status = status;
  2854. e->u.ping.pid = pid;
  2855. e->u.ping.data_size = data_size;
  2856. memcpy(e->u.ping.data, data, data_size);
  2857. qla4xxx_post_work(ha, e);
  2858. return QLA_SUCCESS;
  2859. }
  2860. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  2861. {
  2862. struct qla4_work_evt *e, *tmp;
  2863. unsigned long flags;
  2864. LIST_HEAD(work);
  2865. spin_lock_irqsave(&ha->work_lock, flags);
  2866. list_splice_init(&ha->work_list, &work);
  2867. spin_unlock_irqrestore(&ha->work_lock, flags);
  2868. list_for_each_entry_safe(e, tmp, &work, list) {
  2869. list_del_init(&e->list);
  2870. switch (e->type) {
  2871. case QLA4_EVENT_AEN:
  2872. iscsi_post_host_event(ha->host_no,
  2873. &qla4xxx_iscsi_transport,
  2874. e->u.aen.code,
  2875. e->u.aen.data_size,
  2876. e->u.aen.data);
  2877. break;
  2878. case QLA4_EVENT_PING_STATUS:
  2879. iscsi_ping_comp_event(ha->host_no,
  2880. &qla4xxx_iscsi_transport,
  2881. e->u.ping.status,
  2882. e->u.ping.pid,
  2883. e->u.ping.data_size,
  2884. e->u.ping.data);
  2885. break;
  2886. default:
  2887. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  2888. "supported", e->type);
  2889. }
  2890. kfree(e);
  2891. }
  2892. }
  2893. /**
  2894. * qla4xxx_do_dpc - dpc routine
  2895. * @data: in our case pointer to adapter structure
  2896. *
  2897. * This routine is a task that is schedule by the interrupt handler
  2898. * to perform the background processing for interrupts. We put it
  2899. * on a task queue that is consumed whenever the scheduler runs; that's
  2900. * so you can do anything (i.e. put the process to sleep etc). In fact,
  2901. * the mid-level tries to sleep when it reaches the driver threshold
  2902. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  2903. **/
  2904. static void qla4xxx_do_dpc(struct work_struct *work)
  2905. {
  2906. struct scsi_qla_host *ha =
  2907. container_of(work, struct scsi_qla_host, dpc_work);
  2908. int status = QLA_ERROR;
  2909. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  2910. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  2911. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  2912. /* Initialization not yet finished. Don't do anything yet. */
  2913. if (!test_bit(AF_INIT_DONE, &ha->flags))
  2914. return;
  2915. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2916. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  2917. ha->host_no, __func__, ha->flags));
  2918. return;
  2919. }
  2920. /* post events to application */
  2921. qla4xxx_do_work(ha);
  2922. if (is_qla8022(ha)) {
  2923. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  2924. qla4_8xxx_idc_lock(ha);
  2925. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2926. QLA82XX_DEV_FAILED);
  2927. qla4_8xxx_idc_unlock(ha);
  2928. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  2929. qla4_8xxx_device_state_handler(ha);
  2930. }
  2931. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2932. qla4_8xxx_need_qsnt_handler(ha);
  2933. }
  2934. }
  2935. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  2936. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2937. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2938. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  2939. if (ql4xdontresethba) {
  2940. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  2941. ha->host_no, __func__));
  2942. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2943. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2944. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2945. goto dpc_post_reset_ha;
  2946. }
  2947. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2948. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2949. qla4xxx_recover_adapter(ha);
  2950. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2951. uint8_t wait_time = RESET_INTR_TOV;
  2952. while ((readw(&ha->reg->ctrl_status) &
  2953. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  2954. if (--wait_time == 0)
  2955. break;
  2956. msleep(1000);
  2957. }
  2958. if (wait_time == 0)
  2959. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  2960. "bit not cleared-- resetting\n",
  2961. ha->host_no, __func__));
  2962. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2963. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  2964. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2965. status = qla4xxx_recover_adapter(ha);
  2966. }
  2967. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2968. if (status == QLA_SUCCESS)
  2969. ha->isp_ops->enable_intrs(ha);
  2970. }
  2971. }
  2972. dpc_post_reset_ha:
  2973. /* ---- process AEN? --- */
  2974. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  2975. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  2976. /* ---- Get DHCP IP Address? --- */
  2977. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  2978. qla4xxx_get_dhcp_ip_address(ha);
  2979. /* ---- relogin device? --- */
  2980. if (adapter_up(ha) &&
  2981. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  2982. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  2983. }
  2984. /* ---- link change? --- */
  2985. if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  2986. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  2987. /* ---- link down? --- */
  2988. qla4xxx_mark_all_devices_missing(ha);
  2989. } else {
  2990. /* ---- link up? --- *
  2991. * F/W will auto login to all devices ONLY ONCE after
  2992. * link up during driver initialization and runtime
  2993. * fatal error recovery. Therefore, the driver must
  2994. * manually relogin to devices when recovering from
  2995. * connection failures, logouts, expired KATO, etc. */
  2996. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  2997. qla4xxx_build_ddb_list(ha, ha->is_reset);
  2998. iscsi_host_for_each_session(ha->host,
  2999. qla4xxx_login_flash_ddb);
  3000. } else
  3001. qla4xxx_relogin_all_devices(ha);
  3002. }
  3003. }
  3004. }
  3005. /**
  3006. * qla4xxx_free_adapter - release the adapter
  3007. * @ha: pointer to adapter structure
  3008. **/
  3009. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  3010. {
  3011. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3012. if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
  3013. /* Turn-off interrupts on the card. */
  3014. ha->isp_ops->disable_intrs(ha);
  3015. }
  3016. /* Remove timer thread, if present */
  3017. if (ha->timer_active)
  3018. qla4xxx_stop_timer(ha);
  3019. /* Kill the kernel thread for this host */
  3020. if (ha->dpc_thread)
  3021. destroy_workqueue(ha->dpc_thread);
  3022. /* Kill the kernel thread for this host */
  3023. if (ha->task_wq)
  3024. destroy_workqueue(ha->task_wq);
  3025. /* Put firmware in known state */
  3026. ha->isp_ops->reset_firmware(ha);
  3027. if (is_qla8022(ha)) {
  3028. qla4_8xxx_idc_lock(ha);
  3029. qla4_8xxx_clear_drv_active(ha);
  3030. qla4_8xxx_idc_unlock(ha);
  3031. }
  3032. /* Detach interrupts */
  3033. if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
  3034. qla4xxx_free_irqs(ha);
  3035. /* free extra memory */
  3036. qla4xxx_mem_free(ha);
  3037. }
  3038. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  3039. {
  3040. int status = 0;
  3041. unsigned long mem_base, mem_len, db_base, db_len;
  3042. struct pci_dev *pdev = ha->pdev;
  3043. status = pci_request_regions(pdev, DRIVER_NAME);
  3044. if (status) {
  3045. printk(KERN_WARNING
  3046. "scsi(%ld) Failed to reserve PIO regions (%s) "
  3047. "status=%d\n", ha->host_no, pci_name(pdev), status);
  3048. goto iospace_error_exit;
  3049. }
  3050. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  3051. __func__, pdev->revision));
  3052. ha->revision_id = pdev->revision;
  3053. /* remap phys address */
  3054. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  3055. mem_len = pci_resource_len(pdev, 0);
  3056. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  3057. __func__, mem_base, mem_len));
  3058. /* mapping of pcibase pointer */
  3059. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  3060. if (!ha->nx_pcibase) {
  3061. printk(KERN_ERR
  3062. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  3063. pci_release_regions(ha->pdev);
  3064. goto iospace_error_exit;
  3065. }
  3066. /* Mapping of IO base pointer, door bell read and write pointer */
  3067. /* mapping of IO base pointer */
  3068. ha->qla4_8xxx_reg =
  3069. (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
  3070. 0xbc000 + (ha->pdev->devfn << 11));
  3071. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  3072. db_len = pci_resource_len(pdev, 4);
  3073. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  3074. QLA82XX_CAM_RAM_DB2);
  3075. return 0;
  3076. iospace_error_exit:
  3077. return -ENOMEM;
  3078. }
  3079. /***
  3080. * qla4xxx_iospace_config - maps registers
  3081. * @ha: pointer to adapter structure
  3082. *
  3083. * This routines maps HBA's registers from the pci address space
  3084. * into the kernel virtual address space for memory mapped i/o.
  3085. **/
  3086. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  3087. {
  3088. unsigned long pio, pio_len, pio_flags;
  3089. unsigned long mmio, mmio_len, mmio_flags;
  3090. pio = pci_resource_start(ha->pdev, 0);
  3091. pio_len = pci_resource_len(ha->pdev, 0);
  3092. pio_flags = pci_resource_flags(ha->pdev, 0);
  3093. if (pio_flags & IORESOURCE_IO) {
  3094. if (pio_len < MIN_IOBASE_LEN) {
  3095. ql4_printk(KERN_WARNING, ha,
  3096. "Invalid PCI I/O region size\n");
  3097. pio = 0;
  3098. }
  3099. } else {
  3100. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  3101. pio = 0;
  3102. }
  3103. /* Use MMIO operations for all accesses. */
  3104. mmio = pci_resource_start(ha->pdev, 1);
  3105. mmio_len = pci_resource_len(ha->pdev, 1);
  3106. mmio_flags = pci_resource_flags(ha->pdev, 1);
  3107. if (!(mmio_flags & IORESOURCE_MEM)) {
  3108. ql4_printk(KERN_ERR, ha,
  3109. "region #0 not an MMIO resource, aborting\n");
  3110. goto iospace_error_exit;
  3111. }
  3112. if (mmio_len < MIN_IOBASE_LEN) {
  3113. ql4_printk(KERN_ERR, ha,
  3114. "Invalid PCI mem region size, aborting\n");
  3115. goto iospace_error_exit;
  3116. }
  3117. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  3118. ql4_printk(KERN_WARNING, ha,
  3119. "Failed to reserve PIO/MMIO regions\n");
  3120. goto iospace_error_exit;
  3121. }
  3122. ha->pio_address = pio;
  3123. ha->pio_length = pio_len;
  3124. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  3125. if (!ha->reg) {
  3126. ql4_printk(KERN_ERR, ha,
  3127. "cannot remap MMIO, aborting\n");
  3128. goto iospace_error_exit;
  3129. }
  3130. return 0;
  3131. iospace_error_exit:
  3132. return -ENOMEM;
  3133. }
  3134. static struct isp_operations qla4xxx_isp_ops = {
  3135. .iospace_config = qla4xxx_iospace_config,
  3136. .pci_config = qla4xxx_pci_config,
  3137. .disable_intrs = qla4xxx_disable_intrs,
  3138. .enable_intrs = qla4xxx_enable_intrs,
  3139. .start_firmware = qla4xxx_start_firmware,
  3140. .intr_handler = qla4xxx_intr_handler,
  3141. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  3142. .reset_chip = qla4xxx_soft_reset,
  3143. .reset_firmware = qla4xxx_hw_reset,
  3144. .queue_iocb = qla4xxx_queue_iocb,
  3145. .complete_iocb = qla4xxx_complete_iocb,
  3146. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3147. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3148. .get_sys_info = qla4xxx_get_sys_info,
  3149. };
  3150. static struct isp_operations qla4_8xxx_isp_ops = {
  3151. .iospace_config = qla4_8xxx_iospace_config,
  3152. .pci_config = qla4_8xxx_pci_config,
  3153. .disable_intrs = qla4_8xxx_disable_intrs,
  3154. .enable_intrs = qla4_8xxx_enable_intrs,
  3155. .start_firmware = qla4_8xxx_load_risc,
  3156. .intr_handler = qla4_8xxx_intr_handler,
  3157. .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
  3158. .reset_chip = qla4_8xxx_isp_reset,
  3159. .reset_firmware = qla4_8xxx_stop_firmware,
  3160. .queue_iocb = qla4_8xxx_queue_iocb,
  3161. .complete_iocb = qla4_8xxx_complete_iocb,
  3162. .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
  3163. .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
  3164. .get_sys_info = qla4_8xxx_get_sys_info,
  3165. };
  3166. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3167. {
  3168. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  3169. }
  3170. uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3171. {
  3172. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
  3173. }
  3174. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3175. {
  3176. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  3177. }
  3178. uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3179. {
  3180. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
  3181. }
  3182. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  3183. {
  3184. struct scsi_qla_host *ha = data;
  3185. char *str = buf;
  3186. int rc;
  3187. switch (type) {
  3188. case ISCSI_BOOT_ETH_FLAGS:
  3189. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3190. break;
  3191. case ISCSI_BOOT_ETH_INDEX:
  3192. rc = sprintf(str, "0\n");
  3193. break;
  3194. case ISCSI_BOOT_ETH_MAC:
  3195. rc = sysfs_format_mac(str, ha->my_mac,
  3196. MAC_ADDR_LEN);
  3197. break;
  3198. default:
  3199. rc = -ENOSYS;
  3200. break;
  3201. }
  3202. return rc;
  3203. }
  3204. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  3205. {
  3206. int rc;
  3207. switch (type) {
  3208. case ISCSI_BOOT_ETH_FLAGS:
  3209. case ISCSI_BOOT_ETH_MAC:
  3210. case ISCSI_BOOT_ETH_INDEX:
  3211. rc = S_IRUGO;
  3212. break;
  3213. default:
  3214. rc = 0;
  3215. break;
  3216. }
  3217. return rc;
  3218. }
  3219. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  3220. {
  3221. struct scsi_qla_host *ha = data;
  3222. char *str = buf;
  3223. int rc;
  3224. switch (type) {
  3225. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3226. rc = sprintf(str, "%s\n", ha->name_string);
  3227. break;
  3228. default:
  3229. rc = -ENOSYS;
  3230. break;
  3231. }
  3232. return rc;
  3233. }
  3234. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  3235. {
  3236. int rc;
  3237. switch (type) {
  3238. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3239. rc = S_IRUGO;
  3240. break;
  3241. default:
  3242. rc = 0;
  3243. break;
  3244. }
  3245. return rc;
  3246. }
  3247. static ssize_t
  3248. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  3249. char *buf)
  3250. {
  3251. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3252. char *str = buf;
  3253. int rc;
  3254. switch (type) {
  3255. case ISCSI_BOOT_TGT_NAME:
  3256. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  3257. break;
  3258. case ISCSI_BOOT_TGT_IP_ADDR:
  3259. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  3260. rc = sprintf(buf, "%pI4\n",
  3261. &boot_conn->dest_ipaddr.ip_address);
  3262. else
  3263. rc = sprintf(str, "%pI6\n",
  3264. &boot_conn->dest_ipaddr.ip_address);
  3265. break;
  3266. case ISCSI_BOOT_TGT_PORT:
  3267. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  3268. break;
  3269. case ISCSI_BOOT_TGT_CHAP_NAME:
  3270. rc = sprintf(str, "%.*s\n",
  3271. boot_conn->chap.target_chap_name_length,
  3272. (char *)&boot_conn->chap.target_chap_name);
  3273. break;
  3274. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3275. rc = sprintf(str, "%.*s\n",
  3276. boot_conn->chap.target_secret_length,
  3277. (char *)&boot_conn->chap.target_secret);
  3278. break;
  3279. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3280. rc = sprintf(str, "%.*s\n",
  3281. boot_conn->chap.intr_chap_name_length,
  3282. (char *)&boot_conn->chap.intr_chap_name);
  3283. break;
  3284. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3285. rc = sprintf(str, "%.*s\n",
  3286. boot_conn->chap.intr_secret_length,
  3287. (char *)&boot_conn->chap.intr_secret);
  3288. break;
  3289. case ISCSI_BOOT_TGT_FLAGS:
  3290. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3291. break;
  3292. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3293. rc = sprintf(str, "0\n");
  3294. break;
  3295. default:
  3296. rc = -ENOSYS;
  3297. break;
  3298. }
  3299. return rc;
  3300. }
  3301. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  3302. {
  3303. struct scsi_qla_host *ha = data;
  3304. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  3305. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3306. }
  3307. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  3308. {
  3309. struct scsi_qla_host *ha = data;
  3310. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  3311. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3312. }
  3313. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  3314. {
  3315. int rc;
  3316. switch (type) {
  3317. case ISCSI_BOOT_TGT_NAME:
  3318. case ISCSI_BOOT_TGT_IP_ADDR:
  3319. case ISCSI_BOOT_TGT_PORT:
  3320. case ISCSI_BOOT_TGT_CHAP_NAME:
  3321. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3322. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3323. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3324. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3325. case ISCSI_BOOT_TGT_FLAGS:
  3326. rc = S_IRUGO;
  3327. break;
  3328. default:
  3329. rc = 0;
  3330. break;
  3331. }
  3332. return rc;
  3333. }
  3334. static void qla4xxx_boot_release(void *data)
  3335. {
  3336. struct scsi_qla_host *ha = data;
  3337. scsi_host_put(ha->host);
  3338. }
  3339. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  3340. {
  3341. dma_addr_t buf_dma;
  3342. uint32_t addr, pri_addr, sec_addr;
  3343. uint32_t offset;
  3344. uint16_t func_num;
  3345. uint8_t val;
  3346. uint8_t *buf = NULL;
  3347. size_t size = 13 * sizeof(uint8_t);
  3348. int ret = QLA_SUCCESS;
  3349. func_num = PCI_FUNC(ha->pdev->devfn);
  3350. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  3351. __func__, ha->pdev->device, func_num);
  3352. if (is_qla40XX(ha)) {
  3353. if (func_num == 1) {
  3354. addr = NVRAM_PORT0_BOOT_MODE;
  3355. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  3356. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  3357. } else if (func_num == 3) {
  3358. addr = NVRAM_PORT1_BOOT_MODE;
  3359. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  3360. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  3361. } else {
  3362. ret = QLA_ERROR;
  3363. goto exit_boot_info;
  3364. }
  3365. /* Check Boot Mode */
  3366. val = rd_nvram_byte(ha, addr);
  3367. if (!(val & 0x07)) {
  3368. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  3369. "options : 0x%x\n", __func__, val));
  3370. ret = QLA_ERROR;
  3371. goto exit_boot_info;
  3372. }
  3373. /* get primary valid target index */
  3374. val = rd_nvram_byte(ha, pri_addr);
  3375. if (val & BIT_7)
  3376. ddb_index[0] = (val & 0x7f);
  3377. /* get secondary valid target index */
  3378. val = rd_nvram_byte(ha, sec_addr);
  3379. if (val & BIT_7)
  3380. ddb_index[1] = (val & 0x7f);
  3381. } else if (is_qla8022(ha)) {
  3382. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  3383. &buf_dma, GFP_KERNEL);
  3384. if (!buf) {
  3385. DEBUG2(ql4_printk(KERN_ERR, ha,
  3386. "%s: Unable to allocate dma buffer\n",
  3387. __func__));
  3388. ret = QLA_ERROR;
  3389. goto exit_boot_info;
  3390. }
  3391. if (ha->port_num == 0)
  3392. offset = BOOT_PARAM_OFFSET_PORT0;
  3393. else if (ha->port_num == 1)
  3394. offset = BOOT_PARAM_OFFSET_PORT1;
  3395. else {
  3396. ret = QLA_ERROR;
  3397. goto exit_boot_info_free;
  3398. }
  3399. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  3400. offset;
  3401. if (qla4xxx_get_flash(ha, buf_dma, addr,
  3402. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  3403. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  3404. " failed\n", ha->host_no, __func__));
  3405. ret = QLA_ERROR;
  3406. goto exit_boot_info_free;
  3407. }
  3408. /* Check Boot Mode */
  3409. if (!(buf[1] & 0x07)) {
  3410. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  3411. " : 0x%x\n", buf[1]));
  3412. ret = QLA_ERROR;
  3413. goto exit_boot_info_free;
  3414. }
  3415. /* get primary valid target index */
  3416. if (buf[2] & BIT_7)
  3417. ddb_index[0] = buf[2] & 0x7f;
  3418. /* get secondary valid target index */
  3419. if (buf[11] & BIT_7)
  3420. ddb_index[1] = buf[11] & 0x7f;
  3421. } else {
  3422. ret = QLA_ERROR;
  3423. goto exit_boot_info;
  3424. }
  3425. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  3426. " target ID %d\n", __func__, ddb_index[0],
  3427. ddb_index[1]));
  3428. exit_boot_info_free:
  3429. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  3430. exit_boot_info:
  3431. ha->pri_ddb_idx = ddb_index[0];
  3432. ha->sec_ddb_idx = ddb_index[1];
  3433. return ret;
  3434. }
  3435. /**
  3436. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  3437. * @ha: pointer to adapter structure
  3438. * @username: CHAP username to be returned
  3439. * @password: CHAP password to be returned
  3440. *
  3441. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  3442. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  3443. * So from the CHAP cache find the first BIDI CHAP entry and set it
  3444. * to the boot record in sysfs.
  3445. **/
  3446. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  3447. char *password)
  3448. {
  3449. int i, ret = -EINVAL;
  3450. int max_chap_entries = 0;
  3451. struct ql4_chap_table *chap_table;
  3452. if (is_qla8022(ha))
  3453. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  3454. sizeof(struct ql4_chap_table);
  3455. else
  3456. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  3457. if (!ha->chap_list) {
  3458. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  3459. return ret;
  3460. }
  3461. mutex_lock(&ha->chap_sem);
  3462. for (i = 0; i < max_chap_entries; i++) {
  3463. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  3464. if (chap_table->cookie !=
  3465. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  3466. continue;
  3467. }
  3468. if (chap_table->flags & BIT_7) /* local */
  3469. continue;
  3470. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  3471. continue;
  3472. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  3473. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  3474. ret = 0;
  3475. break;
  3476. }
  3477. mutex_unlock(&ha->chap_sem);
  3478. return ret;
  3479. }
  3480. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  3481. struct ql4_boot_session_info *boot_sess,
  3482. uint16_t ddb_index)
  3483. {
  3484. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3485. struct dev_db_entry *fw_ddb_entry;
  3486. dma_addr_t fw_ddb_entry_dma;
  3487. uint16_t idx;
  3488. uint16_t options;
  3489. int ret = QLA_SUCCESS;
  3490. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3491. &fw_ddb_entry_dma, GFP_KERNEL);
  3492. if (!fw_ddb_entry) {
  3493. DEBUG2(ql4_printk(KERN_ERR, ha,
  3494. "%s: Unable to allocate dma buffer.\n",
  3495. __func__));
  3496. ret = QLA_ERROR;
  3497. return ret;
  3498. }
  3499. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  3500. fw_ddb_entry_dma, ddb_index)) {
  3501. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  3502. "index [%d]\n", __func__, ddb_index));
  3503. ret = QLA_ERROR;
  3504. goto exit_boot_target;
  3505. }
  3506. /* Update target name and IP from DDB */
  3507. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  3508. min(sizeof(boot_sess->target_name),
  3509. sizeof(fw_ddb_entry->iscsi_name)));
  3510. options = le16_to_cpu(fw_ddb_entry->options);
  3511. if (options & DDB_OPT_IPV6_DEVICE) {
  3512. memcpy(&boot_conn->dest_ipaddr.ip_address,
  3513. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  3514. } else {
  3515. boot_conn->dest_ipaddr.ip_type = 0x1;
  3516. memcpy(&boot_conn->dest_ipaddr.ip_address,
  3517. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  3518. }
  3519. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  3520. /* update chap information */
  3521. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3522. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  3523. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  3524. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  3525. target_chap_name,
  3526. (char *)&boot_conn->chap.target_secret,
  3527. idx);
  3528. if (ret) {
  3529. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  3530. ret = QLA_ERROR;
  3531. goto exit_boot_target;
  3532. }
  3533. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  3534. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  3535. }
  3536. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  3537. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  3538. ret = qla4xxx_get_bidi_chap(ha,
  3539. (char *)&boot_conn->chap.intr_chap_name,
  3540. (char *)&boot_conn->chap.intr_secret);
  3541. if (ret) {
  3542. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  3543. ret = QLA_ERROR;
  3544. goto exit_boot_target;
  3545. }
  3546. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  3547. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  3548. }
  3549. exit_boot_target:
  3550. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3551. fw_ddb_entry, fw_ddb_entry_dma);
  3552. return ret;
  3553. }
  3554. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  3555. {
  3556. uint16_t ddb_index[2];
  3557. int ret = QLA_ERROR;
  3558. int rval;
  3559. memset(ddb_index, 0, sizeof(ddb_index));
  3560. ddb_index[0] = 0xffff;
  3561. ddb_index[1] = 0xffff;
  3562. ret = get_fw_boot_info(ha, ddb_index);
  3563. if (ret != QLA_SUCCESS) {
  3564. DEBUG2(ql4_printk(KERN_INFO, ha,
  3565. "%s: No boot target configured.\n", __func__));
  3566. return ret;
  3567. }
  3568. if (ql4xdisablesysfsboot)
  3569. return QLA_SUCCESS;
  3570. if (ddb_index[0] == 0xffff)
  3571. goto sec_target;
  3572. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  3573. ddb_index[0]);
  3574. if (rval != QLA_SUCCESS) {
  3575. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  3576. "configured\n", __func__));
  3577. } else
  3578. ret = QLA_SUCCESS;
  3579. sec_target:
  3580. if (ddb_index[1] == 0xffff)
  3581. goto exit_get_boot_info;
  3582. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  3583. ddb_index[1]);
  3584. if (rval != QLA_SUCCESS) {
  3585. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  3586. " configured\n", __func__));
  3587. } else
  3588. ret = QLA_SUCCESS;
  3589. exit_get_boot_info:
  3590. return ret;
  3591. }
  3592. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  3593. {
  3594. struct iscsi_boot_kobj *boot_kobj;
  3595. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  3596. return QLA_ERROR;
  3597. if (ql4xdisablesysfsboot) {
  3598. ql4_printk(KERN_INFO, ha,
  3599. "%s: syfsboot disabled - driver will trigger login "
  3600. "and publish session for discovery .\n", __func__);
  3601. return QLA_SUCCESS;
  3602. }
  3603. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  3604. if (!ha->boot_kset)
  3605. goto kset_free;
  3606. if (!scsi_host_get(ha->host))
  3607. goto kset_free;
  3608. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  3609. qla4xxx_show_boot_tgt_pri_info,
  3610. qla4xxx_tgt_get_attr_visibility,
  3611. qla4xxx_boot_release);
  3612. if (!boot_kobj)
  3613. goto put_host;
  3614. if (!scsi_host_get(ha->host))
  3615. goto kset_free;
  3616. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  3617. qla4xxx_show_boot_tgt_sec_info,
  3618. qla4xxx_tgt_get_attr_visibility,
  3619. qla4xxx_boot_release);
  3620. if (!boot_kobj)
  3621. goto put_host;
  3622. if (!scsi_host_get(ha->host))
  3623. goto kset_free;
  3624. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  3625. qla4xxx_show_boot_ini_info,
  3626. qla4xxx_ini_get_attr_visibility,
  3627. qla4xxx_boot_release);
  3628. if (!boot_kobj)
  3629. goto put_host;
  3630. if (!scsi_host_get(ha->host))
  3631. goto kset_free;
  3632. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  3633. qla4xxx_show_boot_eth_info,
  3634. qla4xxx_eth_get_attr_visibility,
  3635. qla4xxx_boot_release);
  3636. if (!boot_kobj)
  3637. goto put_host;
  3638. return QLA_SUCCESS;
  3639. put_host:
  3640. scsi_host_put(ha->host);
  3641. kset_free:
  3642. iscsi_boot_destroy_kset(ha->boot_kset);
  3643. return -ENOMEM;
  3644. }
  3645. /**
  3646. * qla4xxx_create chap_list - Create CHAP list from FLASH
  3647. * @ha: pointer to adapter structure
  3648. *
  3649. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  3650. * is received, it will be checked in this list. If entry exist then the CHAP
  3651. * entry index is set in the DDB. If CHAP entry does not exist in this list
  3652. * then a new entry is added in FLASH in CHAP table and the index obtained is
  3653. * used in the DDB.
  3654. **/
  3655. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  3656. {
  3657. int rval = 0;
  3658. uint8_t *chap_flash_data = NULL;
  3659. uint32_t offset;
  3660. dma_addr_t chap_dma;
  3661. uint32_t chap_size = 0;
  3662. if (is_qla40XX(ha))
  3663. chap_size = MAX_CHAP_ENTRIES_40XX *
  3664. sizeof(struct ql4_chap_table);
  3665. else /* Single region contains CHAP info for both
  3666. * ports which is divided into half for each port.
  3667. */
  3668. chap_size = ha->hw.flt_chap_size / 2;
  3669. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  3670. &chap_dma, GFP_KERNEL);
  3671. if (!chap_flash_data) {
  3672. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  3673. return;
  3674. }
  3675. if (is_qla40XX(ha))
  3676. offset = FLASH_CHAP_OFFSET;
  3677. else {
  3678. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  3679. if (ha->port_num == 1)
  3680. offset += chap_size;
  3681. }
  3682. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  3683. if (rval != QLA_SUCCESS)
  3684. goto exit_chap_list;
  3685. if (ha->chap_list == NULL)
  3686. ha->chap_list = vmalloc(chap_size);
  3687. if (ha->chap_list == NULL) {
  3688. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  3689. goto exit_chap_list;
  3690. }
  3691. memcpy(ha->chap_list, chap_flash_data, chap_size);
  3692. exit_chap_list:
  3693. dma_free_coherent(&ha->pdev->dev, chap_size,
  3694. chap_flash_data, chap_dma);
  3695. }
  3696. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  3697. struct ql4_tuple_ddb *tddb)
  3698. {
  3699. struct scsi_qla_host *ha;
  3700. struct iscsi_cls_session *cls_sess;
  3701. struct iscsi_cls_conn *cls_conn;
  3702. struct iscsi_session *sess;
  3703. struct iscsi_conn *conn;
  3704. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  3705. ha = ddb_entry->ha;
  3706. cls_sess = ddb_entry->sess;
  3707. sess = cls_sess->dd_data;
  3708. cls_conn = ddb_entry->conn;
  3709. conn = cls_conn->dd_data;
  3710. tddb->tpgt = sess->tpgt;
  3711. tddb->port = conn->persistent_port;
  3712. strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  3713. strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  3714. }
  3715. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  3716. struct ql4_tuple_ddb *tddb,
  3717. uint8_t *flash_isid)
  3718. {
  3719. uint16_t options = 0;
  3720. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  3721. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  3722. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  3723. options = le16_to_cpu(fw_ddb_entry->options);
  3724. if (options & DDB_OPT_IPV6_DEVICE)
  3725. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  3726. else
  3727. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  3728. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  3729. if (flash_isid == NULL)
  3730. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  3731. sizeof(tddb->isid));
  3732. else
  3733. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  3734. }
  3735. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  3736. struct ql4_tuple_ddb *old_tddb,
  3737. struct ql4_tuple_ddb *new_tddb,
  3738. uint8_t is_isid_compare)
  3739. {
  3740. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  3741. return QLA_ERROR;
  3742. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  3743. return QLA_ERROR;
  3744. if (old_tddb->port != new_tddb->port)
  3745. return QLA_ERROR;
  3746. /* For multi sessions, driver generates the ISID, so do not compare
  3747. * ISID in reset path since it would be a comparision between the
  3748. * driver generated ISID and firmware generated ISID. This could
  3749. * lead to adding duplicated DDBs in the list as driver generated
  3750. * ISID would not match firmware generated ISID.
  3751. */
  3752. if (is_isid_compare) {
  3753. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  3754. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  3755. __func__, old_tddb->isid[5], old_tddb->isid[4],
  3756. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  3757. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  3758. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  3759. new_tddb->isid[0]));
  3760. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  3761. sizeof(old_tddb->isid)))
  3762. return QLA_ERROR;
  3763. }
  3764. DEBUG2(ql4_printk(KERN_INFO, ha,
  3765. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  3766. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  3767. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  3768. new_tddb->ip_addr, new_tddb->iscsi_name));
  3769. return QLA_SUCCESS;
  3770. }
  3771. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  3772. struct dev_db_entry *fw_ddb_entry)
  3773. {
  3774. struct ddb_entry *ddb_entry;
  3775. struct ql4_tuple_ddb *fw_tddb = NULL;
  3776. struct ql4_tuple_ddb *tmp_tddb = NULL;
  3777. int idx;
  3778. int ret = QLA_ERROR;
  3779. fw_tddb = vzalloc(sizeof(*fw_tddb));
  3780. if (!fw_tddb) {
  3781. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3782. "Memory Allocation failed.\n"));
  3783. ret = QLA_SUCCESS;
  3784. goto exit_check;
  3785. }
  3786. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  3787. if (!tmp_tddb) {
  3788. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3789. "Memory Allocation failed.\n"));
  3790. ret = QLA_SUCCESS;
  3791. goto exit_check;
  3792. }
  3793. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  3794. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  3795. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  3796. if (ddb_entry == NULL)
  3797. continue;
  3798. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  3799. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  3800. ret = QLA_SUCCESS; /* found */
  3801. goto exit_check;
  3802. }
  3803. }
  3804. exit_check:
  3805. if (fw_tddb)
  3806. vfree(fw_tddb);
  3807. if (tmp_tddb)
  3808. vfree(tmp_tddb);
  3809. return ret;
  3810. }
  3811. /**
  3812. * qla4xxx_check_existing_isid - check if target with same isid exist
  3813. * in target list
  3814. * @list_nt: list of target
  3815. * @isid: isid to check
  3816. *
  3817. * This routine return QLA_SUCCESS if target with same isid exist
  3818. **/
  3819. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  3820. {
  3821. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  3822. struct dev_db_entry *fw_ddb_entry;
  3823. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  3824. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  3825. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  3826. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  3827. return QLA_SUCCESS;
  3828. }
  3829. }
  3830. return QLA_ERROR;
  3831. }
  3832. /**
  3833. * qla4xxx_update_isid - compare ddbs and updated isid
  3834. * @ha: Pointer to host adapter structure.
  3835. * @list_nt: list of nt target
  3836. * @fw_ddb_entry: firmware ddb entry
  3837. *
  3838. * This routine update isid if ddbs have same iqn, same isid and
  3839. * different IP addr.
  3840. * Return QLA_SUCCESS if isid is updated.
  3841. **/
  3842. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  3843. struct list_head *list_nt,
  3844. struct dev_db_entry *fw_ddb_entry)
  3845. {
  3846. uint8_t base_value, i;
  3847. base_value = fw_ddb_entry->isid[1] & 0x1f;
  3848. for (i = 0; i < 8; i++) {
  3849. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  3850. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  3851. break;
  3852. }
  3853. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  3854. return QLA_ERROR;
  3855. return QLA_SUCCESS;
  3856. }
  3857. /**
  3858. * qla4xxx_should_update_isid - check if isid need to update
  3859. * @ha: Pointer to host adapter structure.
  3860. * @old_tddb: ddb tuple
  3861. * @new_tddb: ddb tuple
  3862. *
  3863. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  3864. * same isid
  3865. **/
  3866. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  3867. struct ql4_tuple_ddb *old_tddb,
  3868. struct ql4_tuple_ddb *new_tddb)
  3869. {
  3870. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  3871. /* Same ip */
  3872. if (old_tddb->port == new_tddb->port)
  3873. return QLA_ERROR;
  3874. }
  3875. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  3876. /* different iqn */
  3877. return QLA_ERROR;
  3878. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  3879. sizeof(old_tddb->isid)))
  3880. /* different isid */
  3881. return QLA_ERROR;
  3882. return QLA_SUCCESS;
  3883. }
  3884. /**
  3885. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  3886. * @ha: Pointer to host adapter structure.
  3887. * @list_nt: list of nt target.
  3888. * @fw_ddb_entry: firmware ddb entry.
  3889. *
  3890. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  3891. * duplicate ddb in list_nt.
  3892. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  3893. * Note: This function also update isid of DDB if required.
  3894. **/
  3895. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  3896. struct list_head *list_nt,
  3897. struct dev_db_entry *fw_ddb_entry)
  3898. {
  3899. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  3900. struct ql4_tuple_ddb *fw_tddb = NULL;
  3901. struct ql4_tuple_ddb *tmp_tddb = NULL;
  3902. int rval, ret = QLA_ERROR;
  3903. fw_tddb = vzalloc(sizeof(*fw_tddb));
  3904. if (!fw_tddb) {
  3905. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3906. "Memory Allocation failed.\n"));
  3907. ret = QLA_SUCCESS;
  3908. goto exit_check;
  3909. }
  3910. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  3911. if (!tmp_tddb) {
  3912. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3913. "Memory Allocation failed.\n"));
  3914. ret = QLA_SUCCESS;
  3915. goto exit_check;
  3916. }
  3917. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  3918. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  3919. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  3920. nt_ddb_idx->flash_isid);
  3921. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  3922. /* found duplicate ddb */
  3923. if (ret == QLA_SUCCESS)
  3924. goto exit_check;
  3925. }
  3926. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  3927. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  3928. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  3929. if (ret == QLA_SUCCESS) {
  3930. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  3931. if (rval == QLA_SUCCESS)
  3932. ret = QLA_ERROR;
  3933. else
  3934. ret = QLA_SUCCESS;
  3935. goto exit_check;
  3936. }
  3937. }
  3938. exit_check:
  3939. if (fw_tddb)
  3940. vfree(fw_tddb);
  3941. if (tmp_tddb)
  3942. vfree(tmp_tddb);
  3943. return ret;
  3944. }
  3945. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  3946. {
  3947. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  3948. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  3949. list_del_init(&ddb_idx->list);
  3950. vfree(ddb_idx);
  3951. }
  3952. }
  3953. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  3954. struct dev_db_entry *fw_ddb_entry)
  3955. {
  3956. struct iscsi_endpoint *ep;
  3957. struct sockaddr_in *addr;
  3958. struct sockaddr_in6 *addr6;
  3959. struct sockaddr *dst_addr;
  3960. char *ip;
  3961. /* TODO: need to destroy on unload iscsi_endpoint*/
  3962. dst_addr = vmalloc(sizeof(*dst_addr));
  3963. if (!dst_addr)
  3964. return NULL;
  3965. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  3966. dst_addr->sa_family = AF_INET6;
  3967. addr6 = (struct sockaddr_in6 *)dst_addr;
  3968. ip = (char *)&addr6->sin6_addr;
  3969. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  3970. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  3971. } else {
  3972. dst_addr->sa_family = AF_INET;
  3973. addr = (struct sockaddr_in *)dst_addr;
  3974. ip = (char *)&addr->sin_addr;
  3975. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  3976. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  3977. }
  3978. ep = qla4xxx_ep_connect(ha->host, dst_addr, 0);
  3979. vfree(dst_addr);
  3980. return ep;
  3981. }
  3982. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  3983. {
  3984. if (ql4xdisablesysfsboot)
  3985. return QLA_SUCCESS;
  3986. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  3987. return QLA_ERROR;
  3988. return QLA_SUCCESS;
  3989. }
  3990. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  3991. struct ddb_entry *ddb_entry)
  3992. {
  3993. uint16_t def_timeout;
  3994. ddb_entry->ddb_type = FLASH_DDB;
  3995. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  3996. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  3997. ddb_entry->ha = ha;
  3998. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  3999. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  4000. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  4001. atomic_set(&ddb_entry->relogin_timer, 0);
  4002. atomic_set(&ddb_entry->relogin_retry_count, 0);
  4003. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  4004. ddb_entry->default_relogin_timeout =
  4005. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  4006. def_timeout : LOGIN_TOV;
  4007. ddb_entry->default_time2wait =
  4008. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  4009. }
  4010. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  4011. {
  4012. uint32_t idx = 0;
  4013. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  4014. uint32_t sts[MBOX_REG_COUNT];
  4015. uint32_t ip_state;
  4016. unsigned long wtime;
  4017. int ret;
  4018. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  4019. do {
  4020. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  4021. if (ip_idx[idx] == -1)
  4022. continue;
  4023. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  4024. if (ret == QLA_ERROR) {
  4025. ip_idx[idx] = -1;
  4026. continue;
  4027. }
  4028. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  4029. DEBUG2(ql4_printk(KERN_INFO, ha,
  4030. "Waiting for IP state for idx = %d, state = 0x%x\n",
  4031. ip_idx[idx], ip_state));
  4032. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  4033. ip_state == IP_ADDRSTATE_INVALID ||
  4034. ip_state == IP_ADDRSTATE_PREFERRED ||
  4035. ip_state == IP_ADDRSTATE_DEPRICATED ||
  4036. ip_state == IP_ADDRSTATE_DISABLING)
  4037. ip_idx[idx] = -1;
  4038. }
  4039. /* Break if all IP states checked */
  4040. if ((ip_idx[0] == -1) &&
  4041. (ip_idx[1] == -1) &&
  4042. (ip_idx[2] == -1) &&
  4043. (ip_idx[3] == -1))
  4044. break;
  4045. schedule_timeout_uninterruptible(HZ);
  4046. } while (time_after(wtime, jiffies));
  4047. }
  4048. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  4049. struct list_head *list_st)
  4050. {
  4051. struct qla_ddb_index *st_ddb_idx;
  4052. int max_ddbs;
  4053. int fw_idx_size;
  4054. struct dev_db_entry *fw_ddb_entry;
  4055. dma_addr_t fw_ddb_dma;
  4056. int ret;
  4057. uint32_t idx = 0, next_idx = 0;
  4058. uint32_t state = 0, conn_err = 0;
  4059. uint16_t conn_id = 0;
  4060. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4061. &fw_ddb_dma);
  4062. if (fw_ddb_entry == NULL) {
  4063. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4064. goto exit_st_list;
  4065. }
  4066. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4067. MAX_DEV_DB_ENTRIES;
  4068. fw_idx_size = sizeof(struct qla_ddb_index);
  4069. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4070. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4071. NULL, &next_idx, &state,
  4072. &conn_err, NULL, &conn_id);
  4073. if (ret == QLA_ERROR)
  4074. break;
  4075. /* Ignore DDB if invalid state (unassigned) */
  4076. if (state == DDB_DS_UNASSIGNED)
  4077. goto continue_next_st;
  4078. /* Check if ST, add to the list_st */
  4079. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  4080. goto continue_next_st;
  4081. st_ddb_idx = vzalloc(fw_idx_size);
  4082. if (!st_ddb_idx)
  4083. break;
  4084. st_ddb_idx->fw_ddb_idx = idx;
  4085. list_add_tail(&st_ddb_idx->list, list_st);
  4086. continue_next_st:
  4087. if (next_idx == 0)
  4088. break;
  4089. }
  4090. exit_st_list:
  4091. if (fw_ddb_entry)
  4092. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4093. }
  4094. /**
  4095. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  4096. * @ha: pointer to adapter structure
  4097. * @list_ddb: List from which failed ddb to be removed
  4098. *
  4099. * Iterate over the list of DDBs and find and remove DDBs that are either in
  4100. * no connection active state or failed state
  4101. **/
  4102. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  4103. struct list_head *list_ddb)
  4104. {
  4105. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4106. uint32_t next_idx = 0;
  4107. uint32_t state = 0, conn_err = 0;
  4108. int ret;
  4109. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4110. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  4111. NULL, 0, NULL, &next_idx, &state,
  4112. &conn_err, NULL, NULL);
  4113. if (ret == QLA_ERROR)
  4114. continue;
  4115. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4116. state == DDB_DS_SESSION_FAILED) {
  4117. list_del_init(&ddb_idx->list);
  4118. vfree(ddb_idx);
  4119. }
  4120. }
  4121. }
  4122. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  4123. struct dev_db_entry *fw_ddb_entry,
  4124. int is_reset)
  4125. {
  4126. struct iscsi_cls_session *cls_sess;
  4127. struct iscsi_session *sess;
  4128. struct iscsi_cls_conn *cls_conn;
  4129. struct iscsi_endpoint *ep;
  4130. uint16_t cmds_max = 32;
  4131. uint16_t conn_id = 0;
  4132. uint32_t initial_cmdsn = 0;
  4133. int ret = QLA_SUCCESS;
  4134. struct ddb_entry *ddb_entry = NULL;
  4135. /* Create session object, with INVALID_ENTRY,
  4136. * the targer_id would get set when we issue the login
  4137. */
  4138. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  4139. cmds_max, sizeof(struct ddb_entry),
  4140. sizeof(struct ql4_task_data),
  4141. initial_cmdsn, INVALID_ENTRY);
  4142. if (!cls_sess) {
  4143. ret = QLA_ERROR;
  4144. goto exit_setup;
  4145. }
  4146. /*
  4147. * so calling module_put function to decrement the
  4148. * reference count.
  4149. **/
  4150. module_put(qla4xxx_iscsi_transport.owner);
  4151. sess = cls_sess->dd_data;
  4152. ddb_entry = sess->dd_data;
  4153. ddb_entry->sess = cls_sess;
  4154. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  4155. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  4156. sizeof(struct dev_db_entry));
  4157. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry);
  4158. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  4159. if (!cls_conn) {
  4160. ret = QLA_ERROR;
  4161. goto exit_setup;
  4162. }
  4163. ddb_entry->conn = cls_conn;
  4164. /* Setup ep, for displaying attributes in sysfs */
  4165. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  4166. if (ep) {
  4167. ep->conn = cls_conn;
  4168. cls_conn->ep = ep;
  4169. } else {
  4170. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  4171. ret = QLA_ERROR;
  4172. goto exit_setup;
  4173. }
  4174. /* Update sess/conn params */
  4175. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  4176. if (is_reset == RESET_ADAPTER) {
  4177. iscsi_block_session(cls_sess);
  4178. /* Use the relogin path to discover new devices
  4179. * by short-circuting the logic of setting
  4180. * timer to relogin - instead set the flags
  4181. * to initiate login right away.
  4182. */
  4183. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4184. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4185. }
  4186. exit_setup:
  4187. return ret;
  4188. }
  4189. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  4190. struct list_head *list_nt, int is_reset)
  4191. {
  4192. struct dev_db_entry *fw_ddb_entry;
  4193. dma_addr_t fw_ddb_dma;
  4194. int max_ddbs;
  4195. int fw_idx_size;
  4196. int ret;
  4197. uint32_t idx = 0, next_idx = 0;
  4198. uint32_t state = 0, conn_err = 0;
  4199. uint16_t conn_id = 0;
  4200. struct qla_ddb_index *nt_ddb_idx;
  4201. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4202. &fw_ddb_dma);
  4203. if (fw_ddb_entry == NULL) {
  4204. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4205. goto exit_nt_list;
  4206. }
  4207. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4208. MAX_DEV_DB_ENTRIES;
  4209. fw_idx_size = sizeof(struct qla_ddb_index);
  4210. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4211. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4212. NULL, &next_idx, &state,
  4213. &conn_err, NULL, &conn_id);
  4214. if (ret == QLA_ERROR)
  4215. break;
  4216. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  4217. goto continue_next_nt;
  4218. /* Check if NT, then add to list it */
  4219. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  4220. goto continue_next_nt;
  4221. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4222. state == DDB_DS_SESSION_FAILED))
  4223. goto continue_next_nt;
  4224. DEBUG2(ql4_printk(KERN_INFO, ha,
  4225. "Adding DDB to session = 0x%x\n", idx));
  4226. if (is_reset == INIT_ADAPTER) {
  4227. nt_ddb_idx = vmalloc(fw_idx_size);
  4228. if (!nt_ddb_idx)
  4229. break;
  4230. nt_ddb_idx->fw_ddb_idx = idx;
  4231. /* Copy original isid as it may get updated in function
  4232. * qla4xxx_update_isid(). We need original isid in
  4233. * function qla4xxx_compare_tuple_ddb to find duplicate
  4234. * target */
  4235. memcpy(&nt_ddb_idx->flash_isid[0],
  4236. &fw_ddb_entry->isid[0],
  4237. sizeof(nt_ddb_idx->flash_isid));
  4238. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  4239. fw_ddb_entry);
  4240. if (ret == QLA_SUCCESS) {
  4241. /* free nt_ddb_idx and do not add to list_nt */
  4242. vfree(nt_ddb_idx);
  4243. goto continue_next_nt;
  4244. }
  4245. /* Copy updated isid */
  4246. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  4247. sizeof(struct dev_db_entry));
  4248. list_add_tail(&nt_ddb_idx->list, list_nt);
  4249. } else if (is_reset == RESET_ADAPTER) {
  4250. if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
  4251. QLA_SUCCESS)
  4252. goto continue_next_nt;
  4253. }
  4254. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset);
  4255. if (ret == QLA_ERROR)
  4256. goto exit_nt_list;
  4257. continue_next_nt:
  4258. if (next_idx == 0)
  4259. break;
  4260. }
  4261. exit_nt_list:
  4262. if (fw_ddb_entry)
  4263. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4264. }
  4265. /**
  4266. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  4267. * @ha: pointer to adapter structure
  4268. * @is_reset: Is this init path or reset path
  4269. *
  4270. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  4271. * using connection open, then create the list of normal targets (nt)
  4272. * from firmware DDBs. Based on the list of nt setup session and connection
  4273. * objects.
  4274. **/
  4275. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  4276. {
  4277. uint16_t tmo = 0;
  4278. struct list_head list_st, list_nt;
  4279. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  4280. unsigned long wtime;
  4281. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  4282. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  4283. ha->is_reset = is_reset;
  4284. return;
  4285. }
  4286. INIT_LIST_HEAD(&list_st);
  4287. INIT_LIST_HEAD(&list_nt);
  4288. qla4xxx_build_st_list(ha, &list_st);
  4289. /* Before issuing conn open mbox, ensure all IPs states are configured
  4290. * Note, conn open fails if IPs are not configured
  4291. */
  4292. qla4xxx_wait_for_ip_configuration(ha);
  4293. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  4294. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  4295. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  4296. }
  4297. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  4298. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  4299. (ha->def_timeout < LOGIN_TOV * 10) ?
  4300. ha->def_timeout : LOGIN_TOV);
  4301. DEBUG2(ql4_printk(KERN_INFO, ha,
  4302. "Default time to wait for build ddb %d\n", tmo));
  4303. wtime = jiffies + (HZ * tmo);
  4304. do {
  4305. if (list_empty(&list_st))
  4306. break;
  4307. qla4xxx_remove_failed_ddb(ha, &list_st);
  4308. schedule_timeout_uninterruptible(HZ / 10);
  4309. } while (time_after(wtime, jiffies));
  4310. /* Free up the sendtargets list */
  4311. qla4xxx_free_ddb_list(&list_st);
  4312. qla4xxx_build_nt_list(ha, &list_nt, is_reset);
  4313. qla4xxx_free_ddb_list(&list_nt);
  4314. qla4xxx_free_ddb_index(ha);
  4315. }
  4316. /**
  4317. * qla4xxx_probe_adapter - callback function to probe HBA
  4318. * @pdev: pointer to pci_dev structure
  4319. * @pci_device_id: pointer to pci_device entry
  4320. *
  4321. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  4322. * It returns zero if successful. It also initializes all data necessary for
  4323. * the driver.
  4324. **/
  4325. static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
  4326. const struct pci_device_id *ent)
  4327. {
  4328. int ret = -ENODEV, status;
  4329. struct Scsi_Host *host;
  4330. struct scsi_qla_host *ha;
  4331. uint8_t init_retry_count = 0;
  4332. char buf[34];
  4333. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  4334. uint32_t dev_state;
  4335. if (pci_enable_device(pdev))
  4336. return -1;
  4337. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  4338. if (host == NULL) {
  4339. printk(KERN_WARNING
  4340. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  4341. goto probe_disable_device;
  4342. }
  4343. /* Clear our data area */
  4344. ha = to_qla_host(host);
  4345. memset(ha, 0, sizeof(*ha));
  4346. /* Save the information from PCI BIOS. */
  4347. ha->pdev = pdev;
  4348. ha->host = host;
  4349. ha->host_no = host->host_no;
  4350. pci_enable_pcie_error_reporting(pdev);
  4351. /* Setup Runtime configurable options */
  4352. if (is_qla8022(ha)) {
  4353. ha->isp_ops = &qla4_8xxx_isp_ops;
  4354. rwlock_init(&ha->hw_lock);
  4355. ha->qdr_sn_window = -1;
  4356. ha->ddr_mn_window = -1;
  4357. ha->curr_window = 255;
  4358. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  4359. nx_legacy_intr = &legacy_intr[ha->func_num];
  4360. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  4361. ha->nx_legacy_intr.tgt_status_reg =
  4362. nx_legacy_intr->tgt_status_reg;
  4363. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  4364. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  4365. } else {
  4366. ha->isp_ops = &qla4xxx_isp_ops;
  4367. }
  4368. /* Set EEH reset type to fundamental if required by hba */
  4369. if (is_qla8022(ha))
  4370. pdev->needs_freset = 1;
  4371. /* Configure PCI I/O space. */
  4372. ret = ha->isp_ops->iospace_config(ha);
  4373. if (ret)
  4374. goto probe_failed_ioconfig;
  4375. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  4376. pdev->device, pdev->irq, ha->reg);
  4377. qla4xxx_config_dma_addressing(ha);
  4378. /* Initialize lists and spinlocks. */
  4379. INIT_LIST_HEAD(&ha->free_srb_q);
  4380. mutex_init(&ha->mbox_sem);
  4381. mutex_init(&ha->chap_sem);
  4382. init_completion(&ha->mbx_intr_comp);
  4383. init_completion(&ha->disable_acb_comp);
  4384. spin_lock_init(&ha->hardware_lock);
  4385. /* Initialize work list */
  4386. INIT_LIST_HEAD(&ha->work_list);
  4387. /* Allocate dma buffers */
  4388. if (qla4xxx_mem_alloc(ha)) {
  4389. ql4_printk(KERN_WARNING, ha,
  4390. "[ERROR] Failed to allocate memory for adapter\n");
  4391. ret = -ENOMEM;
  4392. goto probe_failed;
  4393. }
  4394. host->cmd_per_lun = 3;
  4395. host->max_channel = 0;
  4396. host->max_lun = MAX_LUNS - 1;
  4397. host->max_id = MAX_TARGETS;
  4398. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  4399. host->can_queue = MAX_SRBS ;
  4400. host->transportt = qla4xxx_scsi_transport;
  4401. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  4402. if (ret) {
  4403. ql4_printk(KERN_WARNING, ha,
  4404. "%s: scsi_init_shared_tag_map failed\n", __func__);
  4405. goto probe_failed;
  4406. }
  4407. pci_set_drvdata(pdev, ha);
  4408. ret = scsi_add_host(host, &pdev->dev);
  4409. if (ret)
  4410. goto probe_failed;
  4411. if (is_qla8022(ha))
  4412. (void) qla4_8xxx_get_flash_info(ha);
  4413. /*
  4414. * Initialize the Host adapter request/response queues and
  4415. * firmware
  4416. * NOTE: interrupts enabled upon successful completion
  4417. */
  4418. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  4419. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  4420. init_retry_count++ < MAX_INIT_RETRIES) {
  4421. if (is_qla8022(ha)) {
  4422. qla4_8xxx_idc_lock(ha);
  4423. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  4424. qla4_8xxx_idc_unlock(ha);
  4425. if (dev_state == QLA82XX_DEV_FAILED) {
  4426. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  4427. "initialize adapter. H/W is in failed state\n",
  4428. __func__);
  4429. break;
  4430. }
  4431. }
  4432. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  4433. "(%d)\n", __func__, init_retry_count));
  4434. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  4435. continue;
  4436. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  4437. }
  4438. if (!test_bit(AF_ONLINE, &ha->flags)) {
  4439. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  4440. if (is_qla8022(ha) && ql4xdontresethba) {
  4441. /* Put the device in failed state. */
  4442. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  4443. qla4_8xxx_idc_lock(ha);
  4444. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4445. QLA82XX_DEV_FAILED);
  4446. qla4_8xxx_idc_unlock(ha);
  4447. }
  4448. ret = -ENODEV;
  4449. goto remove_host;
  4450. }
  4451. /* Startup the kernel thread for this host adapter. */
  4452. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  4453. "qla4xxx_dpc\n", __func__));
  4454. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  4455. ha->dpc_thread = create_singlethread_workqueue(buf);
  4456. if (!ha->dpc_thread) {
  4457. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  4458. ret = -ENODEV;
  4459. goto remove_host;
  4460. }
  4461. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  4462. sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
  4463. ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
  4464. if (!ha->task_wq) {
  4465. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  4466. ret = -ENODEV;
  4467. goto remove_host;
  4468. }
  4469. /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
  4470. * (which is called indirectly by qla4xxx_initialize_adapter),
  4471. * so that irqs will be registered after crbinit but before
  4472. * mbx_intr_enable.
  4473. */
  4474. if (!is_qla8022(ha)) {
  4475. ret = qla4xxx_request_irqs(ha);
  4476. if (ret) {
  4477. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  4478. "interrupt %d already in use.\n", pdev->irq);
  4479. goto remove_host;
  4480. }
  4481. }
  4482. pci_save_state(ha->pdev);
  4483. ha->isp_ops->enable_intrs(ha);
  4484. /* Start timer thread. */
  4485. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  4486. set_bit(AF_INIT_DONE, &ha->flags);
  4487. qla4_8xxx_alloc_sysfs_attr(ha);
  4488. printk(KERN_INFO
  4489. " QLogic iSCSI HBA Driver version: %s\n"
  4490. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  4491. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  4492. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  4493. ha->patch_number, ha->build_number);
  4494. if (qla4xxx_setup_boot_info(ha))
  4495. ql4_printk(KERN_ERR, ha,
  4496. "%s: No iSCSI boot target configured\n", __func__);
  4497. /* Perform the build ddb list and login to each */
  4498. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  4499. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  4500. qla4xxx_create_chap_list(ha);
  4501. qla4xxx_create_ifaces(ha);
  4502. return 0;
  4503. remove_host:
  4504. scsi_remove_host(ha->host);
  4505. probe_failed:
  4506. qla4xxx_free_adapter(ha);
  4507. probe_failed_ioconfig:
  4508. pci_disable_pcie_error_reporting(pdev);
  4509. scsi_host_put(ha->host);
  4510. probe_disable_device:
  4511. pci_disable_device(pdev);
  4512. return ret;
  4513. }
  4514. /**
  4515. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  4516. * @ha: pointer to adapter structure
  4517. *
  4518. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  4519. * so that the other port will not re-initialize while in the process of
  4520. * removing the ha due to driver unload or hba hotplug.
  4521. **/
  4522. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  4523. {
  4524. struct scsi_qla_host *other_ha = NULL;
  4525. struct pci_dev *other_pdev = NULL;
  4526. int fn = ISP4XXX_PCI_FN_2;
  4527. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  4528. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  4529. fn = ISP4XXX_PCI_FN_1;
  4530. other_pdev =
  4531. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  4532. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  4533. fn));
  4534. /* Get other_ha if other_pdev is valid and state is enable*/
  4535. if (other_pdev) {
  4536. if (atomic_read(&other_pdev->enable_cnt)) {
  4537. other_ha = pci_get_drvdata(other_pdev);
  4538. if (other_ha) {
  4539. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  4540. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  4541. "Prevent %s reinit\n", __func__,
  4542. dev_name(&other_ha->pdev->dev)));
  4543. }
  4544. }
  4545. pci_dev_put(other_pdev);
  4546. }
  4547. }
  4548. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  4549. {
  4550. struct ddb_entry *ddb_entry;
  4551. int options;
  4552. int idx;
  4553. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  4554. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4555. if ((ddb_entry != NULL) &&
  4556. (ddb_entry->ddb_type == FLASH_DDB)) {
  4557. options = LOGOUT_OPTION_CLOSE_SESSION;
  4558. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
  4559. == QLA_ERROR)
  4560. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
  4561. __func__);
  4562. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  4563. /*
  4564. * we have decremented the reference count of the driver
  4565. * when we setup the session to have the driver unload
  4566. * to be seamless without actually destroying the
  4567. * session
  4568. **/
  4569. try_module_get(qla4xxx_iscsi_transport.owner);
  4570. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  4571. qla4xxx_free_ddb(ha, ddb_entry);
  4572. iscsi_session_teardown(ddb_entry->sess);
  4573. }
  4574. }
  4575. }
  4576. /**
  4577. * qla4xxx_remove_adapter - calback function to remove adapter.
  4578. * @pci_dev: PCI device pointer
  4579. **/
  4580. static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
  4581. {
  4582. struct scsi_qla_host *ha;
  4583. ha = pci_get_drvdata(pdev);
  4584. if (!is_qla8022(ha))
  4585. qla4xxx_prevent_other_port_reinit(ha);
  4586. /* destroy iface from sysfs */
  4587. qla4xxx_destroy_ifaces(ha);
  4588. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  4589. iscsi_boot_destroy_kset(ha->boot_kset);
  4590. qla4xxx_destroy_fw_ddb_session(ha);
  4591. qla4_8xxx_free_sysfs_attr(ha);
  4592. scsi_remove_host(ha->host);
  4593. qla4xxx_free_adapter(ha);
  4594. scsi_host_put(ha->host);
  4595. pci_disable_pcie_error_reporting(pdev);
  4596. pci_disable_device(pdev);
  4597. pci_set_drvdata(pdev, NULL);
  4598. }
  4599. /**
  4600. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  4601. * @ha: HA context
  4602. *
  4603. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  4604. * supported addressing method.
  4605. */
  4606. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  4607. {
  4608. int retval;
  4609. /* Update our PCI device dma_mask for full 64 bit mask */
  4610. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  4611. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  4612. dev_dbg(&ha->pdev->dev,
  4613. "Failed to set 64 bit PCI consistent mask; "
  4614. "using 32 bit.\n");
  4615. retval = pci_set_consistent_dma_mask(ha->pdev,
  4616. DMA_BIT_MASK(32));
  4617. }
  4618. } else
  4619. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  4620. }
  4621. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  4622. {
  4623. struct iscsi_cls_session *cls_sess;
  4624. struct iscsi_session *sess;
  4625. struct ddb_entry *ddb;
  4626. int queue_depth = QL4_DEF_QDEPTH;
  4627. cls_sess = starget_to_session(sdev->sdev_target);
  4628. sess = cls_sess->dd_data;
  4629. ddb = sess->dd_data;
  4630. sdev->hostdata = ddb;
  4631. sdev->tagged_supported = 1;
  4632. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  4633. queue_depth = ql4xmaxqdepth;
  4634. scsi_activate_tcq(sdev, queue_depth);
  4635. return 0;
  4636. }
  4637. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  4638. {
  4639. sdev->tagged_supported = 1;
  4640. return 0;
  4641. }
  4642. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  4643. {
  4644. scsi_deactivate_tcq(sdev, 1);
  4645. }
  4646. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  4647. int reason)
  4648. {
  4649. if (!ql4xqfulltracking)
  4650. return -EOPNOTSUPP;
  4651. return iscsi_change_queue_depth(sdev, qdepth, reason);
  4652. }
  4653. /**
  4654. * qla4xxx_del_from_active_array - returns an active srb
  4655. * @ha: Pointer to host adapter structure.
  4656. * @index: index into the active_array
  4657. *
  4658. * This routine removes and returns the srb at the specified index
  4659. **/
  4660. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  4661. uint32_t index)
  4662. {
  4663. struct srb *srb = NULL;
  4664. struct scsi_cmnd *cmd = NULL;
  4665. cmd = scsi_host_find_tag(ha->host, index);
  4666. if (!cmd)
  4667. return srb;
  4668. srb = (struct srb *)CMD_SP(cmd);
  4669. if (!srb)
  4670. return srb;
  4671. /* update counters */
  4672. if (srb->flags & SRB_DMA_VALID) {
  4673. ha->req_q_count += srb->iocb_cnt;
  4674. ha->iocb_cnt -= srb->iocb_cnt;
  4675. if (srb->cmd)
  4676. srb->cmd->host_scribble =
  4677. (unsigned char *)(unsigned long) MAX_SRBS;
  4678. }
  4679. return srb;
  4680. }
  4681. /**
  4682. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  4683. * @ha: Pointer to host adapter structure.
  4684. * @cmd: Scsi Command to wait on.
  4685. *
  4686. * This routine waits for the command to be returned by the Firmware
  4687. * for some max time.
  4688. **/
  4689. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  4690. struct scsi_cmnd *cmd)
  4691. {
  4692. int done = 0;
  4693. struct srb *rp;
  4694. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  4695. int ret = SUCCESS;
  4696. /* Dont wait on command if PCI error is being handled
  4697. * by PCI AER driver
  4698. */
  4699. if (unlikely(pci_channel_offline(ha->pdev)) ||
  4700. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  4701. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  4702. ha->host_no, __func__);
  4703. return ret;
  4704. }
  4705. do {
  4706. /* Checking to see if its returned to OS */
  4707. rp = (struct srb *) CMD_SP(cmd);
  4708. if (rp == NULL) {
  4709. done++;
  4710. break;
  4711. }
  4712. msleep(2000);
  4713. } while (max_wait_time--);
  4714. return done;
  4715. }
  4716. /**
  4717. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  4718. * @ha: Pointer to host adapter structure
  4719. **/
  4720. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  4721. {
  4722. unsigned long wait_online;
  4723. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  4724. while (time_before(jiffies, wait_online)) {
  4725. if (adapter_up(ha))
  4726. return QLA_SUCCESS;
  4727. msleep(2000);
  4728. }
  4729. return QLA_ERROR;
  4730. }
  4731. /**
  4732. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  4733. * @ha: pointer to HBA
  4734. * @t: target id
  4735. * @l: lun id
  4736. *
  4737. * This function waits for all outstanding commands to a lun to complete. It
  4738. * returns 0 if all pending commands are returned and 1 otherwise.
  4739. **/
  4740. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  4741. struct scsi_target *stgt,
  4742. struct scsi_device *sdev)
  4743. {
  4744. int cnt;
  4745. int status = 0;
  4746. struct scsi_cmnd *cmd;
  4747. /*
  4748. * Waiting for all commands for the designated target or dev
  4749. * in the active array
  4750. */
  4751. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  4752. cmd = scsi_host_find_tag(ha->host, cnt);
  4753. if (cmd && stgt == scsi_target(cmd->device) &&
  4754. (!sdev || sdev == cmd->device)) {
  4755. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  4756. status++;
  4757. break;
  4758. }
  4759. }
  4760. }
  4761. return status;
  4762. }
  4763. /**
  4764. * qla4xxx_eh_abort - callback for abort task.
  4765. * @cmd: Pointer to Linux's SCSI command structure
  4766. *
  4767. * This routine is called by the Linux OS to abort the specified
  4768. * command.
  4769. **/
  4770. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  4771. {
  4772. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  4773. unsigned int id = cmd->device->id;
  4774. unsigned int lun = cmd->device->lun;
  4775. unsigned long flags;
  4776. struct srb *srb = NULL;
  4777. int ret = SUCCESS;
  4778. int wait = 0;
  4779. ql4_printk(KERN_INFO, ha,
  4780. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  4781. ha->host_no, id, lun, cmd);
  4782. spin_lock_irqsave(&ha->hardware_lock, flags);
  4783. srb = (struct srb *) CMD_SP(cmd);
  4784. if (!srb) {
  4785. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4786. return SUCCESS;
  4787. }
  4788. kref_get(&srb->srb_ref);
  4789. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4790. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  4791. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  4792. ha->host_no, id, lun));
  4793. ret = FAILED;
  4794. } else {
  4795. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  4796. ha->host_no, id, lun));
  4797. wait = 1;
  4798. }
  4799. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  4800. /* Wait for command to complete */
  4801. if (wait) {
  4802. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  4803. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  4804. ha->host_no, id, lun));
  4805. ret = FAILED;
  4806. }
  4807. }
  4808. ql4_printk(KERN_INFO, ha,
  4809. "scsi%ld:%d:%d: Abort command - %s\n",
  4810. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  4811. return ret;
  4812. }
  4813. /**
  4814. * qla4xxx_eh_device_reset - callback for target reset.
  4815. * @cmd: Pointer to Linux's SCSI command structure
  4816. *
  4817. * This routine is called by the Linux OS to reset all luns on the
  4818. * specified target.
  4819. **/
  4820. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  4821. {
  4822. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  4823. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  4824. int ret = FAILED, stat;
  4825. if (!ddb_entry)
  4826. return ret;
  4827. ret = iscsi_block_scsi_eh(cmd);
  4828. if (ret)
  4829. return ret;
  4830. ret = FAILED;
  4831. ql4_printk(KERN_INFO, ha,
  4832. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  4833. cmd->device->channel, cmd->device->id, cmd->device->lun);
  4834. DEBUG2(printk(KERN_INFO
  4835. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  4836. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  4837. cmd, jiffies, cmd->request->timeout / HZ,
  4838. ha->dpc_flags, cmd->result, cmd->allowed));
  4839. /* FIXME: wait for hba to go online */
  4840. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  4841. if (stat != QLA_SUCCESS) {
  4842. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  4843. goto eh_dev_reset_done;
  4844. }
  4845. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  4846. cmd->device)) {
  4847. ql4_printk(KERN_INFO, ha,
  4848. "DEVICE RESET FAILED - waiting for "
  4849. "commands.\n");
  4850. goto eh_dev_reset_done;
  4851. }
  4852. /* Send marker. */
  4853. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  4854. MM_LUN_RESET) != QLA_SUCCESS)
  4855. goto eh_dev_reset_done;
  4856. ql4_printk(KERN_INFO, ha,
  4857. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  4858. ha->host_no, cmd->device->channel, cmd->device->id,
  4859. cmd->device->lun);
  4860. ret = SUCCESS;
  4861. eh_dev_reset_done:
  4862. return ret;
  4863. }
  4864. /**
  4865. * qla4xxx_eh_target_reset - callback for target reset.
  4866. * @cmd: Pointer to Linux's SCSI command structure
  4867. *
  4868. * This routine is called by the Linux OS to reset the target.
  4869. **/
  4870. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  4871. {
  4872. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  4873. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  4874. int stat, ret;
  4875. if (!ddb_entry)
  4876. return FAILED;
  4877. ret = iscsi_block_scsi_eh(cmd);
  4878. if (ret)
  4879. return ret;
  4880. starget_printk(KERN_INFO, scsi_target(cmd->device),
  4881. "WARM TARGET RESET ISSUED.\n");
  4882. DEBUG2(printk(KERN_INFO
  4883. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  4884. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  4885. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  4886. ha->dpc_flags, cmd->result, cmd->allowed));
  4887. stat = qla4xxx_reset_target(ha, ddb_entry);
  4888. if (stat != QLA_SUCCESS) {
  4889. starget_printk(KERN_INFO, scsi_target(cmd->device),
  4890. "WARM TARGET RESET FAILED.\n");
  4891. return FAILED;
  4892. }
  4893. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  4894. NULL)) {
  4895. starget_printk(KERN_INFO, scsi_target(cmd->device),
  4896. "WARM TARGET DEVICE RESET FAILED - "
  4897. "waiting for commands.\n");
  4898. return FAILED;
  4899. }
  4900. /* Send marker. */
  4901. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  4902. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  4903. starget_printk(KERN_INFO, scsi_target(cmd->device),
  4904. "WARM TARGET DEVICE RESET FAILED - "
  4905. "marker iocb failed.\n");
  4906. return FAILED;
  4907. }
  4908. starget_printk(KERN_INFO, scsi_target(cmd->device),
  4909. "WARM TARGET RESET SUCCEEDED.\n");
  4910. return SUCCESS;
  4911. }
  4912. /**
  4913. * qla4xxx_is_eh_active - check if error handler is running
  4914. * @shost: Pointer to SCSI Host struct
  4915. *
  4916. * This routine finds that if reset host is called in EH
  4917. * scenario or from some application like sg_reset
  4918. **/
  4919. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  4920. {
  4921. if (shost->shost_state == SHOST_RECOVERY)
  4922. return 1;
  4923. return 0;
  4924. }
  4925. /**
  4926. * qla4xxx_eh_host_reset - kernel callback
  4927. * @cmd: Pointer to Linux's SCSI command structure
  4928. *
  4929. * This routine is invoked by the Linux kernel to perform fatal error
  4930. * recovery on the specified adapter.
  4931. **/
  4932. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  4933. {
  4934. int return_status = FAILED;
  4935. struct scsi_qla_host *ha;
  4936. ha = to_qla_host(cmd->device->host);
  4937. if (ql4xdontresethba) {
  4938. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  4939. ha->host_no, __func__));
  4940. /* Clear outstanding srb in queues */
  4941. if (qla4xxx_is_eh_active(cmd->device->host))
  4942. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  4943. return FAILED;
  4944. }
  4945. ql4_printk(KERN_INFO, ha,
  4946. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  4947. cmd->device->channel, cmd->device->id, cmd->device->lun);
  4948. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  4949. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  4950. "DEAD.\n", ha->host_no, cmd->device->channel,
  4951. __func__));
  4952. return FAILED;
  4953. }
  4954. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  4955. if (is_qla8022(ha))
  4956. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  4957. else
  4958. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  4959. }
  4960. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  4961. return_status = SUCCESS;
  4962. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  4963. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  4964. return return_status;
  4965. }
  4966. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  4967. {
  4968. uint32_t mbox_cmd[MBOX_REG_COUNT];
  4969. uint32_t mbox_sts[MBOX_REG_COUNT];
  4970. struct addr_ctrl_blk_def *acb = NULL;
  4971. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  4972. int rval = QLA_SUCCESS;
  4973. dma_addr_t acb_dma;
  4974. acb = dma_alloc_coherent(&ha->pdev->dev,
  4975. sizeof(struct addr_ctrl_blk_def),
  4976. &acb_dma, GFP_KERNEL);
  4977. if (!acb) {
  4978. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  4979. __func__);
  4980. rval = -ENOMEM;
  4981. goto exit_port_reset;
  4982. }
  4983. memset(acb, 0, acb_len);
  4984. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  4985. if (rval != QLA_SUCCESS) {
  4986. rval = -EIO;
  4987. goto exit_free_acb;
  4988. }
  4989. rval = qla4xxx_disable_acb(ha);
  4990. if (rval != QLA_SUCCESS) {
  4991. rval = -EIO;
  4992. goto exit_free_acb;
  4993. }
  4994. wait_for_completion_timeout(&ha->disable_acb_comp,
  4995. DISABLE_ACB_TOV * HZ);
  4996. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  4997. if (rval != QLA_SUCCESS) {
  4998. rval = -EIO;
  4999. goto exit_free_acb;
  5000. }
  5001. exit_free_acb:
  5002. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  5003. acb, acb_dma);
  5004. exit_port_reset:
  5005. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  5006. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  5007. return rval;
  5008. }
  5009. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  5010. {
  5011. struct scsi_qla_host *ha = to_qla_host(shost);
  5012. int rval = QLA_SUCCESS;
  5013. if (ql4xdontresethba) {
  5014. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  5015. __func__));
  5016. rval = -EPERM;
  5017. goto exit_host_reset;
  5018. }
  5019. rval = qla4xxx_wait_for_hba_online(ha);
  5020. if (rval != QLA_SUCCESS) {
  5021. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
  5022. "adapter\n", __func__));
  5023. rval = -EIO;
  5024. goto exit_host_reset;
  5025. }
  5026. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  5027. goto recover_adapter;
  5028. switch (reset_type) {
  5029. case SCSI_ADAPTER_RESET:
  5030. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  5031. break;
  5032. case SCSI_FIRMWARE_RESET:
  5033. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  5034. if (is_qla8022(ha))
  5035. /* set firmware context reset */
  5036. set_bit(DPC_RESET_HA_FW_CONTEXT,
  5037. &ha->dpc_flags);
  5038. else {
  5039. rval = qla4xxx_context_reset(ha);
  5040. goto exit_host_reset;
  5041. }
  5042. }
  5043. break;
  5044. }
  5045. recover_adapter:
  5046. rval = qla4xxx_recover_adapter(ha);
  5047. if (rval != QLA_SUCCESS) {
  5048. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  5049. __func__));
  5050. rval = -EIO;
  5051. }
  5052. exit_host_reset:
  5053. return rval;
  5054. }
  5055. /* PCI AER driver recovers from all correctable errors w/o
  5056. * driver intervention. For uncorrectable errors PCI AER
  5057. * driver calls the following device driver's callbacks
  5058. *
  5059. * - Fatal Errors - link_reset
  5060. * - Non-Fatal Errors - driver's pci_error_detected() which
  5061. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  5062. *
  5063. * PCI AER driver calls
  5064. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  5065. * returns RECOVERED or NEED_RESET if fw_hung
  5066. * NEED_RESET - driver's slot_reset()
  5067. * DISCONNECT - device is dead & cannot recover
  5068. * RECOVERED - driver's pci_resume()
  5069. */
  5070. static pci_ers_result_t
  5071. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  5072. {
  5073. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5074. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  5075. ha->host_no, __func__, state);
  5076. if (!is_aer_supported(ha))
  5077. return PCI_ERS_RESULT_NONE;
  5078. switch (state) {
  5079. case pci_channel_io_normal:
  5080. clear_bit(AF_EEH_BUSY, &ha->flags);
  5081. return PCI_ERS_RESULT_CAN_RECOVER;
  5082. case pci_channel_io_frozen:
  5083. set_bit(AF_EEH_BUSY, &ha->flags);
  5084. qla4xxx_mailbox_premature_completion(ha);
  5085. qla4xxx_free_irqs(ha);
  5086. pci_disable_device(pdev);
  5087. /* Return back all IOs */
  5088. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  5089. return PCI_ERS_RESULT_NEED_RESET;
  5090. case pci_channel_io_perm_failure:
  5091. set_bit(AF_EEH_BUSY, &ha->flags);
  5092. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  5093. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  5094. return PCI_ERS_RESULT_DISCONNECT;
  5095. }
  5096. return PCI_ERS_RESULT_NEED_RESET;
  5097. }
  5098. /**
  5099. * qla4xxx_pci_mmio_enabled() gets called if
  5100. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  5101. * and read/write to the device still works.
  5102. **/
  5103. static pci_ers_result_t
  5104. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  5105. {
  5106. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5107. if (!is_aer_supported(ha))
  5108. return PCI_ERS_RESULT_NONE;
  5109. return PCI_ERS_RESULT_RECOVERED;
  5110. }
  5111. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  5112. {
  5113. uint32_t rval = QLA_ERROR;
  5114. uint32_t ret = 0;
  5115. int fn;
  5116. struct pci_dev *other_pdev = NULL;
  5117. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  5118. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  5119. if (test_bit(AF_ONLINE, &ha->flags)) {
  5120. clear_bit(AF_ONLINE, &ha->flags);
  5121. clear_bit(AF_LINK_UP, &ha->flags);
  5122. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  5123. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  5124. }
  5125. fn = PCI_FUNC(ha->pdev->devfn);
  5126. while (fn > 0) {
  5127. fn--;
  5128. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  5129. "func %x\n", ha->host_no, __func__, fn);
  5130. /* Get the pci device given the domain, bus,
  5131. * slot/function number */
  5132. other_pdev =
  5133. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  5134. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  5135. fn));
  5136. if (!other_pdev)
  5137. continue;
  5138. if (atomic_read(&other_pdev->enable_cnt)) {
  5139. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  5140. "func in enabled state%x\n", ha->host_no,
  5141. __func__, fn);
  5142. pci_dev_put(other_pdev);
  5143. break;
  5144. }
  5145. pci_dev_put(other_pdev);
  5146. }
  5147. /* The first function on the card, the reset owner will
  5148. * start & initialize the firmware. The other functions
  5149. * on the card will reset the firmware context
  5150. */
  5151. if (!fn) {
  5152. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  5153. "0x%x is the owner\n", ha->host_no, __func__,
  5154. ha->pdev->devfn);
  5155. qla4_8xxx_idc_lock(ha);
  5156. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5157. QLA82XX_DEV_COLD);
  5158. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  5159. QLA82XX_IDC_VERSION);
  5160. qla4_8xxx_idc_unlock(ha);
  5161. clear_bit(AF_FW_RECOVERY, &ha->flags);
  5162. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  5163. qla4_8xxx_idc_lock(ha);
  5164. if (rval != QLA_SUCCESS) {
  5165. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  5166. "FAILED\n", ha->host_no, __func__);
  5167. qla4_8xxx_clear_drv_active(ha);
  5168. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5169. QLA82XX_DEV_FAILED);
  5170. } else {
  5171. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  5172. "READY\n", ha->host_no, __func__);
  5173. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5174. QLA82XX_DEV_READY);
  5175. /* Clear driver state register */
  5176. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  5177. qla4_8xxx_set_drv_active(ha);
  5178. ret = qla4xxx_request_irqs(ha);
  5179. if (ret) {
  5180. ql4_printk(KERN_WARNING, ha, "Failed to "
  5181. "reserve interrupt %d already in use.\n",
  5182. ha->pdev->irq);
  5183. rval = QLA_ERROR;
  5184. } else {
  5185. ha->isp_ops->enable_intrs(ha);
  5186. rval = QLA_SUCCESS;
  5187. }
  5188. }
  5189. qla4_8xxx_idc_unlock(ha);
  5190. } else {
  5191. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  5192. "the reset owner\n", ha->host_no, __func__,
  5193. ha->pdev->devfn);
  5194. if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  5195. QLA82XX_DEV_READY)) {
  5196. clear_bit(AF_FW_RECOVERY, &ha->flags);
  5197. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  5198. if (rval == QLA_SUCCESS) {
  5199. ret = qla4xxx_request_irqs(ha);
  5200. if (ret) {
  5201. ql4_printk(KERN_WARNING, ha, "Failed to"
  5202. " reserve interrupt %d already in"
  5203. " use.\n", ha->pdev->irq);
  5204. rval = QLA_ERROR;
  5205. } else {
  5206. ha->isp_ops->enable_intrs(ha);
  5207. rval = QLA_SUCCESS;
  5208. }
  5209. }
  5210. qla4_8xxx_idc_lock(ha);
  5211. qla4_8xxx_set_drv_active(ha);
  5212. qla4_8xxx_idc_unlock(ha);
  5213. }
  5214. }
  5215. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  5216. return rval;
  5217. }
  5218. static pci_ers_result_t
  5219. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  5220. {
  5221. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  5222. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5223. int rc;
  5224. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  5225. ha->host_no, __func__);
  5226. if (!is_aer_supported(ha))
  5227. return PCI_ERS_RESULT_NONE;
  5228. /* Restore the saved state of PCIe device -
  5229. * BAR registers, PCI Config space, PCIX, MSI,
  5230. * IOV states
  5231. */
  5232. pci_restore_state(pdev);
  5233. /* pci_restore_state() clears the saved_state flag of the device
  5234. * save restored state which resets saved_state flag
  5235. */
  5236. pci_save_state(pdev);
  5237. /* Initialize device or resume if in suspended state */
  5238. rc = pci_enable_device(pdev);
  5239. if (rc) {
  5240. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  5241. "device after reset\n", ha->host_no, __func__);
  5242. goto exit_slot_reset;
  5243. }
  5244. ha->isp_ops->disable_intrs(ha);
  5245. if (is_qla8022(ha)) {
  5246. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  5247. ret = PCI_ERS_RESULT_RECOVERED;
  5248. goto exit_slot_reset;
  5249. } else
  5250. goto exit_slot_reset;
  5251. }
  5252. exit_slot_reset:
  5253. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  5254. "device after reset\n", ha->host_no, __func__, ret);
  5255. return ret;
  5256. }
  5257. static void
  5258. qla4xxx_pci_resume(struct pci_dev *pdev)
  5259. {
  5260. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5261. int ret;
  5262. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  5263. ha->host_no, __func__);
  5264. ret = qla4xxx_wait_for_hba_online(ha);
  5265. if (ret != QLA_SUCCESS) {
  5266. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  5267. "resume I/O from slot/link_reset\n", ha->host_no,
  5268. __func__);
  5269. }
  5270. pci_cleanup_aer_uncorrect_error_status(pdev);
  5271. clear_bit(AF_EEH_BUSY, &ha->flags);
  5272. }
  5273. static struct pci_error_handlers qla4xxx_err_handler = {
  5274. .error_detected = qla4xxx_pci_error_detected,
  5275. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  5276. .slot_reset = qla4xxx_pci_slot_reset,
  5277. .resume = qla4xxx_pci_resume,
  5278. };
  5279. static struct pci_device_id qla4xxx_pci_tbl[] = {
  5280. {
  5281. .vendor = PCI_VENDOR_ID_QLOGIC,
  5282. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  5283. .subvendor = PCI_ANY_ID,
  5284. .subdevice = PCI_ANY_ID,
  5285. },
  5286. {
  5287. .vendor = PCI_VENDOR_ID_QLOGIC,
  5288. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  5289. .subvendor = PCI_ANY_ID,
  5290. .subdevice = PCI_ANY_ID,
  5291. },
  5292. {
  5293. .vendor = PCI_VENDOR_ID_QLOGIC,
  5294. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  5295. .subvendor = PCI_ANY_ID,
  5296. .subdevice = PCI_ANY_ID,
  5297. },
  5298. {
  5299. .vendor = PCI_VENDOR_ID_QLOGIC,
  5300. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  5301. .subvendor = PCI_ANY_ID,
  5302. .subdevice = PCI_ANY_ID,
  5303. },
  5304. {0, 0},
  5305. };
  5306. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  5307. static struct pci_driver qla4xxx_pci_driver = {
  5308. .name = DRIVER_NAME,
  5309. .id_table = qla4xxx_pci_tbl,
  5310. .probe = qla4xxx_probe_adapter,
  5311. .remove = qla4xxx_remove_adapter,
  5312. .err_handler = &qla4xxx_err_handler,
  5313. };
  5314. static int __init qla4xxx_module_init(void)
  5315. {
  5316. int ret;
  5317. /* Allocate cache for SRBs. */
  5318. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  5319. SLAB_HWCACHE_ALIGN, NULL);
  5320. if (srb_cachep == NULL) {
  5321. printk(KERN_ERR
  5322. "%s: Unable to allocate SRB cache..."
  5323. "Failing load!\n", DRIVER_NAME);
  5324. ret = -ENOMEM;
  5325. goto no_srp_cache;
  5326. }
  5327. /* Derive version string. */
  5328. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  5329. if (ql4xextended_error_logging)
  5330. strcat(qla4xxx_version_str, "-debug");
  5331. qla4xxx_scsi_transport =
  5332. iscsi_register_transport(&qla4xxx_iscsi_transport);
  5333. if (!qla4xxx_scsi_transport){
  5334. ret = -ENODEV;
  5335. goto release_srb_cache;
  5336. }
  5337. ret = pci_register_driver(&qla4xxx_pci_driver);
  5338. if (ret)
  5339. goto unregister_transport;
  5340. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  5341. return 0;
  5342. unregister_transport:
  5343. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  5344. release_srb_cache:
  5345. kmem_cache_destroy(srb_cachep);
  5346. no_srp_cache:
  5347. return ret;
  5348. }
  5349. static void __exit qla4xxx_module_exit(void)
  5350. {
  5351. pci_unregister_driver(&qla4xxx_pci_driver);
  5352. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  5353. kmem_cache_destroy(srb_cachep);
  5354. }
  5355. module_init(qla4xxx_module_init);
  5356. module_exit(qla4xxx_module_exit);
  5357. MODULE_AUTHOR("QLogic Corporation");
  5358. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  5359. MODULE_LICENSE("GPL");
  5360. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);