ql4_os.c 283 KB

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