ql4_os.c 283 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911
  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, "%s: old ISID [%02x%02x%02x"
  5598. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  5599. __func__, old_tddb->isid[5], old_tddb->isid[4],
  5600. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  5601. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  5602. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  5603. new_tddb->isid[0]));
  5604. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  5605. sizeof(old_tddb->isid)))
  5606. return QLA_ERROR;
  5607. }
  5608. DEBUG2(ql4_printk(KERN_INFO, ha,
  5609. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  5610. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  5611. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  5612. new_tddb->ip_addr, new_tddb->iscsi_name));
  5613. return QLA_SUCCESS;
  5614. }
  5615. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  5616. struct dev_db_entry *fw_ddb_entry,
  5617. uint32_t *index)
  5618. {
  5619. struct ddb_entry *ddb_entry;
  5620. struct ql4_tuple_ddb *fw_tddb = NULL;
  5621. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5622. int idx;
  5623. int ret = QLA_ERROR;
  5624. fw_tddb = vzalloc(sizeof(*fw_tddb));
  5625. if (!fw_tddb) {
  5626. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5627. "Memory Allocation failed.\n"));
  5628. ret = QLA_SUCCESS;
  5629. goto exit_check;
  5630. }
  5631. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5632. if (!tmp_tddb) {
  5633. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5634. "Memory Allocation failed.\n"));
  5635. ret = QLA_SUCCESS;
  5636. goto exit_check;
  5637. }
  5638. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  5639. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  5640. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  5641. if (ddb_entry == NULL)
  5642. continue;
  5643. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  5644. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  5645. ret = QLA_SUCCESS; /* found */
  5646. if (index != NULL)
  5647. *index = idx;
  5648. goto exit_check;
  5649. }
  5650. }
  5651. exit_check:
  5652. if (fw_tddb)
  5653. vfree(fw_tddb);
  5654. if (tmp_tddb)
  5655. vfree(tmp_tddb);
  5656. return ret;
  5657. }
  5658. /**
  5659. * qla4xxx_check_existing_isid - check if target with same isid exist
  5660. * in target list
  5661. * @list_nt: list of target
  5662. * @isid: isid to check
  5663. *
  5664. * This routine return QLA_SUCCESS if target with same isid exist
  5665. **/
  5666. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  5667. {
  5668. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  5669. struct dev_db_entry *fw_ddb_entry;
  5670. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5671. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  5672. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  5673. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  5674. return QLA_SUCCESS;
  5675. }
  5676. }
  5677. return QLA_ERROR;
  5678. }
  5679. /**
  5680. * qla4xxx_update_isid - compare ddbs and updated isid
  5681. * @ha: Pointer to host adapter structure.
  5682. * @list_nt: list of nt target
  5683. * @fw_ddb_entry: firmware ddb entry
  5684. *
  5685. * This routine update isid if ddbs have same iqn, same isid and
  5686. * different IP addr.
  5687. * Return QLA_SUCCESS if isid is updated.
  5688. **/
  5689. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  5690. struct list_head *list_nt,
  5691. struct dev_db_entry *fw_ddb_entry)
  5692. {
  5693. uint8_t base_value, i;
  5694. base_value = fw_ddb_entry->isid[1] & 0x1f;
  5695. for (i = 0; i < 8; i++) {
  5696. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  5697. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  5698. break;
  5699. }
  5700. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  5701. return QLA_ERROR;
  5702. return QLA_SUCCESS;
  5703. }
  5704. /**
  5705. * qla4xxx_should_update_isid - check if isid need to update
  5706. * @ha: Pointer to host adapter structure.
  5707. * @old_tddb: ddb tuple
  5708. * @new_tddb: ddb tuple
  5709. *
  5710. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  5711. * same isid
  5712. **/
  5713. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  5714. struct ql4_tuple_ddb *old_tddb,
  5715. struct ql4_tuple_ddb *new_tddb)
  5716. {
  5717. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  5718. /* Same ip */
  5719. if (old_tddb->port == new_tddb->port)
  5720. return QLA_ERROR;
  5721. }
  5722. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  5723. /* different iqn */
  5724. return QLA_ERROR;
  5725. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  5726. sizeof(old_tddb->isid)))
  5727. /* different isid */
  5728. return QLA_ERROR;
  5729. return QLA_SUCCESS;
  5730. }
  5731. /**
  5732. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  5733. * @ha: Pointer to host adapter structure.
  5734. * @list_nt: list of nt target.
  5735. * @fw_ddb_entry: firmware ddb entry.
  5736. *
  5737. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  5738. * duplicate ddb in list_nt.
  5739. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  5740. * Note: This function also update isid of DDB if required.
  5741. **/
  5742. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  5743. struct list_head *list_nt,
  5744. struct dev_db_entry *fw_ddb_entry)
  5745. {
  5746. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  5747. struct ql4_tuple_ddb *fw_tddb = NULL;
  5748. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5749. int rval, ret = QLA_ERROR;
  5750. fw_tddb = vzalloc(sizeof(*fw_tddb));
  5751. if (!fw_tddb) {
  5752. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5753. "Memory Allocation failed.\n"));
  5754. ret = QLA_SUCCESS;
  5755. goto exit_check;
  5756. }
  5757. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5758. if (!tmp_tddb) {
  5759. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5760. "Memory Allocation failed.\n"));
  5761. ret = QLA_SUCCESS;
  5762. goto exit_check;
  5763. }
  5764. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  5765. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5766. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  5767. nt_ddb_idx->flash_isid);
  5768. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  5769. /* found duplicate ddb */
  5770. if (ret == QLA_SUCCESS)
  5771. goto exit_check;
  5772. }
  5773. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5774. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  5775. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  5776. if (ret == QLA_SUCCESS) {
  5777. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  5778. if (rval == QLA_SUCCESS)
  5779. ret = QLA_ERROR;
  5780. else
  5781. ret = QLA_SUCCESS;
  5782. goto exit_check;
  5783. }
  5784. }
  5785. exit_check:
  5786. if (fw_tddb)
  5787. vfree(fw_tddb);
  5788. if (tmp_tddb)
  5789. vfree(tmp_tddb);
  5790. return ret;
  5791. }
  5792. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  5793. {
  5794. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  5795. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  5796. list_del_init(&ddb_idx->list);
  5797. vfree(ddb_idx);
  5798. }
  5799. }
  5800. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  5801. struct dev_db_entry *fw_ddb_entry)
  5802. {
  5803. struct iscsi_endpoint *ep;
  5804. struct sockaddr_in *addr;
  5805. struct sockaddr_in6 *addr6;
  5806. struct sockaddr *t_addr;
  5807. struct sockaddr_storage *dst_addr;
  5808. char *ip;
  5809. /* TODO: need to destroy on unload iscsi_endpoint*/
  5810. dst_addr = vmalloc(sizeof(*dst_addr));
  5811. if (!dst_addr)
  5812. return NULL;
  5813. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  5814. t_addr = (struct sockaddr *)dst_addr;
  5815. t_addr->sa_family = AF_INET6;
  5816. addr6 = (struct sockaddr_in6 *)dst_addr;
  5817. ip = (char *)&addr6->sin6_addr;
  5818. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  5819. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  5820. } else {
  5821. t_addr = (struct sockaddr *)dst_addr;
  5822. t_addr->sa_family = AF_INET;
  5823. addr = (struct sockaddr_in *)dst_addr;
  5824. ip = (char *)&addr->sin_addr;
  5825. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  5826. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  5827. }
  5828. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  5829. vfree(dst_addr);
  5830. return ep;
  5831. }
  5832. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  5833. {
  5834. if (ql4xdisablesysfsboot)
  5835. return QLA_SUCCESS;
  5836. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  5837. return QLA_ERROR;
  5838. return QLA_SUCCESS;
  5839. }
  5840. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  5841. struct ddb_entry *ddb_entry,
  5842. uint16_t idx)
  5843. {
  5844. uint16_t def_timeout;
  5845. ddb_entry->ddb_type = FLASH_DDB;
  5846. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  5847. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  5848. ddb_entry->ha = ha;
  5849. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  5850. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  5851. ddb_entry->chap_tbl_idx = INVALID_ENTRY;
  5852. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  5853. atomic_set(&ddb_entry->relogin_timer, 0);
  5854. atomic_set(&ddb_entry->relogin_retry_count, 0);
  5855. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  5856. ddb_entry->default_relogin_timeout =
  5857. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  5858. def_timeout : LOGIN_TOV;
  5859. ddb_entry->default_time2wait =
  5860. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  5861. if (ql4xdisablesysfsboot &&
  5862. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  5863. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  5864. }
  5865. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  5866. {
  5867. uint32_t idx = 0;
  5868. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  5869. uint32_t sts[MBOX_REG_COUNT];
  5870. uint32_t ip_state;
  5871. unsigned long wtime;
  5872. int ret;
  5873. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  5874. do {
  5875. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  5876. if (ip_idx[idx] == -1)
  5877. continue;
  5878. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  5879. if (ret == QLA_ERROR) {
  5880. ip_idx[idx] = -1;
  5881. continue;
  5882. }
  5883. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  5884. DEBUG2(ql4_printk(KERN_INFO, ha,
  5885. "Waiting for IP state for idx = %d, state = 0x%x\n",
  5886. ip_idx[idx], ip_state));
  5887. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  5888. ip_state == IP_ADDRSTATE_INVALID ||
  5889. ip_state == IP_ADDRSTATE_PREFERRED ||
  5890. ip_state == IP_ADDRSTATE_DEPRICATED ||
  5891. ip_state == IP_ADDRSTATE_DISABLING)
  5892. ip_idx[idx] = -1;
  5893. }
  5894. /* Break if all IP states checked */
  5895. if ((ip_idx[0] == -1) &&
  5896. (ip_idx[1] == -1) &&
  5897. (ip_idx[2] == -1) &&
  5898. (ip_idx[3] == -1))
  5899. break;
  5900. schedule_timeout_uninterruptible(HZ);
  5901. } while (time_after(wtime, jiffies));
  5902. }
  5903. static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
  5904. struct dev_db_entry *flash_ddb_entry)
  5905. {
  5906. uint16_t options = 0;
  5907. size_t ip_len = IP_ADDR_LEN;
  5908. options = le16_to_cpu(fw_ddb_entry->options);
  5909. if (options & DDB_OPT_IPV6_DEVICE)
  5910. ip_len = IPv6_ADDR_LEN;
  5911. if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
  5912. return QLA_ERROR;
  5913. if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
  5914. sizeof(fw_ddb_entry->isid)))
  5915. return QLA_ERROR;
  5916. if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
  5917. sizeof(fw_ddb_entry->port)))
  5918. return QLA_ERROR;
  5919. return QLA_SUCCESS;
  5920. }
  5921. static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
  5922. struct dev_db_entry *fw_ddb_entry,
  5923. uint32_t fw_idx, uint32_t *flash_index)
  5924. {
  5925. struct dev_db_entry *flash_ddb_entry;
  5926. dma_addr_t flash_ddb_entry_dma;
  5927. uint32_t idx = 0;
  5928. int max_ddbs;
  5929. int ret = QLA_ERROR, status;
  5930. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  5931. MAX_DEV_DB_ENTRIES;
  5932. flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5933. &flash_ddb_entry_dma);
  5934. if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
  5935. ql4_printk(KERN_ERR, ha, "Out of memory\n");
  5936. goto exit_find_st_idx;
  5937. }
  5938. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  5939. flash_ddb_entry_dma, fw_idx);
  5940. if (status == QLA_SUCCESS) {
  5941. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  5942. if (status == QLA_SUCCESS) {
  5943. *flash_index = fw_idx;
  5944. ret = QLA_SUCCESS;
  5945. goto exit_find_st_idx;
  5946. }
  5947. }
  5948. for (idx = 0; idx < max_ddbs; idx++) {
  5949. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  5950. flash_ddb_entry_dma, idx);
  5951. if (status == QLA_ERROR)
  5952. continue;
  5953. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  5954. if (status == QLA_SUCCESS) {
  5955. *flash_index = idx;
  5956. ret = QLA_SUCCESS;
  5957. goto exit_find_st_idx;
  5958. }
  5959. }
  5960. if (idx == max_ddbs)
  5961. ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
  5962. fw_idx);
  5963. exit_find_st_idx:
  5964. if (flash_ddb_entry)
  5965. dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
  5966. flash_ddb_entry_dma);
  5967. return ret;
  5968. }
  5969. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  5970. struct list_head *list_st)
  5971. {
  5972. struct qla_ddb_index *st_ddb_idx;
  5973. int max_ddbs;
  5974. int fw_idx_size;
  5975. struct dev_db_entry *fw_ddb_entry;
  5976. dma_addr_t fw_ddb_dma;
  5977. int ret;
  5978. uint32_t idx = 0, next_idx = 0;
  5979. uint32_t state = 0, conn_err = 0;
  5980. uint32_t flash_index = -1;
  5981. uint16_t conn_id = 0;
  5982. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5983. &fw_ddb_dma);
  5984. if (fw_ddb_entry == NULL) {
  5985. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  5986. goto exit_st_list;
  5987. }
  5988. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  5989. MAX_DEV_DB_ENTRIES;
  5990. fw_idx_size = sizeof(struct qla_ddb_index);
  5991. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  5992. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  5993. NULL, &next_idx, &state,
  5994. &conn_err, NULL, &conn_id);
  5995. if (ret == QLA_ERROR)
  5996. break;
  5997. /* Ignore DDB if invalid state (unassigned) */
  5998. if (state == DDB_DS_UNASSIGNED)
  5999. goto continue_next_st;
  6000. /* Check if ST, add to the list_st */
  6001. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  6002. goto continue_next_st;
  6003. st_ddb_idx = vzalloc(fw_idx_size);
  6004. if (!st_ddb_idx)
  6005. break;
  6006. ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
  6007. &flash_index);
  6008. if (ret == QLA_ERROR) {
  6009. ql4_printk(KERN_ERR, ha,
  6010. "No flash entry for ST at idx [%d]\n", idx);
  6011. st_ddb_idx->flash_ddb_idx = idx;
  6012. } else {
  6013. ql4_printk(KERN_INFO, ha,
  6014. "ST at idx [%d] is stored at flash [%d]\n",
  6015. idx, flash_index);
  6016. st_ddb_idx->flash_ddb_idx = flash_index;
  6017. }
  6018. st_ddb_idx->fw_ddb_idx = idx;
  6019. list_add_tail(&st_ddb_idx->list, list_st);
  6020. continue_next_st:
  6021. if (next_idx == 0)
  6022. break;
  6023. }
  6024. exit_st_list:
  6025. if (fw_ddb_entry)
  6026. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6027. }
  6028. /**
  6029. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  6030. * @ha: pointer to adapter structure
  6031. * @list_ddb: List from which failed ddb to be removed
  6032. *
  6033. * Iterate over the list of DDBs and find and remove DDBs that are either in
  6034. * no connection active state or failed state
  6035. **/
  6036. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  6037. struct list_head *list_ddb)
  6038. {
  6039. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6040. uint32_t next_idx = 0;
  6041. uint32_t state = 0, conn_err = 0;
  6042. int ret;
  6043. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  6044. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  6045. NULL, 0, NULL, &next_idx, &state,
  6046. &conn_err, NULL, NULL);
  6047. if (ret == QLA_ERROR)
  6048. continue;
  6049. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6050. state == DDB_DS_SESSION_FAILED) {
  6051. list_del_init(&ddb_idx->list);
  6052. vfree(ddb_idx);
  6053. }
  6054. }
  6055. }
  6056. static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
  6057. struct ddb_entry *ddb_entry,
  6058. struct dev_db_entry *fw_ddb_entry)
  6059. {
  6060. struct iscsi_cls_session *cls_sess;
  6061. struct iscsi_session *sess;
  6062. uint32_t max_ddbs = 0;
  6063. uint16_t ddb_link = -1;
  6064. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6065. MAX_DEV_DB_ENTRIES;
  6066. cls_sess = ddb_entry->sess;
  6067. sess = cls_sess->dd_data;
  6068. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6069. if (ddb_link < max_ddbs)
  6070. sess->discovery_parent_idx = ddb_link;
  6071. else
  6072. sess->discovery_parent_idx = DDB_NO_LINK;
  6073. }
  6074. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  6075. struct dev_db_entry *fw_ddb_entry,
  6076. int is_reset, uint16_t idx)
  6077. {
  6078. struct iscsi_cls_session *cls_sess;
  6079. struct iscsi_session *sess;
  6080. struct iscsi_cls_conn *cls_conn;
  6081. struct iscsi_endpoint *ep;
  6082. uint16_t cmds_max = 32;
  6083. uint16_t conn_id = 0;
  6084. uint32_t initial_cmdsn = 0;
  6085. int ret = QLA_SUCCESS;
  6086. struct ddb_entry *ddb_entry = NULL;
  6087. /* Create session object, with INVALID_ENTRY,
  6088. * the targer_id would get set when we issue the login
  6089. */
  6090. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  6091. cmds_max, sizeof(struct ddb_entry),
  6092. sizeof(struct ql4_task_data),
  6093. initial_cmdsn, INVALID_ENTRY);
  6094. if (!cls_sess) {
  6095. ret = QLA_ERROR;
  6096. goto exit_setup;
  6097. }
  6098. /*
  6099. * so calling module_put function to decrement the
  6100. * reference count.
  6101. **/
  6102. module_put(qla4xxx_iscsi_transport.owner);
  6103. sess = cls_sess->dd_data;
  6104. ddb_entry = sess->dd_data;
  6105. ddb_entry->sess = cls_sess;
  6106. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  6107. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  6108. sizeof(struct dev_db_entry));
  6109. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  6110. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  6111. if (!cls_conn) {
  6112. ret = QLA_ERROR;
  6113. goto exit_setup;
  6114. }
  6115. ddb_entry->conn = cls_conn;
  6116. /* Setup ep, for displaying attributes in sysfs */
  6117. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  6118. if (ep) {
  6119. ep->conn = cls_conn;
  6120. cls_conn->ep = ep;
  6121. } else {
  6122. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  6123. ret = QLA_ERROR;
  6124. goto exit_setup;
  6125. }
  6126. /* Update sess/conn params */
  6127. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  6128. qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
  6129. if (is_reset == RESET_ADAPTER) {
  6130. iscsi_block_session(cls_sess);
  6131. /* Use the relogin path to discover new devices
  6132. * by short-circuting the logic of setting
  6133. * timer to relogin - instead set the flags
  6134. * to initiate login right away.
  6135. */
  6136. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  6137. set_bit(DF_RELOGIN, &ddb_entry->flags);
  6138. }
  6139. exit_setup:
  6140. return ret;
  6141. }
  6142. static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
  6143. struct list_head *list_ddb,
  6144. struct dev_db_entry *fw_ddb_entry)
  6145. {
  6146. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6147. uint16_t ddb_link;
  6148. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6149. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  6150. if (ddb_idx->fw_ddb_idx == ddb_link) {
  6151. DEBUG2(ql4_printk(KERN_INFO, ha,
  6152. "Updating NT parent idx from [%d] to [%d]\n",
  6153. ddb_link, ddb_idx->flash_ddb_idx));
  6154. fw_ddb_entry->ddb_link =
  6155. cpu_to_le16(ddb_idx->flash_ddb_idx);
  6156. return;
  6157. }
  6158. }
  6159. }
  6160. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  6161. struct list_head *list_nt,
  6162. struct list_head *list_st,
  6163. int is_reset)
  6164. {
  6165. struct dev_db_entry *fw_ddb_entry;
  6166. struct ddb_entry *ddb_entry = NULL;
  6167. dma_addr_t fw_ddb_dma;
  6168. int max_ddbs;
  6169. int fw_idx_size;
  6170. int ret;
  6171. uint32_t idx = 0, next_idx = 0;
  6172. uint32_t state = 0, conn_err = 0;
  6173. uint32_t ddb_idx = -1;
  6174. uint16_t conn_id = 0;
  6175. uint16_t ddb_link = -1;
  6176. struct qla_ddb_index *nt_ddb_idx;
  6177. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6178. &fw_ddb_dma);
  6179. if (fw_ddb_entry == NULL) {
  6180. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  6181. goto exit_nt_list;
  6182. }
  6183. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6184. MAX_DEV_DB_ENTRIES;
  6185. fw_idx_size = sizeof(struct qla_ddb_index);
  6186. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  6187. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  6188. NULL, &next_idx, &state,
  6189. &conn_err, NULL, &conn_id);
  6190. if (ret == QLA_ERROR)
  6191. break;
  6192. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  6193. goto continue_next_nt;
  6194. /* Check if NT, then add to list it */
  6195. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  6196. goto continue_next_nt;
  6197. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6198. if (ddb_link < max_ddbs)
  6199. qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
  6200. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6201. state == DDB_DS_SESSION_FAILED) &&
  6202. (is_reset == INIT_ADAPTER))
  6203. goto continue_next_nt;
  6204. DEBUG2(ql4_printk(KERN_INFO, ha,
  6205. "Adding DDB to session = 0x%x\n", idx));
  6206. if (is_reset == INIT_ADAPTER) {
  6207. nt_ddb_idx = vmalloc(fw_idx_size);
  6208. if (!nt_ddb_idx)
  6209. break;
  6210. nt_ddb_idx->fw_ddb_idx = idx;
  6211. /* Copy original isid as it may get updated in function
  6212. * qla4xxx_update_isid(). We need original isid in
  6213. * function qla4xxx_compare_tuple_ddb to find duplicate
  6214. * target */
  6215. memcpy(&nt_ddb_idx->flash_isid[0],
  6216. &fw_ddb_entry->isid[0],
  6217. sizeof(nt_ddb_idx->flash_isid));
  6218. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  6219. fw_ddb_entry);
  6220. if (ret == QLA_SUCCESS) {
  6221. /* free nt_ddb_idx and do not add to list_nt */
  6222. vfree(nt_ddb_idx);
  6223. goto continue_next_nt;
  6224. }
  6225. /* Copy updated isid */
  6226. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  6227. sizeof(struct dev_db_entry));
  6228. list_add_tail(&nt_ddb_idx->list, list_nt);
  6229. } else if (is_reset == RESET_ADAPTER) {
  6230. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
  6231. &ddb_idx);
  6232. if (ret == QLA_SUCCESS) {
  6233. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
  6234. ddb_idx);
  6235. if (ddb_entry != NULL)
  6236. qla4xxx_update_sess_disc_idx(ha,
  6237. ddb_entry,
  6238. fw_ddb_entry);
  6239. goto continue_next_nt;
  6240. }
  6241. }
  6242. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  6243. if (ret == QLA_ERROR)
  6244. goto exit_nt_list;
  6245. continue_next_nt:
  6246. if (next_idx == 0)
  6247. break;
  6248. }
  6249. exit_nt_list:
  6250. if (fw_ddb_entry)
  6251. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6252. }
  6253. static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  6254. struct list_head *list_nt,
  6255. uint16_t target_id)
  6256. {
  6257. struct dev_db_entry *fw_ddb_entry;
  6258. dma_addr_t fw_ddb_dma;
  6259. int max_ddbs;
  6260. int fw_idx_size;
  6261. int ret;
  6262. uint32_t idx = 0, next_idx = 0;
  6263. uint32_t state = 0, conn_err = 0;
  6264. uint16_t conn_id = 0;
  6265. struct qla_ddb_index *nt_ddb_idx;
  6266. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6267. &fw_ddb_dma);
  6268. if (fw_ddb_entry == NULL) {
  6269. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  6270. goto exit_new_nt_list;
  6271. }
  6272. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6273. MAX_DEV_DB_ENTRIES;
  6274. fw_idx_size = sizeof(struct qla_ddb_index);
  6275. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  6276. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  6277. NULL, &next_idx, &state,
  6278. &conn_err, NULL, &conn_id);
  6279. if (ret == QLA_ERROR)
  6280. break;
  6281. /* Check if NT, then add it to list */
  6282. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  6283. goto continue_next_new_nt;
  6284. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
  6285. goto continue_next_new_nt;
  6286. DEBUG2(ql4_printk(KERN_INFO, ha,
  6287. "Adding DDB to session = 0x%x\n", idx));
  6288. nt_ddb_idx = vmalloc(fw_idx_size);
  6289. if (!nt_ddb_idx)
  6290. break;
  6291. nt_ddb_idx->fw_ddb_idx = idx;
  6292. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  6293. if (ret == QLA_SUCCESS) {
  6294. /* free nt_ddb_idx and do not add to list_nt */
  6295. vfree(nt_ddb_idx);
  6296. goto continue_next_new_nt;
  6297. }
  6298. if (target_id < max_ddbs)
  6299. fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
  6300. list_add_tail(&nt_ddb_idx->list, list_nt);
  6301. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  6302. idx);
  6303. if (ret == QLA_ERROR)
  6304. goto exit_new_nt_list;
  6305. continue_next_new_nt:
  6306. if (next_idx == 0)
  6307. break;
  6308. }
  6309. exit_new_nt_list:
  6310. if (fw_ddb_entry)
  6311. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6312. }
  6313. /**
  6314. * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
  6315. * @dev: dev associated with the sysfs entry
  6316. * @data: pointer to flashnode session object
  6317. *
  6318. * Returns:
  6319. * 1: if flashnode entry is non-persistent
  6320. * 0: if flashnode entry is persistent
  6321. **/
  6322. static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
  6323. {
  6324. struct iscsi_bus_flash_session *fnode_sess;
  6325. if (!iscsi_flashnode_bus_match(dev, NULL))
  6326. return 0;
  6327. fnode_sess = iscsi_dev_to_flash_session(dev);
  6328. return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
  6329. }
  6330. /**
  6331. * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
  6332. * @ha: pointer to host
  6333. * @fw_ddb_entry: flash ddb data
  6334. * @idx: target index
  6335. * @user: if set then this call is made from userland else from kernel
  6336. *
  6337. * Returns:
  6338. * On sucess: QLA_SUCCESS
  6339. * On failure: QLA_ERROR
  6340. *
  6341. * This create separate sysfs entries for session and connection attributes of
  6342. * the given fw ddb entry.
  6343. * If this is invoked as a result of a userspace call then the entry is marked
  6344. * as nonpersistent using flash_state field.
  6345. **/
  6346. static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
  6347. struct dev_db_entry *fw_ddb_entry,
  6348. uint16_t *idx, int user)
  6349. {
  6350. struct iscsi_bus_flash_session *fnode_sess = NULL;
  6351. struct iscsi_bus_flash_conn *fnode_conn = NULL;
  6352. int rc = QLA_ERROR;
  6353. fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
  6354. &qla4xxx_iscsi_transport, 0);
  6355. if (!fnode_sess) {
  6356. ql4_printk(KERN_ERR, ha,
  6357. "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
  6358. __func__, *idx, ha->host_no);
  6359. goto exit_tgt_create;
  6360. }
  6361. fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
  6362. &qla4xxx_iscsi_transport, 0);
  6363. if (!fnode_conn) {
  6364. ql4_printk(KERN_ERR, ha,
  6365. "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
  6366. __func__, *idx, ha->host_no);
  6367. goto free_sess;
  6368. }
  6369. if (user) {
  6370. fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
  6371. } else {
  6372. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  6373. if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
  6374. fnode_sess->is_boot_target = 1;
  6375. else
  6376. fnode_sess->is_boot_target = 0;
  6377. }
  6378. rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
  6379. fw_ddb_entry);
  6380. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  6381. __func__, fnode_sess->dev.kobj.name);
  6382. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  6383. __func__, fnode_conn->dev.kobj.name);
  6384. return QLA_SUCCESS;
  6385. free_sess:
  6386. iscsi_destroy_flashnode_sess(fnode_sess);
  6387. exit_tgt_create:
  6388. return QLA_ERROR;
  6389. }
  6390. /**
  6391. * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
  6392. * @shost: pointer to host
  6393. * @buf: type of ddb entry (ipv4/ipv6)
  6394. * @len: length of buf
  6395. *
  6396. * This creates new ddb entry in the flash by finding first free index and
  6397. * storing default ddb there. And then create sysfs entry for the new ddb entry.
  6398. **/
  6399. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  6400. int len)
  6401. {
  6402. struct scsi_qla_host *ha = to_qla_host(shost);
  6403. struct dev_db_entry *fw_ddb_entry = NULL;
  6404. dma_addr_t fw_ddb_entry_dma;
  6405. struct device *dev;
  6406. uint16_t idx = 0;
  6407. uint16_t max_ddbs = 0;
  6408. uint32_t options = 0;
  6409. uint32_t rval = QLA_ERROR;
  6410. if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
  6411. strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
  6412. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
  6413. __func__));
  6414. goto exit_ddb_add;
  6415. }
  6416. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  6417. MAX_DEV_DB_ENTRIES;
  6418. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6419. &fw_ddb_entry_dma, GFP_KERNEL);
  6420. if (!fw_ddb_entry) {
  6421. DEBUG2(ql4_printk(KERN_ERR, ha,
  6422. "%s: Unable to allocate dma buffer\n",
  6423. __func__));
  6424. goto exit_ddb_add;
  6425. }
  6426. dev = iscsi_find_flashnode_sess(ha->host, NULL,
  6427. qla4xxx_sysfs_ddb_is_non_persistent);
  6428. if (dev) {
  6429. ql4_printk(KERN_ERR, ha,
  6430. "%s: A non-persistent entry %s found\n",
  6431. __func__, dev->kobj.name);
  6432. put_device(dev);
  6433. goto exit_ddb_add;
  6434. }
  6435. /* Index 0 and 1 are reserved for boot target entries */
  6436. for (idx = 2; idx < max_ddbs; idx++) {
  6437. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
  6438. fw_ddb_entry_dma, idx))
  6439. break;
  6440. }
  6441. if (idx == max_ddbs)
  6442. goto exit_ddb_add;
  6443. if (!strncasecmp("ipv6", buf, 4))
  6444. options |= IPV6_DEFAULT_DDB_ENTRY;
  6445. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6446. if (rval == QLA_ERROR)
  6447. goto exit_ddb_add;
  6448. rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
  6449. exit_ddb_add:
  6450. if (fw_ddb_entry)
  6451. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6452. fw_ddb_entry, fw_ddb_entry_dma);
  6453. if (rval == QLA_SUCCESS)
  6454. return idx;
  6455. else
  6456. return -EIO;
  6457. }
  6458. /**
  6459. * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
  6460. * @fnode_sess: pointer to session attrs of flash ddb entry
  6461. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6462. *
  6463. * This writes the contents of target ddb buffer to Flash with a valid cookie
  6464. * value in order to make the ddb entry persistent.
  6465. **/
  6466. static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
  6467. struct iscsi_bus_flash_conn *fnode_conn)
  6468. {
  6469. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6470. struct scsi_qla_host *ha = to_qla_host(shost);
  6471. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  6472. struct dev_db_entry *fw_ddb_entry = NULL;
  6473. dma_addr_t fw_ddb_entry_dma;
  6474. uint32_t options = 0;
  6475. int rval = 0;
  6476. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6477. &fw_ddb_entry_dma, GFP_KERNEL);
  6478. if (!fw_ddb_entry) {
  6479. DEBUG2(ql4_printk(KERN_ERR, ha,
  6480. "%s: Unable to allocate dma buffer\n",
  6481. __func__));
  6482. rval = -ENOMEM;
  6483. goto exit_ddb_apply;
  6484. }
  6485. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6486. options |= IPV6_DEFAULT_DDB_ENTRY;
  6487. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6488. if (rval == QLA_ERROR)
  6489. goto exit_ddb_apply;
  6490. dev_db_start_offset += (fnode_sess->target_id *
  6491. sizeof(*fw_ddb_entry));
  6492. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  6493. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  6494. rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  6495. sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
  6496. if (rval == QLA_SUCCESS) {
  6497. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  6498. ql4_printk(KERN_INFO, ha,
  6499. "%s: flash node %u of host %lu written to flash\n",
  6500. __func__, fnode_sess->target_id, ha->host_no);
  6501. } else {
  6502. rval = -EIO;
  6503. ql4_printk(KERN_ERR, ha,
  6504. "%s: Error while writing flash node %u of host %lu to flash\n",
  6505. __func__, fnode_sess->target_id, ha->host_no);
  6506. }
  6507. exit_ddb_apply:
  6508. if (fw_ddb_entry)
  6509. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6510. fw_ddb_entry, fw_ddb_entry_dma);
  6511. return rval;
  6512. }
  6513. static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
  6514. struct dev_db_entry *fw_ddb_entry,
  6515. uint16_t idx)
  6516. {
  6517. struct dev_db_entry *ddb_entry = NULL;
  6518. dma_addr_t ddb_entry_dma;
  6519. unsigned long wtime;
  6520. uint32_t mbx_sts = 0;
  6521. uint32_t state = 0, conn_err = 0;
  6522. uint16_t tmo = 0;
  6523. int ret = 0;
  6524. ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  6525. &ddb_entry_dma, GFP_KERNEL);
  6526. if (!ddb_entry) {
  6527. DEBUG2(ql4_printk(KERN_ERR, ha,
  6528. "%s: Unable to allocate dma buffer\n",
  6529. __func__));
  6530. return QLA_ERROR;
  6531. }
  6532. memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
  6533. ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
  6534. if (ret != QLA_SUCCESS) {
  6535. DEBUG2(ql4_printk(KERN_ERR, ha,
  6536. "%s: Unable to set ddb entry for index %d\n",
  6537. __func__, idx));
  6538. goto exit_ddb_conn_open;
  6539. }
  6540. qla4xxx_conn_open(ha, idx);
  6541. /* To ensure that sendtargets is done, wait for at least 12 secs */
  6542. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  6543. (ha->def_timeout < LOGIN_TOV * 10) ?
  6544. ha->def_timeout : LOGIN_TOV);
  6545. DEBUG2(ql4_printk(KERN_INFO, ha,
  6546. "Default time to wait for login to ddb %d\n", tmo));
  6547. wtime = jiffies + (HZ * tmo);
  6548. do {
  6549. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  6550. NULL, &state, &conn_err, NULL,
  6551. NULL);
  6552. if (ret == QLA_ERROR)
  6553. continue;
  6554. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6555. state == DDB_DS_SESSION_FAILED)
  6556. break;
  6557. schedule_timeout_uninterruptible(HZ / 10);
  6558. } while (time_after(wtime, jiffies));
  6559. exit_ddb_conn_open:
  6560. if (ddb_entry)
  6561. dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  6562. ddb_entry, ddb_entry_dma);
  6563. return ret;
  6564. }
  6565. static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
  6566. struct dev_db_entry *fw_ddb_entry,
  6567. uint16_t target_id)
  6568. {
  6569. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6570. struct list_head list_nt;
  6571. uint16_t ddb_index;
  6572. int ret = 0;
  6573. if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
  6574. ql4_printk(KERN_WARNING, ha,
  6575. "%s: A discovery already in progress!\n", __func__);
  6576. return QLA_ERROR;
  6577. }
  6578. INIT_LIST_HEAD(&list_nt);
  6579. set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  6580. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  6581. if (ret == QLA_ERROR)
  6582. goto exit_login_st_clr_bit;
  6583. ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
  6584. if (ret == QLA_ERROR)
  6585. goto exit_login_st;
  6586. qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
  6587. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
  6588. list_del_init(&ddb_idx->list);
  6589. qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
  6590. vfree(ddb_idx);
  6591. }
  6592. exit_login_st:
  6593. if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
  6594. ql4_printk(KERN_ERR, ha,
  6595. "Unable to clear DDB index = 0x%x\n", ddb_index);
  6596. }
  6597. clear_bit(ddb_index, ha->ddb_idx_map);
  6598. exit_login_st_clr_bit:
  6599. clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  6600. return ret;
  6601. }
  6602. static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
  6603. struct dev_db_entry *fw_ddb_entry,
  6604. uint16_t idx)
  6605. {
  6606. int ret = QLA_ERROR;
  6607. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  6608. if (ret != QLA_SUCCESS)
  6609. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  6610. idx);
  6611. else
  6612. ret = -EPERM;
  6613. return ret;
  6614. }
  6615. /**
  6616. * qla4xxx_sysfs_ddb_login - Login to the specified target
  6617. * @fnode_sess: pointer to session attrs of flash ddb entry
  6618. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6619. *
  6620. * This logs in to the specified target
  6621. **/
  6622. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  6623. struct iscsi_bus_flash_conn *fnode_conn)
  6624. {
  6625. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6626. struct scsi_qla_host *ha = to_qla_host(shost);
  6627. struct dev_db_entry *fw_ddb_entry = NULL;
  6628. dma_addr_t fw_ddb_entry_dma;
  6629. uint32_t options = 0;
  6630. int ret = 0;
  6631. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
  6632. ql4_printk(KERN_ERR, ha,
  6633. "%s: Target info is not persistent\n", __func__);
  6634. ret = -EIO;
  6635. goto exit_ddb_login;
  6636. }
  6637. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6638. &fw_ddb_entry_dma, GFP_KERNEL);
  6639. if (!fw_ddb_entry) {
  6640. DEBUG2(ql4_printk(KERN_ERR, ha,
  6641. "%s: Unable to allocate dma buffer\n",
  6642. __func__));
  6643. ret = -ENOMEM;
  6644. goto exit_ddb_login;
  6645. }
  6646. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6647. options |= IPV6_DEFAULT_DDB_ENTRY;
  6648. ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6649. if (ret == QLA_ERROR)
  6650. goto exit_ddb_login;
  6651. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  6652. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  6653. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  6654. ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
  6655. fnode_sess->target_id);
  6656. else
  6657. ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
  6658. fnode_sess->target_id);
  6659. if (ret > 0)
  6660. ret = -EIO;
  6661. exit_ddb_login:
  6662. if (fw_ddb_entry)
  6663. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6664. fw_ddb_entry, fw_ddb_entry_dma);
  6665. return ret;
  6666. }
  6667. /**
  6668. * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
  6669. * @cls_sess: pointer to session to be logged out
  6670. *
  6671. * This performs session log out from the specified target
  6672. **/
  6673. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
  6674. {
  6675. struct iscsi_session *sess;
  6676. struct ddb_entry *ddb_entry = NULL;
  6677. struct scsi_qla_host *ha;
  6678. struct dev_db_entry *fw_ddb_entry = NULL;
  6679. dma_addr_t fw_ddb_entry_dma;
  6680. unsigned long flags;
  6681. unsigned long wtime;
  6682. uint32_t ddb_state;
  6683. int options;
  6684. int ret = 0;
  6685. sess = cls_sess->dd_data;
  6686. ddb_entry = sess->dd_data;
  6687. ha = ddb_entry->ha;
  6688. if (ddb_entry->ddb_type != FLASH_DDB) {
  6689. ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
  6690. __func__);
  6691. ret = -ENXIO;
  6692. goto exit_ddb_logout;
  6693. }
  6694. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  6695. ql4_printk(KERN_ERR, ha,
  6696. "%s: Logout from boot target entry is not permitted.\n",
  6697. __func__);
  6698. ret = -EPERM;
  6699. goto exit_ddb_logout;
  6700. }
  6701. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6702. &fw_ddb_entry_dma, GFP_KERNEL);
  6703. if (!fw_ddb_entry) {
  6704. ql4_printk(KERN_ERR, ha,
  6705. "%s: Unable to allocate dma buffer\n", __func__);
  6706. ret = -ENOMEM;
  6707. goto exit_ddb_logout;
  6708. }
  6709. if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  6710. goto ddb_logout_init;
  6711. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  6712. fw_ddb_entry, fw_ddb_entry_dma,
  6713. NULL, NULL, &ddb_state, NULL,
  6714. NULL, NULL);
  6715. if (ret == QLA_ERROR)
  6716. goto ddb_logout_init;
  6717. if (ddb_state == DDB_DS_SESSION_ACTIVE)
  6718. goto ddb_logout_init;
  6719. /* wait until next relogin is triggered using DF_RELOGIN and
  6720. * clear DF_RELOGIN to avoid invocation of further relogin
  6721. */
  6722. wtime = jiffies + (HZ * RELOGIN_TOV);
  6723. do {
  6724. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
  6725. goto ddb_logout_init;
  6726. schedule_timeout_uninterruptible(HZ);
  6727. } while ((time_after(wtime, jiffies)));
  6728. ddb_logout_init:
  6729. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  6730. atomic_set(&ddb_entry->relogin_timer, 0);
  6731. options = LOGOUT_OPTION_CLOSE_SESSION;
  6732. qla4xxx_session_logout_ddb(ha, ddb_entry, options);
  6733. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  6734. wtime = jiffies + (HZ * LOGOUT_TOV);
  6735. do {
  6736. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  6737. fw_ddb_entry, fw_ddb_entry_dma,
  6738. NULL, NULL, &ddb_state, NULL,
  6739. NULL, NULL);
  6740. if (ret == QLA_ERROR)
  6741. goto ddb_logout_clr_sess;
  6742. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  6743. (ddb_state == DDB_DS_SESSION_FAILED))
  6744. goto ddb_logout_clr_sess;
  6745. schedule_timeout_uninterruptible(HZ);
  6746. } while ((time_after(wtime, jiffies)));
  6747. ddb_logout_clr_sess:
  6748. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  6749. /*
  6750. * we have decremented the reference count of the driver
  6751. * when we setup the session to have the driver unload
  6752. * to be seamless without actually destroying the
  6753. * session
  6754. **/
  6755. try_module_get(qla4xxx_iscsi_transport.owner);
  6756. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  6757. spin_lock_irqsave(&ha->hardware_lock, flags);
  6758. qla4xxx_free_ddb(ha, ddb_entry);
  6759. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  6760. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6761. iscsi_session_teardown(ddb_entry->sess);
  6762. clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
  6763. ret = QLA_SUCCESS;
  6764. exit_ddb_logout:
  6765. if (fw_ddb_entry)
  6766. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6767. fw_ddb_entry, fw_ddb_entry_dma);
  6768. return ret;
  6769. }
  6770. /**
  6771. * qla4xxx_sysfs_ddb_logout - Logout from the specified target
  6772. * @fnode_sess: pointer to session attrs of flash ddb entry
  6773. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6774. *
  6775. * This performs log out from the specified target
  6776. **/
  6777. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  6778. struct iscsi_bus_flash_conn *fnode_conn)
  6779. {
  6780. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6781. struct scsi_qla_host *ha = to_qla_host(shost);
  6782. struct ql4_tuple_ddb *flash_tddb = NULL;
  6783. struct ql4_tuple_ddb *tmp_tddb = NULL;
  6784. struct dev_db_entry *fw_ddb_entry = NULL;
  6785. struct ddb_entry *ddb_entry = NULL;
  6786. dma_addr_t fw_ddb_dma;
  6787. uint32_t next_idx = 0;
  6788. uint32_t state = 0, conn_err = 0;
  6789. uint16_t conn_id = 0;
  6790. int idx, index;
  6791. int status, ret = 0;
  6792. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6793. &fw_ddb_dma);
  6794. if (fw_ddb_entry == NULL) {
  6795. ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
  6796. ret = -ENOMEM;
  6797. goto exit_ddb_logout;
  6798. }
  6799. flash_tddb = vzalloc(sizeof(*flash_tddb));
  6800. if (!flash_tddb) {
  6801. ql4_printk(KERN_WARNING, ha,
  6802. "%s:Memory Allocation failed.\n", __func__);
  6803. ret = -ENOMEM;
  6804. goto exit_ddb_logout;
  6805. }
  6806. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  6807. if (!tmp_tddb) {
  6808. ql4_printk(KERN_WARNING, ha,
  6809. "%s:Memory Allocation failed.\n", __func__);
  6810. ret = -ENOMEM;
  6811. goto exit_ddb_logout;
  6812. }
  6813. if (!fnode_sess->targetname) {
  6814. ql4_printk(KERN_ERR, ha,
  6815. "%s:Cannot logout from SendTarget entry\n",
  6816. __func__);
  6817. ret = -EPERM;
  6818. goto exit_ddb_logout;
  6819. }
  6820. if (fnode_sess->is_boot_target) {
  6821. ql4_printk(KERN_ERR, ha,
  6822. "%s: Logout from boot target entry is not permitted.\n",
  6823. __func__);
  6824. ret = -EPERM;
  6825. goto exit_ddb_logout;
  6826. }
  6827. strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
  6828. ISCSI_NAME_SIZE);
  6829. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6830. sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
  6831. else
  6832. sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
  6833. flash_tddb->tpgt = fnode_sess->tpgt;
  6834. flash_tddb->port = fnode_conn->port;
  6835. COPY_ISID(flash_tddb->isid, fnode_sess->isid);
  6836. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  6837. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6838. if (ddb_entry == NULL)
  6839. continue;
  6840. if (ddb_entry->ddb_type != FLASH_DDB)
  6841. continue;
  6842. index = ddb_entry->sess->target_id;
  6843. status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
  6844. fw_ddb_dma, NULL, &next_idx,
  6845. &state, &conn_err, NULL,
  6846. &conn_id);
  6847. if (status == QLA_ERROR) {
  6848. ret = -ENOMEM;
  6849. break;
  6850. }
  6851. qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
  6852. status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
  6853. true);
  6854. if (status == QLA_SUCCESS) {
  6855. ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
  6856. break;
  6857. }
  6858. }
  6859. if (idx == MAX_DDB_ENTRIES)
  6860. ret = -ESRCH;
  6861. exit_ddb_logout:
  6862. if (flash_tddb)
  6863. vfree(flash_tddb);
  6864. if (tmp_tddb)
  6865. vfree(tmp_tddb);
  6866. if (fw_ddb_entry)
  6867. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6868. return ret;
  6869. }
  6870. static int
  6871. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  6872. int param, char *buf)
  6873. {
  6874. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6875. struct scsi_qla_host *ha = to_qla_host(shost);
  6876. struct iscsi_bus_flash_conn *fnode_conn;
  6877. struct ql4_chap_table chap_tbl;
  6878. struct device *dev;
  6879. int parent_type;
  6880. int rc = 0;
  6881. dev = iscsi_find_flashnode_conn(fnode_sess);
  6882. if (!dev)
  6883. return -EIO;
  6884. fnode_conn = iscsi_dev_to_flash_conn(dev);
  6885. switch (param) {
  6886. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  6887. rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
  6888. break;
  6889. case ISCSI_FLASHNODE_PORTAL_TYPE:
  6890. rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
  6891. break;
  6892. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  6893. rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
  6894. break;
  6895. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  6896. rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
  6897. break;
  6898. case ISCSI_FLASHNODE_ENTRY_EN:
  6899. rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
  6900. break;
  6901. case ISCSI_FLASHNODE_HDR_DGST_EN:
  6902. rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
  6903. break;
  6904. case ISCSI_FLASHNODE_DATA_DGST_EN:
  6905. rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
  6906. break;
  6907. case ISCSI_FLASHNODE_IMM_DATA_EN:
  6908. rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
  6909. break;
  6910. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  6911. rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
  6912. break;
  6913. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  6914. rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
  6915. break;
  6916. case ISCSI_FLASHNODE_PDU_INORDER:
  6917. rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
  6918. break;
  6919. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  6920. rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
  6921. break;
  6922. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  6923. rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
  6924. break;
  6925. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  6926. rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
  6927. break;
  6928. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  6929. rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
  6930. break;
  6931. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  6932. rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
  6933. break;
  6934. case ISCSI_FLASHNODE_ERL:
  6935. rc = sprintf(buf, "%u\n", fnode_sess->erl);
  6936. break;
  6937. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  6938. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
  6939. break;
  6940. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  6941. rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
  6942. break;
  6943. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  6944. rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
  6945. break;
  6946. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  6947. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
  6948. break;
  6949. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  6950. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
  6951. break;
  6952. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  6953. rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
  6954. break;
  6955. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  6956. rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
  6957. break;
  6958. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  6959. rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
  6960. break;
  6961. case ISCSI_FLASHNODE_FIRST_BURST:
  6962. rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
  6963. break;
  6964. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  6965. rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
  6966. break;
  6967. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  6968. rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
  6969. break;
  6970. case ISCSI_FLASHNODE_MAX_R2T:
  6971. rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
  6972. break;
  6973. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  6974. rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
  6975. break;
  6976. case ISCSI_FLASHNODE_ISID:
  6977. rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
  6978. fnode_sess->isid[0], fnode_sess->isid[1],
  6979. fnode_sess->isid[2], fnode_sess->isid[3],
  6980. fnode_sess->isid[4], fnode_sess->isid[5]);
  6981. break;
  6982. case ISCSI_FLASHNODE_TSID:
  6983. rc = sprintf(buf, "%u\n", fnode_sess->tsid);
  6984. break;
  6985. case ISCSI_FLASHNODE_PORT:
  6986. rc = sprintf(buf, "%d\n", fnode_conn->port);
  6987. break;
  6988. case ISCSI_FLASHNODE_MAX_BURST:
  6989. rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
  6990. break;
  6991. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  6992. rc = sprintf(buf, "%u\n",
  6993. fnode_sess->default_taskmgmt_timeout);
  6994. break;
  6995. case ISCSI_FLASHNODE_IPADDR:
  6996. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6997. rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
  6998. else
  6999. rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
  7000. break;
  7001. case ISCSI_FLASHNODE_ALIAS:
  7002. if (fnode_sess->targetalias)
  7003. rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
  7004. else
  7005. rc = sprintf(buf, "\n");
  7006. break;
  7007. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  7008. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7009. rc = sprintf(buf, "%pI6\n",
  7010. fnode_conn->redirect_ipaddr);
  7011. else
  7012. rc = sprintf(buf, "%pI4\n",
  7013. fnode_conn->redirect_ipaddr);
  7014. break;
  7015. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  7016. rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
  7017. break;
  7018. case ISCSI_FLASHNODE_LOCAL_PORT:
  7019. rc = sprintf(buf, "%u\n", fnode_conn->local_port);
  7020. break;
  7021. case ISCSI_FLASHNODE_IPV4_TOS:
  7022. rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
  7023. break;
  7024. case ISCSI_FLASHNODE_IPV6_TC:
  7025. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7026. rc = sprintf(buf, "%u\n",
  7027. fnode_conn->ipv6_traffic_class);
  7028. else
  7029. rc = sprintf(buf, "\n");
  7030. break;
  7031. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  7032. rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
  7033. break;
  7034. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  7035. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7036. rc = sprintf(buf, "%pI6\n",
  7037. fnode_conn->link_local_ipv6_addr);
  7038. else
  7039. rc = sprintf(buf, "\n");
  7040. break;
  7041. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  7042. rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
  7043. break;
  7044. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  7045. if (fnode_sess->discovery_parent_type == DDB_ISNS)
  7046. parent_type = ISCSI_DISC_PARENT_ISNS;
  7047. else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
  7048. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  7049. else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
  7050. parent_type = ISCSI_DISC_PARENT_SENDTGT;
  7051. else
  7052. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  7053. rc = sprintf(buf, "%s\n",
  7054. iscsi_get_discovery_parent_name(parent_type));
  7055. break;
  7056. case ISCSI_FLASHNODE_NAME:
  7057. if (fnode_sess->targetname)
  7058. rc = sprintf(buf, "%s\n", fnode_sess->targetname);
  7059. else
  7060. rc = sprintf(buf, "\n");
  7061. break;
  7062. case ISCSI_FLASHNODE_TPGT:
  7063. rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
  7064. break;
  7065. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  7066. rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
  7067. break;
  7068. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  7069. rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
  7070. break;
  7071. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  7072. rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
  7073. break;
  7074. case ISCSI_FLASHNODE_USERNAME:
  7075. if (fnode_sess->chap_auth_en) {
  7076. qla4xxx_get_uni_chap_at_index(ha,
  7077. chap_tbl.name,
  7078. chap_tbl.secret,
  7079. fnode_sess->chap_out_idx);
  7080. rc = sprintf(buf, "%s\n", chap_tbl.name);
  7081. } else {
  7082. rc = sprintf(buf, "\n");
  7083. }
  7084. break;
  7085. case ISCSI_FLASHNODE_PASSWORD:
  7086. if (fnode_sess->chap_auth_en) {
  7087. qla4xxx_get_uni_chap_at_index(ha,
  7088. chap_tbl.name,
  7089. chap_tbl.secret,
  7090. fnode_sess->chap_out_idx);
  7091. rc = sprintf(buf, "%s\n", chap_tbl.secret);
  7092. } else {
  7093. rc = sprintf(buf, "\n");
  7094. }
  7095. break;
  7096. case ISCSI_FLASHNODE_STATSN:
  7097. rc = sprintf(buf, "%u\n", fnode_conn->statsn);
  7098. break;
  7099. case ISCSI_FLASHNODE_EXP_STATSN:
  7100. rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
  7101. break;
  7102. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  7103. rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
  7104. break;
  7105. default:
  7106. rc = -ENOSYS;
  7107. break;
  7108. }
  7109. put_device(dev);
  7110. return rc;
  7111. }
  7112. /**
  7113. * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
  7114. * @fnode_sess: pointer to session attrs of flash ddb entry
  7115. * @fnode_conn: pointer to connection attrs of flash ddb entry
  7116. * @data: Parameters and their values to update
  7117. * @len: len of data
  7118. *
  7119. * This sets the parameter of flash ddb entry and writes them to flash
  7120. **/
  7121. static int
  7122. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  7123. struct iscsi_bus_flash_conn *fnode_conn,
  7124. void *data, int len)
  7125. {
  7126. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  7127. struct scsi_qla_host *ha = to_qla_host(shost);
  7128. struct iscsi_flashnode_param_info *fnode_param;
  7129. struct ql4_chap_table chap_tbl;
  7130. struct nlattr *attr;
  7131. uint16_t chap_out_idx = INVALID_ENTRY;
  7132. int rc = QLA_ERROR;
  7133. uint32_t rem = len;
  7134. memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
  7135. nla_for_each_attr(attr, data, len, rem) {
  7136. fnode_param = nla_data(attr);
  7137. switch (fnode_param->param) {
  7138. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  7139. fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
  7140. break;
  7141. case ISCSI_FLASHNODE_PORTAL_TYPE:
  7142. memcpy(fnode_sess->portal_type, fnode_param->value,
  7143. strlen(fnode_sess->portal_type));
  7144. break;
  7145. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  7146. fnode_sess->auto_snd_tgt_disable =
  7147. fnode_param->value[0];
  7148. break;
  7149. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  7150. fnode_sess->discovery_sess = fnode_param->value[0];
  7151. break;
  7152. case ISCSI_FLASHNODE_ENTRY_EN:
  7153. fnode_sess->entry_state = fnode_param->value[0];
  7154. break;
  7155. case ISCSI_FLASHNODE_HDR_DGST_EN:
  7156. fnode_conn->hdrdgst_en = fnode_param->value[0];
  7157. break;
  7158. case ISCSI_FLASHNODE_DATA_DGST_EN:
  7159. fnode_conn->datadgst_en = fnode_param->value[0];
  7160. break;
  7161. case ISCSI_FLASHNODE_IMM_DATA_EN:
  7162. fnode_sess->imm_data_en = fnode_param->value[0];
  7163. break;
  7164. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  7165. fnode_sess->initial_r2t_en = fnode_param->value[0];
  7166. break;
  7167. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  7168. fnode_sess->dataseq_inorder_en = fnode_param->value[0];
  7169. break;
  7170. case ISCSI_FLASHNODE_PDU_INORDER:
  7171. fnode_sess->pdu_inorder_en = fnode_param->value[0];
  7172. break;
  7173. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  7174. fnode_sess->chap_auth_en = fnode_param->value[0];
  7175. /* Invalidate chap index if chap auth is disabled */
  7176. if (!fnode_sess->chap_auth_en)
  7177. fnode_sess->chap_out_idx = INVALID_ENTRY;
  7178. break;
  7179. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  7180. fnode_conn->snack_req_en = fnode_param->value[0];
  7181. break;
  7182. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  7183. fnode_sess->discovery_logout_en = fnode_param->value[0];
  7184. break;
  7185. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  7186. fnode_sess->bidi_chap_en = fnode_param->value[0];
  7187. break;
  7188. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  7189. fnode_sess->discovery_auth_optional =
  7190. fnode_param->value[0];
  7191. break;
  7192. case ISCSI_FLASHNODE_ERL:
  7193. fnode_sess->erl = fnode_param->value[0];
  7194. break;
  7195. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  7196. fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
  7197. break;
  7198. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  7199. fnode_conn->tcp_nagle_disable = fnode_param->value[0];
  7200. break;
  7201. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  7202. fnode_conn->tcp_wsf_disable = fnode_param->value[0];
  7203. break;
  7204. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  7205. fnode_conn->tcp_timer_scale = fnode_param->value[0];
  7206. break;
  7207. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  7208. fnode_conn->tcp_timestamp_en = fnode_param->value[0];
  7209. break;
  7210. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  7211. fnode_conn->fragment_disable = fnode_param->value[0];
  7212. break;
  7213. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  7214. fnode_conn->max_recv_dlength =
  7215. *(unsigned *)fnode_param->value;
  7216. break;
  7217. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  7218. fnode_conn->max_xmit_dlength =
  7219. *(unsigned *)fnode_param->value;
  7220. break;
  7221. case ISCSI_FLASHNODE_FIRST_BURST:
  7222. fnode_sess->first_burst =
  7223. *(unsigned *)fnode_param->value;
  7224. break;
  7225. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  7226. fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
  7227. break;
  7228. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  7229. fnode_sess->time2retain =
  7230. *(uint16_t *)fnode_param->value;
  7231. break;
  7232. case ISCSI_FLASHNODE_MAX_R2T:
  7233. fnode_sess->max_r2t =
  7234. *(uint16_t *)fnode_param->value;
  7235. break;
  7236. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  7237. fnode_conn->keepalive_timeout =
  7238. *(uint16_t *)fnode_param->value;
  7239. break;
  7240. case ISCSI_FLASHNODE_ISID:
  7241. memcpy(fnode_sess->isid, fnode_param->value,
  7242. sizeof(fnode_sess->isid));
  7243. break;
  7244. case ISCSI_FLASHNODE_TSID:
  7245. fnode_sess->tsid = *(uint16_t *)fnode_param->value;
  7246. break;
  7247. case ISCSI_FLASHNODE_PORT:
  7248. fnode_conn->port = *(uint16_t *)fnode_param->value;
  7249. break;
  7250. case ISCSI_FLASHNODE_MAX_BURST:
  7251. fnode_sess->max_burst = *(unsigned *)fnode_param->value;
  7252. break;
  7253. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  7254. fnode_sess->default_taskmgmt_timeout =
  7255. *(uint16_t *)fnode_param->value;
  7256. break;
  7257. case ISCSI_FLASHNODE_IPADDR:
  7258. memcpy(fnode_conn->ipaddress, fnode_param->value,
  7259. IPv6_ADDR_LEN);
  7260. break;
  7261. case ISCSI_FLASHNODE_ALIAS:
  7262. rc = iscsi_switch_str_param(&fnode_sess->targetalias,
  7263. (char *)fnode_param->value);
  7264. break;
  7265. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  7266. memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
  7267. IPv6_ADDR_LEN);
  7268. break;
  7269. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  7270. fnode_conn->max_segment_size =
  7271. *(unsigned *)fnode_param->value;
  7272. break;
  7273. case ISCSI_FLASHNODE_LOCAL_PORT:
  7274. fnode_conn->local_port =
  7275. *(uint16_t *)fnode_param->value;
  7276. break;
  7277. case ISCSI_FLASHNODE_IPV4_TOS:
  7278. fnode_conn->ipv4_tos = fnode_param->value[0];
  7279. break;
  7280. case ISCSI_FLASHNODE_IPV6_TC:
  7281. fnode_conn->ipv6_traffic_class = fnode_param->value[0];
  7282. break;
  7283. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  7284. fnode_conn->ipv6_flow_label = fnode_param->value[0];
  7285. break;
  7286. case ISCSI_FLASHNODE_NAME:
  7287. rc = iscsi_switch_str_param(&fnode_sess->targetname,
  7288. (char *)fnode_param->value);
  7289. break;
  7290. case ISCSI_FLASHNODE_TPGT:
  7291. fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
  7292. break;
  7293. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  7294. memcpy(fnode_conn->link_local_ipv6_addr,
  7295. fnode_param->value, IPv6_ADDR_LEN);
  7296. break;
  7297. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  7298. fnode_sess->discovery_parent_idx =
  7299. *(uint16_t *)fnode_param->value;
  7300. break;
  7301. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  7302. fnode_conn->tcp_xmit_wsf =
  7303. *(uint8_t *)fnode_param->value;
  7304. break;
  7305. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  7306. fnode_conn->tcp_recv_wsf =
  7307. *(uint8_t *)fnode_param->value;
  7308. break;
  7309. case ISCSI_FLASHNODE_STATSN:
  7310. fnode_conn->statsn = *(uint32_t *)fnode_param->value;
  7311. break;
  7312. case ISCSI_FLASHNODE_EXP_STATSN:
  7313. fnode_conn->exp_statsn =
  7314. *(uint32_t *)fnode_param->value;
  7315. break;
  7316. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  7317. chap_out_idx = *(uint16_t *)fnode_param->value;
  7318. if (!qla4xxx_get_uni_chap_at_index(ha,
  7319. chap_tbl.name,
  7320. chap_tbl.secret,
  7321. chap_out_idx)) {
  7322. fnode_sess->chap_out_idx = chap_out_idx;
  7323. /* Enable chap auth if chap index is valid */
  7324. fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
  7325. }
  7326. break;
  7327. default:
  7328. ql4_printk(KERN_ERR, ha,
  7329. "%s: No such sysfs attribute\n", __func__);
  7330. rc = -ENOSYS;
  7331. goto exit_set_param;
  7332. }
  7333. }
  7334. rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
  7335. exit_set_param:
  7336. return rc;
  7337. }
  7338. /**
  7339. * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
  7340. * @fnode_sess: pointer to session attrs of flash ddb entry
  7341. *
  7342. * This invalidates the flash ddb entry at the given index
  7343. **/
  7344. static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
  7345. {
  7346. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  7347. struct scsi_qla_host *ha = to_qla_host(shost);
  7348. uint32_t dev_db_start_offset;
  7349. uint32_t dev_db_end_offset;
  7350. struct dev_db_entry *fw_ddb_entry = NULL;
  7351. dma_addr_t fw_ddb_entry_dma;
  7352. uint16_t *ddb_cookie = NULL;
  7353. size_t ddb_size = 0;
  7354. void *pddb = NULL;
  7355. int target_id;
  7356. int rc = 0;
  7357. if (fnode_sess->is_boot_target) {
  7358. rc = -EPERM;
  7359. DEBUG2(ql4_printk(KERN_ERR, ha,
  7360. "%s: Deletion of boot target entry is not permitted.\n",
  7361. __func__));
  7362. goto exit_ddb_del;
  7363. }
  7364. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
  7365. goto sysfs_ddb_del;
  7366. if (is_qla40XX(ha)) {
  7367. dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  7368. dev_db_end_offset = FLASH_OFFSET_DB_END;
  7369. dev_db_start_offset += (fnode_sess->target_id *
  7370. sizeof(*fw_ddb_entry));
  7371. ddb_size = sizeof(*fw_ddb_entry);
  7372. } else {
  7373. dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
  7374. (ha->hw.flt_region_ddb << 2);
  7375. /* flt_ddb_size is DDB table size for both ports
  7376. * so divide it by 2 to calculate the offset for second port
  7377. */
  7378. if (ha->port_num == 1)
  7379. dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
  7380. dev_db_end_offset = dev_db_start_offset +
  7381. (ha->hw.flt_ddb_size / 2);
  7382. dev_db_start_offset += (fnode_sess->target_id *
  7383. sizeof(*fw_ddb_entry));
  7384. dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
  7385. ddb_size = sizeof(*ddb_cookie);
  7386. }
  7387. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
  7388. __func__, dev_db_start_offset, dev_db_end_offset));
  7389. if (dev_db_start_offset > dev_db_end_offset) {
  7390. rc = -EIO;
  7391. DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
  7392. __func__, fnode_sess->target_id));
  7393. goto exit_ddb_del;
  7394. }
  7395. pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
  7396. &fw_ddb_entry_dma, GFP_KERNEL);
  7397. if (!pddb) {
  7398. rc = -ENOMEM;
  7399. DEBUG2(ql4_printk(KERN_ERR, ha,
  7400. "%s: Unable to allocate dma buffer\n",
  7401. __func__));
  7402. goto exit_ddb_del;
  7403. }
  7404. if (is_qla40XX(ha)) {
  7405. fw_ddb_entry = pddb;
  7406. memset(fw_ddb_entry, 0, ddb_size);
  7407. ddb_cookie = &fw_ddb_entry->cookie;
  7408. } else {
  7409. ddb_cookie = pddb;
  7410. }
  7411. /* invalidate the cookie */
  7412. *ddb_cookie = 0xFFEE;
  7413. qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  7414. ddb_size, FLASH_OPT_RMW_COMMIT);
  7415. sysfs_ddb_del:
  7416. target_id = fnode_sess->target_id;
  7417. iscsi_destroy_flashnode_sess(fnode_sess);
  7418. ql4_printk(KERN_INFO, ha,
  7419. "%s: session and conn entries for flashnode %u of host %lu deleted\n",
  7420. __func__, target_id, ha->host_no);
  7421. exit_ddb_del:
  7422. if (pddb)
  7423. dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
  7424. fw_ddb_entry_dma);
  7425. return rc;
  7426. }
  7427. /**
  7428. * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
  7429. * @ha: pointer to adapter structure
  7430. *
  7431. * Export the firmware DDB for all send targets and normal targets to sysfs.
  7432. **/
  7433. int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
  7434. {
  7435. struct dev_db_entry *fw_ddb_entry = NULL;
  7436. dma_addr_t fw_ddb_entry_dma;
  7437. uint16_t max_ddbs;
  7438. uint16_t idx = 0;
  7439. int ret = QLA_SUCCESS;
  7440. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  7441. sizeof(*fw_ddb_entry),
  7442. &fw_ddb_entry_dma, GFP_KERNEL);
  7443. if (!fw_ddb_entry) {
  7444. DEBUG2(ql4_printk(KERN_ERR, ha,
  7445. "%s: Unable to allocate dma buffer\n",
  7446. __func__));
  7447. return -ENOMEM;
  7448. }
  7449. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  7450. MAX_DEV_DB_ENTRIES;
  7451. for (idx = 0; idx < max_ddbs; idx++) {
  7452. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
  7453. idx))
  7454. continue;
  7455. ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
  7456. if (ret) {
  7457. ret = -EIO;
  7458. break;
  7459. }
  7460. }
  7461. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
  7462. fw_ddb_entry_dma);
  7463. return ret;
  7464. }
  7465. static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
  7466. {
  7467. iscsi_destroy_all_flashnode(ha->host);
  7468. }
  7469. /**
  7470. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  7471. * @ha: pointer to adapter structure
  7472. * @is_reset: Is this init path or reset path
  7473. *
  7474. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  7475. * using connection open, then create the list of normal targets (nt)
  7476. * from firmware DDBs. Based on the list of nt setup session and connection
  7477. * objects.
  7478. **/
  7479. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  7480. {
  7481. uint16_t tmo = 0;
  7482. struct list_head list_st, list_nt;
  7483. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  7484. unsigned long wtime;
  7485. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  7486. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  7487. ha->is_reset = is_reset;
  7488. return;
  7489. }
  7490. INIT_LIST_HEAD(&list_st);
  7491. INIT_LIST_HEAD(&list_nt);
  7492. qla4xxx_build_st_list(ha, &list_st);
  7493. /* Before issuing conn open mbox, ensure all IPs states are configured
  7494. * Note, conn open fails if IPs are not configured
  7495. */
  7496. qla4xxx_wait_for_ip_configuration(ha);
  7497. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  7498. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  7499. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  7500. }
  7501. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  7502. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  7503. (ha->def_timeout < LOGIN_TOV * 10) ?
  7504. ha->def_timeout : LOGIN_TOV);
  7505. DEBUG2(ql4_printk(KERN_INFO, ha,
  7506. "Default time to wait for build ddb %d\n", tmo));
  7507. wtime = jiffies + (HZ * tmo);
  7508. do {
  7509. if (list_empty(&list_st))
  7510. break;
  7511. qla4xxx_remove_failed_ddb(ha, &list_st);
  7512. schedule_timeout_uninterruptible(HZ / 10);
  7513. } while (time_after(wtime, jiffies));
  7514. qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
  7515. qla4xxx_free_ddb_list(&list_st);
  7516. qla4xxx_free_ddb_list(&list_nt);
  7517. qla4xxx_free_ddb_index(ha);
  7518. }
  7519. /**
  7520. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  7521. * response.
  7522. * @ha: pointer to adapter structure
  7523. *
  7524. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  7525. * set in DDB and we will wait for login response of boot targets during
  7526. * probe.
  7527. **/
  7528. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  7529. {
  7530. struct ddb_entry *ddb_entry;
  7531. struct dev_db_entry *fw_ddb_entry = NULL;
  7532. dma_addr_t fw_ddb_entry_dma;
  7533. unsigned long wtime;
  7534. uint32_t ddb_state;
  7535. int max_ddbs, idx, ret;
  7536. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  7537. MAX_DEV_DB_ENTRIES;
  7538. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7539. &fw_ddb_entry_dma, GFP_KERNEL);
  7540. if (!fw_ddb_entry) {
  7541. ql4_printk(KERN_ERR, ha,
  7542. "%s: Unable to allocate dma buffer\n", __func__);
  7543. goto exit_login_resp;
  7544. }
  7545. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  7546. for (idx = 0; idx < max_ddbs; idx++) {
  7547. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  7548. if (ddb_entry == NULL)
  7549. continue;
  7550. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  7551. DEBUG2(ql4_printk(KERN_INFO, ha,
  7552. "%s: DDB index [%d]\n", __func__,
  7553. ddb_entry->fw_ddb_index));
  7554. do {
  7555. ret = qla4xxx_get_fwddb_entry(ha,
  7556. ddb_entry->fw_ddb_index,
  7557. fw_ddb_entry, fw_ddb_entry_dma,
  7558. NULL, NULL, &ddb_state, NULL,
  7559. NULL, NULL);
  7560. if (ret == QLA_ERROR)
  7561. goto exit_login_resp;
  7562. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  7563. (ddb_state == DDB_DS_SESSION_FAILED))
  7564. break;
  7565. schedule_timeout_uninterruptible(HZ);
  7566. } while ((time_after(wtime, jiffies)));
  7567. if (!time_after(wtime, jiffies)) {
  7568. DEBUG2(ql4_printk(KERN_INFO, ha,
  7569. "%s: Login response wait timer expired\n",
  7570. __func__));
  7571. goto exit_login_resp;
  7572. }
  7573. }
  7574. }
  7575. exit_login_resp:
  7576. if (fw_ddb_entry)
  7577. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7578. fw_ddb_entry, fw_ddb_entry_dma);
  7579. }
  7580. /**
  7581. * qla4xxx_probe_adapter - callback function to probe HBA
  7582. * @pdev: pointer to pci_dev structure
  7583. * @pci_device_id: pointer to pci_device entry
  7584. *
  7585. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  7586. * It returns zero if successful. It also initializes all data necessary for
  7587. * the driver.
  7588. **/
  7589. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  7590. const struct pci_device_id *ent)
  7591. {
  7592. int ret = -ENODEV, status;
  7593. struct Scsi_Host *host;
  7594. struct scsi_qla_host *ha;
  7595. uint8_t init_retry_count = 0;
  7596. char buf[34];
  7597. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  7598. uint32_t dev_state;
  7599. if (pci_enable_device(pdev))
  7600. return -1;
  7601. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  7602. if (host == NULL) {
  7603. printk(KERN_WARNING
  7604. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  7605. goto probe_disable_device;
  7606. }
  7607. /* Clear our data area */
  7608. ha = to_qla_host(host);
  7609. memset(ha, 0, sizeof(*ha));
  7610. /* Save the information from PCI BIOS. */
  7611. ha->pdev = pdev;
  7612. ha->host = host;
  7613. ha->host_no = host->host_no;
  7614. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  7615. pci_enable_pcie_error_reporting(pdev);
  7616. /* Setup Runtime configurable options */
  7617. if (is_qla8022(ha)) {
  7618. ha->isp_ops = &qla4_82xx_isp_ops;
  7619. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  7620. ha->qdr_sn_window = -1;
  7621. ha->ddr_mn_window = -1;
  7622. ha->curr_window = 255;
  7623. nx_legacy_intr = &legacy_intr[ha->func_num];
  7624. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  7625. ha->nx_legacy_intr.tgt_status_reg =
  7626. nx_legacy_intr->tgt_status_reg;
  7627. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  7628. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  7629. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  7630. ha->isp_ops = &qla4_83xx_isp_ops;
  7631. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  7632. } else {
  7633. ha->isp_ops = &qla4xxx_isp_ops;
  7634. }
  7635. if (is_qla80XX(ha)) {
  7636. rwlock_init(&ha->hw_lock);
  7637. ha->pf_bit = ha->func_num << 16;
  7638. /* Set EEH reset type to fundamental if required by hba */
  7639. pdev->needs_freset = 1;
  7640. }
  7641. /* Configure PCI I/O space. */
  7642. ret = ha->isp_ops->iospace_config(ha);
  7643. if (ret)
  7644. goto probe_failed_ioconfig;
  7645. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  7646. pdev->device, pdev->irq, ha->reg);
  7647. qla4xxx_config_dma_addressing(ha);
  7648. /* Initialize lists and spinlocks. */
  7649. INIT_LIST_HEAD(&ha->free_srb_q);
  7650. mutex_init(&ha->mbox_sem);
  7651. mutex_init(&ha->chap_sem);
  7652. init_completion(&ha->mbx_intr_comp);
  7653. init_completion(&ha->disable_acb_comp);
  7654. init_completion(&ha->idc_comp);
  7655. init_completion(&ha->link_up_comp);
  7656. init_completion(&ha->disable_acb_comp);
  7657. spin_lock_init(&ha->hardware_lock);
  7658. spin_lock_init(&ha->work_lock);
  7659. /* Initialize work list */
  7660. INIT_LIST_HEAD(&ha->work_list);
  7661. /* Allocate dma buffers */
  7662. if (qla4xxx_mem_alloc(ha)) {
  7663. ql4_printk(KERN_WARNING, ha,
  7664. "[ERROR] Failed to allocate memory for adapter\n");
  7665. ret = -ENOMEM;
  7666. goto probe_failed;
  7667. }
  7668. host->cmd_per_lun = 3;
  7669. host->max_channel = 0;
  7670. host->max_lun = MAX_LUNS - 1;
  7671. host->max_id = MAX_TARGETS;
  7672. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  7673. host->can_queue = MAX_SRBS ;
  7674. host->transportt = qla4xxx_scsi_transport;
  7675. pci_set_drvdata(pdev, ha);
  7676. ret = scsi_add_host(host, &pdev->dev);
  7677. if (ret)
  7678. goto probe_failed;
  7679. if (is_qla80XX(ha))
  7680. qla4_8xxx_get_flash_info(ha);
  7681. if (is_qla8032(ha) || is_qla8042(ha)) {
  7682. qla4_83xx_read_reset_template(ha);
  7683. /*
  7684. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  7685. * If DONRESET_BIT0 is set, drivers should not set dev_state
  7686. * to NEED_RESET. But if NEED_RESET is set, drivers should
  7687. * should honor the reset.
  7688. */
  7689. if (ql4xdontresethba == 1)
  7690. qla4_83xx_set_idc_dontreset(ha);
  7691. }
  7692. /*
  7693. * Initialize the Host adapter request/response queues and
  7694. * firmware
  7695. * NOTE: interrupts enabled upon successful completion
  7696. */
  7697. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  7698. /* Dont retry adapter initialization if IRQ allocation failed */
  7699. if (is_qla80XX(ha) && (status == QLA_ERROR))
  7700. goto skip_retry_init;
  7701. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  7702. init_retry_count++ < MAX_INIT_RETRIES) {
  7703. if (is_qla80XX(ha)) {
  7704. ha->isp_ops->idc_lock(ha);
  7705. dev_state = qla4_8xxx_rd_direct(ha,
  7706. QLA8XXX_CRB_DEV_STATE);
  7707. ha->isp_ops->idc_unlock(ha);
  7708. if (dev_state == QLA8XXX_DEV_FAILED) {
  7709. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  7710. "initialize adapter. H/W is in failed state\n",
  7711. __func__);
  7712. break;
  7713. }
  7714. }
  7715. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  7716. "(%d)\n", __func__, init_retry_count));
  7717. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  7718. continue;
  7719. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  7720. if (is_qla80XX(ha) && (status == QLA_ERROR)) {
  7721. if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
  7722. goto skip_retry_init;
  7723. }
  7724. }
  7725. skip_retry_init:
  7726. if (!test_bit(AF_ONLINE, &ha->flags)) {
  7727. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  7728. if ((is_qla8022(ha) && ql4xdontresethba) ||
  7729. ((is_qla8032(ha) || is_qla8042(ha)) &&
  7730. qla4_83xx_idc_dontreset(ha))) {
  7731. /* Put the device in failed state. */
  7732. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  7733. ha->isp_ops->idc_lock(ha);
  7734. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7735. QLA8XXX_DEV_FAILED);
  7736. ha->isp_ops->idc_unlock(ha);
  7737. }
  7738. ret = -ENODEV;
  7739. goto remove_host;
  7740. }
  7741. /* Startup the kernel thread for this host adapter. */
  7742. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  7743. "qla4xxx_dpc\n", __func__));
  7744. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  7745. ha->dpc_thread = create_singlethread_workqueue(buf);
  7746. if (!ha->dpc_thread) {
  7747. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  7748. ret = -ENODEV;
  7749. goto remove_host;
  7750. }
  7751. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  7752. ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
  7753. ha->host_no);
  7754. if (!ha->task_wq) {
  7755. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  7756. ret = -ENODEV;
  7757. goto remove_host;
  7758. }
  7759. /*
  7760. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  7761. * (which is called indirectly by qla4xxx_initialize_adapter),
  7762. * so that irqs will be registered after crbinit but before
  7763. * mbx_intr_enable.
  7764. */
  7765. if (is_qla40XX(ha)) {
  7766. ret = qla4xxx_request_irqs(ha);
  7767. if (ret) {
  7768. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  7769. "interrupt %d already in use.\n", pdev->irq);
  7770. goto remove_host;
  7771. }
  7772. }
  7773. pci_save_state(ha->pdev);
  7774. ha->isp_ops->enable_intrs(ha);
  7775. /* Start timer thread. */
  7776. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  7777. set_bit(AF_INIT_DONE, &ha->flags);
  7778. qla4_8xxx_alloc_sysfs_attr(ha);
  7779. printk(KERN_INFO
  7780. " QLogic iSCSI HBA Driver version: %s\n"
  7781. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  7782. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  7783. ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
  7784. ha->fw_info.fw_patch, ha->fw_info.fw_build);
  7785. /* Set the driver version */
  7786. if (is_qla80XX(ha))
  7787. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  7788. if (qla4xxx_setup_boot_info(ha))
  7789. ql4_printk(KERN_ERR, ha,
  7790. "%s: No iSCSI boot target configured\n", __func__);
  7791. set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
  7792. /* Perform the build ddb list and login to each */
  7793. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  7794. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  7795. qla4xxx_wait_login_resp_boot_tgt(ha);
  7796. qla4xxx_create_chap_list(ha);
  7797. qla4xxx_create_ifaces(ha);
  7798. return 0;
  7799. remove_host:
  7800. scsi_remove_host(ha->host);
  7801. probe_failed:
  7802. qla4xxx_free_adapter(ha);
  7803. probe_failed_ioconfig:
  7804. pci_disable_pcie_error_reporting(pdev);
  7805. scsi_host_put(ha->host);
  7806. probe_disable_device:
  7807. pci_disable_device(pdev);
  7808. return ret;
  7809. }
  7810. /**
  7811. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  7812. * @ha: pointer to adapter structure
  7813. *
  7814. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  7815. * so that the other port will not re-initialize while in the process of
  7816. * removing the ha due to driver unload or hba hotplug.
  7817. **/
  7818. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  7819. {
  7820. struct scsi_qla_host *other_ha = NULL;
  7821. struct pci_dev *other_pdev = NULL;
  7822. int fn = ISP4XXX_PCI_FN_2;
  7823. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  7824. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  7825. fn = ISP4XXX_PCI_FN_1;
  7826. other_pdev =
  7827. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  7828. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  7829. fn));
  7830. /* Get other_ha if other_pdev is valid and state is enable*/
  7831. if (other_pdev) {
  7832. if (atomic_read(&other_pdev->enable_cnt)) {
  7833. other_ha = pci_get_drvdata(other_pdev);
  7834. if (other_ha) {
  7835. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  7836. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  7837. "Prevent %s reinit\n", __func__,
  7838. dev_name(&other_ha->pdev->dev)));
  7839. }
  7840. }
  7841. pci_dev_put(other_pdev);
  7842. }
  7843. }
  7844. static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
  7845. struct ddb_entry *ddb_entry)
  7846. {
  7847. struct dev_db_entry *fw_ddb_entry = NULL;
  7848. dma_addr_t fw_ddb_entry_dma;
  7849. unsigned long wtime;
  7850. uint32_t ddb_state;
  7851. int options;
  7852. int status;
  7853. options = LOGOUT_OPTION_CLOSE_SESSION;
  7854. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
  7855. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  7856. goto clear_ddb;
  7857. }
  7858. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7859. &fw_ddb_entry_dma, GFP_KERNEL);
  7860. if (!fw_ddb_entry) {
  7861. ql4_printk(KERN_ERR, ha,
  7862. "%s: Unable to allocate dma buffer\n", __func__);
  7863. goto clear_ddb;
  7864. }
  7865. wtime = jiffies + (HZ * LOGOUT_TOV);
  7866. do {
  7867. status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  7868. fw_ddb_entry, fw_ddb_entry_dma,
  7869. NULL, NULL, &ddb_state, NULL,
  7870. NULL, NULL);
  7871. if (status == QLA_ERROR)
  7872. goto free_ddb;
  7873. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  7874. (ddb_state == DDB_DS_SESSION_FAILED))
  7875. goto free_ddb;
  7876. schedule_timeout_uninterruptible(HZ);
  7877. } while ((time_after(wtime, jiffies)));
  7878. free_ddb:
  7879. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7880. fw_ddb_entry, fw_ddb_entry_dma);
  7881. clear_ddb:
  7882. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  7883. }
  7884. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  7885. {
  7886. struct ddb_entry *ddb_entry;
  7887. int idx;
  7888. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  7889. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  7890. if ((ddb_entry != NULL) &&
  7891. (ddb_entry->ddb_type == FLASH_DDB)) {
  7892. qla4xxx_destroy_ddb(ha, ddb_entry);
  7893. /*
  7894. * we have decremented the reference count of the driver
  7895. * when we setup the session to have the driver unload
  7896. * to be seamless without actually destroying the
  7897. * session
  7898. **/
  7899. try_module_get(qla4xxx_iscsi_transport.owner);
  7900. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  7901. qla4xxx_free_ddb(ha, ddb_entry);
  7902. iscsi_session_teardown(ddb_entry->sess);
  7903. }
  7904. }
  7905. }
  7906. /**
  7907. * qla4xxx_remove_adapter - callback function to remove adapter.
  7908. * @pci_dev: PCI device pointer
  7909. **/
  7910. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  7911. {
  7912. struct scsi_qla_host *ha;
  7913. /*
  7914. * If the PCI device is disabled then it means probe_adapter had
  7915. * failed and resources already cleaned up on probe_adapter exit.
  7916. */
  7917. if (!pci_is_enabled(pdev))
  7918. return;
  7919. ha = pci_get_drvdata(pdev);
  7920. if (is_qla40XX(ha))
  7921. qla4xxx_prevent_other_port_reinit(ha);
  7922. /* destroy iface from sysfs */
  7923. qla4xxx_destroy_ifaces(ha);
  7924. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  7925. iscsi_boot_destroy_kset(ha->boot_kset);
  7926. qla4xxx_destroy_fw_ddb_session(ha);
  7927. qla4_8xxx_free_sysfs_attr(ha);
  7928. qla4xxx_sysfs_ddb_remove(ha);
  7929. scsi_remove_host(ha->host);
  7930. qla4xxx_free_adapter(ha);
  7931. scsi_host_put(ha->host);
  7932. pci_disable_pcie_error_reporting(pdev);
  7933. pci_disable_device(pdev);
  7934. }
  7935. /**
  7936. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  7937. * @ha: HA context
  7938. *
  7939. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  7940. * supported addressing method.
  7941. */
  7942. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  7943. {
  7944. int retval;
  7945. /* Update our PCI device dma_mask for full 64 bit mask */
  7946. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  7947. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  7948. dev_dbg(&ha->pdev->dev,
  7949. "Failed to set 64 bit PCI consistent mask; "
  7950. "using 32 bit.\n");
  7951. retval = pci_set_consistent_dma_mask(ha->pdev,
  7952. DMA_BIT_MASK(32));
  7953. }
  7954. } else
  7955. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  7956. }
  7957. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  7958. {
  7959. struct iscsi_cls_session *cls_sess;
  7960. struct iscsi_session *sess;
  7961. struct ddb_entry *ddb;
  7962. int queue_depth = QL4_DEF_QDEPTH;
  7963. cls_sess = starget_to_session(sdev->sdev_target);
  7964. sess = cls_sess->dd_data;
  7965. ddb = sess->dd_data;
  7966. sdev->hostdata = ddb;
  7967. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  7968. queue_depth = ql4xmaxqdepth;
  7969. scsi_change_queue_depth(sdev, queue_depth);
  7970. return 0;
  7971. }
  7972. /**
  7973. * qla4xxx_del_from_active_array - returns an active srb
  7974. * @ha: Pointer to host adapter structure.
  7975. * @index: index into the active_array
  7976. *
  7977. * This routine removes and returns the srb at the specified index
  7978. **/
  7979. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  7980. uint32_t index)
  7981. {
  7982. struct srb *srb = NULL;
  7983. struct scsi_cmnd *cmd = NULL;
  7984. cmd = scsi_host_find_tag(ha->host, index);
  7985. if (!cmd)
  7986. return srb;
  7987. srb = (struct srb *)CMD_SP(cmd);
  7988. if (!srb)
  7989. return srb;
  7990. /* update counters */
  7991. if (srb->flags & SRB_DMA_VALID) {
  7992. ha->iocb_cnt -= srb->iocb_cnt;
  7993. if (srb->cmd)
  7994. srb->cmd->host_scribble =
  7995. (unsigned char *)(unsigned long) MAX_SRBS;
  7996. }
  7997. return srb;
  7998. }
  7999. /**
  8000. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  8001. * @ha: Pointer to host adapter structure.
  8002. * @cmd: Scsi Command to wait on.
  8003. *
  8004. * This routine waits for the command to be returned by the Firmware
  8005. * for some max time.
  8006. **/
  8007. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  8008. struct scsi_cmnd *cmd)
  8009. {
  8010. int done = 0;
  8011. struct srb *rp;
  8012. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  8013. int ret = SUCCESS;
  8014. /* Dont wait on command if PCI error is being handled
  8015. * by PCI AER driver
  8016. */
  8017. if (unlikely(pci_channel_offline(ha->pdev)) ||
  8018. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  8019. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  8020. ha->host_no, __func__);
  8021. return ret;
  8022. }
  8023. do {
  8024. /* Checking to see if its returned to OS */
  8025. rp = (struct srb *) CMD_SP(cmd);
  8026. if (rp == NULL) {
  8027. done++;
  8028. break;
  8029. }
  8030. msleep(2000);
  8031. } while (max_wait_time--);
  8032. return done;
  8033. }
  8034. /**
  8035. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  8036. * @ha: Pointer to host adapter structure
  8037. **/
  8038. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  8039. {
  8040. unsigned long wait_online;
  8041. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  8042. while (time_before(jiffies, wait_online)) {
  8043. if (adapter_up(ha))
  8044. return QLA_SUCCESS;
  8045. msleep(2000);
  8046. }
  8047. return QLA_ERROR;
  8048. }
  8049. /**
  8050. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  8051. * @ha: pointer to HBA
  8052. * @t: target id
  8053. * @l: lun id
  8054. *
  8055. * This function waits for all outstanding commands to a lun to complete. It
  8056. * returns 0 if all pending commands are returned and 1 otherwise.
  8057. **/
  8058. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  8059. struct scsi_target *stgt,
  8060. struct scsi_device *sdev)
  8061. {
  8062. int cnt;
  8063. int status = 0;
  8064. struct scsi_cmnd *cmd;
  8065. /*
  8066. * Waiting for all commands for the designated target or dev
  8067. * in the active array
  8068. */
  8069. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  8070. cmd = scsi_host_find_tag(ha->host, cnt);
  8071. if (cmd && stgt == scsi_target(cmd->device) &&
  8072. (!sdev || sdev == cmd->device)) {
  8073. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  8074. status++;
  8075. break;
  8076. }
  8077. }
  8078. }
  8079. return status;
  8080. }
  8081. /**
  8082. * qla4xxx_eh_abort - callback for abort task.
  8083. * @cmd: Pointer to Linux's SCSI command structure
  8084. *
  8085. * This routine is called by the Linux OS to abort the specified
  8086. * command.
  8087. **/
  8088. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  8089. {
  8090. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8091. unsigned int id = cmd->device->id;
  8092. uint64_t lun = cmd->device->lun;
  8093. unsigned long flags;
  8094. struct srb *srb = NULL;
  8095. int ret = SUCCESS;
  8096. int wait = 0;
  8097. ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
  8098. ha->host_no, id, lun, cmd, cmd->cmnd[0]);
  8099. spin_lock_irqsave(&ha->hardware_lock, flags);
  8100. srb = (struct srb *) CMD_SP(cmd);
  8101. if (!srb) {
  8102. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  8103. ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
  8104. ha->host_no, id, lun);
  8105. return SUCCESS;
  8106. }
  8107. kref_get(&srb->srb_ref);
  8108. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  8109. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  8110. DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
  8111. ha->host_no, id, lun));
  8112. ret = FAILED;
  8113. } else {
  8114. DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
  8115. ha->host_no, id, lun));
  8116. wait = 1;
  8117. }
  8118. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  8119. /* Wait for command to complete */
  8120. if (wait) {
  8121. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  8122. DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
  8123. ha->host_no, id, lun));
  8124. ret = FAILED;
  8125. }
  8126. }
  8127. ql4_printk(KERN_INFO, ha,
  8128. "scsi%ld:%d:%llu: Abort command - %s\n",
  8129. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  8130. return ret;
  8131. }
  8132. /**
  8133. * qla4xxx_eh_device_reset - callback for target reset.
  8134. * @cmd: Pointer to Linux's SCSI command structure
  8135. *
  8136. * This routine is called by the Linux OS to reset all luns on the
  8137. * specified target.
  8138. **/
  8139. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  8140. {
  8141. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8142. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  8143. int ret = FAILED, stat;
  8144. if (!ddb_entry)
  8145. return ret;
  8146. ret = iscsi_block_scsi_eh(cmd);
  8147. if (ret)
  8148. return ret;
  8149. ret = FAILED;
  8150. ql4_printk(KERN_INFO, ha,
  8151. "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
  8152. cmd->device->channel, cmd->device->id, cmd->device->lun);
  8153. DEBUG2(printk(KERN_INFO
  8154. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  8155. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  8156. cmd, jiffies, cmd->request->timeout / HZ,
  8157. ha->dpc_flags, cmd->result, cmd->allowed));
  8158. /* FIXME: wait for hba to go online */
  8159. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  8160. if (stat != QLA_SUCCESS) {
  8161. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  8162. goto eh_dev_reset_done;
  8163. }
  8164. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  8165. cmd->device)) {
  8166. ql4_printk(KERN_INFO, ha,
  8167. "DEVICE RESET FAILED - waiting for "
  8168. "commands.\n");
  8169. goto eh_dev_reset_done;
  8170. }
  8171. /* Send marker. */
  8172. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  8173. MM_LUN_RESET) != QLA_SUCCESS)
  8174. goto eh_dev_reset_done;
  8175. ql4_printk(KERN_INFO, ha,
  8176. "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
  8177. ha->host_no, cmd->device->channel, cmd->device->id,
  8178. cmd->device->lun);
  8179. ret = SUCCESS;
  8180. eh_dev_reset_done:
  8181. return ret;
  8182. }
  8183. /**
  8184. * qla4xxx_eh_target_reset - callback for target reset.
  8185. * @cmd: Pointer to Linux's SCSI command structure
  8186. *
  8187. * This routine is called by the Linux OS to reset the target.
  8188. **/
  8189. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  8190. {
  8191. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8192. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  8193. int stat, ret;
  8194. if (!ddb_entry)
  8195. return FAILED;
  8196. ret = iscsi_block_scsi_eh(cmd);
  8197. if (ret)
  8198. return ret;
  8199. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8200. "WARM TARGET RESET ISSUED.\n");
  8201. DEBUG2(printk(KERN_INFO
  8202. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  8203. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  8204. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  8205. ha->dpc_flags, cmd->result, cmd->allowed));
  8206. stat = qla4xxx_reset_target(ha, ddb_entry);
  8207. if (stat != QLA_SUCCESS) {
  8208. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8209. "WARM TARGET RESET FAILED.\n");
  8210. return FAILED;
  8211. }
  8212. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  8213. NULL)) {
  8214. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8215. "WARM TARGET DEVICE RESET FAILED - "
  8216. "waiting for commands.\n");
  8217. return FAILED;
  8218. }
  8219. /* Send marker. */
  8220. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  8221. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  8222. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8223. "WARM TARGET DEVICE RESET FAILED - "
  8224. "marker iocb failed.\n");
  8225. return FAILED;
  8226. }
  8227. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8228. "WARM TARGET RESET SUCCEEDED.\n");
  8229. return SUCCESS;
  8230. }
  8231. /**
  8232. * qla4xxx_is_eh_active - check if error handler is running
  8233. * @shost: Pointer to SCSI Host struct
  8234. *
  8235. * This routine finds that if reset host is called in EH
  8236. * scenario or from some application like sg_reset
  8237. **/
  8238. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  8239. {
  8240. if (shost->shost_state == SHOST_RECOVERY)
  8241. return 1;
  8242. return 0;
  8243. }
  8244. /**
  8245. * qla4xxx_eh_host_reset - kernel callback
  8246. * @cmd: Pointer to Linux's SCSI command structure
  8247. *
  8248. * This routine is invoked by the Linux kernel to perform fatal error
  8249. * recovery on the specified adapter.
  8250. **/
  8251. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  8252. {
  8253. int return_status = FAILED;
  8254. struct scsi_qla_host *ha;
  8255. ha = to_qla_host(cmd->device->host);
  8256. if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
  8257. qla4_83xx_set_idc_dontreset(ha);
  8258. /*
  8259. * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
  8260. * protocol drivers, we should not set device_state to NEED_RESET
  8261. */
  8262. if (ql4xdontresethba ||
  8263. ((is_qla8032(ha) || is_qla8042(ha)) &&
  8264. qla4_83xx_idc_dontreset(ha))) {
  8265. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  8266. ha->host_no, __func__));
  8267. /* Clear outstanding srb in queues */
  8268. if (qla4xxx_is_eh_active(cmd->device->host))
  8269. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  8270. return FAILED;
  8271. }
  8272. ql4_printk(KERN_INFO, ha,
  8273. "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
  8274. cmd->device->channel, cmd->device->id, cmd->device->lun);
  8275. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  8276. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  8277. "DEAD.\n", ha->host_no, cmd->device->channel,
  8278. __func__));
  8279. return FAILED;
  8280. }
  8281. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8282. if (is_qla80XX(ha))
  8283. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  8284. else
  8285. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  8286. }
  8287. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  8288. return_status = SUCCESS;
  8289. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  8290. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  8291. return return_status;
  8292. }
  8293. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  8294. {
  8295. uint32_t mbox_cmd[MBOX_REG_COUNT];
  8296. uint32_t mbox_sts[MBOX_REG_COUNT];
  8297. struct addr_ctrl_blk_def *acb = NULL;
  8298. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  8299. int rval = QLA_SUCCESS;
  8300. dma_addr_t acb_dma;
  8301. acb = dma_alloc_coherent(&ha->pdev->dev,
  8302. sizeof(struct addr_ctrl_blk_def),
  8303. &acb_dma, GFP_KERNEL);
  8304. if (!acb) {
  8305. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  8306. __func__);
  8307. rval = -ENOMEM;
  8308. goto exit_port_reset;
  8309. }
  8310. memset(acb, 0, acb_len);
  8311. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  8312. if (rval != QLA_SUCCESS) {
  8313. rval = -EIO;
  8314. goto exit_free_acb;
  8315. }
  8316. rval = qla4xxx_disable_acb(ha);
  8317. if (rval != QLA_SUCCESS) {
  8318. rval = -EIO;
  8319. goto exit_free_acb;
  8320. }
  8321. wait_for_completion_timeout(&ha->disable_acb_comp,
  8322. DISABLE_ACB_TOV * HZ);
  8323. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  8324. if (rval != QLA_SUCCESS) {
  8325. rval = -EIO;
  8326. goto exit_free_acb;
  8327. }
  8328. exit_free_acb:
  8329. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  8330. acb, acb_dma);
  8331. exit_port_reset:
  8332. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  8333. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  8334. return rval;
  8335. }
  8336. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  8337. {
  8338. struct scsi_qla_host *ha = to_qla_host(shost);
  8339. int rval = QLA_SUCCESS;
  8340. uint32_t idc_ctrl;
  8341. if (ql4xdontresethba) {
  8342. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  8343. __func__));
  8344. rval = -EPERM;
  8345. goto exit_host_reset;
  8346. }
  8347. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  8348. goto recover_adapter;
  8349. switch (reset_type) {
  8350. case SCSI_ADAPTER_RESET:
  8351. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  8352. break;
  8353. case SCSI_FIRMWARE_RESET:
  8354. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8355. if (is_qla80XX(ha))
  8356. /* set firmware context reset */
  8357. set_bit(DPC_RESET_HA_FW_CONTEXT,
  8358. &ha->dpc_flags);
  8359. else {
  8360. rval = qla4xxx_context_reset(ha);
  8361. goto exit_host_reset;
  8362. }
  8363. }
  8364. break;
  8365. }
  8366. recover_adapter:
  8367. /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
  8368. * reset is issued by application */
  8369. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  8370. test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8371. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  8372. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  8373. (idc_ctrl | GRACEFUL_RESET_BIT1));
  8374. }
  8375. rval = qla4xxx_recover_adapter(ha);
  8376. if (rval != QLA_SUCCESS) {
  8377. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  8378. __func__));
  8379. rval = -EIO;
  8380. }
  8381. exit_host_reset:
  8382. return rval;
  8383. }
  8384. /* PCI AER driver recovers from all correctable errors w/o
  8385. * driver intervention. For uncorrectable errors PCI AER
  8386. * driver calls the following device driver's callbacks
  8387. *
  8388. * - Fatal Errors - link_reset
  8389. * - Non-Fatal Errors - driver's pci_error_detected() which
  8390. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  8391. *
  8392. * PCI AER driver calls
  8393. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  8394. * returns RECOVERED or NEED_RESET if fw_hung
  8395. * NEED_RESET - driver's slot_reset()
  8396. * DISCONNECT - device is dead & cannot recover
  8397. * RECOVERED - driver's pci_resume()
  8398. */
  8399. static pci_ers_result_t
  8400. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  8401. {
  8402. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8403. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  8404. ha->host_no, __func__, state);
  8405. if (!is_aer_supported(ha))
  8406. return PCI_ERS_RESULT_NONE;
  8407. switch (state) {
  8408. case pci_channel_io_normal:
  8409. clear_bit(AF_EEH_BUSY, &ha->flags);
  8410. return PCI_ERS_RESULT_CAN_RECOVER;
  8411. case pci_channel_io_frozen:
  8412. set_bit(AF_EEH_BUSY, &ha->flags);
  8413. qla4xxx_mailbox_premature_completion(ha);
  8414. qla4xxx_free_irqs(ha);
  8415. pci_disable_device(pdev);
  8416. /* Return back all IOs */
  8417. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  8418. return PCI_ERS_RESULT_NEED_RESET;
  8419. case pci_channel_io_perm_failure:
  8420. set_bit(AF_EEH_BUSY, &ha->flags);
  8421. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  8422. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  8423. return PCI_ERS_RESULT_DISCONNECT;
  8424. }
  8425. return PCI_ERS_RESULT_NEED_RESET;
  8426. }
  8427. /**
  8428. * qla4xxx_pci_mmio_enabled() gets called if
  8429. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  8430. * and read/write to the device still works.
  8431. **/
  8432. static pci_ers_result_t
  8433. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  8434. {
  8435. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8436. if (!is_aer_supported(ha))
  8437. return PCI_ERS_RESULT_NONE;
  8438. return PCI_ERS_RESULT_RECOVERED;
  8439. }
  8440. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  8441. {
  8442. uint32_t rval = QLA_ERROR;
  8443. int fn;
  8444. struct pci_dev *other_pdev = NULL;
  8445. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  8446. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  8447. if (test_bit(AF_ONLINE, &ha->flags)) {
  8448. clear_bit(AF_ONLINE, &ha->flags);
  8449. clear_bit(AF_LINK_UP, &ha->flags);
  8450. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  8451. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  8452. }
  8453. fn = PCI_FUNC(ha->pdev->devfn);
  8454. if (is_qla8022(ha)) {
  8455. while (fn > 0) {
  8456. fn--;
  8457. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
  8458. ha->host_no, __func__, fn);
  8459. /* Get the pci device given the domain, bus,
  8460. * slot/function number */
  8461. other_pdev = pci_get_domain_bus_and_slot(
  8462. pci_domain_nr(ha->pdev->bus),
  8463. ha->pdev->bus->number,
  8464. PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  8465. fn));
  8466. if (!other_pdev)
  8467. continue;
  8468. if (atomic_read(&other_pdev->enable_cnt)) {
  8469. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
  8470. ha->host_no, __func__, fn);
  8471. pci_dev_put(other_pdev);
  8472. break;
  8473. }
  8474. pci_dev_put(other_pdev);
  8475. }
  8476. } else {
  8477. /* this case is meant for ISP83xx/ISP84xx only */
  8478. if (qla4_83xx_can_perform_reset(ha)) {
  8479. /* reset fn as iSCSI is going to perform the reset */
  8480. fn = 0;
  8481. }
  8482. }
  8483. /* The first function on the card, the reset owner will
  8484. * start & initialize the firmware. The other functions
  8485. * on the card will reset the firmware context
  8486. */
  8487. if (!fn) {
  8488. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  8489. "0x%x is the owner\n", ha->host_no, __func__,
  8490. ha->pdev->devfn);
  8491. ha->isp_ops->idc_lock(ha);
  8492. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8493. QLA8XXX_DEV_COLD);
  8494. ha->isp_ops->idc_unlock(ha);
  8495. rval = qla4_8xxx_update_idc_reg(ha);
  8496. if (rval == QLA_ERROR) {
  8497. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  8498. ha->host_no, __func__);
  8499. ha->isp_ops->idc_lock(ha);
  8500. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8501. QLA8XXX_DEV_FAILED);
  8502. ha->isp_ops->idc_unlock(ha);
  8503. goto exit_error_recovery;
  8504. }
  8505. clear_bit(AF_FW_RECOVERY, &ha->flags);
  8506. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  8507. if (rval != QLA_SUCCESS) {
  8508. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  8509. "FAILED\n", ha->host_no, __func__);
  8510. qla4xxx_free_irqs(ha);
  8511. ha->isp_ops->idc_lock(ha);
  8512. qla4_8xxx_clear_drv_active(ha);
  8513. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8514. QLA8XXX_DEV_FAILED);
  8515. ha->isp_ops->idc_unlock(ha);
  8516. } else {
  8517. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  8518. "READY\n", ha->host_no, __func__);
  8519. ha->isp_ops->idc_lock(ha);
  8520. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8521. QLA8XXX_DEV_READY);
  8522. /* Clear driver state register */
  8523. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  8524. qla4_8xxx_set_drv_active(ha);
  8525. ha->isp_ops->idc_unlock(ha);
  8526. ha->isp_ops->enable_intrs(ha);
  8527. }
  8528. } else {
  8529. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  8530. "the reset owner\n", ha->host_no, __func__,
  8531. ha->pdev->devfn);
  8532. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  8533. QLA8XXX_DEV_READY)) {
  8534. clear_bit(AF_FW_RECOVERY, &ha->flags);
  8535. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  8536. if (rval == QLA_SUCCESS)
  8537. ha->isp_ops->enable_intrs(ha);
  8538. else
  8539. qla4xxx_free_irqs(ha);
  8540. ha->isp_ops->idc_lock(ha);
  8541. qla4_8xxx_set_drv_active(ha);
  8542. ha->isp_ops->idc_unlock(ha);
  8543. }
  8544. }
  8545. exit_error_recovery:
  8546. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  8547. return rval;
  8548. }
  8549. static pci_ers_result_t
  8550. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  8551. {
  8552. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  8553. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8554. int rc;
  8555. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  8556. ha->host_no, __func__);
  8557. if (!is_aer_supported(ha))
  8558. return PCI_ERS_RESULT_NONE;
  8559. /* Restore the saved state of PCIe device -
  8560. * BAR registers, PCI Config space, PCIX, MSI,
  8561. * IOV states
  8562. */
  8563. pci_restore_state(pdev);
  8564. /* pci_restore_state() clears the saved_state flag of the device
  8565. * save restored state which resets saved_state flag
  8566. */
  8567. pci_save_state(pdev);
  8568. /* Initialize device or resume if in suspended state */
  8569. rc = pci_enable_device(pdev);
  8570. if (rc) {
  8571. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  8572. "device after reset\n", ha->host_no, __func__);
  8573. goto exit_slot_reset;
  8574. }
  8575. ha->isp_ops->disable_intrs(ha);
  8576. if (is_qla80XX(ha)) {
  8577. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  8578. ret = PCI_ERS_RESULT_RECOVERED;
  8579. goto exit_slot_reset;
  8580. } else
  8581. goto exit_slot_reset;
  8582. }
  8583. exit_slot_reset:
  8584. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  8585. "device after reset\n", ha->host_no, __func__, ret);
  8586. return ret;
  8587. }
  8588. static void
  8589. qla4xxx_pci_resume(struct pci_dev *pdev)
  8590. {
  8591. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8592. int ret;
  8593. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  8594. ha->host_no, __func__);
  8595. ret = qla4xxx_wait_for_hba_online(ha);
  8596. if (ret != QLA_SUCCESS) {
  8597. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  8598. "resume I/O from slot/link_reset\n", ha->host_no,
  8599. __func__);
  8600. }
  8601. pci_cleanup_aer_uncorrect_error_status(pdev);
  8602. clear_bit(AF_EEH_BUSY, &ha->flags);
  8603. }
  8604. static const struct pci_error_handlers qla4xxx_err_handler = {
  8605. .error_detected = qla4xxx_pci_error_detected,
  8606. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  8607. .slot_reset = qla4xxx_pci_slot_reset,
  8608. .resume = qla4xxx_pci_resume,
  8609. };
  8610. static struct pci_device_id qla4xxx_pci_tbl[] = {
  8611. {
  8612. .vendor = PCI_VENDOR_ID_QLOGIC,
  8613. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  8614. .subvendor = PCI_ANY_ID,
  8615. .subdevice = PCI_ANY_ID,
  8616. },
  8617. {
  8618. .vendor = PCI_VENDOR_ID_QLOGIC,
  8619. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  8620. .subvendor = PCI_ANY_ID,
  8621. .subdevice = PCI_ANY_ID,
  8622. },
  8623. {
  8624. .vendor = PCI_VENDOR_ID_QLOGIC,
  8625. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  8626. .subvendor = PCI_ANY_ID,
  8627. .subdevice = PCI_ANY_ID,
  8628. },
  8629. {
  8630. .vendor = PCI_VENDOR_ID_QLOGIC,
  8631. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  8632. .subvendor = PCI_ANY_ID,
  8633. .subdevice = PCI_ANY_ID,
  8634. },
  8635. {
  8636. .vendor = PCI_VENDOR_ID_QLOGIC,
  8637. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  8638. .subvendor = PCI_ANY_ID,
  8639. .subdevice = PCI_ANY_ID,
  8640. },
  8641. {
  8642. .vendor = PCI_VENDOR_ID_QLOGIC,
  8643. .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
  8644. .subvendor = PCI_ANY_ID,
  8645. .subdevice = PCI_ANY_ID,
  8646. },
  8647. {0, 0},
  8648. };
  8649. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  8650. static struct pci_driver qla4xxx_pci_driver = {
  8651. .name = DRIVER_NAME,
  8652. .id_table = qla4xxx_pci_tbl,
  8653. .probe = qla4xxx_probe_adapter,
  8654. .remove = qla4xxx_remove_adapter,
  8655. .err_handler = &qla4xxx_err_handler,
  8656. };
  8657. static int __init qla4xxx_module_init(void)
  8658. {
  8659. int ret;
  8660. if (ql4xqfulltracking)
  8661. qla4xxx_driver_template.track_queue_depth = 1;
  8662. /* Allocate cache for SRBs. */
  8663. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  8664. SLAB_HWCACHE_ALIGN, NULL);
  8665. if (srb_cachep == NULL) {
  8666. printk(KERN_ERR
  8667. "%s: Unable to allocate SRB cache..."
  8668. "Failing load!\n", DRIVER_NAME);
  8669. ret = -ENOMEM;
  8670. goto no_srp_cache;
  8671. }
  8672. /* Derive version string. */
  8673. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  8674. if (ql4xextended_error_logging)
  8675. strcat(qla4xxx_version_str, "-debug");
  8676. qla4xxx_scsi_transport =
  8677. iscsi_register_transport(&qla4xxx_iscsi_transport);
  8678. if (!qla4xxx_scsi_transport){
  8679. ret = -ENODEV;
  8680. goto release_srb_cache;
  8681. }
  8682. ret = pci_register_driver(&qla4xxx_pci_driver);
  8683. if (ret)
  8684. goto unregister_transport;
  8685. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  8686. return 0;
  8687. unregister_transport:
  8688. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  8689. release_srb_cache:
  8690. kmem_cache_destroy(srb_cachep);
  8691. no_srp_cache:
  8692. return ret;
  8693. }
  8694. static void __exit qla4xxx_module_exit(void)
  8695. {
  8696. pci_unregister_driver(&qla4xxx_pci_driver);
  8697. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  8698. kmem_cache_destroy(srb_cachep);
  8699. }
  8700. module_init(qla4xxx_module_init);
  8701. module_exit(qla4xxx_module_exit);
  8702. MODULE_AUTHOR("QLogic Corporation");
  8703. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  8704. MODULE_LICENSE("GPL");
  8705. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);