ql4_os.c 282 KB

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