lpfc_sli.c 392 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697
  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 <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. return iocbq;
  419. }
  420. /**
  421. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  422. * @phba: Pointer to HBA context object.
  423. * @xritag: XRI value.
  424. *
  425. * This function clears the sglq pointer from the array of acive
  426. * sglq's. The xritag that is passed in is used to index into the
  427. * array. Before the xritag can be used it needs to be adjusted
  428. * by subtracting the xribase.
  429. *
  430. * Returns sglq ponter = success, NULL = Failure.
  431. **/
  432. static struct lpfc_sglq *
  433. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  434. {
  435. uint16_t adj_xri;
  436. struct lpfc_sglq *sglq;
  437. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  438. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  439. return NULL;
  440. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  441. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  442. return sglq;
  443. }
  444. /**
  445. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  446. * @phba: Pointer to HBA context object.
  447. * @xritag: XRI value.
  448. *
  449. * This function returns the sglq pointer from the array of acive
  450. * sglq's. The xritag that is passed in is used to index into the
  451. * array. Before the xritag can be used it needs to be adjusted
  452. * by subtracting the xribase.
  453. *
  454. * Returns sglq ponter = success, NULL = Failure.
  455. **/
  456. struct lpfc_sglq *
  457. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  458. {
  459. uint16_t adj_xri;
  460. struct lpfc_sglq *sglq;
  461. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  462. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  463. return NULL;
  464. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  465. return sglq;
  466. }
  467. /**
  468. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  469. * @phba: Pointer to HBA context object.
  470. *
  471. * This function is called with hbalock held. This function
  472. * Gets a new driver sglq object from the sglq list. If the
  473. * list is not empty then it is successful, it returns pointer to the newly
  474. * allocated sglq object else it returns NULL.
  475. **/
  476. static struct lpfc_sglq *
  477. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  478. {
  479. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  480. struct lpfc_sglq *sglq = NULL;
  481. uint16_t adj_xri;
  482. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  483. if (!sglq)
  484. return NULL;
  485. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  486. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  487. sglq->state = SGL_ALLOCATED;
  488. return sglq;
  489. }
  490. /**
  491. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  492. * @phba: Pointer to HBA context object.
  493. *
  494. * This function is called with no lock held. This function
  495. * allocates a new driver iocb object from the iocb pool. If the
  496. * allocation is successful, it returns pointer to the newly
  497. * allocated iocb object else it returns NULL.
  498. **/
  499. struct lpfc_iocbq *
  500. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  501. {
  502. struct lpfc_iocbq * iocbq = NULL;
  503. unsigned long iflags;
  504. spin_lock_irqsave(&phba->hbalock, iflags);
  505. iocbq = __lpfc_sli_get_iocbq(phba);
  506. spin_unlock_irqrestore(&phba->hbalock, iflags);
  507. return iocbq;
  508. }
  509. /**
  510. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  511. * @phba: Pointer to HBA context object.
  512. * @iocbq: Pointer to driver iocb object.
  513. *
  514. * This function is called with hbalock held to release driver
  515. * iocb object to the iocb pool. The iotag in the iocb object
  516. * does not change for each use of the iocb object. This function
  517. * clears all other fields of the iocb object when it is freed.
  518. * The sqlq structure that holds the xritag and phys and virtual
  519. * mappings for the scatter gather list is retrieved from the
  520. * active array of sglq. The get of the sglq pointer also clears
  521. * the entry in the array. If the status of the IO indiactes that
  522. * this IO was aborted then the sglq entry it put on the
  523. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  524. * IO has good status or fails for any other reason then the sglq
  525. * entry is added to the free list (lpfc_sgl_list).
  526. **/
  527. static void
  528. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  529. {
  530. struct lpfc_sglq *sglq;
  531. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  532. unsigned long iflag;
  533. if (iocbq->sli4_xritag == NO_XRI)
  534. sglq = NULL;
  535. else
  536. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  537. if (sglq) {
  538. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  539. (sglq->state != SGL_XRI_ABORTED)) {
  540. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  541. iflag);
  542. list_add(&sglq->list,
  543. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  544. spin_unlock_irqrestore(
  545. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  546. } else {
  547. sglq->state = SGL_FREED;
  548. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  549. }
  550. }
  551. /*
  552. * Clean all volatile data fields, preserve iotag and node struct.
  553. */
  554. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  555. iocbq->sli4_xritag = NO_XRI;
  556. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  557. }
  558. /**
  559. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  560. * @phba: Pointer to HBA context object.
  561. * @iocbq: Pointer to driver iocb object.
  562. *
  563. * This function is called with hbalock held to release driver
  564. * iocb object to the iocb pool. The iotag in the iocb object
  565. * does not change for each use of the iocb object. This function
  566. * clears all other fields of the iocb object when it is freed.
  567. **/
  568. static void
  569. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  570. {
  571. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  572. /*
  573. * Clean all volatile data fields, preserve iotag and node struct.
  574. */
  575. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  576. iocbq->sli4_xritag = NO_XRI;
  577. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  578. }
  579. /**
  580. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  581. * @phba: Pointer to HBA context object.
  582. * @iocbq: Pointer to driver iocb object.
  583. *
  584. * This function is called with hbalock held to release driver
  585. * iocb object to the iocb pool. The iotag in the iocb object
  586. * does not change for each use of the iocb object. This function
  587. * clears all other fields of the iocb object when it is freed.
  588. **/
  589. static void
  590. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  591. {
  592. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  593. }
  594. /**
  595. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  596. * @phba: Pointer to HBA context object.
  597. * @iocbq: Pointer to driver iocb object.
  598. *
  599. * This function is called with no lock held to release the iocb to
  600. * iocb pool.
  601. **/
  602. void
  603. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  604. {
  605. unsigned long iflags;
  606. /*
  607. * Clean all volatile data fields, preserve iotag and node struct.
  608. */
  609. spin_lock_irqsave(&phba->hbalock, iflags);
  610. __lpfc_sli_release_iocbq(phba, iocbq);
  611. spin_unlock_irqrestore(&phba->hbalock, iflags);
  612. }
  613. /**
  614. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  615. * @phba: Pointer to HBA context object.
  616. * @iocblist: List of IOCBs.
  617. * @ulpstatus: ULP status in IOCB command field.
  618. * @ulpWord4: ULP word-4 in IOCB command field.
  619. *
  620. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  621. * on the list by invoking the complete callback function associated with the
  622. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  623. * fields.
  624. **/
  625. void
  626. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  627. uint32_t ulpstatus, uint32_t ulpWord4)
  628. {
  629. struct lpfc_iocbq *piocb;
  630. while (!list_empty(iocblist)) {
  631. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  632. if (!piocb->iocb_cmpl)
  633. lpfc_sli_release_iocbq(phba, piocb);
  634. else {
  635. piocb->iocb.ulpStatus = ulpstatus;
  636. piocb->iocb.un.ulpWord[4] = ulpWord4;
  637. (piocb->iocb_cmpl) (phba, piocb, piocb);
  638. }
  639. }
  640. return;
  641. }
  642. /**
  643. * lpfc_sli_iocb_cmd_type - Get the iocb type
  644. * @iocb_cmnd: iocb command code.
  645. *
  646. * This function is called by ring event handler function to get the iocb type.
  647. * This function translates the iocb command to an iocb command type used to
  648. * decide the final disposition of each completed IOCB.
  649. * The function returns
  650. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  651. * LPFC_SOL_IOCB if it is a solicited iocb completion
  652. * LPFC_ABORT_IOCB if it is an abort iocb
  653. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  654. *
  655. * The caller is not required to hold any lock.
  656. **/
  657. static lpfc_iocb_type
  658. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  659. {
  660. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  661. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  662. return 0;
  663. switch (iocb_cmnd) {
  664. case CMD_XMIT_SEQUENCE_CR:
  665. case CMD_XMIT_SEQUENCE_CX:
  666. case CMD_XMIT_BCAST_CN:
  667. case CMD_XMIT_BCAST_CX:
  668. case CMD_ELS_REQUEST_CR:
  669. case CMD_ELS_REQUEST_CX:
  670. case CMD_CREATE_XRI_CR:
  671. case CMD_CREATE_XRI_CX:
  672. case CMD_GET_RPI_CN:
  673. case CMD_XMIT_ELS_RSP_CX:
  674. case CMD_GET_RPI_CR:
  675. case CMD_FCP_IWRITE_CR:
  676. case CMD_FCP_IWRITE_CX:
  677. case CMD_FCP_IREAD_CR:
  678. case CMD_FCP_IREAD_CX:
  679. case CMD_FCP_ICMND_CR:
  680. case CMD_FCP_ICMND_CX:
  681. case CMD_FCP_TSEND_CX:
  682. case CMD_FCP_TRSP_CX:
  683. case CMD_FCP_TRECEIVE_CX:
  684. case CMD_FCP_AUTO_TRSP_CX:
  685. case CMD_ADAPTER_MSG:
  686. case CMD_ADAPTER_DUMP:
  687. case CMD_XMIT_SEQUENCE64_CR:
  688. case CMD_XMIT_SEQUENCE64_CX:
  689. case CMD_XMIT_BCAST64_CN:
  690. case CMD_XMIT_BCAST64_CX:
  691. case CMD_ELS_REQUEST64_CR:
  692. case CMD_ELS_REQUEST64_CX:
  693. case CMD_FCP_IWRITE64_CR:
  694. case CMD_FCP_IWRITE64_CX:
  695. case CMD_FCP_IREAD64_CR:
  696. case CMD_FCP_IREAD64_CX:
  697. case CMD_FCP_ICMND64_CR:
  698. case CMD_FCP_ICMND64_CX:
  699. case CMD_FCP_TSEND64_CX:
  700. case CMD_FCP_TRSP64_CX:
  701. case CMD_FCP_TRECEIVE64_CX:
  702. case CMD_GEN_REQUEST64_CR:
  703. case CMD_GEN_REQUEST64_CX:
  704. case CMD_XMIT_ELS_RSP64_CX:
  705. case DSSCMD_IWRITE64_CR:
  706. case DSSCMD_IWRITE64_CX:
  707. case DSSCMD_IREAD64_CR:
  708. case DSSCMD_IREAD64_CX:
  709. type = LPFC_SOL_IOCB;
  710. break;
  711. case CMD_ABORT_XRI_CN:
  712. case CMD_ABORT_XRI_CX:
  713. case CMD_CLOSE_XRI_CN:
  714. case CMD_CLOSE_XRI_CX:
  715. case CMD_XRI_ABORTED_CX:
  716. case CMD_ABORT_MXRI64_CN:
  717. case CMD_XMIT_BLS_RSP64_CX:
  718. type = LPFC_ABORT_IOCB;
  719. break;
  720. case CMD_RCV_SEQUENCE_CX:
  721. case CMD_RCV_ELS_REQ_CX:
  722. case CMD_RCV_SEQUENCE64_CX:
  723. case CMD_RCV_ELS_REQ64_CX:
  724. case CMD_ASYNC_STATUS:
  725. case CMD_IOCB_RCV_SEQ64_CX:
  726. case CMD_IOCB_RCV_ELS64_CX:
  727. case CMD_IOCB_RCV_CONT64_CX:
  728. case CMD_IOCB_RET_XRI64_CX:
  729. type = LPFC_UNSOL_IOCB;
  730. break;
  731. case CMD_IOCB_XMIT_MSEQ64_CR:
  732. case CMD_IOCB_XMIT_MSEQ64_CX:
  733. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  734. case CMD_IOCB_RCV_ELS_LIST64_CX:
  735. case CMD_IOCB_CLOSE_EXTENDED_CN:
  736. case CMD_IOCB_ABORT_EXTENDED_CN:
  737. case CMD_IOCB_RET_HBQE64_CN:
  738. case CMD_IOCB_FCP_IBIDIR64_CR:
  739. case CMD_IOCB_FCP_IBIDIR64_CX:
  740. case CMD_IOCB_FCP_ITASKMGT64_CX:
  741. case CMD_IOCB_LOGENTRY_CN:
  742. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  743. printk("%s - Unhandled SLI-3 Command x%x\n",
  744. __func__, iocb_cmnd);
  745. type = LPFC_UNKNOWN_IOCB;
  746. break;
  747. default:
  748. type = LPFC_UNKNOWN_IOCB;
  749. break;
  750. }
  751. return type;
  752. }
  753. /**
  754. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  755. * @phba: Pointer to HBA context object.
  756. *
  757. * This function is called from SLI initialization code
  758. * to configure every ring of the HBA's SLI interface. The
  759. * caller is not required to hold any lock. This function issues
  760. * a config_ring mailbox command for each ring.
  761. * This function returns zero if successful else returns a negative
  762. * error code.
  763. **/
  764. static int
  765. lpfc_sli_ring_map(struct lpfc_hba *phba)
  766. {
  767. struct lpfc_sli *psli = &phba->sli;
  768. LPFC_MBOXQ_t *pmb;
  769. MAILBOX_t *pmbox;
  770. int i, rc, ret = 0;
  771. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  772. if (!pmb)
  773. return -ENOMEM;
  774. pmbox = &pmb->u.mb;
  775. phba->link_state = LPFC_INIT_MBX_CMDS;
  776. for (i = 0; i < psli->num_rings; i++) {
  777. lpfc_config_ring(phba, i, pmb);
  778. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  779. if (rc != MBX_SUCCESS) {
  780. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  781. "0446 Adapter failed to init (%d), "
  782. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  783. "ring %d\n",
  784. rc, pmbox->mbxCommand,
  785. pmbox->mbxStatus, i);
  786. phba->link_state = LPFC_HBA_ERROR;
  787. ret = -ENXIO;
  788. break;
  789. }
  790. }
  791. mempool_free(pmb, phba->mbox_mem_pool);
  792. return ret;
  793. }
  794. /**
  795. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  796. * @phba: Pointer to HBA context object.
  797. * @pring: Pointer to driver SLI ring object.
  798. * @piocb: Pointer to the driver iocb object.
  799. *
  800. * This function is called with hbalock held. The function adds the
  801. * new iocb to txcmplq of the given ring. This function always returns
  802. * 0. If this function is called for ELS ring, this function checks if
  803. * there is a vport associated with the ELS command. This function also
  804. * starts els_tmofunc timer if this is an ELS command.
  805. **/
  806. static int
  807. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  808. struct lpfc_iocbq *piocb)
  809. {
  810. list_add_tail(&piocb->list, &pring->txcmplq);
  811. pring->txcmplq_cnt++;
  812. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  813. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  814. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  815. if (!piocb->vport)
  816. BUG();
  817. else
  818. mod_timer(&piocb->vport->els_tmofunc,
  819. jiffies + HZ * (phba->fc_ratov << 1));
  820. }
  821. return 0;
  822. }
  823. /**
  824. * lpfc_sli_ringtx_get - Get first element of the txq
  825. * @phba: Pointer to HBA context object.
  826. * @pring: Pointer to driver SLI ring object.
  827. *
  828. * This function is called with hbalock held to get next
  829. * iocb in txq of the given ring. If there is any iocb in
  830. * the txq, the function returns first iocb in the list after
  831. * removing the iocb from the list, else it returns NULL.
  832. **/
  833. static struct lpfc_iocbq *
  834. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  835. {
  836. struct lpfc_iocbq *cmd_iocb;
  837. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  838. if (cmd_iocb != NULL)
  839. pring->txq_cnt--;
  840. return cmd_iocb;
  841. }
  842. /**
  843. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  844. * @phba: Pointer to HBA context object.
  845. * @pring: Pointer to driver SLI ring object.
  846. *
  847. * This function is called with hbalock held and the caller must post the
  848. * iocb without releasing the lock. If the caller releases the lock,
  849. * iocb slot returned by the function is not guaranteed to be available.
  850. * The function returns pointer to the next available iocb slot if there
  851. * is available slot in the ring, else it returns NULL.
  852. * If the get index of the ring is ahead of the put index, the function
  853. * will post an error attention event to the worker thread to take the
  854. * HBA to offline state.
  855. **/
  856. static IOCB_t *
  857. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  858. {
  859. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  860. uint32_t max_cmd_idx = pring->numCiocb;
  861. if ((pring->next_cmdidx == pring->cmdidx) &&
  862. (++pring->next_cmdidx >= max_cmd_idx))
  863. pring->next_cmdidx = 0;
  864. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  865. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  866. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  867. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  868. "0315 Ring %d issue: portCmdGet %d "
  869. "is bigger than cmd ring %d\n",
  870. pring->ringno,
  871. pring->local_getidx, max_cmd_idx);
  872. phba->link_state = LPFC_HBA_ERROR;
  873. /*
  874. * All error attention handlers are posted to
  875. * worker thread
  876. */
  877. phba->work_ha |= HA_ERATT;
  878. phba->work_hs = HS_FFER3;
  879. lpfc_worker_wake_up(phba);
  880. return NULL;
  881. }
  882. if (pring->local_getidx == pring->next_cmdidx)
  883. return NULL;
  884. }
  885. return lpfc_cmd_iocb(phba, pring);
  886. }
  887. /**
  888. * lpfc_sli_next_iotag - Get an iotag for the iocb
  889. * @phba: Pointer to HBA context object.
  890. * @iocbq: Pointer to driver iocb object.
  891. *
  892. * This function gets an iotag for the iocb. If there is no unused iotag and
  893. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  894. * array and assigns a new iotag.
  895. * The function returns the allocated iotag if successful, else returns zero.
  896. * Zero is not a valid iotag.
  897. * The caller is not required to hold any lock.
  898. **/
  899. uint16_t
  900. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  901. {
  902. struct lpfc_iocbq **new_arr;
  903. struct lpfc_iocbq **old_arr;
  904. size_t new_len;
  905. struct lpfc_sli *psli = &phba->sli;
  906. uint16_t iotag;
  907. spin_lock_irq(&phba->hbalock);
  908. iotag = psli->last_iotag;
  909. if(++iotag < psli->iocbq_lookup_len) {
  910. psli->last_iotag = iotag;
  911. psli->iocbq_lookup[iotag] = iocbq;
  912. spin_unlock_irq(&phba->hbalock);
  913. iocbq->iotag = iotag;
  914. return iotag;
  915. } else if (psli->iocbq_lookup_len < (0xffff
  916. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  917. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  918. spin_unlock_irq(&phba->hbalock);
  919. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  920. GFP_KERNEL);
  921. if (new_arr) {
  922. spin_lock_irq(&phba->hbalock);
  923. old_arr = psli->iocbq_lookup;
  924. if (new_len <= psli->iocbq_lookup_len) {
  925. /* highly unprobable case */
  926. kfree(new_arr);
  927. iotag = psli->last_iotag;
  928. if(++iotag < psli->iocbq_lookup_len) {
  929. psli->last_iotag = iotag;
  930. psli->iocbq_lookup[iotag] = iocbq;
  931. spin_unlock_irq(&phba->hbalock);
  932. iocbq->iotag = iotag;
  933. return iotag;
  934. }
  935. spin_unlock_irq(&phba->hbalock);
  936. return 0;
  937. }
  938. if (psli->iocbq_lookup)
  939. memcpy(new_arr, old_arr,
  940. ((psli->last_iotag + 1) *
  941. sizeof (struct lpfc_iocbq *)));
  942. psli->iocbq_lookup = new_arr;
  943. psli->iocbq_lookup_len = new_len;
  944. psli->last_iotag = iotag;
  945. psli->iocbq_lookup[iotag] = iocbq;
  946. spin_unlock_irq(&phba->hbalock);
  947. iocbq->iotag = iotag;
  948. kfree(old_arr);
  949. return iotag;
  950. }
  951. } else
  952. spin_unlock_irq(&phba->hbalock);
  953. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  954. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  955. psli->last_iotag);
  956. return 0;
  957. }
  958. /**
  959. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  960. * @phba: Pointer to HBA context object.
  961. * @pring: Pointer to driver SLI ring object.
  962. * @iocb: Pointer to iocb slot in the ring.
  963. * @nextiocb: Pointer to driver iocb object which need to be
  964. * posted to firmware.
  965. *
  966. * This function is called with hbalock held to post a new iocb to
  967. * the firmware. This function copies the new iocb to ring iocb slot and
  968. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  969. * a completion call back for this iocb else the function will free the
  970. * iocb object.
  971. **/
  972. static void
  973. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  974. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  975. {
  976. /*
  977. * Set up an iotag
  978. */
  979. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  980. if (pring->ringno == LPFC_ELS_RING) {
  981. lpfc_debugfs_slow_ring_trc(phba,
  982. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  983. *(((uint32_t *) &nextiocb->iocb) + 4),
  984. *(((uint32_t *) &nextiocb->iocb) + 6),
  985. *(((uint32_t *) &nextiocb->iocb) + 7));
  986. }
  987. /*
  988. * Issue iocb command to adapter
  989. */
  990. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  991. wmb();
  992. pring->stats.iocb_cmd++;
  993. /*
  994. * If there is no completion routine to call, we can release the
  995. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  996. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  997. */
  998. if (nextiocb->iocb_cmpl)
  999. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1000. else
  1001. __lpfc_sli_release_iocbq(phba, nextiocb);
  1002. /*
  1003. * Let the HBA know what IOCB slot will be the next one the
  1004. * driver will put a command into.
  1005. */
  1006. pring->cmdidx = pring->next_cmdidx;
  1007. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1008. }
  1009. /**
  1010. * lpfc_sli_update_full_ring - Update the chip attention register
  1011. * @phba: Pointer to HBA context object.
  1012. * @pring: Pointer to driver SLI ring object.
  1013. *
  1014. * The caller is not required to hold any lock for calling this function.
  1015. * This function updates the chip attention bits for the ring to inform firmware
  1016. * that there are pending work to be done for this ring and requests an
  1017. * interrupt when there is space available in the ring. This function is
  1018. * called when the driver is unable to post more iocbs to the ring due
  1019. * to unavailability of space in the ring.
  1020. **/
  1021. static void
  1022. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1023. {
  1024. int ringno = pring->ringno;
  1025. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1026. wmb();
  1027. /*
  1028. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1029. * The HBA will tell us when an IOCB entry is available.
  1030. */
  1031. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1032. readl(phba->CAregaddr); /* flush */
  1033. pring->stats.iocb_cmd_full++;
  1034. }
  1035. /**
  1036. * lpfc_sli_update_ring - Update chip attention register
  1037. * @phba: Pointer to HBA context object.
  1038. * @pring: Pointer to driver SLI ring object.
  1039. *
  1040. * This function updates the chip attention register bit for the
  1041. * given ring to inform HBA that there is more work to be done
  1042. * in this ring. The caller is not required to hold any lock.
  1043. **/
  1044. static void
  1045. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1046. {
  1047. int ringno = pring->ringno;
  1048. /*
  1049. * Tell the HBA that there is work to do in this ring.
  1050. */
  1051. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1052. wmb();
  1053. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1054. readl(phba->CAregaddr); /* flush */
  1055. }
  1056. }
  1057. /**
  1058. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1059. * @phba: Pointer to HBA context object.
  1060. * @pring: Pointer to driver SLI ring object.
  1061. *
  1062. * This function is called with hbalock held to post pending iocbs
  1063. * in the txq to the firmware. This function is called when driver
  1064. * detects space available in the ring.
  1065. **/
  1066. static void
  1067. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1068. {
  1069. IOCB_t *iocb;
  1070. struct lpfc_iocbq *nextiocb;
  1071. /*
  1072. * Check to see if:
  1073. * (a) there is anything on the txq to send
  1074. * (b) link is up
  1075. * (c) link attention events can be processed (fcp ring only)
  1076. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1077. */
  1078. if (pring->txq_cnt &&
  1079. lpfc_is_link_up(phba) &&
  1080. (pring->ringno != phba->sli.fcp_ring ||
  1081. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1082. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1083. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1084. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1085. if (iocb)
  1086. lpfc_sli_update_ring(phba, pring);
  1087. else
  1088. lpfc_sli_update_full_ring(phba, pring);
  1089. }
  1090. return;
  1091. }
  1092. /**
  1093. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1094. * @phba: Pointer to HBA context object.
  1095. * @hbqno: HBQ number.
  1096. *
  1097. * This function is called with hbalock held to get the next
  1098. * available slot for the given HBQ. If there is free slot
  1099. * available for the HBQ it will return pointer to the next available
  1100. * HBQ entry else it will return NULL.
  1101. **/
  1102. static struct lpfc_hbq_entry *
  1103. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1104. {
  1105. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1106. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1107. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1108. hbqp->next_hbqPutIdx = 0;
  1109. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1110. uint32_t raw_index = phba->hbq_get[hbqno];
  1111. uint32_t getidx = le32_to_cpu(raw_index);
  1112. hbqp->local_hbqGetIdx = getidx;
  1113. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1114. lpfc_printf_log(phba, KERN_ERR,
  1115. LOG_SLI | LOG_VPORT,
  1116. "1802 HBQ %d: local_hbqGetIdx "
  1117. "%u is > than hbqp->entry_count %u\n",
  1118. hbqno, hbqp->local_hbqGetIdx,
  1119. hbqp->entry_count);
  1120. phba->link_state = LPFC_HBA_ERROR;
  1121. return NULL;
  1122. }
  1123. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1124. return NULL;
  1125. }
  1126. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1127. hbqp->hbqPutIdx;
  1128. }
  1129. /**
  1130. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1131. * @phba: Pointer to HBA context object.
  1132. *
  1133. * This function is called with no lock held to free all the
  1134. * hbq buffers while uninitializing the SLI interface. It also
  1135. * frees the HBQ buffers returned by the firmware but not yet
  1136. * processed by the upper layers.
  1137. **/
  1138. void
  1139. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1140. {
  1141. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1142. struct hbq_dmabuf *hbq_buf;
  1143. unsigned long flags;
  1144. int i, hbq_count;
  1145. uint32_t hbqno;
  1146. hbq_count = lpfc_sli_hbq_count();
  1147. /* Return all memory used by all HBQs */
  1148. spin_lock_irqsave(&phba->hbalock, flags);
  1149. for (i = 0; i < hbq_count; ++i) {
  1150. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1151. &phba->hbqs[i].hbq_buffer_list, list) {
  1152. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1153. list_del(&hbq_buf->dbuf.list);
  1154. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1155. }
  1156. phba->hbqs[i].buffer_count = 0;
  1157. }
  1158. /* Return all HBQ buffer that are in-fly */
  1159. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1160. list) {
  1161. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1162. list_del(&hbq_buf->dbuf.list);
  1163. if (hbq_buf->tag == -1) {
  1164. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1165. (phba, hbq_buf);
  1166. } else {
  1167. hbqno = hbq_buf->tag >> 16;
  1168. if (hbqno >= LPFC_MAX_HBQS)
  1169. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1170. (phba, hbq_buf);
  1171. else
  1172. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1173. hbq_buf);
  1174. }
  1175. }
  1176. /* Mark the HBQs not in use */
  1177. phba->hbq_in_use = 0;
  1178. spin_unlock_irqrestore(&phba->hbalock, flags);
  1179. }
  1180. /**
  1181. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1182. * @phba: Pointer to HBA context object.
  1183. * @hbqno: HBQ number.
  1184. * @hbq_buf: Pointer to HBQ buffer.
  1185. *
  1186. * This function is called with the hbalock held to post a
  1187. * hbq buffer to the firmware. If the function finds an empty
  1188. * slot in the HBQ, it will post the buffer. The function will return
  1189. * pointer to the hbq entry if it successfully post the buffer
  1190. * else it will return NULL.
  1191. **/
  1192. static int
  1193. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1194. struct hbq_dmabuf *hbq_buf)
  1195. {
  1196. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1197. }
  1198. /**
  1199. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1200. * @phba: Pointer to HBA context object.
  1201. * @hbqno: HBQ number.
  1202. * @hbq_buf: Pointer to HBQ buffer.
  1203. *
  1204. * This function is called with the hbalock held to post a hbq buffer to the
  1205. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1206. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1207. * it successfully post the buffer else it will return an error.
  1208. **/
  1209. static int
  1210. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1211. struct hbq_dmabuf *hbq_buf)
  1212. {
  1213. struct lpfc_hbq_entry *hbqe;
  1214. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1215. /* Get next HBQ entry slot to use */
  1216. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1217. if (hbqe) {
  1218. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1219. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1220. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1221. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1222. hbqe->bde.tus.f.bdeFlags = 0;
  1223. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1224. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1225. /* Sync SLIM */
  1226. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1227. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1228. /* flush */
  1229. readl(phba->hbq_put + hbqno);
  1230. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1231. return 0;
  1232. } else
  1233. return -ENOMEM;
  1234. }
  1235. /**
  1236. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1237. * @phba: Pointer to HBA context object.
  1238. * @hbqno: HBQ number.
  1239. * @hbq_buf: Pointer to HBQ buffer.
  1240. *
  1241. * This function is called with the hbalock held to post an RQE to the SLI4
  1242. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1243. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1244. **/
  1245. static int
  1246. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1247. struct hbq_dmabuf *hbq_buf)
  1248. {
  1249. int rc;
  1250. struct lpfc_rqe hrqe;
  1251. struct lpfc_rqe drqe;
  1252. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1253. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1254. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1255. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1256. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1257. &hrqe, &drqe);
  1258. if (rc < 0)
  1259. return rc;
  1260. hbq_buf->tag = rc;
  1261. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1262. return 0;
  1263. }
  1264. /* HBQ for ELS and CT traffic. */
  1265. static struct lpfc_hbq_init lpfc_els_hbq = {
  1266. .rn = 1,
  1267. .entry_count = 256,
  1268. .mask_count = 0,
  1269. .profile = 0,
  1270. .ring_mask = (1 << LPFC_ELS_RING),
  1271. .buffer_count = 0,
  1272. .init_count = 40,
  1273. .add_count = 40,
  1274. };
  1275. /* HBQ for the extra ring if needed */
  1276. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1277. .rn = 1,
  1278. .entry_count = 200,
  1279. .mask_count = 0,
  1280. .profile = 0,
  1281. .ring_mask = (1 << LPFC_EXTRA_RING),
  1282. .buffer_count = 0,
  1283. .init_count = 0,
  1284. .add_count = 5,
  1285. };
  1286. /* Array of HBQs */
  1287. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1288. &lpfc_els_hbq,
  1289. &lpfc_extra_hbq,
  1290. };
  1291. /**
  1292. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1293. * @phba: Pointer to HBA context object.
  1294. * @hbqno: HBQ number.
  1295. * @count: Number of HBQ buffers to be posted.
  1296. *
  1297. * This function is called with no lock held to post more hbq buffers to the
  1298. * given HBQ. The function returns the number of HBQ buffers successfully
  1299. * posted.
  1300. **/
  1301. static int
  1302. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1303. {
  1304. uint32_t i, posted = 0;
  1305. unsigned long flags;
  1306. struct hbq_dmabuf *hbq_buffer;
  1307. LIST_HEAD(hbq_buf_list);
  1308. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1309. return 0;
  1310. if ((phba->hbqs[hbqno].buffer_count + count) >
  1311. lpfc_hbq_defs[hbqno]->entry_count)
  1312. count = lpfc_hbq_defs[hbqno]->entry_count -
  1313. phba->hbqs[hbqno].buffer_count;
  1314. if (!count)
  1315. return 0;
  1316. /* Allocate HBQ entries */
  1317. for (i = 0; i < count; i++) {
  1318. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1319. if (!hbq_buffer)
  1320. break;
  1321. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1322. }
  1323. /* Check whether HBQ is still in use */
  1324. spin_lock_irqsave(&phba->hbalock, flags);
  1325. if (!phba->hbq_in_use)
  1326. goto err;
  1327. while (!list_empty(&hbq_buf_list)) {
  1328. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1329. dbuf.list);
  1330. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1331. (hbqno << 16));
  1332. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1333. phba->hbqs[hbqno].buffer_count++;
  1334. posted++;
  1335. } else
  1336. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1337. }
  1338. spin_unlock_irqrestore(&phba->hbalock, flags);
  1339. return posted;
  1340. err:
  1341. spin_unlock_irqrestore(&phba->hbalock, flags);
  1342. while (!list_empty(&hbq_buf_list)) {
  1343. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1344. dbuf.list);
  1345. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1346. }
  1347. return 0;
  1348. }
  1349. /**
  1350. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1351. * @phba: Pointer to HBA context object.
  1352. * @qno: HBQ number.
  1353. *
  1354. * This function posts more buffers to the HBQ. This function
  1355. * is called with no lock held. The function returns the number of HBQ entries
  1356. * successfully allocated.
  1357. **/
  1358. int
  1359. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1360. {
  1361. if (phba->sli_rev == LPFC_SLI_REV4)
  1362. return 0;
  1363. else
  1364. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1365. lpfc_hbq_defs[qno]->add_count);
  1366. }
  1367. /**
  1368. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1369. * @phba: Pointer to HBA context object.
  1370. * @qno: HBQ queue number.
  1371. *
  1372. * This function is called from SLI initialization code path with
  1373. * no lock held to post initial HBQ buffers to firmware. The
  1374. * function returns the number of HBQ entries successfully allocated.
  1375. **/
  1376. static int
  1377. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1378. {
  1379. if (phba->sli_rev == LPFC_SLI_REV4)
  1380. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1381. lpfc_hbq_defs[qno]->entry_count);
  1382. else
  1383. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1384. lpfc_hbq_defs[qno]->init_count);
  1385. }
  1386. /**
  1387. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1388. * @phba: Pointer to HBA context object.
  1389. * @hbqno: HBQ number.
  1390. *
  1391. * This function removes the first hbq buffer on an hbq list and returns a
  1392. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1393. **/
  1394. static struct hbq_dmabuf *
  1395. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1396. {
  1397. struct lpfc_dmabuf *d_buf;
  1398. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1399. if (!d_buf)
  1400. return NULL;
  1401. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1402. }
  1403. /**
  1404. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1405. * @phba: Pointer to HBA context object.
  1406. * @tag: Tag of the hbq buffer.
  1407. *
  1408. * This function is called with hbalock held. This function searches
  1409. * for the hbq buffer associated with the given tag in the hbq buffer
  1410. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1411. * it returns NULL.
  1412. **/
  1413. static struct hbq_dmabuf *
  1414. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1415. {
  1416. struct lpfc_dmabuf *d_buf;
  1417. struct hbq_dmabuf *hbq_buf;
  1418. uint32_t hbqno;
  1419. hbqno = tag >> 16;
  1420. if (hbqno >= LPFC_MAX_HBQS)
  1421. return NULL;
  1422. spin_lock_irq(&phba->hbalock);
  1423. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1424. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1425. if (hbq_buf->tag == tag) {
  1426. spin_unlock_irq(&phba->hbalock);
  1427. return hbq_buf;
  1428. }
  1429. }
  1430. spin_unlock_irq(&phba->hbalock);
  1431. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1432. "1803 Bad hbq tag. Data: x%x x%x\n",
  1433. tag, phba->hbqs[tag >> 16].buffer_count);
  1434. return NULL;
  1435. }
  1436. /**
  1437. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1438. * @phba: Pointer to HBA context object.
  1439. * @hbq_buffer: Pointer to HBQ buffer.
  1440. *
  1441. * This function is called with hbalock. This function gives back
  1442. * the hbq buffer to firmware. If the HBQ does not have space to
  1443. * post the buffer, it will free the buffer.
  1444. **/
  1445. void
  1446. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1447. {
  1448. uint32_t hbqno;
  1449. if (hbq_buffer) {
  1450. hbqno = hbq_buffer->tag >> 16;
  1451. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1452. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1453. }
  1454. }
  1455. /**
  1456. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1457. * @mbxCommand: mailbox command code.
  1458. *
  1459. * This function is called by the mailbox event handler function to verify
  1460. * that the completed mailbox command is a legitimate mailbox command. If the
  1461. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1462. * and the mailbox event handler will take the HBA offline.
  1463. **/
  1464. static int
  1465. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1466. {
  1467. uint8_t ret;
  1468. switch (mbxCommand) {
  1469. case MBX_LOAD_SM:
  1470. case MBX_READ_NV:
  1471. case MBX_WRITE_NV:
  1472. case MBX_WRITE_VPARMS:
  1473. case MBX_RUN_BIU_DIAG:
  1474. case MBX_INIT_LINK:
  1475. case MBX_DOWN_LINK:
  1476. case MBX_CONFIG_LINK:
  1477. case MBX_CONFIG_RING:
  1478. case MBX_RESET_RING:
  1479. case MBX_READ_CONFIG:
  1480. case MBX_READ_RCONFIG:
  1481. case MBX_READ_SPARM:
  1482. case MBX_READ_STATUS:
  1483. case MBX_READ_RPI:
  1484. case MBX_READ_XRI:
  1485. case MBX_READ_REV:
  1486. case MBX_READ_LNK_STAT:
  1487. case MBX_REG_LOGIN:
  1488. case MBX_UNREG_LOGIN:
  1489. case MBX_READ_LA:
  1490. case MBX_CLEAR_LA:
  1491. case MBX_DUMP_MEMORY:
  1492. case MBX_DUMP_CONTEXT:
  1493. case MBX_RUN_DIAGS:
  1494. case MBX_RESTART:
  1495. case MBX_UPDATE_CFG:
  1496. case MBX_DOWN_LOAD:
  1497. case MBX_DEL_LD_ENTRY:
  1498. case MBX_RUN_PROGRAM:
  1499. case MBX_SET_MASK:
  1500. case MBX_SET_VARIABLE:
  1501. case MBX_UNREG_D_ID:
  1502. case MBX_KILL_BOARD:
  1503. case MBX_CONFIG_FARP:
  1504. case MBX_BEACON:
  1505. case MBX_LOAD_AREA:
  1506. case MBX_RUN_BIU_DIAG64:
  1507. case MBX_CONFIG_PORT:
  1508. case MBX_READ_SPARM64:
  1509. case MBX_READ_RPI64:
  1510. case MBX_REG_LOGIN64:
  1511. case MBX_READ_LA64:
  1512. case MBX_WRITE_WWN:
  1513. case MBX_SET_DEBUG:
  1514. case MBX_LOAD_EXP_ROM:
  1515. case MBX_ASYNCEVT_ENABLE:
  1516. case MBX_REG_VPI:
  1517. case MBX_UNREG_VPI:
  1518. case MBX_HEARTBEAT:
  1519. case MBX_PORT_CAPABILITIES:
  1520. case MBX_PORT_IOV_CONTROL:
  1521. case MBX_SLI4_CONFIG:
  1522. case MBX_SLI4_REQ_FTRS:
  1523. case MBX_REG_FCFI:
  1524. case MBX_UNREG_FCFI:
  1525. case MBX_REG_VFI:
  1526. case MBX_UNREG_VFI:
  1527. case MBX_INIT_VPI:
  1528. case MBX_INIT_VFI:
  1529. case MBX_RESUME_RPI:
  1530. case MBX_READ_EVENT_LOG_STATUS:
  1531. case MBX_READ_EVENT_LOG:
  1532. ret = mbxCommand;
  1533. break;
  1534. default:
  1535. ret = MBX_SHUTDOWN;
  1536. break;
  1537. }
  1538. return ret;
  1539. }
  1540. /**
  1541. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1542. * @phba: Pointer to HBA context object.
  1543. * @pmboxq: Pointer to mailbox command.
  1544. *
  1545. * This is completion handler function for mailbox commands issued from
  1546. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1547. * mailbox event handler function with no lock held. This function
  1548. * will wake up thread waiting on the wait queue pointed by context1
  1549. * of the mailbox.
  1550. **/
  1551. void
  1552. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1553. {
  1554. wait_queue_head_t *pdone_q;
  1555. unsigned long drvr_flag;
  1556. /*
  1557. * If pdone_q is empty, the driver thread gave up waiting and
  1558. * continued running.
  1559. */
  1560. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1561. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1562. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1563. if (pdone_q)
  1564. wake_up_interruptible(pdone_q);
  1565. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1566. return;
  1567. }
  1568. /**
  1569. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1570. * @phba: Pointer to HBA context object.
  1571. * @pmb: Pointer to mailbox object.
  1572. *
  1573. * This function is the default mailbox completion handler. It
  1574. * frees the memory resources associated with the completed mailbox
  1575. * command. If the completed command is a REG_LOGIN mailbox command,
  1576. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1577. **/
  1578. void
  1579. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1580. {
  1581. struct lpfc_dmabuf *mp;
  1582. uint16_t rpi, vpi;
  1583. int rc;
  1584. struct lpfc_vport *vport = pmb->vport;
  1585. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1586. if (mp) {
  1587. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1588. kfree(mp);
  1589. }
  1590. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1591. (phba->sli_rev == LPFC_SLI_REV4))
  1592. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1593. /*
  1594. * If a REG_LOGIN succeeded after node is destroyed or node
  1595. * is in re-discovery driver need to cleanup the RPI.
  1596. */
  1597. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1598. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1599. !pmb->u.mb.mbxStatus) {
  1600. rpi = pmb->u.mb.un.varWords[0];
  1601. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1602. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1603. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1604. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1605. if (rc != MBX_NOT_FINISHED)
  1606. return;
  1607. }
  1608. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1609. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1610. !(phba->pport->load_flag & FC_UNLOADING) &&
  1611. !pmb->u.mb.mbxStatus) {
  1612. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1613. pmb->vport = vport;
  1614. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1615. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1616. if (rc != MBX_NOT_FINISHED)
  1617. return;
  1618. }
  1619. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1620. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1621. else
  1622. mempool_free(pmb, phba->mbox_mem_pool);
  1623. }
  1624. /**
  1625. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1626. * @phba: Pointer to HBA context object.
  1627. *
  1628. * This function is called with no lock held. This function processes all
  1629. * the completed mailbox commands and gives it to upper layers. The interrupt
  1630. * service routine processes mailbox completion interrupt and adds completed
  1631. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1632. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1633. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1634. * function returns the mailbox commands to the upper layer by calling the
  1635. * completion handler function of each mailbox.
  1636. **/
  1637. int
  1638. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1639. {
  1640. MAILBOX_t *pmbox;
  1641. LPFC_MBOXQ_t *pmb;
  1642. int rc;
  1643. LIST_HEAD(cmplq);
  1644. phba->sli.slistat.mbox_event++;
  1645. /* Get all completed mailboxe buffers into the cmplq */
  1646. spin_lock_irq(&phba->hbalock);
  1647. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1648. spin_unlock_irq(&phba->hbalock);
  1649. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1650. do {
  1651. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1652. if (pmb == NULL)
  1653. break;
  1654. pmbox = &pmb->u.mb;
  1655. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1656. if (pmb->vport) {
  1657. lpfc_debugfs_disc_trc(pmb->vport,
  1658. LPFC_DISC_TRC_MBOX_VPORT,
  1659. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1660. (uint32_t)pmbox->mbxCommand,
  1661. pmbox->un.varWords[0],
  1662. pmbox->un.varWords[1]);
  1663. }
  1664. else {
  1665. lpfc_debugfs_disc_trc(phba->pport,
  1666. LPFC_DISC_TRC_MBOX,
  1667. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1668. (uint32_t)pmbox->mbxCommand,
  1669. pmbox->un.varWords[0],
  1670. pmbox->un.varWords[1]);
  1671. }
  1672. }
  1673. /*
  1674. * It is a fatal error if unknown mbox command completion.
  1675. */
  1676. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1677. MBX_SHUTDOWN) {
  1678. /* Unknown mailbox command compl */
  1679. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1680. "(%d):0323 Unknown Mailbox command "
  1681. "x%x (x%x) Cmpl\n",
  1682. pmb->vport ? pmb->vport->vpi : 0,
  1683. pmbox->mbxCommand,
  1684. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1685. phba->link_state = LPFC_HBA_ERROR;
  1686. phba->work_hs = HS_FFER3;
  1687. lpfc_handle_eratt(phba);
  1688. continue;
  1689. }
  1690. if (pmbox->mbxStatus) {
  1691. phba->sli.slistat.mbox_stat_err++;
  1692. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1693. /* Mbox cmd cmpl error - RETRYing */
  1694. lpfc_printf_log(phba, KERN_INFO,
  1695. LOG_MBOX | LOG_SLI,
  1696. "(%d):0305 Mbox cmd cmpl "
  1697. "error - RETRYing Data: x%x "
  1698. "(x%x) x%x x%x x%x\n",
  1699. pmb->vport ? pmb->vport->vpi :0,
  1700. pmbox->mbxCommand,
  1701. lpfc_sli4_mbox_opcode_get(phba,
  1702. pmb),
  1703. pmbox->mbxStatus,
  1704. pmbox->un.varWords[0],
  1705. pmb->vport->port_state);
  1706. pmbox->mbxStatus = 0;
  1707. pmbox->mbxOwner = OWN_HOST;
  1708. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1709. if (rc != MBX_NOT_FINISHED)
  1710. continue;
  1711. }
  1712. }
  1713. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1714. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1715. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1716. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1717. pmb->vport ? pmb->vport->vpi : 0,
  1718. pmbox->mbxCommand,
  1719. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1720. pmb->mbox_cmpl,
  1721. *((uint32_t *) pmbox),
  1722. pmbox->un.varWords[0],
  1723. pmbox->un.varWords[1],
  1724. pmbox->un.varWords[2],
  1725. pmbox->un.varWords[3],
  1726. pmbox->un.varWords[4],
  1727. pmbox->un.varWords[5],
  1728. pmbox->un.varWords[6],
  1729. pmbox->un.varWords[7]);
  1730. if (pmb->mbox_cmpl)
  1731. pmb->mbox_cmpl(phba,pmb);
  1732. } while (1);
  1733. return 0;
  1734. }
  1735. /**
  1736. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1737. * @phba: Pointer to HBA context object.
  1738. * @pring: Pointer to driver SLI ring object.
  1739. * @tag: buffer tag.
  1740. *
  1741. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1742. * is set in the tag the buffer is posted for a particular exchange,
  1743. * the function will return the buffer without replacing the buffer.
  1744. * If the buffer is for unsolicited ELS or CT traffic, this function
  1745. * returns the buffer and also posts another buffer to the firmware.
  1746. **/
  1747. static struct lpfc_dmabuf *
  1748. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1749. struct lpfc_sli_ring *pring,
  1750. uint32_t tag)
  1751. {
  1752. struct hbq_dmabuf *hbq_entry;
  1753. if (tag & QUE_BUFTAG_BIT)
  1754. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1755. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1756. if (!hbq_entry)
  1757. return NULL;
  1758. return &hbq_entry->dbuf;
  1759. }
  1760. /**
  1761. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1762. * @phba: Pointer to HBA context object.
  1763. * @pring: Pointer to driver SLI ring object.
  1764. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1765. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1766. * @fch_type: the type for the first frame of the sequence.
  1767. *
  1768. * This function is called with no lock held. This function uses the r_ctl and
  1769. * type of the received sequence to find the correct callback function to call
  1770. * to process the sequence.
  1771. **/
  1772. static int
  1773. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1774. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1775. uint32_t fch_type)
  1776. {
  1777. int i;
  1778. /* unSolicited Responses */
  1779. if (pring->prt[0].profile) {
  1780. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1781. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1782. saveq);
  1783. return 1;
  1784. }
  1785. /* We must search, based on rctl / type
  1786. for the right routine */
  1787. for (i = 0; i < pring->num_mask; i++) {
  1788. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1789. (pring->prt[i].type == fch_type)) {
  1790. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1791. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1792. (phba, pring, saveq);
  1793. return 1;
  1794. }
  1795. }
  1796. return 0;
  1797. }
  1798. /**
  1799. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1800. * @phba: Pointer to HBA context object.
  1801. * @pring: Pointer to driver SLI ring object.
  1802. * @saveq: Pointer to the unsolicited iocb.
  1803. *
  1804. * This function is called with no lock held by the ring event handler
  1805. * when there is an unsolicited iocb posted to the response ring by the
  1806. * firmware. This function gets the buffer associated with the iocbs
  1807. * and calls the event handler for the ring. This function handles both
  1808. * qring buffers and hbq buffers.
  1809. * When the function returns 1 the caller can free the iocb object otherwise
  1810. * upper layer functions will free the iocb objects.
  1811. **/
  1812. static int
  1813. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1814. struct lpfc_iocbq *saveq)
  1815. {
  1816. IOCB_t * irsp;
  1817. WORD5 * w5p;
  1818. uint32_t Rctl, Type;
  1819. uint32_t match;
  1820. struct lpfc_iocbq *iocbq;
  1821. struct lpfc_dmabuf *dmzbuf;
  1822. match = 0;
  1823. irsp = &(saveq->iocb);
  1824. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1825. if (pring->lpfc_sli_rcv_async_status)
  1826. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1827. else
  1828. lpfc_printf_log(phba,
  1829. KERN_WARNING,
  1830. LOG_SLI,
  1831. "0316 Ring %d handler: unexpected "
  1832. "ASYNC_STATUS iocb received evt_code "
  1833. "0x%x\n",
  1834. pring->ringno,
  1835. irsp->un.asyncstat.evt_code);
  1836. return 1;
  1837. }
  1838. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1839. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1840. if (irsp->ulpBdeCount > 0) {
  1841. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1842. irsp->un.ulpWord[3]);
  1843. lpfc_in_buf_free(phba, dmzbuf);
  1844. }
  1845. if (irsp->ulpBdeCount > 1) {
  1846. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1847. irsp->unsli3.sli3Words[3]);
  1848. lpfc_in_buf_free(phba, dmzbuf);
  1849. }
  1850. if (irsp->ulpBdeCount > 2) {
  1851. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1852. irsp->unsli3.sli3Words[7]);
  1853. lpfc_in_buf_free(phba, dmzbuf);
  1854. }
  1855. return 1;
  1856. }
  1857. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1858. if (irsp->ulpBdeCount != 0) {
  1859. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1860. irsp->un.ulpWord[3]);
  1861. if (!saveq->context2)
  1862. lpfc_printf_log(phba,
  1863. KERN_ERR,
  1864. LOG_SLI,
  1865. "0341 Ring %d Cannot find buffer for "
  1866. "an unsolicited iocb. tag 0x%x\n",
  1867. pring->ringno,
  1868. irsp->un.ulpWord[3]);
  1869. }
  1870. if (irsp->ulpBdeCount == 2) {
  1871. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1872. irsp->unsli3.sli3Words[7]);
  1873. if (!saveq->context3)
  1874. lpfc_printf_log(phba,
  1875. KERN_ERR,
  1876. LOG_SLI,
  1877. "0342 Ring %d Cannot find buffer for an"
  1878. " unsolicited iocb. tag 0x%x\n",
  1879. pring->ringno,
  1880. irsp->unsli3.sli3Words[7]);
  1881. }
  1882. list_for_each_entry(iocbq, &saveq->list, list) {
  1883. irsp = &(iocbq->iocb);
  1884. if (irsp->ulpBdeCount != 0) {
  1885. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1886. irsp->un.ulpWord[3]);
  1887. if (!iocbq->context2)
  1888. lpfc_printf_log(phba,
  1889. KERN_ERR,
  1890. LOG_SLI,
  1891. "0343 Ring %d Cannot find "
  1892. "buffer for an unsolicited iocb"
  1893. ". tag 0x%x\n", pring->ringno,
  1894. irsp->un.ulpWord[3]);
  1895. }
  1896. if (irsp->ulpBdeCount == 2) {
  1897. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1898. irsp->unsli3.sli3Words[7]);
  1899. if (!iocbq->context3)
  1900. lpfc_printf_log(phba,
  1901. KERN_ERR,
  1902. LOG_SLI,
  1903. "0344 Ring %d Cannot find "
  1904. "buffer for an unsolicited "
  1905. "iocb. tag 0x%x\n",
  1906. pring->ringno,
  1907. irsp->unsli3.sli3Words[7]);
  1908. }
  1909. }
  1910. }
  1911. if (irsp->ulpBdeCount != 0 &&
  1912. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1913. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1914. int found = 0;
  1915. /* search continue save q for same XRI */
  1916. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1917. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1918. list_add_tail(&saveq->list, &iocbq->list);
  1919. found = 1;
  1920. break;
  1921. }
  1922. }
  1923. if (!found)
  1924. list_add_tail(&saveq->clist,
  1925. &pring->iocb_continue_saveq);
  1926. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1927. list_del_init(&iocbq->clist);
  1928. saveq = iocbq;
  1929. irsp = &(saveq->iocb);
  1930. } else
  1931. return 0;
  1932. }
  1933. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1934. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1935. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1936. Rctl = FC_RCTL_ELS_REQ;
  1937. Type = FC_TYPE_ELS;
  1938. } else {
  1939. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1940. Rctl = w5p->hcsw.Rctl;
  1941. Type = w5p->hcsw.Type;
  1942. /* Firmware Workaround */
  1943. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1944. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1945. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1946. Rctl = FC_RCTL_ELS_REQ;
  1947. Type = FC_TYPE_ELS;
  1948. w5p->hcsw.Rctl = Rctl;
  1949. w5p->hcsw.Type = Type;
  1950. }
  1951. }
  1952. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1953. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1954. "0313 Ring %d handler: unexpected Rctl x%x "
  1955. "Type x%x received\n",
  1956. pring->ringno, Rctl, Type);
  1957. return 1;
  1958. }
  1959. /**
  1960. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1961. * @phba: Pointer to HBA context object.
  1962. * @pring: Pointer to driver SLI ring object.
  1963. * @prspiocb: Pointer to response iocb object.
  1964. *
  1965. * This function looks up the iocb_lookup table to get the command iocb
  1966. * corresponding to the given response iocb using the iotag of the
  1967. * response iocb. This function is called with the hbalock held.
  1968. * This function returns the command iocb object if it finds the command
  1969. * iocb else returns NULL.
  1970. **/
  1971. static struct lpfc_iocbq *
  1972. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1973. struct lpfc_sli_ring *pring,
  1974. struct lpfc_iocbq *prspiocb)
  1975. {
  1976. struct lpfc_iocbq *cmd_iocb = NULL;
  1977. uint16_t iotag;
  1978. iotag = prspiocb->iocb.ulpIoTag;
  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. "0317 iotag x%x is out off "
  1987. "range: max iotag x%x wd0 x%x\n",
  1988. iotag, phba->sli.last_iotag,
  1989. *(((uint32_t *) &prspiocb->iocb) + 7));
  1990. return NULL;
  1991. }
  1992. /**
  1993. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1994. * @phba: Pointer to HBA context object.
  1995. * @pring: Pointer to driver SLI ring object.
  1996. * @iotag: IOCB tag.
  1997. *
  1998. * This function looks up the iocb_lookup table to get the command iocb
  1999. * corresponding to the given iotag. This function is called with the
  2000. * hbalock held.
  2001. * This function returns the command iocb object if it finds the command
  2002. * iocb else returns NULL.
  2003. **/
  2004. static struct lpfc_iocbq *
  2005. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2006. struct lpfc_sli_ring *pring, uint16_t iotag)
  2007. {
  2008. struct lpfc_iocbq *cmd_iocb;
  2009. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2010. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2011. list_del_init(&cmd_iocb->list);
  2012. pring->txcmplq_cnt--;
  2013. return cmd_iocb;
  2014. }
  2015. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2016. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2017. iotag, phba->sli.last_iotag);
  2018. return NULL;
  2019. }
  2020. /**
  2021. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2022. * @phba: Pointer to HBA context object.
  2023. * @pring: Pointer to driver SLI ring object.
  2024. * @saveq: Pointer to the response iocb to be processed.
  2025. *
  2026. * This function is called by the ring event handler for non-fcp
  2027. * rings when there is a new response iocb in the response ring.
  2028. * The caller is not required to hold any locks. This function
  2029. * gets the command iocb associated with the response iocb and
  2030. * calls the completion handler for the command iocb. If there
  2031. * is no completion handler, the function will free the resources
  2032. * associated with command iocb. If the response iocb is for
  2033. * an already aborted command iocb, the status of the completion
  2034. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2035. * This function always returns 1.
  2036. **/
  2037. static int
  2038. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2039. struct lpfc_iocbq *saveq)
  2040. {
  2041. struct lpfc_iocbq *cmdiocbp;
  2042. int rc = 1;
  2043. unsigned long iflag;
  2044. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2045. spin_lock_irqsave(&phba->hbalock, iflag);
  2046. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2047. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2048. if (cmdiocbp) {
  2049. if (cmdiocbp->iocb_cmpl) {
  2050. /*
  2051. * If an ELS command failed send an event to mgmt
  2052. * application.
  2053. */
  2054. if (saveq->iocb.ulpStatus &&
  2055. (pring->ringno == LPFC_ELS_RING) &&
  2056. (cmdiocbp->iocb.ulpCommand ==
  2057. CMD_ELS_REQUEST64_CR))
  2058. lpfc_send_els_failure_event(phba,
  2059. cmdiocbp, saveq);
  2060. /*
  2061. * Post all ELS completions to the worker thread.
  2062. * All other are passed to the completion callback.
  2063. */
  2064. if (pring->ringno == LPFC_ELS_RING) {
  2065. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2066. (cmdiocbp->iocb_flag &
  2067. LPFC_DRIVER_ABORTED)) {
  2068. spin_lock_irqsave(&phba->hbalock,
  2069. iflag);
  2070. cmdiocbp->iocb_flag &=
  2071. ~LPFC_DRIVER_ABORTED;
  2072. spin_unlock_irqrestore(&phba->hbalock,
  2073. iflag);
  2074. saveq->iocb.ulpStatus =
  2075. IOSTAT_LOCAL_REJECT;
  2076. saveq->iocb.un.ulpWord[4] =
  2077. IOERR_SLI_ABORTED;
  2078. /* Firmware could still be in progress
  2079. * of DMAing payload, so don't free data
  2080. * buffer till after a hbeat.
  2081. */
  2082. spin_lock_irqsave(&phba->hbalock,
  2083. iflag);
  2084. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2085. spin_unlock_irqrestore(&phba->hbalock,
  2086. iflag);
  2087. }
  2088. if (phba->sli_rev == LPFC_SLI_REV4) {
  2089. if (saveq->iocb_flag &
  2090. LPFC_EXCHANGE_BUSY) {
  2091. /* Set cmdiocb flag for the
  2092. * exchange busy so sgl (xri)
  2093. * will not be released until
  2094. * the abort xri is received
  2095. * from hba.
  2096. */
  2097. spin_lock_irqsave(
  2098. &phba->hbalock, iflag);
  2099. cmdiocbp->iocb_flag |=
  2100. LPFC_EXCHANGE_BUSY;
  2101. spin_unlock_irqrestore(
  2102. &phba->hbalock, iflag);
  2103. }
  2104. if (cmdiocbp->iocb_flag &
  2105. LPFC_DRIVER_ABORTED) {
  2106. /*
  2107. * Clear LPFC_DRIVER_ABORTED
  2108. * bit in case it was driver
  2109. * initiated abort.
  2110. */
  2111. spin_lock_irqsave(
  2112. &phba->hbalock, iflag);
  2113. cmdiocbp->iocb_flag &=
  2114. ~LPFC_DRIVER_ABORTED;
  2115. spin_unlock_irqrestore(
  2116. &phba->hbalock, iflag);
  2117. cmdiocbp->iocb.ulpStatus =
  2118. IOSTAT_LOCAL_REJECT;
  2119. cmdiocbp->iocb.un.ulpWord[4] =
  2120. IOERR_ABORT_REQUESTED;
  2121. /*
  2122. * For SLI4, irsiocb contains
  2123. * NO_XRI in sli_xritag, it
  2124. * shall not affect releasing
  2125. * sgl (xri) process.
  2126. */
  2127. saveq->iocb.ulpStatus =
  2128. IOSTAT_LOCAL_REJECT;
  2129. saveq->iocb.un.ulpWord[4] =
  2130. IOERR_SLI_ABORTED;
  2131. spin_lock_irqsave(
  2132. &phba->hbalock, iflag);
  2133. saveq->iocb_flag |=
  2134. LPFC_DELAY_MEM_FREE;
  2135. spin_unlock_irqrestore(
  2136. &phba->hbalock, iflag);
  2137. }
  2138. }
  2139. }
  2140. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2141. } else
  2142. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2143. } else {
  2144. /*
  2145. * Unknown initiating command based on the response iotag.
  2146. * This could be the case on the ELS ring because of
  2147. * lpfc_els_abort().
  2148. */
  2149. if (pring->ringno != LPFC_ELS_RING) {
  2150. /*
  2151. * Ring <ringno> handler: unexpected completion IoTag
  2152. * <IoTag>
  2153. */
  2154. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2155. "0322 Ring %d handler: "
  2156. "unexpected completion IoTag x%x "
  2157. "Data: x%x x%x x%x x%x\n",
  2158. pring->ringno,
  2159. saveq->iocb.ulpIoTag,
  2160. saveq->iocb.ulpStatus,
  2161. saveq->iocb.un.ulpWord[4],
  2162. saveq->iocb.ulpCommand,
  2163. saveq->iocb.ulpContext);
  2164. }
  2165. }
  2166. return rc;
  2167. }
  2168. /**
  2169. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2170. * @phba: Pointer to HBA context object.
  2171. * @pring: Pointer to driver SLI ring object.
  2172. *
  2173. * This function is called from the iocb ring event handlers when
  2174. * put pointer is ahead of the get pointer for a ring. This function signal
  2175. * an error attention condition to the worker thread and the worker
  2176. * thread will transition the HBA to offline state.
  2177. **/
  2178. static void
  2179. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2180. {
  2181. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2182. /*
  2183. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2184. * rsp ring <portRspMax>
  2185. */
  2186. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2187. "0312 Ring %d handler: portRspPut %d "
  2188. "is bigger than rsp ring %d\n",
  2189. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2190. pring->numRiocb);
  2191. phba->link_state = LPFC_HBA_ERROR;
  2192. /*
  2193. * All error attention handlers are posted to
  2194. * worker thread
  2195. */
  2196. phba->work_ha |= HA_ERATT;
  2197. phba->work_hs = HS_FFER3;
  2198. lpfc_worker_wake_up(phba);
  2199. return;
  2200. }
  2201. /**
  2202. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2203. * @ptr: Pointer to address of HBA context object.
  2204. *
  2205. * This function is invoked by the Error Attention polling timer when the
  2206. * timer times out. It will check the SLI Error Attention register for
  2207. * possible attention events. If so, it will post an Error Attention event
  2208. * and wake up worker thread to process it. Otherwise, it will set up the
  2209. * Error Attention polling timer for the next poll.
  2210. **/
  2211. void lpfc_poll_eratt(unsigned long ptr)
  2212. {
  2213. struct lpfc_hba *phba;
  2214. uint32_t eratt = 0;
  2215. phba = (struct lpfc_hba *)ptr;
  2216. /* Check chip HA register for error event */
  2217. eratt = lpfc_sli_check_eratt(phba);
  2218. if (eratt)
  2219. /* Tell the worker thread there is work to do */
  2220. lpfc_worker_wake_up(phba);
  2221. else
  2222. /* Restart the timer for next eratt poll */
  2223. mod_timer(&phba->eratt_poll, jiffies +
  2224. HZ * LPFC_ERATT_POLL_INTERVAL);
  2225. return;
  2226. }
  2227. /**
  2228. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2229. * @phba: Pointer to HBA context object.
  2230. * @pring: Pointer to driver SLI ring object.
  2231. * @mask: Host attention register mask for this ring.
  2232. *
  2233. * This function is called from the interrupt context when there is a ring
  2234. * event for the fcp ring. The caller does not hold any lock.
  2235. * The function processes each response iocb in the response ring until it
  2236. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2237. * LE bit set. The function will call the completion handler of the command iocb
  2238. * if the response iocb indicates a completion for a command iocb or it is
  2239. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2240. * function if this is an unsolicited iocb.
  2241. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2242. * to check it explicitly.
  2243. */
  2244. int
  2245. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2246. struct lpfc_sli_ring *pring, uint32_t mask)
  2247. {
  2248. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2249. IOCB_t *irsp = NULL;
  2250. IOCB_t *entry = NULL;
  2251. struct lpfc_iocbq *cmdiocbq = NULL;
  2252. struct lpfc_iocbq rspiocbq;
  2253. uint32_t status;
  2254. uint32_t portRspPut, portRspMax;
  2255. int rc = 1;
  2256. lpfc_iocb_type type;
  2257. unsigned long iflag;
  2258. uint32_t rsp_cmpl = 0;
  2259. spin_lock_irqsave(&phba->hbalock, iflag);
  2260. pring->stats.iocb_event++;
  2261. /*
  2262. * The next available response entry should never exceed the maximum
  2263. * entries. If it does, treat it as an adapter hardware error.
  2264. */
  2265. portRspMax = pring->numRiocb;
  2266. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2267. if (unlikely(portRspPut >= portRspMax)) {
  2268. lpfc_sli_rsp_pointers_error(phba, pring);
  2269. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2270. return 1;
  2271. }
  2272. if (phba->fcp_ring_in_use) {
  2273. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2274. return 1;
  2275. } else
  2276. phba->fcp_ring_in_use = 1;
  2277. rmb();
  2278. while (pring->rspidx != portRspPut) {
  2279. /*
  2280. * Fetch an entry off the ring and copy it into a local data
  2281. * structure. The copy involves a byte-swap since the
  2282. * network byte order and pci byte orders are different.
  2283. */
  2284. entry = lpfc_resp_iocb(phba, pring);
  2285. phba->last_completion_time = jiffies;
  2286. if (++pring->rspidx >= portRspMax)
  2287. pring->rspidx = 0;
  2288. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2289. (uint32_t *) &rspiocbq.iocb,
  2290. phba->iocb_rsp_size);
  2291. INIT_LIST_HEAD(&(rspiocbq.list));
  2292. irsp = &rspiocbq.iocb;
  2293. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2294. pring->stats.iocb_rsp++;
  2295. rsp_cmpl++;
  2296. if (unlikely(irsp->ulpStatus)) {
  2297. /*
  2298. * If resource errors reported from HBA, reduce
  2299. * queuedepths of the SCSI device.
  2300. */
  2301. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2302. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2303. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2304. phba->lpfc_rampdown_queue_depth(phba);
  2305. spin_lock_irqsave(&phba->hbalock, iflag);
  2306. }
  2307. /* Rsp ring <ringno> error: IOCB */
  2308. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2309. "0336 Rsp Ring %d error: IOCB Data: "
  2310. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2311. pring->ringno,
  2312. irsp->un.ulpWord[0],
  2313. irsp->un.ulpWord[1],
  2314. irsp->un.ulpWord[2],
  2315. irsp->un.ulpWord[3],
  2316. irsp->un.ulpWord[4],
  2317. irsp->un.ulpWord[5],
  2318. *(uint32_t *)&irsp->un1,
  2319. *((uint32_t *)&irsp->un1 + 1));
  2320. }
  2321. switch (type) {
  2322. case LPFC_ABORT_IOCB:
  2323. case LPFC_SOL_IOCB:
  2324. /*
  2325. * Idle exchange closed via ABTS from port. No iocb
  2326. * resources need to be recovered.
  2327. */
  2328. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2329. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2330. "0333 IOCB cmd 0x%x"
  2331. " processed. Skipping"
  2332. " completion\n",
  2333. irsp->ulpCommand);
  2334. break;
  2335. }
  2336. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2337. &rspiocbq);
  2338. if (unlikely(!cmdiocbq))
  2339. break;
  2340. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2341. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2342. if (cmdiocbq->iocb_cmpl) {
  2343. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2344. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2345. &rspiocbq);
  2346. spin_lock_irqsave(&phba->hbalock, iflag);
  2347. }
  2348. break;
  2349. case LPFC_UNSOL_IOCB:
  2350. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2351. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2352. spin_lock_irqsave(&phba->hbalock, iflag);
  2353. break;
  2354. default:
  2355. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2356. char adaptermsg[LPFC_MAX_ADPTMSG];
  2357. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2358. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2359. MAX_MSG_DATA);
  2360. dev_warn(&((phba->pcidev)->dev),
  2361. "lpfc%d: %s\n",
  2362. phba->brd_no, adaptermsg);
  2363. } else {
  2364. /* Unknown IOCB command */
  2365. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2366. "0334 Unknown IOCB command "
  2367. "Data: x%x, x%x x%x x%x x%x\n",
  2368. type, irsp->ulpCommand,
  2369. irsp->ulpStatus,
  2370. irsp->ulpIoTag,
  2371. irsp->ulpContext);
  2372. }
  2373. break;
  2374. }
  2375. /*
  2376. * The response IOCB has been processed. Update the ring
  2377. * pointer in SLIM. If the port response put pointer has not
  2378. * been updated, sync the pgp->rspPutInx and fetch the new port
  2379. * response put pointer.
  2380. */
  2381. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2382. if (pring->rspidx == portRspPut)
  2383. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2384. }
  2385. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2386. pring->stats.iocb_rsp_full++;
  2387. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2388. writel(status, phba->CAregaddr);
  2389. readl(phba->CAregaddr);
  2390. }
  2391. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2392. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2393. pring->stats.iocb_cmd_empty++;
  2394. /* Force update of the local copy of cmdGetInx */
  2395. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2396. lpfc_sli_resume_iocb(phba, pring);
  2397. if ((pring->lpfc_sli_cmd_available))
  2398. (pring->lpfc_sli_cmd_available) (phba, pring);
  2399. }
  2400. phba->fcp_ring_in_use = 0;
  2401. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2402. return rc;
  2403. }
  2404. /**
  2405. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2406. * @phba: Pointer to HBA context object.
  2407. * @pring: Pointer to driver SLI ring object.
  2408. * @rspiocbp: Pointer to driver response IOCB object.
  2409. *
  2410. * This function is called from the worker thread when there is a slow-path
  2411. * response IOCB to process. This function chains all the response iocbs until
  2412. * seeing the iocb with the LE bit set. The function will call
  2413. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2414. * completion of a command iocb. The function will call the
  2415. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2416. * The function frees the resources or calls the completion handler if this
  2417. * iocb is an abort completion. The function returns NULL when the response
  2418. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2419. * this function shall chain the iocb on to the iocb_continueq and return the
  2420. * response iocb passed in.
  2421. **/
  2422. static struct lpfc_iocbq *
  2423. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2424. struct lpfc_iocbq *rspiocbp)
  2425. {
  2426. struct lpfc_iocbq *saveq;
  2427. struct lpfc_iocbq *cmdiocbp;
  2428. struct lpfc_iocbq *next_iocb;
  2429. IOCB_t *irsp = NULL;
  2430. uint32_t free_saveq;
  2431. uint8_t iocb_cmd_type;
  2432. lpfc_iocb_type type;
  2433. unsigned long iflag;
  2434. int rc;
  2435. spin_lock_irqsave(&phba->hbalock, iflag);
  2436. /* First add the response iocb to the countinueq list */
  2437. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2438. pring->iocb_continueq_cnt++;
  2439. /* Now, determine whetehr the list is completed for processing */
  2440. irsp = &rspiocbp->iocb;
  2441. if (irsp->ulpLe) {
  2442. /*
  2443. * By default, the driver expects to free all resources
  2444. * associated with this iocb completion.
  2445. */
  2446. free_saveq = 1;
  2447. saveq = list_get_first(&pring->iocb_continueq,
  2448. struct lpfc_iocbq, list);
  2449. irsp = &(saveq->iocb);
  2450. list_del_init(&pring->iocb_continueq);
  2451. pring->iocb_continueq_cnt = 0;
  2452. pring->stats.iocb_rsp++;
  2453. /*
  2454. * If resource errors reported from HBA, reduce
  2455. * queuedepths of the SCSI device.
  2456. */
  2457. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2458. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2459. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2460. phba->lpfc_rampdown_queue_depth(phba);
  2461. spin_lock_irqsave(&phba->hbalock, iflag);
  2462. }
  2463. if (irsp->ulpStatus) {
  2464. /* Rsp ring <ringno> error: IOCB */
  2465. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2466. "0328 Rsp Ring %d error: "
  2467. "IOCB Data: "
  2468. "x%x x%x x%x x%x "
  2469. "x%x x%x x%x x%x "
  2470. "x%x x%x x%x x%x "
  2471. "x%x x%x x%x x%x\n",
  2472. pring->ringno,
  2473. irsp->un.ulpWord[0],
  2474. irsp->un.ulpWord[1],
  2475. irsp->un.ulpWord[2],
  2476. irsp->un.ulpWord[3],
  2477. irsp->un.ulpWord[4],
  2478. irsp->un.ulpWord[5],
  2479. *(((uint32_t *) irsp) + 6),
  2480. *(((uint32_t *) irsp) + 7),
  2481. *(((uint32_t *) irsp) + 8),
  2482. *(((uint32_t *) irsp) + 9),
  2483. *(((uint32_t *) irsp) + 10),
  2484. *(((uint32_t *) irsp) + 11),
  2485. *(((uint32_t *) irsp) + 12),
  2486. *(((uint32_t *) irsp) + 13),
  2487. *(((uint32_t *) irsp) + 14),
  2488. *(((uint32_t *) irsp) + 15));
  2489. }
  2490. /*
  2491. * Fetch the IOCB command type and call the correct completion
  2492. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2493. * get freed back to the lpfc_iocb_list by the discovery
  2494. * kernel thread.
  2495. */
  2496. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2497. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2498. switch (type) {
  2499. case LPFC_SOL_IOCB:
  2500. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2501. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2502. spin_lock_irqsave(&phba->hbalock, iflag);
  2503. break;
  2504. case LPFC_UNSOL_IOCB:
  2505. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2506. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2507. spin_lock_irqsave(&phba->hbalock, iflag);
  2508. if (!rc)
  2509. free_saveq = 0;
  2510. break;
  2511. case LPFC_ABORT_IOCB:
  2512. cmdiocbp = NULL;
  2513. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2514. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2515. saveq);
  2516. if (cmdiocbp) {
  2517. /* Call the specified completion routine */
  2518. if (cmdiocbp->iocb_cmpl) {
  2519. spin_unlock_irqrestore(&phba->hbalock,
  2520. iflag);
  2521. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2522. saveq);
  2523. spin_lock_irqsave(&phba->hbalock,
  2524. iflag);
  2525. } else
  2526. __lpfc_sli_release_iocbq(phba,
  2527. cmdiocbp);
  2528. }
  2529. break;
  2530. case LPFC_UNKNOWN_IOCB:
  2531. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2532. char adaptermsg[LPFC_MAX_ADPTMSG];
  2533. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2534. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2535. MAX_MSG_DATA);
  2536. dev_warn(&((phba->pcidev)->dev),
  2537. "lpfc%d: %s\n",
  2538. phba->brd_no, adaptermsg);
  2539. } else {
  2540. /* Unknown IOCB command */
  2541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2542. "0335 Unknown IOCB "
  2543. "command Data: x%x "
  2544. "x%x x%x x%x\n",
  2545. irsp->ulpCommand,
  2546. irsp->ulpStatus,
  2547. irsp->ulpIoTag,
  2548. irsp->ulpContext);
  2549. }
  2550. break;
  2551. }
  2552. if (free_saveq) {
  2553. list_for_each_entry_safe(rspiocbp, next_iocb,
  2554. &saveq->list, list) {
  2555. list_del(&rspiocbp->list);
  2556. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2557. }
  2558. __lpfc_sli_release_iocbq(phba, saveq);
  2559. }
  2560. rspiocbp = NULL;
  2561. }
  2562. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2563. return rspiocbp;
  2564. }
  2565. /**
  2566. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2567. * @phba: Pointer to HBA context object.
  2568. * @pring: Pointer to driver SLI ring object.
  2569. * @mask: Host attention register mask for this ring.
  2570. *
  2571. * This routine wraps the actual slow_ring event process routine from the
  2572. * API jump table function pointer from the lpfc_hba struct.
  2573. **/
  2574. void
  2575. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2576. struct lpfc_sli_ring *pring, uint32_t mask)
  2577. {
  2578. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2579. }
  2580. /**
  2581. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2582. * @phba: Pointer to HBA context object.
  2583. * @pring: Pointer to driver SLI ring object.
  2584. * @mask: Host attention register mask for this ring.
  2585. *
  2586. * This function is called from the worker thread when there is a ring event
  2587. * for non-fcp rings. The caller does not hold any lock. The function will
  2588. * remove each response iocb in the response ring and calls the handle
  2589. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2590. **/
  2591. static void
  2592. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2593. struct lpfc_sli_ring *pring, uint32_t mask)
  2594. {
  2595. struct lpfc_pgp *pgp;
  2596. IOCB_t *entry;
  2597. IOCB_t *irsp = NULL;
  2598. struct lpfc_iocbq *rspiocbp = NULL;
  2599. uint32_t portRspPut, portRspMax;
  2600. unsigned long iflag;
  2601. uint32_t status;
  2602. pgp = &phba->port_gp[pring->ringno];
  2603. spin_lock_irqsave(&phba->hbalock, iflag);
  2604. pring->stats.iocb_event++;
  2605. /*
  2606. * The next available response entry should never exceed the maximum
  2607. * entries. If it does, treat it as an adapter hardware error.
  2608. */
  2609. portRspMax = pring->numRiocb;
  2610. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2611. if (portRspPut >= portRspMax) {
  2612. /*
  2613. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2614. * rsp ring <portRspMax>
  2615. */
  2616. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2617. "0303 Ring %d handler: portRspPut %d "
  2618. "is bigger than rsp ring %d\n",
  2619. pring->ringno, portRspPut, portRspMax);
  2620. phba->link_state = LPFC_HBA_ERROR;
  2621. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2622. phba->work_hs = HS_FFER3;
  2623. lpfc_handle_eratt(phba);
  2624. return;
  2625. }
  2626. rmb();
  2627. while (pring->rspidx != portRspPut) {
  2628. /*
  2629. * Build a completion list and call the appropriate handler.
  2630. * The process is to get the next available response iocb, get
  2631. * a free iocb from the list, copy the response data into the
  2632. * free iocb, insert to the continuation list, and update the
  2633. * next response index to slim. This process makes response
  2634. * iocb's in the ring available to DMA as fast as possible but
  2635. * pays a penalty for a copy operation. Since the iocb is
  2636. * only 32 bytes, this penalty is considered small relative to
  2637. * the PCI reads for register values and a slim write. When
  2638. * the ulpLe field is set, the entire Command has been
  2639. * received.
  2640. */
  2641. entry = lpfc_resp_iocb(phba, pring);
  2642. phba->last_completion_time = jiffies;
  2643. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2644. if (rspiocbp == NULL) {
  2645. printk(KERN_ERR "%s: out of buffers! Failing "
  2646. "completion.\n", __func__);
  2647. break;
  2648. }
  2649. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2650. phba->iocb_rsp_size);
  2651. irsp = &rspiocbp->iocb;
  2652. if (++pring->rspidx >= portRspMax)
  2653. pring->rspidx = 0;
  2654. if (pring->ringno == LPFC_ELS_RING) {
  2655. lpfc_debugfs_slow_ring_trc(phba,
  2656. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2657. *(((uint32_t *) irsp) + 4),
  2658. *(((uint32_t *) irsp) + 6),
  2659. *(((uint32_t *) irsp) + 7));
  2660. }
  2661. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2662. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2663. /* Handle the response IOCB */
  2664. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2665. spin_lock_irqsave(&phba->hbalock, iflag);
  2666. /*
  2667. * If the port response put pointer has not been updated, sync
  2668. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2669. * response put pointer.
  2670. */
  2671. if (pring->rspidx == portRspPut) {
  2672. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2673. }
  2674. } /* while (pring->rspidx != portRspPut) */
  2675. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2676. /* At least one response entry has been freed */
  2677. pring->stats.iocb_rsp_full++;
  2678. /* SET RxRE_RSP in Chip Att register */
  2679. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2680. writel(status, phba->CAregaddr);
  2681. readl(phba->CAregaddr); /* flush */
  2682. }
  2683. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2684. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2685. pring->stats.iocb_cmd_empty++;
  2686. /* Force update of the local copy of cmdGetInx */
  2687. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2688. lpfc_sli_resume_iocb(phba, pring);
  2689. if ((pring->lpfc_sli_cmd_available))
  2690. (pring->lpfc_sli_cmd_available) (phba, pring);
  2691. }
  2692. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2693. return;
  2694. }
  2695. /**
  2696. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2697. * @phba: Pointer to HBA context object.
  2698. * @pring: Pointer to driver SLI ring object.
  2699. * @mask: Host attention register mask for this ring.
  2700. *
  2701. * This function is called from the worker thread when there is a pending
  2702. * ELS response iocb on the driver internal slow-path response iocb worker
  2703. * queue. The caller does not hold any lock. The function will remove each
  2704. * response iocb from the response worker queue and calls the handle
  2705. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2706. **/
  2707. static void
  2708. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2709. struct lpfc_sli_ring *pring, uint32_t mask)
  2710. {
  2711. struct lpfc_iocbq *irspiocbq;
  2712. struct hbq_dmabuf *dmabuf;
  2713. struct lpfc_cq_event *cq_event;
  2714. unsigned long iflag;
  2715. spin_lock_irqsave(&phba->hbalock, iflag);
  2716. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2717. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2718. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2719. /* Get the response iocb from the head of work queue */
  2720. spin_lock_irqsave(&phba->hbalock, iflag);
  2721. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2722. cq_event, struct lpfc_cq_event, list);
  2723. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2724. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2725. case CQE_CODE_COMPL_WQE:
  2726. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2727. cq_event);
  2728. /* Translate ELS WCQE to response IOCBQ */
  2729. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2730. irspiocbq);
  2731. if (irspiocbq)
  2732. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2733. irspiocbq);
  2734. break;
  2735. case CQE_CODE_RECEIVE:
  2736. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2737. cq_event);
  2738. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2739. break;
  2740. default:
  2741. break;
  2742. }
  2743. }
  2744. }
  2745. /**
  2746. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2747. * @phba: Pointer to HBA context object.
  2748. * @pring: Pointer to driver SLI ring object.
  2749. *
  2750. * This function aborts all iocbs in the given ring and frees all the iocb
  2751. * objects in txq. This function issues an abort iocb for all the iocb commands
  2752. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2753. * the return of this function. The caller is not required to hold any locks.
  2754. **/
  2755. void
  2756. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2757. {
  2758. LIST_HEAD(completions);
  2759. struct lpfc_iocbq *iocb, *next_iocb;
  2760. if (pring->ringno == LPFC_ELS_RING) {
  2761. lpfc_fabric_abort_hba(phba);
  2762. }
  2763. /* Error everything on txq and txcmplq
  2764. * First do the txq.
  2765. */
  2766. spin_lock_irq(&phba->hbalock);
  2767. list_splice_init(&pring->txq, &completions);
  2768. pring->txq_cnt = 0;
  2769. /* Next issue ABTS for everything on the txcmplq */
  2770. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2771. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2772. spin_unlock_irq(&phba->hbalock);
  2773. /* Cancel all the IOCBs from the completions list */
  2774. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2775. IOERR_SLI_ABORTED);
  2776. }
  2777. /**
  2778. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2779. * @phba: Pointer to HBA context object.
  2780. *
  2781. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2782. * objects in txq and txcmplq. This function will not issue abort iocbs
  2783. * for all the iocb commands in txcmplq, they will just be returned with
  2784. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2785. * slot has been permanently disabled.
  2786. **/
  2787. void
  2788. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2789. {
  2790. LIST_HEAD(txq);
  2791. LIST_HEAD(txcmplq);
  2792. struct lpfc_sli *psli = &phba->sli;
  2793. struct lpfc_sli_ring *pring;
  2794. /* Currently, only one fcp ring */
  2795. pring = &psli->ring[psli->fcp_ring];
  2796. spin_lock_irq(&phba->hbalock);
  2797. /* Retrieve everything on txq */
  2798. list_splice_init(&pring->txq, &txq);
  2799. pring->txq_cnt = 0;
  2800. /* Retrieve everything on the txcmplq */
  2801. list_splice_init(&pring->txcmplq, &txcmplq);
  2802. pring->txcmplq_cnt = 0;
  2803. spin_unlock_irq(&phba->hbalock);
  2804. /* Flush the txq */
  2805. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2806. IOERR_SLI_DOWN);
  2807. /* Flush the txcmpq */
  2808. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2809. IOERR_SLI_DOWN);
  2810. }
  2811. /**
  2812. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2813. * @phba: Pointer to HBA context object.
  2814. * @mask: Bit mask to be checked.
  2815. *
  2816. * This function reads the host status register and compares
  2817. * with the provided bit mask to check if HBA completed
  2818. * the restart. This function will wait in a loop for the
  2819. * HBA to complete restart. If the HBA does not restart within
  2820. * 15 iterations, the function will reset the HBA again. The
  2821. * function returns 1 when HBA fail to restart otherwise returns
  2822. * zero.
  2823. **/
  2824. static int
  2825. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2826. {
  2827. uint32_t status;
  2828. int i = 0;
  2829. int retval = 0;
  2830. /* Read the HBA Host Status Register */
  2831. status = readl(phba->HSregaddr);
  2832. /*
  2833. * Check status register every 100ms for 5 retries, then every
  2834. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2835. * every 2.5 sec for 4.
  2836. * Break our of the loop if errors occurred during init.
  2837. */
  2838. while (((status & mask) != mask) &&
  2839. !(status & HS_FFERM) &&
  2840. i++ < 20) {
  2841. if (i <= 5)
  2842. msleep(10);
  2843. else if (i <= 10)
  2844. msleep(500);
  2845. else
  2846. msleep(2500);
  2847. if (i == 15) {
  2848. /* Do post */
  2849. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2850. lpfc_sli_brdrestart(phba);
  2851. }
  2852. /* Read the HBA Host Status Register */
  2853. status = readl(phba->HSregaddr);
  2854. }
  2855. /* Check to see if any errors occurred during init */
  2856. if ((status & HS_FFERM) || (i >= 20)) {
  2857. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2858. "2751 Adapter failed to restart, "
  2859. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2860. status,
  2861. readl(phba->MBslimaddr + 0xa8),
  2862. readl(phba->MBslimaddr + 0xac));
  2863. phba->link_state = LPFC_HBA_ERROR;
  2864. retval = 1;
  2865. }
  2866. return retval;
  2867. }
  2868. /**
  2869. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2870. * @phba: Pointer to HBA context object.
  2871. * @mask: Bit mask to be checked.
  2872. *
  2873. * This function checks the host status register to check if HBA is
  2874. * ready. This function will wait in a loop for the HBA to be ready
  2875. * If the HBA is not ready , the function will will reset the HBA PCI
  2876. * function again. The function returns 1 when HBA fail to be ready
  2877. * otherwise returns zero.
  2878. **/
  2879. static int
  2880. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2881. {
  2882. uint32_t status;
  2883. int retval = 0;
  2884. /* Read the HBA Host Status Register */
  2885. status = lpfc_sli4_post_status_check(phba);
  2886. if (status) {
  2887. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2888. lpfc_sli_brdrestart(phba);
  2889. status = lpfc_sli4_post_status_check(phba);
  2890. }
  2891. /* Check to see if any errors occurred during init */
  2892. if (status) {
  2893. phba->link_state = LPFC_HBA_ERROR;
  2894. retval = 1;
  2895. } else
  2896. phba->sli4_hba.intr_enable = 0;
  2897. return retval;
  2898. }
  2899. /**
  2900. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2901. * @phba: Pointer to HBA context object.
  2902. * @mask: Bit mask to be checked.
  2903. *
  2904. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2905. * from the API jump table function pointer from the lpfc_hba struct.
  2906. **/
  2907. int
  2908. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2909. {
  2910. return phba->lpfc_sli_brdready(phba, mask);
  2911. }
  2912. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2913. /**
  2914. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2915. * @phba: Pointer to HBA context object.
  2916. *
  2917. * This function is called before resetting an HBA. This
  2918. * function requests HBA to quiesce DMAs before a reset.
  2919. **/
  2920. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2921. {
  2922. uint32_t __iomem *resp_buf;
  2923. uint32_t __iomem *mbox_buf;
  2924. volatile uint32_t mbox;
  2925. uint32_t hc_copy;
  2926. int i;
  2927. uint8_t hdrtype;
  2928. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2929. if (hdrtype != 0x80 ||
  2930. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2931. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2932. return;
  2933. /*
  2934. * Tell the other part of the chip to suspend temporarily all
  2935. * its DMA activity.
  2936. */
  2937. resp_buf = phba->MBslimaddr;
  2938. /* Disable the error attention */
  2939. hc_copy = readl(phba->HCregaddr);
  2940. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2941. readl(phba->HCregaddr); /* flush */
  2942. phba->link_flag |= LS_IGNORE_ERATT;
  2943. if (readl(phba->HAregaddr) & HA_ERATT) {
  2944. /* Clear Chip error bit */
  2945. writel(HA_ERATT, phba->HAregaddr);
  2946. phba->pport->stopped = 1;
  2947. }
  2948. mbox = 0;
  2949. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2950. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2951. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2952. mbox_buf = phba->MBslimaddr;
  2953. writel(mbox, mbox_buf);
  2954. for (i = 0;
  2955. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2956. mdelay(1);
  2957. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2958. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2959. phba->pport->stopped)
  2960. goto restore_hc;
  2961. else
  2962. goto clear_errat;
  2963. }
  2964. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2965. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2966. mdelay(1);
  2967. clear_errat:
  2968. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2969. mdelay(1);
  2970. if (readl(phba->HAregaddr) & HA_ERATT) {
  2971. writel(HA_ERATT, phba->HAregaddr);
  2972. phba->pport->stopped = 1;
  2973. }
  2974. restore_hc:
  2975. phba->link_flag &= ~LS_IGNORE_ERATT;
  2976. writel(hc_copy, phba->HCregaddr);
  2977. readl(phba->HCregaddr); /* flush */
  2978. }
  2979. /**
  2980. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2981. * @phba: Pointer to HBA context object.
  2982. *
  2983. * This function issues a kill_board mailbox command and waits for
  2984. * the error attention interrupt. This function is called for stopping
  2985. * the firmware processing. The caller is not required to hold any
  2986. * locks. This function calls lpfc_hba_down_post function to free
  2987. * any pending commands after the kill. The function will return 1 when it
  2988. * fails to kill the board else will return 0.
  2989. **/
  2990. int
  2991. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2992. {
  2993. struct lpfc_sli *psli;
  2994. LPFC_MBOXQ_t *pmb;
  2995. uint32_t status;
  2996. uint32_t ha_copy;
  2997. int retval;
  2998. int i = 0;
  2999. psli = &phba->sli;
  3000. /* Kill HBA */
  3001. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3002. "0329 Kill HBA Data: x%x x%x\n",
  3003. phba->pport->port_state, psli->sli_flag);
  3004. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3005. if (!pmb)
  3006. return 1;
  3007. /* Disable the error attention */
  3008. spin_lock_irq(&phba->hbalock);
  3009. status = readl(phba->HCregaddr);
  3010. status &= ~HC_ERINT_ENA;
  3011. writel(status, phba->HCregaddr);
  3012. readl(phba->HCregaddr); /* flush */
  3013. phba->link_flag |= LS_IGNORE_ERATT;
  3014. spin_unlock_irq(&phba->hbalock);
  3015. lpfc_kill_board(phba, pmb);
  3016. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3017. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3018. if (retval != MBX_SUCCESS) {
  3019. if (retval != MBX_BUSY)
  3020. mempool_free(pmb, phba->mbox_mem_pool);
  3021. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3022. "2752 KILL_BOARD command failed retval %d\n",
  3023. retval);
  3024. spin_lock_irq(&phba->hbalock);
  3025. phba->link_flag &= ~LS_IGNORE_ERATT;
  3026. spin_unlock_irq(&phba->hbalock);
  3027. return 1;
  3028. }
  3029. spin_lock_irq(&phba->hbalock);
  3030. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3031. spin_unlock_irq(&phba->hbalock);
  3032. mempool_free(pmb, phba->mbox_mem_pool);
  3033. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3034. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3035. * 3 seconds we still set HBA_ERROR state because the status of the
  3036. * board is now undefined.
  3037. */
  3038. ha_copy = readl(phba->HAregaddr);
  3039. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3040. mdelay(100);
  3041. ha_copy = readl(phba->HAregaddr);
  3042. }
  3043. del_timer_sync(&psli->mbox_tmo);
  3044. if (ha_copy & HA_ERATT) {
  3045. writel(HA_ERATT, phba->HAregaddr);
  3046. phba->pport->stopped = 1;
  3047. }
  3048. spin_lock_irq(&phba->hbalock);
  3049. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3050. psli->mbox_active = NULL;
  3051. phba->link_flag &= ~LS_IGNORE_ERATT;
  3052. spin_unlock_irq(&phba->hbalock);
  3053. lpfc_hba_down_post(phba);
  3054. phba->link_state = LPFC_HBA_ERROR;
  3055. return ha_copy & HA_ERATT ? 0 : 1;
  3056. }
  3057. /**
  3058. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3059. * @phba: Pointer to HBA context object.
  3060. *
  3061. * This function resets the HBA by writing HC_INITFF to the control
  3062. * register. After the HBA resets, this function resets all the iocb ring
  3063. * indices. This function disables PCI layer parity checking during
  3064. * the reset.
  3065. * This function returns 0 always.
  3066. * The caller is not required to hold any locks.
  3067. **/
  3068. int
  3069. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3070. {
  3071. struct lpfc_sli *psli;
  3072. struct lpfc_sli_ring *pring;
  3073. uint16_t cfg_value;
  3074. int i;
  3075. psli = &phba->sli;
  3076. /* Reset HBA */
  3077. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3078. "0325 Reset HBA Data: x%x x%x\n",
  3079. phba->pport->port_state, psli->sli_flag);
  3080. /* perform board reset */
  3081. phba->fc_eventTag = 0;
  3082. phba->link_events = 0;
  3083. phba->pport->fc_myDID = 0;
  3084. phba->pport->fc_prevDID = 0;
  3085. /* Turn off parity checking and serr during the physical reset */
  3086. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3087. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3088. (cfg_value &
  3089. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3090. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3091. /* Now toggle INITFF bit in the Host Control Register */
  3092. writel(HC_INITFF, phba->HCregaddr);
  3093. mdelay(1);
  3094. readl(phba->HCregaddr); /* flush */
  3095. writel(0, phba->HCregaddr);
  3096. readl(phba->HCregaddr); /* flush */
  3097. /* Restore PCI cmd register */
  3098. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3099. /* Initialize relevant SLI info */
  3100. for (i = 0; i < psli->num_rings; i++) {
  3101. pring = &psli->ring[i];
  3102. pring->flag = 0;
  3103. pring->rspidx = 0;
  3104. pring->next_cmdidx = 0;
  3105. pring->local_getidx = 0;
  3106. pring->cmdidx = 0;
  3107. pring->missbufcnt = 0;
  3108. }
  3109. phba->link_state = LPFC_WARM_START;
  3110. return 0;
  3111. }
  3112. /**
  3113. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3114. * @phba: Pointer to HBA context object.
  3115. *
  3116. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3117. * checking during resets the device. The caller is not required to hold
  3118. * any locks.
  3119. *
  3120. * This function returns 0 always.
  3121. **/
  3122. int
  3123. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3124. {
  3125. struct lpfc_sli *psli = &phba->sli;
  3126. uint16_t cfg_value;
  3127. uint8_t qindx;
  3128. /* Reset HBA */
  3129. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3130. "0295 Reset HBA Data: x%x x%x\n",
  3131. phba->pport->port_state, psli->sli_flag);
  3132. /* perform board reset */
  3133. phba->fc_eventTag = 0;
  3134. phba->link_events = 0;
  3135. phba->pport->fc_myDID = 0;
  3136. phba->pport->fc_prevDID = 0;
  3137. /* Turn off parity checking and serr during the physical reset */
  3138. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3139. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3140. (cfg_value &
  3141. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3142. spin_lock_irq(&phba->hbalock);
  3143. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3144. phba->fcf.fcf_flag = 0;
  3145. /* Clean up the child queue list for the CQs */
  3146. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3147. list_del_init(&phba->sli4_hba.els_wq->list);
  3148. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3149. list_del_init(&phba->sli4_hba.dat_rq->list);
  3150. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3151. list_del_init(&phba->sli4_hba.els_cq->list);
  3152. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3153. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3154. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3155. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3156. spin_unlock_irq(&phba->hbalock);
  3157. /* Now physically reset the device */
  3158. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3159. "0389 Performing PCI function reset!\n");
  3160. /* Perform FCoE PCI function reset */
  3161. lpfc_pci_function_reset(phba);
  3162. return 0;
  3163. }
  3164. /**
  3165. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3166. * @phba: Pointer to HBA context object.
  3167. *
  3168. * This function is called in the SLI initialization code path to
  3169. * restart the HBA. The caller is not required to hold any lock.
  3170. * This function writes MBX_RESTART mailbox command to the SLIM and
  3171. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3172. * function to free any pending commands. The function enables
  3173. * POST only during the first initialization. The function returns zero.
  3174. * The function does not guarantee completion of MBX_RESTART mailbox
  3175. * command before the return of this function.
  3176. **/
  3177. static int
  3178. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3179. {
  3180. MAILBOX_t *mb;
  3181. struct lpfc_sli *psli;
  3182. volatile uint32_t word0;
  3183. void __iomem *to_slim;
  3184. uint32_t hba_aer_enabled;
  3185. spin_lock_irq(&phba->hbalock);
  3186. /* Take PCIe device Advanced Error Reporting (AER) state */
  3187. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3188. psli = &phba->sli;
  3189. /* Restart HBA */
  3190. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3191. "0337 Restart HBA Data: x%x x%x\n",
  3192. phba->pport->port_state, psli->sli_flag);
  3193. word0 = 0;
  3194. mb = (MAILBOX_t *) &word0;
  3195. mb->mbxCommand = MBX_RESTART;
  3196. mb->mbxHc = 1;
  3197. lpfc_reset_barrier(phba);
  3198. to_slim = phba->MBslimaddr;
  3199. writel(*(uint32_t *) mb, to_slim);
  3200. readl(to_slim); /* flush */
  3201. /* Only skip post after fc_ffinit is completed */
  3202. if (phba->pport->port_state)
  3203. word0 = 1; /* This is really setting up word1 */
  3204. else
  3205. word0 = 0; /* This is really setting up word1 */
  3206. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3207. writel(*(uint32_t *) mb, to_slim);
  3208. readl(to_slim); /* flush */
  3209. lpfc_sli_brdreset(phba);
  3210. phba->pport->stopped = 0;
  3211. phba->link_state = LPFC_INIT_START;
  3212. phba->hba_flag = 0;
  3213. spin_unlock_irq(&phba->hbalock);
  3214. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3215. psli->stats_start = get_seconds();
  3216. /* Give the INITFF and Post time to settle. */
  3217. mdelay(100);
  3218. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3219. if (hba_aer_enabled)
  3220. pci_disable_pcie_error_reporting(phba->pcidev);
  3221. lpfc_hba_down_post(phba);
  3222. return 0;
  3223. }
  3224. /**
  3225. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3226. * @phba: Pointer to HBA context object.
  3227. *
  3228. * This function is called in the SLI initialization code path to restart
  3229. * a SLI4 HBA. The caller is not required to hold any lock.
  3230. * At the end of the function, it calls lpfc_hba_down_post function to
  3231. * free any pending commands.
  3232. **/
  3233. static int
  3234. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3235. {
  3236. struct lpfc_sli *psli = &phba->sli;
  3237. /* Restart HBA */
  3238. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3239. "0296 Restart HBA Data: x%x x%x\n",
  3240. phba->pport->port_state, psli->sli_flag);
  3241. lpfc_sli4_brdreset(phba);
  3242. spin_lock_irq(&phba->hbalock);
  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. lpfc_hba_down_post(phba);
  3250. return 0;
  3251. }
  3252. /**
  3253. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3254. * @phba: Pointer to HBA context object.
  3255. *
  3256. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3257. * API jump table function pointer from the lpfc_hba struct.
  3258. **/
  3259. int
  3260. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3261. {
  3262. return phba->lpfc_sli_brdrestart(phba);
  3263. }
  3264. /**
  3265. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3266. * @phba: Pointer to HBA context object.
  3267. *
  3268. * This function is called after a HBA restart to wait for successful
  3269. * restart of the HBA. Successful restart of the HBA is indicated by
  3270. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3271. * iteration, the function will restart the HBA again. The function returns
  3272. * zero if HBA successfully restarted else returns negative error code.
  3273. **/
  3274. static int
  3275. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3276. {
  3277. uint32_t status, i = 0;
  3278. /* Read the HBA Host Status Register */
  3279. status = readl(phba->HSregaddr);
  3280. /* Check status register to see what current state is */
  3281. i = 0;
  3282. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3283. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3284. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3285. * 4.
  3286. */
  3287. if (i++ >= 20) {
  3288. /* Adapter failed to init, timeout, status reg
  3289. <status> */
  3290. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3291. "0436 Adapter failed to init, "
  3292. "timeout, status reg x%x, "
  3293. "FW Data: A8 x%x AC x%x\n", status,
  3294. readl(phba->MBslimaddr + 0xa8),
  3295. readl(phba->MBslimaddr + 0xac));
  3296. phba->link_state = LPFC_HBA_ERROR;
  3297. return -ETIMEDOUT;
  3298. }
  3299. /* Check to see if any errors occurred during init */
  3300. if (status & HS_FFERM) {
  3301. /* ERROR: During chipset initialization */
  3302. /* Adapter failed to init, chipset, status reg
  3303. <status> */
  3304. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3305. "0437 Adapter failed to init, "
  3306. "chipset, status reg x%x, "
  3307. "FW Data: A8 x%x AC x%x\n", status,
  3308. readl(phba->MBslimaddr + 0xa8),
  3309. readl(phba->MBslimaddr + 0xac));
  3310. phba->link_state = LPFC_HBA_ERROR;
  3311. return -EIO;
  3312. }
  3313. if (i <= 5) {
  3314. msleep(10);
  3315. } else if (i <= 10) {
  3316. msleep(500);
  3317. } else {
  3318. msleep(2500);
  3319. }
  3320. if (i == 15) {
  3321. /* Do post */
  3322. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3323. lpfc_sli_brdrestart(phba);
  3324. }
  3325. /* Read the HBA Host Status Register */
  3326. status = readl(phba->HSregaddr);
  3327. }
  3328. /* Check to see if any errors occurred during init */
  3329. if (status & HS_FFERM) {
  3330. /* ERROR: During chipset initialization */
  3331. /* Adapter failed to init, chipset, status reg <status> */
  3332. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3333. "0438 Adapter failed to init, chipset, "
  3334. "status reg x%x, "
  3335. "FW Data: A8 x%x AC x%x\n", status,
  3336. readl(phba->MBslimaddr + 0xa8),
  3337. readl(phba->MBslimaddr + 0xac));
  3338. phba->link_state = LPFC_HBA_ERROR;
  3339. return -EIO;
  3340. }
  3341. /* Clear all interrupt enable conditions */
  3342. writel(0, phba->HCregaddr);
  3343. readl(phba->HCregaddr); /* flush */
  3344. /* setup host attn register */
  3345. writel(0xffffffff, phba->HAregaddr);
  3346. readl(phba->HAregaddr); /* flush */
  3347. return 0;
  3348. }
  3349. /**
  3350. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3351. *
  3352. * This function calculates and returns the number of HBQs required to be
  3353. * configured.
  3354. **/
  3355. int
  3356. lpfc_sli_hbq_count(void)
  3357. {
  3358. return ARRAY_SIZE(lpfc_hbq_defs);
  3359. }
  3360. /**
  3361. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3362. *
  3363. * This function adds the number of hbq entries in every HBQ to get
  3364. * the total number of hbq entries required for the HBA and returns
  3365. * the total count.
  3366. **/
  3367. static int
  3368. lpfc_sli_hbq_entry_count(void)
  3369. {
  3370. int hbq_count = lpfc_sli_hbq_count();
  3371. int count = 0;
  3372. int i;
  3373. for (i = 0; i < hbq_count; ++i)
  3374. count += lpfc_hbq_defs[i]->entry_count;
  3375. return count;
  3376. }
  3377. /**
  3378. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3379. *
  3380. * This function calculates amount of memory required for all hbq entries
  3381. * to be configured and returns the total memory required.
  3382. **/
  3383. int
  3384. lpfc_sli_hbq_size(void)
  3385. {
  3386. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3387. }
  3388. /**
  3389. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3390. * @phba: Pointer to HBA context object.
  3391. *
  3392. * This function is called during the SLI initialization to configure
  3393. * all the HBQs and post buffers to the HBQ. The caller is not
  3394. * required to hold any locks. This function will return zero if successful
  3395. * else it will return negative error code.
  3396. **/
  3397. static int
  3398. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3399. {
  3400. int hbq_count = lpfc_sli_hbq_count();
  3401. LPFC_MBOXQ_t *pmb;
  3402. MAILBOX_t *pmbox;
  3403. uint32_t hbqno;
  3404. uint32_t hbq_entry_index;
  3405. /* Get a Mailbox buffer to setup mailbox
  3406. * commands for HBA initialization
  3407. */
  3408. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3409. if (!pmb)
  3410. return -ENOMEM;
  3411. pmbox = &pmb->u.mb;
  3412. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3413. phba->link_state = LPFC_INIT_MBX_CMDS;
  3414. phba->hbq_in_use = 1;
  3415. hbq_entry_index = 0;
  3416. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3417. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3418. phba->hbqs[hbqno].hbqPutIdx = 0;
  3419. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3420. phba->hbqs[hbqno].entry_count =
  3421. lpfc_hbq_defs[hbqno]->entry_count;
  3422. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3423. hbq_entry_index, pmb);
  3424. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3425. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3426. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3427. mbxStatus <status>, ring <num> */
  3428. lpfc_printf_log(phba, KERN_ERR,
  3429. LOG_SLI | LOG_VPORT,
  3430. "1805 Adapter failed to init. "
  3431. "Data: x%x x%x x%x\n",
  3432. pmbox->mbxCommand,
  3433. pmbox->mbxStatus, hbqno);
  3434. phba->link_state = LPFC_HBA_ERROR;
  3435. mempool_free(pmb, phba->mbox_mem_pool);
  3436. return -ENXIO;
  3437. }
  3438. }
  3439. phba->hbq_count = hbq_count;
  3440. mempool_free(pmb, phba->mbox_mem_pool);
  3441. /* Initially populate or replenish the HBQs */
  3442. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3443. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3444. return 0;
  3445. }
  3446. /**
  3447. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3448. * @phba: Pointer to HBA context object.
  3449. *
  3450. * This function is called during the SLI initialization to configure
  3451. * all the HBQs and post buffers to the HBQ. The caller is not
  3452. * required to hold any locks. This function will return zero if successful
  3453. * else it will return negative error code.
  3454. **/
  3455. static int
  3456. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3457. {
  3458. phba->hbq_in_use = 1;
  3459. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3460. phba->hbq_count = 1;
  3461. /* Initially populate or replenish the HBQs */
  3462. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3463. return 0;
  3464. }
  3465. /**
  3466. * lpfc_sli_config_port - Issue config port mailbox command
  3467. * @phba: Pointer to HBA context object.
  3468. * @sli_mode: sli mode - 2/3
  3469. *
  3470. * This function is called by the sli intialization code path
  3471. * to issue config_port mailbox command. This function restarts the
  3472. * HBA firmware and issues a config_port mailbox command to configure
  3473. * the SLI interface in the sli mode specified by sli_mode
  3474. * variable. The caller is not required to hold any locks.
  3475. * The function returns 0 if successful, else returns negative error
  3476. * code.
  3477. **/
  3478. int
  3479. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3480. {
  3481. LPFC_MBOXQ_t *pmb;
  3482. uint32_t resetcount = 0, rc = 0, done = 0;
  3483. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3484. if (!pmb) {
  3485. phba->link_state = LPFC_HBA_ERROR;
  3486. return -ENOMEM;
  3487. }
  3488. phba->sli_rev = sli_mode;
  3489. while (resetcount < 2 && !done) {
  3490. spin_lock_irq(&phba->hbalock);
  3491. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3492. spin_unlock_irq(&phba->hbalock);
  3493. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3494. lpfc_sli_brdrestart(phba);
  3495. rc = lpfc_sli_chipset_init(phba);
  3496. if (rc)
  3497. break;
  3498. spin_lock_irq(&phba->hbalock);
  3499. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3500. spin_unlock_irq(&phba->hbalock);
  3501. resetcount++;
  3502. /* Call pre CONFIG_PORT mailbox command initialization. A
  3503. * value of 0 means the call was successful. Any other
  3504. * nonzero value is a failure, but if ERESTART is returned,
  3505. * the driver may reset the HBA and try again.
  3506. */
  3507. rc = lpfc_config_port_prep(phba);
  3508. if (rc == -ERESTART) {
  3509. phba->link_state = LPFC_LINK_UNKNOWN;
  3510. continue;
  3511. } else if (rc)
  3512. break;
  3513. phba->link_state = LPFC_INIT_MBX_CMDS;
  3514. lpfc_config_port(phba, pmb);
  3515. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3516. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3517. LPFC_SLI3_HBQ_ENABLED |
  3518. LPFC_SLI3_CRP_ENABLED |
  3519. LPFC_SLI3_BG_ENABLED);
  3520. if (rc != MBX_SUCCESS) {
  3521. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3522. "0442 Adapter failed to init, mbxCmd x%x "
  3523. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3524. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3525. spin_lock_irq(&phba->hbalock);
  3526. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3527. spin_unlock_irq(&phba->hbalock);
  3528. rc = -ENXIO;
  3529. } else {
  3530. /* Allow asynchronous mailbox command to go through */
  3531. spin_lock_irq(&phba->hbalock);
  3532. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3533. spin_unlock_irq(&phba->hbalock);
  3534. done = 1;
  3535. }
  3536. }
  3537. if (!done) {
  3538. rc = -EINVAL;
  3539. goto do_prep_failed;
  3540. }
  3541. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3542. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3543. rc = -ENXIO;
  3544. goto do_prep_failed;
  3545. }
  3546. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3547. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3548. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3549. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3550. phba->max_vpi : phba->max_vports;
  3551. } else
  3552. phba->max_vpi = 0;
  3553. if (pmb->u.mb.un.varCfgPort.gdss)
  3554. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3555. if (pmb->u.mb.un.varCfgPort.gerbm)
  3556. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3557. if (pmb->u.mb.un.varCfgPort.gcrp)
  3558. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3559. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3560. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3561. if (phba->cfg_enable_bg) {
  3562. if (pmb->u.mb.un.varCfgPort.gbg)
  3563. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3564. else
  3565. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3566. "0443 Adapter did not grant "
  3567. "BlockGuard\n");
  3568. }
  3569. } else {
  3570. phba->hbq_get = NULL;
  3571. phba->port_gp = phba->mbox->us.s2.port;
  3572. phba->max_vpi = 0;
  3573. }
  3574. do_prep_failed:
  3575. mempool_free(pmb, phba->mbox_mem_pool);
  3576. return rc;
  3577. }
  3578. /**
  3579. * lpfc_sli_hba_setup - SLI intialization function
  3580. * @phba: Pointer to HBA context object.
  3581. *
  3582. * This function is the main SLI intialization function. This function
  3583. * is called by the HBA intialization code, HBA reset code and HBA
  3584. * error attention handler code. Caller is not required to hold any
  3585. * locks. This function issues config_port mailbox command to configure
  3586. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3587. * calls the config_port_post function to issue init_link mailbox
  3588. * command and to start the discovery. The function will return zero
  3589. * if successful, else it will return negative error code.
  3590. **/
  3591. int
  3592. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3593. {
  3594. uint32_t rc;
  3595. int mode = 3;
  3596. switch (lpfc_sli_mode) {
  3597. case 2:
  3598. if (phba->cfg_enable_npiv) {
  3599. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3600. "1824 NPIV enabled: Override lpfc_sli_mode "
  3601. "parameter (%d) to auto (0).\n",
  3602. lpfc_sli_mode);
  3603. break;
  3604. }
  3605. mode = 2;
  3606. break;
  3607. case 0:
  3608. case 3:
  3609. break;
  3610. default:
  3611. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3612. "1819 Unrecognized lpfc_sli_mode "
  3613. "parameter: %d.\n", lpfc_sli_mode);
  3614. break;
  3615. }
  3616. rc = lpfc_sli_config_port(phba, mode);
  3617. if (rc && lpfc_sli_mode == 3)
  3618. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3619. "1820 Unable to select SLI-3. "
  3620. "Not supported by adapter.\n");
  3621. if (rc && mode != 2)
  3622. rc = lpfc_sli_config_port(phba, 2);
  3623. if (rc)
  3624. goto lpfc_sli_hba_setup_error;
  3625. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3626. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3627. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3628. if (!rc) {
  3629. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3630. "2709 This device supports "
  3631. "Advanced Error Reporting (AER)\n");
  3632. spin_lock_irq(&phba->hbalock);
  3633. phba->hba_flag |= HBA_AER_ENABLED;
  3634. spin_unlock_irq(&phba->hbalock);
  3635. } else {
  3636. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3637. "2708 This device does not support "
  3638. "Advanced Error Reporting (AER)\n");
  3639. phba->cfg_aer_support = 0;
  3640. }
  3641. }
  3642. if (phba->sli_rev == 3) {
  3643. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3644. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3645. } else {
  3646. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3647. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3648. phba->sli3_options = 0;
  3649. }
  3650. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3651. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3652. phba->sli_rev, phba->max_vpi);
  3653. rc = lpfc_sli_ring_map(phba);
  3654. if (rc)
  3655. goto lpfc_sli_hba_setup_error;
  3656. /* Init HBQs */
  3657. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3658. rc = lpfc_sli_hbq_setup(phba);
  3659. if (rc)
  3660. goto lpfc_sli_hba_setup_error;
  3661. }
  3662. spin_lock_irq(&phba->hbalock);
  3663. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3664. spin_unlock_irq(&phba->hbalock);
  3665. rc = lpfc_config_port_post(phba);
  3666. if (rc)
  3667. goto lpfc_sli_hba_setup_error;
  3668. return rc;
  3669. lpfc_sli_hba_setup_error:
  3670. phba->link_state = LPFC_HBA_ERROR;
  3671. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3672. "0445 Firmware initialization failed\n");
  3673. return rc;
  3674. }
  3675. /**
  3676. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3677. * @phba: Pointer to HBA context object.
  3678. * @mboxq: mailbox pointer.
  3679. * This function issue a dump mailbox command to read config region
  3680. * 23 and parse the records in the region and populate driver
  3681. * data structure.
  3682. **/
  3683. static int
  3684. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3685. LPFC_MBOXQ_t *mboxq)
  3686. {
  3687. struct lpfc_dmabuf *mp;
  3688. struct lpfc_mqe *mqe;
  3689. uint32_t data_length;
  3690. int rc;
  3691. /* Program the default value of vlan_id and fc_map */
  3692. phba->valid_vlan = 0;
  3693. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3694. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3695. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3696. mqe = &mboxq->u.mqe;
  3697. if (lpfc_dump_fcoe_param(phba, mboxq))
  3698. return -ENOMEM;
  3699. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3700. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3701. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3702. "(%d):2571 Mailbox cmd x%x Status x%x "
  3703. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3704. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3705. "CQ: x%x x%x x%x x%x\n",
  3706. mboxq->vport ? mboxq->vport->vpi : 0,
  3707. bf_get(lpfc_mqe_command, mqe),
  3708. bf_get(lpfc_mqe_status, mqe),
  3709. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3710. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3711. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3712. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3713. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3714. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3715. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3716. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3717. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3718. mboxq->mcqe.word0,
  3719. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3720. mboxq->mcqe.trailer);
  3721. if (rc) {
  3722. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3723. kfree(mp);
  3724. return -EIO;
  3725. }
  3726. data_length = mqe->un.mb_words[5];
  3727. if (data_length > DMP_RGN23_SIZE) {
  3728. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3729. kfree(mp);
  3730. return -EIO;
  3731. }
  3732. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3733. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3734. kfree(mp);
  3735. return 0;
  3736. }
  3737. /**
  3738. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3739. * @phba: pointer to lpfc hba data structure.
  3740. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3741. * @vpd: pointer to the memory to hold resulting port vpd data.
  3742. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3743. * On output, the number of data bytes in @vpd.
  3744. *
  3745. * This routine executes a READ_REV SLI4 mailbox command. In
  3746. * addition, this routine gets the port vpd data.
  3747. *
  3748. * Return codes
  3749. * 0 - successful
  3750. * ENOMEM - could not allocated memory.
  3751. **/
  3752. static int
  3753. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3754. uint8_t *vpd, uint32_t *vpd_size)
  3755. {
  3756. int rc = 0;
  3757. uint32_t dma_size;
  3758. struct lpfc_dmabuf *dmabuf;
  3759. struct lpfc_mqe *mqe;
  3760. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3761. if (!dmabuf)
  3762. return -ENOMEM;
  3763. /*
  3764. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3765. * mailbox command.
  3766. */
  3767. dma_size = *vpd_size;
  3768. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3769. dma_size,
  3770. &dmabuf->phys,
  3771. GFP_KERNEL);
  3772. if (!dmabuf->virt) {
  3773. kfree(dmabuf);
  3774. return -ENOMEM;
  3775. }
  3776. memset(dmabuf->virt, 0, dma_size);
  3777. /*
  3778. * The SLI4 implementation of READ_REV conflicts at word1,
  3779. * bits 31:16 and SLI4 adds vpd functionality not present
  3780. * in SLI3. This code corrects the conflicts.
  3781. */
  3782. lpfc_read_rev(phba, mboxq);
  3783. mqe = &mboxq->u.mqe;
  3784. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3785. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3786. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3787. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3788. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3789. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3790. if (rc) {
  3791. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3792. dmabuf->virt, dmabuf->phys);
  3793. kfree(dmabuf);
  3794. return -EIO;
  3795. }
  3796. /*
  3797. * The available vpd length cannot be bigger than the
  3798. * DMA buffer passed to the port. Catch the less than
  3799. * case and update the caller's size.
  3800. */
  3801. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3802. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3803. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3804. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3805. dmabuf->virt, dmabuf->phys);
  3806. kfree(dmabuf);
  3807. return 0;
  3808. }
  3809. /**
  3810. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3811. * @phba: pointer to lpfc hba data structure.
  3812. *
  3813. * This routine is called to explicitly arm the SLI4 device's completion and
  3814. * event queues
  3815. **/
  3816. static void
  3817. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3818. {
  3819. uint8_t fcp_eqidx;
  3820. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3821. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3822. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3823. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3824. LPFC_QUEUE_REARM);
  3825. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3826. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3827. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3828. LPFC_QUEUE_REARM);
  3829. }
  3830. /**
  3831. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3832. * @phba: Pointer to HBA context object.
  3833. *
  3834. * This function is the main SLI4 device intialization PCI function. This
  3835. * function is called by the HBA intialization code, HBA reset code and
  3836. * HBA error attention handler code. Caller is not required to hold any
  3837. * locks.
  3838. **/
  3839. int
  3840. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3841. {
  3842. int rc;
  3843. LPFC_MBOXQ_t *mboxq;
  3844. struct lpfc_mqe *mqe;
  3845. uint8_t *vpd;
  3846. uint32_t vpd_size;
  3847. uint32_t ftr_rsp = 0;
  3848. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3849. struct lpfc_vport *vport = phba->pport;
  3850. struct lpfc_dmabuf *mp;
  3851. /* Perform a PCI function reset to start from clean */
  3852. rc = lpfc_pci_function_reset(phba);
  3853. if (unlikely(rc))
  3854. return -ENODEV;
  3855. /* Check the HBA Host Status Register for readyness */
  3856. rc = lpfc_sli4_post_status_check(phba);
  3857. if (unlikely(rc))
  3858. return -ENODEV;
  3859. else {
  3860. spin_lock_irq(&phba->hbalock);
  3861. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3862. spin_unlock_irq(&phba->hbalock);
  3863. }
  3864. /*
  3865. * Allocate a single mailbox container for initializing the
  3866. * port.
  3867. */
  3868. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3869. if (!mboxq)
  3870. return -ENOMEM;
  3871. /*
  3872. * Continue initialization with default values even if driver failed
  3873. * to read FCoE param config regions
  3874. */
  3875. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3876. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3877. "2570 Failed to read FCoE parameters\n");
  3878. /* Issue READ_REV to collect vpd and FW information. */
  3879. vpd_size = SLI4_PAGE_SIZE;
  3880. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3881. if (!vpd) {
  3882. rc = -ENOMEM;
  3883. goto out_free_mbox;
  3884. }
  3885. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3886. if (unlikely(rc))
  3887. goto out_free_vpd;
  3888. mqe = &mboxq->u.mqe;
  3889. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3890. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3891. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3892. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3893. LPFC_DCBX_CEE_MODE)
  3894. phba->hba_flag |= HBA_FIP_SUPPORT;
  3895. else
  3896. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3897. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3898. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3899. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3900. "0376 READ_REV Error. SLI Level %d "
  3901. "FCoE enabled %d\n",
  3902. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3903. rc = -EIO;
  3904. goto out_free_vpd;
  3905. }
  3906. /*
  3907. * Evaluate the read rev and vpd data. Populate the driver
  3908. * state with the results. If this routine fails, the failure
  3909. * is not fatal as the driver will use generic values.
  3910. */
  3911. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3912. if (unlikely(!rc)) {
  3913. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3914. "0377 Error %d parsing vpd. "
  3915. "Using defaults.\n", rc);
  3916. rc = 0;
  3917. }
  3918. /* Save information as VPD data */
  3919. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3920. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3921. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3922. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3923. &mqe->un.read_rev);
  3924. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3925. &mqe->un.read_rev);
  3926. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3927. &mqe->un.read_rev);
  3928. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3929. &mqe->un.read_rev);
  3930. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3931. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3932. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3933. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3934. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3935. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3936. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3937. "(%d):0380 READ_REV Status x%x "
  3938. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3939. mboxq->vport ? mboxq->vport->vpi : 0,
  3940. bf_get(lpfc_mqe_status, mqe),
  3941. phba->vpd.rev.opFwName,
  3942. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3943. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3944. /*
  3945. * Discover the port's supported feature set and match it against the
  3946. * hosts requests.
  3947. */
  3948. lpfc_request_features(phba, mboxq);
  3949. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3950. if (unlikely(rc)) {
  3951. rc = -EIO;
  3952. goto out_free_vpd;
  3953. }
  3954. /*
  3955. * The port must support FCP initiator mode as this is the
  3956. * only mode running in the host.
  3957. */
  3958. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3959. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3960. "0378 No support for fcpi mode.\n");
  3961. ftr_rsp++;
  3962. }
  3963. /*
  3964. * If the port cannot support the host's requested features
  3965. * then turn off the global config parameters to disable the
  3966. * feature in the driver. This is not a fatal error.
  3967. */
  3968. if ((phba->cfg_enable_bg) &&
  3969. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3970. ftr_rsp++;
  3971. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3972. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3973. ftr_rsp++;
  3974. if (ftr_rsp) {
  3975. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3976. "0379 Feature Mismatch Data: x%08x %08x "
  3977. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3978. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3979. phba->cfg_enable_npiv, phba->max_vpi);
  3980. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3981. phba->cfg_enable_bg = 0;
  3982. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3983. phba->cfg_enable_npiv = 0;
  3984. }
  3985. /* These SLI3 features are assumed in SLI4 */
  3986. spin_lock_irq(&phba->hbalock);
  3987. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3988. spin_unlock_irq(&phba->hbalock);
  3989. /* Read the port's service parameters. */
  3990. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  3991. if (rc) {
  3992. phba->link_state = LPFC_HBA_ERROR;
  3993. rc = -ENOMEM;
  3994. goto out_free_vpd;
  3995. }
  3996. mboxq->vport = vport;
  3997. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3998. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3999. if (rc == MBX_SUCCESS) {
  4000. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4001. rc = 0;
  4002. }
  4003. /*
  4004. * This memory was allocated by the lpfc_read_sparam routine. Release
  4005. * it to the mbuf pool.
  4006. */
  4007. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4008. kfree(mp);
  4009. mboxq->context1 = NULL;
  4010. if (unlikely(rc)) {
  4011. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4012. "0382 READ_SPARAM command failed "
  4013. "status %d, mbxStatus x%x\n",
  4014. rc, bf_get(lpfc_mqe_status, mqe));
  4015. phba->link_state = LPFC_HBA_ERROR;
  4016. rc = -EIO;
  4017. goto out_free_vpd;
  4018. }
  4019. if (phba->cfg_soft_wwnn)
  4020. u64_to_wwn(phba->cfg_soft_wwnn,
  4021. vport->fc_sparam.nodeName.u.wwn);
  4022. if (phba->cfg_soft_wwpn)
  4023. u64_to_wwn(phba->cfg_soft_wwpn,
  4024. vport->fc_sparam.portName.u.wwn);
  4025. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4026. sizeof(struct lpfc_name));
  4027. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4028. sizeof(struct lpfc_name));
  4029. /* Update the fc_host data structures with new wwn. */
  4030. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4031. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4032. /* Register SGL pool to the device using non-embedded mailbox command */
  4033. rc = lpfc_sli4_post_sgl_list(phba);
  4034. if (unlikely(rc)) {
  4035. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4036. "0582 Error %d during sgl post operation\n",
  4037. rc);
  4038. rc = -ENODEV;
  4039. goto out_free_vpd;
  4040. }
  4041. /* Register SCSI SGL pool to the device */
  4042. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4043. if (unlikely(rc)) {
  4044. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4045. "0383 Error %d during scsi sgl post "
  4046. "operation\n", rc);
  4047. /* Some Scsi buffers were moved to the abort scsi list */
  4048. /* A pci function reset will repost them */
  4049. rc = -ENODEV;
  4050. goto out_free_vpd;
  4051. }
  4052. /* Post the rpi header region to the device. */
  4053. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4054. if (unlikely(rc)) {
  4055. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4056. "0393 Error %d during rpi post operation\n",
  4057. rc);
  4058. rc = -ENODEV;
  4059. goto out_free_vpd;
  4060. }
  4061. /* Set up all the queues to the device */
  4062. rc = lpfc_sli4_queue_setup(phba);
  4063. if (unlikely(rc)) {
  4064. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4065. "0381 Error %d during queue setup.\n ", rc);
  4066. goto out_stop_timers;
  4067. }
  4068. /* Arm the CQs and then EQs on device */
  4069. lpfc_sli4_arm_cqeq_intr(phba);
  4070. /* Indicate device interrupt mode */
  4071. phba->sli4_hba.intr_enable = 1;
  4072. /* Allow asynchronous mailbox command to go through */
  4073. spin_lock_irq(&phba->hbalock);
  4074. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4075. spin_unlock_irq(&phba->hbalock);
  4076. /* Post receive buffers to the device */
  4077. lpfc_sli4_rb_setup(phba);
  4078. /* Reset HBA FCF states after HBA reset */
  4079. phba->fcf.fcf_flag = 0;
  4080. phba->fcf.current_rec.flag = 0;
  4081. /* Start the ELS watchdog timer */
  4082. mod_timer(&vport->els_tmofunc,
  4083. jiffies + HZ * (phba->fc_ratov * 2));
  4084. /* Start heart beat timer */
  4085. mod_timer(&phba->hb_tmofunc,
  4086. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4087. phba->hb_outstanding = 0;
  4088. phba->last_completion_time = jiffies;
  4089. /* Start error attention (ERATT) polling timer */
  4090. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4091. /*
  4092. * The port is ready, set the host's link state to LINK_DOWN
  4093. * in preparation for link interrupts.
  4094. */
  4095. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4096. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4097. lpfc_set_loopback_flag(phba);
  4098. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4099. spin_lock_irq(&phba->hbalock);
  4100. phba->link_state = LPFC_LINK_DOWN;
  4101. spin_unlock_irq(&phba->hbalock);
  4102. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4103. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4104. kfree(vpd);
  4105. return 0;
  4106. } else
  4107. rc = -EIO;
  4108. /* Unset all the queues set up in this routine when error out */
  4109. if (rc)
  4110. lpfc_sli4_queue_unset(phba);
  4111. out_stop_timers:
  4112. if (rc)
  4113. lpfc_stop_hba_timers(phba);
  4114. out_free_vpd:
  4115. kfree(vpd);
  4116. out_free_mbox:
  4117. mempool_free(mboxq, phba->mbox_mem_pool);
  4118. return rc;
  4119. }
  4120. /**
  4121. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4122. * @ptr: context object - pointer to hba structure.
  4123. *
  4124. * This is the callback function for mailbox timer. The mailbox
  4125. * timer is armed when a new mailbox command is issued and the timer
  4126. * is deleted when the mailbox complete. The function is called by
  4127. * the kernel timer code when a mailbox does not complete within
  4128. * expected time. This function wakes up the worker thread to
  4129. * process the mailbox timeout and returns. All the processing is
  4130. * done by the worker thread function lpfc_mbox_timeout_handler.
  4131. **/
  4132. void
  4133. lpfc_mbox_timeout(unsigned long ptr)
  4134. {
  4135. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4136. unsigned long iflag;
  4137. uint32_t tmo_posted;
  4138. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4139. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4140. if (!tmo_posted)
  4141. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4142. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4143. if (!tmo_posted)
  4144. lpfc_worker_wake_up(phba);
  4145. return;
  4146. }
  4147. /**
  4148. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4149. * @phba: Pointer to HBA context object.
  4150. *
  4151. * This function is called from worker thread when a mailbox command times out.
  4152. * The caller is not required to hold any locks. This function will reset the
  4153. * HBA and recover all the pending commands.
  4154. **/
  4155. void
  4156. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4157. {
  4158. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4159. MAILBOX_t *mb = &pmbox->u.mb;
  4160. struct lpfc_sli *psli = &phba->sli;
  4161. struct lpfc_sli_ring *pring;
  4162. /* Check the pmbox pointer first. There is a race condition
  4163. * between the mbox timeout handler getting executed in the
  4164. * worklist and the mailbox actually completing. When this
  4165. * race condition occurs, the mbox_active will be NULL.
  4166. */
  4167. spin_lock_irq(&phba->hbalock);
  4168. if (pmbox == NULL) {
  4169. lpfc_printf_log(phba, KERN_WARNING,
  4170. LOG_MBOX | LOG_SLI,
  4171. "0353 Active Mailbox cleared - mailbox timeout "
  4172. "exiting\n");
  4173. spin_unlock_irq(&phba->hbalock);
  4174. return;
  4175. }
  4176. /* Mbox cmd <mbxCommand> timeout */
  4177. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4178. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4179. mb->mbxCommand,
  4180. phba->pport->port_state,
  4181. phba->sli.sli_flag,
  4182. phba->sli.mbox_active);
  4183. spin_unlock_irq(&phba->hbalock);
  4184. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4185. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4186. * it to fail all oustanding SCSI IO.
  4187. */
  4188. spin_lock_irq(&phba->pport->work_port_lock);
  4189. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4190. spin_unlock_irq(&phba->pport->work_port_lock);
  4191. spin_lock_irq(&phba->hbalock);
  4192. phba->link_state = LPFC_LINK_UNKNOWN;
  4193. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4194. spin_unlock_irq(&phba->hbalock);
  4195. pring = &psli->ring[psli->fcp_ring];
  4196. lpfc_sli_abort_iocb_ring(phba, pring);
  4197. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4198. "0345 Resetting board due to mailbox timeout\n");
  4199. /* Reset the HBA device */
  4200. lpfc_reset_hba(phba);
  4201. }
  4202. /**
  4203. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4204. * @phba: Pointer to HBA context object.
  4205. * @pmbox: Pointer to mailbox object.
  4206. * @flag: Flag indicating how the mailbox need to be processed.
  4207. *
  4208. * This function is called by discovery code and HBA management code
  4209. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4210. * function gets the hbalock to protect the data structures.
  4211. * The mailbox command can be submitted in polling mode, in which case
  4212. * this function will wait in a polling loop for the completion of the
  4213. * mailbox.
  4214. * If the mailbox is submitted in no_wait mode (not polling) the
  4215. * function will submit the command and returns immediately without waiting
  4216. * for the mailbox completion. The no_wait is supported only when HBA
  4217. * is in SLI2/SLI3 mode - interrupts are enabled.
  4218. * The SLI interface allows only one mailbox pending at a time. If the
  4219. * mailbox is issued in polling mode and there is already a mailbox
  4220. * pending, then the function will return an error. If the mailbox is issued
  4221. * in NO_WAIT mode and there is a mailbox pending already, the function
  4222. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4223. * The sli layer owns the mailbox object until the completion of mailbox
  4224. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4225. * return codes the caller owns the mailbox command after the return of
  4226. * the function.
  4227. **/
  4228. static int
  4229. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4230. uint32_t flag)
  4231. {
  4232. MAILBOX_t *mb;
  4233. struct lpfc_sli *psli = &phba->sli;
  4234. uint32_t status, evtctr;
  4235. uint32_t ha_copy;
  4236. int i;
  4237. unsigned long timeout;
  4238. unsigned long drvr_flag = 0;
  4239. uint32_t word0, ldata;
  4240. void __iomem *to_slim;
  4241. int processing_queue = 0;
  4242. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4243. if (!pmbox) {
  4244. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4245. /* processing mbox queue from intr_handler */
  4246. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4247. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4248. return MBX_SUCCESS;
  4249. }
  4250. processing_queue = 1;
  4251. pmbox = lpfc_mbox_get(phba);
  4252. if (!pmbox) {
  4253. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4254. return MBX_SUCCESS;
  4255. }
  4256. }
  4257. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4258. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4259. if(!pmbox->vport) {
  4260. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4261. lpfc_printf_log(phba, KERN_ERR,
  4262. LOG_MBOX | LOG_VPORT,
  4263. "1806 Mbox x%x failed. No vport\n",
  4264. pmbox->u.mb.mbxCommand);
  4265. dump_stack();
  4266. goto out_not_finished;
  4267. }
  4268. }
  4269. /* If the PCI channel is in offline state, do not post mbox. */
  4270. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4271. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4272. goto out_not_finished;
  4273. }
  4274. /* If HBA has a deferred error attention, fail the iocb. */
  4275. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4276. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4277. goto out_not_finished;
  4278. }
  4279. psli = &phba->sli;
  4280. mb = &pmbox->u.mb;
  4281. status = MBX_SUCCESS;
  4282. if (phba->link_state == LPFC_HBA_ERROR) {
  4283. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4284. /* Mbox command <mbxCommand> cannot issue */
  4285. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4286. "(%d):0311 Mailbox command x%x cannot "
  4287. "issue Data: x%x x%x\n",
  4288. pmbox->vport ? pmbox->vport->vpi : 0,
  4289. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4290. goto out_not_finished;
  4291. }
  4292. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4293. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4294. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4295. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4296. "(%d):2528 Mailbox command x%x cannot "
  4297. "issue Data: x%x x%x\n",
  4298. pmbox->vport ? pmbox->vport->vpi : 0,
  4299. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4300. goto out_not_finished;
  4301. }
  4302. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4303. /* Polling for a mbox command when another one is already active
  4304. * is not allowed in SLI. Also, the driver must have established
  4305. * SLI2 mode to queue and process multiple mbox commands.
  4306. */
  4307. if (flag & MBX_POLL) {
  4308. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4309. /* Mbox command <mbxCommand> cannot issue */
  4310. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4311. "(%d):2529 Mailbox command x%x "
  4312. "cannot issue Data: x%x x%x\n",
  4313. pmbox->vport ? pmbox->vport->vpi : 0,
  4314. pmbox->u.mb.mbxCommand,
  4315. psli->sli_flag, flag);
  4316. goto out_not_finished;
  4317. }
  4318. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4319. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4320. /* Mbox command <mbxCommand> cannot issue */
  4321. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4322. "(%d):2530 Mailbox command x%x "
  4323. "cannot issue Data: x%x x%x\n",
  4324. pmbox->vport ? pmbox->vport->vpi : 0,
  4325. pmbox->u.mb.mbxCommand,
  4326. psli->sli_flag, flag);
  4327. goto out_not_finished;
  4328. }
  4329. /* Another mailbox command is still being processed, queue this
  4330. * command to be processed later.
  4331. */
  4332. lpfc_mbox_put(phba, pmbox);
  4333. /* Mbox cmd issue - BUSY */
  4334. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4335. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4336. "x%x x%x x%x x%x\n",
  4337. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4338. mb->mbxCommand, phba->pport->port_state,
  4339. psli->sli_flag, flag);
  4340. psli->slistat.mbox_busy++;
  4341. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4342. if (pmbox->vport) {
  4343. lpfc_debugfs_disc_trc(pmbox->vport,
  4344. LPFC_DISC_TRC_MBOX_VPORT,
  4345. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4346. (uint32_t)mb->mbxCommand,
  4347. mb->un.varWords[0], mb->un.varWords[1]);
  4348. }
  4349. else {
  4350. lpfc_debugfs_disc_trc(phba->pport,
  4351. LPFC_DISC_TRC_MBOX,
  4352. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4353. (uint32_t)mb->mbxCommand,
  4354. mb->un.varWords[0], mb->un.varWords[1]);
  4355. }
  4356. return MBX_BUSY;
  4357. }
  4358. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4359. /* If we are not polling, we MUST be in SLI2 mode */
  4360. if (flag != MBX_POLL) {
  4361. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4362. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4363. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4364. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4365. /* Mbox command <mbxCommand> cannot issue */
  4366. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4367. "(%d):2531 Mailbox command x%x "
  4368. "cannot issue Data: x%x x%x\n",
  4369. pmbox->vport ? pmbox->vport->vpi : 0,
  4370. pmbox->u.mb.mbxCommand,
  4371. psli->sli_flag, flag);
  4372. goto out_not_finished;
  4373. }
  4374. /* timeout active mbox command */
  4375. mod_timer(&psli->mbox_tmo, (jiffies +
  4376. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4377. }
  4378. /* Mailbox cmd <cmd> issue */
  4379. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4380. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4381. "x%x\n",
  4382. pmbox->vport ? pmbox->vport->vpi : 0,
  4383. mb->mbxCommand, phba->pport->port_state,
  4384. psli->sli_flag, flag);
  4385. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4386. if (pmbox->vport) {
  4387. lpfc_debugfs_disc_trc(pmbox->vport,
  4388. LPFC_DISC_TRC_MBOX_VPORT,
  4389. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4390. (uint32_t)mb->mbxCommand,
  4391. mb->un.varWords[0], mb->un.varWords[1]);
  4392. }
  4393. else {
  4394. lpfc_debugfs_disc_trc(phba->pport,
  4395. LPFC_DISC_TRC_MBOX,
  4396. "MBOX Send: cmd:x%x mb:x%x x%x",
  4397. (uint32_t)mb->mbxCommand,
  4398. mb->un.varWords[0], mb->un.varWords[1]);
  4399. }
  4400. }
  4401. psli->slistat.mbox_cmd++;
  4402. evtctr = psli->slistat.mbox_event;
  4403. /* next set own bit for the adapter and copy over command word */
  4404. mb->mbxOwner = OWN_CHIP;
  4405. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4406. /* Populate mbox extension offset word. */
  4407. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4408. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4409. = (uint8_t *)phba->mbox_ext
  4410. - (uint8_t *)phba->mbox;
  4411. }
  4412. /* Copy the mailbox extension data */
  4413. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4414. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4415. (uint8_t *)phba->mbox_ext,
  4416. pmbox->in_ext_byte_len);
  4417. }
  4418. /* Copy command data to host SLIM area */
  4419. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4420. } else {
  4421. /* Populate mbox extension offset word. */
  4422. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4423. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4424. = MAILBOX_HBA_EXT_OFFSET;
  4425. /* Copy the mailbox extension data */
  4426. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4427. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4428. MAILBOX_HBA_EXT_OFFSET,
  4429. pmbox->context2, pmbox->in_ext_byte_len);
  4430. }
  4431. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4432. /* copy command data into host mbox for cmpl */
  4433. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4434. }
  4435. /* First copy mbox command data to HBA SLIM, skip past first
  4436. word */
  4437. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4438. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4439. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4440. /* Next copy over first word, with mbxOwner set */
  4441. ldata = *((uint32_t *)mb);
  4442. to_slim = phba->MBslimaddr;
  4443. writel(ldata, to_slim);
  4444. readl(to_slim); /* flush */
  4445. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4446. /* switch over to host mailbox */
  4447. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4448. }
  4449. }
  4450. wmb();
  4451. switch (flag) {
  4452. case MBX_NOWAIT:
  4453. /* Set up reference to mailbox command */
  4454. psli->mbox_active = pmbox;
  4455. /* Interrupt board to do it */
  4456. writel(CA_MBATT, phba->CAregaddr);
  4457. readl(phba->CAregaddr); /* flush */
  4458. /* Don't wait for it to finish, just return */
  4459. break;
  4460. case MBX_POLL:
  4461. /* Set up null reference to mailbox command */
  4462. psli->mbox_active = NULL;
  4463. /* Interrupt board to do it */
  4464. writel(CA_MBATT, phba->CAregaddr);
  4465. readl(phba->CAregaddr); /* flush */
  4466. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4467. /* First read mbox status word */
  4468. word0 = *((uint32_t *)phba->mbox);
  4469. word0 = le32_to_cpu(word0);
  4470. } else {
  4471. /* First read mbox status word */
  4472. word0 = readl(phba->MBslimaddr);
  4473. }
  4474. /* Read the HBA Host Attention Register */
  4475. ha_copy = readl(phba->HAregaddr);
  4476. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4477. mb->mbxCommand) *
  4478. 1000) + jiffies;
  4479. i = 0;
  4480. /* Wait for command to complete */
  4481. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4482. (!(ha_copy & HA_MBATT) &&
  4483. (phba->link_state > LPFC_WARM_START))) {
  4484. if (time_after(jiffies, timeout)) {
  4485. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4486. spin_unlock_irqrestore(&phba->hbalock,
  4487. drvr_flag);
  4488. goto out_not_finished;
  4489. }
  4490. /* Check if we took a mbox interrupt while we were
  4491. polling */
  4492. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4493. && (evtctr != psli->slistat.mbox_event))
  4494. break;
  4495. if (i++ > 10) {
  4496. spin_unlock_irqrestore(&phba->hbalock,
  4497. drvr_flag);
  4498. msleep(1);
  4499. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4500. }
  4501. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4502. /* First copy command data */
  4503. word0 = *((uint32_t *)phba->mbox);
  4504. word0 = le32_to_cpu(word0);
  4505. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4506. MAILBOX_t *slimmb;
  4507. uint32_t slimword0;
  4508. /* Check real SLIM for any errors */
  4509. slimword0 = readl(phba->MBslimaddr);
  4510. slimmb = (MAILBOX_t *) & slimword0;
  4511. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4512. && slimmb->mbxStatus) {
  4513. psli->sli_flag &=
  4514. ~LPFC_SLI_ACTIVE;
  4515. word0 = slimword0;
  4516. }
  4517. }
  4518. } else {
  4519. /* First copy command data */
  4520. word0 = readl(phba->MBslimaddr);
  4521. }
  4522. /* Read the HBA Host Attention Register */
  4523. ha_copy = readl(phba->HAregaddr);
  4524. }
  4525. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4526. /* copy results back to user */
  4527. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4528. /* Copy the mailbox extension data */
  4529. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4530. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4531. pmbox->context2,
  4532. pmbox->out_ext_byte_len);
  4533. }
  4534. } else {
  4535. /* First copy command data */
  4536. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4537. MAILBOX_CMD_SIZE);
  4538. /* Copy the mailbox extension data */
  4539. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4540. lpfc_memcpy_from_slim(pmbox->context2,
  4541. phba->MBslimaddr +
  4542. MAILBOX_HBA_EXT_OFFSET,
  4543. pmbox->out_ext_byte_len);
  4544. }
  4545. }
  4546. writel(HA_MBATT, phba->HAregaddr);
  4547. readl(phba->HAregaddr); /* flush */
  4548. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4549. status = mb->mbxStatus;
  4550. }
  4551. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4552. return status;
  4553. out_not_finished:
  4554. if (processing_queue) {
  4555. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4556. lpfc_mbox_cmpl_put(phba, pmbox);
  4557. }
  4558. return MBX_NOT_FINISHED;
  4559. }
  4560. /**
  4561. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4562. * @phba: Pointer to HBA context object.
  4563. *
  4564. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4565. * the driver internal pending mailbox queue. It will then try to wait out the
  4566. * possible outstanding mailbox command before return.
  4567. *
  4568. * Returns:
  4569. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4570. * the outstanding mailbox command timed out.
  4571. **/
  4572. static int
  4573. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4574. {
  4575. struct lpfc_sli *psli = &phba->sli;
  4576. uint8_t actcmd = MBX_HEARTBEAT;
  4577. int rc = 0;
  4578. unsigned long timeout;
  4579. /* Mark the asynchronous mailbox command posting as blocked */
  4580. spin_lock_irq(&phba->hbalock);
  4581. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4582. if (phba->sli.mbox_active)
  4583. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4584. spin_unlock_irq(&phba->hbalock);
  4585. /* Determine how long we might wait for the active mailbox
  4586. * command to be gracefully completed by firmware.
  4587. */
  4588. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4589. jiffies;
  4590. /* Wait for the outstnading mailbox command to complete */
  4591. while (phba->sli.mbox_active) {
  4592. /* Check active mailbox complete status every 2ms */
  4593. msleep(2);
  4594. if (time_after(jiffies, timeout)) {
  4595. /* Timeout, marked the outstanding cmd not complete */
  4596. rc = 1;
  4597. break;
  4598. }
  4599. }
  4600. /* Can not cleanly block async mailbox command, fails it */
  4601. if (rc) {
  4602. spin_lock_irq(&phba->hbalock);
  4603. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4604. spin_unlock_irq(&phba->hbalock);
  4605. }
  4606. return rc;
  4607. }
  4608. /**
  4609. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4610. * @phba: Pointer to HBA context object.
  4611. *
  4612. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4613. * commands from the driver internal pending mailbox queue. It makes sure
  4614. * that there is no outstanding mailbox command before resuming posting
  4615. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4616. * mailbox command, it will try to wait it out before resuming asynchronous
  4617. * mailbox command posting.
  4618. **/
  4619. static void
  4620. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4621. {
  4622. struct lpfc_sli *psli = &phba->sli;
  4623. spin_lock_irq(&phba->hbalock);
  4624. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4625. /* Asynchronous mailbox posting is not blocked, do nothing */
  4626. spin_unlock_irq(&phba->hbalock);
  4627. return;
  4628. }
  4629. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4630. * successful or timeout, after timing-out the outstanding mailbox
  4631. * command shall always be removed, so just unblock posting async
  4632. * mailbox command and resume
  4633. */
  4634. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4635. spin_unlock_irq(&phba->hbalock);
  4636. /* wake up worker thread to post asynchronlous mailbox command */
  4637. lpfc_worker_wake_up(phba);
  4638. }
  4639. /**
  4640. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4641. * @phba: Pointer to HBA context object.
  4642. * @mboxq: Pointer to mailbox object.
  4643. *
  4644. * The function posts a mailbox to the port. The mailbox is expected
  4645. * to be comletely filled in and ready for the port to operate on it.
  4646. * This routine executes a synchronous completion operation on the
  4647. * mailbox by polling for its completion.
  4648. *
  4649. * The caller must not be holding any locks when calling this routine.
  4650. *
  4651. * Returns:
  4652. * MBX_SUCCESS - mailbox posted successfully
  4653. * Any of the MBX error values.
  4654. **/
  4655. static int
  4656. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4657. {
  4658. int rc = MBX_SUCCESS;
  4659. unsigned long iflag;
  4660. uint32_t db_ready;
  4661. uint32_t mcqe_status;
  4662. uint32_t mbx_cmnd;
  4663. unsigned long timeout;
  4664. struct lpfc_sli *psli = &phba->sli;
  4665. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4666. struct lpfc_bmbx_create *mbox_rgn;
  4667. struct dma_address *dma_address;
  4668. struct lpfc_register bmbx_reg;
  4669. /*
  4670. * Only one mailbox can be active to the bootstrap mailbox region
  4671. * at a time and there is no queueing provided.
  4672. */
  4673. spin_lock_irqsave(&phba->hbalock, iflag);
  4674. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4675. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4676. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4677. "(%d):2532 Mailbox command x%x (x%x) "
  4678. "cannot issue Data: x%x x%x\n",
  4679. mboxq->vport ? mboxq->vport->vpi : 0,
  4680. mboxq->u.mb.mbxCommand,
  4681. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4682. psli->sli_flag, MBX_POLL);
  4683. return MBXERR_ERROR;
  4684. }
  4685. /* The server grabs the token and owns it until release */
  4686. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4687. phba->sli.mbox_active = mboxq;
  4688. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4689. /*
  4690. * Initialize the bootstrap memory region to avoid stale data areas
  4691. * in the mailbox post. Then copy the caller's mailbox contents to
  4692. * the bmbx mailbox region.
  4693. */
  4694. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4695. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4696. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4697. sizeof(struct lpfc_mqe));
  4698. /* Post the high mailbox dma address to the port and wait for ready. */
  4699. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4700. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4701. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4702. * 1000) + jiffies;
  4703. do {
  4704. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4705. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4706. if (!db_ready)
  4707. msleep(2);
  4708. if (time_after(jiffies, timeout)) {
  4709. rc = MBXERR_ERROR;
  4710. goto exit;
  4711. }
  4712. } while (!db_ready);
  4713. /* Post the low mailbox dma address to the port. */
  4714. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4715. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4716. * 1000) + jiffies;
  4717. do {
  4718. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4719. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4720. if (!db_ready)
  4721. msleep(2);
  4722. if (time_after(jiffies, timeout)) {
  4723. rc = MBXERR_ERROR;
  4724. goto exit;
  4725. }
  4726. } while (!db_ready);
  4727. /*
  4728. * Read the CQ to ensure the mailbox has completed.
  4729. * If so, update the mailbox status so that the upper layers
  4730. * can complete the request normally.
  4731. */
  4732. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4733. sizeof(struct lpfc_mqe));
  4734. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4735. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4736. sizeof(struct lpfc_mcqe));
  4737. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4738. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4739. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4740. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4741. rc = MBXERR_ERROR;
  4742. }
  4743. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4744. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4745. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4746. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4747. mboxq->vport ? mboxq->vport->vpi : 0,
  4748. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4749. bf_get(lpfc_mqe_status, mb),
  4750. mb->un.mb_words[0], mb->un.mb_words[1],
  4751. mb->un.mb_words[2], mb->un.mb_words[3],
  4752. mb->un.mb_words[4], mb->un.mb_words[5],
  4753. mb->un.mb_words[6], mb->un.mb_words[7],
  4754. mb->un.mb_words[8], mb->un.mb_words[9],
  4755. mb->un.mb_words[10], mb->un.mb_words[11],
  4756. mb->un.mb_words[12], mboxq->mcqe.word0,
  4757. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4758. mboxq->mcqe.trailer);
  4759. exit:
  4760. /* We are holding the token, no needed for lock when release */
  4761. spin_lock_irqsave(&phba->hbalock, iflag);
  4762. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4763. phba->sli.mbox_active = NULL;
  4764. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4765. return rc;
  4766. }
  4767. /**
  4768. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4769. * @phba: Pointer to HBA context object.
  4770. * @pmbox: Pointer to mailbox object.
  4771. * @flag: Flag indicating how the mailbox need to be processed.
  4772. *
  4773. * This function is called by discovery code and HBA management code to submit
  4774. * a mailbox command to firmware with SLI-4 interface spec.
  4775. *
  4776. * Return codes the caller owns the mailbox command after the return of the
  4777. * function.
  4778. **/
  4779. static int
  4780. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4781. uint32_t flag)
  4782. {
  4783. struct lpfc_sli *psli = &phba->sli;
  4784. unsigned long iflags;
  4785. int rc;
  4786. rc = lpfc_mbox_dev_check(phba);
  4787. if (unlikely(rc)) {
  4788. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4789. "(%d):2544 Mailbox command x%x (x%x) "
  4790. "cannot issue Data: x%x x%x\n",
  4791. mboxq->vport ? mboxq->vport->vpi : 0,
  4792. mboxq->u.mb.mbxCommand,
  4793. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4794. psli->sli_flag, flag);
  4795. goto out_not_finished;
  4796. }
  4797. /* Detect polling mode and jump to a handler */
  4798. if (!phba->sli4_hba.intr_enable) {
  4799. if (flag == MBX_POLL)
  4800. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4801. else
  4802. rc = -EIO;
  4803. if (rc != MBX_SUCCESS)
  4804. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4805. "(%d):2541 Mailbox command x%x "
  4806. "(x%x) cannot issue Data: x%x x%x\n",
  4807. mboxq->vport ? mboxq->vport->vpi : 0,
  4808. mboxq->u.mb.mbxCommand,
  4809. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4810. psli->sli_flag, flag);
  4811. return rc;
  4812. } else if (flag == MBX_POLL) {
  4813. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4814. "(%d):2542 Try to issue mailbox command "
  4815. "x%x (x%x) synchronously ahead of async"
  4816. "mailbox command queue: x%x x%x\n",
  4817. mboxq->vport ? mboxq->vport->vpi : 0,
  4818. mboxq->u.mb.mbxCommand,
  4819. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4820. psli->sli_flag, flag);
  4821. /* Try to block the asynchronous mailbox posting */
  4822. rc = lpfc_sli4_async_mbox_block(phba);
  4823. if (!rc) {
  4824. /* Successfully blocked, now issue sync mbox cmd */
  4825. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4826. if (rc != MBX_SUCCESS)
  4827. lpfc_printf_log(phba, KERN_ERR,
  4828. LOG_MBOX | LOG_SLI,
  4829. "(%d):2597 Mailbox command "
  4830. "x%x (x%x) cannot issue "
  4831. "Data: x%x x%x\n",
  4832. mboxq->vport ?
  4833. mboxq->vport->vpi : 0,
  4834. mboxq->u.mb.mbxCommand,
  4835. lpfc_sli4_mbox_opcode_get(phba,
  4836. mboxq),
  4837. psli->sli_flag, flag);
  4838. /* Unblock the async mailbox posting afterward */
  4839. lpfc_sli4_async_mbox_unblock(phba);
  4840. }
  4841. return rc;
  4842. }
  4843. /* Now, interrupt mode asynchrous mailbox command */
  4844. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4845. if (rc) {
  4846. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4847. "(%d):2543 Mailbox command x%x (x%x) "
  4848. "cannot issue Data: x%x x%x\n",
  4849. mboxq->vport ? mboxq->vport->vpi : 0,
  4850. mboxq->u.mb.mbxCommand,
  4851. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4852. psli->sli_flag, flag);
  4853. goto out_not_finished;
  4854. }
  4855. /* Put the mailbox command to the driver internal FIFO */
  4856. psli->slistat.mbox_busy++;
  4857. spin_lock_irqsave(&phba->hbalock, iflags);
  4858. lpfc_mbox_put(phba, mboxq);
  4859. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4860. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4861. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4862. "x%x (x%x) x%x x%x x%x\n",
  4863. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4864. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4865. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4866. phba->pport->port_state,
  4867. psli->sli_flag, MBX_NOWAIT);
  4868. /* Wake up worker thread to transport mailbox command from head */
  4869. lpfc_worker_wake_up(phba);
  4870. return MBX_BUSY;
  4871. out_not_finished:
  4872. return MBX_NOT_FINISHED;
  4873. }
  4874. /**
  4875. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4876. * @phba: Pointer to HBA context object.
  4877. *
  4878. * This function is called by worker thread to send a mailbox command to
  4879. * SLI4 HBA firmware.
  4880. *
  4881. **/
  4882. int
  4883. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4884. {
  4885. struct lpfc_sli *psli = &phba->sli;
  4886. LPFC_MBOXQ_t *mboxq;
  4887. int rc = MBX_SUCCESS;
  4888. unsigned long iflags;
  4889. struct lpfc_mqe *mqe;
  4890. uint32_t mbx_cmnd;
  4891. /* Check interrupt mode before post async mailbox command */
  4892. if (unlikely(!phba->sli4_hba.intr_enable))
  4893. return MBX_NOT_FINISHED;
  4894. /* Check for mailbox command service token */
  4895. spin_lock_irqsave(&phba->hbalock, iflags);
  4896. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4897. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4898. return MBX_NOT_FINISHED;
  4899. }
  4900. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4901. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4902. return MBX_NOT_FINISHED;
  4903. }
  4904. if (unlikely(phba->sli.mbox_active)) {
  4905. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4906. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4907. "0384 There is pending active mailbox cmd\n");
  4908. return MBX_NOT_FINISHED;
  4909. }
  4910. /* Take the mailbox command service token */
  4911. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4912. /* Get the next mailbox command from head of queue */
  4913. mboxq = lpfc_mbox_get(phba);
  4914. /* If no more mailbox command waiting for post, we're done */
  4915. if (!mboxq) {
  4916. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4917. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4918. return MBX_SUCCESS;
  4919. }
  4920. phba->sli.mbox_active = mboxq;
  4921. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4922. /* Check device readiness for posting mailbox command */
  4923. rc = lpfc_mbox_dev_check(phba);
  4924. if (unlikely(rc))
  4925. /* Driver clean routine will clean up pending mailbox */
  4926. goto out_not_finished;
  4927. /* Prepare the mbox command to be posted */
  4928. mqe = &mboxq->u.mqe;
  4929. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4930. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4931. mod_timer(&psli->mbox_tmo, (jiffies +
  4932. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4933. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4934. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4935. "x%x x%x\n",
  4936. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4937. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4938. phba->pport->port_state, psli->sli_flag);
  4939. if (mbx_cmnd != MBX_HEARTBEAT) {
  4940. if (mboxq->vport) {
  4941. lpfc_debugfs_disc_trc(mboxq->vport,
  4942. LPFC_DISC_TRC_MBOX_VPORT,
  4943. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4944. mbx_cmnd, mqe->un.mb_words[0],
  4945. mqe->un.mb_words[1]);
  4946. } else {
  4947. lpfc_debugfs_disc_trc(phba->pport,
  4948. LPFC_DISC_TRC_MBOX,
  4949. "MBOX Send: cmd:x%x mb:x%x x%x",
  4950. mbx_cmnd, mqe->un.mb_words[0],
  4951. mqe->un.mb_words[1]);
  4952. }
  4953. }
  4954. psli->slistat.mbox_cmd++;
  4955. /* Post the mailbox command to the port */
  4956. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4957. if (rc != MBX_SUCCESS) {
  4958. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4959. "(%d):2533 Mailbox command x%x (x%x) "
  4960. "cannot issue Data: x%x x%x\n",
  4961. mboxq->vport ? mboxq->vport->vpi : 0,
  4962. mboxq->u.mb.mbxCommand,
  4963. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4964. psli->sli_flag, MBX_NOWAIT);
  4965. goto out_not_finished;
  4966. }
  4967. return rc;
  4968. out_not_finished:
  4969. spin_lock_irqsave(&phba->hbalock, iflags);
  4970. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4971. __lpfc_mbox_cmpl_put(phba, mboxq);
  4972. /* Release the token */
  4973. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4974. phba->sli.mbox_active = NULL;
  4975. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4976. return MBX_NOT_FINISHED;
  4977. }
  4978. /**
  4979. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4980. * @phba: Pointer to HBA context object.
  4981. * @pmbox: Pointer to mailbox object.
  4982. * @flag: Flag indicating how the mailbox need to be processed.
  4983. *
  4984. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4985. * the API jump table function pointer from the lpfc_hba struct.
  4986. *
  4987. * Return codes the caller owns the mailbox command after the return of the
  4988. * function.
  4989. **/
  4990. int
  4991. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4992. {
  4993. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4994. }
  4995. /**
  4996. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4997. * @phba: The hba struct for which this call is being executed.
  4998. * @dev_grp: The HBA PCI-Device group number.
  4999. *
  5000. * This routine sets up the mbox interface API function jump table in @phba
  5001. * struct.
  5002. * Returns: 0 - success, -ENODEV - failure.
  5003. **/
  5004. int
  5005. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5006. {
  5007. switch (dev_grp) {
  5008. case LPFC_PCI_DEV_LP:
  5009. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5010. phba->lpfc_sli_handle_slow_ring_event =
  5011. lpfc_sli_handle_slow_ring_event_s3;
  5012. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5013. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5014. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5015. break;
  5016. case LPFC_PCI_DEV_OC:
  5017. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5018. phba->lpfc_sli_handle_slow_ring_event =
  5019. lpfc_sli_handle_slow_ring_event_s4;
  5020. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5021. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5022. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5023. break;
  5024. default:
  5025. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5026. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5027. dev_grp);
  5028. return -ENODEV;
  5029. break;
  5030. }
  5031. return 0;
  5032. }
  5033. /**
  5034. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5035. * @phba: Pointer to HBA context object.
  5036. * @pring: Pointer to driver SLI ring object.
  5037. * @piocb: Pointer to address of newly added command iocb.
  5038. *
  5039. * This function is called with hbalock held to add a command
  5040. * iocb to the txq when SLI layer cannot submit the command iocb
  5041. * to the ring.
  5042. **/
  5043. static void
  5044. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5045. struct lpfc_iocbq *piocb)
  5046. {
  5047. /* Insert the caller's iocb in the txq tail for later processing. */
  5048. list_add_tail(&piocb->list, &pring->txq);
  5049. pring->txq_cnt++;
  5050. }
  5051. /**
  5052. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5053. * @phba: Pointer to HBA context object.
  5054. * @pring: Pointer to driver SLI ring object.
  5055. * @piocb: Pointer to address of newly added command iocb.
  5056. *
  5057. * This function is called with hbalock held before a new
  5058. * iocb is submitted to the firmware. This function checks
  5059. * txq to flush the iocbs in txq to Firmware before
  5060. * submitting new iocbs to the Firmware.
  5061. * If there are iocbs in the txq which need to be submitted
  5062. * to firmware, lpfc_sli_next_iocb returns the first element
  5063. * of the txq after dequeuing it from txq.
  5064. * If there is no iocb in the txq then the function will return
  5065. * *piocb and *piocb is set to NULL. Caller needs to check
  5066. * *piocb to find if there are more commands in the txq.
  5067. **/
  5068. static struct lpfc_iocbq *
  5069. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5070. struct lpfc_iocbq **piocb)
  5071. {
  5072. struct lpfc_iocbq * nextiocb;
  5073. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5074. if (!nextiocb) {
  5075. nextiocb = *piocb;
  5076. *piocb = NULL;
  5077. }
  5078. return nextiocb;
  5079. }
  5080. /**
  5081. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5082. * @phba: Pointer to HBA context object.
  5083. * @ring_number: SLI ring number to issue iocb on.
  5084. * @piocb: Pointer to command iocb.
  5085. * @flag: Flag indicating if this command can be put into txq.
  5086. *
  5087. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5088. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5089. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5090. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5091. * this function allows only iocbs for posting buffers. This function finds
  5092. * next available slot in the command ring and posts the command to the
  5093. * available slot and writes the port attention register to request HBA start
  5094. * processing new iocb. If there is no slot available in the ring and
  5095. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5096. * the function returns IOCB_BUSY.
  5097. *
  5098. * This function is called with hbalock held. The function will return success
  5099. * after it successfully submit the iocb to firmware or after adding to the
  5100. * txq.
  5101. **/
  5102. static int
  5103. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5104. struct lpfc_iocbq *piocb, uint32_t flag)
  5105. {
  5106. struct lpfc_iocbq *nextiocb;
  5107. IOCB_t *iocb;
  5108. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5109. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5110. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5111. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5112. lpfc_printf_log(phba, KERN_ERR,
  5113. LOG_SLI | LOG_VPORT,
  5114. "1807 IOCB x%x failed. No vport\n",
  5115. piocb->iocb.ulpCommand);
  5116. dump_stack();
  5117. return IOCB_ERROR;
  5118. }
  5119. /* If the PCI channel is in offline state, do not post iocbs. */
  5120. if (unlikely(pci_channel_offline(phba->pcidev)))
  5121. return IOCB_ERROR;
  5122. /* If HBA has a deferred error attention, fail the iocb. */
  5123. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5124. return IOCB_ERROR;
  5125. /*
  5126. * We should never get an IOCB if we are in a < LINK_DOWN state
  5127. */
  5128. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5129. return IOCB_ERROR;
  5130. /*
  5131. * Check to see if we are blocking IOCB processing because of a
  5132. * outstanding event.
  5133. */
  5134. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5135. goto iocb_busy;
  5136. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5137. /*
  5138. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5139. * can be issued if the link is not up.
  5140. */
  5141. switch (piocb->iocb.ulpCommand) {
  5142. case CMD_GEN_REQUEST64_CR:
  5143. case CMD_GEN_REQUEST64_CX:
  5144. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5145. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5146. FC_RCTL_DD_UNSOL_CMD) ||
  5147. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5148. MENLO_TRANSPORT_TYPE))
  5149. goto iocb_busy;
  5150. break;
  5151. case CMD_QUE_RING_BUF_CN:
  5152. case CMD_QUE_RING_BUF64_CN:
  5153. /*
  5154. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5155. * completion, iocb_cmpl MUST be 0.
  5156. */
  5157. if (piocb->iocb_cmpl)
  5158. piocb->iocb_cmpl = NULL;
  5159. /*FALLTHROUGH*/
  5160. case CMD_CREATE_XRI_CR:
  5161. case CMD_CLOSE_XRI_CN:
  5162. case CMD_CLOSE_XRI_CX:
  5163. break;
  5164. default:
  5165. goto iocb_busy;
  5166. }
  5167. /*
  5168. * For FCP commands, we must be in a state where we can process link
  5169. * attention events.
  5170. */
  5171. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5172. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5173. goto iocb_busy;
  5174. }
  5175. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5176. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5177. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5178. if (iocb)
  5179. lpfc_sli_update_ring(phba, pring);
  5180. else
  5181. lpfc_sli_update_full_ring(phba, pring);
  5182. if (!piocb)
  5183. return IOCB_SUCCESS;
  5184. goto out_busy;
  5185. iocb_busy:
  5186. pring->stats.iocb_cmd_delay++;
  5187. out_busy:
  5188. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5189. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5190. return IOCB_SUCCESS;
  5191. }
  5192. return IOCB_BUSY;
  5193. }
  5194. /**
  5195. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5196. * @phba: Pointer to HBA context object.
  5197. * @piocb: Pointer to command iocb.
  5198. * @sglq: Pointer to the scatter gather queue object.
  5199. *
  5200. * This routine converts the bpl or bde that is in the IOCB
  5201. * to a sgl list for the sli4 hardware. The physical address
  5202. * of the bpl/bde is converted back to a virtual address.
  5203. * If the IOCB contains a BPL then the list of BDE's is
  5204. * converted to sli4_sge's. If the IOCB contains a single
  5205. * BDE then it is converted to a single sli_sge.
  5206. * The IOCB is still in cpu endianess so the contents of
  5207. * the bpl can be used without byte swapping.
  5208. *
  5209. * Returns valid XRI = Success, NO_XRI = Failure.
  5210. **/
  5211. static uint16_t
  5212. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5213. struct lpfc_sglq *sglq)
  5214. {
  5215. uint16_t xritag = NO_XRI;
  5216. struct ulp_bde64 *bpl = NULL;
  5217. struct ulp_bde64 bde;
  5218. struct sli4_sge *sgl = NULL;
  5219. IOCB_t *icmd;
  5220. int numBdes = 0;
  5221. int i = 0;
  5222. if (!piocbq || !sglq)
  5223. return xritag;
  5224. sgl = (struct sli4_sge *)sglq->sgl;
  5225. icmd = &piocbq->iocb;
  5226. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5227. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5228. sizeof(struct ulp_bde64);
  5229. /* The addrHigh and addrLow fields within the IOCB
  5230. * have not been byteswapped yet so there is no
  5231. * need to swap them back.
  5232. */
  5233. bpl = (struct ulp_bde64 *)
  5234. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5235. if (!bpl)
  5236. return xritag;
  5237. for (i = 0; i < numBdes; i++) {
  5238. /* Should already be byte swapped. */
  5239. sgl->addr_hi = bpl->addrHigh;
  5240. sgl->addr_lo = bpl->addrLow;
  5241. if ((i+1) == numBdes)
  5242. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5243. else
  5244. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5245. sgl->word2 = cpu_to_le32(sgl->word2);
  5246. /* swap the size field back to the cpu so we
  5247. * can assign it to the sgl.
  5248. */
  5249. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5250. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5251. bpl++;
  5252. sgl++;
  5253. }
  5254. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5255. /* The addrHigh and addrLow fields of the BDE have not
  5256. * been byteswapped yet so they need to be swapped
  5257. * before putting them in the sgl.
  5258. */
  5259. sgl->addr_hi =
  5260. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5261. sgl->addr_lo =
  5262. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5263. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5264. sgl->word2 = cpu_to_le32(sgl->word2);
  5265. sgl->sge_len =
  5266. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5267. }
  5268. return sglq->sli4_xritag;
  5269. }
  5270. /**
  5271. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5272. * @phba: Pointer to HBA context object.
  5273. *
  5274. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5275. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5276. * held.
  5277. *
  5278. * Return: index into SLI4 fast-path FCP queue index.
  5279. **/
  5280. static uint32_t
  5281. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5282. {
  5283. ++phba->fcp_qidx;
  5284. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5285. phba->fcp_qidx = 0;
  5286. return phba->fcp_qidx;
  5287. }
  5288. /**
  5289. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5290. * @phba: Pointer to HBA context object.
  5291. * @piocb: Pointer to command iocb.
  5292. * @wqe: Pointer to the work queue entry.
  5293. *
  5294. * This routine converts the iocb command to its Work Queue Entry
  5295. * equivalent. The wqe pointer should not have any fields set when
  5296. * this routine is called because it will memcpy over them.
  5297. * This routine does not set the CQ_ID or the WQEC bits in the
  5298. * wqe.
  5299. *
  5300. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5301. **/
  5302. static int
  5303. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5304. union lpfc_wqe *wqe)
  5305. {
  5306. uint32_t xmit_len = 0, total_len = 0;
  5307. uint8_t ct = 0;
  5308. uint32_t fip;
  5309. uint32_t abort_tag;
  5310. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5311. uint8_t cmnd;
  5312. uint16_t xritag;
  5313. struct ulp_bde64 *bpl = NULL;
  5314. uint32_t els_id = ELS_ID_DEFAULT;
  5315. int numBdes, i;
  5316. struct ulp_bde64 bde;
  5317. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5318. /* The fcp commands will set command type */
  5319. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5320. command_type = FCP_COMMAND;
  5321. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5322. command_type = ELS_COMMAND_FIP;
  5323. else
  5324. command_type = ELS_COMMAND_NON_FIP;
  5325. /* Some of the fields are in the right position already */
  5326. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5327. abort_tag = (uint32_t) iocbq->iotag;
  5328. xritag = iocbq->sli4_xritag;
  5329. wqe->words[7] = 0; /* The ct field has moved so reset */
  5330. /* words0-2 bpl convert bde */
  5331. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5332. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5333. sizeof(struct ulp_bde64);
  5334. bpl = (struct ulp_bde64 *)
  5335. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5336. if (!bpl)
  5337. return IOCB_ERROR;
  5338. /* Should already be byte swapped. */
  5339. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5340. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5341. /* swap the size field back to the cpu so we
  5342. * can assign it to the sgl.
  5343. */
  5344. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5345. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5346. total_len = 0;
  5347. for (i = 0; i < numBdes; i++) {
  5348. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5349. total_len += bde.tus.f.bdeSize;
  5350. }
  5351. } else
  5352. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5353. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5354. cmnd = iocbq->iocb.ulpCommand;
  5355. switch (iocbq->iocb.ulpCommand) {
  5356. case CMD_ELS_REQUEST64_CR:
  5357. if (!iocbq->iocb.ulpLe) {
  5358. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5359. "2007 Only Limited Edition cmd Format"
  5360. " supported 0x%x\n",
  5361. iocbq->iocb.ulpCommand);
  5362. return IOCB_ERROR;
  5363. }
  5364. wqe->els_req.payload_len = xmit_len;
  5365. /* Els_reguest64 has a TMO */
  5366. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5367. iocbq->iocb.ulpTimeout);
  5368. /* Need a VF for word 4 set the vf bit*/
  5369. bf_set(els_req64_vf, &wqe->els_req, 0);
  5370. /* And a VFID for word 12 */
  5371. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5372. /*
  5373. * Set ct field to 3, indicates that the context_tag field
  5374. * contains the FCFI and remote N_Port_ID is
  5375. * in word 5.
  5376. */
  5377. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5378. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5379. iocbq->iocb.ulpContext);
  5380. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5381. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5382. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5383. if (command_type == ELS_COMMAND_FIP) {
  5384. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5385. >> LPFC_FIP_ELS_ID_SHIFT);
  5386. }
  5387. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5388. break;
  5389. case CMD_XMIT_SEQUENCE64_CX:
  5390. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5391. iocbq->iocb.un.ulpWord[3]);
  5392. wqe->generic.word3 = 0;
  5393. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5394. /* The entire sequence is transmitted for this IOCB */
  5395. xmit_len = total_len;
  5396. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5397. case CMD_XMIT_SEQUENCE64_CR:
  5398. /* word3 iocb=io_tag32 wqe=payload_offset */
  5399. /* payload offset used for multilpe outstanding
  5400. * sequences on the same exchange
  5401. */
  5402. wqe->words[3] = 0;
  5403. /* word4 relative_offset memcpy */
  5404. /* word5 r_ctl/df_ctl memcpy */
  5405. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5406. wqe->xmit_sequence.xmit_len = xmit_len;
  5407. command_type = OTHER_COMMAND;
  5408. break;
  5409. case CMD_XMIT_BCAST64_CN:
  5410. /* word3 iocb=iotag32 wqe=payload_len */
  5411. wqe->words[3] = 0; /* no definition for this in wqe */
  5412. /* word4 iocb=rsvd wqe=rsvd */
  5413. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5414. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5415. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5416. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5417. break;
  5418. case CMD_FCP_IWRITE64_CR:
  5419. command_type = FCP_COMMAND_DATA_OUT;
  5420. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5421. * confusing.
  5422. * word3 is payload_len: byte offset to the sgl entry for the
  5423. * fcp_command.
  5424. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5425. * word5 is initial xfer len 0 = wait for xfer-ready
  5426. */
  5427. /* Always wait for xfer-ready before sending data */
  5428. wqe->fcp_iwrite.initial_xfer_len = 0;
  5429. /* word 4 (xfer length) should have been set on the memcpy */
  5430. /* allow write to fall through to read */
  5431. case CMD_FCP_IREAD64_CR:
  5432. /* FCP_CMD is always the 1st sgl entry */
  5433. wqe->fcp_iread.payload_len =
  5434. xmit_len + sizeof(struct fcp_rsp);
  5435. /* word 4 (xfer length) should have been set on the memcpy */
  5436. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5437. iocbq->iocb.ulpFCP2Rcvy);
  5438. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5439. /* The XC bit and the XS bit are similar. The driver never
  5440. * tracked whether or not the exchange was previouslly open.
  5441. * XC = Exchange create, 0 is create. 1 is already open.
  5442. * XS = link cmd: 1 do not close the exchange after command.
  5443. * XS = 0 close exchange when command completes.
  5444. * The only time we would not set the XC bit is when the XS bit
  5445. * is set and we are sending our 2nd or greater command on
  5446. * this exchange.
  5447. */
  5448. /* Always open the exchange */
  5449. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5450. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5451. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5452. break;
  5453. case CMD_FCP_ICMND64_CR:
  5454. /* Always open the exchange */
  5455. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5456. wqe->words[4] = 0;
  5457. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5458. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5459. break;
  5460. case CMD_GEN_REQUEST64_CR:
  5461. /* word3 command length is described as byte offset to the
  5462. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5463. * sgl[0] = cmnd
  5464. * sgl[1] = rsp.
  5465. *
  5466. */
  5467. wqe->gen_req.command_len = xmit_len;
  5468. /* Word4 parameter copied in the memcpy */
  5469. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5470. /* word6 context tag copied in memcpy */
  5471. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5472. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5473. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5474. "2015 Invalid CT %x command 0x%x\n",
  5475. ct, iocbq->iocb.ulpCommand);
  5476. return IOCB_ERROR;
  5477. }
  5478. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5479. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5480. iocbq->iocb.ulpTimeout);
  5481. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5482. command_type = OTHER_COMMAND;
  5483. break;
  5484. case CMD_XMIT_ELS_RSP64_CX:
  5485. /* words0-2 BDE memcpy */
  5486. /* word3 iocb=iotag32 wqe=rsvd */
  5487. wqe->words[3] = 0;
  5488. /* word4 iocb=did wge=rsvd. */
  5489. wqe->words[4] = 0;
  5490. /* word5 iocb=rsvd wge=did */
  5491. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5492. iocbq->iocb.un.elsreq64.remoteID);
  5493. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5494. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5495. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5496. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5497. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5498. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5499. iocbq->vport->vpi + phba->vpi_base);
  5500. command_type = OTHER_COMMAND;
  5501. break;
  5502. case CMD_CLOSE_XRI_CN:
  5503. case CMD_ABORT_XRI_CN:
  5504. case CMD_ABORT_XRI_CX:
  5505. /* words 0-2 memcpy should be 0 rserved */
  5506. /* port will send abts */
  5507. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5508. /*
  5509. * The link is down so the fw does not need to send abts
  5510. * on the wire.
  5511. */
  5512. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5513. else
  5514. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5515. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5516. wqe->words[5] = 0;
  5517. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5518. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5519. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5520. /*
  5521. * The abort handler will send us CMD_ABORT_XRI_CN or
  5522. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5523. */
  5524. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5525. cmnd = CMD_ABORT_XRI_CX;
  5526. command_type = OTHER_COMMAND;
  5527. xritag = 0;
  5528. break;
  5529. case CMD_XMIT_BLS_RSP64_CX:
  5530. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5531. * we re-construct this WQE here based on information in
  5532. * iocbq from scratch.
  5533. */
  5534. memset(wqe, 0, sizeof(union lpfc_wqe));
  5535. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5536. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5537. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5538. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5539. LPFC_ABTS_UNSOL_INT) {
  5540. /* ABTS sent by initiator to CT exchange, the
  5541. * RX_ID field will be filled with the newly
  5542. * allocated responder XRI.
  5543. */
  5544. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5545. iocbq->sli4_xritag);
  5546. } else {
  5547. /* ABTS sent by responder to CT exchange, the
  5548. * RX_ID field will be filled with the responder
  5549. * RX_ID from ABTS.
  5550. */
  5551. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5552. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5553. }
  5554. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5555. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5556. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5557. iocbq->iocb.ulpContext);
  5558. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5559. command_type = OTHER_COMMAND;
  5560. break;
  5561. case CMD_XRI_ABORTED_CX:
  5562. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5563. /* words0-2 are all 0's no bde */
  5564. /* word3 and word4 are rsvrd */
  5565. wqe->words[3] = 0;
  5566. wqe->words[4] = 0;
  5567. /* word5 iocb=rsvd wge=did */
  5568. /* There is no remote port id in the IOCB? */
  5569. /* Let this fall through and fail */
  5570. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5571. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5572. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5573. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5574. default:
  5575. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5576. "2014 Invalid command 0x%x\n",
  5577. iocbq->iocb.ulpCommand);
  5578. return IOCB_ERROR;
  5579. break;
  5580. }
  5581. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5582. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5583. wqe->generic.abort_tag = abort_tag;
  5584. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5585. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5586. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5587. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5588. return 0;
  5589. }
  5590. /**
  5591. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5592. * @phba: Pointer to HBA context object.
  5593. * @ring_number: SLI ring number to issue iocb on.
  5594. * @piocb: Pointer to command iocb.
  5595. * @flag: Flag indicating if this command can be put into txq.
  5596. *
  5597. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5598. * an iocb command to an HBA with SLI-4 interface spec.
  5599. *
  5600. * This function is called with hbalock held. The function will return success
  5601. * after it successfully submit the iocb to firmware or after adding to the
  5602. * txq.
  5603. **/
  5604. static int
  5605. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5606. struct lpfc_iocbq *piocb, uint32_t flag)
  5607. {
  5608. struct lpfc_sglq *sglq;
  5609. uint16_t xritag;
  5610. union lpfc_wqe wqe;
  5611. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5612. if (piocb->sli4_xritag == NO_XRI) {
  5613. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5614. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5615. sglq = NULL;
  5616. else {
  5617. sglq = __lpfc_sli_get_sglq(phba);
  5618. if (!sglq)
  5619. return IOCB_ERROR;
  5620. piocb->sli4_xritag = sglq->sli4_xritag;
  5621. }
  5622. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5623. sglq = NULL; /* These IO's already have an XRI and
  5624. * a mapped sgl.
  5625. */
  5626. } else {
  5627. /* This is a continuation of a commandi,(CX) so this
  5628. * sglq is on the active list
  5629. */
  5630. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5631. if (!sglq)
  5632. return IOCB_ERROR;
  5633. }
  5634. if (sglq) {
  5635. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5636. if (xritag != sglq->sli4_xritag)
  5637. return IOCB_ERROR;
  5638. }
  5639. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5640. return IOCB_ERROR;
  5641. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5642. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5643. /*
  5644. * For FCP command IOCB, get a new WQ index to distribute
  5645. * WQE across the WQsr. On the other hand, for abort IOCB,
  5646. * it carries the same WQ index to the original command
  5647. * IOCB.
  5648. */
  5649. if (piocb->iocb_flag & LPFC_IO_FCP)
  5650. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5651. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5652. &wqe))
  5653. return IOCB_ERROR;
  5654. } else {
  5655. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5656. return IOCB_ERROR;
  5657. }
  5658. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5659. return 0;
  5660. }
  5661. /**
  5662. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5663. *
  5664. * This routine wraps the actual lockless version for issusing IOCB function
  5665. * pointer from the lpfc_hba struct.
  5666. *
  5667. * Return codes:
  5668. * IOCB_ERROR - Error
  5669. * IOCB_SUCCESS - Success
  5670. * IOCB_BUSY - Busy
  5671. **/
  5672. static inline int
  5673. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5674. struct lpfc_iocbq *piocb, uint32_t flag)
  5675. {
  5676. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5677. }
  5678. /**
  5679. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5680. * @phba: The hba struct for which this call is being executed.
  5681. * @dev_grp: The HBA PCI-Device group number.
  5682. *
  5683. * This routine sets up the SLI interface API function jump table in @phba
  5684. * struct.
  5685. * Returns: 0 - success, -ENODEV - failure.
  5686. **/
  5687. int
  5688. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5689. {
  5690. switch (dev_grp) {
  5691. case LPFC_PCI_DEV_LP:
  5692. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5693. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5694. break;
  5695. case LPFC_PCI_DEV_OC:
  5696. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5697. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5698. break;
  5699. default:
  5700. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5701. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5702. dev_grp);
  5703. return -ENODEV;
  5704. break;
  5705. }
  5706. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5707. return 0;
  5708. }
  5709. /**
  5710. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5711. * @phba: Pointer to HBA context object.
  5712. * @pring: Pointer to driver SLI ring object.
  5713. * @piocb: Pointer to command iocb.
  5714. * @flag: Flag indicating if this command can be put into txq.
  5715. *
  5716. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5717. * function. This function gets the hbalock and calls
  5718. * __lpfc_sli_issue_iocb function and will return the error returned
  5719. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5720. * functions which do not hold hbalock.
  5721. **/
  5722. int
  5723. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5724. struct lpfc_iocbq *piocb, uint32_t flag)
  5725. {
  5726. unsigned long iflags;
  5727. int rc;
  5728. spin_lock_irqsave(&phba->hbalock, iflags);
  5729. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5730. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5731. return rc;
  5732. }
  5733. /**
  5734. * lpfc_extra_ring_setup - Extra ring setup function
  5735. * @phba: Pointer to HBA context object.
  5736. *
  5737. * This function is called while driver attaches with the
  5738. * HBA to setup the extra ring. The extra ring is used
  5739. * only when driver needs to support target mode functionality
  5740. * or IP over FC functionalities.
  5741. *
  5742. * This function is called with no lock held.
  5743. **/
  5744. static int
  5745. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5746. {
  5747. struct lpfc_sli *psli;
  5748. struct lpfc_sli_ring *pring;
  5749. psli = &phba->sli;
  5750. /* Adjust cmd/rsp ring iocb entries more evenly */
  5751. /* Take some away from the FCP ring */
  5752. pring = &psli->ring[psli->fcp_ring];
  5753. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5754. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5755. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5756. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5757. /* and give them to the extra ring */
  5758. pring = &psli->ring[psli->extra_ring];
  5759. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5760. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5761. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5762. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5763. /* Setup default profile for this ring */
  5764. pring->iotag_max = 4096;
  5765. pring->num_mask = 1;
  5766. pring->prt[0].profile = 0; /* Mask 0 */
  5767. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5768. pring->prt[0].type = phba->cfg_multi_ring_type;
  5769. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5770. return 0;
  5771. }
  5772. /**
  5773. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5774. * @phba: Pointer to HBA context object.
  5775. * @pring: Pointer to driver SLI ring object.
  5776. * @iocbq: Pointer to iocb object.
  5777. *
  5778. * This function is called by the slow ring event handler
  5779. * function when there is an ASYNC event iocb in the ring.
  5780. * This function is called with no lock held.
  5781. * Currently this function handles only temperature related
  5782. * ASYNC events. The function decodes the temperature sensor
  5783. * event message and posts events for the management applications.
  5784. **/
  5785. static void
  5786. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5787. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5788. {
  5789. IOCB_t *icmd;
  5790. uint16_t evt_code;
  5791. uint16_t temp;
  5792. struct temp_event temp_event_data;
  5793. struct Scsi_Host *shost;
  5794. uint32_t *iocb_w;
  5795. icmd = &iocbq->iocb;
  5796. evt_code = icmd->un.asyncstat.evt_code;
  5797. temp = icmd->ulpContext;
  5798. if ((evt_code != ASYNC_TEMP_WARN) &&
  5799. (evt_code != ASYNC_TEMP_SAFE)) {
  5800. iocb_w = (uint32_t *) icmd;
  5801. lpfc_printf_log(phba,
  5802. KERN_ERR,
  5803. LOG_SLI,
  5804. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5805. " evt_code 0x%x\n"
  5806. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5807. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5808. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5809. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5810. pring->ringno,
  5811. icmd->un.asyncstat.evt_code,
  5812. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5813. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5814. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5815. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5816. return;
  5817. }
  5818. temp_event_data.data = (uint32_t)temp;
  5819. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5820. if (evt_code == ASYNC_TEMP_WARN) {
  5821. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5822. lpfc_printf_log(phba,
  5823. KERN_ERR,
  5824. LOG_TEMP,
  5825. "0347 Adapter is very hot, please take "
  5826. "corrective action. temperature : %d Celsius\n",
  5827. temp);
  5828. }
  5829. if (evt_code == ASYNC_TEMP_SAFE) {
  5830. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5831. lpfc_printf_log(phba,
  5832. KERN_ERR,
  5833. LOG_TEMP,
  5834. "0340 Adapter temperature is OK now. "
  5835. "temperature : %d Celsius\n",
  5836. temp);
  5837. }
  5838. /* Send temperature change event to applications */
  5839. shost = lpfc_shost_from_vport(phba->pport);
  5840. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5841. sizeof(temp_event_data), (char *) &temp_event_data,
  5842. LPFC_NL_VENDOR_ID);
  5843. }
  5844. /**
  5845. * lpfc_sli_setup - SLI ring setup function
  5846. * @phba: Pointer to HBA context object.
  5847. *
  5848. * lpfc_sli_setup sets up rings of the SLI interface with
  5849. * number of iocbs per ring and iotags. This function is
  5850. * called while driver attach to the HBA and before the
  5851. * interrupts are enabled. So there is no need for locking.
  5852. *
  5853. * This function always returns 0.
  5854. **/
  5855. int
  5856. lpfc_sli_setup(struct lpfc_hba *phba)
  5857. {
  5858. int i, totiocbsize = 0;
  5859. struct lpfc_sli *psli = &phba->sli;
  5860. struct lpfc_sli_ring *pring;
  5861. psli->num_rings = MAX_CONFIGURED_RINGS;
  5862. psli->sli_flag = 0;
  5863. psli->fcp_ring = LPFC_FCP_RING;
  5864. psli->next_ring = LPFC_FCP_NEXT_RING;
  5865. psli->extra_ring = LPFC_EXTRA_RING;
  5866. psli->iocbq_lookup = NULL;
  5867. psli->iocbq_lookup_len = 0;
  5868. psli->last_iotag = 0;
  5869. for (i = 0; i < psli->num_rings; i++) {
  5870. pring = &psli->ring[i];
  5871. switch (i) {
  5872. case LPFC_FCP_RING: /* ring 0 - FCP */
  5873. /* numCiocb and numRiocb are used in config_port */
  5874. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5875. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5876. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5877. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5878. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5879. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5880. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5881. SLI3_IOCB_CMD_SIZE :
  5882. SLI2_IOCB_CMD_SIZE;
  5883. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5884. SLI3_IOCB_RSP_SIZE :
  5885. SLI2_IOCB_RSP_SIZE;
  5886. pring->iotag_ctr = 0;
  5887. pring->iotag_max =
  5888. (phba->cfg_hba_queue_depth * 2);
  5889. pring->fast_iotag = pring->iotag_max;
  5890. pring->num_mask = 0;
  5891. break;
  5892. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5893. /* numCiocb and numRiocb are used in config_port */
  5894. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5895. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5896. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5897. SLI3_IOCB_CMD_SIZE :
  5898. SLI2_IOCB_CMD_SIZE;
  5899. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5900. SLI3_IOCB_RSP_SIZE :
  5901. SLI2_IOCB_RSP_SIZE;
  5902. pring->iotag_max = phba->cfg_hba_queue_depth;
  5903. pring->num_mask = 0;
  5904. break;
  5905. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5906. /* numCiocb and numRiocb are used in config_port */
  5907. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5908. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5909. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5910. SLI3_IOCB_CMD_SIZE :
  5911. SLI2_IOCB_CMD_SIZE;
  5912. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5913. SLI3_IOCB_RSP_SIZE :
  5914. SLI2_IOCB_RSP_SIZE;
  5915. pring->fast_iotag = 0;
  5916. pring->iotag_ctr = 0;
  5917. pring->iotag_max = 4096;
  5918. pring->lpfc_sli_rcv_async_status =
  5919. lpfc_sli_async_event_handler;
  5920. pring->num_mask = LPFC_MAX_RING_MASK;
  5921. pring->prt[0].profile = 0; /* Mask 0 */
  5922. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5923. pring->prt[0].type = FC_TYPE_ELS;
  5924. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5925. lpfc_els_unsol_event;
  5926. pring->prt[1].profile = 0; /* Mask 1 */
  5927. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5928. pring->prt[1].type = FC_TYPE_ELS;
  5929. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5930. lpfc_els_unsol_event;
  5931. pring->prt[2].profile = 0; /* Mask 2 */
  5932. /* NameServer Inquiry */
  5933. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5934. /* NameServer */
  5935. pring->prt[2].type = FC_TYPE_CT;
  5936. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5937. lpfc_ct_unsol_event;
  5938. pring->prt[3].profile = 0; /* Mask 3 */
  5939. /* NameServer response */
  5940. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5941. /* NameServer */
  5942. pring->prt[3].type = FC_TYPE_CT;
  5943. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5944. lpfc_ct_unsol_event;
  5945. /* abort unsolicited sequence */
  5946. pring->prt[4].profile = 0; /* Mask 4 */
  5947. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5948. pring->prt[4].type = FC_TYPE_BLS;
  5949. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5950. lpfc_sli4_ct_abort_unsol_event;
  5951. break;
  5952. }
  5953. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5954. (pring->numRiocb * pring->sizeRiocb);
  5955. }
  5956. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5957. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5958. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5959. "SLI2 SLIM Data: x%x x%lx\n",
  5960. phba->brd_no, totiocbsize,
  5961. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5962. }
  5963. if (phba->cfg_multi_ring_support == 2)
  5964. lpfc_extra_ring_setup(phba);
  5965. return 0;
  5966. }
  5967. /**
  5968. * lpfc_sli_queue_setup - Queue initialization function
  5969. * @phba: Pointer to HBA context object.
  5970. *
  5971. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5972. * ring. This function also initializes ring indices of each ring.
  5973. * This function is called during the initialization of the SLI
  5974. * interface of an HBA.
  5975. * This function is called with no lock held and always returns
  5976. * 1.
  5977. **/
  5978. int
  5979. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5980. {
  5981. struct lpfc_sli *psli;
  5982. struct lpfc_sli_ring *pring;
  5983. int i;
  5984. psli = &phba->sli;
  5985. spin_lock_irq(&phba->hbalock);
  5986. INIT_LIST_HEAD(&psli->mboxq);
  5987. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5988. /* Initialize list headers for txq and txcmplq as double linked lists */
  5989. for (i = 0; i < psli->num_rings; i++) {
  5990. pring = &psli->ring[i];
  5991. pring->ringno = i;
  5992. pring->next_cmdidx = 0;
  5993. pring->local_getidx = 0;
  5994. pring->cmdidx = 0;
  5995. INIT_LIST_HEAD(&pring->txq);
  5996. INIT_LIST_HEAD(&pring->txcmplq);
  5997. INIT_LIST_HEAD(&pring->iocb_continueq);
  5998. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5999. INIT_LIST_HEAD(&pring->postbufq);
  6000. }
  6001. spin_unlock_irq(&phba->hbalock);
  6002. return 1;
  6003. }
  6004. /**
  6005. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6006. * @phba: Pointer to HBA context object.
  6007. *
  6008. * This routine flushes the mailbox command subsystem. It will unconditionally
  6009. * flush all the mailbox commands in the three possible stages in the mailbox
  6010. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6011. * command; and completed mailbox command queue. It is caller's responsibility
  6012. * to make sure that the driver is in the proper state to flush the mailbox
  6013. * command sub-system. Namely, the posting of mailbox commands into the
  6014. * pending mailbox command queue from the various clients must be stopped;
  6015. * either the HBA is in a state that it will never works on the outstanding
  6016. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6017. * mailbox command has been completed.
  6018. **/
  6019. static void
  6020. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6021. {
  6022. LIST_HEAD(completions);
  6023. struct lpfc_sli *psli = &phba->sli;
  6024. LPFC_MBOXQ_t *pmb;
  6025. unsigned long iflag;
  6026. /* Flush all the mailbox commands in the mbox system */
  6027. spin_lock_irqsave(&phba->hbalock, iflag);
  6028. /* The pending mailbox command queue */
  6029. list_splice_init(&phba->sli.mboxq, &completions);
  6030. /* The outstanding active mailbox command */
  6031. if (psli->mbox_active) {
  6032. list_add_tail(&psli->mbox_active->list, &completions);
  6033. psli->mbox_active = NULL;
  6034. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6035. }
  6036. /* The completed mailbox command queue */
  6037. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6038. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6039. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6040. while (!list_empty(&completions)) {
  6041. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6042. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6043. if (pmb->mbox_cmpl)
  6044. pmb->mbox_cmpl(phba, pmb);
  6045. }
  6046. }
  6047. /**
  6048. * lpfc_sli_host_down - Vport cleanup function
  6049. * @vport: Pointer to virtual port object.
  6050. *
  6051. * lpfc_sli_host_down is called to clean up the resources
  6052. * associated with a vport before destroying virtual
  6053. * port data structures.
  6054. * This function does following operations:
  6055. * - Free discovery resources associated with this virtual
  6056. * port.
  6057. * - Free iocbs associated with this virtual port in
  6058. * the txq.
  6059. * - Send abort for all iocb commands associated with this
  6060. * vport in txcmplq.
  6061. *
  6062. * This function is called with no lock held and always returns 1.
  6063. **/
  6064. int
  6065. lpfc_sli_host_down(struct lpfc_vport *vport)
  6066. {
  6067. LIST_HEAD(completions);
  6068. struct lpfc_hba *phba = vport->phba;
  6069. struct lpfc_sli *psli = &phba->sli;
  6070. struct lpfc_sli_ring *pring;
  6071. struct lpfc_iocbq *iocb, *next_iocb;
  6072. int i;
  6073. unsigned long flags = 0;
  6074. uint16_t prev_pring_flag;
  6075. lpfc_cleanup_discovery_resources(vport);
  6076. spin_lock_irqsave(&phba->hbalock, flags);
  6077. for (i = 0; i < psli->num_rings; i++) {
  6078. pring = &psli->ring[i];
  6079. prev_pring_flag = pring->flag;
  6080. /* Only slow rings */
  6081. if (pring->ringno == LPFC_ELS_RING) {
  6082. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6083. /* Set the lpfc data pending flag */
  6084. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6085. }
  6086. /*
  6087. * Error everything on the txq since these iocbs have not been
  6088. * given to the FW yet.
  6089. */
  6090. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6091. if (iocb->vport != vport)
  6092. continue;
  6093. list_move_tail(&iocb->list, &completions);
  6094. pring->txq_cnt--;
  6095. }
  6096. /* Next issue ABTS for everything on the txcmplq */
  6097. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6098. list) {
  6099. if (iocb->vport != vport)
  6100. continue;
  6101. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6102. }
  6103. pring->flag = prev_pring_flag;
  6104. }
  6105. spin_unlock_irqrestore(&phba->hbalock, flags);
  6106. /* Cancel all the IOCBs from the completions list */
  6107. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6108. IOERR_SLI_DOWN);
  6109. return 1;
  6110. }
  6111. /**
  6112. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6113. * @phba: Pointer to HBA context object.
  6114. *
  6115. * This function cleans up all iocb, buffers, mailbox commands
  6116. * while shutting down the HBA. This function is called with no
  6117. * lock held and always returns 1.
  6118. * This function does the following to cleanup driver resources:
  6119. * - Free discovery resources for each virtual port
  6120. * - Cleanup any pending fabric iocbs
  6121. * - Iterate through the iocb txq and free each entry
  6122. * in the list.
  6123. * - Free up any buffer posted to the HBA
  6124. * - Free mailbox commands in the mailbox queue.
  6125. **/
  6126. int
  6127. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6128. {
  6129. LIST_HEAD(completions);
  6130. struct lpfc_sli *psli = &phba->sli;
  6131. struct lpfc_sli_ring *pring;
  6132. struct lpfc_dmabuf *buf_ptr;
  6133. unsigned long flags = 0;
  6134. int i;
  6135. /* Shutdown the mailbox command sub-system */
  6136. lpfc_sli_mbox_sys_shutdown(phba);
  6137. lpfc_hba_down_prep(phba);
  6138. lpfc_fabric_abort_hba(phba);
  6139. spin_lock_irqsave(&phba->hbalock, flags);
  6140. for (i = 0; i < psli->num_rings; i++) {
  6141. pring = &psli->ring[i];
  6142. /* Only slow rings */
  6143. if (pring->ringno == LPFC_ELS_RING) {
  6144. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6145. /* Set the lpfc data pending flag */
  6146. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6147. }
  6148. /*
  6149. * Error everything on the txq since these iocbs have not been
  6150. * given to the FW yet.
  6151. */
  6152. list_splice_init(&pring->txq, &completions);
  6153. pring->txq_cnt = 0;
  6154. }
  6155. spin_unlock_irqrestore(&phba->hbalock, flags);
  6156. /* Cancel all the IOCBs from the completions list */
  6157. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6158. IOERR_SLI_DOWN);
  6159. spin_lock_irqsave(&phba->hbalock, flags);
  6160. list_splice_init(&phba->elsbuf, &completions);
  6161. phba->elsbuf_cnt = 0;
  6162. phba->elsbuf_prev_cnt = 0;
  6163. spin_unlock_irqrestore(&phba->hbalock, flags);
  6164. while (!list_empty(&completions)) {
  6165. list_remove_head(&completions, buf_ptr,
  6166. struct lpfc_dmabuf, list);
  6167. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6168. kfree(buf_ptr);
  6169. }
  6170. /* Return any active mbox cmds */
  6171. del_timer_sync(&psli->mbox_tmo);
  6172. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6173. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6174. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6175. return 1;
  6176. }
  6177. /**
  6178. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6179. * @phba: Pointer to HBA context object.
  6180. *
  6181. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6182. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6183. * lock held and always returns 1.
  6184. *
  6185. * This function does the following to cleanup driver FCoE function resources:
  6186. * - Free discovery resources for each virtual port
  6187. * - Cleanup any pending fabric iocbs
  6188. * - Iterate through the iocb txq and free each entry in the list.
  6189. * - Free up any buffer posted to the HBA.
  6190. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6191. * - Free mailbox commands in the mailbox queue.
  6192. **/
  6193. int
  6194. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6195. {
  6196. /* Stop the SLI4 device port */
  6197. lpfc_stop_port(phba);
  6198. /* Tear down the queues in the HBA */
  6199. lpfc_sli4_queue_unset(phba);
  6200. /* unregister default FCFI from the HBA */
  6201. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6202. return 1;
  6203. }
  6204. /**
  6205. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6206. * @srcp: Source memory pointer.
  6207. * @destp: Destination memory pointer.
  6208. * @cnt: Number of words required to be copied.
  6209. *
  6210. * This function is used for copying data between driver memory
  6211. * and the SLI memory. This function also changes the endianness
  6212. * of each word if native endianness is different from SLI
  6213. * endianness. This function can be called with or without
  6214. * lock.
  6215. **/
  6216. void
  6217. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6218. {
  6219. uint32_t *src = srcp;
  6220. uint32_t *dest = destp;
  6221. uint32_t ldata;
  6222. int i;
  6223. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6224. ldata = *src;
  6225. ldata = le32_to_cpu(ldata);
  6226. *dest = ldata;
  6227. src++;
  6228. dest++;
  6229. }
  6230. }
  6231. /**
  6232. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6233. * @srcp: Source memory pointer.
  6234. * @destp: Destination memory pointer.
  6235. * @cnt: Number of words required to be copied.
  6236. *
  6237. * This function is used for copying data between a data structure
  6238. * with big endian representation to local endianness.
  6239. * This function can be called with or without lock.
  6240. **/
  6241. void
  6242. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6243. {
  6244. uint32_t *src = srcp;
  6245. uint32_t *dest = destp;
  6246. uint32_t ldata;
  6247. int i;
  6248. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6249. ldata = *src;
  6250. ldata = be32_to_cpu(ldata);
  6251. *dest = ldata;
  6252. src++;
  6253. dest++;
  6254. }
  6255. }
  6256. /**
  6257. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6258. * @phba: Pointer to HBA context object.
  6259. * @pring: Pointer to driver SLI ring object.
  6260. * @mp: Pointer to driver buffer object.
  6261. *
  6262. * This function is called with no lock held.
  6263. * It always return zero after adding the buffer to the postbufq
  6264. * buffer list.
  6265. **/
  6266. int
  6267. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6268. struct lpfc_dmabuf *mp)
  6269. {
  6270. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6271. later */
  6272. spin_lock_irq(&phba->hbalock);
  6273. list_add_tail(&mp->list, &pring->postbufq);
  6274. pring->postbufq_cnt++;
  6275. spin_unlock_irq(&phba->hbalock);
  6276. return 0;
  6277. }
  6278. /**
  6279. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6280. * @phba: Pointer to HBA context object.
  6281. *
  6282. * When HBQ is enabled, buffers are searched based on tags. This function
  6283. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6284. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6285. * does not conflict with tags of buffer posted for unsolicited events.
  6286. * The function returns the allocated tag. The function is called with
  6287. * no locks held.
  6288. **/
  6289. uint32_t
  6290. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6291. {
  6292. spin_lock_irq(&phba->hbalock);
  6293. phba->buffer_tag_count++;
  6294. /*
  6295. * Always set the QUE_BUFTAG_BIT to distiguish between
  6296. * a tag assigned by HBQ.
  6297. */
  6298. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6299. spin_unlock_irq(&phba->hbalock);
  6300. return phba->buffer_tag_count;
  6301. }
  6302. /**
  6303. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6304. * @phba: Pointer to HBA context object.
  6305. * @pring: Pointer to driver SLI ring object.
  6306. * @tag: Buffer tag.
  6307. *
  6308. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6309. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6310. * iocb is posted to the response ring with the tag of the buffer.
  6311. * This function searches the pring->postbufq list using the tag
  6312. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6313. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6314. * buffer is returned to the caller else NULL is returned.
  6315. * This function is called with no lock held.
  6316. **/
  6317. struct lpfc_dmabuf *
  6318. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6319. uint32_t tag)
  6320. {
  6321. struct lpfc_dmabuf *mp, *next_mp;
  6322. struct list_head *slp = &pring->postbufq;
  6323. /* Search postbufq, from the begining, looking for a match on tag */
  6324. spin_lock_irq(&phba->hbalock);
  6325. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6326. if (mp->buffer_tag == tag) {
  6327. list_del_init(&mp->list);
  6328. pring->postbufq_cnt--;
  6329. spin_unlock_irq(&phba->hbalock);
  6330. return mp;
  6331. }
  6332. }
  6333. spin_unlock_irq(&phba->hbalock);
  6334. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6335. "0402 Cannot find virtual addr for buffer tag on "
  6336. "ring %d Data x%lx x%p x%p x%x\n",
  6337. pring->ringno, (unsigned long) tag,
  6338. slp->next, slp->prev, pring->postbufq_cnt);
  6339. return NULL;
  6340. }
  6341. /**
  6342. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6343. * @phba: Pointer to HBA context object.
  6344. * @pring: Pointer to driver SLI ring object.
  6345. * @phys: DMA address of the buffer.
  6346. *
  6347. * This function searches the buffer list using the dma_address
  6348. * of unsolicited event to find the driver's lpfc_dmabuf object
  6349. * corresponding to the dma_address. The function returns the
  6350. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6351. * This function is called by the ct and els unsolicited event
  6352. * handlers to get the buffer associated with the unsolicited
  6353. * event.
  6354. *
  6355. * This function is called with no lock held.
  6356. **/
  6357. struct lpfc_dmabuf *
  6358. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6359. dma_addr_t phys)
  6360. {
  6361. struct lpfc_dmabuf *mp, *next_mp;
  6362. struct list_head *slp = &pring->postbufq;
  6363. /* Search postbufq, from the begining, looking for a match on phys */
  6364. spin_lock_irq(&phba->hbalock);
  6365. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6366. if (mp->phys == phys) {
  6367. list_del_init(&mp->list);
  6368. pring->postbufq_cnt--;
  6369. spin_unlock_irq(&phba->hbalock);
  6370. return mp;
  6371. }
  6372. }
  6373. spin_unlock_irq(&phba->hbalock);
  6374. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6375. "0410 Cannot find virtual addr for mapped buf on "
  6376. "ring %d Data x%llx x%p x%p x%x\n",
  6377. pring->ringno, (unsigned long long)phys,
  6378. slp->next, slp->prev, pring->postbufq_cnt);
  6379. return NULL;
  6380. }
  6381. /**
  6382. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6383. * @phba: Pointer to HBA context object.
  6384. * @cmdiocb: Pointer to driver command iocb object.
  6385. * @rspiocb: Pointer to driver response iocb object.
  6386. *
  6387. * This function is the completion handler for the abort iocbs for
  6388. * ELS commands. This function is called from the ELS ring event
  6389. * handler with no lock held. This function frees memory resources
  6390. * associated with the abort iocb.
  6391. **/
  6392. static void
  6393. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6394. struct lpfc_iocbq *rspiocb)
  6395. {
  6396. IOCB_t *irsp = &rspiocb->iocb;
  6397. uint16_t abort_iotag, abort_context;
  6398. struct lpfc_iocbq *abort_iocb;
  6399. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6400. abort_iocb = NULL;
  6401. if (irsp->ulpStatus) {
  6402. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6403. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6404. spin_lock_irq(&phba->hbalock);
  6405. if (phba->sli_rev < LPFC_SLI_REV4) {
  6406. if (abort_iotag != 0 &&
  6407. abort_iotag <= phba->sli.last_iotag)
  6408. abort_iocb =
  6409. phba->sli.iocbq_lookup[abort_iotag];
  6410. } else
  6411. /* For sli4 the abort_tag is the XRI,
  6412. * so the abort routine puts the iotag of the iocb
  6413. * being aborted in the context field of the abort
  6414. * IOCB.
  6415. */
  6416. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6417. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6418. "0327 Cannot abort els iocb %p "
  6419. "with tag %x context %x, abort status %x, "
  6420. "abort code %x\n",
  6421. abort_iocb, abort_iotag, abort_context,
  6422. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6423. /*
  6424. * If the iocb is not found in Firmware queue the iocb
  6425. * might have completed already. Do not free it again.
  6426. */
  6427. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6428. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6429. spin_unlock_irq(&phba->hbalock);
  6430. lpfc_sli_release_iocbq(phba, cmdiocb);
  6431. return;
  6432. }
  6433. /* For SLI4 the ulpContext field for abort IOCB
  6434. * holds the iotag of the IOCB being aborted so
  6435. * the local abort_context needs to be reset to
  6436. * match the aborted IOCBs ulpContext.
  6437. */
  6438. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6439. abort_context = abort_iocb->iocb.ulpContext;
  6440. }
  6441. /*
  6442. * make sure we have the right iocbq before taking it
  6443. * off the txcmplq and try to call completion routine.
  6444. */
  6445. if (!abort_iocb ||
  6446. abort_iocb->iocb.ulpContext != abort_context ||
  6447. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6448. spin_unlock_irq(&phba->hbalock);
  6449. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6450. /*
  6451. * leave the SLI4 aborted command on the txcmplq
  6452. * list and the command complete WCQE's XB bit
  6453. * will tell whether the SGL (XRI) can be released
  6454. * immediately or to the aborted SGL list for the
  6455. * following abort XRI from the HBA.
  6456. */
  6457. list_del_init(&abort_iocb->list);
  6458. pring->txcmplq_cnt--;
  6459. /* Firmware could still be in progress of DMAing
  6460. * payload, so don't free data buffer till after
  6461. * a hbeat.
  6462. */
  6463. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6464. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6465. spin_unlock_irq(&phba->hbalock);
  6466. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6467. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6468. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6469. } else
  6470. spin_unlock_irq(&phba->hbalock);
  6471. }
  6472. lpfc_sli_release_iocbq(phba, cmdiocb);
  6473. return;
  6474. }
  6475. /**
  6476. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6477. * @phba: Pointer to HBA context object.
  6478. * @cmdiocb: Pointer to driver command iocb object.
  6479. * @rspiocb: Pointer to driver response iocb object.
  6480. *
  6481. * The function is called from SLI ring event handler with no
  6482. * lock held. This function is the completion handler for ELS commands
  6483. * which are aborted. The function frees memory resources used for
  6484. * the aborted ELS commands.
  6485. **/
  6486. static void
  6487. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6488. struct lpfc_iocbq *rspiocb)
  6489. {
  6490. IOCB_t *irsp = &rspiocb->iocb;
  6491. /* ELS cmd tag <ulpIoTag> completes */
  6492. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6493. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6494. "x%x x%x x%x\n",
  6495. irsp->ulpIoTag, irsp->ulpStatus,
  6496. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6497. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6498. lpfc_ct_free_iocb(phba, cmdiocb);
  6499. else
  6500. lpfc_els_free_iocb(phba, cmdiocb);
  6501. return;
  6502. }
  6503. /**
  6504. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6505. * @phba: Pointer to HBA context object.
  6506. * @pring: Pointer to driver SLI ring object.
  6507. * @cmdiocb: Pointer to driver command iocb object.
  6508. *
  6509. * This function issues an abort iocb for the provided command
  6510. * iocb. This function is called with hbalock held.
  6511. * The function returns 0 when it fails due to memory allocation
  6512. * failure or when the command iocb is an abort request.
  6513. **/
  6514. int
  6515. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6516. struct lpfc_iocbq *cmdiocb)
  6517. {
  6518. struct lpfc_vport *vport = cmdiocb->vport;
  6519. struct lpfc_iocbq *abtsiocbp;
  6520. IOCB_t *icmd = NULL;
  6521. IOCB_t *iabt = NULL;
  6522. int retval = IOCB_ERROR;
  6523. /*
  6524. * There are certain command types we don't want to abort. And we
  6525. * don't want to abort commands that are already in the process of
  6526. * being aborted.
  6527. */
  6528. icmd = &cmdiocb->iocb;
  6529. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6530. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6531. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6532. return 0;
  6533. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6534. * callback so that nothing happens when it finishes.
  6535. */
  6536. if ((vport->load_flag & FC_UNLOADING) &&
  6537. (pring->ringno == LPFC_ELS_RING)) {
  6538. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6539. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6540. else
  6541. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6542. goto abort_iotag_exit;
  6543. }
  6544. /* issue ABTS for this IOCB based on iotag */
  6545. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6546. if (abtsiocbp == NULL)
  6547. return 0;
  6548. /* This signals the response to set the correct status
  6549. * before calling the completion handler
  6550. */
  6551. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6552. iabt = &abtsiocbp->iocb;
  6553. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6554. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6555. if (phba->sli_rev == LPFC_SLI_REV4) {
  6556. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6557. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6558. }
  6559. else
  6560. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6561. iabt->ulpLe = 1;
  6562. iabt->ulpClass = icmd->ulpClass;
  6563. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6564. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6565. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6566. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6567. if (phba->link_state >= LPFC_LINK_UP)
  6568. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6569. else
  6570. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6571. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6572. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6573. "0339 Abort xri x%x, original iotag x%x, "
  6574. "abort cmd iotag x%x\n",
  6575. iabt->un.acxri.abortContextTag,
  6576. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6577. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6578. if (retval)
  6579. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6580. abort_iotag_exit:
  6581. /*
  6582. * Caller to this routine should check for IOCB_ERROR
  6583. * and handle it properly. This routine no longer removes
  6584. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6585. */
  6586. return retval;
  6587. }
  6588. /**
  6589. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6590. * @iocbq: Pointer to driver iocb object.
  6591. * @vport: Pointer to driver virtual port object.
  6592. * @tgt_id: SCSI ID of the target.
  6593. * @lun_id: LUN ID of the scsi device.
  6594. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6595. *
  6596. * This function acts as an iocb filter for functions which abort or count
  6597. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6598. * 0 if the filtering criteria is met for the given iocb and will return
  6599. * 1 if the filtering criteria is not met.
  6600. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6601. * given iocb is for the SCSI device specified by vport, tgt_id and
  6602. * lun_id parameter.
  6603. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6604. * given iocb is for the SCSI target specified by vport and tgt_id
  6605. * parameters.
  6606. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6607. * given iocb is for the SCSI host associated with the given vport.
  6608. * This function is called with no locks held.
  6609. **/
  6610. static int
  6611. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6612. uint16_t tgt_id, uint64_t lun_id,
  6613. lpfc_ctx_cmd ctx_cmd)
  6614. {
  6615. struct lpfc_scsi_buf *lpfc_cmd;
  6616. int rc = 1;
  6617. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6618. return rc;
  6619. if (iocbq->vport != vport)
  6620. return rc;
  6621. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6622. if (lpfc_cmd->pCmd == NULL)
  6623. return rc;
  6624. switch (ctx_cmd) {
  6625. case LPFC_CTX_LUN:
  6626. if ((lpfc_cmd->rdata->pnode) &&
  6627. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6628. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6629. rc = 0;
  6630. break;
  6631. case LPFC_CTX_TGT:
  6632. if ((lpfc_cmd->rdata->pnode) &&
  6633. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6634. rc = 0;
  6635. break;
  6636. case LPFC_CTX_HOST:
  6637. rc = 0;
  6638. break;
  6639. default:
  6640. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6641. __func__, ctx_cmd);
  6642. break;
  6643. }
  6644. return rc;
  6645. }
  6646. /**
  6647. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6648. * @vport: Pointer to virtual port.
  6649. * @tgt_id: SCSI ID of the target.
  6650. * @lun_id: LUN ID of the scsi device.
  6651. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6652. *
  6653. * This function returns number of FCP commands pending for the vport.
  6654. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6655. * commands pending on the vport associated with SCSI device specified
  6656. * by tgt_id and lun_id parameters.
  6657. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6658. * commands pending on the vport associated with SCSI target specified
  6659. * by tgt_id parameter.
  6660. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6661. * commands pending on the vport.
  6662. * This function returns the number of iocbs which satisfy the filter.
  6663. * This function is called without any lock held.
  6664. **/
  6665. int
  6666. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6667. lpfc_ctx_cmd ctx_cmd)
  6668. {
  6669. struct lpfc_hba *phba = vport->phba;
  6670. struct lpfc_iocbq *iocbq;
  6671. int sum, i;
  6672. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6673. iocbq = phba->sli.iocbq_lookup[i];
  6674. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6675. ctx_cmd) == 0)
  6676. sum++;
  6677. }
  6678. return sum;
  6679. }
  6680. /**
  6681. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6682. * @phba: Pointer to HBA context object
  6683. * @cmdiocb: Pointer to command iocb object.
  6684. * @rspiocb: Pointer to response iocb object.
  6685. *
  6686. * This function is called when an aborted FCP iocb completes. This
  6687. * function is called by the ring event handler with no lock held.
  6688. * This function frees the iocb.
  6689. **/
  6690. void
  6691. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6692. struct lpfc_iocbq *rspiocb)
  6693. {
  6694. lpfc_sli_release_iocbq(phba, cmdiocb);
  6695. return;
  6696. }
  6697. /**
  6698. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6699. * @vport: Pointer to virtual port.
  6700. * @pring: Pointer to driver SLI ring object.
  6701. * @tgt_id: SCSI ID of the target.
  6702. * @lun_id: LUN ID of the scsi device.
  6703. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6704. *
  6705. * This function sends an abort command for every SCSI command
  6706. * associated with the given virtual port pending on the ring
  6707. * filtered by lpfc_sli_validate_fcp_iocb function.
  6708. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6709. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6710. * parameters
  6711. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6712. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6713. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6714. * FCP iocbs associated with virtual port.
  6715. * This function returns number of iocbs it failed to abort.
  6716. * This function is called with no locks held.
  6717. **/
  6718. int
  6719. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6720. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6721. {
  6722. struct lpfc_hba *phba = vport->phba;
  6723. struct lpfc_iocbq *iocbq;
  6724. struct lpfc_iocbq *abtsiocb;
  6725. IOCB_t *cmd = NULL;
  6726. int errcnt = 0, ret_val = 0;
  6727. int i;
  6728. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6729. iocbq = phba->sli.iocbq_lookup[i];
  6730. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6731. abort_cmd) != 0)
  6732. continue;
  6733. /* issue ABTS for this IOCB based on iotag */
  6734. abtsiocb = lpfc_sli_get_iocbq(phba);
  6735. if (abtsiocb == NULL) {
  6736. errcnt++;
  6737. continue;
  6738. }
  6739. cmd = &iocbq->iocb;
  6740. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6741. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6742. if (phba->sli_rev == LPFC_SLI_REV4)
  6743. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6744. else
  6745. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6746. abtsiocb->iocb.ulpLe = 1;
  6747. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6748. abtsiocb->vport = phba->pport;
  6749. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6750. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6751. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6752. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6753. if (lpfc_is_link_up(phba))
  6754. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6755. else
  6756. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6757. /* Setup callback routine and issue the command. */
  6758. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6759. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6760. abtsiocb, 0);
  6761. if (ret_val == IOCB_ERROR) {
  6762. lpfc_sli_release_iocbq(phba, abtsiocb);
  6763. errcnt++;
  6764. continue;
  6765. }
  6766. }
  6767. return errcnt;
  6768. }
  6769. /**
  6770. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6771. * @phba: Pointer to HBA context object.
  6772. * @cmdiocbq: Pointer to command iocb.
  6773. * @rspiocbq: Pointer to response iocb.
  6774. *
  6775. * This function is the completion handler for iocbs issued using
  6776. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6777. * ring event handler function without any lock held. This function
  6778. * can be called from both worker thread context and interrupt
  6779. * context. This function also can be called from other thread which
  6780. * cleans up the SLI layer objects.
  6781. * This function copy the contents of the response iocb to the
  6782. * response iocb memory object provided by the caller of
  6783. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6784. * sleeps for the iocb completion.
  6785. **/
  6786. static void
  6787. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6788. struct lpfc_iocbq *cmdiocbq,
  6789. struct lpfc_iocbq *rspiocbq)
  6790. {
  6791. wait_queue_head_t *pdone_q;
  6792. unsigned long iflags;
  6793. struct lpfc_scsi_buf *lpfc_cmd;
  6794. spin_lock_irqsave(&phba->hbalock, iflags);
  6795. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6796. if (cmdiocbq->context2 && rspiocbq)
  6797. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6798. &rspiocbq->iocb, sizeof(IOCB_t));
  6799. /* Set the exchange busy flag for task management commands */
  6800. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6801. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6802. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6803. cur_iocbq);
  6804. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6805. }
  6806. pdone_q = cmdiocbq->context_un.wait_queue;
  6807. if (pdone_q)
  6808. wake_up(pdone_q);
  6809. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6810. return;
  6811. }
  6812. /**
  6813. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6814. * @phba: Pointer to HBA context object..
  6815. * @piocbq: Pointer to command iocb.
  6816. * @flag: Flag to test.
  6817. *
  6818. * This routine grabs the hbalock and then test the iocb_flag to
  6819. * see if the passed in flag is set.
  6820. * Returns:
  6821. * 1 if flag is set.
  6822. * 0 if flag is not set.
  6823. **/
  6824. static int
  6825. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6826. struct lpfc_iocbq *piocbq, uint32_t flag)
  6827. {
  6828. unsigned long iflags;
  6829. int ret;
  6830. spin_lock_irqsave(&phba->hbalock, iflags);
  6831. ret = piocbq->iocb_flag & flag;
  6832. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6833. return ret;
  6834. }
  6835. /**
  6836. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6837. * @phba: Pointer to HBA context object..
  6838. * @pring: Pointer to sli ring.
  6839. * @piocb: Pointer to command iocb.
  6840. * @prspiocbq: Pointer to response iocb.
  6841. * @timeout: Timeout in number of seconds.
  6842. *
  6843. * This function issues the iocb to firmware and waits for the
  6844. * iocb to complete. If the iocb command is not
  6845. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6846. * Caller should not free the iocb resources if this function
  6847. * returns IOCB_TIMEDOUT.
  6848. * The function waits for the iocb completion using an
  6849. * non-interruptible wait.
  6850. * This function will sleep while waiting for iocb completion.
  6851. * So, this function should not be called from any context which
  6852. * does not allow sleeping. Due to the same reason, this function
  6853. * cannot be called with interrupt disabled.
  6854. * This function assumes that the iocb completions occur while
  6855. * this function sleep. So, this function cannot be called from
  6856. * the thread which process iocb completion for this ring.
  6857. * This function clears the iocb_flag of the iocb object before
  6858. * issuing the iocb and the iocb completion handler sets this
  6859. * flag and wakes this thread when the iocb completes.
  6860. * The contents of the response iocb will be copied to prspiocbq
  6861. * by the completion handler when the command completes.
  6862. * This function returns IOCB_SUCCESS when success.
  6863. * This function is called with no lock held.
  6864. **/
  6865. int
  6866. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6867. uint32_t ring_number,
  6868. struct lpfc_iocbq *piocb,
  6869. struct lpfc_iocbq *prspiocbq,
  6870. uint32_t timeout)
  6871. {
  6872. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6873. long timeleft, timeout_req = 0;
  6874. int retval = IOCB_SUCCESS;
  6875. uint32_t creg_val;
  6876. /*
  6877. * If the caller has provided a response iocbq buffer, then context2
  6878. * is NULL or its an error.
  6879. */
  6880. if (prspiocbq) {
  6881. if (piocb->context2)
  6882. return IOCB_ERROR;
  6883. piocb->context2 = prspiocbq;
  6884. }
  6885. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6886. piocb->context_un.wait_queue = &done_q;
  6887. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6888. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6889. creg_val = readl(phba->HCregaddr);
  6890. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6891. writel(creg_val, phba->HCregaddr);
  6892. readl(phba->HCregaddr); /* flush */
  6893. }
  6894. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6895. if (retval == IOCB_SUCCESS) {
  6896. timeout_req = timeout * HZ;
  6897. timeleft = wait_event_timeout(done_q,
  6898. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6899. timeout_req);
  6900. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6901. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6902. "0331 IOCB wake signaled\n");
  6903. } else if (timeleft == 0) {
  6904. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6905. "0338 IOCB wait timeout error - no "
  6906. "wake response Data x%x\n", timeout);
  6907. retval = IOCB_TIMEDOUT;
  6908. } else {
  6909. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6910. "0330 IOCB wake NOT set, "
  6911. "Data x%x x%lx\n",
  6912. timeout, (timeleft / jiffies));
  6913. retval = IOCB_TIMEDOUT;
  6914. }
  6915. } else {
  6916. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6917. "0332 IOCB wait issue failed, Data x%x\n",
  6918. retval);
  6919. retval = IOCB_ERROR;
  6920. }
  6921. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6922. creg_val = readl(phba->HCregaddr);
  6923. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6924. writel(creg_val, phba->HCregaddr);
  6925. readl(phba->HCregaddr); /* flush */
  6926. }
  6927. if (prspiocbq)
  6928. piocb->context2 = NULL;
  6929. piocb->context_un.wait_queue = NULL;
  6930. piocb->iocb_cmpl = NULL;
  6931. return retval;
  6932. }
  6933. /**
  6934. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6935. * @phba: Pointer to HBA context object.
  6936. * @pmboxq: Pointer to driver mailbox object.
  6937. * @timeout: Timeout in number of seconds.
  6938. *
  6939. * This function issues the mailbox to firmware and waits for the
  6940. * mailbox command to complete. If the mailbox command is not
  6941. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6942. * The function waits for the mailbox completion using an
  6943. * interruptible wait. If the thread is woken up due to a
  6944. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6945. * should not free the mailbox resources, if this function returns
  6946. * MBX_TIMEOUT.
  6947. * This function will sleep while waiting for mailbox completion.
  6948. * So, this function should not be called from any context which
  6949. * does not allow sleeping. Due to the same reason, this function
  6950. * cannot be called with interrupt disabled.
  6951. * This function assumes that the mailbox completion occurs while
  6952. * this function sleep. So, this function cannot be called from
  6953. * the worker thread which processes mailbox completion.
  6954. * This function is called in the context of HBA management
  6955. * applications.
  6956. * This function returns MBX_SUCCESS when successful.
  6957. * This function is called with no lock held.
  6958. **/
  6959. int
  6960. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6961. uint32_t timeout)
  6962. {
  6963. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6964. int retval;
  6965. unsigned long flag;
  6966. /* The caller must leave context1 empty. */
  6967. if (pmboxq->context1)
  6968. return MBX_NOT_FINISHED;
  6969. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6970. /* setup wake call as IOCB callback */
  6971. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6972. /* setup context field to pass wait_queue pointer to wake function */
  6973. pmboxq->context1 = &done_q;
  6974. /* now issue the command */
  6975. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6976. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6977. wait_event_interruptible_timeout(done_q,
  6978. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6979. timeout * HZ);
  6980. spin_lock_irqsave(&phba->hbalock, flag);
  6981. pmboxq->context1 = NULL;
  6982. /*
  6983. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6984. * else do not free the resources.
  6985. */
  6986. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6987. retval = MBX_SUCCESS;
  6988. else {
  6989. retval = MBX_TIMEOUT;
  6990. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6991. }
  6992. spin_unlock_irqrestore(&phba->hbalock, flag);
  6993. }
  6994. return retval;
  6995. }
  6996. /**
  6997. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6998. * @phba: Pointer to HBA context.
  6999. *
  7000. * This function is called to shutdown the driver's mailbox sub-system.
  7001. * It first marks the mailbox sub-system is in a block state to prevent
  7002. * the asynchronous mailbox command from issued off the pending mailbox
  7003. * command queue. If the mailbox command sub-system shutdown is due to
  7004. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7005. * the mailbox sub-system flush routine to forcefully bring down the
  7006. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7007. * as with offline or HBA function reset), this routine will wait for the
  7008. * outstanding mailbox command to complete before invoking the mailbox
  7009. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7010. **/
  7011. void
  7012. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7013. {
  7014. struct lpfc_sli *psli = &phba->sli;
  7015. uint8_t actcmd = MBX_HEARTBEAT;
  7016. unsigned long timeout;
  7017. spin_lock_irq(&phba->hbalock);
  7018. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7019. spin_unlock_irq(&phba->hbalock);
  7020. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7021. spin_lock_irq(&phba->hbalock);
  7022. if (phba->sli.mbox_active)
  7023. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7024. spin_unlock_irq(&phba->hbalock);
  7025. /* Determine how long we might wait for the active mailbox
  7026. * command to be gracefully completed by firmware.
  7027. */
  7028. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7029. 1000) + jiffies;
  7030. while (phba->sli.mbox_active) {
  7031. /* Check active mailbox complete status every 2ms */
  7032. msleep(2);
  7033. if (time_after(jiffies, timeout))
  7034. /* Timeout, let the mailbox flush routine to
  7035. * forcefully release active mailbox command
  7036. */
  7037. break;
  7038. }
  7039. }
  7040. lpfc_sli_mbox_sys_flush(phba);
  7041. }
  7042. /**
  7043. * lpfc_sli_eratt_read - read sli-3 error attention events
  7044. * @phba: Pointer to HBA context.
  7045. *
  7046. * This function is called to read the SLI3 device error attention registers
  7047. * for possible error attention events. The caller must hold the hostlock
  7048. * with spin_lock_irq().
  7049. *
  7050. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7051. * Register and returns 0 otherwise.
  7052. **/
  7053. static int
  7054. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7055. {
  7056. uint32_t ha_copy;
  7057. /* Read chip Host Attention (HA) register */
  7058. ha_copy = readl(phba->HAregaddr);
  7059. if (ha_copy & HA_ERATT) {
  7060. /* Read host status register to retrieve error event */
  7061. lpfc_sli_read_hs(phba);
  7062. /* Check if there is a deferred error condition is active */
  7063. if ((HS_FFER1 & phba->work_hs) &&
  7064. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7065. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7066. phba->hba_flag |= DEFER_ERATT;
  7067. /* Clear all interrupt enable conditions */
  7068. writel(0, phba->HCregaddr);
  7069. readl(phba->HCregaddr);
  7070. }
  7071. /* Set the driver HA work bitmap */
  7072. phba->work_ha |= HA_ERATT;
  7073. /* Indicate polling handles this ERATT */
  7074. phba->hba_flag |= HBA_ERATT_HANDLED;
  7075. return 1;
  7076. }
  7077. return 0;
  7078. }
  7079. /**
  7080. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7081. * @phba: Pointer to HBA context.
  7082. *
  7083. * This function is called to read the SLI4 device error attention registers
  7084. * for possible error attention events. The caller must hold the hostlock
  7085. * with spin_lock_irq().
  7086. *
  7087. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7088. * Register and returns 0 otherwise.
  7089. **/
  7090. static int
  7091. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7092. {
  7093. uint32_t uerr_sta_hi, uerr_sta_lo;
  7094. /* For now, use the SLI4 device internal unrecoverable error
  7095. * registers for error attention. This can be changed later.
  7096. */
  7097. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7098. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7099. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7100. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7101. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7102. "1423 HBA Unrecoverable error: "
  7103. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7104. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7105. uerr_sta_lo, uerr_sta_hi,
  7106. phba->sli4_hba.ue_mask_lo,
  7107. phba->sli4_hba.ue_mask_hi);
  7108. phba->work_status[0] = uerr_sta_lo;
  7109. phba->work_status[1] = uerr_sta_hi;
  7110. /* Set the driver HA work bitmap */
  7111. phba->work_ha |= HA_ERATT;
  7112. /* Indicate polling handles this ERATT */
  7113. phba->hba_flag |= HBA_ERATT_HANDLED;
  7114. return 1;
  7115. }
  7116. return 0;
  7117. }
  7118. /**
  7119. * lpfc_sli_check_eratt - check error attention events
  7120. * @phba: Pointer to HBA context.
  7121. *
  7122. * This function is called from timer soft interrupt context to check HBA's
  7123. * error attention register bit for error attention events.
  7124. *
  7125. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7126. * Register and returns 0 otherwise.
  7127. **/
  7128. int
  7129. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7130. {
  7131. uint32_t ha_copy;
  7132. /* If somebody is waiting to handle an eratt, don't process it
  7133. * here. The brdkill function will do this.
  7134. */
  7135. if (phba->link_flag & LS_IGNORE_ERATT)
  7136. return 0;
  7137. /* Check if interrupt handler handles this ERATT */
  7138. spin_lock_irq(&phba->hbalock);
  7139. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7140. /* Interrupt handler has handled ERATT */
  7141. spin_unlock_irq(&phba->hbalock);
  7142. return 0;
  7143. }
  7144. /*
  7145. * If there is deferred error attention, do not check for error
  7146. * attention
  7147. */
  7148. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7149. spin_unlock_irq(&phba->hbalock);
  7150. return 0;
  7151. }
  7152. /* If PCI channel is offline, don't process it */
  7153. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7154. spin_unlock_irq(&phba->hbalock);
  7155. return 0;
  7156. }
  7157. switch (phba->sli_rev) {
  7158. case LPFC_SLI_REV2:
  7159. case LPFC_SLI_REV3:
  7160. /* Read chip Host Attention (HA) register */
  7161. ha_copy = lpfc_sli_eratt_read(phba);
  7162. break;
  7163. case LPFC_SLI_REV4:
  7164. /* Read devcie Uncoverable Error (UERR) registers */
  7165. ha_copy = lpfc_sli4_eratt_read(phba);
  7166. break;
  7167. default:
  7168. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7169. "0299 Invalid SLI revision (%d)\n",
  7170. phba->sli_rev);
  7171. ha_copy = 0;
  7172. break;
  7173. }
  7174. spin_unlock_irq(&phba->hbalock);
  7175. return ha_copy;
  7176. }
  7177. /**
  7178. * lpfc_intr_state_check - Check device state for interrupt handling
  7179. * @phba: Pointer to HBA context.
  7180. *
  7181. * This inline routine checks whether a device or its PCI slot is in a state
  7182. * that the interrupt should be handled.
  7183. *
  7184. * This function returns 0 if the device or the PCI slot is in a state that
  7185. * interrupt should be handled, otherwise -EIO.
  7186. */
  7187. static inline int
  7188. lpfc_intr_state_check(struct lpfc_hba *phba)
  7189. {
  7190. /* If the pci channel is offline, ignore all the interrupts */
  7191. if (unlikely(pci_channel_offline(phba->pcidev)))
  7192. return -EIO;
  7193. /* Update device level interrupt statistics */
  7194. phba->sli.slistat.sli_intr++;
  7195. /* Ignore all interrupts during initialization. */
  7196. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7197. return -EIO;
  7198. return 0;
  7199. }
  7200. /**
  7201. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7202. * @irq: Interrupt number.
  7203. * @dev_id: The device context pointer.
  7204. *
  7205. * This function is directly called from the PCI layer as an interrupt
  7206. * service routine when device with SLI-3 interface spec is enabled with
  7207. * MSI-X multi-message interrupt mode and there are slow-path events in
  7208. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7209. * interrupt mode, this function is called as part of the device-level
  7210. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7211. * is undergoing initialization, the interrupt handler will not process
  7212. * the interrupt. The link attention and ELS ring attention events are
  7213. * handled by the worker thread. The interrupt handler signals the worker
  7214. * thread and returns for these events. This function is called without
  7215. * any lock held. It gets the hbalock to access and update SLI data
  7216. * structures.
  7217. *
  7218. * This function returns IRQ_HANDLED when interrupt is handled else it
  7219. * returns IRQ_NONE.
  7220. **/
  7221. irqreturn_t
  7222. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7223. {
  7224. struct lpfc_hba *phba;
  7225. uint32_t ha_copy, hc_copy;
  7226. uint32_t work_ha_copy;
  7227. unsigned long status;
  7228. unsigned long iflag;
  7229. uint32_t control;
  7230. MAILBOX_t *mbox, *pmbox;
  7231. struct lpfc_vport *vport;
  7232. struct lpfc_nodelist *ndlp;
  7233. struct lpfc_dmabuf *mp;
  7234. LPFC_MBOXQ_t *pmb;
  7235. int rc;
  7236. /*
  7237. * Get the driver's phba structure from the dev_id and
  7238. * assume the HBA is not interrupting.
  7239. */
  7240. phba = (struct lpfc_hba *)dev_id;
  7241. if (unlikely(!phba))
  7242. return IRQ_NONE;
  7243. /*
  7244. * Stuff needs to be attented to when this function is invoked as an
  7245. * individual interrupt handler in MSI-X multi-message interrupt mode
  7246. */
  7247. if (phba->intr_type == MSIX) {
  7248. /* Check device state for handling interrupt */
  7249. if (lpfc_intr_state_check(phba))
  7250. return IRQ_NONE;
  7251. /* Need to read HA REG for slow-path events */
  7252. spin_lock_irqsave(&phba->hbalock, iflag);
  7253. ha_copy = readl(phba->HAregaddr);
  7254. /* If somebody is waiting to handle an eratt don't process it
  7255. * here. The brdkill function will do this.
  7256. */
  7257. if (phba->link_flag & LS_IGNORE_ERATT)
  7258. ha_copy &= ~HA_ERATT;
  7259. /* Check the need for handling ERATT in interrupt handler */
  7260. if (ha_copy & HA_ERATT) {
  7261. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7262. /* ERATT polling has handled ERATT */
  7263. ha_copy &= ~HA_ERATT;
  7264. else
  7265. /* Indicate interrupt handler handles ERATT */
  7266. phba->hba_flag |= HBA_ERATT_HANDLED;
  7267. }
  7268. /*
  7269. * If there is deferred error attention, do not check for any
  7270. * interrupt.
  7271. */
  7272. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7273. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7274. return IRQ_NONE;
  7275. }
  7276. /* Clear up only attention source related to slow-path */
  7277. hc_copy = readl(phba->HCregaddr);
  7278. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7279. HC_LAINT_ENA | HC_ERINT_ENA),
  7280. phba->HCregaddr);
  7281. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7282. phba->HAregaddr);
  7283. writel(hc_copy, phba->HCregaddr);
  7284. readl(phba->HAregaddr); /* flush */
  7285. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7286. } else
  7287. ha_copy = phba->ha_copy;
  7288. work_ha_copy = ha_copy & phba->work_ha_mask;
  7289. if (work_ha_copy) {
  7290. if (work_ha_copy & HA_LATT) {
  7291. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7292. /*
  7293. * Turn off Link Attention interrupts
  7294. * until CLEAR_LA done
  7295. */
  7296. spin_lock_irqsave(&phba->hbalock, iflag);
  7297. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7298. control = readl(phba->HCregaddr);
  7299. control &= ~HC_LAINT_ENA;
  7300. writel(control, phba->HCregaddr);
  7301. readl(phba->HCregaddr); /* flush */
  7302. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7303. }
  7304. else
  7305. work_ha_copy &= ~HA_LATT;
  7306. }
  7307. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7308. /*
  7309. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7310. * the only slow ring.
  7311. */
  7312. status = (work_ha_copy &
  7313. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7314. status >>= (4*LPFC_ELS_RING);
  7315. if (status & HA_RXMASK) {
  7316. spin_lock_irqsave(&phba->hbalock, iflag);
  7317. control = readl(phba->HCregaddr);
  7318. lpfc_debugfs_slow_ring_trc(phba,
  7319. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7320. control, status,
  7321. (uint32_t)phba->sli.slistat.sli_intr);
  7322. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7323. lpfc_debugfs_slow_ring_trc(phba,
  7324. "ISR Disable ring:"
  7325. "pwork:x%x hawork:x%x wait:x%x",
  7326. phba->work_ha, work_ha_copy,
  7327. (uint32_t)((unsigned long)
  7328. &phba->work_waitq));
  7329. control &=
  7330. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7331. writel(control, phba->HCregaddr);
  7332. readl(phba->HCregaddr); /* flush */
  7333. }
  7334. else {
  7335. lpfc_debugfs_slow_ring_trc(phba,
  7336. "ISR slow ring: pwork:"
  7337. "x%x hawork:x%x wait:x%x",
  7338. phba->work_ha, work_ha_copy,
  7339. (uint32_t)((unsigned long)
  7340. &phba->work_waitq));
  7341. }
  7342. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7343. }
  7344. }
  7345. spin_lock_irqsave(&phba->hbalock, iflag);
  7346. if (work_ha_copy & HA_ERATT) {
  7347. lpfc_sli_read_hs(phba);
  7348. /*
  7349. * Check if there is a deferred error condition
  7350. * is active
  7351. */
  7352. if ((HS_FFER1 & phba->work_hs) &&
  7353. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7354. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7355. phba->hba_flag |= DEFER_ERATT;
  7356. /* Clear all interrupt enable conditions */
  7357. writel(0, phba->HCregaddr);
  7358. readl(phba->HCregaddr);
  7359. }
  7360. }
  7361. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7362. pmb = phba->sli.mbox_active;
  7363. pmbox = &pmb->u.mb;
  7364. mbox = phba->mbox;
  7365. vport = pmb->vport;
  7366. /* First check out the status word */
  7367. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7368. if (pmbox->mbxOwner != OWN_HOST) {
  7369. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7370. /*
  7371. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7372. * mbxStatus <status>
  7373. */
  7374. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7375. LOG_SLI,
  7376. "(%d):0304 Stray Mailbox "
  7377. "Interrupt mbxCommand x%x "
  7378. "mbxStatus x%x\n",
  7379. (vport ? vport->vpi : 0),
  7380. pmbox->mbxCommand,
  7381. pmbox->mbxStatus);
  7382. /* clear mailbox attention bit */
  7383. work_ha_copy &= ~HA_MBATT;
  7384. } else {
  7385. phba->sli.mbox_active = NULL;
  7386. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7387. phba->last_completion_time = jiffies;
  7388. del_timer(&phba->sli.mbox_tmo);
  7389. if (pmb->mbox_cmpl) {
  7390. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7391. MAILBOX_CMD_SIZE);
  7392. if (pmb->out_ext_byte_len &&
  7393. pmb->context2)
  7394. lpfc_sli_pcimem_bcopy(
  7395. phba->mbox_ext,
  7396. pmb->context2,
  7397. pmb->out_ext_byte_len);
  7398. }
  7399. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7400. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7401. lpfc_debugfs_disc_trc(vport,
  7402. LPFC_DISC_TRC_MBOX_VPORT,
  7403. "MBOX dflt rpi: : "
  7404. "status:x%x rpi:x%x",
  7405. (uint32_t)pmbox->mbxStatus,
  7406. pmbox->un.varWords[0], 0);
  7407. if (!pmbox->mbxStatus) {
  7408. mp = (struct lpfc_dmabuf *)
  7409. (pmb->context1);
  7410. ndlp = (struct lpfc_nodelist *)
  7411. pmb->context2;
  7412. /* Reg_LOGIN of dflt RPI was
  7413. * successful. new lets get
  7414. * rid of the RPI using the
  7415. * same mbox buffer.
  7416. */
  7417. lpfc_unreg_login(phba,
  7418. vport->vpi,
  7419. pmbox->un.varWords[0],
  7420. pmb);
  7421. pmb->mbox_cmpl =
  7422. lpfc_mbx_cmpl_dflt_rpi;
  7423. pmb->context1 = mp;
  7424. pmb->context2 = ndlp;
  7425. pmb->vport = vport;
  7426. rc = lpfc_sli_issue_mbox(phba,
  7427. pmb,
  7428. MBX_NOWAIT);
  7429. if (rc != MBX_BUSY)
  7430. lpfc_printf_log(phba,
  7431. KERN_ERR,
  7432. LOG_MBOX | LOG_SLI,
  7433. "0350 rc should have"
  7434. "been MBX_BUSY\n");
  7435. if (rc != MBX_NOT_FINISHED)
  7436. goto send_current_mbox;
  7437. }
  7438. }
  7439. spin_lock_irqsave(
  7440. &phba->pport->work_port_lock,
  7441. iflag);
  7442. phba->pport->work_port_events &=
  7443. ~WORKER_MBOX_TMO;
  7444. spin_unlock_irqrestore(
  7445. &phba->pport->work_port_lock,
  7446. iflag);
  7447. lpfc_mbox_cmpl_put(phba, pmb);
  7448. }
  7449. } else
  7450. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7451. if ((work_ha_copy & HA_MBATT) &&
  7452. (phba->sli.mbox_active == NULL)) {
  7453. send_current_mbox:
  7454. /* Process next mailbox command if there is one */
  7455. do {
  7456. rc = lpfc_sli_issue_mbox(phba, NULL,
  7457. MBX_NOWAIT);
  7458. } while (rc == MBX_NOT_FINISHED);
  7459. if (rc != MBX_SUCCESS)
  7460. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7461. LOG_SLI, "0349 rc should be "
  7462. "MBX_SUCCESS\n");
  7463. }
  7464. spin_lock_irqsave(&phba->hbalock, iflag);
  7465. phba->work_ha |= work_ha_copy;
  7466. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7467. lpfc_worker_wake_up(phba);
  7468. }
  7469. return IRQ_HANDLED;
  7470. } /* lpfc_sli_sp_intr_handler */
  7471. /**
  7472. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7473. * @irq: Interrupt number.
  7474. * @dev_id: The device context pointer.
  7475. *
  7476. * This function is directly called from the PCI layer as an interrupt
  7477. * service routine when device with SLI-3 interface spec is enabled with
  7478. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7479. * ring event in the HBA. However, when the device is enabled with either
  7480. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7481. * device-level interrupt handler. When the PCI slot is in error recovery
  7482. * or the HBA is undergoing initialization, the interrupt handler will not
  7483. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7484. * the intrrupt context. This function is called without any lock held.
  7485. * It gets the hbalock to access and update SLI data structures.
  7486. *
  7487. * This function returns IRQ_HANDLED when interrupt is handled else it
  7488. * returns IRQ_NONE.
  7489. **/
  7490. irqreturn_t
  7491. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7492. {
  7493. struct lpfc_hba *phba;
  7494. uint32_t ha_copy;
  7495. unsigned long status;
  7496. unsigned long iflag;
  7497. /* Get the driver's phba structure from the dev_id and
  7498. * assume the HBA is not interrupting.
  7499. */
  7500. phba = (struct lpfc_hba *) dev_id;
  7501. if (unlikely(!phba))
  7502. return IRQ_NONE;
  7503. /*
  7504. * Stuff needs to be attented to when this function is invoked as an
  7505. * individual interrupt handler in MSI-X multi-message interrupt mode
  7506. */
  7507. if (phba->intr_type == MSIX) {
  7508. /* Check device state for handling interrupt */
  7509. if (lpfc_intr_state_check(phba))
  7510. return IRQ_NONE;
  7511. /* Need to read HA REG for FCP ring and other ring events */
  7512. ha_copy = readl(phba->HAregaddr);
  7513. /* Clear up only attention source related to fast-path */
  7514. spin_lock_irqsave(&phba->hbalock, iflag);
  7515. /*
  7516. * If there is deferred error attention, do not check for
  7517. * any interrupt.
  7518. */
  7519. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7520. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7521. return IRQ_NONE;
  7522. }
  7523. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7524. phba->HAregaddr);
  7525. readl(phba->HAregaddr); /* flush */
  7526. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7527. } else
  7528. ha_copy = phba->ha_copy;
  7529. /*
  7530. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7531. */
  7532. ha_copy &= ~(phba->work_ha_mask);
  7533. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7534. status >>= (4*LPFC_FCP_RING);
  7535. if (status & HA_RXMASK)
  7536. lpfc_sli_handle_fast_ring_event(phba,
  7537. &phba->sli.ring[LPFC_FCP_RING],
  7538. status);
  7539. if (phba->cfg_multi_ring_support == 2) {
  7540. /*
  7541. * Process all events on extra ring. Take the optimized path
  7542. * for extra ring IO.
  7543. */
  7544. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7545. status >>= (4*LPFC_EXTRA_RING);
  7546. if (status & HA_RXMASK) {
  7547. lpfc_sli_handle_fast_ring_event(phba,
  7548. &phba->sli.ring[LPFC_EXTRA_RING],
  7549. status);
  7550. }
  7551. }
  7552. return IRQ_HANDLED;
  7553. } /* lpfc_sli_fp_intr_handler */
  7554. /**
  7555. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7556. * @irq: Interrupt number.
  7557. * @dev_id: The device context pointer.
  7558. *
  7559. * This function is the HBA device-level interrupt handler to device with
  7560. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7561. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7562. * requires driver attention. This function invokes the slow-path interrupt
  7563. * attention handling function and fast-path interrupt attention handling
  7564. * function in turn to process the relevant HBA attention events. This
  7565. * function is called without any lock held. It gets the hbalock to access
  7566. * and update SLI data structures.
  7567. *
  7568. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7569. * returns IRQ_NONE.
  7570. **/
  7571. irqreturn_t
  7572. lpfc_sli_intr_handler(int irq, void *dev_id)
  7573. {
  7574. struct lpfc_hba *phba;
  7575. irqreturn_t sp_irq_rc, fp_irq_rc;
  7576. unsigned long status1, status2;
  7577. uint32_t hc_copy;
  7578. /*
  7579. * Get the driver's phba structure from the dev_id and
  7580. * assume the HBA is not interrupting.
  7581. */
  7582. phba = (struct lpfc_hba *) dev_id;
  7583. if (unlikely(!phba))
  7584. return IRQ_NONE;
  7585. /* Check device state for handling interrupt */
  7586. if (lpfc_intr_state_check(phba))
  7587. return IRQ_NONE;
  7588. spin_lock(&phba->hbalock);
  7589. phba->ha_copy = readl(phba->HAregaddr);
  7590. if (unlikely(!phba->ha_copy)) {
  7591. spin_unlock(&phba->hbalock);
  7592. return IRQ_NONE;
  7593. } else if (phba->ha_copy & HA_ERATT) {
  7594. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7595. /* ERATT polling has handled ERATT */
  7596. phba->ha_copy &= ~HA_ERATT;
  7597. else
  7598. /* Indicate interrupt handler handles ERATT */
  7599. phba->hba_flag |= HBA_ERATT_HANDLED;
  7600. }
  7601. /*
  7602. * If there is deferred error attention, do not check for any interrupt.
  7603. */
  7604. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7605. spin_unlock_irq(&phba->hbalock);
  7606. return IRQ_NONE;
  7607. }
  7608. /* Clear attention sources except link and error attentions */
  7609. hc_copy = readl(phba->HCregaddr);
  7610. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7611. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7612. phba->HCregaddr);
  7613. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7614. writel(hc_copy, phba->HCregaddr);
  7615. readl(phba->HAregaddr); /* flush */
  7616. spin_unlock(&phba->hbalock);
  7617. /*
  7618. * Invokes slow-path host attention interrupt handling as appropriate.
  7619. */
  7620. /* status of events with mailbox and link attention */
  7621. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7622. /* status of events with ELS ring */
  7623. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7624. status2 >>= (4*LPFC_ELS_RING);
  7625. if (status1 || (status2 & HA_RXMASK))
  7626. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7627. else
  7628. sp_irq_rc = IRQ_NONE;
  7629. /*
  7630. * Invoke fast-path host attention interrupt handling as appropriate.
  7631. */
  7632. /* status of events with FCP ring */
  7633. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7634. status1 >>= (4*LPFC_FCP_RING);
  7635. /* status of events with extra ring */
  7636. if (phba->cfg_multi_ring_support == 2) {
  7637. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7638. status2 >>= (4*LPFC_EXTRA_RING);
  7639. } else
  7640. status2 = 0;
  7641. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7642. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7643. else
  7644. fp_irq_rc = IRQ_NONE;
  7645. /* Return device-level interrupt handling status */
  7646. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7647. } /* lpfc_sli_intr_handler */
  7648. /**
  7649. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7650. * @phba: pointer to lpfc hba data structure.
  7651. *
  7652. * This routine is invoked by the worker thread to process all the pending
  7653. * SLI4 FCP abort XRI events.
  7654. **/
  7655. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7656. {
  7657. struct lpfc_cq_event *cq_event;
  7658. /* First, declare the fcp xri abort event has been handled */
  7659. spin_lock_irq(&phba->hbalock);
  7660. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7661. spin_unlock_irq(&phba->hbalock);
  7662. /* Now, handle all the fcp xri abort events */
  7663. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7664. /* Get the first event from the head of the event queue */
  7665. spin_lock_irq(&phba->hbalock);
  7666. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7667. cq_event, struct lpfc_cq_event, list);
  7668. spin_unlock_irq(&phba->hbalock);
  7669. /* Notify aborted XRI for FCP work queue */
  7670. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7671. /* Free the event processed back to the free pool */
  7672. lpfc_sli4_cq_event_release(phba, cq_event);
  7673. }
  7674. }
  7675. /**
  7676. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7677. * @phba: pointer to lpfc hba data structure.
  7678. *
  7679. * This routine is invoked by the worker thread to process all the pending
  7680. * SLI4 els abort xri events.
  7681. **/
  7682. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7683. {
  7684. struct lpfc_cq_event *cq_event;
  7685. /* First, declare the els xri abort event has been handled */
  7686. spin_lock_irq(&phba->hbalock);
  7687. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7688. spin_unlock_irq(&phba->hbalock);
  7689. /* Now, handle all the els xri abort events */
  7690. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7691. /* Get the first event from the head of the event queue */
  7692. spin_lock_irq(&phba->hbalock);
  7693. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7694. cq_event, struct lpfc_cq_event, list);
  7695. spin_unlock_irq(&phba->hbalock);
  7696. /* Notify aborted XRI for ELS work queue */
  7697. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7698. /* Free the event processed back to the free pool */
  7699. lpfc_sli4_cq_event_release(phba, cq_event);
  7700. }
  7701. }
  7702. /**
  7703. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7704. * @phba: pointer to lpfc hba data structure
  7705. * @pIocbIn: pointer to the rspiocbq
  7706. * @pIocbOut: pointer to the cmdiocbq
  7707. * @wcqe: pointer to the complete wcqe
  7708. *
  7709. * This routine transfers the fields of a command iocbq to a response iocbq
  7710. * by copying all the IOCB fields from command iocbq and transferring the
  7711. * completion status information from the complete wcqe.
  7712. **/
  7713. static void
  7714. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7715. struct lpfc_iocbq *pIocbIn,
  7716. struct lpfc_iocbq *pIocbOut,
  7717. struct lpfc_wcqe_complete *wcqe)
  7718. {
  7719. unsigned long iflags;
  7720. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7721. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7722. sizeof(struct lpfc_iocbq) - offset);
  7723. /* Map WCQE parameters into irspiocb parameters */
  7724. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7725. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7726. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7727. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7728. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7729. wcqe->total_data_placed;
  7730. else
  7731. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7732. else {
  7733. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7734. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7735. }
  7736. /* Pick up HBA exchange busy condition */
  7737. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7738. spin_lock_irqsave(&phba->hbalock, iflags);
  7739. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7740. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7741. }
  7742. }
  7743. /**
  7744. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7745. * @phba: Pointer to HBA context object.
  7746. * @wcqe: Pointer to work-queue completion queue entry.
  7747. *
  7748. * This routine handles an ELS work-queue completion event and construct
  7749. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7750. * discovery engine to handle.
  7751. *
  7752. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7753. **/
  7754. static struct lpfc_iocbq *
  7755. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7756. struct lpfc_iocbq *irspiocbq)
  7757. {
  7758. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7759. struct lpfc_iocbq *cmdiocbq;
  7760. struct lpfc_wcqe_complete *wcqe;
  7761. unsigned long iflags;
  7762. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7763. spin_lock_irqsave(&phba->hbalock, iflags);
  7764. pring->stats.iocb_event++;
  7765. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7766. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7767. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7768. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7769. if (unlikely(!cmdiocbq)) {
  7770. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7771. "0386 ELS complete with no corresponding "
  7772. "cmdiocb: iotag (%d)\n",
  7773. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7774. lpfc_sli_release_iocbq(phba, irspiocbq);
  7775. return NULL;
  7776. }
  7777. /* Fake the irspiocbq and copy necessary response information */
  7778. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7779. return irspiocbq;
  7780. }
  7781. /**
  7782. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7783. * @phba: Pointer to HBA context object.
  7784. * @cqe: Pointer to mailbox completion queue entry.
  7785. *
  7786. * This routine process a mailbox completion queue entry with asynchrous
  7787. * event.
  7788. *
  7789. * Return: true if work posted to worker thread, otherwise false.
  7790. **/
  7791. static bool
  7792. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7793. {
  7794. struct lpfc_cq_event *cq_event;
  7795. unsigned long iflags;
  7796. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7797. "0392 Async Event: word0:x%x, word1:x%x, "
  7798. "word2:x%x, word3:x%x\n", mcqe->word0,
  7799. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7800. /* Allocate a new internal CQ_EVENT entry */
  7801. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7802. if (!cq_event) {
  7803. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7804. "0394 Failed to allocate CQ_EVENT entry\n");
  7805. return false;
  7806. }
  7807. /* Move the CQE into an asynchronous event entry */
  7808. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7809. spin_lock_irqsave(&phba->hbalock, iflags);
  7810. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7811. /* Set the async event flag */
  7812. phba->hba_flag |= ASYNC_EVENT;
  7813. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7814. return true;
  7815. }
  7816. /**
  7817. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7818. * @phba: Pointer to HBA context object.
  7819. * @cqe: Pointer to mailbox completion queue entry.
  7820. *
  7821. * This routine process a mailbox completion queue entry with mailbox
  7822. * completion event.
  7823. *
  7824. * Return: true if work posted to worker thread, otherwise false.
  7825. **/
  7826. static bool
  7827. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7828. {
  7829. uint32_t mcqe_status;
  7830. MAILBOX_t *mbox, *pmbox;
  7831. struct lpfc_mqe *mqe;
  7832. struct lpfc_vport *vport;
  7833. struct lpfc_nodelist *ndlp;
  7834. struct lpfc_dmabuf *mp;
  7835. unsigned long iflags;
  7836. LPFC_MBOXQ_t *pmb;
  7837. bool workposted = false;
  7838. int rc;
  7839. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7840. if (!bf_get(lpfc_trailer_completed, mcqe))
  7841. goto out_no_mqe_complete;
  7842. /* Get the reference to the active mbox command */
  7843. spin_lock_irqsave(&phba->hbalock, iflags);
  7844. pmb = phba->sli.mbox_active;
  7845. if (unlikely(!pmb)) {
  7846. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7847. "1832 No pending MBOX command to handle\n");
  7848. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7849. goto out_no_mqe_complete;
  7850. }
  7851. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7852. mqe = &pmb->u.mqe;
  7853. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7854. mbox = phba->mbox;
  7855. vport = pmb->vport;
  7856. /* Reset heartbeat timer */
  7857. phba->last_completion_time = jiffies;
  7858. del_timer(&phba->sli.mbox_tmo);
  7859. /* Move mbox data to caller's mailbox region, do endian swapping */
  7860. if (pmb->mbox_cmpl && mbox)
  7861. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7862. /* Set the mailbox status with SLI4 range 0x4000 */
  7863. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7864. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7865. bf_set(lpfc_mqe_status, mqe,
  7866. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7867. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7868. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7869. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7870. "MBOX dflt rpi: status:x%x rpi:x%x",
  7871. mcqe_status,
  7872. pmbox->un.varWords[0], 0);
  7873. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7874. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7875. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7876. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7877. * RID of the PPI using the same mbox buffer.
  7878. */
  7879. lpfc_unreg_login(phba, vport->vpi,
  7880. pmbox->un.varWords[0], pmb);
  7881. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7882. pmb->context1 = mp;
  7883. pmb->context2 = ndlp;
  7884. pmb->vport = vport;
  7885. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7886. if (rc != MBX_BUSY)
  7887. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7888. LOG_SLI, "0385 rc should "
  7889. "have been MBX_BUSY\n");
  7890. if (rc != MBX_NOT_FINISHED)
  7891. goto send_current_mbox;
  7892. }
  7893. }
  7894. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7895. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7896. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7897. /* There is mailbox completion work to do */
  7898. spin_lock_irqsave(&phba->hbalock, iflags);
  7899. __lpfc_mbox_cmpl_put(phba, pmb);
  7900. phba->work_ha |= HA_MBATT;
  7901. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7902. workposted = true;
  7903. send_current_mbox:
  7904. spin_lock_irqsave(&phba->hbalock, iflags);
  7905. /* Release the mailbox command posting token */
  7906. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7907. /* Setting active mailbox pointer need to be in sync to flag clear */
  7908. phba->sli.mbox_active = NULL;
  7909. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7910. /* Wake up worker thread to post the next pending mailbox command */
  7911. lpfc_worker_wake_up(phba);
  7912. out_no_mqe_complete:
  7913. if (bf_get(lpfc_trailer_consumed, mcqe))
  7914. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7915. return workposted;
  7916. }
  7917. /**
  7918. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7919. * @phba: Pointer to HBA context object.
  7920. * @cqe: Pointer to mailbox completion queue entry.
  7921. *
  7922. * This routine process a mailbox completion queue entry, it invokes the
  7923. * proper mailbox complete handling or asynchrous event handling routine
  7924. * according to the MCQE's async bit.
  7925. *
  7926. * Return: true if work posted to worker thread, otherwise false.
  7927. **/
  7928. static bool
  7929. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7930. {
  7931. struct lpfc_mcqe mcqe;
  7932. bool workposted;
  7933. /* Copy the mailbox MCQE and convert endian order as needed */
  7934. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7935. /* Invoke the proper event handling routine */
  7936. if (!bf_get(lpfc_trailer_async, &mcqe))
  7937. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7938. else
  7939. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7940. return workposted;
  7941. }
  7942. /**
  7943. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7944. * @phba: Pointer to HBA context object.
  7945. * @wcqe: Pointer to work-queue completion queue entry.
  7946. *
  7947. * This routine handles an ELS work-queue completion event.
  7948. *
  7949. * Return: true if work posted to worker thread, otherwise false.
  7950. **/
  7951. static bool
  7952. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7953. struct lpfc_wcqe_complete *wcqe)
  7954. {
  7955. struct lpfc_iocbq *irspiocbq;
  7956. unsigned long iflags;
  7957. /* Get an irspiocbq for later ELS response processing use */
  7958. irspiocbq = lpfc_sli_get_iocbq(phba);
  7959. if (!irspiocbq) {
  7960. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7961. "0387 Failed to allocate an iocbq\n");
  7962. return false;
  7963. }
  7964. /* Save off the slow-path queue event for work thread to process */
  7965. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7966. spin_lock_irqsave(&phba->hbalock, iflags);
  7967. list_add_tail(&irspiocbq->cq_event.list,
  7968. &phba->sli4_hba.sp_queue_event);
  7969. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7970. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7971. return true;
  7972. }
  7973. /**
  7974. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7975. * @phba: Pointer to HBA context object.
  7976. * @wcqe: Pointer to work-queue completion queue entry.
  7977. *
  7978. * This routine handles slow-path WQ entry comsumed event by invoking the
  7979. * proper WQ release routine to the slow-path WQ.
  7980. **/
  7981. static void
  7982. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7983. struct lpfc_wcqe_release *wcqe)
  7984. {
  7985. /* Check for the slow-path ELS work queue */
  7986. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7987. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7988. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7989. else
  7990. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7991. "2579 Slow-path wqe consume event carries "
  7992. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7993. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7994. phba->sli4_hba.els_wq->queue_id);
  7995. }
  7996. /**
  7997. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7998. * @phba: Pointer to HBA context object.
  7999. * @cq: Pointer to a WQ completion queue.
  8000. * @wcqe: Pointer to work-queue completion queue entry.
  8001. *
  8002. * This routine handles an XRI abort event.
  8003. *
  8004. * Return: true if work posted to worker thread, otherwise false.
  8005. **/
  8006. static bool
  8007. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8008. struct lpfc_queue *cq,
  8009. struct sli4_wcqe_xri_aborted *wcqe)
  8010. {
  8011. bool workposted = false;
  8012. struct lpfc_cq_event *cq_event;
  8013. unsigned long iflags;
  8014. /* Allocate a new internal CQ_EVENT entry */
  8015. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8016. if (!cq_event) {
  8017. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8018. "0602 Failed to allocate CQ_EVENT entry\n");
  8019. return false;
  8020. }
  8021. /* Move the CQE into the proper xri abort event list */
  8022. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8023. switch (cq->subtype) {
  8024. case LPFC_FCP:
  8025. spin_lock_irqsave(&phba->hbalock, iflags);
  8026. list_add_tail(&cq_event->list,
  8027. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8028. /* Set the fcp xri abort event flag */
  8029. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8030. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8031. workposted = true;
  8032. break;
  8033. case LPFC_ELS:
  8034. spin_lock_irqsave(&phba->hbalock, iflags);
  8035. list_add_tail(&cq_event->list,
  8036. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8037. /* Set the els xri abort event flag */
  8038. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8039. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8040. workposted = true;
  8041. break;
  8042. default:
  8043. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8044. "0603 Invalid work queue CQE subtype (x%x)\n",
  8045. cq->subtype);
  8046. workposted = false;
  8047. break;
  8048. }
  8049. return workposted;
  8050. }
  8051. /**
  8052. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8053. * @phba: Pointer to HBA context object.
  8054. * @rcqe: Pointer to receive-queue completion queue entry.
  8055. *
  8056. * This routine process a receive-queue completion queue entry.
  8057. *
  8058. * Return: true if work posted to worker thread, otherwise false.
  8059. **/
  8060. static bool
  8061. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8062. {
  8063. bool workposted = false;
  8064. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8065. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8066. struct hbq_dmabuf *dma_buf;
  8067. uint32_t status;
  8068. unsigned long iflags;
  8069. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8070. goto out;
  8071. status = bf_get(lpfc_rcqe_status, rcqe);
  8072. switch (status) {
  8073. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8074. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8075. "2537 Receive Frame Truncated!!\n");
  8076. case FC_STATUS_RQ_SUCCESS:
  8077. lpfc_sli4_rq_release(hrq, drq);
  8078. spin_lock_irqsave(&phba->hbalock, iflags);
  8079. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8080. if (!dma_buf) {
  8081. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8082. goto out;
  8083. }
  8084. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8085. /* save off the frame for the word thread to process */
  8086. list_add_tail(&dma_buf->cq_event.list,
  8087. &phba->sli4_hba.sp_queue_event);
  8088. /* Frame received */
  8089. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8090. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8091. workposted = true;
  8092. break;
  8093. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8094. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8095. /* Post more buffers if possible */
  8096. spin_lock_irqsave(&phba->hbalock, iflags);
  8097. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8098. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8099. workposted = true;
  8100. break;
  8101. }
  8102. out:
  8103. return workposted;
  8104. }
  8105. /**
  8106. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8107. * @phba: Pointer to HBA context object.
  8108. * @cq: Pointer to the completion queue.
  8109. * @wcqe: Pointer to a completion queue entry.
  8110. *
  8111. * This routine process a slow-path work-queue or recieve queue completion queue
  8112. * entry.
  8113. *
  8114. * Return: true if work posted to worker thread, otherwise false.
  8115. **/
  8116. static bool
  8117. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8118. struct lpfc_cqe *cqe)
  8119. {
  8120. struct lpfc_cqe cqevt;
  8121. bool workposted = false;
  8122. /* Copy the work queue CQE and convert endian order if needed */
  8123. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8124. /* Check and process for different type of WCQE and dispatch */
  8125. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8126. case CQE_CODE_COMPL_WQE:
  8127. /* Process the WQ/RQ complete event */
  8128. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8129. (struct lpfc_wcqe_complete *)&cqevt);
  8130. break;
  8131. case CQE_CODE_RELEASE_WQE:
  8132. /* Process the WQ release event */
  8133. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8134. (struct lpfc_wcqe_release *)&cqevt);
  8135. break;
  8136. case CQE_CODE_XRI_ABORTED:
  8137. /* Process the WQ XRI abort event */
  8138. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8139. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8140. break;
  8141. case CQE_CODE_RECEIVE:
  8142. /* Process the RQ event */
  8143. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8144. (struct lpfc_rcqe *)&cqevt);
  8145. break;
  8146. default:
  8147. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8148. "0388 Not a valid WCQE code: x%x\n",
  8149. bf_get(lpfc_cqe_code, &cqevt));
  8150. break;
  8151. }
  8152. return workposted;
  8153. }
  8154. /**
  8155. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8156. * @phba: Pointer to HBA context object.
  8157. * @eqe: Pointer to fast-path event queue entry.
  8158. *
  8159. * This routine process a event queue entry from the slow-path event queue.
  8160. * It will check the MajorCode and MinorCode to determine this is for a
  8161. * completion event on a completion queue, if not, an error shall be logged
  8162. * and just return. Otherwise, it will get to the corresponding completion
  8163. * queue and process all the entries on that completion queue, rearm the
  8164. * completion queue, and then return.
  8165. *
  8166. **/
  8167. static void
  8168. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8169. {
  8170. struct lpfc_queue *cq = NULL, *childq, *speq;
  8171. struct lpfc_cqe *cqe;
  8172. bool workposted = false;
  8173. int ecount = 0;
  8174. uint16_t cqid;
  8175. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8176. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8177. "0359 Not a valid slow-path completion "
  8178. "event: majorcode=x%x, minorcode=x%x\n",
  8179. bf_get_le32(lpfc_eqe_major_code, eqe),
  8180. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8181. return;
  8182. }
  8183. /* Get the reference to the corresponding CQ */
  8184. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8185. /* Search for completion queue pointer matching this cqid */
  8186. speq = phba->sli4_hba.sp_eq;
  8187. list_for_each_entry(childq, &speq->child_list, list) {
  8188. if (childq->queue_id == cqid) {
  8189. cq = childq;
  8190. break;
  8191. }
  8192. }
  8193. if (unlikely(!cq)) {
  8194. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8195. "0365 Slow-path CQ identifier (%d) does "
  8196. "not exist\n", cqid);
  8197. return;
  8198. }
  8199. /* Process all the entries to the CQ */
  8200. switch (cq->type) {
  8201. case LPFC_MCQ:
  8202. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8203. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8204. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8205. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8206. }
  8207. break;
  8208. case LPFC_WCQ:
  8209. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8210. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8211. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8212. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8213. }
  8214. break;
  8215. default:
  8216. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8217. "0370 Invalid completion queue type (%d)\n",
  8218. cq->type);
  8219. return;
  8220. }
  8221. /* Catch the no cq entry condition, log an error */
  8222. if (unlikely(ecount == 0))
  8223. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8224. "0371 No entry from the CQ: identifier "
  8225. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8226. /* In any case, flash and re-arm the RCQ */
  8227. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8228. /* wake up worker thread if there are works to be done */
  8229. if (workposted)
  8230. lpfc_worker_wake_up(phba);
  8231. }
  8232. /**
  8233. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8234. * @eqe: Pointer to fast-path completion queue entry.
  8235. *
  8236. * This routine process a fast-path work queue completion entry from fast-path
  8237. * event queue for FCP command response completion.
  8238. **/
  8239. static void
  8240. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8241. struct lpfc_wcqe_complete *wcqe)
  8242. {
  8243. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8244. struct lpfc_iocbq *cmdiocbq;
  8245. struct lpfc_iocbq irspiocbq;
  8246. unsigned long iflags;
  8247. spin_lock_irqsave(&phba->hbalock, iflags);
  8248. pring->stats.iocb_event++;
  8249. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8250. /* Check for response status */
  8251. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8252. /* If resource errors reported from HBA, reduce queue
  8253. * depth of the SCSI device.
  8254. */
  8255. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8256. IOSTAT_LOCAL_REJECT) &&
  8257. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8258. phba->lpfc_rampdown_queue_depth(phba);
  8259. }
  8260. /* Log the error status */
  8261. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8262. "0373 FCP complete error: status=x%x, "
  8263. "hw_status=x%x, total_data_specified=%d, "
  8264. "parameter=x%x, word3=x%x\n",
  8265. bf_get(lpfc_wcqe_c_status, wcqe),
  8266. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8267. wcqe->total_data_placed, wcqe->parameter,
  8268. wcqe->word3);
  8269. }
  8270. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8271. spin_lock_irqsave(&phba->hbalock, iflags);
  8272. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8273. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8274. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8275. if (unlikely(!cmdiocbq)) {
  8276. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8277. "0374 FCP complete with no corresponding "
  8278. "cmdiocb: iotag (%d)\n",
  8279. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8280. return;
  8281. }
  8282. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8283. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8284. "0375 FCP cmdiocb not callback function "
  8285. "iotag: (%d)\n",
  8286. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8287. return;
  8288. }
  8289. /* Fake the irspiocb and copy necessary response information */
  8290. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8291. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8292. spin_lock_irqsave(&phba->hbalock, iflags);
  8293. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8294. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8295. }
  8296. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8297. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8298. }
  8299. /**
  8300. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8301. * @phba: Pointer to HBA context object.
  8302. * @cq: Pointer to completion queue.
  8303. * @wcqe: Pointer to work-queue completion queue entry.
  8304. *
  8305. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8306. * proper WQ release routine to the slow-path WQ.
  8307. **/
  8308. static void
  8309. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8310. struct lpfc_wcqe_release *wcqe)
  8311. {
  8312. struct lpfc_queue *childwq;
  8313. bool wqid_matched = false;
  8314. uint16_t fcp_wqid;
  8315. /* Check for fast-path FCP work queue release */
  8316. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8317. list_for_each_entry(childwq, &cq->child_list, list) {
  8318. if (childwq->queue_id == fcp_wqid) {
  8319. lpfc_sli4_wq_release(childwq,
  8320. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8321. wqid_matched = true;
  8322. break;
  8323. }
  8324. }
  8325. /* Report warning log message if no match found */
  8326. if (wqid_matched != true)
  8327. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8328. "2580 Fast-path wqe consume event carries "
  8329. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8330. }
  8331. /**
  8332. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8333. * @cq: Pointer to the completion queue.
  8334. * @eqe: Pointer to fast-path completion queue entry.
  8335. *
  8336. * This routine process a fast-path work queue completion entry from fast-path
  8337. * event queue for FCP command response completion.
  8338. **/
  8339. static int
  8340. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8341. struct lpfc_cqe *cqe)
  8342. {
  8343. struct lpfc_wcqe_release wcqe;
  8344. bool workposted = false;
  8345. unsigned long iflag;
  8346. /* Copy the work queue CQE and convert endian order if needed */
  8347. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8348. /* Check and process for different type of WCQE and dispatch */
  8349. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8350. case CQE_CODE_COMPL_WQE:
  8351. /* Process the WQ complete event */
  8352. spin_lock_irqsave(&phba->hbalock, iflag);
  8353. phba->last_completion_time = jiffies;
  8354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8355. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8356. (struct lpfc_wcqe_complete *)&wcqe);
  8357. break;
  8358. case CQE_CODE_RELEASE_WQE:
  8359. /* Process the WQ release event */
  8360. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8361. (struct lpfc_wcqe_release *)&wcqe);
  8362. break;
  8363. case CQE_CODE_XRI_ABORTED:
  8364. /* Process the WQ XRI abort event */
  8365. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8366. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8367. break;
  8368. default:
  8369. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8370. "0144 Not a valid WCQE code: x%x\n",
  8371. bf_get(lpfc_wcqe_c_code, &wcqe));
  8372. break;
  8373. }
  8374. return workposted;
  8375. }
  8376. /**
  8377. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8378. * @phba: Pointer to HBA context object.
  8379. * @eqe: Pointer to fast-path event queue entry.
  8380. *
  8381. * This routine process a event queue entry from the fast-path event queue.
  8382. * It will check the MajorCode and MinorCode to determine this is for a
  8383. * completion event on a completion queue, if not, an error shall be logged
  8384. * and just return. Otherwise, it will get to the corresponding completion
  8385. * queue and process all the entries on the completion queue, rearm the
  8386. * completion queue, and then return.
  8387. **/
  8388. static void
  8389. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8390. uint32_t fcp_cqidx)
  8391. {
  8392. struct lpfc_queue *cq;
  8393. struct lpfc_cqe *cqe;
  8394. bool workposted = false;
  8395. uint16_t cqid;
  8396. int ecount = 0;
  8397. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8398. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8399. "0366 Not a valid fast-path completion "
  8400. "event: majorcode=x%x, minorcode=x%x\n",
  8401. bf_get_le32(lpfc_eqe_major_code, eqe),
  8402. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8403. return;
  8404. }
  8405. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8406. if (unlikely(!cq)) {
  8407. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8408. "0367 Fast-path completion queue does not "
  8409. "exist\n");
  8410. return;
  8411. }
  8412. /* Get the reference to the corresponding CQ */
  8413. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8414. if (unlikely(cqid != cq->queue_id)) {
  8415. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8416. "0368 Miss-matched fast-path completion "
  8417. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8418. cqid, cq->queue_id);
  8419. return;
  8420. }
  8421. /* Process all the entries to the CQ */
  8422. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8423. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8424. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8425. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8426. }
  8427. /* Catch the no cq entry condition */
  8428. if (unlikely(ecount == 0))
  8429. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8430. "0369 No entry from fast-path completion "
  8431. "queue fcpcqid=%d\n", cq->queue_id);
  8432. /* In any case, flash and re-arm the CQ */
  8433. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8434. /* wake up worker thread if there are works to be done */
  8435. if (workposted)
  8436. lpfc_worker_wake_up(phba);
  8437. }
  8438. static void
  8439. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8440. {
  8441. struct lpfc_eqe *eqe;
  8442. /* walk all the EQ entries and drop on the floor */
  8443. while ((eqe = lpfc_sli4_eq_get(eq)))
  8444. ;
  8445. /* Clear and re-arm the EQ */
  8446. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8447. }
  8448. /**
  8449. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8450. * @irq: Interrupt number.
  8451. * @dev_id: The device context pointer.
  8452. *
  8453. * This function is directly called from the PCI layer as an interrupt
  8454. * service routine when device with SLI-4 interface spec is enabled with
  8455. * MSI-X multi-message interrupt mode and there are slow-path events in
  8456. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8457. * interrupt mode, this function is called as part of the device-level
  8458. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8459. * undergoing initialization, the interrupt handler will not process the
  8460. * interrupt. The link attention and ELS ring attention events are handled
  8461. * by the worker thread. The interrupt handler signals the worker thread
  8462. * and returns for these events. This function is called without any lock
  8463. * held. It gets the hbalock to access and update SLI data structures.
  8464. *
  8465. * This function returns IRQ_HANDLED when interrupt is handled else it
  8466. * returns IRQ_NONE.
  8467. **/
  8468. irqreturn_t
  8469. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8470. {
  8471. struct lpfc_hba *phba;
  8472. struct lpfc_queue *speq;
  8473. struct lpfc_eqe *eqe;
  8474. unsigned long iflag;
  8475. int ecount = 0;
  8476. /*
  8477. * Get the driver's phba structure from the dev_id
  8478. */
  8479. phba = (struct lpfc_hba *)dev_id;
  8480. if (unlikely(!phba))
  8481. return IRQ_NONE;
  8482. /* Get to the EQ struct associated with this vector */
  8483. speq = phba->sli4_hba.sp_eq;
  8484. /* Check device state for handling interrupt */
  8485. if (unlikely(lpfc_intr_state_check(phba))) {
  8486. /* Check again for link_state with lock held */
  8487. spin_lock_irqsave(&phba->hbalock, iflag);
  8488. if (phba->link_state < LPFC_LINK_DOWN)
  8489. /* Flush, clear interrupt, and rearm the EQ */
  8490. lpfc_sli4_eq_flush(phba, speq);
  8491. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8492. return IRQ_NONE;
  8493. }
  8494. /*
  8495. * Process all the event on FCP slow-path EQ
  8496. */
  8497. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8498. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8499. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8500. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8501. }
  8502. /* Always clear and re-arm the slow-path EQ */
  8503. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8504. /* Catch the no cq entry condition */
  8505. if (unlikely(ecount == 0)) {
  8506. if (phba->intr_type == MSIX)
  8507. /* MSI-X treated interrupt served as no EQ share INT */
  8508. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8509. "0357 MSI-X interrupt with no EQE\n");
  8510. else
  8511. /* Non MSI-X treated on interrupt as EQ share INT */
  8512. return IRQ_NONE;
  8513. }
  8514. return IRQ_HANDLED;
  8515. } /* lpfc_sli4_sp_intr_handler */
  8516. /**
  8517. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8518. * @irq: Interrupt number.
  8519. * @dev_id: The device context pointer.
  8520. *
  8521. * This function is directly called from the PCI layer as an interrupt
  8522. * service routine when device with SLI-4 interface spec is enabled with
  8523. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8524. * ring event in the HBA. However, when the device is enabled with either
  8525. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8526. * device-level interrupt handler. When the PCI slot is in error recovery
  8527. * or the HBA is undergoing initialization, the interrupt handler will not
  8528. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8529. * the intrrupt context. This function is called without any lock held.
  8530. * It gets the hbalock to access and update SLI data structures. Note that,
  8531. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8532. * equal to that of FCP CQ index.
  8533. *
  8534. * This function returns IRQ_HANDLED when interrupt is handled else it
  8535. * returns IRQ_NONE.
  8536. **/
  8537. irqreturn_t
  8538. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8539. {
  8540. struct lpfc_hba *phba;
  8541. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8542. struct lpfc_queue *fpeq;
  8543. struct lpfc_eqe *eqe;
  8544. unsigned long iflag;
  8545. int ecount = 0;
  8546. uint32_t fcp_eqidx;
  8547. /* Get the driver's phba structure from the dev_id */
  8548. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8549. phba = fcp_eq_hdl->phba;
  8550. fcp_eqidx = fcp_eq_hdl->idx;
  8551. if (unlikely(!phba))
  8552. return IRQ_NONE;
  8553. /* Get to the EQ struct associated with this vector */
  8554. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8555. /* Check device state for handling interrupt */
  8556. if (unlikely(lpfc_intr_state_check(phba))) {
  8557. /* Check again for link_state with lock held */
  8558. spin_lock_irqsave(&phba->hbalock, iflag);
  8559. if (phba->link_state < LPFC_LINK_DOWN)
  8560. /* Flush, clear interrupt, and rearm the EQ */
  8561. lpfc_sli4_eq_flush(phba, fpeq);
  8562. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8563. return IRQ_NONE;
  8564. }
  8565. /*
  8566. * Process all the event on FCP fast-path EQ
  8567. */
  8568. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8569. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8570. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8571. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8572. }
  8573. /* Always clear and re-arm the fast-path EQ */
  8574. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8575. if (unlikely(ecount == 0)) {
  8576. if (phba->intr_type == MSIX)
  8577. /* MSI-X treated interrupt served as no EQ share INT */
  8578. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8579. "0358 MSI-X interrupt with no EQE\n");
  8580. else
  8581. /* Non MSI-X treated on interrupt as EQ share INT */
  8582. return IRQ_NONE;
  8583. }
  8584. return IRQ_HANDLED;
  8585. } /* lpfc_sli4_fp_intr_handler */
  8586. /**
  8587. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8588. * @irq: Interrupt number.
  8589. * @dev_id: The device context pointer.
  8590. *
  8591. * This function is the device-level interrupt handler to device with SLI-4
  8592. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8593. * interrupt mode is enabled and there is an event in the HBA which requires
  8594. * driver attention. This function invokes the slow-path interrupt attention
  8595. * handling function and fast-path interrupt attention handling function in
  8596. * turn to process the relevant HBA attention events. This function is called
  8597. * without any lock held. It gets the hbalock to access and update SLI data
  8598. * structures.
  8599. *
  8600. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8601. * returns IRQ_NONE.
  8602. **/
  8603. irqreturn_t
  8604. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8605. {
  8606. struct lpfc_hba *phba;
  8607. irqreturn_t sp_irq_rc, fp_irq_rc;
  8608. bool fp_handled = false;
  8609. uint32_t fcp_eqidx;
  8610. /* Get the driver's phba structure from the dev_id */
  8611. phba = (struct lpfc_hba *)dev_id;
  8612. if (unlikely(!phba))
  8613. return IRQ_NONE;
  8614. /*
  8615. * Invokes slow-path host attention interrupt handling as appropriate.
  8616. */
  8617. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8618. /*
  8619. * Invoke fast-path host attention interrupt handling as appropriate.
  8620. */
  8621. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8622. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8623. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8624. if (fp_irq_rc == IRQ_HANDLED)
  8625. fp_handled |= true;
  8626. }
  8627. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8628. } /* lpfc_sli4_intr_handler */
  8629. /**
  8630. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8631. * @queue: The queue structure to free.
  8632. *
  8633. * This function frees a queue structure and the DMAable memeory used for
  8634. * the host resident queue. This function must be called after destroying the
  8635. * queue on the HBA.
  8636. **/
  8637. void
  8638. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8639. {
  8640. struct lpfc_dmabuf *dmabuf;
  8641. if (!queue)
  8642. return;
  8643. while (!list_empty(&queue->page_list)) {
  8644. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8645. list);
  8646. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8647. dmabuf->virt, dmabuf->phys);
  8648. kfree(dmabuf);
  8649. }
  8650. kfree(queue);
  8651. return;
  8652. }
  8653. /**
  8654. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8655. * @phba: The HBA that this queue is being created on.
  8656. * @entry_size: The size of each queue entry for this queue.
  8657. * @entry count: The number of entries that this queue will handle.
  8658. *
  8659. * This function allocates a queue structure and the DMAable memory used for
  8660. * the host resident queue. This function must be called before creating the
  8661. * queue on the HBA.
  8662. **/
  8663. struct lpfc_queue *
  8664. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8665. uint32_t entry_count)
  8666. {
  8667. struct lpfc_queue *queue;
  8668. struct lpfc_dmabuf *dmabuf;
  8669. int x, total_qe_count;
  8670. void *dma_pointer;
  8671. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8672. if (!phba->sli4_hba.pc_sli4_params.supported)
  8673. hw_page_size = SLI4_PAGE_SIZE;
  8674. queue = kzalloc(sizeof(struct lpfc_queue) +
  8675. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8676. if (!queue)
  8677. return NULL;
  8678. queue->page_count = (ALIGN(entry_size * entry_count,
  8679. hw_page_size))/hw_page_size;
  8680. INIT_LIST_HEAD(&queue->list);
  8681. INIT_LIST_HEAD(&queue->page_list);
  8682. INIT_LIST_HEAD(&queue->child_list);
  8683. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8684. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8685. if (!dmabuf)
  8686. goto out_fail;
  8687. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8688. hw_page_size, &dmabuf->phys,
  8689. GFP_KERNEL);
  8690. if (!dmabuf->virt) {
  8691. kfree(dmabuf);
  8692. goto out_fail;
  8693. }
  8694. memset(dmabuf->virt, 0, hw_page_size);
  8695. dmabuf->buffer_tag = x;
  8696. list_add_tail(&dmabuf->list, &queue->page_list);
  8697. /* initialize queue's entry array */
  8698. dma_pointer = dmabuf->virt;
  8699. for (; total_qe_count < entry_count &&
  8700. dma_pointer < (hw_page_size + dmabuf->virt);
  8701. total_qe_count++, dma_pointer += entry_size) {
  8702. queue->qe[total_qe_count].address = dma_pointer;
  8703. }
  8704. }
  8705. queue->entry_size = entry_size;
  8706. queue->entry_count = entry_count;
  8707. queue->phba = phba;
  8708. return queue;
  8709. out_fail:
  8710. lpfc_sli4_queue_free(queue);
  8711. return NULL;
  8712. }
  8713. /**
  8714. * lpfc_eq_create - Create an Event Queue on the HBA
  8715. * @phba: HBA structure that indicates port to create a queue on.
  8716. * @eq: The queue structure to use to create the event queue.
  8717. * @imax: The maximum interrupt per second limit.
  8718. *
  8719. * This function creates an event queue, as detailed in @eq, on a port,
  8720. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8721. *
  8722. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8723. * is used to get the entry count and entry size that are necessary to
  8724. * determine the number of pages to allocate and use for this queue. This
  8725. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8726. * event queue. This function is asynchronous and will wait for the mailbox
  8727. * command to finish before continuing.
  8728. *
  8729. * On success this function will return a zero. If unable to allocate enough
  8730. * memory this function will return ENOMEM. If the queue create mailbox command
  8731. * fails this function will return ENXIO.
  8732. **/
  8733. uint32_t
  8734. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8735. {
  8736. struct lpfc_mbx_eq_create *eq_create;
  8737. LPFC_MBOXQ_t *mbox;
  8738. int rc, length, status = 0;
  8739. struct lpfc_dmabuf *dmabuf;
  8740. uint32_t shdr_status, shdr_add_status;
  8741. union lpfc_sli4_cfg_shdr *shdr;
  8742. uint16_t dmult;
  8743. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8744. if (!phba->sli4_hba.pc_sli4_params.supported)
  8745. hw_page_size = SLI4_PAGE_SIZE;
  8746. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8747. if (!mbox)
  8748. return -ENOMEM;
  8749. length = (sizeof(struct lpfc_mbx_eq_create) -
  8750. sizeof(struct lpfc_sli4_cfg_mhdr));
  8751. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8752. LPFC_MBOX_OPCODE_EQ_CREATE,
  8753. length, LPFC_SLI4_MBX_EMBED);
  8754. eq_create = &mbox->u.mqe.un.eq_create;
  8755. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8756. eq->page_count);
  8757. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8758. LPFC_EQE_SIZE);
  8759. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8760. /* Calculate delay multiper from maximum interrupt per second */
  8761. dmult = LPFC_DMULT_CONST/imax - 1;
  8762. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8763. dmult);
  8764. switch (eq->entry_count) {
  8765. default:
  8766. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8767. "0360 Unsupported EQ count. (%d)\n",
  8768. eq->entry_count);
  8769. if (eq->entry_count < 256)
  8770. return -EINVAL;
  8771. /* otherwise default to smallest count (drop through) */
  8772. case 256:
  8773. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8774. LPFC_EQ_CNT_256);
  8775. break;
  8776. case 512:
  8777. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8778. LPFC_EQ_CNT_512);
  8779. break;
  8780. case 1024:
  8781. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8782. LPFC_EQ_CNT_1024);
  8783. break;
  8784. case 2048:
  8785. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8786. LPFC_EQ_CNT_2048);
  8787. break;
  8788. case 4096:
  8789. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8790. LPFC_EQ_CNT_4096);
  8791. break;
  8792. }
  8793. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8794. memset(dmabuf->virt, 0, hw_page_size);
  8795. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8796. putPaddrLow(dmabuf->phys);
  8797. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8798. putPaddrHigh(dmabuf->phys);
  8799. }
  8800. mbox->vport = phba->pport;
  8801. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8802. mbox->context1 = NULL;
  8803. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8804. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8805. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8806. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8807. if (shdr_status || shdr_add_status || rc) {
  8808. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8809. "2500 EQ_CREATE mailbox failed with "
  8810. "status x%x add_status x%x, mbx status x%x\n",
  8811. shdr_status, shdr_add_status, rc);
  8812. status = -ENXIO;
  8813. }
  8814. eq->type = LPFC_EQ;
  8815. eq->subtype = LPFC_NONE;
  8816. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8817. if (eq->queue_id == 0xFFFF)
  8818. status = -ENXIO;
  8819. eq->host_index = 0;
  8820. eq->hba_index = 0;
  8821. mempool_free(mbox, phba->mbox_mem_pool);
  8822. return status;
  8823. }
  8824. /**
  8825. * lpfc_cq_create - Create a Completion Queue on the HBA
  8826. * @phba: HBA structure that indicates port to create a queue on.
  8827. * @cq: The queue structure to use to create the completion queue.
  8828. * @eq: The event queue to bind this completion queue to.
  8829. *
  8830. * This function creates a completion queue, as detailed in @wq, on a port,
  8831. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8832. *
  8833. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8834. * is used to get the entry count and entry size that are necessary to
  8835. * determine the number of pages to allocate and use for this queue. The @eq
  8836. * is used to indicate which event queue to bind this completion queue to. This
  8837. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8838. * completion queue. This function is asynchronous and will wait for the mailbox
  8839. * command to finish before continuing.
  8840. *
  8841. * On success this function will return a zero. If unable to allocate enough
  8842. * memory this function will return ENOMEM. If the queue create mailbox command
  8843. * fails this function will return ENXIO.
  8844. **/
  8845. uint32_t
  8846. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8847. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8848. {
  8849. struct lpfc_mbx_cq_create *cq_create;
  8850. struct lpfc_dmabuf *dmabuf;
  8851. LPFC_MBOXQ_t *mbox;
  8852. int rc, length, status = 0;
  8853. uint32_t shdr_status, shdr_add_status;
  8854. union lpfc_sli4_cfg_shdr *shdr;
  8855. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8856. if (!phba->sli4_hba.pc_sli4_params.supported)
  8857. hw_page_size = SLI4_PAGE_SIZE;
  8858. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8859. if (!mbox)
  8860. return -ENOMEM;
  8861. length = (sizeof(struct lpfc_mbx_cq_create) -
  8862. sizeof(struct lpfc_sli4_cfg_mhdr));
  8863. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8864. LPFC_MBOX_OPCODE_CQ_CREATE,
  8865. length, LPFC_SLI4_MBX_EMBED);
  8866. cq_create = &mbox->u.mqe.un.cq_create;
  8867. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8868. cq->page_count);
  8869. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8870. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8871. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8872. switch (cq->entry_count) {
  8873. default:
  8874. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8875. "0361 Unsupported CQ count. (%d)\n",
  8876. cq->entry_count);
  8877. if (cq->entry_count < 256)
  8878. return -EINVAL;
  8879. /* otherwise default to smallest count (drop through) */
  8880. case 256:
  8881. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8882. LPFC_CQ_CNT_256);
  8883. break;
  8884. case 512:
  8885. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8886. LPFC_CQ_CNT_512);
  8887. break;
  8888. case 1024:
  8889. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8890. LPFC_CQ_CNT_1024);
  8891. break;
  8892. }
  8893. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8894. memset(dmabuf->virt, 0, hw_page_size);
  8895. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8896. putPaddrLow(dmabuf->phys);
  8897. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8898. putPaddrHigh(dmabuf->phys);
  8899. }
  8900. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8901. /* The IOCTL status is embedded in the mailbox subheader. */
  8902. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8903. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8904. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8905. if (shdr_status || shdr_add_status || rc) {
  8906. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8907. "2501 CQ_CREATE mailbox failed with "
  8908. "status x%x add_status x%x, mbx status x%x\n",
  8909. shdr_status, shdr_add_status, rc);
  8910. status = -ENXIO;
  8911. goto out;
  8912. }
  8913. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8914. if (cq->queue_id == 0xFFFF) {
  8915. status = -ENXIO;
  8916. goto out;
  8917. }
  8918. /* link the cq onto the parent eq child list */
  8919. list_add_tail(&cq->list, &eq->child_list);
  8920. /* Set up completion queue's type and subtype */
  8921. cq->type = type;
  8922. cq->subtype = subtype;
  8923. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8924. cq->host_index = 0;
  8925. cq->hba_index = 0;
  8926. out:
  8927. mempool_free(mbox, phba->mbox_mem_pool);
  8928. return status;
  8929. }
  8930. /**
  8931. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  8932. * @phba: HBA structure that indicates port to create a queue on.
  8933. * @mq: The queue structure to use to create the mailbox queue.
  8934. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  8935. * @cq: The completion queue to associate with this cq.
  8936. *
  8937. * This function provides failback (fb) functionality when the
  8938. * mq_create_ext fails on older FW generations. It's purpose is identical
  8939. * to mq_create_ext otherwise.
  8940. *
  8941. * This routine cannot fail as all attributes were previously accessed and
  8942. * initialized in mq_create_ext.
  8943. **/
  8944. static void
  8945. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8946. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  8947. {
  8948. struct lpfc_mbx_mq_create *mq_create;
  8949. struct lpfc_dmabuf *dmabuf;
  8950. int length;
  8951. length = (sizeof(struct lpfc_mbx_mq_create) -
  8952. sizeof(struct lpfc_sli4_cfg_mhdr));
  8953. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8954. LPFC_MBOX_OPCODE_MQ_CREATE,
  8955. length, LPFC_SLI4_MBX_EMBED);
  8956. mq_create = &mbox->u.mqe.un.mq_create;
  8957. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8958. mq->page_count);
  8959. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8960. cq->queue_id);
  8961. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8962. switch (mq->entry_count) {
  8963. case 16:
  8964. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8965. LPFC_MQ_CNT_16);
  8966. break;
  8967. case 32:
  8968. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8969. LPFC_MQ_CNT_32);
  8970. break;
  8971. case 64:
  8972. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8973. LPFC_MQ_CNT_64);
  8974. break;
  8975. case 128:
  8976. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8977. LPFC_MQ_CNT_128);
  8978. break;
  8979. }
  8980. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8981. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8982. putPaddrLow(dmabuf->phys);
  8983. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8984. putPaddrHigh(dmabuf->phys);
  8985. }
  8986. }
  8987. /**
  8988. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8989. * @phba: HBA structure that indicates port to create a queue on.
  8990. * @mq: The queue structure to use to create the mailbox queue.
  8991. * @cq: The completion queue to associate with this cq.
  8992. * @subtype: The queue's subtype.
  8993. *
  8994. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8995. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8996. *
  8997. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8998. * is used to get the entry count and entry size that are necessary to
  8999. * determine the number of pages to allocate and use for this queue. This
  9000. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9001. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9002. * command to finish before continuing.
  9003. *
  9004. * On success this function will return a zero. If unable to allocate enough
  9005. * memory this function will return ENOMEM. If the queue create mailbox command
  9006. * fails this function will return ENXIO.
  9007. **/
  9008. int32_t
  9009. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9010. struct lpfc_queue *cq, uint32_t subtype)
  9011. {
  9012. struct lpfc_mbx_mq_create *mq_create;
  9013. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9014. struct lpfc_dmabuf *dmabuf;
  9015. LPFC_MBOXQ_t *mbox;
  9016. int rc, length, status = 0;
  9017. uint32_t shdr_status, shdr_add_status;
  9018. union lpfc_sli4_cfg_shdr *shdr;
  9019. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9020. if (!phba->sli4_hba.pc_sli4_params.supported)
  9021. hw_page_size = SLI4_PAGE_SIZE;
  9022. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9023. if (!mbox)
  9024. return -ENOMEM;
  9025. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9026. sizeof(struct lpfc_sli4_cfg_mhdr));
  9027. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9028. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9029. length, LPFC_SLI4_MBX_EMBED);
  9030. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9031. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9032. mq->page_count);
  9033. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9034. 1);
  9035. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9036. &mq_create_ext->u.request, 1);
  9037. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9038. &mq_create_ext->u.request, 1);
  9039. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9040. cq->queue_id);
  9041. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9042. switch (mq->entry_count) {
  9043. default:
  9044. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9045. "0362 Unsupported MQ count. (%d)\n",
  9046. mq->entry_count);
  9047. if (mq->entry_count < 16)
  9048. return -EINVAL;
  9049. /* otherwise default to smallest count (drop through) */
  9050. case 16:
  9051. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9052. LPFC_MQ_CNT_16);
  9053. break;
  9054. case 32:
  9055. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9056. LPFC_MQ_CNT_32);
  9057. break;
  9058. case 64:
  9059. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9060. LPFC_MQ_CNT_64);
  9061. break;
  9062. case 128:
  9063. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9064. LPFC_MQ_CNT_128);
  9065. break;
  9066. }
  9067. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9068. memset(dmabuf->virt, 0, hw_page_size);
  9069. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9070. putPaddrLow(dmabuf->phys);
  9071. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9072. putPaddrHigh(dmabuf->phys);
  9073. }
  9074. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9075. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9076. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9077. &mq_create_ext->u.response);
  9078. if (rc != MBX_SUCCESS) {
  9079. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9080. "2795 MQ_CREATE_EXT failed with "
  9081. "status x%x. Failback to MQ_CREATE.\n",
  9082. rc);
  9083. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9084. mq_create = &mbox->u.mqe.un.mq_create;
  9085. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9086. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9087. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9088. &mq_create->u.response);
  9089. }
  9090. /* The IOCTL status is embedded in the mailbox subheader. */
  9091. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9092. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9093. if (shdr_status || shdr_add_status || rc) {
  9094. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9095. "2502 MQ_CREATE mailbox failed with "
  9096. "status x%x add_status x%x, mbx status x%x\n",
  9097. shdr_status, shdr_add_status, rc);
  9098. status = -ENXIO;
  9099. goto out;
  9100. }
  9101. if (mq->queue_id == 0xFFFF) {
  9102. status = -ENXIO;
  9103. goto out;
  9104. }
  9105. mq->type = LPFC_MQ;
  9106. mq->subtype = subtype;
  9107. mq->host_index = 0;
  9108. mq->hba_index = 0;
  9109. /* link the mq onto the parent cq child list */
  9110. list_add_tail(&mq->list, &cq->child_list);
  9111. out:
  9112. mempool_free(mbox, phba->mbox_mem_pool);
  9113. return status;
  9114. }
  9115. /**
  9116. * lpfc_wq_create - Create a Work Queue on the HBA
  9117. * @phba: HBA structure that indicates port to create a queue on.
  9118. * @wq: The queue structure to use to create the work queue.
  9119. * @cq: The completion queue to bind this work queue to.
  9120. * @subtype: The subtype of the work queue indicating its functionality.
  9121. *
  9122. * This function creates a work queue, as detailed in @wq, on a port, described
  9123. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9124. *
  9125. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9126. * is used to get the entry count and entry size that are necessary to
  9127. * determine the number of pages to allocate and use for this queue. The @cq
  9128. * is used to indicate which completion queue to bind this work queue to. This
  9129. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9130. * work queue. This function is asynchronous and will wait for the mailbox
  9131. * command to finish before continuing.
  9132. *
  9133. * On success this function will return a zero. If unable to allocate enough
  9134. * memory this function will return ENOMEM. If the queue create mailbox command
  9135. * fails this function will return ENXIO.
  9136. **/
  9137. uint32_t
  9138. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9139. struct lpfc_queue *cq, uint32_t subtype)
  9140. {
  9141. struct lpfc_mbx_wq_create *wq_create;
  9142. struct lpfc_dmabuf *dmabuf;
  9143. LPFC_MBOXQ_t *mbox;
  9144. int rc, length, status = 0;
  9145. uint32_t shdr_status, shdr_add_status;
  9146. union lpfc_sli4_cfg_shdr *shdr;
  9147. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9148. if (!phba->sli4_hba.pc_sli4_params.supported)
  9149. hw_page_size = SLI4_PAGE_SIZE;
  9150. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9151. if (!mbox)
  9152. return -ENOMEM;
  9153. length = (sizeof(struct lpfc_mbx_wq_create) -
  9154. sizeof(struct lpfc_sli4_cfg_mhdr));
  9155. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9156. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9157. length, LPFC_SLI4_MBX_EMBED);
  9158. wq_create = &mbox->u.mqe.un.wq_create;
  9159. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9160. wq->page_count);
  9161. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9162. cq->queue_id);
  9163. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9164. memset(dmabuf->virt, 0, hw_page_size);
  9165. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9166. putPaddrLow(dmabuf->phys);
  9167. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9168. putPaddrHigh(dmabuf->phys);
  9169. }
  9170. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9171. /* The IOCTL status is embedded in the mailbox subheader. */
  9172. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9173. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9174. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9175. if (shdr_status || shdr_add_status || rc) {
  9176. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9177. "2503 WQ_CREATE mailbox failed with "
  9178. "status x%x add_status x%x, mbx status x%x\n",
  9179. shdr_status, shdr_add_status, rc);
  9180. status = -ENXIO;
  9181. goto out;
  9182. }
  9183. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9184. if (wq->queue_id == 0xFFFF) {
  9185. status = -ENXIO;
  9186. goto out;
  9187. }
  9188. wq->type = LPFC_WQ;
  9189. wq->subtype = subtype;
  9190. wq->host_index = 0;
  9191. wq->hba_index = 0;
  9192. /* link the wq onto the parent cq child list */
  9193. list_add_tail(&wq->list, &cq->child_list);
  9194. out:
  9195. mempool_free(mbox, phba->mbox_mem_pool);
  9196. return status;
  9197. }
  9198. /**
  9199. * lpfc_rq_create - Create a Receive Queue on the HBA
  9200. * @phba: HBA structure that indicates port to create a queue on.
  9201. * @hrq: The queue structure to use to create the header receive queue.
  9202. * @drq: The queue structure to use to create the data receive queue.
  9203. * @cq: The completion queue to bind this work queue to.
  9204. *
  9205. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9206. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9207. * to the HBA.
  9208. *
  9209. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9210. * struct is used to get the entry count that is necessary to determine the
  9211. * number of pages to use for this queue. The @cq is used to indicate which
  9212. * completion queue to bind received buffers that are posted to these queues to.
  9213. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9214. * receive queue pair. This function is asynchronous and will wait for the
  9215. * mailbox command to finish before continuing.
  9216. *
  9217. * On success this function will return a zero. If unable to allocate enough
  9218. * memory this function will return ENOMEM. If the queue create mailbox command
  9219. * fails this function will return ENXIO.
  9220. **/
  9221. uint32_t
  9222. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9223. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9224. {
  9225. struct lpfc_mbx_rq_create *rq_create;
  9226. struct lpfc_dmabuf *dmabuf;
  9227. LPFC_MBOXQ_t *mbox;
  9228. int rc, length, status = 0;
  9229. uint32_t shdr_status, shdr_add_status;
  9230. union lpfc_sli4_cfg_shdr *shdr;
  9231. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9232. if (!phba->sli4_hba.pc_sli4_params.supported)
  9233. hw_page_size = SLI4_PAGE_SIZE;
  9234. if (hrq->entry_count != drq->entry_count)
  9235. return -EINVAL;
  9236. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9237. if (!mbox)
  9238. return -ENOMEM;
  9239. length = (sizeof(struct lpfc_mbx_rq_create) -
  9240. sizeof(struct lpfc_sli4_cfg_mhdr));
  9241. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9242. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9243. length, LPFC_SLI4_MBX_EMBED);
  9244. rq_create = &mbox->u.mqe.un.rq_create;
  9245. switch (hrq->entry_count) {
  9246. default:
  9247. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9248. "2535 Unsupported RQ count. (%d)\n",
  9249. hrq->entry_count);
  9250. if (hrq->entry_count < 512)
  9251. return -EINVAL;
  9252. /* otherwise default to smallest count (drop through) */
  9253. case 512:
  9254. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9255. LPFC_RQ_RING_SIZE_512);
  9256. break;
  9257. case 1024:
  9258. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9259. LPFC_RQ_RING_SIZE_1024);
  9260. break;
  9261. case 2048:
  9262. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9263. LPFC_RQ_RING_SIZE_2048);
  9264. break;
  9265. case 4096:
  9266. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9267. LPFC_RQ_RING_SIZE_4096);
  9268. break;
  9269. }
  9270. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9271. cq->queue_id);
  9272. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9273. hrq->page_count);
  9274. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9275. LPFC_HDR_BUF_SIZE);
  9276. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9277. memset(dmabuf->virt, 0, hw_page_size);
  9278. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9279. putPaddrLow(dmabuf->phys);
  9280. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9281. putPaddrHigh(dmabuf->phys);
  9282. }
  9283. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9284. /* The IOCTL status is embedded in the mailbox subheader. */
  9285. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9286. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9287. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9288. if (shdr_status || shdr_add_status || rc) {
  9289. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9290. "2504 RQ_CREATE mailbox failed with "
  9291. "status x%x add_status x%x, mbx status x%x\n",
  9292. shdr_status, shdr_add_status, rc);
  9293. status = -ENXIO;
  9294. goto out;
  9295. }
  9296. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9297. if (hrq->queue_id == 0xFFFF) {
  9298. status = -ENXIO;
  9299. goto out;
  9300. }
  9301. hrq->type = LPFC_HRQ;
  9302. hrq->subtype = subtype;
  9303. hrq->host_index = 0;
  9304. hrq->hba_index = 0;
  9305. /* now create the data queue */
  9306. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9307. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9308. length, LPFC_SLI4_MBX_EMBED);
  9309. switch (drq->entry_count) {
  9310. default:
  9311. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9312. "2536 Unsupported RQ count. (%d)\n",
  9313. drq->entry_count);
  9314. if (drq->entry_count < 512)
  9315. return -EINVAL;
  9316. /* otherwise default to smallest count (drop through) */
  9317. case 512:
  9318. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9319. LPFC_RQ_RING_SIZE_512);
  9320. break;
  9321. case 1024:
  9322. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9323. LPFC_RQ_RING_SIZE_1024);
  9324. break;
  9325. case 2048:
  9326. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9327. LPFC_RQ_RING_SIZE_2048);
  9328. break;
  9329. case 4096:
  9330. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9331. LPFC_RQ_RING_SIZE_4096);
  9332. break;
  9333. }
  9334. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9335. cq->queue_id);
  9336. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9337. drq->page_count);
  9338. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9339. LPFC_DATA_BUF_SIZE);
  9340. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9341. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9342. putPaddrLow(dmabuf->phys);
  9343. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9344. putPaddrHigh(dmabuf->phys);
  9345. }
  9346. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9347. /* The IOCTL status is embedded in the mailbox subheader. */
  9348. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9349. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9350. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9351. if (shdr_status || shdr_add_status || rc) {
  9352. status = -ENXIO;
  9353. goto out;
  9354. }
  9355. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9356. if (drq->queue_id == 0xFFFF) {
  9357. status = -ENXIO;
  9358. goto out;
  9359. }
  9360. drq->type = LPFC_DRQ;
  9361. drq->subtype = subtype;
  9362. drq->host_index = 0;
  9363. drq->hba_index = 0;
  9364. /* link the header and data RQs onto the parent cq child list */
  9365. list_add_tail(&hrq->list, &cq->child_list);
  9366. list_add_tail(&drq->list, &cq->child_list);
  9367. out:
  9368. mempool_free(mbox, phba->mbox_mem_pool);
  9369. return status;
  9370. }
  9371. /**
  9372. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9373. * @eq: The queue structure associated with the queue to destroy.
  9374. *
  9375. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9376. * command, specific to the type of queue, to the HBA.
  9377. *
  9378. * The @eq struct is used to get the queue ID of the queue to destroy.
  9379. *
  9380. * On success this function will return a zero. If the queue destroy mailbox
  9381. * command fails this function will return ENXIO.
  9382. **/
  9383. uint32_t
  9384. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9385. {
  9386. LPFC_MBOXQ_t *mbox;
  9387. int rc, length, status = 0;
  9388. uint32_t shdr_status, shdr_add_status;
  9389. union lpfc_sli4_cfg_shdr *shdr;
  9390. if (!eq)
  9391. return -ENODEV;
  9392. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9393. if (!mbox)
  9394. return -ENOMEM;
  9395. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9396. sizeof(struct lpfc_sli4_cfg_mhdr));
  9397. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9398. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9399. length, LPFC_SLI4_MBX_EMBED);
  9400. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9401. eq->queue_id);
  9402. mbox->vport = eq->phba->pport;
  9403. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9404. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9405. /* The IOCTL status is embedded in the mailbox subheader. */
  9406. shdr = (union lpfc_sli4_cfg_shdr *)
  9407. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9408. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9409. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9410. if (shdr_status || shdr_add_status || rc) {
  9411. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9412. "2505 EQ_DESTROY mailbox failed with "
  9413. "status x%x add_status x%x, mbx status x%x\n",
  9414. shdr_status, shdr_add_status, rc);
  9415. status = -ENXIO;
  9416. }
  9417. /* Remove eq from any list */
  9418. list_del_init(&eq->list);
  9419. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9420. return status;
  9421. }
  9422. /**
  9423. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9424. * @cq: The queue structure associated with the queue to destroy.
  9425. *
  9426. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9427. * command, specific to the type of queue, to the HBA.
  9428. *
  9429. * The @cq struct is used to get the queue ID of the queue to destroy.
  9430. *
  9431. * On success this function will return a zero. If the queue destroy mailbox
  9432. * command fails this function will return ENXIO.
  9433. **/
  9434. uint32_t
  9435. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9436. {
  9437. LPFC_MBOXQ_t *mbox;
  9438. int rc, length, status = 0;
  9439. uint32_t shdr_status, shdr_add_status;
  9440. union lpfc_sli4_cfg_shdr *shdr;
  9441. if (!cq)
  9442. return -ENODEV;
  9443. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9444. if (!mbox)
  9445. return -ENOMEM;
  9446. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9447. sizeof(struct lpfc_sli4_cfg_mhdr));
  9448. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9449. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9450. length, LPFC_SLI4_MBX_EMBED);
  9451. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9452. cq->queue_id);
  9453. mbox->vport = cq->phba->pport;
  9454. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9455. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9456. /* The IOCTL status is embedded in the mailbox subheader. */
  9457. shdr = (union lpfc_sli4_cfg_shdr *)
  9458. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9459. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9460. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9461. if (shdr_status || shdr_add_status || rc) {
  9462. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9463. "2506 CQ_DESTROY mailbox failed with "
  9464. "status x%x add_status x%x, mbx status x%x\n",
  9465. shdr_status, shdr_add_status, rc);
  9466. status = -ENXIO;
  9467. }
  9468. /* Remove cq from any list */
  9469. list_del_init(&cq->list);
  9470. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9471. return status;
  9472. }
  9473. /**
  9474. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9475. * @qm: The queue structure associated with the queue to destroy.
  9476. *
  9477. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9478. * command, specific to the type of queue, to the HBA.
  9479. *
  9480. * The @mq struct is used to get the queue ID of the queue to destroy.
  9481. *
  9482. * On success this function will return a zero. If the queue destroy mailbox
  9483. * command fails this function will return ENXIO.
  9484. **/
  9485. uint32_t
  9486. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9487. {
  9488. LPFC_MBOXQ_t *mbox;
  9489. int rc, length, status = 0;
  9490. uint32_t shdr_status, shdr_add_status;
  9491. union lpfc_sli4_cfg_shdr *shdr;
  9492. if (!mq)
  9493. return -ENODEV;
  9494. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9495. if (!mbox)
  9496. return -ENOMEM;
  9497. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9498. sizeof(struct lpfc_sli4_cfg_mhdr));
  9499. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9500. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9501. length, LPFC_SLI4_MBX_EMBED);
  9502. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9503. mq->queue_id);
  9504. mbox->vport = mq->phba->pport;
  9505. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9506. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9507. /* The IOCTL status is embedded in the mailbox subheader. */
  9508. shdr = (union lpfc_sli4_cfg_shdr *)
  9509. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9510. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9511. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9512. if (shdr_status || shdr_add_status || rc) {
  9513. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9514. "2507 MQ_DESTROY mailbox failed with "
  9515. "status x%x add_status x%x, mbx status x%x\n",
  9516. shdr_status, shdr_add_status, rc);
  9517. status = -ENXIO;
  9518. }
  9519. /* Remove mq from any list */
  9520. list_del_init(&mq->list);
  9521. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9522. return status;
  9523. }
  9524. /**
  9525. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9526. * @wq: The queue structure associated with the queue to destroy.
  9527. *
  9528. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9529. * command, specific to the type of queue, to the HBA.
  9530. *
  9531. * The @wq struct is used to get the queue ID of the queue to destroy.
  9532. *
  9533. * On success this function will return a zero. If the queue destroy mailbox
  9534. * command fails this function will return ENXIO.
  9535. **/
  9536. uint32_t
  9537. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9538. {
  9539. LPFC_MBOXQ_t *mbox;
  9540. int rc, length, status = 0;
  9541. uint32_t shdr_status, shdr_add_status;
  9542. union lpfc_sli4_cfg_shdr *shdr;
  9543. if (!wq)
  9544. return -ENODEV;
  9545. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9546. if (!mbox)
  9547. return -ENOMEM;
  9548. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9549. sizeof(struct lpfc_sli4_cfg_mhdr));
  9550. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9551. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9552. length, LPFC_SLI4_MBX_EMBED);
  9553. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9554. wq->queue_id);
  9555. mbox->vport = wq->phba->pport;
  9556. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9557. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9558. shdr = (union lpfc_sli4_cfg_shdr *)
  9559. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9560. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9561. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9562. if (shdr_status || shdr_add_status || rc) {
  9563. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9564. "2508 WQ_DESTROY mailbox failed with "
  9565. "status x%x add_status x%x, mbx status x%x\n",
  9566. shdr_status, shdr_add_status, rc);
  9567. status = -ENXIO;
  9568. }
  9569. /* Remove wq from any list */
  9570. list_del_init(&wq->list);
  9571. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9572. return status;
  9573. }
  9574. /**
  9575. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9576. * @rq: The queue structure associated with the queue to destroy.
  9577. *
  9578. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9579. * command, specific to the type of queue, to the HBA.
  9580. *
  9581. * The @rq struct is used to get the queue ID of the queue to destroy.
  9582. *
  9583. * On success this function will return a zero. If the queue destroy mailbox
  9584. * command fails this function will return ENXIO.
  9585. **/
  9586. uint32_t
  9587. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9588. struct lpfc_queue *drq)
  9589. {
  9590. LPFC_MBOXQ_t *mbox;
  9591. int rc, length, status = 0;
  9592. uint32_t shdr_status, shdr_add_status;
  9593. union lpfc_sli4_cfg_shdr *shdr;
  9594. if (!hrq || !drq)
  9595. return -ENODEV;
  9596. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9597. if (!mbox)
  9598. return -ENOMEM;
  9599. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9600. sizeof(struct mbox_header));
  9601. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9602. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9603. length, LPFC_SLI4_MBX_EMBED);
  9604. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9605. hrq->queue_id);
  9606. mbox->vport = hrq->phba->pport;
  9607. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9608. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9609. /* The IOCTL status is embedded in the mailbox subheader. */
  9610. shdr = (union lpfc_sli4_cfg_shdr *)
  9611. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9612. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9613. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9614. if (shdr_status || shdr_add_status || rc) {
  9615. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9616. "2509 RQ_DESTROY mailbox failed with "
  9617. "status x%x add_status x%x, mbx status x%x\n",
  9618. shdr_status, shdr_add_status, rc);
  9619. if (rc != MBX_TIMEOUT)
  9620. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9621. return -ENXIO;
  9622. }
  9623. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9624. drq->queue_id);
  9625. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9626. shdr = (union lpfc_sli4_cfg_shdr *)
  9627. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9628. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9629. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9630. if (shdr_status || shdr_add_status || rc) {
  9631. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9632. "2510 RQ_DESTROY mailbox failed with "
  9633. "status x%x add_status x%x, mbx status x%x\n",
  9634. shdr_status, shdr_add_status, rc);
  9635. status = -ENXIO;
  9636. }
  9637. list_del_init(&hrq->list);
  9638. list_del_init(&drq->list);
  9639. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9640. return status;
  9641. }
  9642. /**
  9643. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9644. * @phba: The virtual port for which this call being executed.
  9645. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9646. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9647. * @xritag: the xritag that ties this io to the SGL pages.
  9648. *
  9649. * This routine will post the sgl pages for the IO that has the xritag
  9650. * that is in the iocbq structure. The xritag is assigned during iocbq
  9651. * creation and persists for as long as the driver is loaded.
  9652. * if the caller has fewer than 256 scatter gather segments to map then
  9653. * pdma_phys_addr1 should be 0.
  9654. * If the caller needs to map more than 256 scatter gather segment then
  9655. * pdma_phys_addr1 should be a valid physical address.
  9656. * physical address for SGLs must be 64 byte aligned.
  9657. * If you are going to map 2 SGL's then the first one must have 256 entries
  9658. * the second sgl can have between 1 and 256 entries.
  9659. *
  9660. * Return codes:
  9661. * 0 - Success
  9662. * -ENXIO, -ENOMEM - Failure
  9663. **/
  9664. int
  9665. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9666. dma_addr_t pdma_phys_addr0,
  9667. dma_addr_t pdma_phys_addr1,
  9668. uint16_t xritag)
  9669. {
  9670. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9671. LPFC_MBOXQ_t *mbox;
  9672. int rc;
  9673. uint32_t shdr_status, shdr_add_status;
  9674. union lpfc_sli4_cfg_shdr *shdr;
  9675. if (xritag == NO_XRI) {
  9676. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9677. "0364 Invalid param:\n");
  9678. return -EINVAL;
  9679. }
  9680. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9681. if (!mbox)
  9682. return -ENOMEM;
  9683. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9684. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9685. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9686. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9687. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9688. &mbox->u.mqe.un.post_sgl_pages;
  9689. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9690. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9691. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9692. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9693. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9694. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9695. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9696. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9697. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9698. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9699. if (!phba->sli4_hba.intr_enable)
  9700. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9701. else
  9702. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9703. /* The IOCTL status is embedded in the mailbox subheader. */
  9704. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9705. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9706. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9707. if (rc != MBX_TIMEOUT)
  9708. mempool_free(mbox, phba->mbox_mem_pool);
  9709. if (shdr_status || shdr_add_status || rc) {
  9710. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9711. "2511 POST_SGL mailbox failed with "
  9712. "status x%x add_status x%x, mbx status x%x\n",
  9713. shdr_status, shdr_add_status, rc);
  9714. rc = -ENXIO;
  9715. }
  9716. return 0;
  9717. }
  9718. /**
  9719. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9720. * @phba: The virtual port for which this call being executed.
  9721. *
  9722. * This routine will remove all of the sgl pages registered with the hba.
  9723. *
  9724. * Return codes:
  9725. * 0 - Success
  9726. * -ENXIO, -ENOMEM - Failure
  9727. **/
  9728. int
  9729. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9730. {
  9731. LPFC_MBOXQ_t *mbox;
  9732. int rc;
  9733. uint32_t shdr_status, shdr_add_status;
  9734. union lpfc_sli4_cfg_shdr *shdr;
  9735. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9736. if (!mbox)
  9737. return -ENOMEM;
  9738. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9739. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9740. LPFC_SLI4_MBX_EMBED);
  9741. if (!phba->sli4_hba.intr_enable)
  9742. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9743. else
  9744. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9745. /* The IOCTL status is embedded in the mailbox subheader. */
  9746. shdr = (union lpfc_sli4_cfg_shdr *)
  9747. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9748. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9749. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9750. if (rc != MBX_TIMEOUT)
  9751. mempool_free(mbox, phba->mbox_mem_pool);
  9752. if (shdr_status || shdr_add_status || rc) {
  9753. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9754. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9755. "status x%x add_status x%x, mbx status x%x\n",
  9756. shdr_status, shdr_add_status, rc);
  9757. rc = -ENXIO;
  9758. }
  9759. return rc;
  9760. }
  9761. /**
  9762. * lpfc_sli4_next_xritag - Get an xritag for the io
  9763. * @phba: Pointer to HBA context object.
  9764. *
  9765. * This function gets an xritag for the iocb. If there is no unused xritag
  9766. * it will return 0xffff.
  9767. * The function returns the allocated xritag if successful, else returns zero.
  9768. * Zero is not a valid xritag.
  9769. * The caller is not required to hold any lock.
  9770. **/
  9771. uint16_t
  9772. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9773. {
  9774. uint16_t xritag;
  9775. spin_lock_irq(&phba->hbalock);
  9776. xritag = phba->sli4_hba.next_xri;
  9777. if ((xritag != (uint16_t) -1) && xritag <
  9778. (phba->sli4_hba.max_cfg_param.max_xri
  9779. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9780. phba->sli4_hba.next_xri++;
  9781. phba->sli4_hba.max_cfg_param.xri_used++;
  9782. spin_unlock_irq(&phba->hbalock);
  9783. return xritag;
  9784. }
  9785. spin_unlock_irq(&phba->hbalock);
  9786. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9787. "2004 Failed to allocate XRI.last XRITAG is %d"
  9788. " Max XRI is %d, Used XRI is %d\n",
  9789. phba->sli4_hba.next_xri,
  9790. phba->sli4_hba.max_cfg_param.max_xri,
  9791. phba->sli4_hba.max_cfg_param.xri_used);
  9792. return -1;
  9793. }
  9794. /**
  9795. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9796. * @phba: pointer to lpfc hba data structure.
  9797. *
  9798. * This routine is invoked to post a block of driver's sgl pages to the
  9799. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9800. * is only called when the driver is loading and after all IO has been
  9801. * stopped.
  9802. **/
  9803. int
  9804. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9805. {
  9806. struct lpfc_sglq *sglq_entry;
  9807. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9808. struct sgl_page_pairs *sgl_pg_pairs;
  9809. void *viraddr;
  9810. LPFC_MBOXQ_t *mbox;
  9811. uint32_t reqlen, alloclen, pg_pairs;
  9812. uint32_t mbox_tmo;
  9813. uint16_t xritag_start = 0;
  9814. int els_xri_cnt, rc = 0;
  9815. uint32_t shdr_status, shdr_add_status;
  9816. union lpfc_sli4_cfg_shdr *shdr;
  9817. /* The number of sgls to be posted */
  9818. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9819. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9820. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9821. if (reqlen > SLI4_PAGE_SIZE) {
  9822. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9823. "2559 Block sgl registration required DMA "
  9824. "size (%d) great than a page\n", reqlen);
  9825. return -ENOMEM;
  9826. }
  9827. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9828. if (!mbox) {
  9829. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9830. "2560 Failed to allocate mbox cmd memory\n");
  9831. return -ENOMEM;
  9832. }
  9833. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9834. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9835. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9836. LPFC_SLI4_MBX_NEMBED);
  9837. if (alloclen < reqlen) {
  9838. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9839. "0285 Allocated DMA memory size (%d) is "
  9840. "less than the requested DMA memory "
  9841. "size (%d)\n", alloclen, reqlen);
  9842. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9843. return -ENOMEM;
  9844. }
  9845. /* Get the first SGE entry from the non-embedded DMA memory */
  9846. viraddr = mbox->sge_array->addr[0];
  9847. /* Set up the SGL pages in the non-embedded DMA pages */
  9848. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9849. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9850. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9851. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9852. /* Set up the sge entry */
  9853. sgl_pg_pairs->sgl_pg0_addr_lo =
  9854. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9855. sgl_pg_pairs->sgl_pg0_addr_hi =
  9856. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9857. sgl_pg_pairs->sgl_pg1_addr_lo =
  9858. cpu_to_le32(putPaddrLow(0));
  9859. sgl_pg_pairs->sgl_pg1_addr_hi =
  9860. cpu_to_le32(putPaddrHigh(0));
  9861. /* Keep the first xritag on the list */
  9862. if (pg_pairs == 0)
  9863. xritag_start = sglq_entry->sli4_xritag;
  9864. sgl_pg_pairs++;
  9865. }
  9866. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9867. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9868. /* Perform endian conversion if necessary */
  9869. sgl->word0 = cpu_to_le32(sgl->word0);
  9870. if (!phba->sli4_hba.intr_enable)
  9871. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9872. else {
  9873. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9874. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9875. }
  9876. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9877. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9878. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9879. if (rc != MBX_TIMEOUT)
  9880. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9881. if (shdr_status || shdr_add_status || rc) {
  9882. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9883. "2513 POST_SGL_BLOCK mailbox command failed "
  9884. "status x%x add_status x%x mbx status x%x\n",
  9885. shdr_status, shdr_add_status, rc);
  9886. rc = -ENXIO;
  9887. }
  9888. return rc;
  9889. }
  9890. /**
  9891. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9892. * @phba: pointer to lpfc hba data structure.
  9893. * @sblist: pointer to scsi buffer list.
  9894. * @count: number of scsi buffers on the list.
  9895. *
  9896. * This routine is invoked to post a block of @count scsi sgl pages from a
  9897. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9898. * No Lock is held.
  9899. *
  9900. **/
  9901. int
  9902. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9903. int cnt)
  9904. {
  9905. struct lpfc_scsi_buf *psb;
  9906. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9907. struct sgl_page_pairs *sgl_pg_pairs;
  9908. void *viraddr;
  9909. LPFC_MBOXQ_t *mbox;
  9910. uint32_t reqlen, alloclen, pg_pairs;
  9911. uint32_t mbox_tmo;
  9912. uint16_t xritag_start = 0;
  9913. int rc = 0;
  9914. uint32_t shdr_status, shdr_add_status;
  9915. dma_addr_t pdma_phys_bpl1;
  9916. union lpfc_sli4_cfg_shdr *shdr;
  9917. /* Calculate the requested length of the dma memory */
  9918. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9919. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9920. if (reqlen > SLI4_PAGE_SIZE) {
  9921. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9922. "0217 Block sgl registration required DMA "
  9923. "size (%d) great than a page\n", reqlen);
  9924. return -ENOMEM;
  9925. }
  9926. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9927. if (!mbox) {
  9928. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9929. "0283 Failed to allocate mbox cmd memory\n");
  9930. return -ENOMEM;
  9931. }
  9932. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9933. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9934. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9935. LPFC_SLI4_MBX_NEMBED);
  9936. if (alloclen < reqlen) {
  9937. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9938. "2561 Allocated DMA memory size (%d) is "
  9939. "less than the requested DMA memory "
  9940. "size (%d)\n", alloclen, reqlen);
  9941. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9942. return -ENOMEM;
  9943. }
  9944. /* Get the first SGE entry from the non-embedded DMA memory */
  9945. viraddr = mbox->sge_array->addr[0];
  9946. /* Set up the SGL pages in the non-embedded DMA pages */
  9947. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9948. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9949. pg_pairs = 0;
  9950. list_for_each_entry(psb, sblist, list) {
  9951. /* Set up the sge entry */
  9952. sgl_pg_pairs->sgl_pg0_addr_lo =
  9953. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9954. sgl_pg_pairs->sgl_pg0_addr_hi =
  9955. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9956. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9957. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9958. else
  9959. pdma_phys_bpl1 = 0;
  9960. sgl_pg_pairs->sgl_pg1_addr_lo =
  9961. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9962. sgl_pg_pairs->sgl_pg1_addr_hi =
  9963. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9964. /* Keep the first xritag on the list */
  9965. if (pg_pairs == 0)
  9966. xritag_start = psb->cur_iocbq.sli4_xritag;
  9967. sgl_pg_pairs++;
  9968. pg_pairs++;
  9969. }
  9970. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9971. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9972. /* Perform endian conversion if necessary */
  9973. sgl->word0 = cpu_to_le32(sgl->word0);
  9974. if (!phba->sli4_hba.intr_enable)
  9975. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9976. else {
  9977. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9978. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9979. }
  9980. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9981. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9982. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9983. if (rc != MBX_TIMEOUT)
  9984. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9985. if (shdr_status || shdr_add_status || rc) {
  9986. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9987. "2564 POST_SGL_BLOCK mailbox command failed "
  9988. "status x%x add_status x%x mbx status x%x\n",
  9989. shdr_status, shdr_add_status, rc);
  9990. rc = -ENXIO;
  9991. }
  9992. return rc;
  9993. }
  9994. /**
  9995. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9996. * @phba: pointer to lpfc_hba struct that the frame was received on
  9997. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9998. *
  9999. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10000. * valid type of frame that the LPFC driver will handle. This function will
  10001. * return a zero if the frame is a valid frame or a non zero value when the
  10002. * frame does not pass the check.
  10003. **/
  10004. static int
  10005. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10006. {
  10007. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10008. char *type_names[] = FC_TYPE_NAMES_INIT;
  10009. struct fc_vft_header *fc_vft_hdr;
  10010. switch (fc_hdr->fh_r_ctl) {
  10011. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10012. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10013. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10014. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10015. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10016. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10017. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10018. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10019. case FC_RCTL_ELS_REQ: /* extended link services request */
  10020. case FC_RCTL_ELS_REP: /* extended link services reply */
  10021. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10022. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10023. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10024. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10025. case FC_RCTL_BA_RMC: /* remove connection */
  10026. case FC_RCTL_BA_ACC: /* basic accept */
  10027. case FC_RCTL_BA_RJT: /* basic reject */
  10028. case FC_RCTL_BA_PRMT:
  10029. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10030. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10031. case FC_RCTL_P_RJT: /* port reject */
  10032. case FC_RCTL_F_RJT: /* fabric reject */
  10033. case FC_RCTL_P_BSY: /* port busy */
  10034. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10035. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10036. case FC_RCTL_LCR: /* link credit reset */
  10037. case FC_RCTL_END: /* end */
  10038. break;
  10039. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10040. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10041. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10042. return lpfc_fc_frame_check(phba, fc_hdr);
  10043. default:
  10044. goto drop;
  10045. }
  10046. switch (fc_hdr->fh_type) {
  10047. case FC_TYPE_BLS:
  10048. case FC_TYPE_ELS:
  10049. case FC_TYPE_FCP:
  10050. case FC_TYPE_CT:
  10051. break;
  10052. case FC_TYPE_IP:
  10053. case FC_TYPE_ILS:
  10054. default:
  10055. goto drop;
  10056. }
  10057. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10058. "2538 Received frame rctl:%s type:%s\n",
  10059. rctl_names[fc_hdr->fh_r_ctl],
  10060. type_names[fc_hdr->fh_type]);
  10061. return 0;
  10062. drop:
  10063. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10064. "2539 Dropped frame rctl:%s type:%s\n",
  10065. rctl_names[fc_hdr->fh_r_ctl],
  10066. type_names[fc_hdr->fh_type]);
  10067. return 1;
  10068. }
  10069. /**
  10070. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10071. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10072. *
  10073. * This function processes the FC header to retrieve the VFI from the VF
  10074. * header, if one exists. This function will return the VFI if one exists
  10075. * or 0 if no VSAN Header exists.
  10076. **/
  10077. static uint32_t
  10078. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10079. {
  10080. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10081. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10082. return 0;
  10083. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10084. }
  10085. /**
  10086. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10087. * @phba: Pointer to the HBA structure to search for the vport on
  10088. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10089. * @fcfi: The FC Fabric ID that the frame came from
  10090. *
  10091. * This function searches the @phba for a vport that matches the content of the
  10092. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10093. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10094. * returns the matching vport pointer or NULL if unable to match frame to a
  10095. * vport.
  10096. **/
  10097. static struct lpfc_vport *
  10098. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10099. uint16_t fcfi)
  10100. {
  10101. struct lpfc_vport **vports;
  10102. struct lpfc_vport *vport = NULL;
  10103. int i;
  10104. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10105. fc_hdr->fh_d_id[1] << 8 |
  10106. fc_hdr->fh_d_id[2]);
  10107. vports = lpfc_create_vport_work_array(phba);
  10108. if (vports != NULL)
  10109. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10110. if (phba->fcf.fcfi == fcfi &&
  10111. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10112. vports[i]->fc_myDID == did) {
  10113. vport = vports[i];
  10114. break;
  10115. }
  10116. }
  10117. lpfc_destroy_vport_work_array(phba, vports);
  10118. return vport;
  10119. }
  10120. /**
  10121. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10122. * @vport: The vport to work on.
  10123. *
  10124. * This function updates the receive sequence time stamp for this vport. The
  10125. * receive sequence time stamp indicates the time that the last frame of the
  10126. * the sequence that has been idle for the longest amount of time was received.
  10127. * the driver uses this time stamp to indicate if any received sequences have
  10128. * timed out.
  10129. **/
  10130. void
  10131. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10132. {
  10133. struct lpfc_dmabuf *h_buf;
  10134. struct hbq_dmabuf *dmabuf = NULL;
  10135. /* get the oldest sequence on the rcv list */
  10136. h_buf = list_get_first(&vport->rcv_buffer_list,
  10137. struct lpfc_dmabuf, list);
  10138. if (!h_buf)
  10139. return;
  10140. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10141. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10142. }
  10143. /**
  10144. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10145. * @vport: The vport that the received sequences were sent to.
  10146. *
  10147. * This function cleans up all outstanding received sequences. This is called
  10148. * by the driver when a link event or user action invalidates all the received
  10149. * sequences.
  10150. **/
  10151. void
  10152. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10153. {
  10154. struct lpfc_dmabuf *h_buf, *hnext;
  10155. struct lpfc_dmabuf *d_buf, *dnext;
  10156. struct hbq_dmabuf *dmabuf = NULL;
  10157. /* start with the oldest sequence on the rcv list */
  10158. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10159. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10160. list_del_init(&dmabuf->hbuf.list);
  10161. list_for_each_entry_safe(d_buf, dnext,
  10162. &dmabuf->dbuf.list, list) {
  10163. list_del_init(&d_buf->list);
  10164. lpfc_in_buf_free(vport->phba, d_buf);
  10165. }
  10166. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10167. }
  10168. }
  10169. /**
  10170. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10171. * @vport: The vport that the received sequences were sent to.
  10172. *
  10173. * This function determines whether any received sequences have timed out by
  10174. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10175. * indicates that there is at least one timed out sequence this routine will
  10176. * go through the received sequences one at a time from most inactive to most
  10177. * active to determine which ones need to be cleaned up. Once it has determined
  10178. * that a sequence needs to be cleaned up it will simply free up the resources
  10179. * without sending an abort.
  10180. **/
  10181. void
  10182. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10183. {
  10184. struct lpfc_dmabuf *h_buf, *hnext;
  10185. struct lpfc_dmabuf *d_buf, *dnext;
  10186. struct hbq_dmabuf *dmabuf = NULL;
  10187. unsigned long timeout;
  10188. int abort_count = 0;
  10189. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10190. vport->rcv_buffer_time_stamp);
  10191. if (list_empty(&vport->rcv_buffer_list) ||
  10192. time_before(jiffies, timeout))
  10193. return;
  10194. /* start with the oldest sequence on the rcv list */
  10195. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10196. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10197. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10198. dmabuf->time_stamp);
  10199. if (time_before(jiffies, timeout))
  10200. break;
  10201. abort_count++;
  10202. list_del_init(&dmabuf->hbuf.list);
  10203. list_for_each_entry_safe(d_buf, dnext,
  10204. &dmabuf->dbuf.list, list) {
  10205. list_del_init(&d_buf->list);
  10206. lpfc_in_buf_free(vport->phba, d_buf);
  10207. }
  10208. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10209. }
  10210. if (abort_count)
  10211. lpfc_update_rcv_time_stamp(vport);
  10212. }
  10213. /**
  10214. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10215. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10216. *
  10217. * This function searches through the existing incomplete sequences that have
  10218. * been sent to this @vport. If the frame matches one of the incomplete
  10219. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10220. * make up that sequence. If no sequence is found that matches this frame then
  10221. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10222. * This function returns a pointer to the first dmabuf in the sequence list that
  10223. * the frame was linked to.
  10224. **/
  10225. static struct hbq_dmabuf *
  10226. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10227. {
  10228. struct fc_frame_header *new_hdr;
  10229. struct fc_frame_header *temp_hdr;
  10230. struct lpfc_dmabuf *d_buf;
  10231. struct lpfc_dmabuf *h_buf;
  10232. struct hbq_dmabuf *seq_dmabuf = NULL;
  10233. struct hbq_dmabuf *temp_dmabuf = NULL;
  10234. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10235. dmabuf->time_stamp = jiffies;
  10236. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10237. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10238. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10239. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10240. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10241. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10242. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10243. continue;
  10244. /* found a pending sequence that matches this frame */
  10245. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10246. break;
  10247. }
  10248. if (!seq_dmabuf) {
  10249. /*
  10250. * This indicates first frame received for this sequence.
  10251. * Queue the buffer on the vport's rcv_buffer_list.
  10252. */
  10253. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10254. lpfc_update_rcv_time_stamp(vport);
  10255. return dmabuf;
  10256. }
  10257. temp_hdr = seq_dmabuf->hbuf.virt;
  10258. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10259. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10260. list_del_init(&seq_dmabuf->hbuf.list);
  10261. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10262. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10263. lpfc_update_rcv_time_stamp(vport);
  10264. return dmabuf;
  10265. }
  10266. /* move this sequence to the tail to indicate a young sequence */
  10267. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10268. seq_dmabuf->time_stamp = jiffies;
  10269. lpfc_update_rcv_time_stamp(vport);
  10270. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10271. temp_hdr = dmabuf->hbuf.virt;
  10272. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10273. return seq_dmabuf;
  10274. }
  10275. /* find the correct place in the sequence to insert this frame */
  10276. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10277. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10278. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10279. /*
  10280. * If the frame's sequence count is greater than the frame on
  10281. * the list then insert the frame right after this frame
  10282. */
  10283. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10284. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10285. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10286. return seq_dmabuf;
  10287. }
  10288. }
  10289. return NULL;
  10290. }
  10291. /**
  10292. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10293. * @vport: pointer to a vitural port
  10294. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10295. *
  10296. * This function tries to abort from the partially assembed sequence, described
  10297. * by the information from basic abbort @dmabuf. It checks to see whether such
  10298. * partially assembled sequence held by the driver. If so, it shall free up all
  10299. * the frames from the partially assembled sequence.
  10300. *
  10301. * Return
  10302. * true -- if there is matching partially assembled sequence present and all
  10303. * the frames freed with the sequence;
  10304. * false -- if there is no matching partially assembled sequence present so
  10305. * nothing got aborted in the lower layer driver
  10306. **/
  10307. static bool
  10308. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10309. struct hbq_dmabuf *dmabuf)
  10310. {
  10311. struct fc_frame_header *new_hdr;
  10312. struct fc_frame_header *temp_hdr;
  10313. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10314. struct hbq_dmabuf *seq_dmabuf = NULL;
  10315. /* Use the hdr_buf to find the sequence that matches this frame */
  10316. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10317. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10318. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10319. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10320. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10321. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10322. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10323. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10324. continue;
  10325. /* found a pending sequence that matches this frame */
  10326. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10327. break;
  10328. }
  10329. /* Free up all the frames from the partially assembled sequence */
  10330. if (seq_dmabuf) {
  10331. list_for_each_entry_safe(d_buf, n_buf,
  10332. &seq_dmabuf->dbuf.list, list) {
  10333. list_del_init(&d_buf->list);
  10334. lpfc_in_buf_free(vport->phba, d_buf);
  10335. }
  10336. return true;
  10337. }
  10338. return false;
  10339. }
  10340. /**
  10341. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10342. * @phba: Pointer to HBA context object.
  10343. * @cmd_iocbq: pointer to the command iocbq structure.
  10344. * @rsp_iocbq: pointer to the response iocbq structure.
  10345. *
  10346. * This function handles the sequence abort accept iocb command complete
  10347. * event. It properly releases the memory allocated to the sequence abort
  10348. * accept iocb.
  10349. **/
  10350. static void
  10351. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10352. struct lpfc_iocbq *cmd_iocbq,
  10353. struct lpfc_iocbq *rsp_iocbq)
  10354. {
  10355. if (cmd_iocbq)
  10356. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10357. }
  10358. /**
  10359. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10360. * @phba: Pointer to HBA context object.
  10361. * @fc_hdr: pointer to a FC frame header.
  10362. *
  10363. * This function sends a basic accept to a previous unsol sequence abort
  10364. * event after aborting the sequence handling.
  10365. **/
  10366. static void
  10367. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10368. struct fc_frame_header *fc_hdr)
  10369. {
  10370. struct lpfc_iocbq *ctiocb = NULL;
  10371. struct lpfc_nodelist *ndlp;
  10372. uint16_t oxid, rxid;
  10373. uint32_t sid, fctl;
  10374. IOCB_t *icmd;
  10375. if (!lpfc_is_link_up(phba))
  10376. return;
  10377. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10378. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10379. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10380. ndlp = lpfc_findnode_did(phba->pport, sid);
  10381. if (!ndlp) {
  10382. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10383. "1268 Find ndlp returned NULL for oxid:x%x "
  10384. "SID:x%x\n", oxid, sid);
  10385. return;
  10386. }
  10387. /* Allocate buffer for acc iocb */
  10388. ctiocb = lpfc_sli_get_iocbq(phba);
  10389. if (!ctiocb)
  10390. return;
  10391. /* Extract the F_CTL field from FC_HDR */
  10392. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10393. icmd = &ctiocb->iocb;
  10394. icmd->un.xseq64.bdl.bdeSize = 0;
  10395. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10396. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10397. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10398. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10399. /* Fill in the rest of iocb fields */
  10400. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10401. icmd->ulpBdeCount = 0;
  10402. icmd->ulpLe = 1;
  10403. icmd->ulpClass = CLASS3;
  10404. icmd->ulpContext = ndlp->nlp_rpi;
  10405. ctiocb->iocb_cmpl = NULL;
  10406. ctiocb->vport = phba->pport;
  10407. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10408. if (fctl & FC_FC_EX_CTX) {
  10409. /* ABTS sent by responder to CT exchange, construction
  10410. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10411. * field and RX_ID from ABTS for RX_ID field.
  10412. */
  10413. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10414. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10415. ctiocb->sli4_xritag = oxid;
  10416. } else {
  10417. /* ABTS sent by initiator to CT exchange, construction
  10418. * of BA_ACC will need to allocate a new XRI as for the
  10419. * XRI_TAG and RX_ID fields.
  10420. */
  10421. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10422. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10423. ctiocb->sli4_xritag = NO_XRI;
  10424. }
  10425. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10426. /* Xmit CT abts accept on exchange <xid> */
  10427. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10428. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10429. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10430. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10431. }
  10432. /**
  10433. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10434. * @vport: Pointer to the vport on which this sequence was received
  10435. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10436. *
  10437. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10438. * receive sequence is only partially assembed by the driver, it shall abort
  10439. * the partially assembled frames for the sequence. Otherwise, if the
  10440. * unsolicited receive sequence has been completely assembled and passed to
  10441. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10442. * unsolicited sequence has been aborted. After that, it will issue a basic
  10443. * accept to accept the abort.
  10444. **/
  10445. void
  10446. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10447. struct hbq_dmabuf *dmabuf)
  10448. {
  10449. struct lpfc_hba *phba = vport->phba;
  10450. struct fc_frame_header fc_hdr;
  10451. uint32_t fctl;
  10452. bool abts_par;
  10453. /* Make a copy of fc_hdr before the dmabuf being released */
  10454. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10455. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10456. if (fctl & FC_FC_EX_CTX) {
  10457. /*
  10458. * ABTS sent by responder to exchange, just free the buffer
  10459. */
  10460. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10461. } else {
  10462. /*
  10463. * ABTS sent by initiator to exchange, need to do cleanup
  10464. */
  10465. /* Try to abort partially assembled seq */
  10466. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10467. /* Send abort to ULP if partially seq abort failed */
  10468. if (abts_par == false)
  10469. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10470. else
  10471. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10472. }
  10473. /* Send basic accept (BA_ACC) to the abort requester */
  10474. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10475. }
  10476. /**
  10477. * lpfc_seq_complete - Indicates if a sequence is complete
  10478. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10479. *
  10480. * This function checks the sequence, starting with the frame described by
  10481. * @dmabuf, to see if all the frames associated with this sequence are present.
  10482. * the frames associated with this sequence are linked to the @dmabuf using the
  10483. * dbuf list. This function looks for two major things. 1) That the first frame
  10484. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10485. * set. 3) That there are no holes in the sequence count. The function will
  10486. * return 1 when the sequence is complete, otherwise it will return 0.
  10487. **/
  10488. static int
  10489. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10490. {
  10491. struct fc_frame_header *hdr;
  10492. struct lpfc_dmabuf *d_buf;
  10493. struct hbq_dmabuf *seq_dmabuf;
  10494. uint32_t fctl;
  10495. int seq_count = 0;
  10496. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10497. /* make sure first fame of sequence has a sequence count of zero */
  10498. if (hdr->fh_seq_cnt != seq_count)
  10499. return 0;
  10500. fctl = (hdr->fh_f_ctl[0] << 16 |
  10501. hdr->fh_f_ctl[1] << 8 |
  10502. hdr->fh_f_ctl[2]);
  10503. /* If last frame of sequence we can return success. */
  10504. if (fctl & FC_FC_END_SEQ)
  10505. return 1;
  10506. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10507. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10508. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10509. /* If there is a hole in the sequence count then fail. */
  10510. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10511. return 0;
  10512. fctl = (hdr->fh_f_ctl[0] << 16 |
  10513. hdr->fh_f_ctl[1] << 8 |
  10514. hdr->fh_f_ctl[2]);
  10515. /* If last frame of sequence we can return success. */
  10516. if (fctl & FC_FC_END_SEQ)
  10517. return 1;
  10518. }
  10519. return 0;
  10520. }
  10521. /**
  10522. * lpfc_prep_seq - Prep sequence for ULP processing
  10523. * @vport: Pointer to the vport on which this sequence was received
  10524. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10525. *
  10526. * This function takes a sequence, described by a list of frames, and creates
  10527. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10528. * used to issue to the generic unsolicited sequence handler. This routine
  10529. * returns a pointer to the first iocbq in the list. If the function is unable
  10530. * to allocate an iocbq then it throw out the received frames that were not
  10531. * able to be described and return a pointer to the first iocbq. If unable to
  10532. * allocate any iocbqs (including the first) this function will return NULL.
  10533. **/
  10534. static struct lpfc_iocbq *
  10535. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10536. {
  10537. struct lpfc_dmabuf *d_buf, *n_buf;
  10538. struct lpfc_iocbq *first_iocbq, *iocbq;
  10539. struct fc_frame_header *fc_hdr;
  10540. uint32_t sid;
  10541. struct ulp_bde64 *pbde;
  10542. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10543. /* remove from receive buffer list */
  10544. list_del_init(&seq_dmabuf->hbuf.list);
  10545. lpfc_update_rcv_time_stamp(vport);
  10546. /* get the Remote Port's SID */
  10547. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10548. /* Get an iocbq struct to fill in. */
  10549. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10550. if (first_iocbq) {
  10551. /* Initialize the first IOCB. */
  10552. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10553. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10554. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10555. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10556. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10557. vport->vpi + vport->phba->vpi_base;
  10558. /* put the first buffer into the first IOCBq */
  10559. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10560. first_iocbq->context3 = NULL;
  10561. first_iocbq->iocb.ulpBdeCount = 1;
  10562. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10563. LPFC_DATA_BUF_SIZE;
  10564. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10565. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10566. bf_get(lpfc_rcqe_length,
  10567. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10568. }
  10569. iocbq = first_iocbq;
  10570. /*
  10571. * Each IOCBq can have two Buffers assigned, so go through the list
  10572. * of buffers for this sequence and save two buffers in each IOCBq
  10573. */
  10574. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10575. if (!iocbq) {
  10576. lpfc_in_buf_free(vport->phba, d_buf);
  10577. continue;
  10578. }
  10579. if (!iocbq->context3) {
  10580. iocbq->context3 = d_buf;
  10581. iocbq->iocb.ulpBdeCount++;
  10582. pbde = (struct ulp_bde64 *)
  10583. &iocbq->iocb.unsli3.sli3Words[4];
  10584. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10585. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10586. bf_get(lpfc_rcqe_length,
  10587. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10588. } else {
  10589. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10590. if (!iocbq) {
  10591. if (first_iocbq) {
  10592. first_iocbq->iocb.ulpStatus =
  10593. IOSTAT_FCP_RSP_ERROR;
  10594. first_iocbq->iocb.un.ulpWord[4] =
  10595. IOERR_NO_RESOURCES;
  10596. }
  10597. lpfc_in_buf_free(vport->phba, d_buf);
  10598. continue;
  10599. }
  10600. iocbq->context2 = d_buf;
  10601. iocbq->context3 = NULL;
  10602. iocbq->iocb.ulpBdeCount = 1;
  10603. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10604. LPFC_DATA_BUF_SIZE;
  10605. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10606. bf_get(lpfc_rcqe_length,
  10607. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10608. iocbq->iocb.un.rcvels.remoteID = sid;
  10609. list_add_tail(&iocbq->list, &first_iocbq->list);
  10610. }
  10611. }
  10612. return first_iocbq;
  10613. }
  10614. static void
  10615. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10616. struct hbq_dmabuf *seq_dmabuf)
  10617. {
  10618. struct fc_frame_header *fc_hdr;
  10619. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10620. struct lpfc_hba *phba = vport->phba;
  10621. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10622. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10623. if (!iocbq) {
  10624. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10625. "2707 Ring %d handler: Failed to allocate "
  10626. "iocb Rctl x%x Type x%x received\n",
  10627. LPFC_ELS_RING,
  10628. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10629. return;
  10630. }
  10631. if (!lpfc_complete_unsol_iocb(phba,
  10632. &phba->sli.ring[LPFC_ELS_RING],
  10633. iocbq, fc_hdr->fh_r_ctl,
  10634. fc_hdr->fh_type))
  10635. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10636. "2540 Ring %d handler: unexpected Rctl "
  10637. "x%x Type x%x received\n",
  10638. LPFC_ELS_RING,
  10639. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10640. /* Free iocb created in lpfc_prep_seq */
  10641. list_for_each_entry_safe(curr_iocb, next_iocb,
  10642. &iocbq->list, list) {
  10643. list_del_init(&curr_iocb->list);
  10644. lpfc_sli_release_iocbq(phba, curr_iocb);
  10645. }
  10646. lpfc_sli_release_iocbq(phba, iocbq);
  10647. }
  10648. /**
  10649. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10650. * @phba: Pointer to HBA context object.
  10651. *
  10652. * This function is called with no lock held. This function processes all
  10653. * the received buffers and gives it to upper layers when a received buffer
  10654. * indicates that it is the final frame in the sequence. The interrupt
  10655. * service routine processes received buffers at interrupt contexts and adds
  10656. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10657. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10658. * appropriate receive function when the final frame in a sequence is received.
  10659. **/
  10660. void
  10661. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10662. struct hbq_dmabuf *dmabuf)
  10663. {
  10664. struct hbq_dmabuf *seq_dmabuf;
  10665. struct fc_frame_header *fc_hdr;
  10666. struct lpfc_vport *vport;
  10667. uint32_t fcfi;
  10668. /* Process each received buffer */
  10669. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10670. /* check to see if this a valid type of frame */
  10671. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10672. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10673. return;
  10674. }
  10675. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10676. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10677. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10678. /* throw out the frame */
  10679. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10680. return;
  10681. }
  10682. /* Handle the basic abort sequence (BA_ABTS) event */
  10683. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10684. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10685. return;
  10686. }
  10687. /* Link this frame */
  10688. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10689. if (!seq_dmabuf) {
  10690. /* unable to add frame to vport - throw it out */
  10691. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10692. return;
  10693. }
  10694. /* If not last frame in sequence continue processing frames. */
  10695. if (!lpfc_seq_complete(seq_dmabuf))
  10696. return;
  10697. /* Send the complete sequence to the upper layer protocol */
  10698. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10699. }
  10700. /**
  10701. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10702. * @phba: pointer to lpfc hba data structure.
  10703. *
  10704. * This routine is invoked to post rpi header templates to the
  10705. * HBA consistent with the SLI-4 interface spec. This routine
  10706. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10707. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10708. *
  10709. * This routine does not require any locks. It's usage is expected
  10710. * to be driver load or reset recovery when the driver is
  10711. * sequential.
  10712. *
  10713. * Return codes
  10714. * 0 - successful
  10715. * EIO - The mailbox failed to complete successfully.
  10716. * When this error occurs, the driver is not guaranteed
  10717. * to have any rpi regions posted to the device and
  10718. * must either attempt to repost the regions or take a
  10719. * fatal error.
  10720. **/
  10721. int
  10722. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10723. {
  10724. struct lpfc_rpi_hdr *rpi_page;
  10725. uint32_t rc = 0;
  10726. /* Post all rpi memory regions to the port. */
  10727. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10728. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10729. if (rc != MBX_SUCCESS) {
  10730. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10731. "2008 Error %d posting all rpi "
  10732. "headers\n", rc);
  10733. rc = -EIO;
  10734. break;
  10735. }
  10736. }
  10737. return rc;
  10738. }
  10739. /**
  10740. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10741. * @phba: pointer to lpfc hba data structure.
  10742. * @rpi_page: pointer to the rpi memory region.
  10743. *
  10744. * This routine is invoked to post a single rpi header to the
  10745. * HBA consistent with the SLI-4 interface spec. This memory region
  10746. * maps up to 64 rpi context regions.
  10747. *
  10748. * Return codes
  10749. * 0 - successful
  10750. * ENOMEM - No available memory
  10751. * EIO - The mailbox failed to complete successfully.
  10752. **/
  10753. int
  10754. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10755. {
  10756. LPFC_MBOXQ_t *mboxq;
  10757. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10758. uint32_t rc = 0;
  10759. uint32_t mbox_tmo;
  10760. uint32_t shdr_status, shdr_add_status;
  10761. union lpfc_sli4_cfg_shdr *shdr;
  10762. /* The port is notified of the header region via a mailbox command. */
  10763. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10764. if (!mboxq) {
  10765. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10766. "2001 Unable to allocate memory for issuing "
  10767. "SLI_CONFIG_SPECIAL mailbox command\n");
  10768. return -ENOMEM;
  10769. }
  10770. /* Post all rpi memory regions to the port. */
  10771. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10772. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10773. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10774. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10775. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10776. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10777. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10778. hdr_tmpl, rpi_page->page_count);
  10779. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10780. rpi_page->start_rpi);
  10781. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10782. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10783. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10784. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10785. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10786. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10787. if (rc != MBX_TIMEOUT)
  10788. mempool_free(mboxq, phba->mbox_mem_pool);
  10789. if (shdr_status || shdr_add_status || rc) {
  10790. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10791. "2514 POST_RPI_HDR mailbox failed with "
  10792. "status x%x add_status x%x, mbx status x%x\n",
  10793. shdr_status, shdr_add_status, rc);
  10794. rc = -ENXIO;
  10795. }
  10796. return rc;
  10797. }
  10798. /**
  10799. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10800. * @phba: pointer to lpfc hba data structure.
  10801. *
  10802. * This routine is invoked to post rpi header templates to the
  10803. * HBA consistent with the SLI-4 interface spec. This routine
  10804. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10805. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10806. *
  10807. * Returns
  10808. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10809. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10810. **/
  10811. int
  10812. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10813. {
  10814. int rpi;
  10815. uint16_t max_rpi, rpi_base, rpi_limit;
  10816. uint16_t rpi_remaining;
  10817. struct lpfc_rpi_hdr *rpi_hdr;
  10818. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10819. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10820. rpi_limit = phba->sli4_hba.next_rpi;
  10821. /*
  10822. * The valid rpi range is not guaranteed to be zero-based. Start
  10823. * the search at the rpi_base as reported by the port.
  10824. */
  10825. spin_lock_irq(&phba->hbalock);
  10826. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10827. if (rpi >= rpi_limit || rpi < rpi_base)
  10828. rpi = LPFC_RPI_ALLOC_ERROR;
  10829. else {
  10830. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10831. phba->sli4_hba.max_cfg_param.rpi_used++;
  10832. phba->sli4_hba.rpi_count++;
  10833. }
  10834. /*
  10835. * Don't try to allocate more rpi header regions if the device limit
  10836. * on available rpis max has been exhausted.
  10837. */
  10838. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10839. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10840. spin_unlock_irq(&phba->hbalock);
  10841. return rpi;
  10842. }
  10843. /*
  10844. * If the driver is running low on rpi resources, allocate another
  10845. * page now. Note that the next_rpi value is used because
  10846. * it represents how many are actually in use whereas max_rpi notes
  10847. * how many are supported max by the device.
  10848. */
  10849. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10850. phba->sli4_hba.rpi_count;
  10851. spin_unlock_irq(&phba->hbalock);
  10852. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10853. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10854. if (!rpi_hdr) {
  10855. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10856. "2002 Error Could not grow rpi "
  10857. "count\n");
  10858. } else {
  10859. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10860. }
  10861. }
  10862. return rpi;
  10863. }
  10864. /**
  10865. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10866. * @phba: pointer to lpfc hba data structure.
  10867. *
  10868. * This routine is invoked to release an rpi to the pool of
  10869. * available rpis maintained by the driver.
  10870. **/
  10871. void
  10872. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10873. {
  10874. spin_lock_irq(&phba->hbalock);
  10875. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10876. phba->sli4_hba.rpi_count--;
  10877. phba->sli4_hba.max_cfg_param.rpi_used--;
  10878. spin_unlock_irq(&phba->hbalock);
  10879. }
  10880. /**
  10881. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10882. * @phba: pointer to lpfc hba data structure.
  10883. *
  10884. * This routine is invoked to remove the memory region that
  10885. * provided rpi via a bitmask.
  10886. **/
  10887. void
  10888. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10889. {
  10890. kfree(phba->sli4_hba.rpi_bmask);
  10891. }
  10892. /**
  10893. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10894. * @phba: pointer to lpfc hba data structure.
  10895. *
  10896. * This routine is invoked to remove the memory region that
  10897. * provided rpi via a bitmask.
  10898. **/
  10899. int
  10900. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10901. {
  10902. LPFC_MBOXQ_t *mboxq;
  10903. struct lpfc_hba *phba = ndlp->phba;
  10904. int rc;
  10905. /* The port is notified of the header region via a mailbox command. */
  10906. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10907. if (!mboxq)
  10908. return -ENOMEM;
  10909. /* Post all rpi memory regions to the port. */
  10910. lpfc_resume_rpi(mboxq, ndlp);
  10911. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10912. if (rc == MBX_NOT_FINISHED) {
  10913. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10914. "2010 Resume RPI Mailbox failed "
  10915. "status %d, mbxStatus x%x\n", rc,
  10916. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10917. mempool_free(mboxq, phba->mbox_mem_pool);
  10918. return -EIO;
  10919. }
  10920. return 0;
  10921. }
  10922. /**
  10923. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10924. * @phba: pointer to lpfc hba data structure.
  10925. * @vpi: vpi value to activate with the port.
  10926. *
  10927. * This routine is invoked to activate a vpi with the
  10928. * port when the host intends to use vports with a
  10929. * nonzero vpi.
  10930. *
  10931. * Returns:
  10932. * 0 success
  10933. * -Evalue otherwise
  10934. **/
  10935. int
  10936. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10937. {
  10938. LPFC_MBOXQ_t *mboxq;
  10939. int rc = 0;
  10940. int retval = MBX_SUCCESS;
  10941. uint32_t mbox_tmo;
  10942. if (vpi == 0)
  10943. return -EINVAL;
  10944. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10945. if (!mboxq)
  10946. return -ENOMEM;
  10947. lpfc_init_vpi(phba, mboxq, vpi);
  10948. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10949. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10950. if (rc != MBX_SUCCESS) {
  10951. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10952. "2022 INIT VPI Mailbox failed "
  10953. "status %d, mbxStatus x%x\n", rc,
  10954. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10955. retval = -EIO;
  10956. }
  10957. if (rc != MBX_TIMEOUT)
  10958. mempool_free(mboxq, phba->mbox_mem_pool);
  10959. return retval;
  10960. }
  10961. /**
  10962. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10963. * @phba: pointer to lpfc hba data structure.
  10964. * @mboxq: Pointer to mailbox object.
  10965. *
  10966. * This routine is invoked to manually add a single FCF record. The caller
  10967. * must pass a completely initialized FCF_Record. This routine takes
  10968. * care of the nonembedded mailbox operations.
  10969. **/
  10970. static void
  10971. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10972. {
  10973. void *virt_addr;
  10974. union lpfc_sli4_cfg_shdr *shdr;
  10975. uint32_t shdr_status, shdr_add_status;
  10976. virt_addr = mboxq->sge_array->addr[0];
  10977. /* The IOCTL status is embedded in the mailbox subheader. */
  10978. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10979. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10980. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10981. if ((shdr_status || shdr_add_status) &&
  10982. (shdr_status != STATUS_FCF_IN_USE))
  10983. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10984. "2558 ADD_FCF_RECORD mailbox failed with "
  10985. "status x%x add_status x%x\n",
  10986. shdr_status, shdr_add_status);
  10987. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10988. }
  10989. /**
  10990. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10991. * @phba: pointer to lpfc hba data structure.
  10992. * @fcf_record: pointer to the initialized fcf record to add.
  10993. *
  10994. * This routine is invoked to manually add a single FCF record. The caller
  10995. * must pass a completely initialized FCF_Record. This routine takes
  10996. * care of the nonembedded mailbox operations.
  10997. **/
  10998. int
  10999. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11000. {
  11001. int rc = 0;
  11002. LPFC_MBOXQ_t *mboxq;
  11003. uint8_t *bytep;
  11004. void *virt_addr;
  11005. dma_addr_t phys_addr;
  11006. struct lpfc_mbx_sge sge;
  11007. uint32_t alloc_len, req_len;
  11008. uint32_t fcfindex;
  11009. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11010. if (!mboxq) {
  11011. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11012. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11013. return -ENOMEM;
  11014. }
  11015. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11016. sizeof(uint32_t);
  11017. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11018. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11019. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11020. req_len, LPFC_SLI4_MBX_NEMBED);
  11021. if (alloc_len < req_len) {
  11022. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11023. "2523 Allocated DMA memory size (x%x) is "
  11024. "less than the requested DMA memory "
  11025. "size (x%x)\n", alloc_len, req_len);
  11026. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11027. return -ENOMEM;
  11028. }
  11029. /*
  11030. * Get the first SGE entry from the non-embedded DMA memory. This
  11031. * routine only uses a single SGE.
  11032. */
  11033. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11034. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11035. virt_addr = mboxq->sge_array->addr[0];
  11036. /*
  11037. * Configure the FCF record for FCFI 0. This is the driver's
  11038. * hardcoded default and gets used in nonFIP mode.
  11039. */
  11040. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11041. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11042. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11043. /*
  11044. * Copy the fcf_index and the FCF Record Data. The data starts after
  11045. * the FCoE header plus word10. The data copy needs to be endian
  11046. * correct.
  11047. */
  11048. bytep += sizeof(uint32_t);
  11049. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11050. mboxq->vport = phba->pport;
  11051. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11052. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11053. if (rc == MBX_NOT_FINISHED) {
  11054. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11055. "2515 ADD_FCF_RECORD mailbox failed with "
  11056. "status 0x%x\n", rc);
  11057. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11058. rc = -EIO;
  11059. } else
  11060. rc = 0;
  11061. return rc;
  11062. }
  11063. /**
  11064. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11065. * @phba: pointer to lpfc hba data structure.
  11066. * @fcf_record: pointer to the fcf record to write the default data.
  11067. * @fcf_index: FCF table entry index.
  11068. *
  11069. * This routine is invoked to build the driver's default FCF record. The
  11070. * values used are hardcoded. This routine handles memory initialization.
  11071. *
  11072. **/
  11073. void
  11074. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11075. struct fcf_record *fcf_record,
  11076. uint16_t fcf_index)
  11077. {
  11078. memset(fcf_record, 0, sizeof(struct fcf_record));
  11079. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11080. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11081. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11082. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11083. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11084. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11085. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11086. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11087. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11088. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11089. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11090. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11091. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11092. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11093. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11094. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11095. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11096. /* Set the VLAN bit map */
  11097. if (phba->valid_vlan) {
  11098. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11099. = 1 << (phba->vlan_id % 8);
  11100. }
  11101. }
  11102. /**
  11103. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11104. * @phba: pointer to lpfc hba data structure.
  11105. * @fcf_index: FCF table entry offset.
  11106. *
  11107. * This routine is invoked to scan the entire FCF table by reading FCF
  11108. * record and processing it one at a time starting from the @fcf_index
  11109. * for initial FCF discovery or fast FCF failover rediscovery.
  11110. *
  11111. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11112. * otherwise.
  11113. **/
  11114. int
  11115. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11116. {
  11117. int rc = 0, error;
  11118. LPFC_MBOXQ_t *mboxq;
  11119. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11120. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11121. if (!mboxq) {
  11122. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11123. "2000 Failed to allocate mbox for "
  11124. "READ_FCF cmd\n");
  11125. error = -ENOMEM;
  11126. goto fail_fcf_scan;
  11127. }
  11128. /* Construct the read FCF record mailbox command */
  11129. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11130. if (rc) {
  11131. error = -EINVAL;
  11132. goto fail_fcf_scan;
  11133. }
  11134. /* Issue the mailbox command asynchronously */
  11135. mboxq->vport = phba->pport;
  11136. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11137. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11138. if (rc == MBX_NOT_FINISHED)
  11139. error = -EIO;
  11140. else {
  11141. spin_lock_irq(&phba->hbalock);
  11142. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11143. spin_unlock_irq(&phba->hbalock);
  11144. /* Reset FCF round robin index bmask for new scan */
  11145. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) {
  11146. memset(phba->fcf.fcf_rr_bmask, 0,
  11147. sizeof(*phba->fcf.fcf_rr_bmask));
  11148. phba->fcf.eligible_fcf_cnt = 0;
  11149. }
  11150. error = 0;
  11151. }
  11152. fail_fcf_scan:
  11153. if (error) {
  11154. if (mboxq)
  11155. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11156. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11157. spin_lock_irq(&phba->hbalock);
  11158. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11159. spin_unlock_irq(&phba->hbalock);
  11160. }
  11161. return error;
  11162. }
  11163. /**
  11164. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11165. * @phba: pointer to lpfc hba data structure.
  11166. * @fcf_index: FCF table entry offset.
  11167. *
  11168. * This routine is invoked to read an FCF record indicated by @fcf_index
  11169. * and to use it for FLOGI round robin FCF failover.
  11170. *
  11171. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11172. * otherwise.
  11173. **/
  11174. int
  11175. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11176. {
  11177. int rc = 0, error;
  11178. LPFC_MBOXQ_t *mboxq;
  11179. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11180. if (!mboxq) {
  11181. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11182. "2763 Failed to allocate mbox for "
  11183. "READ_FCF cmd\n");
  11184. error = -ENOMEM;
  11185. goto fail_fcf_read;
  11186. }
  11187. /* Construct the read FCF record mailbox command */
  11188. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11189. if (rc) {
  11190. error = -EINVAL;
  11191. goto fail_fcf_read;
  11192. }
  11193. /* Issue the mailbox command asynchronously */
  11194. mboxq->vport = phba->pport;
  11195. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11196. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11197. if (rc == MBX_NOT_FINISHED)
  11198. error = -EIO;
  11199. else
  11200. error = 0;
  11201. fail_fcf_read:
  11202. if (error && mboxq)
  11203. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11204. return error;
  11205. }
  11206. /**
  11207. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11208. * @phba: pointer to lpfc hba data structure.
  11209. * @fcf_index: FCF table entry offset.
  11210. *
  11211. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11212. * determine whether it's eligible for FLOGI round robin failover list.
  11213. *
  11214. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11215. * otherwise.
  11216. **/
  11217. int
  11218. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11219. {
  11220. int rc = 0, error;
  11221. LPFC_MBOXQ_t *mboxq;
  11222. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11223. if (!mboxq) {
  11224. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11225. "2758 Failed to allocate mbox for "
  11226. "READ_FCF cmd\n");
  11227. error = -ENOMEM;
  11228. goto fail_fcf_read;
  11229. }
  11230. /* Construct the read FCF record mailbox command */
  11231. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11232. if (rc) {
  11233. error = -EINVAL;
  11234. goto fail_fcf_read;
  11235. }
  11236. /* Issue the mailbox command asynchronously */
  11237. mboxq->vport = phba->pport;
  11238. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11239. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11240. if (rc == MBX_NOT_FINISHED)
  11241. error = -EIO;
  11242. else
  11243. error = 0;
  11244. fail_fcf_read:
  11245. if (error && mboxq)
  11246. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11247. return error;
  11248. }
  11249. /**
  11250. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11251. * @phba: pointer to lpfc hba data structure.
  11252. *
  11253. * This routine is to get the next eligible FCF record index in a round
  11254. * robin fashion. If the next eligible FCF record index equals to the
  11255. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11256. * shall be returned, otherwise, the next eligible FCF record's index
  11257. * shall be returned.
  11258. **/
  11259. uint16_t
  11260. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11261. {
  11262. uint16_t next_fcf_index;
  11263. /* Search from the currently registered FCF index */
  11264. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11265. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11266. phba->fcf.current_rec.fcf_indx);
  11267. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11268. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11269. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11270. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11271. /* Round robin failover stop condition */
  11272. if (next_fcf_index == phba->fcf.fcf_rr_init_indx)
  11273. return LPFC_FCOE_FCF_NEXT_NONE;
  11274. return next_fcf_index;
  11275. }
  11276. /**
  11277. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11278. * @phba: pointer to lpfc hba data structure.
  11279. *
  11280. * This routine sets the FCF record index in to the eligible bmask for
  11281. * round robin failover search. It checks to make sure that the index
  11282. * does not go beyond the range of the driver allocated bmask dimension
  11283. * before setting the bit.
  11284. *
  11285. * Returns 0 if the index bit successfully set, otherwise, it returns
  11286. * -EINVAL.
  11287. **/
  11288. int
  11289. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11290. {
  11291. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11292. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11293. "2610 HBA FCF index reached driver's "
  11294. "book keeping dimension: fcf_index:%d, "
  11295. "driver_bmask_max:%d\n",
  11296. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11297. return -EINVAL;
  11298. }
  11299. /* Set the eligible FCF record index bmask */
  11300. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11301. return 0;
  11302. }
  11303. /**
  11304. * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
  11305. * @phba: pointer to lpfc hba data structure.
  11306. *
  11307. * This routine clears the FCF record index from the eligible bmask for
  11308. * round robin failover search. It checks to make sure that the index
  11309. * does not go beyond the range of the driver allocated bmask dimension
  11310. * before clearing the bit.
  11311. **/
  11312. void
  11313. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11314. {
  11315. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11316. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11317. "2762 HBA FCF index goes beyond driver's "
  11318. "book keeping dimension: fcf_index:%d, "
  11319. "driver_bmask_max:%d\n",
  11320. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11321. return;
  11322. }
  11323. /* Clear the eligible FCF record index bmask */
  11324. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11325. }
  11326. /**
  11327. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11328. * @phba: pointer to lpfc hba data structure.
  11329. *
  11330. * This routine is the completion routine for the rediscover FCF table mailbox
  11331. * command. If the mailbox command returned failure, it will try to stop the
  11332. * FCF rediscover wait timer.
  11333. **/
  11334. void
  11335. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11336. {
  11337. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11338. uint32_t shdr_status, shdr_add_status;
  11339. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11340. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11341. &redisc_fcf->header.cfg_shdr.response);
  11342. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11343. &redisc_fcf->header.cfg_shdr.response);
  11344. if (shdr_status || shdr_add_status) {
  11345. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11346. "2746 Requesting for FCF rediscovery failed "
  11347. "status x%x add_status x%x\n",
  11348. shdr_status, shdr_add_status);
  11349. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11350. spin_lock_irq(&phba->hbalock);
  11351. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11352. spin_unlock_irq(&phba->hbalock);
  11353. /*
  11354. * CVL event triggered FCF rediscover request failed,
  11355. * last resort to re-try current registered FCF entry.
  11356. */
  11357. lpfc_retry_pport_discovery(phba);
  11358. } else {
  11359. spin_lock_irq(&phba->hbalock);
  11360. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11361. spin_unlock_irq(&phba->hbalock);
  11362. /*
  11363. * DEAD FCF event triggered FCF rediscover request
  11364. * failed, last resort to fail over as a link down
  11365. * to FCF registration.
  11366. */
  11367. lpfc_sli4_fcf_dead_failthrough(phba);
  11368. }
  11369. } else {
  11370. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11371. "2775 Start FCF rediscovery quiescent period "
  11372. "wait timer before scaning FCF table\n");
  11373. /*
  11374. * Start FCF rediscovery wait timer for pending FCF
  11375. * before rescan FCF record table.
  11376. */
  11377. lpfc_fcf_redisc_wait_start_timer(phba);
  11378. }
  11379. mempool_free(mbox, phba->mbox_mem_pool);
  11380. }
  11381. /**
  11382. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11383. * @phba: pointer to lpfc hba data structure.
  11384. *
  11385. * This routine is invoked to request for rediscovery of the entire FCF table
  11386. * by the port.
  11387. **/
  11388. int
  11389. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11390. {
  11391. LPFC_MBOXQ_t *mbox;
  11392. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11393. int rc, length;
  11394. /* Cancel retry delay timers to all vports before FCF rediscover */
  11395. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11396. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11397. if (!mbox) {
  11398. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11399. "2745 Failed to allocate mbox for "
  11400. "requesting FCF rediscover.\n");
  11401. return -ENOMEM;
  11402. }
  11403. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11404. sizeof(struct lpfc_sli4_cfg_mhdr));
  11405. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11406. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11407. length, LPFC_SLI4_MBX_EMBED);
  11408. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11409. /* Set count to 0 for invalidating the entire FCF database */
  11410. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11411. /* Issue the mailbox command asynchronously */
  11412. mbox->vport = phba->pport;
  11413. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11414. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11415. if (rc == MBX_NOT_FINISHED) {
  11416. mempool_free(mbox, phba->mbox_mem_pool);
  11417. return -EIO;
  11418. }
  11419. return 0;
  11420. }
  11421. /**
  11422. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11423. * @phba: pointer to lpfc hba data structure.
  11424. *
  11425. * This function is the failover routine as a last resort to the FCF DEAD
  11426. * event when driver failed to perform fast FCF failover.
  11427. **/
  11428. void
  11429. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11430. {
  11431. uint32_t link_state;
  11432. /*
  11433. * Last resort as FCF DEAD event failover will treat this as
  11434. * a link down, but save the link state because we don't want
  11435. * it to be changed to Link Down unless it is already down.
  11436. */
  11437. link_state = phba->link_state;
  11438. lpfc_linkdown(phba);
  11439. phba->link_state = link_state;
  11440. /* Unregister FCF if no devices connected to it */
  11441. lpfc_unregister_unused_fcf(phba);
  11442. }
  11443. /**
  11444. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11445. * @phba: pointer to lpfc hba data structure.
  11446. *
  11447. * This function read region 23 and parse TLV for port status to
  11448. * decide if the user disaled the port. If the TLV indicates the
  11449. * port is disabled, the hba_flag is set accordingly.
  11450. **/
  11451. void
  11452. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11453. {
  11454. LPFC_MBOXQ_t *pmb = NULL;
  11455. MAILBOX_t *mb;
  11456. uint8_t *rgn23_data = NULL;
  11457. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11458. int rc;
  11459. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11460. if (!pmb) {
  11461. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11462. "2600 lpfc_sli_read_serdes_param failed to"
  11463. " allocate mailbox memory\n");
  11464. goto out;
  11465. }
  11466. mb = &pmb->u.mb;
  11467. /* Get adapter Region 23 data */
  11468. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11469. if (!rgn23_data)
  11470. goto out;
  11471. do {
  11472. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11473. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11474. if (rc != MBX_SUCCESS) {
  11475. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11476. "2601 lpfc_sli_read_link_ste failed to"
  11477. " read config region 23 rc 0x%x Status 0x%x\n",
  11478. rc, mb->mbxStatus);
  11479. mb->un.varDmp.word_cnt = 0;
  11480. }
  11481. /*
  11482. * dump mem may return a zero when finished or we got a
  11483. * mailbox error, either way we are done.
  11484. */
  11485. if (mb->un.varDmp.word_cnt == 0)
  11486. break;
  11487. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11488. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11489. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11490. rgn23_data + offset,
  11491. mb->un.varDmp.word_cnt);
  11492. offset += mb->un.varDmp.word_cnt;
  11493. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11494. data_size = offset;
  11495. offset = 0;
  11496. if (!data_size)
  11497. goto out;
  11498. /* Check the region signature first */
  11499. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11500. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11501. "2619 Config region 23 has bad signature\n");
  11502. goto out;
  11503. }
  11504. offset += 4;
  11505. /* Check the data structure version */
  11506. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11507. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11508. "2620 Config region 23 has bad version\n");
  11509. goto out;
  11510. }
  11511. offset += 4;
  11512. /* Parse TLV entries in the region */
  11513. while (offset < data_size) {
  11514. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11515. break;
  11516. /*
  11517. * If the TLV is not driver specific TLV or driver id is
  11518. * not linux driver id, skip the record.
  11519. */
  11520. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11521. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11522. (rgn23_data[offset + 3] != 0)) {
  11523. offset += rgn23_data[offset + 1] * 4 + 4;
  11524. continue;
  11525. }
  11526. /* Driver found a driver specific TLV in the config region */
  11527. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11528. offset += 4;
  11529. tlv_offset = 0;
  11530. /*
  11531. * Search for configured port state sub-TLV.
  11532. */
  11533. while ((offset < data_size) &&
  11534. (tlv_offset < sub_tlv_len)) {
  11535. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11536. offset += 4;
  11537. tlv_offset += 4;
  11538. break;
  11539. }
  11540. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11541. offset += rgn23_data[offset + 1] * 4 + 4;
  11542. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11543. continue;
  11544. }
  11545. /* This HBA contains PORT_STE configured */
  11546. if (!rgn23_data[offset + 2])
  11547. phba->hba_flag |= LINK_DISABLED;
  11548. goto out;
  11549. }
  11550. }
  11551. out:
  11552. if (pmb)
  11553. mempool_free(pmb, phba->mbox_mem_pool);
  11554. kfree(rgn23_data);
  11555. return;
  11556. }
  11557. /**
  11558. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11559. * @vport: pointer to vport data structure.
  11560. *
  11561. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11562. * and REG_VPI mailbox commands associated with the vport. This function
  11563. * is called when driver want to restart discovery of the vport due to
  11564. * a Clear Virtual Link event.
  11565. **/
  11566. void
  11567. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11568. {
  11569. struct lpfc_hba *phba = vport->phba;
  11570. LPFC_MBOXQ_t *mb, *nextmb;
  11571. struct lpfc_dmabuf *mp;
  11572. struct lpfc_nodelist *ndlp;
  11573. spin_lock_irq(&phba->hbalock);
  11574. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11575. if (mb->vport != vport)
  11576. continue;
  11577. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11578. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11579. continue;
  11580. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11581. mp = (struct lpfc_dmabuf *) (mb->context1);
  11582. if (mp) {
  11583. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11584. kfree(mp);
  11585. }
  11586. ndlp = (struct lpfc_nodelist *) mb->context2;
  11587. if (ndlp) {
  11588. lpfc_nlp_put(ndlp);
  11589. mb->context2 = NULL;
  11590. }
  11591. }
  11592. list_del(&mb->list);
  11593. mempool_free(mb, phba->mbox_mem_pool);
  11594. }
  11595. mb = phba->sli.mbox_active;
  11596. if (mb && (mb->vport == vport)) {
  11597. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11598. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11599. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11600. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11601. ndlp = (struct lpfc_nodelist *) mb->context2;
  11602. if (ndlp) {
  11603. lpfc_nlp_put(ndlp);
  11604. mb->context2 = NULL;
  11605. }
  11606. /* Unregister the RPI when mailbox complete */
  11607. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11608. }
  11609. }
  11610. spin_unlock_irq(&phba->hbalock);
  11611. }