ql4_os.c 284 KB

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