lpfc_sli.c 361 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_nl.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_logmsg.h"
  41. #include "lpfc_compat.h"
  42. #include "lpfc_debugfs.h"
  43. #include "lpfc_vport.h"
  44. /* There are only four IOCB completion types. */
  45. typedef enum _lpfc_iocb_type {
  46. LPFC_UNKNOWN_IOCB,
  47. LPFC_UNSOL_IOCB,
  48. LPFC_SOL_IOCB,
  49. LPFC_ABORT_IOCB
  50. } lpfc_iocb_type;
  51. /* Provide function prototypes local to this module. */
  52. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  53. uint32_t);
  54. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint8_t *, uint32_t *);
  56. static IOCB_t *
  57. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  58. {
  59. return &iocbq->iocb;
  60. }
  61. /**
  62. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  63. * @q: The Work Queue to operate on.
  64. * @wqe: The work Queue Entry to put on the Work queue.
  65. *
  66. * This routine will copy the contents of @wqe to the next available entry on
  67. * the @q. This function will then ring the Work Queue Doorbell to signal the
  68. * HBA to start processing the Work Queue Entry. This function returns 0 if
  69. * successful. If no entries are available on @q then this function will return
  70. * -ENOMEM.
  71. * The caller is expected to hold the hbalock when calling this routine.
  72. **/
  73. static uint32_t
  74. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  75. {
  76. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  77. struct lpfc_register doorbell;
  78. uint32_t host_index;
  79. /* If the host has not yet processed the next entry then we are done */
  80. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  81. return -ENOMEM;
  82. /* set consumption flag every once in a while */
  83. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  84. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  85. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  86. /* Update the host index before invoking device */
  87. host_index = q->host_index;
  88. q->host_index = ((q->host_index + 1) % q->entry_count);
  89. /* Ring Doorbell */
  90. doorbell.word0 = 0;
  91. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  92. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  93. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  94. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  95. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  96. return 0;
  97. }
  98. /**
  99. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  100. * @q: The Work Queue to operate on.
  101. * @index: The index to advance the hba index to.
  102. *
  103. * This routine will update the HBA index of a queue to reflect consumption of
  104. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  105. * an entry the host calls this function to update the queue's internal
  106. * pointers. This routine returns the number of entries that were consumed by
  107. * the HBA.
  108. **/
  109. static uint32_t
  110. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  111. {
  112. uint32_t released = 0;
  113. if (q->hba_index == index)
  114. return 0;
  115. do {
  116. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  117. released++;
  118. } while (q->hba_index != index);
  119. return released;
  120. }
  121. /**
  122. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  123. * @q: The Mailbox Queue to operate on.
  124. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  125. *
  126. * This routine will copy the contents of @mqe to the next available entry on
  127. * the @q. This function will then ring the Work Queue Doorbell to signal the
  128. * HBA to start processing the Work Queue Entry. This function returns 0 if
  129. * successful. If no entries are available on @q then this function will return
  130. * -ENOMEM.
  131. * The caller is expected to hold the hbalock when calling this routine.
  132. **/
  133. static uint32_t
  134. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  135. {
  136. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  137. struct lpfc_register doorbell;
  138. uint32_t host_index;
  139. /* If the host has not yet processed the next entry then we are done */
  140. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  141. return -ENOMEM;
  142. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  143. /* Save off the mailbox pointer for completion */
  144. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  145. /* Update the host index before invoking device */
  146. host_index = q->host_index;
  147. q->host_index = ((q->host_index + 1) % q->entry_count);
  148. /* Ring Doorbell */
  149. doorbell.word0 = 0;
  150. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  151. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  152. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  153. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  154. return 0;
  155. }
  156. /**
  157. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  158. * @q: The Mailbox Queue to operate on.
  159. *
  160. * This routine will update the HBA index of a queue to reflect consumption of
  161. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  162. * an entry the host calls this function to update the queue's internal
  163. * pointers. This routine returns the number of entries that were consumed by
  164. * the HBA.
  165. **/
  166. static uint32_t
  167. lpfc_sli4_mq_release(struct lpfc_queue *q)
  168. {
  169. /* Clear the mailbox pointer for completion */
  170. q->phba->mbox = NULL;
  171. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  172. return 1;
  173. }
  174. /**
  175. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  176. * @q: The Event Queue to get the first valid EQE from
  177. *
  178. * This routine will get the first valid Event Queue Entry from @q, update
  179. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  180. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  181. * processed, but not popped back to the HBA then this routine will return NULL.
  182. **/
  183. static struct lpfc_eqe *
  184. lpfc_sli4_eq_get(struct lpfc_queue *q)
  185. {
  186. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  187. /* If the next EQE is not valid then we are done */
  188. if (!bf_get(lpfc_eqe_valid, eqe))
  189. return NULL;
  190. /* If the host has not yet processed the next entry then we are done */
  191. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  192. return NULL;
  193. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  194. return eqe;
  195. }
  196. /**
  197. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  198. * @q: The Event Queue that the host has completed processing for.
  199. * @arm: Indicates whether the host wants to arms this CQ.
  200. *
  201. * This routine will mark all Event Queue Entries on @q, from the last
  202. * known completed entry to the last entry that was processed, as completed
  203. * by clearing the valid bit for each completion queue entry. Then it will
  204. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  205. * The internal host index in the @q will be updated by this routine to indicate
  206. * that the host has finished processing the entries. The @arm parameter
  207. * indicates that the queue should be rearmed when ringing the doorbell.
  208. *
  209. * This function will return the number of EQEs that were popped.
  210. **/
  211. uint32_t
  212. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  213. {
  214. uint32_t released = 0;
  215. struct lpfc_eqe *temp_eqe;
  216. struct lpfc_register doorbell;
  217. /* while there are valid entries */
  218. while (q->hba_index != q->host_index) {
  219. temp_eqe = q->qe[q->host_index].eqe;
  220. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  221. released++;
  222. q->host_index = ((q->host_index + 1) % q->entry_count);
  223. }
  224. if (unlikely(released == 0 && !arm))
  225. return 0;
  226. /* ring doorbell for number popped */
  227. doorbell.word0 = 0;
  228. if (arm) {
  229. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  230. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  231. }
  232. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  233. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  234. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  235. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  236. return released;
  237. }
  238. /**
  239. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  240. * @q: The Completion Queue to get the first valid CQE from
  241. *
  242. * This routine will get the first valid Completion Queue Entry from @q, update
  243. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  244. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  245. * processed, but not popped back to the HBA then this routine will return NULL.
  246. **/
  247. static struct lpfc_cqe *
  248. lpfc_sli4_cq_get(struct lpfc_queue *q)
  249. {
  250. struct lpfc_cqe *cqe;
  251. /* If the next CQE is not valid then we are done */
  252. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  253. return NULL;
  254. /* If the host has not yet processed the next entry then we are done */
  255. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  256. return NULL;
  257. cqe = q->qe[q->hba_index].cqe;
  258. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  259. return cqe;
  260. }
  261. /**
  262. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  263. * @q: The Completion Queue that the host has completed processing for.
  264. * @arm: Indicates whether the host wants to arms this CQ.
  265. *
  266. * This routine will mark all Completion queue entries on @q, from the last
  267. * known completed entry to the last entry that was processed, as completed
  268. * by clearing the valid bit for each completion queue entry. Then it will
  269. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  270. * The internal host index in the @q will be updated by this routine to indicate
  271. * that the host has finished processing the entries. The @arm parameter
  272. * indicates that the queue should be rearmed when ringing the doorbell.
  273. *
  274. * This function will return the number of CQEs that were released.
  275. **/
  276. uint32_t
  277. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  278. {
  279. uint32_t released = 0;
  280. struct lpfc_cqe *temp_qe;
  281. struct lpfc_register doorbell;
  282. /* while there are valid entries */
  283. while (q->hba_index != q->host_index) {
  284. temp_qe = q->qe[q->host_index].cqe;
  285. bf_set(lpfc_cqe_valid, temp_qe, 0);
  286. released++;
  287. q->host_index = ((q->host_index + 1) % q->entry_count);
  288. }
  289. if (unlikely(released == 0 && !arm))
  290. return 0;
  291. /* ring doorbell for number popped */
  292. doorbell.word0 = 0;
  293. if (arm)
  294. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  295. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  296. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  297. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  298. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  299. return released;
  300. }
  301. /**
  302. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  303. * @q: The Header Receive Queue to operate on.
  304. * @wqe: The Receive Queue Entry to put on the Receive queue.
  305. *
  306. * This routine will copy the contents of @wqe to the next available entry on
  307. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  308. * HBA to start processing the Receive Queue Entry. This function returns the
  309. * index that the rqe was copied to if successful. If no entries are available
  310. * on @q then this function will return -ENOMEM.
  311. * The caller is expected to hold the hbalock when calling this routine.
  312. **/
  313. static int
  314. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  315. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  316. {
  317. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  318. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  319. struct lpfc_register doorbell;
  320. int put_index = hq->host_index;
  321. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  322. return -EINVAL;
  323. if (hq->host_index != dq->host_index)
  324. return -EINVAL;
  325. /* If the host has not yet processed the next entry then we are done */
  326. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  327. return -EBUSY;
  328. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  329. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  330. /* Update the host index to point to the next slot */
  331. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  332. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  333. /* Ring The Header Receive Queue Doorbell */
  334. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  335. doorbell.word0 = 0;
  336. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  337. LPFC_RQ_POST_BATCH);
  338. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  339. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  340. }
  341. return put_index;
  342. }
  343. /**
  344. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  345. * @q: The Header Receive Queue to operate on.
  346. *
  347. * This routine will update the HBA index of a queue to reflect consumption of
  348. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  349. * consumed an entry the host calls this function to update the queue's
  350. * internal pointers. This routine returns the number of entries that were
  351. * consumed by the HBA.
  352. **/
  353. static uint32_t
  354. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  355. {
  356. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  357. return 0;
  358. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  359. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  360. return 1;
  361. }
  362. /**
  363. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  364. * @phba: Pointer to HBA context object.
  365. * @pring: Pointer to driver SLI ring object.
  366. *
  367. * This function returns pointer to next command iocb entry
  368. * in the command ring. The caller must hold hbalock to prevent
  369. * other threads consume the next command iocb.
  370. * SLI-2/SLI-3 provide different sized iocbs.
  371. **/
  372. static inline IOCB_t *
  373. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  374. {
  375. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  376. pring->cmdidx * phba->iocb_cmd_size);
  377. }
  378. /**
  379. * lpfc_resp_iocb - Get next response iocb entry in the ring
  380. * @phba: Pointer to HBA context object.
  381. * @pring: Pointer to driver SLI ring object.
  382. *
  383. * This function returns pointer to next response iocb entry
  384. * in the response ring. The caller must hold hbalock to make sure
  385. * that no other thread consume the next response iocb.
  386. * SLI-2/SLI-3 provide different sized iocbs.
  387. **/
  388. static inline IOCB_t *
  389. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  390. {
  391. return (IOCB_t *) (((char *) pring->rspringaddr) +
  392. pring->rspidx * phba->iocb_rsp_size);
  393. }
  394. /**
  395. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  396. * @phba: Pointer to HBA context object.
  397. *
  398. * This function is called with hbalock held. This function
  399. * allocates a new driver iocb object from the iocb pool. If the
  400. * allocation is successful, it returns pointer to the newly
  401. * allocated iocb object else it returns NULL.
  402. **/
  403. static struct lpfc_iocbq *
  404. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  405. {
  406. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  407. struct lpfc_iocbq * iocbq = NULL;
  408. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  409. return iocbq;
  410. }
  411. /**
  412. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  413. * @phba: Pointer to HBA context object.
  414. * @xritag: XRI value.
  415. *
  416. * This function clears the sglq pointer from the array of acive
  417. * sglq's. The xritag that is passed in is used to index into the
  418. * array. Before the xritag can be used it needs to be adjusted
  419. * by subtracting the xribase.
  420. *
  421. * Returns sglq ponter = success, NULL = Failure.
  422. **/
  423. static struct lpfc_sglq *
  424. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  425. {
  426. uint16_t adj_xri;
  427. struct lpfc_sglq *sglq;
  428. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  429. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  430. return NULL;
  431. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  432. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  433. return sglq;
  434. }
  435. /**
  436. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  437. * @phba: Pointer to HBA context object.
  438. * @xritag: XRI value.
  439. *
  440. * This function returns the sglq pointer from the array of acive
  441. * sglq's. The xritag that is passed in is used to index into the
  442. * array. Before the xritag can be used it needs to be adjusted
  443. * by subtracting the xribase.
  444. *
  445. * Returns sglq ponter = success, NULL = Failure.
  446. **/
  447. static struct lpfc_sglq *
  448. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  449. {
  450. uint16_t adj_xri;
  451. struct lpfc_sglq *sglq;
  452. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  453. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  454. return NULL;
  455. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  456. return sglq;
  457. }
  458. /**
  459. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  460. * @phba: Pointer to HBA context object.
  461. *
  462. * This function is called with hbalock held. This function
  463. * Gets a new driver sglq object from the sglq list. If the
  464. * list is not empty then it is successful, it returns pointer to the newly
  465. * allocated sglq object else it returns NULL.
  466. **/
  467. static struct lpfc_sglq *
  468. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  469. {
  470. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  471. struct lpfc_sglq *sglq = NULL;
  472. uint16_t adj_xri;
  473. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  474. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  475. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  476. return sglq;
  477. }
  478. /**
  479. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  480. * @phba: Pointer to HBA context object.
  481. *
  482. * This function is called with no lock held. This function
  483. * allocates a new driver iocb object from the iocb pool. If the
  484. * allocation is successful, it returns pointer to the newly
  485. * allocated iocb object else it returns NULL.
  486. **/
  487. struct lpfc_iocbq *
  488. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  489. {
  490. struct lpfc_iocbq * iocbq = NULL;
  491. unsigned long iflags;
  492. spin_lock_irqsave(&phba->hbalock, iflags);
  493. iocbq = __lpfc_sli_get_iocbq(phba);
  494. spin_unlock_irqrestore(&phba->hbalock, iflags);
  495. return iocbq;
  496. }
  497. /**
  498. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  499. * @phba: Pointer to HBA context object.
  500. * @iocbq: Pointer to driver iocb object.
  501. *
  502. * This function is called with hbalock held to release driver
  503. * iocb object to the iocb pool. The iotag in the iocb object
  504. * does not change for each use of the iocb object. This function
  505. * clears all other fields of the iocb object when it is freed.
  506. * The sqlq structure that holds the xritag and phys and virtual
  507. * mappings for the scatter gather list is retrieved from the
  508. * active array of sglq. The get of the sglq pointer also clears
  509. * the entry in the array. If the status of the IO indiactes that
  510. * this IO was aborted then the sglq entry it put on the
  511. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  512. * IO has good status or fails for any other reason then the sglq
  513. * entry is added to the free list (lpfc_sgl_list).
  514. **/
  515. static void
  516. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  517. {
  518. struct lpfc_sglq *sglq;
  519. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  520. unsigned long iflag;
  521. if (iocbq->sli4_xritag == NO_XRI)
  522. sglq = NULL;
  523. else
  524. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  525. if (sglq) {
  526. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
  527. || ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  528. && (iocbq->iocb.un.ulpWord[4]
  529. == IOERR_SLI_ABORTED))) {
  530. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  531. iflag);
  532. list_add(&sglq->list,
  533. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  534. spin_unlock_irqrestore(
  535. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  536. } else
  537. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  538. }
  539. /*
  540. * Clean all volatile data fields, preserve iotag and node struct.
  541. */
  542. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  543. iocbq->sli4_xritag = NO_XRI;
  544. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  545. }
  546. /**
  547. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  548. * @phba: Pointer to HBA context object.
  549. * @iocbq: Pointer to driver iocb object.
  550. *
  551. * This function is called with hbalock held to release driver
  552. * iocb object to the iocb pool. The iotag in the iocb object
  553. * does not change for each use of the iocb object. This function
  554. * clears all other fields of the iocb object when it is freed.
  555. **/
  556. static void
  557. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  558. {
  559. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  560. /*
  561. * Clean all volatile data fields, preserve iotag and node struct.
  562. */
  563. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  564. iocbq->sli4_xritag = NO_XRI;
  565. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  566. }
  567. /**
  568. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  569. * @phba: Pointer to HBA context object.
  570. * @iocbq: Pointer to driver iocb object.
  571. *
  572. * This function is called with hbalock held to release driver
  573. * iocb object to the iocb pool. The iotag in the iocb object
  574. * does not change for each use of the iocb object. This function
  575. * clears all other fields of the iocb object when it is freed.
  576. **/
  577. static void
  578. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  579. {
  580. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  581. }
  582. /**
  583. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  584. * @phba: Pointer to HBA context object.
  585. * @iocbq: Pointer to driver iocb object.
  586. *
  587. * This function is called with no lock held to release the iocb to
  588. * iocb pool.
  589. **/
  590. void
  591. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  592. {
  593. unsigned long iflags;
  594. /*
  595. * Clean all volatile data fields, preserve iotag and node struct.
  596. */
  597. spin_lock_irqsave(&phba->hbalock, iflags);
  598. __lpfc_sli_release_iocbq(phba, iocbq);
  599. spin_unlock_irqrestore(&phba->hbalock, iflags);
  600. }
  601. /**
  602. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  603. * @phba: Pointer to HBA context object.
  604. * @iocblist: List of IOCBs.
  605. * @ulpstatus: ULP status in IOCB command field.
  606. * @ulpWord4: ULP word-4 in IOCB command field.
  607. *
  608. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  609. * on the list by invoking the complete callback function associated with the
  610. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  611. * fields.
  612. **/
  613. void
  614. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  615. uint32_t ulpstatus, uint32_t ulpWord4)
  616. {
  617. struct lpfc_iocbq *piocb;
  618. while (!list_empty(iocblist)) {
  619. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  620. if (!piocb->iocb_cmpl)
  621. lpfc_sli_release_iocbq(phba, piocb);
  622. else {
  623. piocb->iocb.ulpStatus = ulpstatus;
  624. piocb->iocb.un.ulpWord[4] = ulpWord4;
  625. (piocb->iocb_cmpl) (phba, piocb, piocb);
  626. }
  627. }
  628. return;
  629. }
  630. /**
  631. * lpfc_sli_iocb_cmd_type - Get the iocb type
  632. * @iocb_cmnd: iocb command code.
  633. *
  634. * This function is called by ring event handler function to get the iocb type.
  635. * This function translates the iocb command to an iocb command type used to
  636. * decide the final disposition of each completed IOCB.
  637. * The function returns
  638. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  639. * LPFC_SOL_IOCB if it is a solicited iocb completion
  640. * LPFC_ABORT_IOCB if it is an abort iocb
  641. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  642. *
  643. * The caller is not required to hold any lock.
  644. **/
  645. static lpfc_iocb_type
  646. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  647. {
  648. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  649. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  650. return 0;
  651. switch (iocb_cmnd) {
  652. case CMD_XMIT_SEQUENCE_CR:
  653. case CMD_XMIT_SEQUENCE_CX:
  654. case CMD_XMIT_BCAST_CN:
  655. case CMD_XMIT_BCAST_CX:
  656. case CMD_ELS_REQUEST_CR:
  657. case CMD_ELS_REQUEST_CX:
  658. case CMD_CREATE_XRI_CR:
  659. case CMD_CREATE_XRI_CX:
  660. case CMD_GET_RPI_CN:
  661. case CMD_XMIT_ELS_RSP_CX:
  662. case CMD_GET_RPI_CR:
  663. case CMD_FCP_IWRITE_CR:
  664. case CMD_FCP_IWRITE_CX:
  665. case CMD_FCP_IREAD_CR:
  666. case CMD_FCP_IREAD_CX:
  667. case CMD_FCP_ICMND_CR:
  668. case CMD_FCP_ICMND_CX:
  669. case CMD_FCP_TSEND_CX:
  670. case CMD_FCP_TRSP_CX:
  671. case CMD_FCP_TRECEIVE_CX:
  672. case CMD_FCP_AUTO_TRSP_CX:
  673. case CMD_ADAPTER_MSG:
  674. case CMD_ADAPTER_DUMP:
  675. case CMD_XMIT_SEQUENCE64_CR:
  676. case CMD_XMIT_SEQUENCE64_CX:
  677. case CMD_XMIT_BCAST64_CN:
  678. case CMD_XMIT_BCAST64_CX:
  679. case CMD_ELS_REQUEST64_CR:
  680. case CMD_ELS_REQUEST64_CX:
  681. case CMD_FCP_IWRITE64_CR:
  682. case CMD_FCP_IWRITE64_CX:
  683. case CMD_FCP_IREAD64_CR:
  684. case CMD_FCP_IREAD64_CX:
  685. case CMD_FCP_ICMND64_CR:
  686. case CMD_FCP_ICMND64_CX:
  687. case CMD_FCP_TSEND64_CX:
  688. case CMD_FCP_TRSP64_CX:
  689. case CMD_FCP_TRECEIVE64_CX:
  690. case CMD_GEN_REQUEST64_CR:
  691. case CMD_GEN_REQUEST64_CX:
  692. case CMD_XMIT_ELS_RSP64_CX:
  693. case DSSCMD_IWRITE64_CR:
  694. case DSSCMD_IWRITE64_CX:
  695. case DSSCMD_IREAD64_CR:
  696. case DSSCMD_IREAD64_CX:
  697. case DSSCMD_INVALIDATE_DEK:
  698. case DSSCMD_SET_KEK:
  699. case DSSCMD_GET_KEK_ID:
  700. case DSSCMD_GEN_XFER:
  701. type = LPFC_SOL_IOCB;
  702. break;
  703. case CMD_ABORT_XRI_CN:
  704. case CMD_ABORT_XRI_CX:
  705. case CMD_CLOSE_XRI_CN:
  706. case CMD_CLOSE_XRI_CX:
  707. case CMD_XRI_ABORTED_CX:
  708. case CMD_ABORT_MXRI64_CN:
  709. type = LPFC_ABORT_IOCB;
  710. break;
  711. case CMD_RCV_SEQUENCE_CX:
  712. case CMD_RCV_ELS_REQ_CX:
  713. case CMD_RCV_SEQUENCE64_CX:
  714. case CMD_RCV_ELS_REQ64_CX:
  715. case CMD_ASYNC_STATUS:
  716. case CMD_IOCB_RCV_SEQ64_CX:
  717. case CMD_IOCB_RCV_ELS64_CX:
  718. case CMD_IOCB_RCV_CONT64_CX:
  719. case CMD_IOCB_RET_XRI64_CX:
  720. type = LPFC_UNSOL_IOCB;
  721. break;
  722. case CMD_IOCB_XMIT_MSEQ64_CR:
  723. case CMD_IOCB_XMIT_MSEQ64_CX:
  724. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  725. case CMD_IOCB_RCV_ELS_LIST64_CX:
  726. case CMD_IOCB_CLOSE_EXTENDED_CN:
  727. case CMD_IOCB_ABORT_EXTENDED_CN:
  728. case CMD_IOCB_RET_HBQE64_CN:
  729. case CMD_IOCB_FCP_IBIDIR64_CR:
  730. case CMD_IOCB_FCP_IBIDIR64_CX:
  731. case CMD_IOCB_FCP_ITASKMGT64_CX:
  732. case CMD_IOCB_LOGENTRY_CN:
  733. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  734. printk("%s - Unhandled SLI-3 Command x%x\n",
  735. __func__, iocb_cmnd);
  736. type = LPFC_UNKNOWN_IOCB;
  737. break;
  738. default:
  739. type = LPFC_UNKNOWN_IOCB;
  740. break;
  741. }
  742. return type;
  743. }
  744. /**
  745. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  746. * @phba: Pointer to HBA context object.
  747. *
  748. * This function is called from SLI initialization code
  749. * to configure every ring of the HBA's SLI interface. The
  750. * caller is not required to hold any lock. This function issues
  751. * a config_ring mailbox command for each ring.
  752. * This function returns zero if successful else returns a negative
  753. * error code.
  754. **/
  755. static int
  756. lpfc_sli_ring_map(struct lpfc_hba *phba)
  757. {
  758. struct lpfc_sli *psli = &phba->sli;
  759. LPFC_MBOXQ_t *pmb;
  760. MAILBOX_t *pmbox;
  761. int i, rc, ret = 0;
  762. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  763. if (!pmb)
  764. return -ENOMEM;
  765. pmbox = &pmb->u.mb;
  766. phba->link_state = LPFC_INIT_MBX_CMDS;
  767. for (i = 0; i < psli->num_rings; i++) {
  768. lpfc_config_ring(phba, i, pmb);
  769. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  770. if (rc != MBX_SUCCESS) {
  771. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  772. "0446 Adapter failed to init (%d), "
  773. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  774. "ring %d\n",
  775. rc, pmbox->mbxCommand,
  776. pmbox->mbxStatus, i);
  777. phba->link_state = LPFC_HBA_ERROR;
  778. ret = -ENXIO;
  779. break;
  780. }
  781. }
  782. mempool_free(pmb, phba->mbox_mem_pool);
  783. return ret;
  784. }
  785. /**
  786. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  787. * @phba: Pointer to HBA context object.
  788. * @pring: Pointer to driver SLI ring object.
  789. * @piocb: Pointer to the driver iocb object.
  790. *
  791. * This function is called with hbalock held. The function adds the
  792. * new iocb to txcmplq of the given ring. This function always returns
  793. * 0. If this function is called for ELS ring, this function checks if
  794. * there is a vport associated with the ELS command. This function also
  795. * starts els_tmofunc timer if this is an ELS command.
  796. **/
  797. static int
  798. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  799. struct lpfc_iocbq *piocb)
  800. {
  801. list_add_tail(&piocb->list, &pring->txcmplq);
  802. pring->txcmplq_cnt++;
  803. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  804. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  805. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  806. if (!piocb->vport)
  807. BUG();
  808. else
  809. mod_timer(&piocb->vport->els_tmofunc,
  810. jiffies + HZ * (phba->fc_ratov << 1));
  811. }
  812. return 0;
  813. }
  814. /**
  815. * lpfc_sli_ringtx_get - Get first element of the txq
  816. * @phba: Pointer to HBA context object.
  817. * @pring: Pointer to driver SLI ring object.
  818. *
  819. * This function is called with hbalock held to get next
  820. * iocb in txq of the given ring. If there is any iocb in
  821. * the txq, the function returns first iocb in the list after
  822. * removing the iocb from the list, else it returns NULL.
  823. **/
  824. static struct lpfc_iocbq *
  825. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  826. {
  827. struct lpfc_iocbq *cmd_iocb;
  828. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  829. if (cmd_iocb != NULL)
  830. pring->txq_cnt--;
  831. return cmd_iocb;
  832. }
  833. /**
  834. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  835. * @phba: Pointer to HBA context object.
  836. * @pring: Pointer to driver SLI ring object.
  837. *
  838. * This function is called with hbalock held and the caller must post the
  839. * iocb without releasing the lock. If the caller releases the lock,
  840. * iocb slot returned by the function is not guaranteed to be available.
  841. * The function returns pointer to the next available iocb slot if there
  842. * is available slot in the ring, else it returns NULL.
  843. * If the get index of the ring is ahead of the put index, the function
  844. * will post an error attention event to the worker thread to take the
  845. * HBA to offline state.
  846. **/
  847. static IOCB_t *
  848. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  849. {
  850. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  851. uint32_t max_cmd_idx = pring->numCiocb;
  852. if ((pring->next_cmdidx == pring->cmdidx) &&
  853. (++pring->next_cmdidx >= max_cmd_idx))
  854. pring->next_cmdidx = 0;
  855. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  856. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  857. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  858. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  859. "0315 Ring %d issue: portCmdGet %d "
  860. "is bigger than cmd ring %d\n",
  861. pring->ringno,
  862. pring->local_getidx, max_cmd_idx);
  863. phba->link_state = LPFC_HBA_ERROR;
  864. /*
  865. * All error attention handlers are posted to
  866. * worker thread
  867. */
  868. phba->work_ha |= HA_ERATT;
  869. phba->work_hs = HS_FFER3;
  870. lpfc_worker_wake_up(phba);
  871. return NULL;
  872. }
  873. if (pring->local_getidx == pring->next_cmdidx)
  874. return NULL;
  875. }
  876. return lpfc_cmd_iocb(phba, pring);
  877. }
  878. /**
  879. * lpfc_sli_next_iotag - Get an iotag for the iocb
  880. * @phba: Pointer to HBA context object.
  881. * @iocbq: Pointer to driver iocb object.
  882. *
  883. * This function gets an iotag for the iocb. If there is no unused iotag and
  884. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  885. * array and assigns a new iotag.
  886. * The function returns the allocated iotag if successful, else returns zero.
  887. * Zero is not a valid iotag.
  888. * The caller is not required to hold any lock.
  889. **/
  890. uint16_t
  891. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  892. {
  893. struct lpfc_iocbq **new_arr;
  894. struct lpfc_iocbq **old_arr;
  895. size_t new_len;
  896. struct lpfc_sli *psli = &phba->sli;
  897. uint16_t iotag;
  898. spin_lock_irq(&phba->hbalock);
  899. iotag = psli->last_iotag;
  900. if(++iotag < psli->iocbq_lookup_len) {
  901. psli->last_iotag = iotag;
  902. psli->iocbq_lookup[iotag] = iocbq;
  903. spin_unlock_irq(&phba->hbalock);
  904. iocbq->iotag = iotag;
  905. return iotag;
  906. } else if (psli->iocbq_lookup_len < (0xffff
  907. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  908. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  909. spin_unlock_irq(&phba->hbalock);
  910. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  911. GFP_KERNEL);
  912. if (new_arr) {
  913. spin_lock_irq(&phba->hbalock);
  914. old_arr = psli->iocbq_lookup;
  915. if (new_len <= psli->iocbq_lookup_len) {
  916. /* highly unprobable case */
  917. kfree(new_arr);
  918. iotag = psli->last_iotag;
  919. if(++iotag < psli->iocbq_lookup_len) {
  920. psli->last_iotag = iotag;
  921. psli->iocbq_lookup[iotag] = iocbq;
  922. spin_unlock_irq(&phba->hbalock);
  923. iocbq->iotag = iotag;
  924. return iotag;
  925. }
  926. spin_unlock_irq(&phba->hbalock);
  927. return 0;
  928. }
  929. if (psli->iocbq_lookup)
  930. memcpy(new_arr, old_arr,
  931. ((psli->last_iotag + 1) *
  932. sizeof (struct lpfc_iocbq *)));
  933. psli->iocbq_lookup = new_arr;
  934. psli->iocbq_lookup_len = new_len;
  935. psli->last_iotag = iotag;
  936. psli->iocbq_lookup[iotag] = iocbq;
  937. spin_unlock_irq(&phba->hbalock);
  938. iocbq->iotag = iotag;
  939. kfree(old_arr);
  940. return iotag;
  941. }
  942. } else
  943. spin_unlock_irq(&phba->hbalock);
  944. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  945. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  946. psli->last_iotag);
  947. return 0;
  948. }
  949. /**
  950. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  951. * @phba: Pointer to HBA context object.
  952. * @pring: Pointer to driver SLI ring object.
  953. * @iocb: Pointer to iocb slot in the ring.
  954. * @nextiocb: Pointer to driver iocb object which need to be
  955. * posted to firmware.
  956. *
  957. * This function is called with hbalock held to post a new iocb to
  958. * the firmware. This function copies the new iocb to ring iocb slot and
  959. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  960. * a completion call back for this iocb else the function will free the
  961. * iocb object.
  962. **/
  963. static void
  964. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  965. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  966. {
  967. /*
  968. * Set up an iotag
  969. */
  970. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  971. if (pring->ringno == LPFC_ELS_RING) {
  972. lpfc_debugfs_slow_ring_trc(phba,
  973. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  974. *(((uint32_t *) &nextiocb->iocb) + 4),
  975. *(((uint32_t *) &nextiocb->iocb) + 6),
  976. *(((uint32_t *) &nextiocb->iocb) + 7));
  977. }
  978. /*
  979. * Issue iocb command to adapter
  980. */
  981. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  982. wmb();
  983. pring->stats.iocb_cmd++;
  984. /*
  985. * If there is no completion routine to call, we can release the
  986. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  987. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  988. */
  989. if (nextiocb->iocb_cmpl)
  990. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  991. else
  992. __lpfc_sli_release_iocbq(phba, nextiocb);
  993. /*
  994. * Let the HBA know what IOCB slot will be the next one the
  995. * driver will put a command into.
  996. */
  997. pring->cmdidx = pring->next_cmdidx;
  998. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  999. }
  1000. /**
  1001. * lpfc_sli_update_full_ring - Update the chip attention register
  1002. * @phba: Pointer to HBA context object.
  1003. * @pring: Pointer to driver SLI ring object.
  1004. *
  1005. * The caller is not required to hold any lock for calling this function.
  1006. * This function updates the chip attention bits for the ring to inform firmware
  1007. * that there are pending work to be done for this ring and requests an
  1008. * interrupt when there is space available in the ring. This function is
  1009. * called when the driver is unable to post more iocbs to the ring due
  1010. * to unavailability of space in the ring.
  1011. **/
  1012. static void
  1013. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1014. {
  1015. int ringno = pring->ringno;
  1016. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1017. wmb();
  1018. /*
  1019. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1020. * The HBA will tell us when an IOCB entry is available.
  1021. */
  1022. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1023. readl(phba->CAregaddr); /* flush */
  1024. pring->stats.iocb_cmd_full++;
  1025. }
  1026. /**
  1027. * lpfc_sli_update_ring - Update chip attention register
  1028. * @phba: Pointer to HBA context object.
  1029. * @pring: Pointer to driver SLI ring object.
  1030. *
  1031. * This function updates the chip attention register bit for the
  1032. * given ring to inform HBA that there is more work to be done
  1033. * in this ring. The caller is not required to hold any lock.
  1034. **/
  1035. static void
  1036. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1037. {
  1038. int ringno = pring->ringno;
  1039. /*
  1040. * Tell the HBA that there is work to do in this ring.
  1041. */
  1042. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1043. wmb();
  1044. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1045. readl(phba->CAregaddr); /* flush */
  1046. }
  1047. }
  1048. /**
  1049. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1050. * @phba: Pointer to HBA context object.
  1051. * @pring: Pointer to driver SLI ring object.
  1052. *
  1053. * This function is called with hbalock held to post pending iocbs
  1054. * in the txq to the firmware. This function is called when driver
  1055. * detects space available in the ring.
  1056. **/
  1057. static void
  1058. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1059. {
  1060. IOCB_t *iocb;
  1061. struct lpfc_iocbq *nextiocb;
  1062. /*
  1063. * Check to see if:
  1064. * (a) there is anything on the txq to send
  1065. * (b) link is up
  1066. * (c) link attention events can be processed (fcp ring only)
  1067. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1068. */
  1069. if (pring->txq_cnt &&
  1070. lpfc_is_link_up(phba) &&
  1071. (pring->ringno != phba->sli.fcp_ring ||
  1072. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1073. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1074. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1075. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1076. if (iocb)
  1077. lpfc_sli_update_ring(phba, pring);
  1078. else
  1079. lpfc_sli_update_full_ring(phba, pring);
  1080. }
  1081. return;
  1082. }
  1083. /**
  1084. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1085. * @phba: Pointer to HBA context object.
  1086. * @hbqno: HBQ number.
  1087. *
  1088. * This function is called with hbalock held to get the next
  1089. * available slot for the given HBQ. If there is free slot
  1090. * available for the HBQ it will return pointer to the next available
  1091. * HBQ entry else it will return NULL.
  1092. **/
  1093. static struct lpfc_hbq_entry *
  1094. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1095. {
  1096. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1097. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1098. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1099. hbqp->next_hbqPutIdx = 0;
  1100. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1101. uint32_t raw_index = phba->hbq_get[hbqno];
  1102. uint32_t getidx = le32_to_cpu(raw_index);
  1103. hbqp->local_hbqGetIdx = getidx;
  1104. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1105. lpfc_printf_log(phba, KERN_ERR,
  1106. LOG_SLI | LOG_VPORT,
  1107. "1802 HBQ %d: local_hbqGetIdx "
  1108. "%u is > than hbqp->entry_count %u\n",
  1109. hbqno, hbqp->local_hbqGetIdx,
  1110. hbqp->entry_count);
  1111. phba->link_state = LPFC_HBA_ERROR;
  1112. return NULL;
  1113. }
  1114. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1115. return NULL;
  1116. }
  1117. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1118. hbqp->hbqPutIdx;
  1119. }
  1120. /**
  1121. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1122. * @phba: Pointer to HBA context object.
  1123. *
  1124. * This function is called with no lock held to free all the
  1125. * hbq buffers while uninitializing the SLI interface. It also
  1126. * frees the HBQ buffers returned by the firmware but not yet
  1127. * processed by the upper layers.
  1128. **/
  1129. void
  1130. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1131. {
  1132. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1133. struct hbq_dmabuf *hbq_buf;
  1134. unsigned long flags;
  1135. int i, hbq_count;
  1136. uint32_t hbqno;
  1137. hbq_count = lpfc_sli_hbq_count();
  1138. /* Return all memory used by all HBQs */
  1139. spin_lock_irqsave(&phba->hbalock, flags);
  1140. for (i = 0; i < hbq_count; ++i) {
  1141. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1142. &phba->hbqs[i].hbq_buffer_list, list) {
  1143. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1144. list_del(&hbq_buf->dbuf.list);
  1145. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1146. }
  1147. phba->hbqs[i].buffer_count = 0;
  1148. }
  1149. /* Return all HBQ buffer that are in-fly */
  1150. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1151. list) {
  1152. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1153. list_del(&hbq_buf->dbuf.list);
  1154. if (hbq_buf->tag == -1) {
  1155. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1156. (phba, hbq_buf);
  1157. } else {
  1158. hbqno = hbq_buf->tag >> 16;
  1159. if (hbqno >= LPFC_MAX_HBQS)
  1160. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1161. (phba, hbq_buf);
  1162. else
  1163. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1164. hbq_buf);
  1165. }
  1166. }
  1167. /* Mark the HBQs not in use */
  1168. phba->hbq_in_use = 0;
  1169. spin_unlock_irqrestore(&phba->hbalock, flags);
  1170. }
  1171. /**
  1172. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1173. * @phba: Pointer to HBA context object.
  1174. * @hbqno: HBQ number.
  1175. * @hbq_buf: Pointer to HBQ buffer.
  1176. *
  1177. * This function is called with the hbalock held to post a
  1178. * hbq buffer to the firmware. If the function finds an empty
  1179. * slot in the HBQ, it will post the buffer. The function will return
  1180. * pointer to the hbq entry if it successfully post the buffer
  1181. * else it will return NULL.
  1182. **/
  1183. static int
  1184. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1185. struct hbq_dmabuf *hbq_buf)
  1186. {
  1187. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1188. }
  1189. /**
  1190. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1191. * @phba: Pointer to HBA context object.
  1192. * @hbqno: HBQ number.
  1193. * @hbq_buf: Pointer to HBQ buffer.
  1194. *
  1195. * This function is called with the hbalock held to post a hbq buffer to the
  1196. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1197. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1198. * it successfully post the buffer else it will return an error.
  1199. **/
  1200. static int
  1201. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1202. struct hbq_dmabuf *hbq_buf)
  1203. {
  1204. struct lpfc_hbq_entry *hbqe;
  1205. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1206. /* Get next HBQ entry slot to use */
  1207. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1208. if (hbqe) {
  1209. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1210. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1211. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1212. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1213. hbqe->bde.tus.f.bdeFlags = 0;
  1214. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1215. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1216. /* Sync SLIM */
  1217. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1218. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1219. /* flush */
  1220. readl(phba->hbq_put + hbqno);
  1221. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1222. return 0;
  1223. } else
  1224. return -ENOMEM;
  1225. }
  1226. /**
  1227. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1228. * @phba: Pointer to HBA context object.
  1229. * @hbqno: HBQ number.
  1230. * @hbq_buf: Pointer to HBQ buffer.
  1231. *
  1232. * This function is called with the hbalock held to post an RQE to the SLI4
  1233. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1234. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1235. **/
  1236. static int
  1237. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1238. struct hbq_dmabuf *hbq_buf)
  1239. {
  1240. int rc;
  1241. struct lpfc_rqe hrqe;
  1242. struct lpfc_rqe drqe;
  1243. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1244. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1245. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1246. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1247. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1248. &hrqe, &drqe);
  1249. if (rc < 0)
  1250. return rc;
  1251. hbq_buf->tag = rc;
  1252. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1253. return 0;
  1254. }
  1255. /* HBQ for ELS and CT traffic. */
  1256. static struct lpfc_hbq_init lpfc_els_hbq = {
  1257. .rn = 1,
  1258. .entry_count = 200,
  1259. .mask_count = 0,
  1260. .profile = 0,
  1261. .ring_mask = (1 << LPFC_ELS_RING),
  1262. .buffer_count = 0,
  1263. .init_count = 40,
  1264. .add_count = 40,
  1265. };
  1266. /* HBQ for the extra ring if needed */
  1267. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1268. .rn = 1,
  1269. .entry_count = 200,
  1270. .mask_count = 0,
  1271. .profile = 0,
  1272. .ring_mask = (1 << LPFC_EXTRA_RING),
  1273. .buffer_count = 0,
  1274. .init_count = 0,
  1275. .add_count = 5,
  1276. };
  1277. /* Array of HBQs */
  1278. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1279. &lpfc_els_hbq,
  1280. &lpfc_extra_hbq,
  1281. };
  1282. /**
  1283. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1284. * @phba: Pointer to HBA context object.
  1285. * @hbqno: HBQ number.
  1286. * @count: Number of HBQ buffers to be posted.
  1287. *
  1288. * This function is called with no lock held to post more hbq buffers to the
  1289. * given HBQ. The function returns the number of HBQ buffers successfully
  1290. * posted.
  1291. **/
  1292. static int
  1293. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1294. {
  1295. uint32_t i, posted = 0;
  1296. unsigned long flags;
  1297. struct hbq_dmabuf *hbq_buffer;
  1298. LIST_HEAD(hbq_buf_list);
  1299. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1300. return 0;
  1301. if ((phba->hbqs[hbqno].buffer_count + count) >
  1302. lpfc_hbq_defs[hbqno]->entry_count)
  1303. count = lpfc_hbq_defs[hbqno]->entry_count -
  1304. phba->hbqs[hbqno].buffer_count;
  1305. if (!count)
  1306. return 0;
  1307. /* Allocate HBQ entries */
  1308. for (i = 0; i < count; i++) {
  1309. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1310. if (!hbq_buffer)
  1311. break;
  1312. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1313. }
  1314. /* Check whether HBQ is still in use */
  1315. spin_lock_irqsave(&phba->hbalock, flags);
  1316. if (!phba->hbq_in_use)
  1317. goto err;
  1318. while (!list_empty(&hbq_buf_list)) {
  1319. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1320. dbuf.list);
  1321. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1322. (hbqno << 16));
  1323. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1324. phba->hbqs[hbqno].buffer_count++;
  1325. posted++;
  1326. } else
  1327. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1328. }
  1329. spin_unlock_irqrestore(&phba->hbalock, flags);
  1330. return posted;
  1331. err:
  1332. spin_unlock_irqrestore(&phba->hbalock, flags);
  1333. while (!list_empty(&hbq_buf_list)) {
  1334. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1335. dbuf.list);
  1336. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1337. }
  1338. return 0;
  1339. }
  1340. /**
  1341. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1342. * @phba: Pointer to HBA context object.
  1343. * @qno: HBQ number.
  1344. *
  1345. * This function posts more buffers to the HBQ. This function
  1346. * is called with no lock held. The function returns the number of HBQ entries
  1347. * successfully allocated.
  1348. **/
  1349. int
  1350. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1351. {
  1352. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1353. lpfc_hbq_defs[qno]->add_count));
  1354. }
  1355. /**
  1356. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1357. * @phba: Pointer to HBA context object.
  1358. * @qno: HBQ queue number.
  1359. *
  1360. * This function is called from SLI initialization code path with
  1361. * no lock held to post initial HBQ buffers to firmware. The
  1362. * function returns the number of HBQ entries successfully allocated.
  1363. **/
  1364. static int
  1365. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1366. {
  1367. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1368. lpfc_hbq_defs[qno]->init_count));
  1369. }
  1370. /**
  1371. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1372. * @phba: Pointer to HBA context object.
  1373. * @hbqno: HBQ number.
  1374. *
  1375. * This function removes the first hbq buffer on an hbq list and returns a
  1376. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1377. **/
  1378. static struct hbq_dmabuf *
  1379. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1380. {
  1381. struct lpfc_dmabuf *d_buf;
  1382. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1383. if (!d_buf)
  1384. return NULL;
  1385. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1386. }
  1387. /**
  1388. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1389. * @phba: Pointer to HBA context object.
  1390. * @tag: Tag of the hbq buffer.
  1391. *
  1392. * This function is called with hbalock held. This function searches
  1393. * for the hbq buffer associated with the given tag in the hbq buffer
  1394. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1395. * it returns NULL.
  1396. **/
  1397. static struct hbq_dmabuf *
  1398. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1399. {
  1400. struct lpfc_dmabuf *d_buf;
  1401. struct hbq_dmabuf *hbq_buf;
  1402. uint32_t hbqno;
  1403. hbqno = tag >> 16;
  1404. if (hbqno >= LPFC_MAX_HBQS)
  1405. return NULL;
  1406. spin_lock_irq(&phba->hbalock);
  1407. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1408. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1409. if (hbq_buf->tag == tag) {
  1410. spin_unlock_irq(&phba->hbalock);
  1411. return hbq_buf;
  1412. }
  1413. }
  1414. spin_unlock_irq(&phba->hbalock);
  1415. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1416. "1803 Bad hbq tag. Data: x%x x%x\n",
  1417. tag, phba->hbqs[tag >> 16].buffer_count);
  1418. return NULL;
  1419. }
  1420. /**
  1421. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1422. * @phba: Pointer to HBA context object.
  1423. * @hbq_buffer: Pointer to HBQ buffer.
  1424. *
  1425. * This function is called with hbalock. This function gives back
  1426. * the hbq buffer to firmware. If the HBQ does not have space to
  1427. * post the buffer, it will free the buffer.
  1428. **/
  1429. void
  1430. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1431. {
  1432. uint32_t hbqno;
  1433. if (hbq_buffer) {
  1434. hbqno = hbq_buffer->tag >> 16;
  1435. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1436. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1437. }
  1438. }
  1439. /**
  1440. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1441. * @mbxCommand: mailbox command code.
  1442. *
  1443. * This function is called by the mailbox event handler function to verify
  1444. * that the completed mailbox command is a legitimate mailbox command. If the
  1445. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1446. * and the mailbox event handler will take the HBA offline.
  1447. **/
  1448. static int
  1449. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1450. {
  1451. uint8_t ret;
  1452. switch (mbxCommand) {
  1453. case MBX_LOAD_SM:
  1454. case MBX_READ_NV:
  1455. case MBX_WRITE_NV:
  1456. case MBX_WRITE_VPARMS:
  1457. case MBX_RUN_BIU_DIAG:
  1458. case MBX_INIT_LINK:
  1459. case MBX_DOWN_LINK:
  1460. case MBX_CONFIG_LINK:
  1461. case MBX_CONFIG_RING:
  1462. case MBX_RESET_RING:
  1463. case MBX_READ_CONFIG:
  1464. case MBX_READ_RCONFIG:
  1465. case MBX_READ_SPARM:
  1466. case MBX_READ_STATUS:
  1467. case MBX_READ_RPI:
  1468. case MBX_READ_XRI:
  1469. case MBX_READ_REV:
  1470. case MBX_READ_LNK_STAT:
  1471. case MBX_REG_LOGIN:
  1472. case MBX_UNREG_LOGIN:
  1473. case MBX_READ_LA:
  1474. case MBX_CLEAR_LA:
  1475. case MBX_DUMP_MEMORY:
  1476. case MBX_DUMP_CONTEXT:
  1477. case MBX_RUN_DIAGS:
  1478. case MBX_RESTART:
  1479. case MBX_UPDATE_CFG:
  1480. case MBX_DOWN_LOAD:
  1481. case MBX_DEL_LD_ENTRY:
  1482. case MBX_RUN_PROGRAM:
  1483. case MBX_SET_MASK:
  1484. case MBX_SET_VARIABLE:
  1485. case MBX_UNREG_D_ID:
  1486. case MBX_KILL_BOARD:
  1487. case MBX_CONFIG_FARP:
  1488. case MBX_BEACON:
  1489. case MBX_LOAD_AREA:
  1490. case MBX_RUN_BIU_DIAG64:
  1491. case MBX_CONFIG_PORT:
  1492. case MBX_READ_SPARM64:
  1493. case MBX_READ_RPI64:
  1494. case MBX_REG_LOGIN64:
  1495. case MBX_READ_LA64:
  1496. case MBX_WRITE_WWN:
  1497. case MBX_SET_DEBUG:
  1498. case MBX_LOAD_EXP_ROM:
  1499. case MBX_ASYNCEVT_ENABLE:
  1500. case MBX_REG_VPI:
  1501. case MBX_UNREG_VPI:
  1502. case MBX_HEARTBEAT:
  1503. case MBX_PORT_CAPABILITIES:
  1504. case MBX_PORT_IOV_CONTROL:
  1505. case MBX_SLI4_CONFIG:
  1506. case MBX_SLI4_REQ_FTRS:
  1507. case MBX_REG_FCFI:
  1508. case MBX_UNREG_FCFI:
  1509. case MBX_REG_VFI:
  1510. case MBX_UNREG_VFI:
  1511. case MBX_INIT_VPI:
  1512. case MBX_INIT_VFI:
  1513. case MBX_RESUME_RPI:
  1514. ret = mbxCommand;
  1515. break;
  1516. default:
  1517. ret = MBX_SHUTDOWN;
  1518. break;
  1519. }
  1520. return ret;
  1521. }
  1522. /**
  1523. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1524. * @phba: Pointer to HBA context object.
  1525. * @pmboxq: Pointer to mailbox command.
  1526. *
  1527. * This is completion handler function for mailbox commands issued from
  1528. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1529. * mailbox event handler function with no lock held. This function
  1530. * will wake up thread waiting on the wait queue pointed by context1
  1531. * of the mailbox.
  1532. **/
  1533. void
  1534. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1535. {
  1536. wait_queue_head_t *pdone_q;
  1537. unsigned long drvr_flag;
  1538. /*
  1539. * If pdone_q is empty, the driver thread gave up waiting and
  1540. * continued running.
  1541. */
  1542. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1543. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1544. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1545. if (pdone_q)
  1546. wake_up_interruptible(pdone_q);
  1547. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1548. return;
  1549. }
  1550. /**
  1551. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1552. * @phba: Pointer to HBA context object.
  1553. * @pmb: Pointer to mailbox object.
  1554. *
  1555. * This function is the default mailbox completion handler. It
  1556. * frees the memory resources associated with the completed mailbox
  1557. * command. If the completed command is a REG_LOGIN mailbox command,
  1558. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1559. **/
  1560. void
  1561. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1562. {
  1563. struct lpfc_dmabuf *mp;
  1564. uint16_t rpi, vpi;
  1565. int rc;
  1566. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1567. if (mp) {
  1568. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1569. kfree(mp);
  1570. }
  1571. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1572. (phba->sli_rev == LPFC_SLI_REV4))
  1573. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1574. /*
  1575. * If a REG_LOGIN succeeded after node is destroyed or node
  1576. * is in re-discovery driver need to cleanup the RPI.
  1577. */
  1578. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1579. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1580. !pmb->u.mb.mbxStatus) {
  1581. rpi = pmb->u.mb.un.varWords[0];
  1582. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1583. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1584. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1585. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1586. if (rc != MBX_NOT_FINISHED)
  1587. return;
  1588. }
  1589. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1590. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1591. else
  1592. mempool_free(pmb, phba->mbox_mem_pool);
  1593. }
  1594. /**
  1595. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1596. * @phba: Pointer to HBA context object.
  1597. *
  1598. * This function is called with no lock held. This function processes all
  1599. * the completed mailbox commands and gives it to upper layers. The interrupt
  1600. * service routine processes mailbox completion interrupt and adds completed
  1601. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1602. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1603. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1604. * function returns the mailbox commands to the upper layer by calling the
  1605. * completion handler function of each mailbox.
  1606. **/
  1607. int
  1608. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1609. {
  1610. MAILBOX_t *pmbox;
  1611. LPFC_MBOXQ_t *pmb;
  1612. int rc;
  1613. LIST_HEAD(cmplq);
  1614. phba->sli.slistat.mbox_event++;
  1615. /* Get all completed mailboxe buffers into the cmplq */
  1616. spin_lock_irq(&phba->hbalock);
  1617. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1618. spin_unlock_irq(&phba->hbalock);
  1619. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1620. do {
  1621. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1622. if (pmb == NULL)
  1623. break;
  1624. pmbox = &pmb->u.mb;
  1625. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1626. if (pmb->vport) {
  1627. lpfc_debugfs_disc_trc(pmb->vport,
  1628. LPFC_DISC_TRC_MBOX_VPORT,
  1629. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1630. (uint32_t)pmbox->mbxCommand,
  1631. pmbox->un.varWords[0],
  1632. pmbox->un.varWords[1]);
  1633. }
  1634. else {
  1635. lpfc_debugfs_disc_trc(phba->pport,
  1636. LPFC_DISC_TRC_MBOX,
  1637. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1638. (uint32_t)pmbox->mbxCommand,
  1639. pmbox->un.varWords[0],
  1640. pmbox->un.varWords[1]);
  1641. }
  1642. }
  1643. /*
  1644. * It is a fatal error if unknown mbox command completion.
  1645. */
  1646. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1647. MBX_SHUTDOWN) {
  1648. /* Unknow mailbox command compl */
  1649. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1650. "(%d):0323 Unknown Mailbox command "
  1651. "x%x (x%x) Cmpl\n",
  1652. pmb->vport ? pmb->vport->vpi : 0,
  1653. pmbox->mbxCommand,
  1654. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1655. phba->link_state = LPFC_HBA_ERROR;
  1656. phba->work_hs = HS_FFER3;
  1657. lpfc_handle_eratt(phba);
  1658. continue;
  1659. }
  1660. if (pmbox->mbxStatus) {
  1661. phba->sli.slistat.mbox_stat_err++;
  1662. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1663. /* Mbox cmd cmpl error - RETRYing */
  1664. lpfc_printf_log(phba, KERN_INFO,
  1665. LOG_MBOX | LOG_SLI,
  1666. "(%d):0305 Mbox cmd cmpl "
  1667. "error - RETRYing Data: x%x "
  1668. "(x%x) x%x x%x x%x\n",
  1669. pmb->vport ? pmb->vport->vpi :0,
  1670. pmbox->mbxCommand,
  1671. lpfc_sli4_mbox_opcode_get(phba,
  1672. pmb),
  1673. pmbox->mbxStatus,
  1674. pmbox->un.varWords[0],
  1675. pmb->vport->port_state);
  1676. pmbox->mbxStatus = 0;
  1677. pmbox->mbxOwner = OWN_HOST;
  1678. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1679. if (rc != MBX_NOT_FINISHED)
  1680. continue;
  1681. }
  1682. }
  1683. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1684. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1685. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1686. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1687. pmb->vport ? pmb->vport->vpi : 0,
  1688. pmbox->mbxCommand,
  1689. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1690. pmb->mbox_cmpl,
  1691. *((uint32_t *) pmbox),
  1692. pmbox->un.varWords[0],
  1693. pmbox->un.varWords[1],
  1694. pmbox->un.varWords[2],
  1695. pmbox->un.varWords[3],
  1696. pmbox->un.varWords[4],
  1697. pmbox->un.varWords[5],
  1698. pmbox->un.varWords[6],
  1699. pmbox->un.varWords[7]);
  1700. if (pmb->mbox_cmpl)
  1701. pmb->mbox_cmpl(phba,pmb);
  1702. } while (1);
  1703. return 0;
  1704. }
  1705. /**
  1706. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1707. * @phba: Pointer to HBA context object.
  1708. * @pring: Pointer to driver SLI ring object.
  1709. * @tag: buffer tag.
  1710. *
  1711. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1712. * is set in the tag the buffer is posted for a particular exchange,
  1713. * the function will return the buffer without replacing the buffer.
  1714. * If the buffer is for unsolicited ELS or CT traffic, this function
  1715. * returns the buffer and also posts another buffer to the firmware.
  1716. **/
  1717. static struct lpfc_dmabuf *
  1718. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1719. struct lpfc_sli_ring *pring,
  1720. uint32_t tag)
  1721. {
  1722. struct hbq_dmabuf *hbq_entry;
  1723. if (tag & QUE_BUFTAG_BIT)
  1724. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1725. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1726. if (!hbq_entry)
  1727. return NULL;
  1728. return &hbq_entry->dbuf;
  1729. }
  1730. /**
  1731. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1732. * @phba: Pointer to HBA context object.
  1733. * @pring: Pointer to driver SLI ring object.
  1734. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1735. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1736. * @fch_type: the type for the first frame of the sequence.
  1737. *
  1738. * This function is called with no lock held. This function uses the r_ctl and
  1739. * type of the received sequence to find the correct callback function to call
  1740. * to process the sequence.
  1741. **/
  1742. static int
  1743. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1744. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1745. uint32_t fch_type)
  1746. {
  1747. int i;
  1748. /* unSolicited Responses */
  1749. if (pring->prt[0].profile) {
  1750. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1751. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1752. saveq);
  1753. return 1;
  1754. }
  1755. /* We must search, based on rctl / type
  1756. for the right routine */
  1757. for (i = 0; i < pring->num_mask; i++) {
  1758. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1759. (pring->prt[i].type == fch_type)) {
  1760. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1761. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1762. (phba, pring, saveq);
  1763. return 1;
  1764. }
  1765. }
  1766. return 0;
  1767. }
  1768. /**
  1769. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1770. * @phba: Pointer to HBA context object.
  1771. * @pring: Pointer to driver SLI ring object.
  1772. * @saveq: Pointer to the unsolicited iocb.
  1773. *
  1774. * This function is called with no lock held by the ring event handler
  1775. * when there is an unsolicited iocb posted to the response ring by the
  1776. * firmware. This function gets the buffer associated with the iocbs
  1777. * and calls the event handler for the ring. This function handles both
  1778. * qring buffers and hbq buffers.
  1779. * When the function returns 1 the caller can free the iocb object otherwise
  1780. * upper layer functions will free the iocb objects.
  1781. **/
  1782. static int
  1783. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1784. struct lpfc_iocbq *saveq)
  1785. {
  1786. IOCB_t * irsp;
  1787. WORD5 * w5p;
  1788. uint32_t Rctl, Type;
  1789. uint32_t match;
  1790. struct lpfc_iocbq *iocbq;
  1791. struct lpfc_dmabuf *dmzbuf;
  1792. match = 0;
  1793. irsp = &(saveq->iocb);
  1794. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1795. if (pring->lpfc_sli_rcv_async_status)
  1796. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1797. else
  1798. lpfc_printf_log(phba,
  1799. KERN_WARNING,
  1800. LOG_SLI,
  1801. "0316 Ring %d handler: unexpected "
  1802. "ASYNC_STATUS iocb received evt_code "
  1803. "0x%x\n",
  1804. pring->ringno,
  1805. irsp->un.asyncstat.evt_code);
  1806. return 1;
  1807. }
  1808. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1809. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1810. if (irsp->ulpBdeCount > 0) {
  1811. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1812. irsp->un.ulpWord[3]);
  1813. lpfc_in_buf_free(phba, dmzbuf);
  1814. }
  1815. if (irsp->ulpBdeCount > 1) {
  1816. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1817. irsp->unsli3.sli3Words[3]);
  1818. lpfc_in_buf_free(phba, dmzbuf);
  1819. }
  1820. if (irsp->ulpBdeCount > 2) {
  1821. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1822. irsp->unsli3.sli3Words[7]);
  1823. lpfc_in_buf_free(phba, dmzbuf);
  1824. }
  1825. return 1;
  1826. }
  1827. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1828. if (irsp->ulpBdeCount != 0) {
  1829. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1830. irsp->un.ulpWord[3]);
  1831. if (!saveq->context2)
  1832. lpfc_printf_log(phba,
  1833. KERN_ERR,
  1834. LOG_SLI,
  1835. "0341 Ring %d Cannot find buffer for "
  1836. "an unsolicited iocb. tag 0x%x\n",
  1837. pring->ringno,
  1838. irsp->un.ulpWord[3]);
  1839. }
  1840. if (irsp->ulpBdeCount == 2) {
  1841. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1842. irsp->unsli3.sli3Words[7]);
  1843. if (!saveq->context3)
  1844. lpfc_printf_log(phba,
  1845. KERN_ERR,
  1846. LOG_SLI,
  1847. "0342 Ring %d Cannot find buffer for an"
  1848. " unsolicited iocb. tag 0x%x\n",
  1849. pring->ringno,
  1850. irsp->unsli3.sli3Words[7]);
  1851. }
  1852. list_for_each_entry(iocbq, &saveq->list, list) {
  1853. irsp = &(iocbq->iocb);
  1854. if (irsp->ulpBdeCount != 0) {
  1855. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1856. irsp->un.ulpWord[3]);
  1857. if (!iocbq->context2)
  1858. lpfc_printf_log(phba,
  1859. KERN_ERR,
  1860. LOG_SLI,
  1861. "0343 Ring %d Cannot find "
  1862. "buffer for an unsolicited iocb"
  1863. ". tag 0x%x\n", pring->ringno,
  1864. irsp->un.ulpWord[3]);
  1865. }
  1866. if (irsp->ulpBdeCount == 2) {
  1867. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1868. irsp->unsli3.sli3Words[7]);
  1869. if (!iocbq->context3)
  1870. lpfc_printf_log(phba,
  1871. KERN_ERR,
  1872. LOG_SLI,
  1873. "0344 Ring %d Cannot find "
  1874. "buffer for an unsolicited "
  1875. "iocb. tag 0x%x\n",
  1876. pring->ringno,
  1877. irsp->unsli3.sli3Words[7]);
  1878. }
  1879. }
  1880. }
  1881. if (irsp->ulpBdeCount != 0 &&
  1882. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1883. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1884. int found = 0;
  1885. /* search continue save q for same XRI */
  1886. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1887. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1888. list_add_tail(&saveq->list, &iocbq->list);
  1889. found = 1;
  1890. break;
  1891. }
  1892. }
  1893. if (!found)
  1894. list_add_tail(&saveq->clist,
  1895. &pring->iocb_continue_saveq);
  1896. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1897. list_del_init(&iocbq->clist);
  1898. saveq = iocbq;
  1899. irsp = &(saveq->iocb);
  1900. } else
  1901. return 0;
  1902. }
  1903. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1904. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1905. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1906. Rctl = FC_ELS_REQ;
  1907. Type = FC_ELS_DATA;
  1908. } else {
  1909. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1910. Rctl = w5p->hcsw.Rctl;
  1911. Type = w5p->hcsw.Type;
  1912. /* Firmware Workaround */
  1913. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1914. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1915. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1916. Rctl = FC_ELS_REQ;
  1917. Type = FC_ELS_DATA;
  1918. w5p->hcsw.Rctl = Rctl;
  1919. w5p->hcsw.Type = Type;
  1920. }
  1921. }
  1922. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1923. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1924. "0313 Ring %d handler: unexpected Rctl x%x "
  1925. "Type x%x received\n",
  1926. pring->ringno, Rctl, Type);
  1927. return 1;
  1928. }
  1929. /**
  1930. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1931. * @phba: Pointer to HBA context object.
  1932. * @pring: Pointer to driver SLI ring object.
  1933. * @prspiocb: Pointer to response iocb object.
  1934. *
  1935. * This function looks up the iocb_lookup table to get the command iocb
  1936. * corresponding to the given response iocb using the iotag of the
  1937. * response iocb. This function is called with the hbalock held.
  1938. * This function returns the command iocb object if it finds the command
  1939. * iocb else returns NULL.
  1940. **/
  1941. static struct lpfc_iocbq *
  1942. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1943. struct lpfc_sli_ring *pring,
  1944. struct lpfc_iocbq *prspiocb)
  1945. {
  1946. struct lpfc_iocbq *cmd_iocb = NULL;
  1947. uint16_t iotag;
  1948. iotag = prspiocb->iocb.ulpIoTag;
  1949. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1950. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1951. list_del_init(&cmd_iocb->list);
  1952. pring->txcmplq_cnt--;
  1953. return cmd_iocb;
  1954. }
  1955. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1956. "0317 iotag x%x is out off "
  1957. "range: max iotag x%x wd0 x%x\n",
  1958. iotag, phba->sli.last_iotag,
  1959. *(((uint32_t *) &prspiocb->iocb) + 7));
  1960. return NULL;
  1961. }
  1962. /**
  1963. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1964. * @phba: Pointer to HBA context object.
  1965. * @pring: Pointer to driver SLI ring object.
  1966. * @iotag: IOCB tag.
  1967. *
  1968. * This function looks up the iocb_lookup table to get the command iocb
  1969. * corresponding to the given iotag. This function is called with the
  1970. * hbalock held.
  1971. * This function returns the command iocb object if it finds the command
  1972. * iocb else returns NULL.
  1973. **/
  1974. static struct lpfc_iocbq *
  1975. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1976. struct lpfc_sli_ring *pring, uint16_t iotag)
  1977. {
  1978. struct lpfc_iocbq *cmd_iocb;
  1979. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1980. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1981. list_del_init(&cmd_iocb->list);
  1982. pring->txcmplq_cnt--;
  1983. return cmd_iocb;
  1984. }
  1985. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1986. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  1987. iotag, phba->sli.last_iotag);
  1988. return NULL;
  1989. }
  1990. /**
  1991. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  1992. * @phba: Pointer to HBA context object.
  1993. * @pring: Pointer to driver SLI ring object.
  1994. * @saveq: Pointer to the response iocb to be processed.
  1995. *
  1996. * This function is called by the ring event handler for non-fcp
  1997. * rings when there is a new response iocb in the response ring.
  1998. * The caller is not required to hold any locks. This function
  1999. * gets the command iocb associated with the response iocb and
  2000. * calls the completion handler for the command iocb. If there
  2001. * is no completion handler, the function will free the resources
  2002. * associated with command iocb. If the response iocb is for
  2003. * an already aborted command iocb, the status of the completion
  2004. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2005. * This function always returns 1.
  2006. **/
  2007. static int
  2008. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2009. struct lpfc_iocbq *saveq)
  2010. {
  2011. struct lpfc_iocbq *cmdiocbp;
  2012. int rc = 1;
  2013. unsigned long iflag;
  2014. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2015. spin_lock_irqsave(&phba->hbalock, iflag);
  2016. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2018. if (cmdiocbp) {
  2019. if (cmdiocbp->iocb_cmpl) {
  2020. /*
  2021. * If an ELS command failed send an event to mgmt
  2022. * application.
  2023. */
  2024. if (saveq->iocb.ulpStatus &&
  2025. (pring->ringno == LPFC_ELS_RING) &&
  2026. (cmdiocbp->iocb.ulpCommand ==
  2027. CMD_ELS_REQUEST64_CR))
  2028. lpfc_send_els_failure_event(phba,
  2029. cmdiocbp, saveq);
  2030. /*
  2031. * Post all ELS completions to the worker thread.
  2032. * All other are passed to the completion callback.
  2033. */
  2034. if (pring->ringno == LPFC_ELS_RING) {
  2035. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  2036. cmdiocbp->iocb_flag &=
  2037. ~LPFC_DRIVER_ABORTED;
  2038. saveq->iocb.ulpStatus =
  2039. IOSTAT_LOCAL_REJECT;
  2040. saveq->iocb.un.ulpWord[4] =
  2041. IOERR_SLI_ABORTED;
  2042. /* Firmware could still be in progress
  2043. * of DMAing payload, so don't free data
  2044. * buffer till after a hbeat.
  2045. */
  2046. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2047. }
  2048. }
  2049. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2050. } else
  2051. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2052. } else {
  2053. /*
  2054. * Unknown initiating command based on the response iotag.
  2055. * This could be the case on the ELS ring because of
  2056. * lpfc_els_abort().
  2057. */
  2058. if (pring->ringno != LPFC_ELS_RING) {
  2059. /*
  2060. * Ring <ringno> handler: unexpected completion IoTag
  2061. * <IoTag>
  2062. */
  2063. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2064. "0322 Ring %d handler: "
  2065. "unexpected completion IoTag x%x "
  2066. "Data: x%x x%x x%x x%x\n",
  2067. pring->ringno,
  2068. saveq->iocb.ulpIoTag,
  2069. saveq->iocb.ulpStatus,
  2070. saveq->iocb.un.ulpWord[4],
  2071. saveq->iocb.ulpCommand,
  2072. saveq->iocb.ulpContext);
  2073. }
  2074. }
  2075. return rc;
  2076. }
  2077. /**
  2078. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2079. * @phba: Pointer to HBA context object.
  2080. * @pring: Pointer to driver SLI ring object.
  2081. *
  2082. * This function is called from the iocb ring event handlers when
  2083. * put pointer is ahead of the get pointer for a ring. This function signal
  2084. * an error attention condition to the worker thread and the worker
  2085. * thread will transition the HBA to offline state.
  2086. **/
  2087. static void
  2088. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2089. {
  2090. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2091. /*
  2092. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2093. * rsp ring <portRspMax>
  2094. */
  2095. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2096. "0312 Ring %d handler: portRspPut %d "
  2097. "is bigger than rsp ring %d\n",
  2098. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2099. pring->numRiocb);
  2100. phba->link_state = LPFC_HBA_ERROR;
  2101. /*
  2102. * All error attention handlers are posted to
  2103. * worker thread
  2104. */
  2105. phba->work_ha |= HA_ERATT;
  2106. phba->work_hs = HS_FFER3;
  2107. lpfc_worker_wake_up(phba);
  2108. return;
  2109. }
  2110. /**
  2111. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2112. * @ptr: Pointer to address of HBA context object.
  2113. *
  2114. * This function is invoked by the Error Attention polling timer when the
  2115. * timer times out. It will check the SLI Error Attention register for
  2116. * possible attention events. If so, it will post an Error Attention event
  2117. * and wake up worker thread to process it. Otherwise, it will set up the
  2118. * Error Attention polling timer for the next poll.
  2119. **/
  2120. void lpfc_poll_eratt(unsigned long ptr)
  2121. {
  2122. struct lpfc_hba *phba;
  2123. uint32_t eratt = 0;
  2124. phba = (struct lpfc_hba *)ptr;
  2125. /* Check chip HA register for error event */
  2126. eratt = lpfc_sli_check_eratt(phba);
  2127. if (eratt)
  2128. /* Tell the worker thread there is work to do */
  2129. lpfc_worker_wake_up(phba);
  2130. else
  2131. /* Restart the timer for next eratt poll */
  2132. mod_timer(&phba->eratt_poll, jiffies +
  2133. HZ * LPFC_ERATT_POLL_INTERVAL);
  2134. return;
  2135. }
  2136. /**
  2137. * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode
  2138. * @phba: Pointer to HBA context object.
  2139. *
  2140. * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
  2141. * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
  2142. * is enabled.
  2143. *
  2144. * The caller does not hold any lock.
  2145. * The function processes each response iocb in the response ring until it
  2146. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2147. * LE bit set. The function will call the completion handler of the command iocb
  2148. * if the response iocb indicates a completion for a command iocb or it is
  2149. * an abort completion.
  2150. **/
  2151. void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
  2152. {
  2153. struct lpfc_sli *psli = &phba->sli;
  2154. struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
  2155. IOCB_t *irsp = NULL;
  2156. IOCB_t *entry = NULL;
  2157. struct lpfc_iocbq *cmdiocbq = NULL;
  2158. struct lpfc_iocbq rspiocbq;
  2159. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2160. uint32_t status;
  2161. uint32_t portRspPut, portRspMax;
  2162. int type;
  2163. uint32_t rsp_cmpl = 0;
  2164. uint32_t ha_copy;
  2165. unsigned long iflags;
  2166. pring->stats.iocb_event++;
  2167. /*
  2168. * The next available response entry should never exceed the maximum
  2169. * entries. If it does, treat it as an adapter hardware error.
  2170. */
  2171. portRspMax = pring->numRiocb;
  2172. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2173. if (unlikely(portRspPut >= portRspMax)) {
  2174. lpfc_sli_rsp_pointers_error(phba, pring);
  2175. return;
  2176. }
  2177. rmb();
  2178. while (pring->rspidx != portRspPut) {
  2179. entry = lpfc_resp_iocb(phba, pring);
  2180. if (++pring->rspidx >= portRspMax)
  2181. pring->rspidx = 0;
  2182. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2183. (uint32_t *) &rspiocbq.iocb,
  2184. phba->iocb_rsp_size);
  2185. irsp = &rspiocbq.iocb;
  2186. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2187. pring->stats.iocb_rsp++;
  2188. rsp_cmpl++;
  2189. if (unlikely(irsp->ulpStatus)) {
  2190. /* Rsp ring <ringno> error: IOCB */
  2191. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2192. "0326 Rsp Ring %d error: IOCB Data: "
  2193. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2194. pring->ringno,
  2195. irsp->un.ulpWord[0],
  2196. irsp->un.ulpWord[1],
  2197. irsp->un.ulpWord[2],
  2198. irsp->un.ulpWord[3],
  2199. irsp->un.ulpWord[4],
  2200. irsp->un.ulpWord[5],
  2201. *(uint32_t *)&irsp->un1,
  2202. *((uint32_t *)&irsp->un1 + 1));
  2203. }
  2204. switch (type) {
  2205. case LPFC_ABORT_IOCB:
  2206. case LPFC_SOL_IOCB:
  2207. /*
  2208. * Idle exchange closed via ABTS from port. No iocb
  2209. * resources need to be recovered.
  2210. */
  2211. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2212. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2213. "0314 IOCB cmd 0x%x "
  2214. "processed. Skipping "
  2215. "completion",
  2216. irsp->ulpCommand);
  2217. break;
  2218. }
  2219. spin_lock_irqsave(&phba->hbalock, iflags);
  2220. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2221. &rspiocbq);
  2222. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2223. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2224. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2225. &rspiocbq);
  2226. }
  2227. break;
  2228. default:
  2229. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2230. char adaptermsg[LPFC_MAX_ADPTMSG];
  2231. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2232. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2233. MAX_MSG_DATA);
  2234. dev_warn(&((phba->pcidev)->dev),
  2235. "lpfc%d: %s\n",
  2236. phba->brd_no, adaptermsg);
  2237. } else {
  2238. /* Unknown IOCB command */
  2239. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2240. "0321 Unknown IOCB command "
  2241. "Data: x%x, x%x x%x x%x x%x\n",
  2242. type, irsp->ulpCommand,
  2243. irsp->ulpStatus,
  2244. irsp->ulpIoTag,
  2245. irsp->ulpContext);
  2246. }
  2247. break;
  2248. }
  2249. /*
  2250. * The response IOCB has been processed. Update the ring
  2251. * pointer in SLIM. If the port response put pointer has not
  2252. * been updated, sync the pgp->rspPutInx and fetch the new port
  2253. * response put pointer.
  2254. */
  2255. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2256. if (pring->rspidx == portRspPut)
  2257. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2258. }
  2259. ha_copy = readl(phba->HAregaddr);
  2260. ha_copy >>= (LPFC_FCP_RING * 4);
  2261. if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
  2262. spin_lock_irqsave(&phba->hbalock, iflags);
  2263. pring->stats.iocb_rsp_full++;
  2264. status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
  2265. writel(status, phba->CAregaddr);
  2266. readl(phba->CAregaddr);
  2267. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2268. }
  2269. if ((ha_copy & HA_R0CE_RSP) &&
  2270. (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2271. spin_lock_irqsave(&phba->hbalock, iflags);
  2272. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2273. pring->stats.iocb_cmd_empty++;
  2274. /* Force update of the local copy of cmdGetInx */
  2275. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2276. lpfc_sli_resume_iocb(phba, pring);
  2277. if ((pring->lpfc_sli_cmd_available))
  2278. (pring->lpfc_sli_cmd_available) (phba, pring);
  2279. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2280. }
  2281. return;
  2282. }
  2283. /**
  2284. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2285. * @phba: Pointer to HBA context object.
  2286. * @pring: Pointer to driver SLI ring object.
  2287. * @mask: Host attention register mask for this ring.
  2288. *
  2289. * This function is called from the interrupt context when there is a ring
  2290. * event for the fcp ring. The caller does not hold any lock.
  2291. * The function processes each response iocb in the response ring until it
  2292. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2293. * LE bit set. The function will call the completion handler of the command iocb
  2294. * if the response iocb indicates a completion for a command iocb or it is
  2295. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2296. * function if this is an unsolicited iocb.
  2297. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2298. * to check it explicitly. This function always returns 1.
  2299. **/
  2300. static int
  2301. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2302. struct lpfc_sli_ring *pring, uint32_t mask)
  2303. {
  2304. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2305. IOCB_t *irsp = NULL;
  2306. IOCB_t *entry = NULL;
  2307. struct lpfc_iocbq *cmdiocbq = NULL;
  2308. struct lpfc_iocbq rspiocbq;
  2309. uint32_t status;
  2310. uint32_t portRspPut, portRspMax;
  2311. int rc = 1;
  2312. lpfc_iocb_type type;
  2313. unsigned long iflag;
  2314. uint32_t rsp_cmpl = 0;
  2315. spin_lock_irqsave(&phba->hbalock, iflag);
  2316. pring->stats.iocb_event++;
  2317. /*
  2318. * The next available response entry should never exceed the maximum
  2319. * entries. If it does, treat it as an adapter hardware error.
  2320. */
  2321. portRspMax = pring->numRiocb;
  2322. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2323. if (unlikely(portRspPut >= portRspMax)) {
  2324. lpfc_sli_rsp_pointers_error(phba, pring);
  2325. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2326. return 1;
  2327. }
  2328. rmb();
  2329. while (pring->rspidx != portRspPut) {
  2330. /*
  2331. * Fetch an entry off the ring and copy it into a local data
  2332. * structure. The copy involves a byte-swap since the
  2333. * network byte order and pci byte orders are different.
  2334. */
  2335. entry = lpfc_resp_iocb(phba, pring);
  2336. phba->last_completion_time = jiffies;
  2337. if (++pring->rspidx >= portRspMax)
  2338. pring->rspidx = 0;
  2339. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2340. (uint32_t *) &rspiocbq.iocb,
  2341. phba->iocb_rsp_size);
  2342. INIT_LIST_HEAD(&(rspiocbq.list));
  2343. irsp = &rspiocbq.iocb;
  2344. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2345. pring->stats.iocb_rsp++;
  2346. rsp_cmpl++;
  2347. if (unlikely(irsp->ulpStatus)) {
  2348. /*
  2349. * If resource errors reported from HBA, reduce
  2350. * queuedepths of the SCSI device.
  2351. */
  2352. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2353. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2355. phba->lpfc_rampdown_queue_depth(phba);
  2356. spin_lock_irqsave(&phba->hbalock, iflag);
  2357. }
  2358. /* Rsp ring <ringno> error: IOCB */
  2359. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2360. "0336 Rsp Ring %d error: IOCB Data: "
  2361. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2362. pring->ringno,
  2363. irsp->un.ulpWord[0],
  2364. irsp->un.ulpWord[1],
  2365. irsp->un.ulpWord[2],
  2366. irsp->un.ulpWord[3],
  2367. irsp->un.ulpWord[4],
  2368. irsp->un.ulpWord[5],
  2369. *(uint32_t *)&irsp->un1,
  2370. *((uint32_t *)&irsp->un1 + 1));
  2371. }
  2372. switch (type) {
  2373. case LPFC_ABORT_IOCB:
  2374. case LPFC_SOL_IOCB:
  2375. /*
  2376. * Idle exchange closed via ABTS from port. No iocb
  2377. * resources need to be recovered.
  2378. */
  2379. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2380. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2381. "0333 IOCB cmd 0x%x"
  2382. " processed. Skipping"
  2383. " completion\n",
  2384. irsp->ulpCommand);
  2385. break;
  2386. }
  2387. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2388. &rspiocbq);
  2389. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2390. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  2391. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2392. &rspiocbq);
  2393. } else {
  2394. spin_unlock_irqrestore(&phba->hbalock,
  2395. iflag);
  2396. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2397. &rspiocbq);
  2398. spin_lock_irqsave(&phba->hbalock,
  2399. iflag);
  2400. }
  2401. }
  2402. break;
  2403. case LPFC_UNSOL_IOCB:
  2404. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2405. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2406. spin_lock_irqsave(&phba->hbalock, iflag);
  2407. break;
  2408. default:
  2409. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2410. char adaptermsg[LPFC_MAX_ADPTMSG];
  2411. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2412. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2413. MAX_MSG_DATA);
  2414. dev_warn(&((phba->pcidev)->dev),
  2415. "lpfc%d: %s\n",
  2416. phba->brd_no, adaptermsg);
  2417. } else {
  2418. /* Unknown IOCB command */
  2419. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2420. "0334 Unknown IOCB command "
  2421. "Data: x%x, x%x x%x x%x x%x\n",
  2422. type, irsp->ulpCommand,
  2423. irsp->ulpStatus,
  2424. irsp->ulpIoTag,
  2425. irsp->ulpContext);
  2426. }
  2427. break;
  2428. }
  2429. /*
  2430. * The response IOCB has been processed. Update the ring
  2431. * pointer in SLIM. If the port response put pointer has not
  2432. * been updated, sync the pgp->rspPutInx and fetch the new port
  2433. * response put pointer.
  2434. */
  2435. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2436. if (pring->rspidx == portRspPut)
  2437. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2438. }
  2439. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2440. pring->stats.iocb_rsp_full++;
  2441. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2442. writel(status, phba->CAregaddr);
  2443. readl(phba->CAregaddr);
  2444. }
  2445. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2446. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2447. pring->stats.iocb_cmd_empty++;
  2448. /* Force update of the local copy of cmdGetInx */
  2449. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2450. lpfc_sli_resume_iocb(phba, pring);
  2451. if ((pring->lpfc_sli_cmd_available))
  2452. (pring->lpfc_sli_cmd_available) (phba, pring);
  2453. }
  2454. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2455. return rc;
  2456. }
  2457. /**
  2458. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2459. * @phba: Pointer to HBA context object.
  2460. * @pring: Pointer to driver SLI ring object.
  2461. * @rspiocbp: Pointer to driver response IOCB object.
  2462. *
  2463. * This function is called from the worker thread when there is a slow-path
  2464. * response IOCB to process. This function chains all the response iocbs until
  2465. * seeing the iocb with the LE bit set. The function will call
  2466. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2467. * completion of a command iocb. The function will call the
  2468. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2469. * The function frees the resources or calls the completion handler if this
  2470. * iocb is an abort completion. The function returns NULL when the response
  2471. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2472. * this function shall chain the iocb on to the iocb_continueq and return the
  2473. * response iocb passed in.
  2474. **/
  2475. static struct lpfc_iocbq *
  2476. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2477. struct lpfc_iocbq *rspiocbp)
  2478. {
  2479. struct lpfc_iocbq *saveq;
  2480. struct lpfc_iocbq *cmdiocbp;
  2481. struct lpfc_iocbq *next_iocb;
  2482. IOCB_t *irsp = NULL;
  2483. uint32_t free_saveq;
  2484. uint8_t iocb_cmd_type;
  2485. lpfc_iocb_type type;
  2486. unsigned long iflag;
  2487. int rc;
  2488. spin_lock_irqsave(&phba->hbalock, iflag);
  2489. /* First add the response iocb to the countinueq list */
  2490. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2491. pring->iocb_continueq_cnt++;
  2492. /* Now, determine whetehr the list is completed for processing */
  2493. irsp = &rspiocbp->iocb;
  2494. if (irsp->ulpLe) {
  2495. /*
  2496. * By default, the driver expects to free all resources
  2497. * associated with this iocb completion.
  2498. */
  2499. free_saveq = 1;
  2500. saveq = list_get_first(&pring->iocb_continueq,
  2501. struct lpfc_iocbq, list);
  2502. irsp = &(saveq->iocb);
  2503. list_del_init(&pring->iocb_continueq);
  2504. pring->iocb_continueq_cnt = 0;
  2505. pring->stats.iocb_rsp++;
  2506. /*
  2507. * If resource errors reported from HBA, reduce
  2508. * queuedepths of the SCSI device.
  2509. */
  2510. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2511. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2512. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2513. phba->lpfc_rampdown_queue_depth(phba);
  2514. spin_lock_irqsave(&phba->hbalock, iflag);
  2515. }
  2516. if (irsp->ulpStatus) {
  2517. /* Rsp ring <ringno> error: IOCB */
  2518. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2519. "0328 Rsp Ring %d error: "
  2520. "IOCB Data: "
  2521. "x%x x%x x%x x%x "
  2522. "x%x x%x x%x x%x "
  2523. "x%x x%x x%x x%x "
  2524. "x%x x%x x%x x%x\n",
  2525. pring->ringno,
  2526. irsp->un.ulpWord[0],
  2527. irsp->un.ulpWord[1],
  2528. irsp->un.ulpWord[2],
  2529. irsp->un.ulpWord[3],
  2530. irsp->un.ulpWord[4],
  2531. irsp->un.ulpWord[5],
  2532. *(((uint32_t *) irsp) + 6),
  2533. *(((uint32_t *) irsp) + 7),
  2534. *(((uint32_t *) irsp) + 8),
  2535. *(((uint32_t *) irsp) + 9),
  2536. *(((uint32_t *) irsp) + 10),
  2537. *(((uint32_t *) irsp) + 11),
  2538. *(((uint32_t *) irsp) + 12),
  2539. *(((uint32_t *) irsp) + 13),
  2540. *(((uint32_t *) irsp) + 14),
  2541. *(((uint32_t *) irsp) + 15));
  2542. }
  2543. /*
  2544. * Fetch the IOCB command type and call the correct completion
  2545. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2546. * get freed back to the lpfc_iocb_list by the discovery
  2547. * kernel thread.
  2548. */
  2549. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2550. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2551. switch (type) {
  2552. case LPFC_SOL_IOCB:
  2553. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2554. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2555. spin_lock_irqsave(&phba->hbalock, iflag);
  2556. break;
  2557. case LPFC_UNSOL_IOCB:
  2558. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2559. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2560. spin_lock_irqsave(&phba->hbalock, iflag);
  2561. if (!rc)
  2562. free_saveq = 0;
  2563. break;
  2564. case LPFC_ABORT_IOCB:
  2565. cmdiocbp = NULL;
  2566. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2567. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2568. saveq);
  2569. if (cmdiocbp) {
  2570. /* Call the specified completion routine */
  2571. if (cmdiocbp->iocb_cmpl) {
  2572. spin_unlock_irqrestore(&phba->hbalock,
  2573. iflag);
  2574. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2575. saveq);
  2576. spin_lock_irqsave(&phba->hbalock,
  2577. iflag);
  2578. } else
  2579. __lpfc_sli_release_iocbq(phba,
  2580. cmdiocbp);
  2581. }
  2582. break;
  2583. case LPFC_UNKNOWN_IOCB:
  2584. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2585. char adaptermsg[LPFC_MAX_ADPTMSG];
  2586. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2587. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2588. MAX_MSG_DATA);
  2589. dev_warn(&((phba->pcidev)->dev),
  2590. "lpfc%d: %s\n",
  2591. phba->brd_no, adaptermsg);
  2592. } else {
  2593. /* Unknown IOCB command */
  2594. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2595. "0335 Unknown IOCB "
  2596. "command Data: x%x "
  2597. "x%x x%x x%x\n",
  2598. irsp->ulpCommand,
  2599. irsp->ulpStatus,
  2600. irsp->ulpIoTag,
  2601. irsp->ulpContext);
  2602. }
  2603. break;
  2604. }
  2605. if (free_saveq) {
  2606. list_for_each_entry_safe(rspiocbp, next_iocb,
  2607. &saveq->list, list) {
  2608. list_del(&rspiocbp->list);
  2609. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2610. }
  2611. __lpfc_sli_release_iocbq(phba, saveq);
  2612. }
  2613. rspiocbp = NULL;
  2614. }
  2615. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2616. return rspiocbp;
  2617. }
  2618. /**
  2619. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2620. * @phba: Pointer to HBA context object.
  2621. * @pring: Pointer to driver SLI ring object.
  2622. * @mask: Host attention register mask for this ring.
  2623. *
  2624. * This routine wraps the actual slow_ring event process routine from the
  2625. * API jump table function pointer from the lpfc_hba struct.
  2626. **/
  2627. void
  2628. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2629. struct lpfc_sli_ring *pring, uint32_t mask)
  2630. {
  2631. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2632. }
  2633. /**
  2634. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2635. * @phba: Pointer to HBA context object.
  2636. * @pring: Pointer to driver SLI ring object.
  2637. * @mask: Host attention register mask for this ring.
  2638. *
  2639. * This function is called from the worker thread when there is a ring event
  2640. * for non-fcp rings. The caller does not hold any lock. The function will
  2641. * remove each response iocb in the response ring and calls the handle
  2642. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2643. **/
  2644. static void
  2645. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2646. struct lpfc_sli_ring *pring, uint32_t mask)
  2647. {
  2648. struct lpfc_pgp *pgp;
  2649. IOCB_t *entry;
  2650. IOCB_t *irsp = NULL;
  2651. struct lpfc_iocbq *rspiocbp = NULL;
  2652. uint32_t portRspPut, portRspMax;
  2653. unsigned long iflag;
  2654. uint32_t status;
  2655. pgp = &phba->port_gp[pring->ringno];
  2656. spin_lock_irqsave(&phba->hbalock, iflag);
  2657. pring->stats.iocb_event++;
  2658. /*
  2659. * The next available response entry should never exceed the maximum
  2660. * entries. If it does, treat it as an adapter hardware error.
  2661. */
  2662. portRspMax = pring->numRiocb;
  2663. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2664. if (portRspPut >= portRspMax) {
  2665. /*
  2666. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2667. * rsp ring <portRspMax>
  2668. */
  2669. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2670. "0303 Ring %d handler: portRspPut %d "
  2671. "is bigger than rsp ring %d\n",
  2672. pring->ringno, portRspPut, portRspMax);
  2673. phba->link_state = LPFC_HBA_ERROR;
  2674. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2675. phba->work_hs = HS_FFER3;
  2676. lpfc_handle_eratt(phba);
  2677. return;
  2678. }
  2679. rmb();
  2680. while (pring->rspidx != portRspPut) {
  2681. /*
  2682. * Build a completion list and call the appropriate handler.
  2683. * The process is to get the next available response iocb, get
  2684. * a free iocb from the list, copy the response data into the
  2685. * free iocb, insert to the continuation list, and update the
  2686. * next response index to slim. This process makes response
  2687. * iocb's in the ring available to DMA as fast as possible but
  2688. * pays a penalty for a copy operation. Since the iocb is
  2689. * only 32 bytes, this penalty is considered small relative to
  2690. * the PCI reads for register values and a slim write. When
  2691. * the ulpLe field is set, the entire Command has been
  2692. * received.
  2693. */
  2694. entry = lpfc_resp_iocb(phba, pring);
  2695. phba->last_completion_time = jiffies;
  2696. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2697. if (rspiocbp == NULL) {
  2698. printk(KERN_ERR "%s: out of buffers! Failing "
  2699. "completion.\n", __func__);
  2700. break;
  2701. }
  2702. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2703. phba->iocb_rsp_size);
  2704. irsp = &rspiocbp->iocb;
  2705. if (++pring->rspidx >= portRspMax)
  2706. pring->rspidx = 0;
  2707. if (pring->ringno == LPFC_ELS_RING) {
  2708. lpfc_debugfs_slow_ring_trc(phba,
  2709. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2710. *(((uint32_t *) irsp) + 4),
  2711. *(((uint32_t *) irsp) + 6),
  2712. *(((uint32_t *) irsp) + 7));
  2713. }
  2714. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2715. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2716. /* Handle the response IOCB */
  2717. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2718. spin_lock_irqsave(&phba->hbalock, iflag);
  2719. /*
  2720. * If the port response put pointer has not been updated, sync
  2721. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2722. * response put pointer.
  2723. */
  2724. if (pring->rspidx == portRspPut) {
  2725. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2726. }
  2727. } /* while (pring->rspidx != portRspPut) */
  2728. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2729. /* At least one response entry has been freed */
  2730. pring->stats.iocb_rsp_full++;
  2731. /* SET RxRE_RSP in Chip Att register */
  2732. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2733. writel(status, phba->CAregaddr);
  2734. readl(phba->CAregaddr); /* flush */
  2735. }
  2736. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2737. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2738. pring->stats.iocb_cmd_empty++;
  2739. /* Force update of the local copy of cmdGetInx */
  2740. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2741. lpfc_sli_resume_iocb(phba, pring);
  2742. if ((pring->lpfc_sli_cmd_available))
  2743. (pring->lpfc_sli_cmd_available) (phba, pring);
  2744. }
  2745. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2746. return;
  2747. }
  2748. /**
  2749. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2750. * @phba: Pointer to HBA context object.
  2751. * @pring: Pointer to driver SLI ring object.
  2752. * @mask: Host attention register mask for this ring.
  2753. *
  2754. * This function is called from the worker thread when there is a pending
  2755. * ELS response iocb on the driver internal slow-path response iocb worker
  2756. * queue. The caller does not hold any lock. The function will remove each
  2757. * response iocb from the response worker queue and calls the handle
  2758. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2759. **/
  2760. static void
  2761. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2762. struct lpfc_sli_ring *pring, uint32_t mask)
  2763. {
  2764. struct lpfc_iocbq *irspiocbq;
  2765. struct hbq_dmabuf *dmabuf;
  2766. struct lpfc_cq_event *cq_event;
  2767. unsigned long iflag;
  2768. while (!list_empty(&phba->sli4_hba.sp_rspiocb_work_queue)) {
  2769. /* Get the response iocb from the head of work queue */
  2770. spin_lock_irqsave(&phba->hbalock, iflag);
  2771. list_remove_head(&phba->sli4_hba.sp_rspiocb_work_queue,
  2772. cq_event, struct lpfc_cq_event, list);
  2773. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2774. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2775. case CQE_CODE_COMPL_WQE:
  2776. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2777. cq_event);
  2778. lpfc_sli_sp_handle_rspiocb(phba, pring, irspiocbq);
  2779. break;
  2780. case CQE_CODE_RECEIVE:
  2781. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2782. cq_event);
  2783. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2784. break;
  2785. default:
  2786. break;
  2787. }
  2788. }
  2789. }
  2790. /**
  2791. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2792. * @phba: Pointer to HBA context object.
  2793. * @pring: Pointer to driver SLI ring object.
  2794. *
  2795. * This function aborts all iocbs in the given ring and frees all the iocb
  2796. * objects in txq. This function issues an abort iocb for all the iocb commands
  2797. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2798. * the return of this function. The caller is not required to hold any locks.
  2799. **/
  2800. void
  2801. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2802. {
  2803. LIST_HEAD(completions);
  2804. struct lpfc_iocbq *iocb, *next_iocb;
  2805. if (pring->ringno == LPFC_ELS_RING) {
  2806. lpfc_fabric_abort_hba(phba);
  2807. }
  2808. /* Error everything on txq and txcmplq
  2809. * First do the txq.
  2810. */
  2811. spin_lock_irq(&phba->hbalock);
  2812. list_splice_init(&pring->txq, &completions);
  2813. pring->txq_cnt = 0;
  2814. /* Next issue ABTS for everything on the txcmplq */
  2815. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2816. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2817. spin_unlock_irq(&phba->hbalock);
  2818. /* Cancel all the IOCBs from the completions list */
  2819. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2820. IOERR_SLI_ABORTED);
  2821. }
  2822. /**
  2823. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2824. * @phba: Pointer to HBA context object.
  2825. *
  2826. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2827. * objects in txq and txcmplq. This function will not issue abort iocbs
  2828. * for all the iocb commands in txcmplq, they will just be returned with
  2829. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2830. * slot has been permanently disabled.
  2831. **/
  2832. void
  2833. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2834. {
  2835. LIST_HEAD(txq);
  2836. LIST_HEAD(txcmplq);
  2837. struct lpfc_sli *psli = &phba->sli;
  2838. struct lpfc_sli_ring *pring;
  2839. /* Currently, only one fcp ring */
  2840. pring = &psli->ring[psli->fcp_ring];
  2841. spin_lock_irq(&phba->hbalock);
  2842. /* Retrieve everything on txq */
  2843. list_splice_init(&pring->txq, &txq);
  2844. pring->txq_cnt = 0;
  2845. /* Retrieve everything on the txcmplq */
  2846. list_splice_init(&pring->txcmplq, &txcmplq);
  2847. pring->txcmplq_cnt = 0;
  2848. spin_unlock_irq(&phba->hbalock);
  2849. /* Flush the txq */
  2850. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2851. IOERR_SLI_DOWN);
  2852. /* Flush the txcmpq */
  2853. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2854. IOERR_SLI_DOWN);
  2855. }
  2856. /**
  2857. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2858. * @phba: Pointer to HBA context object.
  2859. * @mask: Bit mask to be checked.
  2860. *
  2861. * This function reads the host status register and compares
  2862. * with the provided bit mask to check if HBA completed
  2863. * the restart. This function will wait in a loop for the
  2864. * HBA to complete restart. If the HBA does not restart within
  2865. * 15 iterations, the function will reset the HBA again. The
  2866. * function returns 1 when HBA fail to restart otherwise returns
  2867. * zero.
  2868. **/
  2869. static int
  2870. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2871. {
  2872. uint32_t status;
  2873. int i = 0;
  2874. int retval = 0;
  2875. /* Read the HBA Host Status Register */
  2876. status = readl(phba->HSregaddr);
  2877. /*
  2878. * Check status register every 100ms for 5 retries, then every
  2879. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2880. * every 2.5 sec for 4.
  2881. * Break our of the loop if errors occurred during init.
  2882. */
  2883. while (((status & mask) != mask) &&
  2884. !(status & HS_FFERM) &&
  2885. i++ < 20) {
  2886. if (i <= 5)
  2887. msleep(10);
  2888. else if (i <= 10)
  2889. msleep(500);
  2890. else
  2891. msleep(2500);
  2892. if (i == 15) {
  2893. /* Do post */
  2894. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2895. lpfc_sli_brdrestart(phba);
  2896. }
  2897. /* Read the HBA Host Status Register */
  2898. status = readl(phba->HSregaddr);
  2899. }
  2900. /* Check to see if any errors occurred during init */
  2901. if ((status & HS_FFERM) || (i >= 20)) {
  2902. phba->link_state = LPFC_HBA_ERROR;
  2903. retval = 1;
  2904. }
  2905. return retval;
  2906. }
  2907. /**
  2908. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2909. * @phba: Pointer to HBA context object.
  2910. * @mask: Bit mask to be checked.
  2911. *
  2912. * This function checks the host status register to check if HBA is
  2913. * ready. This function will wait in a loop for the HBA to be ready
  2914. * If the HBA is not ready , the function will will reset the HBA PCI
  2915. * function again. The function returns 1 when HBA fail to be ready
  2916. * otherwise returns zero.
  2917. **/
  2918. static int
  2919. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2920. {
  2921. uint32_t status;
  2922. int retval = 0;
  2923. /* Read the HBA Host Status Register */
  2924. status = lpfc_sli4_post_status_check(phba);
  2925. if (status) {
  2926. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2927. lpfc_sli_brdrestart(phba);
  2928. status = lpfc_sli4_post_status_check(phba);
  2929. }
  2930. /* Check to see if any errors occurred during init */
  2931. if (status) {
  2932. phba->link_state = LPFC_HBA_ERROR;
  2933. retval = 1;
  2934. } else
  2935. phba->sli4_hba.intr_enable = 0;
  2936. return retval;
  2937. }
  2938. /**
  2939. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2940. * @phba: Pointer to HBA context object.
  2941. * @mask: Bit mask to be checked.
  2942. *
  2943. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2944. * from the API jump table function pointer from the lpfc_hba struct.
  2945. **/
  2946. int
  2947. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2948. {
  2949. return phba->lpfc_sli_brdready(phba, mask);
  2950. }
  2951. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2952. /**
  2953. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2954. * @phba: Pointer to HBA context object.
  2955. *
  2956. * This function is called before resetting an HBA. This
  2957. * function requests HBA to quiesce DMAs before a reset.
  2958. **/
  2959. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2960. {
  2961. uint32_t __iomem *resp_buf;
  2962. uint32_t __iomem *mbox_buf;
  2963. volatile uint32_t mbox;
  2964. uint32_t hc_copy;
  2965. int i;
  2966. uint8_t hdrtype;
  2967. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2968. if (hdrtype != 0x80 ||
  2969. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2970. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2971. return;
  2972. /*
  2973. * Tell the other part of the chip to suspend temporarily all
  2974. * its DMA activity.
  2975. */
  2976. resp_buf = phba->MBslimaddr;
  2977. /* Disable the error attention */
  2978. hc_copy = readl(phba->HCregaddr);
  2979. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2980. readl(phba->HCregaddr); /* flush */
  2981. phba->link_flag |= LS_IGNORE_ERATT;
  2982. if (readl(phba->HAregaddr) & HA_ERATT) {
  2983. /* Clear Chip error bit */
  2984. writel(HA_ERATT, phba->HAregaddr);
  2985. phba->pport->stopped = 1;
  2986. }
  2987. mbox = 0;
  2988. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2989. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2990. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2991. mbox_buf = phba->MBslimaddr;
  2992. writel(mbox, mbox_buf);
  2993. for (i = 0;
  2994. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2995. mdelay(1);
  2996. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2997. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2998. phba->pport->stopped)
  2999. goto restore_hc;
  3000. else
  3001. goto clear_errat;
  3002. }
  3003. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3004. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  3005. mdelay(1);
  3006. clear_errat:
  3007. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3008. mdelay(1);
  3009. if (readl(phba->HAregaddr) & HA_ERATT) {
  3010. writel(HA_ERATT, phba->HAregaddr);
  3011. phba->pport->stopped = 1;
  3012. }
  3013. restore_hc:
  3014. phba->link_flag &= ~LS_IGNORE_ERATT;
  3015. writel(hc_copy, phba->HCregaddr);
  3016. readl(phba->HCregaddr); /* flush */
  3017. }
  3018. /**
  3019. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3020. * @phba: Pointer to HBA context object.
  3021. *
  3022. * This function issues a kill_board mailbox command and waits for
  3023. * the error attention interrupt. This function is called for stopping
  3024. * the firmware processing. The caller is not required to hold any
  3025. * locks. This function calls lpfc_hba_down_post function to free
  3026. * any pending commands after the kill. The function will return 1 when it
  3027. * fails to kill the board else will return 0.
  3028. **/
  3029. int
  3030. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3031. {
  3032. struct lpfc_sli *psli;
  3033. LPFC_MBOXQ_t *pmb;
  3034. uint32_t status;
  3035. uint32_t ha_copy;
  3036. int retval;
  3037. int i = 0;
  3038. psli = &phba->sli;
  3039. /* Kill HBA */
  3040. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3041. "0329 Kill HBA Data: x%x x%x\n",
  3042. phba->pport->port_state, psli->sli_flag);
  3043. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3044. if (!pmb)
  3045. return 1;
  3046. /* Disable the error attention */
  3047. spin_lock_irq(&phba->hbalock);
  3048. status = readl(phba->HCregaddr);
  3049. status &= ~HC_ERINT_ENA;
  3050. writel(status, phba->HCregaddr);
  3051. readl(phba->HCregaddr); /* flush */
  3052. phba->link_flag |= LS_IGNORE_ERATT;
  3053. spin_unlock_irq(&phba->hbalock);
  3054. lpfc_kill_board(phba, pmb);
  3055. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3056. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3057. if (retval != MBX_SUCCESS) {
  3058. if (retval != MBX_BUSY)
  3059. mempool_free(pmb, phba->mbox_mem_pool);
  3060. spin_lock_irq(&phba->hbalock);
  3061. phba->link_flag &= ~LS_IGNORE_ERATT;
  3062. spin_unlock_irq(&phba->hbalock);
  3063. return 1;
  3064. }
  3065. spin_lock_irq(&phba->hbalock);
  3066. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3067. spin_unlock_irq(&phba->hbalock);
  3068. mempool_free(pmb, phba->mbox_mem_pool);
  3069. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3070. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3071. * 3 seconds we still set HBA_ERROR state because the status of the
  3072. * board is now undefined.
  3073. */
  3074. ha_copy = readl(phba->HAregaddr);
  3075. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3076. mdelay(100);
  3077. ha_copy = readl(phba->HAregaddr);
  3078. }
  3079. del_timer_sync(&psli->mbox_tmo);
  3080. if (ha_copy & HA_ERATT) {
  3081. writel(HA_ERATT, phba->HAregaddr);
  3082. phba->pport->stopped = 1;
  3083. }
  3084. spin_lock_irq(&phba->hbalock);
  3085. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3086. psli->mbox_active = NULL;
  3087. phba->link_flag &= ~LS_IGNORE_ERATT;
  3088. spin_unlock_irq(&phba->hbalock);
  3089. lpfc_hba_down_post(phba);
  3090. phba->link_state = LPFC_HBA_ERROR;
  3091. return ha_copy & HA_ERATT ? 0 : 1;
  3092. }
  3093. /**
  3094. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3095. * @phba: Pointer to HBA context object.
  3096. *
  3097. * This function resets the HBA by writing HC_INITFF to the control
  3098. * register. After the HBA resets, this function resets all the iocb ring
  3099. * indices. This function disables PCI layer parity checking during
  3100. * the reset.
  3101. * This function returns 0 always.
  3102. * The caller is not required to hold any locks.
  3103. **/
  3104. int
  3105. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3106. {
  3107. struct lpfc_sli *psli;
  3108. struct lpfc_sli_ring *pring;
  3109. uint16_t cfg_value;
  3110. int i;
  3111. psli = &phba->sli;
  3112. /* Reset HBA */
  3113. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3114. "0325 Reset HBA Data: x%x x%x\n",
  3115. phba->pport->port_state, psli->sli_flag);
  3116. /* perform board reset */
  3117. phba->fc_eventTag = 0;
  3118. phba->link_events = 0;
  3119. phba->pport->fc_myDID = 0;
  3120. phba->pport->fc_prevDID = 0;
  3121. /* Turn off parity checking and serr during the physical reset */
  3122. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3123. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3124. (cfg_value &
  3125. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3126. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3127. /* Now toggle INITFF bit in the Host Control Register */
  3128. writel(HC_INITFF, phba->HCregaddr);
  3129. mdelay(1);
  3130. readl(phba->HCregaddr); /* flush */
  3131. writel(0, phba->HCregaddr);
  3132. readl(phba->HCregaddr); /* flush */
  3133. /* Restore PCI cmd register */
  3134. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3135. /* Initialize relevant SLI info */
  3136. for (i = 0; i < psli->num_rings; i++) {
  3137. pring = &psli->ring[i];
  3138. pring->flag = 0;
  3139. pring->rspidx = 0;
  3140. pring->next_cmdidx = 0;
  3141. pring->local_getidx = 0;
  3142. pring->cmdidx = 0;
  3143. pring->missbufcnt = 0;
  3144. }
  3145. phba->link_state = LPFC_WARM_START;
  3146. return 0;
  3147. }
  3148. /**
  3149. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3150. * @phba: Pointer to HBA context object.
  3151. *
  3152. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3153. * checking during resets the device. The caller is not required to hold
  3154. * any locks.
  3155. *
  3156. * This function returns 0 always.
  3157. **/
  3158. int
  3159. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3160. {
  3161. struct lpfc_sli *psli = &phba->sli;
  3162. uint16_t cfg_value;
  3163. uint8_t qindx;
  3164. /* Reset HBA */
  3165. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3166. "0295 Reset HBA Data: x%x x%x\n",
  3167. phba->pport->port_state, psli->sli_flag);
  3168. /* perform board reset */
  3169. phba->fc_eventTag = 0;
  3170. phba->link_events = 0;
  3171. phba->pport->fc_myDID = 0;
  3172. phba->pport->fc_prevDID = 0;
  3173. /* Turn off parity checking and serr during the physical reset */
  3174. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3175. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3176. (cfg_value &
  3177. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3178. spin_lock_irq(&phba->hbalock);
  3179. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3180. phba->fcf.fcf_flag = 0;
  3181. /* Clean up the child queue list for the CQs */
  3182. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3183. list_del_init(&phba->sli4_hba.els_wq->list);
  3184. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3185. list_del_init(&phba->sli4_hba.dat_rq->list);
  3186. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3187. list_del_init(&phba->sli4_hba.els_cq->list);
  3188. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3189. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3190. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3191. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3192. spin_unlock_irq(&phba->hbalock);
  3193. /* Now physically reset the device */
  3194. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3195. "0389 Performing PCI function reset!\n");
  3196. /* Perform FCoE PCI function reset */
  3197. lpfc_pci_function_reset(phba);
  3198. return 0;
  3199. }
  3200. /**
  3201. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3202. * @phba: Pointer to HBA context object.
  3203. *
  3204. * This function is called in the SLI initialization code path to
  3205. * restart the HBA. The caller is not required to hold any lock.
  3206. * This function writes MBX_RESTART mailbox command to the SLIM and
  3207. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3208. * function to free any pending commands. The function enables
  3209. * POST only during the first initialization. The function returns zero.
  3210. * The function does not guarantee completion of MBX_RESTART mailbox
  3211. * command before the return of this function.
  3212. **/
  3213. static int
  3214. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3215. {
  3216. MAILBOX_t *mb;
  3217. struct lpfc_sli *psli;
  3218. volatile uint32_t word0;
  3219. void __iomem *to_slim;
  3220. spin_lock_irq(&phba->hbalock);
  3221. psli = &phba->sli;
  3222. /* Restart HBA */
  3223. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3224. "0337 Restart HBA Data: x%x x%x\n",
  3225. phba->pport->port_state, psli->sli_flag);
  3226. word0 = 0;
  3227. mb = (MAILBOX_t *) &word0;
  3228. mb->mbxCommand = MBX_RESTART;
  3229. mb->mbxHc = 1;
  3230. lpfc_reset_barrier(phba);
  3231. to_slim = phba->MBslimaddr;
  3232. writel(*(uint32_t *) mb, to_slim);
  3233. readl(to_slim); /* flush */
  3234. /* Only skip post after fc_ffinit is completed */
  3235. if (phba->pport->port_state)
  3236. word0 = 1; /* This is really setting up word1 */
  3237. else
  3238. word0 = 0; /* This is really setting up word1 */
  3239. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3240. writel(*(uint32_t *) mb, to_slim);
  3241. readl(to_slim); /* flush */
  3242. lpfc_sli_brdreset(phba);
  3243. phba->pport->stopped = 0;
  3244. phba->link_state = LPFC_INIT_START;
  3245. phba->hba_flag = 0;
  3246. spin_unlock_irq(&phba->hbalock);
  3247. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3248. psli->stats_start = get_seconds();
  3249. /* Give the INITFF and Post time to settle. */
  3250. mdelay(100);
  3251. lpfc_hba_down_post(phba);
  3252. return 0;
  3253. }
  3254. /**
  3255. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3256. * @phba: Pointer to HBA context object.
  3257. *
  3258. * This function is called in the SLI initialization code path to restart
  3259. * a SLI4 HBA. The caller is not required to hold any lock.
  3260. * At the end of the function, it calls lpfc_hba_down_post function to
  3261. * free any pending commands.
  3262. **/
  3263. static int
  3264. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3265. {
  3266. struct lpfc_sli *psli = &phba->sli;
  3267. /* Restart HBA */
  3268. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3269. "0296 Restart HBA Data: x%x x%x\n",
  3270. phba->pport->port_state, psli->sli_flag);
  3271. lpfc_sli4_brdreset(phba);
  3272. spin_lock_irq(&phba->hbalock);
  3273. phba->pport->stopped = 0;
  3274. phba->link_state = LPFC_INIT_START;
  3275. phba->hba_flag = 0;
  3276. spin_unlock_irq(&phba->hbalock);
  3277. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3278. psli->stats_start = get_seconds();
  3279. lpfc_hba_down_post(phba);
  3280. return 0;
  3281. }
  3282. /**
  3283. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3284. * @phba: Pointer to HBA context object.
  3285. *
  3286. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3287. * API jump table function pointer from the lpfc_hba struct.
  3288. **/
  3289. int
  3290. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3291. {
  3292. return phba->lpfc_sli_brdrestart(phba);
  3293. }
  3294. /**
  3295. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3296. * @phba: Pointer to HBA context object.
  3297. *
  3298. * This function is called after a HBA restart to wait for successful
  3299. * restart of the HBA. Successful restart of the HBA is indicated by
  3300. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3301. * iteration, the function will restart the HBA again. The function returns
  3302. * zero if HBA successfully restarted else returns negative error code.
  3303. **/
  3304. static int
  3305. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3306. {
  3307. uint32_t status, i = 0;
  3308. /* Read the HBA Host Status Register */
  3309. status = readl(phba->HSregaddr);
  3310. /* Check status register to see what current state is */
  3311. i = 0;
  3312. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3313. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3314. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3315. * 4.
  3316. */
  3317. if (i++ >= 20) {
  3318. /* Adapter failed to init, timeout, status reg
  3319. <status> */
  3320. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3321. "0436 Adapter failed to init, "
  3322. "timeout, status reg x%x, "
  3323. "FW Data: A8 x%x AC x%x\n", status,
  3324. readl(phba->MBslimaddr + 0xa8),
  3325. readl(phba->MBslimaddr + 0xac));
  3326. phba->link_state = LPFC_HBA_ERROR;
  3327. return -ETIMEDOUT;
  3328. }
  3329. /* Check to see if any errors occurred during init */
  3330. if (status & HS_FFERM) {
  3331. /* ERROR: During chipset initialization */
  3332. /* Adapter failed to init, chipset, status reg
  3333. <status> */
  3334. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3335. "0437 Adapter failed to init, "
  3336. "chipset, status reg x%x, "
  3337. "FW Data: A8 x%x AC x%x\n", status,
  3338. readl(phba->MBslimaddr + 0xa8),
  3339. readl(phba->MBslimaddr + 0xac));
  3340. phba->link_state = LPFC_HBA_ERROR;
  3341. return -EIO;
  3342. }
  3343. if (i <= 5) {
  3344. msleep(10);
  3345. } else if (i <= 10) {
  3346. msleep(500);
  3347. } else {
  3348. msleep(2500);
  3349. }
  3350. if (i == 15) {
  3351. /* Do post */
  3352. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3353. lpfc_sli_brdrestart(phba);
  3354. }
  3355. /* Read the HBA Host Status Register */
  3356. status = readl(phba->HSregaddr);
  3357. }
  3358. /* Check to see if any errors occurred during init */
  3359. if (status & HS_FFERM) {
  3360. /* ERROR: During chipset initialization */
  3361. /* Adapter failed to init, chipset, status reg <status> */
  3362. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3363. "0438 Adapter failed to init, chipset, "
  3364. "status reg x%x, "
  3365. "FW Data: A8 x%x AC x%x\n", status,
  3366. readl(phba->MBslimaddr + 0xa8),
  3367. readl(phba->MBslimaddr + 0xac));
  3368. phba->link_state = LPFC_HBA_ERROR;
  3369. return -EIO;
  3370. }
  3371. /* Clear all interrupt enable conditions */
  3372. writel(0, phba->HCregaddr);
  3373. readl(phba->HCregaddr); /* flush */
  3374. /* setup host attn register */
  3375. writel(0xffffffff, phba->HAregaddr);
  3376. readl(phba->HAregaddr); /* flush */
  3377. return 0;
  3378. }
  3379. /**
  3380. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3381. *
  3382. * This function calculates and returns the number of HBQs required to be
  3383. * configured.
  3384. **/
  3385. int
  3386. lpfc_sli_hbq_count(void)
  3387. {
  3388. return ARRAY_SIZE(lpfc_hbq_defs);
  3389. }
  3390. /**
  3391. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3392. *
  3393. * This function adds the number of hbq entries in every HBQ to get
  3394. * the total number of hbq entries required for the HBA and returns
  3395. * the total count.
  3396. **/
  3397. static int
  3398. lpfc_sli_hbq_entry_count(void)
  3399. {
  3400. int hbq_count = lpfc_sli_hbq_count();
  3401. int count = 0;
  3402. int i;
  3403. for (i = 0; i < hbq_count; ++i)
  3404. count += lpfc_hbq_defs[i]->entry_count;
  3405. return count;
  3406. }
  3407. /**
  3408. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3409. *
  3410. * This function calculates amount of memory required for all hbq entries
  3411. * to be configured and returns the total memory required.
  3412. **/
  3413. int
  3414. lpfc_sli_hbq_size(void)
  3415. {
  3416. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3417. }
  3418. /**
  3419. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3420. * @phba: Pointer to HBA context object.
  3421. *
  3422. * This function is called during the SLI initialization to configure
  3423. * all the HBQs and post buffers to the HBQ. The caller is not
  3424. * required to hold any locks. This function will return zero if successful
  3425. * else it will return negative error code.
  3426. **/
  3427. static int
  3428. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3429. {
  3430. int hbq_count = lpfc_sli_hbq_count();
  3431. LPFC_MBOXQ_t *pmb;
  3432. MAILBOX_t *pmbox;
  3433. uint32_t hbqno;
  3434. uint32_t hbq_entry_index;
  3435. /* Get a Mailbox buffer to setup mailbox
  3436. * commands for HBA initialization
  3437. */
  3438. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3439. if (!pmb)
  3440. return -ENOMEM;
  3441. pmbox = &pmb->u.mb;
  3442. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3443. phba->link_state = LPFC_INIT_MBX_CMDS;
  3444. phba->hbq_in_use = 1;
  3445. hbq_entry_index = 0;
  3446. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3447. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3448. phba->hbqs[hbqno].hbqPutIdx = 0;
  3449. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3450. phba->hbqs[hbqno].entry_count =
  3451. lpfc_hbq_defs[hbqno]->entry_count;
  3452. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3453. hbq_entry_index, pmb);
  3454. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3455. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3456. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3457. mbxStatus <status>, ring <num> */
  3458. lpfc_printf_log(phba, KERN_ERR,
  3459. LOG_SLI | LOG_VPORT,
  3460. "1805 Adapter failed to init. "
  3461. "Data: x%x x%x x%x\n",
  3462. pmbox->mbxCommand,
  3463. pmbox->mbxStatus, hbqno);
  3464. phba->link_state = LPFC_HBA_ERROR;
  3465. mempool_free(pmb, phba->mbox_mem_pool);
  3466. return ENXIO;
  3467. }
  3468. }
  3469. phba->hbq_count = hbq_count;
  3470. mempool_free(pmb, phba->mbox_mem_pool);
  3471. /* Initially populate or replenish the HBQs */
  3472. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3473. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3474. return 0;
  3475. }
  3476. /**
  3477. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3478. * @phba: Pointer to HBA context object.
  3479. *
  3480. * This function is called during the SLI initialization to configure
  3481. * all the HBQs and post buffers to the HBQ. The caller is not
  3482. * required to hold any locks. This function will return zero if successful
  3483. * else it will return negative error code.
  3484. **/
  3485. static int
  3486. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3487. {
  3488. phba->hbq_in_use = 1;
  3489. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3490. phba->hbq_count = 1;
  3491. /* Initially populate or replenish the HBQs */
  3492. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3493. return 0;
  3494. }
  3495. /**
  3496. * lpfc_sli_config_port - Issue config port mailbox command
  3497. * @phba: Pointer to HBA context object.
  3498. * @sli_mode: sli mode - 2/3
  3499. *
  3500. * This function is called by the sli intialization code path
  3501. * to issue config_port mailbox command. This function restarts the
  3502. * HBA firmware and issues a config_port mailbox command to configure
  3503. * the SLI interface in the sli mode specified by sli_mode
  3504. * variable. The caller is not required to hold any locks.
  3505. * The function returns 0 if successful, else returns negative error
  3506. * code.
  3507. **/
  3508. int
  3509. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3510. {
  3511. LPFC_MBOXQ_t *pmb;
  3512. uint32_t resetcount = 0, rc = 0, done = 0;
  3513. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3514. if (!pmb) {
  3515. phba->link_state = LPFC_HBA_ERROR;
  3516. return -ENOMEM;
  3517. }
  3518. phba->sli_rev = sli_mode;
  3519. while (resetcount < 2 && !done) {
  3520. spin_lock_irq(&phba->hbalock);
  3521. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3522. spin_unlock_irq(&phba->hbalock);
  3523. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3524. lpfc_sli_brdrestart(phba);
  3525. rc = lpfc_sli_chipset_init(phba);
  3526. if (rc)
  3527. break;
  3528. spin_lock_irq(&phba->hbalock);
  3529. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3530. spin_unlock_irq(&phba->hbalock);
  3531. resetcount++;
  3532. /* Call pre CONFIG_PORT mailbox command initialization. A
  3533. * value of 0 means the call was successful. Any other
  3534. * nonzero value is a failure, but if ERESTART is returned,
  3535. * the driver may reset the HBA and try again.
  3536. */
  3537. rc = lpfc_config_port_prep(phba);
  3538. if (rc == -ERESTART) {
  3539. phba->link_state = LPFC_LINK_UNKNOWN;
  3540. continue;
  3541. } else if (rc)
  3542. break;
  3543. phba->link_state = LPFC_INIT_MBX_CMDS;
  3544. lpfc_config_port(phba, pmb);
  3545. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3546. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3547. LPFC_SLI3_HBQ_ENABLED |
  3548. LPFC_SLI3_CRP_ENABLED |
  3549. LPFC_SLI3_INB_ENABLED |
  3550. LPFC_SLI3_BG_ENABLED);
  3551. if (rc != MBX_SUCCESS) {
  3552. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3553. "0442 Adapter failed to init, mbxCmd x%x "
  3554. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3555. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3556. spin_lock_irq(&phba->hbalock);
  3557. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3558. spin_unlock_irq(&phba->hbalock);
  3559. rc = -ENXIO;
  3560. } else {
  3561. /* Allow asynchronous mailbox command to go through */
  3562. spin_lock_irq(&phba->hbalock);
  3563. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3564. spin_unlock_irq(&phba->hbalock);
  3565. done = 1;
  3566. }
  3567. }
  3568. if (!done) {
  3569. rc = -EINVAL;
  3570. goto do_prep_failed;
  3571. }
  3572. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3573. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3574. rc = -ENXIO;
  3575. goto do_prep_failed;
  3576. }
  3577. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3578. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3579. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3580. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3581. phba->max_vpi : phba->max_vports;
  3582. } else
  3583. phba->max_vpi = 0;
  3584. if (pmb->u.mb.un.varCfgPort.gdss)
  3585. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3586. if (pmb->u.mb.un.varCfgPort.gerbm)
  3587. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3588. if (pmb->u.mb.un.varCfgPort.gcrp)
  3589. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3590. if (pmb->u.mb.un.varCfgPort.ginb) {
  3591. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3592. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3593. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3594. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3595. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3596. phba->inb_last_counter =
  3597. phba->mbox->us.s3_inb_pgp.counter;
  3598. } else {
  3599. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3600. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3601. phba->inb_ha_copy = NULL;
  3602. phba->inb_counter = NULL;
  3603. }
  3604. if (phba->cfg_enable_bg) {
  3605. if (pmb->u.mb.un.varCfgPort.gbg)
  3606. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3607. else
  3608. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3609. "0443 Adapter did not grant "
  3610. "BlockGuard\n");
  3611. }
  3612. } else {
  3613. phba->hbq_get = NULL;
  3614. phba->port_gp = phba->mbox->us.s2.port;
  3615. phba->inb_ha_copy = NULL;
  3616. phba->inb_counter = NULL;
  3617. phba->max_vpi = 0;
  3618. }
  3619. do_prep_failed:
  3620. mempool_free(pmb, phba->mbox_mem_pool);
  3621. return rc;
  3622. }
  3623. /**
  3624. * lpfc_sli_hba_setup - SLI intialization function
  3625. * @phba: Pointer to HBA context object.
  3626. *
  3627. * This function is the main SLI intialization function. This function
  3628. * is called by the HBA intialization code, HBA reset code and HBA
  3629. * error attention handler code. Caller is not required to hold any
  3630. * locks. This function issues config_port mailbox command to configure
  3631. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3632. * calls the config_port_post function to issue init_link mailbox
  3633. * command and to start the discovery. The function will return zero
  3634. * if successful, else it will return negative error code.
  3635. **/
  3636. int
  3637. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3638. {
  3639. uint32_t rc;
  3640. int mode = 3;
  3641. switch (lpfc_sli_mode) {
  3642. case 2:
  3643. if (phba->cfg_enable_npiv) {
  3644. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3645. "1824 NPIV enabled: Override lpfc_sli_mode "
  3646. "parameter (%d) to auto (0).\n",
  3647. lpfc_sli_mode);
  3648. break;
  3649. }
  3650. mode = 2;
  3651. break;
  3652. case 0:
  3653. case 3:
  3654. break;
  3655. default:
  3656. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3657. "1819 Unrecognized lpfc_sli_mode "
  3658. "parameter: %d.\n", lpfc_sli_mode);
  3659. break;
  3660. }
  3661. rc = lpfc_sli_config_port(phba, mode);
  3662. if (rc && lpfc_sli_mode == 3)
  3663. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3664. "1820 Unable to select SLI-3. "
  3665. "Not supported by adapter.\n");
  3666. if (rc && mode != 2)
  3667. rc = lpfc_sli_config_port(phba, 2);
  3668. if (rc)
  3669. goto lpfc_sli_hba_setup_error;
  3670. if (phba->sli_rev == 3) {
  3671. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3672. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3673. } else {
  3674. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3675. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3676. phba->sli3_options = 0;
  3677. }
  3678. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3679. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3680. phba->sli_rev, phba->max_vpi);
  3681. rc = lpfc_sli_ring_map(phba);
  3682. if (rc)
  3683. goto lpfc_sli_hba_setup_error;
  3684. /* Init HBQs */
  3685. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3686. rc = lpfc_sli_hbq_setup(phba);
  3687. if (rc)
  3688. goto lpfc_sli_hba_setup_error;
  3689. }
  3690. spin_lock_irq(&phba->hbalock);
  3691. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3692. spin_unlock_irq(&phba->hbalock);
  3693. rc = lpfc_config_port_post(phba);
  3694. if (rc)
  3695. goto lpfc_sli_hba_setup_error;
  3696. return rc;
  3697. lpfc_sli_hba_setup_error:
  3698. phba->link_state = LPFC_HBA_ERROR;
  3699. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3700. "0445 Firmware initialization failed\n");
  3701. return rc;
  3702. }
  3703. /**
  3704. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3705. * @phba: Pointer to HBA context object.
  3706. * @mboxq: mailbox pointer.
  3707. * This function issue a dump mailbox command to read config region
  3708. * 23 and parse the records in the region and populate driver
  3709. * data structure.
  3710. **/
  3711. static int
  3712. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3713. LPFC_MBOXQ_t *mboxq)
  3714. {
  3715. struct lpfc_dmabuf *mp;
  3716. struct lpfc_mqe *mqe;
  3717. uint32_t data_length;
  3718. int rc;
  3719. /* Program the default value of vlan_id and fc_map */
  3720. phba->valid_vlan = 0;
  3721. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3722. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3723. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3724. mqe = &mboxq->u.mqe;
  3725. if (lpfc_dump_fcoe_param(phba, mboxq))
  3726. return -ENOMEM;
  3727. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3728. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3729. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3730. "(%d):2571 Mailbox cmd x%x Status x%x "
  3731. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3732. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3733. "CQ: x%x x%x x%x x%x\n",
  3734. mboxq->vport ? mboxq->vport->vpi : 0,
  3735. bf_get(lpfc_mqe_command, mqe),
  3736. bf_get(lpfc_mqe_status, mqe),
  3737. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3738. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3739. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3740. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3741. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3742. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3743. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3744. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3745. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3746. mboxq->mcqe.word0,
  3747. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3748. mboxq->mcqe.trailer);
  3749. if (rc) {
  3750. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3751. kfree(mp);
  3752. return -EIO;
  3753. }
  3754. data_length = mqe->un.mb_words[5];
  3755. if (data_length > DMP_RGN23_SIZE) {
  3756. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3757. kfree(mp);
  3758. return -EIO;
  3759. }
  3760. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3761. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3762. kfree(mp);
  3763. return 0;
  3764. }
  3765. /**
  3766. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3767. * @phba: pointer to lpfc hba data structure.
  3768. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3769. * @vpd: pointer to the memory to hold resulting port vpd data.
  3770. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3771. * On output, the number of data bytes in @vpd.
  3772. *
  3773. * This routine executes a READ_REV SLI4 mailbox command. In
  3774. * addition, this routine gets the port vpd data.
  3775. *
  3776. * Return codes
  3777. * 0 - sucessful
  3778. * ENOMEM - could not allocated memory.
  3779. **/
  3780. static int
  3781. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3782. uint8_t *vpd, uint32_t *vpd_size)
  3783. {
  3784. int rc = 0;
  3785. uint32_t dma_size;
  3786. struct lpfc_dmabuf *dmabuf;
  3787. struct lpfc_mqe *mqe;
  3788. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3789. if (!dmabuf)
  3790. return -ENOMEM;
  3791. /*
  3792. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3793. * mailbox command.
  3794. */
  3795. dma_size = *vpd_size;
  3796. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3797. dma_size,
  3798. &dmabuf->phys,
  3799. GFP_KERNEL);
  3800. if (!dmabuf->virt) {
  3801. kfree(dmabuf);
  3802. return -ENOMEM;
  3803. }
  3804. memset(dmabuf->virt, 0, dma_size);
  3805. /*
  3806. * The SLI4 implementation of READ_REV conflicts at word1,
  3807. * bits 31:16 and SLI4 adds vpd functionality not present
  3808. * in SLI3. This code corrects the conflicts.
  3809. */
  3810. lpfc_read_rev(phba, mboxq);
  3811. mqe = &mboxq->u.mqe;
  3812. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3813. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3814. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3815. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3816. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3817. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3818. if (rc) {
  3819. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3820. dmabuf->virt, dmabuf->phys);
  3821. return -EIO;
  3822. }
  3823. /*
  3824. * The available vpd length cannot be bigger than the
  3825. * DMA buffer passed to the port. Catch the less than
  3826. * case and update the caller's size.
  3827. */
  3828. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3829. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3830. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3831. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3832. dmabuf->virt, dmabuf->phys);
  3833. kfree(dmabuf);
  3834. return 0;
  3835. }
  3836. /**
  3837. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3838. * @phba: pointer to lpfc hba data structure.
  3839. *
  3840. * This routine is called to explicitly arm the SLI4 device's completion and
  3841. * event queues
  3842. **/
  3843. static void
  3844. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3845. {
  3846. uint8_t fcp_eqidx;
  3847. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3848. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3849. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3850. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3851. LPFC_QUEUE_REARM);
  3852. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3853. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3854. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3855. LPFC_QUEUE_REARM);
  3856. }
  3857. /**
  3858. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3859. * @phba: Pointer to HBA context object.
  3860. *
  3861. * This function is the main SLI4 device intialization PCI function. This
  3862. * function is called by the HBA intialization code, HBA reset code and
  3863. * HBA error attention handler code. Caller is not required to hold any
  3864. * locks.
  3865. **/
  3866. int
  3867. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3868. {
  3869. int rc;
  3870. LPFC_MBOXQ_t *mboxq;
  3871. struct lpfc_mqe *mqe;
  3872. uint8_t *vpd;
  3873. uint32_t vpd_size;
  3874. uint32_t ftr_rsp = 0;
  3875. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3876. struct lpfc_vport *vport = phba->pport;
  3877. struct lpfc_dmabuf *mp;
  3878. /* Perform a PCI function reset to start from clean */
  3879. rc = lpfc_pci_function_reset(phba);
  3880. if (unlikely(rc))
  3881. return -ENODEV;
  3882. /* Check the HBA Host Status Register for readyness */
  3883. rc = lpfc_sli4_post_status_check(phba);
  3884. if (unlikely(rc))
  3885. return -ENODEV;
  3886. else {
  3887. spin_lock_irq(&phba->hbalock);
  3888. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3889. spin_unlock_irq(&phba->hbalock);
  3890. }
  3891. /*
  3892. * Allocate a single mailbox container for initializing the
  3893. * port.
  3894. */
  3895. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3896. if (!mboxq)
  3897. return -ENOMEM;
  3898. /*
  3899. * Continue initialization with default values even if driver failed
  3900. * to read FCoE param config regions
  3901. */
  3902. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3903. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3904. "2570 Failed to read FCoE parameters\n");
  3905. /* Issue READ_REV to collect vpd and FW information. */
  3906. vpd_size = PAGE_SIZE;
  3907. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3908. if (!vpd) {
  3909. rc = -ENOMEM;
  3910. goto out_free_mbox;
  3911. }
  3912. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3913. if (unlikely(rc))
  3914. goto out_free_vpd;
  3915. mqe = &mboxq->u.mqe;
  3916. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3917. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3918. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3919. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3920. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3921. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3922. "0376 READ_REV Error. SLI Level %d "
  3923. "FCoE enabled %d\n",
  3924. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3925. rc = -EIO;
  3926. goto out_free_vpd;
  3927. }
  3928. /*
  3929. * Evaluate the read rev and vpd data. Populate the driver
  3930. * state with the results. If this routine fails, the failure
  3931. * is not fatal as the driver will use generic values.
  3932. */
  3933. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3934. if (unlikely(!rc)) {
  3935. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3936. "0377 Error %d parsing vpd. "
  3937. "Using defaults.\n", rc);
  3938. rc = 0;
  3939. }
  3940. /* Save information as VPD data */
  3941. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3942. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3943. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3944. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3945. &mqe->un.read_rev);
  3946. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3947. &mqe->un.read_rev);
  3948. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3949. &mqe->un.read_rev);
  3950. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3951. &mqe->un.read_rev);
  3952. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3953. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3954. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3955. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3956. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3957. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3958. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3959. "(%d):0380 READ_REV Status x%x "
  3960. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3961. mboxq->vport ? mboxq->vport->vpi : 0,
  3962. bf_get(lpfc_mqe_status, mqe),
  3963. phba->vpd.rev.opFwName,
  3964. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3965. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3966. /*
  3967. * Discover the port's supported feature set and match it against the
  3968. * hosts requests.
  3969. */
  3970. lpfc_request_features(phba, mboxq);
  3971. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3972. if (unlikely(rc)) {
  3973. rc = -EIO;
  3974. goto out_free_vpd;
  3975. }
  3976. /*
  3977. * The port must support FCP initiator mode as this is the
  3978. * only mode running in the host.
  3979. */
  3980. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3981. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3982. "0378 No support for fcpi mode.\n");
  3983. ftr_rsp++;
  3984. }
  3985. /*
  3986. * If the port cannot support the host's requested features
  3987. * then turn off the global config parameters to disable the
  3988. * feature in the driver. This is not a fatal error.
  3989. */
  3990. if ((phba->cfg_enable_bg) &&
  3991. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3992. ftr_rsp++;
  3993. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3994. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3995. ftr_rsp++;
  3996. if (ftr_rsp) {
  3997. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3998. "0379 Feature Mismatch Data: x%08x %08x "
  3999. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4000. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4001. phba->cfg_enable_npiv, phba->max_vpi);
  4002. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4003. phba->cfg_enable_bg = 0;
  4004. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4005. phba->cfg_enable_npiv = 0;
  4006. }
  4007. /* These SLI3 features are assumed in SLI4 */
  4008. spin_lock_irq(&phba->hbalock);
  4009. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4010. spin_unlock_irq(&phba->hbalock);
  4011. /* Read the port's service parameters. */
  4012. lpfc_read_sparam(phba, mboxq, vport->vpi);
  4013. mboxq->vport = vport;
  4014. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4015. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4016. if (rc == MBX_SUCCESS) {
  4017. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4018. rc = 0;
  4019. }
  4020. /*
  4021. * This memory was allocated by the lpfc_read_sparam routine. Release
  4022. * it to the mbuf pool.
  4023. */
  4024. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4025. kfree(mp);
  4026. mboxq->context1 = NULL;
  4027. if (unlikely(rc)) {
  4028. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4029. "0382 READ_SPARAM command failed "
  4030. "status %d, mbxStatus x%x\n",
  4031. rc, bf_get(lpfc_mqe_status, mqe));
  4032. phba->link_state = LPFC_HBA_ERROR;
  4033. rc = -EIO;
  4034. goto out_free_vpd;
  4035. }
  4036. if (phba->cfg_soft_wwnn)
  4037. u64_to_wwn(phba->cfg_soft_wwnn,
  4038. vport->fc_sparam.nodeName.u.wwn);
  4039. if (phba->cfg_soft_wwpn)
  4040. u64_to_wwn(phba->cfg_soft_wwpn,
  4041. vport->fc_sparam.portName.u.wwn);
  4042. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4043. sizeof(struct lpfc_name));
  4044. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4045. sizeof(struct lpfc_name));
  4046. /* Update the fc_host data structures with new wwn. */
  4047. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4048. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4049. /* Register SGL pool to the device using non-embedded mailbox command */
  4050. rc = lpfc_sli4_post_sgl_list(phba);
  4051. if (unlikely(rc)) {
  4052. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4053. "0582 Error %d during sgl post operation", rc);
  4054. rc = -ENODEV;
  4055. goto out_free_vpd;
  4056. }
  4057. /* Register SCSI SGL pool to the device */
  4058. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4059. if (unlikely(rc)) {
  4060. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4061. "0383 Error %d during scsi sgl post opeation",
  4062. rc);
  4063. /* Some Scsi buffers were moved to the abort scsi list */
  4064. /* A pci function reset will repost them */
  4065. rc = -ENODEV;
  4066. goto out_free_vpd;
  4067. }
  4068. /* Post the rpi header region to the device. */
  4069. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4070. if (unlikely(rc)) {
  4071. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4072. "0393 Error %d during rpi post operation\n",
  4073. rc);
  4074. rc = -ENODEV;
  4075. goto out_free_vpd;
  4076. }
  4077. if (phba->cfg_enable_fip)
  4078. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 1);
  4079. else
  4080. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0);
  4081. /* Set up all the queues to the device */
  4082. rc = lpfc_sli4_queue_setup(phba);
  4083. if (unlikely(rc)) {
  4084. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4085. "0381 Error %d during queue setup.\n ", rc);
  4086. goto out_stop_timers;
  4087. }
  4088. /* Arm the CQs and then EQs on device */
  4089. lpfc_sli4_arm_cqeq_intr(phba);
  4090. /* Indicate device interrupt mode */
  4091. phba->sli4_hba.intr_enable = 1;
  4092. /* Allow asynchronous mailbox command to go through */
  4093. spin_lock_irq(&phba->hbalock);
  4094. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4095. spin_unlock_irq(&phba->hbalock);
  4096. /* Post receive buffers to the device */
  4097. lpfc_sli4_rb_setup(phba);
  4098. /* Start the ELS watchdog timer */
  4099. mod_timer(&vport->els_tmofunc,
  4100. jiffies + HZ * (phba->fc_ratov * 2));
  4101. /* Start heart beat timer */
  4102. mod_timer(&phba->hb_tmofunc,
  4103. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4104. phba->hb_outstanding = 0;
  4105. phba->last_completion_time = jiffies;
  4106. /* Start error attention (ERATT) polling timer */
  4107. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4108. /*
  4109. * The port is ready, set the host's link state to LINK_DOWN
  4110. * in preparation for link interrupts.
  4111. */
  4112. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4113. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4114. lpfc_set_loopback_flag(phba);
  4115. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4116. spin_lock_irq(&phba->hbalock);
  4117. phba->link_state = LPFC_LINK_DOWN;
  4118. spin_unlock_irq(&phba->hbalock);
  4119. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4120. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4121. kfree(vpd);
  4122. return 0;
  4123. } else
  4124. rc = -EIO;
  4125. /* Unset all the queues set up in this routine when error out */
  4126. if (rc)
  4127. lpfc_sli4_queue_unset(phba);
  4128. out_stop_timers:
  4129. if (rc)
  4130. lpfc_stop_hba_timers(phba);
  4131. out_free_vpd:
  4132. kfree(vpd);
  4133. out_free_mbox:
  4134. mempool_free(mboxq, phba->mbox_mem_pool);
  4135. return rc;
  4136. }
  4137. /**
  4138. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4139. * @ptr: context object - pointer to hba structure.
  4140. *
  4141. * This is the callback function for mailbox timer. The mailbox
  4142. * timer is armed when a new mailbox command is issued and the timer
  4143. * is deleted when the mailbox complete. The function is called by
  4144. * the kernel timer code when a mailbox does not complete within
  4145. * expected time. This function wakes up the worker thread to
  4146. * process the mailbox timeout and returns. All the processing is
  4147. * done by the worker thread function lpfc_mbox_timeout_handler.
  4148. **/
  4149. void
  4150. lpfc_mbox_timeout(unsigned long ptr)
  4151. {
  4152. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4153. unsigned long iflag;
  4154. uint32_t tmo_posted;
  4155. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4156. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4157. if (!tmo_posted)
  4158. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4159. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4160. if (!tmo_posted)
  4161. lpfc_worker_wake_up(phba);
  4162. return;
  4163. }
  4164. /**
  4165. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4166. * @phba: Pointer to HBA context object.
  4167. *
  4168. * This function is called from worker thread when a mailbox command times out.
  4169. * The caller is not required to hold any locks. This function will reset the
  4170. * HBA and recover all the pending commands.
  4171. **/
  4172. void
  4173. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4174. {
  4175. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4176. MAILBOX_t *mb = &pmbox->u.mb;
  4177. struct lpfc_sli *psli = &phba->sli;
  4178. struct lpfc_sli_ring *pring;
  4179. /* Check the pmbox pointer first. There is a race condition
  4180. * between the mbox timeout handler getting executed in the
  4181. * worklist and the mailbox actually completing. When this
  4182. * race condition occurs, the mbox_active will be NULL.
  4183. */
  4184. spin_lock_irq(&phba->hbalock);
  4185. if (pmbox == NULL) {
  4186. lpfc_printf_log(phba, KERN_WARNING,
  4187. LOG_MBOX | LOG_SLI,
  4188. "0353 Active Mailbox cleared - mailbox timeout "
  4189. "exiting\n");
  4190. spin_unlock_irq(&phba->hbalock);
  4191. return;
  4192. }
  4193. /* Mbox cmd <mbxCommand> timeout */
  4194. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4195. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4196. mb->mbxCommand,
  4197. phba->pport->port_state,
  4198. phba->sli.sli_flag,
  4199. phba->sli.mbox_active);
  4200. spin_unlock_irq(&phba->hbalock);
  4201. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4202. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4203. * it to fail all oustanding SCSI IO.
  4204. */
  4205. spin_lock_irq(&phba->pport->work_port_lock);
  4206. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4207. spin_unlock_irq(&phba->pport->work_port_lock);
  4208. spin_lock_irq(&phba->hbalock);
  4209. phba->link_state = LPFC_LINK_UNKNOWN;
  4210. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4211. spin_unlock_irq(&phba->hbalock);
  4212. pring = &psli->ring[psli->fcp_ring];
  4213. lpfc_sli_abort_iocb_ring(phba, pring);
  4214. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4215. "0345 Resetting board due to mailbox timeout\n");
  4216. /* Reset the HBA device */
  4217. lpfc_reset_hba(phba);
  4218. }
  4219. /**
  4220. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4221. * @phba: Pointer to HBA context object.
  4222. * @pmbox: Pointer to mailbox object.
  4223. * @flag: Flag indicating how the mailbox need to be processed.
  4224. *
  4225. * This function is called by discovery code and HBA management code
  4226. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4227. * function gets the hbalock to protect the data structures.
  4228. * The mailbox command can be submitted in polling mode, in which case
  4229. * this function will wait in a polling loop for the completion of the
  4230. * mailbox.
  4231. * If the mailbox is submitted in no_wait mode (not polling) the
  4232. * function will submit the command and returns immediately without waiting
  4233. * for the mailbox completion. The no_wait is supported only when HBA
  4234. * is in SLI2/SLI3 mode - interrupts are enabled.
  4235. * The SLI interface allows only one mailbox pending at a time. If the
  4236. * mailbox is issued in polling mode and there is already a mailbox
  4237. * pending, then the function will return an error. If the mailbox is issued
  4238. * in NO_WAIT mode and there is a mailbox pending already, the function
  4239. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4240. * The sli layer owns the mailbox object until the completion of mailbox
  4241. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4242. * return codes the caller owns the mailbox command after the return of
  4243. * the function.
  4244. **/
  4245. static int
  4246. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4247. uint32_t flag)
  4248. {
  4249. MAILBOX_t *mb;
  4250. struct lpfc_sli *psli = &phba->sli;
  4251. uint32_t status, evtctr;
  4252. uint32_t ha_copy;
  4253. int i;
  4254. unsigned long timeout;
  4255. unsigned long drvr_flag = 0;
  4256. uint32_t word0, ldata;
  4257. void __iomem *to_slim;
  4258. int processing_queue = 0;
  4259. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4260. if (!pmbox) {
  4261. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4262. /* processing mbox queue from intr_handler */
  4263. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4264. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4265. return MBX_SUCCESS;
  4266. }
  4267. processing_queue = 1;
  4268. pmbox = lpfc_mbox_get(phba);
  4269. if (!pmbox) {
  4270. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4271. return MBX_SUCCESS;
  4272. }
  4273. }
  4274. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4275. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4276. if(!pmbox->vport) {
  4277. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4278. lpfc_printf_log(phba, KERN_ERR,
  4279. LOG_MBOX | LOG_VPORT,
  4280. "1806 Mbox x%x failed. No vport\n",
  4281. pmbox->u.mb.mbxCommand);
  4282. dump_stack();
  4283. goto out_not_finished;
  4284. }
  4285. }
  4286. /* If the PCI channel is in offline state, do not post mbox. */
  4287. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4288. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4289. goto out_not_finished;
  4290. }
  4291. /* If HBA has a deferred error attention, fail the iocb. */
  4292. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4293. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4294. goto out_not_finished;
  4295. }
  4296. psli = &phba->sli;
  4297. mb = &pmbox->u.mb;
  4298. status = MBX_SUCCESS;
  4299. if (phba->link_state == LPFC_HBA_ERROR) {
  4300. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4301. /* Mbox command <mbxCommand> cannot issue */
  4302. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4303. "(%d):0311 Mailbox command x%x cannot "
  4304. "issue Data: x%x x%x\n",
  4305. pmbox->vport ? pmbox->vport->vpi : 0,
  4306. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4307. goto out_not_finished;
  4308. }
  4309. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4310. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4311. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4312. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4313. "(%d):2528 Mailbox command x%x cannot "
  4314. "issue Data: x%x x%x\n",
  4315. pmbox->vport ? pmbox->vport->vpi : 0,
  4316. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4317. goto out_not_finished;
  4318. }
  4319. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4320. /* Polling for a mbox command when another one is already active
  4321. * is not allowed in SLI. Also, the driver must have established
  4322. * SLI2 mode to queue and process multiple mbox commands.
  4323. */
  4324. if (flag & MBX_POLL) {
  4325. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4326. /* Mbox command <mbxCommand> cannot issue */
  4327. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4328. "(%d):2529 Mailbox command x%x "
  4329. "cannot issue Data: x%x x%x\n",
  4330. pmbox->vport ? pmbox->vport->vpi : 0,
  4331. pmbox->u.mb.mbxCommand,
  4332. psli->sli_flag, flag);
  4333. goto out_not_finished;
  4334. }
  4335. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4336. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4337. /* Mbox command <mbxCommand> cannot issue */
  4338. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4339. "(%d):2530 Mailbox command x%x "
  4340. "cannot issue Data: x%x x%x\n",
  4341. pmbox->vport ? pmbox->vport->vpi : 0,
  4342. pmbox->u.mb.mbxCommand,
  4343. psli->sli_flag, flag);
  4344. goto out_not_finished;
  4345. }
  4346. /* Another mailbox command is still being processed, queue this
  4347. * command to be processed later.
  4348. */
  4349. lpfc_mbox_put(phba, pmbox);
  4350. /* Mbox cmd issue - BUSY */
  4351. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4352. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4353. "x%x x%x x%x x%x\n",
  4354. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4355. mb->mbxCommand, phba->pport->port_state,
  4356. psli->sli_flag, flag);
  4357. psli->slistat.mbox_busy++;
  4358. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4359. if (pmbox->vport) {
  4360. lpfc_debugfs_disc_trc(pmbox->vport,
  4361. LPFC_DISC_TRC_MBOX_VPORT,
  4362. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4363. (uint32_t)mb->mbxCommand,
  4364. mb->un.varWords[0], mb->un.varWords[1]);
  4365. }
  4366. else {
  4367. lpfc_debugfs_disc_trc(phba->pport,
  4368. LPFC_DISC_TRC_MBOX,
  4369. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4370. (uint32_t)mb->mbxCommand,
  4371. mb->un.varWords[0], mb->un.varWords[1]);
  4372. }
  4373. return MBX_BUSY;
  4374. }
  4375. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4376. /* If we are not polling, we MUST be in SLI2 mode */
  4377. if (flag != MBX_POLL) {
  4378. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4379. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4380. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4381. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4382. /* Mbox command <mbxCommand> cannot issue */
  4383. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4384. "(%d):2531 Mailbox command x%x "
  4385. "cannot issue Data: x%x x%x\n",
  4386. pmbox->vport ? pmbox->vport->vpi : 0,
  4387. pmbox->u.mb.mbxCommand,
  4388. psli->sli_flag, flag);
  4389. goto out_not_finished;
  4390. }
  4391. /* timeout active mbox command */
  4392. mod_timer(&psli->mbox_tmo, (jiffies +
  4393. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4394. }
  4395. /* Mailbox cmd <cmd> issue */
  4396. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4397. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4398. "x%x\n",
  4399. pmbox->vport ? pmbox->vport->vpi : 0,
  4400. mb->mbxCommand, phba->pport->port_state,
  4401. psli->sli_flag, flag);
  4402. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4403. if (pmbox->vport) {
  4404. lpfc_debugfs_disc_trc(pmbox->vport,
  4405. LPFC_DISC_TRC_MBOX_VPORT,
  4406. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4407. (uint32_t)mb->mbxCommand,
  4408. mb->un.varWords[0], mb->un.varWords[1]);
  4409. }
  4410. else {
  4411. lpfc_debugfs_disc_trc(phba->pport,
  4412. LPFC_DISC_TRC_MBOX,
  4413. "MBOX Send: cmd:x%x mb:x%x x%x",
  4414. (uint32_t)mb->mbxCommand,
  4415. mb->un.varWords[0], mb->un.varWords[1]);
  4416. }
  4417. }
  4418. psli->slistat.mbox_cmd++;
  4419. evtctr = psli->slistat.mbox_event;
  4420. /* next set own bit for the adapter and copy over command word */
  4421. mb->mbxOwner = OWN_CHIP;
  4422. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4423. /* First copy command data to host SLIM area */
  4424. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4425. } else {
  4426. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4427. /* copy command data into host mbox for cmpl */
  4428. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4429. }
  4430. /* First copy mbox command data to HBA SLIM, skip past first
  4431. word */
  4432. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4433. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4434. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4435. /* Next copy over first word, with mbxOwner set */
  4436. ldata = *((uint32_t *)mb);
  4437. to_slim = phba->MBslimaddr;
  4438. writel(ldata, to_slim);
  4439. readl(to_slim); /* flush */
  4440. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4441. /* switch over to host mailbox */
  4442. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4443. }
  4444. }
  4445. wmb();
  4446. switch (flag) {
  4447. case MBX_NOWAIT:
  4448. /* Set up reference to mailbox command */
  4449. psli->mbox_active = pmbox;
  4450. /* Interrupt board to do it */
  4451. writel(CA_MBATT, phba->CAregaddr);
  4452. readl(phba->CAregaddr); /* flush */
  4453. /* Don't wait for it to finish, just return */
  4454. break;
  4455. case MBX_POLL:
  4456. /* Set up null reference to mailbox command */
  4457. psli->mbox_active = NULL;
  4458. /* Interrupt board to do it */
  4459. writel(CA_MBATT, phba->CAregaddr);
  4460. readl(phba->CAregaddr); /* flush */
  4461. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4462. /* First read mbox status word */
  4463. word0 = *((uint32_t *)phba->mbox);
  4464. word0 = le32_to_cpu(word0);
  4465. } else {
  4466. /* First read mbox status word */
  4467. word0 = readl(phba->MBslimaddr);
  4468. }
  4469. /* Read the HBA Host Attention Register */
  4470. ha_copy = readl(phba->HAregaddr);
  4471. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4472. mb->mbxCommand) *
  4473. 1000) + jiffies;
  4474. i = 0;
  4475. /* Wait for command to complete */
  4476. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4477. (!(ha_copy & HA_MBATT) &&
  4478. (phba->link_state > LPFC_WARM_START))) {
  4479. if (time_after(jiffies, timeout)) {
  4480. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4481. spin_unlock_irqrestore(&phba->hbalock,
  4482. drvr_flag);
  4483. goto out_not_finished;
  4484. }
  4485. /* Check if we took a mbox interrupt while we were
  4486. polling */
  4487. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4488. && (evtctr != psli->slistat.mbox_event))
  4489. break;
  4490. if (i++ > 10) {
  4491. spin_unlock_irqrestore(&phba->hbalock,
  4492. drvr_flag);
  4493. msleep(1);
  4494. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4495. }
  4496. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4497. /* First copy command data */
  4498. word0 = *((uint32_t *)phba->mbox);
  4499. word0 = le32_to_cpu(word0);
  4500. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4501. MAILBOX_t *slimmb;
  4502. uint32_t slimword0;
  4503. /* Check real SLIM for any errors */
  4504. slimword0 = readl(phba->MBslimaddr);
  4505. slimmb = (MAILBOX_t *) & slimword0;
  4506. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4507. && slimmb->mbxStatus) {
  4508. psli->sli_flag &=
  4509. ~LPFC_SLI_ACTIVE;
  4510. word0 = slimword0;
  4511. }
  4512. }
  4513. } else {
  4514. /* First copy command data */
  4515. word0 = readl(phba->MBslimaddr);
  4516. }
  4517. /* Read the HBA Host Attention Register */
  4518. ha_copy = readl(phba->HAregaddr);
  4519. }
  4520. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4521. /* copy results back to user */
  4522. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4523. } else {
  4524. /* First copy command data */
  4525. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4526. MAILBOX_CMD_SIZE);
  4527. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4528. pmbox->context2) {
  4529. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4530. phba->MBslimaddr + DMP_RSP_OFFSET,
  4531. mb->un.varDmp.word_cnt);
  4532. }
  4533. }
  4534. writel(HA_MBATT, phba->HAregaddr);
  4535. readl(phba->HAregaddr); /* flush */
  4536. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4537. status = mb->mbxStatus;
  4538. }
  4539. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4540. return status;
  4541. out_not_finished:
  4542. if (processing_queue) {
  4543. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4544. lpfc_mbox_cmpl_put(phba, pmbox);
  4545. }
  4546. return MBX_NOT_FINISHED;
  4547. }
  4548. /**
  4549. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4550. * @phba: Pointer to HBA context object.
  4551. *
  4552. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4553. * the driver internal pending mailbox queue. It will then try to wait out the
  4554. * possible outstanding mailbox command before return.
  4555. *
  4556. * Returns:
  4557. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4558. * the outstanding mailbox command timed out.
  4559. **/
  4560. static int
  4561. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4562. {
  4563. struct lpfc_sli *psli = &phba->sli;
  4564. uint8_t actcmd = MBX_HEARTBEAT;
  4565. int rc = 0;
  4566. unsigned long timeout;
  4567. /* Mark the asynchronous mailbox command posting as blocked */
  4568. spin_lock_irq(&phba->hbalock);
  4569. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4570. if (phba->sli.mbox_active)
  4571. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4572. spin_unlock_irq(&phba->hbalock);
  4573. /* Determine how long we might wait for the active mailbox
  4574. * command to be gracefully completed by firmware.
  4575. */
  4576. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4577. jiffies;
  4578. /* Wait for the outstnading mailbox command to complete */
  4579. while (phba->sli.mbox_active) {
  4580. /* Check active mailbox complete status every 2ms */
  4581. msleep(2);
  4582. if (time_after(jiffies, timeout)) {
  4583. /* Timeout, marked the outstanding cmd not complete */
  4584. rc = 1;
  4585. break;
  4586. }
  4587. }
  4588. /* Can not cleanly block async mailbox command, fails it */
  4589. if (rc) {
  4590. spin_lock_irq(&phba->hbalock);
  4591. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4592. spin_unlock_irq(&phba->hbalock);
  4593. }
  4594. return rc;
  4595. }
  4596. /**
  4597. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4598. * @phba: Pointer to HBA context object.
  4599. *
  4600. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4601. * commands from the driver internal pending mailbox queue. It makes sure
  4602. * that there is no outstanding mailbox command before resuming posting
  4603. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4604. * mailbox command, it will try to wait it out before resuming asynchronous
  4605. * mailbox command posting.
  4606. **/
  4607. static void
  4608. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4609. {
  4610. struct lpfc_sli *psli = &phba->sli;
  4611. spin_lock_irq(&phba->hbalock);
  4612. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4613. /* Asynchronous mailbox posting is not blocked, do nothing */
  4614. spin_unlock_irq(&phba->hbalock);
  4615. return;
  4616. }
  4617. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4618. * successful or timeout, after timing-out the outstanding mailbox
  4619. * command shall always be removed, so just unblock posting async
  4620. * mailbox command and resume
  4621. */
  4622. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4623. spin_unlock_irq(&phba->hbalock);
  4624. /* wake up worker thread to post asynchronlous mailbox command */
  4625. lpfc_worker_wake_up(phba);
  4626. }
  4627. /**
  4628. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4629. * @phba: Pointer to HBA context object.
  4630. * @mboxq: Pointer to mailbox object.
  4631. *
  4632. * The function posts a mailbox to the port. The mailbox is expected
  4633. * to be comletely filled in and ready for the port to operate on it.
  4634. * This routine executes a synchronous completion operation on the
  4635. * mailbox by polling for its completion.
  4636. *
  4637. * The caller must not be holding any locks when calling this routine.
  4638. *
  4639. * Returns:
  4640. * MBX_SUCCESS - mailbox posted successfully
  4641. * Any of the MBX error values.
  4642. **/
  4643. static int
  4644. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4645. {
  4646. int rc = MBX_SUCCESS;
  4647. unsigned long iflag;
  4648. uint32_t db_ready;
  4649. uint32_t mcqe_status;
  4650. uint32_t mbx_cmnd;
  4651. unsigned long timeout;
  4652. struct lpfc_sli *psli = &phba->sli;
  4653. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4654. struct lpfc_bmbx_create *mbox_rgn;
  4655. struct dma_address *dma_address;
  4656. struct lpfc_register bmbx_reg;
  4657. /*
  4658. * Only one mailbox can be active to the bootstrap mailbox region
  4659. * at a time and there is no queueing provided.
  4660. */
  4661. spin_lock_irqsave(&phba->hbalock, iflag);
  4662. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4663. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4664. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4665. "(%d):2532 Mailbox command x%x (x%x) "
  4666. "cannot issue Data: x%x x%x\n",
  4667. mboxq->vport ? mboxq->vport->vpi : 0,
  4668. mboxq->u.mb.mbxCommand,
  4669. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4670. psli->sli_flag, MBX_POLL);
  4671. return MBXERR_ERROR;
  4672. }
  4673. /* The server grabs the token and owns it until release */
  4674. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4675. phba->sli.mbox_active = mboxq;
  4676. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4677. /*
  4678. * Initialize the bootstrap memory region to avoid stale data areas
  4679. * in the mailbox post. Then copy the caller's mailbox contents to
  4680. * the bmbx mailbox region.
  4681. */
  4682. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4683. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4684. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4685. sizeof(struct lpfc_mqe));
  4686. /* Post the high mailbox dma address to the port and wait for ready. */
  4687. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4688. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4689. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4690. * 1000) + jiffies;
  4691. do {
  4692. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4693. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4694. if (!db_ready)
  4695. msleep(2);
  4696. if (time_after(jiffies, timeout)) {
  4697. rc = MBXERR_ERROR;
  4698. goto exit;
  4699. }
  4700. } while (!db_ready);
  4701. /* Post the low mailbox dma address to the port. */
  4702. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4703. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4704. * 1000) + jiffies;
  4705. do {
  4706. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4707. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4708. if (!db_ready)
  4709. msleep(2);
  4710. if (time_after(jiffies, timeout)) {
  4711. rc = MBXERR_ERROR;
  4712. goto exit;
  4713. }
  4714. } while (!db_ready);
  4715. /*
  4716. * Read the CQ to ensure the mailbox has completed.
  4717. * If so, update the mailbox status so that the upper layers
  4718. * can complete the request normally.
  4719. */
  4720. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4721. sizeof(struct lpfc_mqe));
  4722. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4723. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4724. sizeof(struct lpfc_mcqe));
  4725. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4726. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4727. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4728. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4729. rc = MBXERR_ERROR;
  4730. }
  4731. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4732. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4733. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4734. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4735. mboxq->vport ? mboxq->vport->vpi : 0,
  4736. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4737. bf_get(lpfc_mqe_status, mb),
  4738. mb->un.mb_words[0], mb->un.mb_words[1],
  4739. mb->un.mb_words[2], mb->un.mb_words[3],
  4740. mb->un.mb_words[4], mb->un.mb_words[5],
  4741. mb->un.mb_words[6], mb->un.mb_words[7],
  4742. mb->un.mb_words[8], mb->un.mb_words[9],
  4743. mb->un.mb_words[10], mb->un.mb_words[11],
  4744. mb->un.mb_words[12], mboxq->mcqe.word0,
  4745. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4746. mboxq->mcqe.trailer);
  4747. exit:
  4748. /* We are holding the token, no needed for lock when release */
  4749. spin_lock_irqsave(&phba->hbalock, iflag);
  4750. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4751. phba->sli.mbox_active = NULL;
  4752. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4753. return rc;
  4754. }
  4755. /**
  4756. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4757. * @phba: Pointer to HBA context object.
  4758. * @pmbox: Pointer to mailbox object.
  4759. * @flag: Flag indicating how the mailbox need to be processed.
  4760. *
  4761. * This function is called by discovery code and HBA management code to submit
  4762. * a mailbox command to firmware with SLI-4 interface spec.
  4763. *
  4764. * Return codes the caller owns the mailbox command after the return of the
  4765. * function.
  4766. **/
  4767. static int
  4768. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4769. uint32_t flag)
  4770. {
  4771. struct lpfc_sli *psli = &phba->sli;
  4772. unsigned long iflags;
  4773. int rc;
  4774. rc = lpfc_mbox_dev_check(phba);
  4775. if (unlikely(rc)) {
  4776. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4777. "(%d):2544 Mailbox command x%x (x%x) "
  4778. "cannot issue Data: x%x x%x\n",
  4779. mboxq->vport ? mboxq->vport->vpi : 0,
  4780. mboxq->u.mb.mbxCommand,
  4781. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4782. psli->sli_flag, flag);
  4783. goto out_not_finished;
  4784. }
  4785. /* Detect polling mode and jump to a handler */
  4786. if (!phba->sli4_hba.intr_enable) {
  4787. if (flag == MBX_POLL)
  4788. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4789. else
  4790. rc = -EIO;
  4791. if (rc != MBX_SUCCESS)
  4792. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4793. "(%d):2541 Mailbox command x%x "
  4794. "(x%x) cannot issue Data: x%x x%x\n",
  4795. mboxq->vport ? mboxq->vport->vpi : 0,
  4796. mboxq->u.mb.mbxCommand,
  4797. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4798. psli->sli_flag, flag);
  4799. return rc;
  4800. } else if (flag == MBX_POLL) {
  4801. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4802. "(%d):2542 Try to issue mailbox command "
  4803. "x%x (x%x) synchronously ahead of async"
  4804. "mailbox command queue: x%x x%x\n",
  4805. mboxq->vport ? mboxq->vport->vpi : 0,
  4806. mboxq->u.mb.mbxCommand,
  4807. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4808. psli->sli_flag, flag);
  4809. /* Try to block the asynchronous mailbox posting */
  4810. rc = lpfc_sli4_async_mbox_block(phba);
  4811. if (!rc) {
  4812. /* Successfully blocked, now issue sync mbox cmd */
  4813. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4814. if (rc != MBX_SUCCESS)
  4815. lpfc_printf_log(phba, KERN_ERR,
  4816. LOG_MBOX | LOG_SLI,
  4817. "(%d):2597 Mailbox command "
  4818. "x%x (x%x) cannot issue "
  4819. "Data: x%x x%x\n",
  4820. mboxq->vport ?
  4821. mboxq->vport->vpi : 0,
  4822. mboxq->u.mb.mbxCommand,
  4823. lpfc_sli4_mbox_opcode_get(phba,
  4824. mboxq),
  4825. psli->sli_flag, flag);
  4826. /* Unblock the async mailbox posting afterward */
  4827. lpfc_sli4_async_mbox_unblock(phba);
  4828. }
  4829. return rc;
  4830. }
  4831. /* Now, interrupt mode asynchrous mailbox command */
  4832. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4833. if (rc) {
  4834. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4835. "(%d):2543 Mailbox command x%x (x%x) "
  4836. "cannot issue Data: x%x x%x\n",
  4837. mboxq->vport ? mboxq->vport->vpi : 0,
  4838. mboxq->u.mb.mbxCommand,
  4839. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4840. psli->sli_flag, flag);
  4841. goto out_not_finished;
  4842. }
  4843. /* Put the mailbox command to the driver internal FIFO */
  4844. psli->slistat.mbox_busy++;
  4845. spin_lock_irqsave(&phba->hbalock, iflags);
  4846. lpfc_mbox_put(phba, mboxq);
  4847. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4848. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4849. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4850. "x%x (x%x) x%x x%x x%x\n",
  4851. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4852. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4853. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4854. phba->pport->port_state,
  4855. psli->sli_flag, MBX_NOWAIT);
  4856. /* Wake up worker thread to transport mailbox command from head */
  4857. lpfc_worker_wake_up(phba);
  4858. return MBX_BUSY;
  4859. out_not_finished:
  4860. return MBX_NOT_FINISHED;
  4861. }
  4862. /**
  4863. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4864. * @phba: Pointer to HBA context object.
  4865. *
  4866. * This function is called by worker thread to send a mailbox command to
  4867. * SLI4 HBA firmware.
  4868. *
  4869. **/
  4870. int
  4871. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4872. {
  4873. struct lpfc_sli *psli = &phba->sli;
  4874. LPFC_MBOXQ_t *mboxq;
  4875. int rc = MBX_SUCCESS;
  4876. unsigned long iflags;
  4877. struct lpfc_mqe *mqe;
  4878. uint32_t mbx_cmnd;
  4879. /* Check interrupt mode before post async mailbox command */
  4880. if (unlikely(!phba->sli4_hba.intr_enable))
  4881. return MBX_NOT_FINISHED;
  4882. /* Check for mailbox command service token */
  4883. spin_lock_irqsave(&phba->hbalock, iflags);
  4884. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4885. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4886. return MBX_NOT_FINISHED;
  4887. }
  4888. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4889. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4890. return MBX_NOT_FINISHED;
  4891. }
  4892. if (unlikely(phba->sli.mbox_active)) {
  4893. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4894. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4895. "0384 There is pending active mailbox cmd\n");
  4896. return MBX_NOT_FINISHED;
  4897. }
  4898. /* Take the mailbox command service token */
  4899. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4900. /* Get the next mailbox command from head of queue */
  4901. mboxq = lpfc_mbox_get(phba);
  4902. /* If no more mailbox command waiting for post, we're done */
  4903. if (!mboxq) {
  4904. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4905. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4906. return MBX_SUCCESS;
  4907. }
  4908. phba->sli.mbox_active = mboxq;
  4909. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4910. /* Check device readiness for posting mailbox command */
  4911. rc = lpfc_mbox_dev_check(phba);
  4912. if (unlikely(rc))
  4913. /* Driver clean routine will clean up pending mailbox */
  4914. goto out_not_finished;
  4915. /* Prepare the mbox command to be posted */
  4916. mqe = &mboxq->u.mqe;
  4917. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4918. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4919. mod_timer(&psli->mbox_tmo, (jiffies +
  4920. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4921. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4922. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4923. "x%x x%x\n",
  4924. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4925. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4926. phba->pport->port_state, psli->sli_flag);
  4927. if (mbx_cmnd != MBX_HEARTBEAT) {
  4928. if (mboxq->vport) {
  4929. lpfc_debugfs_disc_trc(mboxq->vport,
  4930. LPFC_DISC_TRC_MBOX_VPORT,
  4931. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4932. mbx_cmnd, mqe->un.mb_words[0],
  4933. mqe->un.mb_words[1]);
  4934. } else {
  4935. lpfc_debugfs_disc_trc(phba->pport,
  4936. LPFC_DISC_TRC_MBOX,
  4937. "MBOX Send: cmd:x%x mb:x%x x%x",
  4938. mbx_cmnd, mqe->un.mb_words[0],
  4939. mqe->un.mb_words[1]);
  4940. }
  4941. }
  4942. psli->slistat.mbox_cmd++;
  4943. /* Post the mailbox command to the port */
  4944. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4945. if (rc != MBX_SUCCESS) {
  4946. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4947. "(%d):2533 Mailbox command x%x (x%x) "
  4948. "cannot issue Data: x%x x%x\n",
  4949. mboxq->vport ? mboxq->vport->vpi : 0,
  4950. mboxq->u.mb.mbxCommand,
  4951. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4952. psli->sli_flag, MBX_NOWAIT);
  4953. goto out_not_finished;
  4954. }
  4955. return rc;
  4956. out_not_finished:
  4957. spin_lock_irqsave(&phba->hbalock, iflags);
  4958. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4959. __lpfc_mbox_cmpl_put(phba, mboxq);
  4960. /* Release the token */
  4961. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4962. phba->sli.mbox_active = NULL;
  4963. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4964. return MBX_NOT_FINISHED;
  4965. }
  4966. /**
  4967. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4968. * @phba: Pointer to HBA context object.
  4969. * @pmbox: Pointer to mailbox object.
  4970. * @flag: Flag indicating how the mailbox need to be processed.
  4971. *
  4972. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4973. * the API jump table function pointer from the lpfc_hba struct.
  4974. *
  4975. * Return codes the caller owns the mailbox command after the return of the
  4976. * function.
  4977. **/
  4978. int
  4979. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4980. {
  4981. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4982. }
  4983. /**
  4984. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4985. * @phba: The hba struct for which this call is being executed.
  4986. * @dev_grp: The HBA PCI-Device group number.
  4987. *
  4988. * This routine sets up the mbox interface API function jump table in @phba
  4989. * struct.
  4990. * Returns: 0 - success, -ENODEV - failure.
  4991. **/
  4992. int
  4993. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4994. {
  4995. switch (dev_grp) {
  4996. case LPFC_PCI_DEV_LP:
  4997. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4998. phba->lpfc_sli_handle_slow_ring_event =
  4999. lpfc_sli_handle_slow_ring_event_s3;
  5000. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5001. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5002. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5003. break;
  5004. case LPFC_PCI_DEV_OC:
  5005. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5006. phba->lpfc_sli_handle_slow_ring_event =
  5007. lpfc_sli_handle_slow_ring_event_s4;
  5008. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5009. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5010. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5011. break;
  5012. default:
  5013. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5014. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5015. dev_grp);
  5016. return -ENODEV;
  5017. break;
  5018. }
  5019. return 0;
  5020. }
  5021. /**
  5022. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5023. * @phba: Pointer to HBA context object.
  5024. * @pring: Pointer to driver SLI ring object.
  5025. * @piocb: Pointer to address of newly added command iocb.
  5026. *
  5027. * This function is called with hbalock held to add a command
  5028. * iocb to the txq when SLI layer cannot submit the command iocb
  5029. * to the ring.
  5030. **/
  5031. static void
  5032. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5033. struct lpfc_iocbq *piocb)
  5034. {
  5035. /* Insert the caller's iocb in the txq tail for later processing. */
  5036. list_add_tail(&piocb->list, &pring->txq);
  5037. pring->txq_cnt++;
  5038. }
  5039. /**
  5040. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5041. * @phba: Pointer to HBA context object.
  5042. * @pring: Pointer to driver SLI ring object.
  5043. * @piocb: Pointer to address of newly added command iocb.
  5044. *
  5045. * This function is called with hbalock held before a new
  5046. * iocb is submitted to the firmware. This function checks
  5047. * txq to flush the iocbs in txq to Firmware before
  5048. * submitting new iocbs to the Firmware.
  5049. * If there are iocbs in the txq which need to be submitted
  5050. * to firmware, lpfc_sli_next_iocb returns the first element
  5051. * of the txq after dequeuing it from txq.
  5052. * If there is no iocb in the txq then the function will return
  5053. * *piocb and *piocb is set to NULL. Caller needs to check
  5054. * *piocb to find if there are more commands in the txq.
  5055. **/
  5056. static struct lpfc_iocbq *
  5057. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5058. struct lpfc_iocbq **piocb)
  5059. {
  5060. struct lpfc_iocbq * nextiocb;
  5061. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5062. if (!nextiocb) {
  5063. nextiocb = *piocb;
  5064. *piocb = NULL;
  5065. }
  5066. return nextiocb;
  5067. }
  5068. /**
  5069. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5070. * @phba: Pointer to HBA context object.
  5071. * @ring_number: SLI ring number to issue iocb on.
  5072. * @piocb: Pointer to command iocb.
  5073. * @flag: Flag indicating if this command can be put into txq.
  5074. *
  5075. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5076. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5077. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5078. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5079. * this function allows only iocbs for posting buffers. This function finds
  5080. * next available slot in the command ring and posts the command to the
  5081. * available slot and writes the port attention register to request HBA start
  5082. * processing new iocb. If there is no slot available in the ring and
  5083. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5084. * the function returns IOCB_BUSY.
  5085. *
  5086. * This function is called with hbalock held. The function will return success
  5087. * after it successfully submit the iocb to firmware or after adding to the
  5088. * txq.
  5089. **/
  5090. static int
  5091. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5092. struct lpfc_iocbq *piocb, uint32_t flag)
  5093. {
  5094. struct lpfc_iocbq *nextiocb;
  5095. IOCB_t *iocb;
  5096. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5097. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5098. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5099. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5100. lpfc_printf_log(phba, KERN_ERR,
  5101. LOG_SLI | LOG_VPORT,
  5102. "1807 IOCB x%x failed. No vport\n",
  5103. piocb->iocb.ulpCommand);
  5104. dump_stack();
  5105. return IOCB_ERROR;
  5106. }
  5107. /* If the PCI channel is in offline state, do not post iocbs. */
  5108. if (unlikely(pci_channel_offline(phba->pcidev)))
  5109. return IOCB_ERROR;
  5110. /* If HBA has a deferred error attention, fail the iocb. */
  5111. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5112. return IOCB_ERROR;
  5113. /*
  5114. * We should never get an IOCB if we are in a < LINK_DOWN state
  5115. */
  5116. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5117. return IOCB_ERROR;
  5118. /*
  5119. * Check to see if we are blocking IOCB processing because of a
  5120. * outstanding event.
  5121. */
  5122. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5123. goto iocb_busy;
  5124. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5125. /*
  5126. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5127. * can be issued if the link is not up.
  5128. */
  5129. switch (piocb->iocb.ulpCommand) {
  5130. case CMD_GEN_REQUEST64_CR:
  5131. case CMD_GEN_REQUEST64_CX:
  5132. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5133. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5134. FC_FCP_CMND) ||
  5135. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5136. MENLO_TRANSPORT_TYPE))
  5137. goto iocb_busy;
  5138. break;
  5139. case CMD_QUE_RING_BUF_CN:
  5140. case CMD_QUE_RING_BUF64_CN:
  5141. /*
  5142. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5143. * completion, iocb_cmpl MUST be 0.
  5144. */
  5145. if (piocb->iocb_cmpl)
  5146. piocb->iocb_cmpl = NULL;
  5147. /*FALLTHROUGH*/
  5148. case CMD_CREATE_XRI_CR:
  5149. case CMD_CLOSE_XRI_CN:
  5150. case CMD_CLOSE_XRI_CX:
  5151. break;
  5152. default:
  5153. goto iocb_busy;
  5154. }
  5155. /*
  5156. * For FCP commands, we must be in a state where we can process link
  5157. * attention events.
  5158. */
  5159. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5160. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5161. goto iocb_busy;
  5162. }
  5163. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5164. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5165. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5166. if (iocb)
  5167. lpfc_sli_update_ring(phba, pring);
  5168. else
  5169. lpfc_sli_update_full_ring(phba, pring);
  5170. if (!piocb)
  5171. return IOCB_SUCCESS;
  5172. goto out_busy;
  5173. iocb_busy:
  5174. pring->stats.iocb_cmd_delay++;
  5175. out_busy:
  5176. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5177. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5178. return IOCB_SUCCESS;
  5179. }
  5180. return IOCB_BUSY;
  5181. }
  5182. /**
  5183. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5184. * @phba: Pointer to HBA context object.
  5185. * @piocb: Pointer to command iocb.
  5186. * @sglq: Pointer to the scatter gather queue object.
  5187. *
  5188. * This routine converts the bpl or bde that is in the IOCB
  5189. * to a sgl list for the sli4 hardware. The physical address
  5190. * of the bpl/bde is converted back to a virtual address.
  5191. * If the IOCB contains a BPL then the list of BDE's is
  5192. * converted to sli4_sge's. If the IOCB contains a single
  5193. * BDE then it is converted to a single sli_sge.
  5194. * The IOCB is still in cpu endianess so the contents of
  5195. * the bpl can be used without byte swapping.
  5196. *
  5197. * Returns valid XRI = Success, NO_XRI = Failure.
  5198. **/
  5199. static uint16_t
  5200. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5201. struct lpfc_sglq *sglq)
  5202. {
  5203. uint16_t xritag = NO_XRI;
  5204. struct ulp_bde64 *bpl = NULL;
  5205. struct ulp_bde64 bde;
  5206. struct sli4_sge *sgl = NULL;
  5207. IOCB_t *icmd;
  5208. int numBdes = 0;
  5209. int i = 0;
  5210. if (!piocbq || !sglq)
  5211. return xritag;
  5212. sgl = (struct sli4_sge *)sglq->sgl;
  5213. icmd = &piocbq->iocb;
  5214. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5215. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5216. sizeof(struct ulp_bde64);
  5217. /* The addrHigh and addrLow fields within the IOCB
  5218. * have not been byteswapped yet so there is no
  5219. * need to swap them back.
  5220. */
  5221. bpl = (struct ulp_bde64 *)
  5222. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5223. if (!bpl)
  5224. return xritag;
  5225. for (i = 0; i < numBdes; i++) {
  5226. /* Should already be byte swapped. */
  5227. sgl->addr_hi = bpl->addrHigh;
  5228. sgl->addr_lo = bpl->addrLow;
  5229. /* swap the size field back to the cpu so we
  5230. * can assign it to the sgl.
  5231. */
  5232. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5233. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5234. if ((i+1) == numBdes)
  5235. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5236. else
  5237. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5238. sgl->word2 = cpu_to_le32(sgl->word2);
  5239. sgl->word3 = cpu_to_le32(sgl->word3);
  5240. bpl++;
  5241. sgl++;
  5242. }
  5243. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5244. /* The addrHigh and addrLow fields of the BDE have not
  5245. * been byteswapped yet so they need to be swapped
  5246. * before putting them in the sgl.
  5247. */
  5248. sgl->addr_hi =
  5249. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5250. sgl->addr_lo =
  5251. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5252. bf_set(lpfc_sli4_sge_len, sgl,
  5253. icmd->un.genreq64.bdl.bdeSize);
  5254. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5255. sgl->word2 = cpu_to_le32(sgl->word2);
  5256. sgl->word3 = cpu_to_le32(sgl->word3);
  5257. }
  5258. return sglq->sli4_xritag;
  5259. }
  5260. /**
  5261. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5262. * @phba: Pointer to HBA context object.
  5263. *
  5264. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5265. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5266. * held.
  5267. *
  5268. * Return: index into SLI4 fast-path FCP queue index.
  5269. **/
  5270. static uint32_t
  5271. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5272. {
  5273. ++phba->fcp_qidx;
  5274. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5275. phba->fcp_qidx = 0;
  5276. return phba->fcp_qidx;
  5277. }
  5278. /**
  5279. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5280. * @phba: Pointer to HBA context object.
  5281. * @piocb: Pointer to command iocb.
  5282. * @wqe: Pointer to the work queue entry.
  5283. *
  5284. * This routine converts the iocb command to its Work Queue Entry
  5285. * equivalent. The wqe pointer should not have any fields set when
  5286. * this routine is called because it will memcpy over them.
  5287. * This routine does not set the CQ_ID or the WQEC bits in the
  5288. * wqe.
  5289. *
  5290. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5291. **/
  5292. static int
  5293. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5294. union lpfc_wqe *wqe)
  5295. {
  5296. uint32_t payload_len = 0;
  5297. uint8_t ct = 0;
  5298. uint32_t fip;
  5299. uint32_t abort_tag;
  5300. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5301. uint8_t cmnd;
  5302. uint16_t xritag;
  5303. struct ulp_bde64 *bpl = NULL;
  5304. fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags);
  5305. /* The fcp commands will set command type */
  5306. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5307. command_type = FCP_COMMAND;
  5308. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS))
  5309. command_type = ELS_COMMAND_FIP;
  5310. else
  5311. command_type = ELS_COMMAND_NON_FIP;
  5312. /* Some of the fields are in the right position already */
  5313. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5314. abort_tag = (uint32_t) iocbq->iotag;
  5315. xritag = iocbq->sli4_xritag;
  5316. wqe->words[7] = 0; /* The ct field has moved so reset */
  5317. /* words0-2 bpl convert bde */
  5318. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5319. bpl = (struct ulp_bde64 *)
  5320. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5321. if (!bpl)
  5322. return IOCB_ERROR;
  5323. /* Should already be byte swapped. */
  5324. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5325. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5326. /* swap the size field back to the cpu so we
  5327. * can assign it to the sgl.
  5328. */
  5329. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5330. payload_len = wqe->generic.bde.tus.f.bdeSize;
  5331. } else
  5332. payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5333. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5334. cmnd = iocbq->iocb.ulpCommand;
  5335. switch (iocbq->iocb.ulpCommand) {
  5336. case CMD_ELS_REQUEST64_CR:
  5337. if (!iocbq->iocb.ulpLe) {
  5338. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5339. "2007 Only Limited Edition cmd Format"
  5340. " supported 0x%x\n",
  5341. iocbq->iocb.ulpCommand);
  5342. return IOCB_ERROR;
  5343. }
  5344. wqe->els_req.payload_len = payload_len;
  5345. /* Els_reguest64 has a TMO */
  5346. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5347. iocbq->iocb.ulpTimeout);
  5348. /* Need a VF for word 4 set the vf bit*/
  5349. bf_set(els_req64_vf, &wqe->els_req, 0);
  5350. /* And a VFID for word 12 */
  5351. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5352. /*
  5353. * Set ct field to 3, indicates that the context_tag field
  5354. * contains the FCFI and remote N_Port_ID is
  5355. * in word 5.
  5356. */
  5357. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5358. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5359. iocbq->iocb.ulpContext);
  5360. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5361. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5362. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5363. break;
  5364. case CMD_XMIT_SEQUENCE64_CR:
  5365. /* word3 iocb=io_tag32 wqe=payload_offset */
  5366. /* payload offset used for multilpe outstanding
  5367. * sequences on the same exchange
  5368. */
  5369. wqe->words[3] = 0;
  5370. /* word4 relative_offset memcpy */
  5371. /* word5 r_ctl/df_ctl memcpy */
  5372. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5373. wqe->xmit_sequence.xmit_len = payload_len;
  5374. break;
  5375. case CMD_XMIT_BCAST64_CN:
  5376. /* word3 iocb=iotag32 wqe=payload_len */
  5377. wqe->words[3] = 0; /* no definition for this in wqe */
  5378. /* word4 iocb=rsvd wqe=rsvd */
  5379. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5380. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5381. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5382. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5383. break;
  5384. case CMD_FCP_IWRITE64_CR:
  5385. command_type = FCP_COMMAND_DATA_OUT;
  5386. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5387. * confusing.
  5388. * word3 is payload_len: byte offset to the sgl entry for the
  5389. * fcp_command.
  5390. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5391. * word5 is initial xfer len 0 = wait for xfer-ready
  5392. */
  5393. /* Always wait for xfer-ready before sending data */
  5394. wqe->fcp_iwrite.initial_xfer_len = 0;
  5395. /* word 4 (xfer length) should have been set on the memcpy */
  5396. /* allow write to fall through to read */
  5397. case CMD_FCP_IREAD64_CR:
  5398. /* FCP_CMD is always the 1st sgl entry */
  5399. wqe->fcp_iread.payload_len =
  5400. payload_len + sizeof(struct fcp_rsp);
  5401. /* word 4 (xfer length) should have been set on the memcpy */
  5402. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5403. iocbq->iocb.ulpFCP2Rcvy);
  5404. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5405. /* The XC bit and the XS bit are similar. The driver never
  5406. * tracked whether or not the exchange was previouslly open.
  5407. * XC = Exchange create, 0 is create. 1 is already open.
  5408. * XS = link cmd: 1 do not close the exchange after command.
  5409. * XS = 0 close exchange when command completes.
  5410. * The only time we would not set the XC bit is when the XS bit
  5411. * is set and we are sending our 2nd or greater command on
  5412. * this exchange.
  5413. */
  5414. /* Always open the exchange */
  5415. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5416. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5417. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5418. break;
  5419. case CMD_FCP_ICMND64_CR:
  5420. /* Always open the exchange */
  5421. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5422. wqe->words[4] = 0;
  5423. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5424. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5425. break;
  5426. case CMD_GEN_REQUEST64_CR:
  5427. /* word3 command length is described as byte offset to the
  5428. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5429. * sgl[0] = cmnd
  5430. * sgl[1] = rsp.
  5431. *
  5432. */
  5433. wqe->gen_req.command_len = payload_len;
  5434. /* Word4 parameter copied in the memcpy */
  5435. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5436. /* word6 context tag copied in memcpy */
  5437. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5438. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5439. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5440. "2015 Invalid CT %x command 0x%x\n",
  5441. ct, iocbq->iocb.ulpCommand);
  5442. return IOCB_ERROR;
  5443. }
  5444. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5445. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5446. iocbq->iocb.ulpTimeout);
  5447. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5448. command_type = OTHER_COMMAND;
  5449. break;
  5450. case CMD_XMIT_ELS_RSP64_CX:
  5451. /* words0-2 BDE memcpy */
  5452. /* word3 iocb=iotag32 wqe=rsvd */
  5453. wqe->words[3] = 0;
  5454. /* word4 iocb=did wge=rsvd. */
  5455. wqe->words[4] = 0;
  5456. /* word5 iocb=rsvd wge=did */
  5457. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5458. iocbq->iocb.un.elsreq64.remoteID);
  5459. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5460. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5461. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5462. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5463. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5464. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5465. iocbq->vport->vpi + phba->vpi_base);
  5466. command_type = OTHER_COMMAND;
  5467. break;
  5468. case CMD_CLOSE_XRI_CN:
  5469. case CMD_ABORT_XRI_CN:
  5470. case CMD_ABORT_XRI_CX:
  5471. /* words 0-2 memcpy should be 0 rserved */
  5472. /* port will send abts */
  5473. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5474. /*
  5475. * The link is down so the fw does not need to send abts
  5476. * on the wire.
  5477. */
  5478. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5479. else
  5480. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5481. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5482. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5483. wqe->words[5] = 0;
  5484. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5485. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5486. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5487. wqe->generic.abort_tag = abort_tag;
  5488. /*
  5489. * The abort handler will send us CMD_ABORT_XRI_CN or
  5490. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5491. */
  5492. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5493. cmnd = CMD_ABORT_XRI_CX;
  5494. command_type = OTHER_COMMAND;
  5495. xritag = 0;
  5496. break;
  5497. case CMD_XRI_ABORTED_CX:
  5498. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5499. /* words0-2 are all 0's no bde */
  5500. /* word3 and word4 are rsvrd */
  5501. wqe->words[3] = 0;
  5502. wqe->words[4] = 0;
  5503. /* word5 iocb=rsvd wge=did */
  5504. /* There is no remote port id in the IOCB? */
  5505. /* Let this fall through and fail */
  5506. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5507. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5508. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5509. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5510. default:
  5511. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5512. "2014 Invalid command 0x%x\n",
  5513. iocbq->iocb.ulpCommand);
  5514. return IOCB_ERROR;
  5515. break;
  5516. }
  5517. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5518. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5519. wqe->generic.abort_tag = abort_tag;
  5520. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5521. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5522. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5523. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5524. return 0;
  5525. }
  5526. /**
  5527. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5528. * @phba: Pointer to HBA context object.
  5529. * @ring_number: SLI ring number to issue iocb on.
  5530. * @piocb: Pointer to command iocb.
  5531. * @flag: Flag indicating if this command can be put into txq.
  5532. *
  5533. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5534. * an iocb command to an HBA with SLI-4 interface spec.
  5535. *
  5536. * This function is called with hbalock held. The function will return success
  5537. * after it successfully submit the iocb to firmware or after adding to the
  5538. * txq.
  5539. **/
  5540. static int
  5541. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5542. struct lpfc_iocbq *piocb, uint32_t flag)
  5543. {
  5544. struct lpfc_sglq *sglq;
  5545. uint16_t xritag;
  5546. union lpfc_wqe wqe;
  5547. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5548. uint32_t fcp_wqidx;
  5549. if (piocb->sli4_xritag == NO_XRI) {
  5550. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5551. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5552. sglq = NULL;
  5553. else {
  5554. sglq = __lpfc_sli_get_sglq(phba);
  5555. if (!sglq)
  5556. return IOCB_ERROR;
  5557. piocb->sli4_xritag = sglq->sli4_xritag;
  5558. }
  5559. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5560. sglq = NULL; /* These IO's already have an XRI and
  5561. * a mapped sgl.
  5562. */
  5563. } else {
  5564. /* This is a continuation of a commandi,(CX) so this
  5565. * sglq is on the active list
  5566. */
  5567. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5568. if (!sglq)
  5569. return IOCB_ERROR;
  5570. }
  5571. if (sglq) {
  5572. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5573. if (xritag != sglq->sli4_xritag)
  5574. return IOCB_ERROR;
  5575. }
  5576. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5577. return IOCB_ERROR;
  5578. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5579. fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5580. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
  5581. return IOCB_ERROR;
  5582. } else {
  5583. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5584. return IOCB_ERROR;
  5585. }
  5586. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5587. return 0;
  5588. }
  5589. /**
  5590. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5591. *
  5592. * This routine wraps the actual lockless version for issusing IOCB function
  5593. * pointer from the lpfc_hba struct.
  5594. *
  5595. * Return codes:
  5596. * IOCB_ERROR - Error
  5597. * IOCB_SUCCESS - Success
  5598. * IOCB_BUSY - Busy
  5599. **/
  5600. static inline int
  5601. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5602. struct lpfc_iocbq *piocb, uint32_t flag)
  5603. {
  5604. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5605. }
  5606. /**
  5607. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5608. * @phba: The hba struct for which this call is being executed.
  5609. * @dev_grp: The HBA PCI-Device group number.
  5610. *
  5611. * This routine sets up the SLI interface API function jump table in @phba
  5612. * struct.
  5613. * Returns: 0 - success, -ENODEV - failure.
  5614. **/
  5615. int
  5616. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5617. {
  5618. switch (dev_grp) {
  5619. case LPFC_PCI_DEV_LP:
  5620. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5621. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5622. break;
  5623. case LPFC_PCI_DEV_OC:
  5624. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5625. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5626. break;
  5627. default:
  5628. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5629. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5630. dev_grp);
  5631. return -ENODEV;
  5632. break;
  5633. }
  5634. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5635. return 0;
  5636. }
  5637. /**
  5638. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5639. * @phba: Pointer to HBA context object.
  5640. * @pring: Pointer to driver SLI ring object.
  5641. * @piocb: Pointer to command iocb.
  5642. * @flag: Flag indicating if this command can be put into txq.
  5643. *
  5644. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5645. * function. This function gets the hbalock and calls
  5646. * __lpfc_sli_issue_iocb function and will return the error returned
  5647. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5648. * functions which do not hold hbalock.
  5649. **/
  5650. int
  5651. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5652. struct lpfc_iocbq *piocb, uint32_t flag)
  5653. {
  5654. unsigned long iflags;
  5655. int rc;
  5656. spin_lock_irqsave(&phba->hbalock, iflags);
  5657. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5658. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5659. return rc;
  5660. }
  5661. /**
  5662. * lpfc_extra_ring_setup - Extra ring setup function
  5663. * @phba: Pointer to HBA context object.
  5664. *
  5665. * This function is called while driver attaches with the
  5666. * HBA to setup the extra ring. The extra ring is used
  5667. * only when driver needs to support target mode functionality
  5668. * or IP over FC functionalities.
  5669. *
  5670. * This function is called with no lock held.
  5671. **/
  5672. static int
  5673. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5674. {
  5675. struct lpfc_sli *psli;
  5676. struct lpfc_sli_ring *pring;
  5677. psli = &phba->sli;
  5678. /* Adjust cmd/rsp ring iocb entries more evenly */
  5679. /* Take some away from the FCP ring */
  5680. pring = &psli->ring[psli->fcp_ring];
  5681. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5682. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5683. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5684. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5685. /* and give them to the extra ring */
  5686. pring = &psli->ring[psli->extra_ring];
  5687. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5688. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5689. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5690. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5691. /* Setup default profile for this ring */
  5692. pring->iotag_max = 4096;
  5693. pring->num_mask = 1;
  5694. pring->prt[0].profile = 0; /* Mask 0 */
  5695. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5696. pring->prt[0].type = phba->cfg_multi_ring_type;
  5697. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5698. return 0;
  5699. }
  5700. /**
  5701. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5702. * @phba: Pointer to HBA context object.
  5703. * @pring: Pointer to driver SLI ring object.
  5704. * @iocbq: Pointer to iocb object.
  5705. *
  5706. * This function is called by the slow ring event handler
  5707. * function when there is an ASYNC event iocb in the ring.
  5708. * This function is called with no lock held.
  5709. * Currently this function handles only temperature related
  5710. * ASYNC events. The function decodes the temperature sensor
  5711. * event message and posts events for the management applications.
  5712. **/
  5713. static void
  5714. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5715. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5716. {
  5717. IOCB_t *icmd;
  5718. uint16_t evt_code;
  5719. uint16_t temp;
  5720. struct temp_event temp_event_data;
  5721. struct Scsi_Host *shost;
  5722. uint32_t *iocb_w;
  5723. icmd = &iocbq->iocb;
  5724. evt_code = icmd->un.asyncstat.evt_code;
  5725. temp = icmd->ulpContext;
  5726. if ((evt_code != ASYNC_TEMP_WARN) &&
  5727. (evt_code != ASYNC_TEMP_SAFE)) {
  5728. iocb_w = (uint32_t *) icmd;
  5729. lpfc_printf_log(phba,
  5730. KERN_ERR,
  5731. LOG_SLI,
  5732. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5733. " evt_code 0x%x\n"
  5734. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5735. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5736. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5737. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5738. pring->ringno,
  5739. icmd->un.asyncstat.evt_code,
  5740. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5741. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5742. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5743. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5744. return;
  5745. }
  5746. temp_event_data.data = (uint32_t)temp;
  5747. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5748. if (evt_code == ASYNC_TEMP_WARN) {
  5749. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5750. lpfc_printf_log(phba,
  5751. KERN_ERR,
  5752. LOG_TEMP,
  5753. "0347 Adapter is very hot, please take "
  5754. "corrective action. temperature : %d Celsius\n",
  5755. temp);
  5756. }
  5757. if (evt_code == ASYNC_TEMP_SAFE) {
  5758. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5759. lpfc_printf_log(phba,
  5760. KERN_ERR,
  5761. LOG_TEMP,
  5762. "0340 Adapter temperature is OK now. "
  5763. "temperature : %d Celsius\n",
  5764. temp);
  5765. }
  5766. /* Send temperature change event to applications */
  5767. shost = lpfc_shost_from_vport(phba->pport);
  5768. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5769. sizeof(temp_event_data), (char *) &temp_event_data,
  5770. LPFC_NL_VENDOR_ID);
  5771. }
  5772. /**
  5773. * lpfc_sli_setup - SLI ring setup function
  5774. * @phba: Pointer to HBA context object.
  5775. *
  5776. * lpfc_sli_setup sets up rings of the SLI interface with
  5777. * number of iocbs per ring and iotags. This function is
  5778. * called while driver attach to the HBA and before the
  5779. * interrupts are enabled. So there is no need for locking.
  5780. *
  5781. * This function always returns 0.
  5782. **/
  5783. int
  5784. lpfc_sli_setup(struct lpfc_hba *phba)
  5785. {
  5786. int i, totiocbsize = 0;
  5787. struct lpfc_sli *psli = &phba->sli;
  5788. struct lpfc_sli_ring *pring;
  5789. psli->num_rings = MAX_CONFIGURED_RINGS;
  5790. psli->sli_flag = 0;
  5791. psli->fcp_ring = LPFC_FCP_RING;
  5792. psli->next_ring = LPFC_FCP_NEXT_RING;
  5793. psli->extra_ring = LPFC_EXTRA_RING;
  5794. psli->iocbq_lookup = NULL;
  5795. psli->iocbq_lookup_len = 0;
  5796. psli->last_iotag = 0;
  5797. for (i = 0; i < psli->num_rings; i++) {
  5798. pring = &psli->ring[i];
  5799. switch (i) {
  5800. case LPFC_FCP_RING: /* ring 0 - FCP */
  5801. /* numCiocb and numRiocb are used in config_port */
  5802. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5803. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5804. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5805. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5806. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5807. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5808. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5809. SLI3_IOCB_CMD_SIZE :
  5810. SLI2_IOCB_CMD_SIZE;
  5811. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5812. SLI3_IOCB_RSP_SIZE :
  5813. SLI2_IOCB_RSP_SIZE;
  5814. pring->iotag_ctr = 0;
  5815. pring->iotag_max =
  5816. (phba->cfg_hba_queue_depth * 2);
  5817. pring->fast_iotag = pring->iotag_max;
  5818. pring->num_mask = 0;
  5819. break;
  5820. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5821. /* numCiocb and numRiocb are used in config_port */
  5822. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5823. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5824. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5825. SLI3_IOCB_CMD_SIZE :
  5826. SLI2_IOCB_CMD_SIZE;
  5827. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5828. SLI3_IOCB_RSP_SIZE :
  5829. SLI2_IOCB_RSP_SIZE;
  5830. pring->iotag_max = phba->cfg_hba_queue_depth;
  5831. pring->num_mask = 0;
  5832. break;
  5833. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5834. /* numCiocb and numRiocb are used in config_port */
  5835. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5836. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5837. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5838. SLI3_IOCB_CMD_SIZE :
  5839. SLI2_IOCB_CMD_SIZE;
  5840. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5841. SLI3_IOCB_RSP_SIZE :
  5842. SLI2_IOCB_RSP_SIZE;
  5843. pring->fast_iotag = 0;
  5844. pring->iotag_ctr = 0;
  5845. pring->iotag_max = 4096;
  5846. pring->lpfc_sli_rcv_async_status =
  5847. lpfc_sli_async_event_handler;
  5848. pring->num_mask = 4;
  5849. pring->prt[0].profile = 0; /* Mask 0 */
  5850. pring->prt[0].rctl = FC_ELS_REQ;
  5851. pring->prt[0].type = FC_ELS_DATA;
  5852. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5853. lpfc_els_unsol_event;
  5854. pring->prt[1].profile = 0; /* Mask 1 */
  5855. pring->prt[1].rctl = FC_ELS_RSP;
  5856. pring->prt[1].type = FC_ELS_DATA;
  5857. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5858. lpfc_els_unsol_event;
  5859. pring->prt[2].profile = 0; /* Mask 2 */
  5860. /* NameServer Inquiry */
  5861. pring->prt[2].rctl = FC_UNSOL_CTL;
  5862. /* NameServer */
  5863. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  5864. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5865. lpfc_ct_unsol_event;
  5866. pring->prt[3].profile = 0; /* Mask 3 */
  5867. /* NameServer response */
  5868. pring->prt[3].rctl = FC_SOL_CTL;
  5869. /* NameServer */
  5870. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  5871. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5872. lpfc_ct_unsol_event;
  5873. break;
  5874. }
  5875. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5876. (pring->numRiocb * pring->sizeRiocb);
  5877. }
  5878. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5879. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5880. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5881. "SLI2 SLIM Data: x%x x%lx\n",
  5882. phba->brd_no, totiocbsize,
  5883. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5884. }
  5885. if (phba->cfg_multi_ring_support == 2)
  5886. lpfc_extra_ring_setup(phba);
  5887. return 0;
  5888. }
  5889. /**
  5890. * lpfc_sli_queue_setup - Queue initialization function
  5891. * @phba: Pointer to HBA context object.
  5892. *
  5893. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5894. * ring. This function also initializes ring indices of each ring.
  5895. * This function is called during the initialization of the SLI
  5896. * interface of an HBA.
  5897. * This function is called with no lock held and always returns
  5898. * 1.
  5899. **/
  5900. int
  5901. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5902. {
  5903. struct lpfc_sli *psli;
  5904. struct lpfc_sli_ring *pring;
  5905. int i;
  5906. psli = &phba->sli;
  5907. spin_lock_irq(&phba->hbalock);
  5908. INIT_LIST_HEAD(&psli->mboxq);
  5909. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5910. /* Initialize list headers for txq and txcmplq as double linked lists */
  5911. for (i = 0; i < psli->num_rings; i++) {
  5912. pring = &psli->ring[i];
  5913. pring->ringno = i;
  5914. pring->next_cmdidx = 0;
  5915. pring->local_getidx = 0;
  5916. pring->cmdidx = 0;
  5917. INIT_LIST_HEAD(&pring->txq);
  5918. INIT_LIST_HEAD(&pring->txcmplq);
  5919. INIT_LIST_HEAD(&pring->iocb_continueq);
  5920. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5921. INIT_LIST_HEAD(&pring->postbufq);
  5922. }
  5923. spin_unlock_irq(&phba->hbalock);
  5924. return 1;
  5925. }
  5926. /**
  5927. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5928. * @phba: Pointer to HBA context object.
  5929. *
  5930. * This routine flushes the mailbox command subsystem. It will unconditionally
  5931. * flush all the mailbox commands in the three possible stages in the mailbox
  5932. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5933. * command; and completed mailbox command queue. It is caller's responsibility
  5934. * to make sure that the driver is in the proper state to flush the mailbox
  5935. * command sub-system. Namely, the posting of mailbox commands into the
  5936. * pending mailbox command queue from the various clients must be stopped;
  5937. * either the HBA is in a state that it will never works on the outstanding
  5938. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5939. * mailbox command has been completed.
  5940. **/
  5941. static void
  5942. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5943. {
  5944. LIST_HEAD(completions);
  5945. struct lpfc_sli *psli = &phba->sli;
  5946. LPFC_MBOXQ_t *pmb;
  5947. unsigned long iflag;
  5948. /* Flush all the mailbox commands in the mbox system */
  5949. spin_lock_irqsave(&phba->hbalock, iflag);
  5950. /* The pending mailbox command queue */
  5951. list_splice_init(&phba->sli.mboxq, &completions);
  5952. /* The outstanding active mailbox command */
  5953. if (psli->mbox_active) {
  5954. list_add_tail(&psli->mbox_active->list, &completions);
  5955. psli->mbox_active = NULL;
  5956. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5957. }
  5958. /* The completed mailbox command queue */
  5959. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5960. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5961. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5962. while (!list_empty(&completions)) {
  5963. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5964. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5965. if (pmb->mbox_cmpl)
  5966. pmb->mbox_cmpl(phba, pmb);
  5967. }
  5968. }
  5969. /**
  5970. * lpfc_sli_host_down - Vport cleanup function
  5971. * @vport: Pointer to virtual port object.
  5972. *
  5973. * lpfc_sli_host_down is called to clean up the resources
  5974. * associated with a vport before destroying virtual
  5975. * port data structures.
  5976. * This function does following operations:
  5977. * - Free discovery resources associated with this virtual
  5978. * port.
  5979. * - Free iocbs associated with this virtual port in
  5980. * the txq.
  5981. * - Send abort for all iocb commands associated with this
  5982. * vport in txcmplq.
  5983. *
  5984. * This function is called with no lock held and always returns 1.
  5985. **/
  5986. int
  5987. lpfc_sli_host_down(struct lpfc_vport *vport)
  5988. {
  5989. LIST_HEAD(completions);
  5990. struct lpfc_hba *phba = vport->phba;
  5991. struct lpfc_sli *psli = &phba->sli;
  5992. struct lpfc_sli_ring *pring;
  5993. struct lpfc_iocbq *iocb, *next_iocb;
  5994. int i;
  5995. unsigned long flags = 0;
  5996. uint16_t prev_pring_flag;
  5997. lpfc_cleanup_discovery_resources(vport);
  5998. spin_lock_irqsave(&phba->hbalock, flags);
  5999. for (i = 0; i < psli->num_rings; i++) {
  6000. pring = &psli->ring[i];
  6001. prev_pring_flag = pring->flag;
  6002. /* Only slow rings */
  6003. if (pring->ringno == LPFC_ELS_RING) {
  6004. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6005. /* Set the lpfc data pending flag */
  6006. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6007. }
  6008. /*
  6009. * Error everything on the txq since these iocbs have not been
  6010. * given to the FW yet.
  6011. */
  6012. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6013. if (iocb->vport != vport)
  6014. continue;
  6015. list_move_tail(&iocb->list, &completions);
  6016. pring->txq_cnt--;
  6017. }
  6018. /* Next issue ABTS for everything on the txcmplq */
  6019. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6020. list) {
  6021. if (iocb->vport != vport)
  6022. continue;
  6023. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6024. }
  6025. pring->flag = prev_pring_flag;
  6026. }
  6027. spin_unlock_irqrestore(&phba->hbalock, flags);
  6028. /* Cancel all the IOCBs from the completions list */
  6029. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6030. IOERR_SLI_DOWN);
  6031. return 1;
  6032. }
  6033. /**
  6034. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6035. * @phba: Pointer to HBA context object.
  6036. *
  6037. * This function cleans up all iocb, buffers, mailbox commands
  6038. * while shutting down the HBA. This function is called with no
  6039. * lock held and always returns 1.
  6040. * This function does the following to cleanup driver resources:
  6041. * - Free discovery resources for each virtual port
  6042. * - Cleanup any pending fabric iocbs
  6043. * - Iterate through the iocb txq and free each entry
  6044. * in the list.
  6045. * - Free up any buffer posted to the HBA
  6046. * - Free mailbox commands in the mailbox queue.
  6047. **/
  6048. int
  6049. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6050. {
  6051. LIST_HEAD(completions);
  6052. struct lpfc_sli *psli = &phba->sli;
  6053. struct lpfc_sli_ring *pring;
  6054. struct lpfc_dmabuf *buf_ptr;
  6055. unsigned long flags = 0;
  6056. int i;
  6057. /* Shutdown the mailbox command sub-system */
  6058. lpfc_sli_mbox_sys_shutdown(phba);
  6059. lpfc_hba_down_prep(phba);
  6060. lpfc_fabric_abort_hba(phba);
  6061. spin_lock_irqsave(&phba->hbalock, flags);
  6062. for (i = 0; i < psli->num_rings; i++) {
  6063. pring = &psli->ring[i];
  6064. /* Only slow rings */
  6065. if (pring->ringno == LPFC_ELS_RING) {
  6066. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6067. /* Set the lpfc data pending flag */
  6068. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6069. }
  6070. /*
  6071. * Error everything on the txq since these iocbs have not been
  6072. * given to the FW yet.
  6073. */
  6074. list_splice_init(&pring->txq, &completions);
  6075. pring->txq_cnt = 0;
  6076. }
  6077. spin_unlock_irqrestore(&phba->hbalock, flags);
  6078. /* Cancel all the IOCBs from the completions list */
  6079. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6080. IOERR_SLI_DOWN);
  6081. spin_lock_irqsave(&phba->hbalock, flags);
  6082. list_splice_init(&phba->elsbuf, &completions);
  6083. phba->elsbuf_cnt = 0;
  6084. phba->elsbuf_prev_cnt = 0;
  6085. spin_unlock_irqrestore(&phba->hbalock, flags);
  6086. while (!list_empty(&completions)) {
  6087. list_remove_head(&completions, buf_ptr,
  6088. struct lpfc_dmabuf, list);
  6089. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6090. kfree(buf_ptr);
  6091. }
  6092. /* Return any active mbox cmds */
  6093. del_timer_sync(&psli->mbox_tmo);
  6094. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6095. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6096. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6097. return 1;
  6098. }
  6099. /**
  6100. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6101. * @phba: Pointer to HBA context object.
  6102. *
  6103. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6104. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6105. * lock held and always returns 1.
  6106. *
  6107. * This function does the following to cleanup driver FCoE function resources:
  6108. * - Free discovery resources for each virtual port
  6109. * - Cleanup any pending fabric iocbs
  6110. * - Iterate through the iocb txq and free each entry in the list.
  6111. * - Free up any buffer posted to the HBA.
  6112. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6113. * - Free mailbox commands in the mailbox queue.
  6114. **/
  6115. int
  6116. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6117. {
  6118. /* Stop the SLI4 device port */
  6119. lpfc_stop_port(phba);
  6120. /* Tear down the queues in the HBA */
  6121. lpfc_sli4_queue_unset(phba);
  6122. /* unregister default FCFI from the HBA */
  6123. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6124. return 1;
  6125. }
  6126. /**
  6127. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6128. * @srcp: Source memory pointer.
  6129. * @destp: Destination memory pointer.
  6130. * @cnt: Number of words required to be copied.
  6131. *
  6132. * This function is used for copying data between driver memory
  6133. * and the SLI memory. This function also changes the endianness
  6134. * of each word if native endianness is different from SLI
  6135. * endianness. This function can be called with or without
  6136. * lock.
  6137. **/
  6138. void
  6139. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6140. {
  6141. uint32_t *src = srcp;
  6142. uint32_t *dest = destp;
  6143. uint32_t ldata;
  6144. int i;
  6145. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6146. ldata = *src;
  6147. ldata = le32_to_cpu(ldata);
  6148. *dest = ldata;
  6149. src++;
  6150. dest++;
  6151. }
  6152. }
  6153. /**
  6154. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6155. * @srcp: Source memory pointer.
  6156. * @destp: Destination memory pointer.
  6157. * @cnt: Number of words required to be copied.
  6158. *
  6159. * This function is used for copying data between a data structure
  6160. * with big endian representation to local endianness.
  6161. * This function can be called with or without lock.
  6162. **/
  6163. void
  6164. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6165. {
  6166. uint32_t *src = srcp;
  6167. uint32_t *dest = destp;
  6168. uint32_t ldata;
  6169. int i;
  6170. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6171. ldata = *src;
  6172. ldata = be32_to_cpu(ldata);
  6173. *dest = ldata;
  6174. src++;
  6175. dest++;
  6176. }
  6177. }
  6178. /**
  6179. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6180. * @phba: Pointer to HBA context object.
  6181. * @pring: Pointer to driver SLI ring object.
  6182. * @mp: Pointer to driver buffer object.
  6183. *
  6184. * This function is called with no lock held.
  6185. * It always return zero after adding the buffer to the postbufq
  6186. * buffer list.
  6187. **/
  6188. int
  6189. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6190. struct lpfc_dmabuf *mp)
  6191. {
  6192. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6193. later */
  6194. spin_lock_irq(&phba->hbalock);
  6195. list_add_tail(&mp->list, &pring->postbufq);
  6196. pring->postbufq_cnt++;
  6197. spin_unlock_irq(&phba->hbalock);
  6198. return 0;
  6199. }
  6200. /**
  6201. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6202. * @phba: Pointer to HBA context object.
  6203. *
  6204. * When HBQ is enabled, buffers are searched based on tags. This function
  6205. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6206. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6207. * does not conflict with tags of buffer posted for unsolicited events.
  6208. * The function returns the allocated tag. The function is called with
  6209. * no locks held.
  6210. **/
  6211. uint32_t
  6212. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6213. {
  6214. spin_lock_irq(&phba->hbalock);
  6215. phba->buffer_tag_count++;
  6216. /*
  6217. * Always set the QUE_BUFTAG_BIT to distiguish between
  6218. * a tag assigned by HBQ.
  6219. */
  6220. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6221. spin_unlock_irq(&phba->hbalock);
  6222. return phba->buffer_tag_count;
  6223. }
  6224. /**
  6225. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6226. * @phba: Pointer to HBA context object.
  6227. * @pring: Pointer to driver SLI ring object.
  6228. * @tag: Buffer tag.
  6229. *
  6230. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6231. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6232. * iocb is posted to the response ring with the tag of the buffer.
  6233. * This function searches the pring->postbufq list using the tag
  6234. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6235. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6236. * buffer is returned to the caller else NULL is returned.
  6237. * This function is called with no lock held.
  6238. **/
  6239. struct lpfc_dmabuf *
  6240. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6241. uint32_t tag)
  6242. {
  6243. struct lpfc_dmabuf *mp, *next_mp;
  6244. struct list_head *slp = &pring->postbufq;
  6245. /* Search postbufq, from the begining, looking for a match on tag */
  6246. spin_lock_irq(&phba->hbalock);
  6247. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6248. if (mp->buffer_tag == tag) {
  6249. list_del_init(&mp->list);
  6250. pring->postbufq_cnt--;
  6251. spin_unlock_irq(&phba->hbalock);
  6252. return mp;
  6253. }
  6254. }
  6255. spin_unlock_irq(&phba->hbalock);
  6256. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6257. "0402 Cannot find virtual addr for buffer tag on "
  6258. "ring %d Data x%lx x%p x%p x%x\n",
  6259. pring->ringno, (unsigned long) tag,
  6260. slp->next, slp->prev, pring->postbufq_cnt);
  6261. return NULL;
  6262. }
  6263. /**
  6264. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6265. * @phba: Pointer to HBA context object.
  6266. * @pring: Pointer to driver SLI ring object.
  6267. * @phys: DMA address of the buffer.
  6268. *
  6269. * This function searches the buffer list using the dma_address
  6270. * of unsolicited event to find the driver's lpfc_dmabuf object
  6271. * corresponding to the dma_address. The function returns the
  6272. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6273. * This function is called by the ct and els unsolicited event
  6274. * handlers to get the buffer associated with the unsolicited
  6275. * event.
  6276. *
  6277. * This function is called with no lock held.
  6278. **/
  6279. struct lpfc_dmabuf *
  6280. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6281. dma_addr_t phys)
  6282. {
  6283. struct lpfc_dmabuf *mp, *next_mp;
  6284. struct list_head *slp = &pring->postbufq;
  6285. /* Search postbufq, from the begining, looking for a match on phys */
  6286. spin_lock_irq(&phba->hbalock);
  6287. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6288. if (mp->phys == phys) {
  6289. list_del_init(&mp->list);
  6290. pring->postbufq_cnt--;
  6291. spin_unlock_irq(&phba->hbalock);
  6292. return mp;
  6293. }
  6294. }
  6295. spin_unlock_irq(&phba->hbalock);
  6296. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6297. "0410 Cannot find virtual addr for mapped buf on "
  6298. "ring %d Data x%llx x%p x%p x%x\n",
  6299. pring->ringno, (unsigned long long)phys,
  6300. slp->next, slp->prev, pring->postbufq_cnt);
  6301. return NULL;
  6302. }
  6303. /**
  6304. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6305. * @phba: Pointer to HBA context object.
  6306. * @cmdiocb: Pointer to driver command iocb object.
  6307. * @rspiocb: Pointer to driver response iocb object.
  6308. *
  6309. * This function is the completion handler for the abort iocbs for
  6310. * ELS commands. This function is called from the ELS ring event
  6311. * handler with no lock held. This function frees memory resources
  6312. * associated with the abort iocb.
  6313. **/
  6314. static void
  6315. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6316. struct lpfc_iocbq *rspiocb)
  6317. {
  6318. IOCB_t *irsp = &rspiocb->iocb;
  6319. uint16_t abort_iotag, abort_context;
  6320. struct lpfc_iocbq *abort_iocb;
  6321. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6322. abort_iocb = NULL;
  6323. if (irsp->ulpStatus) {
  6324. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6325. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6326. spin_lock_irq(&phba->hbalock);
  6327. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  6328. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  6329. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6330. "0327 Cannot abort els iocb %p "
  6331. "with tag %x context %x, abort status %x, "
  6332. "abort code %x\n",
  6333. abort_iocb, abort_iotag, abort_context,
  6334. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6335. /*
  6336. * If the iocb is not found in Firmware queue the iocb
  6337. * might have completed already. Do not free it again.
  6338. */
  6339. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6340. spin_unlock_irq(&phba->hbalock);
  6341. lpfc_sli_release_iocbq(phba, cmdiocb);
  6342. return;
  6343. }
  6344. /*
  6345. * make sure we have the right iocbq before taking it
  6346. * off the txcmplq and try to call completion routine.
  6347. */
  6348. if (!abort_iocb ||
  6349. abort_iocb->iocb.ulpContext != abort_context ||
  6350. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6351. spin_unlock_irq(&phba->hbalock);
  6352. else {
  6353. list_del_init(&abort_iocb->list);
  6354. pring->txcmplq_cnt--;
  6355. spin_unlock_irq(&phba->hbalock);
  6356. /* Firmware could still be in progress of DMAing
  6357. * payload, so don't free data buffer till after
  6358. * a hbeat.
  6359. */
  6360. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6361. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6362. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6363. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6364. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6365. }
  6366. }
  6367. lpfc_sli_release_iocbq(phba, cmdiocb);
  6368. return;
  6369. }
  6370. /**
  6371. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6372. * @phba: Pointer to HBA context object.
  6373. * @cmdiocb: Pointer to driver command iocb object.
  6374. * @rspiocb: Pointer to driver response iocb object.
  6375. *
  6376. * The function is called from SLI ring event handler with no
  6377. * lock held. This function is the completion handler for ELS commands
  6378. * which are aborted. The function frees memory resources used for
  6379. * the aborted ELS commands.
  6380. **/
  6381. static void
  6382. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6383. struct lpfc_iocbq *rspiocb)
  6384. {
  6385. IOCB_t *irsp = &rspiocb->iocb;
  6386. /* ELS cmd tag <ulpIoTag> completes */
  6387. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6388. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6389. "x%x x%x x%x\n",
  6390. irsp->ulpIoTag, irsp->ulpStatus,
  6391. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6392. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6393. lpfc_ct_free_iocb(phba, cmdiocb);
  6394. else
  6395. lpfc_els_free_iocb(phba, cmdiocb);
  6396. return;
  6397. }
  6398. /**
  6399. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6400. * @phba: Pointer to HBA context object.
  6401. * @pring: Pointer to driver SLI ring object.
  6402. * @cmdiocb: Pointer to driver command iocb object.
  6403. *
  6404. * This function issues an abort iocb for the provided command
  6405. * iocb. This function is called with hbalock held.
  6406. * The function returns 0 when it fails due to memory allocation
  6407. * failure or when the command iocb is an abort request.
  6408. **/
  6409. int
  6410. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6411. struct lpfc_iocbq *cmdiocb)
  6412. {
  6413. struct lpfc_vport *vport = cmdiocb->vport;
  6414. struct lpfc_iocbq *abtsiocbp;
  6415. IOCB_t *icmd = NULL;
  6416. IOCB_t *iabt = NULL;
  6417. int retval = IOCB_ERROR;
  6418. /*
  6419. * There are certain command types we don't want to abort. And we
  6420. * don't want to abort commands that are already in the process of
  6421. * being aborted.
  6422. */
  6423. icmd = &cmdiocb->iocb;
  6424. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6425. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6426. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6427. return 0;
  6428. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6429. * callback so that nothing happens when it finishes.
  6430. */
  6431. if ((vport->load_flag & FC_UNLOADING) &&
  6432. (pring->ringno == LPFC_ELS_RING)) {
  6433. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6434. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6435. else
  6436. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6437. goto abort_iotag_exit;
  6438. }
  6439. /* issue ABTS for this IOCB based on iotag */
  6440. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6441. if (abtsiocbp == NULL)
  6442. return 0;
  6443. /* This signals the response to set the correct status
  6444. * before calling the completion handler.
  6445. */
  6446. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6447. iabt = &abtsiocbp->iocb;
  6448. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6449. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6450. if (phba->sli_rev == LPFC_SLI_REV4)
  6451. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6452. else
  6453. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6454. iabt->ulpLe = 1;
  6455. iabt->ulpClass = icmd->ulpClass;
  6456. if (phba->link_state >= LPFC_LINK_UP)
  6457. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6458. else
  6459. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6460. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6461. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6462. "0339 Abort xri x%x, original iotag x%x, "
  6463. "abort cmd iotag x%x\n",
  6464. iabt->un.acxri.abortContextTag,
  6465. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6466. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6467. if (retval)
  6468. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6469. abort_iotag_exit:
  6470. /*
  6471. * Caller to this routine should check for IOCB_ERROR
  6472. * and handle it properly. This routine no longer removes
  6473. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6474. */
  6475. return retval;
  6476. }
  6477. /**
  6478. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6479. * @iocbq: Pointer to driver iocb object.
  6480. * @vport: Pointer to driver virtual port object.
  6481. * @tgt_id: SCSI ID of the target.
  6482. * @lun_id: LUN ID of the scsi device.
  6483. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6484. *
  6485. * This function acts as an iocb filter for functions which abort or count
  6486. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6487. * 0 if the filtering criteria is met for the given iocb and will return
  6488. * 1 if the filtering criteria is not met.
  6489. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6490. * given iocb is for the SCSI device specified by vport, tgt_id and
  6491. * lun_id parameter.
  6492. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6493. * given iocb is for the SCSI target specified by vport and tgt_id
  6494. * parameters.
  6495. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6496. * given iocb is for the SCSI host associated with the given vport.
  6497. * This function is called with no locks held.
  6498. **/
  6499. static int
  6500. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6501. uint16_t tgt_id, uint64_t lun_id,
  6502. lpfc_ctx_cmd ctx_cmd)
  6503. {
  6504. struct lpfc_scsi_buf *lpfc_cmd;
  6505. int rc = 1;
  6506. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6507. return rc;
  6508. if (iocbq->vport != vport)
  6509. return rc;
  6510. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6511. if (lpfc_cmd->pCmd == NULL)
  6512. return rc;
  6513. switch (ctx_cmd) {
  6514. case LPFC_CTX_LUN:
  6515. if ((lpfc_cmd->rdata->pnode) &&
  6516. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6517. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6518. rc = 0;
  6519. break;
  6520. case LPFC_CTX_TGT:
  6521. if ((lpfc_cmd->rdata->pnode) &&
  6522. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6523. rc = 0;
  6524. break;
  6525. case LPFC_CTX_HOST:
  6526. rc = 0;
  6527. break;
  6528. default:
  6529. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6530. __func__, ctx_cmd);
  6531. break;
  6532. }
  6533. return rc;
  6534. }
  6535. /**
  6536. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6537. * @vport: Pointer to virtual port.
  6538. * @tgt_id: SCSI ID of the target.
  6539. * @lun_id: LUN ID of the scsi device.
  6540. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6541. *
  6542. * This function returns number of FCP commands pending for the vport.
  6543. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6544. * commands pending on the vport associated with SCSI device specified
  6545. * by tgt_id and lun_id parameters.
  6546. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6547. * commands pending on the vport associated with SCSI target specified
  6548. * by tgt_id parameter.
  6549. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6550. * commands pending on the vport.
  6551. * This function returns the number of iocbs which satisfy the filter.
  6552. * This function is called without any lock held.
  6553. **/
  6554. int
  6555. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6556. lpfc_ctx_cmd ctx_cmd)
  6557. {
  6558. struct lpfc_hba *phba = vport->phba;
  6559. struct lpfc_iocbq *iocbq;
  6560. int sum, i;
  6561. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6562. iocbq = phba->sli.iocbq_lookup[i];
  6563. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6564. ctx_cmd) == 0)
  6565. sum++;
  6566. }
  6567. return sum;
  6568. }
  6569. /**
  6570. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6571. * @phba: Pointer to HBA context object
  6572. * @cmdiocb: Pointer to command iocb object.
  6573. * @rspiocb: Pointer to response iocb object.
  6574. *
  6575. * This function is called when an aborted FCP iocb completes. This
  6576. * function is called by the ring event handler with no lock held.
  6577. * This function frees the iocb.
  6578. **/
  6579. void
  6580. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6581. struct lpfc_iocbq *rspiocb)
  6582. {
  6583. lpfc_sli_release_iocbq(phba, cmdiocb);
  6584. return;
  6585. }
  6586. /**
  6587. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6588. * @vport: Pointer to virtual port.
  6589. * @pring: Pointer to driver SLI ring object.
  6590. * @tgt_id: SCSI ID of the target.
  6591. * @lun_id: LUN ID of the scsi device.
  6592. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6593. *
  6594. * This function sends an abort command for every SCSI command
  6595. * associated with the given virtual port pending on the ring
  6596. * filtered by lpfc_sli_validate_fcp_iocb function.
  6597. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6598. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6599. * parameters
  6600. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6601. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6602. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6603. * FCP iocbs associated with virtual port.
  6604. * This function returns number of iocbs it failed to abort.
  6605. * This function is called with no locks held.
  6606. **/
  6607. int
  6608. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6609. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6610. {
  6611. struct lpfc_hba *phba = vport->phba;
  6612. struct lpfc_iocbq *iocbq;
  6613. struct lpfc_iocbq *abtsiocb;
  6614. IOCB_t *cmd = NULL;
  6615. int errcnt = 0, ret_val = 0;
  6616. int i;
  6617. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6618. iocbq = phba->sli.iocbq_lookup[i];
  6619. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6620. abort_cmd) != 0)
  6621. continue;
  6622. /* issue ABTS for this IOCB based on iotag */
  6623. abtsiocb = lpfc_sli_get_iocbq(phba);
  6624. if (abtsiocb == NULL) {
  6625. errcnt++;
  6626. continue;
  6627. }
  6628. cmd = &iocbq->iocb;
  6629. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6630. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6631. if (phba->sli_rev == LPFC_SLI_REV4)
  6632. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6633. else
  6634. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6635. abtsiocb->iocb.ulpLe = 1;
  6636. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6637. abtsiocb->vport = phba->pport;
  6638. if (lpfc_is_link_up(phba))
  6639. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6640. else
  6641. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6642. /* Setup callback routine and issue the command. */
  6643. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6644. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6645. abtsiocb, 0);
  6646. if (ret_val == IOCB_ERROR) {
  6647. lpfc_sli_release_iocbq(phba, abtsiocb);
  6648. errcnt++;
  6649. continue;
  6650. }
  6651. }
  6652. return errcnt;
  6653. }
  6654. /**
  6655. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6656. * @phba: Pointer to HBA context object.
  6657. * @cmdiocbq: Pointer to command iocb.
  6658. * @rspiocbq: Pointer to response iocb.
  6659. *
  6660. * This function is the completion handler for iocbs issued using
  6661. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6662. * ring event handler function without any lock held. This function
  6663. * can be called from both worker thread context and interrupt
  6664. * context. This function also can be called from other thread which
  6665. * cleans up the SLI layer objects.
  6666. * This function copy the contents of the response iocb to the
  6667. * response iocb memory object provided by the caller of
  6668. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6669. * sleeps for the iocb completion.
  6670. **/
  6671. static void
  6672. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6673. struct lpfc_iocbq *cmdiocbq,
  6674. struct lpfc_iocbq *rspiocbq)
  6675. {
  6676. wait_queue_head_t *pdone_q;
  6677. unsigned long iflags;
  6678. spin_lock_irqsave(&phba->hbalock, iflags);
  6679. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6680. if (cmdiocbq->context2 && rspiocbq)
  6681. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6682. &rspiocbq->iocb, sizeof(IOCB_t));
  6683. pdone_q = cmdiocbq->context_un.wait_queue;
  6684. if (pdone_q)
  6685. wake_up(pdone_q);
  6686. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6687. return;
  6688. }
  6689. /**
  6690. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6691. * @phba: Pointer to HBA context object..
  6692. * @piocbq: Pointer to command iocb.
  6693. * @flag: Flag to test.
  6694. *
  6695. * This routine grabs the hbalock and then test the iocb_flag to
  6696. * see if the passed in flag is set.
  6697. * Returns:
  6698. * 1 if flag is set.
  6699. * 0 if flag is not set.
  6700. **/
  6701. static int
  6702. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6703. struct lpfc_iocbq *piocbq, uint32_t flag)
  6704. {
  6705. unsigned long iflags;
  6706. int ret;
  6707. spin_lock_irqsave(&phba->hbalock, iflags);
  6708. ret = piocbq->iocb_flag & flag;
  6709. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6710. return ret;
  6711. }
  6712. /**
  6713. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6714. * @phba: Pointer to HBA context object..
  6715. * @pring: Pointer to sli ring.
  6716. * @piocb: Pointer to command iocb.
  6717. * @prspiocbq: Pointer to response iocb.
  6718. * @timeout: Timeout in number of seconds.
  6719. *
  6720. * This function issues the iocb to firmware and waits for the
  6721. * iocb to complete. If the iocb command is not
  6722. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6723. * Caller should not free the iocb resources if this function
  6724. * returns IOCB_TIMEDOUT.
  6725. * The function waits for the iocb completion using an
  6726. * non-interruptible wait.
  6727. * This function will sleep while waiting for iocb completion.
  6728. * So, this function should not be called from any context which
  6729. * does not allow sleeping. Due to the same reason, this function
  6730. * cannot be called with interrupt disabled.
  6731. * This function assumes that the iocb completions occur while
  6732. * this function sleep. So, this function cannot be called from
  6733. * the thread which process iocb completion for this ring.
  6734. * This function clears the iocb_flag of the iocb object before
  6735. * issuing the iocb and the iocb completion handler sets this
  6736. * flag and wakes this thread when the iocb completes.
  6737. * The contents of the response iocb will be copied to prspiocbq
  6738. * by the completion handler when the command completes.
  6739. * This function returns IOCB_SUCCESS when success.
  6740. * This function is called with no lock held.
  6741. **/
  6742. int
  6743. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6744. uint32_t ring_number,
  6745. struct lpfc_iocbq *piocb,
  6746. struct lpfc_iocbq *prspiocbq,
  6747. uint32_t timeout)
  6748. {
  6749. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6750. long timeleft, timeout_req = 0;
  6751. int retval = IOCB_SUCCESS;
  6752. uint32_t creg_val;
  6753. /*
  6754. * If the caller has provided a response iocbq buffer, then context2
  6755. * is NULL or its an error.
  6756. */
  6757. if (prspiocbq) {
  6758. if (piocb->context2)
  6759. return IOCB_ERROR;
  6760. piocb->context2 = prspiocbq;
  6761. }
  6762. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6763. piocb->context_un.wait_queue = &done_q;
  6764. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6765. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6766. creg_val = readl(phba->HCregaddr);
  6767. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6768. writel(creg_val, phba->HCregaddr);
  6769. readl(phba->HCregaddr); /* flush */
  6770. }
  6771. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6772. if (retval == IOCB_SUCCESS) {
  6773. timeout_req = timeout * HZ;
  6774. timeleft = wait_event_timeout(done_q,
  6775. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6776. timeout_req);
  6777. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6778. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6779. "0331 IOCB wake signaled\n");
  6780. } else if (timeleft == 0) {
  6781. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6782. "0338 IOCB wait timeout error - no "
  6783. "wake response Data x%x\n", timeout);
  6784. retval = IOCB_TIMEDOUT;
  6785. } else {
  6786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6787. "0330 IOCB wake NOT set, "
  6788. "Data x%x x%lx\n",
  6789. timeout, (timeleft / jiffies));
  6790. retval = IOCB_TIMEDOUT;
  6791. }
  6792. } else {
  6793. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6794. "0332 IOCB wait issue failed, Data x%x\n",
  6795. retval);
  6796. retval = IOCB_ERROR;
  6797. }
  6798. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6799. creg_val = readl(phba->HCregaddr);
  6800. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6801. writel(creg_val, phba->HCregaddr);
  6802. readl(phba->HCregaddr); /* flush */
  6803. }
  6804. if (prspiocbq)
  6805. piocb->context2 = NULL;
  6806. piocb->context_un.wait_queue = NULL;
  6807. piocb->iocb_cmpl = NULL;
  6808. return retval;
  6809. }
  6810. /**
  6811. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6812. * @phba: Pointer to HBA context object.
  6813. * @pmboxq: Pointer to driver mailbox object.
  6814. * @timeout: Timeout in number of seconds.
  6815. *
  6816. * This function issues the mailbox to firmware and waits for the
  6817. * mailbox command to complete. If the mailbox command is not
  6818. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6819. * The function waits for the mailbox completion using an
  6820. * interruptible wait. If the thread is woken up due to a
  6821. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6822. * should not free the mailbox resources, if this function returns
  6823. * MBX_TIMEOUT.
  6824. * This function will sleep while waiting for mailbox completion.
  6825. * So, this function should not be called from any context which
  6826. * does not allow sleeping. Due to the same reason, this function
  6827. * cannot be called with interrupt disabled.
  6828. * This function assumes that the mailbox completion occurs while
  6829. * this function sleep. So, this function cannot be called from
  6830. * the worker thread which processes mailbox completion.
  6831. * This function is called in the context of HBA management
  6832. * applications.
  6833. * This function returns MBX_SUCCESS when successful.
  6834. * This function is called with no lock held.
  6835. **/
  6836. int
  6837. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6838. uint32_t timeout)
  6839. {
  6840. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6841. int retval;
  6842. unsigned long flag;
  6843. /* The caller must leave context1 empty. */
  6844. if (pmboxq->context1)
  6845. return MBX_NOT_FINISHED;
  6846. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6847. /* setup wake call as IOCB callback */
  6848. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6849. /* setup context field to pass wait_queue pointer to wake function */
  6850. pmboxq->context1 = &done_q;
  6851. /* now issue the command */
  6852. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6853. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6854. wait_event_interruptible_timeout(done_q,
  6855. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6856. timeout * HZ);
  6857. spin_lock_irqsave(&phba->hbalock, flag);
  6858. pmboxq->context1 = NULL;
  6859. /*
  6860. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6861. * else do not free the resources.
  6862. */
  6863. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6864. retval = MBX_SUCCESS;
  6865. else {
  6866. retval = MBX_TIMEOUT;
  6867. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6868. }
  6869. spin_unlock_irqrestore(&phba->hbalock, flag);
  6870. }
  6871. return retval;
  6872. }
  6873. /**
  6874. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6875. * @phba: Pointer to HBA context.
  6876. *
  6877. * This function is called to shutdown the driver's mailbox sub-system.
  6878. * It first marks the mailbox sub-system is in a block state to prevent
  6879. * the asynchronous mailbox command from issued off the pending mailbox
  6880. * command queue. If the mailbox command sub-system shutdown is due to
  6881. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6882. * the mailbox sub-system flush routine to forcefully bring down the
  6883. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6884. * as with offline or HBA function reset), this routine will wait for the
  6885. * outstanding mailbox command to complete before invoking the mailbox
  6886. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6887. **/
  6888. void
  6889. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6890. {
  6891. struct lpfc_sli *psli = &phba->sli;
  6892. uint8_t actcmd = MBX_HEARTBEAT;
  6893. unsigned long timeout;
  6894. spin_lock_irq(&phba->hbalock);
  6895. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6896. spin_unlock_irq(&phba->hbalock);
  6897. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6898. spin_lock_irq(&phba->hbalock);
  6899. if (phba->sli.mbox_active)
  6900. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6901. spin_unlock_irq(&phba->hbalock);
  6902. /* Determine how long we might wait for the active mailbox
  6903. * command to be gracefully completed by firmware.
  6904. */
  6905. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6906. 1000) + jiffies;
  6907. while (phba->sli.mbox_active) {
  6908. /* Check active mailbox complete status every 2ms */
  6909. msleep(2);
  6910. if (time_after(jiffies, timeout))
  6911. /* Timeout, let the mailbox flush routine to
  6912. * forcefully release active mailbox command
  6913. */
  6914. break;
  6915. }
  6916. }
  6917. lpfc_sli_mbox_sys_flush(phba);
  6918. }
  6919. /**
  6920. * lpfc_sli_eratt_read - read sli-3 error attention events
  6921. * @phba: Pointer to HBA context.
  6922. *
  6923. * This function is called to read the SLI3 device error attention registers
  6924. * for possible error attention events. The caller must hold the hostlock
  6925. * with spin_lock_irq().
  6926. *
  6927. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6928. * Register and returns 0 otherwise.
  6929. **/
  6930. static int
  6931. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6932. {
  6933. uint32_t ha_copy;
  6934. /* Read chip Host Attention (HA) register */
  6935. ha_copy = readl(phba->HAregaddr);
  6936. if (ha_copy & HA_ERATT) {
  6937. /* Read host status register to retrieve error event */
  6938. lpfc_sli_read_hs(phba);
  6939. /* Check if there is a deferred error condition is active */
  6940. if ((HS_FFER1 & phba->work_hs) &&
  6941. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6942. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6943. phba->hba_flag |= DEFER_ERATT;
  6944. /* Clear all interrupt enable conditions */
  6945. writel(0, phba->HCregaddr);
  6946. readl(phba->HCregaddr);
  6947. }
  6948. /* Set the driver HA work bitmap */
  6949. phba->work_ha |= HA_ERATT;
  6950. /* Indicate polling handles this ERATT */
  6951. phba->hba_flag |= HBA_ERATT_HANDLED;
  6952. return 1;
  6953. }
  6954. return 0;
  6955. }
  6956. /**
  6957. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6958. * @phba: Pointer to HBA context.
  6959. *
  6960. * This function is called to read the SLI4 device error attention registers
  6961. * for possible error attention events. The caller must hold the hostlock
  6962. * with spin_lock_irq().
  6963. *
  6964. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6965. * Register and returns 0 otherwise.
  6966. **/
  6967. static int
  6968. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6969. {
  6970. uint32_t uerr_sta_hi, uerr_sta_lo;
  6971. uint32_t onlnreg0, onlnreg1;
  6972. /* For now, use the SLI4 device internal unrecoverable error
  6973. * registers for error attention. This can be changed later.
  6974. */
  6975. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  6976. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  6977. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  6978. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  6979. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  6980. if (uerr_sta_lo || uerr_sta_hi) {
  6981. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6982. "1423 HBA Unrecoverable error: "
  6983. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  6984. "online0_reg=0x%x, online1_reg=0x%x\n",
  6985. uerr_sta_lo, uerr_sta_hi,
  6986. onlnreg0, onlnreg1);
  6987. phba->work_status[0] = uerr_sta_lo;
  6988. phba->work_status[1] = uerr_sta_hi;
  6989. /* Set the driver HA work bitmap */
  6990. phba->work_ha |= HA_ERATT;
  6991. /* Indicate polling handles this ERATT */
  6992. phba->hba_flag |= HBA_ERATT_HANDLED;
  6993. return 1;
  6994. }
  6995. }
  6996. return 0;
  6997. }
  6998. /**
  6999. * lpfc_sli_check_eratt - check error attention events
  7000. * @phba: Pointer to HBA context.
  7001. *
  7002. * This function is called from timer soft interrupt context to check HBA's
  7003. * error attention register bit for error attention events.
  7004. *
  7005. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7006. * Register and returns 0 otherwise.
  7007. **/
  7008. int
  7009. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7010. {
  7011. uint32_t ha_copy;
  7012. /* If somebody is waiting to handle an eratt, don't process it
  7013. * here. The brdkill function will do this.
  7014. */
  7015. if (phba->link_flag & LS_IGNORE_ERATT)
  7016. return 0;
  7017. /* Check if interrupt handler handles this ERATT */
  7018. spin_lock_irq(&phba->hbalock);
  7019. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7020. /* Interrupt handler has handled ERATT */
  7021. spin_unlock_irq(&phba->hbalock);
  7022. return 0;
  7023. }
  7024. /*
  7025. * If there is deferred error attention, do not check for error
  7026. * attention
  7027. */
  7028. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7029. spin_unlock_irq(&phba->hbalock);
  7030. return 0;
  7031. }
  7032. /* If PCI channel is offline, don't process it */
  7033. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7034. spin_unlock_irq(&phba->hbalock);
  7035. return 0;
  7036. }
  7037. switch (phba->sli_rev) {
  7038. case LPFC_SLI_REV2:
  7039. case LPFC_SLI_REV3:
  7040. /* Read chip Host Attention (HA) register */
  7041. ha_copy = lpfc_sli_eratt_read(phba);
  7042. break;
  7043. case LPFC_SLI_REV4:
  7044. /* Read devcie Uncoverable Error (UERR) registers */
  7045. ha_copy = lpfc_sli4_eratt_read(phba);
  7046. break;
  7047. default:
  7048. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7049. "0299 Invalid SLI revision (%d)\n",
  7050. phba->sli_rev);
  7051. ha_copy = 0;
  7052. break;
  7053. }
  7054. spin_unlock_irq(&phba->hbalock);
  7055. return ha_copy;
  7056. }
  7057. /**
  7058. * lpfc_intr_state_check - Check device state for interrupt handling
  7059. * @phba: Pointer to HBA context.
  7060. *
  7061. * This inline routine checks whether a device or its PCI slot is in a state
  7062. * that the interrupt should be handled.
  7063. *
  7064. * This function returns 0 if the device or the PCI slot is in a state that
  7065. * interrupt should be handled, otherwise -EIO.
  7066. */
  7067. static inline int
  7068. lpfc_intr_state_check(struct lpfc_hba *phba)
  7069. {
  7070. /* If the pci channel is offline, ignore all the interrupts */
  7071. if (unlikely(pci_channel_offline(phba->pcidev)))
  7072. return -EIO;
  7073. /* Update device level interrupt statistics */
  7074. phba->sli.slistat.sli_intr++;
  7075. /* Ignore all interrupts during initialization. */
  7076. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7077. return -EIO;
  7078. return 0;
  7079. }
  7080. /**
  7081. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7082. * @irq: Interrupt number.
  7083. * @dev_id: The device context pointer.
  7084. *
  7085. * This function is directly called from the PCI layer as an interrupt
  7086. * service routine when device with SLI-3 interface spec is enabled with
  7087. * MSI-X multi-message interrupt mode and there are slow-path events in
  7088. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7089. * interrupt mode, this function is called as part of the device-level
  7090. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7091. * is undergoing initialization, the interrupt handler will not process
  7092. * the interrupt. The link attention and ELS ring attention events are
  7093. * handled by the worker thread. The interrupt handler signals the worker
  7094. * thread and returns for these events. This function is called without
  7095. * any lock held. It gets the hbalock to access and update SLI data
  7096. * structures.
  7097. *
  7098. * This function returns IRQ_HANDLED when interrupt is handled else it
  7099. * returns IRQ_NONE.
  7100. **/
  7101. irqreturn_t
  7102. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7103. {
  7104. struct lpfc_hba *phba;
  7105. uint32_t ha_copy;
  7106. uint32_t work_ha_copy;
  7107. unsigned long status;
  7108. unsigned long iflag;
  7109. uint32_t control;
  7110. MAILBOX_t *mbox, *pmbox;
  7111. struct lpfc_vport *vport;
  7112. struct lpfc_nodelist *ndlp;
  7113. struct lpfc_dmabuf *mp;
  7114. LPFC_MBOXQ_t *pmb;
  7115. int rc;
  7116. /*
  7117. * Get the driver's phba structure from the dev_id and
  7118. * assume the HBA is not interrupting.
  7119. */
  7120. phba = (struct lpfc_hba *)dev_id;
  7121. if (unlikely(!phba))
  7122. return IRQ_NONE;
  7123. /*
  7124. * Stuff needs to be attented to when this function is invoked as an
  7125. * individual interrupt handler in MSI-X multi-message interrupt mode
  7126. */
  7127. if (phba->intr_type == MSIX) {
  7128. /* Check device state for handling interrupt */
  7129. if (lpfc_intr_state_check(phba))
  7130. return IRQ_NONE;
  7131. /* Need to read HA REG for slow-path events */
  7132. spin_lock_irqsave(&phba->hbalock, iflag);
  7133. ha_copy = readl(phba->HAregaddr);
  7134. /* If somebody is waiting to handle an eratt don't process it
  7135. * here. The brdkill function will do this.
  7136. */
  7137. if (phba->link_flag & LS_IGNORE_ERATT)
  7138. ha_copy &= ~HA_ERATT;
  7139. /* Check the need for handling ERATT in interrupt handler */
  7140. if (ha_copy & HA_ERATT) {
  7141. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7142. /* ERATT polling has handled ERATT */
  7143. ha_copy &= ~HA_ERATT;
  7144. else
  7145. /* Indicate interrupt handler handles ERATT */
  7146. phba->hba_flag |= HBA_ERATT_HANDLED;
  7147. }
  7148. /*
  7149. * If there is deferred error attention, do not check for any
  7150. * interrupt.
  7151. */
  7152. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7153. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7154. return IRQ_NONE;
  7155. }
  7156. /* Clear up only attention source related to slow-path */
  7157. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7158. phba->HAregaddr);
  7159. readl(phba->HAregaddr); /* flush */
  7160. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7161. } else
  7162. ha_copy = phba->ha_copy;
  7163. work_ha_copy = ha_copy & phba->work_ha_mask;
  7164. if (work_ha_copy) {
  7165. if (work_ha_copy & HA_LATT) {
  7166. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7167. /*
  7168. * Turn off Link Attention interrupts
  7169. * until CLEAR_LA done
  7170. */
  7171. spin_lock_irqsave(&phba->hbalock, iflag);
  7172. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7173. control = readl(phba->HCregaddr);
  7174. control &= ~HC_LAINT_ENA;
  7175. writel(control, phba->HCregaddr);
  7176. readl(phba->HCregaddr); /* flush */
  7177. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7178. }
  7179. else
  7180. work_ha_copy &= ~HA_LATT;
  7181. }
  7182. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7183. /*
  7184. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7185. * the only slow ring.
  7186. */
  7187. status = (work_ha_copy &
  7188. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7189. status >>= (4*LPFC_ELS_RING);
  7190. if (status & HA_RXMASK) {
  7191. spin_lock_irqsave(&phba->hbalock, iflag);
  7192. control = readl(phba->HCregaddr);
  7193. lpfc_debugfs_slow_ring_trc(phba,
  7194. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7195. control, status,
  7196. (uint32_t)phba->sli.slistat.sli_intr);
  7197. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7198. lpfc_debugfs_slow_ring_trc(phba,
  7199. "ISR Disable ring:"
  7200. "pwork:x%x hawork:x%x wait:x%x",
  7201. phba->work_ha, work_ha_copy,
  7202. (uint32_t)((unsigned long)
  7203. &phba->work_waitq));
  7204. control &=
  7205. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7206. writel(control, phba->HCregaddr);
  7207. readl(phba->HCregaddr); /* flush */
  7208. }
  7209. else {
  7210. lpfc_debugfs_slow_ring_trc(phba,
  7211. "ISR slow ring: pwork:"
  7212. "x%x hawork:x%x wait:x%x",
  7213. phba->work_ha, work_ha_copy,
  7214. (uint32_t)((unsigned long)
  7215. &phba->work_waitq));
  7216. }
  7217. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7218. }
  7219. }
  7220. spin_lock_irqsave(&phba->hbalock, iflag);
  7221. if (work_ha_copy & HA_ERATT) {
  7222. lpfc_sli_read_hs(phba);
  7223. /*
  7224. * Check if there is a deferred error condition
  7225. * is active
  7226. */
  7227. if ((HS_FFER1 & phba->work_hs) &&
  7228. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7229. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7230. phba->hba_flag |= DEFER_ERATT;
  7231. /* Clear all interrupt enable conditions */
  7232. writel(0, phba->HCregaddr);
  7233. readl(phba->HCregaddr);
  7234. }
  7235. }
  7236. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7237. pmb = phba->sli.mbox_active;
  7238. pmbox = &pmb->u.mb;
  7239. mbox = phba->mbox;
  7240. vport = pmb->vport;
  7241. /* First check out the status word */
  7242. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7243. if (pmbox->mbxOwner != OWN_HOST) {
  7244. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7245. /*
  7246. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7247. * mbxStatus <status>
  7248. */
  7249. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7250. LOG_SLI,
  7251. "(%d):0304 Stray Mailbox "
  7252. "Interrupt mbxCommand x%x "
  7253. "mbxStatus x%x\n",
  7254. (vport ? vport->vpi : 0),
  7255. pmbox->mbxCommand,
  7256. pmbox->mbxStatus);
  7257. /* clear mailbox attention bit */
  7258. work_ha_copy &= ~HA_MBATT;
  7259. } else {
  7260. phba->sli.mbox_active = NULL;
  7261. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7262. phba->last_completion_time = jiffies;
  7263. del_timer(&phba->sli.mbox_tmo);
  7264. if (pmb->mbox_cmpl) {
  7265. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7266. MAILBOX_CMD_SIZE);
  7267. }
  7268. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7269. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7270. lpfc_debugfs_disc_trc(vport,
  7271. LPFC_DISC_TRC_MBOX_VPORT,
  7272. "MBOX dflt rpi: : "
  7273. "status:x%x rpi:x%x",
  7274. (uint32_t)pmbox->mbxStatus,
  7275. pmbox->un.varWords[0], 0);
  7276. if (!pmbox->mbxStatus) {
  7277. mp = (struct lpfc_dmabuf *)
  7278. (pmb->context1);
  7279. ndlp = (struct lpfc_nodelist *)
  7280. pmb->context2;
  7281. /* Reg_LOGIN of dflt RPI was
  7282. * successful. new lets get
  7283. * rid of the RPI using the
  7284. * same mbox buffer.
  7285. */
  7286. lpfc_unreg_login(phba,
  7287. vport->vpi,
  7288. pmbox->un.varWords[0],
  7289. pmb);
  7290. pmb->mbox_cmpl =
  7291. lpfc_mbx_cmpl_dflt_rpi;
  7292. pmb->context1 = mp;
  7293. pmb->context2 = ndlp;
  7294. pmb->vport = vport;
  7295. rc = lpfc_sli_issue_mbox(phba,
  7296. pmb,
  7297. MBX_NOWAIT);
  7298. if (rc != MBX_BUSY)
  7299. lpfc_printf_log(phba,
  7300. KERN_ERR,
  7301. LOG_MBOX | LOG_SLI,
  7302. "0350 rc should have"
  7303. "been MBX_BUSY");
  7304. if (rc != MBX_NOT_FINISHED)
  7305. goto send_current_mbox;
  7306. }
  7307. }
  7308. spin_lock_irqsave(
  7309. &phba->pport->work_port_lock,
  7310. iflag);
  7311. phba->pport->work_port_events &=
  7312. ~WORKER_MBOX_TMO;
  7313. spin_unlock_irqrestore(
  7314. &phba->pport->work_port_lock,
  7315. iflag);
  7316. lpfc_mbox_cmpl_put(phba, pmb);
  7317. }
  7318. } else
  7319. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7320. if ((work_ha_copy & HA_MBATT) &&
  7321. (phba->sli.mbox_active == NULL)) {
  7322. send_current_mbox:
  7323. /* Process next mailbox command if there is one */
  7324. do {
  7325. rc = lpfc_sli_issue_mbox(phba, NULL,
  7326. MBX_NOWAIT);
  7327. } while (rc == MBX_NOT_FINISHED);
  7328. if (rc != MBX_SUCCESS)
  7329. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7330. LOG_SLI, "0349 rc should be "
  7331. "MBX_SUCCESS");
  7332. }
  7333. spin_lock_irqsave(&phba->hbalock, iflag);
  7334. phba->work_ha |= work_ha_copy;
  7335. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7336. lpfc_worker_wake_up(phba);
  7337. }
  7338. return IRQ_HANDLED;
  7339. } /* lpfc_sli_sp_intr_handler */
  7340. /**
  7341. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7342. * @irq: Interrupt number.
  7343. * @dev_id: The device context pointer.
  7344. *
  7345. * This function is directly called from the PCI layer as an interrupt
  7346. * service routine when device with SLI-3 interface spec is enabled with
  7347. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7348. * ring event in the HBA. However, when the device is enabled with either
  7349. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7350. * device-level interrupt handler. When the PCI slot is in error recovery
  7351. * or the HBA is undergoing initialization, the interrupt handler will not
  7352. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7353. * the intrrupt context. This function is called without any lock held.
  7354. * It gets the hbalock to access and update SLI data structures.
  7355. *
  7356. * This function returns IRQ_HANDLED when interrupt is handled else it
  7357. * returns IRQ_NONE.
  7358. **/
  7359. irqreturn_t
  7360. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7361. {
  7362. struct lpfc_hba *phba;
  7363. uint32_t ha_copy;
  7364. unsigned long status;
  7365. unsigned long iflag;
  7366. /* Get the driver's phba structure from the dev_id and
  7367. * assume the HBA is not interrupting.
  7368. */
  7369. phba = (struct lpfc_hba *) dev_id;
  7370. if (unlikely(!phba))
  7371. return IRQ_NONE;
  7372. /*
  7373. * Stuff needs to be attented to when this function is invoked as an
  7374. * individual interrupt handler in MSI-X multi-message interrupt mode
  7375. */
  7376. if (phba->intr_type == MSIX) {
  7377. /* Check device state for handling interrupt */
  7378. if (lpfc_intr_state_check(phba))
  7379. return IRQ_NONE;
  7380. /* Need to read HA REG for FCP ring and other ring events */
  7381. ha_copy = readl(phba->HAregaddr);
  7382. /* Clear up only attention source related to fast-path */
  7383. spin_lock_irqsave(&phba->hbalock, iflag);
  7384. /*
  7385. * If there is deferred error attention, do not check for
  7386. * any interrupt.
  7387. */
  7388. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7389. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7390. return IRQ_NONE;
  7391. }
  7392. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7393. phba->HAregaddr);
  7394. readl(phba->HAregaddr); /* flush */
  7395. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7396. } else
  7397. ha_copy = phba->ha_copy;
  7398. /*
  7399. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7400. */
  7401. ha_copy &= ~(phba->work_ha_mask);
  7402. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7403. status >>= (4*LPFC_FCP_RING);
  7404. if (status & HA_RXMASK)
  7405. lpfc_sli_handle_fast_ring_event(phba,
  7406. &phba->sli.ring[LPFC_FCP_RING],
  7407. status);
  7408. if (phba->cfg_multi_ring_support == 2) {
  7409. /*
  7410. * Process all events on extra ring. Take the optimized path
  7411. * for extra ring IO.
  7412. */
  7413. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7414. status >>= (4*LPFC_EXTRA_RING);
  7415. if (status & HA_RXMASK) {
  7416. lpfc_sli_handle_fast_ring_event(phba,
  7417. &phba->sli.ring[LPFC_EXTRA_RING],
  7418. status);
  7419. }
  7420. }
  7421. return IRQ_HANDLED;
  7422. } /* lpfc_sli_fp_intr_handler */
  7423. /**
  7424. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7425. * @irq: Interrupt number.
  7426. * @dev_id: The device context pointer.
  7427. *
  7428. * This function is the HBA device-level interrupt handler to device with
  7429. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7430. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7431. * requires driver attention. This function invokes the slow-path interrupt
  7432. * attention handling function and fast-path interrupt attention handling
  7433. * function in turn to process the relevant HBA attention events. This
  7434. * function is called without any lock held. It gets the hbalock to access
  7435. * and update SLI data structures.
  7436. *
  7437. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7438. * returns IRQ_NONE.
  7439. **/
  7440. irqreturn_t
  7441. lpfc_sli_intr_handler(int irq, void *dev_id)
  7442. {
  7443. struct lpfc_hba *phba;
  7444. irqreturn_t sp_irq_rc, fp_irq_rc;
  7445. unsigned long status1, status2;
  7446. /*
  7447. * Get the driver's phba structure from the dev_id and
  7448. * assume the HBA is not interrupting.
  7449. */
  7450. phba = (struct lpfc_hba *) dev_id;
  7451. if (unlikely(!phba))
  7452. return IRQ_NONE;
  7453. /* Check device state for handling interrupt */
  7454. if (lpfc_intr_state_check(phba))
  7455. return IRQ_NONE;
  7456. spin_lock(&phba->hbalock);
  7457. phba->ha_copy = readl(phba->HAregaddr);
  7458. if (unlikely(!phba->ha_copy)) {
  7459. spin_unlock(&phba->hbalock);
  7460. return IRQ_NONE;
  7461. } else if (phba->ha_copy & HA_ERATT) {
  7462. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7463. /* ERATT polling has handled ERATT */
  7464. phba->ha_copy &= ~HA_ERATT;
  7465. else
  7466. /* Indicate interrupt handler handles ERATT */
  7467. phba->hba_flag |= HBA_ERATT_HANDLED;
  7468. }
  7469. /*
  7470. * If there is deferred error attention, do not check for any interrupt.
  7471. */
  7472. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7473. spin_unlock_irq(&phba->hbalock);
  7474. return IRQ_NONE;
  7475. }
  7476. /* Clear attention sources except link and error attentions */
  7477. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7478. readl(phba->HAregaddr); /* flush */
  7479. spin_unlock(&phba->hbalock);
  7480. /*
  7481. * Invokes slow-path host attention interrupt handling as appropriate.
  7482. */
  7483. /* status of events with mailbox and link attention */
  7484. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7485. /* status of events with ELS ring */
  7486. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7487. status2 >>= (4*LPFC_ELS_RING);
  7488. if (status1 || (status2 & HA_RXMASK))
  7489. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7490. else
  7491. sp_irq_rc = IRQ_NONE;
  7492. /*
  7493. * Invoke fast-path host attention interrupt handling as appropriate.
  7494. */
  7495. /* status of events with FCP ring */
  7496. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7497. status1 >>= (4*LPFC_FCP_RING);
  7498. /* status of events with extra ring */
  7499. if (phba->cfg_multi_ring_support == 2) {
  7500. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7501. status2 >>= (4*LPFC_EXTRA_RING);
  7502. } else
  7503. status2 = 0;
  7504. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7505. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7506. else
  7507. fp_irq_rc = IRQ_NONE;
  7508. /* Return device-level interrupt handling status */
  7509. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7510. } /* lpfc_sli_intr_handler */
  7511. /**
  7512. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7513. * @phba: pointer to lpfc hba data structure.
  7514. *
  7515. * This routine is invoked by the worker thread to process all the pending
  7516. * SLI4 FCP abort XRI events.
  7517. **/
  7518. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7519. {
  7520. struct lpfc_cq_event *cq_event;
  7521. /* First, declare the fcp xri abort event has been handled */
  7522. spin_lock_irq(&phba->hbalock);
  7523. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7524. spin_unlock_irq(&phba->hbalock);
  7525. /* Now, handle all the fcp xri abort events */
  7526. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7527. /* Get the first event from the head of the event queue */
  7528. spin_lock_irq(&phba->hbalock);
  7529. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7530. cq_event, struct lpfc_cq_event, list);
  7531. spin_unlock_irq(&phba->hbalock);
  7532. /* Notify aborted XRI for FCP work queue */
  7533. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7534. /* Free the event processed back to the free pool */
  7535. lpfc_sli4_cq_event_release(phba, cq_event);
  7536. }
  7537. }
  7538. /**
  7539. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7540. * @phba: pointer to lpfc hba data structure.
  7541. *
  7542. * This routine is invoked by the worker thread to process all the pending
  7543. * SLI4 els abort xri events.
  7544. **/
  7545. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7546. {
  7547. struct lpfc_cq_event *cq_event;
  7548. /* First, declare the els xri abort event has been handled */
  7549. spin_lock_irq(&phba->hbalock);
  7550. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7551. spin_unlock_irq(&phba->hbalock);
  7552. /* Now, handle all the els xri abort events */
  7553. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7554. /* Get the first event from the head of the event queue */
  7555. spin_lock_irq(&phba->hbalock);
  7556. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7557. cq_event, struct lpfc_cq_event, list);
  7558. spin_unlock_irq(&phba->hbalock);
  7559. /* Notify aborted XRI for ELS work queue */
  7560. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7561. /* Free the event processed back to the free pool */
  7562. lpfc_sli4_cq_event_release(phba, cq_event);
  7563. }
  7564. }
  7565. static void
  7566. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7567. struct lpfc_iocbq *pIocbOut,
  7568. struct lpfc_wcqe_complete *wcqe)
  7569. {
  7570. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7571. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7572. sizeof(struct lpfc_iocbq) - offset);
  7573. pIocbIn->cq_event.cqe.wcqe_cmpl = *wcqe;
  7574. /* Map WCQE parameters into irspiocb parameters */
  7575. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7576. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7577. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7578. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7579. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7580. wcqe->total_data_placed;
  7581. else
  7582. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7583. else
  7584. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7585. }
  7586. /**
  7587. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7588. * @phba: Pointer to HBA context object.
  7589. * @cqe: Pointer to mailbox completion queue entry.
  7590. *
  7591. * This routine process a mailbox completion queue entry with asynchrous
  7592. * event.
  7593. *
  7594. * Return: true if work posted to worker thread, otherwise false.
  7595. **/
  7596. static bool
  7597. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7598. {
  7599. struct lpfc_cq_event *cq_event;
  7600. unsigned long iflags;
  7601. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7602. "0392 Async Event: word0:x%x, word1:x%x, "
  7603. "word2:x%x, word3:x%x\n", mcqe->word0,
  7604. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7605. /* Allocate a new internal CQ_EVENT entry */
  7606. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7607. if (!cq_event) {
  7608. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7609. "0394 Failed to allocate CQ_EVENT entry\n");
  7610. return false;
  7611. }
  7612. /* Move the CQE into an asynchronous event entry */
  7613. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7614. spin_lock_irqsave(&phba->hbalock, iflags);
  7615. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7616. /* Set the async event flag */
  7617. phba->hba_flag |= ASYNC_EVENT;
  7618. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7619. return true;
  7620. }
  7621. /**
  7622. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7623. * @phba: Pointer to HBA context object.
  7624. * @cqe: Pointer to mailbox completion queue entry.
  7625. *
  7626. * This routine process a mailbox completion queue entry with mailbox
  7627. * completion event.
  7628. *
  7629. * Return: true if work posted to worker thread, otherwise false.
  7630. **/
  7631. static bool
  7632. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7633. {
  7634. uint32_t mcqe_status;
  7635. MAILBOX_t *mbox, *pmbox;
  7636. struct lpfc_mqe *mqe;
  7637. struct lpfc_vport *vport;
  7638. struct lpfc_nodelist *ndlp;
  7639. struct lpfc_dmabuf *mp;
  7640. unsigned long iflags;
  7641. LPFC_MBOXQ_t *pmb;
  7642. bool workposted = false;
  7643. int rc;
  7644. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7645. if (!bf_get(lpfc_trailer_completed, mcqe))
  7646. goto out_no_mqe_complete;
  7647. /* Get the reference to the active mbox command */
  7648. spin_lock_irqsave(&phba->hbalock, iflags);
  7649. pmb = phba->sli.mbox_active;
  7650. if (unlikely(!pmb)) {
  7651. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7652. "1832 No pending MBOX command to handle\n");
  7653. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7654. goto out_no_mqe_complete;
  7655. }
  7656. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7657. mqe = &pmb->u.mqe;
  7658. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7659. mbox = phba->mbox;
  7660. vport = pmb->vport;
  7661. /* Reset heartbeat timer */
  7662. phba->last_completion_time = jiffies;
  7663. del_timer(&phba->sli.mbox_tmo);
  7664. /* Move mbox data to caller's mailbox region, do endian swapping */
  7665. if (pmb->mbox_cmpl && mbox)
  7666. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7667. /* Set the mailbox status with SLI4 range 0x4000 */
  7668. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7669. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7670. bf_set(lpfc_mqe_status, mqe,
  7671. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7672. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7673. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7674. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7675. "MBOX dflt rpi: status:x%x rpi:x%x",
  7676. mcqe_status,
  7677. pmbox->un.varWords[0], 0);
  7678. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7679. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7680. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7681. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7682. * RID of the PPI using the same mbox buffer.
  7683. */
  7684. lpfc_unreg_login(phba, vport->vpi,
  7685. pmbox->un.varWords[0], pmb);
  7686. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7687. pmb->context1 = mp;
  7688. pmb->context2 = ndlp;
  7689. pmb->vport = vport;
  7690. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7691. if (rc != MBX_BUSY)
  7692. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7693. LOG_SLI, "0385 rc should "
  7694. "have been MBX_BUSY\n");
  7695. if (rc != MBX_NOT_FINISHED)
  7696. goto send_current_mbox;
  7697. }
  7698. }
  7699. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7700. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7701. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7702. /* There is mailbox completion work to do */
  7703. spin_lock_irqsave(&phba->hbalock, iflags);
  7704. __lpfc_mbox_cmpl_put(phba, pmb);
  7705. phba->work_ha |= HA_MBATT;
  7706. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7707. workposted = true;
  7708. send_current_mbox:
  7709. spin_lock_irqsave(&phba->hbalock, iflags);
  7710. /* Release the mailbox command posting token */
  7711. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7712. /* Setting active mailbox pointer need to be in sync to flag clear */
  7713. phba->sli.mbox_active = NULL;
  7714. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7715. /* Wake up worker thread to post the next pending mailbox command */
  7716. lpfc_worker_wake_up(phba);
  7717. out_no_mqe_complete:
  7718. if (bf_get(lpfc_trailer_consumed, mcqe))
  7719. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7720. return workposted;
  7721. }
  7722. /**
  7723. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7724. * @phba: Pointer to HBA context object.
  7725. * @cqe: Pointer to mailbox completion queue entry.
  7726. *
  7727. * This routine process a mailbox completion queue entry, it invokes the
  7728. * proper mailbox complete handling or asynchrous event handling routine
  7729. * according to the MCQE's async bit.
  7730. *
  7731. * Return: true if work posted to worker thread, otherwise false.
  7732. **/
  7733. static bool
  7734. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7735. {
  7736. struct lpfc_mcqe mcqe;
  7737. bool workposted;
  7738. /* Copy the mailbox MCQE and convert endian order as needed */
  7739. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7740. /* Invoke the proper event handling routine */
  7741. if (!bf_get(lpfc_trailer_async, &mcqe))
  7742. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7743. else
  7744. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7745. return workposted;
  7746. }
  7747. /**
  7748. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7749. * @phba: Pointer to HBA context object.
  7750. * @wcqe: Pointer to work-queue completion queue entry.
  7751. *
  7752. * This routine handles an ELS work-queue completion event.
  7753. *
  7754. * Return: true if work posted to worker thread, otherwise false.
  7755. **/
  7756. static bool
  7757. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7758. struct lpfc_wcqe_complete *wcqe)
  7759. {
  7760. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7761. struct lpfc_iocbq *cmdiocbq;
  7762. struct lpfc_iocbq *irspiocbq;
  7763. unsigned long iflags;
  7764. bool workposted = false;
  7765. spin_lock_irqsave(&phba->hbalock, iflags);
  7766. pring->stats.iocb_event++;
  7767. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7768. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7769. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7770. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7771. if (unlikely(!cmdiocbq)) {
  7772. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7773. "0386 ELS complete with no corresponding "
  7774. "cmdiocb: iotag (%d)\n",
  7775. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7776. return workposted;
  7777. }
  7778. /* Fake the irspiocbq and copy necessary response information */
  7779. irspiocbq = lpfc_sli_get_iocbq(phba);
  7780. if (!irspiocbq) {
  7781. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7782. "0387 Failed to allocate an iocbq\n");
  7783. return workposted;
  7784. }
  7785. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7786. /* Add the irspiocb to the response IOCB work list */
  7787. spin_lock_irqsave(&phba->hbalock, iflags);
  7788. list_add_tail(&irspiocbq->cq_event.list,
  7789. &phba->sli4_hba.sp_rspiocb_work_queue);
  7790. /* Indicate ELS ring attention */
  7791. phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING));
  7792. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7793. workposted = true;
  7794. return workposted;
  7795. }
  7796. /**
  7797. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7798. * @phba: Pointer to HBA context object.
  7799. * @wcqe: Pointer to work-queue completion queue entry.
  7800. *
  7801. * This routine handles slow-path WQ entry comsumed event by invoking the
  7802. * proper WQ release routine to the slow-path WQ.
  7803. **/
  7804. static void
  7805. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7806. struct lpfc_wcqe_release *wcqe)
  7807. {
  7808. /* Check for the slow-path ELS work queue */
  7809. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7810. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7811. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7812. else
  7813. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7814. "2579 Slow-path wqe consume event carries "
  7815. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7816. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7817. phba->sli4_hba.els_wq->queue_id);
  7818. }
  7819. /**
  7820. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7821. * @phba: Pointer to HBA context object.
  7822. * @cq: Pointer to a WQ completion queue.
  7823. * @wcqe: Pointer to work-queue completion queue entry.
  7824. *
  7825. * This routine handles an XRI abort event.
  7826. *
  7827. * Return: true if work posted to worker thread, otherwise false.
  7828. **/
  7829. static bool
  7830. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7831. struct lpfc_queue *cq,
  7832. struct sli4_wcqe_xri_aborted *wcqe)
  7833. {
  7834. bool workposted = false;
  7835. struct lpfc_cq_event *cq_event;
  7836. unsigned long iflags;
  7837. /* Allocate a new internal CQ_EVENT entry */
  7838. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7839. if (!cq_event) {
  7840. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7841. "0602 Failed to allocate CQ_EVENT entry\n");
  7842. return false;
  7843. }
  7844. /* Move the CQE into the proper xri abort event list */
  7845. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7846. switch (cq->subtype) {
  7847. case LPFC_FCP:
  7848. spin_lock_irqsave(&phba->hbalock, iflags);
  7849. list_add_tail(&cq_event->list,
  7850. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7851. /* Set the fcp xri abort event flag */
  7852. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7853. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7854. workposted = true;
  7855. break;
  7856. case LPFC_ELS:
  7857. spin_lock_irqsave(&phba->hbalock, iflags);
  7858. list_add_tail(&cq_event->list,
  7859. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7860. /* Set the els xri abort event flag */
  7861. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7862. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7863. workposted = true;
  7864. break;
  7865. default:
  7866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7867. "0603 Invalid work queue CQE subtype (x%x)\n",
  7868. cq->subtype);
  7869. workposted = false;
  7870. break;
  7871. }
  7872. return workposted;
  7873. }
  7874. /**
  7875. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7876. * @phba: Pointer to HBA context object.
  7877. * @rcqe: Pointer to receive-queue completion queue entry.
  7878. *
  7879. * This routine process a receive-queue completion queue entry.
  7880. *
  7881. * Return: true if work posted to worker thread, otherwise false.
  7882. **/
  7883. static bool
  7884. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  7885. {
  7886. bool workposted = false;
  7887. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7888. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7889. struct hbq_dmabuf *dma_buf;
  7890. uint32_t status;
  7891. unsigned long iflags;
  7892. lpfc_sli4_rq_release(hrq, drq);
  7893. if (bf_get(lpfc_rcqe_code, rcqe) != CQE_CODE_RECEIVE)
  7894. goto out;
  7895. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  7896. goto out;
  7897. status = bf_get(lpfc_rcqe_status, rcqe);
  7898. switch (status) {
  7899. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  7900. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7901. "2537 Receive Frame Truncated!!\n");
  7902. case FC_STATUS_RQ_SUCCESS:
  7903. spin_lock_irqsave(&phba->hbalock, iflags);
  7904. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7905. if (!dma_buf) {
  7906. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7907. goto out;
  7908. }
  7909. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  7910. /* save off the frame for the word thread to process */
  7911. list_add_tail(&dma_buf->cq_event.list,
  7912. &phba->sli4_hba.sp_rspiocb_work_queue);
  7913. /* Frame received */
  7914. phba->hba_flag |= HBA_RECEIVE_BUFFER;
  7915. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7916. workposted = true;
  7917. break;
  7918. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7919. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7920. /* Post more buffers if possible */
  7921. spin_lock_irqsave(&phba->hbalock, iflags);
  7922. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7923. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7924. workposted = true;
  7925. break;
  7926. }
  7927. out:
  7928. return workposted;
  7929. }
  7930. /**
  7931. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  7932. * @phba: Pointer to HBA context object.
  7933. * @cq: Pointer to the completion queue.
  7934. * @wcqe: Pointer to a completion queue entry.
  7935. *
  7936. * This routine process a slow-path work-queue or recieve queue completion queue
  7937. * entry.
  7938. *
  7939. * Return: true if work posted to worker thread, otherwise false.
  7940. **/
  7941. static bool
  7942. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7943. struct lpfc_cqe *cqe)
  7944. {
  7945. struct lpfc_wcqe_complete wcqe;
  7946. bool workposted = false;
  7947. /* Copy the work queue CQE and convert endian order if needed */
  7948. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  7949. /* Check and process for different type of WCQE and dispatch */
  7950. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  7951. case CQE_CODE_COMPL_WQE:
  7952. /* Process the WQ complete event */
  7953. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7954. (struct lpfc_wcqe_complete *)&wcqe);
  7955. break;
  7956. case CQE_CODE_RELEASE_WQE:
  7957. /* Process the WQ release event */
  7958. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7959. (struct lpfc_wcqe_release *)&wcqe);
  7960. break;
  7961. case CQE_CODE_XRI_ABORTED:
  7962. /* Process the WQ XRI abort event */
  7963. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7964. (struct sli4_wcqe_xri_aborted *)&wcqe);
  7965. break;
  7966. case CQE_CODE_RECEIVE:
  7967. /* Process the RQ event */
  7968. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  7969. (struct lpfc_rcqe *)&wcqe);
  7970. break;
  7971. default:
  7972. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7973. "0388 Not a valid WCQE code: x%x\n",
  7974. bf_get(lpfc_wcqe_c_code, &wcqe));
  7975. break;
  7976. }
  7977. return workposted;
  7978. }
  7979. /**
  7980. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  7981. * @phba: Pointer to HBA context object.
  7982. * @eqe: Pointer to fast-path event queue entry.
  7983. *
  7984. * This routine process a event queue entry from the slow-path event queue.
  7985. * It will check the MajorCode and MinorCode to determine this is for a
  7986. * completion event on a completion queue, if not, an error shall be logged
  7987. * and just return. Otherwise, it will get to the corresponding completion
  7988. * queue and process all the entries on that completion queue, rearm the
  7989. * completion queue, and then return.
  7990. *
  7991. **/
  7992. static void
  7993. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  7994. {
  7995. struct lpfc_queue *cq = NULL, *childq, *speq;
  7996. struct lpfc_cqe *cqe;
  7997. bool workposted = false;
  7998. int ecount = 0;
  7999. uint16_t cqid;
  8000. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  8001. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  8002. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8003. "0359 Not a valid slow-path completion "
  8004. "event: majorcode=x%x, minorcode=x%x\n",
  8005. bf_get(lpfc_eqe_major_code, eqe),
  8006. bf_get(lpfc_eqe_minor_code, eqe));
  8007. return;
  8008. }
  8009. /* Get the reference to the corresponding CQ */
  8010. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8011. /* Search for completion queue pointer matching this cqid */
  8012. speq = phba->sli4_hba.sp_eq;
  8013. list_for_each_entry(childq, &speq->child_list, list) {
  8014. if (childq->queue_id == cqid) {
  8015. cq = childq;
  8016. break;
  8017. }
  8018. }
  8019. if (unlikely(!cq)) {
  8020. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8021. "0365 Slow-path CQ identifier (%d) does "
  8022. "not exist\n", cqid);
  8023. return;
  8024. }
  8025. /* Process all the entries to the CQ */
  8026. switch (cq->type) {
  8027. case LPFC_MCQ:
  8028. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8029. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8030. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8031. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8032. }
  8033. break;
  8034. case LPFC_WCQ:
  8035. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8036. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8037. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8038. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8039. }
  8040. break;
  8041. default:
  8042. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8043. "0370 Invalid completion queue type (%d)\n",
  8044. cq->type);
  8045. return;
  8046. }
  8047. /* Catch the no cq entry condition, log an error */
  8048. if (unlikely(ecount == 0))
  8049. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8050. "0371 No entry from the CQ: identifier "
  8051. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8052. /* In any case, flash and re-arm the RCQ */
  8053. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8054. /* wake up worker thread if there are works to be done */
  8055. if (workposted)
  8056. lpfc_worker_wake_up(phba);
  8057. }
  8058. /**
  8059. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8060. * @eqe: Pointer to fast-path completion queue entry.
  8061. *
  8062. * This routine process a fast-path work queue completion entry from fast-path
  8063. * event queue for FCP command response completion.
  8064. **/
  8065. static void
  8066. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8067. struct lpfc_wcqe_complete *wcqe)
  8068. {
  8069. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8070. struct lpfc_iocbq *cmdiocbq;
  8071. struct lpfc_iocbq irspiocbq;
  8072. unsigned long iflags;
  8073. spin_lock_irqsave(&phba->hbalock, iflags);
  8074. pring->stats.iocb_event++;
  8075. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8076. /* Check for response status */
  8077. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8078. /* If resource errors reported from HBA, reduce queue
  8079. * depth of the SCSI device.
  8080. */
  8081. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8082. IOSTAT_LOCAL_REJECT) &&
  8083. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8084. phba->lpfc_rampdown_queue_depth(phba);
  8085. }
  8086. /* Log the error status */
  8087. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8088. "0373 FCP complete error: status=x%x, "
  8089. "hw_status=x%x, total_data_specified=%d, "
  8090. "parameter=x%x, word3=x%x\n",
  8091. bf_get(lpfc_wcqe_c_status, wcqe),
  8092. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8093. wcqe->total_data_placed, wcqe->parameter,
  8094. wcqe->word3);
  8095. }
  8096. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8097. spin_lock_irqsave(&phba->hbalock, iflags);
  8098. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8099. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8100. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8101. if (unlikely(!cmdiocbq)) {
  8102. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8103. "0374 FCP complete with no corresponding "
  8104. "cmdiocb: iotag (%d)\n",
  8105. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8106. return;
  8107. }
  8108. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8109. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8110. "0375 FCP cmdiocb not callback function "
  8111. "iotag: (%d)\n",
  8112. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8113. return;
  8114. }
  8115. /* Fake the irspiocb and copy necessary response information */
  8116. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  8117. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8118. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8119. }
  8120. /**
  8121. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8122. * @phba: Pointer to HBA context object.
  8123. * @cq: Pointer to completion queue.
  8124. * @wcqe: Pointer to work-queue completion queue entry.
  8125. *
  8126. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8127. * proper WQ release routine to the slow-path WQ.
  8128. **/
  8129. static void
  8130. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8131. struct lpfc_wcqe_release *wcqe)
  8132. {
  8133. struct lpfc_queue *childwq;
  8134. bool wqid_matched = false;
  8135. uint16_t fcp_wqid;
  8136. /* Check for fast-path FCP work queue release */
  8137. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8138. list_for_each_entry(childwq, &cq->child_list, list) {
  8139. if (childwq->queue_id == fcp_wqid) {
  8140. lpfc_sli4_wq_release(childwq,
  8141. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8142. wqid_matched = true;
  8143. break;
  8144. }
  8145. }
  8146. /* Report warning log message if no match found */
  8147. if (wqid_matched != true)
  8148. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8149. "2580 Fast-path wqe consume event carries "
  8150. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8151. }
  8152. /**
  8153. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8154. * @cq: Pointer to the completion queue.
  8155. * @eqe: Pointer to fast-path completion queue entry.
  8156. *
  8157. * This routine process a fast-path work queue completion entry from fast-path
  8158. * event queue for FCP command response completion.
  8159. **/
  8160. static int
  8161. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8162. struct lpfc_cqe *cqe)
  8163. {
  8164. struct lpfc_wcqe_release wcqe;
  8165. bool workposted = false;
  8166. /* Copy the work queue CQE and convert endian order if needed */
  8167. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8168. /* Check and process for different type of WCQE and dispatch */
  8169. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8170. case CQE_CODE_COMPL_WQE:
  8171. /* Process the WQ complete event */
  8172. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8173. (struct lpfc_wcqe_complete *)&wcqe);
  8174. break;
  8175. case CQE_CODE_RELEASE_WQE:
  8176. /* Process the WQ release event */
  8177. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8178. (struct lpfc_wcqe_release *)&wcqe);
  8179. break;
  8180. case CQE_CODE_XRI_ABORTED:
  8181. /* Process the WQ XRI abort event */
  8182. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8183. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8184. break;
  8185. default:
  8186. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8187. "0144 Not a valid WCQE code: x%x\n",
  8188. bf_get(lpfc_wcqe_c_code, &wcqe));
  8189. break;
  8190. }
  8191. return workposted;
  8192. }
  8193. /**
  8194. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8195. * @phba: Pointer to HBA context object.
  8196. * @eqe: Pointer to fast-path event queue entry.
  8197. *
  8198. * This routine process a event queue entry from the fast-path event queue.
  8199. * It will check the MajorCode and MinorCode to determine this is for a
  8200. * completion event on a completion queue, if not, an error shall be logged
  8201. * and just return. Otherwise, it will get to the corresponding completion
  8202. * queue and process all the entries on the completion queue, rearm the
  8203. * completion queue, and then return.
  8204. **/
  8205. static void
  8206. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8207. uint32_t fcp_cqidx)
  8208. {
  8209. struct lpfc_queue *cq;
  8210. struct lpfc_cqe *cqe;
  8211. bool workposted = false;
  8212. uint16_t cqid;
  8213. int ecount = 0;
  8214. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8215. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8216. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8217. "0366 Not a valid fast-path completion "
  8218. "event: majorcode=x%x, minorcode=x%x\n",
  8219. bf_get(lpfc_eqe_major_code, eqe),
  8220. bf_get(lpfc_eqe_minor_code, eqe));
  8221. return;
  8222. }
  8223. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8224. if (unlikely(!cq)) {
  8225. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8226. "0367 Fast-path completion queue does not "
  8227. "exist\n");
  8228. return;
  8229. }
  8230. /* Get the reference to the corresponding CQ */
  8231. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8232. if (unlikely(cqid != cq->queue_id)) {
  8233. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8234. "0368 Miss-matched fast-path completion "
  8235. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8236. cqid, cq->queue_id);
  8237. return;
  8238. }
  8239. /* Process all the entries to the CQ */
  8240. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8241. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8242. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8243. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8244. }
  8245. /* Catch the no cq entry condition */
  8246. if (unlikely(ecount == 0))
  8247. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8248. "0369 No entry from fast-path completion "
  8249. "queue fcpcqid=%d\n", cq->queue_id);
  8250. /* In any case, flash and re-arm the CQ */
  8251. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8252. /* wake up worker thread if there are works to be done */
  8253. if (workposted)
  8254. lpfc_worker_wake_up(phba);
  8255. }
  8256. static void
  8257. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8258. {
  8259. struct lpfc_eqe *eqe;
  8260. /* walk all the EQ entries and drop on the floor */
  8261. while ((eqe = lpfc_sli4_eq_get(eq)))
  8262. ;
  8263. /* Clear and re-arm the EQ */
  8264. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8265. }
  8266. /**
  8267. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8268. * @irq: Interrupt number.
  8269. * @dev_id: The device context pointer.
  8270. *
  8271. * This function is directly called from the PCI layer as an interrupt
  8272. * service routine when device with SLI-4 interface spec is enabled with
  8273. * MSI-X multi-message interrupt mode and there are slow-path events in
  8274. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8275. * interrupt mode, this function is called as part of the device-level
  8276. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8277. * undergoing initialization, the interrupt handler will not process the
  8278. * interrupt. The link attention and ELS ring attention events are handled
  8279. * by the worker thread. The interrupt handler signals the worker thread
  8280. * and returns for these events. This function is called without any lock
  8281. * held. It gets the hbalock to access and update SLI data structures.
  8282. *
  8283. * This function returns IRQ_HANDLED when interrupt is handled else it
  8284. * returns IRQ_NONE.
  8285. **/
  8286. irqreturn_t
  8287. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8288. {
  8289. struct lpfc_hba *phba;
  8290. struct lpfc_queue *speq;
  8291. struct lpfc_eqe *eqe;
  8292. unsigned long iflag;
  8293. int ecount = 0;
  8294. /*
  8295. * Get the driver's phba structure from the dev_id
  8296. */
  8297. phba = (struct lpfc_hba *)dev_id;
  8298. if (unlikely(!phba))
  8299. return IRQ_NONE;
  8300. /* Get to the EQ struct associated with this vector */
  8301. speq = phba->sli4_hba.sp_eq;
  8302. /* Check device state for handling interrupt */
  8303. if (unlikely(lpfc_intr_state_check(phba))) {
  8304. /* Check again for link_state with lock held */
  8305. spin_lock_irqsave(&phba->hbalock, iflag);
  8306. if (phba->link_state < LPFC_LINK_DOWN)
  8307. /* Flush, clear interrupt, and rearm the EQ */
  8308. lpfc_sli4_eq_flush(phba, speq);
  8309. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8310. return IRQ_NONE;
  8311. }
  8312. /*
  8313. * Process all the event on FCP slow-path EQ
  8314. */
  8315. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8316. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8317. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8318. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8319. }
  8320. /* Always clear and re-arm the slow-path EQ */
  8321. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8322. /* Catch the no cq entry condition */
  8323. if (unlikely(ecount == 0)) {
  8324. if (phba->intr_type == MSIX)
  8325. /* MSI-X treated interrupt served as no EQ share INT */
  8326. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8327. "0357 MSI-X interrupt with no EQE\n");
  8328. else
  8329. /* Non MSI-X treated on interrupt as EQ share INT */
  8330. return IRQ_NONE;
  8331. }
  8332. return IRQ_HANDLED;
  8333. } /* lpfc_sli4_sp_intr_handler */
  8334. /**
  8335. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8336. * @irq: Interrupt number.
  8337. * @dev_id: The device context pointer.
  8338. *
  8339. * This function is directly called from the PCI layer as an interrupt
  8340. * service routine when device with SLI-4 interface spec is enabled with
  8341. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8342. * ring event in the HBA. However, when the device is enabled with either
  8343. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8344. * device-level interrupt handler. When the PCI slot is in error recovery
  8345. * or the HBA is undergoing initialization, the interrupt handler will not
  8346. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8347. * the intrrupt context. This function is called without any lock held.
  8348. * It gets the hbalock to access and update SLI data structures. Note that,
  8349. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8350. * equal to that of FCP CQ index.
  8351. *
  8352. * This function returns IRQ_HANDLED when interrupt is handled else it
  8353. * returns IRQ_NONE.
  8354. **/
  8355. irqreturn_t
  8356. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8357. {
  8358. struct lpfc_hba *phba;
  8359. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8360. struct lpfc_queue *fpeq;
  8361. struct lpfc_eqe *eqe;
  8362. unsigned long iflag;
  8363. int ecount = 0;
  8364. uint32_t fcp_eqidx;
  8365. /* Get the driver's phba structure from the dev_id */
  8366. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8367. phba = fcp_eq_hdl->phba;
  8368. fcp_eqidx = fcp_eq_hdl->idx;
  8369. if (unlikely(!phba))
  8370. return IRQ_NONE;
  8371. /* Get to the EQ struct associated with this vector */
  8372. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8373. /* Check device state for handling interrupt */
  8374. if (unlikely(lpfc_intr_state_check(phba))) {
  8375. /* Check again for link_state with lock held */
  8376. spin_lock_irqsave(&phba->hbalock, iflag);
  8377. if (phba->link_state < LPFC_LINK_DOWN)
  8378. /* Flush, clear interrupt, and rearm the EQ */
  8379. lpfc_sli4_eq_flush(phba, fpeq);
  8380. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8381. return IRQ_NONE;
  8382. }
  8383. /*
  8384. * Process all the event on FCP fast-path EQ
  8385. */
  8386. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8387. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8388. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8389. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8390. }
  8391. /* Always clear and re-arm the fast-path EQ */
  8392. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8393. if (unlikely(ecount == 0)) {
  8394. if (phba->intr_type == MSIX)
  8395. /* MSI-X treated interrupt served as no EQ share INT */
  8396. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8397. "0358 MSI-X interrupt with no EQE\n");
  8398. else
  8399. /* Non MSI-X treated on interrupt as EQ share INT */
  8400. return IRQ_NONE;
  8401. }
  8402. return IRQ_HANDLED;
  8403. } /* lpfc_sli4_fp_intr_handler */
  8404. /**
  8405. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8406. * @irq: Interrupt number.
  8407. * @dev_id: The device context pointer.
  8408. *
  8409. * This function is the device-level interrupt handler to device with SLI-4
  8410. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8411. * interrupt mode is enabled and there is an event in the HBA which requires
  8412. * driver attention. This function invokes the slow-path interrupt attention
  8413. * handling function and fast-path interrupt attention handling function in
  8414. * turn to process the relevant HBA attention events. This function is called
  8415. * without any lock held. It gets the hbalock to access and update SLI data
  8416. * structures.
  8417. *
  8418. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8419. * returns IRQ_NONE.
  8420. **/
  8421. irqreturn_t
  8422. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8423. {
  8424. struct lpfc_hba *phba;
  8425. irqreturn_t sp_irq_rc, fp_irq_rc;
  8426. bool fp_handled = false;
  8427. uint32_t fcp_eqidx;
  8428. /* Get the driver's phba structure from the dev_id */
  8429. phba = (struct lpfc_hba *)dev_id;
  8430. if (unlikely(!phba))
  8431. return IRQ_NONE;
  8432. /*
  8433. * Invokes slow-path host attention interrupt handling as appropriate.
  8434. */
  8435. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8436. /*
  8437. * Invoke fast-path host attention interrupt handling as appropriate.
  8438. */
  8439. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8440. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8441. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8442. if (fp_irq_rc == IRQ_HANDLED)
  8443. fp_handled |= true;
  8444. }
  8445. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8446. } /* lpfc_sli4_intr_handler */
  8447. /**
  8448. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8449. * @queue: The queue structure to free.
  8450. *
  8451. * This function frees a queue structure and the DMAable memeory used for
  8452. * the host resident queue. This function must be called after destroying the
  8453. * queue on the HBA.
  8454. **/
  8455. void
  8456. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8457. {
  8458. struct lpfc_dmabuf *dmabuf;
  8459. if (!queue)
  8460. return;
  8461. while (!list_empty(&queue->page_list)) {
  8462. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8463. list);
  8464. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8465. dmabuf->virt, dmabuf->phys);
  8466. kfree(dmabuf);
  8467. }
  8468. kfree(queue);
  8469. return;
  8470. }
  8471. /**
  8472. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8473. * @phba: The HBA that this queue is being created on.
  8474. * @entry_size: The size of each queue entry for this queue.
  8475. * @entry count: The number of entries that this queue will handle.
  8476. *
  8477. * This function allocates a queue structure and the DMAable memory used for
  8478. * the host resident queue. This function must be called before creating the
  8479. * queue on the HBA.
  8480. **/
  8481. struct lpfc_queue *
  8482. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8483. uint32_t entry_count)
  8484. {
  8485. struct lpfc_queue *queue;
  8486. struct lpfc_dmabuf *dmabuf;
  8487. int x, total_qe_count;
  8488. void *dma_pointer;
  8489. queue = kzalloc(sizeof(struct lpfc_queue) +
  8490. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8491. if (!queue)
  8492. return NULL;
  8493. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8494. INIT_LIST_HEAD(&queue->list);
  8495. INIT_LIST_HEAD(&queue->page_list);
  8496. INIT_LIST_HEAD(&queue->child_list);
  8497. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8498. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8499. if (!dmabuf)
  8500. goto out_fail;
  8501. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8502. PAGE_SIZE, &dmabuf->phys,
  8503. GFP_KERNEL);
  8504. if (!dmabuf->virt) {
  8505. kfree(dmabuf);
  8506. goto out_fail;
  8507. }
  8508. memset(dmabuf->virt, 0, PAGE_SIZE);
  8509. dmabuf->buffer_tag = x;
  8510. list_add_tail(&dmabuf->list, &queue->page_list);
  8511. /* initialize queue's entry array */
  8512. dma_pointer = dmabuf->virt;
  8513. for (; total_qe_count < entry_count &&
  8514. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8515. total_qe_count++, dma_pointer += entry_size) {
  8516. queue->qe[total_qe_count].address = dma_pointer;
  8517. }
  8518. }
  8519. queue->entry_size = entry_size;
  8520. queue->entry_count = entry_count;
  8521. queue->phba = phba;
  8522. return queue;
  8523. out_fail:
  8524. lpfc_sli4_queue_free(queue);
  8525. return NULL;
  8526. }
  8527. /**
  8528. * lpfc_eq_create - Create an Event Queue on the HBA
  8529. * @phba: HBA structure that indicates port to create a queue on.
  8530. * @eq: The queue structure to use to create the event queue.
  8531. * @imax: The maximum interrupt per second limit.
  8532. *
  8533. * This function creates an event queue, as detailed in @eq, on a port,
  8534. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8535. *
  8536. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8537. * is used to get the entry count and entry size that are necessary to
  8538. * determine the number of pages to allocate and use for this queue. This
  8539. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8540. * event queue. This function is asynchronous and will wait for the mailbox
  8541. * command to finish before continuing.
  8542. *
  8543. * On success this function will return a zero. If unable to allocate enough
  8544. * memory this function will return ENOMEM. If the queue create mailbox command
  8545. * fails this function will return ENXIO.
  8546. **/
  8547. uint32_t
  8548. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8549. {
  8550. struct lpfc_mbx_eq_create *eq_create;
  8551. LPFC_MBOXQ_t *mbox;
  8552. int rc, length, status = 0;
  8553. struct lpfc_dmabuf *dmabuf;
  8554. uint32_t shdr_status, shdr_add_status;
  8555. union lpfc_sli4_cfg_shdr *shdr;
  8556. uint16_t dmult;
  8557. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8558. if (!mbox)
  8559. return -ENOMEM;
  8560. length = (sizeof(struct lpfc_mbx_eq_create) -
  8561. sizeof(struct lpfc_sli4_cfg_mhdr));
  8562. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8563. LPFC_MBOX_OPCODE_EQ_CREATE,
  8564. length, LPFC_SLI4_MBX_EMBED);
  8565. eq_create = &mbox->u.mqe.un.eq_create;
  8566. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8567. eq->page_count);
  8568. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8569. LPFC_EQE_SIZE);
  8570. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8571. /* Calculate delay multiper from maximum interrupt per second */
  8572. dmult = LPFC_DMULT_CONST/imax - 1;
  8573. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8574. dmult);
  8575. switch (eq->entry_count) {
  8576. default:
  8577. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8578. "0360 Unsupported EQ count. (%d)\n",
  8579. eq->entry_count);
  8580. if (eq->entry_count < 256)
  8581. return -EINVAL;
  8582. /* otherwise default to smallest count (drop through) */
  8583. case 256:
  8584. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8585. LPFC_EQ_CNT_256);
  8586. break;
  8587. case 512:
  8588. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8589. LPFC_EQ_CNT_512);
  8590. break;
  8591. case 1024:
  8592. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8593. LPFC_EQ_CNT_1024);
  8594. break;
  8595. case 2048:
  8596. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8597. LPFC_EQ_CNT_2048);
  8598. break;
  8599. case 4096:
  8600. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8601. LPFC_EQ_CNT_4096);
  8602. break;
  8603. }
  8604. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8605. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8606. putPaddrLow(dmabuf->phys);
  8607. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8608. putPaddrHigh(dmabuf->phys);
  8609. }
  8610. mbox->vport = phba->pport;
  8611. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8612. mbox->context1 = NULL;
  8613. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8614. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8615. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8616. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8617. if (shdr_status || shdr_add_status || rc) {
  8618. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8619. "2500 EQ_CREATE mailbox failed with "
  8620. "status x%x add_status x%x, mbx status x%x\n",
  8621. shdr_status, shdr_add_status, rc);
  8622. status = -ENXIO;
  8623. }
  8624. eq->type = LPFC_EQ;
  8625. eq->subtype = LPFC_NONE;
  8626. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8627. if (eq->queue_id == 0xFFFF)
  8628. status = -ENXIO;
  8629. eq->host_index = 0;
  8630. eq->hba_index = 0;
  8631. mempool_free(mbox, phba->mbox_mem_pool);
  8632. return status;
  8633. }
  8634. /**
  8635. * lpfc_cq_create - Create a Completion Queue on the HBA
  8636. * @phba: HBA structure that indicates port to create a queue on.
  8637. * @cq: The queue structure to use to create the completion queue.
  8638. * @eq: The event queue to bind this completion queue to.
  8639. *
  8640. * This function creates a completion queue, as detailed in @wq, on a port,
  8641. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8642. *
  8643. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8644. * is used to get the entry count and entry size that are necessary to
  8645. * determine the number of pages to allocate and use for this queue. The @eq
  8646. * is used to indicate which event queue to bind this completion queue to. This
  8647. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8648. * completion queue. This function is asynchronous and will wait for the mailbox
  8649. * command to finish before continuing.
  8650. *
  8651. * On success this function will return a zero. If unable to allocate enough
  8652. * memory this function will return ENOMEM. If the queue create mailbox command
  8653. * fails this function will return ENXIO.
  8654. **/
  8655. uint32_t
  8656. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8657. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8658. {
  8659. struct lpfc_mbx_cq_create *cq_create;
  8660. struct lpfc_dmabuf *dmabuf;
  8661. LPFC_MBOXQ_t *mbox;
  8662. int rc, length, status = 0;
  8663. uint32_t shdr_status, shdr_add_status;
  8664. union lpfc_sli4_cfg_shdr *shdr;
  8665. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8666. if (!mbox)
  8667. return -ENOMEM;
  8668. length = (sizeof(struct lpfc_mbx_cq_create) -
  8669. sizeof(struct lpfc_sli4_cfg_mhdr));
  8670. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8671. LPFC_MBOX_OPCODE_CQ_CREATE,
  8672. length, LPFC_SLI4_MBX_EMBED);
  8673. cq_create = &mbox->u.mqe.un.cq_create;
  8674. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8675. cq->page_count);
  8676. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8677. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8678. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8679. switch (cq->entry_count) {
  8680. default:
  8681. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8682. "0361 Unsupported CQ count. (%d)\n",
  8683. cq->entry_count);
  8684. if (cq->entry_count < 256)
  8685. return -EINVAL;
  8686. /* otherwise default to smallest count (drop through) */
  8687. case 256:
  8688. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8689. LPFC_CQ_CNT_256);
  8690. break;
  8691. case 512:
  8692. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8693. LPFC_CQ_CNT_512);
  8694. break;
  8695. case 1024:
  8696. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8697. LPFC_CQ_CNT_1024);
  8698. break;
  8699. }
  8700. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8701. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8702. putPaddrLow(dmabuf->phys);
  8703. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8704. putPaddrHigh(dmabuf->phys);
  8705. }
  8706. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8707. /* The IOCTL status is embedded in the mailbox subheader. */
  8708. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8709. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8710. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8711. if (shdr_status || shdr_add_status || rc) {
  8712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8713. "2501 CQ_CREATE mailbox failed with "
  8714. "status x%x add_status x%x, mbx status x%x\n",
  8715. shdr_status, shdr_add_status, rc);
  8716. status = -ENXIO;
  8717. goto out;
  8718. }
  8719. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8720. if (cq->queue_id == 0xFFFF) {
  8721. status = -ENXIO;
  8722. goto out;
  8723. }
  8724. /* link the cq onto the parent eq child list */
  8725. list_add_tail(&cq->list, &eq->child_list);
  8726. /* Set up completion queue's type and subtype */
  8727. cq->type = type;
  8728. cq->subtype = subtype;
  8729. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8730. cq->host_index = 0;
  8731. cq->hba_index = 0;
  8732. out:
  8733. mempool_free(mbox, phba->mbox_mem_pool);
  8734. return status;
  8735. }
  8736. /**
  8737. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8738. * @phba: HBA structure that indicates port to create a queue on.
  8739. * @mq: The queue structure to use to create the mailbox queue.
  8740. *
  8741. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8742. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8743. *
  8744. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8745. * is used to get the entry count and entry size that are necessary to
  8746. * determine the number of pages to allocate and use for this queue. This
  8747. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8748. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8749. * command to finish before continuing.
  8750. *
  8751. * On success this function will return a zero. If unable to allocate enough
  8752. * memory this function will return ENOMEM. If the queue create mailbox command
  8753. * fails this function will return ENXIO.
  8754. **/
  8755. uint32_t
  8756. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8757. struct lpfc_queue *cq, uint32_t subtype)
  8758. {
  8759. struct lpfc_mbx_mq_create *mq_create;
  8760. struct lpfc_dmabuf *dmabuf;
  8761. LPFC_MBOXQ_t *mbox;
  8762. int rc, length, status = 0;
  8763. uint32_t shdr_status, shdr_add_status;
  8764. union lpfc_sli4_cfg_shdr *shdr;
  8765. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8766. if (!mbox)
  8767. return -ENOMEM;
  8768. length = (sizeof(struct lpfc_mbx_mq_create) -
  8769. sizeof(struct lpfc_sli4_cfg_mhdr));
  8770. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8771. LPFC_MBOX_OPCODE_MQ_CREATE,
  8772. length, LPFC_SLI4_MBX_EMBED);
  8773. mq_create = &mbox->u.mqe.un.mq_create;
  8774. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8775. mq->page_count);
  8776. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8777. cq->queue_id);
  8778. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8779. switch (mq->entry_count) {
  8780. default:
  8781. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8782. "0362 Unsupported MQ count. (%d)\n",
  8783. mq->entry_count);
  8784. if (mq->entry_count < 16)
  8785. return -EINVAL;
  8786. /* otherwise default to smallest count (drop through) */
  8787. case 16:
  8788. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8789. LPFC_MQ_CNT_16);
  8790. break;
  8791. case 32:
  8792. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8793. LPFC_MQ_CNT_32);
  8794. break;
  8795. case 64:
  8796. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8797. LPFC_MQ_CNT_64);
  8798. break;
  8799. case 128:
  8800. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8801. LPFC_MQ_CNT_128);
  8802. break;
  8803. }
  8804. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8805. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8806. putPaddrLow(dmabuf->phys);
  8807. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8808. putPaddrHigh(dmabuf->phys);
  8809. }
  8810. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8811. /* The IOCTL status is embedded in the mailbox subheader. */
  8812. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8813. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8814. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8815. if (shdr_status || shdr_add_status || rc) {
  8816. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8817. "2502 MQ_CREATE mailbox failed with "
  8818. "status x%x add_status x%x, mbx status x%x\n",
  8819. shdr_status, shdr_add_status, rc);
  8820. status = -ENXIO;
  8821. goto out;
  8822. }
  8823. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8824. if (mq->queue_id == 0xFFFF) {
  8825. status = -ENXIO;
  8826. goto out;
  8827. }
  8828. mq->type = LPFC_MQ;
  8829. mq->subtype = subtype;
  8830. mq->host_index = 0;
  8831. mq->hba_index = 0;
  8832. /* link the mq onto the parent cq child list */
  8833. list_add_tail(&mq->list, &cq->child_list);
  8834. out:
  8835. mempool_free(mbox, phba->mbox_mem_pool);
  8836. return status;
  8837. }
  8838. /**
  8839. * lpfc_wq_create - Create a Work Queue on the HBA
  8840. * @phba: HBA structure that indicates port to create a queue on.
  8841. * @wq: The queue structure to use to create the work queue.
  8842. * @cq: The completion queue to bind this work queue to.
  8843. * @subtype: The subtype of the work queue indicating its functionality.
  8844. *
  8845. * This function creates a work queue, as detailed in @wq, on a port, described
  8846. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8847. *
  8848. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8849. * is used to get the entry count and entry size that are necessary to
  8850. * determine the number of pages to allocate and use for this queue. The @cq
  8851. * is used to indicate which completion queue to bind this work queue to. This
  8852. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8853. * work queue. This function is asynchronous and will wait for the mailbox
  8854. * command to finish before continuing.
  8855. *
  8856. * On success this function will return a zero. If unable to allocate enough
  8857. * memory this function will return ENOMEM. If the queue create mailbox command
  8858. * fails this function will return ENXIO.
  8859. **/
  8860. uint32_t
  8861. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8862. struct lpfc_queue *cq, uint32_t subtype)
  8863. {
  8864. struct lpfc_mbx_wq_create *wq_create;
  8865. struct lpfc_dmabuf *dmabuf;
  8866. LPFC_MBOXQ_t *mbox;
  8867. int rc, length, status = 0;
  8868. uint32_t shdr_status, shdr_add_status;
  8869. union lpfc_sli4_cfg_shdr *shdr;
  8870. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8871. if (!mbox)
  8872. return -ENOMEM;
  8873. length = (sizeof(struct lpfc_mbx_wq_create) -
  8874. sizeof(struct lpfc_sli4_cfg_mhdr));
  8875. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8876. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8877. length, LPFC_SLI4_MBX_EMBED);
  8878. wq_create = &mbox->u.mqe.un.wq_create;
  8879. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8880. wq->page_count);
  8881. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8882. cq->queue_id);
  8883. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8884. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8885. putPaddrLow(dmabuf->phys);
  8886. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8887. putPaddrHigh(dmabuf->phys);
  8888. }
  8889. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8890. /* The IOCTL status is embedded in the mailbox subheader. */
  8891. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8892. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8893. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8894. if (shdr_status || shdr_add_status || rc) {
  8895. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8896. "2503 WQ_CREATE mailbox failed with "
  8897. "status x%x add_status x%x, mbx status x%x\n",
  8898. shdr_status, shdr_add_status, rc);
  8899. status = -ENXIO;
  8900. goto out;
  8901. }
  8902. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8903. if (wq->queue_id == 0xFFFF) {
  8904. status = -ENXIO;
  8905. goto out;
  8906. }
  8907. wq->type = LPFC_WQ;
  8908. wq->subtype = subtype;
  8909. wq->host_index = 0;
  8910. wq->hba_index = 0;
  8911. /* link the wq onto the parent cq child list */
  8912. list_add_tail(&wq->list, &cq->child_list);
  8913. out:
  8914. mempool_free(mbox, phba->mbox_mem_pool);
  8915. return status;
  8916. }
  8917. /**
  8918. * lpfc_rq_create - Create a Receive Queue on the HBA
  8919. * @phba: HBA structure that indicates port to create a queue on.
  8920. * @hrq: The queue structure to use to create the header receive queue.
  8921. * @drq: The queue structure to use to create the data receive queue.
  8922. * @cq: The completion queue to bind this work queue to.
  8923. *
  8924. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8925. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8926. * to the HBA.
  8927. *
  8928. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8929. * struct is used to get the entry count that is necessary to determine the
  8930. * number of pages to use for this queue. The @cq is used to indicate which
  8931. * completion queue to bind received buffers that are posted to these queues to.
  8932. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8933. * receive queue pair. This function is asynchronous and will wait for the
  8934. * mailbox command to finish before continuing.
  8935. *
  8936. * On success this function will return a zero. If unable to allocate enough
  8937. * memory this function will return ENOMEM. If the queue create mailbox command
  8938. * fails this function will return ENXIO.
  8939. **/
  8940. uint32_t
  8941. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8942. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8943. {
  8944. struct lpfc_mbx_rq_create *rq_create;
  8945. struct lpfc_dmabuf *dmabuf;
  8946. LPFC_MBOXQ_t *mbox;
  8947. int rc, length, status = 0;
  8948. uint32_t shdr_status, shdr_add_status;
  8949. union lpfc_sli4_cfg_shdr *shdr;
  8950. if (hrq->entry_count != drq->entry_count)
  8951. return -EINVAL;
  8952. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8953. if (!mbox)
  8954. return -ENOMEM;
  8955. length = (sizeof(struct lpfc_mbx_rq_create) -
  8956. sizeof(struct lpfc_sli4_cfg_mhdr));
  8957. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8958. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8959. length, LPFC_SLI4_MBX_EMBED);
  8960. rq_create = &mbox->u.mqe.un.rq_create;
  8961. switch (hrq->entry_count) {
  8962. default:
  8963. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8964. "2535 Unsupported RQ count. (%d)\n",
  8965. hrq->entry_count);
  8966. if (hrq->entry_count < 512)
  8967. return -EINVAL;
  8968. /* otherwise default to smallest count (drop through) */
  8969. case 512:
  8970. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8971. LPFC_RQ_RING_SIZE_512);
  8972. break;
  8973. case 1024:
  8974. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8975. LPFC_RQ_RING_SIZE_1024);
  8976. break;
  8977. case 2048:
  8978. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8979. LPFC_RQ_RING_SIZE_2048);
  8980. break;
  8981. case 4096:
  8982. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8983. LPFC_RQ_RING_SIZE_4096);
  8984. break;
  8985. }
  8986. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  8987. cq->queue_id);
  8988. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  8989. hrq->page_count);
  8990. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  8991. LPFC_HDR_BUF_SIZE);
  8992. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  8993. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8994. putPaddrLow(dmabuf->phys);
  8995. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8996. putPaddrHigh(dmabuf->phys);
  8997. }
  8998. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8999. /* The IOCTL status is embedded in the mailbox subheader. */
  9000. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9001. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9002. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9003. if (shdr_status || shdr_add_status || rc) {
  9004. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9005. "2504 RQ_CREATE mailbox failed with "
  9006. "status x%x add_status x%x, mbx status x%x\n",
  9007. shdr_status, shdr_add_status, rc);
  9008. status = -ENXIO;
  9009. goto out;
  9010. }
  9011. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9012. if (hrq->queue_id == 0xFFFF) {
  9013. status = -ENXIO;
  9014. goto out;
  9015. }
  9016. hrq->type = LPFC_HRQ;
  9017. hrq->subtype = subtype;
  9018. hrq->host_index = 0;
  9019. hrq->hba_index = 0;
  9020. /* now create the data queue */
  9021. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9022. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9023. length, LPFC_SLI4_MBX_EMBED);
  9024. switch (drq->entry_count) {
  9025. default:
  9026. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9027. "2536 Unsupported RQ count. (%d)\n",
  9028. drq->entry_count);
  9029. if (drq->entry_count < 512)
  9030. return -EINVAL;
  9031. /* otherwise default to smallest count (drop through) */
  9032. case 512:
  9033. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9034. LPFC_RQ_RING_SIZE_512);
  9035. break;
  9036. case 1024:
  9037. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9038. LPFC_RQ_RING_SIZE_1024);
  9039. break;
  9040. case 2048:
  9041. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9042. LPFC_RQ_RING_SIZE_2048);
  9043. break;
  9044. case 4096:
  9045. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9046. LPFC_RQ_RING_SIZE_4096);
  9047. break;
  9048. }
  9049. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9050. cq->queue_id);
  9051. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9052. drq->page_count);
  9053. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9054. LPFC_DATA_BUF_SIZE);
  9055. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9056. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9057. putPaddrLow(dmabuf->phys);
  9058. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9059. putPaddrHigh(dmabuf->phys);
  9060. }
  9061. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9062. /* The IOCTL status is embedded in the mailbox subheader. */
  9063. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9064. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9065. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9066. if (shdr_status || shdr_add_status || rc) {
  9067. status = -ENXIO;
  9068. goto out;
  9069. }
  9070. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9071. if (drq->queue_id == 0xFFFF) {
  9072. status = -ENXIO;
  9073. goto out;
  9074. }
  9075. drq->type = LPFC_DRQ;
  9076. drq->subtype = subtype;
  9077. drq->host_index = 0;
  9078. drq->hba_index = 0;
  9079. /* link the header and data RQs onto the parent cq child list */
  9080. list_add_tail(&hrq->list, &cq->child_list);
  9081. list_add_tail(&drq->list, &cq->child_list);
  9082. out:
  9083. mempool_free(mbox, phba->mbox_mem_pool);
  9084. return status;
  9085. }
  9086. /**
  9087. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9088. * @eq: The queue structure associated with the queue to destroy.
  9089. *
  9090. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9091. * command, specific to the type of queue, to the HBA.
  9092. *
  9093. * The @eq struct is used to get the queue ID of the queue to destroy.
  9094. *
  9095. * On success this function will return a zero. If the queue destroy mailbox
  9096. * command fails this function will return ENXIO.
  9097. **/
  9098. uint32_t
  9099. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9100. {
  9101. LPFC_MBOXQ_t *mbox;
  9102. int rc, length, status = 0;
  9103. uint32_t shdr_status, shdr_add_status;
  9104. union lpfc_sli4_cfg_shdr *shdr;
  9105. if (!eq)
  9106. return -ENODEV;
  9107. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9108. if (!mbox)
  9109. return -ENOMEM;
  9110. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9111. sizeof(struct lpfc_sli4_cfg_mhdr));
  9112. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9113. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9114. length, LPFC_SLI4_MBX_EMBED);
  9115. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9116. eq->queue_id);
  9117. mbox->vport = eq->phba->pport;
  9118. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9119. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9120. /* The IOCTL status is embedded in the mailbox subheader. */
  9121. shdr = (union lpfc_sli4_cfg_shdr *)
  9122. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9123. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9124. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9125. if (shdr_status || shdr_add_status || rc) {
  9126. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9127. "2505 EQ_DESTROY mailbox failed with "
  9128. "status x%x add_status x%x, mbx status x%x\n",
  9129. shdr_status, shdr_add_status, rc);
  9130. status = -ENXIO;
  9131. }
  9132. /* Remove eq from any list */
  9133. list_del_init(&eq->list);
  9134. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9135. return status;
  9136. }
  9137. /**
  9138. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9139. * @cq: The queue structure associated with the queue to destroy.
  9140. *
  9141. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9142. * command, specific to the type of queue, to the HBA.
  9143. *
  9144. * The @cq struct is used to get the queue ID of the queue to destroy.
  9145. *
  9146. * On success this function will return a zero. If the queue destroy mailbox
  9147. * command fails this function will return ENXIO.
  9148. **/
  9149. uint32_t
  9150. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9151. {
  9152. LPFC_MBOXQ_t *mbox;
  9153. int rc, length, status = 0;
  9154. uint32_t shdr_status, shdr_add_status;
  9155. union lpfc_sli4_cfg_shdr *shdr;
  9156. if (!cq)
  9157. return -ENODEV;
  9158. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9159. if (!mbox)
  9160. return -ENOMEM;
  9161. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9162. sizeof(struct lpfc_sli4_cfg_mhdr));
  9163. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9164. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9165. length, LPFC_SLI4_MBX_EMBED);
  9166. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9167. cq->queue_id);
  9168. mbox->vport = cq->phba->pport;
  9169. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9170. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9171. /* The IOCTL status is embedded in the mailbox subheader. */
  9172. shdr = (union lpfc_sli4_cfg_shdr *)
  9173. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9174. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9175. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9176. if (shdr_status || shdr_add_status || rc) {
  9177. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9178. "2506 CQ_DESTROY mailbox failed with "
  9179. "status x%x add_status x%x, mbx status x%x\n",
  9180. shdr_status, shdr_add_status, rc);
  9181. status = -ENXIO;
  9182. }
  9183. /* Remove cq from any list */
  9184. list_del_init(&cq->list);
  9185. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9186. return status;
  9187. }
  9188. /**
  9189. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9190. * @qm: The queue structure associated with the queue to destroy.
  9191. *
  9192. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9193. * command, specific to the type of queue, to the HBA.
  9194. *
  9195. * The @mq struct is used to get the queue ID of the queue to destroy.
  9196. *
  9197. * On success this function will return a zero. If the queue destroy mailbox
  9198. * command fails this function will return ENXIO.
  9199. **/
  9200. uint32_t
  9201. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9202. {
  9203. LPFC_MBOXQ_t *mbox;
  9204. int rc, length, status = 0;
  9205. uint32_t shdr_status, shdr_add_status;
  9206. union lpfc_sli4_cfg_shdr *shdr;
  9207. if (!mq)
  9208. return -ENODEV;
  9209. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9210. if (!mbox)
  9211. return -ENOMEM;
  9212. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9213. sizeof(struct lpfc_sli4_cfg_mhdr));
  9214. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9215. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9216. length, LPFC_SLI4_MBX_EMBED);
  9217. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9218. mq->queue_id);
  9219. mbox->vport = mq->phba->pport;
  9220. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9221. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9222. /* The IOCTL status is embedded in the mailbox subheader. */
  9223. shdr = (union lpfc_sli4_cfg_shdr *)
  9224. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9225. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9226. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9227. if (shdr_status || shdr_add_status || rc) {
  9228. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9229. "2507 MQ_DESTROY mailbox failed with "
  9230. "status x%x add_status x%x, mbx status x%x\n",
  9231. shdr_status, shdr_add_status, rc);
  9232. status = -ENXIO;
  9233. }
  9234. /* Remove mq from any list */
  9235. list_del_init(&mq->list);
  9236. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9237. return status;
  9238. }
  9239. /**
  9240. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9241. * @wq: The queue structure associated with the queue to destroy.
  9242. *
  9243. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9244. * command, specific to the type of queue, to the HBA.
  9245. *
  9246. * The @wq struct is used to get the queue ID of the queue to destroy.
  9247. *
  9248. * On success this function will return a zero. If the queue destroy mailbox
  9249. * command fails this function will return ENXIO.
  9250. **/
  9251. uint32_t
  9252. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9253. {
  9254. LPFC_MBOXQ_t *mbox;
  9255. int rc, length, status = 0;
  9256. uint32_t shdr_status, shdr_add_status;
  9257. union lpfc_sli4_cfg_shdr *shdr;
  9258. if (!wq)
  9259. return -ENODEV;
  9260. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9261. if (!mbox)
  9262. return -ENOMEM;
  9263. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9264. sizeof(struct lpfc_sli4_cfg_mhdr));
  9265. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9266. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9267. length, LPFC_SLI4_MBX_EMBED);
  9268. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9269. wq->queue_id);
  9270. mbox->vport = wq->phba->pport;
  9271. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9272. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9273. shdr = (union lpfc_sli4_cfg_shdr *)
  9274. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9275. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9276. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9277. if (shdr_status || shdr_add_status || rc) {
  9278. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9279. "2508 WQ_DESTROY mailbox failed with "
  9280. "status x%x add_status x%x, mbx status x%x\n",
  9281. shdr_status, shdr_add_status, rc);
  9282. status = -ENXIO;
  9283. }
  9284. /* Remove wq from any list */
  9285. list_del_init(&wq->list);
  9286. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9287. return status;
  9288. }
  9289. /**
  9290. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9291. * @rq: The queue structure associated with the queue to destroy.
  9292. *
  9293. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9294. * command, specific to the type of queue, to the HBA.
  9295. *
  9296. * The @rq struct is used to get the queue ID of the queue to destroy.
  9297. *
  9298. * On success this function will return a zero. If the queue destroy mailbox
  9299. * command fails this function will return ENXIO.
  9300. **/
  9301. uint32_t
  9302. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9303. struct lpfc_queue *drq)
  9304. {
  9305. LPFC_MBOXQ_t *mbox;
  9306. int rc, length, status = 0;
  9307. uint32_t shdr_status, shdr_add_status;
  9308. union lpfc_sli4_cfg_shdr *shdr;
  9309. if (!hrq || !drq)
  9310. return -ENODEV;
  9311. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9312. if (!mbox)
  9313. return -ENOMEM;
  9314. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9315. sizeof(struct mbox_header));
  9316. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9317. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9318. length, LPFC_SLI4_MBX_EMBED);
  9319. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9320. hrq->queue_id);
  9321. mbox->vport = hrq->phba->pport;
  9322. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9323. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9324. /* The IOCTL status is embedded in the mailbox subheader. */
  9325. shdr = (union lpfc_sli4_cfg_shdr *)
  9326. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9327. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9328. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9329. if (shdr_status || shdr_add_status || rc) {
  9330. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9331. "2509 RQ_DESTROY mailbox failed with "
  9332. "status x%x add_status x%x, mbx status x%x\n",
  9333. shdr_status, shdr_add_status, rc);
  9334. if (rc != MBX_TIMEOUT)
  9335. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9336. return -ENXIO;
  9337. }
  9338. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9339. drq->queue_id);
  9340. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9341. shdr = (union lpfc_sli4_cfg_shdr *)
  9342. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9343. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9344. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9345. if (shdr_status || shdr_add_status || rc) {
  9346. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9347. "2510 RQ_DESTROY mailbox failed with "
  9348. "status x%x add_status x%x, mbx status x%x\n",
  9349. shdr_status, shdr_add_status, rc);
  9350. status = -ENXIO;
  9351. }
  9352. list_del_init(&hrq->list);
  9353. list_del_init(&drq->list);
  9354. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9355. return status;
  9356. }
  9357. /**
  9358. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9359. * @phba: The virtual port for which this call being executed.
  9360. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9361. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9362. * @xritag: the xritag that ties this io to the SGL pages.
  9363. *
  9364. * This routine will post the sgl pages for the IO that has the xritag
  9365. * that is in the iocbq structure. The xritag is assigned during iocbq
  9366. * creation and persists for as long as the driver is loaded.
  9367. * if the caller has fewer than 256 scatter gather segments to map then
  9368. * pdma_phys_addr1 should be 0.
  9369. * If the caller needs to map more than 256 scatter gather segment then
  9370. * pdma_phys_addr1 should be a valid physical address.
  9371. * physical address for SGLs must be 64 byte aligned.
  9372. * If you are going to map 2 SGL's then the first one must have 256 entries
  9373. * the second sgl can have between 1 and 256 entries.
  9374. *
  9375. * Return codes:
  9376. * 0 - Success
  9377. * -ENXIO, -ENOMEM - Failure
  9378. **/
  9379. int
  9380. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9381. dma_addr_t pdma_phys_addr0,
  9382. dma_addr_t pdma_phys_addr1,
  9383. uint16_t xritag)
  9384. {
  9385. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9386. LPFC_MBOXQ_t *mbox;
  9387. int rc;
  9388. uint32_t shdr_status, shdr_add_status;
  9389. union lpfc_sli4_cfg_shdr *shdr;
  9390. if (xritag == NO_XRI) {
  9391. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9392. "0364 Invalid param:\n");
  9393. return -EINVAL;
  9394. }
  9395. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9396. if (!mbox)
  9397. return -ENOMEM;
  9398. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9399. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9400. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9401. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9402. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9403. &mbox->u.mqe.un.post_sgl_pages;
  9404. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9405. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9406. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9407. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9408. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9409. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9410. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9411. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9412. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9413. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9414. if (!phba->sli4_hba.intr_enable)
  9415. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9416. else
  9417. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9418. /* The IOCTL status is embedded in the mailbox subheader. */
  9419. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9420. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9421. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9422. if (rc != MBX_TIMEOUT)
  9423. mempool_free(mbox, phba->mbox_mem_pool);
  9424. if (shdr_status || shdr_add_status || rc) {
  9425. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9426. "2511 POST_SGL mailbox failed with "
  9427. "status x%x add_status x%x, mbx status x%x\n",
  9428. shdr_status, shdr_add_status, rc);
  9429. rc = -ENXIO;
  9430. }
  9431. return 0;
  9432. }
  9433. /**
  9434. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9435. * @phba: The virtual port for which this call being executed.
  9436. *
  9437. * This routine will remove all of the sgl pages registered with the hba.
  9438. *
  9439. * Return codes:
  9440. * 0 - Success
  9441. * -ENXIO, -ENOMEM - Failure
  9442. **/
  9443. int
  9444. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9445. {
  9446. LPFC_MBOXQ_t *mbox;
  9447. int rc;
  9448. uint32_t shdr_status, shdr_add_status;
  9449. union lpfc_sli4_cfg_shdr *shdr;
  9450. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9451. if (!mbox)
  9452. return -ENOMEM;
  9453. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9454. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9455. LPFC_SLI4_MBX_EMBED);
  9456. if (!phba->sli4_hba.intr_enable)
  9457. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9458. else
  9459. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9460. /* The IOCTL status is embedded in the mailbox subheader. */
  9461. shdr = (union lpfc_sli4_cfg_shdr *)
  9462. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9463. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9464. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9465. if (rc != MBX_TIMEOUT)
  9466. mempool_free(mbox, phba->mbox_mem_pool);
  9467. if (shdr_status || shdr_add_status || rc) {
  9468. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9469. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9470. "status x%x add_status x%x, mbx status x%x\n",
  9471. shdr_status, shdr_add_status, rc);
  9472. rc = -ENXIO;
  9473. }
  9474. return rc;
  9475. }
  9476. /**
  9477. * lpfc_sli4_next_xritag - Get an xritag for the io
  9478. * @phba: Pointer to HBA context object.
  9479. *
  9480. * This function gets an xritag for the iocb. If there is no unused xritag
  9481. * it will return 0xffff.
  9482. * The function returns the allocated xritag if successful, else returns zero.
  9483. * Zero is not a valid xritag.
  9484. * The caller is not required to hold any lock.
  9485. **/
  9486. uint16_t
  9487. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9488. {
  9489. uint16_t xritag;
  9490. spin_lock_irq(&phba->hbalock);
  9491. xritag = phba->sli4_hba.next_xri;
  9492. if ((xritag != (uint16_t) -1) && xritag <
  9493. (phba->sli4_hba.max_cfg_param.max_xri
  9494. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9495. phba->sli4_hba.next_xri++;
  9496. phba->sli4_hba.max_cfg_param.xri_used++;
  9497. spin_unlock_irq(&phba->hbalock);
  9498. return xritag;
  9499. }
  9500. spin_unlock_irq(&phba->hbalock);
  9501. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9502. "2004 Failed to allocate XRI.last XRITAG is %d"
  9503. " Max XRI is %d, Used XRI is %d\n",
  9504. phba->sli4_hba.next_xri,
  9505. phba->sli4_hba.max_cfg_param.max_xri,
  9506. phba->sli4_hba.max_cfg_param.xri_used);
  9507. return -1;
  9508. }
  9509. /**
  9510. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9511. * @phba: pointer to lpfc hba data structure.
  9512. *
  9513. * This routine is invoked to post a block of driver's sgl pages to the
  9514. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9515. * is only called when the driver is loading and after all IO has been
  9516. * stopped.
  9517. **/
  9518. int
  9519. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9520. {
  9521. struct lpfc_sglq *sglq_entry;
  9522. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9523. struct sgl_page_pairs *sgl_pg_pairs;
  9524. void *viraddr;
  9525. LPFC_MBOXQ_t *mbox;
  9526. uint32_t reqlen, alloclen, pg_pairs;
  9527. uint32_t mbox_tmo;
  9528. uint16_t xritag_start = 0;
  9529. int els_xri_cnt, rc = 0;
  9530. uint32_t shdr_status, shdr_add_status;
  9531. union lpfc_sli4_cfg_shdr *shdr;
  9532. /* The number of sgls to be posted */
  9533. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9534. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9535. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9536. if (reqlen > PAGE_SIZE) {
  9537. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9538. "2559 Block sgl registration required DMA "
  9539. "size (%d) great than a page\n", reqlen);
  9540. return -ENOMEM;
  9541. }
  9542. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9543. if (!mbox) {
  9544. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9545. "2560 Failed to allocate mbox cmd memory\n");
  9546. return -ENOMEM;
  9547. }
  9548. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9549. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9550. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9551. LPFC_SLI4_MBX_NEMBED);
  9552. if (alloclen < reqlen) {
  9553. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9554. "0285 Allocated DMA memory size (%d) is "
  9555. "less than the requested DMA memory "
  9556. "size (%d)\n", alloclen, reqlen);
  9557. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9558. return -ENOMEM;
  9559. }
  9560. /* Get the first SGE entry from the non-embedded DMA memory */
  9561. if (unlikely(!mbox->sge_array)) {
  9562. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9563. "2525 Failed to get the non-embedded SGE "
  9564. "virtual address\n");
  9565. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9566. return -ENOMEM;
  9567. }
  9568. viraddr = mbox->sge_array->addr[0];
  9569. /* Set up the SGL pages in the non-embedded DMA pages */
  9570. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9571. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9572. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9573. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9574. /* Set up the sge entry */
  9575. sgl_pg_pairs->sgl_pg0_addr_lo =
  9576. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9577. sgl_pg_pairs->sgl_pg0_addr_hi =
  9578. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9579. sgl_pg_pairs->sgl_pg1_addr_lo =
  9580. cpu_to_le32(putPaddrLow(0));
  9581. sgl_pg_pairs->sgl_pg1_addr_hi =
  9582. cpu_to_le32(putPaddrHigh(0));
  9583. /* Keep the first xritag on the list */
  9584. if (pg_pairs == 0)
  9585. xritag_start = sglq_entry->sli4_xritag;
  9586. sgl_pg_pairs++;
  9587. }
  9588. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9589. pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs;
  9590. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9591. /* Perform endian conversion if necessary */
  9592. sgl->word0 = cpu_to_le32(sgl->word0);
  9593. if (!phba->sli4_hba.intr_enable)
  9594. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9595. else {
  9596. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9597. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9598. }
  9599. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9600. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9601. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9602. if (rc != MBX_TIMEOUT)
  9603. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9604. if (shdr_status || shdr_add_status || rc) {
  9605. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9606. "2513 POST_SGL_BLOCK mailbox command failed "
  9607. "status x%x add_status x%x mbx status x%x\n",
  9608. shdr_status, shdr_add_status, rc);
  9609. rc = -ENXIO;
  9610. }
  9611. return rc;
  9612. }
  9613. /**
  9614. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9615. * @phba: pointer to lpfc hba data structure.
  9616. * @sblist: pointer to scsi buffer list.
  9617. * @count: number of scsi buffers on the list.
  9618. *
  9619. * This routine is invoked to post a block of @count scsi sgl pages from a
  9620. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9621. * No Lock is held.
  9622. *
  9623. **/
  9624. int
  9625. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9626. int cnt)
  9627. {
  9628. struct lpfc_scsi_buf *psb;
  9629. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9630. struct sgl_page_pairs *sgl_pg_pairs;
  9631. void *viraddr;
  9632. LPFC_MBOXQ_t *mbox;
  9633. uint32_t reqlen, alloclen, pg_pairs;
  9634. uint32_t mbox_tmo;
  9635. uint16_t xritag_start = 0;
  9636. int rc = 0;
  9637. uint32_t shdr_status, shdr_add_status;
  9638. dma_addr_t pdma_phys_bpl1;
  9639. union lpfc_sli4_cfg_shdr *shdr;
  9640. /* Calculate the requested length of the dma memory */
  9641. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9642. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9643. if (reqlen > PAGE_SIZE) {
  9644. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9645. "0217 Block sgl registration required DMA "
  9646. "size (%d) great than a page\n", reqlen);
  9647. return -ENOMEM;
  9648. }
  9649. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9650. if (!mbox) {
  9651. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9652. "0283 Failed to allocate mbox cmd memory\n");
  9653. return -ENOMEM;
  9654. }
  9655. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9656. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9657. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9658. LPFC_SLI4_MBX_NEMBED);
  9659. if (alloclen < reqlen) {
  9660. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9661. "2561 Allocated DMA memory size (%d) is "
  9662. "less than the requested DMA memory "
  9663. "size (%d)\n", alloclen, reqlen);
  9664. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9665. return -ENOMEM;
  9666. }
  9667. /* Get the first SGE entry from the non-embedded DMA memory */
  9668. if (unlikely(!mbox->sge_array)) {
  9669. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9670. "2565 Failed to get the non-embedded SGE "
  9671. "virtual address\n");
  9672. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9673. return -ENOMEM;
  9674. }
  9675. viraddr = mbox->sge_array->addr[0];
  9676. /* Set up the SGL pages in the non-embedded DMA pages */
  9677. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9678. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9679. pg_pairs = 0;
  9680. list_for_each_entry(psb, sblist, list) {
  9681. /* Set up the sge entry */
  9682. sgl_pg_pairs->sgl_pg0_addr_lo =
  9683. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9684. sgl_pg_pairs->sgl_pg0_addr_hi =
  9685. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9686. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9687. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9688. else
  9689. pdma_phys_bpl1 = 0;
  9690. sgl_pg_pairs->sgl_pg1_addr_lo =
  9691. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9692. sgl_pg_pairs->sgl_pg1_addr_hi =
  9693. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9694. /* Keep the first xritag on the list */
  9695. if (pg_pairs == 0)
  9696. xritag_start = psb->cur_iocbq.sli4_xritag;
  9697. sgl_pg_pairs++;
  9698. pg_pairs++;
  9699. }
  9700. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9701. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9702. /* Perform endian conversion if necessary */
  9703. sgl->word0 = cpu_to_le32(sgl->word0);
  9704. if (!phba->sli4_hba.intr_enable)
  9705. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9706. else {
  9707. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9708. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9709. }
  9710. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9711. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9712. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9713. if (rc != MBX_TIMEOUT)
  9714. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9715. if (shdr_status || shdr_add_status || rc) {
  9716. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9717. "2564 POST_SGL_BLOCK mailbox command failed "
  9718. "status x%x add_status x%x mbx status x%x\n",
  9719. shdr_status, shdr_add_status, rc);
  9720. rc = -ENXIO;
  9721. }
  9722. return rc;
  9723. }
  9724. /**
  9725. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9726. * @phba: pointer to lpfc_hba struct that the frame was received on
  9727. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9728. *
  9729. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9730. * valid type of frame that the LPFC driver will handle. This function will
  9731. * return a zero if the frame is a valid frame or a non zero value when the
  9732. * frame does not pass the check.
  9733. **/
  9734. static int
  9735. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9736. {
  9737. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9738. char *type_names[] = FC_TYPE_NAMES_INIT;
  9739. struct fc_vft_header *fc_vft_hdr;
  9740. switch (fc_hdr->fh_r_ctl) {
  9741. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9742. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9743. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9744. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9745. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9746. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9747. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9748. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9749. case FC_RCTL_ELS_REQ: /* extended link services request */
  9750. case FC_RCTL_ELS_REP: /* extended link services reply */
  9751. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9752. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9753. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9754. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9755. case FC_RCTL_BA_RMC: /* remove connection */
  9756. case FC_RCTL_BA_ACC: /* basic accept */
  9757. case FC_RCTL_BA_RJT: /* basic reject */
  9758. case FC_RCTL_BA_PRMT:
  9759. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9760. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9761. case FC_RCTL_P_RJT: /* port reject */
  9762. case FC_RCTL_F_RJT: /* fabric reject */
  9763. case FC_RCTL_P_BSY: /* port busy */
  9764. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9765. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9766. case FC_RCTL_LCR: /* link credit reset */
  9767. case FC_RCTL_END: /* end */
  9768. break;
  9769. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9770. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9771. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9772. return lpfc_fc_frame_check(phba, fc_hdr);
  9773. default:
  9774. goto drop;
  9775. }
  9776. switch (fc_hdr->fh_type) {
  9777. case FC_TYPE_BLS:
  9778. case FC_TYPE_ELS:
  9779. case FC_TYPE_FCP:
  9780. case FC_TYPE_CT:
  9781. break;
  9782. case FC_TYPE_IP:
  9783. case FC_TYPE_ILS:
  9784. default:
  9785. goto drop;
  9786. }
  9787. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9788. "2538 Received frame rctl:%s type:%s\n",
  9789. rctl_names[fc_hdr->fh_r_ctl],
  9790. type_names[fc_hdr->fh_type]);
  9791. return 0;
  9792. drop:
  9793. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9794. "2539 Dropped frame rctl:%s type:%s\n",
  9795. rctl_names[fc_hdr->fh_r_ctl],
  9796. type_names[fc_hdr->fh_type]);
  9797. return 1;
  9798. }
  9799. /**
  9800. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9801. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9802. *
  9803. * This function processes the FC header to retrieve the VFI from the VF
  9804. * header, if one exists. This function will return the VFI if one exists
  9805. * or 0 if no VSAN Header exists.
  9806. **/
  9807. static uint32_t
  9808. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9809. {
  9810. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9811. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9812. return 0;
  9813. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9814. }
  9815. /**
  9816. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9817. * @phba: Pointer to the HBA structure to search for the vport on
  9818. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9819. * @fcfi: The FC Fabric ID that the frame came from
  9820. *
  9821. * This function searches the @phba for a vport that matches the content of the
  9822. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9823. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9824. * returns the matching vport pointer or NULL if unable to match frame to a
  9825. * vport.
  9826. **/
  9827. static struct lpfc_vport *
  9828. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9829. uint16_t fcfi)
  9830. {
  9831. struct lpfc_vport **vports;
  9832. struct lpfc_vport *vport = NULL;
  9833. int i;
  9834. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9835. fc_hdr->fh_d_id[1] << 8 |
  9836. fc_hdr->fh_d_id[2]);
  9837. vports = lpfc_create_vport_work_array(phba);
  9838. if (vports != NULL)
  9839. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9840. if (phba->fcf.fcfi == fcfi &&
  9841. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9842. vports[i]->fc_myDID == did) {
  9843. vport = vports[i];
  9844. break;
  9845. }
  9846. }
  9847. lpfc_destroy_vport_work_array(phba, vports);
  9848. return vport;
  9849. }
  9850. /**
  9851. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9852. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9853. *
  9854. * This function searches through the existing incomplete sequences that have
  9855. * been sent to this @vport. If the frame matches one of the incomplete
  9856. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9857. * make up that sequence. If no sequence is found that matches this frame then
  9858. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9859. * This function returns a pointer to the first dmabuf in the sequence list that
  9860. * the frame was linked to.
  9861. **/
  9862. static struct hbq_dmabuf *
  9863. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9864. {
  9865. struct fc_frame_header *new_hdr;
  9866. struct fc_frame_header *temp_hdr;
  9867. struct lpfc_dmabuf *d_buf;
  9868. struct lpfc_dmabuf *h_buf;
  9869. struct hbq_dmabuf *seq_dmabuf = NULL;
  9870. struct hbq_dmabuf *temp_dmabuf = NULL;
  9871. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  9872. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9873. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9874. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9875. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9876. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9877. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9878. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9879. continue;
  9880. /* found a pending sequence that matches this frame */
  9881. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9882. break;
  9883. }
  9884. if (!seq_dmabuf) {
  9885. /*
  9886. * This indicates first frame received for this sequence.
  9887. * Queue the buffer on the vport's rcv_buffer_list.
  9888. */
  9889. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9890. return dmabuf;
  9891. }
  9892. temp_hdr = seq_dmabuf->hbuf.virt;
  9893. if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
  9894. list_del_init(&seq_dmabuf->hbuf.list);
  9895. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9896. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  9897. return dmabuf;
  9898. }
  9899. /* find the correct place in the sequence to insert this frame */
  9900. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  9901. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9902. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  9903. /*
  9904. * If the frame's sequence count is greater than the frame on
  9905. * the list then insert the frame right after this frame
  9906. */
  9907. if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
  9908. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  9909. return seq_dmabuf;
  9910. }
  9911. }
  9912. return NULL;
  9913. }
  9914. /**
  9915. * lpfc_seq_complete - Indicates if a sequence is complete
  9916. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9917. *
  9918. * This function checks the sequence, starting with the frame described by
  9919. * @dmabuf, to see if all the frames associated with this sequence are present.
  9920. * the frames associated with this sequence are linked to the @dmabuf using the
  9921. * dbuf list. This function looks for two major things. 1) That the first frame
  9922. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  9923. * set. 3) That there are no holes in the sequence count. The function will
  9924. * return 1 when the sequence is complete, otherwise it will return 0.
  9925. **/
  9926. static int
  9927. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  9928. {
  9929. struct fc_frame_header *hdr;
  9930. struct lpfc_dmabuf *d_buf;
  9931. struct hbq_dmabuf *seq_dmabuf;
  9932. uint32_t fctl;
  9933. int seq_count = 0;
  9934. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9935. /* make sure first fame of sequence has a sequence count of zero */
  9936. if (hdr->fh_seq_cnt != seq_count)
  9937. return 0;
  9938. fctl = (hdr->fh_f_ctl[0] << 16 |
  9939. hdr->fh_f_ctl[1] << 8 |
  9940. hdr->fh_f_ctl[2]);
  9941. /* If last frame of sequence we can return success. */
  9942. if (fctl & FC_FC_END_SEQ)
  9943. return 1;
  9944. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  9945. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9946. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9947. /* If there is a hole in the sequence count then fail. */
  9948. if (++seq_count != hdr->fh_seq_cnt)
  9949. return 0;
  9950. fctl = (hdr->fh_f_ctl[0] << 16 |
  9951. hdr->fh_f_ctl[1] << 8 |
  9952. hdr->fh_f_ctl[2]);
  9953. /* If last frame of sequence we can return success. */
  9954. if (fctl & FC_FC_END_SEQ)
  9955. return 1;
  9956. }
  9957. return 0;
  9958. }
  9959. /**
  9960. * lpfc_prep_seq - Prep sequence for ULP processing
  9961. * @vport: Pointer to the vport on which this sequence was received
  9962. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9963. *
  9964. * This function takes a sequence, described by a list of frames, and creates
  9965. * a list of iocbq structures to describe the sequence. This iocbq list will be
  9966. * used to issue to the generic unsolicited sequence handler. This routine
  9967. * returns a pointer to the first iocbq in the list. If the function is unable
  9968. * to allocate an iocbq then it throw out the received frames that were not
  9969. * able to be described and return a pointer to the first iocbq. If unable to
  9970. * allocate any iocbqs (including the first) this function will return NULL.
  9971. **/
  9972. static struct lpfc_iocbq *
  9973. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  9974. {
  9975. struct lpfc_dmabuf *d_buf, *n_buf;
  9976. struct lpfc_iocbq *first_iocbq, *iocbq;
  9977. struct fc_frame_header *fc_hdr;
  9978. uint32_t sid;
  9979. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9980. /* remove from receive buffer list */
  9981. list_del_init(&seq_dmabuf->hbuf.list);
  9982. /* get the Remote Port's SID */
  9983. sid = (fc_hdr->fh_s_id[0] << 16 |
  9984. fc_hdr->fh_s_id[1] << 8 |
  9985. fc_hdr->fh_s_id[2]);
  9986. /* Get an iocbq struct to fill in. */
  9987. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  9988. if (first_iocbq) {
  9989. /* Initialize the first IOCB. */
  9990. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  9991. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  9992. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  9993. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  9994. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  9995. vport->vpi + vport->phba->vpi_base;
  9996. /* put the first buffer into the first IOCBq */
  9997. first_iocbq->context2 = &seq_dmabuf->dbuf;
  9998. first_iocbq->context3 = NULL;
  9999. first_iocbq->iocb.ulpBdeCount = 1;
  10000. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10001. LPFC_DATA_BUF_SIZE;
  10002. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10003. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10004. bf_get(lpfc_rcqe_length,
  10005. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10006. }
  10007. iocbq = first_iocbq;
  10008. /*
  10009. * Each IOCBq can have two Buffers assigned, so go through the list
  10010. * of buffers for this sequence and save two buffers in each IOCBq
  10011. */
  10012. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10013. if (!iocbq) {
  10014. lpfc_in_buf_free(vport->phba, d_buf);
  10015. continue;
  10016. }
  10017. if (!iocbq->context3) {
  10018. iocbq->context3 = d_buf;
  10019. iocbq->iocb.ulpBdeCount++;
  10020. iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
  10021. LPFC_DATA_BUF_SIZE;
  10022. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10023. bf_get(lpfc_rcqe_length,
  10024. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10025. } else {
  10026. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10027. if (!iocbq) {
  10028. if (first_iocbq) {
  10029. first_iocbq->iocb.ulpStatus =
  10030. IOSTAT_FCP_RSP_ERROR;
  10031. first_iocbq->iocb.un.ulpWord[4] =
  10032. IOERR_NO_RESOURCES;
  10033. }
  10034. lpfc_in_buf_free(vport->phba, d_buf);
  10035. continue;
  10036. }
  10037. iocbq->context2 = d_buf;
  10038. iocbq->context3 = NULL;
  10039. iocbq->iocb.ulpBdeCount = 1;
  10040. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10041. LPFC_DATA_BUF_SIZE;
  10042. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10043. bf_get(lpfc_rcqe_length,
  10044. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10045. iocbq->iocb.un.rcvels.remoteID = sid;
  10046. list_add_tail(&iocbq->list, &first_iocbq->list);
  10047. }
  10048. }
  10049. return first_iocbq;
  10050. }
  10051. /**
  10052. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10053. * @phba: Pointer to HBA context object.
  10054. *
  10055. * This function is called with no lock held. This function processes all
  10056. * the received buffers and gives it to upper layers when a received buffer
  10057. * indicates that it is the final frame in the sequence. The interrupt
  10058. * service routine processes received buffers at interrupt contexts and adds
  10059. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10060. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10061. * appropriate receive function when the final frame in a sequence is received.
  10062. **/
  10063. void
  10064. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10065. struct hbq_dmabuf *dmabuf)
  10066. {
  10067. struct hbq_dmabuf *seq_dmabuf;
  10068. struct fc_frame_header *fc_hdr;
  10069. struct lpfc_vport *vport;
  10070. uint32_t fcfi;
  10071. struct lpfc_iocbq *iocbq;
  10072. /* Clear hba flag and get all received buffers into the cmplq */
  10073. spin_lock_irq(&phba->hbalock);
  10074. phba->hba_flag &= ~HBA_RECEIVE_BUFFER;
  10075. spin_unlock_irq(&phba->hbalock);
  10076. /* Process each received buffer */
  10077. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10078. /* check to see if this a valid type of frame */
  10079. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10080. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10081. return;
  10082. }
  10083. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10084. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10085. if (!vport) {
  10086. /* throw out the frame */
  10087. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10088. return;
  10089. }
  10090. /* Link this frame */
  10091. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10092. if (!seq_dmabuf) {
  10093. /* unable to add frame to vport - throw it out */
  10094. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10095. return;
  10096. }
  10097. /* If not last frame in sequence continue processing frames. */
  10098. if (!lpfc_seq_complete(seq_dmabuf)) {
  10099. /*
  10100. * When saving off frames post a new one and mark this
  10101. * frame to be freed when it is finished.
  10102. **/
  10103. lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
  10104. dmabuf->tag = -1;
  10105. return;
  10106. }
  10107. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10108. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10109. if (!lpfc_complete_unsol_iocb(phba,
  10110. &phba->sli.ring[LPFC_ELS_RING],
  10111. iocbq, fc_hdr->fh_r_ctl,
  10112. fc_hdr->fh_type))
  10113. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10114. "2540 Ring %d handler: unexpected Rctl "
  10115. "x%x Type x%x received\n",
  10116. LPFC_ELS_RING,
  10117. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10118. }
  10119. /**
  10120. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10121. * @phba: pointer to lpfc hba data structure.
  10122. *
  10123. * This routine is invoked to post rpi header templates to the
  10124. * HBA consistent with the SLI-4 interface spec. This routine
  10125. * posts a PAGE_SIZE memory region to the port to hold up to
  10126. * PAGE_SIZE modulo 64 rpi context headers.
  10127. *
  10128. * This routine does not require any locks. It's usage is expected
  10129. * to be driver load or reset recovery when the driver is
  10130. * sequential.
  10131. *
  10132. * Return codes
  10133. * 0 - sucessful
  10134. * EIO - The mailbox failed to complete successfully.
  10135. * When this error occurs, the driver is not guaranteed
  10136. * to have any rpi regions posted to the device and
  10137. * must either attempt to repost the regions or take a
  10138. * fatal error.
  10139. **/
  10140. int
  10141. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10142. {
  10143. struct lpfc_rpi_hdr *rpi_page;
  10144. uint32_t rc = 0;
  10145. /* Post all rpi memory regions to the port. */
  10146. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10147. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10148. if (rc != MBX_SUCCESS) {
  10149. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10150. "2008 Error %d posting all rpi "
  10151. "headers\n", rc);
  10152. rc = -EIO;
  10153. break;
  10154. }
  10155. }
  10156. return rc;
  10157. }
  10158. /**
  10159. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10160. * @phba: pointer to lpfc hba data structure.
  10161. * @rpi_page: pointer to the rpi memory region.
  10162. *
  10163. * This routine is invoked to post a single rpi header to the
  10164. * HBA consistent with the SLI-4 interface spec. This memory region
  10165. * maps up to 64 rpi context regions.
  10166. *
  10167. * Return codes
  10168. * 0 - sucessful
  10169. * ENOMEM - No available memory
  10170. * EIO - The mailbox failed to complete successfully.
  10171. **/
  10172. int
  10173. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10174. {
  10175. LPFC_MBOXQ_t *mboxq;
  10176. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10177. uint32_t rc = 0;
  10178. uint32_t mbox_tmo;
  10179. uint32_t shdr_status, shdr_add_status;
  10180. union lpfc_sli4_cfg_shdr *shdr;
  10181. /* The port is notified of the header region via a mailbox command. */
  10182. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10183. if (!mboxq) {
  10184. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10185. "2001 Unable to allocate memory for issuing "
  10186. "SLI_CONFIG_SPECIAL mailbox command\n");
  10187. return -ENOMEM;
  10188. }
  10189. /* Post all rpi memory regions to the port. */
  10190. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10191. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10192. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10193. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10194. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10195. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10196. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10197. hdr_tmpl, rpi_page->page_count);
  10198. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10199. rpi_page->start_rpi);
  10200. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10201. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10202. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10203. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10204. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10205. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10206. if (rc != MBX_TIMEOUT)
  10207. mempool_free(mboxq, phba->mbox_mem_pool);
  10208. if (shdr_status || shdr_add_status || rc) {
  10209. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10210. "2514 POST_RPI_HDR mailbox failed with "
  10211. "status x%x add_status x%x, mbx status x%x\n",
  10212. shdr_status, shdr_add_status, rc);
  10213. rc = -ENXIO;
  10214. }
  10215. return rc;
  10216. }
  10217. /**
  10218. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10219. * @phba: pointer to lpfc hba data structure.
  10220. *
  10221. * This routine is invoked to post rpi header templates to the
  10222. * HBA consistent with the SLI-4 interface spec. This routine
  10223. * posts a PAGE_SIZE memory region to the port to hold up to
  10224. * PAGE_SIZE modulo 64 rpi context headers.
  10225. *
  10226. * Returns
  10227. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
  10228. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10229. **/
  10230. int
  10231. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10232. {
  10233. int rpi;
  10234. uint16_t max_rpi, rpi_base, rpi_limit;
  10235. uint16_t rpi_remaining;
  10236. struct lpfc_rpi_hdr *rpi_hdr;
  10237. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10238. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10239. rpi_limit = phba->sli4_hba.next_rpi;
  10240. /*
  10241. * The valid rpi range is not guaranteed to be zero-based. Start
  10242. * the search at the rpi_base as reported by the port.
  10243. */
  10244. spin_lock_irq(&phba->hbalock);
  10245. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10246. if (rpi >= rpi_limit || rpi < rpi_base)
  10247. rpi = LPFC_RPI_ALLOC_ERROR;
  10248. else {
  10249. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10250. phba->sli4_hba.max_cfg_param.rpi_used++;
  10251. phba->sli4_hba.rpi_count++;
  10252. }
  10253. /*
  10254. * Don't try to allocate more rpi header regions if the device limit
  10255. * on available rpis max has been exhausted.
  10256. */
  10257. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10258. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10259. spin_unlock_irq(&phba->hbalock);
  10260. return rpi;
  10261. }
  10262. /*
  10263. * If the driver is running low on rpi resources, allocate another
  10264. * page now. Note that the next_rpi value is used because
  10265. * it represents how many are actually in use whereas max_rpi notes
  10266. * how many are supported max by the device.
  10267. */
  10268. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10269. phba->sli4_hba.rpi_count;
  10270. spin_unlock_irq(&phba->hbalock);
  10271. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10272. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10273. if (!rpi_hdr) {
  10274. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10275. "2002 Error Could not grow rpi "
  10276. "count\n");
  10277. } else {
  10278. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10279. }
  10280. }
  10281. return rpi;
  10282. }
  10283. /**
  10284. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10285. * @phba: pointer to lpfc hba data structure.
  10286. *
  10287. * This routine is invoked to release an rpi to the pool of
  10288. * available rpis maintained by the driver.
  10289. **/
  10290. void
  10291. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10292. {
  10293. spin_lock_irq(&phba->hbalock);
  10294. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10295. phba->sli4_hba.rpi_count--;
  10296. phba->sli4_hba.max_cfg_param.rpi_used--;
  10297. spin_unlock_irq(&phba->hbalock);
  10298. }
  10299. /**
  10300. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10301. * @phba: pointer to lpfc hba data structure.
  10302. *
  10303. * This routine is invoked to remove the memory region that
  10304. * provided rpi via a bitmask.
  10305. **/
  10306. void
  10307. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10308. {
  10309. kfree(phba->sli4_hba.rpi_bmask);
  10310. }
  10311. /**
  10312. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10313. * @phba: pointer to lpfc hba data structure.
  10314. *
  10315. * This routine is invoked to remove the memory region that
  10316. * provided rpi via a bitmask.
  10317. **/
  10318. int
  10319. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10320. {
  10321. LPFC_MBOXQ_t *mboxq;
  10322. struct lpfc_hba *phba = ndlp->phba;
  10323. int rc;
  10324. /* The port is notified of the header region via a mailbox command. */
  10325. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10326. if (!mboxq)
  10327. return -ENOMEM;
  10328. /* Post all rpi memory regions to the port. */
  10329. lpfc_resume_rpi(mboxq, ndlp);
  10330. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10331. if (rc == MBX_NOT_FINISHED) {
  10332. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10333. "2010 Resume RPI Mailbox failed "
  10334. "status %d, mbxStatus x%x\n", rc,
  10335. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10336. mempool_free(mboxq, phba->mbox_mem_pool);
  10337. return -EIO;
  10338. }
  10339. return 0;
  10340. }
  10341. /**
  10342. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10343. * @phba: pointer to lpfc hba data structure.
  10344. * @vpi: vpi value to activate with the port.
  10345. *
  10346. * This routine is invoked to activate a vpi with the
  10347. * port when the host intends to use vports with a
  10348. * nonzero vpi.
  10349. *
  10350. * Returns:
  10351. * 0 success
  10352. * -Evalue otherwise
  10353. **/
  10354. int
  10355. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10356. {
  10357. LPFC_MBOXQ_t *mboxq;
  10358. int rc = 0;
  10359. uint32_t mbox_tmo;
  10360. if (vpi == 0)
  10361. return -EINVAL;
  10362. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10363. if (!mboxq)
  10364. return -ENOMEM;
  10365. lpfc_init_vpi(phba, mboxq, vpi);
  10366. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10367. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10368. if (rc != MBX_TIMEOUT)
  10369. mempool_free(mboxq, phba->mbox_mem_pool);
  10370. if (rc != MBX_SUCCESS) {
  10371. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10372. "2022 INIT VPI Mailbox failed "
  10373. "status %d, mbxStatus x%x\n", rc,
  10374. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10375. rc = -EIO;
  10376. }
  10377. return rc;
  10378. }
  10379. /**
  10380. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10381. * @phba: pointer to lpfc hba data structure.
  10382. * @mboxq: Pointer to mailbox object.
  10383. *
  10384. * This routine is invoked to manually add a single FCF record. The caller
  10385. * must pass a completely initialized FCF_Record. This routine takes
  10386. * care of the nonembedded mailbox operations.
  10387. **/
  10388. static void
  10389. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10390. {
  10391. void *virt_addr;
  10392. union lpfc_sli4_cfg_shdr *shdr;
  10393. uint32_t shdr_status, shdr_add_status;
  10394. virt_addr = mboxq->sge_array->addr[0];
  10395. /* The IOCTL status is embedded in the mailbox subheader. */
  10396. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10397. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10398. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10399. if ((shdr_status || shdr_add_status) &&
  10400. (shdr_status != STATUS_FCF_IN_USE))
  10401. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10402. "2558 ADD_FCF_RECORD mailbox failed with "
  10403. "status x%x add_status x%x\n",
  10404. shdr_status, shdr_add_status);
  10405. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10406. }
  10407. /**
  10408. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10409. * @phba: pointer to lpfc hba data structure.
  10410. * @fcf_record: pointer to the initialized fcf record to add.
  10411. *
  10412. * This routine is invoked to manually add a single FCF record. The caller
  10413. * must pass a completely initialized FCF_Record. This routine takes
  10414. * care of the nonembedded mailbox operations.
  10415. **/
  10416. int
  10417. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10418. {
  10419. int rc = 0;
  10420. LPFC_MBOXQ_t *mboxq;
  10421. uint8_t *bytep;
  10422. void *virt_addr;
  10423. dma_addr_t phys_addr;
  10424. struct lpfc_mbx_sge sge;
  10425. uint32_t alloc_len, req_len;
  10426. uint32_t fcfindex;
  10427. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10428. if (!mboxq) {
  10429. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10430. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10431. return -ENOMEM;
  10432. }
  10433. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10434. sizeof(uint32_t);
  10435. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10436. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10437. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10438. req_len, LPFC_SLI4_MBX_NEMBED);
  10439. if (alloc_len < req_len) {
  10440. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10441. "2523 Allocated DMA memory size (x%x) is "
  10442. "less than the requested DMA memory "
  10443. "size (x%x)\n", alloc_len, req_len);
  10444. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10445. return -ENOMEM;
  10446. }
  10447. /*
  10448. * Get the first SGE entry from the non-embedded DMA memory. This
  10449. * routine only uses a single SGE.
  10450. */
  10451. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10452. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10453. if (unlikely(!mboxq->sge_array)) {
  10454. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10455. "2526 Failed to get the non-embedded SGE "
  10456. "virtual address\n");
  10457. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10458. return -ENOMEM;
  10459. }
  10460. virt_addr = mboxq->sge_array->addr[0];
  10461. /*
  10462. * Configure the FCF record for FCFI 0. This is the driver's
  10463. * hardcoded default and gets used in nonFIP mode.
  10464. */
  10465. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10466. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10467. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10468. /*
  10469. * Copy the fcf_index and the FCF Record Data. The data starts after
  10470. * the FCoE header plus word10. The data copy needs to be endian
  10471. * correct.
  10472. */
  10473. bytep += sizeof(uint32_t);
  10474. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10475. mboxq->vport = phba->pport;
  10476. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10477. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10478. if (rc == MBX_NOT_FINISHED) {
  10479. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10480. "2515 ADD_FCF_RECORD mailbox failed with "
  10481. "status 0x%x\n", rc);
  10482. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10483. rc = -EIO;
  10484. } else
  10485. rc = 0;
  10486. return rc;
  10487. }
  10488. /**
  10489. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10490. * @phba: pointer to lpfc hba data structure.
  10491. * @fcf_record: pointer to the fcf record to write the default data.
  10492. * @fcf_index: FCF table entry index.
  10493. *
  10494. * This routine is invoked to build the driver's default FCF record. The
  10495. * values used are hardcoded. This routine handles memory initialization.
  10496. *
  10497. **/
  10498. void
  10499. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10500. struct fcf_record *fcf_record,
  10501. uint16_t fcf_index)
  10502. {
  10503. memset(fcf_record, 0, sizeof(struct fcf_record));
  10504. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10505. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10506. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10507. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10508. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10509. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10510. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10511. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10512. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10513. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10514. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10515. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10516. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10517. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10518. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10519. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10520. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10521. /* Set the VLAN bit map */
  10522. if (phba->valid_vlan) {
  10523. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10524. = 1 << (phba->vlan_id % 8);
  10525. }
  10526. }
  10527. /**
  10528. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10529. * @phba: pointer to lpfc hba data structure.
  10530. * @fcf_index: FCF table entry offset.
  10531. *
  10532. * This routine is invoked to read up to @fcf_num of FCF record from the
  10533. * device starting with the given @fcf_index.
  10534. **/
  10535. int
  10536. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10537. {
  10538. int rc = 0, error;
  10539. LPFC_MBOXQ_t *mboxq;
  10540. void *virt_addr;
  10541. dma_addr_t phys_addr;
  10542. uint8_t *bytep;
  10543. struct lpfc_mbx_sge sge;
  10544. uint32_t alloc_len, req_len;
  10545. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10546. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10547. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10548. if (!mboxq) {
  10549. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10550. "2000 Failed to allocate mbox for "
  10551. "READ_FCF cmd\n");
  10552. error = -ENOMEM;
  10553. goto fail_fcfscan;
  10554. }
  10555. req_len = sizeof(struct fcf_record) +
  10556. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10557. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10558. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10559. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10560. LPFC_SLI4_MBX_NEMBED);
  10561. if (alloc_len < req_len) {
  10562. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10563. "0291 Allocated DMA memory size (x%x) is "
  10564. "less than the requested DMA memory "
  10565. "size (x%x)\n", alloc_len, req_len);
  10566. error = -ENOMEM;
  10567. goto fail_fcfscan;
  10568. }
  10569. /* Get the first SGE entry from the non-embedded DMA memory. This
  10570. * routine only uses a single SGE.
  10571. */
  10572. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10573. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10574. if (unlikely(!mboxq->sge_array)) {
  10575. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10576. "2527 Failed to get the non-embedded SGE "
  10577. "virtual address\n");
  10578. error = -ENOMEM;
  10579. goto fail_fcfscan;
  10580. }
  10581. virt_addr = mboxq->sge_array->addr[0];
  10582. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10583. /* Set up command fields */
  10584. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10585. /* Perform necessary endian conversion */
  10586. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10587. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10588. mboxq->vport = phba->pport;
  10589. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10590. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10591. if (rc == MBX_NOT_FINISHED) {
  10592. error = -EIO;
  10593. } else {
  10594. spin_lock_irq(&phba->hbalock);
  10595. phba->hba_flag |= FCF_DISC_INPROGRESS;
  10596. spin_unlock_irq(&phba->hbalock);
  10597. error = 0;
  10598. }
  10599. fail_fcfscan:
  10600. if (error) {
  10601. if (mboxq)
  10602. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10603. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  10604. spin_lock_irq(&phba->hbalock);
  10605. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  10606. spin_unlock_irq(&phba->hbalock);
  10607. }
  10608. return error;
  10609. }
  10610. /**
  10611. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  10612. * @phba: pointer to lpfc hba data structure.
  10613. *
  10614. * This function read region 23 and parse TLV for port status to
  10615. * decide if the user disaled the port. If the TLV indicates the
  10616. * port is disabled, the hba_flag is set accordingly.
  10617. **/
  10618. void
  10619. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  10620. {
  10621. LPFC_MBOXQ_t *pmb = NULL;
  10622. MAILBOX_t *mb;
  10623. uint8_t *rgn23_data = NULL;
  10624. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  10625. int rc;
  10626. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10627. if (!pmb) {
  10628. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10629. "2600 lpfc_sli_read_serdes_param failed to"
  10630. " allocate mailbox memory\n");
  10631. goto out;
  10632. }
  10633. mb = &pmb->u.mb;
  10634. /* Get adapter Region 23 data */
  10635. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  10636. if (!rgn23_data)
  10637. goto out;
  10638. do {
  10639. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  10640. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  10641. if (rc != MBX_SUCCESS) {
  10642. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10643. "2601 lpfc_sli_read_link_ste failed to"
  10644. " read config region 23 rc 0x%x Status 0x%x\n",
  10645. rc, mb->mbxStatus);
  10646. mb->un.varDmp.word_cnt = 0;
  10647. }
  10648. /*
  10649. * dump mem may return a zero when finished or we got a
  10650. * mailbox error, either way we are done.
  10651. */
  10652. if (mb->un.varDmp.word_cnt == 0)
  10653. break;
  10654. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  10655. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  10656. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  10657. rgn23_data + offset,
  10658. mb->un.varDmp.word_cnt);
  10659. offset += mb->un.varDmp.word_cnt;
  10660. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  10661. data_size = offset;
  10662. offset = 0;
  10663. if (!data_size)
  10664. goto out;
  10665. /* Check the region signature first */
  10666. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  10667. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10668. "2619 Config region 23 has bad signature\n");
  10669. goto out;
  10670. }
  10671. offset += 4;
  10672. /* Check the data structure version */
  10673. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  10674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10675. "2620 Config region 23 has bad version\n");
  10676. goto out;
  10677. }
  10678. offset += 4;
  10679. /* Parse TLV entries in the region */
  10680. while (offset < data_size) {
  10681. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  10682. break;
  10683. /*
  10684. * If the TLV is not driver specific TLV or driver id is
  10685. * not linux driver id, skip the record.
  10686. */
  10687. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  10688. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  10689. (rgn23_data[offset + 3] != 0)) {
  10690. offset += rgn23_data[offset + 1] * 4 + 4;
  10691. continue;
  10692. }
  10693. /* Driver found a driver specific TLV in the config region */
  10694. sub_tlv_len = rgn23_data[offset + 1] * 4;
  10695. offset += 4;
  10696. tlv_offset = 0;
  10697. /*
  10698. * Search for configured port state sub-TLV.
  10699. */
  10700. while ((offset < data_size) &&
  10701. (tlv_offset < sub_tlv_len)) {
  10702. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  10703. offset += 4;
  10704. tlv_offset += 4;
  10705. break;
  10706. }
  10707. if (rgn23_data[offset] != PORT_STE_TYPE) {
  10708. offset += rgn23_data[offset + 1] * 4 + 4;
  10709. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  10710. continue;
  10711. }
  10712. /* This HBA contains PORT_STE configured */
  10713. if (!rgn23_data[offset + 2])
  10714. phba->hba_flag |= LINK_DISABLED;
  10715. goto out;
  10716. }
  10717. }
  10718. out:
  10719. if (pmb)
  10720. mempool_free(pmb, phba->mbox_mem_pool);
  10721. kfree(rgn23_data);
  10722. return;
  10723. }