ql4_os.c 234 KB

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