lpfc_sli.c 397 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871
  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. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  473. * @phba: Pointer to HBA context object.
  474. *
  475. * This function is called with hbalock held. This function
  476. * Gets a new driver sglq object from the sglq list. If the
  477. * list is not empty then it is successful, it returns pointer to the newly
  478. * allocated sglq object else it returns NULL.
  479. **/
  480. static struct lpfc_sglq *
  481. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  482. {
  483. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  484. struct lpfc_sglq *sglq = NULL;
  485. uint16_t adj_xri;
  486. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  487. if (!sglq)
  488. return NULL;
  489. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  490. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  491. sglq->state = SGL_ALLOCATED;
  492. return sglq;
  493. }
  494. /**
  495. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  496. * @phba: Pointer to HBA context object.
  497. *
  498. * This function is called with no lock held. This function
  499. * allocates a new driver iocb object from the iocb pool. If the
  500. * allocation is successful, it returns pointer to the newly
  501. * allocated iocb object else it returns NULL.
  502. **/
  503. struct lpfc_iocbq *
  504. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  505. {
  506. struct lpfc_iocbq * iocbq = NULL;
  507. unsigned long iflags;
  508. spin_lock_irqsave(&phba->hbalock, iflags);
  509. iocbq = __lpfc_sli_get_iocbq(phba);
  510. spin_unlock_irqrestore(&phba->hbalock, iflags);
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  515. * @phba: Pointer to HBA context object.
  516. * @iocbq: Pointer to driver iocb object.
  517. *
  518. * This function is called with hbalock held to release driver
  519. * iocb object to the iocb pool. The iotag in the iocb object
  520. * does not change for each use of the iocb object. This function
  521. * clears all other fields of the iocb object when it is freed.
  522. * The sqlq structure that holds the xritag and phys and virtual
  523. * mappings for the scatter gather list is retrieved from the
  524. * active array of sglq. The get of the sglq pointer also clears
  525. * the entry in the array. If the status of the IO indiactes that
  526. * this IO was aborted then the sglq entry it put on the
  527. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  528. * IO has good status or fails for any other reason then the sglq
  529. * entry is added to the free list (lpfc_sgl_list).
  530. **/
  531. static void
  532. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  533. {
  534. struct lpfc_sglq *sglq;
  535. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  536. unsigned long iflag = 0;
  537. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  538. if (iocbq->sli4_xritag == NO_XRI)
  539. sglq = NULL;
  540. else
  541. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  542. if (sglq) {
  543. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  544. (sglq->state != SGL_XRI_ABORTED)) {
  545. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  546. iflag);
  547. list_add(&sglq->list,
  548. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  549. spin_unlock_irqrestore(
  550. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  551. } else {
  552. sglq->state = SGL_FREED;
  553. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  554. /* Check if TXQ queue needs to be serviced */
  555. if (pring->txq_cnt) {
  556. spin_lock_irqsave(
  557. &phba->pport->work_port_lock, iflag);
  558. phba->pport->work_port_events |=
  559. WORKER_SERVICE_TXQ;
  560. lpfc_worker_wake_up(phba);
  561. spin_unlock_irqrestore(
  562. &phba->pport->work_port_lock, iflag);
  563. }
  564. }
  565. }
  566. /*
  567. * Clean all volatile data fields, preserve iotag and node struct.
  568. */
  569. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  570. iocbq->sli4_xritag = NO_XRI;
  571. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  572. }
  573. /**
  574. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  575. * @phba: Pointer to HBA context object.
  576. * @iocbq: Pointer to driver iocb object.
  577. *
  578. * This function is called with hbalock held to release driver
  579. * iocb object to the iocb pool. The iotag in the iocb object
  580. * does not change for each use of the iocb object. This function
  581. * clears all other fields of the iocb object when it is freed.
  582. **/
  583. static void
  584. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  585. {
  586. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  587. /*
  588. * Clean all volatile data fields, preserve iotag and node struct.
  589. */
  590. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  591. iocbq->sli4_xritag = NO_XRI;
  592. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  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 hbalock held to release driver
  600. * iocb object to the iocb pool. The iotag in the iocb object
  601. * does not change for each use of the iocb object. This function
  602. * clears all other fields of the iocb object when it is freed.
  603. **/
  604. static void
  605. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  606. {
  607. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  608. phba->iocb_cnt--;
  609. }
  610. /**
  611. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  612. * @phba: Pointer to HBA context object.
  613. * @iocbq: Pointer to driver iocb object.
  614. *
  615. * This function is called with no lock held to release the iocb to
  616. * iocb pool.
  617. **/
  618. void
  619. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  620. {
  621. unsigned long iflags;
  622. /*
  623. * Clean all volatile data fields, preserve iotag and node struct.
  624. */
  625. spin_lock_irqsave(&phba->hbalock, iflags);
  626. __lpfc_sli_release_iocbq(phba, iocbq);
  627. spin_unlock_irqrestore(&phba->hbalock, iflags);
  628. }
  629. /**
  630. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  631. * @phba: Pointer to HBA context object.
  632. * @iocblist: List of IOCBs.
  633. * @ulpstatus: ULP status in IOCB command field.
  634. * @ulpWord4: ULP word-4 in IOCB command field.
  635. *
  636. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  637. * on the list by invoking the complete callback function associated with the
  638. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  639. * fields.
  640. **/
  641. void
  642. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  643. uint32_t ulpstatus, uint32_t ulpWord4)
  644. {
  645. struct lpfc_iocbq *piocb;
  646. while (!list_empty(iocblist)) {
  647. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  648. if (!piocb->iocb_cmpl)
  649. lpfc_sli_release_iocbq(phba, piocb);
  650. else {
  651. piocb->iocb.ulpStatus = ulpstatus;
  652. piocb->iocb.un.ulpWord[4] = ulpWord4;
  653. (piocb->iocb_cmpl) (phba, piocb, piocb);
  654. }
  655. }
  656. return;
  657. }
  658. /**
  659. * lpfc_sli_iocb_cmd_type - Get the iocb type
  660. * @iocb_cmnd: iocb command code.
  661. *
  662. * This function is called by ring event handler function to get the iocb type.
  663. * This function translates the iocb command to an iocb command type used to
  664. * decide the final disposition of each completed IOCB.
  665. * The function returns
  666. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  667. * LPFC_SOL_IOCB if it is a solicited iocb completion
  668. * LPFC_ABORT_IOCB if it is an abort iocb
  669. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  670. *
  671. * The caller is not required to hold any lock.
  672. **/
  673. static lpfc_iocb_type
  674. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  675. {
  676. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  677. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  678. return 0;
  679. switch (iocb_cmnd) {
  680. case CMD_XMIT_SEQUENCE_CR:
  681. case CMD_XMIT_SEQUENCE_CX:
  682. case CMD_XMIT_BCAST_CN:
  683. case CMD_XMIT_BCAST_CX:
  684. case CMD_ELS_REQUEST_CR:
  685. case CMD_ELS_REQUEST_CX:
  686. case CMD_CREATE_XRI_CR:
  687. case CMD_CREATE_XRI_CX:
  688. case CMD_GET_RPI_CN:
  689. case CMD_XMIT_ELS_RSP_CX:
  690. case CMD_GET_RPI_CR:
  691. case CMD_FCP_IWRITE_CR:
  692. case CMD_FCP_IWRITE_CX:
  693. case CMD_FCP_IREAD_CR:
  694. case CMD_FCP_IREAD_CX:
  695. case CMD_FCP_ICMND_CR:
  696. case CMD_FCP_ICMND_CX:
  697. case CMD_FCP_TSEND_CX:
  698. case CMD_FCP_TRSP_CX:
  699. case CMD_FCP_TRECEIVE_CX:
  700. case CMD_FCP_AUTO_TRSP_CX:
  701. case CMD_ADAPTER_MSG:
  702. case CMD_ADAPTER_DUMP:
  703. case CMD_XMIT_SEQUENCE64_CR:
  704. case CMD_XMIT_SEQUENCE64_CX:
  705. case CMD_XMIT_BCAST64_CN:
  706. case CMD_XMIT_BCAST64_CX:
  707. case CMD_ELS_REQUEST64_CR:
  708. case CMD_ELS_REQUEST64_CX:
  709. case CMD_FCP_IWRITE64_CR:
  710. case CMD_FCP_IWRITE64_CX:
  711. case CMD_FCP_IREAD64_CR:
  712. case CMD_FCP_IREAD64_CX:
  713. case CMD_FCP_ICMND64_CR:
  714. case CMD_FCP_ICMND64_CX:
  715. case CMD_FCP_TSEND64_CX:
  716. case CMD_FCP_TRSP64_CX:
  717. case CMD_FCP_TRECEIVE64_CX:
  718. case CMD_GEN_REQUEST64_CR:
  719. case CMD_GEN_REQUEST64_CX:
  720. case CMD_XMIT_ELS_RSP64_CX:
  721. case DSSCMD_IWRITE64_CR:
  722. case DSSCMD_IWRITE64_CX:
  723. case DSSCMD_IREAD64_CR:
  724. case DSSCMD_IREAD64_CX:
  725. type = LPFC_SOL_IOCB;
  726. break;
  727. case CMD_ABORT_XRI_CN:
  728. case CMD_ABORT_XRI_CX:
  729. case CMD_CLOSE_XRI_CN:
  730. case CMD_CLOSE_XRI_CX:
  731. case CMD_XRI_ABORTED_CX:
  732. case CMD_ABORT_MXRI64_CN:
  733. case CMD_XMIT_BLS_RSP64_CX:
  734. type = LPFC_ABORT_IOCB;
  735. break;
  736. case CMD_RCV_SEQUENCE_CX:
  737. case CMD_RCV_ELS_REQ_CX:
  738. case CMD_RCV_SEQUENCE64_CX:
  739. case CMD_RCV_ELS_REQ64_CX:
  740. case CMD_ASYNC_STATUS:
  741. case CMD_IOCB_RCV_SEQ64_CX:
  742. case CMD_IOCB_RCV_ELS64_CX:
  743. case CMD_IOCB_RCV_CONT64_CX:
  744. case CMD_IOCB_RET_XRI64_CX:
  745. type = LPFC_UNSOL_IOCB;
  746. break;
  747. case CMD_IOCB_XMIT_MSEQ64_CR:
  748. case CMD_IOCB_XMIT_MSEQ64_CX:
  749. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  750. case CMD_IOCB_RCV_ELS_LIST64_CX:
  751. case CMD_IOCB_CLOSE_EXTENDED_CN:
  752. case CMD_IOCB_ABORT_EXTENDED_CN:
  753. case CMD_IOCB_RET_HBQE64_CN:
  754. case CMD_IOCB_FCP_IBIDIR64_CR:
  755. case CMD_IOCB_FCP_IBIDIR64_CX:
  756. case CMD_IOCB_FCP_ITASKMGT64_CX:
  757. case CMD_IOCB_LOGENTRY_CN:
  758. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  759. printk("%s - Unhandled SLI-3 Command x%x\n",
  760. __func__, iocb_cmnd);
  761. type = LPFC_UNKNOWN_IOCB;
  762. break;
  763. default:
  764. type = LPFC_UNKNOWN_IOCB;
  765. break;
  766. }
  767. return type;
  768. }
  769. /**
  770. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  771. * @phba: Pointer to HBA context object.
  772. *
  773. * This function is called from SLI initialization code
  774. * to configure every ring of the HBA's SLI interface. The
  775. * caller is not required to hold any lock. This function issues
  776. * a config_ring mailbox command for each ring.
  777. * This function returns zero if successful else returns a negative
  778. * error code.
  779. **/
  780. static int
  781. lpfc_sli_ring_map(struct lpfc_hba *phba)
  782. {
  783. struct lpfc_sli *psli = &phba->sli;
  784. LPFC_MBOXQ_t *pmb;
  785. MAILBOX_t *pmbox;
  786. int i, rc, ret = 0;
  787. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  788. if (!pmb)
  789. return -ENOMEM;
  790. pmbox = &pmb->u.mb;
  791. phba->link_state = LPFC_INIT_MBX_CMDS;
  792. for (i = 0; i < psli->num_rings; i++) {
  793. lpfc_config_ring(phba, i, pmb);
  794. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  795. if (rc != MBX_SUCCESS) {
  796. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  797. "0446 Adapter failed to init (%d), "
  798. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  799. "ring %d\n",
  800. rc, pmbox->mbxCommand,
  801. pmbox->mbxStatus, i);
  802. phba->link_state = LPFC_HBA_ERROR;
  803. ret = -ENXIO;
  804. break;
  805. }
  806. }
  807. mempool_free(pmb, phba->mbox_mem_pool);
  808. return ret;
  809. }
  810. /**
  811. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  812. * @phba: Pointer to HBA context object.
  813. * @pring: Pointer to driver SLI ring object.
  814. * @piocb: Pointer to the driver iocb object.
  815. *
  816. * This function is called with hbalock held. The function adds the
  817. * new iocb to txcmplq of the given ring. This function always returns
  818. * 0. If this function is called for ELS ring, this function checks if
  819. * there is a vport associated with the ELS command. This function also
  820. * starts els_tmofunc timer if this is an ELS command.
  821. **/
  822. static int
  823. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  824. struct lpfc_iocbq *piocb)
  825. {
  826. list_add_tail(&piocb->list, &pring->txcmplq);
  827. piocb->iocb_flag |= LPFC_IO_ON_Q;
  828. pring->txcmplq_cnt++;
  829. if (pring->txcmplq_cnt > pring->txcmplq_max)
  830. pring->txcmplq_max = pring->txcmplq_cnt;
  831. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  832. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  833. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  834. if (!piocb->vport)
  835. BUG();
  836. else
  837. mod_timer(&piocb->vport->els_tmofunc,
  838. jiffies + HZ * (phba->fc_ratov << 1));
  839. }
  840. return 0;
  841. }
  842. /**
  843. * lpfc_sli_ringtx_get - Get first element of the txq
  844. * @phba: Pointer to HBA context object.
  845. * @pring: Pointer to driver SLI ring object.
  846. *
  847. * This function is called with hbalock held to get next
  848. * iocb in txq of the given ring. If there is any iocb in
  849. * the txq, the function returns first iocb in the list after
  850. * removing the iocb from the list, else it returns NULL.
  851. **/
  852. struct lpfc_iocbq *
  853. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  854. {
  855. struct lpfc_iocbq *cmd_iocb;
  856. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  857. if (cmd_iocb != NULL)
  858. pring->txq_cnt--;
  859. return cmd_iocb;
  860. }
  861. /**
  862. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  863. * @phba: Pointer to HBA context object.
  864. * @pring: Pointer to driver SLI ring object.
  865. *
  866. * This function is called with hbalock held and the caller must post the
  867. * iocb without releasing the lock. If the caller releases the lock,
  868. * iocb slot returned by the function is not guaranteed to be available.
  869. * The function returns pointer to the next available iocb slot if there
  870. * is available slot in the ring, else it returns NULL.
  871. * If the get index of the ring is ahead of the put index, the function
  872. * will post an error attention event to the worker thread to take the
  873. * HBA to offline state.
  874. **/
  875. static IOCB_t *
  876. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  877. {
  878. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  879. uint32_t max_cmd_idx = pring->numCiocb;
  880. if ((pring->next_cmdidx == pring->cmdidx) &&
  881. (++pring->next_cmdidx >= max_cmd_idx))
  882. pring->next_cmdidx = 0;
  883. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  884. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  885. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  886. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  887. "0315 Ring %d issue: portCmdGet %d "
  888. "is bigger than cmd ring %d\n",
  889. pring->ringno,
  890. pring->local_getidx, max_cmd_idx);
  891. phba->link_state = LPFC_HBA_ERROR;
  892. /*
  893. * All error attention handlers are posted to
  894. * worker thread
  895. */
  896. phba->work_ha |= HA_ERATT;
  897. phba->work_hs = HS_FFER3;
  898. lpfc_worker_wake_up(phba);
  899. return NULL;
  900. }
  901. if (pring->local_getidx == pring->next_cmdidx)
  902. return NULL;
  903. }
  904. return lpfc_cmd_iocb(phba, pring);
  905. }
  906. /**
  907. * lpfc_sli_next_iotag - Get an iotag for the iocb
  908. * @phba: Pointer to HBA context object.
  909. * @iocbq: Pointer to driver iocb object.
  910. *
  911. * This function gets an iotag for the iocb. If there is no unused iotag and
  912. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  913. * array and assigns a new iotag.
  914. * The function returns the allocated iotag if successful, else returns zero.
  915. * Zero is not a valid iotag.
  916. * The caller is not required to hold any lock.
  917. **/
  918. uint16_t
  919. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  920. {
  921. struct lpfc_iocbq **new_arr;
  922. struct lpfc_iocbq **old_arr;
  923. size_t new_len;
  924. struct lpfc_sli *psli = &phba->sli;
  925. uint16_t iotag;
  926. spin_lock_irq(&phba->hbalock);
  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. } else if (psli->iocbq_lookup_len < (0xffff
  935. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  936. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  937. spin_unlock_irq(&phba->hbalock);
  938. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  939. GFP_KERNEL);
  940. if (new_arr) {
  941. spin_lock_irq(&phba->hbalock);
  942. old_arr = psli->iocbq_lookup;
  943. if (new_len <= psli->iocbq_lookup_len) {
  944. /* highly unprobable case */
  945. kfree(new_arr);
  946. iotag = psli->last_iotag;
  947. if(++iotag < psli->iocbq_lookup_len) {
  948. psli->last_iotag = iotag;
  949. psli->iocbq_lookup[iotag] = iocbq;
  950. spin_unlock_irq(&phba->hbalock);
  951. iocbq->iotag = iotag;
  952. return iotag;
  953. }
  954. spin_unlock_irq(&phba->hbalock);
  955. return 0;
  956. }
  957. if (psli->iocbq_lookup)
  958. memcpy(new_arr, old_arr,
  959. ((psli->last_iotag + 1) *
  960. sizeof (struct lpfc_iocbq *)));
  961. psli->iocbq_lookup = new_arr;
  962. psli->iocbq_lookup_len = new_len;
  963. psli->last_iotag = iotag;
  964. psli->iocbq_lookup[iotag] = iocbq;
  965. spin_unlock_irq(&phba->hbalock);
  966. iocbq->iotag = iotag;
  967. kfree(old_arr);
  968. return iotag;
  969. }
  970. } else
  971. spin_unlock_irq(&phba->hbalock);
  972. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  973. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  974. psli->last_iotag);
  975. return 0;
  976. }
  977. /**
  978. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  979. * @phba: Pointer to HBA context object.
  980. * @pring: Pointer to driver SLI ring object.
  981. * @iocb: Pointer to iocb slot in the ring.
  982. * @nextiocb: Pointer to driver iocb object which need to be
  983. * posted to firmware.
  984. *
  985. * This function is called with hbalock held to post a new iocb to
  986. * the firmware. This function copies the new iocb to ring iocb slot and
  987. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  988. * a completion call back for this iocb else the function will free the
  989. * iocb object.
  990. **/
  991. static void
  992. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  993. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  994. {
  995. /*
  996. * Set up an iotag
  997. */
  998. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  999. if (pring->ringno == LPFC_ELS_RING) {
  1000. lpfc_debugfs_slow_ring_trc(phba,
  1001. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1002. *(((uint32_t *) &nextiocb->iocb) + 4),
  1003. *(((uint32_t *) &nextiocb->iocb) + 6),
  1004. *(((uint32_t *) &nextiocb->iocb) + 7));
  1005. }
  1006. /*
  1007. * Issue iocb command to adapter
  1008. */
  1009. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1010. wmb();
  1011. pring->stats.iocb_cmd++;
  1012. /*
  1013. * If there is no completion routine to call, we can release the
  1014. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1015. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1016. */
  1017. if (nextiocb->iocb_cmpl)
  1018. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1019. else
  1020. __lpfc_sli_release_iocbq(phba, nextiocb);
  1021. /*
  1022. * Let the HBA know what IOCB slot will be the next one the
  1023. * driver will put a command into.
  1024. */
  1025. pring->cmdidx = pring->next_cmdidx;
  1026. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1027. }
  1028. /**
  1029. * lpfc_sli_update_full_ring - Update the chip attention register
  1030. * @phba: Pointer to HBA context object.
  1031. * @pring: Pointer to driver SLI ring object.
  1032. *
  1033. * The caller is not required to hold any lock for calling this function.
  1034. * This function updates the chip attention bits for the ring to inform firmware
  1035. * that there are pending work to be done for this ring and requests an
  1036. * interrupt when there is space available in the ring. This function is
  1037. * called when the driver is unable to post more iocbs to the ring due
  1038. * to unavailability of space in the ring.
  1039. **/
  1040. static void
  1041. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1042. {
  1043. int ringno = pring->ringno;
  1044. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1045. wmb();
  1046. /*
  1047. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1048. * The HBA will tell us when an IOCB entry is available.
  1049. */
  1050. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1051. readl(phba->CAregaddr); /* flush */
  1052. pring->stats.iocb_cmd_full++;
  1053. }
  1054. /**
  1055. * lpfc_sli_update_ring - Update chip attention register
  1056. * @phba: Pointer to HBA context object.
  1057. * @pring: Pointer to driver SLI ring object.
  1058. *
  1059. * This function updates the chip attention register bit for the
  1060. * given ring to inform HBA that there is more work to be done
  1061. * in this ring. The caller is not required to hold any lock.
  1062. **/
  1063. static void
  1064. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1065. {
  1066. int ringno = pring->ringno;
  1067. /*
  1068. * Tell the HBA that there is work to do in this ring.
  1069. */
  1070. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1071. wmb();
  1072. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1073. readl(phba->CAregaddr); /* flush */
  1074. }
  1075. }
  1076. /**
  1077. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1078. * @phba: Pointer to HBA context object.
  1079. * @pring: Pointer to driver SLI ring object.
  1080. *
  1081. * This function is called with hbalock held to post pending iocbs
  1082. * in the txq to the firmware. This function is called when driver
  1083. * detects space available in the ring.
  1084. **/
  1085. static void
  1086. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1087. {
  1088. IOCB_t *iocb;
  1089. struct lpfc_iocbq *nextiocb;
  1090. /*
  1091. * Check to see if:
  1092. * (a) there is anything on the txq to send
  1093. * (b) link is up
  1094. * (c) link attention events can be processed (fcp ring only)
  1095. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1096. */
  1097. if (pring->txq_cnt &&
  1098. lpfc_is_link_up(phba) &&
  1099. (pring->ringno != phba->sli.fcp_ring ||
  1100. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1101. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1102. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1103. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1104. if (iocb)
  1105. lpfc_sli_update_ring(phba, pring);
  1106. else
  1107. lpfc_sli_update_full_ring(phba, pring);
  1108. }
  1109. return;
  1110. }
  1111. /**
  1112. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1113. * @phba: Pointer to HBA context object.
  1114. * @hbqno: HBQ number.
  1115. *
  1116. * This function is called with hbalock held to get the next
  1117. * available slot for the given HBQ. If there is free slot
  1118. * available for the HBQ it will return pointer to the next available
  1119. * HBQ entry else it will return NULL.
  1120. **/
  1121. static struct lpfc_hbq_entry *
  1122. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1123. {
  1124. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1125. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1126. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1127. hbqp->next_hbqPutIdx = 0;
  1128. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1129. uint32_t raw_index = phba->hbq_get[hbqno];
  1130. uint32_t getidx = le32_to_cpu(raw_index);
  1131. hbqp->local_hbqGetIdx = getidx;
  1132. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1133. lpfc_printf_log(phba, KERN_ERR,
  1134. LOG_SLI | LOG_VPORT,
  1135. "1802 HBQ %d: local_hbqGetIdx "
  1136. "%u is > than hbqp->entry_count %u\n",
  1137. hbqno, hbqp->local_hbqGetIdx,
  1138. hbqp->entry_count);
  1139. phba->link_state = LPFC_HBA_ERROR;
  1140. return NULL;
  1141. }
  1142. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1143. return NULL;
  1144. }
  1145. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1146. hbqp->hbqPutIdx;
  1147. }
  1148. /**
  1149. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1150. * @phba: Pointer to HBA context object.
  1151. *
  1152. * This function is called with no lock held to free all the
  1153. * hbq buffers while uninitializing the SLI interface. It also
  1154. * frees the HBQ buffers returned by the firmware but not yet
  1155. * processed by the upper layers.
  1156. **/
  1157. void
  1158. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1159. {
  1160. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1161. struct hbq_dmabuf *hbq_buf;
  1162. unsigned long flags;
  1163. int i, hbq_count;
  1164. uint32_t hbqno;
  1165. hbq_count = lpfc_sli_hbq_count();
  1166. /* Return all memory used by all HBQs */
  1167. spin_lock_irqsave(&phba->hbalock, flags);
  1168. for (i = 0; i < hbq_count; ++i) {
  1169. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1170. &phba->hbqs[i].hbq_buffer_list, list) {
  1171. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1172. list_del(&hbq_buf->dbuf.list);
  1173. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1174. }
  1175. phba->hbqs[i].buffer_count = 0;
  1176. }
  1177. /* Return all HBQ buffer that are in-fly */
  1178. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1179. list) {
  1180. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1181. list_del(&hbq_buf->dbuf.list);
  1182. if (hbq_buf->tag == -1) {
  1183. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1184. (phba, hbq_buf);
  1185. } else {
  1186. hbqno = hbq_buf->tag >> 16;
  1187. if (hbqno >= LPFC_MAX_HBQS)
  1188. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1189. (phba, hbq_buf);
  1190. else
  1191. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1192. hbq_buf);
  1193. }
  1194. }
  1195. /* Mark the HBQs not in use */
  1196. phba->hbq_in_use = 0;
  1197. spin_unlock_irqrestore(&phba->hbalock, flags);
  1198. }
  1199. /**
  1200. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1201. * @phba: Pointer to HBA context object.
  1202. * @hbqno: HBQ number.
  1203. * @hbq_buf: Pointer to HBQ buffer.
  1204. *
  1205. * This function is called with the hbalock held to post a
  1206. * hbq buffer to the firmware. If the function finds an empty
  1207. * slot in the HBQ, it will post the buffer. The function will return
  1208. * pointer to the hbq entry if it successfully post the buffer
  1209. * else it will return NULL.
  1210. **/
  1211. static int
  1212. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1213. struct hbq_dmabuf *hbq_buf)
  1214. {
  1215. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1216. }
  1217. /**
  1218. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1219. * @phba: Pointer to HBA context object.
  1220. * @hbqno: HBQ number.
  1221. * @hbq_buf: Pointer to HBQ buffer.
  1222. *
  1223. * This function is called with the hbalock held to post a hbq buffer to the
  1224. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1225. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1226. * it successfully post the buffer else it will return an error.
  1227. **/
  1228. static int
  1229. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1230. struct hbq_dmabuf *hbq_buf)
  1231. {
  1232. struct lpfc_hbq_entry *hbqe;
  1233. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1234. /* Get next HBQ entry slot to use */
  1235. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1236. if (hbqe) {
  1237. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1238. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1239. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1240. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1241. hbqe->bde.tus.f.bdeFlags = 0;
  1242. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1243. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1244. /* Sync SLIM */
  1245. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1246. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1247. /* flush */
  1248. readl(phba->hbq_put + hbqno);
  1249. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1250. return 0;
  1251. } else
  1252. return -ENOMEM;
  1253. }
  1254. /**
  1255. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1256. * @phba: Pointer to HBA context object.
  1257. * @hbqno: HBQ number.
  1258. * @hbq_buf: Pointer to HBQ buffer.
  1259. *
  1260. * This function is called with the hbalock held to post an RQE to the SLI4
  1261. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1262. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1263. **/
  1264. static int
  1265. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1266. struct hbq_dmabuf *hbq_buf)
  1267. {
  1268. int rc;
  1269. struct lpfc_rqe hrqe;
  1270. struct lpfc_rqe drqe;
  1271. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1272. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1273. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1274. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1275. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1276. &hrqe, &drqe);
  1277. if (rc < 0)
  1278. return rc;
  1279. hbq_buf->tag = rc;
  1280. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1281. return 0;
  1282. }
  1283. /* HBQ for ELS and CT traffic. */
  1284. static struct lpfc_hbq_init lpfc_els_hbq = {
  1285. .rn = 1,
  1286. .entry_count = 256,
  1287. .mask_count = 0,
  1288. .profile = 0,
  1289. .ring_mask = (1 << LPFC_ELS_RING),
  1290. .buffer_count = 0,
  1291. .init_count = 40,
  1292. .add_count = 40,
  1293. };
  1294. /* HBQ for the extra ring if needed */
  1295. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1296. .rn = 1,
  1297. .entry_count = 200,
  1298. .mask_count = 0,
  1299. .profile = 0,
  1300. .ring_mask = (1 << LPFC_EXTRA_RING),
  1301. .buffer_count = 0,
  1302. .init_count = 0,
  1303. .add_count = 5,
  1304. };
  1305. /* Array of HBQs */
  1306. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1307. &lpfc_els_hbq,
  1308. &lpfc_extra_hbq,
  1309. };
  1310. /**
  1311. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1312. * @phba: Pointer to HBA context object.
  1313. * @hbqno: HBQ number.
  1314. * @count: Number of HBQ buffers to be posted.
  1315. *
  1316. * This function is called with no lock held to post more hbq buffers to the
  1317. * given HBQ. The function returns the number of HBQ buffers successfully
  1318. * posted.
  1319. **/
  1320. static int
  1321. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1322. {
  1323. uint32_t i, posted = 0;
  1324. unsigned long flags;
  1325. struct hbq_dmabuf *hbq_buffer;
  1326. LIST_HEAD(hbq_buf_list);
  1327. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1328. return 0;
  1329. if ((phba->hbqs[hbqno].buffer_count + count) >
  1330. lpfc_hbq_defs[hbqno]->entry_count)
  1331. count = lpfc_hbq_defs[hbqno]->entry_count -
  1332. phba->hbqs[hbqno].buffer_count;
  1333. if (!count)
  1334. return 0;
  1335. /* Allocate HBQ entries */
  1336. for (i = 0; i < count; i++) {
  1337. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1338. if (!hbq_buffer)
  1339. break;
  1340. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1341. }
  1342. /* Check whether HBQ is still in use */
  1343. spin_lock_irqsave(&phba->hbalock, flags);
  1344. if (!phba->hbq_in_use)
  1345. goto err;
  1346. while (!list_empty(&hbq_buf_list)) {
  1347. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1348. dbuf.list);
  1349. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1350. (hbqno << 16));
  1351. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1352. phba->hbqs[hbqno].buffer_count++;
  1353. posted++;
  1354. } else
  1355. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1356. }
  1357. spin_unlock_irqrestore(&phba->hbalock, flags);
  1358. return posted;
  1359. err:
  1360. spin_unlock_irqrestore(&phba->hbalock, flags);
  1361. while (!list_empty(&hbq_buf_list)) {
  1362. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1363. dbuf.list);
  1364. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1365. }
  1366. return 0;
  1367. }
  1368. /**
  1369. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1370. * @phba: Pointer to HBA context object.
  1371. * @qno: HBQ number.
  1372. *
  1373. * This function posts more buffers to the HBQ. This function
  1374. * is called with no lock held. The function returns the number of HBQ entries
  1375. * successfully allocated.
  1376. **/
  1377. int
  1378. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1379. {
  1380. if (phba->sli_rev == LPFC_SLI_REV4)
  1381. return 0;
  1382. else
  1383. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1384. lpfc_hbq_defs[qno]->add_count);
  1385. }
  1386. /**
  1387. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1388. * @phba: Pointer to HBA context object.
  1389. * @qno: HBQ queue number.
  1390. *
  1391. * This function is called from SLI initialization code path with
  1392. * no lock held to post initial HBQ buffers to firmware. The
  1393. * function returns the number of HBQ entries successfully allocated.
  1394. **/
  1395. static int
  1396. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1397. {
  1398. if (phba->sli_rev == LPFC_SLI_REV4)
  1399. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1400. lpfc_hbq_defs[qno]->entry_count);
  1401. else
  1402. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1403. lpfc_hbq_defs[qno]->init_count);
  1404. }
  1405. /**
  1406. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1407. * @phba: Pointer to HBA context object.
  1408. * @hbqno: HBQ number.
  1409. *
  1410. * This function removes the first hbq buffer on an hbq list and returns a
  1411. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1412. **/
  1413. static struct hbq_dmabuf *
  1414. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1415. {
  1416. struct lpfc_dmabuf *d_buf;
  1417. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1418. if (!d_buf)
  1419. return NULL;
  1420. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1421. }
  1422. /**
  1423. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1424. * @phba: Pointer to HBA context object.
  1425. * @tag: Tag of the hbq buffer.
  1426. *
  1427. * This function is called with hbalock held. This function searches
  1428. * for the hbq buffer associated with the given tag in the hbq buffer
  1429. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1430. * it returns NULL.
  1431. **/
  1432. static struct hbq_dmabuf *
  1433. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1434. {
  1435. struct lpfc_dmabuf *d_buf;
  1436. struct hbq_dmabuf *hbq_buf;
  1437. uint32_t hbqno;
  1438. hbqno = tag >> 16;
  1439. if (hbqno >= LPFC_MAX_HBQS)
  1440. return NULL;
  1441. spin_lock_irq(&phba->hbalock);
  1442. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1443. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1444. if (hbq_buf->tag == tag) {
  1445. spin_unlock_irq(&phba->hbalock);
  1446. return hbq_buf;
  1447. }
  1448. }
  1449. spin_unlock_irq(&phba->hbalock);
  1450. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1451. "1803 Bad hbq tag. Data: x%x x%x\n",
  1452. tag, phba->hbqs[tag >> 16].buffer_count);
  1453. return NULL;
  1454. }
  1455. /**
  1456. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1457. * @phba: Pointer to HBA context object.
  1458. * @hbq_buffer: Pointer to HBQ buffer.
  1459. *
  1460. * This function is called with hbalock. This function gives back
  1461. * the hbq buffer to firmware. If the HBQ does not have space to
  1462. * post the buffer, it will free the buffer.
  1463. **/
  1464. void
  1465. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1466. {
  1467. uint32_t hbqno;
  1468. if (hbq_buffer) {
  1469. hbqno = hbq_buffer->tag >> 16;
  1470. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1471. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1472. }
  1473. }
  1474. /**
  1475. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1476. * @mbxCommand: mailbox command code.
  1477. *
  1478. * This function is called by the mailbox event handler function to verify
  1479. * that the completed mailbox command is a legitimate mailbox command. If the
  1480. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1481. * and the mailbox event handler will take the HBA offline.
  1482. **/
  1483. static int
  1484. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1485. {
  1486. uint8_t ret;
  1487. switch (mbxCommand) {
  1488. case MBX_LOAD_SM:
  1489. case MBX_READ_NV:
  1490. case MBX_WRITE_NV:
  1491. case MBX_WRITE_VPARMS:
  1492. case MBX_RUN_BIU_DIAG:
  1493. case MBX_INIT_LINK:
  1494. case MBX_DOWN_LINK:
  1495. case MBX_CONFIG_LINK:
  1496. case MBX_CONFIG_RING:
  1497. case MBX_RESET_RING:
  1498. case MBX_READ_CONFIG:
  1499. case MBX_READ_RCONFIG:
  1500. case MBX_READ_SPARM:
  1501. case MBX_READ_STATUS:
  1502. case MBX_READ_RPI:
  1503. case MBX_READ_XRI:
  1504. case MBX_READ_REV:
  1505. case MBX_READ_LNK_STAT:
  1506. case MBX_REG_LOGIN:
  1507. case MBX_UNREG_LOGIN:
  1508. case MBX_READ_LA:
  1509. case MBX_CLEAR_LA:
  1510. case MBX_DUMP_MEMORY:
  1511. case MBX_DUMP_CONTEXT:
  1512. case MBX_RUN_DIAGS:
  1513. case MBX_RESTART:
  1514. case MBX_UPDATE_CFG:
  1515. case MBX_DOWN_LOAD:
  1516. case MBX_DEL_LD_ENTRY:
  1517. case MBX_RUN_PROGRAM:
  1518. case MBX_SET_MASK:
  1519. case MBX_SET_VARIABLE:
  1520. case MBX_UNREG_D_ID:
  1521. case MBX_KILL_BOARD:
  1522. case MBX_CONFIG_FARP:
  1523. case MBX_BEACON:
  1524. case MBX_LOAD_AREA:
  1525. case MBX_RUN_BIU_DIAG64:
  1526. case MBX_CONFIG_PORT:
  1527. case MBX_READ_SPARM64:
  1528. case MBX_READ_RPI64:
  1529. case MBX_REG_LOGIN64:
  1530. case MBX_READ_LA64:
  1531. case MBX_WRITE_WWN:
  1532. case MBX_SET_DEBUG:
  1533. case MBX_LOAD_EXP_ROM:
  1534. case MBX_ASYNCEVT_ENABLE:
  1535. case MBX_REG_VPI:
  1536. case MBX_UNREG_VPI:
  1537. case MBX_HEARTBEAT:
  1538. case MBX_PORT_CAPABILITIES:
  1539. case MBX_PORT_IOV_CONTROL:
  1540. case MBX_SLI4_CONFIG:
  1541. case MBX_SLI4_REQ_FTRS:
  1542. case MBX_REG_FCFI:
  1543. case MBX_UNREG_FCFI:
  1544. case MBX_REG_VFI:
  1545. case MBX_UNREG_VFI:
  1546. case MBX_INIT_VPI:
  1547. case MBX_INIT_VFI:
  1548. case MBX_RESUME_RPI:
  1549. case MBX_READ_EVENT_LOG_STATUS:
  1550. case MBX_READ_EVENT_LOG:
  1551. ret = mbxCommand;
  1552. break;
  1553. default:
  1554. ret = MBX_SHUTDOWN;
  1555. break;
  1556. }
  1557. return ret;
  1558. }
  1559. /**
  1560. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1561. * @phba: Pointer to HBA context object.
  1562. * @pmboxq: Pointer to mailbox command.
  1563. *
  1564. * This is completion handler function for mailbox commands issued from
  1565. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1566. * mailbox event handler function with no lock held. This function
  1567. * will wake up thread waiting on the wait queue pointed by context1
  1568. * of the mailbox.
  1569. **/
  1570. void
  1571. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1572. {
  1573. wait_queue_head_t *pdone_q;
  1574. unsigned long drvr_flag;
  1575. /*
  1576. * If pdone_q is empty, the driver thread gave up waiting and
  1577. * continued running.
  1578. */
  1579. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1580. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1581. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1582. if (pdone_q)
  1583. wake_up_interruptible(pdone_q);
  1584. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1585. return;
  1586. }
  1587. /**
  1588. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1589. * @phba: Pointer to HBA context object.
  1590. * @pmb: Pointer to mailbox object.
  1591. *
  1592. * This function is the default mailbox completion handler. It
  1593. * frees the memory resources associated with the completed mailbox
  1594. * command. If the completed command is a REG_LOGIN mailbox command,
  1595. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1596. **/
  1597. void
  1598. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1599. {
  1600. struct lpfc_dmabuf *mp;
  1601. uint16_t rpi, vpi;
  1602. int rc;
  1603. struct lpfc_vport *vport = pmb->vport;
  1604. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1605. if (mp) {
  1606. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1607. kfree(mp);
  1608. }
  1609. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1610. (phba->sli_rev == LPFC_SLI_REV4))
  1611. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1612. /*
  1613. * If a REG_LOGIN succeeded after node is destroyed or node
  1614. * is in re-discovery driver need to cleanup the RPI.
  1615. */
  1616. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1617. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1618. !pmb->u.mb.mbxStatus) {
  1619. rpi = pmb->u.mb.un.varWords[0];
  1620. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1621. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1622. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1623. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1624. if (rc != MBX_NOT_FINISHED)
  1625. return;
  1626. }
  1627. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1628. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1629. !(phba->pport->load_flag & FC_UNLOADING) &&
  1630. !pmb->u.mb.mbxStatus) {
  1631. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1632. pmb->vport = vport;
  1633. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1634. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1635. if (rc != MBX_NOT_FINISHED)
  1636. return;
  1637. }
  1638. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1639. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1640. else
  1641. mempool_free(pmb, phba->mbox_mem_pool);
  1642. }
  1643. /**
  1644. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1645. * @phba: Pointer to HBA context object.
  1646. *
  1647. * This function is called with no lock held. This function processes all
  1648. * the completed mailbox commands and gives it to upper layers. The interrupt
  1649. * service routine processes mailbox completion interrupt and adds completed
  1650. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1651. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1652. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1653. * function returns the mailbox commands to the upper layer by calling the
  1654. * completion handler function of each mailbox.
  1655. **/
  1656. int
  1657. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1658. {
  1659. MAILBOX_t *pmbox;
  1660. LPFC_MBOXQ_t *pmb;
  1661. int rc;
  1662. LIST_HEAD(cmplq);
  1663. phba->sli.slistat.mbox_event++;
  1664. /* Get all completed mailboxe buffers into the cmplq */
  1665. spin_lock_irq(&phba->hbalock);
  1666. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1667. spin_unlock_irq(&phba->hbalock);
  1668. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1669. do {
  1670. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1671. if (pmb == NULL)
  1672. break;
  1673. pmbox = &pmb->u.mb;
  1674. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1675. if (pmb->vport) {
  1676. lpfc_debugfs_disc_trc(pmb->vport,
  1677. LPFC_DISC_TRC_MBOX_VPORT,
  1678. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1679. (uint32_t)pmbox->mbxCommand,
  1680. pmbox->un.varWords[0],
  1681. pmbox->un.varWords[1]);
  1682. }
  1683. else {
  1684. lpfc_debugfs_disc_trc(phba->pport,
  1685. LPFC_DISC_TRC_MBOX,
  1686. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1687. (uint32_t)pmbox->mbxCommand,
  1688. pmbox->un.varWords[0],
  1689. pmbox->un.varWords[1]);
  1690. }
  1691. }
  1692. /*
  1693. * It is a fatal error if unknown mbox command completion.
  1694. */
  1695. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1696. MBX_SHUTDOWN) {
  1697. /* Unknown mailbox command compl */
  1698. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1699. "(%d):0323 Unknown Mailbox command "
  1700. "x%x (x%x) Cmpl\n",
  1701. pmb->vport ? pmb->vport->vpi : 0,
  1702. pmbox->mbxCommand,
  1703. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1704. phba->link_state = LPFC_HBA_ERROR;
  1705. phba->work_hs = HS_FFER3;
  1706. lpfc_handle_eratt(phba);
  1707. continue;
  1708. }
  1709. if (pmbox->mbxStatus) {
  1710. phba->sli.slistat.mbox_stat_err++;
  1711. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1712. /* Mbox cmd cmpl error - RETRYing */
  1713. lpfc_printf_log(phba, KERN_INFO,
  1714. LOG_MBOX | LOG_SLI,
  1715. "(%d):0305 Mbox cmd cmpl "
  1716. "error - RETRYing Data: x%x "
  1717. "(x%x) x%x x%x x%x\n",
  1718. pmb->vport ? pmb->vport->vpi :0,
  1719. pmbox->mbxCommand,
  1720. lpfc_sli4_mbox_opcode_get(phba,
  1721. pmb),
  1722. pmbox->mbxStatus,
  1723. pmbox->un.varWords[0],
  1724. pmb->vport->port_state);
  1725. pmbox->mbxStatus = 0;
  1726. pmbox->mbxOwner = OWN_HOST;
  1727. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1728. if (rc != MBX_NOT_FINISHED)
  1729. continue;
  1730. }
  1731. }
  1732. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1733. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1734. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1735. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1736. pmb->vport ? pmb->vport->vpi : 0,
  1737. pmbox->mbxCommand,
  1738. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1739. pmb->mbox_cmpl,
  1740. *((uint32_t *) pmbox),
  1741. pmbox->un.varWords[0],
  1742. pmbox->un.varWords[1],
  1743. pmbox->un.varWords[2],
  1744. pmbox->un.varWords[3],
  1745. pmbox->un.varWords[4],
  1746. pmbox->un.varWords[5],
  1747. pmbox->un.varWords[6],
  1748. pmbox->un.varWords[7]);
  1749. if (pmb->mbox_cmpl)
  1750. pmb->mbox_cmpl(phba,pmb);
  1751. } while (1);
  1752. return 0;
  1753. }
  1754. /**
  1755. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1756. * @phba: Pointer to HBA context object.
  1757. * @pring: Pointer to driver SLI ring object.
  1758. * @tag: buffer tag.
  1759. *
  1760. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1761. * is set in the tag the buffer is posted for a particular exchange,
  1762. * the function will return the buffer without replacing the buffer.
  1763. * If the buffer is for unsolicited ELS or CT traffic, this function
  1764. * returns the buffer and also posts another buffer to the firmware.
  1765. **/
  1766. static struct lpfc_dmabuf *
  1767. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1768. struct lpfc_sli_ring *pring,
  1769. uint32_t tag)
  1770. {
  1771. struct hbq_dmabuf *hbq_entry;
  1772. if (tag & QUE_BUFTAG_BIT)
  1773. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1774. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1775. if (!hbq_entry)
  1776. return NULL;
  1777. return &hbq_entry->dbuf;
  1778. }
  1779. /**
  1780. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1781. * @phba: Pointer to HBA context object.
  1782. * @pring: Pointer to driver SLI ring object.
  1783. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1784. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1785. * @fch_type: the type for the first frame of the sequence.
  1786. *
  1787. * This function is called with no lock held. This function uses the r_ctl and
  1788. * type of the received sequence to find the correct callback function to call
  1789. * to process the sequence.
  1790. **/
  1791. static int
  1792. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1793. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1794. uint32_t fch_type)
  1795. {
  1796. int i;
  1797. /* unSolicited Responses */
  1798. if (pring->prt[0].profile) {
  1799. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1800. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1801. saveq);
  1802. return 1;
  1803. }
  1804. /* We must search, based on rctl / type
  1805. for the right routine */
  1806. for (i = 0; i < pring->num_mask; i++) {
  1807. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1808. (pring->prt[i].type == fch_type)) {
  1809. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1810. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1811. (phba, pring, saveq);
  1812. return 1;
  1813. }
  1814. }
  1815. return 0;
  1816. }
  1817. /**
  1818. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1819. * @phba: Pointer to HBA context object.
  1820. * @pring: Pointer to driver SLI ring object.
  1821. * @saveq: Pointer to the unsolicited iocb.
  1822. *
  1823. * This function is called with no lock held by the ring event handler
  1824. * when there is an unsolicited iocb posted to the response ring by the
  1825. * firmware. This function gets the buffer associated with the iocbs
  1826. * and calls the event handler for the ring. This function handles both
  1827. * qring buffers and hbq buffers.
  1828. * When the function returns 1 the caller can free the iocb object otherwise
  1829. * upper layer functions will free the iocb objects.
  1830. **/
  1831. static int
  1832. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1833. struct lpfc_iocbq *saveq)
  1834. {
  1835. IOCB_t * irsp;
  1836. WORD5 * w5p;
  1837. uint32_t Rctl, Type;
  1838. uint32_t match;
  1839. struct lpfc_iocbq *iocbq;
  1840. struct lpfc_dmabuf *dmzbuf;
  1841. match = 0;
  1842. irsp = &(saveq->iocb);
  1843. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1844. if (pring->lpfc_sli_rcv_async_status)
  1845. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1846. else
  1847. lpfc_printf_log(phba,
  1848. KERN_WARNING,
  1849. LOG_SLI,
  1850. "0316 Ring %d handler: unexpected "
  1851. "ASYNC_STATUS iocb received evt_code "
  1852. "0x%x\n",
  1853. pring->ringno,
  1854. irsp->un.asyncstat.evt_code);
  1855. return 1;
  1856. }
  1857. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1858. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1859. if (irsp->ulpBdeCount > 0) {
  1860. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1861. irsp->un.ulpWord[3]);
  1862. lpfc_in_buf_free(phba, dmzbuf);
  1863. }
  1864. if (irsp->ulpBdeCount > 1) {
  1865. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1866. irsp->unsli3.sli3Words[3]);
  1867. lpfc_in_buf_free(phba, dmzbuf);
  1868. }
  1869. if (irsp->ulpBdeCount > 2) {
  1870. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1871. irsp->unsli3.sli3Words[7]);
  1872. lpfc_in_buf_free(phba, dmzbuf);
  1873. }
  1874. return 1;
  1875. }
  1876. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1877. if (irsp->ulpBdeCount != 0) {
  1878. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1879. irsp->un.ulpWord[3]);
  1880. if (!saveq->context2)
  1881. lpfc_printf_log(phba,
  1882. KERN_ERR,
  1883. LOG_SLI,
  1884. "0341 Ring %d Cannot find buffer for "
  1885. "an unsolicited iocb. tag 0x%x\n",
  1886. pring->ringno,
  1887. irsp->un.ulpWord[3]);
  1888. }
  1889. if (irsp->ulpBdeCount == 2) {
  1890. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1891. irsp->unsli3.sli3Words[7]);
  1892. if (!saveq->context3)
  1893. lpfc_printf_log(phba,
  1894. KERN_ERR,
  1895. LOG_SLI,
  1896. "0342 Ring %d Cannot find buffer for an"
  1897. " unsolicited iocb. tag 0x%x\n",
  1898. pring->ringno,
  1899. irsp->unsli3.sli3Words[7]);
  1900. }
  1901. list_for_each_entry(iocbq, &saveq->list, list) {
  1902. irsp = &(iocbq->iocb);
  1903. if (irsp->ulpBdeCount != 0) {
  1904. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1905. irsp->un.ulpWord[3]);
  1906. if (!iocbq->context2)
  1907. lpfc_printf_log(phba,
  1908. KERN_ERR,
  1909. LOG_SLI,
  1910. "0343 Ring %d Cannot find "
  1911. "buffer for an unsolicited iocb"
  1912. ". tag 0x%x\n", pring->ringno,
  1913. irsp->un.ulpWord[3]);
  1914. }
  1915. if (irsp->ulpBdeCount == 2) {
  1916. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1917. irsp->unsli3.sli3Words[7]);
  1918. if (!iocbq->context3)
  1919. lpfc_printf_log(phba,
  1920. KERN_ERR,
  1921. LOG_SLI,
  1922. "0344 Ring %d Cannot find "
  1923. "buffer for an unsolicited "
  1924. "iocb. tag 0x%x\n",
  1925. pring->ringno,
  1926. irsp->unsli3.sli3Words[7]);
  1927. }
  1928. }
  1929. }
  1930. if (irsp->ulpBdeCount != 0 &&
  1931. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1932. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1933. int found = 0;
  1934. /* search continue save q for same XRI */
  1935. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1936. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1937. list_add_tail(&saveq->list, &iocbq->list);
  1938. found = 1;
  1939. break;
  1940. }
  1941. }
  1942. if (!found)
  1943. list_add_tail(&saveq->clist,
  1944. &pring->iocb_continue_saveq);
  1945. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1946. list_del_init(&iocbq->clist);
  1947. saveq = iocbq;
  1948. irsp = &(saveq->iocb);
  1949. } else
  1950. return 0;
  1951. }
  1952. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1953. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1954. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1955. Rctl = FC_RCTL_ELS_REQ;
  1956. Type = FC_TYPE_ELS;
  1957. } else {
  1958. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1959. Rctl = w5p->hcsw.Rctl;
  1960. Type = w5p->hcsw.Type;
  1961. /* Firmware Workaround */
  1962. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1963. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1964. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1965. Rctl = FC_RCTL_ELS_REQ;
  1966. Type = FC_TYPE_ELS;
  1967. w5p->hcsw.Rctl = Rctl;
  1968. w5p->hcsw.Type = Type;
  1969. }
  1970. }
  1971. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1972. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1973. "0313 Ring %d handler: unexpected Rctl x%x "
  1974. "Type x%x received\n",
  1975. pring->ringno, Rctl, Type);
  1976. return 1;
  1977. }
  1978. /**
  1979. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1980. * @phba: Pointer to HBA context object.
  1981. * @pring: Pointer to driver SLI ring object.
  1982. * @prspiocb: Pointer to response iocb object.
  1983. *
  1984. * This function looks up the iocb_lookup table to get the command iocb
  1985. * corresponding to the given response iocb using the iotag of the
  1986. * response iocb. This function is called with the hbalock held.
  1987. * This function returns the command iocb object if it finds the command
  1988. * iocb else returns NULL.
  1989. **/
  1990. static struct lpfc_iocbq *
  1991. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1992. struct lpfc_sli_ring *pring,
  1993. struct lpfc_iocbq *prspiocb)
  1994. {
  1995. struct lpfc_iocbq *cmd_iocb = NULL;
  1996. uint16_t iotag;
  1997. iotag = prspiocb->iocb.ulpIoTag;
  1998. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1999. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2000. list_del_init(&cmd_iocb->list);
  2001. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2002. pring->txcmplq_cnt--;
  2003. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2004. }
  2005. return cmd_iocb;
  2006. }
  2007. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2008. "0317 iotag x%x is out off "
  2009. "range: max iotag x%x wd0 x%x\n",
  2010. iotag, phba->sli.last_iotag,
  2011. *(((uint32_t *) &prspiocb->iocb) + 7));
  2012. return NULL;
  2013. }
  2014. /**
  2015. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2016. * @phba: Pointer to HBA context object.
  2017. * @pring: Pointer to driver SLI ring object.
  2018. * @iotag: IOCB tag.
  2019. *
  2020. * This function looks up the iocb_lookup table to get the command iocb
  2021. * corresponding to the given iotag. This function is called with the
  2022. * hbalock held.
  2023. * This function returns the command iocb object if it finds the command
  2024. * iocb else returns NULL.
  2025. **/
  2026. static struct lpfc_iocbq *
  2027. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2028. struct lpfc_sli_ring *pring, uint16_t iotag)
  2029. {
  2030. struct lpfc_iocbq *cmd_iocb;
  2031. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2032. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2033. list_del_init(&cmd_iocb->list);
  2034. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2035. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2036. pring->txcmplq_cnt--;
  2037. }
  2038. return cmd_iocb;
  2039. }
  2040. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2041. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2042. iotag, phba->sli.last_iotag);
  2043. return NULL;
  2044. }
  2045. /**
  2046. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2047. * @phba: Pointer to HBA context object.
  2048. * @pring: Pointer to driver SLI ring object.
  2049. * @saveq: Pointer to the response iocb to be processed.
  2050. *
  2051. * This function is called by the ring event handler for non-fcp
  2052. * rings when there is a new response iocb in the response ring.
  2053. * The caller is not required to hold any locks. This function
  2054. * gets the command iocb associated with the response iocb and
  2055. * calls the completion handler for the command iocb. If there
  2056. * is no completion handler, the function will free the resources
  2057. * associated with command iocb. If the response iocb is for
  2058. * an already aborted command iocb, the status of the completion
  2059. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2060. * This function always returns 1.
  2061. **/
  2062. static int
  2063. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2064. struct lpfc_iocbq *saveq)
  2065. {
  2066. struct lpfc_iocbq *cmdiocbp;
  2067. int rc = 1;
  2068. unsigned long iflag;
  2069. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2070. spin_lock_irqsave(&phba->hbalock, iflag);
  2071. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2072. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2073. if (cmdiocbp) {
  2074. if (cmdiocbp->iocb_cmpl) {
  2075. /*
  2076. * If an ELS command failed send an event to mgmt
  2077. * application.
  2078. */
  2079. if (saveq->iocb.ulpStatus &&
  2080. (pring->ringno == LPFC_ELS_RING) &&
  2081. (cmdiocbp->iocb.ulpCommand ==
  2082. CMD_ELS_REQUEST64_CR))
  2083. lpfc_send_els_failure_event(phba,
  2084. cmdiocbp, saveq);
  2085. /*
  2086. * Post all ELS completions to the worker thread.
  2087. * All other are passed to the completion callback.
  2088. */
  2089. if (pring->ringno == LPFC_ELS_RING) {
  2090. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2091. (cmdiocbp->iocb_flag &
  2092. LPFC_DRIVER_ABORTED)) {
  2093. spin_lock_irqsave(&phba->hbalock,
  2094. iflag);
  2095. cmdiocbp->iocb_flag &=
  2096. ~LPFC_DRIVER_ABORTED;
  2097. spin_unlock_irqrestore(&phba->hbalock,
  2098. iflag);
  2099. saveq->iocb.ulpStatus =
  2100. IOSTAT_LOCAL_REJECT;
  2101. saveq->iocb.un.ulpWord[4] =
  2102. IOERR_SLI_ABORTED;
  2103. /* Firmware could still be in progress
  2104. * of DMAing payload, so don't free data
  2105. * buffer till after a hbeat.
  2106. */
  2107. spin_lock_irqsave(&phba->hbalock,
  2108. iflag);
  2109. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2110. spin_unlock_irqrestore(&phba->hbalock,
  2111. iflag);
  2112. }
  2113. if (phba->sli_rev == LPFC_SLI_REV4) {
  2114. if (saveq->iocb_flag &
  2115. LPFC_EXCHANGE_BUSY) {
  2116. /* Set cmdiocb flag for the
  2117. * exchange busy so sgl (xri)
  2118. * will not be released until
  2119. * the abort xri is received
  2120. * from hba.
  2121. */
  2122. spin_lock_irqsave(
  2123. &phba->hbalock, iflag);
  2124. cmdiocbp->iocb_flag |=
  2125. LPFC_EXCHANGE_BUSY;
  2126. spin_unlock_irqrestore(
  2127. &phba->hbalock, iflag);
  2128. }
  2129. if (cmdiocbp->iocb_flag &
  2130. LPFC_DRIVER_ABORTED) {
  2131. /*
  2132. * Clear LPFC_DRIVER_ABORTED
  2133. * bit in case it was driver
  2134. * initiated abort.
  2135. */
  2136. spin_lock_irqsave(
  2137. &phba->hbalock, iflag);
  2138. cmdiocbp->iocb_flag &=
  2139. ~LPFC_DRIVER_ABORTED;
  2140. spin_unlock_irqrestore(
  2141. &phba->hbalock, iflag);
  2142. cmdiocbp->iocb.ulpStatus =
  2143. IOSTAT_LOCAL_REJECT;
  2144. cmdiocbp->iocb.un.ulpWord[4] =
  2145. IOERR_ABORT_REQUESTED;
  2146. /*
  2147. * For SLI4, irsiocb contains
  2148. * NO_XRI in sli_xritag, it
  2149. * shall not affect releasing
  2150. * sgl (xri) process.
  2151. */
  2152. saveq->iocb.ulpStatus =
  2153. IOSTAT_LOCAL_REJECT;
  2154. saveq->iocb.un.ulpWord[4] =
  2155. IOERR_SLI_ABORTED;
  2156. spin_lock_irqsave(
  2157. &phba->hbalock, iflag);
  2158. saveq->iocb_flag |=
  2159. LPFC_DELAY_MEM_FREE;
  2160. spin_unlock_irqrestore(
  2161. &phba->hbalock, iflag);
  2162. }
  2163. }
  2164. }
  2165. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2166. } else
  2167. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2168. } else {
  2169. /*
  2170. * Unknown initiating command based on the response iotag.
  2171. * This could be the case on the ELS ring because of
  2172. * lpfc_els_abort().
  2173. */
  2174. if (pring->ringno != LPFC_ELS_RING) {
  2175. /*
  2176. * Ring <ringno> handler: unexpected completion IoTag
  2177. * <IoTag>
  2178. */
  2179. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2180. "0322 Ring %d handler: "
  2181. "unexpected completion IoTag x%x "
  2182. "Data: x%x x%x x%x x%x\n",
  2183. pring->ringno,
  2184. saveq->iocb.ulpIoTag,
  2185. saveq->iocb.ulpStatus,
  2186. saveq->iocb.un.ulpWord[4],
  2187. saveq->iocb.ulpCommand,
  2188. saveq->iocb.ulpContext);
  2189. }
  2190. }
  2191. return rc;
  2192. }
  2193. /**
  2194. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2195. * @phba: Pointer to HBA context object.
  2196. * @pring: Pointer to driver SLI ring object.
  2197. *
  2198. * This function is called from the iocb ring event handlers when
  2199. * put pointer is ahead of the get pointer for a ring. This function signal
  2200. * an error attention condition to the worker thread and the worker
  2201. * thread will transition the HBA to offline state.
  2202. **/
  2203. static void
  2204. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2205. {
  2206. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2207. /*
  2208. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2209. * rsp ring <portRspMax>
  2210. */
  2211. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2212. "0312 Ring %d handler: portRspPut %d "
  2213. "is bigger than rsp ring %d\n",
  2214. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2215. pring->numRiocb);
  2216. phba->link_state = LPFC_HBA_ERROR;
  2217. /*
  2218. * All error attention handlers are posted to
  2219. * worker thread
  2220. */
  2221. phba->work_ha |= HA_ERATT;
  2222. phba->work_hs = HS_FFER3;
  2223. lpfc_worker_wake_up(phba);
  2224. return;
  2225. }
  2226. /**
  2227. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2228. * @ptr: Pointer to address of HBA context object.
  2229. *
  2230. * This function is invoked by the Error Attention polling timer when the
  2231. * timer times out. It will check the SLI Error Attention register for
  2232. * possible attention events. If so, it will post an Error Attention event
  2233. * and wake up worker thread to process it. Otherwise, it will set up the
  2234. * Error Attention polling timer for the next poll.
  2235. **/
  2236. void lpfc_poll_eratt(unsigned long ptr)
  2237. {
  2238. struct lpfc_hba *phba;
  2239. uint32_t eratt = 0;
  2240. phba = (struct lpfc_hba *)ptr;
  2241. /* Check chip HA register for error event */
  2242. eratt = lpfc_sli_check_eratt(phba);
  2243. if (eratt)
  2244. /* Tell the worker thread there is work to do */
  2245. lpfc_worker_wake_up(phba);
  2246. else
  2247. /* Restart the timer for next eratt poll */
  2248. mod_timer(&phba->eratt_poll, jiffies +
  2249. HZ * LPFC_ERATT_POLL_INTERVAL);
  2250. return;
  2251. }
  2252. /**
  2253. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2254. * @phba: Pointer to HBA context object.
  2255. * @pring: Pointer to driver SLI ring object.
  2256. * @mask: Host attention register mask for this ring.
  2257. *
  2258. * This function is called from the interrupt context when there is a ring
  2259. * event for the fcp ring. The caller does not hold any lock.
  2260. * The function processes each response iocb in the response ring until it
  2261. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2262. * LE bit set. The function will call the completion handler of the command iocb
  2263. * if the response iocb indicates a completion for a command iocb or it is
  2264. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2265. * function if this is an unsolicited iocb.
  2266. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2267. * to check it explicitly.
  2268. */
  2269. int
  2270. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2271. struct lpfc_sli_ring *pring, uint32_t mask)
  2272. {
  2273. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2274. IOCB_t *irsp = NULL;
  2275. IOCB_t *entry = NULL;
  2276. struct lpfc_iocbq *cmdiocbq = NULL;
  2277. struct lpfc_iocbq rspiocbq;
  2278. uint32_t status;
  2279. uint32_t portRspPut, portRspMax;
  2280. int rc = 1;
  2281. lpfc_iocb_type type;
  2282. unsigned long iflag;
  2283. uint32_t rsp_cmpl = 0;
  2284. spin_lock_irqsave(&phba->hbalock, iflag);
  2285. pring->stats.iocb_event++;
  2286. /*
  2287. * The next available response entry should never exceed the maximum
  2288. * entries. If it does, treat it as an adapter hardware error.
  2289. */
  2290. portRspMax = pring->numRiocb;
  2291. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2292. if (unlikely(portRspPut >= portRspMax)) {
  2293. lpfc_sli_rsp_pointers_error(phba, pring);
  2294. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2295. return 1;
  2296. }
  2297. if (phba->fcp_ring_in_use) {
  2298. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2299. return 1;
  2300. } else
  2301. phba->fcp_ring_in_use = 1;
  2302. rmb();
  2303. while (pring->rspidx != portRspPut) {
  2304. /*
  2305. * Fetch an entry off the ring and copy it into a local data
  2306. * structure. The copy involves a byte-swap since the
  2307. * network byte order and pci byte orders are different.
  2308. */
  2309. entry = lpfc_resp_iocb(phba, pring);
  2310. phba->last_completion_time = jiffies;
  2311. if (++pring->rspidx >= portRspMax)
  2312. pring->rspidx = 0;
  2313. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2314. (uint32_t *) &rspiocbq.iocb,
  2315. phba->iocb_rsp_size);
  2316. INIT_LIST_HEAD(&(rspiocbq.list));
  2317. irsp = &rspiocbq.iocb;
  2318. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2319. pring->stats.iocb_rsp++;
  2320. rsp_cmpl++;
  2321. if (unlikely(irsp->ulpStatus)) {
  2322. /*
  2323. * If resource errors reported from HBA, reduce
  2324. * queuedepths of the SCSI device.
  2325. */
  2326. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2327. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2328. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2329. phba->lpfc_rampdown_queue_depth(phba);
  2330. spin_lock_irqsave(&phba->hbalock, iflag);
  2331. }
  2332. /* Rsp ring <ringno> error: IOCB */
  2333. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2334. "0336 Rsp Ring %d error: IOCB Data: "
  2335. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2336. pring->ringno,
  2337. irsp->un.ulpWord[0],
  2338. irsp->un.ulpWord[1],
  2339. irsp->un.ulpWord[2],
  2340. irsp->un.ulpWord[3],
  2341. irsp->un.ulpWord[4],
  2342. irsp->un.ulpWord[5],
  2343. *(uint32_t *)&irsp->un1,
  2344. *((uint32_t *)&irsp->un1 + 1));
  2345. }
  2346. switch (type) {
  2347. case LPFC_ABORT_IOCB:
  2348. case LPFC_SOL_IOCB:
  2349. /*
  2350. * Idle exchange closed via ABTS from port. No iocb
  2351. * resources need to be recovered.
  2352. */
  2353. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2354. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2355. "0333 IOCB cmd 0x%x"
  2356. " processed. Skipping"
  2357. " completion\n",
  2358. irsp->ulpCommand);
  2359. break;
  2360. }
  2361. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2362. &rspiocbq);
  2363. if (unlikely(!cmdiocbq))
  2364. break;
  2365. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2366. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2367. if (cmdiocbq->iocb_cmpl) {
  2368. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2369. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2370. &rspiocbq);
  2371. spin_lock_irqsave(&phba->hbalock, iflag);
  2372. }
  2373. break;
  2374. case LPFC_UNSOL_IOCB:
  2375. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2376. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2377. spin_lock_irqsave(&phba->hbalock, iflag);
  2378. break;
  2379. default:
  2380. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2381. char adaptermsg[LPFC_MAX_ADPTMSG];
  2382. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2383. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2384. MAX_MSG_DATA);
  2385. dev_warn(&((phba->pcidev)->dev),
  2386. "lpfc%d: %s\n",
  2387. phba->brd_no, adaptermsg);
  2388. } else {
  2389. /* Unknown IOCB command */
  2390. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2391. "0334 Unknown IOCB command "
  2392. "Data: x%x, x%x x%x x%x x%x\n",
  2393. type, irsp->ulpCommand,
  2394. irsp->ulpStatus,
  2395. irsp->ulpIoTag,
  2396. irsp->ulpContext);
  2397. }
  2398. break;
  2399. }
  2400. /*
  2401. * The response IOCB has been processed. Update the ring
  2402. * pointer in SLIM. If the port response put pointer has not
  2403. * been updated, sync the pgp->rspPutInx and fetch the new port
  2404. * response put pointer.
  2405. */
  2406. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2407. if (pring->rspidx == portRspPut)
  2408. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2409. }
  2410. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2411. pring->stats.iocb_rsp_full++;
  2412. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2413. writel(status, phba->CAregaddr);
  2414. readl(phba->CAregaddr);
  2415. }
  2416. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2417. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2418. pring->stats.iocb_cmd_empty++;
  2419. /* Force update of the local copy of cmdGetInx */
  2420. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2421. lpfc_sli_resume_iocb(phba, pring);
  2422. if ((pring->lpfc_sli_cmd_available))
  2423. (pring->lpfc_sli_cmd_available) (phba, pring);
  2424. }
  2425. phba->fcp_ring_in_use = 0;
  2426. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2427. return rc;
  2428. }
  2429. /**
  2430. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2431. * @phba: Pointer to HBA context object.
  2432. * @pring: Pointer to driver SLI ring object.
  2433. * @rspiocbp: Pointer to driver response IOCB object.
  2434. *
  2435. * This function is called from the worker thread when there is a slow-path
  2436. * response IOCB to process. This function chains all the response iocbs until
  2437. * seeing the iocb with the LE bit set. The function will call
  2438. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2439. * completion of a command iocb. The function will call the
  2440. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2441. * The function frees the resources or calls the completion handler if this
  2442. * iocb is an abort completion. The function returns NULL when the response
  2443. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2444. * this function shall chain the iocb on to the iocb_continueq and return the
  2445. * response iocb passed in.
  2446. **/
  2447. static struct lpfc_iocbq *
  2448. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2449. struct lpfc_iocbq *rspiocbp)
  2450. {
  2451. struct lpfc_iocbq *saveq;
  2452. struct lpfc_iocbq *cmdiocbp;
  2453. struct lpfc_iocbq *next_iocb;
  2454. IOCB_t *irsp = NULL;
  2455. uint32_t free_saveq;
  2456. uint8_t iocb_cmd_type;
  2457. lpfc_iocb_type type;
  2458. unsigned long iflag;
  2459. int rc;
  2460. spin_lock_irqsave(&phba->hbalock, iflag);
  2461. /* First add the response iocb to the countinueq list */
  2462. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2463. pring->iocb_continueq_cnt++;
  2464. /* Now, determine whetehr the list is completed for processing */
  2465. irsp = &rspiocbp->iocb;
  2466. if (irsp->ulpLe) {
  2467. /*
  2468. * By default, the driver expects to free all resources
  2469. * associated with this iocb completion.
  2470. */
  2471. free_saveq = 1;
  2472. saveq = list_get_first(&pring->iocb_continueq,
  2473. struct lpfc_iocbq, list);
  2474. irsp = &(saveq->iocb);
  2475. list_del_init(&pring->iocb_continueq);
  2476. pring->iocb_continueq_cnt = 0;
  2477. pring->stats.iocb_rsp++;
  2478. /*
  2479. * If resource errors reported from HBA, reduce
  2480. * queuedepths of the SCSI device.
  2481. */
  2482. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2483. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2484. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2485. phba->lpfc_rampdown_queue_depth(phba);
  2486. spin_lock_irqsave(&phba->hbalock, iflag);
  2487. }
  2488. if (irsp->ulpStatus) {
  2489. /* Rsp ring <ringno> error: IOCB */
  2490. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2491. "0328 Rsp Ring %d error: "
  2492. "IOCB Data: "
  2493. "x%x x%x x%x x%x "
  2494. "x%x x%x x%x x%x "
  2495. "x%x x%x x%x x%x "
  2496. "x%x x%x x%x x%x\n",
  2497. pring->ringno,
  2498. irsp->un.ulpWord[0],
  2499. irsp->un.ulpWord[1],
  2500. irsp->un.ulpWord[2],
  2501. irsp->un.ulpWord[3],
  2502. irsp->un.ulpWord[4],
  2503. irsp->un.ulpWord[5],
  2504. *(((uint32_t *) irsp) + 6),
  2505. *(((uint32_t *) irsp) + 7),
  2506. *(((uint32_t *) irsp) + 8),
  2507. *(((uint32_t *) irsp) + 9),
  2508. *(((uint32_t *) irsp) + 10),
  2509. *(((uint32_t *) irsp) + 11),
  2510. *(((uint32_t *) irsp) + 12),
  2511. *(((uint32_t *) irsp) + 13),
  2512. *(((uint32_t *) irsp) + 14),
  2513. *(((uint32_t *) irsp) + 15));
  2514. }
  2515. /*
  2516. * Fetch the IOCB command type and call the correct completion
  2517. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2518. * get freed back to the lpfc_iocb_list by the discovery
  2519. * kernel thread.
  2520. */
  2521. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2522. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2523. switch (type) {
  2524. case LPFC_SOL_IOCB:
  2525. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2526. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2527. spin_lock_irqsave(&phba->hbalock, iflag);
  2528. break;
  2529. case LPFC_UNSOL_IOCB:
  2530. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2531. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2532. spin_lock_irqsave(&phba->hbalock, iflag);
  2533. if (!rc)
  2534. free_saveq = 0;
  2535. break;
  2536. case LPFC_ABORT_IOCB:
  2537. cmdiocbp = NULL;
  2538. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2539. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2540. saveq);
  2541. if (cmdiocbp) {
  2542. /* Call the specified completion routine */
  2543. if (cmdiocbp->iocb_cmpl) {
  2544. spin_unlock_irqrestore(&phba->hbalock,
  2545. iflag);
  2546. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2547. saveq);
  2548. spin_lock_irqsave(&phba->hbalock,
  2549. iflag);
  2550. } else
  2551. __lpfc_sli_release_iocbq(phba,
  2552. cmdiocbp);
  2553. }
  2554. break;
  2555. case LPFC_UNKNOWN_IOCB:
  2556. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2557. char adaptermsg[LPFC_MAX_ADPTMSG];
  2558. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2559. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2560. MAX_MSG_DATA);
  2561. dev_warn(&((phba->pcidev)->dev),
  2562. "lpfc%d: %s\n",
  2563. phba->brd_no, adaptermsg);
  2564. } else {
  2565. /* Unknown IOCB command */
  2566. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2567. "0335 Unknown IOCB "
  2568. "command Data: x%x "
  2569. "x%x x%x x%x\n",
  2570. irsp->ulpCommand,
  2571. irsp->ulpStatus,
  2572. irsp->ulpIoTag,
  2573. irsp->ulpContext);
  2574. }
  2575. break;
  2576. }
  2577. if (free_saveq) {
  2578. list_for_each_entry_safe(rspiocbp, next_iocb,
  2579. &saveq->list, list) {
  2580. list_del(&rspiocbp->list);
  2581. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2582. }
  2583. __lpfc_sli_release_iocbq(phba, saveq);
  2584. }
  2585. rspiocbp = NULL;
  2586. }
  2587. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2588. return rspiocbp;
  2589. }
  2590. /**
  2591. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2592. * @phba: Pointer to HBA context object.
  2593. * @pring: Pointer to driver SLI ring object.
  2594. * @mask: Host attention register mask for this ring.
  2595. *
  2596. * This routine wraps the actual slow_ring event process routine from the
  2597. * API jump table function pointer from the lpfc_hba struct.
  2598. **/
  2599. void
  2600. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2601. struct lpfc_sli_ring *pring, uint32_t mask)
  2602. {
  2603. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2604. }
  2605. /**
  2606. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2607. * @phba: Pointer to HBA context object.
  2608. * @pring: Pointer to driver SLI ring object.
  2609. * @mask: Host attention register mask for this ring.
  2610. *
  2611. * This function is called from the worker thread when there is a ring event
  2612. * for non-fcp rings. The caller does not hold any lock. The function will
  2613. * remove each response iocb in the response ring and calls the handle
  2614. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2615. **/
  2616. static void
  2617. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2618. struct lpfc_sli_ring *pring, uint32_t mask)
  2619. {
  2620. struct lpfc_pgp *pgp;
  2621. IOCB_t *entry;
  2622. IOCB_t *irsp = NULL;
  2623. struct lpfc_iocbq *rspiocbp = NULL;
  2624. uint32_t portRspPut, portRspMax;
  2625. unsigned long iflag;
  2626. uint32_t status;
  2627. pgp = &phba->port_gp[pring->ringno];
  2628. spin_lock_irqsave(&phba->hbalock, iflag);
  2629. pring->stats.iocb_event++;
  2630. /*
  2631. * The next available response entry should never exceed the maximum
  2632. * entries. If it does, treat it as an adapter hardware error.
  2633. */
  2634. portRspMax = pring->numRiocb;
  2635. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2636. if (portRspPut >= portRspMax) {
  2637. /*
  2638. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2639. * rsp ring <portRspMax>
  2640. */
  2641. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2642. "0303 Ring %d handler: portRspPut %d "
  2643. "is bigger than rsp ring %d\n",
  2644. pring->ringno, portRspPut, portRspMax);
  2645. phba->link_state = LPFC_HBA_ERROR;
  2646. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2647. phba->work_hs = HS_FFER3;
  2648. lpfc_handle_eratt(phba);
  2649. return;
  2650. }
  2651. rmb();
  2652. while (pring->rspidx != portRspPut) {
  2653. /*
  2654. * Build a completion list and call the appropriate handler.
  2655. * The process is to get the next available response iocb, get
  2656. * a free iocb from the list, copy the response data into the
  2657. * free iocb, insert to the continuation list, and update the
  2658. * next response index to slim. This process makes response
  2659. * iocb's in the ring available to DMA as fast as possible but
  2660. * pays a penalty for a copy operation. Since the iocb is
  2661. * only 32 bytes, this penalty is considered small relative to
  2662. * the PCI reads for register values and a slim write. When
  2663. * the ulpLe field is set, the entire Command has been
  2664. * received.
  2665. */
  2666. entry = lpfc_resp_iocb(phba, pring);
  2667. phba->last_completion_time = jiffies;
  2668. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2669. if (rspiocbp == NULL) {
  2670. printk(KERN_ERR "%s: out of buffers! Failing "
  2671. "completion.\n", __func__);
  2672. break;
  2673. }
  2674. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2675. phba->iocb_rsp_size);
  2676. irsp = &rspiocbp->iocb;
  2677. if (++pring->rspidx >= portRspMax)
  2678. pring->rspidx = 0;
  2679. if (pring->ringno == LPFC_ELS_RING) {
  2680. lpfc_debugfs_slow_ring_trc(phba,
  2681. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2682. *(((uint32_t *) irsp) + 4),
  2683. *(((uint32_t *) irsp) + 6),
  2684. *(((uint32_t *) irsp) + 7));
  2685. }
  2686. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2687. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2688. /* Handle the response IOCB */
  2689. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2690. spin_lock_irqsave(&phba->hbalock, iflag);
  2691. /*
  2692. * If the port response put pointer has not been updated, sync
  2693. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2694. * response put pointer.
  2695. */
  2696. if (pring->rspidx == portRspPut) {
  2697. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2698. }
  2699. } /* while (pring->rspidx != portRspPut) */
  2700. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2701. /* At least one response entry has been freed */
  2702. pring->stats.iocb_rsp_full++;
  2703. /* SET RxRE_RSP in Chip Att register */
  2704. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2705. writel(status, phba->CAregaddr);
  2706. readl(phba->CAregaddr); /* flush */
  2707. }
  2708. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2709. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2710. pring->stats.iocb_cmd_empty++;
  2711. /* Force update of the local copy of cmdGetInx */
  2712. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2713. lpfc_sli_resume_iocb(phba, pring);
  2714. if ((pring->lpfc_sli_cmd_available))
  2715. (pring->lpfc_sli_cmd_available) (phba, pring);
  2716. }
  2717. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2718. return;
  2719. }
  2720. /**
  2721. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2722. * @phba: Pointer to HBA context object.
  2723. * @pring: Pointer to driver SLI ring object.
  2724. * @mask: Host attention register mask for this ring.
  2725. *
  2726. * This function is called from the worker thread when there is a pending
  2727. * ELS response iocb on the driver internal slow-path response iocb worker
  2728. * queue. The caller does not hold any lock. The function will remove each
  2729. * response iocb from the response worker queue and calls the handle
  2730. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2731. **/
  2732. static void
  2733. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2734. struct lpfc_sli_ring *pring, uint32_t mask)
  2735. {
  2736. struct lpfc_iocbq *irspiocbq;
  2737. struct hbq_dmabuf *dmabuf;
  2738. struct lpfc_cq_event *cq_event;
  2739. unsigned long iflag;
  2740. spin_lock_irqsave(&phba->hbalock, iflag);
  2741. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2742. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2743. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2744. /* Get the response iocb from the head of work queue */
  2745. spin_lock_irqsave(&phba->hbalock, iflag);
  2746. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2747. cq_event, struct lpfc_cq_event, list);
  2748. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2749. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2750. case CQE_CODE_COMPL_WQE:
  2751. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2752. cq_event);
  2753. /* Translate ELS WCQE to response IOCBQ */
  2754. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2755. irspiocbq);
  2756. if (irspiocbq)
  2757. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2758. irspiocbq);
  2759. break;
  2760. case CQE_CODE_RECEIVE:
  2761. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2762. cq_event);
  2763. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2764. break;
  2765. default:
  2766. break;
  2767. }
  2768. }
  2769. }
  2770. /**
  2771. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2772. * @phba: Pointer to HBA context object.
  2773. * @pring: Pointer to driver SLI ring object.
  2774. *
  2775. * This function aborts all iocbs in the given ring and frees all the iocb
  2776. * objects in txq. This function issues an abort iocb for all the iocb commands
  2777. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2778. * the return of this function. The caller is not required to hold any locks.
  2779. **/
  2780. void
  2781. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2782. {
  2783. LIST_HEAD(completions);
  2784. struct lpfc_iocbq *iocb, *next_iocb;
  2785. if (pring->ringno == LPFC_ELS_RING) {
  2786. lpfc_fabric_abort_hba(phba);
  2787. }
  2788. /* Error everything on txq and txcmplq
  2789. * First do the txq.
  2790. */
  2791. spin_lock_irq(&phba->hbalock);
  2792. list_splice_init(&pring->txq, &completions);
  2793. pring->txq_cnt = 0;
  2794. /* Next issue ABTS for everything on the txcmplq */
  2795. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2796. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2797. spin_unlock_irq(&phba->hbalock);
  2798. /* Cancel all the IOCBs from the completions list */
  2799. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2800. IOERR_SLI_ABORTED);
  2801. }
  2802. /**
  2803. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2804. * @phba: Pointer to HBA context object.
  2805. *
  2806. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2807. * objects in txq and txcmplq. This function will not issue abort iocbs
  2808. * for all the iocb commands in txcmplq, they will just be returned with
  2809. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2810. * slot has been permanently disabled.
  2811. **/
  2812. void
  2813. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2814. {
  2815. LIST_HEAD(txq);
  2816. LIST_HEAD(txcmplq);
  2817. struct lpfc_sli *psli = &phba->sli;
  2818. struct lpfc_sli_ring *pring;
  2819. /* Currently, only one fcp ring */
  2820. pring = &psli->ring[psli->fcp_ring];
  2821. spin_lock_irq(&phba->hbalock);
  2822. /* Retrieve everything on txq */
  2823. list_splice_init(&pring->txq, &txq);
  2824. pring->txq_cnt = 0;
  2825. /* Retrieve everything on the txcmplq */
  2826. list_splice_init(&pring->txcmplq, &txcmplq);
  2827. pring->txcmplq_cnt = 0;
  2828. spin_unlock_irq(&phba->hbalock);
  2829. /* Flush the txq */
  2830. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2831. IOERR_SLI_DOWN);
  2832. /* Flush the txcmpq */
  2833. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2834. IOERR_SLI_DOWN);
  2835. }
  2836. /**
  2837. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2838. * @phba: Pointer to HBA context object.
  2839. * @mask: Bit mask to be checked.
  2840. *
  2841. * This function reads the host status register and compares
  2842. * with the provided bit mask to check if HBA completed
  2843. * the restart. This function will wait in a loop for the
  2844. * HBA to complete restart. If the HBA does not restart within
  2845. * 15 iterations, the function will reset the HBA again. The
  2846. * function returns 1 when HBA fail to restart otherwise returns
  2847. * zero.
  2848. **/
  2849. static int
  2850. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2851. {
  2852. uint32_t status;
  2853. int i = 0;
  2854. int retval = 0;
  2855. /* Read the HBA Host Status Register */
  2856. status = readl(phba->HSregaddr);
  2857. /*
  2858. * Check status register every 100ms for 5 retries, then every
  2859. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2860. * every 2.5 sec for 4.
  2861. * Break our of the loop if errors occurred during init.
  2862. */
  2863. while (((status & mask) != mask) &&
  2864. !(status & HS_FFERM) &&
  2865. i++ < 20) {
  2866. if (i <= 5)
  2867. msleep(10);
  2868. else if (i <= 10)
  2869. msleep(500);
  2870. else
  2871. msleep(2500);
  2872. if (i == 15) {
  2873. /* Do post */
  2874. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2875. lpfc_sli_brdrestart(phba);
  2876. }
  2877. /* Read the HBA Host Status Register */
  2878. status = readl(phba->HSregaddr);
  2879. }
  2880. /* Check to see if any errors occurred during init */
  2881. if ((status & HS_FFERM) || (i >= 20)) {
  2882. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2883. "2751 Adapter failed to restart, "
  2884. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2885. status,
  2886. readl(phba->MBslimaddr + 0xa8),
  2887. readl(phba->MBslimaddr + 0xac));
  2888. phba->link_state = LPFC_HBA_ERROR;
  2889. retval = 1;
  2890. }
  2891. return retval;
  2892. }
  2893. /**
  2894. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2895. * @phba: Pointer to HBA context object.
  2896. * @mask: Bit mask to be checked.
  2897. *
  2898. * This function checks the host status register to check if HBA is
  2899. * ready. This function will wait in a loop for the HBA to be ready
  2900. * If the HBA is not ready , the function will will reset the HBA PCI
  2901. * function again. The function returns 1 when HBA fail to be ready
  2902. * otherwise returns zero.
  2903. **/
  2904. static int
  2905. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2906. {
  2907. uint32_t status;
  2908. int retval = 0;
  2909. /* Read the HBA Host Status Register */
  2910. status = lpfc_sli4_post_status_check(phba);
  2911. if (status) {
  2912. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2913. lpfc_sli_brdrestart(phba);
  2914. status = lpfc_sli4_post_status_check(phba);
  2915. }
  2916. /* Check to see if any errors occurred during init */
  2917. if (status) {
  2918. phba->link_state = LPFC_HBA_ERROR;
  2919. retval = 1;
  2920. } else
  2921. phba->sli4_hba.intr_enable = 0;
  2922. return retval;
  2923. }
  2924. /**
  2925. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2926. * @phba: Pointer to HBA context object.
  2927. * @mask: Bit mask to be checked.
  2928. *
  2929. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2930. * from the API jump table function pointer from the lpfc_hba struct.
  2931. **/
  2932. int
  2933. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2934. {
  2935. return phba->lpfc_sli_brdready(phba, mask);
  2936. }
  2937. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2938. /**
  2939. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2940. * @phba: Pointer to HBA context object.
  2941. *
  2942. * This function is called before resetting an HBA. This
  2943. * function requests HBA to quiesce DMAs before a reset.
  2944. **/
  2945. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2946. {
  2947. uint32_t __iomem *resp_buf;
  2948. uint32_t __iomem *mbox_buf;
  2949. volatile uint32_t mbox;
  2950. uint32_t hc_copy;
  2951. int i;
  2952. uint8_t hdrtype;
  2953. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2954. if (hdrtype != 0x80 ||
  2955. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2956. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2957. return;
  2958. /*
  2959. * Tell the other part of the chip to suspend temporarily all
  2960. * its DMA activity.
  2961. */
  2962. resp_buf = phba->MBslimaddr;
  2963. /* Disable the error attention */
  2964. hc_copy = readl(phba->HCregaddr);
  2965. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2966. readl(phba->HCregaddr); /* flush */
  2967. phba->link_flag |= LS_IGNORE_ERATT;
  2968. if (readl(phba->HAregaddr) & HA_ERATT) {
  2969. /* Clear Chip error bit */
  2970. writel(HA_ERATT, phba->HAregaddr);
  2971. phba->pport->stopped = 1;
  2972. }
  2973. mbox = 0;
  2974. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2975. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2976. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2977. mbox_buf = phba->MBslimaddr;
  2978. writel(mbox, mbox_buf);
  2979. for (i = 0;
  2980. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2981. mdelay(1);
  2982. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2983. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2984. phba->pport->stopped)
  2985. goto restore_hc;
  2986. else
  2987. goto clear_errat;
  2988. }
  2989. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2990. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2991. mdelay(1);
  2992. clear_errat:
  2993. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2994. mdelay(1);
  2995. if (readl(phba->HAregaddr) & HA_ERATT) {
  2996. writel(HA_ERATT, phba->HAregaddr);
  2997. phba->pport->stopped = 1;
  2998. }
  2999. restore_hc:
  3000. phba->link_flag &= ~LS_IGNORE_ERATT;
  3001. writel(hc_copy, phba->HCregaddr);
  3002. readl(phba->HCregaddr); /* flush */
  3003. }
  3004. /**
  3005. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3006. * @phba: Pointer to HBA context object.
  3007. *
  3008. * This function issues a kill_board mailbox command and waits for
  3009. * the error attention interrupt. This function is called for stopping
  3010. * the firmware processing. The caller is not required to hold any
  3011. * locks. This function calls lpfc_hba_down_post function to free
  3012. * any pending commands after the kill. The function will return 1 when it
  3013. * fails to kill the board else will return 0.
  3014. **/
  3015. int
  3016. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3017. {
  3018. struct lpfc_sli *psli;
  3019. LPFC_MBOXQ_t *pmb;
  3020. uint32_t status;
  3021. uint32_t ha_copy;
  3022. int retval;
  3023. int i = 0;
  3024. psli = &phba->sli;
  3025. /* Kill HBA */
  3026. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3027. "0329 Kill HBA Data: x%x x%x\n",
  3028. phba->pport->port_state, psli->sli_flag);
  3029. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3030. if (!pmb)
  3031. return 1;
  3032. /* Disable the error attention */
  3033. spin_lock_irq(&phba->hbalock);
  3034. status = readl(phba->HCregaddr);
  3035. status &= ~HC_ERINT_ENA;
  3036. writel(status, phba->HCregaddr);
  3037. readl(phba->HCregaddr); /* flush */
  3038. phba->link_flag |= LS_IGNORE_ERATT;
  3039. spin_unlock_irq(&phba->hbalock);
  3040. lpfc_kill_board(phba, pmb);
  3041. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3042. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3043. if (retval != MBX_SUCCESS) {
  3044. if (retval != MBX_BUSY)
  3045. mempool_free(pmb, phba->mbox_mem_pool);
  3046. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3047. "2752 KILL_BOARD command failed retval %d\n",
  3048. retval);
  3049. spin_lock_irq(&phba->hbalock);
  3050. phba->link_flag &= ~LS_IGNORE_ERATT;
  3051. spin_unlock_irq(&phba->hbalock);
  3052. return 1;
  3053. }
  3054. spin_lock_irq(&phba->hbalock);
  3055. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3056. spin_unlock_irq(&phba->hbalock);
  3057. mempool_free(pmb, phba->mbox_mem_pool);
  3058. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3059. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3060. * 3 seconds we still set HBA_ERROR state because the status of the
  3061. * board is now undefined.
  3062. */
  3063. ha_copy = readl(phba->HAregaddr);
  3064. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3065. mdelay(100);
  3066. ha_copy = readl(phba->HAregaddr);
  3067. }
  3068. del_timer_sync(&psli->mbox_tmo);
  3069. if (ha_copy & HA_ERATT) {
  3070. writel(HA_ERATT, phba->HAregaddr);
  3071. phba->pport->stopped = 1;
  3072. }
  3073. spin_lock_irq(&phba->hbalock);
  3074. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3075. psli->mbox_active = NULL;
  3076. phba->link_flag &= ~LS_IGNORE_ERATT;
  3077. spin_unlock_irq(&phba->hbalock);
  3078. lpfc_hba_down_post(phba);
  3079. phba->link_state = LPFC_HBA_ERROR;
  3080. return ha_copy & HA_ERATT ? 0 : 1;
  3081. }
  3082. /**
  3083. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3084. * @phba: Pointer to HBA context object.
  3085. *
  3086. * This function resets the HBA by writing HC_INITFF to the control
  3087. * register. After the HBA resets, this function resets all the iocb ring
  3088. * indices. This function disables PCI layer parity checking during
  3089. * the reset.
  3090. * This function returns 0 always.
  3091. * The caller is not required to hold any locks.
  3092. **/
  3093. int
  3094. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3095. {
  3096. struct lpfc_sli *psli;
  3097. struct lpfc_sli_ring *pring;
  3098. uint16_t cfg_value;
  3099. int i;
  3100. psli = &phba->sli;
  3101. /* Reset HBA */
  3102. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3103. "0325 Reset HBA Data: x%x x%x\n",
  3104. phba->pport->port_state, psli->sli_flag);
  3105. /* perform board reset */
  3106. phba->fc_eventTag = 0;
  3107. phba->link_events = 0;
  3108. phba->pport->fc_myDID = 0;
  3109. phba->pport->fc_prevDID = 0;
  3110. /* Turn off parity checking and serr during the physical reset */
  3111. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3112. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3113. (cfg_value &
  3114. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3115. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3116. /* Now toggle INITFF bit in the Host Control Register */
  3117. writel(HC_INITFF, phba->HCregaddr);
  3118. mdelay(1);
  3119. readl(phba->HCregaddr); /* flush */
  3120. writel(0, phba->HCregaddr);
  3121. readl(phba->HCregaddr); /* flush */
  3122. /* Restore PCI cmd register */
  3123. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3124. /* Initialize relevant SLI info */
  3125. for (i = 0; i < psli->num_rings; i++) {
  3126. pring = &psli->ring[i];
  3127. pring->flag = 0;
  3128. pring->rspidx = 0;
  3129. pring->next_cmdidx = 0;
  3130. pring->local_getidx = 0;
  3131. pring->cmdidx = 0;
  3132. pring->missbufcnt = 0;
  3133. }
  3134. phba->link_state = LPFC_WARM_START;
  3135. return 0;
  3136. }
  3137. /**
  3138. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3139. * @phba: Pointer to HBA context object.
  3140. *
  3141. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3142. * checking during resets the device. The caller is not required to hold
  3143. * any locks.
  3144. *
  3145. * This function returns 0 always.
  3146. **/
  3147. int
  3148. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3149. {
  3150. struct lpfc_sli *psli = &phba->sli;
  3151. uint16_t cfg_value;
  3152. uint8_t qindx;
  3153. /* Reset HBA */
  3154. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3155. "0295 Reset HBA Data: x%x x%x\n",
  3156. phba->pport->port_state, psli->sli_flag);
  3157. /* perform board reset */
  3158. phba->fc_eventTag = 0;
  3159. phba->link_events = 0;
  3160. phba->pport->fc_myDID = 0;
  3161. phba->pport->fc_prevDID = 0;
  3162. /* Turn off parity checking and serr during the physical reset */
  3163. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3164. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3165. (cfg_value &
  3166. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3167. spin_lock_irq(&phba->hbalock);
  3168. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3169. phba->fcf.fcf_flag = 0;
  3170. /* Clean up the child queue list for the CQs */
  3171. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3172. list_del_init(&phba->sli4_hba.els_wq->list);
  3173. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3174. list_del_init(&phba->sli4_hba.dat_rq->list);
  3175. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3176. list_del_init(&phba->sli4_hba.els_cq->list);
  3177. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3178. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3179. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3180. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3181. spin_unlock_irq(&phba->hbalock);
  3182. /* Now physically reset the device */
  3183. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3184. "0389 Performing PCI function reset!\n");
  3185. /* Perform FCoE PCI function reset */
  3186. lpfc_pci_function_reset(phba);
  3187. return 0;
  3188. }
  3189. /**
  3190. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3191. * @phba: Pointer to HBA context object.
  3192. *
  3193. * This function is called in the SLI initialization code path to
  3194. * restart the HBA. The caller is not required to hold any lock.
  3195. * This function writes MBX_RESTART mailbox command to the SLIM and
  3196. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3197. * function to free any pending commands. The function enables
  3198. * POST only during the first initialization. The function returns zero.
  3199. * The function does not guarantee completion of MBX_RESTART mailbox
  3200. * command before the return of this function.
  3201. **/
  3202. static int
  3203. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3204. {
  3205. MAILBOX_t *mb;
  3206. struct lpfc_sli *psli;
  3207. volatile uint32_t word0;
  3208. void __iomem *to_slim;
  3209. uint32_t hba_aer_enabled;
  3210. spin_lock_irq(&phba->hbalock);
  3211. /* Take PCIe device Advanced Error Reporting (AER) state */
  3212. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3213. psli = &phba->sli;
  3214. /* Restart HBA */
  3215. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3216. "0337 Restart HBA Data: x%x x%x\n",
  3217. phba->pport->port_state, psli->sli_flag);
  3218. word0 = 0;
  3219. mb = (MAILBOX_t *) &word0;
  3220. mb->mbxCommand = MBX_RESTART;
  3221. mb->mbxHc = 1;
  3222. lpfc_reset_barrier(phba);
  3223. to_slim = phba->MBslimaddr;
  3224. writel(*(uint32_t *) mb, to_slim);
  3225. readl(to_slim); /* flush */
  3226. /* Only skip post after fc_ffinit is completed */
  3227. if (phba->pport->port_state)
  3228. word0 = 1; /* This is really setting up word1 */
  3229. else
  3230. word0 = 0; /* This is really setting up word1 */
  3231. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3232. writel(*(uint32_t *) mb, to_slim);
  3233. readl(to_slim); /* flush */
  3234. lpfc_sli_brdreset(phba);
  3235. phba->pport->stopped = 0;
  3236. phba->link_state = LPFC_INIT_START;
  3237. phba->hba_flag = 0;
  3238. spin_unlock_irq(&phba->hbalock);
  3239. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3240. psli->stats_start = get_seconds();
  3241. /* Give the INITFF and Post time to settle. */
  3242. mdelay(100);
  3243. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3244. if (hba_aer_enabled)
  3245. pci_disable_pcie_error_reporting(phba->pcidev);
  3246. lpfc_hba_down_post(phba);
  3247. return 0;
  3248. }
  3249. /**
  3250. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3251. * @phba: Pointer to HBA context object.
  3252. *
  3253. * This function is called in the SLI initialization code path to restart
  3254. * a SLI4 HBA. The caller is not required to hold any lock.
  3255. * At the end of the function, it calls lpfc_hba_down_post function to
  3256. * free any pending commands.
  3257. **/
  3258. static int
  3259. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3260. {
  3261. struct lpfc_sli *psli = &phba->sli;
  3262. uint32_t hba_aer_enabled;
  3263. /* Restart HBA */
  3264. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3265. "0296 Restart HBA Data: x%x x%x\n",
  3266. phba->pport->port_state, psli->sli_flag);
  3267. /* Take PCIe device Advanced Error Reporting (AER) state */
  3268. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3269. lpfc_sli4_brdreset(phba);
  3270. spin_lock_irq(&phba->hbalock);
  3271. phba->pport->stopped = 0;
  3272. phba->link_state = LPFC_INIT_START;
  3273. phba->hba_flag = 0;
  3274. spin_unlock_irq(&phba->hbalock);
  3275. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3276. psli->stats_start = get_seconds();
  3277. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3278. if (hba_aer_enabled)
  3279. pci_disable_pcie_error_reporting(phba->pcidev);
  3280. lpfc_hba_down_post(phba);
  3281. return 0;
  3282. }
  3283. /**
  3284. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3285. * @phba: Pointer to HBA context object.
  3286. *
  3287. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3288. * API jump table function pointer from the lpfc_hba struct.
  3289. **/
  3290. int
  3291. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3292. {
  3293. return phba->lpfc_sli_brdrestart(phba);
  3294. }
  3295. /**
  3296. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3297. * @phba: Pointer to HBA context object.
  3298. *
  3299. * This function is called after a HBA restart to wait for successful
  3300. * restart of the HBA. Successful restart of the HBA is indicated by
  3301. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3302. * iteration, the function will restart the HBA again. The function returns
  3303. * zero if HBA successfully restarted else returns negative error code.
  3304. **/
  3305. static int
  3306. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3307. {
  3308. uint32_t status, i = 0;
  3309. /* Read the HBA Host Status Register */
  3310. status = readl(phba->HSregaddr);
  3311. /* Check status register to see what current state is */
  3312. i = 0;
  3313. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3314. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3315. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3316. * 4.
  3317. */
  3318. if (i++ >= 20) {
  3319. /* Adapter failed to init, timeout, status reg
  3320. <status> */
  3321. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3322. "0436 Adapter failed to init, "
  3323. "timeout, status reg x%x, "
  3324. "FW Data: A8 x%x AC x%x\n", status,
  3325. readl(phba->MBslimaddr + 0xa8),
  3326. readl(phba->MBslimaddr + 0xac));
  3327. phba->link_state = LPFC_HBA_ERROR;
  3328. return -ETIMEDOUT;
  3329. }
  3330. /* Check to see if any errors occurred during init */
  3331. if (status & HS_FFERM) {
  3332. /* ERROR: During chipset initialization */
  3333. /* Adapter failed to init, chipset, status reg
  3334. <status> */
  3335. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3336. "0437 Adapter failed to init, "
  3337. "chipset, status reg x%x, "
  3338. "FW Data: A8 x%x AC x%x\n", status,
  3339. readl(phba->MBslimaddr + 0xa8),
  3340. readl(phba->MBslimaddr + 0xac));
  3341. phba->link_state = LPFC_HBA_ERROR;
  3342. return -EIO;
  3343. }
  3344. if (i <= 5) {
  3345. msleep(10);
  3346. } else if (i <= 10) {
  3347. msleep(500);
  3348. } else {
  3349. msleep(2500);
  3350. }
  3351. if (i == 15) {
  3352. /* Do post */
  3353. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3354. lpfc_sli_brdrestart(phba);
  3355. }
  3356. /* Read the HBA Host Status Register */
  3357. status = readl(phba->HSregaddr);
  3358. }
  3359. /* Check to see if any errors occurred during init */
  3360. if (status & HS_FFERM) {
  3361. /* ERROR: During chipset initialization */
  3362. /* Adapter failed to init, chipset, status reg <status> */
  3363. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3364. "0438 Adapter failed to init, chipset, "
  3365. "status reg x%x, "
  3366. "FW Data: A8 x%x AC x%x\n", status,
  3367. readl(phba->MBslimaddr + 0xa8),
  3368. readl(phba->MBslimaddr + 0xac));
  3369. phba->link_state = LPFC_HBA_ERROR;
  3370. return -EIO;
  3371. }
  3372. /* Clear all interrupt enable conditions */
  3373. writel(0, phba->HCregaddr);
  3374. readl(phba->HCregaddr); /* flush */
  3375. /* setup host attn register */
  3376. writel(0xffffffff, phba->HAregaddr);
  3377. readl(phba->HAregaddr); /* flush */
  3378. return 0;
  3379. }
  3380. /**
  3381. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3382. *
  3383. * This function calculates and returns the number of HBQs required to be
  3384. * configured.
  3385. **/
  3386. int
  3387. lpfc_sli_hbq_count(void)
  3388. {
  3389. return ARRAY_SIZE(lpfc_hbq_defs);
  3390. }
  3391. /**
  3392. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3393. *
  3394. * This function adds the number of hbq entries in every HBQ to get
  3395. * the total number of hbq entries required for the HBA and returns
  3396. * the total count.
  3397. **/
  3398. static int
  3399. lpfc_sli_hbq_entry_count(void)
  3400. {
  3401. int hbq_count = lpfc_sli_hbq_count();
  3402. int count = 0;
  3403. int i;
  3404. for (i = 0; i < hbq_count; ++i)
  3405. count += lpfc_hbq_defs[i]->entry_count;
  3406. return count;
  3407. }
  3408. /**
  3409. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3410. *
  3411. * This function calculates amount of memory required for all hbq entries
  3412. * to be configured and returns the total memory required.
  3413. **/
  3414. int
  3415. lpfc_sli_hbq_size(void)
  3416. {
  3417. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3418. }
  3419. /**
  3420. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3421. * @phba: Pointer to HBA context object.
  3422. *
  3423. * This function is called during the SLI initialization to configure
  3424. * all the HBQs and post buffers to the HBQ. The caller is not
  3425. * required to hold any locks. This function will return zero if successful
  3426. * else it will return negative error code.
  3427. **/
  3428. static int
  3429. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3430. {
  3431. int hbq_count = lpfc_sli_hbq_count();
  3432. LPFC_MBOXQ_t *pmb;
  3433. MAILBOX_t *pmbox;
  3434. uint32_t hbqno;
  3435. uint32_t hbq_entry_index;
  3436. /* Get a Mailbox buffer to setup mailbox
  3437. * commands for HBA initialization
  3438. */
  3439. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3440. if (!pmb)
  3441. return -ENOMEM;
  3442. pmbox = &pmb->u.mb;
  3443. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3444. phba->link_state = LPFC_INIT_MBX_CMDS;
  3445. phba->hbq_in_use = 1;
  3446. hbq_entry_index = 0;
  3447. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3448. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3449. phba->hbqs[hbqno].hbqPutIdx = 0;
  3450. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3451. phba->hbqs[hbqno].entry_count =
  3452. lpfc_hbq_defs[hbqno]->entry_count;
  3453. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3454. hbq_entry_index, pmb);
  3455. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3456. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3457. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3458. mbxStatus <status>, ring <num> */
  3459. lpfc_printf_log(phba, KERN_ERR,
  3460. LOG_SLI | LOG_VPORT,
  3461. "1805 Adapter failed to init. "
  3462. "Data: x%x x%x x%x\n",
  3463. pmbox->mbxCommand,
  3464. pmbox->mbxStatus, hbqno);
  3465. phba->link_state = LPFC_HBA_ERROR;
  3466. mempool_free(pmb, phba->mbox_mem_pool);
  3467. return -ENXIO;
  3468. }
  3469. }
  3470. phba->hbq_count = hbq_count;
  3471. mempool_free(pmb, phba->mbox_mem_pool);
  3472. /* Initially populate or replenish the HBQs */
  3473. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3474. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3475. return 0;
  3476. }
  3477. /**
  3478. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3479. * @phba: Pointer to HBA context object.
  3480. *
  3481. * This function is called during the SLI initialization to configure
  3482. * all the HBQs and post buffers to the HBQ. The caller is not
  3483. * required to hold any locks. This function will return zero if successful
  3484. * else it will return negative error code.
  3485. **/
  3486. static int
  3487. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3488. {
  3489. phba->hbq_in_use = 1;
  3490. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3491. phba->hbq_count = 1;
  3492. /* Initially populate or replenish the HBQs */
  3493. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3494. return 0;
  3495. }
  3496. /**
  3497. * lpfc_sli_config_port - Issue config port mailbox command
  3498. * @phba: Pointer to HBA context object.
  3499. * @sli_mode: sli mode - 2/3
  3500. *
  3501. * This function is called by the sli intialization code path
  3502. * to issue config_port mailbox command. This function restarts the
  3503. * HBA firmware and issues a config_port mailbox command to configure
  3504. * the SLI interface in the sli mode specified by sli_mode
  3505. * variable. The caller is not required to hold any locks.
  3506. * The function returns 0 if successful, else returns negative error
  3507. * code.
  3508. **/
  3509. int
  3510. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3511. {
  3512. LPFC_MBOXQ_t *pmb;
  3513. uint32_t resetcount = 0, rc = 0, done = 0;
  3514. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3515. if (!pmb) {
  3516. phba->link_state = LPFC_HBA_ERROR;
  3517. return -ENOMEM;
  3518. }
  3519. phba->sli_rev = sli_mode;
  3520. while (resetcount < 2 && !done) {
  3521. spin_lock_irq(&phba->hbalock);
  3522. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3523. spin_unlock_irq(&phba->hbalock);
  3524. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3525. lpfc_sli_brdrestart(phba);
  3526. rc = lpfc_sli_chipset_init(phba);
  3527. if (rc)
  3528. break;
  3529. spin_lock_irq(&phba->hbalock);
  3530. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3531. spin_unlock_irq(&phba->hbalock);
  3532. resetcount++;
  3533. /* Call pre CONFIG_PORT mailbox command initialization. A
  3534. * value of 0 means the call was successful. Any other
  3535. * nonzero value is a failure, but if ERESTART is returned,
  3536. * the driver may reset the HBA and try again.
  3537. */
  3538. rc = lpfc_config_port_prep(phba);
  3539. if (rc == -ERESTART) {
  3540. phba->link_state = LPFC_LINK_UNKNOWN;
  3541. continue;
  3542. } else if (rc)
  3543. break;
  3544. phba->link_state = LPFC_INIT_MBX_CMDS;
  3545. lpfc_config_port(phba, pmb);
  3546. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3547. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3548. LPFC_SLI3_HBQ_ENABLED |
  3549. LPFC_SLI3_CRP_ENABLED |
  3550. LPFC_SLI3_BG_ENABLED);
  3551. if (rc != MBX_SUCCESS) {
  3552. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3553. "0442 Adapter failed to init, mbxCmd x%x "
  3554. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3555. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3556. spin_lock_irq(&phba->hbalock);
  3557. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3558. spin_unlock_irq(&phba->hbalock);
  3559. rc = -ENXIO;
  3560. } else {
  3561. /* Allow asynchronous mailbox command to go through */
  3562. spin_lock_irq(&phba->hbalock);
  3563. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3564. spin_unlock_irq(&phba->hbalock);
  3565. done = 1;
  3566. }
  3567. }
  3568. if (!done) {
  3569. rc = -EINVAL;
  3570. goto do_prep_failed;
  3571. }
  3572. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3573. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3574. rc = -ENXIO;
  3575. goto do_prep_failed;
  3576. }
  3577. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3578. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3579. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3580. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3581. phba->max_vpi : phba->max_vports;
  3582. } else
  3583. phba->max_vpi = 0;
  3584. if (pmb->u.mb.un.varCfgPort.gdss)
  3585. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3586. if (pmb->u.mb.un.varCfgPort.gerbm)
  3587. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3588. if (pmb->u.mb.un.varCfgPort.gcrp)
  3589. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3590. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3591. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3592. if (phba->cfg_enable_bg) {
  3593. if (pmb->u.mb.un.varCfgPort.gbg)
  3594. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3595. else
  3596. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3597. "0443 Adapter did not grant "
  3598. "BlockGuard\n");
  3599. }
  3600. } else {
  3601. phba->hbq_get = NULL;
  3602. phba->port_gp = phba->mbox->us.s2.port;
  3603. phba->max_vpi = 0;
  3604. }
  3605. do_prep_failed:
  3606. mempool_free(pmb, phba->mbox_mem_pool);
  3607. return rc;
  3608. }
  3609. /**
  3610. * lpfc_sli_hba_setup - SLI intialization function
  3611. * @phba: Pointer to HBA context object.
  3612. *
  3613. * This function is the main SLI intialization function. This function
  3614. * is called by the HBA intialization code, HBA reset code and HBA
  3615. * error attention handler code. Caller is not required to hold any
  3616. * locks. This function issues config_port mailbox command to configure
  3617. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3618. * calls the config_port_post function to issue init_link mailbox
  3619. * command and to start the discovery. The function will return zero
  3620. * if successful, else it will return negative error code.
  3621. **/
  3622. int
  3623. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3624. {
  3625. uint32_t rc;
  3626. int mode = 3;
  3627. switch (lpfc_sli_mode) {
  3628. case 2:
  3629. if (phba->cfg_enable_npiv) {
  3630. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3631. "1824 NPIV enabled: Override lpfc_sli_mode "
  3632. "parameter (%d) to auto (0).\n",
  3633. lpfc_sli_mode);
  3634. break;
  3635. }
  3636. mode = 2;
  3637. break;
  3638. case 0:
  3639. case 3:
  3640. break;
  3641. default:
  3642. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3643. "1819 Unrecognized lpfc_sli_mode "
  3644. "parameter: %d.\n", lpfc_sli_mode);
  3645. break;
  3646. }
  3647. rc = lpfc_sli_config_port(phba, mode);
  3648. if (rc && lpfc_sli_mode == 3)
  3649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3650. "1820 Unable to select SLI-3. "
  3651. "Not supported by adapter.\n");
  3652. if (rc && mode != 2)
  3653. rc = lpfc_sli_config_port(phba, 2);
  3654. if (rc)
  3655. goto lpfc_sli_hba_setup_error;
  3656. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3657. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3658. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3659. if (!rc) {
  3660. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3661. "2709 This device supports "
  3662. "Advanced Error Reporting (AER)\n");
  3663. spin_lock_irq(&phba->hbalock);
  3664. phba->hba_flag |= HBA_AER_ENABLED;
  3665. spin_unlock_irq(&phba->hbalock);
  3666. } else {
  3667. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3668. "2708 This device does not support "
  3669. "Advanced Error Reporting (AER)\n");
  3670. phba->cfg_aer_support = 0;
  3671. }
  3672. }
  3673. if (phba->sli_rev == 3) {
  3674. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3675. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3676. } else {
  3677. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3678. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3679. phba->sli3_options = 0;
  3680. }
  3681. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3682. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3683. phba->sli_rev, phba->max_vpi);
  3684. rc = lpfc_sli_ring_map(phba);
  3685. if (rc)
  3686. goto lpfc_sli_hba_setup_error;
  3687. /* Init HBQs */
  3688. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3689. rc = lpfc_sli_hbq_setup(phba);
  3690. if (rc)
  3691. goto lpfc_sli_hba_setup_error;
  3692. }
  3693. spin_lock_irq(&phba->hbalock);
  3694. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3695. spin_unlock_irq(&phba->hbalock);
  3696. rc = lpfc_config_port_post(phba);
  3697. if (rc)
  3698. goto lpfc_sli_hba_setup_error;
  3699. return rc;
  3700. lpfc_sli_hba_setup_error:
  3701. phba->link_state = LPFC_HBA_ERROR;
  3702. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3703. "0445 Firmware initialization failed\n");
  3704. return rc;
  3705. }
  3706. /**
  3707. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3708. * @phba: Pointer to HBA context object.
  3709. * @mboxq: mailbox pointer.
  3710. * This function issue a dump mailbox command to read config region
  3711. * 23 and parse the records in the region and populate driver
  3712. * data structure.
  3713. **/
  3714. static int
  3715. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3716. LPFC_MBOXQ_t *mboxq)
  3717. {
  3718. struct lpfc_dmabuf *mp;
  3719. struct lpfc_mqe *mqe;
  3720. uint32_t data_length;
  3721. int rc;
  3722. /* Program the default value of vlan_id and fc_map */
  3723. phba->valid_vlan = 0;
  3724. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3725. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3726. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3727. mqe = &mboxq->u.mqe;
  3728. if (lpfc_dump_fcoe_param(phba, mboxq))
  3729. return -ENOMEM;
  3730. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3731. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3732. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3733. "(%d):2571 Mailbox cmd x%x Status x%x "
  3734. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3735. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3736. "CQ: x%x x%x x%x x%x\n",
  3737. mboxq->vport ? mboxq->vport->vpi : 0,
  3738. bf_get(lpfc_mqe_command, mqe),
  3739. bf_get(lpfc_mqe_status, mqe),
  3740. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3741. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3742. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3743. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3744. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3745. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3746. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3747. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3748. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3749. mboxq->mcqe.word0,
  3750. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3751. mboxq->mcqe.trailer);
  3752. if (rc) {
  3753. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3754. kfree(mp);
  3755. return -EIO;
  3756. }
  3757. data_length = mqe->un.mb_words[5];
  3758. if (data_length > DMP_RGN23_SIZE) {
  3759. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3760. kfree(mp);
  3761. return -EIO;
  3762. }
  3763. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3764. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3765. kfree(mp);
  3766. return 0;
  3767. }
  3768. /**
  3769. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3770. * @phba: pointer to lpfc hba data structure.
  3771. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3772. * @vpd: pointer to the memory to hold resulting port vpd data.
  3773. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3774. * On output, the number of data bytes in @vpd.
  3775. *
  3776. * This routine executes a READ_REV SLI4 mailbox command. In
  3777. * addition, this routine gets the port vpd data.
  3778. *
  3779. * Return codes
  3780. * 0 - successful
  3781. * ENOMEM - could not allocated memory.
  3782. **/
  3783. static int
  3784. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3785. uint8_t *vpd, uint32_t *vpd_size)
  3786. {
  3787. int rc = 0;
  3788. uint32_t dma_size;
  3789. struct lpfc_dmabuf *dmabuf;
  3790. struct lpfc_mqe *mqe;
  3791. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3792. if (!dmabuf)
  3793. return -ENOMEM;
  3794. /*
  3795. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3796. * mailbox command.
  3797. */
  3798. dma_size = *vpd_size;
  3799. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3800. dma_size,
  3801. &dmabuf->phys,
  3802. GFP_KERNEL);
  3803. if (!dmabuf->virt) {
  3804. kfree(dmabuf);
  3805. return -ENOMEM;
  3806. }
  3807. memset(dmabuf->virt, 0, dma_size);
  3808. /*
  3809. * The SLI4 implementation of READ_REV conflicts at word1,
  3810. * bits 31:16 and SLI4 adds vpd functionality not present
  3811. * in SLI3. This code corrects the conflicts.
  3812. */
  3813. lpfc_read_rev(phba, mboxq);
  3814. mqe = &mboxq->u.mqe;
  3815. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3816. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3817. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3818. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3819. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3820. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3821. if (rc) {
  3822. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3823. dmabuf->virt, dmabuf->phys);
  3824. kfree(dmabuf);
  3825. return -EIO;
  3826. }
  3827. /*
  3828. * The available vpd length cannot be bigger than the
  3829. * DMA buffer passed to the port. Catch the less than
  3830. * case and update the caller's size.
  3831. */
  3832. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3833. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3834. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3835. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3836. dmabuf->virt, dmabuf->phys);
  3837. kfree(dmabuf);
  3838. return 0;
  3839. }
  3840. /**
  3841. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3842. * @phba: pointer to lpfc hba data structure.
  3843. *
  3844. * This routine is called to explicitly arm the SLI4 device's completion and
  3845. * event queues
  3846. **/
  3847. static void
  3848. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3849. {
  3850. uint8_t fcp_eqidx;
  3851. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3852. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3853. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3854. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3855. LPFC_QUEUE_REARM);
  3856. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3857. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3858. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3859. LPFC_QUEUE_REARM);
  3860. }
  3861. /**
  3862. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3863. * @phba: Pointer to HBA context object.
  3864. *
  3865. * This function is the main SLI4 device intialization PCI function. This
  3866. * function is called by the HBA intialization code, HBA reset code and
  3867. * HBA error attention handler code. Caller is not required to hold any
  3868. * locks.
  3869. **/
  3870. int
  3871. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3872. {
  3873. int rc;
  3874. LPFC_MBOXQ_t *mboxq;
  3875. struct lpfc_mqe *mqe;
  3876. uint8_t *vpd;
  3877. uint32_t vpd_size;
  3878. uint32_t ftr_rsp = 0;
  3879. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3880. struct lpfc_vport *vport = phba->pport;
  3881. struct lpfc_dmabuf *mp;
  3882. /* Perform a PCI function reset to start from clean */
  3883. rc = lpfc_pci_function_reset(phba);
  3884. if (unlikely(rc))
  3885. return -ENODEV;
  3886. /* Check the HBA Host Status Register for readyness */
  3887. rc = lpfc_sli4_post_status_check(phba);
  3888. if (unlikely(rc))
  3889. return -ENODEV;
  3890. else {
  3891. spin_lock_irq(&phba->hbalock);
  3892. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3893. spin_unlock_irq(&phba->hbalock);
  3894. }
  3895. /*
  3896. * Allocate a single mailbox container for initializing the
  3897. * port.
  3898. */
  3899. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3900. if (!mboxq)
  3901. return -ENOMEM;
  3902. /*
  3903. * Continue initialization with default values even if driver failed
  3904. * to read FCoE param config regions
  3905. */
  3906. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3907. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3908. "2570 Failed to read FCoE parameters\n");
  3909. /* Issue READ_REV to collect vpd and FW information. */
  3910. vpd_size = SLI4_PAGE_SIZE;
  3911. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3912. if (!vpd) {
  3913. rc = -ENOMEM;
  3914. goto out_free_mbox;
  3915. }
  3916. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3917. if (unlikely(rc))
  3918. goto out_free_vpd;
  3919. mqe = &mboxq->u.mqe;
  3920. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3921. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3922. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3923. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3924. LPFC_DCBX_CEE_MODE)
  3925. phba->hba_flag |= HBA_FIP_SUPPORT;
  3926. else
  3927. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3928. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3929. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3930. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3931. "0376 READ_REV Error. SLI Level %d "
  3932. "FCoE enabled %d\n",
  3933. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3934. rc = -EIO;
  3935. goto out_free_vpd;
  3936. }
  3937. /*
  3938. * Evaluate the read rev and vpd data. Populate the driver
  3939. * state with the results. If this routine fails, the failure
  3940. * is not fatal as the driver will use generic values.
  3941. */
  3942. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3943. if (unlikely(!rc)) {
  3944. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3945. "0377 Error %d parsing vpd. "
  3946. "Using defaults.\n", rc);
  3947. rc = 0;
  3948. }
  3949. /* Save information as VPD data */
  3950. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3951. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3952. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3953. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3954. &mqe->un.read_rev);
  3955. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3956. &mqe->un.read_rev);
  3957. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3958. &mqe->un.read_rev);
  3959. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3960. &mqe->un.read_rev);
  3961. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3962. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3963. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3964. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3965. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3966. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3967. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3968. "(%d):0380 READ_REV Status x%x "
  3969. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3970. mboxq->vport ? mboxq->vport->vpi : 0,
  3971. bf_get(lpfc_mqe_status, mqe),
  3972. phba->vpd.rev.opFwName,
  3973. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3974. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3975. /*
  3976. * Discover the port's supported feature set and match it against the
  3977. * hosts requests.
  3978. */
  3979. lpfc_request_features(phba, mboxq);
  3980. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3981. if (unlikely(rc)) {
  3982. rc = -EIO;
  3983. goto out_free_vpd;
  3984. }
  3985. /*
  3986. * The port must support FCP initiator mode as this is the
  3987. * only mode running in the host.
  3988. */
  3989. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3990. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3991. "0378 No support for fcpi mode.\n");
  3992. ftr_rsp++;
  3993. }
  3994. /*
  3995. * If the port cannot support the host's requested features
  3996. * then turn off the global config parameters to disable the
  3997. * feature in the driver. This is not a fatal error.
  3998. */
  3999. if ((phba->cfg_enable_bg) &&
  4000. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4001. ftr_rsp++;
  4002. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4003. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4004. ftr_rsp++;
  4005. if (ftr_rsp) {
  4006. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4007. "0379 Feature Mismatch Data: x%08x %08x "
  4008. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4009. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4010. phba->cfg_enable_npiv, phba->max_vpi);
  4011. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4012. phba->cfg_enable_bg = 0;
  4013. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4014. phba->cfg_enable_npiv = 0;
  4015. }
  4016. /* These SLI3 features are assumed in SLI4 */
  4017. spin_lock_irq(&phba->hbalock);
  4018. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4019. spin_unlock_irq(&phba->hbalock);
  4020. /* Read the port's service parameters. */
  4021. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4022. if (rc) {
  4023. phba->link_state = LPFC_HBA_ERROR;
  4024. rc = -ENOMEM;
  4025. goto out_free_vpd;
  4026. }
  4027. mboxq->vport = vport;
  4028. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4029. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4030. if (rc == MBX_SUCCESS) {
  4031. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4032. rc = 0;
  4033. }
  4034. /*
  4035. * This memory was allocated by the lpfc_read_sparam routine. Release
  4036. * it to the mbuf pool.
  4037. */
  4038. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4039. kfree(mp);
  4040. mboxq->context1 = NULL;
  4041. if (unlikely(rc)) {
  4042. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4043. "0382 READ_SPARAM command failed "
  4044. "status %d, mbxStatus x%x\n",
  4045. rc, bf_get(lpfc_mqe_status, mqe));
  4046. phba->link_state = LPFC_HBA_ERROR;
  4047. rc = -EIO;
  4048. goto out_free_vpd;
  4049. }
  4050. if (phba->cfg_soft_wwnn)
  4051. u64_to_wwn(phba->cfg_soft_wwnn,
  4052. vport->fc_sparam.nodeName.u.wwn);
  4053. if (phba->cfg_soft_wwpn)
  4054. u64_to_wwn(phba->cfg_soft_wwpn,
  4055. vport->fc_sparam.portName.u.wwn);
  4056. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4057. sizeof(struct lpfc_name));
  4058. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4059. sizeof(struct lpfc_name));
  4060. /* Update the fc_host data structures with new wwn. */
  4061. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4062. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4063. /* Register SGL pool to the device using non-embedded mailbox command */
  4064. rc = lpfc_sli4_post_sgl_list(phba);
  4065. if (unlikely(rc)) {
  4066. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4067. "0582 Error %d during sgl post operation\n",
  4068. rc);
  4069. rc = -ENODEV;
  4070. goto out_free_vpd;
  4071. }
  4072. /* Register SCSI SGL pool to the device */
  4073. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4074. if (unlikely(rc)) {
  4075. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4076. "0383 Error %d during scsi sgl post "
  4077. "operation\n", rc);
  4078. /* Some Scsi buffers were moved to the abort scsi list */
  4079. /* A pci function reset will repost them */
  4080. rc = -ENODEV;
  4081. goto out_free_vpd;
  4082. }
  4083. /* Post the rpi header region to the device. */
  4084. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4085. if (unlikely(rc)) {
  4086. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4087. "0393 Error %d during rpi post operation\n",
  4088. rc);
  4089. rc = -ENODEV;
  4090. goto out_free_vpd;
  4091. }
  4092. /* Set up all the queues to the device */
  4093. rc = lpfc_sli4_queue_setup(phba);
  4094. if (unlikely(rc)) {
  4095. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4096. "0381 Error %d during queue setup.\n ", rc);
  4097. goto out_stop_timers;
  4098. }
  4099. /* Arm the CQs and then EQs on device */
  4100. lpfc_sli4_arm_cqeq_intr(phba);
  4101. /* Indicate device interrupt mode */
  4102. phba->sli4_hba.intr_enable = 1;
  4103. /* Allow asynchronous mailbox command to go through */
  4104. spin_lock_irq(&phba->hbalock);
  4105. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4106. spin_unlock_irq(&phba->hbalock);
  4107. /* Post receive buffers to the device */
  4108. lpfc_sli4_rb_setup(phba);
  4109. /* Reset HBA FCF states after HBA reset */
  4110. phba->fcf.fcf_flag = 0;
  4111. phba->fcf.current_rec.flag = 0;
  4112. /* Start the ELS watchdog timer */
  4113. mod_timer(&vport->els_tmofunc,
  4114. jiffies + HZ * (phba->fc_ratov * 2));
  4115. /* Start heart beat timer */
  4116. mod_timer(&phba->hb_tmofunc,
  4117. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4118. phba->hb_outstanding = 0;
  4119. phba->last_completion_time = jiffies;
  4120. /* Start error attention (ERATT) polling timer */
  4121. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4122. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4123. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4124. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4125. if (!rc) {
  4126. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4127. "2829 This device supports "
  4128. "Advanced Error Reporting (AER)\n");
  4129. spin_lock_irq(&phba->hbalock);
  4130. phba->hba_flag |= HBA_AER_ENABLED;
  4131. spin_unlock_irq(&phba->hbalock);
  4132. } else {
  4133. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4134. "2830 This device does not support "
  4135. "Advanced Error Reporting (AER)\n");
  4136. phba->cfg_aer_support = 0;
  4137. }
  4138. }
  4139. /*
  4140. * The port is ready, set the host's link state to LINK_DOWN
  4141. * in preparation for link interrupts.
  4142. */
  4143. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4144. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4145. lpfc_set_loopback_flag(phba);
  4146. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4147. spin_lock_irq(&phba->hbalock);
  4148. phba->link_state = LPFC_LINK_DOWN;
  4149. spin_unlock_irq(&phba->hbalock);
  4150. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4151. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4152. kfree(vpd);
  4153. return 0;
  4154. } else
  4155. rc = -EIO;
  4156. /* Unset all the queues set up in this routine when error out */
  4157. if (rc)
  4158. lpfc_sli4_queue_unset(phba);
  4159. out_stop_timers:
  4160. if (rc)
  4161. lpfc_stop_hba_timers(phba);
  4162. out_free_vpd:
  4163. kfree(vpd);
  4164. out_free_mbox:
  4165. mempool_free(mboxq, phba->mbox_mem_pool);
  4166. return rc;
  4167. }
  4168. /**
  4169. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4170. * @ptr: context object - pointer to hba structure.
  4171. *
  4172. * This is the callback function for mailbox timer. The mailbox
  4173. * timer is armed when a new mailbox command is issued and the timer
  4174. * is deleted when the mailbox complete. The function is called by
  4175. * the kernel timer code when a mailbox does not complete within
  4176. * expected time. This function wakes up the worker thread to
  4177. * process the mailbox timeout and returns. All the processing is
  4178. * done by the worker thread function lpfc_mbox_timeout_handler.
  4179. **/
  4180. void
  4181. lpfc_mbox_timeout(unsigned long ptr)
  4182. {
  4183. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4184. unsigned long iflag;
  4185. uint32_t tmo_posted;
  4186. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4187. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4188. if (!tmo_posted)
  4189. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4190. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4191. if (!tmo_posted)
  4192. lpfc_worker_wake_up(phba);
  4193. return;
  4194. }
  4195. /**
  4196. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4197. * @phba: Pointer to HBA context object.
  4198. *
  4199. * This function is called from worker thread when a mailbox command times out.
  4200. * The caller is not required to hold any locks. This function will reset the
  4201. * HBA and recover all the pending commands.
  4202. **/
  4203. void
  4204. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4205. {
  4206. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4207. MAILBOX_t *mb = &pmbox->u.mb;
  4208. struct lpfc_sli *psli = &phba->sli;
  4209. struct lpfc_sli_ring *pring;
  4210. /* Check the pmbox pointer first. There is a race condition
  4211. * between the mbox timeout handler getting executed in the
  4212. * worklist and the mailbox actually completing. When this
  4213. * race condition occurs, the mbox_active will be NULL.
  4214. */
  4215. spin_lock_irq(&phba->hbalock);
  4216. if (pmbox == NULL) {
  4217. lpfc_printf_log(phba, KERN_WARNING,
  4218. LOG_MBOX | LOG_SLI,
  4219. "0353 Active Mailbox cleared - mailbox timeout "
  4220. "exiting\n");
  4221. spin_unlock_irq(&phba->hbalock);
  4222. return;
  4223. }
  4224. /* Mbox cmd <mbxCommand> timeout */
  4225. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4226. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4227. mb->mbxCommand,
  4228. phba->pport->port_state,
  4229. phba->sli.sli_flag,
  4230. phba->sli.mbox_active);
  4231. spin_unlock_irq(&phba->hbalock);
  4232. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4233. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4234. * it to fail all oustanding SCSI IO.
  4235. */
  4236. spin_lock_irq(&phba->pport->work_port_lock);
  4237. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4238. spin_unlock_irq(&phba->pport->work_port_lock);
  4239. spin_lock_irq(&phba->hbalock);
  4240. phba->link_state = LPFC_LINK_UNKNOWN;
  4241. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4242. spin_unlock_irq(&phba->hbalock);
  4243. pring = &psli->ring[psli->fcp_ring];
  4244. lpfc_sli_abort_iocb_ring(phba, pring);
  4245. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4246. "0345 Resetting board due to mailbox timeout\n");
  4247. /* Reset the HBA device */
  4248. lpfc_reset_hba(phba);
  4249. }
  4250. /**
  4251. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4252. * @phba: Pointer to HBA context object.
  4253. * @pmbox: Pointer to mailbox object.
  4254. * @flag: Flag indicating how the mailbox need to be processed.
  4255. *
  4256. * This function is called by discovery code and HBA management code
  4257. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4258. * function gets the hbalock to protect the data structures.
  4259. * The mailbox command can be submitted in polling mode, in which case
  4260. * this function will wait in a polling loop for the completion of the
  4261. * mailbox.
  4262. * If the mailbox is submitted in no_wait mode (not polling) the
  4263. * function will submit the command and returns immediately without waiting
  4264. * for the mailbox completion. The no_wait is supported only when HBA
  4265. * is in SLI2/SLI3 mode - interrupts are enabled.
  4266. * The SLI interface allows only one mailbox pending at a time. If the
  4267. * mailbox is issued in polling mode and there is already a mailbox
  4268. * pending, then the function will return an error. If the mailbox is issued
  4269. * in NO_WAIT mode and there is a mailbox pending already, the function
  4270. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4271. * The sli layer owns the mailbox object until the completion of mailbox
  4272. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4273. * return codes the caller owns the mailbox command after the return of
  4274. * the function.
  4275. **/
  4276. static int
  4277. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4278. uint32_t flag)
  4279. {
  4280. MAILBOX_t *mb;
  4281. struct lpfc_sli *psli = &phba->sli;
  4282. uint32_t status, evtctr;
  4283. uint32_t ha_copy;
  4284. int i;
  4285. unsigned long timeout;
  4286. unsigned long drvr_flag = 0;
  4287. uint32_t word0, ldata;
  4288. void __iomem *to_slim;
  4289. int processing_queue = 0;
  4290. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4291. if (!pmbox) {
  4292. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4293. /* processing mbox queue from intr_handler */
  4294. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4295. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4296. return MBX_SUCCESS;
  4297. }
  4298. processing_queue = 1;
  4299. pmbox = lpfc_mbox_get(phba);
  4300. if (!pmbox) {
  4301. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4302. return MBX_SUCCESS;
  4303. }
  4304. }
  4305. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4306. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4307. if(!pmbox->vport) {
  4308. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4309. lpfc_printf_log(phba, KERN_ERR,
  4310. LOG_MBOX | LOG_VPORT,
  4311. "1806 Mbox x%x failed. No vport\n",
  4312. pmbox->u.mb.mbxCommand);
  4313. dump_stack();
  4314. goto out_not_finished;
  4315. }
  4316. }
  4317. /* If the PCI channel is in offline state, do not post mbox. */
  4318. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4319. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4320. goto out_not_finished;
  4321. }
  4322. /* If HBA has a deferred error attention, fail the iocb. */
  4323. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4324. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4325. goto out_not_finished;
  4326. }
  4327. psli = &phba->sli;
  4328. mb = &pmbox->u.mb;
  4329. status = MBX_SUCCESS;
  4330. if (phba->link_state == LPFC_HBA_ERROR) {
  4331. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4332. /* Mbox command <mbxCommand> cannot issue */
  4333. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4334. "(%d):0311 Mailbox command x%x cannot "
  4335. "issue Data: x%x x%x\n",
  4336. pmbox->vport ? pmbox->vport->vpi : 0,
  4337. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4338. goto out_not_finished;
  4339. }
  4340. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4341. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4342. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4343. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4344. "(%d):2528 Mailbox command x%x cannot "
  4345. "issue Data: x%x x%x\n",
  4346. pmbox->vport ? pmbox->vport->vpi : 0,
  4347. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4348. goto out_not_finished;
  4349. }
  4350. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4351. /* Polling for a mbox command when another one is already active
  4352. * is not allowed in SLI. Also, the driver must have established
  4353. * SLI2 mode to queue and process multiple mbox commands.
  4354. */
  4355. if (flag & MBX_POLL) {
  4356. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4357. /* Mbox command <mbxCommand> cannot issue */
  4358. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4359. "(%d):2529 Mailbox command x%x "
  4360. "cannot issue Data: x%x x%x\n",
  4361. pmbox->vport ? pmbox->vport->vpi : 0,
  4362. pmbox->u.mb.mbxCommand,
  4363. psli->sli_flag, flag);
  4364. goto out_not_finished;
  4365. }
  4366. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4367. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4368. /* Mbox command <mbxCommand> cannot issue */
  4369. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4370. "(%d):2530 Mailbox command x%x "
  4371. "cannot issue Data: x%x x%x\n",
  4372. pmbox->vport ? pmbox->vport->vpi : 0,
  4373. pmbox->u.mb.mbxCommand,
  4374. psli->sli_flag, flag);
  4375. goto out_not_finished;
  4376. }
  4377. /* Another mailbox command is still being processed, queue this
  4378. * command to be processed later.
  4379. */
  4380. lpfc_mbox_put(phba, pmbox);
  4381. /* Mbox cmd issue - BUSY */
  4382. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4383. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4384. "x%x x%x x%x x%x\n",
  4385. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4386. mb->mbxCommand, phba->pport->port_state,
  4387. psli->sli_flag, flag);
  4388. psli->slistat.mbox_busy++;
  4389. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4390. if (pmbox->vport) {
  4391. lpfc_debugfs_disc_trc(pmbox->vport,
  4392. LPFC_DISC_TRC_MBOX_VPORT,
  4393. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4394. (uint32_t)mb->mbxCommand,
  4395. mb->un.varWords[0], mb->un.varWords[1]);
  4396. }
  4397. else {
  4398. lpfc_debugfs_disc_trc(phba->pport,
  4399. LPFC_DISC_TRC_MBOX,
  4400. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4401. (uint32_t)mb->mbxCommand,
  4402. mb->un.varWords[0], mb->un.varWords[1]);
  4403. }
  4404. return MBX_BUSY;
  4405. }
  4406. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4407. /* If we are not polling, we MUST be in SLI2 mode */
  4408. if (flag != MBX_POLL) {
  4409. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4410. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4411. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4412. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4413. /* Mbox command <mbxCommand> cannot issue */
  4414. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4415. "(%d):2531 Mailbox command x%x "
  4416. "cannot issue Data: x%x x%x\n",
  4417. pmbox->vport ? pmbox->vport->vpi : 0,
  4418. pmbox->u.mb.mbxCommand,
  4419. psli->sli_flag, flag);
  4420. goto out_not_finished;
  4421. }
  4422. /* timeout active mbox command */
  4423. mod_timer(&psli->mbox_tmo, (jiffies +
  4424. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4425. }
  4426. /* Mailbox cmd <cmd> issue */
  4427. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4428. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4429. "x%x\n",
  4430. pmbox->vport ? pmbox->vport->vpi : 0,
  4431. mb->mbxCommand, phba->pport->port_state,
  4432. psli->sli_flag, flag);
  4433. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4434. if (pmbox->vport) {
  4435. lpfc_debugfs_disc_trc(pmbox->vport,
  4436. LPFC_DISC_TRC_MBOX_VPORT,
  4437. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4438. (uint32_t)mb->mbxCommand,
  4439. mb->un.varWords[0], mb->un.varWords[1]);
  4440. }
  4441. else {
  4442. lpfc_debugfs_disc_trc(phba->pport,
  4443. LPFC_DISC_TRC_MBOX,
  4444. "MBOX Send: cmd:x%x mb:x%x x%x",
  4445. (uint32_t)mb->mbxCommand,
  4446. mb->un.varWords[0], mb->un.varWords[1]);
  4447. }
  4448. }
  4449. psli->slistat.mbox_cmd++;
  4450. evtctr = psli->slistat.mbox_event;
  4451. /* next set own bit for the adapter and copy over command word */
  4452. mb->mbxOwner = OWN_CHIP;
  4453. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4454. /* Populate mbox extension offset word. */
  4455. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4456. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4457. = (uint8_t *)phba->mbox_ext
  4458. - (uint8_t *)phba->mbox;
  4459. }
  4460. /* Copy the mailbox extension data */
  4461. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4462. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4463. (uint8_t *)phba->mbox_ext,
  4464. pmbox->in_ext_byte_len);
  4465. }
  4466. /* Copy command data to host SLIM area */
  4467. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4468. } else {
  4469. /* Populate mbox extension offset word. */
  4470. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4471. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4472. = MAILBOX_HBA_EXT_OFFSET;
  4473. /* Copy the mailbox extension data */
  4474. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4475. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4476. MAILBOX_HBA_EXT_OFFSET,
  4477. pmbox->context2, pmbox->in_ext_byte_len);
  4478. }
  4479. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4480. /* copy command data into host mbox for cmpl */
  4481. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4482. }
  4483. /* First copy mbox command data to HBA SLIM, skip past first
  4484. word */
  4485. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4486. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4487. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4488. /* Next copy over first word, with mbxOwner set */
  4489. ldata = *((uint32_t *)mb);
  4490. to_slim = phba->MBslimaddr;
  4491. writel(ldata, to_slim);
  4492. readl(to_slim); /* flush */
  4493. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4494. /* switch over to host mailbox */
  4495. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4496. }
  4497. }
  4498. wmb();
  4499. switch (flag) {
  4500. case MBX_NOWAIT:
  4501. /* Set up reference to mailbox command */
  4502. psli->mbox_active = pmbox;
  4503. /* Interrupt board to do it */
  4504. writel(CA_MBATT, phba->CAregaddr);
  4505. readl(phba->CAregaddr); /* flush */
  4506. /* Don't wait for it to finish, just return */
  4507. break;
  4508. case MBX_POLL:
  4509. /* Set up null reference to mailbox command */
  4510. psli->mbox_active = NULL;
  4511. /* Interrupt board to do it */
  4512. writel(CA_MBATT, phba->CAregaddr);
  4513. readl(phba->CAregaddr); /* flush */
  4514. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4515. /* First read mbox status word */
  4516. word0 = *((uint32_t *)phba->mbox);
  4517. word0 = le32_to_cpu(word0);
  4518. } else {
  4519. /* First read mbox status word */
  4520. word0 = readl(phba->MBslimaddr);
  4521. }
  4522. /* Read the HBA Host Attention Register */
  4523. ha_copy = readl(phba->HAregaddr);
  4524. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4525. mb->mbxCommand) *
  4526. 1000) + jiffies;
  4527. i = 0;
  4528. /* Wait for command to complete */
  4529. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4530. (!(ha_copy & HA_MBATT) &&
  4531. (phba->link_state > LPFC_WARM_START))) {
  4532. if (time_after(jiffies, timeout)) {
  4533. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4534. spin_unlock_irqrestore(&phba->hbalock,
  4535. drvr_flag);
  4536. goto out_not_finished;
  4537. }
  4538. /* Check if we took a mbox interrupt while we were
  4539. polling */
  4540. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4541. && (evtctr != psli->slistat.mbox_event))
  4542. break;
  4543. if (i++ > 10) {
  4544. spin_unlock_irqrestore(&phba->hbalock,
  4545. drvr_flag);
  4546. msleep(1);
  4547. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4548. }
  4549. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4550. /* First copy command data */
  4551. word0 = *((uint32_t *)phba->mbox);
  4552. word0 = le32_to_cpu(word0);
  4553. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4554. MAILBOX_t *slimmb;
  4555. uint32_t slimword0;
  4556. /* Check real SLIM for any errors */
  4557. slimword0 = readl(phba->MBslimaddr);
  4558. slimmb = (MAILBOX_t *) & slimword0;
  4559. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4560. && slimmb->mbxStatus) {
  4561. psli->sli_flag &=
  4562. ~LPFC_SLI_ACTIVE;
  4563. word0 = slimword0;
  4564. }
  4565. }
  4566. } else {
  4567. /* First copy command data */
  4568. word0 = readl(phba->MBslimaddr);
  4569. }
  4570. /* Read the HBA Host Attention Register */
  4571. ha_copy = readl(phba->HAregaddr);
  4572. }
  4573. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4574. /* copy results back to user */
  4575. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4576. /* Copy the mailbox extension data */
  4577. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4578. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4579. pmbox->context2,
  4580. pmbox->out_ext_byte_len);
  4581. }
  4582. } else {
  4583. /* First copy command data */
  4584. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4585. MAILBOX_CMD_SIZE);
  4586. /* Copy the mailbox extension data */
  4587. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4588. lpfc_memcpy_from_slim(pmbox->context2,
  4589. phba->MBslimaddr +
  4590. MAILBOX_HBA_EXT_OFFSET,
  4591. pmbox->out_ext_byte_len);
  4592. }
  4593. }
  4594. writel(HA_MBATT, phba->HAregaddr);
  4595. readl(phba->HAregaddr); /* flush */
  4596. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4597. status = mb->mbxStatus;
  4598. }
  4599. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4600. return status;
  4601. out_not_finished:
  4602. if (processing_queue) {
  4603. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4604. lpfc_mbox_cmpl_put(phba, pmbox);
  4605. }
  4606. return MBX_NOT_FINISHED;
  4607. }
  4608. /**
  4609. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4610. * @phba: Pointer to HBA context object.
  4611. *
  4612. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4613. * the driver internal pending mailbox queue. It will then try to wait out the
  4614. * possible outstanding mailbox command before return.
  4615. *
  4616. * Returns:
  4617. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4618. * the outstanding mailbox command timed out.
  4619. **/
  4620. static int
  4621. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4622. {
  4623. struct lpfc_sli *psli = &phba->sli;
  4624. uint8_t actcmd = MBX_HEARTBEAT;
  4625. int rc = 0;
  4626. unsigned long timeout;
  4627. /* Mark the asynchronous mailbox command posting as blocked */
  4628. spin_lock_irq(&phba->hbalock);
  4629. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4630. if (phba->sli.mbox_active)
  4631. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4632. spin_unlock_irq(&phba->hbalock);
  4633. /* Determine how long we might wait for the active mailbox
  4634. * command to be gracefully completed by firmware.
  4635. */
  4636. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4637. jiffies;
  4638. /* Wait for the outstnading mailbox command to complete */
  4639. while (phba->sli.mbox_active) {
  4640. /* Check active mailbox complete status every 2ms */
  4641. msleep(2);
  4642. if (time_after(jiffies, timeout)) {
  4643. /* Timeout, marked the outstanding cmd not complete */
  4644. rc = 1;
  4645. break;
  4646. }
  4647. }
  4648. /* Can not cleanly block async mailbox command, fails it */
  4649. if (rc) {
  4650. spin_lock_irq(&phba->hbalock);
  4651. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4652. spin_unlock_irq(&phba->hbalock);
  4653. }
  4654. return rc;
  4655. }
  4656. /**
  4657. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4658. * @phba: Pointer to HBA context object.
  4659. *
  4660. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4661. * commands from the driver internal pending mailbox queue. It makes sure
  4662. * that there is no outstanding mailbox command before resuming posting
  4663. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4664. * mailbox command, it will try to wait it out before resuming asynchronous
  4665. * mailbox command posting.
  4666. **/
  4667. static void
  4668. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4669. {
  4670. struct lpfc_sli *psli = &phba->sli;
  4671. spin_lock_irq(&phba->hbalock);
  4672. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4673. /* Asynchronous mailbox posting is not blocked, do nothing */
  4674. spin_unlock_irq(&phba->hbalock);
  4675. return;
  4676. }
  4677. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4678. * successful or timeout, after timing-out the outstanding mailbox
  4679. * command shall always be removed, so just unblock posting async
  4680. * mailbox command and resume
  4681. */
  4682. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4683. spin_unlock_irq(&phba->hbalock);
  4684. /* wake up worker thread to post asynchronlous mailbox command */
  4685. lpfc_worker_wake_up(phba);
  4686. }
  4687. /**
  4688. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4689. * @phba: Pointer to HBA context object.
  4690. * @mboxq: Pointer to mailbox object.
  4691. *
  4692. * The function posts a mailbox to the port. The mailbox is expected
  4693. * to be comletely filled in and ready for the port to operate on it.
  4694. * This routine executes a synchronous completion operation on the
  4695. * mailbox by polling for its completion.
  4696. *
  4697. * The caller must not be holding any locks when calling this routine.
  4698. *
  4699. * Returns:
  4700. * MBX_SUCCESS - mailbox posted successfully
  4701. * Any of the MBX error values.
  4702. **/
  4703. static int
  4704. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4705. {
  4706. int rc = MBX_SUCCESS;
  4707. unsigned long iflag;
  4708. uint32_t db_ready;
  4709. uint32_t mcqe_status;
  4710. uint32_t mbx_cmnd;
  4711. unsigned long timeout;
  4712. struct lpfc_sli *psli = &phba->sli;
  4713. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4714. struct lpfc_bmbx_create *mbox_rgn;
  4715. struct dma_address *dma_address;
  4716. struct lpfc_register bmbx_reg;
  4717. /*
  4718. * Only one mailbox can be active to the bootstrap mailbox region
  4719. * at a time and there is no queueing provided.
  4720. */
  4721. spin_lock_irqsave(&phba->hbalock, iflag);
  4722. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4723. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4724. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4725. "(%d):2532 Mailbox command x%x (x%x) "
  4726. "cannot issue Data: x%x x%x\n",
  4727. mboxq->vport ? mboxq->vport->vpi : 0,
  4728. mboxq->u.mb.mbxCommand,
  4729. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4730. psli->sli_flag, MBX_POLL);
  4731. return MBXERR_ERROR;
  4732. }
  4733. /* The server grabs the token and owns it until release */
  4734. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4735. phba->sli.mbox_active = mboxq;
  4736. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4737. /*
  4738. * Initialize the bootstrap memory region to avoid stale data areas
  4739. * in the mailbox post. Then copy the caller's mailbox contents to
  4740. * the bmbx mailbox region.
  4741. */
  4742. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4743. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4744. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4745. sizeof(struct lpfc_mqe));
  4746. /* Post the high mailbox dma address to the port and wait for ready. */
  4747. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4748. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4749. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4750. * 1000) + jiffies;
  4751. do {
  4752. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4753. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4754. if (!db_ready)
  4755. msleep(2);
  4756. if (time_after(jiffies, timeout)) {
  4757. rc = MBXERR_ERROR;
  4758. goto exit;
  4759. }
  4760. } while (!db_ready);
  4761. /* Post the low mailbox dma address to the port. */
  4762. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4763. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4764. * 1000) + jiffies;
  4765. do {
  4766. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4767. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4768. if (!db_ready)
  4769. msleep(2);
  4770. if (time_after(jiffies, timeout)) {
  4771. rc = MBXERR_ERROR;
  4772. goto exit;
  4773. }
  4774. } while (!db_ready);
  4775. /*
  4776. * Read the CQ to ensure the mailbox has completed.
  4777. * If so, update the mailbox status so that the upper layers
  4778. * can complete the request normally.
  4779. */
  4780. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4781. sizeof(struct lpfc_mqe));
  4782. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4783. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4784. sizeof(struct lpfc_mcqe));
  4785. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4786. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4787. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4788. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4789. rc = MBXERR_ERROR;
  4790. }
  4791. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4792. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4793. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4794. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4795. mboxq->vport ? mboxq->vport->vpi : 0,
  4796. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4797. bf_get(lpfc_mqe_status, mb),
  4798. mb->un.mb_words[0], mb->un.mb_words[1],
  4799. mb->un.mb_words[2], mb->un.mb_words[3],
  4800. mb->un.mb_words[4], mb->un.mb_words[5],
  4801. mb->un.mb_words[6], mb->un.mb_words[7],
  4802. mb->un.mb_words[8], mb->un.mb_words[9],
  4803. mb->un.mb_words[10], mb->un.mb_words[11],
  4804. mb->un.mb_words[12], mboxq->mcqe.word0,
  4805. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4806. mboxq->mcqe.trailer);
  4807. exit:
  4808. /* We are holding the token, no needed for lock when release */
  4809. spin_lock_irqsave(&phba->hbalock, iflag);
  4810. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4811. phba->sli.mbox_active = NULL;
  4812. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4813. return rc;
  4814. }
  4815. /**
  4816. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4817. * @phba: Pointer to HBA context object.
  4818. * @pmbox: Pointer to mailbox object.
  4819. * @flag: Flag indicating how the mailbox need to be processed.
  4820. *
  4821. * This function is called by discovery code and HBA management code to submit
  4822. * a mailbox command to firmware with SLI-4 interface spec.
  4823. *
  4824. * Return codes the caller owns the mailbox command after the return of the
  4825. * function.
  4826. **/
  4827. static int
  4828. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4829. uint32_t flag)
  4830. {
  4831. struct lpfc_sli *psli = &phba->sli;
  4832. unsigned long iflags;
  4833. int rc;
  4834. rc = lpfc_mbox_dev_check(phba);
  4835. if (unlikely(rc)) {
  4836. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4837. "(%d):2544 Mailbox command x%x (x%x) "
  4838. "cannot issue Data: x%x x%x\n",
  4839. mboxq->vport ? mboxq->vport->vpi : 0,
  4840. mboxq->u.mb.mbxCommand,
  4841. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4842. psli->sli_flag, flag);
  4843. goto out_not_finished;
  4844. }
  4845. /* Detect polling mode and jump to a handler */
  4846. if (!phba->sli4_hba.intr_enable) {
  4847. if (flag == MBX_POLL)
  4848. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4849. else
  4850. rc = -EIO;
  4851. if (rc != MBX_SUCCESS)
  4852. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4853. "(%d):2541 Mailbox command x%x "
  4854. "(x%x) cannot issue Data: x%x x%x\n",
  4855. mboxq->vport ? mboxq->vport->vpi : 0,
  4856. mboxq->u.mb.mbxCommand,
  4857. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4858. psli->sli_flag, flag);
  4859. return rc;
  4860. } else if (flag == MBX_POLL) {
  4861. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4862. "(%d):2542 Try to issue mailbox command "
  4863. "x%x (x%x) synchronously ahead of async"
  4864. "mailbox command queue: x%x x%x\n",
  4865. mboxq->vport ? mboxq->vport->vpi : 0,
  4866. mboxq->u.mb.mbxCommand,
  4867. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4868. psli->sli_flag, flag);
  4869. /* Try to block the asynchronous mailbox posting */
  4870. rc = lpfc_sli4_async_mbox_block(phba);
  4871. if (!rc) {
  4872. /* Successfully blocked, now issue sync mbox cmd */
  4873. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4874. if (rc != MBX_SUCCESS)
  4875. lpfc_printf_log(phba, KERN_ERR,
  4876. LOG_MBOX | LOG_SLI,
  4877. "(%d):2597 Mailbox command "
  4878. "x%x (x%x) cannot issue "
  4879. "Data: x%x x%x\n",
  4880. mboxq->vport ?
  4881. mboxq->vport->vpi : 0,
  4882. mboxq->u.mb.mbxCommand,
  4883. lpfc_sli4_mbox_opcode_get(phba,
  4884. mboxq),
  4885. psli->sli_flag, flag);
  4886. /* Unblock the async mailbox posting afterward */
  4887. lpfc_sli4_async_mbox_unblock(phba);
  4888. }
  4889. return rc;
  4890. }
  4891. /* Now, interrupt mode asynchrous mailbox command */
  4892. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4893. if (rc) {
  4894. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4895. "(%d):2543 Mailbox command x%x (x%x) "
  4896. "cannot issue Data: x%x x%x\n",
  4897. mboxq->vport ? mboxq->vport->vpi : 0,
  4898. mboxq->u.mb.mbxCommand,
  4899. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4900. psli->sli_flag, flag);
  4901. goto out_not_finished;
  4902. }
  4903. /* Put the mailbox command to the driver internal FIFO */
  4904. psli->slistat.mbox_busy++;
  4905. spin_lock_irqsave(&phba->hbalock, iflags);
  4906. lpfc_mbox_put(phba, mboxq);
  4907. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4908. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4909. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4910. "x%x (x%x) x%x x%x x%x\n",
  4911. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4912. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4913. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4914. phba->pport->port_state,
  4915. psli->sli_flag, MBX_NOWAIT);
  4916. /* Wake up worker thread to transport mailbox command from head */
  4917. lpfc_worker_wake_up(phba);
  4918. return MBX_BUSY;
  4919. out_not_finished:
  4920. return MBX_NOT_FINISHED;
  4921. }
  4922. /**
  4923. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4924. * @phba: Pointer to HBA context object.
  4925. *
  4926. * This function is called by worker thread to send a mailbox command to
  4927. * SLI4 HBA firmware.
  4928. *
  4929. **/
  4930. int
  4931. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4932. {
  4933. struct lpfc_sli *psli = &phba->sli;
  4934. LPFC_MBOXQ_t *mboxq;
  4935. int rc = MBX_SUCCESS;
  4936. unsigned long iflags;
  4937. struct lpfc_mqe *mqe;
  4938. uint32_t mbx_cmnd;
  4939. /* Check interrupt mode before post async mailbox command */
  4940. if (unlikely(!phba->sli4_hba.intr_enable))
  4941. return MBX_NOT_FINISHED;
  4942. /* Check for mailbox command service token */
  4943. spin_lock_irqsave(&phba->hbalock, iflags);
  4944. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4945. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4946. return MBX_NOT_FINISHED;
  4947. }
  4948. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4949. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4950. return MBX_NOT_FINISHED;
  4951. }
  4952. if (unlikely(phba->sli.mbox_active)) {
  4953. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4954. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4955. "0384 There is pending active mailbox cmd\n");
  4956. return MBX_NOT_FINISHED;
  4957. }
  4958. /* Take the mailbox command service token */
  4959. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4960. /* Get the next mailbox command from head of queue */
  4961. mboxq = lpfc_mbox_get(phba);
  4962. /* If no more mailbox command waiting for post, we're done */
  4963. if (!mboxq) {
  4964. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4965. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4966. return MBX_SUCCESS;
  4967. }
  4968. phba->sli.mbox_active = mboxq;
  4969. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4970. /* Check device readiness for posting mailbox command */
  4971. rc = lpfc_mbox_dev_check(phba);
  4972. if (unlikely(rc))
  4973. /* Driver clean routine will clean up pending mailbox */
  4974. goto out_not_finished;
  4975. /* Prepare the mbox command to be posted */
  4976. mqe = &mboxq->u.mqe;
  4977. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4978. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4979. mod_timer(&psli->mbox_tmo, (jiffies +
  4980. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4981. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4982. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4983. "x%x x%x\n",
  4984. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4985. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4986. phba->pport->port_state, psli->sli_flag);
  4987. if (mbx_cmnd != MBX_HEARTBEAT) {
  4988. if (mboxq->vport) {
  4989. lpfc_debugfs_disc_trc(mboxq->vport,
  4990. LPFC_DISC_TRC_MBOX_VPORT,
  4991. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4992. mbx_cmnd, mqe->un.mb_words[0],
  4993. mqe->un.mb_words[1]);
  4994. } else {
  4995. lpfc_debugfs_disc_trc(phba->pport,
  4996. LPFC_DISC_TRC_MBOX,
  4997. "MBOX Send: cmd:x%x mb:x%x x%x",
  4998. mbx_cmnd, mqe->un.mb_words[0],
  4999. mqe->un.mb_words[1]);
  5000. }
  5001. }
  5002. psli->slistat.mbox_cmd++;
  5003. /* Post the mailbox command to the port */
  5004. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5005. if (rc != MBX_SUCCESS) {
  5006. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5007. "(%d):2533 Mailbox command x%x (x%x) "
  5008. "cannot issue Data: x%x x%x\n",
  5009. mboxq->vport ? mboxq->vport->vpi : 0,
  5010. mboxq->u.mb.mbxCommand,
  5011. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5012. psli->sli_flag, MBX_NOWAIT);
  5013. goto out_not_finished;
  5014. }
  5015. return rc;
  5016. out_not_finished:
  5017. spin_lock_irqsave(&phba->hbalock, iflags);
  5018. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5019. __lpfc_mbox_cmpl_put(phba, mboxq);
  5020. /* Release the token */
  5021. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5022. phba->sli.mbox_active = NULL;
  5023. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5024. return MBX_NOT_FINISHED;
  5025. }
  5026. /**
  5027. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5028. * @phba: Pointer to HBA context object.
  5029. * @pmbox: Pointer to mailbox object.
  5030. * @flag: Flag indicating how the mailbox need to be processed.
  5031. *
  5032. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5033. * the API jump table function pointer from the lpfc_hba struct.
  5034. *
  5035. * Return codes the caller owns the mailbox command after the return of the
  5036. * function.
  5037. **/
  5038. int
  5039. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5040. {
  5041. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5042. }
  5043. /**
  5044. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5045. * @phba: The hba struct for which this call is being executed.
  5046. * @dev_grp: The HBA PCI-Device group number.
  5047. *
  5048. * This routine sets up the mbox interface API function jump table in @phba
  5049. * struct.
  5050. * Returns: 0 - success, -ENODEV - failure.
  5051. **/
  5052. int
  5053. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5054. {
  5055. switch (dev_grp) {
  5056. case LPFC_PCI_DEV_LP:
  5057. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5058. phba->lpfc_sli_handle_slow_ring_event =
  5059. lpfc_sli_handle_slow_ring_event_s3;
  5060. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5061. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5062. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5063. break;
  5064. case LPFC_PCI_DEV_OC:
  5065. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5066. phba->lpfc_sli_handle_slow_ring_event =
  5067. lpfc_sli_handle_slow_ring_event_s4;
  5068. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5069. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5070. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5071. break;
  5072. default:
  5073. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5074. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5075. dev_grp);
  5076. return -ENODEV;
  5077. break;
  5078. }
  5079. return 0;
  5080. }
  5081. /**
  5082. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5083. * @phba: Pointer to HBA context object.
  5084. * @pring: Pointer to driver SLI ring object.
  5085. * @piocb: Pointer to address of newly added command iocb.
  5086. *
  5087. * This function is called with hbalock held to add a command
  5088. * iocb to the txq when SLI layer cannot submit the command iocb
  5089. * to the ring.
  5090. **/
  5091. void
  5092. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5093. struct lpfc_iocbq *piocb)
  5094. {
  5095. /* Insert the caller's iocb in the txq tail for later processing. */
  5096. list_add_tail(&piocb->list, &pring->txq);
  5097. pring->txq_cnt++;
  5098. }
  5099. /**
  5100. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5101. * @phba: Pointer to HBA context object.
  5102. * @pring: Pointer to driver SLI ring object.
  5103. * @piocb: Pointer to address of newly added command iocb.
  5104. *
  5105. * This function is called with hbalock held before a new
  5106. * iocb is submitted to the firmware. This function checks
  5107. * txq to flush the iocbs in txq to Firmware before
  5108. * submitting new iocbs to the Firmware.
  5109. * If there are iocbs in the txq which need to be submitted
  5110. * to firmware, lpfc_sli_next_iocb returns the first element
  5111. * of the txq after dequeuing it from txq.
  5112. * If there is no iocb in the txq then the function will return
  5113. * *piocb and *piocb is set to NULL. Caller needs to check
  5114. * *piocb to find if there are more commands in the txq.
  5115. **/
  5116. static struct lpfc_iocbq *
  5117. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5118. struct lpfc_iocbq **piocb)
  5119. {
  5120. struct lpfc_iocbq * nextiocb;
  5121. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5122. if (!nextiocb) {
  5123. nextiocb = *piocb;
  5124. *piocb = NULL;
  5125. }
  5126. return nextiocb;
  5127. }
  5128. /**
  5129. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5130. * @phba: Pointer to HBA context object.
  5131. * @ring_number: SLI ring number to issue iocb on.
  5132. * @piocb: Pointer to command iocb.
  5133. * @flag: Flag indicating if this command can be put into txq.
  5134. *
  5135. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5136. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5137. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5138. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5139. * this function allows only iocbs for posting buffers. This function finds
  5140. * next available slot in the command ring and posts the command to the
  5141. * available slot and writes the port attention register to request HBA start
  5142. * processing new iocb. If there is no slot available in the ring and
  5143. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5144. * the function returns IOCB_BUSY.
  5145. *
  5146. * This function is called with hbalock held. The function will return success
  5147. * after it successfully submit the iocb to firmware or after adding to the
  5148. * txq.
  5149. **/
  5150. static int
  5151. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5152. struct lpfc_iocbq *piocb, uint32_t flag)
  5153. {
  5154. struct lpfc_iocbq *nextiocb;
  5155. IOCB_t *iocb;
  5156. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5157. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5158. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5159. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5160. lpfc_printf_log(phba, KERN_ERR,
  5161. LOG_SLI | LOG_VPORT,
  5162. "1807 IOCB x%x failed. No vport\n",
  5163. piocb->iocb.ulpCommand);
  5164. dump_stack();
  5165. return IOCB_ERROR;
  5166. }
  5167. /* If the PCI channel is in offline state, do not post iocbs. */
  5168. if (unlikely(pci_channel_offline(phba->pcidev)))
  5169. return IOCB_ERROR;
  5170. /* If HBA has a deferred error attention, fail the iocb. */
  5171. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5172. return IOCB_ERROR;
  5173. /*
  5174. * We should never get an IOCB if we are in a < LINK_DOWN state
  5175. */
  5176. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5177. return IOCB_ERROR;
  5178. /*
  5179. * Check to see if we are blocking IOCB processing because of a
  5180. * outstanding event.
  5181. */
  5182. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5183. goto iocb_busy;
  5184. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5185. /*
  5186. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5187. * can be issued if the link is not up.
  5188. */
  5189. switch (piocb->iocb.ulpCommand) {
  5190. case CMD_GEN_REQUEST64_CR:
  5191. case CMD_GEN_REQUEST64_CX:
  5192. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5193. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5194. FC_RCTL_DD_UNSOL_CMD) ||
  5195. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5196. MENLO_TRANSPORT_TYPE))
  5197. goto iocb_busy;
  5198. break;
  5199. case CMD_QUE_RING_BUF_CN:
  5200. case CMD_QUE_RING_BUF64_CN:
  5201. /*
  5202. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5203. * completion, iocb_cmpl MUST be 0.
  5204. */
  5205. if (piocb->iocb_cmpl)
  5206. piocb->iocb_cmpl = NULL;
  5207. /*FALLTHROUGH*/
  5208. case CMD_CREATE_XRI_CR:
  5209. case CMD_CLOSE_XRI_CN:
  5210. case CMD_CLOSE_XRI_CX:
  5211. break;
  5212. default:
  5213. goto iocb_busy;
  5214. }
  5215. /*
  5216. * For FCP commands, we must be in a state where we can process link
  5217. * attention events.
  5218. */
  5219. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5220. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5221. goto iocb_busy;
  5222. }
  5223. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5224. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5225. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5226. if (iocb)
  5227. lpfc_sli_update_ring(phba, pring);
  5228. else
  5229. lpfc_sli_update_full_ring(phba, pring);
  5230. if (!piocb)
  5231. return IOCB_SUCCESS;
  5232. goto out_busy;
  5233. iocb_busy:
  5234. pring->stats.iocb_cmd_delay++;
  5235. out_busy:
  5236. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5237. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5238. return IOCB_SUCCESS;
  5239. }
  5240. return IOCB_BUSY;
  5241. }
  5242. /**
  5243. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5244. * @phba: Pointer to HBA context object.
  5245. * @piocb: Pointer to command iocb.
  5246. * @sglq: Pointer to the scatter gather queue object.
  5247. *
  5248. * This routine converts the bpl or bde that is in the IOCB
  5249. * to a sgl list for the sli4 hardware. The physical address
  5250. * of the bpl/bde is converted back to a virtual address.
  5251. * If the IOCB contains a BPL then the list of BDE's is
  5252. * converted to sli4_sge's. If the IOCB contains a single
  5253. * BDE then it is converted to a single sli_sge.
  5254. * The IOCB is still in cpu endianess so the contents of
  5255. * the bpl can be used without byte swapping.
  5256. *
  5257. * Returns valid XRI = Success, NO_XRI = Failure.
  5258. **/
  5259. static uint16_t
  5260. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5261. struct lpfc_sglq *sglq)
  5262. {
  5263. uint16_t xritag = NO_XRI;
  5264. struct ulp_bde64 *bpl = NULL;
  5265. struct ulp_bde64 bde;
  5266. struct sli4_sge *sgl = NULL;
  5267. IOCB_t *icmd;
  5268. int numBdes = 0;
  5269. int i = 0;
  5270. if (!piocbq || !sglq)
  5271. return xritag;
  5272. sgl = (struct sli4_sge *)sglq->sgl;
  5273. icmd = &piocbq->iocb;
  5274. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5275. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5276. sizeof(struct ulp_bde64);
  5277. /* The addrHigh and addrLow fields within the IOCB
  5278. * have not been byteswapped yet so there is no
  5279. * need to swap them back.
  5280. */
  5281. bpl = (struct ulp_bde64 *)
  5282. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5283. if (!bpl)
  5284. return xritag;
  5285. for (i = 0; i < numBdes; i++) {
  5286. /* Should already be byte swapped. */
  5287. sgl->addr_hi = bpl->addrHigh;
  5288. sgl->addr_lo = bpl->addrLow;
  5289. if ((i+1) == numBdes)
  5290. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5291. else
  5292. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5293. sgl->word2 = cpu_to_le32(sgl->word2);
  5294. /* swap the size field back to the cpu so we
  5295. * can assign it to the sgl.
  5296. */
  5297. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5298. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5299. bpl++;
  5300. sgl++;
  5301. }
  5302. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5303. /* The addrHigh and addrLow fields of the BDE have not
  5304. * been byteswapped yet so they need to be swapped
  5305. * before putting them in the sgl.
  5306. */
  5307. sgl->addr_hi =
  5308. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5309. sgl->addr_lo =
  5310. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5311. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5312. sgl->word2 = cpu_to_le32(sgl->word2);
  5313. sgl->sge_len =
  5314. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5315. }
  5316. return sglq->sli4_xritag;
  5317. }
  5318. /**
  5319. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5320. * @phba: Pointer to HBA context object.
  5321. *
  5322. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5323. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5324. * held.
  5325. *
  5326. * Return: index into SLI4 fast-path FCP queue index.
  5327. **/
  5328. static uint32_t
  5329. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5330. {
  5331. ++phba->fcp_qidx;
  5332. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5333. phba->fcp_qidx = 0;
  5334. return phba->fcp_qidx;
  5335. }
  5336. /**
  5337. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5338. * @phba: Pointer to HBA context object.
  5339. * @piocb: Pointer to command iocb.
  5340. * @wqe: Pointer to the work queue entry.
  5341. *
  5342. * This routine converts the iocb command to its Work Queue Entry
  5343. * equivalent. The wqe pointer should not have any fields set when
  5344. * this routine is called because it will memcpy over them.
  5345. * This routine does not set the CQ_ID or the WQEC bits in the
  5346. * wqe.
  5347. *
  5348. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5349. **/
  5350. static int
  5351. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5352. union lpfc_wqe *wqe)
  5353. {
  5354. uint32_t xmit_len = 0, total_len = 0;
  5355. uint8_t ct = 0;
  5356. uint32_t fip;
  5357. uint32_t abort_tag;
  5358. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5359. uint8_t cmnd;
  5360. uint16_t xritag;
  5361. struct ulp_bde64 *bpl = NULL;
  5362. uint32_t els_id = ELS_ID_DEFAULT;
  5363. int numBdes, i;
  5364. struct ulp_bde64 bde;
  5365. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5366. /* The fcp commands will set command type */
  5367. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5368. command_type = FCP_COMMAND;
  5369. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5370. command_type = ELS_COMMAND_FIP;
  5371. else
  5372. command_type = ELS_COMMAND_NON_FIP;
  5373. /* Some of the fields are in the right position already */
  5374. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5375. abort_tag = (uint32_t) iocbq->iotag;
  5376. xritag = iocbq->sli4_xritag;
  5377. wqe->words[7] = 0; /* The ct field has moved so reset */
  5378. /* words0-2 bpl convert bde */
  5379. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5380. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5381. sizeof(struct ulp_bde64);
  5382. bpl = (struct ulp_bde64 *)
  5383. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5384. if (!bpl)
  5385. return IOCB_ERROR;
  5386. /* Should already be byte swapped. */
  5387. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5388. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5389. /* swap the size field back to the cpu so we
  5390. * can assign it to the sgl.
  5391. */
  5392. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5393. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5394. total_len = 0;
  5395. for (i = 0; i < numBdes; i++) {
  5396. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5397. total_len += bde.tus.f.bdeSize;
  5398. }
  5399. } else
  5400. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5401. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5402. cmnd = iocbq->iocb.ulpCommand;
  5403. switch (iocbq->iocb.ulpCommand) {
  5404. case CMD_ELS_REQUEST64_CR:
  5405. if (!iocbq->iocb.ulpLe) {
  5406. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5407. "2007 Only Limited Edition cmd Format"
  5408. " supported 0x%x\n",
  5409. iocbq->iocb.ulpCommand);
  5410. return IOCB_ERROR;
  5411. }
  5412. wqe->els_req.payload_len = xmit_len;
  5413. /* Els_reguest64 has a TMO */
  5414. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5415. iocbq->iocb.ulpTimeout);
  5416. /* Need a VF for word 4 set the vf bit*/
  5417. bf_set(els_req64_vf, &wqe->els_req, 0);
  5418. /* And a VFID for word 12 */
  5419. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5420. /*
  5421. * Set ct field to 3, indicates that the context_tag field
  5422. * contains the FCFI and remote N_Port_ID is
  5423. * in word 5.
  5424. */
  5425. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5426. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5427. iocbq->iocb.ulpContext);
  5428. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5429. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5430. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5431. if (command_type == ELS_COMMAND_FIP) {
  5432. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5433. >> LPFC_FIP_ELS_ID_SHIFT);
  5434. }
  5435. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5436. break;
  5437. case CMD_XMIT_SEQUENCE64_CX:
  5438. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5439. iocbq->iocb.un.ulpWord[3]);
  5440. wqe->generic.word3 = 0;
  5441. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5442. /* The entire sequence is transmitted for this IOCB */
  5443. xmit_len = total_len;
  5444. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5445. case CMD_XMIT_SEQUENCE64_CR:
  5446. /* word3 iocb=io_tag32 wqe=payload_offset */
  5447. /* payload offset used for multilpe outstanding
  5448. * sequences on the same exchange
  5449. */
  5450. wqe->words[3] = 0;
  5451. /* word4 relative_offset memcpy */
  5452. /* word5 r_ctl/df_ctl memcpy */
  5453. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5454. wqe->xmit_sequence.xmit_len = xmit_len;
  5455. command_type = OTHER_COMMAND;
  5456. break;
  5457. case CMD_XMIT_BCAST64_CN:
  5458. /* word3 iocb=iotag32 wqe=payload_len */
  5459. wqe->words[3] = 0; /* no definition for this in wqe */
  5460. /* word4 iocb=rsvd wqe=rsvd */
  5461. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5462. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5463. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5464. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5465. break;
  5466. case CMD_FCP_IWRITE64_CR:
  5467. command_type = FCP_COMMAND_DATA_OUT;
  5468. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5469. * confusing.
  5470. * word3 is payload_len: byte offset to the sgl entry for the
  5471. * fcp_command.
  5472. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5473. * word5 is initial xfer len 0 = wait for xfer-ready
  5474. */
  5475. /* Always wait for xfer-ready before sending data */
  5476. wqe->fcp_iwrite.initial_xfer_len = 0;
  5477. /* word 4 (xfer length) should have been set on the memcpy */
  5478. /* allow write to fall through to read */
  5479. case CMD_FCP_IREAD64_CR:
  5480. /* FCP_CMD is always the 1st sgl entry */
  5481. wqe->fcp_iread.payload_len =
  5482. xmit_len + sizeof(struct fcp_rsp);
  5483. /* word 4 (xfer length) should have been set on the memcpy */
  5484. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5485. iocbq->iocb.ulpFCP2Rcvy);
  5486. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5487. /* The XC bit and the XS bit are similar. The driver never
  5488. * tracked whether or not the exchange was previouslly open.
  5489. * XC = Exchange create, 0 is create. 1 is already open.
  5490. * XS = link cmd: 1 do not close the exchange after command.
  5491. * XS = 0 close exchange when command completes.
  5492. * The only time we would not set the XC bit is when the XS bit
  5493. * is set and we are sending our 2nd or greater command on
  5494. * this exchange.
  5495. */
  5496. /* Always open the exchange */
  5497. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5498. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5499. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5500. break;
  5501. case CMD_FCP_ICMND64_CR:
  5502. /* Always open the exchange */
  5503. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5504. wqe->words[4] = 0;
  5505. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5506. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5507. break;
  5508. case CMD_GEN_REQUEST64_CR:
  5509. /* word3 command length is described as byte offset to the
  5510. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5511. * sgl[0] = cmnd
  5512. * sgl[1] = rsp.
  5513. *
  5514. */
  5515. wqe->gen_req.command_len = xmit_len;
  5516. /* Word4 parameter copied in the memcpy */
  5517. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5518. /* word6 context tag copied in memcpy */
  5519. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5520. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5521. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5522. "2015 Invalid CT %x command 0x%x\n",
  5523. ct, iocbq->iocb.ulpCommand);
  5524. return IOCB_ERROR;
  5525. }
  5526. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5527. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5528. iocbq->iocb.ulpTimeout);
  5529. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5530. command_type = OTHER_COMMAND;
  5531. break;
  5532. case CMD_XMIT_ELS_RSP64_CX:
  5533. /* words0-2 BDE memcpy */
  5534. /* word3 iocb=iotag32 wqe=rsvd */
  5535. wqe->words[3] = 0;
  5536. /* word4 iocb=did wge=rsvd. */
  5537. wqe->words[4] = 0;
  5538. /* word5 iocb=rsvd wge=did */
  5539. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5540. iocbq->iocb.un.elsreq64.remoteID);
  5541. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5542. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5543. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5544. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5545. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5546. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5547. iocbq->vport->vpi + phba->vpi_base);
  5548. command_type = OTHER_COMMAND;
  5549. break;
  5550. case CMD_CLOSE_XRI_CN:
  5551. case CMD_ABORT_XRI_CN:
  5552. case CMD_ABORT_XRI_CX:
  5553. /* words 0-2 memcpy should be 0 rserved */
  5554. /* port will send abts */
  5555. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5556. /*
  5557. * The link is down so the fw does not need to send abts
  5558. * on the wire.
  5559. */
  5560. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5561. else
  5562. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5563. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5564. wqe->words[5] = 0;
  5565. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5566. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5567. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5568. /*
  5569. * The abort handler will send us CMD_ABORT_XRI_CN or
  5570. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5571. */
  5572. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5573. cmnd = CMD_ABORT_XRI_CX;
  5574. command_type = OTHER_COMMAND;
  5575. xritag = 0;
  5576. break;
  5577. case CMD_XMIT_BLS_RSP64_CX:
  5578. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5579. * we re-construct this WQE here based on information in
  5580. * iocbq from scratch.
  5581. */
  5582. memset(wqe, 0, sizeof(union lpfc_wqe));
  5583. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5584. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5585. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5586. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5587. LPFC_ABTS_UNSOL_INT) {
  5588. /* ABTS sent by initiator to CT exchange, the
  5589. * RX_ID field will be filled with the newly
  5590. * allocated responder XRI.
  5591. */
  5592. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5593. iocbq->sli4_xritag);
  5594. } else {
  5595. /* ABTS sent by responder to CT exchange, the
  5596. * RX_ID field will be filled with the responder
  5597. * RX_ID from ABTS.
  5598. */
  5599. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5600. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5601. }
  5602. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5603. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5604. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5605. iocbq->iocb.ulpContext);
  5606. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5607. command_type = OTHER_COMMAND;
  5608. break;
  5609. case CMD_XRI_ABORTED_CX:
  5610. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5611. /* words0-2 are all 0's no bde */
  5612. /* word3 and word4 are rsvrd */
  5613. wqe->words[3] = 0;
  5614. wqe->words[4] = 0;
  5615. /* word5 iocb=rsvd wge=did */
  5616. /* There is no remote port id in the IOCB? */
  5617. /* Let this fall through and fail */
  5618. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5619. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5620. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5621. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5622. default:
  5623. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5624. "2014 Invalid command 0x%x\n",
  5625. iocbq->iocb.ulpCommand);
  5626. return IOCB_ERROR;
  5627. break;
  5628. }
  5629. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5630. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5631. wqe->generic.abort_tag = abort_tag;
  5632. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5633. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5634. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5635. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5636. return 0;
  5637. }
  5638. /**
  5639. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5640. * @phba: Pointer to HBA context object.
  5641. * @ring_number: SLI ring number to issue iocb on.
  5642. * @piocb: Pointer to command iocb.
  5643. * @flag: Flag indicating if this command can be put into txq.
  5644. *
  5645. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5646. * an iocb command to an HBA with SLI-4 interface spec.
  5647. *
  5648. * This function is called with hbalock held. The function will return success
  5649. * after it successfully submit the iocb to firmware or after adding to the
  5650. * txq.
  5651. **/
  5652. static int
  5653. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5654. struct lpfc_iocbq *piocb, uint32_t flag)
  5655. {
  5656. struct lpfc_sglq *sglq;
  5657. union lpfc_wqe wqe;
  5658. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5659. if (piocb->sli4_xritag == NO_XRI) {
  5660. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5661. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5662. sglq = NULL;
  5663. else {
  5664. if (pring->txq_cnt) {
  5665. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5666. __lpfc_sli_ringtx_put(phba,
  5667. pring, piocb);
  5668. return IOCB_SUCCESS;
  5669. } else {
  5670. return IOCB_BUSY;
  5671. }
  5672. } else {
  5673. sglq = __lpfc_sli_get_sglq(phba);
  5674. if (!sglq) {
  5675. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5676. __lpfc_sli_ringtx_put(phba,
  5677. pring,
  5678. piocb);
  5679. return IOCB_SUCCESS;
  5680. } else
  5681. return IOCB_BUSY;
  5682. }
  5683. }
  5684. }
  5685. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5686. sglq = NULL; /* These IO's already have an XRI and
  5687. * a mapped sgl.
  5688. */
  5689. } else {
  5690. /* This is a continuation of a commandi,(CX) so this
  5691. * sglq is on the active list
  5692. */
  5693. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5694. if (!sglq)
  5695. return IOCB_ERROR;
  5696. }
  5697. if (sglq) {
  5698. piocb->sli4_xritag = sglq->sli4_xritag;
  5699. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  5700. return IOCB_ERROR;
  5701. }
  5702. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5703. return IOCB_ERROR;
  5704. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5705. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5706. /*
  5707. * For FCP command IOCB, get a new WQ index to distribute
  5708. * WQE across the WQsr. On the other hand, for abort IOCB,
  5709. * it carries the same WQ index to the original command
  5710. * IOCB.
  5711. */
  5712. if (piocb->iocb_flag & LPFC_IO_FCP)
  5713. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5714. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5715. &wqe))
  5716. return IOCB_ERROR;
  5717. } else {
  5718. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5719. return IOCB_ERROR;
  5720. }
  5721. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5722. return 0;
  5723. }
  5724. /**
  5725. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5726. *
  5727. * This routine wraps the actual lockless version for issusing IOCB function
  5728. * pointer from the lpfc_hba struct.
  5729. *
  5730. * Return codes:
  5731. * IOCB_ERROR - Error
  5732. * IOCB_SUCCESS - Success
  5733. * IOCB_BUSY - Busy
  5734. **/
  5735. int
  5736. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5737. struct lpfc_iocbq *piocb, uint32_t flag)
  5738. {
  5739. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5740. }
  5741. /**
  5742. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5743. * @phba: The hba struct for which this call is being executed.
  5744. * @dev_grp: The HBA PCI-Device group number.
  5745. *
  5746. * This routine sets up the SLI interface API function jump table in @phba
  5747. * struct.
  5748. * Returns: 0 - success, -ENODEV - failure.
  5749. **/
  5750. int
  5751. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5752. {
  5753. switch (dev_grp) {
  5754. case LPFC_PCI_DEV_LP:
  5755. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5756. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5757. break;
  5758. case LPFC_PCI_DEV_OC:
  5759. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5760. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5761. break;
  5762. default:
  5763. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5764. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5765. dev_grp);
  5766. return -ENODEV;
  5767. break;
  5768. }
  5769. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5770. return 0;
  5771. }
  5772. /**
  5773. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5774. * @phba: Pointer to HBA context object.
  5775. * @pring: Pointer to driver SLI ring object.
  5776. * @piocb: Pointer to command iocb.
  5777. * @flag: Flag indicating if this command can be put into txq.
  5778. *
  5779. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5780. * function. This function gets the hbalock and calls
  5781. * __lpfc_sli_issue_iocb function and will return the error returned
  5782. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5783. * functions which do not hold hbalock.
  5784. **/
  5785. int
  5786. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5787. struct lpfc_iocbq *piocb, uint32_t flag)
  5788. {
  5789. unsigned long iflags;
  5790. int rc;
  5791. spin_lock_irqsave(&phba->hbalock, iflags);
  5792. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5793. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5794. return rc;
  5795. }
  5796. /**
  5797. * lpfc_extra_ring_setup - Extra ring setup function
  5798. * @phba: Pointer to HBA context object.
  5799. *
  5800. * This function is called while driver attaches with the
  5801. * HBA to setup the extra ring. The extra ring is used
  5802. * only when driver needs to support target mode functionality
  5803. * or IP over FC functionalities.
  5804. *
  5805. * This function is called with no lock held.
  5806. **/
  5807. static int
  5808. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5809. {
  5810. struct lpfc_sli *psli;
  5811. struct lpfc_sli_ring *pring;
  5812. psli = &phba->sli;
  5813. /* Adjust cmd/rsp ring iocb entries more evenly */
  5814. /* Take some away from the FCP ring */
  5815. pring = &psli->ring[psli->fcp_ring];
  5816. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5817. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5818. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5819. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5820. /* and give them to the extra ring */
  5821. pring = &psli->ring[psli->extra_ring];
  5822. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5823. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5824. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5825. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5826. /* Setup default profile for this ring */
  5827. pring->iotag_max = 4096;
  5828. pring->num_mask = 1;
  5829. pring->prt[0].profile = 0; /* Mask 0 */
  5830. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5831. pring->prt[0].type = phba->cfg_multi_ring_type;
  5832. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5833. return 0;
  5834. }
  5835. /**
  5836. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5837. * @phba: Pointer to HBA context object.
  5838. * @pring: Pointer to driver SLI ring object.
  5839. * @iocbq: Pointer to iocb object.
  5840. *
  5841. * This function is called by the slow ring event handler
  5842. * function when there is an ASYNC event iocb in the ring.
  5843. * This function is called with no lock held.
  5844. * Currently this function handles only temperature related
  5845. * ASYNC events. The function decodes the temperature sensor
  5846. * event message and posts events for the management applications.
  5847. **/
  5848. static void
  5849. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5850. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5851. {
  5852. IOCB_t *icmd;
  5853. uint16_t evt_code;
  5854. uint16_t temp;
  5855. struct temp_event temp_event_data;
  5856. struct Scsi_Host *shost;
  5857. uint32_t *iocb_w;
  5858. icmd = &iocbq->iocb;
  5859. evt_code = icmd->un.asyncstat.evt_code;
  5860. temp = icmd->ulpContext;
  5861. if ((evt_code != ASYNC_TEMP_WARN) &&
  5862. (evt_code != ASYNC_TEMP_SAFE)) {
  5863. iocb_w = (uint32_t *) icmd;
  5864. lpfc_printf_log(phba,
  5865. KERN_ERR,
  5866. LOG_SLI,
  5867. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5868. " evt_code 0x%x\n"
  5869. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5870. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5871. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5872. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5873. pring->ringno,
  5874. icmd->un.asyncstat.evt_code,
  5875. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5876. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5877. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5878. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5879. return;
  5880. }
  5881. temp_event_data.data = (uint32_t)temp;
  5882. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5883. if (evt_code == ASYNC_TEMP_WARN) {
  5884. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5885. lpfc_printf_log(phba,
  5886. KERN_ERR,
  5887. LOG_TEMP,
  5888. "0347 Adapter is very hot, please take "
  5889. "corrective action. temperature : %d Celsius\n",
  5890. temp);
  5891. }
  5892. if (evt_code == ASYNC_TEMP_SAFE) {
  5893. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5894. lpfc_printf_log(phba,
  5895. KERN_ERR,
  5896. LOG_TEMP,
  5897. "0340 Adapter temperature is OK now. "
  5898. "temperature : %d Celsius\n",
  5899. temp);
  5900. }
  5901. /* Send temperature change event to applications */
  5902. shost = lpfc_shost_from_vport(phba->pport);
  5903. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5904. sizeof(temp_event_data), (char *) &temp_event_data,
  5905. LPFC_NL_VENDOR_ID);
  5906. }
  5907. /**
  5908. * lpfc_sli_setup - SLI ring setup function
  5909. * @phba: Pointer to HBA context object.
  5910. *
  5911. * lpfc_sli_setup sets up rings of the SLI interface with
  5912. * number of iocbs per ring and iotags. This function is
  5913. * called while driver attach to the HBA and before the
  5914. * interrupts are enabled. So there is no need for locking.
  5915. *
  5916. * This function always returns 0.
  5917. **/
  5918. int
  5919. lpfc_sli_setup(struct lpfc_hba *phba)
  5920. {
  5921. int i, totiocbsize = 0;
  5922. struct lpfc_sli *psli = &phba->sli;
  5923. struct lpfc_sli_ring *pring;
  5924. psli->num_rings = MAX_CONFIGURED_RINGS;
  5925. psli->sli_flag = 0;
  5926. psli->fcp_ring = LPFC_FCP_RING;
  5927. psli->next_ring = LPFC_FCP_NEXT_RING;
  5928. psli->extra_ring = LPFC_EXTRA_RING;
  5929. psli->iocbq_lookup = NULL;
  5930. psli->iocbq_lookup_len = 0;
  5931. psli->last_iotag = 0;
  5932. for (i = 0; i < psli->num_rings; i++) {
  5933. pring = &psli->ring[i];
  5934. switch (i) {
  5935. case LPFC_FCP_RING: /* ring 0 - FCP */
  5936. /* numCiocb and numRiocb are used in config_port */
  5937. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5938. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5939. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5940. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5941. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5942. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5943. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5944. SLI3_IOCB_CMD_SIZE :
  5945. SLI2_IOCB_CMD_SIZE;
  5946. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5947. SLI3_IOCB_RSP_SIZE :
  5948. SLI2_IOCB_RSP_SIZE;
  5949. pring->iotag_ctr = 0;
  5950. pring->iotag_max =
  5951. (phba->cfg_hba_queue_depth * 2);
  5952. pring->fast_iotag = pring->iotag_max;
  5953. pring->num_mask = 0;
  5954. break;
  5955. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5956. /* numCiocb and numRiocb are used in config_port */
  5957. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5958. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5959. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5960. SLI3_IOCB_CMD_SIZE :
  5961. SLI2_IOCB_CMD_SIZE;
  5962. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5963. SLI3_IOCB_RSP_SIZE :
  5964. SLI2_IOCB_RSP_SIZE;
  5965. pring->iotag_max = phba->cfg_hba_queue_depth;
  5966. pring->num_mask = 0;
  5967. break;
  5968. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5969. /* numCiocb and numRiocb are used in config_port */
  5970. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5971. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5972. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5973. SLI3_IOCB_CMD_SIZE :
  5974. SLI2_IOCB_CMD_SIZE;
  5975. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5976. SLI3_IOCB_RSP_SIZE :
  5977. SLI2_IOCB_RSP_SIZE;
  5978. pring->fast_iotag = 0;
  5979. pring->iotag_ctr = 0;
  5980. pring->iotag_max = 4096;
  5981. pring->lpfc_sli_rcv_async_status =
  5982. lpfc_sli_async_event_handler;
  5983. pring->num_mask = LPFC_MAX_RING_MASK;
  5984. pring->prt[0].profile = 0; /* Mask 0 */
  5985. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5986. pring->prt[0].type = FC_TYPE_ELS;
  5987. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5988. lpfc_els_unsol_event;
  5989. pring->prt[1].profile = 0; /* Mask 1 */
  5990. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5991. pring->prt[1].type = FC_TYPE_ELS;
  5992. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5993. lpfc_els_unsol_event;
  5994. pring->prt[2].profile = 0; /* Mask 2 */
  5995. /* NameServer Inquiry */
  5996. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5997. /* NameServer */
  5998. pring->prt[2].type = FC_TYPE_CT;
  5999. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6000. lpfc_ct_unsol_event;
  6001. pring->prt[3].profile = 0; /* Mask 3 */
  6002. /* NameServer response */
  6003. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6004. /* NameServer */
  6005. pring->prt[3].type = FC_TYPE_CT;
  6006. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6007. lpfc_ct_unsol_event;
  6008. /* abort unsolicited sequence */
  6009. pring->prt[4].profile = 0; /* Mask 4 */
  6010. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6011. pring->prt[4].type = FC_TYPE_BLS;
  6012. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6013. lpfc_sli4_ct_abort_unsol_event;
  6014. break;
  6015. }
  6016. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6017. (pring->numRiocb * pring->sizeRiocb);
  6018. }
  6019. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6020. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6021. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6022. "SLI2 SLIM Data: x%x x%lx\n",
  6023. phba->brd_no, totiocbsize,
  6024. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6025. }
  6026. if (phba->cfg_multi_ring_support == 2)
  6027. lpfc_extra_ring_setup(phba);
  6028. return 0;
  6029. }
  6030. /**
  6031. * lpfc_sli_queue_setup - Queue initialization function
  6032. * @phba: Pointer to HBA context object.
  6033. *
  6034. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6035. * ring. This function also initializes ring indices of each ring.
  6036. * This function is called during the initialization of the SLI
  6037. * interface of an HBA.
  6038. * This function is called with no lock held and always returns
  6039. * 1.
  6040. **/
  6041. int
  6042. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6043. {
  6044. struct lpfc_sli *psli;
  6045. struct lpfc_sli_ring *pring;
  6046. int i;
  6047. psli = &phba->sli;
  6048. spin_lock_irq(&phba->hbalock);
  6049. INIT_LIST_HEAD(&psli->mboxq);
  6050. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6051. /* Initialize list headers for txq and txcmplq as double linked lists */
  6052. for (i = 0; i < psli->num_rings; i++) {
  6053. pring = &psli->ring[i];
  6054. pring->ringno = i;
  6055. pring->next_cmdidx = 0;
  6056. pring->local_getidx = 0;
  6057. pring->cmdidx = 0;
  6058. INIT_LIST_HEAD(&pring->txq);
  6059. INIT_LIST_HEAD(&pring->txcmplq);
  6060. INIT_LIST_HEAD(&pring->iocb_continueq);
  6061. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6062. INIT_LIST_HEAD(&pring->postbufq);
  6063. }
  6064. spin_unlock_irq(&phba->hbalock);
  6065. return 1;
  6066. }
  6067. /**
  6068. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6069. * @phba: Pointer to HBA context object.
  6070. *
  6071. * This routine flushes the mailbox command subsystem. It will unconditionally
  6072. * flush all the mailbox commands in the three possible stages in the mailbox
  6073. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6074. * command; and completed mailbox command queue. It is caller's responsibility
  6075. * to make sure that the driver is in the proper state to flush the mailbox
  6076. * command sub-system. Namely, the posting of mailbox commands into the
  6077. * pending mailbox command queue from the various clients must be stopped;
  6078. * either the HBA is in a state that it will never works on the outstanding
  6079. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6080. * mailbox command has been completed.
  6081. **/
  6082. static void
  6083. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6084. {
  6085. LIST_HEAD(completions);
  6086. struct lpfc_sli *psli = &phba->sli;
  6087. LPFC_MBOXQ_t *pmb;
  6088. unsigned long iflag;
  6089. /* Flush all the mailbox commands in the mbox system */
  6090. spin_lock_irqsave(&phba->hbalock, iflag);
  6091. /* The pending mailbox command queue */
  6092. list_splice_init(&phba->sli.mboxq, &completions);
  6093. /* The outstanding active mailbox command */
  6094. if (psli->mbox_active) {
  6095. list_add_tail(&psli->mbox_active->list, &completions);
  6096. psli->mbox_active = NULL;
  6097. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6098. }
  6099. /* The completed mailbox command queue */
  6100. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6101. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6102. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6103. while (!list_empty(&completions)) {
  6104. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6105. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6106. if (pmb->mbox_cmpl)
  6107. pmb->mbox_cmpl(phba, pmb);
  6108. }
  6109. }
  6110. /**
  6111. * lpfc_sli_host_down - Vport cleanup function
  6112. * @vport: Pointer to virtual port object.
  6113. *
  6114. * lpfc_sli_host_down is called to clean up the resources
  6115. * associated with a vport before destroying virtual
  6116. * port data structures.
  6117. * This function does following operations:
  6118. * - Free discovery resources associated with this virtual
  6119. * port.
  6120. * - Free iocbs associated with this virtual port in
  6121. * the txq.
  6122. * - Send abort for all iocb commands associated with this
  6123. * vport in txcmplq.
  6124. *
  6125. * This function is called with no lock held and always returns 1.
  6126. **/
  6127. int
  6128. lpfc_sli_host_down(struct lpfc_vport *vport)
  6129. {
  6130. LIST_HEAD(completions);
  6131. struct lpfc_hba *phba = vport->phba;
  6132. struct lpfc_sli *psli = &phba->sli;
  6133. struct lpfc_sli_ring *pring;
  6134. struct lpfc_iocbq *iocb, *next_iocb;
  6135. int i;
  6136. unsigned long flags = 0;
  6137. uint16_t prev_pring_flag;
  6138. lpfc_cleanup_discovery_resources(vport);
  6139. spin_lock_irqsave(&phba->hbalock, flags);
  6140. for (i = 0; i < psli->num_rings; i++) {
  6141. pring = &psli->ring[i];
  6142. prev_pring_flag = pring->flag;
  6143. /* Only slow rings */
  6144. if (pring->ringno == LPFC_ELS_RING) {
  6145. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6146. /* Set the lpfc data pending flag */
  6147. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6148. }
  6149. /*
  6150. * Error everything on the txq since these iocbs have not been
  6151. * given to the FW yet.
  6152. */
  6153. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6154. if (iocb->vport != vport)
  6155. continue;
  6156. list_move_tail(&iocb->list, &completions);
  6157. pring->txq_cnt--;
  6158. }
  6159. /* Next issue ABTS for everything on the txcmplq */
  6160. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6161. list) {
  6162. if (iocb->vport != vport)
  6163. continue;
  6164. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6165. }
  6166. pring->flag = prev_pring_flag;
  6167. }
  6168. spin_unlock_irqrestore(&phba->hbalock, flags);
  6169. /* Cancel all the IOCBs from the completions list */
  6170. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6171. IOERR_SLI_DOWN);
  6172. return 1;
  6173. }
  6174. /**
  6175. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6176. * @phba: Pointer to HBA context object.
  6177. *
  6178. * This function cleans up all iocb, buffers, mailbox commands
  6179. * while shutting down the HBA. This function is called with no
  6180. * lock held and always returns 1.
  6181. * This function does the following to cleanup driver resources:
  6182. * - Free discovery resources for each virtual port
  6183. * - Cleanup any pending fabric iocbs
  6184. * - Iterate through the iocb txq and free each entry
  6185. * in the list.
  6186. * - Free up any buffer posted to the HBA
  6187. * - Free mailbox commands in the mailbox queue.
  6188. **/
  6189. int
  6190. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6191. {
  6192. LIST_HEAD(completions);
  6193. struct lpfc_sli *psli = &phba->sli;
  6194. struct lpfc_sli_ring *pring;
  6195. struct lpfc_dmabuf *buf_ptr;
  6196. unsigned long flags = 0;
  6197. int i;
  6198. /* Shutdown the mailbox command sub-system */
  6199. lpfc_sli_mbox_sys_shutdown(phba);
  6200. lpfc_hba_down_prep(phba);
  6201. lpfc_fabric_abort_hba(phba);
  6202. spin_lock_irqsave(&phba->hbalock, flags);
  6203. for (i = 0; i < psli->num_rings; i++) {
  6204. pring = &psli->ring[i];
  6205. /* Only slow rings */
  6206. if (pring->ringno == LPFC_ELS_RING) {
  6207. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6208. /* Set the lpfc data pending flag */
  6209. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6210. }
  6211. /*
  6212. * Error everything on the txq since these iocbs have not been
  6213. * given to the FW yet.
  6214. */
  6215. list_splice_init(&pring->txq, &completions);
  6216. pring->txq_cnt = 0;
  6217. }
  6218. spin_unlock_irqrestore(&phba->hbalock, flags);
  6219. /* Cancel all the IOCBs from the completions list */
  6220. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6221. IOERR_SLI_DOWN);
  6222. spin_lock_irqsave(&phba->hbalock, flags);
  6223. list_splice_init(&phba->elsbuf, &completions);
  6224. phba->elsbuf_cnt = 0;
  6225. phba->elsbuf_prev_cnt = 0;
  6226. spin_unlock_irqrestore(&phba->hbalock, flags);
  6227. while (!list_empty(&completions)) {
  6228. list_remove_head(&completions, buf_ptr,
  6229. struct lpfc_dmabuf, list);
  6230. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6231. kfree(buf_ptr);
  6232. }
  6233. /* Return any active mbox cmds */
  6234. del_timer_sync(&psli->mbox_tmo);
  6235. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6236. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6237. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6238. return 1;
  6239. }
  6240. /**
  6241. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6242. * @phba: Pointer to HBA context object.
  6243. *
  6244. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6245. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6246. * lock held and always returns 1.
  6247. *
  6248. * This function does the following to cleanup driver FCoE function resources:
  6249. * - Free discovery resources for each virtual port
  6250. * - Cleanup any pending fabric iocbs
  6251. * - Iterate through the iocb txq and free each entry in the list.
  6252. * - Free up any buffer posted to the HBA.
  6253. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6254. * - Free mailbox commands in the mailbox queue.
  6255. **/
  6256. int
  6257. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6258. {
  6259. /* Stop the SLI4 device port */
  6260. lpfc_stop_port(phba);
  6261. /* Tear down the queues in the HBA */
  6262. lpfc_sli4_queue_unset(phba);
  6263. /* unregister default FCFI from the HBA */
  6264. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6265. return 1;
  6266. }
  6267. /**
  6268. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6269. * @srcp: Source memory pointer.
  6270. * @destp: Destination memory pointer.
  6271. * @cnt: Number of words required to be copied.
  6272. *
  6273. * This function is used for copying data between driver memory
  6274. * and the SLI memory. This function also changes the endianness
  6275. * of each word if native endianness is different from SLI
  6276. * endianness. This function can be called with or without
  6277. * lock.
  6278. **/
  6279. void
  6280. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6281. {
  6282. uint32_t *src = srcp;
  6283. uint32_t *dest = destp;
  6284. uint32_t ldata;
  6285. int i;
  6286. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6287. ldata = *src;
  6288. ldata = le32_to_cpu(ldata);
  6289. *dest = ldata;
  6290. src++;
  6291. dest++;
  6292. }
  6293. }
  6294. /**
  6295. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6296. * @srcp: Source memory pointer.
  6297. * @destp: Destination memory pointer.
  6298. * @cnt: Number of words required to be copied.
  6299. *
  6300. * This function is used for copying data between a data structure
  6301. * with big endian representation to local endianness.
  6302. * This function can be called with or without lock.
  6303. **/
  6304. void
  6305. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6306. {
  6307. uint32_t *src = srcp;
  6308. uint32_t *dest = destp;
  6309. uint32_t ldata;
  6310. int i;
  6311. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6312. ldata = *src;
  6313. ldata = be32_to_cpu(ldata);
  6314. *dest = ldata;
  6315. src++;
  6316. dest++;
  6317. }
  6318. }
  6319. /**
  6320. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6321. * @phba: Pointer to HBA context object.
  6322. * @pring: Pointer to driver SLI ring object.
  6323. * @mp: Pointer to driver buffer object.
  6324. *
  6325. * This function is called with no lock held.
  6326. * It always return zero after adding the buffer to the postbufq
  6327. * buffer list.
  6328. **/
  6329. int
  6330. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6331. struct lpfc_dmabuf *mp)
  6332. {
  6333. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6334. later */
  6335. spin_lock_irq(&phba->hbalock);
  6336. list_add_tail(&mp->list, &pring->postbufq);
  6337. pring->postbufq_cnt++;
  6338. spin_unlock_irq(&phba->hbalock);
  6339. return 0;
  6340. }
  6341. /**
  6342. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6343. * @phba: Pointer to HBA context object.
  6344. *
  6345. * When HBQ is enabled, buffers are searched based on tags. This function
  6346. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6347. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6348. * does not conflict with tags of buffer posted for unsolicited events.
  6349. * The function returns the allocated tag. The function is called with
  6350. * no locks held.
  6351. **/
  6352. uint32_t
  6353. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6354. {
  6355. spin_lock_irq(&phba->hbalock);
  6356. phba->buffer_tag_count++;
  6357. /*
  6358. * Always set the QUE_BUFTAG_BIT to distiguish between
  6359. * a tag assigned by HBQ.
  6360. */
  6361. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6362. spin_unlock_irq(&phba->hbalock);
  6363. return phba->buffer_tag_count;
  6364. }
  6365. /**
  6366. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6367. * @phba: Pointer to HBA context object.
  6368. * @pring: Pointer to driver SLI ring object.
  6369. * @tag: Buffer tag.
  6370. *
  6371. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6372. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6373. * iocb is posted to the response ring with the tag of the buffer.
  6374. * This function searches the pring->postbufq list using the tag
  6375. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6376. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6377. * buffer is returned to the caller else NULL is returned.
  6378. * This function is called with no lock held.
  6379. **/
  6380. struct lpfc_dmabuf *
  6381. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6382. uint32_t tag)
  6383. {
  6384. struct lpfc_dmabuf *mp, *next_mp;
  6385. struct list_head *slp = &pring->postbufq;
  6386. /* Search postbufq, from the begining, looking for a match on tag */
  6387. spin_lock_irq(&phba->hbalock);
  6388. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6389. if (mp->buffer_tag == tag) {
  6390. list_del_init(&mp->list);
  6391. pring->postbufq_cnt--;
  6392. spin_unlock_irq(&phba->hbalock);
  6393. return mp;
  6394. }
  6395. }
  6396. spin_unlock_irq(&phba->hbalock);
  6397. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6398. "0402 Cannot find virtual addr for buffer tag on "
  6399. "ring %d Data x%lx x%p x%p x%x\n",
  6400. pring->ringno, (unsigned long) tag,
  6401. slp->next, slp->prev, pring->postbufq_cnt);
  6402. return NULL;
  6403. }
  6404. /**
  6405. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6406. * @phba: Pointer to HBA context object.
  6407. * @pring: Pointer to driver SLI ring object.
  6408. * @phys: DMA address of the buffer.
  6409. *
  6410. * This function searches the buffer list using the dma_address
  6411. * of unsolicited event to find the driver's lpfc_dmabuf object
  6412. * corresponding to the dma_address. The function returns the
  6413. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6414. * This function is called by the ct and els unsolicited event
  6415. * handlers to get the buffer associated with the unsolicited
  6416. * event.
  6417. *
  6418. * This function is called with no lock held.
  6419. **/
  6420. struct lpfc_dmabuf *
  6421. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6422. dma_addr_t phys)
  6423. {
  6424. struct lpfc_dmabuf *mp, *next_mp;
  6425. struct list_head *slp = &pring->postbufq;
  6426. /* Search postbufq, from the begining, looking for a match on phys */
  6427. spin_lock_irq(&phba->hbalock);
  6428. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6429. if (mp->phys == phys) {
  6430. list_del_init(&mp->list);
  6431. pring->postbufq_cnt--;
  6432. spin_unlock_irq(&phba->hbalock);
  6433. return mp;
  6434. }
  6435. }
  6436. spin_unlock_irq(&phba->hbalock);
  6437. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6438. "0410 Cannot find virtual addr for mapped buf on "
  6439. "ring %d Data x%llx x%p x%p x%x\n",
  6440. pring->ringno, (unsigned long long)phys,
  6441. slp->next, slp->prev, pring->postbufq_cnt);
  6442. return NULL;
  6443. }
  6444. /**
  6445. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6446. * @phba: Pointer to HBA context object.
  6447. * @cmdiocb: Pointer to driver command iocb object.
  6448. * @rspiocb: Pointer to driver response iocb object.
  6449. *
  6450. * This function is the completion handler for the abort iocbs for
  6451. * ELS commands. This function is called from the ELS ring event
  6452. * handler with no lock held. This function frees memory resources
  6453. * associated with the abort iocb.
  6454. **/
  6455. static void
  6456. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6457. struct lpfc_iocbq *rspiocb)
  6458. {
  6459. IOCB_t *irsp = &rspiocb->iocb;
  6460. uint16_t abort_iotag, abort_context;
  6461. struct lpfc_iocbq *abort_iocb;
  6462. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6463. abort_iocb = NULL;
  6464. if (irsp->ulpStatus) {
  6465. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6466. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6467. spin_lock_irq(&phba->hbalock);
  6468. if (phba->sli_rev < LPFC_SLI_REV4) {
  6469. if (abort_iotag != 0 &&
  6470. abort_iotag <= phba->sli.last_iotag)
  6471. abort_iocb =
  6472. phba->sli.iocbq_lookup[abort_iotag];
  6473. } else
  6474. /* For sli4 the abort_tag is the XRI,
  6475. * so the abort routine puts the iotag of the iocb
  6476. * being aborted in the context field of the abort
  6477. * IOCB.
  6478. */
  6479. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6480. /*
  6481. * If the iocb is not found in Firmware queue the iocb
  6482. * might have completed already. Do not free it again.
  6483. */
  6484. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6485. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6486. spin_unlock_irq(&phba->hbalock);
  6487. lpfc_sli_release_iocbq(phba, cmdiocb);
  6488. return;
  6489. }
  6490. /* For SLI4 the ulpContext field for abort IOCB
  6491. * holds the iotag of the IOCB being aborted so
  6492. * the local abort_context needs to be reset to
  6493. * match the aborted IOCBs ulpContext.
  6494. */
  6495. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6496. abort_context = abort_iocb->iocb.ulpContext;
  6497. }
  6498. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6499. "0327 Cannot abort els iocb %p "
  6500. "with tag %x context %x, abort status %x, "
  6501. "abort code %x\n",
  6502. abort_iocb, abort_iotag, abort_context,
  6503. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6504. /*
  6505. * make sure we have the right iocbq before taking it
  6506. * off the txcmplq and try to call completion routine.
  6507. */
  6508. if (!abort_iocb ||
  6509. abort_iocb->iocb.ulpContext != abort_context ||
  6510. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6511. spin_unlock_irq(&phba->hbalock);
  6512. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6513. /*
  6514. * leave the SLI4 aborted command on the txcmplq
  6515. * list and the command complete WCQE's XB bit
  6516. * will tell whether the SGL (XRI) can be released
  6517. * immediately or to the aborted SGL list for the
  6518. * following abort XRI from the HBA.
  6519. */
  6520. list_del_init(&abort_iocb->list);
  6521. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6522. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6523. pring->txcmplq_cnt--;
  6524. }
  6525. /* Firmware could still be in progress of DMAing
  6526. * payload, so don't free data buffer till after
  6527. * a hbeat.
  6528. */
  6529. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6530. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6531. spin_unlock_irq(&phba->hbalock);
  6532. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6533. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6534. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6535. } else
  6536. spin_unlock_irq(&phba->hbalock);
  6537. }
  6538. lpfc_sli_release_iocbq(phba, cmdiocb);
  6539. return;
  6540. }
  6541. /**
  6542. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6543. * @phba: Pointer to HBA context object.
  6544. * @cmdiocb: Pointer to driver command iocb object.
  6545. * @rspiocb: Pointer to driver response iocb object.
  6546. *
  6547. * The function is called from SLI ring event handler with no
  6548. * lock held. This function is the completion handler for ELS commands
  6549. * which are aborted. The function frees memory resources used for
  6550. * the aborted ELS commands.
  6551. **/
  6552. static void
  6553. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6554. struct lpfc_iocbq *rspiocb)
  6555. {
  6556. IOCB_t *irsp = &rspiocb->iocb;
  6557. /* ELS cmd tag <ulpIoTag> completes */
  6558. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6559. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6560. "x%x x%x x%x\n",
  6561. irsp->ulpIoTag, irsp->ulpStatus,
  6562. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6563. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6564. lpfc_ct_free_iocb(phba, cmdiocb);
  6565. else
  6566. lpfc_els_free_iocb(phba, cmdiocb);
  6567. return;
  6568. }
  6569. /**
  6570. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6571. * @phba: Pointer to HBA context object.
  6572. * @pring: Pointer to driver SLI ring object.
  6573. * @cmdiocb: Pointer to driver command iocb object.
  6574. *
  6575. * This function issues an abort iocb for the provided command
  6576. * iocb. This function is called with hbalock held.
  6577. * The function returns 0 when it fails due to memory allocation
  6578. * failure or when the command iocb is an abort request.
  6579. **/
  6580. int
  6581. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6582. struct lpfc_iocbq *cmdiocb)
  6583. {
  6584. struct lpfc_vport *vport = cmdiocb->vport;
  6585. struct lpfc_iocbq *abtsiocbp;
  6586. IOCB_t *icmd = NULL;
  6587. IOCB_t *iabt = NULL;
  6588. int retval = IOCB_ERROR;
  6589. /*
  6590. * There are certain command types we don't want to abort. And we
  6591. * don't want to abort commands that are already in the process of
  6592. * being aborted.
  6593. */
  6594. icmd = &cmdiocb->iocb;
  6595. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6596. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6597. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6598. return 0;
  6599. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6600. * callback so that nothing happens when it finishes.
  6601. */
  6602. if ((vport->load_flag & FC_UNLOADING) &&
  6603. (pring->ringno == LPFC_ELS_RING)) {
  6604. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6605. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6606. else
  6607. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6608. goto abort_iotag_exit;
  6609. }
  6610. /* issue ABTS for this IOCB based on iotag */
  6611. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6612. if (abtsiocbp == NULL)
  6613. return 0;
  6614. /* This signals the response to set the correct status
  6615. * before calling the completion handler
  6616. */
  6617. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6618. iabt = &abtsiocbp->iocb;
  6619. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6620. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6621. if (phba->sli_rev == LPFC_SLI_REV4) {
  6622. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6623. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6624. }
  6625. else
  6626. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6627. iabt->ulpLe = 1;
  6628. iabt->ulpClass = icmd->ulpClass;
  6629. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6630. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6631. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6632. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6633. if (phba->link_state >= LPFC_LINK_UP)
  6634. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6635. else
  6636. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6637. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6638. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6639. "0339 Abort xri x%x, original iotag x%x, "
  6640. "abort cmd iotag x%x\n",
  6641. iabt->un.acxri.abortIoTag,
  6642. iabt->un.acxri.abortContextTag,
  6643. abtsiocbp->iotag);
  6644. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6645. if (retval)
  6646. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6647. abort_iotag_exit:
  6648. /*
  6649. * Caller to this routine should check for IOCB_ERROR
  6650. * and handle it properly. This routine no longer removes
  6651. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6652. */
  6653. return retval;
  6654. }
  6655. /**
  6656. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6657. * @iocbq: Pointer to driver iocb object.
  6658. * @vport: Pointer to driver virtual port object.
  6659. * @tgt_id: SCSI ID of the target.
  6660. * @lun_id: LUN ID of the scsi device.
  6661. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6662. *
  6663. * This function acts as an iocb filter for functions which abort or count
  6664. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6665. * 0 if the filtering criteria is met for the given iocb and will return
  6666. * 1 if the filtering criteria is not met.
  6667. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6668. * given iocb is for the SCSI device specified by vport, tgt_id and
  6669. * lun_id parameter.
  6670. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6671. * given iocb is for the SCSI target specified by vport and tgt_id
  6672. * parameters.
  6673. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6674. * given iocb is for the SCSI host associated with the given vport.
  6675. * This function is called with no locks held.
  6676. **/
  6677. static int
  6678. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6679. uint16_t tgt_id, uint64_t lun_id,
  6680. lpfc_ctx_cmd ctx_cmd)
  6681. {
  6682. struct lpfc_scsi_buf *lpfc_cmd;
  6683. int rc = 1;
  6684. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6685. return rc;
  6686. if (iocbq->vport != vport)
  6687. return rc;
  6688. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6689. if (lpfc_cmd->pCmd == NULL)
  6690. return rc;
  6691. switch (ctx_cmd) {
  6692. case LPFC_CTX_LUN:
  6693. if ((lpfc_cmd->rdata->pnode) &&
  6694. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6695. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6696. rc = 0;
  6697. break;
  6698. case LPFC_CTX_TGT:
  6699. if ((lpfc_cmd->rdata->pnode) &&
  6700. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6701. rc = 0;
  6702. break;
  6703. case LPFC_CTX_HOST:
  6704. rc = 0;
  6705. break;
  6706. default:
  6707. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6708. __func__, ctx_cmd);
  6709. break;
  6710. }
  6711. return rc;
  6712. }
  6713. /**
  6714. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6715. * @vport: Pointer to virtual port.
  6716. * @tgt_id: SCSI ID of the target.
  6717. * @lun_id: LUN ID of the scsi device.
  6718. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6719. *
  6720. * This function returns number of FCP commands pending for the vport.
  6721. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6722. * commands pending on the vport associated with SCSI device specified
  6723. * by tgt_id and lun_id parameters.
  6724. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6725. * commands pending on the vport associated with SCSI target specified
  6726. * by tgt_id parameter.
  6727. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6728. * commands pending on the vport.
  6729. * This function returns the number of iocbs which satisfy the filter.
  6730. * This function is called without any lock held.
  6731. **/
  6732. int
  6733. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6734. lpfc_ctx_cmd ctx_cmd)
  6735. {
  6736. struct lpfc_hba *phba = vport->phba;
  6737. struct lpfc_iocbq *iocbq;
  6738. int sum, i;
  6739. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6740. iocbq = phba->sli.iocbq_lookup[i];
  6741. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6742. ctx_cmd) == 0)
  6743. sum++;
  6744. }
  6745. return sum;
  6746. }
  6747. /**
  6748. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6749. * @phba: Pointer to HBA context object
  6750. * @cmdiocb: Pointer to command iocb object.
  6751. * @rspiocb: Pointer to response iocb object.
  6752. *
  6753. * This function is called when an aborted FCP iocb completes. This
  6754. * function is called by the ring event handler with no lock held.
  6755. * This function frees the iocb.
  6756. **/
  6757. void
  6758. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6759. struct lpfc_iocbq *rspiocb)
  6760. {
  6761. lpfc_sli_release_iocbq(phba, cmdiocb);
  6762. return;
  6763. }
  6764. /**
  6765. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6766. * @vport: Pointer to virtual port.
  6767. * @pring: Pointer to driver SLI ring object.
  6768. * @tgt_id: SCSI ID of the target.
  6769. * @lun_id: LUN ID of the scsi device.
  6770. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6771. *
  6772. * This function sends an abort command for every SCSI command
  6773. * associated with the given virtual port pending on the ring
  6774. * filtered by lpfc_sli_validate_fcp_iocb function.
  6775. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6776. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6777. * parameters
  6778. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6779. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6780. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6781. * FCP iocbs associated with virtual port.
  6782. * This function returns number of iocbs it failed to abort.
  6783. * This function is called with no locks held.
  6784. **/
  6785. int
  6786. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6787. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6788. {
  6789. struct lpfc_hba *phba = vport->phba;
  6790. struct lpfc_iocbq *iocbq;
  6791. struct lpfc_iocbq *abtsiocb;
  6792. IOCB_t *cmd = NULL;
  6793. int errcnt = 0, ret_val = 0;
  6794. int i;
  6795. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6796. iocbq = phba->sli.iocbq_lookup[i];
  6797. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6798. abort_cmd) != 0)
  6799. continue;
  6800. /* issue ABTS for this IOCB based on iotag */
  6801. abtsiocb = lpfc_sli_get_iocbq(phba);
  6802. if (abtsiocb == NULL) {
  6803. errcnt++;
  6804. continue;
  6805. }
  6806. cmd = &iocbq->iocb;
  6807. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6808. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6809. if (phba->sli_rev == LPFC_SLI_REV4)
  6810. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6811. else
  6812. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6813. abtsiocb->iocb.ulpLe = 1;
  6814. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6815. abtsiocb->vport = phba->pport;
  6816. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6817. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6818. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6819. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6820. if (lpfc_is_link_up(phba))
  6821. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6822. else
  6823. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6824. /* Setup callback routine and issue the command. */
  6825. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6826. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6827. abtsiocb, 0);
  6828. if (ret_val == IOCB_ERROR) {
  6829. lpfc_sli_release_iocbq(phba, abtsiocb);
  6830. errcnt++;
  6831. continue;
  6832. }
  6833. }
  6834. return errcnt;
  6835. }
  6836. /**
  6837. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6838. * @phba: Pointer to HBA context object.
  6839. * @cmdiocbq: Pointer to command iocb.
  6840. * @rspiocbq: Pointer to response iocb.
  6841. *
  6842. * This function is the completion handler for iocbs issued using
  6843. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6844. * ring event handler function without any lock held. This function
  6845. * can be called from both worker thread context and interrupt
  6846. * context. This function also can be called from other thread which
  6847. * cleans up the SLI layer objects.
  6848. * This function copy the contents of the response iocb to the
  6849. * response iocb memory object provided by the caller of
  6850. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6851. * sleeps for the iocb completion.
  6852. **/
  6853. static void
  6854. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6855. struct lpfc_iocbq *cmdiocbq,
  6856. struct lpfc_iocbq *rspiocbq)
  6857. {
  6858. wait_queue_head_t *pdone_q;
  6859. unsigned long iflags;
  6860. struct lpfc_scsi_buf *lpfc_cmd;
  6861. spin_lock_irqsave(&phba->hbalock, iflags);
  6862. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6863. if (cmdiocbq->context2 && rspiocbq)
  6864. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6865. &rspiocbq->iocb, sizeof(IOCB_t));
  6866. /* Set the exchange busy flag for task management commands */
  6867. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6868. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6869. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6870. cur_iocbq);
  6871. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6872. }
  6873. pdone_q = cmdiocbq->context_un.wait_queue;
  6874. if (pdone_q)
  6875. wake_up(pdone_q);
  6876. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6877. return;
  6878. }
  6879. /**
  6880. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6881. * @phba: Pointer to HBA context object..
  6882. * @piocbq: Pointer to command iocb.
  6883. * @flag: Flag to test.
  6884. *
  6885. * This routine grabs the hbalock and then test the iocb_flag to
  6886. * see if the passed in flag is set.
  6887. * Returns:
  6888. * 1 if flag is set.
  6889. * 0 if flag is not set.
  6890. **/
  6891. static int
  6892. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6893. struct lpfc_iocbq *piocbq, uint32_t flag)
  6894. {
  6895. unsigned long iflags;
  6896. int ret;
  6897. spin_lock_irqsave(&phba->hbalock, iflags);
  6898. ret = piocbq->iocb_flag & flag;
  6899. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6900. return ret;
  6901. }
  6902. /**
  6903. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6904. * @phba: Pointer to HBA context object..
  6905. * @pring: Pointer to sli ring.
  6906. * @piocb: Pointer to command iocb.
  6907. * @prspiocbq: Pointer to response iocb.
  6908. * @timeout: Timeout in number of seconds.
  6909. *
  6910. * This function issues the iocb to firmware and waits for the
  6911. * iocb to complete. If the iocb command is not
  6912. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6913. * Caller should not free the iocb resources if this function
  6914. * returns IOCB_TIMEDOUT.
  6915. * The function waits for the iocb completion using an
  6916. * non-interruptible wait.
  6917. * This function will sleep while waiting for iocb completion.
  6918. * So, this function should not be called from any context which
  6919. * does not allow sleeping. Due to the same reason, this function
  6920. * cannot be called with interrupt disabled.
  6921. * This function assumes that the iocb completions occur while
  6922. * this function sleep. So, this function cannot be called from
  6923. * the thread which process iocb completion for this ring.
  6924. * This function clears the iocb_flag of the iocb object before
  6925. * issuing the iocb and the iocb completion handler sets this
  6926. * flag and wakes this thread when the iocb completes.
  6927. * The contents of the response iocb will be copied to prspiocbq
  6928. * by the completion handler when the command completes.
  6929. * This function returns IOCB_SUCCESS when success.
  6930. * This function is called with no lock held.
  6931. **/
  6932. int
  6933. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6934. uint32_t ring_number,
  6935. struct lpfc_iocbq *piocb,
  6936. struct lpfc_iocbq *prspiocbq,
  6937. uint32_t timeout)
  6938. {
  6939. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6940. long timeleft, timeout_req = 0;
  6941. int retval = IOCB_SUCCESS;
  6942. uint32_t creg_val;
  6943. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6944. /*
  6945. * If the caller has provided a response iocbq buffer, then context2
  6946. * is NULL or its an error.
  6947. */
  6948. if (prspiocbq) {
  6949. if (piocb->context2)
  6950. return IOCB_ERROR;
  6951. piocb->context2 = prspiocbq;
  6952. }
  6953. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6954. piocb->context_un.wait_queue = &done_q;
  6955. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6956. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6957. creg_val = readl(phba->HCregaddr);
  6958. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6959. writel(creg_val, phba->HCregaddr);
  6960. readl(phba->HCregaddr); /* flush */
  6961. }
  6962. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  6963. SLI_IOCB_RET_IOCB);
  6964. if (retval == IOCB_SUCCESS) {
  6965. timeout_req = timeout * HZ;
  6966. timeleft = wait_event_timeout(done_q,
  6967. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6968. timeout_req);
  6969. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6970. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6971. "0331 IOCB wake signaled\n");
  6972. } else if (timeleft == 0) {
  6973. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6974. "0338 IOCB wait timeout error - no "
  6975. "wake response Data x%x\n", timeout);
  6976. retval = IOCB_TIMEDOUT;
  6977. } else {
  6978. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6979. "0330 IOCB wake NOT set, "
  6980. "Data x%x x%lx\n",
  6981. timeout, (timeleft / jiffies));
  6982. retval = IOCB_TIMEDOUT;
  6983. }
  6984. } else if (retval == IOCB_BUSY) {
  6985. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6986. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  6987. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  6988. return retval;
  6989. } else {
  6990. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6991. "0332 IOCB wait issue failed, Data x%x\n",
  6992. retval);
  6993. retval = IOCB_ERROR;
  6994. }
  6995. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6996. creg_val = readl(phba->HCregaddr);
  6997. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6998. writel(creg_val, phba->HCregaddr);
  6999. readl(phba->HCregaddr); /* flush */
  7000. }
  7001. if (prspiocbq)
  7002. piocb->context2 = NULL;
  7003. piocb->context_un.wait_queue = NULL;
  7004. piocb->iocb_cmpl = NULL;
  7005. return retval;
  7006. }
  7007. /**
  7008. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7009. * @phba: Pointer to HBA context object.
  7010. * @pmboxq: Pointer to driver mailbox object.
  7011. * @timeout: Timeout in number of seconds.
  7012. *
  7013. * This function issues the mailbox to firmware and waits for the
  7014. * mailbox command to complete. If the mailbox command is not
  7015. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7016. * The function waits for the mailbox completion using an
  7017. * interruptible wait. If the thread is woken up due to a
  7018. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7019. * should not free the mailbox resources, if this function returns
  7020. * MBX_TIMEOUT.
  7021. * This function will sleep while waiting for mailbox completion.
  7022. * So, this function should not be called from any context which
  7023. * does not allow sleeping. Due to the same reason, this function
  7024. * cannot be called with interrupt disabled.
  7025. * This function assumes that the mailbox completion occurs while
  7026. * this function sleep. So, this function cannot be called from
  7027. * the worker thread which processes mailbox completion.
  7028. * This function is called in the context of HBA management
  7029. * applications.
  7030. * This function returns MBX_SUCCESS when successful.
  7031. * This function is called with no lock held.
  7032. **/
  7033. int
  7034. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7035. uint32_t timeout)
  7036. {
  7037. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7038. int retval;
  7039. unsigned long flag;
  7040. /* The caller must leave context1 empty. */
  7041. if (pmboxq->context1)
  7042. return MBX_NOT_FINISHED;
  7043. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7044. /* setup wake call as IOCB callback */
  7045. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7046. /* setup context field to pass wait_queue pointer to wake function */
  7047. pmboxq->context1 = &done_q;
  7048. /* now issue the command */
  7049. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7050. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7051. wait_event_interruptible_timeout(done_q,
  7052. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7053. timeout * HZ);
  7054. spin_lock_irqsave(&phba->hbalock, flag);
  7055. pmboxq->context1 = NULL;
  7056. /*
  7057. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7058. * else do not free the resources.
  7059. */
  7060. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  7061. retval = MBX_SUCCESS;
  7062. else {
  7063. retval = MBX_TIMEOUT;
  7064. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7065. }
  7066. spin_unlock_irqrestore(&phba->hbalock, flag);
  7067. }
  7068. return retval;
  7069. }
  7070. /**
  7071. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7072. * @phba: Pointer to HBA context.
  7073. *
  7074. * This function is called to shutdown the driver's mailbox sub-system.
  7075. * It first marks the mailbox sub-system is in a block state to prevent
  7076. * the asynchronous mailbox command from issued off the pending mailbox
  7077. * command queue. If the mailbox command sub-system shutdown is due to
  7078. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7079. * the mailbox sub-system flush routine to forcefully bring down the
  7080. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7081. * as with offline or HBA function reset), this routine will wait for the
  7082. * outstanding mailbox command to complete before invoking the mailbox
  7083. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7084. **/
  7085. void
  7086. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7087. {
  7088. struct lpfc_sli *psli = &phba->sli;
  7089. uint8_t actcmd = MBX_HEARTBEAT;
  7090. unsigned long timeout;
  7091. spin_lock_irq(&phba->hbalock);
  7092. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7093. spin_unlock_irq(&phba->hbalock);
  7094. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7095. spin_lock_irq(&phba->hbalock);
  7096. if (phba->sli.mbox_active)
  7097. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7098. spin_unlock_irq(&phba->hbalock);
  7099. /* Determine how long we might wait for the active mailbox
  7100. * command to be gracefully completed by firmware.
  7101. */
  7102. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7103. 1000) + jiffies;
  7104. while (phba->sli.mbox_active) {
  7105. /* Check active mailbox complete status every 2ms */
  7106. msleep(2);
  7107. if (time_after(jiffies, timeout))
  7108. /* Timeout, let the mailbox flush routine to
  7109. * forcefully release active mailbox command
  7110. */
  7111. break;
  7112. }
  7113. }
  7114. lpfc_sli_mbox_sys_flush(phba);
  7115. }
  7116. /**
  7117. * lpfc_sli_eratt_read - read sli-3 error attention events
  7118. * @phba: Pointer to HBA context.
  7119. *
  7120. * This function is called to read the SLI3 device error attention registers
  7121. * for possible error attention events. The caller must hold the hostlock
  7122. * with spin_lock_irq().
  7123. *
  7124. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7125. * Register and returns 0 otherwise.
  7126. **/
  7127. static int
  7128. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7129. {
  7130. uint32_t ha_copy;
  7131. /* Read chip Host Attention (HA) register */
  7132. ha_copy = readl(phba->HAregaddr);
  7133. if (ha_copy & HA_ERATT) {
  7134. /* Read host status register to retrieve error event */
  7135. lpfc_sli_read_hs(phba);
  7136. /* Check if there is a deferred error condition is active */
  7137. if ((HS_FFER1 & phba->work_hs) &&
  7138. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7139. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7140. phba->hba_flag |= DEFER_ERATT;
  7141. /* Clear all interrupt enable conditions */
  7142. writel(0, phba->HCregaddr);
  7143. readl(phba->HCregaddr);
  7144. }
  7145. /* Set the driver HA work bitmap */
  7146. phba->work_ha |= HA_ERATT;
  7147. /* Indicate polling handles this ERATT */
  7148. phba->hba_flag |= HBA_ERATT_HANDLED;
  7149. return 1;
  7150. }
  7151. return 0;
  7152. }
  7153. /**
  7154. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7155. * @phba: Pointer to HBA context.
  7156. *
  7157. * This function is called to read the SLI4 device error attention registers
  7158. * for possible error attention events. The caller must hold the hostlock
  7159. * with spin_lock_irq().
  7160. *
  7161. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7162. * Register and returns 0 otherwise.
  7163. **/
  7164. static int
  7165. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7166. {
  7167. uint32_t uerr_sta_hi, uerr_sta_lo;
  7168. /* For now, use the SLI4 device internal unrecoverable error
  7169. * registers for error attention. This can be changed later.
  7170. */
  7171. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7172. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7173. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7174. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7175. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7176. "1423 HBA Unrecoverable error: "
  7177. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7178. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7179. uerr_sta_lo, uerr_sta_hi,
  7180. phba->sli4_hba.ue_mask_lo,
  7181. phba->sli4_hba.ue_mask_hi);
  7182. phba->work_status[0] = uerr_sta_lo;
  7183. phba->work_status[1] = uerr_sta_hi;
  7184. /* Set the driver HA work bitmap */
  7185. phba->work_ha |= HA_ERATT;
  7186. /* Indicate polling handles this ERATT */
  7187. phba->hba_flag |= HBA_ERATT_HANDLED;
  7188. return 1;
  7189. }
  7190. return 0;
  7191. }
  7192. /**
  7193. * lpfc_sli_check_eratt - check error attention events
  7194. * @phba: Pointer to HBA context.
  7195. *
  7196. * This function is called from timer soft interrupt context to check HBA's
  7197. * error attention register bit for error attention events.
  7198. *
  7199. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7200. * Register and returns 0 otherwise.
  7201. **/
  7202. int
  7203. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7204. {
  7205. uint32_t ha_copy;
  7206. /* If somebody is waiting to handle an eratt, don't process it
  7207. * here. The brdkill function will do this.
  7208. */
  7209. if (phba->link_flag & LS_IGNORE_ERATT)
  7210. return 0;
  7211. /* Check if interrupt handler handles this ERATT */
  7212. spin_lock_irq(&phba->hbalock);
  7213. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7214. /* Interrupt handler has handled ERATT */
  7215. spin_unlock_irq(&phba->hbalock);
  7216. return 0;
  7217. }
  7218. /*
  7219. * If there is deferred error attention, do not check for error
  7220. * attention
  7221. */
  7222. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7223. spin_unlock_irq(&phba->hbalock);
  7224. return 0;
  7225. }
  7226. /* If PCI channel is offline, don't process it */
  7227. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7228. spin_unlock_irq(&phba->hbalock);
  7229. return 0;
  7230. }
  7231. switch (phba->sli_rev) {
  7232. case LPFC_SLI_REV2:
  7233. case LPFC_SLI_REV3:
  7234. /* Read chip Host Attention (HA) register */
  7235. ha_copy = lpfc_sli_eratt_read(phba);
  7236. break;
  7237. case LPFC_SLI_REV4:
  7238. /* Read devcie Uncoverable Error (UERR) registers */
  7239. ha_copy = lpfc_sli4_eratt_read(phba);
  7240. break;
  7241. default:
  7242. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7243. "0299 Invalid SLI revision (%d)\n",
  7244. phba->sli_rev);
  7245. ha_copy = 0;
  7246. break;
  7247. }
  7248. spin_unlock_irq(&phba->hbalock);
  7249. return ha_copy;
  7250. }
  7251. /**
  7252. * lpfc_intr_state_check - Check device state for interrupt handling
  7253. * @phba: Pointer to HBA context.
  7254. *
  7255. * This inline routine checks whether a device or its PCI slot is in a state
  7256. * that the interrupt should be handled.
  7257. *
  7258. * This function returns 0 if the device or the PCI slot is in a state that
  7259. * interrupt should be handled, otherwise -EIO.
  7260. */
  7261. static inline int
  7262. lpfc_intr_state_check(struct lpfc_hba *phba)
  7263. {
  7264. /* If the pci channel is offline, ignore all the interrupts */
  7265. if (unlikely(pci_channel_offline(phba->pcidev)))
  7266. return -EIO;
  7267. /* Update device level interrupt statistics */
  7268. phba->sli.slistat.sli_intr++;
  7269. /* Ignore all interrupts during initialization. */
  7270. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7271. return -EIO;
  7272. return 0;
  7273. }
  7274. /**
  7275. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7276. * @irq: Interrupt number.
  7277. * @dev_id: The device context pointer.
  7278. *
  7279. * This function is directly called from the PCI layer as an interrupt
  7280. * service routine when device with SLI-3 interface spec is enabled with
  7281. * MSI-X multi-message interrupt mode and there are slow-path events in
  7282. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7283. * interrupt mode, this function is called as part of the device-level
  7284. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7285. * is undergoing initialization, the interrupt handler will not process
  7286. * the interrupt. The link attention and ELS ring attention events are
  7287. * handled by the worker thread. The interrupt handler signals the worker
  7288. * thread and returns for these events. This function is called without
  7289. * any lock held. It gets the hbalock to access and update SLI data
  7290. * structures.
  7291. *
  7292. * This function returns IRQ_HANDLED when interrupt is handled else it
  7293. * returns IRQ_NONE.
  7294. **/
  7295. irqreturn_t
  7296. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7297. {
  7298. struct lpfc_hba *phba;
  7299. uint32_t ha_copy, hc_copy;
  7300. uint32_t work_ha_copy;
  7301. unsigned long status;
  7302. unsigned long iflag;
  7303. uint32_t control;
  7304. MAILBOX_t *mbox, *pmbox;
  7305. struct lpfc_vport *vport;
  7306. struct lpfc_nodelist *ndlp;
  7307. struct lpfc_dmabuf *mp;
  7308. LPFC_MBOXQ_t *pmb;
  7309. int rc;
  7310. /*
  7311. * Get the driver's phba structure from the dev_id and
  7312. * assume the HBA is not interrupting.
  7313. */
  7314. phba = (struct lpfc_hba *)dev_id;
  7315. if (unlikely(!phba))
  7316. return IRQ_NONE;
  7317. /*
  7318. * Stuff needs to be attented to when this function is invoked as an
  7319. * individual interrupt handler in MSI-X multi-message interrupt mode
  7320. */
  7321. if (phba->intr_type == MSIX) {
  7322. /* Check device state for handling interrupt */
  7323. if (lpfc_intr_state_check(phba))
  7324. return IRQ_NONE;
  7325. /* Need to read HA REG for slow-path events */
  7326. spin_lock_irqsave(&phba->hbalock, iflag);
  7327. ha_copy = readl(phba->HAregaddr);
  7328. /* If somebody is waiting to handle an eratt don't process it
  7329. * here. The brdkill function will do this.
  7330. */
  7331. if (phba->link_flag & LS_IGNORE_ERATT)
  7332. ha_copy &= ~HA_ERATT;
  7333. /* Check the need for handling ERATT in interrupt handler */
  7334. if (ha_copy & HA_ERATT) {
  7335. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7336. /* ERATT polling has handled ERATT */
  7337. ha_copy &= ~HA_ERATT;
  7338. else
  7339. /* Indicate interrupt handler handles ERATT */
  7340. phba->hba_flag |= HBA_ERATT_HANDLED;
  7341. }
  7342. /*
  7343. * If there is deferred error attention, do not check for any
  7344. * interrupt.
  7345. */
  7346. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7347. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7348. return IRQ_NONE;
  7349. }
  7350. /* Clear up only attention source related to slow-path */
  7351. hc_copy = readl(phba->HCregaddr);
  7352. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7353. HC_LAINT_ENA | HC_ERINT_ENA),
  7354. phba->HCregaddr);
  7355. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7356. phba->HAregaddr);
  7357. writel(hc_copy, phba->HCregaddr);
  7358. readl(phba->HAregaddr); /* flush */
  7359. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7360. } else
  7361. ha_copy = phba->ha_copy;
  7362. work_ha_copy = ha_copy & phba->work_ha_mask;
  7363. if (work_ha_copy) {
  7364. if (work_ha_copy & HA_LATT) {
  7365. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7366. /*
  7367. * Turn off Link Attention interrupts
  7368. * until CLEAR_LA done
  7369. */
  7370. spin_lock_irqsave(&phba->hbalock, iflag);
  7371. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7372. control = readl(phba->HCregaddr);
  7373. control &= ~HC_LAINT_ENA;
  7374. writel(control, phba->HCregaddr);
  7375. readl(phba->HCregaddr); /* flush */
  7376. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7377. }
  7378. else
  7379. work_ha_copy &= ~HA_LATT;
  7380. }
  7381. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7382. /*
  7383. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7384. * the only slow ring.
  7385. */
  7386. status = (work_ha_copy &
  7387. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7388. status >>= (4*LPFC_ELS_RING);
  7389. if (status & HA_RXMASK) {
  7390. spin_lock_irqsave(&phba->hbalock, iflag);
  7391. control = readl(phba->HCregaddr);
  7392. lpfc_debugfs_slow_ring_trc(phba,
  7393. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7394. control, status,
  7395. (uint32_t)phba->sli.slistat.sli_intr);
  7396. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7397. lpfc_debugfs_slow_ring_trc(phba,
  7398. "ISR Disable ring:"
  7399. "pwork:x%x hawork:x%x wait:x%x",
  7400. phba->work_ha, work_ha_copy,
  7401. (uint32_t)((unsigned long)
  7402. &phba->work_waitq));
  7403. control &=
  7404. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7405. writel(control, phba->HCregaddr);
  7406. readl(phba->HCregaddr); /* flush */
  7407. }
  7408. else {
  7409. lpfc_debugfs_slow_ring_trc(phba,
  7410. "ISR slow ring: pwork:"
  7411. "x%x hawork:x%x wait:x%x",
  7412. phba->work_ha, work_ha_copy,
  7413. (uint32_t)((unsigned long)
  7414. &phba->work_waitq));
  7415. }
  7416. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7417. }
  7418. }
  7419. spin_lock_irqsave(&phba->hbalock, iflag);
  7420. if (work_ha_copy & HA_ERATT) {
  7421. lpfc_sli_read_hs(phba);
  7422. /*
  7423. * Check if there is a deferred error condition
  7424. * is active
  7425. */
  7426. if ((HS_FFER1 & phba->work_hs) &&
  7427. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7428. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7429. phba->hba_flag |= DEFER_ERATT;
  7430. /* Clear all interrupt enable conditions */
  7431. writel(0, phba->HCregaddr);
  7432. readl(phba->HCregaddr);
  7433. }
  7434. }
  7435. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7436. pmb = phba->sli.mbox_active;
  7437. pmbox = &pmb->u.mb;
  7438. mbox = phba->mbox;
  7439. vport = pmb->vport;
  7440. /* First check out the status word */
  7441. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7442. if (pmbox->mbxOwner != OWN_HOST) {
  7443. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7444. /*
  7445. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7446. * mbxStatus <status>
  7447. */
  7448. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7449. LOG_SLI,
  7450. "(%d):0304 Stray Mailbox "
  7451. "Interrupt mbxCommand x%x "
  7452. "mbxStatus x%x\n",
  7453. (vport ? vport->vpi : 0),
  7454. pmbox->mbxCommand,
  7455. pmbox->mbxStatus);
  7456. /* clear mailbox attention bit */
  7457. work_ha_copy &= ~HA_MBATT;
  7458. } else {
  7459. phba->sli.mbox_active = NULL;
  7460. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7461. phba->last_completion_time = jiffies;
  7462. del_timer(&phba->sli.mbox_tmo);
  7463. if (pmb->mbox_cmpl) {
  7464. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7465. MAILBOX_CMD_SIZE);
  7466. if (pmb->out_ext_byte_len &&
  7467. pmb->context2)
  7468. lpfc_sli_pcimem_bcopy(
  7469. phba->mbox_ext,
  7470. pmb->context2,
  7471. pmb->out_ext_byte_len);
  7472. }
  7473. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7474. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7475. lpfc_debugfs_disc_trc(vport,
  7476. LPFC_DISC_TRC_MBOX_VPORT,
  7477. "MBOX dflt rpi: : "
  7478. "status:x%x rpi:x%x",
  7479. (uint32_t)pmbox->mbxStatus,
  7480. pmbox->un.varWords[0], 0);
  7481. if (!pmbox->mbxStatus) {
  7482. mp = (struct lpfc_dmabuf *)
  7483. (pmb->context1);
  7484. ndlp = (struct lpfc_nodelist *)
  7485. pmb->context2;
  7486. /* Reg_LOGIN of dflt RPI was
  7487. * successful. new lets get
  7488. * rid of the RPI using the
  7489. * same mbox buffer.
  7490. */
  7491. lpfc_unreg_login(phba,
  7492. vport->vpi,
  7493. pmbox->un.varWords[0],
  7494. pmb);
  7495. pmb->mbox_cmpl =
  7496. lpfc_mbx_cmpl_dflt_rpi;
  7497. pmb->context1 = mp;
  7498. pmb->context2 = ndlp;
  7499. pmb->vport = vport;
  7500. rc = lpfc_sli_issue_mbox(phba,
  7501. pmb,
  7502. MBX_NOWAIT);
  7503. if (rc != MBX_BUSY)
  7504. lpfc_printf_log(phba,
  7505. KERN_ERR,
  7506. LOG_MBOX | LOG_SLI,
  7507. "0350 rc should have"
  7508. "been MBX_BUSY\n");
  7509. if (rc != MBX_NOT_FINISHED)
  7510. goto send_current_mbox;
  7511. }
  7512. }
  7513. spin_lock_irqsave(
  7514. &phba->pport->work_port_lock,
  7515. iflag);
  7516. phba->pport->work_port_events &=
  7517. ~WORKER_MBOX_TMO;
  7518. spin_unlock_irqrestore(
  7519. &phba->pport->work_port_lock,
  7520. iflag);
  7521. lpfc_mbox_cmpl_put(phba, pmb);
  7522. }
  7523. } else
  7524. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7525. if ((work_ha_copy & HA_MBATT) &&
  7526. (phba->sli.mbox_active == NULL)) {
  7527. send_current_mbox:
  7528. /* Process next mailbox command if there is one */
  7529. do {
  7530. rc = lpfc_sli_issue_mbox(phba, NULL,
  7531. MBX_NOWAIT);
  7532. } while (rc == MBX_NOT_FINISHED);
  7533. if (rc != MBX_SUCCESS)
  7534. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7535. LOG_SLI, "0349 rc should be "
  7536. "MBX_SUCCESS\n");
  7537. }
  7538. spin_lock_irqsave(&phba->hbalock, iflag);
  7539. phba->work_ha |= work_ha_copy;
  7540. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7541. lpfc_worker_wake_up(phba);
  7542. }
  7543. return IRQ_HANDLED;
  7544. } /* lpfc_sli_sp_intr_handler */
  7545. /**
  7546. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7547. * @irq: Interrupt number.
  7548. * @dev_id: The device context pointer.
  7549. *
  7550. * This function is directly called from the PCI layer as an interrupt
  7551. * service routine when device with SLI-3 interface spec is enabled with
  7552. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7553. * ring event in the HBA. However, when the device is enabled with either
  7554. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7555. * device-level interrupt handler. When the PCI slot is in error recovery
  7556. * or the HBA is undergoing initialization, the interrupt handler will not
  7557. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7558. * the intrrupt context. This function is called without any lock held.
  7559. * It gets the hbalock to access and update SLI data structures.
  7560. *
  7561. * This function returns IRQ_HANDLED when interrupt is handled else it
  7562. * returns IRQ_NONE.
  7563. **/
  7564. irqreturn_t
  7565. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7566. {
  7567. struct lpfc_hba *phba;
  7568. uint32_t ha_copy;
  7569. unsigned long status;
  7570. unsigned long iflag;
  7571. /* Get the driver's phba structure from the dev_id and
  7572. * assume the HBA is not interrupting.
  7573. */
  7574. phba = (struct lpfc_hba *) dev_id;
  7575. if (unlikely(!phba))
  7576. return IRQ_NONE;
  7577. /*
  7578. * Stuff needs to be attented to when this function is invoked as an
  7579. * individual interrupt handler in MSI-X multi-message interrupt mode
  7580. */
  7581. if (phba->intr_type == MSIX) {
  7582. /* Check device state for handling interrupt */
  7583. if (lpfc_intr_state_check(phba))
  7584. return IRQ_NONE;
  7585. /* Need to read HA REG for FCP ring and other ring events */
  7586. ha_copy = readl(phba->HAregaddr);
  7587. /* Clear up only attention source related to fast-path */
  7588. spin_lock_irqsave(&phba->hbalock, iflag);
  7589. /*
  7590. * If there is deferred error attention, do not check for
  7591. * any interrupt.
  7592. */
  7593. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7594. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7595. return IRQ_NONE;
  7596. }
  7597. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7598. phba->HAregaddr);
  7599. readl(phba->HAregaddr); /* flush */
  7600. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7601. } else
  7602. ha_copy = phba->ha_copy;
  7603. /*
  7604. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7605. */
  7606. ha_copy &= ~(phba->work_ha_mask);
  7607. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7608. status >>= (4*LPFC_FCP_RING);
  7609. if (status & HA_RXMASK)
  7610. lpfc_sli_handle_fast_ring_event(phba,
  7611. &phba->sli.ring[LPFC_FCP_RING],
  7612. status);
  7613. if (phba->cfg_multi_ring_support == 2) {
  7614. /*
  7615. * Process all events on extra ring. Take the optimized path
  7616. * for extra ring IO.
  7617. */
  7618. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7619. status >>= (4*LPFC_EXTRA_RING);
  7620. if (status & HA_RXMASK) {
  7621. lpfc_sli_handle_fast_ring_event(phba,
  7622. &phba->sli.ring[LPFC_EXTRA_RING],
  7623. status);
  7624. }
  7625. }
  7626. return IRQ_HANDLED;
  7627. } /* lpfc_sli_fp_intr_handler */
  7628. /**
  7629. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7630. * @irq: Interrupt number.
  7631. * @dev_id: The device context pointer.
  7632. *
  7633. * This function is the HBA device-level interrupt handler to device with
  7634. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7635. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7636. * requires driver attention. This function invokes the slow-path interrupt
  7637. * attention handling function and fast-path interrupt attention handling
  7638. * function in turn to process the relevant HBA attention events. This
  7639. * function is called without any lock held. It gets the hbalock to access
  7640. * and update SLI data structures.
  7641. *
  7642. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7643. * returns IRQ_NONE.
  7644. **/
  7645. irqreturn_t
  7646. lpfc_sli_intr_handler(int irq, void *dev_id)
  7647. {
  7648. struct lpfc_hba *phba;
  7649. irqreturn_t sp_irq_rc, fp_irq_rc;
  7650. unsigned long status1, status2;
  7651. uint32_t hc_copy;
  7652. /*
  7653. * Get the driver's phba structure from the dev_id and
  7654. * assume the HBA is not interrupting.
  7655. */
  7656. phba = (struct lpfc_hba *) dev_id;
  7657. if (unlikely(!phba))
  7658. return IRQ_NONE;
  7659. /* Check device state for handling interrupt */
  7660. if (lpfc_intr_state_check(phba))
  7661. return IRQ_NONE;
  7662. spin_lock(&phba->hbalock);
  7663. phba->ha_copy = readl(phba->HAregaddr);
  7664. if (unlikely(!phba->ha_copy)) {
  7665. spin_unlock(&phba->hbalock);
  7666. return IRQ_NONE;
  7667. } else if (phba->ha_copy & HA_ERATT) {
  7668. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7669. /* ERATT polling has handled ERATT */
  7670. phba->ha_copy &= ~HA_ERATT;
  7671. else
  7672. /* Indicate interrupt handler handles ERATT */
  7673. phba->hba_flag |= HBA_ERATT_HANDLED;
  7674. }
  7675. /*
  7676. * If there is deferred error attention, do not check for any interrupt.
  7677. */
  7678. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7679. spin_unlock_irq(&phba->hbalock);
  7680. return IRQ_NONE;
  7681. }
  7682. /* Clear attention sources except link and error attentions */
  7683. hc_copy = readl(phba->HCregaddr);
  7684. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7685. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7686. phba->HCregaddr);
  7687. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7688. writel(hc_copy, phba->HCregaddr);
  7689. readl(phba->HAregaddr); /* flush */
  7690. spin_unlock(&phba->hbalock);
  7691. /*
  7692. * Invokes slow-path host attention interrupt handling as appropriate.
  7693. */
  7694. /* status of events with mailbox and link attention */
  7695. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7696. /* status of events with ELS ring */
  7697. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7698. status2 >>= (4*LPFC_ELS_RING);
  7699. if (status1 || (status2 & HA_RXMASK))
  7700. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7701. else
  7702. sp_irq_rc = IRQ_NONE;
  7703. /*
  7704. * Invoke fast-path host attention interrupt handling as appropriate.
  7705. */
  7706. /* status of events with FCP ring */
  7707. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7708. status1 >>= (4*LPFC_FCP_RING);
  7709. /* status of events with extra ring */
  7710. if (phba->cfg_multi_ring_support == 2) {
  7711. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7712. status2 >>= (4*LPFC_EXTRA_RING);
  7713. } else
  7714. status2 = 0;
  7715. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7716. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7717. else
  7718. fp_irq_rc = IRQ_NONE;
  7719. /* Return device-level interrupt handling status */
  7720. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7721. } /* lpfc_sli_intr_handler */
  7722. /**
  7723. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7724. * @phba: pointer to lpfc hba data structure.
  7725. *
  7726. * This routine is invoked by the worker thread to process all the pending
  7727. * SLI4 FCP abort XRI events.
  7728. **/
  7729. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7730. {
  7731. struct lpfc_cq_event *cq_event;
  7732. /* First, declare the fcp xri abort event has been handled */
  7733. spin_lock_irq(&phba->hbalock);
  7734. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7735. spin_unlock_irq(&phba->hbalock);
  7736. /* Now, handle all the fcp xri abort events */
  7737. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7738. /* Get the first event from the head of the event queue */
  7739. spin_lock_irq(&phba->hbalock);
  7740. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7741. cq_event, struct lpfc_cq_event, list);
  7742. spin_unlock_irq(&phba->hbalock);
  7743. /* Notify aborted XRI for FCP work queue */
  7744. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7745. /* Free the event processed back to the free pool */
  7746. lpfc_sli4_cq_event_release(phba, cq_event);
  7747. }
  7748. }
  7749. /**
  7750. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7751. * @phba: pointer to lpfc hba data structure.
  7752. *
  7753. * This routine is invoked by the worker thread to process all the pending
  7754. * SLI4 els abort xri events.
  7755. **/
  7756. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7757. {
  7758. struct lpfc_cq_event *cq_event;
  7759. /* First, declare the els xri abort event has been handled */
  7760. spin_lock_irq(&phba->hbalock);
  7761. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7762. spin_unlock_irq(&phba->hbalock);
  7763. /* Now, handle all the els xri abort events */
  7764. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7765. /* Get the first event from the head of the event queue */
  7766. spin_lock_irq(&phba->hbalock);
  7767. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7768. cq_event, struct lpfc_cq_event, list);
  7769. spin_unlock_irq(&phba->hbalock);
  7770. /* Notify aborted XRI for ELS work queue */
  7771. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7772. /* Free the event processed back to the free pool */
  7773. lpfc_sli4_cq_event_release(phba, cq_event);
  7774. }
  7775. }
  7776. /**
  7777. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7778. * @phba: pointer to lpfc hba data structure
  7779. * @pIocbIn: pointer to the rspiocbq
  7780. * @pIocbOut: pointer to the cmdiocbq
  7781. * @wcqe: pointer to the complete wcqe
  7782. *
  7783. * This routine transfers the fields of a command iocbq to a response iocbq
  7784. * by copying all the IOCB fields from command iocbq and transferring the
  7785. * completion status information from the complete wcqe.
  7786. **/
  7787. static void
  7788. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7789. struct lpfc_iocbq *pIocbIn,
  7790. struct lpfc_iocbq *pIocbOut,
  7791. struct lpfc_wcqe_complete *wcqe)
  7792. {
  7793. unsigned long iflags;
  7794. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7795. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7796. sizeof(struct lpfc_iocbq) - offset);
  7797. /* Map WCQE parameters into irspiocb parameters */
  7798. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7799. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7800. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7801. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7802. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7803. wcqe->total_data_placed;
  7804. else
  7805. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7806. else {
  7807. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7808. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7809. }
  7810. /* Pick up HBA exchange busy condition */
  7811. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7812. spin_lock_irqsave(&phba->hbalock, iflags);
  7813. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7814. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7815. }
  7816. }
  7817. /**
  7818. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7819. * @phba: Pointer to HBA context object.
  7820. * @wcqe: Pointer to work-queue completion queue entry.
  7821. *
  7822. * This routine handles an ELS work-queue completion event and construct
  7823. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7824. * discovery engine to handle.
  7825. *
  7826. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7827. **/
  7828. static struct lpfc_iocbq *
  7829. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7830. struct lpfc_iocbq *irspiocbq)
  7831. {
  7832. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7833. struct lpfc_iocbq *cmdiocbq;
  7834. struct lpfc_wcqe_complete *wcqe;
  7835. unsigned long iflags;
  7836. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7837. spin_lock_irqsave(&phba->hbalock, iflags);
  7838. pring->stats.iocb_event++;
  7839. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7840. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7841. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7842. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7843. if (unlikely(!cmdiocbq)) {
  7844. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7845. "0386 ELS complete with no corresponding "
  7846. "cmdiocb: iotag (%d)\n",
  7847. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7848. lpfc_sli_release_iocbq(phba, irspiocbq);
  7849. return NULL;
  7850. }
  7851. /* Fake the irspiocbq and copy necessary response information */
  7852. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7853. return irspiocbq;
  7854. }
  7855. /**
  7856. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7857. * @phba: Pointer to HBA context object.
  7858. * @cqe: Pointer to mailbox completion queue entry.
  7859. *
  7860. * This routine process a mailbox completion queue entry with asynchrous
  7861. * event.
  7862. *
  7863. * Return: true if work posted to worker thread, otherwise false.
  7864. **/
  7865. static bool
  7866. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7867. {
  7868. struct lpfc_cq_event *cq_event;
  7869. unsigned long iflags;
  7870. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7871. "0392 Async Event: word0:x%x, word1:x%x, "
  7872. "word2:x%x, word3:x%x\n", mcqe->word0,
  7873. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7874. /* Allocate a new internal CQ_EVENT entry */
  7875. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7876. if (!cq_event) {
  7877. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7878. "0394 Failed to allocate CQ_EVENT entry\n");
  7879. return false;
  7880. }
  7881. /* Move the CQE into an asynchronous event entry */
  7882. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7883. spin_lock_irqsave(&phba->hbalock, iflags);
  7884. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7885. /* Set the async event flag */
  7886. phba->hba_flag |= ASYNC_EVENT;
  7887. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7888. return true;
  7889. }
  7890. /**
  7891. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7892. * @phba: Pointer to HBA context object.
  7893. * @cqe: Pointer to mailbox completion queue entry.
  7894. *
  7895. * This routine process a mailbox completion queue entry with mailbox
  7896. * completion event.
  7897. *
  7898. * Return: true if work posted to worker thread, otherwise false.
  7899. **/
  7900. static bool
  7901. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7902. {
  7903. uint32_t mcqe_status;
  7904. MAILBOX_t *mbox, *pmbox;
  7905. struct lpfc_mqe *mqe;
  7906. struct lpfc_vport *vport;
  7907. struct lpfc_nodelist *ndlp;
  7908. struct lpfc_dmabuf *mp;
  7909. unsigned long iflags;
  7910. LPFC_MBOXQ_t *pmb;
  7911. bool workposted = false;
  7912. int rc;
  7913. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7914. if (!bf_get(lpfc_trailer_completed, mcqe))
  7915. goto out_no_mqe_complete;
  7916. /* Get the reference to the active mbox command */
  7917. spin_lock_irqsave(&phba->hbalock, iflags);
  7918. pmb = phba->sli.mbox_active;
  7919. if (unlikely(!pmb)) {
  7920. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7921. "1832 No pending MBOX command to handle\n");
  7922. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7923. goto out_no_mqe_complete;
  7924. }
  7925. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7926. mqe = &pmb->u.mqe;
  7927. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7928. mbox = phba->mbox;
  7929. vport = pmb->vport;
  7930. /* Reset heartbeat timer */
  7931. phba->last_completion_time = jiffies;
  7932. del_timer(&phba->sli.mbox_tmo);
  7933. /* Move mbox data to caller's mailbox region, do endian swapping */
  7934. if (pmb->mbox_cmpl && mbox)
  7935. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7936. /* Set the mailbox status with SLI4 range 0x4000 */
  7937. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7938. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7939. bf_set(lpfc_mqe_status, mqe,
  7940. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7941. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7942. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7943. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7944. "MBOX dflt rpi: status:x%x rpi:x%x",
  7945. mcqe_status,
  7946. pmbox->un.varWords[0], 0);
  7947. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7948. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7949. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7950. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7951. * RID of the PPI using the same mbox buffer.
  7952. */
  7953. lpfc_unreg_login(phba, vport->vpi,
  7954. pmbox->un.varWords[0], pmb);
  7955. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7956. pmb->context1 = mp;
  7957. pmb->context2 = ndlp;
  7958. pmb->vport = vport;
  7959. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7960. if (rc != MBX_BUSY)
  7961. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7962. LOG_SLI, "0385 rc should "
  7963. "have been MBX_BUSY\n");
  7964. if (rc != MBX_NOT_FINISHED)
  7965. goto send_current_mbox;
  7966. }
  7967. }
  7968. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7969. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7970. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7971. /* There is mailbox completion work to do */
  7972. spin_lock_irqsave(&phba->hbalock, iflags);
  7973. __lpfc_mbox_cmpl_put(phba, pmb);
  7974. phba->work_ha |= HA_MBATT;
  7975. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7976. workposted = true;
  7977. send_current_mbox:
  7978. spin_lock_irqsave(&phba->hbalock, iflags);
  7979. /* Release the mailbox command posting token */
  7980. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7981. /* Setting active mailbox pointer need to be in sync to flag clear */
  7982. phba->sli.mbox_active = NULL;
  7983. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7984. /* Wake up worker thread to post the next pending mailbox command */
  7985. lpfc_worker_wake_up(phba);
  7986. out_no_mqe_complete:
  7987. if (bf_get(lpfc_trailer_consumed, mcqe))
  7988. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7989. return workposted;
  7990. }
  7991. /**
  7992. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7993. * @phba: Pointer to HBA context object.
  7994. * @cqe: Pointer to mailbox completion queue entry.
  7995. *
  7996. * This routine process a mailbox completion queue entry, it invokes the
  7997. * proper mailbox complete handling or asynchrous event handling routine
  7998. * according to the MCQE's async bit.
  7999. *
  8000. * Return: true if work posted to worker thread, otherwise false.
  8001. **/
  8002. static bool
  8003. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8004. {
  8005. struct lpfc_mcqe mcqe;
  8006. bool workposted;
  8007. /* Copy the mailbox MCQE and convert endian order as needed */
  8008. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8009. /* Invoke the proper event handling routine */
  8010. if (!bf_get(lpfc_trailer_async, &mcqe))
  8011. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8012. else
  8013. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8014. return workposted;
  8015. }
  8016. /**
  8017. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8018. * @phba: Pointer to HBA context object.
  8019. * @wcqe: Pointer to work-queue completion queue entry.
  8020. *
  8021. * This routine handles an ELS work-queue completion event.
  8022. *
  8023. * Return: true if work posted to worker thread, otherwise false.
  8024. **/
  8025. static bool
  8026. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8027. struct lpfc_wcqe_complete *wcqe)
  8028. {
  8029. struct lpfc_iocbq *irspiocbq;
  8030. unsigned long iflags;
  8031. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8032. /* Get an irspiocbq for later ELS response processing use */
  8033. irspiocbq = lpfc_sli_get_iocbq(phba);
  8034. if (!irspiocbq) {
  8035. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8036. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8037. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8038. pring->txq_cnt, phba->iocb_cnt,
  8039. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8040. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8041. return false;
  8042. }
  8043. /* Save off the slow-path queue event for work thread to process */
  8044. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8045. spin_lock_irqsave(&phba->hbalock, iflags);
  8046. list_add_tail(&irspiocbq->cq_event.list,
  8047. &phba->sli4_hba.sp_queue_event);
  8048. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8049. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8050. return true;
  8051. }
  8052. /**
  8053. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8054. * @phba: Pointer to HBA context object.
  8055. * @wcqe: Pointer to work-queue completion queue entry.
  8056. *
  8057. * This routine handles slow-path WQ entry comsumed event by invoking the
  8058. * proper WQ release routine to the slow-path WQ.
  8059. **/
  8060. static void
  8061. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8062. struct lpfc_wcqe_release *wcqe)
  8063. {
  8064. /* Check for the slow-path ELS work queue */
  8065. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8066. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8067. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8068. else
  8069. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8070. "2579 Slow-path wqe consume event carries "
  8071. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8072. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8073. phba->sli4_hba.els_wq->queue_id);
  8074. }
  8075. /**
  8076. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8077. * @phba: Pointer to HBA context object.
  8078. * @cq: Pointer to a WQ completion queue.
  8079. * @wcqe: Pointer to work-queue completion queue entry.
  8080. *
  8081. * This routine handles an XRI abort event.
  8082. *
  8083. * Return: true if work posted to worker thread, otherwise false.
  8084. **/
  8085. static bool
  8086. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8087. struct lpfc_queue *cq,
  8088. struct sli4_wcqe_xri_aborted *wcqe)
  8089. {
  8090. bool workposted = false;
  8091. struct lpfc_cq_event *cq_event;
  8092. unsigned long iflags;
  8093. /* Allocate a new internal CQ_EVENT entry */
  8094. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8095. if (!cq_event) {
  8096. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8097. "0602 Failed to allocate CQ_EVENT entry\n");
  8098. return false;
  8099. }
  8100. /* Move the CQE into the proper xri abort event list */
  8101. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8102. switch (cq->subtype) {
  8103. case LPFC_FCP:
  8104. spin_lock_irqsave(&phba->hbalock, iflags);
  8105. list_add_tail(&cq_event->list,
  8106. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8107. /* Set the fcp xri abort event flag */
  8108. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8109. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8110. workposted = true;
  8111. break;
  8112. case LPFC_ELS:
  8113. spin_lock_irqsave(&phba->hbalock, iflags);
  8114. list_add_tail(&cq_event->list,
  8115. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8116. /* Set the els xri abort event flag */
  8117. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8118. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8119. workposted = true;
  8120. break;
  8121. default:
  8122. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8123. "0603 Invalid work queue CQE subtype (x%x)\n",
  8124. cq->subtype);
  8125. workposted = false;
  8126. break;
  8127. }
  8128. return workposted;
  8129. }
  8130. /**
  8131. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8132. * @phba: Pointer to HBA context object.
  8133. * @rcqe: Pointer to receive-queue completion queue entry.
  8134. *
  8135. * This routine process a receive-queue completion queue entry.
  8136. *
  8137. * Return: true if work posted to worker thread, otherwise false.
  8138. **/
  8139. static bool
  8140. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8141. {
  8142. bool workposted = false;
  8143. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8144. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8145. struct hbq_dmabuf *dma_buf;
  8146. uint32_t status;
  8147. unsigned long iflags;
  8148. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8149. goto out;
  8150. status = bf_get(lpfc_rcqe_status, rcqe);
  8151. switch (status) {
  8152. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8153. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8154. "2537 Receive Frame Truncated!!\n");
  8155. case FC_STATUS_RQ_SUCCESS:
  8156. lpfc_sli4_rq_release(hrq, drq);
  8157. spin_lock_irqsave(&phba->hbalock, iflags);
  8158. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8159. if (!dma_buf) {
  8160. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8161. goto out;
  8162. }
  8163. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8164. /* save off the frame for the word thread to process */
  8165. list_add_tail(&dma_buf->cq_event.list,
  8166. &phba->sli4_hba.sp_queue_event);
  8167. /* Frame received */
  8168. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8169. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8170. workposted = true;
  8171. break;
  8172. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8173. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8174. /* Post more buffers if possible */
  8175. spin_lock_irqsave(&phba->hbalock, iflags);
  8176. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8177. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8178. workposted = true;
  8179. break;
  8180. }
  8181. out:
  8182. return workposted;
  8183. }
  8184. /**
  8185. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8186. * @phba: Pointer to HBA context object.
  8187. * @cq: Pointer to the completion queue.
  8188. * @wcqe: Pointer to a completion queue entry.
  8189. *
  8190. * This routine process a slow-path work-queue or recieve queue completion queue
  8191. * entry.
  8192. *
  8193. * Return: true if work posted to worker thread, otherwise false.
  8194. **/
  8195. static bool
  8196. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8197. struct lpfc_cqe *cqe)
  8198. {
  8199. struct lpfc_cqe cqevt;
  8200. bool workposted = false;
  8201. /* Copy the work queue CQE and convert endian order if needed */
  8202. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8203. /* Check and process for different type of WCQE and dispatch */
  8204. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8205. case CQE_CODE_COMPL_WQE:
  8206. /* Process the WQ/RQ complete event */
  8207. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8208. (struct lpfc_wcqe_complete *)&cqevt);
  8209. break;
  8210. case CQE_CODE_RELEASE_WQE:
  8211. /* Process the WQ release event */
  8212. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8213. (struct lpfc_wcqe_release *)&cqevt);
  8214. break;
  8215. case CQE_CODE_XRI_ABORTED:
  8216. /* Process the WQ XRI abort event */
  8217. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8218. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8219. break;
  8220. case CQE_CODE_RECEIVE:
  8221. /* Process the RQ event */
  8222. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8223. (struct lpfc_rcqe *)&cqevt);
  8224. break;
  8225. default:
  8226. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8227. "0388 Not a valid WCQE code: x%x\n",
  8228. bf_get(lpfc_cqe_code, &cqevt));
  8229. break;
  8230. }
  8231. return workposted;
  8232. }
  8233. /**
  8234. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8235. * @phba: Pointer to HBA context object.
  8236. * @eqe: Pointer to fast-path event queue entry.
  8237. *
  8238. * This routine process a event queue entry from the slow-path event queue.
  8239. * It will check the MajorCode and MinorCode to determine this is for a
  8240. * completion event on a completion queue, if not, an error shall be logged
  8241. * and just return. Otherwise, it will get to the corresponding completion
  8242. * queue and process all the entries on that completion queue, rearm the
  8243. * completion queue, and then return.
  8244. *
  8245. **/
  8246. static void
  8247. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8248. {
  8249. struct lpfc_queue *cq = NULL, *childq, *speq;
  8250. struct lpfc_cqe *cqe;
  8251. bool workposted = false;
  8252. int ecount = 0;
  8253. uint16_t cqid;
  8254. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8255. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8256. "0359 Not a valid slow-path completion "
  8257. "event: majorcode=x%x, minorcode=x%x\n",
  8258. bf_get_le32(lpfc_eqe_major_code, eqe),
  8259. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8260. return;
  8261. }
  8262. /* Get the reference to the corresponding CQ */
  8263. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8264. /* Search for completion queue pointer matching this cqid */
  8265. speq = phba->sli4_hba.sp_eq;
  8266. list_for_each_entry(childq, &speq->child_list, list) {
  8267. if (childq->queue_id == cqid) {
  8268. cq = childq;
  8269. break;
  8270. }
  8271. }
  8272. if (unlikely(!cq)) {
  8273. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8274. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8275. "0365 Slow-path CQ identifier "
  8276. "(%d) does not exist\n", cqid);
  8277. return;
  8278. }
  8279. /* Process all the entries to the CQ */
  8280. switch (cq->type) {
  8281. case LPFC_MCQ:
  8282. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8283. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8284. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8285. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8286. }
  8287. break;
  8288. case LPFC_WCQ:
  8289. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8290. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8291. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8292. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8293. }
  8294. break;
  8295. default:
  8296. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8297. "0370 Invalid completion queue type (%d)\n",
  8298. cq->type);
  8299. return;
  8300. }
  8301. /* Catch the no cq entry condition, log an error */
  8302. if (unlikely(ecount == 0))
  8303. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8304. "0371 No entry from the CQ: identifier "
  8305. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8306. /* In any case, flash and re-arm the RCQ */
  8307. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8308. /* wake up worker thread if there are works to be done */
  8309. if (workposted)
  8310. lpfc_worker_wake_up(phba);
  8311. }
  8312. /**
  8313. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8314. * @eqe: Pointer to fast-path completion queue entry.
  8315. *
  8316. * This routine process a fast-path work queue completion entry from fast-path
  8317. * event queue for FCP command response completion.
  8318. **/
  8319. static void
  8320. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8321. struct lpfc_wcqe_complete *wcqe)
  8322. {
  8323. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8324. struct lpfc_iocbq *cmdiocbq;
  8325. struct lpfc_iocbq irspiocbq;
  8326. unsigned long iflags;
  8327. spin_lock_irqsave(&phba->hbalock, iflags);
  8328. pring->stats.iocb_event++;
  8329. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8330. /* Check for response status */
  8331. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8332. /* If resource errors reported from HBA, reduce queue
  8333. * depth of the SCSI device.
  8334. */
  8335. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8336. IOSTAT_LOCAL_REJECT) &&
  8337. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8338. phba->lpfc_rampdown_queue_depth(phba);
  8339. }
  8340. /* Log the error status */
  8341. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8342. "0373 FCP complete error: status=x%x, "
  8343. "hw_status=x%x, total_data_specified=%d, "
  8344. "parameter=x%x, word3=x%x\n",
  8345. bf_get(lpfc_wcqe_c_status, wcqe),
  8346. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8347. wcqe->total_data_placed, wcqe->parameter,
  8348. wcqe->word3);
  8349. }
  8350. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8351. spin_lock_irqsave(&phba->hbalock, iflags);
  8352. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8353. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8354. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8355. if (unlikely(!cmdiocbq)) {
  8356. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8357. "0374 FCP complete with no corresponding "
  8358. "cmdiocb: iotag (%d)\n",
  8359. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8360. return;
  8361. }
  8362. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8363. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8364. "0375 FCP cmdiocb not callback function "
  8365. "iotag: (%d)\n",
  8366. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8367. return;
  8368. }
  8369. /* Fake the irspiocb and copy necessary response information */
  8370. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8371. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8372. spin_lock_irqsave(&phba->hbalock, iflags);
  8373. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8374. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8375. }
  8376. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8377. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8378. }
  8379. /**
  8380. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8381. * @phba: Pointer to HBA context object.
  8382. * @cq: Pointer to completion queue.
  8383. * @wcqe: Pointer to work-queue completion queue entry.
  8384. *
  8385. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8386. * proper WQ release routine to the slow-path WQ.
  8387. **/
  8388. static void
  8389. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8390. struct lpfc_wcqe_release *wcqe)
  8391. {
  8392. struct lpfc_queue *childwq;
  8393. bool wqid_matched = false;
  8394. uint16_t fcp_wqid;
  8395. /* Check for fast-path FCP work queue release */
  8396. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8397. list_for_each_entry(childwq, &cq->child_list, list) {
  8398. if (childwq->queue_id == fcp_wqid) {
  8399. lpfc_sli4_wq_release(childwq,
  8400. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8401. wqid_matched = true;
  8402. break;
  8403. }
  8404. }
  8405. /* Report warning log message if no match found */
  8406. if (wqid_matched != true)
  8407. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8408. "2580 Fast-path wqe consume event carries "
  8409. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8410. }
  8411. /**
  8412. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8413. * @cq: Pointer to the completion queue.
  8414. * @eqe: Pointer to fast-path completion queue entry.
  8415. *
  8416. * This routine process a fast-path work queue completion entry from fast-path
  8417. * event queue for FCP command response completion.
  8418. **/
  8419. static int
  8420. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8421. struct lpfc_cqe *cqe)
  8422. {
  8423. struct lpfc_wcqe_release wcqe;
  8424. bool workposted = false;
  8425. unsigned long iflag;
  8426. /* Copy the work queue CQE and convert endian order if needed */
  8427. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8428. /* Check and process for different type of WCQE and dispatch */
  8429. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8430. case CQE_CODE_COMPL_WQE:
  8431. /* Process the WQ complete event */
  8432. spin_lock_irqsave(&phba->hbalock, iflag);
  8433. phba->last_completion_time = jiffies;
  8434. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8435. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8436. (struct lpfc_wcqe_complete *)&wcqe);
  8437. break;
  8438. case CQE_CODE_RELEASE_WQE:
  8439. /* Process the WQ release event */
  8440. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8441. (struct lpfc_wcqe_release *)&wcqe);
  8442. break;
  8443. case CQE_CODE_XRI_ABORTED:
  8444. /* Process the WQ XRI abort event */
  8445. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8446. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8447. break;
  8448. default:
  8449. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8450. "0144 Not a valid WCQE code: x%x\n",
  8451. bf_get(lpfc_wcqe_c_code, &wcqe));
  8452. break;
  8453. }
  8454. return workposted;
  8455. }
  8456. /**
  8457. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8458. * @phba: Pointer to HBA context object.
  8459. * @eqe: Pointer to fast-path event queue entry.
  8460. *
  8461. * This routine process a event queue entry from the fast-path event queue.
  8462. * It will check the MajorCode and MinorCode to determine this is for a
  8463. * completion event on a completion queue, if not, an error shall be logged
  8464. * and just return. Otherwise, it will get to the corresponding completion
  8465. * queue and process all the entries on the completion queue, rearm the
  8466. * completion queue, and then return.
  8467. **/
  8468. static void
  8469. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8470. uint32_t fcp_cqidx)
  8471. {
  8472. struct lpfc_queue *cq;
  8473. struct lpfc_cqe *cqe;
  8474. bool workposted = false;
  8475. uint16_t cqid;
  8476. int ecount = 0;
  8477. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8478. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8479. "0366 Not a valid fast-path completion "
  8480. "event: majorcode=x%x, minorcode=x%x\n",
  8481. bf_get_le32(lpfc_eqe_major_code, eqe),
  8482. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8483. return;
  8484. }
  8485. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8486. if (unlikely(!cq)) {
  8487. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8488. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8489. "0367 Fast-path completion queue "
  8490. "does not exist\n");
  8491. return;
  8492. }
  8493. /* Get the reference to the corresponding CQ */
  8494. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8495. if (unlikely(cqid != cq->queue_id)) {
  8496. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8497. "0368 Miss-matched fast-path completion "
  8498. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8499. cqid, cq->queue_id);
  8500. return;
  8501. }
  8502. /* Process all the entries to the CQ */
  8503. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8504. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8505. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8506. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8507. }
  8508. /* Catch the no cq entry condition */
  8509. if (unlikely(ecount == 0))
  8510. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8511. "0369 No entry from fast-path completion "
  8512. "queue fcpcqid=%d\n", cq->queue_id);
  8513. /* In any case, flash and re-arm the CQ */
  8514. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8515. /* wake up worker thread if there are works to be done */
  8516. if (workposted)
  8517. lpfc_worker_wake_up(phba);
  8518. }
  8519. static void
  8520. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8521. {
  8522. struct lpfc_eqe *eqe;
  8523. /* walk all the EQ entries and drop on the floor */
  8524. while ((eqe = lpfc_sli4_eq_get(eq)))
  8525. ;
  8526. /* Clear and re-arm the EQ */
  8527. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8528. }
  8529. /**
  8530. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8531. * @irq: Interrupt number.
  8532. * @dev_id: The device context pointer.
  8533. *
  8534. * This function is directly called from the PCI layer as an interrupt
  8535. * service routine when device with SLI-4 interface spec is enabled with
  8536. * MSI-X multi-message interrupt mode and there are slow-path events in
  8537. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8538. * interrupt mode, this function is called as part of the device-level
  8539. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8540. * undergoing initialization, the interrupt handler will not process the
  8541. * interrupt. The link attention and ELS ring attention events are handled
  8542. * by the worker thread. The interrupt handler signals the worker thread
  8543. * and returns for these events. This function is called without any lock
  8544. * held. It gets the hbalock to access and update SLI data structures.
  8545. *
  8546. * This function returns IRQ_HANDLED when interrupt is handled else it
  8547. * returns IRQ_NONE.
  8548. **/
  8549. irqreturn_t
  8550. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8551. {
  8552. struct lpfc_hba *phba;
  8553. struct lpfc_queue *speq;
  8554. struct lpfc_eqe *eqe;
  8555. unsigned long iflag;
  8556. int ecount = 0;
  8557. /*
  8558. * Get the driver's phba structure from the dev_id
  8559. */
  8560. phba = (struct lpfc_hba *)dev_id;
  8561. if (unlikely(!phba))
  8562. return IRQ_NONE;
  8563. /* Get to the EQ struct associated with this vector */
  8564. speq = phba->sli4_hba.sp_eq;
  8565. /* Check device state for handling interrupt */
  8566. if (unlikely(lpfc_intr_state_check(phba))) {
  8567. /* Check again for link_state with lock held */
  8568. spin_lock_irqsave(&phba->hbalock, iflag);
  8569. if (phba->link_state < LPFC_LINK_DOWN)
  8570. /* Flush, clear interrupt, and rearm the EQ */
  8571. lpfc_sli4_eq_flush(phba, speq);
  8572. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8573. return IRQ_NONE;
  8574. }
  8575. /*
  8576. * Process all the event on FCP slow-path EQ
  8577. */
  8578. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8579. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8580. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8581. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8582. }
  8583. /* Always clear and re-arm the slow-path EQ */
  8584. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8585. /* Catch the no cq entry condition */
  8586. if (unlikely(ecount == 0)) {
  8587. if (phba->intr_type == MSIX)
  8588. /* MSI-X treated interrupt served as no EQ share INT */
  8589. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8590. "0357 MSI-X interrupt with no EQE\n");
  8591. else
  8592. /* Non MSI-X treated on interrupt as EQ share INT */
  8593. return IRQ_NONE;
  8594. }
  8595. return IRQ_HANDLED;
  8596. } /* lpfc_sli4_sp_intr_handler */
  8597. /**
  8598. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8599. * @irq: Interrupt number.
  8600. * @dev_id: The device context pointer.
  8601. *
  8602. * This function is directly called from the PCI layer as an interrupt
  8603. * service routine when device with SLI-4 interface spec is enabled with
  8604. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8605. * ring event in the HBA. However, when the device is enabled with either
  8606. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8607. * device-level interrupt handler. When the PCI slot is in error recovery
  8608. * or the HBA is undergoing initialization, the interrupt handler will not
  8609. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8610. * the intrrupt context. This function is called without any lock held.
  8611. * It gets the hbalock to access and update SLI data structures. Note that,
  8612. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8613. * equal to that of FCP CQ index.
  8614. *
  8615. * This function returns IRQ_HANDLED when interrupt is handled else it
  8616. * returns IRQ_NONE.
  8617. **/
  8618. irqreturn_t
  8619. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8620. {
  8621. struct lpfc_hba *phba;
  8622. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8623. struct lpfc_queue *fpeq;
  8624. struct lpfc_eqe *eqe;
  8625. unsigned long iflag;
  8626. int ecount = 0;
  8627. uint32_t fcp_eqidx;
  8628. /* Get the driver's phba structure from the dev_id */
  8629. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8630. phba = fcp_eq_hdl->phba;
  8631. fcp_eqidx = fcp_eq_hdl->idx;
  8632. if (unlikely(!phba))
  8633. return IRQ_NONE;
  8634. /* Get to the EQ struct associated with this vector */
  8635. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8636. /* Check device state for handling interrupt */
  8637. if (unlikely(lpfc_intr_state_check(phba))) {
  8638. /* Check again for link_state with lock held */
  8639. spin_lock_irqsave(&phba->hbalock, iflag);
  8640. if (phba->link_state < LPFC_LINK_DOWN)
  8641. /* Flush, clear interrupt, and rearm the EQ */
  8642. lpfc_sli4_eq_flush(phba, fpeq);
  8643. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8644. return IRQ_NONE;
  8645. }
  8646. /*
  8647. * Process all the event on FCP fast-path EQ
  8648. */
  8649. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8650. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8651. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8652. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8653. }
  8654. /* Always clear and re-arm the fast-path EQ */
  8655. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8656. if (unlikely(ecount == 0)) {
  8657. if (phba->intr_type == MSIX)
  8658. /* MSI-X treated interrupt served as no EQ share INT */
  8659. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8660. "0358 MSI-X interrupt with no EQE\n");
  8661. else
  8662. /* Non MSI-X treated on interrupt as EQ share INT */
  8663. return IRQ_NONE;
  8664. }
  8665. return IRQ_HANDLED;
  8666. } /* lpfc_sli4_fp_intr_handler */
  8667. /**
  8668. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8669. * @irq: Interrupt number.
  8670. * @dev_id: The device context pointer.
  8671. *
  8672. * This function is the device-level interrupt handler to device with SLI-4
  8673. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8674. * interrupt mode is enabled and there is an event in the HBA which requires
  8675. * driver attention. This function invokes the slow-path interrupt attention
  8676. * handling function and fast-path interrupt attention handling function in
  8677. * turn to process the relevant HBA attention events. This function is called
  8678. * without any lock held. It gets the hbalock to access and update SLI data
  8679. * structures.
  8680. *
  8681. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8682. * returns IRQ_NONE.
  8683. **/
  8684. irqreturn_t
  8685. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8686. {
  8687. struct lpfc_hba *phba;
  8688. irqreturn_t sp_irq_rc, fp_irq_rc;
  8689. bool fp_handled = false;
  8690. uint32_t fcp_eqidx;
  8691. /* Get the driver's phba structure from the dev_id */
  8692. phba = (struct lpfc_hba *)dev_id;
  8693. if (unlikely(!phba))
  8694. return IRQ_NONE;
  8695. /*
  8696. * Invokes slow-path host attention interrupt handling as appropriate.
  8697. */
  8698. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8699. /*
  8700. * Invoke fast-path host attention interrupt handling as appropriate.
  8701. */
  8702. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8703. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8704. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8705. if (fp_irq_rc == IRQ_HANDLED)
  8706. fp_handled |= true;
  8707. }
  8708. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8709. } /* lpfc_sli4_intr_handler */
  8710. /**
  8711. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8712. * @queue: The queue structure to free.
  8713. *
  8714. * This function frees a queue structure and the DMAable memeory used for
  8715. * the host resident queue. This function must be called after destroying the
  8716. * queue on the HBA.
  8717. **/
  8718. void
  8719. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8720. {
  8721. struct lpfc_dmabuf *dmabuf;
  8722. if (!queue)
  8723. return;
  8724. while (!list_empty(&queue->page_list)) {
  8725. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8726. list);
  8727. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8728. dmabuf->virt, dmabuf->phys);
  8729. kfree(dmabuf);
  8730. }
  8731. kfree(queue);
  8732. return;
  8733. }
  8734. /**
  8735. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8736. * @phba: The HBA that this queue is being created on.
  8737. * @entry_size: The size of each queue entry for this queue.
  8738. * @entry count: The number of entries that this queue will handle.
  8739. *
  8740. * This function allocates a queue structure and the DMAable memory used for
  8741. * the host resident queue. This function must be called before creating the
  8742. * queue on the HBA.
  8743. **/
  8744. struct lpfc_queue *
  8745. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8746. uint32_t entry_count)
  8747. {
  8748. struct lpfc_queue *queue;
  8749. struct lpfc_dmabuf *dmabuf;
  8750. int x, total_qe_count;
  8751. void *dma_pointer;
  8752. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8753. if (!phba->sli4_hba.pc_sli4_params.supported)
  8754. hw_page_size = SLI4_PAGE_SIZE;
  8755. queue = kzalloc(sizeof(struct lpfc_queue) +
  8756. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8757. if (!queue)
  8758. return NULL;
  8759. queue->page_count = (ALIGN(entry_size * entry_count,
  8760. hw_page_size))/hw_page_size;
  8761. INIT_LIST_HEAD(&queue->list);
  8762. INIT_LIST_HEAD(&queue->page_list);
  8763. INIT_LIST_HEAD(&queue->child_list);
  8764. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8765. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8766. if (!dmabuf)
  8767. goto out_fail;
  8768. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8769. hw_page_size, &dmabuf->phys,
  8770. GFP_KERNEL);
  8771. if (!dmabuf->virt) {
  8772. kfree(dmabuf);
  8773. goto out_fail;
  8774. }
  8775. memset(dmabuf->virt, 0, hw_page_size);
  8776. dmabuf->buffer_tag = x;
  8777. list_add_tail(&dmabuf->list, &queue->page_list);
  8778. /* initialize queue's entry array */
  8779. dma_pointer = dmabuf->virt;
  8780. for (; total_qe_count < entry_count &&
  8781. dma_pointer < (hw_page_size + dmabuf->virt);
  8782. total_qe_count++, dma_pointer += entry_size) {
  8783. queue->qe[total_qe_count].address = dma_pointer;
  8784. }
  8785. }
  8786. queue->entry_size = entry_size;
  8787. queue->entry_count = entry_count;
  8788. queue->phba = phba;
  8789. return queue;
  8790. out_fail:
  8791. lpfc_sli4_queue_free(queue);
  8792. return NULL;
  8793. }
  8794. /**
  8795. * lpfc_eq_create - Create an Event Queue on the HBA
  8796. * @phba: HBA structure that indicates port to create a queue on.
  8797. * @eq: The queue structure to use to create the event queue.
  8798. * @imax: The maximum interrupt per second limit.
  8799. *
  8800. * This function creates an event queue, as detailed in @eq, on a port,
  8801. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8802. *
  8803. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8804. * is used to get the entry count and entry size that are necessary to
  8805. * determine the number of pages to allocate and use for this queue. This
  8806. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8807. * event queue. This function is asynchronous and will wait for the mailbox
  8808. * command to finish before continuing.
  8809. *
  8810. * On success this function will return a zero. If unable to allocate enough
  8811. * memory this function will return ENOMEM. If the queue create mailbox command
  8812. * fails this function will return ENXIO.
  8813. **/
  8814. uint32_t
  8815. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8816. {
  8817. struct lpfc_mbx_eq_create *eq_create;
  8818. LPFC_MBOXQ_t *mbox;
  8819. int rc, length, status = 0;
  8820. struct lpfc_dmabuf *dmabuf;
  8821. uint32_t shdr_status, shdr_add_status;
  8822. union lpfc_sli4_cfg_shdr *shdr;
  8823. uint16_t dmult;
  8824. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8825. if (!phba->sli4_hba.pc_sli4_params.supported)
  8826. hw_page_size = SLI4_PAGE_SIZE;
  8827. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8828. if (!mbox)
  8829. return -ENOMEM;
  8830. length = (sizeof(struct lpfc_mbx_eq_create) -
  8831. sizeof(struct lpfc_sli4_cfg_mhdr));
  8832. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8833. LPFC_MBOX_OPCODE_EQ_CREATE,
  8834. length, LPFC_SLI4_MBX_EMBED);
  8835. eq_create = &mbox->u.mqe.un.eq_create;
  8836. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8837. eq->page_count);
  8838. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8839. LPFC_EQE_SIZE);
  8840. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8841. /* Calculate delay multiper from maximum interrupt per second */
  8842. dmult = LPFC_DMULT_CONST/imax - 1;
  8843. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8844. dmult);
  8845. switch (eq->entry_count) {
  8846. default:
  8847. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8848. "0360 Unsupported EQ count. (%d)\n",
  8849. eq->entry_count);
  8850. if (eq->entry_count < 256)
  8851. return -EINVAL;
  8852. /* otherwise default to smallest count (drop through) */
  8853. case 256:
  8854. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8855. LPFC_EQ_CNT_256);
  8856. break;
  8857. case 512:
  8858. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8859. LPFC_EQ_CNT_512);
  8860. break;
  8861. case 1024:
  8862. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8863. LPFC_EQ_CNT_1024);
  8864. break;
  8865. case 2048:
  8866. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8867. LPFC_EQ_CNT_2048);
  8868. break;
  8869. case 4096:
  8870. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8871. LPFC_EQ_CNT_4096);
  8872. break;
  8873. }
  8874. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8875. memset(dmabuf->virt, 0, hw_page_size);
  8876. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8877. putPaddrLow(dmabuf->phys);
  8878. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8879. putPaddrHigh(dmabuf->phys);
  8880. }
  8881. mbox->vport = phba->pport;
  8882. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8883. mbox->context1 = NULL;
  8884. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8885. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8886. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8887. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8888. if (shdr_status || shdr_add_status || rc) {
  8889. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8890. "2500 EQ_CREATE mailbox failed with "
  8891. "status x%x add_status x%x, mbx status x%x\n",
  8892. shdr_status, shdr_add_status, rc);
  8893. status = -ENXIO;
  8894. }
  8895. eq->type = LPFC_EQ;
  8896. eq->subtype = LPFC_NONE;
  8897. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8898. if (eq->queue_id == 0xFFFF)
  8899. status = -ENXIO;
  8900. eq->host_index = 0;
  8901. eq->hba_index = 0;
  8902. mempool_free(mbox, phba->mbox_mem_pool);
  8903. return status;
  8904. }
  8905. /**
  8906. * lpfc_cq_create - Create a Completion Queue on the HBA
  8907. * @phba: HBA structure that indicates port to create a queue on.
  8908. * @cq: The queue structure to use to create the completion queue.
  8909. * @eq: The event queue to bind this completion queue to.
  8910. *
  8911. * This function creates a completion queue, as detailed in @wq, on a port,
  8912. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8913. *
  8914. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8915. * is used to get the entry count and entry size that are necessary to
  8916. * determine the number of pages to allocate and use for this queue. The @eq
  8917. * is used to indicate which event queue to bind this completion queue to. This
  8918. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8919. * completion queue. This function is asynchronous and will wait for the mailbox
  8920. * command to finish before continuing.
  8921. *
  8922. * On success this function will return a zero. If unable to allocate enough
  8923. * memory this function will return ENOMEM. If the queue create mailbox command
  8924. * fails this function will return ENXIO.
  8925. **/
  8926. uint32_t
  8927. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8928. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8929. {
  8930. struct lpfc_mbx_cq_create *cq_create;
  8931. struct lpfc_dmabuf *dmabuf;
  8932. LPFC_MBOXQ_t *mbox;
  8933. int rc, length, status = 0;
  8934. uint32_t shdr_status, shdr_add_status;
  8935. union lpfc_sli4_cfg_shdr *shdr;
  8936. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8937. if (!phba->sli4_hba.pc_sli4_params.supported)
  8938. hw_page_size = SLI4_PAGE_SIZE;
  8939. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8940. if (!mbox)
  8941. return -ENOMEM;
  8942. length = (sizeof(struct lpfc_mbx_cq_create) -
  8943. sizeof(struct lpfc_sli4_cfg_mhdr));
  8944. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8945. LPFC_MBOX_OPCODE_CQ_CREATE,
  8946. length, LPFC_SLI4_MBX_EMBED);
  8947. cq_create = &mbox->u.mqe.un.cq_create;
  8948. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8949. cq->page_count);
  8950. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8951. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8952. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8953. switch (cq->entry_count) {
  8954. default:
  8955. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8956. "0361 Unsupported CQ count. (%d)\n",
  8957. cq->entry_count);
  8958. if (cq->entry_count < 256)
  8959. return -EINVAL;
  8960. /* otherwise default to smallest count (drop through) */
  8961. case 256:
  8962. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8963. LPFC_CQ_CNT_256);
  8964. break;
  8965. case 512:
  8966. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8967. LPFC_CQ_CNT_512);
  8968. break;
  8969. case 1024:
  8970. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8971. LPFC_CQ_CNT_1024);
  8972. break;
  8973. }
  8974. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8975. memset(dmabuf->virt, 0, hw_page_size);
  8976. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8977. putPaddrLow(dmabuf->phys);
  8978. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8979. putPaddrHigh(dmabuf->phys);
  8980. }
  8981. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8982. /* The IOCTL status is embedded in the mailbox subheader. */
  8983. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8984. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8985. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8986. if (shdr_status || shdr_add_status || rc) {
  8987. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8988. "2501 CQ_CREATE mailbox failed with "
  8989. "status x%x add_status x%x, mbx status x%x\n",
  8990. shdr_status, shdr_add_status, rc);
  8991. status = -ENXIO;
  8992. goto out;
  8993. }
  8994. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8995. if (cq->queue_id == 0xFFFF) {
  8996. status = -ENXIO;
  8997. goto out;
  8998. }
  8999. /* link the cq onto the parent eq child list */
  9000. list_add_tail(&cq->list, &eq->child_list);
  9001. /* Set up completion queue's type and subtype */
  9002. cq->type = type;
  9003. cq->subtype = subtype;
  9004. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9005. cq->host_index = 0;
  9006. cq->hba_index = 0;
  9007. out:
  9008. mempool_free(mbox, phba->mbox_mem_pool);
  9009. return status;
  9010. }
  9011. /**
  9012. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9013. * @phba: HBA structure that indicates port to create a queue on.
  9014. * @mq: The queue structure to use to create the mailbox queue.
  9015. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9016. * @cq: The completion queue to associate with this cq.
  9017. *
  9018. * This function provides failback (fb) functionality when the
  9019. * mq_create_ext fails on older FW generations. It's purpose is identical
  9020. * to mq_create_ext otherwise.
  9021. *
  9022. * This routine cannot fail as all attributes were previously accessed and
  9023. * initialized in mq_create_ext.
  9024. **/
  9025. static void
  9026. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9027. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9028. {
  9029. struct lpfc_mbx_mq_create *mq_create;
  9030. struct lpfc_dmabuf *dmabuf;
  9031. int length;
  9032. length = (sizeof(struct lpfc_mbx_mq_create) -
  9033. sizeof(struct lpfc_sli4_cfg_mhdr));
  9034. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9035. LPFC_MBOX_OPCODE_MQ_CREATE,
  9036. length, LPFC_SLI4_MBX_EMBED);
  9037. mq_create = &mbox->u.mqe.un.mq_create;
  9038. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9039. mq->page_count);
  9040. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9041. cq->queue_id);
  9042. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9043. switch (mq->entry_count) {
  9044. case 16:
  9045. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9046. LPFC_MQ_CNT_16);
  9047. break;
  9048. case 32:
  9049. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9050. LPFC_MQ_CNT_32);
  9051. break;
  9052. case 64:
  9053. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9054. LPFC_MQ_CNT_64);
  9055. break;
  9056. case 128:
  9057. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9058. LPFC_MQ_CNT_128);
  9059. break;
  9060. }
  9061. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9062. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9063. putPaddrLow(dmabuf->phys);
  9064. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9065. putPaddrHigh(dmabuf->phys);
  9066. }
  9067. }
  9068. /**
  9069. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9070. * @phba: HBA structure that indicates port to create a queue on.
  9071. * @mq: The queue structure to use to create the mailbox queue.
  9072. * @cq: The completion queue to associate with this cq.
  9073. * @subtype: The queue's subtype.
  9074. *
  9075. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9076. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9077. *
  9078. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9079. * is used to get the entry count and entry size that are necessary to
  9080. * determine the number of pages to allocate and use for this queue. This
  9081. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9082. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9083. * command to finish before continuing.
  9084. *
  9085. * On success this function will return a zero. If unable to allocate enough
  9086. * memory this function will return ENOMEM. If the queue create mailbox command
  9087. * fails this function will return ENXIO.
  9088. **/
  9089. int32_t
  9090. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9091. struct lpfc_queue *cq, uint32_t subtype)
  9092. {
  9093. struct lpfc_mbx_mq_create *mq_create;
  9094. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9095. struct lpfc_dmabuf *dmabuf;
  9096. LPFC_MBOXQ_t *mbox;
  9097. int rc, length, status = 0;
  9098. uint32_t shdr_status, shdr_add_status;
  9099. union lpfc_sli4_cfg_shdr *shdr;
  9100. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9101. if (!phba->sli4_hba.pc_sli4_params.supported)
  9102. hw_page_size = SLI4_PAGE_SIZE;
  9103. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9104. if (!mbox)
  9105. return -ENOMEM;
  9106. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9107. sizeof(struct lpfc_sli4_cfg_mhdr));
  9108. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9109. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9110. length, LPFC_SLI4_MBX_EMBED);
  9111. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9112. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9113. mq->page_count);
  9114. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9115. 1);
  9116. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9117. &mq_create_ext->u.request, 1);
  9118. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9119. &mq_create_ext->u.request, 1);
  9120. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9121. cq->queue_id);
  9122. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9123. switch (mq->entry_count) {
  9124. default:
  9125. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9126. "0362 Unsupported MQ count. (%d)\n",
  9127. mq->entry_count);
  9128. if (mq->entry_count < 16)
  9129. return -EINVAL;
  9130. /* otherwise default to smallest count (drop through) */
  9131. case 16:
  9132. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9133. LPFC_MQ_CNT_16);
  9134. break;
  9135. case 32:
  9136. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9137. LPFC_MQ_CNT_32);
  9138. break;
  9139. case 64:
  9140. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9141. LPFC_MQ_CNT_64);
  9142. break;
  9143. case 128:
  9144. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9145. LPFC_MQ_CNT_128);
  9146. break;
  9147. }
  9148. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9149. memset(dmabuf->virt, 0, hw_page_size);
  9150. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9151. putPaddrLow(dmabuf->phys);
  9152. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9153. putPaddrHigh(dmabuf->phys);
  9154. }
  9155. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9156. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9157. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9158. &mq_create_ext->u.response);
  9159. if (rc != MBX_SUCCESS) {
  9160. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9161. "2795 MQ_CREATE_EXT failed with "
  9162. "status x%x. Failback to MQ_CREATE.\n",
  9163. rc);
  9164. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9165. mq_create = &mbox->u.mqe.un.mq_create;
  9166. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9167. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9168. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9169. &mq_create->u.response);
  9170. }
  9171. /* The IOCTL status is embedded in the mailbox subheader. */
  9172. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9173. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9174. if (shdr_status || shdr_add_status || rc) {
  9175. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9176. "2502 MQ_CREATE mailbox failed with "
  9177. "status x%x add_status x%x, mbx status x%x\n",
  9178. shdr_status, shdr_add_status, rc);
  9179. status = -ENXIO;
  9180. goto out;
  9181. }
  9182. if (mq->queue_id == 0xFFFF) {
  9183. status = -ENXIO;
  9184. goto out;
  9185. }
  9186. mq->type = LPFC_MQ;
  9187. mq->subtype = subtype;
  9188. mq->host_index = 0;
  9189. mq->hba_index = 0;
  9190. /* link the mq onto the parent cq child list */
  9191. list_add_tail(&mq->list, &cq->child_list);
  9192. out:
  9193. mempool_free(mbox, phba->mbox_mem_pool);
  9194. return status;
  9195. }
  9196. /**
  9197. * lpfc_wq_create - Create a Work Queue on the HBA
  9198. * @phba: HBA structure that indicates port to create a queue on.
  9199. * @wq: The queue structure to use to create the work queue.
  9200. * @cq: The completion queue to bind this work queue to.
  9201. * @subtype: The subtype of the work queue indicating its functionality.
  9202. *
  9203. * This function creates a work queue, as detailed in @wq, on a port, described
  9204. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9205. *
  9206. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9207. * is used to get the entry count and entry size that are necessary to
  9208. * determine the number of pages to allocate and use for this queue. The @cq
  9209. * is used to indicate which completion queue to bind this work queue to. This
  9210. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9211. * work queue. This function is asynchronous and will wait for the mailbox
  9212. * command to finish before continuing.
  9213. *
  9214. * On success this function will return a zero. If unable to allocate enough
  9215. * memory this function will return ENOMEM. If the queue create mailbox command
  9216. * fails this function will return ENXIO.
  9217. **/
  9218. uint32_t
  9219. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9220. struct lpfc_queue *cq, uint32_t subtype)
  9221. {
  9222. struct lpfc_mbx_wq_create *wq_create;
  9223. struct lpfc_dmabuf *dmabuf;
  9224. LPFC_MBOXQ_t *mbox;
  9225. int rc, length, status = 0;
  9226. uint32_t shdr_status, shdr_add_status;
  9227. union lpfc_sli4_cfg_shdr *shdr;
  9228. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9229. if (!phba->sli4_hba.pc_sli4_params.supported)
  9230. hw_page_size = SLI4_PAGE_SIZE;
  9231. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9232. if (!mbox)
  9233. return -ENOMEM;
  9234. length = (sizeof(struct lpfc_mbx_wq_create) -
  9235. sizeof(struct lpfc_sli4_cfg_mhdr));
  9236. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9237. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9238. length, LPFC_SLI4_MBX_EMBED);
  9239. wq_create = &mbox->u.mqe.un.wq_create;
  9240. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9241. wq->page_count);
  9242. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9243. cq->queue_id);
  9244. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9245. memset(dmabuf->virt, 0, hw_page_size);
  9246. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9247. putPaddrLow(dmabuf->phys);
  9248. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9249. putPaddrHigh(dmabuf->phys);
  9250. }
  9251. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9252. /* The IOCTL status is embedded in the mailbox subheader. */
  9253. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9254. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9255. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9256. if (shdr_status || shdr_add_status || rc) {
  9257. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9258. "2503 WQ_CREATE mailbox failed with "
  9259. "status x%x add_status x%x, mbx status x%x\n",
  9260. shdr_status, shdr_add_status, rc);
  9261. status = -ENXIO;
  9262. goto out;
  9263. }
  9264. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9265. if (wq->queue_id == 0xFFFF) {
  9266. status = -ENXIO;
  9267. goto out;
  9268. }
  9269. wq->type = LPFC_WQ;
  9270. wq->subtype = subtype;
  9271. wq->host_index = 0;
  9272. wq->hba_index = 0;
  9273. /* link the wq onto the parent cq child list */
  9274. list_add_tail(&wq->list, &cq->child_list);
  9275. out:
  9276. mempool_free(mbox, phba->mbox_mem_pool);
  9277. return status;
  9278. }
  9279. /**
  9280. * lpfc_rq_create - Create a Receive Queue on the HBA
  9281. * @phba: HBA structure that indicates port to create a queue on.
  9282. * @hrq: The queue structure to use to create the header receive queue.
  9283. * @drq: The queue structure to use to create the data receive queue.
  9284. * @cq: The completion queue to bind this work queue to.
  9285. *
  9286. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9287. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9288. * to the HBA.
  9289. *
  9290. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9291. * struct is used to get the entry count that is necessary to determine the
  9292. * number of pages to use for this queue. The @cq is used to indicate which
  9293. * completion queue to bind received buffers that are posted to these queues to.
  9294. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9295. * receive queue pair. This function is asynchronous and will wait for the
  9296. * mailbox command to finish before continuing.
  9297. *
  9298. * On success this function will return a zero. If unable to allocate enough
  9299. * memory this function will return ENOMEM. If the queue create mailbox command
  9300. * fails this function will return ENXIO.
  9301. **/
  9302. uint32_t
  9303. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9304. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9305. {
  9306. struct lpfc_mbx_rq_create *rq_create;
  9307. struct lpfc_dmabuf *dmabuf;
  9308. LPFC_MBOXQ_t *mbox;
  9309. int rc, length, status = 0;
  9310. uint32_t shdr_status, shdr_add_status;
  9311. union lpfc_sli4_cfg_shdr *shdr;
  9312. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9313. if (!phba->sli4_hba.pc_sli4_params.supported)
  9314. hw_page_size = SLI4_PAGE_SIZE;
  9315. if (hrq->entry_count != drq->entry_count)
  9316. return -EINVAL;
  9317. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9318. if (!mbox)
  9319. return -ENOMEM;
  9320. length = (sizeof(struct lpfc_mbx_rq_create) -
  9321. sizeof(struct lpfc_sli4_cfg_mhdr));
  9322. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9323. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9324. length, LPFC_SLI4_MBX_EMBED);
  9325. rq_create = &mbox->u.mqe.un.rq_create;
  9326. switch (hrq->entry_count) {
  9327. default:
  9328. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9329. "2535 Unsupported RQ count. (%d)\n",
  9330. hrq->entry_count);
  9331. if (hrq->entry_count < 512)
  9332. return -EINVAL;
  9333. /* otherwise default to smallest count (drop through) */
  9334. case 512:
  9335. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9336. LPFC_RQ_RING_SIZE_512);
  9337. break;
  9338. case 1024:
  9339. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9340. LPFC_RQ_RING_SIZE_1024);
  9341. break;
  9342. case 2048:
  9343. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9344. LPFC_RQ_RING_SIZE_2048);
  9345. break;
  9346. case 4096:
  9347. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9348. LPFC_RQ_RING_SIZE_4096);
  9349. break;
  9350. }
  9351. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9352. cq->queue_id);
  9353. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9354. hrq->page_count);
  9355. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9356. LPFC_HDR_BUF_SIZE);
  9357. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9358. memset(dmabuf->virt, 0, hw_page_size);
  9359. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9360. putPaddrLow(dmabuf->phys);
  9361. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9362. putPaddrHigh(dmabuf->phys);
  9363. }
  9364. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9365. /* The IOCTL status is embedded in the mailbox subheader. */
  9366. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9367. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9368. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9369. if (shdr_status || shdr_add_status || rc) {
  9370. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9371. "2504 RQ_CREATE mailbox failed with "
  9372. "status x%x add_status x%x, mbx status x%x\n",
  9373. shdr_status, shdr_add_status, rc);
  9374. status = -ENXIO;
  9375. goto out;
  9376. }
  9377. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9378. if (hrq->queue_id == 0xFFFF) {
  9379. status = -ENXIO;
  9380. goto out;
  9381. }
  9382. hrq->type = LPFC_HRQ;
  9383. hrq->subtype = subtype;
  9384. hrq->host_index = 0;
  9385. hrq->hba_index = 0;
  9386. /* now create the data queue */
  9387. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9388. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9389. length, LPFC_SLI4_MBX_EMBED);
  9390. switch (drq->entry_count) {
  9391. default:
  9392. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9393. "2536 Unsupported RQ count. (%d)\n",
  9394. drq->entry_count);
  9395. if (drq->entry_count < 512)
  9396. return -EINVAL;
  9397. /* otherwise default to smallest count (drop through) */
  9398. case 512:
  9399. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9400. LPFC_RQ_RING_SIZE_512);
  9401. break;
  9402. case 1024:
  9403. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9404. LPFC_RQ_RING_SIZE_1024);
  9405. break;
  9406. case 2048:
  9407. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9408. LPFC_RQ_RING_SIZE_2048);
  9409. break;
  9410. case 4096:
  9411. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9412. LPFC_RQ_RING_SIZE_4096);
  9413. break;
  9414. }
  9415. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9416. cq->queue_id);
  9417. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9418. drq->page_count);
  9419. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9420. LPFC_DATA_BUF_SIZE);
  9421. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9422. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9423. putPaddrLow(dmabuf->phys);
  9424. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9425. putPaddrHigh(dmabuf->phys);
  9426. }
  9427. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9428. /* The IOCTL status is embedded in the mailbox subheader. */
  9429. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9430. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9431. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9432. if (shdr_status || shdr_add_status || rc) {
  9433. status = -ENXIO;
  9434. goto out;
  9435. }
  9436. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9437. if (drq->queue_id == 0xFFFF) {
  9438. status = -ENXIO;
  9439. goto out;
  9440. }
  9441. drq->type = LPFC_DRQ;
  9442. drq->subtype = subtype;
  9443. drq->host_index = 0;
  9444. drq->hba_index = 0;
  9445. /* link the header and data RQs onto the parent cq child list */
  9446. list_add_tail(&hrq->list, &cq->child_list);
  9447. list_add_tail(&drq->list, &cq->child_list);
  9448. out:
  9449. mempool_free(mbox, phba->mbox_mem_pool);
  9450. return status;
  9451. }
  9452. /**
  9453. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9454. * @eq: The queue structure associated with the queue to destroy.
  9455. *
  9456. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9457. * command, specific to the type of queue, to the HBA.
  9458. *
  9459. * The @eq struct is used to get the queue ID of the queue to destroy.
  9460. *
  9461. * On success this function will return a zero. If the queue destroy mailbox
  9462. * command fails this function will return ENXIO.
  9463. **/
  9464. uint32_t
  9465. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9466. {
  9467. LPFC_MBOXQ_t *mbox;
  9468. int rc, length, status = 0;
  9469. uint32_t shdr_status, shdr_add_status;
  9470. union lpfc_sli4_cfg_shdr *shdr;
  9471. if (!eq)
  9472. return -ENODEV;
  9473. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9474. if (!mbox)
  9475. return -ENOMEM;
  9476. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9477. sizeof(struct lpfc_sli4_cfg_mhdr));
  9478. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9479. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9480. length, LPFC_SLI4_MBX_EMBED);
  9481. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9482. eq->queue_id);
  9483. mbox->vport = eq->phba->pport;
  9484. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9485. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9486. /* The IOCTL status is embedded in the mailbox subheader. */
  9487. shdr = (union lpfc_sli4_cfg_shdr *)
  9488. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9489. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9490. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9491. if (shdr_status || shdr_add_status || rc) {
  9492. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9493. "2505 EQ_DESTROY mailbox failed with "
  9494. "status x%x add_status x%x, mbx status x%x\n",
  9495. shdr_status, shdr_add_status, rc);
  9496. status = -ENXIO;
  9497. }
  9498. /* Remove eq from any list */
  9499. list_del_init(&eq->list);
  9500. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9501. return status;
  9502. }
  9503. /**
  9504. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9505. * @cq: The queue structure associated with the queue to destroy.
  9506. *
  9507. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9508. * command, specific to the type of queue, to the HBA.
  9509. *
  9510. * The @cq struct is used to get the queue ID of the queue to destroy.
  9511. *
  9512. * On success this function will return a zero. If the queue destroy mailbox
  9513. * command fails this function will return ENXIO.
  9514. **/
  9515. uint32_t
  9516. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9517. {
  9518. LPFC_MBOXQ_t *mbox;
  9519. int rc, length, status = 0;
  9520. uint32_t shdr_status, shdr_add_status;
  9521. union lpfc_sli4_cfg_shdr *shdr;
  9522. if (!cq)
  9523. return -ENODEV;
  9524. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9525. if (!mbox)
  9526. return -ENOMEM;
  9527. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9528. sizeof(struct lpfc_sli4_cfg_mhdr));
  9529. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9530. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9531. length, LPFC_SLI4_MBX_EMBED);
  9532. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9533. cq->queue_id);
  9534. mbox->vport = cq->phba->pport;
  9535. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9536. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9537. /* The IOCTL status is embedded in the mailbox subheader. */
  9538. shdr = (union lpfc_sli4_cfg_shdr *)
  9539. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9540. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9541. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9542. if (shdr_status || shdr_add_status || rc) {
  9543. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9544. "2506 CQ_DESTROY mailbox failed with "
  9545. "status x%x add_status x%x, mbx status x%x\n",
  9546. shdr_status, shdr_add_status, rc);
  9547. status = -ENXIO;
  9548. }
  9549. /* Remove cq from any list */
  9550. list_del_init(&cq->list);
  9551. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9552. return status;
  9553. }
  9554. /**
  9555. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9556. * @qm: The queue structure associated with the queue to destroy.
  9557. *
  9558. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9559. * command, specific to the type of queue, to the HBA.
  9560. *
  9561. * The @mq struct is used to get the queue ID of the queue to destroy.
  9562. *
  9563. * On success this function will return a zero. If the queue destroy mailbox
  9564. * command fails this function will return ENXIO.
  9565. **/
  9566. uint32_t
  9567. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9568. {
  9569. LPFC_MBOXQ_t *mbox;
  9570. int rc, length, status = 0;
  9571. uint32_t shdr_status, shdr_add_status;
  9572. union lpfc_sli4_cfg_shdr *shdr;
  9573. if (!mq)
  9574. return -ENODEV;
  9575. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9576. if (!mbox)
  9577. return -ENOMEM;
  9578. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9579. sizeof(struct lpfc_sli4_cfg_mhdr));
  9580. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9581. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9582. length, LPFC_SLI4_MBX_EMBED);
  9583. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9584. mq->queue_id);
  9585. mbox->vport = mq->phba->pport;
  9586. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9587. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9588. /* The IOCTL status is embedded in the mailbox subheader. */
  9589. shdr = (union lpfc_sli4_cfg_shdr *)
  9590. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9591. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9592. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9593. if (shdr_status || shdr_add_status || rc) {
  9594. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9595. "2507 MQ_DESTROY mailbox failed with "
  9596. "status x%x add_status x%x, mbx status x%x\n",
  9597. shdr_status, shdr_add_status, rc);
  9598. status = -ENXIO;
  9599. }
  9600. /* Remove mq from any list */
  9601. list_del_init(&mq->list);
  9602. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9603. return status;
  9604. }
  9605. /**
  9606. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9607. * @wq: The queue structure associated with the queue to destroy.
  9608. *
  9609. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9610. * command, specific to the type of queue, to the HBA.
  9611. *
  9612. * The @wq struct is used to get the queue ID of the queue to destroy.
  9613. *
  9614. * On success this function will return a zero. If the queue destroy mailbox
  9615. * command fails this function will return ENXIO.
  9616. **/
  9617. uint32_t
  9618. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9619. {
  9620. LPFC_MBOXQ_t *mbox;
  9621. int rc, length, status = 0;
  9622. uint32_t shdr_status, shdr_add_status;
  9623. union lpfc_sli4_cfg_shdr *shdr;
  9624. if (!wq)
  9625. return -ENODEV;
  9626. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9627. if (!mbox)
  9628. return -ENOMEM;
  9629. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9630. sizeof(struct lpfc_sli4_cfg_mhdr));
  9631. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9632. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9633. length, LPFC_SLI4_MBX_EMBED);
  9634. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9635. wq->queue_id);
  9636. mbox->vport = wq->phba->pport;
  9637. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9638. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9639. shdr = (union lpfc_sli4_cfg_shdr *)
  9640. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9641. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9642. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9643. if (shdr_status || shdr_add_status || rc) {
  9644. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9645. "2508 WQ_DESTROY mailbox failed with "
  9646. "status x%x add_status x%x, mbx status x%x\n",
  9647. shdr_status, shdr_add_status, rc);
  9648. status = -ENXIO;
  9649. }
  9650. /* Remove wq from any list */
  9651. list_del_init(&wq->list);
  9652. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9653. return status;
  9654. }
  9655. /**
  9656. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9657. * @rq: The queue structure associated with the queue to destroy.
  9658. *
  9659. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9660. * command, specific to the type of queue, to the HBA.
  9661. *
  9662. * The @rq struct is used to get the queue ID of the queue to destroy.
  9663. *
  9664. * On success this function will return a zero. If the queue destroy mailbox
  9665. * command fails this function will return ENXIO.
  9666. **/
  9667. uint32_t
  9668. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9669. struct lpfc_queue *drq)
  9670. {
  9671. LPFC_MBOXQ_t *mbox;
  9672. int rc, length, status = 0;
  9673. uint32_t shdr_status, shdr_add_status;
  9674. union lpfc_sli4_cfg_shdr *shdr;
  9675. if (!hrq || !drq)
  9676. return -ENODEV;
  9677. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9678. if (!mbox)
  9679. return -ENOMEM;
  9680. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9681. sizeof(struct mbox_header));
  9682. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9683. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9684. length, LPFC_SLI4_MBX_EMBED);
  9685. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9686. hrq->queue_id);
  9687. mbox->vport = hrq->phba->pport;
  9688. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9689. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9690. /* The IOCTL status is embedded in the mailbox subheader. */
  9691. shdr = (union lpfc_sli4_cfg_shdr *)
  9692. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9693. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9694. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9695. if (shdr_status || shdr_add_status || rc) {
  9696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9697. "2509 RQ_DESTROY mailbox failed with "
  9698. "status x%x add_status x%x, mbx status x%x\n",
  9699. shdr_status, shdr_add_status, rc);
  9700. if (rc != MBX_TIMEOUT)
  9701. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9702. return -ENXIO;
  9703. }
  9704. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9705. drq->queue_id);
  9706. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9707. shdr = (union lpfc_sli4_cfg_shdr *)
  9708. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9709. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9710. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9711. if (shdr_status || shdr_add_status || rc) {
  9712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9713. "2510 RQ_DESTROY mailbox failed with "
  9714. "status x%x add_status x%x, mbx status x%x\n",
  9715. shdr_status, shdr_add_status, rc);
  9716. status = -ENXIO;
  9717. }
  9718. list_del_init(&hrq->list);
  9719. list_del_init(&drq->list);
  9720. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9721. return status;
  9722. }
  9723. /**
  9724. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9725. * @phba: The virtual port for which this call being executed.
  9726. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9727. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9728. * @xritag: the xritag that ties this io to the SGL pages.
  9729. *
  9730. * This routine will post the sgl pages for the IO that has the xritag
  9731. * that is in the iocbq structure. The xritag is assigned during iocbq
  9732. * creation and persists for as long as the driver is loaded.
  9733. * if the caller has fewer than 256 scatter gather segments to map then
  9734. * pdma_phys_addr1 should be 0.
  9735. * If the caller needs to map more than 256 scatter gather segment then
  9736. * pdma_phys_addr1 should be a valid physical address.
  9737. * physical address for SGLs must be 64 byte aligned.
  9738. * If you are going to map 2 SGL's then the first one must have 256 entries
  9739. * the second sgl can have between 1 and 256 entries.
  9740. *
  9741. * Return codes:
  9742. * 0 - Success
  9743. * -ENXIO, -ENOMEM - Failure
  9744. **/
  9745. int
  9746. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9747. dma_addr_t pdma_phys_addr0,
  9748. dma_addr_t pdma_phys_addr1,
  9749. uint16_t xritag)
  9750. {
  9751. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9752. LPFC_MBOXQ_t *mbox;
  9753. int rc;
  9754. uint32_t shdr_status, shdr_add_status;
  9755. union lpfc_sli4_cfg_shdr *shdr;
  9756. if (xritag == NO_XRI) {
  9757. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9758. "0364 Invalid param:\n");
  9759. return -EINVAL;
  9760. }
  9761. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9762. if (!mbox)
  9763. return -ENOMEM;
  9764. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9765. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9766. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9767. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9768. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9769. &mbox->u.mqe.un.post_sgl_pages;
  9770. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9771. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9772. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9773. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9774. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9775. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9776. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9777. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9778. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9779. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9780. if (!phba->sli4_hba.intr_enable)
  9781. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9782. else
  9783. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9784. /* The IOCTL status is embedded in the mailbox subheader. */
  9785. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9786. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9787. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9788. if (rc != MBX_TIMEOUT)
  9789. mempool_free(mbox, phba->mbox_mem_pool);
  9790. if (shdr_status || shdr_add_status || rc) {
  9791. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9792. "2511 POST_SGL mailbox failed with "
  9793. "status x%x add_status x%x, mbx status x%x\n",
  9794. shdr_status, shdr_add_status, rc);
  9795. rc = -ENXIO;
  9796. }
  9797. return 0;
  9798. }
  9799. /**
  9800. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9801. * @phba: The virtual port for which this call being executed.
  9802. *
  9803. * This routine will remove all of the sgl pages registered with the hba.
  9804. *
  9805. * Return codes:
  9806. * 0 - Success
  9807. * -ENXIO, -ENOMEM - Failure
  9808. **/
  9809. int
  9810. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9811. {
  9812. LPFC_MBOXQ_t *mbox;
  9813. int rc;
  9814. uint32_t shdr_status, shdr_add_status;
  9815. union lpfc_sli4_cfg_shdr *shdr;
  9816. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9817. if (!mbox)
  9818. return -ENOMEM;
  9819. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9820. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9821. LPFC_SLI4_MBX_EMBED);
  9822. if (!phba->sli4_hba.intr_enable)
  9823. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9824. else
  9825. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9826. /* The IOCTL status is embedded in the mailbox subheader. */
  9827. shdr = (union lpfc_sli4_cfg_shdr *)
  9828. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9829. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9830. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9831. if (rc != MBX_TIMEOUT)
  9832. mempool_free(mbox, phba->mbox_mem_pool);
  9833. if (shdr_status || shdr_add_status || rc) {
  9834. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9835. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9836. "status x%x add_status x%x, mbx status x%x\n",
  9837. shdr_status, shdr_add_status, rc);
  9838. rc = -ENXIO;
  9839. }
  9840. return rc;
  9841. }
  9842. /**
  9843. * lpfc_sli4_next_xritag - Get an xritag for the io
  9844. * @phba: Pointer to HBA context object.
  9845. *
  9846. * This function gets an xritag for the iocb. If there is no unused xritag
  9847. * it will return 0xffff.
  9848. * The function returns the allocated xritag if successful, else returns zero.
  9849. * Zero is not a valid xritag.
  9850. * The caller is not required to hold any lock.
  9851. **/
  9852. uint16_t
  9853. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9854. {
  9855. uint16_t xritag;
  9856. spin_lock_irq(&phba->hbalock);
  9857. xritag = phba->sli4_hba.next_xri;
  9858. if ((xritag != (uint16_t) -1) && xritag <
  9859. (phba->sli4_hba.max_cfg_param.max_xri
  9860. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9861. phba->sli4_hba.next_xri++;
  9862. phba->sli4_hba.max_cfg_param.xri_used++;
  9863. spin_unlock_irq(&phba->hbalock);
  9864. return xritag;
  9865. }
  9866. spin_unlock_irq(&phba->hbalock);
  9867. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9868. "2004 Failed to allocate XRI.last XRITAG is %d"
  9869. " Max XRI is %d, Used XRI is %d\n",
  9870. phba->sli4_hba.next_xri,
  9871. phba->sli4_hba.max_cfg_param.max_xri,
  9872. phba->sli4_hba.max_cfg_param.xri_used);
  9873. return -1;
  9874. }
  9875. /**
  9876. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9877. * @phba: pointer to lpfc hba data structure.
  9878. *
  9879. * This routine is invoked to post a block of driver's sgl pages to the
  9880. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9881. * is only called when the driver is loading and after all IO has been
  9882. * stopped.
  9883. **/
  9884. int
  9885. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9886. {
  9887. struct lpfc_sglq *sglq_entry;
  9888. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9889. struct sgl_page_pairs *sgl_pg_pairs;
  9890. void *viraddr;
  9891. LPFC_MBOXQ_t *mbox;
  9892. uint32_t reqlen, alloclen, pg_pairs;
  9893. uint32_t mbox_tmo;
  9894. uint16_t xritag_start = 0;
  9895. int els_xri_cnt, rc = 0;
  9896. uint32_t shdr_status, shdr_add_status;
  9897. union lpfc_sli4_cfg_shdr *shdr;
  9898. /* The number of sgls to be posted */
  9899. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9900. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9901. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9902. if (reqlen > SLI4_PAGE_SIZE) {
  9903. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9904. "2559 Block sgl registration required DMA "
  9905. "size (%d) great than a page\n", reqlen);
  9906. return -ENOMEM;
  9907. }
  9908. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9909. if (!mbox) {
  9910. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9911. "2560 Failed to allocate mbox cmd memory\n");
  9912. return -ENOMEM;
  9913. }
  9914. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9915. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9916. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9917. LPFC_SLI4_MBX_NEMBED);
  9918. if (alloclen < reqlen) {
  9919. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9920. "0285 Allocated DMA memory size (%d) is "
  9921. "less than the requested DMA memory "
  9922. "size (%d)\n", alloclen, reqlen);
  9923. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9924. return -ENOMEM;
  9925. }
  9926. /* Get the first SGE entry from the non-embedded DMA memory */
  9927. viraddr = mbox->sge_array->addr[0];
  9928. /* Set up the SGL pages in the non-embedded DMA pages */
  9929. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9930. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9931. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9932. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9933. /* Set up the sge entry */
  9934. sgl_pg_pairs->sgl_pg0_addr_lo =
  9935. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9936. sgl_pg_pairs->sgl_pg0_addr_hi =
  9937. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9938. sgl_pg_pairs->sgl_pg1_addr_lo =
  9939. cpu_to_le32(putPaddrLow(0));
  9940. sgl_pg_pairs->sgl_pg1_addr_hi =
  9941. cpu_to_le32(putPaddrHigh(0));
  9942. /* Keep the first xritag on the list */
  9943. if (pg_pairs == 0)
  9944. xritag_start = sglq_entry->sli4_xritag;
  9945. sgl_pg_pairs++;
  9946. }
  9947. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9948. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9949. /* Perform endian conversion if necessary */
  9950. sgl->word0 = cpu_to_le32(sgl->word0);
  9951. if (!phba->sli4_hba.intr_enable)
  9952. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9953. else {
  9954. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9955. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9956. }
  9957. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9958. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9959. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9960. if (rc != MBX_TIMEOUT)
  9961. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9962. if (shdr_status || shdr_add_status || rc) {
  9963. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9964. "2513 POST_SGL_BLOCK mailbox command failed "
  9965. "status x%x add_status x%x mbx status x%x\n",
  9966. shdr_status, shdr_add_status, rc);
  9967. rc = -ENXIO;
  9968. }
  9969. return rc;
  9970. }
  9971. /**
  9972. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9973. * @phba: pointer to lpfc hba data structure.
  9974. * @sblist: pointer to scsi buffer list.
  9975. * @count: number of scsi buffers on the list.
  9976. *
  9977. * This routine is invoked to post a block of @count scsi sgl pages from a
  9978. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9979. * No Lock is held.
  9980. *
  9981. **/
  9982. int
  9983. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9984. int cnt)
  9985. {
  9986. struct lpfc_scsi_buf *psb;
  9987. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9988. struct sgl_page_pairs *sgl_pg_pairs;
  9989. void *viraddr;
  9990. LPFC_MBOXQ_t *mbox;
  9991. uint32_t reqlen, alloclen, pg_pairs;
  9992. uint32_t mbox_tmo;
  9993. uint16_t xritag_start = 0;
  9994. int rc = 0;
  9995. uint32_t shdr_status, shdr_add_status;
  9996. dma_addr_t pdma_phys_bpl1;
  9997. union lpfc_sli4_cfg_shdr *shdr;
  9998. /* Calculate the requested length of the dma memory */
  9999. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10000. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10001. if (reqlen > SLI4_PAGE_SIZE) {
  10002. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10003. "0217 Block sgl registration required DMA "
  10004. "size (%d) great than a page\n", reqlen);
  10005. return -ENOMEM;
  10006. }
  10007. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10008. if (!mbox) {
  10009. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10010. "0283 Failed to allocate mbox cmd memory\n");
  10011. return -ENOMEM;
  10012. }
  10013. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10014. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10015. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10016. LPFC_SLI4_MBX_NEMBED);
  10017. if (alloclen < reqlen) {
  10018. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10019. "2561 Allocated DMA memory size (%d) is "
  10020. "less than the requested DMA memory "
  10021. "size (%d)\n", alloclen, reqlen);
  10022. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10023. return -ENOMEM;
  10024. }
  10025. /* Get the first SGE entry from the non-embedded DMA memory */
  10026. viraddr = mbox->sge_array->addr[0];
  10027. /* Set up the SGL pages in the non-embedded DMA pages */
  10028. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10029. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10030. pg_pairs = 0;
  10031. list_for_each_entry(psb, sblist, list) {
  10032. /* Set up the sge entry */
  10033. sgl_pg_pairs->sgl_pg0_addr_lo =
  10034. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10035. sgl_pg_pairs->sgl_pg0_addr_hi =
  10036. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10037. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10038. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10039. else
  10040. pdma_phys_bpl1 = 0;
  10041. sgl_pg_pairs->sgl_pg1_addr_lo =
  10042. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10043. sgl_pg_pairs->sgl_pg1_addr_hi =
  10044. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10045. /* Keep the first xritag on the list */
  10046. if (pg_pairs == 0)
  10047. xritag_start = psb->cur_iocbq.sli4_xritag;
  10048. sgl_pg_pairs++;
  10049. pg_pairs++;
  10050. }
  10051. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10052. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10053. /* Perform endian conversion if necessary */
  10054. sgl->word0 = cpu_to_le32(sgl->word0);
  10055. if (!phba->sli4_hba.intr_enable)
  10056. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10057. else {
  10058. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10059. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10060. }
  10061. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10062. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10063. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10064. if (rc != MBX_TIMEOUT)
  10065. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10066. if (shdr_status || shdr_add_status || rc) {
  10067. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10068. "2564 POST_SGL_BLOCK mailbox command failed "
  10069. "status x%x add_status x%x mbx status x%x\n",
  10070. shdr_status, shdr_add_status, rc);
  10071. rc = -ENXIO;
  10072. }
  10073. return rc;
  10074. }
  10075. /**
  10076. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10077. * @phba: pointer to lpfc_hba struct that the frame was received on
  10078. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10079. *
  10080. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10081. * valid type of frame that the LPFC driver will handle. This function will
  10082. * return a zero if the frame is a valid frame or a non zero value when the
  10083. * frame does not pass the check.
  10084. **/
  10085. static int
  10086. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10087. {
  10088. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10089. char *type_names[] = FC_TYPE_NAMES_INIT;
  10090. struct fc_vft_header *fc_vft_hdr;
  10091. switch (fc_hdr->fh_r_ctl) {
  10092. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10093. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10094. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10095. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10096. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10097. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10098. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10099. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10100. case FC_RCTL_ELS_REQ: /* extended link services request */
  10101. case FC_RCTL_ELS_REP: /* extended link services reply */
  10102. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10103. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10104. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10105. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10106. case FC_RCTL_BA_RMC: /* remove connection */
  10107. case FC_RCTL_BA_ACC: /* basic accept */
  10108. case FC_RCTL_BA_RJT: /* basic reject */
  10109. case FC_RCTL_BA_PRMT:
  10110. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10111. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10112. case FC_RCTL_P_RJT: /* port reject */
  10113. case FC_RCTL_F_RJT: /* fabric reject */
  10114. case FC_RCTL_P_BSY: /* port busy */
  10115. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10116. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10117. case FC_RCTL_LCR: /* link credit reset */
  10118. case FC_RCTL_END: /* end */
  10119. break;
  10120. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10121. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10122. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10123. return lpfc_fc_frame_check(phba, fc_hdr);
  10124. default:
  10125. goto drop;
  10126. }
  10127. switch (fc_hdr->fh_type) {
  10128. case FC_TYPE_BLS:
  10129. case FC_TYPE_ELS:
  10130. case FC_TYPE_FCP:
  10131. case FC_TYPE_CT:
  10132. break;
  10133. case FC_TYPE_IP:
  10134. case FC_TYPE_ILS:
  10135. default:
  10136. goto drop;
  10137. }
  10138. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10139. "2538 Received frame rctl:%s type:%s\n",
  10140. rctl_names[fc_hdr->fh_r_ctl],
  10141. type_names[fc_hdr->fh_type]);
  10142. return 0;
  10143. drop:
  10144. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10145. "2539 Dropped frame rctl:%s type:%s\n",
  10146. rctl_names[fc_hdr->fh_r_ctl],
  10147. type_names[fc_hdr->fh_type]);
  10148. return 1;
  10149. }
  10150. /**
  10151. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10152. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10153. *
  10154. * This function processes the FC header to retrieve the VFI from the VF
  10155. * header, if one exists. This function will return the VFI if one exists
  10156. * or 0 if no VSAN Header exists.
  10157. **/
  10158. static uint32_t
  10159. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10160. {
  10161. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10162. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10163. return 0;
  10164. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10165. }
  10166. /**
  10167. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10168. * @phba: Pointer to the HBA structure to search for the vport on
  10169. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10170. * @fcfi: The FC Fabric ID that the frame came from
  10171. *
  10172. * This function searches the @phba for a vport that matches the content of the
  10173. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10174. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10175. * returns the matching vport pointer or NULL if unable to match frame to a
  10176. * vport.
  10177. **/
  10178. static struct lpfc_vport *
  10179. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10180. uint16_t fcfi)
  10181. {
  10182. struct lpfc_vport **vports;
  10183. struct lpfc_vport *vport = NULL;
  10184. int i;
  10185. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10186. fc_hdr->fh_d_id[1] << 8 |
  10187. fc_hdr->fh_d_id[2]);
  10188. vports = lpfc_create_vport_work_array(phba);
  10189. if (vports != NULL)
  10190. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10191. if (phba->fcf.fcfi == fcfi &&
  10192. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10193. vports[i]->fc_myDID == did) {
  10194. vport = vports[i];
  10195. break;
  10196. }
  10197. }
  10198. lpfc_destroy_vport_work_array(phba, vports);
  10199. return vport;
  10200. }
  10201. /**
  10202. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10203. * @vport: The vport to work on.
  10204. *
  10205. * This function updates the receive sequence time stamp for this vport. The
  10206. * receive sequence time stamp indicates the time that the last frame of the
  10207. * the sequence that has been idle for the longest amount of time was received.
  10208. * the driver uses this time stamp to indicate if any received sequences have
  10209. * timed out.
  10210. **/
  10211. void
  10212. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10213. {
  10214. struct lpfc_dmabuf *h_buf;
  10215. struct hbq_dmabuf *dmabuf = NULL;
  10216. /* get the oldest sequence on the rcv list */
  10217. h_buf = list_get_first(&vport->rcv_buffer_list,
  10218. struct lpfc_dmabuf, list);
  10219. if (!h_buf)
  10220. return;
  10221. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10222. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10223. }
  10224. /**
  10225. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10226. * @vport: The vport that the received sequences were sent to.
  10227. *
  10228. * This function cleans up all outstanding received sequences. This is called
  10229. * by the driver when a link event or user action invalidates all the received
  10230. * sequences.
  10231. **/
  10232. void
  10233. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10234. {
  10235. struct lpfc_dmabuf *h_buf, *hnext;
  10236. struct lpfc_dmabuf *d_buf, *dnext;
  10237. struct hbq_dmabuf *dmabuf = NULL;
  10238. /* start with the oldest sequence on the rcv list */
  10239. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10240. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10241. list_del_init(&dmabuf->hbuf.list);
  10242. list_for_each_entry_safe(d_buf, dnext,
  10243. &dmabuf->dbuf.list, list) {
  10244. list_del_init(&d_buf->list);
  10245. lpfc_in_buf_free(vport->phba, d_buf);
  10246. }
  10247. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10248. }
  10249. }
  10250. /**
  10251. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10252. * @vport: The vport that the received sequences were sent to.
  10253. *
  10254. * This function determines whether any received sequences have timed out by
  10255. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10256. * indicates that there is at least one timed out sequence this routine will
  10257. * go through the received sequences one at a time from most inactive to most
  10258. * active to determine which ones need to be cleaned up. Once it has determined
  10259. * that a sequence needs to be cleaned up it will simply free up the resources
  10260. * without sending an abort.
  10261. **/
  10262. void
  10263. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10264. {
  10265. struct lpfc_dmabuf *h_buf, *hnext;
  10266. struct lpfc_dmabuf *d_buf, *dnext;
  10267. struct hbq_dmabuf *dmabuf = NULL;
  10268. unsigned long timeout;
  10269. int abort_count = 0;
  10270. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10271. vport->rcv_buffer_time_stamp);
  10272. if (list_empty(&vport->rcv_buffer_list) ||
  10273. time_before(jiffies, timeout))
  10274. return;
  10275. /* start with the oldest sequence on the rcv list */
  10276. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10277. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10278. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10279. dmabuf->time_stamp);
  10280. if (time_before(jiffies, timeout))
  10281. break;
  10282. abort_count++;
  10283. list_del_init(&dmabuf->hbuf.list);
  10284. list_for_each_entry_safe(d_buf, dnext,
  10285. &dmabuf->dbuf.list, list) {
  10286. list_del_init(&d_buf->list);
  10287. lpfc_in_buf_free(vport->phba, d_buf);
  10288. }
  10289. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10290. }
  10291. if (abort_count)
  10292. lpfc_update_rcv_time_stamp(vport);
  10293. }
  10294. /**
  10295. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10296. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10297. *
  10298. * This function searches through the existing incomplete sequences that have
  10299. * been sent to this @vport. If the frame matches one of the incomplete
  10300. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10301. * make up that sequence. If no sequence is found that matches this frame then
  10302. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10303. * This function returns a pointer to the first dmabuf in the sequence list that
  10304. * the frame was linked to.
  10305. **/
  10306. static struct hbq_dmabuf *
  10307. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10308. {
  10309. struct fc_frame_header *new_hdr;
  10310. struct fc_frame_header *temp_hdr;
  10311. struct lpfc_dmabuf *d_buf;
  10312. struct lpfc_dmabuf *h_buf;
  10313. struct hbq_dmabuf *seq_dmabuf = NULL;
  10314. struct hbq_dmabuf *temp_dmabuf = NULL;
  10315. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10316. dmabuf->time_stamp = jiffies;
  10317. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10318. /* Use the hdr_buf to find the sequence that this frame belongs to */
  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. if (!seq_dmabuf) {
  10330. /*
  10331. * This indicates first frame received for this sequence.
  10332. * Queue the buffer on the vport's rcv_buffer_list.
  10333. */
  10334. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10335. lpfc_update_rcv_time_stamp(vport);
  10336. return dmabuf;
  10337. }
  10338. temp_hdr = seq_dmabuf->hbuf.virt;
  10339. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10340. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10341. list_del_init(&seq_dmabuf->hbuf.list);
  10342. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10343. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10344. lpfc_update_rcv_time_stamp(vport);
  10345. return dmabuf;
  10346. }
  10347. /* move this sequence to the tail to indicate a young sequence */
  10348. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10349. seq_dmabuf->time_stamp = jiffies;
  10350. lpfc_update_rcv_time_stamp(vport);
  10351. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10352. temp_hdr = dmabuf->hbuf.virt;
  10353. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10354. return seq_dmabuf;
  10355. }
  10356. /* find the correct place in the sequence to insert this frame */
  10357. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10358. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10359. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10360. /*
  10361. * If the frame's sequence count is greater than the frame on
  10362. * the list then insert the frame right after this frame
  10363. */
  10364. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10365. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10366. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10367. return seq_dmabuf;
  10368. }
  10369. }
  10370. return NULL;
  10371. }
  10372. /**
  10373. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10374. * @vport: pointer to a vitural port
  10375. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10376. *
  10377. * This function tries to abort from the partially assembed sequence, described
  10378. * by the information from basic abbort @dmabuf. It checks to see whether such
  10379. * partially assembled sequence held by the driver. If so, it shall free up all
  10380. * the frames from the partially assembled sequence.
  10381. *
  10382. * Return
  10383. * true -- if there is matching partially assembled sequence present and all
  10384. * the frames freed with the sequence;
  10385. * false -- if there is no matching partially assembled sequence present so
  10386. * nothing got aborted in the lower layer driver
  10387. **/
  10388. static bool
  10389. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10390. struct hbq_dmabuf *dmabuf)
  10391. {
  10392. struct fc_frame_header *new_hdr;
  10393. struct fc_frame_header *temp_hdr;
  10394. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10395. struct hbq_dmabuf *seq_dmabuf = NULL;
  10396. /* Use the hdr_buf to find the sequence that matches this frame */
  10397. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10398. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10399. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10400. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10401. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10402. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10403. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10404. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10405. continue;
  10406. /* found a pending sequence that matches this frame */
  10407. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10408. break;
  10409. }
  10410. /* Free up all the frames from the partially assembled sequence */
  10411. if (seq_dmabuf) {
  10412. list_for_each_entry_safe(d_buf, n_buf,
  10413. &seq_dmabuf->dbuf.list, list) {
  10414. list_del_init(&d_buf->list);
  10415. lpfc_in_buf_free(vport->phba, d_buf);
  10416. }
  10417. return true;
  10418. }
  10419. return false;
  10420. }
  10421. /**
  10422. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10423. * @phba: Pointer to HBA context object.
  10424. * @cmd_iocbq: pointer to the command iocbq structure.
  10425. * @rsp_iocbq: pointer to the response iocbq structure.
  10426. *
  10427. * This function handles the sequence abort accept iocb command complete
  10428. * event. It properly releases the memory allocated to the sequence abort
  10429. * accept iocb.
  10430. **/
  10431. static void
  10432. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10433. struct lpfc_iocbq *cmd_iocbq,
  10434. struct lpfc_iocbq *rsp_iocbq)
  10435. {
  10436. if (cmd_iocbq)
  10437. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10438. }
  10439. /**
  10440. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10441. * @phba: Pointer to HBA context object.
  10442. * @fc_hdr: pointer to a FC frame header.
  10443. *
  10444. * This function sends a basic accept to a previous unsol sequence abort
  10445. * event after aborting the sequence handling.
  10446. **/
  10447. static void
  10448. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10449. struct fc_frame_header *fc_hdr)
  10450. {
  10451. struct lpfc_iocbq *ctiocb = NULL;
  10452. struct lpfc_nodelist *ndlp;
  10453. uint16_t oxid, rxid;
  10454. uint32_t sid, fctl;
  10455. IOCB_t *icmd;
  10456. if (!lpfc_is_link_up(phba))
  10457. return;
  10458. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10459. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10460. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10461. ndlp = lpfc_findnode_did(phba->pport, sid);
  10462. if (!ndlp) {
  10463. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10464. "1268 Find ndlp returned NULL for oxid:x%x "
  10465. "SID:x%x\n", oxid, sid);
  10466. return;
  10467. }
  10468. /* Allocate buffer for acc iocb */
  10469. ctiocb = lpfc_sli_get_iocbq(phba);
  10470. if (!ctiocb)
  10471. return;
  10472. /* Extract the F_CTL field from FC_HDR */
  10473. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10474. icmd = &ctiocb->iocb;
  10475. icmd->un.xseq64.bdl.bdeSize = 0;
  10476. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10477. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10478. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10479. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10480. /* Fill in the rest of iocb fields */
  10481. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10482. icmd->ulpBdeCount = 0;
  10483. icmd->ulpLe = 1;
  10484. icmd->ulpClass = CLASS3;
  10485. icmd->ulpContext = ndlp->nlp_rpi;
  10486. ctiocb->iocb_cmpl = NULL;
  10487. ctiocb->vport = phba->pport;
  10488. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10489. if (fctl & FC_FC_EX_CTX) {
  10490. /* ABTS sent by responder to CT exchange, construction
  10491. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10492. * field and RX_ID from ABTS for RX_ID field.
  10493. */
  10494. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10495. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10496. ctiocb->sli4_xritag = oxid;
  10497. } else {
  10498. /* ABTS sent by initiator to CT exchange, construction
  10499. * of BA_ACC will need to allocate a new XRI as for the
  10500. * XRI_TAG and RX_ID fields.
  10501. */
  10502. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10503. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10504. ctiocb->sli4_xritag = NO_XRI;
  10505. }
  10506. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10507. /* Xmit CT abts accept on exchange <xid> */
  10508. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10509. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10510. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10511. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10512. }
  10513. /**
  10514. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10515. * @vport: Pointer to the vport on which this sequence was received
  10516. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10517. *
  10518. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10519. * receive sequence is only partially assembed by the driver, it shall abort
  10520. * the partially assembled frames for the sequence. Otherwise, if the
  10521. * unsolicited receive sequence has been completely assembled and passed to
  10522. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10523. * unsolicited sequence has been aborted. After that, it will issue a basic
  10524. * accept to accept the abort.
  10525. **/
  10526. void
  10527. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10528. struct hbq_dmabuf *dmabuf)
  10529. {
  10530. struct lpfc_hba *phba = vport->phba;
  10531. struct fc_frame_header fc_hdr;
  10532. uint32_t fctl;
  10533. bool abts_par;
  10534. /* Make a copy of fc_hdr before the dmabuf being released */
  10535. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10536. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10537. if (fctl & FC_FC_EX_CTX) {
  10538. /*
  10539. * ABTS sent by responder to exchange, just free the buffer
  10540. */
  10541. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10542. } else {
  10543. /*
  10544. * ABTS sent by initiator to exchange, need to do cleanup
  10545. */
  10546. /* Try to abort partially assembled seq */
  10547. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10548. /* Send abort to ULP if partially seq abort failed */
  10549. if (abts_par == false)
  10550. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10551. else
  10552. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10553. }
  10554. /* Send basic accept (BA_ACC) to the abort requester */
  10555. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10556. }
  10557. /**
  10558. * lpfc_seq_complete - Indicates if a sequence is complete
  10559. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10560. *
  10561. * This function checks the sequence, starting with the frame described by
  10562. * @dmabuf, to see if all the frames associated with this sequence are present.
  10563. * the frames associated with this sequence are linked to the @dmabuf using the
  10564. * dbuf list. This function looks for two major things. 1) That the first frame
  10565. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10566. * set. 3) That there are no holes in the sequence count. The function will
  10567. * return 1 when the sequence is complete, otherwise it will return 0.
  10568. **/
  10569. static int
  10570. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10571. {
  10572. struct fc_frame_header *hdr;
  10573. struct lpfc_dmabuf *d_buf;
  10574. struct hbq_dmabuf *seq_dmabuf;
  10575. uint32_t fctl;
  10576. int seq_count = 0;
  10577. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10578. /* make sure first fame of sequence has a sequence count of zero */
  10579. if (hdr->fh_seq_cnt != seq_count)
  10580. return 0;
  10581. fctl = (hdr->fh_f_ctl[0] << 16 |
  10582. hdr->fh_f_ctl[1] << 8 |
  10583. hdr->fh_f_ctl[2]);
  10584. /* If last frame of sequence we can return success. */
  10585. if (fctl & FC_FC_END_SEQ)
  10586. return 1;
  10587. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10588. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10589. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10590. /* If there is a hole in the sequence count then fail. */
  10591. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10592. return 0;
  10593. fctl = (hdr->fh_f_ctl[0] << 16 |
  10594. hdr->fh_f_ctl[1] << 8 |
  10595. hdr->fh_f_ctl[2]);
  10596. /* If last frame of sequence we can return success. */
  10597. if (fctl & FC_FC_END_SEQ)
  10598. return 1;
  10599. }
  10600. return 0;
  10601. }
  10602. /**
  10603. * lpfc_prep_seq - Prep sequence for ULP processing
  10604. * @vport: Pointer to the vport on which this sequence was received
  10605. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10606. *
  10607. * This function takes a sequence, described by a list of frames, and creates
  10608. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10609. * used to issue to the generic unsolicited sequence handler. This routine
  10610. * returns a pointer to the first iocbq in the list. If the function is unable
  10611. * to allocate an iocbq then it throw out the received frames that were not
  10612. * able to be described and return a pointer to the first iocbq. If unable to
  10613. * allocate any iocbqs (including the first) this function will return NULL.
  10614. **/
  10615. static struct lpfc_iocbq *
  10616. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10617. {
  10618. struct lpfc_dmabuf *d_buf, *n_buf;
  10619. struct lpfc_iocbq *first_iocbq, *iocbq;
  10620. struct fc_frame_header *fc_hdr;
  10621. uint32_t sid;
  10622. struct ulp_bde64 *pbde;
  10623. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10624. /* remove from receive buffer list */
  10625. list_del_init(&seq_dmabuf->hbuf.list);
  10626. lpfc_update_rcv_time_stamp(vport);
  10627. /* get the Remote Port's SID */
  10628. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10629. /* Get an iocbq struct to fill in. */
  10630. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10631. if (first_iocbq) {
  10632. /* Initialize the first IOCB. */
  10633. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10634. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10635. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10636. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10637. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10638. vport->vpi + vport->phba->vpi_base;
  10639. /* put the first buffer into the first IOCBq */
  10640. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10641. first_iocbq->context3 = NULL;
  10642. first_iocbq->iocb.ulpBdeCount = 1;
  10643. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10644. LPFC_DATA_BUF_SIZE;
  10645. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10646. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10647. bf_get(lpfc_rcqe_length,
  10648. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10649. }
  10650. iocbq = first_iocbq;
  10651. /*
  10652. * Each IOCBq can have two Buffers assigned, so go through the list
  10653. * of buffers for this sequence and save two buffers in each IOCBq
  10654. */
  10655. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10656. if (!iocbq) {
  10657. lpfc_in_buf_free(vport->phba, d_buf);
  10658. continue;
  10659. }
  10660. if (!iocbq->context3) {
  10661. iocbq->context3 = d_buf;
  10662. iocbq->iocb.ulpBdeCount++;
  10663. pbde = (struct ulp_bde64 *)
  10664. &iocbq->iocb.unsli3.sli3Words[4];
  10665. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10666. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10667. bf_get(lpfc_rcqe_length,
  10668. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10669. } else {
  10670. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10671. if (!iocbq) {
  10672. if (first_iocbq) {
  10673. first_iocbq->iocb.ulpStatus =
  10674. IOSTAT_FCP_RSP_ERROR;
  10675. first_iocbq->iocb.un.ulpWord[4] =
  10676. IOERR_NO_RESOURCES;
  10677. }
  10678. lpfc_in_buf_free(vport->phba, d_buf);
  10679. continue;
  10680. }
  10681. iocbq->context2 = d_buf;
  10682. iocbq->context3 = NULL;
  10683. iocbq->iocb.ulpBdeCount = 1;
  10684. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10685. LPFC_DATA_BUF_SIZE;
  10686. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10687. bf_get(lpfc_rcqe_length,
  10688. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10689. iocbq->iocb.un.rcvels.remoteID = sid;
  10690. list_add_tail(&iocbq->list, &first_iocbq->list);
  10691. }
  10692. }
  10693. return first_iocbq;
  10694. }
  10695. static void
  10696. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10697. struct hbq_dmabuf *seq_dmabuf)
  10698. {
  10699. struct fc_frame_header *fc_hdr;
  10700. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10701. struct lpfc_hba *phba = vport->phba;
  10702. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10703. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10704. if (!iocbq) {
  10705. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10706. "2707 Ring %d handler: Failed to allocate "
  10707. "iocb Rctl x%x Type x%x received\n",
  10708. LPFC_ELS_RING,
  10709. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10710. return;
  10711. }
  10712. if (!lpfc_complete_unsol_iocb(phba,
  10713. &phba->sli.ring[LPFC_ELS_RING],
  10714. iocbq, fc_hdr->fh_r_ctl,
  10715. fc_hdr->fh_type))
  10716. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10717. "2540 Ring %d handler: unexpected Rctl "
  10718. "x%x Type x%x received\n",
  10719. LPFC_ELS_RING,
  10720. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10721. /* Free iocb created in lpfc_prep_seq */
  10722. list_for_each_entry_safe(curr_iocb, next_iocb,
  10723. &iocbq->list, list) {
  10724. list_del_init(&curr_iocb->list);
  10725. lpfc_sli_release_iocbq(phba, curr_iocb);
  10726. }
  10727. lpfc_sli_release_iocbq(phba, iocbq);
  10728. }
  10729. /**
  10730. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10731. * @phba: Pointer to HBA context object.
  10732. *
  10733. * This function is called with no lock held. This function processes all
  10734. * the received buffers and gives it to upper layers when a received buffer
  10735. * indicates that it is the final frame in the sequence. The interrupt
  10736. * service routine processes received buffers at interrupt contexts and adds
  10737. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10738. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10739. * appropriate receive function when the final frame in a sequence is received.
  10740. **/
  10741. void
  10742. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10743. struct hbq_dmabuf *dmabuf)
  10744. {
  10745. struct hbq_dmabuf *seq_dmabuf;
  10746. struct fc_frame_header *fc_hdr;
  10747. struct lpfc_vport *vport;
  10748. uint32_t fcfi;
  10749. /* Process each received buffer */
  10750. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10751. /* check to see if this a valid type of frame */
  10752. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10753. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10754. return;
  10755. }
  10756. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10757. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10758. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10759. /* throw out the frame */
  10760. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10761. return;
  10762. }
  10763. /* Handle the basic abort sequence (BA_ABTS) event */
  10764. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10765. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10766. return;
  10767. }
  10768. /* Link this frame */
  10769. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10770. if (!seq_dmabuf) {
  10771. /* unable to add frame to vport - throw it out */
  10772. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10773. return;
  10774. }
  10775. /* If not last frame in sequence continue processing frames. */
  10776. if (!lpfc_seq_complete(seq_dmabuf))
  10777. return;
  10778. /* Send the complete sequence to the upper layer protocol */
  10779. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10780. }
  10781. /**
  10782. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10783. * @phba: pointer to lpfc hba data structure.
  10784. *
  10785. * This routine is invoked to post rpi header templates to the
  10786. * HBA consistent with the SLI-4 interface spec. This routine
  10787. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10788. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10789. *
  10790. * This routine does not require any locks. It's usage is expected
  10791. * to be driver load or reset recovery when the driver is
  10792. * sequential.
  10793. *
  10794. * Return codes
  10795. * 0 - successful
  10796. * EIO - The mailbox failed to complete successfully.
  10797. * When this error occurs, the driver is not guaranteed
  10798. * to have any rpi regions posted to the device and
  10799. * must either attempt to repost the regions or take a
  10800. * fatal error.
  10801. **/
  10802. int
  10803. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10804. {
  10805. struct lpfc_rpi_hdr *rpi_page;
  10806. uint32_t rc = 0;
  10807. /* Post all rpi memory regions to the port. */
  10808. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10809. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10810. if (rc != MBX_SUCCESS) {
  10811. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10812. "2008 Error %d posting all rpi "
  10813. "headers\n", rc);
  10814. rc = -EIO;
  10815. break;
  10816. }
  10817. }
  10818. return rc;
  10819. }
  10820. /**
  10821. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10822. * @phba: pointer to lpfc hba data structure.
  10823. * @rpi_page: pointer to the rpi memory region.
  10824. *
  10825. * This routine is invoked to post a single rpi header to the
  10826. * HBA consistent with the SLI-4 interface spec. This memory region
  10827. * maps up to 64 rpi context regions.
  10828. *
  10829. * Return codes
  10830. * 0 - successful
  10831. * ENOMEM - No available memory
  10832. * EIO - The mailbox failed to complete successfully.
  10833. **/
  10834. int
  10835. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10836. {
  10837. LPFC_MBOXQ_t *mboxq;
  10838. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10839. uint32_t rc = 0;
  10840. uint32_t mbox_tmo;
  10841. uint32_t shdr_status, shdr_add_status;
  10842. union lpfc_sli4_cfg_shdr *shdr;
  10843. /* The port is notified of the header region via a mailbox command. */
  10844. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10845. if (!mboxq) {
  10846. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10847. "2001 Unable to allocate memory for issuing "
  10848. "SLI_CONFIG_SPECIAL mailbox command\n");
  10849. return -ENOMEM;
  10850. }
  10851. /* Post all rpi memory regions to the port. */
  10852. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10853. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10854. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10855. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10856. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10857. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10858. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10859. hdr_tmpl, rpi_page->page_count);
  10860. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10861. rpi_page->start_rpi);
  10862. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10863. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10864. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10865. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10866. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10867. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10868. if (rc != MBX_TIMEOUT)
  10869. mempool_free(mboxq, phba->mbox_mem_pool);
  10870. if (shdr_status || shdr_add_status || rc) {
  10871. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10872. "2514 POST_RPI_HDR mailbox failed with "
  10873. "status x%x add_status x%x, mbx status x%x\n",
  10874. shdr_status, shdr_add_status, rc);
  10875. rc = -ENXIO;
  10876. }
  10877. return rc;
  10878. }
  10879. /**
  10880. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10881. * @phba: pointer to lpfc hba data structure.
  10882. *
  10883. * This routine is invoked to post rpi header templates to the
  10884. * HBA consistent with the SLI-4 interface spec. This routine
  10885. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10886. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10887. *
  10888. * Returns
  10889. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10890. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10891. **/
  10892. int
  10893. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10894. {
  10895. int rpi;
  10896. uint16_t max_rpi, rpi_base, rpi_limit;
  10897. uint16_t rpi_remaining;
  10898. struct lpfc_rpi_hdr *rpi_hdr;
  10899. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10900. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10901. rpi_limit = phba->sli4_hba.next_rpi;
  10902. /*
  10903. * The valid rpi range is not guaranteed to be zero-based. Start
  10904. * the search at the rpi_base as reported by the port.
  10905. */
  10906. spin_lock_irq(&phba->hbalock);
  10907. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10908. if (rpi >= rpi_limit || rpi < rpi_base)
  10909. rpi = LPFC_RPI_ALLOC_ERROR;
  10910. else {
  10911. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10912. phba->sli4_hba.max_cfg_param.rpi_used++;
  10913. phba->sli4_hba.rpi_count++;
  10914. }
  10915. /*
  10916. * Don't try to allocate more rpi header regions if the device limit
  10917. * on available rpis max has been exhausted.
  10918. */
  10919. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10920. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10921. spin_unlock_irq(&phba->hbalock);
  10922. return rpi;
  10923. }
  10924. /*
  10925. * If the driver is running low on rpi resources, allocate another
  10926. * page now. Note that the next_rpi value is used because
  10927. * it represents how many are actually in use whereas max_rpi notes
  10928. * how many are supported max by the device.
  10929. */
  10930. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10931. phba->sli4_hba.rpi_count;
  10932. spin_unlock_irq(&phba->hbalock);
  10933. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10934. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10935. if (!rpi_hdr) {
  10936. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10937. "2002 Error Could not grow rpi "
  10938. "count\n");
  10939. } else {
  10940. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10941. }
  10942. }
  10943. return rpi;
  10944. }
  10945. /**
  10946. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10947. * @phba: pointer to lpfc hba data structure.
  10948. *
  10949. * This routine is invoked to release an rpi to the pool of
  10950. * available rpis maintained by the driver.
  10951. **/
  10952. void
  10953. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10954. {
  10955. spin_lock_irq(&phba->hbalock);
  10956. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10957. phba->sli4_hba.rpi_count--;
  10958. phba->sli4_hba.max_cfg_param.rpi_used--;
  10959. spin_unlock_irq(&phba->hbalock);
  10960. }
  10961. /**
  10962. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10963. * @phba: pointer to lpfc hba data structure.
  10964. *
  10965. * This routine is invoked to remove the memory region that
  10966. * provided rpi via a bitmask.
  10967. **/
  10968. void
  10969. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10970. {
  10971. kfree(phba->sli4_hba.rpi_bmask);
  10972. }
  10973. /**
  10974. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10975. * @phba: pointer to lpfc hba data structure.
  10976. *
  10977. * This routine is invoked to remove the memory region that
  10978. * provided rpi via a bitmask.
  10979. **/
  10980. int
  10981. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10982. {
  10983. LPFC_MBOXQ_t *mboxq;
  10984. struct lpfc_hba *phba = ndlp->phba;
  10985. int rc;
  10986. /* The port is notified of the header region via a mailbox command. */
  10987. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10988. if (!mboxq)
  10989. return -ENOMEM;
  10990. /* Post all rpi memory regions to the port. */
  10991. lpfc_resume_rpi(mboxq, ndlp);
  10992. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10993. if (rc == MBX_NOT_FINISHED) {
  10994. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10995. "2010 Resume RPI Mailbox failed "
  10996. "status %d, mbxStatus x%x\n", rc,
  10997. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10998. mempool_free(mboxq, phba->mbox_mem_pool);
  10999. return -EIO;
  11000. }
  11001. return 0;
  11002. }
  11003. /**
  11004. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11005. * @phba: pointer to lpfc hba data structure.
  11006. * @vpi: vpi value to activate with the port.
  11007. *
  11008. * This routine is invoked to activate a vpi with the
  11009. * port when the host intends to use vports with a
  11010. * nonzero vpi.
  11011. *
  11012. * Returns:
  11013. * 0 success
  11014. * -Evalue otherwise
  11015. **/
  11016. int
  11017. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  11018. {
  11019. LPFC_MBOXQ_t *mboxq;
  11020. int rc = 0;
  11021. int retval = MBX_SUCCESS;
  11022. uint32_t mbox_tmo;
  11023. if (vpi == 0)
  11024. return -EINVAL;
  11025. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11026. if (!mboxq)
  11027. return -ENOMEM;
  11028. lpfc_init_vpi(phba, mboxq, vpi);
  11029. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11030. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11031. if (rc != MBX_SUCCESS) {
  11032. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11033. "2022 INIT VPI Mailbox failed "
  11034. "status %d, mbxStatus x%x\n", rc,
  11035. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11036. retval = -EIO;
  11037. }
  11038. if (rc != MBX_TIMEOUT)
  11039. mempool_free(mboxq, phba->mbox_mem_pool);
  11040. return retval;
  11041. }
  11042. /**
  11043. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11044. * @phba: pointer to lpfc hba data structure.
  11045. * @mboxq: Pointer to mailbox object.
  11046. *
  11047. * This routine is invoked to manually add a single FCF record. The caller
  11048. * must pass a completely initialized FCF_Record. This routine takes
  11049. * care of the nonembedded mailbox operations.
  11050. **/
  11051. static void
  11052. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11053. {
  11054. void *virt_addr;
  11055. union lpfc_sli4_cfg_shdr *shdr;
  11056. uint32_t shdr_status, shdr_add_status;
  11057. virt_addr = mboxq->sge_array->addr[0];
  11058. /* The IOCTL status is embedded in the mailbox subheader. */
  11059. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11060. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11061. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11062. if ((shdr_status || shdr_add_status) &&
  11063. (shdr_status != STATUS_FCF_IN_USE))
  11064. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11065. "2558 ADD_FCF_RECORD mailbox failed with "
  11066. "status x%x add_status x%x\n",
  11067. shdr_status, shdr_add_status);
  11068. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11069. }
  11070. /**
  11071. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11072. * @phba: pointer to lpfc hba data structure.
  11073. * @fcf_record: pointer to the initialized fcf record to add.
  11074. *
  11075. * This routine is invoked to manually add a single FCF record. The caller
  11076. * must pass a completely initialized FCF_Record. This routine takes
  11077. * care of the nonembedded mailbox operations.
  11078. **/
  11079. int
  11080. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11081. {
  11082. int rc = 0;
  11083. LPFC_MBOXQ_t *mboxq;
  11084. uint8_t *bytep;
  11085. void *virt_addr;
  11086. dma_addr_t phys_addr;
  11087. struct lpfc_mbx_sge sge;
  11088. uint32_t alloc_len, req_len;
  11089. uint32_t fcfindex;
  11090. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11091. if (!mboxq) {
  11092. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11093. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11094. return -ENOMEM;
  11095. }
  11096. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11097. sizeof(uint32_t);
  11098. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11099. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11100. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11101. req_len, LPFC_SLI4_MBX_NEMBED);
  11102. if (alloc_len < req_len) {
  11103. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11104. "2523 Allocated DMA memory size (x%x) is "
  11105. "less than the requested DMA memory "
  11106. "size (x%x)\n", alloc_len, req_len);
  11107. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11108. return -ENOMEM;
  11109. }
  11110. /*
  11111. * Get the first SGE entry from the non-embedded DMA memory. This
  11112. * routine only uses a single SGE.
  11113. */
  11114. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11115. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11116. virt_addr = mboxq->sge_array->addr[0];
  11117. /*
  11118. * Configure the FCF record for FCFI 0. This is the driver's
  11119. * hardcoded default and gets used in nonFIP mode.
  11120. */
  11121. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11122. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11123. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11124. /*
  11125. * Copy the fcf_index and the FCF Record Data. The data starts after
  11126. * the FCoE header plus word10. The data copy needs to be endian
  11127. * correct.
  11128. */
  11129. bytep += sizeof(uint32_t);
  11130. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11131. mboxq->vport = phba->pport;
  11132. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11133. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11134. if (rc == MBX_NOT_FINISHED) {
  11135. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11136. "2515 ADD_FCF_RECORD mailbox failed with "
  11137. "status 0x%x\n", rc);
  11138. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11139. rc = -EIO;
  11140. } else
  11141. rc = 0;
  11142. return rc;
  11143. }
  11144. /**
  11145. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11146. * @phba: pointer to lpfc hba data structure.
  11147. * @fcf_record: pointer to the fcf record to write the default data.
  11148. * @fcf_index: FCF table entry index.
  11149. *
  11150. * This routine is invoked to build the driver's default FCF record. The
  11151. * values used are hardcoded. This routine handles memory initialization.
  11152. *
  11153. **/
  11154. void
  11155. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11156. struct fcf_record *fcf_record,
  11157. uint16_t fcf_index)
  11158. {
  11159. memset(fcf_record, 0, sizeof(struct fcf_record));
  11160. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11161. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11162. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11163. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11164. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11165. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11166. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11167. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11168. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11169. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11170. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11171. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11172. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11173. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11174. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11175. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11176. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11177. /* Set the VLAN bit map */
  11178. if (phba->valid_vlan) {
  11179. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11180. = 1 << (phba->vlan_id % 8);
  11181. }
  11182. }
  11183. /**
  11184. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11185. * @phba: pointer to lpfc hba data structure.
  11186. * @fcf_index: FCF table entry offset.
  11187. *
  11188. * This routine is invoked to scan the entire FCF table by reading FCF
  11189. * record and processing it one at a time starting from the @fcf_index
  11190. * for initial FCF discovery or fast FCF failover rediscovery.
  11191. *
  11192. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11193. * otherwise.
  11194. **/
  11195. int
  11196. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11197. {
  11198. int rc = 0, error;
  11199. LPFC_MBOXQ_t *mboxq;
  11200. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11201. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11202. if (!mboxq) {
  11203. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11204. "2000 Failed to allocate mbox for "
  11205. "READ_FCF cmd\n");
  11206. error = -ENOMEM;
  11207. goto fail_fcf_scan;
  11208. }
  11209. /* Construct the read FCF record mailbox command */
  11210. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11211. if (rc) {
  11212. error = -EINVAL;
  11213. goto fail_fcf_scan;
  11214. }
  11215. /* Issue the mailbox command asynchronously */
  11216. mboxq->vport = phba->pport;
  11217. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11218. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11219. if (rc == MBX_NOT_FINISHED)
  11220. error = -EIO;
  11221. else {
  11222. spin_lock_irq(&phba->hbalock);
  11223. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11224. spin_unlock_irq(&phba->hbalock);
  11225. /* Reset FCF round robin index bmask for new scan */
  11226. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) {
  11227. memset(phba->fcf.fcf_rr_bmask, 0,
  11228. sizeof(*phba->fcf.fcf_rr_bmask));
  11229. phba->fcf.eligible_fcf_cnt = 0;
  11230. }
  11231. error = 0;
  11232. }
  11233. fail_fcf_scan:
  11234. if (error) {
  11235. if (mboxq)
  11236. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11237. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11238. spin_lock_irq(&phba->hbalock);
  11239. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11240. spin_unlock_irq(&phba->hbalock);
  11241. }
  11242. return error;
  11243. }
  11244. /**
  11245. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11246. * @phba: pointer to lpfc hba data structure.
  11247. * @fcf_index: FCF table entry offset.
  11248. *
  11249. * This routine is invoked to read an FCF record indicated by @fcf_index
  11250. * and to use it for FLOGI round robin FCF failover.
  11251. *
  11252. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11253. * otherwise.
  11254. **/
  11255. int
  11256. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11257. {
  11258. int rc = 0, error;
  11259. LPFC_MBOXQ_t *mboxq;
  11260. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11261. if (!mboxq) {
  11262. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11263. "2763 Failed to allocate mbox for "
  11264. "READ_FCF cmd\n");
  11265. error = -ENOMEM;
  11266. goto fail_fcf_read;
  11267. }
  11268. /* Construct the read FCF record mailbox command */
  11269. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11270. if (rc) {
  11271. error = -EINVAL;
  11272. goto fail_fcf_read;
  11273. }
  11274. /* Issue the mailbox command asynchronously */
  11275. mboxq->vport = phba->pport;
  11276. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11277. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11278. if (rc == MBX_NOT_FINISHED)
  11279. error = -EIO;
  11280. else
  11281. error = 0;
  11282. fail_fcf_read:
  11283. if (error && mboxq)
  11284. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11285. return error;
  11286. }
  11287. /**
  11288. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11289. * @phba: pointer to lpfc hba data structure.
  11290. * @fcf_index: FCF table entry offset.
  11291. *
  11292. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11293. * determine whether it's eligible for FLOGI round robin failover list.
  11294. *
  11295. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11296. * otherwise.
  11297. **/
  11298. int
  11299. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11300. {
  11301. int rc = 0, error;
  11302. LPFC_MBOXQ_t *mboxq;
  11303. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11304. if (!mboxq) {
  11305. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11306. "2758 Failed to allocate mbox for "
  11307. "READ_FCF cmd\n");
  11308. error = -ENOMEM;
  11309. goto fail_fcf_read;
  11310. }
  11311. /* Construct the read FCF record mailbox command */
  11312. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11313. if (rc) {
  11314. error = -EINVAL;
  11315. goto fail_fcf_read;
  11316. }
  11317. /* Issue the mailbox command asynchronously */
  11318. mboxq->vport = phba->pport;
  11319. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11320. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11321. if (rc == MBX_NOT_FINISHED)
  11322. error = -EIO;
  11323. else
  11324. error = 0;
  11325. fail_fcf_read:
  11326. if (error && mboxq)
  11327. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11328. return error;
  11329. }
  11330. /**
  11331. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11332. * @phba: pointer to lpfc hba data structure.
  11333. *
  11334. * This routine is to get the next eligible FCF record index in a round
  11335. * robin fashion. If the next eligible FCF record index equals to the
  11336. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11337. * shall be returned, otherwise, the next eligible FCF record's index
  11338. * shall be returned.
  11339. **/
  11340. uint16_t
  11341. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11342. {
  11343. uint16_t next_fcf_index;
  11344. /* Search from the currently registered FCF index */
  11345. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11346. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11347. phba->fcf.current_rec.fcf_indx);
  11348. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11349. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11350. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11351. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11352. /* Round robin failover stop condition */
  11353. if ((next_fcf_index == phba->fcf.fcf_rr_init_indx) ||
  11354. (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX))
  11355. return LPFC_FCOE_FCF_NEXT_NONE;
  11356. return next_fcf_index;
  11357. }
  11358. /**
  11359. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11360. * @phba: pointer to lpfc hba data structure.
  11361. *
  11362. * This routine sets the FCF record index in to the eligible bmask for
  11363. * round robin failover search. It checks to make sure that the index
  11364. * does not go beyond the range of the driver allocated bmask dimension
  11365. * before setting the bit.
  11366. *
  11367. * Returns 0 if the index bit successfully set, otherwise, it returns
  11368. * -EINVAL.
  11369. **/
  11370. int
  11371. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11372. {
  11373. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11374. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11375. "2610 HBA FCF index reached driver's "
  11376. "book keeping dimension: fcf_index:%d, "
  11377. "driver_bmask_max:%d\n",
  11378. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11379. return -EINVAL;
  11380. }
  11381. /* Set the eligible FCF record index bmask */
  11382. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11383. return 0;
  11384. }
  11385. /**
  11386. * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
  11387. * @phba: pointer to lpfc hba data structure.
  11388. *
  11389. * This routine clears the FCF record index from the eligible bmask for
  11390. * round robin failover search. It checks to make sure that the index
  11391. * does not go beyond the range of the driver allocated bmask dimension
  11392. * before clearing the bit.
  11393. **/
  11394. void
  11395. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11396. {
  11397. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11398. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11399. "2762 HBA FCF index goes beyond driver's "
  11400. "book keeping dimension: fcf_index:%d, "
  11401. "driver_bmask_max:%d\n",
  11402. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11403. return;
  11404. }
  11405. /* Clear the eligible FCF record index bmask */
  11406. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11407. }
  11408. /**
  11409. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11410. * @phba: pointer to lpfc hba data structure.
  11411. *
  11412. * This routine is the completion routine for the rediscover FCF table mailbox
  11413. * command. If the mailbox command returned failure, it will try to stop the
  11414. * FCF rediscover wait timer.
  11415. **/
  11416. void
  11417. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11418. {
  11419. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11420. uint32_t shdr_status, shdr_add_status;
  11421. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11422. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11423. &redisc_fcf->header.cfg_shdr.response);
  11424. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11425. &redisc_fcf->header.cfg_shdr.response);
  11426. if (shdr_status || shdr_add_status) {
  11427. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11428. "2746 Requesting for FCF rediscovery failed "
  11429. "status x%x add_status x%x\n",
  11430. shdr_status, shdr_add_status);
  11431. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11432. spin_lock_irq(&phba->hbalock);
  11433. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11434. spin_unlock_irq(&phba->hbalock);
  11435. /*
  11436. * CVL event triggered FCF rediscover request failed,
  11437. * last resort to re-try current registered FCF entry.
  11438. */
  11439. lpfc_retry_pport_discovery(phba);
  11440. } else {
  11441. spin_lock_irq(&phba->hbalock);
  11442. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11443. spin_unlock_irq(&phba->hbalock);
  11444. /*
  11445. * DEAD FCF event triggered FCF rediscover request
  11446. * failed, last resort to fail over as a link down
  11447. * to FCF registration.
  11448. */
  11449. lpfc_sli4_fcf_dead_failthrough(phba);
  11450. }
  11451. } else {
  11452. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11453. "2775 Start FCF rediscovery quiescent period "
  11454. "wait timer before scaning FCF table\n");
  11455. /*
  11456. * Start FCF rediscovery wait timer for pending FCF
  11457. * before rescan FCF record table.
  11458. */
  11459. lpfc_fcf_redisc_wait_start_timer(phba);
  11460. }
  11461. mempool_free(mbox, phba->mbox_mem_pool);
  11462. }
  11463. /**
  11464. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11465. * @phba: pointer to lpfc hba data structure.
  11466. *
  11467. * This routine is invoked to request for rediscovery of the entire FCF table
  11468. * by the port.
  11469. **/
  11470. int
  11471. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11472. {
  11473. LPFC_MBOXQ_t *mbox;
  11474. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11475. int rc, length;
  11476. /* Cancel retry delay timers to all vports before FCF rediscover */
  11477. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11478. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11479. if (!mbox) {
  11480. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11481. "2745 Failed to allocate mbox for "
  11482. "requesting FCF rediscover.\n");
  11483. return -ENOMEM;
  11484. }
  11485. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11486. sizeof(struct lpfc_sli4_cfg_mhdr));
  11487. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11488. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11489. length, LPFC_SLI4_MBX_EMBED);
  11490. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11491. /* Set count to 0 for invalidating the entire FCF database */
  11492. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11493. /* Issue the mailbox command asynchronously */
  11494. mbox->vport = phba->pport;
  11495. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11496. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11497. if (rc == MBX_NOT_FINISHED) {
  11498. mempool_free(mbox, phba->mbox_mem_pool);
  11499. return -EIO;
  11500. }
  11501. return 0;
  11502. }
  11503. /**
  11504. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11505. * @phba: pointer to lpfc hba data structure.
  11506. *
  11507. * This function is the failover routine as a last resort to the FCF DEAD
  11508. * event when driver failed to perform fast FCF failover.
  11509. **/
  11510. void
  11511. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11512. {
  11513. uint32_t link_state;
  11514. /*
  11515. * Last resort as FCF DEAD event failover will treat this as
  11516. * a link down, but save the link state because we don't want
  11517. * it to be changed to Link Down unless it is already down.
  11518. */
  11519. link_state = phba->link_state;
  11520. lpfc_linkdown(phba);
  11521. phba->link_state = link_state;
  11522. /* Unregister FCF if no devices connected to it */
  11523. lpfc_unregister_unused_fcf(phba);
  11524. }
  11525. /**
  11526. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11527. * @phba: pointer to lpfc hba data structure.
  11528. *
  11529. * This function read region 23 and parse TLV for port status to
  11530. * decide if the user disaled the port. If the TLV indicates the
  11531. * port is disabled, the hba_flag is set accordingly.
  11532. **/
  11533. void
  11534. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11535. {
  11536. LPFC_MBOXQ_t *pmb = NULL;
  11537. MAILBOX_t *mb;
  11538. uint8_t *rgn23_data = NULL;
  11539. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11540. int rc;
  11541. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11542. if (!pmb) {
  11543. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11544. "2600 lpfc_sli_read_serdes_param failed to"
  11545. " allocate mailbox memory\n");
  11546. goto out;
  11547. }
  11548. mb = &pmb->u.mb;
  11549. /* Get adapter Region 23 data */
  11550. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11551. if (!rgn23_data)
  11552. goto out;
  11553. do {
  11554. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11555. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11556. if (rc != MBX_SUCCESS) {
  11557. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11558. "2601 lpfc_sli_read_link_ste failed to"
  11559. " read config region 23 rc 0x%x Status 0x%x\n",
  11560. rc, mb->mbxStatus);
  11561. mb->un.varDmp.word_cnt = 0;
  11562. }
  11563. /*
  11564. * dump mem may return a zero when finished or we got a
  11565. * mailbox error, either way we are done.
  11566. */
  11567. if (mb->un.varDmp.word_cnt == 0)
  11568. break;
  11569. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11570. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11571. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11572. rgn23_data + offset,
  11573. mb->un.varDmp.word_cnt);
  11574. offset += mb->un.varDmp.word_cnt;
  11575. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11576. data_size = offset;
  11577. offset = 0;
  11578. if (!data_size)
  11579. goto out;
  11580. /* Check the region signature first */
  11581. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11582. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11583. "2619 Config region 23 has bad signature\n");
  11584. goto out;
  11585. }
  11586. offset += 4;
  11587. /* Check the data structure version */
  11588. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11589. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11590. "2620 Config region 23 has bad version\n");
  11591. goto out;
  11592. }
  11593. offset += 4;
  11594. /* Parse TLV entries in the region */
  11595. while (offset < data_size) {
  11596. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11597. break;
  11598. /*
  11599. * If the TLV is not driver specific TLV or driver id is
  11600. * not linux driver id, skip the record.
  11601. */
  11602. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11603. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11604. (rgn23_data[offset + 3] != 0)) {
  11605. offset += rgn23_data[offset + 1] * 4 + 4;
  11606. continue;
  11607. }
  11608. /* Driver found a driver specific TLV in the config region */
  11609. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11610. offset += 4;
  11611. tlv_offset = 0;
  11612. /*
  11613. * Search for configured port state sub-TLV.
  11614. */
  11615. while ((offset < data_size) &&
  11616. (tlv_offset < sub_tlv_len)) {
  11617. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11618. offset += 4;
  11619. tlv_offset += 4;
  11620. break;
  11621. }
  11622. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11623. offset += rgn23_data[offset + 1] * 4 + 4;
  11624. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11625. continue;
  11626. }
  11627. /* This HBA contains PORT_STE configured */
  11628. if (!rgn23_data[offset + 2])
  11629. phba->hba_flag |= LINK_DISABLED;
  11630. goto out;
  11631. }
  11632. }
  11633. out:
  11634. if (pmb)
  11635. mempool_free(pmb, phba->mbox_mem_pool);
  11636. kfree(rgn23_data);
  11637. return;
  11638. }
  11639. /**
  11640. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11641. * @vport: pointer to vport data structure.
  11642. *
  11643. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11644. * and REG_VPI mailbox commands associated with the vport. This function
  11645. * is called when driver want to restart discovery of the vport due to
  11646. * a Clear Virtual Link event.
  11647. **/
  11648. void
  11649. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11650. {
  11651. struct lpfc_hba *phba = vport->phba;
  11652. LPFC_MBOXQ_t *mb, *nextmb;
  11653. struct lpfc_dmabuf *mp;
  11654. struct lpfc_nodelist *ndlp;
  11655. spin_lock_irq(&phba->hbalock);
  11656. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11657. if (mb->vport != vport)
  11658. continue;
  11659. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11660. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11661. continue;
  11662. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11663. mp = (struct lpfc_dmabuf *) (mb->context1);
  11664. if (mp) {
  11665. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11666. kfree(mp);
  11667. }
  11668. ndlp = (struct lpfc_nodelist *) mb->context2;
  11669. if (ndlp) {
  11670. lpfc_nlp_put(ndlp);
  11671. mb->context2 = NULL;
  11672. }
  11673. }
  11674. list_del(&mb->list);
  11675. mempool_free(mb, phba->mbox_mem_pool);
  11676. }
  11677. mb = phba->sli.mbox_active;
  11678. if (mb && (mb->vport == vport)) {
  11679. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11680. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11681. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11682. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11683. ndlp = (struct lpfc_nodelist *) mb->context2;
  11684. if (ndlp) {
  11685. lpfc_nlp_put(ndlp);
  11686. mb->context2 = NULL;
  11687. }
  11688. /* Unregister the RPI when mailbox complete */
  11689. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11690. }
  11691. }
  11692. spin_unlock_irq(&phba->hbalock);
  11693. }
  11694. /**
  11695. * lpfc_drain_txq - Drain the txq
  11696. * @phba: Pointer to HBA context object.
  11697. *
  11698. * This function attempt to submit IOCBs on the txq
  11699. * to the adapter. For SLI4 adapters, the txq contains
  11700. * ELS IOCBs that have been deferred because the there
  11701. * are no SGLs. This congestion can occur with large
  11702. * vport counts during node discovery.
  11703. **/
  11704. uint32_t
  11705. lpfc_drain_txq(struct lpfc_hba *phba)
  11706. {
  11707. LIST_HEAD(completions);
  11708. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  11709. struct lpfc_iocbq *piocbq = 0;
  11710. unsigned long iflags = 0;
  11711. char *fail_msg = NULL;
  11712. struct lpfc_sglq *sglq;
  11713. union lpfc_wqe wqe;
  11714. spin_lock_irqsave(&phba->hbalock, iflags);
  11715. if (pring->txq_cnt > pring->txq_max)
  11716. pring->txq_max = pring->txq_cnt;
  11717. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11718. while (pring->txq_cnt) {
  11719. spin_lock_irqsave(&phba->hbalock, iflags);
  11720. sglq = __lpfc_sli_get_sglq(phba);
  11721. if (!sglq) {
  11722. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11723. break;
  11724. } else {
  11725. piocbq = lpfc_sli_ringtx_get(phba, pring);
  11726. if (!piocbq) {
  11727. /* The txq_cnt out of sync. This should
  11728. * never happen
  11729. */
  11730. sglq = __lpfc_clear_active_sglq(phba,
  11731. sglq->sli4_xritag);
  11732. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11733. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11734. "2823 txq empty and txq_cnt is %d\n ",
  11735. pring->txq_cnt);
  11736. break;
  11737. }
  11738. }
  11739. /* The xri and iocb resources secured,
  11740. * attempt to issue request
  11741. */
  11742. piocbq->sli4_xritag = sglq->sli4_xritag;
  11743. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  11744. fail_msg = "to convert bpl to sgl";
  11745. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  11746. fail_msg = "to convert iocb to wqe";
  11747. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  11748. fail_msg = " - Wq is full";
  11749. else
  11750. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  11751. if (fail_msg) {
  11752. /* Failed means we can't issue and need to cancel */
  11753. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11754. "2822 IOCB failed %s iotag 0x%x "
  11755. "xri 0x%x\n",
  11756. fail_msg,
  11757. piocbq->iotag, piocbq->sli4_xritag);
  11758. list_add_tail(&piocbq->list, &completions);
  11759. }
  11760. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11761. }
  11762. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  11763. phba->pport->work_port_events &= ~WORKER_SERVICE_TXQ;
  11764. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  11765. /* Cancel all the IOCBs that cannot be issued */
  11766. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  11767. IOERR_SLI_ABORTED);
  11768. return pring->txq_cnt;
  11769. }