ql4_os.c 233 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2012 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 < MAX_DDB_ENTRIES)
  2099. sess->discovery_parent_idx = ddb_link;
  2100. else
  2101. sess->discovery_parent_idx = DDB_NO_LINK;
  2102. if (ddb_link == DDB_ISNS)
  2103. disc_parent = ISCSI_DISC_PARENT_ISNS;
  2104. else if (ddb_link == DDB_NO_LINK)
  2105. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2106. else if (ddb_link < MAX_DDB_ENTRIES)
  2107. disc_parent = ISCSI_DISC_PARENT_SENDTGT;
  2108. else
  2109. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2110. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
  2111. iscsi_get_discovery_parent_name(disc_parent), 0);
  2112. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  2113. (char *)fw_ddb_entry->iscsi_alias, 0);
  2114. }
  2115. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  2116. struct dev_db_entry *fw_ddb_entry,
  2117. struct iscsi_cls_session *cls_sess,
  2118. struct iscsi_cls_conn *cls_conn)
  2119. {
  2120. int buflen = 0;
  2121. struct iscsi_session *sess;
  2122. struct ddb_entry *ddb_entry;
  2123. struct iscsi_conn *conn;
  2124. char ip_addr[DDB_IPADDR_LEN];
  2125. uint16_t options = 0;
  2126. sess = cls_sess->dd_data;
  2127. ddb_entry = sess->dd_data;
  2128. conn = cls_conn->dd_data;
  2129. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2130. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2131. sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
  2132. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  2133. memset(ip_addr, 0, sizeof(ip_addr));
  2134. options = le16_to_cpu(fw_ddb_entry->options);
  2135. if (options & DDB_OPT_IPV6_DEVICE) {
  2136. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
  2137. memset(ip_addr, 0, sizeof(ip_addr));
  2138. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  2139. } else {
  2140. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
  2141. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  2142. }
  2143. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  2144. (char *)ip_addr, buflen);
  2145. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  2146. (char *)fw_ddb_entry->iscsi_name, buflen);
  2147. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  2148. (char *)ha->name_string, buflen);
  2149. }
  2150. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  2151. struct ddb_entry *ddb_entry)
  2152. {
  2153. struct iscsi_cls_session *cls_sess;
  2154. struct iscsi_cls_conn *cls_conn;
  2155. uint32_t ddb_state;
  2156. dma_addr_t fw_ddb_entry_dma;
  2157. struct dev_db_entry *fw_ddb_entry;
  2158. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2159. &fw_ddb_entry_dma, GFP_KERNEL);
  2160. if (!fw_ddb_entry) {
  2161. ql4_printk(KERN_ERR, ha,
  2162. "%s: Unable to allocate dma buffer\n", __func__);
  2163. goto exit_session_conn_fwddb_param;
  2164. }
  2165. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2166. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2167. NULL, NULL, NULL) == QLA_ERROR) {
  2168. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2169. "get_ddb_entry for fw_ddb_index %d\n",
  2170. ha->host_no, __func__,
  2171. ddb_entry->fw_ddb_index));
  2172. goto exit_session_conn_fwddb_param;
  2173. }
  2174. cls_sess = ddb_entry->sess;
  2175. cls_conn = ddb_entry->conn;
  2176. /* Update params */
  2177. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  2178. exit_session_conn_fwddb_param:
  2179. if (fw_ddb_entry)
  2180. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2181. fw_ddb_entry, fw_ddb_entry_dma);
  2182. }
  2183. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  2184. struct ddb_entry *ddb_entry)
  2185. {
  2186. struct iscsi_cls_session *cls_sess;
  2187. struct iscsi_cls_conn *cls_conn;
  2188. struct iscsi_session *sess;
  2189. struct iscsi_conn *conn;
  2190. uint32_t ddb_state;
  2191. dma_addr_t fw_ddb_entry_dma;
  2192. struct dev_db_entry *fw_ddb_entry;
  2193. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2194. &fw_ddb_entry_dma, GFP_KERNEL);
  2195. if (!fw_ddb_entry) {
  2196. ql4_printk(KERN_ERR, ha,
  2197. "%s: Unable to allocate dma buffer\n", __func__);
  2198. goto exit_session_conn_param;
  2199. }
  2200. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2201. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2202. NULL, NULL, NULL) == QLA_ERROR) {
  2203. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2204. "get_ddb_entry for fw_ddb_index %d\n",
  2205. ha->host_no, __func__,
  2206. ddb_entry->fw_ddb_index));
  2207. goto exit_session_conn_param;
  2208. }
  2209. cls_sess = ddb_entry->sess;
  2210. sess = cls_sess->dd_data;
  2211. cls_conn = ddb_entry->conn;
  2212. conn = cls_conn->dd_data;
  2213. /* Update timers after login */
  2214. ddb_entry->default_relogin_timeout =
  2215. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  2216. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  2217. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  2218. ddb_entry->default_time2wait =
  2219. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  2220. /* Update params */
  2221. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2222. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2223. memcpy(sess->initiatorname, ha->name_string,
  2224. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  2225. exit_session_conn_param:
  2226. if (fw_ddb_entry)
  2227. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2228. fw_ddb_entry, fw_ddb_entry_dma);
  2229. }
  2230. /*
  2231. * Timer routines
  2232. */
  2233. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  2234. unsigned long interval)
  2235. {
  2236. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  2237. __func__, ha->host->host_no));
  2238. init_timer(&ha->timer);
  2239. ha->timer.expires = jiffies + interval * HZ;
  2240. ha->timer.data = (unsigned long)ha;
  2241. ha->timer.function = (void (*)(unsigned long))func;
  2242. add_timer(&ha->timer);
  2243. ha->timer_active = 1;
  2244. }
  2245. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  2246. {
  2247. del_timer_sync(&ha->timer);
  2248. ha->timer_active = 0;
  2249. }
  2250. /***
  2251. * qla4xxx_mark_device_missing - blocks the session
  2252. * @cls_session: Pointer to the session to be blocked
  2253. * @ddb_entry: Pointer to device database entry
  2254. *
  2255. * This routine marks a device missing and close connection.
  2256. **/
  2257. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  2258. {
  2259. iscsi_block_session(cls_session);
  2260. }
  2261. /**
  2262. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  2263. * @ha: Pointer to host adapter structure.
  2264. *
  2265. * This routine marks a device missing and resets the relogin retry count.
  2266. **/
  2267. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  2268. {
  2269. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  2270. }
  2271. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  2272. struct ddb_entry *ddb_entry,
  2273. struct scsi_cmnd *cmd)
  2274. {
  2275. struct srb *srb;
  2276. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  2277. if (!srb)
  2278. return srb;
  2279. kref_init(&srb->srb_ref);
  2280. srb->ha = ha;
  2281. srb->ddb = ddb_entry;
  2282. srb->cmd = cmd;
  2283. srb->flags = 0;
  2284. CMD_SP(cmd) = (void *)srb;
  2285. return srb;
  2286. }
  2287. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  2288. {
  2289. struct scsi_cmnd *cmd = srb->cmd;
  2290. if (srb->flags & SRB_DMA_VALID) {
  2291. scsi_dma_unmap(cmd);
  2292. srb->flags &= ~SRB_DMA_VALID;
  2293. }
  2294. CMD_SP(cmd) = NULL;
  2295. }
  2296. void qla4xxx_srb_compl(struct kref *ref)
  2297. {
  2298. struct srb *srb = container_of(ref, struct srb, srb_ref);
  2299. struct scsi_cmnd *cmd = srb->cmd;
  2300. struct scsi_qla_host *ha = srb->ha;
  2301. qla4xxx_srb_free_dma(ha, srb);
  2302. mempool_free(srb, ha->srb_mempool);
  2303. cmd->scsi_done(cmd);
  2304. }
  2305. /**
  2306. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  2307. * @host: scsi host
  2308. * @cmd: Pointer to Linux's SCSI command structure
  2309. *
  2310. * Remarks:
  2311. * This routine is invoked by Linux to send a SCSI command to the driver.
  2312. * The mid-level driver tries to ensure that queuecommand never gets
  2313. * invoked concurrently with itself or the interrupt handler (although
  2314. * the interrupt handler may call this routine as part of request-
  2315. * completion handling). Unfortunely, it sometimes calls the scheduler
  2316. * in interrupt context which is a big NO! NO!.
  2317. **/
  2318. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  2319. {
  2320. struct scsi_qla_host *ha = to_qla_host(host);
  2321. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  2322. struct iscsi_cls_session *sess = ddb_entry->sess;
  2323. struct srb *srb;
  2324. int rval;
  2325. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2326. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  2327. cmd->result = DID_NO_CONNECT << 16;
  2328. else
  2329. cmd->result = DID_REQUEUE << 16;
  2330. goto qc_fail_command;
  2331. }
  2332. if (!sess) {
  2333. cmd->result = DID_IMM_RETRY << 16;
  2334. goto qc_fail_command;
  2335. }
  2336. rval = iscsi_session_chkready(sess);
  2337. if (rval) {
  2338. cmd->result = rval;
  2339. goto qc_fail_command;
  2340. }
  2341. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2342. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2343. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2344. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2345. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2346. !test_bit(AF_ONLINE, &ha->flags) ||
  2347. !test_bit(AF_LINK_UP, &ha->flags) ||
  2348. test_bit(AF_LOOPBACK, &ha->flags) ||
  2349. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  2350. goto qc_host_busy;
  2351. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  2352. if (!srb)
  2353. goto qc_host_busy;
  2354. rval = qla4xxx_send_command_to_isp(ha, srb);
  2355. if (rval != QLA_SUCCESS)
  2356. goto qc_host_busy_free_sp;
  2357. return 0;
  2358. qc_host_busy_free_sp:
  2359. qla4xxx_srb_free_dma(ha, srb);
  2360. mempool_free(srb, ha->srb_mempool);
  2361. qc_host_busy:
  2362. return SCSI_MLQUEUE_HOST_BUSY;
  2363. qc_fail_command:
  2364. cmd->scsi_done(cmd);
  2365. return 0;
  2366. }
  2367. /**
  2368. * qla4xxx_mem_free - frees memory allocated to adapter
  2369. * @ha: Pointer to host adapter structure.
  2370. *
  2371. * Frees memory previously allocated by qla4xxx_mem_alloc
  2372. **/
  2373. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  2374. {
  2375. if (ha->queues)
  2376. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  2377. ha->queues_dma);
  2378. if (ha->fw_dump)
  2379. vfree(ha->fw_dump);
  2380. ha->queues_len = 0;
  2381. ha->queues = NULL;
  2382. ha->queues_dma = 0;
  2383. ha->request_ring = NULL;
  2384. ha->request_dma = 0;
  2385. ha->response_ring = NULL;
  2386. ha->response_dma = 0;
  2387. ha->shadow_regs = NULL;
  2388. ha->shadow_regs_dma = 0;
  2389. ha->fw_dump = NULL;
  2390. ha->fw_dump_size = 0;
  2391. /* Free srb pool. */
  2392. if (ha->srb_mempool)
  2393. mempool_destroy(ha->srb_mempool);
  2394. ha->srb_mempool = NULL;
  2395. if (ha->chap_dma_pool)
  2396. dma_pool_destroy(ha->chap_dma_pool);
  2397. if (ha->chap_list)
  2398. vfree(ha->chap_list);
  2399. ha->chap_list = NULL;
  2400. if (ha->fw_ddb_dma_pool)
  2401. dma_pool_destroy(ha->fw_ddb_dma_pool);
  2402. /* release io space registers */
  2403. if (is_qla8022(ha)) {
  2404. if (ha->nx_pcibase)
  2405. iounmap(
  2406. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  2407. } else if (is_qla8032(ha)) {
  2408. if (ha->nx_pcibase)
  2409. iounmap(
  2410. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  2411. } else if (ha->reg) {
  2412. iounmap(ha->reg);
  2413. }
  2414. if (ha->reset_tmplt.buff)
  2415. vfree(ha->reset_tmplt.buff);
  2416. pci_release_regions(ha->pdev);
  2417. }
  2418. /**
  2419. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  2420. * @ha: Pointer to host adapter structure
  2421. *
  2422. * Allocates DMA memory for request and response queues. Also allocates memory
  2423. * for srbs.
  2424. **/
  2425. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  2426. {
  2427. unsigned long align;
  2428. /* Allocate contiguous block of DMA memory for queues. */
  2429. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2430. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  2431. sizeof(struct shadow_regs) +
  2432. MEM_ALIGN_VALUE +
  2433. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  2434. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  2435. &ha->queues_dma, GFP_KERNEL);
  2436. if (ha->queues == NULL) {
  2437. ql4_printk(KERN_WARNING, ha,
  2438. "Memory Allocation failed - queues.\n");
  2439. goto mem_alloc_error_exit;
  2440. }
  2441. memset(ha->queues, 0, ha->queues_len);
  2442. /*
  2443. * As per RISC alignment requirements -- the bus-address must be a
  2444. * multiple of the request-ring size (in bytes).
  2445. */
  2446. align = 0;
  2447. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  2448. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  2449. (MEM_ALIGN_VALUE - 1));
  2450. /* Update request and response queue pointers. */
  2451. ha->request_dma = ha->queues_dma + align;
  2452. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  2453. ha->response_dma = ha->queues_dma + align +
  2454. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  2455. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  2456. (REQUEST_QUEUE_DEPTH *
  2457. QUEUE_SIZE));
  2458. ha->shadow_regs_dma = ha->queues_dma + align +
  2459. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2460. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  2461. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  2462. (REQUEST_QUEUE_DEPTH *
  2463. QUEUE_SIZE) +
  2464. (RESPONSE_QUEUE_DEPTH *
  2465. QUEUE_SIZE));
  2466. /* Allocate memory for srb pool. */
  2467. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  2468. mempool_free_slab, srb_cachep);
  2469. if (ha->srb_mempool == NULL) {
  2470. ql4_printk(KERN_WARNING, ha,
  2471. "Memory Allocation failed - SRB Pool.\n");
  2472. goto mem_alloc_error_exit;
  2473. }
  2474. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  2475. CHAP_DMA_BLOCK_SIZE, 8, 0);
  2476. if (ha->chap_dma_pool == NULL) {
  2477. ql4_printk(KERN_WARNING, ha,
  2478. "%s: chap_dma_pool allocation failed..\n", __func__);
  2479. goto mem_alloc_error_exit;
  2480. }
  2481. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  2482. DDB_DMA_BLOCK_SIZE, 8, 0);
  2483. if (ha->fw_ddb_dma_pool == NULL) {
  2484. ql4_printk(KERN_WARNING, ha,
  2485. "%s: fw_ddb_dma_pool allocation failed..\n",
  2486. __func__);
  2487. goto mem_alloc_error_exit;
  2488. }
  2489. return QLA_SUCCESS;
  2490. mem_alloc_error_exit:
  2491. qla4xxx_mem_free(ha);
  2492. return QLA_ERROR;
  2493. }
  2494. /**
  2495. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  2496. * @ha: adapter block pointer.
  2497. *
  2498. * Note: The caller should not hold the idc lock.
  2499. **/
  2500. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  2501. {
  2502. uint32_t temp, temp_state, temp_val;
  2503. int status = QLA_SUCCESS;
  2504. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  2505. temp_state = qla82xx_get_temp_state(temp);
  2506. temp_val = qla82xx_get_temp_val(temp);
  2507. if (temp_state == QLA82XX_TEMP_PANIC) {
  2508. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  2509. " exceeds maximum allowed. Hardware has been shut"
  2510. " down.\n", temp_val);
  2511. status = QLA_ERROR;
  2512. } else if (temp_state == QLA82XX_TEMP_WARN) {
  2513. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  2514. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  2515. " degrees C exceeds operating range."
  2516. " Immediate action needed.\n", temp_val);
  2517. } else {
  2518. if (ha->temperature == QLA82XX_TEMP_WARN)
  2519. ql4_printk(KERN_INFO, ha, "Device temperature is"
  2520. " now %d degrees C in normal range.\n",
  2521. temp_val);
  2522. }
  2523. ha->temperature = temp_state;
  2524. return status;
  2525. }
  2526. /**
  2527. * qla4_8xxx_check_fw_alive - Check firmware health
  2528. * @ha: Pointer to host adapter structure.
  2529. *
  2530. * Context: Interrupt
  2531. **/
  2532. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  2533. {
  2534. uint32_t fw_heartbeat_counter;
  2535. int status = QLA_SUCCESS;
  2536. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  2537. QLA8XXX_PEG_ALIVE_COUNTER);
  2538. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  2539. if (fw_heartbeat_counter == 0xffffffff) {
  2540. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  2541. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  2542. ha->host_no, __func__));
  2543. return status;
  2544. }
  2545. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  2546. ha->seconds_since_last_heartbeat++;
  2547. /* FW not alive after 2 seconds */
  2548. if (ha->seconds_since_last_heartbeat == 2) {
  2549. ha->seconds_since_last_heartbeat = 0;
  2550. qla4_8xxx_dump_peg_reg(ha);
  2551. status = QLA_ERROR;
  2552. }
  2553. } else
  2554. ha->seconds_since_last_heartbeat = 0;
  2555. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  2556. return status;
  2557. }
  2558. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  2559. {
  2560. uint32_t halt_status;
  2561. int halt_status_unrecoverable = 0;
  2562. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  2563. if (is_qla8022(ha)) {
  2564. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2565. __func__);
  2566. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2567. CRB_NIU_XG_PAUSE_CTL_P0 |
  2568. CRB_NIU_XG_PAUSE_CTL_P1);
  2569. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  2570. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  2571. __func__);
  2572. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  2573. halt_status_unrecoverable = 1;
  2574. } else if (is_qla8032(ha)) {
  2575. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  2576. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  2577. __func__);
  2578. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  2579. halt_status_unrecoverable = 1;
  2580. }
  2581. /*
  2582. * Since we cannot change dev_state in interrupt context,
  2583. * set appropriate DPC flag then wakeup DPC
  2584. */
  2585. if (halt_status_unrecoverable) {
  2586. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2587. } else {
  2588. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  2589. __func__);
  2590. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2591. }
  2592. qla4xxx_mailbox_premature_completion(ha);
  2593. qla4xxx_wake_dpc(ha);
  2594. }
  2595. /**
  2596. * qla4_8xxx_watchdog - Poll dev state
  2597. * @ha: Pointer to host adapter structure.
  2598. *
  2599. * Context: Interrupt
  2600. **/
  2601. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  2602. {
  2603. uint32_t dev_state;
  2604. uint32_t idc_ctrl;
  2605. /* don't poll if reset is going on */
  2606. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2607. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2608. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  2609. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  2610. if (qla4_8xxx_check_temp(ha)) {
  2611. if (is_qla8022(ha)) {
  2612. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  2613. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2614. CRB_NIU_XG_PAUSE_CTL_P0 |
  2615. CRB_NIU_XG_PAUSE_CTL_P1);
  2616. }
  2617. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2618. qla4xxx_wake_dpc(ha);
  2619. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  2620. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2621. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
  2622. __func__);
  2623. if (is_qla8032(ha)) {
  2624. idc_ctrl = qla4_83xx_rd_reg(ha,
  2625. QLA83XX_IDC_DRV_CTRL);
  2626. if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
  2627. ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
  2628. __func__);
  2629. qla4xxx_mailbox_premature_completion(
  2630. ha);
  2631. }
  2632. }
  2633. if (is_qla8032(ha) ||
  2634. (is_qla8022(ha) && !ql4xdontresethba)) {
  2635. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2636. qla4xxx_wake_dpc(ha);
  2637. }
  2638. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  2639. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2640. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  2641. __func__);
  2642. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  2643. qla4xxx_wake_dpc(ha);
  2644. } else {
  2645. /* Check firmware health */
  2646. if (qla4_8xxx_check_fw_alive(ha))
  2647. qla4_8xxx_process_fw_error(ha);
  2648. }
  2649. }
  2650. }
  2651. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2652. {
  2653. struct iscsi_session *sess;
  2654. struct ddb_entry *ddb_entry;
  2655. struct scsi_qla_host *ha;
  2656. sess = cls_sess->dd_data;
  2657. ddb_entry = sess->dd_data;
  2658. ha = ddb_entry->ha;
  2659. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2660. return;
  2661. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2662. !iscsi_is_session_online(cls_sess)) {
  2663. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  2664. INVALID_ENTRY) {
  2665. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  2666. 0) {
  2667. atomic_set(&ddb_entry->retry_relogin_timer,
  2668. INVALID_ENTRY);
  2669. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2670. set_bit(DF_RELOGIN, &ddb_entry->flags);
  2671. DEBUG2(ql4_printk(KERN_INFO, ha,
  2672. "%s: index [%d] login device\n",
  2673. __func__, ddb_entry->fw_ddb_index));
  2674. } else
  2675. atomic_dec(&ddb_entry->retry_relogin_timer);
  2676. }
  2677. }
  2678. /* Wait for relogin to timeout */
  2679. if (atomic_read(&ddb_entry->relogin_timer) &&
  2680. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  2681. /*
  2682. * If the relogin times out and the device is
  2683. * still NOT ONLINE then try and relogin again.
  2684. */
  2685. if (!iscsi_is_session_online(cls_sess)) {
  2686. /* Reset retry relogin timer */
  2687. atomic_inc(&ddb_entry->relogin_retry_count);
  2688. DEBUG2(ql4_printk(KERN_INFO, ha,
  2689. "%s: index[%d] relogin timed out-retrying"
  2690. " relogin (%d), retry (%d)\n", __func__,
  2691. ddb_entry->fw_ddb_index,
  2692. atomic_read(&ddb_entry->relogin_retry_count),
  2693. ddb_entry->default_time2wait + 4));
  2694. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2695. atomic_set(&ddb_entry->retry_relogin_timer,
  2696. ddb_entry->default_time2wait + 4);
  2697. }
  2698. }
  2699. }
  2700. /**
  2701. * qla4xxx_timer - checks every second for work to do.
  2702. * @ha: Pointer to host adapter structure.
  2703. **/
  2704. static void qla4xxx_timer(struct scsi_qla_host *ha)
  2705. {
  2706. int start_dpc = 0;
  2707. uint16_t w;
  2708. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  2709. /* If we are in the middle of AER/EEH processing
  2710. * skip any processing and reschedule the timer
  2711. */
  2712. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2713. mod_timer(&ha->timer, jiffies + HZ);
  2714. return;
  2715. }
  2716. /* Hardware read to trigger an EEH error during mailbox waits. */
  2717. if (!pci_channel_offline(ha->pdev))
  2718. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2719. if (is_qla80XX(ha))
  2720. qla4_8xxx_watchdog(ha);
  2721. if (is_qla40XX(ha)) {
  2722. /* Check for heartbeat interval. */
  2723. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  2724. ha->heartbeat_interval != 0) {
  2725. ha->seconds_since_last_heartbeat++;
  2726. if (ha->seconds_since_last_heartbeat >
  2727. ha->heartbeat_interval + 2)
  2728. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2729. }
  2730. }
  2731. /* Process any deferred work. */
  2732. if (!list_empty(&ha->work_list))
  2733. start_dpc++;
  2734. /* Wakeup the dpc routine for this adapter, if needed. */
  2735. if (start_dpc ||
  2736. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2737. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  2738. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  2739. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2740. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2741. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  2742. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  2743. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2744. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2745. test_bit(DPC_AEN, &ha->dpc_flags)) {
  2746. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  2747. " - dpc flags = 0x%lx\n",
  2748. ha->host_no, __func__, ha->dpc_flags));
  2749. qla4xxx_wake_dpc(ha);
  2750. }
  2751. /* Reschedule timer thread to call us back in one second */
  2752. mod_timer(&ha->timer, jiffies + HZ);
  2753. DEBUG2(ha->seconds_since_last_intr++);
  2754. }
  2755. /**
  2756. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  2757. * @ha: Pointer to host adapter structure.
  2758. *
  2759. * This routine stalls the driver until all outstanding commands are returned.
  2760. * Caller must release the Hardware Lock prior to calling this routine.
  2761. **/
  2762. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  2763. {
  2764. uint32_t index = 0;
  2765. unsigned long flags;
  2766. struct scsi_cmnd *cmd;
  2767. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  2768. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  2769. "complete\n", WAIT_CMD_TOV));
  2770. while (!time_after_eq(jiffies, wtime)) {
  2771. spin_lock_irqsave(&ha->hardware_lock, flags);
  2772. /* Find a command that hasn't completed. */
  2773. for (index = 0; index < ha->host->can_queue; index++) {
  2774. cmd = scsi_host_find_tag(ha->host, index);
  2775. /*
  2776. * We cannot just check if the index is valid,
  2777. * becase if we are run from the scsi eh, then
  2778. * the scsi/block layer is going to prevent
  2779. * the tag from being released.
  2780. */
  2781. if (cmd != NULL && CMD_SP(cmd))
  2782. break;
  2783. }
  2784. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2785. /* If No Commands are pending, wait is complete */
  2786. if (index == ha->host->can_queue)
  2787. return QLA_SUCCESS;
  2788. msleep(1000);
  2789. }
  2790. /* If we timed out on waiting for commands to come back
  2791. * return ERROR. */
  2792. return QLA_ERROR;
  2793. }
  2794. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  2795. {
  2796. uint32_t ctrl_status;
  2797. unsigned long flags = 0;
  2798. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  2799. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  2800. return QLA_ERROR;
  2801. spin_lock_irqsave(&ha->hardware_lock, flags);
  2802. /*
  2803. * If the SCSI Reset Interrupt bit is set, clear it.
  2804. * Otherwise, the Soft Reset won't work.
  2805. */
  2806. ctrl_status = readw(&ha->reg->ctrl_status);
  2807. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  2808. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2809. /* Issue Soft Reset */
  2810. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  2811. readl(&ha->reg->ctrl_status);
  2812. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2813. return QLA_SUCCESS;
  2814. }
  2815. /**
  2816. * qla4xxx_soft_reset - performs soft reset.
  2817. * @ha: Pointer to host adapter structure.
  2818. **/
  2819. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  2820. {
  2821. uint32_t max_wait_time;
  2822. unsigned long flags = 0;
  2823. int status;
  2824. uint32_t ctrl_status;
  2825. status = qla4xxx_hw_reset(ha);
  2826. if (status != QLA_SUCCESS)
  2827. return status;
  2828. status = QLA_ERROR;
  2829. /* Wait until the Network Reset Intr bit is cleared */
  2830. max_wait_time = RESET_INTR_TOV;
  2831. do {
  2832. spin_lock_irqsave(&ha->hardware_lock, flags);
  2833. ctrl_status = readw(&ha->reg->ctrl_status);
  2834. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2835. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  2836. break;
  2837. msleep(1000);
  2838. } while ((--max_wait_time));
  2839. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  2840. DEBUG2(printk(KERN_WARNING
  2841. "scsi%ld: Network Reset Intr not cleared by "
  2842. "Network function, clearing it now!\n",
  2843. ha->host_no));
  2844. spin_lock_irqsave(&ha->hardware_lock, flags);
  2845. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  2846. readl(&ha->reg->ctrl_status);
  2847. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2848. }
  2849. /* Wait until the firmware tells us the Soft Reset is done */
  2850. max_wait_time = SOFT_RESET_TOV;
  2851. do {
  2852. spin_lock_irqsave(&ha->hardware_lock, flags);
  2853. ctrl_status = readw(&ha->reg->ctrl_status);
  2854. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2855. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  2856. status = QLA_SUCCESS;
  2857. break;
  2858. }
  2859. msleep(1000);
  2860. } while ((--max_wait_time));
  2861. /*
  2862. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  2863. * after the soft reset has taken place.
  2864. */
  2865. spin_lock_irqsave(&ha->hardware_lock, flags);
  2866. ctrl_status = readw(&ha->reg->ctrl_status);
  2867. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  2868. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2869. readl(&ha->reg->ctrl_status);
  2870. }
  2871. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2872. /* If soft reset fails then most probably the bios on other
  2873. * function is also enabled.
  2874. * Since the initialization is sequential the other fn
  2875. * wont be able to acknowledge the soft reset.
  2876. * Issue a force soft reset to workaround this scenario.
  2877. */
  2878. if (max_wait_time == 0) {
  2879. /* Issue Force Soft Reset */
  2880. spin_lock_irqsave(&ha->hardware_lock, flags);
  2881. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  2882. readl(&ha->reg->ctrl_status);
  2883. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2884. /* Wait until the firmware tells us the Soft Reset is done */
  2885. max_wait_time = SOFT_RESET_TOV;
  2886. do {
  2887. spin_lock_irqsave(&ha->hardware_lock, flags);
  2888. ctrl_status = readw(&ha->reg->ctrl_status);
  2889. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2890. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  2891. status = QLA_SUCCESS;
  2892. break;
  2893. }
  2894. msleep(1000);
  2895. } while ((--max_wait_time));
  2896. }
  2897. return status;
  2898. }
  2899. /**
  2900. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  2901. * @ha: Pointer to host adapter structure.
  2902. * @res: returned scsi status
  2903. *
  2904. * This routine is called just prior to a HARD RESET to return all
  2905. * outstanding commands back to the Operating System.
  2906. * Caller should make sure that the following locks are released
  2907. * before this calling routine: Hardware lock, and io_request_lock.
  2908. **/
  2909. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  2910. {
  2911. struct srb *srb;
  2912. int i;
  2913. unsigned long flags;
  2914. spin_lock_irqsave(&ha->hardware_lock, flags);
  2915. for (i = 0; i < ha->host->can_queue; i++) {
  2916. srb = qla4xxx_del_from_active_array(ha, i);
  2917. if (srb != NULL) {
  2918. srb->cmd->result = res;
  2919. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2920. }
  2921. }
  2922. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2923. }
  2924. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  2925. {
  2926. clear_bit(AF_ONLINE, &ha->flags);
  2927. /* Disable the board */
  2928. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  2929. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2930. qla4xxx_mark_all_devices_missing(ha);
  2931. clear_bit(AF_INIT_DONE, &ha->flags);
  2932. }
  2933. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  2934. {
  2935. struct iscsi_session *sess;
  2936. struct ddb_entry *ddb_entry;
  2937. sess = cls_session->dd_data;
  2938. ddb_entry = sess->dd_data;
  2939. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  2940. if (ddb_entry->ddb_type == FLASH_DDB)
  2941. iscsi_block_session(ddb_entry->sess);
  2942. else
  2943. iscsi_session_failure(cls_session->dd_data,
  2944. ISCSI_ERR_CONN_FAILED);
  2945. }
  2946. /**
  2947. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  2948. * @ha: Pointer to host adapter structure.
  2949. **/
  2950. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  2951. {
  2952. int status = QLA_ERROR;
  2953. uint8_t reset_chip = 0;
  2954. uint32_t dev_state;
  2955. unsigned long wait;
  2956. /* Stall incoming I/O until we are done */
  2957. scsi_block_requests(ha->host);
  2958. clear_bit(AF_ONLINE, &ha->flags);
  2959. clear_bit(AF_LINK_UP, &ha->flags);
  2960. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  2961. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2962. if (is_qla8032(ha) &&
  2963. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2964. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2965. __func__);
  2966. /* disable pause frame for ISP83xx */
  2967. qla4_83xx_disable_pause(ha);
  2968. }
  2969. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  2970. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2971. reset_chip = 1;
  2972. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  2973. * do not reset adapter, jump to initialize_adapter */
  2974. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2975. status = QLA_SUCCESS;
  2976. goto recover_ha_init_adapter;
  2977. }
  2978. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  2979. * from eh_host_reset or ioctl module */
  2980. if (is_qla80XX(ha) && !reset_chip &&
  2981. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2982. DEBUG2(ql4_printk(KERN_INFO, ha,
  2983. "scsi%ld: %s - Performing stop_firmware...\n",
  2984. ha->host_no, __func__));
  2985. status = ha->isp_ops->reset_firmware(ha);
  2986. if (status == QLA_SUCCESS) {
  2987. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2988. qla4xxx_cmd_wait(ha);
  2989. ha->isp_ops->disable_intrs(ha);
  2990. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2991. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2992. } else {
  2993. /* If the stop_firmware fails then
  2994. * reset the entire chip */
  2995. reset_chip = 1;
  2996. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2997. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2998. }
  2999. }
  3000. /* Issue full chip reset if recovering from a catastrophic error,
  3001. * or if stop_firmware fails for ISP-8xxx.
  3002. * This is the default case for ISP-4xxx */
  3003. if (is_qla40XX(ha) || reset_chip) {
  3004. if (is_qla40XX(ha))
  3005. goto chip_reset;
  3006. /* Check if 8XXX firmware is alive or not
  3007. * We may have arrived here from NEED_RESET
  3008. * detection only */
  3009. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  3010. goto chip_reset;
  3011. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  3012. while (time_before(jiffies, wait)) {
  3013. if (qla4_8xxx_check_fw_alive(ha)) {
  3014. qla4xxx_mailbox_premature_completion(ha);
  3015. break;
  3016. }
  3017. set_current_state(TASK_UNINTERRUPTIBLE);
  3018. schedule_timeout(HZ);
  3019. }
  3020. chip_reset:
  3021. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  3022. qla4xxx_cmd_wait(ha);
  3023. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3024. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3025. DEBUG2(ql4_printk(KERN_INFO, ha,
  3026. "scsi%ld: %s - Performing chip reset..\n",
  3027. ha->host_no, __func__));
  3028. status = ha->isp_ops->reset_chip(ha);
  3029. }
  3030. /* Flush any pending ddb changed AENs */
  3031. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3032. recover_ha_init_adapter:
  3033. /* Upon successful firmware/chip reset, re-initialize the adapter */
  3034. if (status == QLA_SUCCESS) {
  3035. /* For ISP-4xxx, force function 1 to always initialize
  3036. * before function 3 to prevent both funcions from
  3037. * stepping on top of the other */
  3038. if (is_qla40XX(ha) && (ha->mac_index == 3))
  3039. ssleep(6);
  3040. /* NOTE: AF_ONLINE flag set upon successful completion of
  3041. * qla4xxx_initialize_adapter */
  3042. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  3043. }
  3044. /* Retry failed adapter initialization, if necessary
  3045. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  3046. * case to prevent ping-pong resets between functions */
  3047. if (!test_bit(AF_ONLINE, &ha->flags) &&
  3048. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3049. /* Adapter initialization failed, see if we can retry
  3050. * resetting the ha.
  3051. * Since we don't want to block the DPC for too long
  3052. * with multiple resets in the same thread,
  3053. * utilize DPC to retry */
  3054. if (is_qla80XX(ha)) {
  3055. ha->isp_ops->idc_lock(ha);
  3056. dev_state = qla4_8xxx_rd_direct(ha,
  3057. QLA8XXX_CRB_DEV_STATE);
  3058. ha->isp_ops->idc_unlock(ha);
  3059. if (dev_state == QLA8XXX_DEV_FAILED) {
  3060. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  3061. "recover adapter. H/W is in Failed "
  3062. "state\n", __func__);
  3063. qla4xxx_dead_adapter_cleanup(ha);
  3064. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3065. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3066. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3067. &ha->dpc_flags);
  3068. status = QLA_ERROR;
  3069. goto exit_recover;
  3070. }
  3071. }
  3072. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  3073. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  3074. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  3075. "(%d) more times\n", ha->host_no,
  3076. ha->retry_reset_ha_cnt));
  3077. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3078. status = QLA_ERROR;
  3079. } else {
  3080. if (ha->retry_reset_ha_cnt > 0) {
  3081. /* Schedule another Reset HA--DPC will retry */
  3082. ha->retry_reset_ha_cnt--;
  3083. DEBUG2(printk("scsi%ld: recover adapter - "
  3084. "retry remaining %d\n",
  3085. ha->host_no,
  3086. ha->retry_reset_ha_cnt));
  3087. status = QLA_ERROR;
  3088. }
  3089. if (ha->retry_reset_ha_cnt == 0) {
  3090. /* Recover adapter retries have been exhausted.
  3091. * Adapter DEAD */
  3092. DEBUG2(printk("scsi%ld: recover adapter "
  3093. "failed - board disabled\n",
  3094. ha->host_no));
  3095. qla4xxx_dead_adapter_cleanup(ha);
  3096. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3097. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3098. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3099. &ha->dpc_flags);
  3100. status = QLA_ERROR;
  3101. }
  3102. }
  3103. } else {
  3104. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3105. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3106. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3107. }
  3108. exit_recover:
  3109. ha->adapter_error_count++;
  3110. if (test_bit(AF_ONLINE, &ha->flags))
  3111. ha->isp_ops->enable_intrs(ha);
  3112. scsi_unblock_requests(ha->host);
  3113. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3114. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  3115. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  3116. return status;
  3117. }
  3118. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  3119. {
  3120. struct iscsi_session *sess;
  3121. struct ddb_entry *ddb_entry;
  3122. struct scsi_qla_host *ha;
  3123. sess = cls_session->dd_data;
  3124. ddb_entry = sess->dd_data;
  3125. ha = ddb_entry->ha;
  3126. if (!iscsi_is_session_online(cls_session)) {
  3127. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  3128. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3129. " unblock session\n", ha->host_no, __func__,
  3130. ddb_entry->fw_ddb_index);
  3131. iscsi_unblock_session(ddb_entry->sess);
  3132. } else {
  3133. /* Trigger relogin */
  3134. if (ddb_entry->ddb_type == FLASH_DDB) {
  3135. if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
  3136. test_bit(DF_DISABLE_RELOGIN,
  3137. &ddb_entry->flags)))
  3138. qla4xxx_arm_relogin_timer(ddb_entry);
  3139. } else
  3140. iscsi_session_failure(cls_session->dd_data,
  3141. ISCSI_ERR_CONN_FAILED);
  3142. }
  3143. }
  3144. }
  3145. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  3146. {
  3147. struct iscsi_session *sess;
  3148. struct ddb_entry *ddb_entry;
  3149. struct scsi_qla_host *ha;
  3150. sess = cls_session->dd_data;
  3151. ddb_entry = sess->dd_data;
  3152. ha = ddb_entry->ha;
  3153. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3154. " unblock session\n", ha->host_no, __func__,
  3155. ddb_entry->fw_ddb_index);
  3156. iscsi_unblock_session(ddb_entry->sess);
  3157. /* Start scan target */
  3158. if (test_bit(AF_ONLINE, &ha->flags)) {
  3159. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3160. " start scan\n", ha->host_no, __func__,
  3161. ddb_entry->fw_ddb_index);
  3162. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  3163. }
  3164. return QLA_SUCCESS;
  3165. }
  3166. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  3167. {
  3168. struct iscsi_session *sess;
  3169. struct ddb_entry *ddb_entry;
  3170. struct scsi_qla_host *ha;
  3171. int status = QLA_SUCCESS;
  3172. sess = cls_session->dd_data;
  3173. ddb_entry = sess->dd_data;
  3174. ha = ddb_entry->ha;
  3175. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3176. " unblock user space session\n", ha->host_no, __func__,
  3177. ddb_entry->fw_ddb_index);
  3178. if (!iscsi_is_session_online(cls_session)) {
  3179. iscsi_conn_start(ddb_entry->conn);
  3180. iscsi_conn_login_event(ddb_entry->conn,
  3181. ISCSI_CONN_STATE_LOGGED_IN);
  3182. } else {
  3183. ql4_printk(KERN_INFO, ha,
  3184. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  3185. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  3186. cls_session->sid);
  3187. status = QLA_ERROR;
  3188. }
  3189. return status;
  3190. }
  3191. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  3192. {
  3193. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  3194. }
  3195. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  3196. {
  3197. uint16_t relogin_timer;
  3198. struct iscsi_session *sess;
  3199. struct ddb_entry *ddb_entry;
  3200. struct scsi_qla_host *ha;
  3201. sess = cls_sess->dd_data;
  3202. ddb_entry = sess->dd_data;
  3203. ha = ddb_entry->ha;
  3204. relogin_timer = max(ddb_entry->default_relogin_timeout,
  3205. (uint16_t)RELOGIN_TOV);
  3206. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  3207. DEBUG2(ql4_printk(KERN_INFO, ha,
  3208. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  3209. ddb_entry->fw_ddb_index, relogin_timer));
  3210. qla4xxx_login_flash_ddb(cls_sess);
  3211. }
  3212. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  3213. {
  3214. struct iscsi_session *sess;
  3215. struct ddb_entry *ddb_entry;
  3216. struct scsi_qla_host *ha;
  3217. sess = cls_sess->dd_data;
  3218. ddb_entry = sess->dd_data;
  3219. ha = ddb_entry->ha;
  3220. if (!(ddb_entry->ddb_type == FLASH_DDB))
  3221. return;
  3222. if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  3223. return;
  3224. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  3225. !iscsi_is_session_online(cls_sess)) {
  3226. DEBUG2(ql4_printk(KERN_INFO, ha,
  3227. "relogin issued\n"));
  3228. qla4xxx_relogin_flash_ddb(cls_sess);
  3229. }
  3230. }
  3231. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  3232. {
  3233. if (ha->dpc_thread)
  3234. queue_work(ha->dpc_thread, &ha->dpc_work);
  3235. }
  3236. static struct qla4_work_evt *
  3237. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  3238. enum qla4_work_type type)
  3239. {
  3240. struct qla4_work_evt *e;
  3241. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  3242. e = kzalloc(size, GFP_ATOMIC);
  3243. if (!e)
  3244. return NULL;
  3245. INIT_LIST_HEAD(&e->list);
  3246. e->type = type;
  3247. return e;
  3248. }
  3249. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  3250. struct qla4_work_evt *e)
  3251. {
  3252. unsigned long flags;
  3253. spin_lock_irqsave(&ha->work_lock, flags);
  3254. list_add_tail(&e->list, &ha->work_list);
  3255. spin_unlock_irqrestore(&ha->work_lock, flags);
  3256. qla4xxx_wake_dpc(ha);
  3257. }
  3258. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  3259. enum iscsi_host_event_code aen_code,
  3260. uint32_t data_size, uint8_t *data)
  3261. {
  3262. struct qla4_work_evt *e;
  3263. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  3264. if (!e)
  3265. return QLA_ERROR;
  3266. e->u.aen.code = aen_code;
  3267. e->u.aen.data_size = data_size;
  3268. memcpy(e->u.aen.data, data, data_size);
  3269. qla4xxx_post_work(ha, e);
  3270. return QLA_SUCCESS;
  3271. }
  3272. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  3273. uint32_t status, uint32_t pid,
  3274. uint32_t data_size, uint8_t *data)
  3275. {
  3276. struct qla4_work_evt *e;
  3277. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  3278. if (!e)
  3279. return QLA_ERROR;
  3280. e->u.ping.status = status;
  3281. e->u.ping.pid = pid;
  3282. e->u.ping.data_size = data_size;
  3283. memcpy(e->u.ping.data, data, data_size);
  3284. qla4xxx_post_work(ha, e);
  3285. return QLA_SUCCESS;
  3286. }
  3287. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  3288. {
  3289. struct qla4_work_evt *e, *tmp;
  3290. unsigned long flags;
  3291. LIST_HEAD(work);
  3292. spin_lock_irqsave(&ha->work_lock, flags);
  3293. list_splice_init(&ha->work_list, &work);
  3294. spin_unlock_irqrestore(&ha->work_lock, flags);
  3295. list_for_each_entry_safe(e, tmp, &work, list) {
  3296. list_del_init(&e->list);
  3297. switch (e->type) {
  3298. case QLA4_EVENT_AEN:
  3299. iscsi_post_host_event(ha->host_no,
  3300. &qla4xxx_iscsi_transport,
  3301. e->u.aen.code,
  3302. e->u.aen.data_size,
  3303. e->u.aen.data);
  3304. break;
  3305. case QLA4_EVENT_PING_STATUS:
  3306. iscsi_ping_comp_event(ha->host_no,
  3307. &qla4xxx_iscsi_transport,
  3308. e->u.ping.status,
  3309. e->u.ping.pid,
  3310. e->u.ping.data_size,
  3311. e->u.ping.data);
  3312. break;
  3313. default:
  3314. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  3315. "supported", e->type);
  3316. }
  3317. kfree(e);
  3318. }
  3319. }
  3320. /**
  3321. * qla4xxx_do_dpc - dpc routine
  3322. * @data: in our case pointer to adapter structure
  3323. *
  3324. * This routine is a task that is schedule by the interrupt handler
  3325. * to perform the background processing for interrupts. We put it
  3326. * on a task queue that is consumed whenever the scheduler runs; that's
  3327. * so you can do anything (i.e. put the process to sleep etc). In fact,
  3328. * the mid-level tries to sleep when it reaches the driver threshold
  3329. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  3330. **/
  3331. static void qla4xxx_do_dpc(struct work_struct *work)
  3332. {
  3333. struct scsi_qla_host *ha =
  3334. container_of(work, struct scsi_qla_host, dpc_work);
  3335. int status = QLA_ERROR;
  3336. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  3337. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  3338. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  3339. /* Initialization not yet finished. Don't do anything yet. */
  3340. if (!test_bit(AF_INIT_DONE, &ha->flags))
  3341. return;
  3342. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  3343. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  3344. ha->host_no, __func__, ha->flags));
  3345. return;
  3346. }
  3347. /* post events to application */
  3348. qla4xxx_do_work(ha);
  3349. if (is_qla80XX(ha)) {
  3350. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  3351. if (is_qla8032(ha)) {
  3352. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  3353. __func__);
  3354. /* disable pause frame for ISP83xx */
  3355. qla4_83xx_disable_pause(ha);
  3356. }
  3357. ha->isp_ops->idc_lock(ha);
  3358. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  3359. QLA8XXX_DEV_FAILED);
  3360. ha->isp_ops->idc_unlock(ha);
  3361. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  3362. qla4_8xxx_device_state_handler(ha);
  3363. }
  3364. if (test_and_clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags))
  3365. qla4_83xx_post_idc_ack(ha);
  3366. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  3367. qla4_8xxx_need_qsnt_handler(ha);
  3368. }
  3369. }
  3370. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  3371. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3372. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  3373. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  3374. if ((is_qla8022(ha) && ql4xdontresethba) ||
  3375. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  3376. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  3377. ha->host_no, __func__));
  3378. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3379. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3380. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3381. goto dpc_post_reset_ha;
  3382. }
  3383. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  3384. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  3385. qla4xxx_recover_adapter(ha);
  3386. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3387. uint8_t wait_time = RESET_INTR_TOV;
  3388. while ((readw(&ha->reg->ctrl_status) &
  3389. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  3390. if (--wait_time == 0)
  3391. break;
  3392. msleep(1000);
  3393. }
  3394. if (wait_time == 0)
  3395. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  3396. "bit not cleared-- resetting\n",
  3397. ha->host_no, __func__));
  3398. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3399. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  3400. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3401. status = qla4xxx_recover_adapter(ha);
  3402. }
  3403. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3404. if (status == QLA_SUCCESS)
  3405. ha->isp_ops->enable_intrs(ha);
  3406. }
  3407. }
  3408. dpc_post_reset_ha:
  3409. /* ---- process AEN? --- */
  3410. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  3411. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  3412. /* ---- Get DHCP IP Address? --- */
  3413. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  3414. qla4xxx_get_dhcp_ip_address(ha);
  3415. /* ---- relogin device? --- */
  3416. if (adapter_up(ha) &&
  3417. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  3418. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  3419. }
  3420. /* ---- link change? --- */
  3421. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  3422. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  3423. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  3424. /* ---- link down? --- */
  3425. qla4xxx_mark_all_devices_missing(ha);
  3426. } else {
  3427. /* ---- link up? --- *
  3428. * F/W will auto login to all devices ONLY ONCE after
  3429. * link up during driver initialization and runtime
  3430. * fatal error recovery. Therefore, the driver must
  3431. * manually relogin to devices when recovering from
  3432. * connection failures, logouts, expired KATO, etc. */
  3433. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  3434. qla4xxx_build_ddb_list(ha, ha->is_reset);
  3435. iscsi_host_for_each_session(ha->host,
  3436. qla4xxx_login_flash_ddb);
  3437. } else
  3438. qla4xxx_relogin_all_devices(ha);
  3439. }
  3440. }
  3441. }
  3442. /**
  3443. * qla4xxx_free_adapter - release the adapter
  3444. * @ha: pointer to adapter structure
  3445. **/
  3446. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  3447. {
  3448. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3449. /* Turn-off interrupts on the card. */
  3450. ha->isp_ops->disable_intrs(ha);
  3451. if (is_qla40XX(ha)) {
  3452. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  3453. &ha->reg->ctrl_status);
  3454. readl(&ha->reg->ctrl_status);
  3455. } else if (is_qla8022(ha)) {
  3456. writel(0, &ha->qla4_82xx_reg->host_int);
  3457. readl(&ha->qla4_82xx_reg->host_int);
  3458. } else if (is_qla8032(ha)) {
  3459. writel(0, &ha->qla4_83xx_reg->risc_intr);
  3460. readl(&ha->qla4_83xx_reg->risc_intr);
  3461. }
  3462. /* Remove timer thread, if present */
  3463. if (ha->timer_active)
  3464. qla4xxx_stop_timer(ha);
  3465. /* Kill the kernel thread for this host */
  3466. if (ha->dpc_thread)
  3467. destroy_workqueue(ha->dpc_thread);
  3468. /* Kill the kernel thread for this host */
  3469. if (ha->task_wq)
  3470. destroy_workqueue(ha->task_wq);
  3471. /* Put firmware in known state */
  3472. ha->isp_ops->reset_firmware(ha);
  3473. if (is_qla80XX(ha)) {
  3474. ha->isp_ops->idc_lock(ha);
  3475. qla4_8xxx_clear_drv_active(ha);
  3476. ha->isp_ops->idc_unlock(ha);
  3477. }
  3478. /* Detach interrupts */
  3479. qla4xxx_free_irqs(ha);
  3480. /* free extra memory */
  3481. qla4xxx_mem_free(ha);
  3482. }
  3483. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  3484. {
  3485. int status = 0;
  3486. unsigned long mem_base, mem_len, db_base, db_len;
  3487. struct pci_dev *pdev = ha->pdev;
  3488. status = pci_request_regions(pdev, DRIVER_NAME);
  3489. if (status) {
  3490. printk(KERN_WARNING
  3491. "scsi(%ld) Failed to reserve PIO regions (%s) "
  3492. "status=%d\n", ha->host_no, pci_name(pdev), status);
  3493. goto iospace_error_exit;
  3494. }
  3495. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  3496. __func__, pdev->revision));
  3497. ha->revision_id = pdev->revision;
  3498. /* remap phys address */
  3499. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  3500. mem_len = pci_resource_len(pdev, 0);
  3501. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  3502. __func__, mem_base, mem_len));
  3503. /* mapping of pcibase pointer */
  3504. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  3505. if (!ha->nx_pcibase) {
  3506. printk(KERN_ERR
  3507. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  3508. pci_release_regions(ha->pdev);
  3509. goto iospace_error_exit;
  3510. }
  3511. /* Mapping of IO base pointer, door bell read and write pointer */
  3512. /* mapping of IO base pointer */
  3513. if (is_qla8022(ha)) {
  3514. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  3515. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  3516. (ha->pdev->devfn << 11));
  3517. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  3518. QLA82XX_CAM_RAM_DB2);
  3519. } else if (is_qla8032(ha)) {
  3520. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  3521. ((uint8_t *)ha->nx_pcibase);
  3522. }
  3523. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  3524. db_len = pci_resource_len(pdev, 4);
  3525. return 0;
  3526. iospace_error_exit:
  3527. return -ENOMEM;
  3528. }
  3529. /***
  3530. * qla4xxx_iospace_config - maps registers
  3531. * @ha: pointer to adapter structure
  3532. *
  3533. * This routines maps HBA's registers from the pci address space
  3534. * into the kernel virtual address space for memory mapped i/o.
  3535. **/
  3536. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  3537. {
  3538. unsigned long pio, pio_len, pio_flags;
  3539. unsigned long mmio, mmio_len, mmio_flags;
  3540. pio = pci_resource_start(ha->pdev, 0);
  3541. pio_len = pci_resource_len(ha->pdev, 0);
  3542. pio_flags = pci_resource_flags(ha->pdev, 0);
  3543. if (pio_flags & IORESOURCE_IO) {
  3544. if (pio_len < MIN_IOBASE_LEN) {
  3545. ql4_printk(KERN_WARNING, ha,
  3546. "Invalid PCI I/O region size\n");
  3547. pio = 0;
  3548. }
  3549. } else {
  3550. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  3551. pio = 0;
  3552. }
  3553. /* Use MMIO operations for all accesses. */
  3554. mmio = pci_resource_start(ha->pdev, 1);
  3555. mmio_len = pci_resource_len(ha->pdev, 1);
  3556. mmio_flags = pci_resource_flags(ha->pdev, 1);
  3557. if (!(mmio_flags & IORESOURCE_MEM)) {
  3558. ql4_printk(KERN_ERR, ha,
  3559. "region #0 not an MMIO resource, aborting\n");
  3560. goto iospace_error_exit;
  3561. }
  3562. if (mmio_len < MIN_IOBASE_LEN) {
  3563. ql4_printk(KERN_ERR, ha,
  3564. "Invalid PCI mem region size, aborting\n");
  3565. goto iospace_error_exit;
  3566. }
  3567. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  3568. ql4_printk(KERN_WARNING, ha,
  3569. "Failed to reserve PIO/MMIO regions\n");
  3570. goto iospace_error_exit;
  3571. }
  3572. ha->pio_address = pio;
  3573. ha->pio_length = pio_len;
  3574. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  3575. if (!ha->reg) {
  3576. ql4_printk(KERN_ERR, ha,
  3577. "cannot remap MMIO, aborting\n");
  3578. goto iospace_error_exit;
  3579. }
  3580. return 0;
  3581. iospace_error_exit:
  3582. return -ENOMEM;
  3583. }
  3584. static struct isp_operations qla4xxx_isp_ops = {
  3585. .iospace_config = qla4xxx_iospace_config,
  3586. .pci_config = qla4xxx_pci_config,
  3587. .disable_intrs = qla4xxx_disable_intrs,
  3588. .enable_intrs = qla4xxx_enable_intrs,
  3589. .start_firmware = qla4xxx_start_firmware,
  3590. .intr_handler = qla4xxx_intr_handler,
  3591. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  3592. .reset_chip = qla4xxx_soft_reset,
  3593. .reset_firmware = qla4xxx_hw_reset,
  3594. .queue_iocb = qla4xxx_queue_iocb,
  3595. .complete_iocb = qla4xxx_complete_iocb,
  3596. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3597. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3598. .get_sys_info = qla4xxx_get_sys_info,
  3599. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  3600. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  3601. };
  3602. static struct isp_operations qla4_82xx_isp_ops = {
  3603. .iospace_config = qla4_8xxx_iospace_config,
  3604. .pci_config = qla4_8xxx_pci_config,
  3605. .disable_intrs = qla4_82xx_disable_intrs,
  3606. .enable_intrs = qla4_82xx_enable_intrs,
  3607. .start_firmware = qla4_8xxx_load_risc,
  3608. .restart_firmware = qla4_82xx_try_start_fw,
  3609. .intr_handler = qla4_82xx_intr_handler,
  3610. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  3611. .need_reset = qla4_8xxx_need_reset,
  3612. .reset_chip = qla4_82xx_isp_reset,
  3613. .reset_firmware = qla4_8xxx_stop_firmware,
  3614. .queue_iocb = qla4_82xx_queue_iocb,
  3615. .complete_iocb = qla4_82xx_complete_iocb,
  3616. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  3617. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  3618. .get_sys_info = qla4_8xxx_get_sys_info,
  3619. .rd_reg_direct = qla4_82xx_rd_32,
  3620. .wr_reg_direct = qla4_82xx_wr_32,
  3621. .rd_reg_indirect = qla4_82xx_md_rd_32,
  3622. .wr_reg_indirect = qla4_82xx_md_wr_32,
  3623. .idc_lock = qla4_82xx_idc_lock,
  3624. .idc_unlock = qla4_82xx_idc_unlock,
  3625. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  3626. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  3627. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  3628. };
  3629. static struct isp_operations qla4_83xx_isp_ops = {
  3630. .iospace_config = qla4_8xxx_iospace_config,
  3631. .pci_config = qla4_8xxx_pci_config,
  3632. .disable_intrs = qla4_83xx_disable_intrs,
  3633. .enable_intrs = qla4_83xx_enable_intrs,
  3634. .start_firmware = qla4_8xxx_load_risc,
  3635. .restart_firmware = qla4_83xx_start_firmware,
  3636. .intr_handler = qla4_83xx_intr_handler,
  3637. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  3638. .need_reset = qla4_8xxx_need_reset,
  3639. .reset_chip = qla4_83xx_isp_reset,
  3640. .reset_firmware = qla4_8xxx_stop_firmware,
  3641. .queue_iocb = qla4_83xx_queue_iocb,
  3642. .complete_iocb = qla4_83xx_complete_iocb,
  3643. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3644. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3645. .get_sys_info = qla4_8xxx_get_sys_info,
  3646. .rd_reg_direct = qla4_83xx_rd_reg,
  3647. .wr_reg_direct = qla4_83xx_wr_reg,
  3648. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  3649. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  3650. .idc_lock = qla4_83xx_drv_lock,
  3651. .idc_unlock = qla4_83xx_drv_unlock,
  3652. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  3653. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  3654. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  3655. };
  3656. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3657. {
  3658. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  3659. }
  3660. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3661. {
  3662. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  3663. }
  3664. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3665. {
  3666. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  3667. }
  3668. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3669. {
  3670. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  3671. }
  3672. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  3673. {
  3674. struct scsi_qla_host *ha = data;
  3675. char *str = buf;
  3676. int rc;
  3677. switch (type) {
  3678. case ISCSI_BOOT_ETH_FLAGS:
  3679. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3680. break;
  3681. case ISCSI_BOOT_ETH_INDEX:
  3682. rc = sprintf(str, "0\n");
  3683. break;
  3684. case ISCSI_BOOT_ETH_MAC:
  3685. rc = sysfs_format_mac(str, ha->my_mac,
  3686. MAC_ADDR_LEN);
  3687. break;
  3688. default:
  3689. rc = -ENOSYS;
  3690. break;
  3691. }
  3692. return rc;
  3693. }
  3694. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  3695. {
  3696. int rc;
  3697. switch (type) {
  3698. case ISCSI_BOOT_ETH_FLAGS:
  3699. case ISCSI_BOOT_ETH_MAC:
  3700. case ISCSI_BOOT_ETH_INDEX:
  3701. rc = S_IRUGO;
  3702. break;
  3703. default:
  3704. rc = 0;
  3705. break;
  3706. }
  3707. return rc;
  3708. }
  3709. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  3710. {
  3711. struct scsi_qla_host *ha = data;
  3712. char *str = buf;
  3713. int rc;
  3714. switch (type) {
  3715. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3716. rc = sprintf(str, "%s\n", ha->name_string);
  3717. break;
  3718. default:
  3719. rc = -ENOSYS;
  3720. break;
  3721. }
  3722. return rc;
  3723. }
  3724. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  3725. {
  3726. int rc;
  3727. switch (type) {
  3728. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3729. rc = S_IRUGO;
  3730. break;
  3731. default:
  3732. rc = 0;
  3733. break;
  3734. }
  3735. return rc;
  3736. }
  3737. static ssize_t
  3738. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  3739. char *buf)
  3740. {
  3741. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3742. char *str = buf;
  3743. int rc;
  3744. switch (type) {
  3745. case ISCSI_BOOT_TGT_NAME:
  3746. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  3747. break;
  3748. case ISCSI_BOOT_TGT_IP_ADDR:
  3749. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  3750. rc = sprintf(buf, "%pI4\n",
  3751. &boot_conn->dest_ipaddr.ip_address);
  3752. else
  3753. rc = sprintf(str, "%pI6\n",
  3754. &boot_conn->dest_ipaddr.ip_address);
  3755. break;
  3756. case ISCSI_BOOT_TGT_PORT:
  3757. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  3758. break;
  3759. case ISCSI_BOOT_TGT_CHAP_NAME:
  3760. rc = sprintf(str, "%.*s\n",
  3761. boot_conn->chap.target_chap_name_length,
  3762. (char *)&boot_conn->chap.target_chap_name);
  3763. break;
  3764. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3765. rc = sprintf(str, "%.*s\n",
  3766. boot_conn->chap.target_secret_length,
  3767. (char *)&boot_conn->chap.target_secret);
  3768. break;
  3769. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3770. rc = sprintf(str, "%.*s\n",
  3771. boot_conn->chap.intr_chap_name_length,
  3772. (char *)&boot_conn->chap.intr_chap_name);
  3773. break;
  3774. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3775. rc = sprintf(str, "%.*s\n",
  3776. boot_conn->chap.intr_secret_length,
  3777. (char *)&boot_conn->chap.intr_secret);
  3778. break;
  3779. case ISCSI_BOOT_TGT_FLAGS:
  3780. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3781. break;
  3782. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3783. rc = sprintf(str, "0\n");
  3784. break;
  3785. default:
  3786. rc = -ENOSYS;
  3787. break;
  3788. }
  3789. return rc;
  3790. }
  3791. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  3792. {
  3793. struct scsi_qla_host *ha = data;
  3794. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  3795. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3796. }
  3797. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  3798. {
  3799. struct scsi_qla_host *ha = data;
  3800. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  3801. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3802. }
  3803. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  3804. {
  3805. int rc;
  3806. switch (type) {
  3807. case ISCSI_BOOT_TGT_NAME:
  3808. case ISCSI_BOOT_TGT_IP_ADDR:
  3809. case ISCSI_BOOT_TGT_PORT:
  3810. case ISCSI_BOOT_TGT_CHAP_NAME:
  3811. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3812. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3813. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3814. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3815. case ISCSI_BOOT_TGT_FLAGS:
  3816. rc = S_IRUGO;
  3817. break;
  3818. default:
  3819. rc = 0;
  3820. break;
  3821. }
  3822. return rc;
  3823. }
  3824. static void qla4xxx_boot_release(void *data)
  3825. {
  3826. struct scsi_qla_host *ha = data;
  3827. scsi_host_put(ha->host);
  3828. }
  3829. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  3830. {
  3831. dma_addr_t buf_dma;
  3832. uint32_t addr, pri_addr, sec_addr;
  3833. uint32_t offset;
  3834. uint16_t func_num;
  3835. uint8_t val;
  3836. uint8_t *buf = NULL;
  3837. size_t size = 13 * sizeof(uint8_t);
  3838. int ret = QLA_SUCCESS;
  3839. func_num = PCI_FUNC(ha->pdev->devfn);
  3840. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  3841. __func__, ha->pdev->device, func_num);
  3842. if (is_qla40XX(ha)) {
  3843. if (func_num == 1) {
  3844. addr = NVRAM_PORT0_BOOT_MODE;
  3845. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  3846. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  3847. } else if (func_num == 3) {
  3848. addr = NVRAM_PORT1_BOOT_MODE;
  3849. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  3850. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  3851. } else {
  3852. ret = QLA_ERROR;
  3853. goto exit_boot_info;
  3854. }
  3855. /* Check Boot Mode */
  3856. val = rd_nvram_byte(ha, addr);
  3857. if (!(val & 0x07)) {
  3858. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  3859. "options : 0x%x\n", __func__, val));
  3860. ret = QLA_ERROR;
  3861. goto exit_boot_info;
  3862. }
  3863. /* get primary valid target index */
  3864. val = rd_nvram_byte(ha, pri_addr);
  3865. if (val & BIT_7)
  3866. ddb_index[0] = (val & 0x7f);
  3867. /* get secondary valid target index */
  3868. val = rd_nvram_byte(ha, sec_addr);
  3869. if (val & BIT_7)
  3870. ddb_index[1] = (val & 0x7f);
  3871. } else if (is_qla80XX(ha)) {
  3872. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  3873. &buf_dma, GFP_KERNEL);
  3874. if (!buf) {
  3875. DEBUG2(ql4_printk(KERN_ERR, ha,
  3876. "%s: Unable to allocate dma buffer\n",
  3877. __func__));
  3878. ret = QLA_ERROR;
  3879. goto exit_boot_info;
  3880. }
  3881. if (ha->port_num == 0)
  3882. offset = BOOT_PARAM_OFFSET_PORT0;
  3883. else if (ha->port_num == 1)
  3884. offset = BOOT_PARAM_OFFSET_PORT1;
  3885. else {
  3886. ret = QLA_ERROR;
  3887. goto exit_boot_info_free;
  3888. }
  3889. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  3890. offset;
  3891. if (qla4xxx_get_flash(ha, buf_dma, addr,
  3892. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  3893. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  3894. " failed\n", ha->host_no, __func__));
  3895. ret = QLA_ERROR;
  3896. goto exit_boot_info_free;
  3897. }
  3898. /* Check Boot Mode */
  3899. if (!(buf[1] & 0x07)) {
  3900. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  3901. " : 0x%x\n", buf[1]));
  3902. ret = QLA_ERROR;
  3903. goto exit_boot_info_free;
  3904. }
  3905. /* get primary valid target index */
  3906. if (buf[2] & BIT_7)
  3907. ddb_index[0] = buf[2] & 0x7f;
  3908. /* get secondary valid target index */
  3909. if (buf[11] & BIT_7)
  3910. ddb_index[1] = buf[11] & 0x7f;
  3911. } else {
  3912. ret = QLA_ERROR;
  3913. goto exit_boot_info;
  3914. }
  3915. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  3916. " target ID %d\n", __func__, ddb_index[0],
  3917. ddb_index[1]));
  3918. exit_boot_info_free:
  3919. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  3920. exit_boot_info:
  3921. ha->pri_ddb_idx = ddb_index[0];
  3922. ha->sec_ddb_idx = ddb_index[1];
  3923. return ret;
  3924. }
  3925. /**
  3926. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  3927. * @ha: pointer to adapter structure
  3928. * @username: CHAP username to be returned
  3929. * @password: CHAP password to be returned
  3930. *
  3931. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  3932. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  3933. * So from the CHAP cache find the first BIDI CHAP entry and set it
  3934. * to the boot record in sysfs.
  3935. **/
  3936. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  3937. char *password)
  3938. {
  3939. int i, ret = -EINVAL;
  3940. int max_chap_entries = 0;
  3941. struct ql4_chap_table *chap_table;
  3942. if (is_qla80XX(ha))
  3943. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  3944. sizeof(struct ql4_chap_table);
  3945. else
  3946. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  3947. if (!ha->chap_list) {
  3948. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  3949. return ret;
  3950. }
  3951. mutex_lock(&ha->chap_sem);
  3952. for (i = 0; i < max_chap_entries; i++) {
  3953. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  3954. if (chap_table->cookie !=
  3955. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  3956. continue;
  3957. }
  3958. if (chap_table->flags & BIT_7) /* local */
  3959. continue;
  3960. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  3961. continue;
  3962. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  3963. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  3964. ret = 0;
  3965. break;
  3966. }
  3967. mutex_unlock(&ha->chap_sem);
  3968. return ret;
  3969. }
  3970. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  3971. struct ql4_boot_session_info *boot_sess,
  3972. uint16_t ddb_index)
  3973. {
  3974. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3975. struct dev_db_entry *fw_ddb_entry;
  3976. dma_addr_t fw_ddb_entry_dma;
  3977. uint16_t idx;
  3978. uint16_t options;
  3979. int ret = QLA_SUCCESS;
  3980. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3981. &fw_ddb_entry_dma, GFP_KERNEL);
  3982. if (!fw_ddb_entry) {
  3983. DEBUG2(ql4_printk(KERN_ERR, ha,
  3984. "%s: Unable to allocate dma buffer.\n",
  3985. __func__));
  3986. ret = QLA_ERROR;
  3987. return ret;
  3988. }
  3989. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  3990. fw_ddb_entry_dma, ddb_index)) {
  3991. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  3992. "index [%d]\n", __func__, ddb_index));
  3993. ret = QLA_ERROR;
  3994. goto exit_boot_target;
  3995. }
  3996. /* Update target name and IP from DDB */
  3997. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  3998. min(sizeof(boot_sess->target_name),
  3999. sizeof(fw_ddb_entry->iscsi_name)));
  4000. options = le16_to_cpu(fw_ddb_entry->options);
  4001. if (options & DDB_OPT_IPV6_DEVICE) {
  4002. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4003. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  4004. } else {
  4005. boot_conn->dest_ipaddr.ip_type = 0x1;
  4006. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4007. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  4008. }
  4009. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  4010. /* update chap information */
  4011. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  4012. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4013. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  4014. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  4015. target_chap_name,
  4016. (char *)&boot_conn->chap.target_secret,
  4017. idx);
  4018. if (ret) {
  4019. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  4020. ret = QLA_ERROR;
  4021. goto exit_boot_target;
  4022. }
  4023. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4024. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4025. }
  4026. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4027. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  4028. ret = qla4xxx_get_bidi_chap(ha,
  4029. (char *)&boot_conn->chap.intr_chap_name,
  4030. (char *)&boot_conn->chap.intr_secret);
  4031. if (ret) {
  4032. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  4033. ret = QLA_ERROR;
  4034. goto exit_boot_target;
  4035. }
  4036. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4037. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4038. }
  4039. exit_boot_target:
  4040. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4041. fw_ddb_entry, fw_ddb_entry_dma);
  4042. return ret;
  4043. }
  4044. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  4045. {
  4046. uint16_t ddb_index[2];
  4047. int ret = QLA_ERROR;
  4048. int rval;
  4049. memset(ddb_index, 0, sizeof(ddb_index));
  4050. ddb_index[0] = 0xffff;
  4051. ddb_index[1] = 0xffff;
  4052. ret = get_fw_boot_info(ha, ddb_index);
  4053. if (ret != QLA_SUCCESS) {
  4054. DEBUG2(ql4_printk(KERN_INFO, ha,
  4055. "%s: No boot target configured.\n", __func__));
  4056. return ret;
  4057. }
  4058. if (ql4xdisablesysfsboot)
  4059. return QLA_SUCCESS;
  4060. if (ddb_index[0] == 0xffff)
  4061. goto sec_target;
  4062. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  4063. ddb_index[0]);
  4064. if (rval != QLA_SUCCESS) {
  4065. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  4066. "configured\n", __func__));
  4067. } else
  4068. ret = QLA_SUCCESS;
  4069. sec_target:
  4070. if (ddb_index[1] == 0xffff)
  4071. goto exit_get_boot_info;
  4072. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  4073. ddb_index[1]);
  4074. if (rval != QLA_SUCCESS) {
  4075. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  4076. " configured\n", __func__));
  4077. } else
  4078. ret = QLA_SUCCESS;
  4079. exit_get_boot_info:
  4080. return ret;
  4081. }
  4082. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  4083. {
  4084. struct iscsi_boot_kobj *boot_kobj;
  4085. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  4086. return QLA_ERROR;
  4087. if (ql4xdisablesysfsboot) {
  4088. ql4_printk(KERN_INFO, ha,
  4089. "%s: syfsboot disabled - driver will trigger login "
  4090. "and publish session for discovery .\n", __func__);
  4091. return QLA_SUCCESS;
  4092. }
  4093. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  4094. if (!ha->boot_kset)
  4095. goto kset_free;
  4096. if (!scsi_host_get(ha->host))
  4097. goto kset_free;
  4098. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  4099. qla4xxx_show_boot_tgt_pri_info,
  4100. qla4xxx_tgt_get_attr_visibility,
  4101. qla4xxx_boot_release);
  4102. if (!boot_kobj)
  4103. goto put_host;
  4104. if (!scsi_host_get(ha->host))
  4105. goto kset_free;
  4106. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  4107. qla4xxx_show_boot_tgt_sec_info,
  4108. qla4xxx_tgt_get_attr_visibility,
  4109. qla4xxx_boot_release);
  4110. if (!boot_kobj)
  4111. goto put_host;
  4112. if (!scsi_host_get(ha->host))
  4113. goto kset_free;
  4114. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  4115. qla4xxx_show_boot_ini_info,
  4116. qla4xxx_ini_get_attr_visibility,
  4117. qla4xxx_boot_release);
  4118. if (!boot_kobj)
  4119. goto put_host;
  4120. if (!scsi_host_get(ha->host))
  4121. goto kset_free;
  4122. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  4123. qla4xxx_show_boot_eth_info,
  4124. qla4xxx_eth_get_attr_visibility,
  4125. qla4xxx_boot_release);
  4126. if (!boot_kobj)
  4127. goto put_host;
  4128. return QLA_SUCCESS;
  4129. put_host:
  4130. scsi_host_put(ha->host);
  4131. kset_free:
  4132. iscsi_boot_destroy_kset(ha->boot_kset);
  4133. return -ENOMEM;
  4134. }
  4135. /**
  4136. * qla4xxx_create chap_list - Create CHAP list from FLASH
  4137. * @ha: pointer to adapter structure
  4138. *
  4139. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  4140. * is received, it will be checked in this list. If entry exist then the CHAP
  4141. * entry index is set in the DDB. If CHAP entry does not exist in this list
  4142. * then a new entry is added in FLASH in CHAP table and the index obtained is
  4143. * used in the DDB.
  4144. **/
  4145. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  4146. {
  4147. int rval = 0;
  4148. uint8_t *chap_flash_data = NULL;
  4149. uint32_t offset;
  4150. dma_addr_t chap_dma;
  4151. uint32_t chap_size = 0;
  4152. if (is_qla40XX(ha))
  4153. chap_size = MAX_CHAP_ENTRIES_40XX *
  4154. sizeof(struct ql4_chap_table);
  4155. else /* Single region contains CHAP info for both
  4156. * ports which is divided into half for each port.
  4157. */
  4158. chap_size = ha->hw.flt_chap_size / 2;
  4159. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  4160. &chap_dma, GFP_KERNEL);
  4161. if (!chap_flash_data) {
  4162. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  4163. return;
  4164. }
  4165. if (is_qla40XX(ha))
  4166. offset = FLASH_CHAP_OFFSET;
  4167. else {
  4168. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  4169. if (ha->port_num == 1)
  4170. offset += chap_size;
  4171. }
  4172. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  4173. if (rval != QLA_SUCCESS)
  4174. goto exit_chap_list;
  4175. if (ha->chap_list == NULL)
  4176. ha->chap_list = vmalloc(chap_size);
  4177. if (ha->chap_list == NULL) {
  4178. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  4179. goto exit_chap_list;
  4180. }
  4181. memcpy(ha->chap_list, chap_flash_data, chap_size);
  4182. exit_chap_list:
  4183. dma_free_coherent(&ha->pdev->dev, chap_size,
  4184. chap_flash_data, chap_dma);
  4185. }
  4186. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  4187. struct ql4_tuple_ddb *tddb)
  4188. {
  4189. struct scsi_qla_host *ha;
  4190. struct iscsi_cls_session *cls_sess;
  4191. struct iscsi_cls_conn *cls_conn;
  4192. struct iscsi_session *sess;
  4193. struct iscsi_conn *conn;
  4194. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  4195. ha = ddb_entry->ha;
  4196. cls_sess = ddb_entry->sess;
  4197. sess = cls_sess->dd_data;
  4198. cls_conn = ddb_entry->conn;
  4199. conn = cls_conn->dd_data;
  4200. tddb->tpgt = sess->tpgt;
  4201. tddb->port = conn->persistent_port;
  4202. strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  4203. strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  4204. }
  4205. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  4206. struct ql4_tuple_ddb *tddb,
  4207. uint8_t *flash_isid)
  4208. {
  4209. uint16_t options = 0;
  4210. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  4211. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  4212. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  4213. options = le16_to_cpu(fw_ddb_entry->options);
  4214. if (options & DDB_OPT_IPV6_DEVICE)
  4215. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  4216. else
  4217. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  4218. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  4219. if (flash_isid == NULL)
  4220. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  4221. sizeof(tddb->isid));
  4222. else
  4223. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  4224. }
  4225. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  4226. struct ql4_tuple_ddb *old_tddb,
  4227. struct ql4_tuple_ddb *new_tddb,
  4228. uint8_t is_isid_compare)
  4229. {
  4230. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4231. return QLA_ERROR;
  4232. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  4233. return QLA_ERROR;
  4234. if (old_tddb->port != new_tddb->port)
  4235. return QLA_ERROR;
  4236. /* For multi sessions, driver generates the ISID, so do not compare
  4237. * ISID in reset path since it would be a comparison between the
  4238. * driver generated ISID and firmware generated ISID. This could
  4239. * lead to adding duplicated DDBs in the list as driver generated
  4240. * ISID would not match firmware generated ISID.
  4241. */
  4242. if (is_isid_compare) {
  4243. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  4244. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  4245. __func__, old_tddb->isid[5], old_tddb->isid[4],
  4246. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  4247. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  4248. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  4249. new_tddb->isid[0]));
  4250. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4251. sizeof(old_tddb->isid)))
  4252. return QLA_ERROR;
  4253. }
  4254. DEBUG2(ql4_printk(KERN_INFO, ha,
  4255. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  4256. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  4257. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  4258. new_tddb->ip_addr, new_tddb->iscsi_name));
  4259. return QLA_SUCCESS;
  4260. }
  4261. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  4262. struct dev_db_entry *fw_ddb_entry)
  4263. {
  4264. struct ddb_entry *ddb_entry;
  4265. struct ql4_tuple_ddb *fw_tddb = NULL;
  4266. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4267. int idx;
  4268. int ret = QLA_ERROR;
  4269. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4270. if (!fw_tddb) {
  4271. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4272. "Memory Allocation failed.\n"));
  4273. ret = QLA_SUCCESS;
  4274. goto exit_check;
  4275. }
  4276. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4277. if (!tmp_tddb) {
  4278. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4279. "Memory Allocation failed.\n"));
  4280. ret = QLA_SUCCESS;
  4281. goto exit_check;
  4282. }
  4283. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4284. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  4285. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4286. if (ddb_entry == NULL)
  4287. continue;
  4288. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  4289. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  4290. ret = QLA_SUCCESS; /* found */
  4291. goto exit_check;
  4292. }
  4293. }
  4294. exit_check:
  4295. if (fw_tddb)
  4296. vfree(fw_tddb);
  4297. if (tmp_tddb)
  4298. vfree(tmp_tddb);
  4299. return ret;
  4300. }
  4301. /**
  4302. * qla4xxx_check_existing_isid - check if target with same isid exist
  4303. * in target list
  4304. * @list_nt: list of target
  4305. * @isid: isid to check
  4306. *
  4307. * This routine return QLA_SUCCESS if target with same isid exist
  4308. **/
  4309. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  4310. {
  4311. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4312. struct dev_db_entry *fw_ddb_entry;
  4313. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4314. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  4315. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  4316. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  4317. return QLA_SUCCESS;
  4318. }
  4319. }
  4320. return QLA_ERROR;
  4321. }
  4322. /**
  4323. * qla4xxx_update_isid - compare ddbs and updated isid
  4324. * @ha: Pointer to host adapter structure.
  4325. * @list_nt: list of nt target
  4326. * @fw_ddb_entry: firmware ddb entry
  4327. *
  4328. * This routine update isid if ddbs have same iqn, same isid and
  4329. * different IP addr.
  4330. * Return QLA_SUCCESS if isid is updated.
  4331. **/
  4332. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  4333. struct list_head *list_nt,
  4334. struct dev_db_entry *fw_ddb_entry)
  4335. {
  4336. uint8_t base_value, i;
  4337. base_value = fw_ddb_entry->isid[1] & 0x1f;
  4338. for (i = 0; i < 8; i++) {
  4339. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  4340. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4341. break;
  4342. }
  4343. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4344. return QLA_ERROR;
  4345. return QLA_SUCCESS;
  4346. }
  4347. /**
  4348. * qla4xxx_should_update_isid - check if isid need to update
  4349. * @ha: Pointer to host adapter structure.
  4350. * @old_tddb: ddb tuple
  4351. * @new_tddb: ddb tuple
  4352. *
  4353. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  4354. * same isid
  4355. **/
  4356. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  4357. struct ql4_tuple_ddb *old_tddb,
  4358. struct ql4_tuple_ddb *new_tddb)
  4359. {
  4360. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  4361. /* Same ip */
  4362. if (old_tddb->port == new_tddb->port)
  4363. return QLA_ERROR;
  4364. }
  4365. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4366. /* different iqn */
  4367. return QLA_ERROR;
  4368. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4369. sizeof(old_tddb->isid)))
  4370. /* different isid */
  4371. return QLA_ERROR;
  4372. return QLA_SUCCESS;
  4373. }
  4374. /**
  4375. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  4376. * @ha: Pointer to host adapter structure.
  4377. * @list_nt: list of nt target.
  4378. * @fw_ddb_entry: firmware ddb entry.
  4379. *
  4380. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  4381. * duplicate ddb in list_nt.
  4382. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  4383. * Note: This function also update isid of DDB if required.
  4384. **/
  4385. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  4386. struct list_head *list_nt,
  4387. struct dev_db_entry *fw_ddb_entry)
  4388. {
  4389. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4390. struct ql4_tuple_ddb *fw_tddb = NULL;
  4391. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4392. int rval, ret = QLA_ERROR;
  4393. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4394. if (!fw_tddb) {
  4395. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4396. "Memory Allocation failed.\n"));
  4397. ret = QLA_SUCCESS;
  4398. goto exit_check;
  4399. }
  4400. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4401. if (!tmp_tddb) {
  4402. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4403. "Memory Allocation failed.\n"));
  4404. ret = QLA_SUCCESS;
  4405. goto exit_check;
  4406. }
  4407. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4408. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4409. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  4410. nt_ddb_idx->flash_isid);
  4411. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  4412. /* found duplicate ddb */
  4413. if (ret == QLA_SUCCESS)
  4414. goto exit_check;
  4415. }
  4416. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4417. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  4418. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  4419. if (ret == QLA_SUCCESS) {
  4420. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  4421. if (rval == QLA_SUCCESS)
  4422. ret = QLA_ERROR;
  4423. else
  4424. ret = QLA_SUCCESS;
  4425. goto exit_check;
  4426. }
  4427. }
  4428. exit_check:
  4429. if (fw_tddb)
  4430. vfree(fw_tddb);
  4431. if (tmp_tddb)
  4432. vfree(tmp_tddb);
  4433. return ret;
  4434. }
  4435. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  4436. {
  4437. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4438. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4439. list_del_init(&ddb_idx->list);
  4440. vfree(ddb_idx);
  4441. }
  4442. }
  4443. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  4444. struct dev_db_entry *fw_ddb_entry)
  4445. {
  4446. struct iscsi_endpoint *ep;
  4447. struct sockaddr_in *addr;
  4448. struct sockaddr_in6 *addr6;
  4449. struct sockaddr *t_addr;
  4450. struct sockaddr_storage *dst_addr;
  4451. char *ip;
  4452. /* TODO: need to destroy on unload iscsi_endpoint*/
  4453. dst_addr = vmalloc(sizeof(*dst_addr));
  4454. if (!dst_addr)
  4455. return NULL;
  4456. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  4457. t_addr = (struct sockaddr *)dst_addr;
  4458. t_addr->sa_family = AF_INET6;
  4459. addr6 = (struct sockaddr_in6 *)dst_addr;
  4460. ip = (char *)&addr6->sin6_addr;
  4461. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  4462. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4463. } else {
  4464. t_addr = (struct sockaddr *)dst_addr;
  4465. t_addr->sa_family = AF_INET;
  4466. addr = (struct sockaddr_in *)dst_addr;
  4467. ip = (char *)&addr->sin_addr;
  4468. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  4469. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4470. }
  4471. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  4472. vfree(dst_addr);
  4473. return ep;
  4474. }
  4475. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  4476. {
  4477. if (ql4xdisablesysfsboot)
  4478. return QLA_SUCCESS;
  4479. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  4480. return QLA_ERROR;
  4481. return QLA_SUCCESS;
  4482. }
  4483. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  4484. struct ddb_entry *ddb_entry,
  4485. uint16_t idx)
  4486. {
  4487. uint16_t def_timeout;
  4488. ddb_entry->ddb_type = FLASH_DDB;
  4489. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  4490. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  4491. ddb_entry->ha = ha;
  4492. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  4493. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  4494. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  4495. atomic_set(&ddb_entry->relogin_timer, 0);
  4496. atomic_set(&ddb_entry->relogin_retry_count, 0);
  4497. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  4498. ddb_entry->default_relogin_timeout =
  4499. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  4500. def_timeout : LOGIN_TOV;
  4501. ddb_entry->default_time2wait =
  4502. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  4503. if (ql4xdisablesysfsboot &&
  4504. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  4505. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  4506. }
  4507. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  4508. {
  4509. uint32_t idx = 0;
  4510. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  4511. uint32_t sts[MBOX_REG_COUNT];
  4512. uint32_t ip_state;
  4513. unsigned long wtime;
  4514. int ret;
  4515. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  4516. do {
  4517. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  4518. if (ip_idx[idx] == -1)
  4519. continue;
  4520. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  4521. if (ret == QLA_ERROR) {
  4522. ip_idx[idx] = -1;
  4523. continue;
  4524. }
  4525. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  4526. DEBUG2(ql4_printk(KERN_INFO, ha,
  4527. "Waiting for IP state for idx = %d, state = 0x%x\n",
  4528. ip_idx[idx], ip_state));
  4529. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  4530. ip_state == IP_ADDRSTATE_INVALID ||
  4531. ip_state == IP_ADDRSTATE_PREFERRED ||
  4532. ip_state == IP_ADDRSTATE_DEPRICATED ||
  4533. ip_state == IP_ADDRSTATE_DISABLING)
  4534. ip_idx[idx] = -1;
  4535. }
  4536. /* Break if all IP states checked */
  4537. if ((ip_idx[0] == -1) &&
  4538. (ip_idx[1] == -1) &&
  4539. (ip_idx[2] == -1) &&
  4540. (ip_idx[3] == -1))
  4541. break;
  4542. schedule_timeout_uninterruptible(HZ);
  4543. } while (time_after(wtime, jiffies));
  4544. }
  4545. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  4546. struct list_head *list_st)
  4547. {
  4548. struct qla_ddb_index *st_ddb_idx;
  4549. int max_ddbs;
  4550. int fw_idx_size;
  4551. struct dev_db_entry *fw_ddb_entry;
  4552. dma_addr_t fw_ddb_dma;
  4553. int ret;
  4554. uint32_t idx = 0, next_idx = 0;
  4555. uint32_t state = 0, conn_err = 0;
  4556. uint16_t conn_id = 0;
  4557. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4558. &fw_ddb_dma);
  4559. if (fw_ddb_entry == NULL) {
  4560. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4561. goto exit_st_list;
  4562. }
  4563. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4564. MAX_DEV_DB_ENTRIES;
  4565. fw_idx_size = sizeof(struct qla_ddb_index);
  4566. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4567. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4568. NULL, &next_idx, &state,
  4569. &conn_err, NULL, &conn_id);
  4570. if (ret == QLA_ERROR)
  4571. break;
  4572. /* Ignore DDB if invalid state (unassigned) */
  4573. if (state == DDB_DS_UNASSIGNED)
  4574. goto continue_next_st;
  4575. /* Check if ST, add to the list_st */
  4576. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  4577. goto continue_next_st;
  4578. st_ddb_idx = vzalloc(fw_idx_size);
  4579. if (!st_ddb_idx)
  4580. break;
  4581. st_ddb_idx->fw_ddb_idx = idx;
  4582. list_add_tail(&st_ddb_idx->list, list_st);
  4583. continue_next_st:
  4584. if (next_idx == 0)
  4585. break;
  4586. }
  4587. exit_st_list:
  4588. if (fw_ddb_entry)
  4589. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4590. }
  4591. /**
  4592. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  4593. * @ha: pointer to adapter structure
  4594. * @list_ddb: List from which failed ddb to be removed
  4595. *
  4596. * Iterate over the list of DDBs and find and remove DDBs that are either in
  4597. * no connection active state or failed state
  4598. **/
  4599. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  4600. struct list_head *list_ddb)
  4601. {
  4602. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4603. uint32_t next_idx = 0;
  4604. uint32_t state = 0, conn_err = 0;
  4605. int ret;
  4606. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4607. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  4608. NULL, 0, NULL, &next_idx, &state,
  4609. &conn_err, NULL, NULL);
  4610. if (ret == QLA_ERROR)
  4611. continue;
  4612. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4613. state == DDB_DS_SESSION_FAILED) {
  4614. list_del_init(&ddb_idx->list);
  4615. vfree(ddb_idx);
  4616. }
  4617. }
  4618. }
  4619. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  4620. struct dev_db_entry *fw_ddb_entry,
  4621. int is_reset, uint16_t idx)
  4622. {
  4623. struct iscsi_cls_session *cls_sess;
  4624. struct iscsi_session *sess;
  4625. struct iscsi_cls_conn *cls_conn;
  4626. struct iscsi_endpoint *ep;
  4627. uint16_t cmds_max = 32;
  4628. uint16_t conn_id = 0;
  4629. uint32_t initial_cmdsn = 0;
  4630. int ret = QLA_SUCCESS;
  4631. struct ddb_entry *ddb_entry = NULL;
  4632. /* Create session object, with INVALID_ENTRY,
  4633. * the targer_id would get set when we issue the login
  4634. */
  4635. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  4636. cmds_max, sizeof(struct ddb_entry),
  4637. sizeof(struct ql4_task_data),
  4638. initial_cmdsn, INVALID_ENTRY);
  4639. if (!cls_sess) {
  4640. ret = QLA_ERROR;
  4641. goto exit_setup;
  4642. }
  4643. /*
  4644. * so calling module_put function to decrement the
  4645. * reference count.
  4646. **/
  4647. module_put(qla4xxx_iscsi_transport.owner);
  4648. sess = cls_sess->dd_data;
  4649. ddb_entry = sess->dd_data;
  4650. ddb_entry->sess = cls_sess;
  4651. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  4652. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  4653. sizeof(struct dev_db_entry));
  4654. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  4655. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  4656. if (!cls_conn) {
  4657. ret = QLA_ERROR;
  4658. goto exit_setup;
  4659. }
  4660. ddb_entry->conn = cls_conn;
  4661. /* Setup ep, for displaying attributes in sysfs */
  4662. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  4663. if (ep) {
  4664. ep->conn = cls_conn;
  4665. cls_conn->ep = ep;
  4666. } else {
  4667. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  4668. ret = QLA_ERROR;
  4669. goto exit_setup;
  4670. }
  4671. /* Update sess/conn params */
  4672. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  4673. if (is_reset == RESET_ADAPTER) {
  4674. iscsi_block_session(cls_sess);
  4675. /* Use the relogin path to discover new devices
  4676. * by short-circuting the logic of setting
  4677. * timer to relogin - instead set the flags
  4678. * to initiate login right away.
  4679. */
  4680. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4681. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4682. }
  4683. exit_setup:
  4684. return ret;
  4685. }
  4686. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  4687. struct list_head *list_nt, int is_reset)
  4688. {
  4689. struct dev_db_entry *fw_ddb_entry;
  4690. dma_addr_t fw_ddb_dma;
  4691. int max_ddbs;
  4692. int fw_idx_size;
  4693. int ret;
  4694. uint32_t idx = 0, next_idx = 0;
  4695. uint32_t state = 0, conn_err = 0;
  4696. uint16_t conn_id = 0;
  4697. struct qla_ddb_index *nt_ddb_idx;
  4698. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4699. &fw_ddb_dma);
  4700. if (fw_ddb_entry == NULL) {
  4701. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4702. goto exit_nt_list;
  4703. }
  4704. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4705. MAX_DEV_DB_ENTRIES;
  4706. fw_idx_size = sizeof(struct qla_ddb_index);
  4707. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4708. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4709. NULL, &next_idx, &state,
  4710. &conn_err, NULL, &conn_id);
  4711. if (ret == QLA_ERROR)
  4712. break;
  4713. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  4714. goto continue_next_nt;
  4715. /* Check if NT, then add to list it */
  4716. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  4717. goto continue_next_nt;
  4718. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4719. state == DDB_DS_SESSION_FAILED))
  4720. goto continue_next_nt;
  4721. DEBUG2(ql4_printk(KERN_INFO, ha,
  4722. "Adding DDB to session = 0x%x\n", idx));
  4723. if (is_reset == INIT_ADAPTER) {
  4724. nt_ddb_idx = vmalloc(fw_idx_size);
  4725. if (!nt_ddb_idx)
  4726. break;
  4727. nt_ddb_idx->fw_ddb_idx = idx;
  4728. /* Copy original isid as it may get updated in function
  4729. * qla4xxx_update_isid(). We need original isid in
  4730. * function qla4xxx_compare_tuple_ddb to find duplicate
  4731. * target */
  4732. memcpy(&nt_ddb_idx->flash_isid[0],
  4733. &fw_ddb_entry->isid[0],
  4734. sizeof(nt_ddb_idx->flash_isid));
  4735. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  4736. fw_ddb_entry);
  4737. if (ret == QLA_SUCCESS) {
  4738. /* free nt_ddb_idx and do not add to list_nt */
  4739. vfree(nt_ddb_idx);
  4740. goto continue_next_nt;
  4741. }
  4742. /* Copy updated isid */
  4743. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  4744. sizeof(struct dev_db_entry));
  4745. list_add_tail(&nt_ddb_idx->list, list_nt);
  4746. } else if (is_reset == RESET_ADAPTER) {
  4747. if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
  4748. QLA_SUCCESS)
  4749. goto continue_next_nt;
  4750. }
  4751. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  4752. if (ret == QLA_ERROR)
  4753. goto exit_nt_list;
  4754. continue_next_nt:
  4755. if (next_idx == 0)
  4756. break;
  4757. }
  4758. exit_nt_list:
  4759. if (fw_ddb_entry)
  4760. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4761. }
  4762. static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  4763. struct list_head *list_nt)
  4764. {
  4765. struct dev_db_entry *fw_ddb_entry;
  4766. dma_addr_t fw_ddb_dma;
  4767. int max_ddbs;
  4768. int fw_idx_size;
  4769. int ret;
  4770. uint32_t idx = 0, next_idx = 0;
  4771. uint32_t state = 0, conn_err = 0;
  4772. uint16_t conn_id = 0;
  4773. struct qla_ddb_index *nt_ddb_idx;
  4774. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4775. &fw_ddb_dma);
  4776. if (fw_ddb_entry == NULL) {
  4777. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4778. goto exit_new_nt_list;
  4779. }
  4780. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4781. MAX_DEV_DB_ENTRIES;
  4782. fw_idx_size = sizeof(struct qla_ddb_index);
  4783. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4784. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4785. NULL, &next_idx, &state,
  4786. &conn_err, NULL, &conn_id);
  4787. if (ret == QLA_ERROR)
  4788. break;
  4789. /* Check if NT, then add it to list */
  4790. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  4791. goto continue_next_new_nt;
  4792. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
  4793. goto continue_next_new_nt;
  4794. DEBUG2(ql4_printk(KERN_INFO, ha,
  4795. "Adding DDB to session = 0x%x\n", idx));
  4796. nt_ddb_idx = vmalloc(fw_idx_size);
  4797. if (!nt_ddb_idx)
  4798. break;
  4799. nt_ddb_idx->fw_ddb_idx = idx;
  4800. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
  4801. if (ret == QLA_SUCCESS) {
  4802. /* free nt_ddb_idx and do not add to list_nt */
  4803. vfree(nt_ddb_idx);
  4804. goto continue_next_new_nt;
  4805. }
  4806. list_add_tail(&nt_ddb_idx->list, list_nt);
  4807. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  4808. idx);
  4809. if (ret == QLA_ERROR)
  4810. goto exit_new_nt_list;
  4811. continue_next_new_nt:
  4812. if (next_idx == 0)
  4813. break;
  4814. }
  4815. exit_new_nt_list:
  4816. if (fw_ddb_entry)
  4817. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4818. }
  4819. /**
  4820. * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
  4821. * @dev: dev associated with the sysfs entry
  4822. * @data: pointer to flashnode session object
  4823. *
  4824. * Returns:
  4825. * 1: if flashnode entry is non-persistent
  4826. * 0: if flashnode entry is persistent
  4827. **/
  4828. static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
  4829. {
  4830. struct iscsi_bus_flash_session *fnode_sess;
  4831. if (!iscsi_flashnode_bus_match(dev, NULL))
  4832. return 0;
  4833. fnode_sess = iscsi_dev_to_flash_session(dev);
  4834. return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
  4835. }
  4836. /**
  4837. * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
  4838. * @ha: pointer to host
  4839. * @fw_ddb_entry: flash ddb data
  4840. * @idx: target index
  4841. * @user: if set then this call is made from userland else from kernel
  4842. *
  4843. * Returns:
  4844. * On sucess: QLA_SUCCESS
  4845. * On failure: QLA_ERROR
  4846. *
  4847. * This create separate sysfs entries for session and connection attributes of
  4848. * the given fw ddb entry.
  4849. * If this is invoked as a result of a userspace call then the entry is marked
  4850. * as nonpersistent using flash_state field.
  4851. **/
  4852. static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
  4853. struct dev_db_entry *fw_ddb_entry,
  4854. uint16_t *idx, int user)
  4855. {
  4856. struct iscsi_bus_flash_session *fnode_sess = NULL;
  4857. struct iscsi_bus_flash_conn *fnode_conn = NULL;
  4858. int rc = QLA_ERROR;
  4859. fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
  4860. &qla4xxx_iscsi_transport, 0);
  4861. if (!fnode_sess) {
  4862. ql4_printk(KERN_ERR, ha,
  4863. "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
  4864. __func__, *idx, ha->host_no);
  4865. goto exit_tgt_create;
  4866. }
  4867. fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
  4868. &qla4xxx_iscsi_transport, 0);
  4869. if (!fnode_conn) {
  4870. ql4_printk(KERN_ERR, ha,
  4871. "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
  4872. __func__, *idx, ha->host_no);
  4873. goto free_sess;
  4874. }
  4875. if (user) {
  4876. fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
  4877. } else {
  4878. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  4879. if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
  4880. fnode_sess->is_boot_target = 1;
  4881. else
  4882. fnode_sess->is_boot_target = 0;
  4883. }
  4884. rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
  4885. fw_ddb_entry);
  4886. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  4887. __func__, fnode_sess->dev.kobj.name);
  4888. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  4889. __func__, fnode_conn->dev.kobj.name);
  4890. return QLA_SUCCESS;
  4891. free_sess:
  4892. iscsi_destroy_flashnode_sess(fnode_sess);
  4893. exit_tgt_create:
  4894. return QLA_ERROR;
  4895. }
  4896. /**
  4897. * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
  4898. * @shost: pointer to host
  4899. * @buf: type of ddb entry (ipv4/ipv6)
  4900. * @len: length of buf
  4901. *
  4902. * This creates new ddb entry in the flash by finding first free index and
  4903. * storing default ddb there. And then create sysfs entry for the new ddb entry.
  4904. **/
  4905. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  4906. int len)
  4907. {
  4908. struct scsi_qla_host *ha = to_qla_host(shost);
  4909. struct dev_db_entry *fw_ddb_entry = NULL;
  4910. dma_addr_t fw_ddb_entry_dma;
  4911. struct device *dev;
  4912. uint16_t idx = 0;
  4913. uint16_t max_ddbs = 0;
  4914. uint32_t options = 0;
  4915. uint32_t rval = QLA_ERROR;
  4916. if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
  4917. strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
  4918. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
  4919. __func__));
  4920. goto exit_ddb_add;
  4921. }
  4922. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  4923. MAX_DEV_DB_ENTRIES;
  4924. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4925. &fw_ddb_entry_dma, GFP_KERNEL);
  4926. if (!fw_ddb_entry) {
  4927. DEBUG2(ql4_printk(KERN_ERR, ha,
  4928. "%s: Unable to allocate dma buffer\n",
  4929. __func__));
  4930. goto exit_ddb_add;
  4931. }
  4932. dev = iscsi_find_flashnode_sess(ha->host, NULL,
  4933. qla4xxx_sysfs_ddb_is_non_persistent);
  4934. if (dev) {
  4935. ql4_printk(KERN_ERR, ha,
  4936. "%s: A non-persistent entry %s found\n",
  4937. __func__, dev->kobj.name);
  4938. put_device(dev);
  4939. goto exit_ddb_add;
  4940. }
  4941. for (idx = 0; idx < max_ddbs; idx++) {
  4942. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
  4943. fw_ddb_entry_dma, idx))
  4944. break;
  4945. }
  4946. if (idx == max_ddbs)
  4947. goto exit_ddb_add;
  4948. if (!strncasecmp("ipv6", buf, 4))
  4949. options |= IPV6_DEFAULT_DDB_ENTRY;
  4950. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  4951. if (rval == QLA_ERROR)
  4952. goto exit_ddb_add;
  4953. rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
  4954. exit_ddb_add:
  4955. if (fw_ddb_entry)
  4956. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4957. fw_ddb_entry, fw_ddb_entry_dma);
  4958. if (rval == QLA_SUCCESS)
  4959. return idx;
  4960. else
  4961. return -EIO;
  4962. }
  4963. /**
  4964. * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
  4965. * @fnode_sess: pointer to session attrs of flash ddb entry
  4966. * @fnode_conn: pointer to connection attrs of flash ddb entry
  4967. *
  4968. * This writes the contents of target ddb buffer to Flash with a valid cookie
  4969. * value in order to make the ddb entry persistent.
  4970. **/
  4971. static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
  4972. struct iscsi_bus_flash_conn *fnode_conn)
  4973. {
  4974. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  4975. struct scsi_qla_host *ha = to_qla_host(shost);
  4976. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  4977. struct dev_db_entry *fw_ddb_entry = NULL;
  4978. dma_addr_t fw_ddb_entry_dma;
  4979. uint32_t options = 0;
  4980. int rval = 0;
  4981. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4982. &fw_ddb_entry_dma, GFP_KERNEL);
  4983. if (!fw_ddb_entry) {
  4984. DEBUG2(ql4_printk(KERN_ERR, ha,
  4985. "%s: Unable to allocate dma buffer\n",
  4986. __func__));
  4987. rval = -ENOMEM;
  4988. goto exit_ddb_apply;
  4989. }
  4990. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  4991. options |= IPV6_DEFAULT_DDB_ENTRY;
  4992. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  4993. if (rval == QLA_ERROR)
  4994. goto exit_ddb_apply;
  4995. dev_db_start_offset += (fnode_sess->target_id *
  4996. sizeof(*fw_ddb_entry));
  4997. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  4998. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  4999. rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  5000. sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
  5001. if (rval == QLA_SUCCESS) {
  5002. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  5003. ql4_printk(KERN_INFO, ha,
  5004. "%s: flash node %u of host %lu written to flash\n",
  5005. __func__, fnode_sess->target_id, ha->host_no);
  5006. } else {
  5007. rval = -EIO;
  5008. ql4_printk(KERN_ERR, ha,
  5009. "%s: Error while writing flash node %u of host %lu to flash\n",
  5010. __func__, fnode_sess->target_id, ha->host_no);
  5011. }
  5012. exit_ddb_apply:
  5013. if (fw_ddb_entry)
  5014. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5015. fw_ddb_entry, fw_ddb_entry_dma);
  5016. return rval;
  5017. }
  5018. static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
  5019. struct dev_db_entry *fw_ddb_entry,
  5020. uint16_t idx)
  5021. {
  5022. struct dev_db_entry *ddb_entry = NULL;
  5023. dma_addr_t ddb_entry_dma;
  5024. unsigned long wtime;
  5025. uint32_t mbx_sts = 0;
  5026. uint32_t state = 0, conn_err = 0;
  5027. uint16_t tmo = 0;
  5028. int ret = 0;
  5029. ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5030. &ddb_entry_dma, GFP_KERNEL);
  5031. if (!ddb_entry) {
  5032. DEBUG2(ql4_printk(KERN_ERR, ha,
  5033. "%s: Unable to allocate dma buffer\n",
  5034. __func__));
  5035. return QLA_ERROR;
  5036. }
  5037. memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
  5038. ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
  5039. if (ret != QLA_SUCCESS) {
  5040. DEBUG2(ql4_printk(KERN_ERR, ha,
  5041. "%s: Unable to set ddb entry for index %d\n",
  5042. __func__, idx));
  5043. goto exit_ddb_conn_open;
  5044. }
  5045. qla4xxx_conn_open(ha, idx);
  5046. /* To ensure that sendtargets is done, wait for at least 12 secs */
  5047. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  5048. (ha->def_timeout < LOGIN_TOV * 10) ?
  5049. ha->def_timeout : LOGIN_TOV);
  5050. DEBUG2(ql4_printk(KERN_INFO, ha,
  5051. "Default time to wait for login to ddb %d\n", tmo));
  5052. wtime = jiffies + (HZ * tmo);
  5053. do {
  5054. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  5055. NULL, &state, &conn_err, NULL,
  5056. NULL);
  5057. if (ret == QLA_ERROR)
  5058. continue;
  5059. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  5060. state == DDB_DS_SESSION_FAILED)
  5061. break;
  5062. schedule_timeout_uninterruptible(HZ / 10);
  5063. } while (time_after(wtime, jiffies));
  5064. exit_ddb_conn_open:
  5065. if (ddb_entry)
  5066. dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5067. ddb_entry, ddb_entry_dma);
  5068. return ret;
  5069. }
  5070. static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
  5071. struct dev_db_entry *fw_ddb_entry)
  5072. {
  5073. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  5074. struct list_head list_nt;
  5075. uint16_t ddb_index;
  5076. int ret = 0;
  5077. if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
  5078. ql4_printk(KERN_WARNING, ha,
  5079. "%s: A discovery already in progress!\n", __func__);
  5080. return QLA_ERROR;
  5081. }
  5082. INIT_LIST_HEAD(&list_nt);
  5083. set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5084. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  5085. if (ret == QLA_ERROR)
  5086. goto exit_login_st_clr_bit;
  5087. ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
  5088. if (ret == QLA_ERROR)
  5089. goto exit_login_st;
  5090. qla4xxx_build_new_nt_list(ha, &list_nt);
  5091. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
  5092. list_del_init(&ddb_idx->list);
  5093. qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
  5094. vfree(ddb_idx);
  5095. }
  5096. exit_login_st:
  5097. if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
  5098. ql4_printk(KERN_ERR, ha,
  5099. "Unable to clear DDB index = 0x%x\n", ddb_index);
  5100. }
  5101. clear_bit(ddb_index, ha->ddb_idx_map);
  5102. exit_login_st_clr_bit:
  5103. clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5104. return ret;
  5105. }
  5106. static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
  5107. struct dev_db_entry *fw_ddb_entry,
  5108. uint16_t idx)
  5109. {
  5110. int ret = QLA_ERROR;
  5111. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
  5112. if (ret != QLA_SUCCESS)
  5113. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  5114. idx);
  5115. else
  5116. ret = -EPERM;
  5117. return ret;
  5118. }
  5119. /**
  5120. * qla4xxx_sysfs_ddb_login - Login to the specified target
  5121. * @fnode_sess: pointer to session attrs of flash ddb entry
  5122. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5123. *
  5124. * This logs in to the specified target
  5125. **/
  5126. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  5127. struct iscsi_bus_flash_conn *fnode_conn)
  5128. {
  5129. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5130. struct scsi_qla_host *ha = to_qla_host(shost);
  5131. struct dev_db_entry *fw_ddb_entry = NULL;
  5132. dma_addr_t fw_ddb_entry_dma;
  5133. uint32_t options = 0;
  5134. int ret = 0;
  5135. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
  5136. ql4_printk(KERN_ERR, ha,
  5137. "%s: Target info is not persistent\n", __func__);
  5138. ret = -EIO;
  5139. goto exit_ddb_login;
  5140. }
  5141. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5142. &fw_ddb_entry_dma, GFP_KERNEL);
  5143. if (!fw_ddb_entry) {
  5144. DEBUG2(ql4_printk(KERN_ERR, ha,
  5145. "%s: Unable to allocate dma buffer\n",
  5146. __func__));
  5147. ret = -ENOMEM;
  5148. goto exit_ddb_login;
  5149. }
  5150. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5151. options |= IPV6_DEFAULT_DDB_ENTRY;
  5152. ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  5153. if (ret == QLA_ERROR)
  5154. goto exit_ddb_login;
  5155. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  5156. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  5157. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  5158. ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry);
  5159. else
  5160. ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
  5161. fnode_sess->target_id);
  5162. if (ret > 0)
  5163. ret = -EIO;
  5164. exit_ddb_login:
  5165. if (fw_ddb_entry)
  5166. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5167. fw_ddb_entry, fw_ddb_entry_dma);
  5168. return ret;
  5169. }
  5170. /**
  5171. * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
  5172. * @cls_sess: pointer to session to be logged out
  5173. *
  5174. * This performs session log out from the specified target
  5175. **/
  5176. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
  5177. {
  5178. struct iscsi_session *sess;
  5179. struct ddb_entry *ddb_entry = NULL;
  5180. struct scsi_qla_host *ha;
  5181. struct dev_db_entry *fw_ddb_entry = NULL;
  5182. dma_addr_t fw_ddb_entry_dma;
  5183. unsigned long flags;
  5184. unsigned long wtime;
  5185. uint32_t ddb_state;
  5186. int options;
  5187. int ret = 0;
  5188. sess = cls_sess->dd_data;
  5189. ddb_entry = sess->dd_data;
  5190. ha = ddb_entry->ha;
  5191. if (ddb_entry->ddb_type != FLASH_DDB) {
  5192. ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
  5193. __func__);
  5194. ret = -ENXIO;
  5195. goto exit_ddb_logout;
  5196. }
  5197. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  5198. ql4_printk(KERN_ERR, ha,
  5199. "%s: Logout from boot target entry is not permitted.\n",
  5200. __func__);
  5201. ret = -EPERM;
  5202. goto exit_ddb_logout;
  5203. }
  5204. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5205. &fw_ddb_entry_dma, GFP_KERNEL);
  5206. if (!fw_ddb_entry) {
  5207. ql4_printk(KERN_ERR, ha,
  5208. "%s: Unable to allocate dma buffer\n", __func__);
  5209. ret = -ENOMEM;
  5210. goto exit_ddb_logout;
  5211. }
  5212. if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  5213. goto ddb_logout_init;
  5214. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5215. fw_ddb_entry, fw_ddb_entry_dma,
  5216. NULL, NULL, &ddb_state, NULL,
  5217. NULL, NULL);
  5218. if (ret == QLA_ERROR)
  5219. goto ddb_logout_init;
  5220. if (ddb_state == DDB_DS_SESSION_ACTIVE)
  5221. goto ddb_logout_init;
  5222. /* wait until next relogin is triggered using DF_RELOGIN and
  5223. * clear DF_RELOGIN to avoid invocation of further relogin
  5224. */
  5225. wtime = jiffies + (HZ * RELOGIN_TOV);
  5226. do {
  5227. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
  5228. goto ddb_logout_init;
  5229. schedule_timeout_uninterruptible(HZ);
  5230. } while ((time_after(wtime, jiffies)));
  5231. ddb_logout_init:
  5232. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  5233. atomic_set(&ddb_entry->relogin_timer, 0);
  5234. options = LOGOUT_OPTION_CLOSE_SESSION;
  5235. qla4xxx_session_logout_ddb(ha, ddb_entry, options);
  5236. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  5237. wtime = jiffies + (HZ * LOGOUT_TOV);
  5238. do {
  5239. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5240. fw_ddb_entry, fw_ddb_entry_dma,
  5241. NULL, NULL, &ddb_state, NULL,
  5242. NULL, NULL);
  5243. if (ret == QLA_ERROR)
  5244. goto ddb_logout_clr_sess;
  5245. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  5246. (ddb_state == DDB_DS_SESSION_FAILED))
  5247. goto ddb_logout_clr_sess;
  5248. schedule_timeout_uninterruptible(HZ);
  5249. } while ((time_after(wtime, jiffies)));
  5250. ddb_logout_clr_sess:
  5251. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  5252. /*
  5253. * we have decremented the reference count of the driver
  5254. * when we setup the session to have the driver unload
  5255. * to be seamless without actually destroying the
  5256. * session
  5257. **/
  5258. try_module_get(qla4xxx_iscsi_transport.owner);
  5259. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  5260. spin_lock_irqsave(&ha->hardware_lock, flags);
  5261. qla4xxx_free_ddb(ha, ddb_entry);
  5262. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  5263. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  5264. iscsi_session_teardown(ddb_entry->sess);
  5265. clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
  5266. ret = QLA_SUCCESS;
  5267. exit_ddb_logout:
  5268. if (fw_ddb_entry)
  5269. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5270. fw_ddb_entry, fw_ddb_entry_dma);
  5271. return ret;
  5272. }
  5273. /**
  5274. * qla4xxx_sysfs_ddb_logout - Logout from the specified target
  5275. * @fnode_sess: pointer to session attrs of flash ddb entry
  5276. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5277. *
  5278. * This performs log out from the specified target
  5279. **/
  5280. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  5281. struct iscsi_bus_flash_conn *fnode_conn)
  5282. {
  5283. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5284. struct scsi_qla_host *ha = to_qla_host(shost);
  5285. struct ql4_tuple_ddb *flash_tddb = NULL;
  5286. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5287. struct dev_db_entry *fw_ddb_entry = NULL;
  5288. struct ddb_entry *ddb_entry = NULL;
  5289. dma_addr_t fw_ddb_dma;
  5290. uint32_t next_idx = 0;
  5291. uint32_t state = 0, conn_err = 0;
  5292. uint16_t conn_id = 0;
  5293. int idx, index;
  5294. int status, ret = 0;
  5295. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5296. &fw_ddb_dma);
  5297. if (fw_ddb_entry == NULL) {
  5298. ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
  5299. ret = -ENOMEM;
  5300. goto exit_ddb_logout;
  5301. }
  5302. flash_tddb = vzalloc(sizeof(*flash_tddb));
  5303. if (!flash_tddb) {
  5304. ql4_printk(KERN_WARNING, ha,
  5305. "%s:Memory Allocation failed.\n", __func__);
  5306. ret = -ENOMEM;
  5307. goto exit_ddb_logout;
  5308. }
  5309. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5310. if (!tmp_tddb) {
  5311. ql4_printk(KERN_WARNING, ha,
  5312. "%s:Memory Allocation failed.\n", __func__);
  5313. ret = -ENOMEM;
  5314. goto exit_ddb_logout;
  5315. }
  5316. if (!fnode_sess->targetname) {
  5317. ql4_printk(KERN_ERR, ha,
  5318. "%s:Cannot logout from SendTarget entry\n",
  5319. __func__);
  5320. ret = -EPERM;
  5321. goto exit_ddb_logout;
  5322. }
  5323. if (fnode_sess->is_boot_target) {
  5324. ql4_printk(KERN_ERR, ha,
  5325. "%s: Logout from boot target entry is not permitted.\n",
  5326. __func__);
  5327. ret = -EPERM;
  5328. goto exit_ddb_logout;
  5329. }
  5330. strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
  5331. ISCSI_NAME_SIZE);
  5332. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5333. sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
  5334. else
  5335. sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
  5336. flash_tddb->tpgt = fnode_sess->tpgt;
  5337. flash_tddb->port = fnode_conn->port;
  5338. COPY_ISID(flash_tddb->isid, fnode_sess->isid);
  5339. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  5340. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  5341. if (ddb_entry == NULL)
  5342. continue;
  5343. if (ddb_entry->ddb_type != FLASH_DDB)
  5344. continue;
  5345. index = ddb_entry->sess->target_id;
  5346. status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
  5347. fw_ddb_dma, NULL, &next_idx,
  5348. &state, &conn_err, NULL,
  5349. &conn_id);
  5350. if (status == QLA_ERROR) {
  5351. ret = -ENOMEM;
  5352. break;
  5353. }
  5354. qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
  5355. status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
  5356. true);
  5357. if (status == QLA_SUCCESS) {
  5358. ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
  5359. break;
  5360. }
  5361. }
  5362. if (idx == MAX_DDB_ENTRIES)
  5363. ret = -ESRCH;
  5364. exit_ddb_logout:
  5365. if (flash_tddb)
  5366. vfree(flash_tddb);
  5367. if (tmp_tddb)
  5368. vfree(tmp_tddb);
  5369. if (fw_ddb_entry)
  5370. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  5371. return ret;
  5372. }
  5373. static int
  5374. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  5375. int param, char *buf)
  5376. {
  5377. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5378. struct scsi_qla_host *ha = to_qla_host(shost);
  5379. struct iscsi_bus_flash_conn *fnode_conn;
  5380. struct ql4_chap_table chap_tbl;
  5381. struct device *dev;
  5382. int parent_type, parent_index = 0xffff;
  5383. int rc = 0;
  5384. dev = iscsi_find_flashnode_conn(fnode_sess);
  5385. if (!dev)
  5386. return -EIO;
  5387. fnode_conn = iscsi_dev_to_flash_conn(dev);
  5388. switch (param) {
  5389. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5390. rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
  5391. break;
  5392. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5393. rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
  5394. break;
  5395. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5396. rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
  5397. break;
  5398. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5399. rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
  5400. break;
  5401. case ISCSI_FLASHNODE_ENTRY_EN:
  5402. rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
  5403. break;
  5404. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5405. rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
  5406. break;
  5407. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5408. rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
  5409. break;
  5410. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5411. rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
  5412. break;
  5413. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5414. rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
  5415. break;
  5416. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5417. rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
  5418. break;
  5419. case ISCSI_FLASHNODE_PDU_INORDER:
  5420. rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
  5421. break;
  5422. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5423. rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
  5424. break;
  5425. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5426. rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
  5427. break;
  5428. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5429. rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
  5430. break;
  5431. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5432. rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
  5433. break;
  5434. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5435. rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
  5436. break;
  5437. case ISCSI_FLASHNODE_ERL:
  5438. rc = sprintf(buf, "%u\n", fnode_sess->erl);
  5439. break;
  5440. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5441. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
  5442. break;
  5443. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5444. rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
  5445. break;
  5446. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5447. rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
  5448. break;
  5449. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5450. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
  5451. break;
  5452. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5453. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
  5454. break;
  5455. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5456. rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
  5457. break;
  5458. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5459. rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
  5460. break;
  5461. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5462. rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
  5463. break;
  5464. case ISCSI_FLASHNODE_FIRST_BURST:
  5465. rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
  5466. break;
  5467. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5468. rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
  5469. break;
  5470. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5471. rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
  5472. break;
  5473. case ISCSI_FLASHNODE_MAX_R2T:
  5474. rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
  5475. break;
  5476. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5477. rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
  5478. break;
  5479. case ISCSI_FLASHNODE_ISID:
  5480. rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
  5481. fnode_sess->isid[0], fnode_sess->isid[1],
  5482. fnode_sess->isid[2], fnode_sess->isid[3],
  5483. fnode_sess->isid[4], fnode_sess->isid[5]);
  5484. break;
  5485. case ISCSI_FLASHNODE_TSID:
  5486. rc = sprintf(buf, "%u\n", fnode_sess->tsid);
  5487. break;
  5488. case ISCSI_FLASHNODE_PORT:
  5489. rc = sprintf(buf, "%d\n", fnode_conn->port);
  5490. break;
  5491. case ISCSI_FLASHNODE_MAX_BURST:
  5492. rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
  5493. break;
  5494. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5495. rc = sprintf(buf, "%u\n",
  5496. fnode_sess->default_taskmgmt_timeout);
  5497. break;
  5498. case ISCSI_FLASHNODE_IPADDR:
  5499. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5500. rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
  5501. else
  5502. rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
  5503. break;
  5504. case ISCSI_FLASHNODE_ALIAS:
  5505. if (fnode_sess->targetalias)
  5506. rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
  5507. else
  5508. rc = sprintf(buf, "\n");
  5509. break;
  5510. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5511. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5512. rc = sprintf(buf, "%pI6\n",
  5513. fnode_conn->redirect_ipaddr);
  5514. else
  5515. rc = sprintf(buf, "%pI4\n",
  5516. fnode_conn->redirect_ipaddr);
  5517. break;
  5518. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5519. rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
  5520. break;
  5521. case ISCSI_FLASHNODE_LOCAL_PORT:
  5522. rc = sprintf(buf, "%u\n", fnode_conn->local_port);
  5523. break;
  5524. case ISCSI_FLASHNODE_IPV4_TOS:
  5525. rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
  5526. break;
  5527. case ISCSI_FLASHNODE_IPV6_TC:
  5528. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5529. rc = sprintf(buf, "%u\n",
  5530. fnode_conn->ipv6_traffic_class);
  5531. else
  5532. rc = sprintf(buf, "\n");
  5533. break;
  5534. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5535. rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
  5536. break;
  5537. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5538. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5539. rc = sprintf(buf, "%pI6\n",
  5540. fnode_conn->link_local_ipv6_addr);
  5541. else
  5542. rc = sprintf(buf, "\n");
  5543. break;
  5544. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  5545. if (fnode_sess->discovery_parent_idx < MAX_DDB_ENTRIES)
  5546. parent_index = fnode_sess->discovery_parent_idx;
  5547. rc = sprintf(buf, "%u\n", parent_index);
  5548. break;
  5549. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  5550. if (fnode_sess->discovery_parent_type == DDB_ISNS)
  5551. parent_type = ISCSI_DISC_PARENT_ISNS;
  5552. else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
  5553. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5554. else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
  5555. parent_type = ISCSI_DISC_PARENT_SENDTGT;
  5556. else
  5557. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5558. rc = sprintf(buf, "%s\n",
  5559. iscsi_get_discovery_parent_name(parent_type));
  5560. break;
  5561. case ISCSI_FLASHNODE_NAME:
  5562. if (fnode_sess->targetname)
  5563. rc = sprintf(buf, "%s\n", fnode_sess->targetname);
  5564. else
  5565. rc = sprintf(buf, "\n");
  5566. break;
  5567. case ISCSI_FLASHNODE_TPGT:
  5568. rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
  5569. break;
  5570. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5571. rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
  5572. break;
  5573. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5574. rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
  5575. break;
  5576. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  5577. rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
  5578. break;
  5579. case ISCSI_FLASHNODE_USERNAME:
  5580. if (fnode_sess->chap_auth_en) {
  5581. qla4xxx_get_uni_chap_at_index(ha,
  5582. chap_tbl.name,
  5583. chap_tbl.secret,
  5584. fnode_sess->chap_out_idx);
  5585. rc = sprintf(buf, "%s\n", chap_tbl.name);
  5586. } else {
  5587. rc = sprintf(buf, "\n");
  5588. }
  5589. break;
  5590. case ISCSI_FLASHNODE_PASSWORD:
  5591. if (fnode_sess->chap_auth_en) {
  5592. qla4xxx_get_uni_chap_at_index(ha,
  5593. chap_tbl.name,
  5594. chap_tbl.secret,
  5595. fnode_sess->chap_out_idx);
  5596. rc = sprintf(buf, "%s\n", chap_tbl.secret);
  5597. } else {
  5598. rc = sprintf(buf, "\n");
  5599. }
  5600. break;
  5601. case ISCSI_FLASHNODE_STATSN:
  5602. rc = sprintf(buf, "%u\n", fnode_conn->statsn);
  5603. break;
  5604. case ISCSI_FLASHNODE_EXP_STATSN:
  5605. rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
  5606. break;
  5607. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  5608. rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
  5609. break;
  5610. default:
  5611. rc = -ENOSYS;
  5612. break;
  5613. }
  5614. put_device(dev);
  5615. return rc;
  5616. }
  5617. /**
  5618. * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
  5619. * @fnode_sess: pointer to session attrs of flash ddb entry
  5620. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5621. * @data: Parameters and their values to update
  5622. * @len: len of data
  5623. *
  5624. * This sets the parameter of flash ddb entry and writes them to flash
  5625. **/
  5626. static int
  5627. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  5628. struct iscsi_bus_flash_conn *fnode_conn,
  5629. void *data, int len)
  5630. {
  5631. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5632. struct scsi_qla_host *ha = to_qla_host(shost);
  5633. struct iscsi_flashnode_param_info *fnode_param;
  5634. struct nlattr *attr;
  5635. int rc = QLA_ERROR;
  5636. uint32_t rem = len;
  5637. nla_for_each_attr(attr, data, len, rem) {
  5638. fnode_param = nla_data(attr);
  5639. switch (fnode_param->param) {
  5640. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5641. fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
  5642. break;
  5643. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5644. memcpy(fnode_sess->portal_type, fnode_param->value,
  5645. strlen(fnode_sess->portal_type));
  5646. break;
  5647. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5648. fnode_sess->auto_snd_tgt_disable =
  5649. fnode_param->value[0];
  5650. break;
  5651. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5652. fnode_sess->discovery_sess = fnode_param->value[0];
  5653. break;
  5654. case ISCSI_FLASHNODE_ENTRY_EN:
  5655. fnode_sess->entry_state = fnode_param->value[0];
  5656. break;
  5657. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5658. fnode_conn->hdrdgst_en = fnode_param->value[0];
  5659. break;
  5660. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5661. fnode_conn->datadgst_en = fnode_param->value[0];
  5662. break;
  5663. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5664. fnode_sess->imm_data_en = fnode_param->value[0];
  5665. break;
  5666. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5667. fnode_sess->initial_r2t_en = fnode_param->value[0];
  5668. break;
  5669. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5670. fnode_sess->dataseq_inorder_en = fnode_param->value[0];
  5671. break;
  5672. case ISCSI_FLASHNODE_PDU_INORDER:
  5673. fnode_sess->pdu_inorder_en = fnode_param->value[0];
  5674. break;
  5675. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5676. fnode_sess->chap_auth_en = fnode_param->value[0];
  5677. break;
  5678. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5679. fnode_conn->snack_req_en = fnode_param->value[0];
  5680. break;
  5681. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5682. fnode_sess->discovery_logout_en = fnode_param->value[0];
  5683. break;
  5684. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5685. fnode_sess->bidi_chap_en = fnode_param->value[0];
  5686. break;
  5687. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5688. fnode_sess->discovery_auth_optional =
  5689. fnode_param->value[0];
  5690. break;
  5691. case ISCSI_FLASHNODE_ERL:
  5692. fnode_sess->erl = fnode_param->value[0];
  5693. break;
  5694. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5695. fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
  5696. break;
  5697. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5698. fnode_conn->tcp_nagle_disable = fnode_param->value[0];
  5699. break;
  5700. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5701. fnode_conn->tcp_wsf_disable = fnode_param->value[0];
  5702. break;
  5703. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5704. fnode_conn->tcp_timer_scale = fnode_param->value[0];
  5705. break;
  5706. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5707. fnode_conn->tcp_timestamp_en = fnode_param->value[0];
  5708. break;
  5709. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5710. fnode_conn->fragment_disable = fnode_param->value[0];
  5711. break;
  5712. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5713. fnode_conn->max_recv_dlength =
  5714. *(unsigned *)fnode_param->value;
  5715. break;
  5716. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5717. fnode_conn->max_xmit_dlength =
  5718. *(unsigned *)fnode_param->value;
  5719. break;
  5720. case ISCSI_FLASHNODE_FIRST_BURST:
  5721. fnode_sess->first_burst =
  5722. *(unsigned *)fnode_param->value;
  5723. break;
  5724. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5725. fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
  5726. break;
  5727. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5728. fnode_sess->time2retain =
  5729. *(uint16_t *)fnode_param->value;
  5730. break;
  5731. case ISCSI_FLASHNODE_MAX_R2T:
  5732. fnode_sess->max_r2t =
  5733. *(uint16_t *)fnode_param->value;
  5734. break;
  5735. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5736. fnode_conn->keepalive_timeout =
  5737. *(uint16_t *)fnode_param->value;
  5738. break;
  5739. case ISCSI_FLASHNODE_ISID:
  5740. memcpy(fnode_sess->isid, fnode_param->value,
  5741. sizeof(fnode_sess->isid));
  5742. break;
  5743. case ISCSI_FLASHNODE_TSID:
  5744. fnode_sess->tsid = *(uint16_t *)fnode_param->value;
  5745. break;
  5746. case ISCSI_FLASHNODE_PORT:
  5747. fnode_conn->port = *(uint16_t *)fnode_param->value;
  5748. break;
  5749. case ISCSI_FLASHNODE_MAX_BURST:
  5750. fnode_sess->max_burst = *(unsigned *)fnode_param->value;
  5751. break;
  5752. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5753. fnode_sess->default_taskmgmt_timeout =
  5754. *(uint16_t *)fnode_param->value;
  5755. break;
  5756. case ISCSI_FLASHNODE_IPADDR:
  5757. memcpy(fnode_conn->ipaddress, fnode_param->value,
  5758. IPv6_ADDR_LEN);
  5759. break;
  5760. case ISCSI_FLASHNODE_ALIAS:
  5761. rc = iscsi_switch_str_param(&fnode_sess->targetalias,
  5762. (char *)fnode_param->value);
  5763. break;
  5764. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5765. memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
  5766. IPv6_ADDR_LEN);
  5767. break;
  5768. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5769. fnode_conn->max_segment_size =
  5770. *(unsigned *)fnode_param->value;
  5771. break;
  5772. case ISCSI_FLASHNODE_LOCAL_PORT:
  5773. fnode_conn->local_port =
  5774. *(uint16_t *)fnode_param->value;
  5775. break;
  5776. case ISCSI_FLASHNODE_IPV4_TOS:
  5777. fnode_conn->ipv4_tos = fnode_param->value[0];
  5778. break;
  5779. case ISCSI_FLASHNODE_IPV6_TC:
  5780. fnode_conn->ipv6_traffic_class = fnode_param->value[0];
  5781. break;
  5782. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5783. fnode_conn->ipv6_flow_label = fnode_param->value[0];
  5784. break;
  5785. case ISCSI_FLASHNODE_NAME:
  5786. rc = iscsi_switch_str_param(&fnode_sess->targetname,
  5787. (char *)fnode_param->value);
  5788. break;
  5789. case ISCSI_FLASHNODE_TPGT:
  5790. fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
  5791. break;
  5792. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5793. memcpy(fnode_conn->link_local_ipv6_addr,
  5794. fnode_param->value, IPv6_ADDR_LEN);
  5795. break;
  5796. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  5797. fnode_sess->discovery_parent_idx =
  5798. *(uint16_t *)fnode_param->value;
  5799. break;
  5800. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5801. fnode_conn->tcp_xmit_wsf =
  5802. *(uint8_t *)fnode_param->value;
  5803. break;
  5804. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5805. fnode_conn->tcp_recv_wsf =
  5806. *(uint8_t *)fnode_param->value;
  5807. break;
  5808. case ISCSI_FLASHNODE_STATSN:
  5809. fnode_conn->statsn = *(uint32_t *)fnode_param->value;
  5810. break;
  5811. case ISCSI_FLASHNODE_EXP_STATSN:
  5812. fnode_conn->exp_statsn =
  5813. *(uint32_t *)fnode_param->value;
  5814. break;
  5815. default:
  5816. ql4_printk(KERN_ERR, ha,
  5817. "%s: No such sysfs attribute\n", __func__);
  5818. rc = -ENOSYS;
  5819. goto exit_set_param;
  5820. }
  5821. }
  5822. rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
  5823. exit_set_param:
  5824. return rc;
  5825. }
  5826. /**
  5827. * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
  5828. * @fnode_sess: pointer to session attrs of flash ddb entry
  5829. *
  5830. * This invalidates the flash ddb entry at the given index
  5831. **/
  5832. static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
  5833. {
  5834. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5835. struct scsi_qla_host *ha = to_qla_host(shost);
  5836. uint32_t dev_db_start_offset;
  5837. uint32_t dev_db_end_offset;
  5838. struct dev_db_entry *fw_ddb_entry = NULL;
  5839. dma_addr_t fw_ddb_entry_dma;
  5840. uint16_t *ddb_cookie = NULL;
  5841. size_t ddb_size = 0;
  5842. void *pddb = NULL;
  5843. int target_id;
  5844. int rc = 0;
  5845. if (fnode_sess->is_boot_target) {
  5846. rc = -EPERM;
  5847. DEBUG2(ql4_printk(KERN_ERR, ha,
  5848. "%s: Deletion of boot target entry is not permitted.\n",
  5849. __func__));
  5850. goto exit_ddb_del;
  5851. }
  5852. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
  5853. goto sysfs_ddb_del;
  5854. if (is_qla40XX(ha)) {
  5855. dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  5856. dev_db_end_offset = FLASH_OFFSET_DB_END;
  5857. dev_db_start_offset += (fnode_sess->target_id *
  5858. sizeof(*fw_ddb_entry));
  5859. ddb_size = sizeof(*fw_ddb_entry);
  5860. } else {
  5861. dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
  5862. (ha->hw.flt_region_ddb << 2);
  5863. /* flt_ddb_size is DDB table size for both ports
  5864. * so divide it by 2 to calculate the offset for second port
  5865. */
  5866. if (ha->port_num == 1)
  5867. dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
  5868. dev_db_end_offset = dev_db_start_offset +
  5869. (ha->hw.flt_ddb_size / 2);
  5870. dev_db_start_offset += (fnode_sess->target_id *
  5871. sizeof(*fw_ddb_entry));
  5872. dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
  5873. ddb_size = sizeof(*ddb_cookie);
  5874. }
  5875. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
  5876. __func__, dev_db_start_offset, dev_db_end_offset));
  5877. if (dev_db_start_offset > dev_db_end_offset) {
  5878. rc = -EIO;
  5879. DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
  5880. __func__, fnode_sess->target_id));
  5881. goto exit_ddb_del;
  5882. }
  5883. pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
  5884. &fw_ddb_entry_dma, GFP_KERNEL);
  5885. if (!pddb) {
  5886. rc = -ENOMEM;
  5887. DEBUG2(ql4_printk(KERN_ERR, ha,
  5888. "%s: Unable to allocate dma buffer\n",
  5889. __func__));
  5890. goto exit_ddb_del;
  5891. }
  5892. if (is_qla40XX(ha)) {
  5893. fw_ddb_entry = pddb;
  5894. memset(fw_ddb_entry, 0, ddb_size);
  5895. ddb_cookie = &fw_ddb_entry->cookie;
  5896. } else {
  5897. ddb_cookie = pddb;
  5898. }
  5899. /* invalidate the cookie */
  5900. *ddb_cookie = 0xFFEE;
  5901. qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  5902. ddb_size, FLASH_OPT_RMW_COMMIT);
  5903. sysfs_ddb_del:
  5904. target_id = fnode_sess->target_id;
  5905. iscsi_destroy_flashnode_sess(fnode_sess);
  5906. ql4_printk(KERN_INFO, ha,
  5907. "%s: session and conn entries for flashnode %u of host %lu deleted\n",
  5908. __func__, target_id, ha->host_no);
  5909. exit_ddb_del:
  5910. if (pddb)
  5911. dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
  5912. fw_ddb_entry_dma);
  5913. return rc;
  5914. }
  5915. /**
  5916. * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
  5917. * @ha: pointer to adapter structure
  5918. *
  5919. * Export the firmware DDB for all send targets and normal targets to sysfs.
  5920. **/
  5921. static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
  5922. {
  5923. struct dev_db_entry *fw_ddb_entry = NULL;
  5924. dma_addr_t fw_ddb_entry_dma;
  5925. uint16_t max_ddbs;
  5926. uint16_t idx = 0;
  5927. int ret = QLA_SUCCESS;
  5928. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  5929. sizeof(*fw_ddb_entry),
  5930. &fw_ddb_entry_dma, GFP_KERNEL);
  5931. if (!fw_ddb_entry) {
  5932. DEBUG2(ql4_printk(KERN_ERR, ha,
  5933. "%s: Unable to allocate dma buffer\n",
  5934. __func__));
  5935. return -ENOMEM;
  5936. }
  5937. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  5938. MAX_DEV_DB_ENTRIES;
  5939. for (idx = 0; idx < max_ddbs; idx++) {
  5940. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
  5941. idx))
  5942. continue;
  5943. ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
  5944. if (ret) {
  5945. ret = -EIO;
  5946. break;
  5947. }
  5948. }
  5949. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
  5950. fw_ddb_entry_dma);
  5951. return ret;
  5952. }
  5953. static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
  5954. {
  5955. iscsi_destroy_all_flashnode(ha->host);
  5956. }
  5957. /**
  5958. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  5959. * @ha: pointer to adapter structure
  5960. * @is_reset: Is this init path or reset path
  5961. *
  5962. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  5963. * using connection open, then create the list of normal targets (nt)
  5964. * from firmware DDBs. Based on the list of nt setup session and connection
  5965. * objects.
  5966. **/
  5967. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  5968. {
  5969. uint16_t tmo = 0;
  5970. struct list_head list_st, list_nt;
  5971. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  5972. unsigned long wtime;
  5973. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  5974. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  5975. ha->is_reset = is_reset;
  5976. return;
  5977. }
  5978. INIT_LIST_HEAD(&list_st);
  5979. INIT_LIST_HEAD(&list_nt);
  5980. qla4xxx_build_st_list(ha, &list_st);
  5981. /* Before issuing conn open mbox, ensure all IPs states are configured
  5982. * Note, conn open fails if IPs are not configured
  5983. */
  5984. qla4xxx_wait_for_ip_configuration(ha);
  5985. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  5986. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  5987. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  5988. }
  5989. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  5990. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  5991. (ha->def_timeout < LOGIN_TOV * 10) ?
  5992. ha->def_timeout : LOGIN_TOV);
  5993. DEBUG2(ql4_printk(KERN_INFO, ha,
  5994. "Default time to wait for build ddb %d\n", tmo));
  5995. wtime = jiffies + (HZ * tmo);
  5996. do {
  5997. if (list_empty(&list_st))
  5998. break;
  5999. qla4xxx_remove_failed_ddb(ha, &list_st);
  6000. schedule_timeout_uninterruptible(HZ / 10);
  6001. } while (time_after(wtime, jiffies));
  6002. /* Free up the sendtargets list */
  6003. qla4xxx_free_ddb_list(&list_st);
  6004. qla4xxx_build_nt_list(ha, &list_nt, is_reset);
  6005. qla4xxx_free_ddb_list(&list_nt);
  6006. qla4xxx_free_ddb_index(ha);
  6007. }
  6008. /**
  6009. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  6010. * response.
  6011. * @ha: pointer to adapter structure
  6012. *
  6013. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  6014. * set in DDB and we will wait for login response of boot targets during
  6015. * probe.
  6016. **/
  6017. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  6018. {
  6019. struct ddb_entry *ddb_entry;
  6020. struct dev_db_entry *fw_ddb_entry = NULL;
  6021. dma_addr_t fw_ddb_entry_dma;
  6022. unsigned long wtime;
  6023. uint32_t ddb_state;
  6024. int max_ddbs, idx, ret;
  6025. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6026. MAX_DEV_DB_ENTRIES;
  6027. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6028. &fw_ddb_entry_dma, GFP_KERNEL);
  6029. if (!fw_ddb_entry) {
  6030. ql4_printk(KERN_ERR, ha,
  6031. "%s: Unable to allocate dma buffer\n", __func__);
  6032. goto exit_login_resp;
  6033. }
  6034. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  6035. for (idx = 0; idx < max_ddbs; idx++) {
  6036. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6037. if (ddb_entry == NULL)
  6038. continue;
  6039. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  6040. DEBUG2(ql4_printk(KERN_INFO, ha,
  6041. "%s: DDB index [%d]\n", __func__,
  6042. ddb_entry->fw_ddb_index));
  6043. do {
  6044. ret = qla4xxx_get_fwddb_entry(ha,
  6045. ddb_entry->fw_ddb_index,
  6046. fw_ddb_entry, fw_ddb_entry_dma,
  6047. NULL, NULL, &ddb_state, NULL,
  6048. NULL, NULL);
  6049. if (ret == QLA_ERROR)
  6050. goto exit_login_resp;
  6051. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  6052. (ddb_state == DDB_DS_SESSION_FAILED))
  6053. break;
  6054. schedule_timeout_uninterruptible(HZ);
  6055. } while ((time_after(wtime, jiffies)));
  6056. if (!time_after(wtime, jiffies)) {
  6057. DEBUG2(ql4_printk(KERN_INFO, ha,
  6058. "%s: Login response wait timer expired\n",
  6059. __func__));
  6060. goto exit_login_resp;
  6061. }
  6062. }
  6063. }
  6064. exit_login_resp:
  6065. if (fw_ddb_entry)
  6066. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6067. fw_ddb_entry, fw_ddb_entry_dma);
  6068. }
  6069. /**
  6070. * qla4xxx_probe_adapter - callback function to probe HBA
  6071. * @pdev: pointer to pci_dev structure
  6072. * @pci_device_id: pointer to pci_device entry
  6073. *
  6074. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  6075. * It returns zero if successful. It also initializes all data necessary for
  6076. * the driver.
  6077. **/
  6078. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  6079. const struct pci_device_id *ent)
  6080. {
  6081. int ret = -ENODEV, status;
  6082. struct Scsi_Host *host;
  6083. struct scsi_qla_host *ha;
  6084. uint8_t init_retry_count = 0;
  6085. char buf[34];
  6086. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  6087. uint32_t dev_state;
  6088. if (pci_enable_device(pdev))
  6089. return -1;
  6090. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  6091. if (host == NULL) {
  6092. printk(KERN_WARNING
  6093. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  6094. goto probe_disable_device;
  6095. }
  6096. /* Clear our data area */
  6097. ha = to_qla_host(host);
  6098. memset(ha, 0, sizeof(*ha));
  6099. /* Save the information from PCI BIOS. */
  6100. ha->pdev = pdev;
  6101. ha->host = host;
  6102. ha->host_no = host->host_no;
  6103. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  6104. pci_enable_pcie_error_reporting(pdev);
  6105. /* Setup Runtime configurable options */
  6106. if (is_qla8022(ha)) {
  6107. ha->isp_ops = &qla4_82xx_isp_ops;
  6108. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  6109. ha->qdr_sn_window = -1;
  6110. ha->ddr_mn_window = -1;
  6111. ha->curr_window = 255;
  6112. nx_legacy_intr = &legacy_intr[ha->func_num];
  6113. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  6114. ha->nx_legacy_intr.tgt_status_reg =
  6115. nx_legacy_intr->tgt_status_reg;
  6116. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  6117. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  6118. } else if (is_qla8032(ha)) {
  6119. ha->isp_ops = &qla4_83xx_isp_ops;
  6120. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  6121. } else {
  6122. ha->isp_ops = &qla4xxx_isp_ops;
  6123. }
  6124. if (is_qla80XX(ha)) {
  6125. rwlock_init(&ha->hw_lock);
  6126. ha->pf_bit = ha->func_num << 16;
  6127. /* Set EEH reset type to fundamental if required by hba */
  6128. pdev->needs_freset = 1;
  6129. }
  6130. /* Configure PCI I/O space. */
  6131. ret = ha->isp_ops->iospace_config(ha);
  6132. if (ret)
  6133. goto probe_failed_ioconfig;
  6134. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  6135. pdev->device, pdev->irq, ha->reg);
  6136. qla4xxx_config_dma_addressing(ha);
  6137. /* Initialize lists and spinlocks. */
  6138. INIT_LIST_HEAD(&ha->free_srb_q);
  6139. mutex_init(&ha->mbox_sem);
  6140. mutex_init(&ha->chap_sem);
  6141. init_completion(&ha->mbx_intr_comp);
  6142. init_completion(&ha->disable_acb_comp);
  6143. spin_lock_init(&ha->hardware_lock);
  6144. spin_lock_init(&ha->work_lock);
  6145. /* Initialize work list */
  6146. INIT_LIST_HEAD(&ha->work_list);
  6147. /* Allocate dma buffers */
  6148. if (qla4xxx_mem_alloc(ha)) {
  6149. ql4_printk(KERN_WARNING, ha,
  6150. "[ERROR] Failed to allocate memory for adapter\n");
  6151. ret = -ENOMEM;
  6152. goto probe_failed;
  6153. }
  6154. host->cmd_per_lun = 3;
  6155. host->max_channel = 0;
  6156. host->max_lun = MAX_LUNS - 1;
  6157. host->max_id = MAX_TARGETS;
  6158. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  6159. host->can_queue = MAX_SRBS ;
  6160. host->transportt = qla4xxx_scsi_transport;
  6161. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  6162. if (ret) {
  6163. ql4_printk(KERN_WARNING, ha,
  6164. "%s: scsi_init_shared_tag_map failed\n", __func__);
  6165. goto probe_failed;
  6166. }
  6167. pci_set_drvdata(pdev, ha);
  6168. ret = scsi_add_host(host, &pdev->dev);
  6169. if (ret)
  6170. goto probe_failed;
  6171. if (is_qla80XX(ha))
  6172. qla4_8xxx_get_flash_info(ha);
  6173. if (is_qla8032(ha)) {
  6174. qla4_83xx_read_reset_template(ha);
  6175. /*
  6176. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  6177. * If DONRESET_BIT0 is set, drivers should not set dev_state
  6178. * to NEED_RESET. But if NEED_RESET is set, drivers should
  6179. * should honor the reset.
  6180. */
  6181. if (ql4xdontresethba == 1)
  6182. qla4_83xx_set_idc_dontreset(ha);
  6183. }
  6184. /*
  6185. * Initialize the Host adapter request/response queues and
  6186. * firmware
  6187. * NOTE: interrupts enabled upon successful completion
  6188. */
  6189. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6190. /* Dont retry adapter initialization if IRQ allocation failed */
  6191. if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
  6192. ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n",
  6193. __func__);
  6194. goto skip_retry_init;
  6195. }
  6196. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  6197. init_retry_count++ < MAX_INIT_RETRIES) {
  6198. if (is_qla80XX(ha)) {
  6199. ha->isp_ops->idc_lock(ha);
  6200. dev_state = qla4_8xxx_rd_direct(ha,
  6201. QLA8XXX_CRB_DEV_STATE);
  6202. ha->isp_ops->idc_unlock(ha);
  6203. if (dev_state == QLA8XXX_DEV_FAILED) {
  6204. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  6205. "initialize adapter. H/W is in failed state\n",
  6206. __func__);
  6207. break;
  6208. }
  6209. }
  6210. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  6211. "(%d)\n", __func__, init_retry_count));
  6212. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  6213. continue;
  6214. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6215. }
  6216. skip_retry_init:
  6217. if (!test_bit(AF_ONLINE, &ha->flags)) {
  6218. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  6219. if ((is_qla8022(ha) && ql4xdontresethba) ||
  6220. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  6221. /* Put the device in failed state. */
  6222. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  6223. ha->isp_ops->idc_lock(ha);
  6224. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6225. QLA8XXX_DEV_FAILED);
  6226. ha->isp_ops->idc_unlock(ha);
  6227. }
  6228. ret = -ENODEV;
  6229. goto remove_host;
  6230. }
  6231. /* Startup the kernel thread for this host adapter. */
  6232. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  6233. "qla4xxx_dpc\n", __func__));
  6234. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  6235. ha->dpc_thread = create_singlethread_workqueue(buf);
  6236. if (!ha->dpc_thread) {
  6237. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  6238. ret = -ENODEV;
  6239. goto remove_host;
  6240. }
  6241. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  6242. ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
  6243. ha->host_no);
  6244. if (!ha->task_wq) {
  6245. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  6246. ret = -ENODEV;
  6247. goto remove_host;
  6248. }
  6249. /*
  6250. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  6251. * (which is called indirectly by qla4xxx_initialize_adapter),
  6252. * so that irqs will be registered after crbinit but before
  6253. * mbx_intr_enable.
  6254. */
  6255. if (is_qla40XX(ha)) {
  6256. ret = qla4xxx_request_irqs(ha);
  6257. if (ret) {
  6258. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  6259. "interrupt %d already in use.\n", pdev->irq);
  6260. goto remove_host;
  6261. }
  6262. }
  6263. pci_save_state(ha->pdev);
  6264. ha->isp_ops->enable_intrs(ha);
  6265. /* Start timer thread. */
  6266. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  6267. set_bit(AF_INIT_DONE, &ha->flags);
  6268. qla4_8xxx_alloc_sysfs_attr(ha);
  6269. printk(KERN_INFO
  6270. " QLogic iSCSI HBA Driver version: %s\n"
  6271. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  6272. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  6273. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  6274. ha->patch_number, ha->build_number);
  6275. /* Set the driver version */
  6276. if (is_qla80XX(ha))
  6277. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  6278. if (qla4xxx_setup_boot_info(ha))
  6279. ql4_printk(KERN_ERR, ha,
  6280. "%s: No iSCSI boot target configured\n", __func__);
  6281. if (qla4xxx_sysfs_ddb_export(ha))
  6282. ql4_printk(KERN_ERR, ha,
  6283. "%s: Error exporting ddb to sysfs\n", __func__);
  6284. /* Perform the build ddb list and login to each */
  6285. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  6286. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  6287. qla4xxx_wait_login_resp_boot_tgt(ha);
  6288. qla4xxx_create_chap_list(ha);
  6289. qla4xxx_create_ifaces(ha);
  6290. return 0;
  6291. remove_host:
  6292. scsi_remove_host(ha->host);
  6293. probe_failed:
  6294. qla4xxx_free_adapter(ha);
  6295. probe_failed_ioconfig:
  6296. pci_disable_pcie_error_reporting(pdev);
  6297. scsi_host_put(ha->host);
  6298. probe_disable_device:
  6299. pci_disable_device(pdev);
  6300. return ret;
  6301. }
  6302. /**
  6303. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  6304. * @ha: pointer to adapter structure
  6305. *
  6306. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  6307. * so that the other port will not re-initialize while in the process of
  6308. * removing the ha due to driver unload or hba hotplug.
  6309. **/
  6310. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  6311. {
  6312. struct scsi_qla_host *other_ha = NULL;
  6313. struct pci_dev *other_pdev = NULL;
  6314. int fn = ISP4XXX_PCI_FN_2;
  6315. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  6316. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  6317. fn = ISP4XXX_PCI_FN_1;
  6318. other_pdev =
  6319. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  6320. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  6321. fn));
  6322. /* Get other_ha if other_pdev is valid and state is enable*/
  6323. if (other_pdev) {
  6324. if (atomic_read(&other_pdev->enable_cnt)) {
  6325. other_ha = pci_get_drvdata(other_pdev);
  6326. if (other_ha) {
  6327. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  6328. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  6329. "Prevent %s reinit\n", __func__,
  6330. dev_name(&other_ha->pdev->dev)));
  6331. }
  6332. }
  6333. pci_dev_put(other_pdev);
  6334. }
  6335. }
  6336. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  6337. {
  6338. struct ddb_entry *ddb_entry;
  6339. int options;
  6340. int idx;
  6341. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  6342. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6343. if ((ddb_entry != NULL) &&
  6344. (ddb_entry->ddb_type == FLASH_DDB)) {
  6345. options = LOGOUT_OPTION_CLOSE_SESSION;
  6346. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
  6347. == QLA_ERROR)
  6348. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
  6349. __func__);
  6350. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  6351. /*
  6352. * we have decremented the reference count of the driver
  6353. * when we setup the session to have the driver unload
  6354. * to be seamless without actually destroying the
  6355. * session
  6356. **/
  6357. try_module_get(qla4xxx_iscsi_transport.owner);
  6358. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  6359. qla4xxx_free_ddb(ha, ddb_entry);
  6360. iscsi_session_teardown(ddb_entry->sess);
  6361. }
  6362. }
  6363. }
  6364. /**
  6365. * qla4xxx_remove_adapter - callback function to remove adapter.
  6366. * @pci_dev: PCI device pointer
  6367. **/
  6368. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  6369. {
  6370. struct scsi_qla_host *ha;
  6371. /*
  6372. * If the PCI device is disabled then it means probe_adapter had
  6373. * failed and resources already cleaned up on probe_adapter exit.
  6374. */
  6375. if (!pci_is_enabled(pdev))
  6376. return;
  6377. ha = pci_get_drvdata(pdev);
  6378. if (is_qla40XX(ha))
  6379. qla4xxx_prevent_other_port_reinit(ha);
  6380. /* destroy iface from sysfs */
  6381. qla4xxx_destroy_ifaces(ha);
  6382. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  6383. iscsi_boot_destroy_kset(ha->boot_kset);
  6384. qla4xxx_destroy_fw_ddb_session(ha);
  6385. qla4_8xxx_free_sysfs_attr(ha);
  6386. qla4xxx_sysfs_ddb_remove(ha);
  6387. scsi_remove_host(ha->host);
  6388. qla4xxx_free_adapter(ha);
  6389. scsi_host_put(ha->host);
  6390. pci_disable_pcie_error_reporting(pdev);
  6391. pci_disable_device(pdev);
  6392. pci_set_drvdata(pdev, NULL);
  6393. }
  6394. /**
  6395. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  6396. * @ha: HA context
  6397. *
  6398. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  6399. * supported addressing method.
  6400. */
  6401. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  6402. {
  6403. int retval;
  6404. /* Update our PCI device dma_mask for full 64 bit mask */
  6405. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  6406. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  6407. dev_dbg(&ha->pdev->dev,
  6408. "Failed to set 64 bit PCI consistent mask; "
  6409. "using 32 bit.\n");
  6410. retval = pci_set_consistent_dma_mask(ha->pdev,
  6411. DMA_BIT_MASK(32));
  6412. }
  6413. } else
  6414. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  6415. }
  6416. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  6417. {
  6418. struct iscsi_cls_session *cls_sess;
  6419. struct iscsi_session *sess;
  6420. struct ddb_entry *ddb;
  6421. int queue_depth = QL4_DEF_QDEPTH;
  6422. cls_sess = starget_to_session(sdev->sdev_target);
  6423. sess = cls_sess->dd_data;
  6424. ddb = sess->dd_data;
  6425. sdev->hostdata = ddb;
  6426. sdev->tagged_supported = 1;
  6427. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  6428. queue_depth = ql4xmaxqdepth;
  6429. scsi_activate_tcq(sdev, queue_depth);
  6430. return 0;
  6431. }
  6432. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  6433. {
  6434. sdev->tagged_supported = 1;
  6435. return 0;
  6436. }
  6437. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  6438. {
  6439. scsi_deactivate_tcq(sdev, 1);
  6440. }
  6441. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  6442. int reason)
  6443. {
  6444. if (!ql4xqfulltracking)
  6445. return -EOPNOTSUPP;
  6446. return iscsi_change_queue_depth(sdev, qdepth, reason);
  6447. }
  6448. /**
  6449. * qla4xxx_del_from_active_array - returns an active srb
  6450. * @ha: Pointer to host adapter structure.
  6451. * @index: index into the active_array
  6452. *
  6453. * This routine removes and returns the srb at the specified index
  6454. **/
  6455. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  6456. uint32_t index)
  6457. {
  6458. struct srb *srb = NULL;
  6459. struct scsi_cmnd *cmd = NULL;
  6460. cmd = scsi_host_find_tag(ha->host, index);
  6461. if (!cmd)
  6462. return srb;
  6463. srb = (struct srb *)CMD_SP(cmd);
  6464. if (!srb)
  6465. return srb;
  6466. /* update counters */
  6467. if (srb->flags & SRB_DMA_VALID) {
  6468. ha->iocb_cnt -= srb->iocb_cnt;
  6469. if (srb->cmd)
  6470. srb->cmd->host_scribble =
  6471. (unsigned char *)(unsigned long) MAX_SRBS;
  6472. }
  6473. return srb;
  6474. }
  6475. /**
  6476. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  6477. * @ha: Pointer to host adapter structure.
  6478. * @cmd: Scsi Command to wait on.
  6479. *
  6480. * This routine waits for the command to be returned by the Firmware
  6481. * for some max time.
  6482. **/
  6483. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  6484. struct scsi_cmnd *cmd)
  6485. {
  6486. int done = 0;
  6487. struct srb *rp;
  6488. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  6489. int ret = SUCCESS;
  6490. /* Dont wait on command if PCI error is being handled
  6491. * by PCI AER driver
  6492. */
  6493. if (unlikely(pci_channel_offline(ha->pdev)) ||
  6494. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  6495. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  6496. ha->host_no, __func__);
  6497. return ret;
  6498. }
  6499. do {
  6500. /* Checking to see if its returned to OS */
  6501. rp = (struct srb *) CMD_SP(cmd);
  6502. if (rp == NULL) {
  6503. done++;
  6504. break;
  6505. }
  6506. msleep(2000);
  6507. } while (max_wait_time--);
  6508. return done;
  6509. }
  6510. /**
  6511. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  6512. * @ha: Pointer to host adapter structure
  6513. **/
  6514. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  6515. {
  6516. unsigned long wait_online;
  6517. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  6518. while (time_before(jiffies, wait_online)) {
  6519. if (adapter_up(ha))
  6520. return QLA_SUCCESS;
  6521. msleep(2000);
  6522. }
  6523. return QLA_ERROR;
  6524. }
  6525. /**
  6526. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  6527. * @ha: pointer to HBA
  6528. * @t: target id
  6529. * @l: lun id
  6530. *
  6531. * This function waits for all outstanding commands to a lun to complete. It
  6532. * returns 0 if all pending commands are returned and 1 otherwise.
  6533. **/
  6534. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  6535. struct scsi_target *stgt,
  6536. struct scsi_device *sdev)
  6537. {
  6538. int cnt;
  6539. int status = 0;
  6540. struct scsi_cmnd *cmd;
  6541. /*
  6542. * Waiting for all commands for the designated target or dev
  6543. * in the active array
  6544. */
  6545. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  6546. cmd = scsi_host_find_tag(ha->host, cnt);
  6547. if (cmd && stgt == scsi_target(cmd->device) &&
  6548. (!sdev || sdev == cmd->device)) {
  6549. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6550. status++;
  6551. break;
  6552. }
  6553. }
  6554. }
  6555. return status;
  6556. }
  6557. /**
  6558. * qla4xxx_eh_abort - callback for abort task.
  6559. * @cmd: Pointer to Linux's SCSI command structure
  6560. *
  6561. * This routine is called by the Linux OS to abort the specified
  6562. * command.
  6563. **/
  6564. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  6565. {
  6566. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6567. unsigned int id = cmd->device->id;
  6568. unsigned int lun = cmd->device->lun;
  6569. unsigned long flags;
  6570. struct srb *srb = NULL;
  6571. int ret = SUCCESS;
  6572. int wait = 0;
  6573. ql4_printk(KERN_INFO, ha,
  6574. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  6575. ha->host_no, id, lun, cmd);
  6576. spin_lock_irqsave(&ha->hardware_lock, flags);
  6577. srb = (struct srb *) CMD_SP(cmd);
  6578. if (!srb) {
  6579. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6580. return SUCCESS;
  6581. }
  6582. kref_get(&srb->srb_ref);
  6583. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6584. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  6585. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  6586. ha->host_no, id, lun));
  6587. ret = FAILED;
  6588. } else {
  6589. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  6590. ha->host_no, id, lun));
  6591. wait = 1;
  6592. }
  6593. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  6594. /* Wait for command to complete */
  6595. if (wait) {
  6596. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6597. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  6598. ha->host_no, id, lun));
  6599. ret = FAILED;
  6600. }
  6601. }
  6602. ql4_printk(KERN_INFO, ha,
  6603. "scsi%ld:%d:%d: Abort command - %s\n",
  6604. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  6605. return ret;
  6606. }
  6607. /**
  6608. * qla4xxx_eh_device_reset - callback for target reset.
  6609. * @cmd: Pointer to Linux's SCSI command structure
  6610. *
  6611. * This routine is called by the Linux OS to reset all luns on the
  6612. * specified target.
  6613. **/
  6614. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  6615. {
  6616. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6617. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6618. int ret = FAILED, stat;
  6619. if (!ddb_entry)
  6620. return ret;
  6621. ret = iscsi_block_scsi_eh(cmd);
  6622. if (ret)
  6623. return ret;
  6624. ret = FAILED;
  6625. ql4_printk(KERN_INFO, ha,
  6626. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  6627. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6628. DEBUG2(printk(KERN_INFO
  6629. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  6630. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  6631. cmd, jiffies, cmd->request->timeout / HZ,
  6632. ha->dpc_flags, cmd->result, cmd->allowed));
  6633. /* FIXME: wait for hba to go online */
  6634. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  6635. if (stat != QLA_SUCCESS) {
  6636. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  6637. goto eh_dev_reset_done;
  6638. }
  6639. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6640. cmd->device)) {
  6641. ql4_printk(KERN_INFO, ha,
  6642. "DEVICE RESET FAILED - waiting for "
  6643. "commands.\n");
  6644. goto eh_dev_reset_done;
  6645. }
  6646. /* Send marker. */
  6647. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6648. MM_LUN_RESET) != QLA_SUCCESS)
  6649. goto eh_dev_reset_done;
  6650. ql4_printk(KERN_INFO, ha,
  6651. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  6652. ha->host_no, cmd->device->channel, cmd->device->id,
  6653. cmd->device->lun);
  6654. ret = SUCCESS;
  6655. eh_dev_reset_done:
  6656. return ret;
  6657. }
  6658. /**
  6659. * qla4xxx_eh_target_reset - callback for target reset.
  6660. * @cmd: Pointer to Linux's SCSI command structure
  6661. *
  6662. * This routine is called by the Linux OS to reset the target.
  6663. **/
  6664. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  6665. {
  6666. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6667. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6668. int stat, ret;
  6669. if (!ddb_entry)
  6670. return FAILED;
  6671. ret = iscsi_block_scsi_eh(cmd);
  6672. if (ret)
  6673. return ret;
  6674. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6675. "WARM TARGET RESET ISSUED.\n");
  6676. DEBUG2(printk(KERN_INFO
  6677. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  6678. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  6679. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  6680. ha->dpc_flags, cmd->result, cmd->allowed));
  6681. stat = qla4xxx_reset_target(ha, ddb_entry);
  6682. if (stat != QLA_SUCCESS) {
  6683. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6684. "WARM TARGET RESET FAILED.\n");
  6685. return FAILED;
  6686. }
  6687. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6688. NULL)) {
  6689. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6690. "WARM TARGET DEVICE RESET FAILED - "
  6691. "waiting for commands.\n");
  6692. return FAILED;
  6693. }
  6694. /* Send marker. */
  6695. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6696. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  6697. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6698. "WARM TARGET DEVICE RESET FAILED - "
  6699. "marker iocb failed.\n");
  6700. return FAILED;
  6701. }
  6702. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6703. "WARM TARGET RESET SUCCEEDED.\n");
  6704. return SUCCESS;
  6705. }
  6706. /**
  6707. * qla4xxx_is_eh_active - check if error handler is running
  6708. * @shost: Pointer to SCSI Host struct
  6709. *
  6710. * This routine finds that if reset host is called in EH
  6711. * scenario or from some application like sg_reset
  6712. **/
  6713. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  6714. {
  6715. if (shost->shost_state == SHOST_RECOVERY)
  6716. return 1;
  6717. return 0;
  6718. }
  6719. /**
  6720. * qla4xxx_eh_host_reset - kernel callback
  6721. * @cmd: Pointer to Linux's SCSI command structure
  6722. *
  6723. * This routine is invoked by the Linux kernel to perform fatal error
  6724. * recovery on the specified adapter.
  6725. **/
  6726. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  6727. {
  6728. int return_status = FAILED;
  6729. struct scsi_qla_host *ha;
  6730. ha = to_qla_host(cmd->device->host);
  6731. if (is_qla8032(ha) && ql4xdontresethba)
  6732. qla4_83xx_set_idc_dontreset(ha);
  6733. /*
  6734. * For ISP8324, if IDC_CTRL DONTRESET_BIT0 is set by other
  6735. * protocol drivers, we should not set device_state to
  6736. * NEED_RESET
  6737. */
  6738. if (ql4xdontresethba ||
  6739. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  6740. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  6741. ha->host_no, __func__));
  6742. /* Clear outstanding srb in queues */
  6743. if (qla4xxx_is_eh_active(cmd->device->host))
  6744. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  6745. return FAILED;
  6746. }
  6747. ql4_printk(KERN_INFO, ha,
  6748. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  6749. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6750. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  6751. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  6752. "DEAD.\n", ha->host_no, cmd->device->channel,
  6753. __func__));
  6754. return FAILED;
  6755. }
  6756. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6757. if (is_qla80XX(ha))
  6758. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  6759. else
  6760. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  6761. }
  6762. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  6763. return_status = SUCCESS;
  6764. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  6765. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  6766. return return_status;
  6767. }
  6768. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  6769. {
  6770. uint32_t mbox_cmd[MBOX_REG_COUNT];
  6771. uint32_t mbox_sts[MBOX_REG_COUNT];
  6772. struct addr_ctrl_blk_def *acb = NULL;
  6773. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  6774. int rval = QLA_SUCCESS;
  6775. dma_addr_t acb_dma;
  6776. acb = dma_alloc_coherent(&ha->pdev->dev,
  6777. sizeof(struct addr_ctrl_blk_def),
  6778. &acb_dma, GFP_KERNEL);
  6779. if (!acb) {
  6780. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  6781. __func__);
  6782. rval = -ENOMEM;
  6783. goto exit_port_reset;
  6784. }
  6785. memset(acb, 0, acb_len);
  6786. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  6787. if (rval != QLA_SUCCESS) {
  6788. rval = -EIO;
  6789. goto exit_free_acb;
  6790. }
  6791. rval = qla4xxx_disable_acb(ha);
  6792. if (rval != QLA_SUCCESS) {
  6793. rval = -EIO;
  6794. goto exit_free_acb;
  6795. }
  6796. wait_for_completion_timeout(&ha->disable_acb_comp,
  6797. DISABLE_ACB_TOV * HZ);
  6798. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  6799. if (rval != QLA_SUCCESS) {
  6800. rval = -EIO;
  6801. goto exit_free_acb;
  6802. }
  6803. exit_free_acb:
  6804. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  6805. acb, acb_dma);
  6806. exit_port_reset:
  6807. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  6808. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  6809. return rval;
  6810. }
  6811. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  6812. {
  6813. struct scsi_qla_host *ha = to_qla_host(shost);
  6814. int rval = QLA_SUCCESS;
  6815. uint32_t idc_ctrl;
  6816. if (ql4xdontresethba) {
  6817. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  6818. __func__));
  6819. rval = -EPERM;
  6820. goto exit_host_reset;
  6821. }
  6822. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  6823. goto recover_adapter;
  6824. switch (reset_type) {
  6825. case SCSI_ADAPTER_RESET:
  6826. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  6827. break;
  6828. case SCSI_FIRMWARE_RESET:
  6829. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6830. if (is_qla80XX(ha))
  6831. /* set firmware context reset */
  6832. set_bit(DPC_RESET_HA_FW_CONTEXT,
  6833. &ha->dpc_flags);
  6834. else {
  6835. rval = qla4xxx_context_reset(ha);
  6836. goto exit_host_reset;
  6837. }
  6838. }
  6839. break;
  6840. }
  6841. recover_adapter:
  6842. /* For ISP83XX set graceful reset bit in IDC_DRV_CTRL if
  6843. * reset is issued by application */
  6844. if (is_qla8032(ha) && test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6845. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  6846. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  6847. (idc_ctrl | GRACEFUL_RESET_BIT1));
  6848. }
  6849. rval = qla4xxx_recover_adapter(ha);
  6850. if (rval != QLA_SUCCESS) {
  6851. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  6852. __func__));
  6853. rval = -EIO;
  6854. }
  6855. exit_host_reset:
  6856. return rval;
  6857. }
  6858. /* PCI AER driver recovers from all correctable errors w/o
  6859. * driver intervention. For uncorrectable errors PCI AER
  6860. * driver calls the following device driver's callbacks
  6861. *
  6862. * - Fatal Errors - link_reset
  6863. * - Non-Fatal Errors - driver's pci_error_detected() which
  6864. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  6865. *
  6866. * PCI AER driver calls
  6867. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  6868. * returns RECOVERED or NEED_RESET if fw_hung
  6869. * NEED_RESET - driver's slot_reset()
  6870. * DISCONNECT - device is dead & cannot recover
  6871. * RECOVERED - driver's pci_resume()
  6872. */
  6873. static pci_ers_result_t
  6874. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  6875. {
  6876. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  6877. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  6878. ha->host_no, __func__, state);
  6879. if (!is_aer_supported(ha))
  6880. return PCI_ERS_RESULT_NONE;
  6881. switch (state) {
  6882. case pci_channel_io_normal:
  6883. clear_bit(AF_EEH_BUSY, &ha->flags);
  6884. return PCI_ERS_RESULT_CAN_RECOVER;
  6885. case pci_channel_io_frozen:
  6886. set_bit(AF_EEH_BUSY, &ha->flags);
  6887. qla4xxx_mailbox_premature_completion(ha);
  6888. qla4xxx_free_irqs(ha);
  6889. pci_disable_device(pdev);
  6890. /* Return back all IOs */
  6891. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  6892. return PCI_ERS_RESULT_NEED_RESET;
  6893. case pci_channel_io_perm_failure:
  6894. set_bit(AF_EEH_BUSY, &ha->flags);
  6895. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  6896. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  6897. return PCI_ERS_RESULT_DISCONNECT;
  6898. }
  6899. return PCI_ERS_RESULT_NEED_RESET;
  6900. }
  6901. /**
  6902. * qla4xxx_pci_mmio_enabled() gets called if
  6903. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  6904. * and read/write to the device still works.
  6905. **/
  6906. static pci_ers_result_t
  6907. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  6908. {
  6909. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  6910. if (!is_aer_supported(ha))
  6911. return PCI_ERS_RESULT_NONE;
  6912. return PCI_ERS_RESULT_RECOVERED;
  6913. }
  6914. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  6915. {
  6916. uint32_t rval = QLA_ERROR;
  6917. int fn;
  6918. struct pci_dev *other_pdev = NULL;
  6919. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  6920. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  6921. if (test_bit(AF_ONLINE, &ha->flags)) {
  6922. clear_bit(AF_ONLINE, &ha->flags);
  6923. clear_bit(AF_LINK_UP, &ha->flags);
  6924. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  6925. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  6926. }
  6927. fn = PCI_FUNC(ha->pdev->devfn);
  6928. while (fn > 0) {
  6929. fn--;
  6930. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  6931. "func %x\n", ha->host_no, __func__, fn);
  6932. /* Get the pci device given the domain, bus,
  6933. * slot/function number */
  6934. other_pdev =
  6935. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  6936. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  6937. fn));
  6938. if (!other_pdev)
  6939. continue;
  6940. if (atomic_read(&other_pdev->enable_cnt)) {
  6941. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  6942. "func in enabled state%x\n", ha->host_no,
  6943. __func__, fn);
  6944. pci_dev_put(other_pdev);
  6945. break;
  6946. }
  6947. pci_dev_put(other_pdev);
  6948. }
  6949. /* The first function on the card, the reset owner will
  6950. * start & initialize the firmware. The other functions
  6951. * on the card will reset the firmware context
  6952. */
  6953. if (!fn) {
  6954. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  6955. "0x%x is the owner\n", ha->host_no, __func__,
  6956. ha->pdev->devfn);
  6957. ha->isp_ops->idc_lock(ha);
  6958. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6959. QLA8XXX_DEV_COLD);
  6960. ha->isp_ops->idc_unlock(ha);
  6961. rval = qla4_8xxx_update_idc_reg(ha);
  6962. if (rval == QLA_ERROR) {
  6963. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  6964. ha->host_no, __func__);
  6965. ha->isp_ops->idc_lock(ha);
  6966. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6967. QLA8XXX_DEV_FAILED);
  6968. ha->isp_ops->idc_unlock(ha);
  6969. goto exit_error_recovery;
  6970. }
  6971. clear_bit(AF_FW_RECOVERY, &ha->flags);
  6972. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  6973. if (rval != QLA_SUCCESS) {
  6974. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  6975. "FAILED\n", ha->host_no, __func__);
  6976. ha->isp_ops->idc_lock(ha);
  6977. qla4_8xxx_clear_drv_active(ha);
  6978. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6979. QLA8XXX_DEV_FAILED);
  6980. ha->isp_ops->idc_unlock(ha);
  6981. } else {
  6982. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  6983. "READY\n", ha->host_no, __func__);
  6984. ha->isp_ops->idc_lock(ha);
  6985. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6986. QLA8XXX_DEV_READY);
  6987. /* Clear driver state register */
  6988. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  6989. qla4_8xxx_set_drv_active(ha);
  6990. ha->isp_ops->idc_unlock(ha);
  6991. ha->isp_ops->enable_intrs(ha);
  6992. }
  6993. } else {
  6994. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  6995. "the reset owner\n", ha->host_no, __func__,
  6996. ha->pdev->devfn);
  6997. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  6998. QLA8XXX_DEV_READY)) {
  6999. clear_bit(AF_FW_RECOVERY, &ha->flags);
  7000. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  7001. if (rval == QLA_SUCCESS)
  7002. ha->isp_ops->enable_intrs(ha);
  7003. ha->isp_ops->idc_lock(ha);
  7004. qla4_8xxx_set_drv_active(ha);
  7005. ha->isp_ops->idc_unlock(ha);
  7006. }
  7007. }
  7008. exit_error_recovery:
  7009. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  7010. return rval;
  7011. }
  7012. static pci_ers_result_t
  7013. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  7014. {
  7015. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  7016. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7017. int rc;
  7018. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  7019. ha->host_no, __func__);
  7020. if (!is_aer_supported(ha))
  7021. return PCI_ERS_RESULT_NONE;
  7022. /* Restore the saved state of PCIe device -
  7023. * BAR registers, PCI Config space, PCIX, MSI,
  7024. * IOV states
  7025. */
  7026. pci_restore_state(pdev);
  7027. /* pci_restore_state() clears the saved_state flag of the device
  7028. * save restored state which resets saved_state flag
  7029. */
  7030. pci_save_state(pdev);
  7031. /* Initialize device or resume if in suspended state */
  7032. rc = pci_enable_device(pdev);
  7033. if (rc) {
  7034. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  7035. "device after reset\n", ha->host_no, __func__);
  7036. goto exit_slot_reset;
  7037. }
  7038. ha->isp_ops->disable_intrs(ha);
  7039. if (is_qla80XX(ha)) {
  7040. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  7041. ret = PCI_ERS_RESULT_RECOVERED;
  7042. goto exit_slot_reset;
  7043. } else
  7044. goto exit_slot_reset;
  7045. }
  7046. exit_slot_reset:
  7047. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  7048. "device after reset\n", ha->host_no, __func__, ret);
  7049. return ret;
  7050. }
  7051. static void
  7052. qla4xxx_pci_resume(struct pci_dev *pdev)
  7053. {
  7054. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7055. int ret;
  7056. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  7057. ha->host_no, __func__);
  7058. ret = qla4xxx_wait_for_hba_online(ha);
  7059. if (ret != QLA_SUCCESS) {
  7060. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  7061. "resume I/O from slot/link_reset\n", ha->host_no,
  7062. __func__);
  7063. }
  7064. pci_cleanup_aer_uncorrect_error_status(pdev);
  7065. clear_bit(AF_EEH_BUSY, &ha->flags);
  7066. }
  7067. static const struct pci_error_handlers qla4xxx_err_handler = {
  7068. .error_detected = qla4xxx_pci_error_detected,
  7069. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  7070. .slot_reset = qla4xxx_pci_slot_reset,
  7071. .resume = qla4xxx_pci_resume,
  7072. };
  7073. static struct pci_device_id qla4xxx_pci_tbl[] = {
  7074. {
  7075. .vendor = PCI_VENDOR_ID_QLOGIC,
  7076. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  7077. .subvendor = PCI_ANY_ID,
  7078. .subdevice = PCI_ANY_ID,
  7079. },
  7080. {
  7081. .vendor = PCI_VENDOR_ID_QLOGIC,
  7082. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  7083. .subvendor = PCI_ANY_ID,
  7084. .subdevice = PCI_ANY_ID,
  7085. },
  7086. {
  7087. .vendor = PCI_VENDOR_ID_QLOGIC,
  7088. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  7089. .subvendor = PCI_ANY_ID,
  7090. .subdevice = PCI_ANY_ID,
  7091. },
  7092. {
  7093. .vendor = PCI_VENDOR_ID_QLOGIC,
  7094. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  7095. .subvendor = PCI_ANY_ID,
  7096. .subdevice = PCI_ANY_ID,
  7097. },
  7098. {
  7099. .vendor = PCI_VENDOR_ID_QLOGIC,
  7100. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  7101. .subvendor = PCI_ANY_ID,
  7102. .subdevice = PCI_ANY_ID,
  7103. },
  7104. {0, 0},
  7105. };
  7106. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  7107. static struct pci_driver qla4xxx_pci_driver = {
  7108. .name = DRIVER_NAME,
  7109. .id_table = qla4xxx_pci_tbl,
  7110. .probe = qla4xxx_probe_adapter,
  7111. .remove = qla4xxx_remove_adapter,
  7112. .err_handler = &qla4xxx_err_handler,
  7113. };
  7114. static int __init qla4xxx_module_init(void)
  7115. {
  7116. int ret;
  7117. /* Allocate cache for SRBs. */
  7118. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  7119. SLAB_HWCACHE_ALIGN, NULL);
  7120. if (srb_cachep == NULL) {
  7121. printk(KERN_ERR
  7122. "%s: Unable to allocate SRB cache..."
  7123. "Failing load!\n", DRIVER_NAME);
  7124. ret = -ENOMEM;
  7125. goto no_srp_cache;
  7126. }
  7127. /* Derive version string. */
  7128. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  7129. if (ql4xextended_error_logging)
  7130. strcat(qla4xxx_version_str, "-debug");
  7131. qla4xxx_scsi_transport =
  7132. iscsi_register_transport(&qla4xxx_iscsi_transport);
  7133. if (!qla4xxx_scsi_transport){
  7134. ret = -ENODEV;
  7135. goto release_srb_cache;
  7136. }
  7137. ret = pci_register_driver(&qla4xxx_pci_driver);
  7138. if (ret)
  7139. goto unregister_transport;
  7140. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  7141. return 0;
  7142. unregister_transport:
  7143. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7144. release_srb_cache:
  7145. kmem_cache_destroy(srb_cachep);
  7146. no_srp_cache:
  7147. return ret;
  7148. }
  7149. static void __exit qla4xxx_module_exit(void)
  7150. {
  7151. pci_unregister_driver(&qla4xxx_pci_driver);
  7152. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7153. kmem_cache_destroy(srb_cachep);
  7154. }
  7155. module_init(qla4xxx_module_init);
  7156. module_exit(qla4xxx_module_exit);
  7157. MODULE_AUTHOR("QLogic Corporation");
  7158. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  7159. MODULE_LICENSE("GPL");
  7160. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);