ql4_os.c 239 KB

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