lpfc_sli.c 416 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468
  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(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  92. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  93. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  94. /* Update the host index before invoking device */
  95. host_index = q->host_index;
  96. q->host_index = ((q->host_index + 1) % q->entry_count);
  97. /* Ring Doorbell */
  98. doorbell.word0 = 0;
  99. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  100. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  101. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  102. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  103. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  104. return 0;
  105. }
  106. /**
  107. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  108. * @q: The Work Queue to operate on.
  109. * @index: The index to advance the hba index to.
  110. *
  111. * This routine will update the HBA index of a queue to reflect consumption of
  112. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  113. * an entry the host calls this function to update the queue's internal
  114. * pointers. This routine returns the number of entries that were consumed by
  115. * the HBA.
  116. **/
  117. static uint32_t
  118. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  119. {
  120. uint32_t released = 0;
  121. if (q->hba_index == index)
  122. return 0;
  123. do {
  124. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  125. released++;
  126. } while (q->hba_index != index);
  127. return released;
  128. }
  129. /**
  130. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  131. * @q: The Mailbox Queue to operate on.
  132. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  133. *
  134. * This routine will copy the contents of @mqe to the next available entry on
  135. * the @q. This function will then ring the Work Queue Doorbell to signal the
  136. * HBA to start processing the Work Queue Entry. This function returns 0 if
  137. * successful. If no entries are available on @q then this function will return
  138. * -ENOMEM.
  139. * The caller is expected to hold the hbalock when calling this routine.
  140. **/
  141. static uint32_t
  142. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  143. {
  144. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  145. struct lpfc_register doorbell;
  146. uint32_t host_index;
  147. /* If the host has not yet processed the next entry then we are done */
  148. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  149. return -ENOMEM;
  150. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  151. /* Save off the mailbox pointer for completion */
  152. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  153. /* Update the host index before invoking device */
  154. host_index = q->host_index;
  155. q->host_index = ((q->host_index + 1) % q->entry_count);
  156. /* Ring Doorbell */
  157. doorbell.word0 = 0;
  158. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  159. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  160. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  161. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  162. return 0;
  163. }
  164. /**
  165. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  166. * @q: The Mailbox Queue to operate on.
  167. *
  168. * This routine will update the HBA index of a queue to reflect consumption of
  169. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  170. * an entry the host calls this function to update the queue's internal
  171. * pointers. This routine returns the number of entries that were consumed by
  172. * the HBA.
  173. **/
  174. static uint32_t
  175. lpfc_sli4_mq_release(struct lpfc_queue *q)
  176. {
  177. /* Clear the mailbox pointer for completion */
  178. q->phba->mbox = NULL;
  179. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  180. return 1;
  181. }
  182. /**
  183. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  184. * @q: The Event Queue to get the first valid EQE from
  185. *
  186. * This routine will get the first valid Event Queue Entry from @q, update
  187. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  188. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  189. * processed, but not popped back to the HBA then this routine will return NULL.
  190. **/
  191. static struct lpfc_eqe *
  192. lpfc_sli4_eq_get(struct lpfc_queue *q)
  193. {
  194. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  195. /* If the next EQE is not valid then we are done */
  196. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  197. return NULL;
  198. /* If the host has not yet processed the next entry then we are done */
  199. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  200. return NULL;
  201. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  202. return eqe;
  203. }
  204. /**
  205. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  206. * @q: The Event Queue that the host has completed processing for.
  207. * @arm: Indicates whether the host wants to arms this CQ.
  208. *
  209. * This routine will mark all Event Queue Entries on @q, from the last
  210. * known completed entry to the last entry that was processed, as completed
  211. * by clearing the valid bit for each completion queue entry. Then it will
  212. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  213. * The internal host index in the @q will be updated by this routine to indicate
  214. * that the host has finished processing the entries. The @arm parameter
  215. * indicates that the queue should be rearmed when ringing the doorbell.
  216. *
  217. * This function will return the number of EQEs that were popped.
  218. **/
  219. uint32_t
  220. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  221. {
  222. uint32_t released = 0;
  223. struct lpfc_eqe *temp_eqe;
  224. struct lpfc_register doorbell;
  225. /* while there are valid entries */
  226. while (q->hba_index != q->host_index) {
  227. temp_eqe = q->qe[q->host_index].eqe;
  228. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  229. released++;
  230. q->host_index = ((q->host_index + 1) % q->entry_count);
  231. }
  232. if (unlikely(released == 0 && !arm))
  233. return 0;
  234. /* ring doorbell for number popped */
  235. doorbell.word0 = 0;
  236. if (arm) {
  237. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  238. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  239. }
  240. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  241. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  242. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  243. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  244. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  245. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  246. readl(q->phba->sli4_hba.EQCQDBregaddr);
  247. return released;
  248. }
  249. /**
  250. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  251. * @q: The Completion Queue to get the first valid CQE from
  252. *
  253. * This routine will get the first valid Completion Queue Entry from @q, update
  254. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  255. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  256. * processed, but not popped back to the HBA then this routine will return NULL.
  257. **/
  258. static struct lpfc_cqe *
  259. lpfc_sli4_cq_get(struct lpfc_queue *q)
  260. {
  261. struct lpfc_cqe *cqe;
  262. /* If the next CQE is not valid then we are done */
  263. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  264. return NULL;
  265. /* If the host has not yet processed the next entry then we are done */
  266. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  267. return NULL;
  268. cqe = q->qe[q->hba_index].cqe;
  269. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  270. return cqe;
  271. }
  272. /**
  273. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  274. * @q: The Completion Queue that the host has completed processing for.
  275. * @arm: Indicates whether the host wants to arms this CQ.
  276. *
  277. * This routine will mark all Completion queue entries on @q, from the last
  278. * known completed entry to the last entry that was processed, as completed
  279. * by clearing the valid bit for each completion queue entry. Then it will
  280. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  281. * The internal host index in the @q will be updated by this routine to indicate
  282. * that the host has finished processing the entries. The @arm parameter
  283. * indicates that the queue should be rearmed when ringing the doorbell.
  284. *
  285. * This function will return the number of CQEs that were released.
  286. **/
  287. uint32_t
  288. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  289. {
  290. uint32_t released = 0;
  291. struct lpfc_cqe *temp_qe;
  292. struct lpfc_register doorbell;
  293. /* while there are valid entries */
  294. while (q->hba_index != q->host_index) {
  295. temp_qe = q->qe[q->host_index].cqe;
  296. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  297. released++;
  298. q->host_index = ((q->host_index + 1) % q->entry_count);
  299. }
  300. if (unlikely(released == 0 && !arm))
  301. return 0;
  302. /* ring doorbell for number popped */
  303. doorbell.word0 = 0;
  304. if (arm)
  305. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  306. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  307. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  308. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  309. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  310. return released;
  311. }
  312. /**
  313. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  314. * @q: The Header Receive Queue to operate on.
  315. * @wqe: The Receive Queue Entry to put on the Receive queue.
  316. *
  317. * This routine will copy the contents of @wqe to the next available entry on
  318. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  319. * HBA to start processing the Receive Queue Entry. This function returns the
  320. * index that the rqe was copied to if successful. If no entries are available
  321. * on @q then this function will return -ENOMEM.
  322. * The caller is expected to hold the hbalock when calling this routine.
  323. **/
  324. static int
  325. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  326. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  327. {
  328. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  329. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  330. struct lpfc_register doorbell;
  331. int put_index = hq->host_index;
  332. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  333. return -EINVAL;
  334. if (hq->host_index != dq->host_index)
  335. return -EINVAL;
  336. /* If the host has not yet processed the next entry then we are done */
  337. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  338. return -EBUSY;
  339. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  340. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  341. /* Update the host index to point to the next slot */
  342. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  343. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  344. /* Ring The Header Receive Queue Doorbell */
  345. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  346. doorbell.word0 = 0;
  347. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  348. LPFC_RQ_POST_BATCH);
  349. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  350. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  351. }
  352. return put_index;
  353. }
  354. /**
  355. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  356. * @q: The Header Receive Queue to operate on.
  357. *
  358. * This routine will update the HBA index of a queue to reflect consumption of
  359. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  360. * consumed an entry the host calls this function to update the queue's
  361. * internal pointers. This routine returns the number of entries that were
  362. * consumed by the HBA.
  363. **/
  364. static uint32_t
  365. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  366. {
  367. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  368. return 0;
  369. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  370. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  371. return 1;
  372. }
  373. /**
  374. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  375. * @phba: Pointer to HBA context object.
  376. * @pring: Pointer to driver SLI ring object.
  377. *
  378. * This function returns pointer to next command iocb entry
  379. * in the command ring. The caller must hold hbalock to prevent
  380. * other threads consume the next command iocb.
  381. * SLI-2/SLI-3 provide different sized iocbs.
  382. **/
  383. static inline IOCB_t *
  384. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  385. {
  386. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  387. pring->cmdidx * phba->iocb_cmd_size);
  388. }
  389. /**
  390. * lpfc_resp_iocb - Get next response iocb entry in the ring
  391. * @phba: Pointer to HBA context object.
  392. * @pring: Pointer to driver SLI ring object.
  393. *
  394. * This function returns pointer to next response iocb entry
  395. * in the response ring. The caller must hold hbalock to make sure
  396. * that no other thread consume the next response iocb.
  397. * SLI-2/SLI-3 provide different sized iocbs.
  398. **/
  399. static inline IOCB_t *
  400. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  401. {
  402. return (IOCB_t *) (((char *) pring->rspringaddr) +
  403. pring->rspidx * phba->iocb_rsp_size);
  404. }
  405. /**
  406. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  407. * @phba: Pointer to HBA context object.
  408. *
  409. * This function is called with hbalock held. This function
  410. * allocates a new driver iocb object from the iocb pool. If the
  411. * allocation is successful, it returns pointer to the newly
  412. * allocated iocb object else it returns NULL.
  413. **/
  414. static struct lpfc_iocbq *
  415. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  416. {
  417. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  418. struct lpfc_iocbq * iocbq = NULL;
  419. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  420. if (iocbq)
  421. phba->iocb_cnt++;
  422. if (phba->iocb_cnt > phba->iocb_max)
  423. phba->iocb_max = phba->iocb_cnt;
  424. return iocbq;
  425. }
  426. /**
  427. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  428. * @phba: Pointer to HBA context object.
  429. * @xritag: XRI value.
  430. *
  431. * This function clears the sglq pointer from the array of acive
  432. * sglq's. The xritag that is passed in is used to index into the
  433. * array. Before the xritag can be used it needs to be adjusted
  434. * by subtracting the xribase.
  435. *
  436. * Returns sglq ponter = success, NULL = Failure.
  437. **/
  438. static struct lpfc_sglq *
  439. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  440. {
  441. uint16_t adj_xri;
  442. struct lpfc_sglq *sglq;
  443. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  444. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  445. return NULL;
  446. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  447. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  448. return sglq;
  449. }
  450. /**
  451. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  452. * @phba: Pointer to HBA context object.
  453. * @xritag: XRI value.
  454. *
  455. * This function returns the sglq pointer from the array of acive
  456. * sglq's. The xritag that is passed in is used to index into the
  457. * array. Before the xritag can be used it needs to be adjusted
  458. * by subtracting the xribase.
  459. *
  460. * Returns sglq ponter = success, NULL = Failure.
  461. **/
  462. struct lpfc_sglq *
  463. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  464. {
  465. uint16_t adj_xri;
  466. struct lpfc_sglq *sglq;
  467. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  468. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  469. return NULL;
  470. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  471. return sglq;
  472. }
  473. /**
  474. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  475. * @phba: Pointer to HBA context object.
  476. * @ndlp: nodelist pointer for this target.
  477. * @xritag: xri used in this exchange.
  478. * @rxid: Remote Exchange ID.
  479. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  480. *
  481. * This function is called with hbalock held.
  482. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  483. * rrq struct and adds it to the active_rrq_list.
  484. *
  485. * returns 0 for rrq slot for this xri
  486. * < 0 Were not able to get rrq mem or invalid parameter.
  487. **/
  488. static int
  489. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  490. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  491. {
  492. uint16_t adj_xri;
  493. struct lpfc_node_rrq *rrq;
  494. int empty;
  495. uint32_t did = 0;
  496. if (!ndlp)
  497. return -EINVAL;
  498. if (!phba->cfg_enable_rrq)
  499. return -EINVAL;
  500. if (phba->pport->load_flag & FC_UNLOADING) {
  501. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  502. goto out;
  503. }
  504. did = ndlp->nlp_DID;
  505. /*
  506. * set the active bit even if there is no mem available.
  507. */
  508. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  509. if (NLP_CHK_FREE_REQ(ndlp))
  510. goto out;
  511. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  512. goto out;
  513. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  514. goto out;
  515. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  516. if (rrq) {
  517. rrq->send_rrq = send_rrq;
  518. rrq->xritag = xritag;
  519. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  520. rrq->ndlp = ndlp;
  521. rrq->nlp_DID = ndlp->nlp_DID;
  522. rrq->vport = ndlp->vport;
  523. rrq->rxid = rxid;
  524. empty = list_empty(&phba->active_rrq_list);
  525. rrq->send_rrq = send_rrq;
  526. list_add_tail(&rrq->list, &phba->active_rrq_list);
  527. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  528. phba->hba_flag |= HBA_RRQ_ACTIVE;
  529. if (empty)
  530. lpfc_worker_wake_up(phba);
  531. }
  532. return 0;
  533. }
  534. out:
  535. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  536. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  537. " DID:0x%x Send:%d\n",
  538. xritag, rxid, did, send_rrq);
  539. return -EINVAL;
  540. }
  541. /**
  542. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  543. * @phba: Pointer to HBA context object.
  544. * @xritag: xri used in this exchange.
  545. * @rrq: The RRQ to be cleared.
  546. *
  547. **/
  548. void
  549. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  550. uint16_t xritag,
  551. struct lpfc_node_rrq *rrq)
  552. {
  553. uint16_t adj_xri;
  554. struct lpfc_nodelist *ndlp = NULL;
  555. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  556. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  557. /* The target DID could have been swapped (cable swap)
  558. * we should use the ndlp from the findnode if it is
  559. * available.
  560. */
  561. if ((!ndlp) && rrq->ndlp)
  562. ndlp = rrq->ndlp;
  563. if (!ndlp)
  564. goto out;
  565. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  566. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  567. rrq->send_rrq = 0;
  568. rrq->xritag = 0;
  569. rrq->rrq_stop_time = 0;
  570. }
  571. out:
  572. mempool_free(rrq, phba->rrq_pool);
  573. }
  574. /**
  575. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  576. * @phba: Pointer to HBA context object.
  577. *
  578. * This function is called with hbalock held. This function
  579. * Checks if stop_time (ratov from setting rrq active) has
  580. * been reached, if it has and the send_rrq flag is set then
  581. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  582. * then it will just call the routine to clear the rrq and
  583. * free the rrq resource.
  584. * The timer is set to the next rrq that is going to expire before
  585. * leaving the routine.
  586. *
  587. **/
  588. void
  589. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  590. {
  591. struct lpfc_node_rrq *rrq;
  592. struct lpfc_node_rrq *nextrrq;
  593. unsigned long next_time;
  594. unsigned long iflags;
  595. LIST_HEAD(send_rrq);
  596. spin_lock_irqsave(&phba->hbalock, iflags);
  597. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  598. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  599. list_for_each_entry_safe(rrq, nextrrq,
  600. &phba->active_rrq_list, list) {
  601. if (time_after(jiffies, rrq->rrq_stop_time))
  602. list_move(&rrq->list, &send_rrq);
  603. else if (time_before(rrq->rrq_stop_time, next_time))
  604. next_time = rrq->rrq_stop_time;
  605. }
  606. spin_unlock_irqrestore(&phba->hbalock, iflags);
  607. if (!list_empty(&phba->active_rrq_list))
  608. mod_timer(&phba->rrq_tmr, next_time);
  609. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  610. list_del(&rrq->list);
  611. if (!rrq->send_rrq)
  612. /* this call will free the rrq */
  613. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  614. else if (lpfc_send_rrq(phba, rrq)) {
  615. /* if we send the rrq then the completion handler
  616. * will clear the bit in the xribitmap.
  617. */
  618. lpfc_clr_rrq_active(phba, rrq->xritag,
  619. rrq);
  620. }
  621. }
  622. }
  623. /**
  624. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  625. * @vport: Pointer to vport context object.
  626. * @xri: The xri used in the exchange.
  627. * @did: The targets DID for this exchange.
  628. *
  629. * returns NULL = rrq not found in the phba->active_rrq_list.
  630. * rrq = rrq for this xri and target.
  631. **/
  632. struct lpfc_node_rrq *
  633. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  634. {
  635. struct lpfc_hba *phba = vport->phba;
  636. struct lpfc_node_rrq *rrq;
  637. struct lpfc_node_rrq *nextrrq;
  638. unsigned long iflags;
  639. if (phba->sli_rev != LPFC_SLI_REV4)
  640. return NULL;
  641. spin_lock_irqsave(&phba->hbalock, iflags);
  642. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  643. if (rrq->vport == vport && rrq->xritag == xri &&
  644. rrq->nlp_DID == did){
  645. list_del(&rrq->list);
  646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  647. return rrq;
  648. }
  649. }
  650. spin_unlock_irqrestore(&phba->hbalock, iflags);
  651. return NULL;
  652. }
  653. /**
  654. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  655. * @vport: Pointer to vport context object.
  656. * @ndlp: Pointer to the lpfc_node_list structure.
  657. * If ndlp is NULL Remove all active RRQs for this vport from the
  658. * phba->active_rrq_list and clear the rrq.
  659. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  660. **/
  661. void
  662. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  663. {
  664. struct lpfc_hba *phba = vport->phba;
  665. struct lpfc_node_rrq *rrq;
  666. struct lpfc_node_rrq *nextrrq;
  667. unsigned long iflags;
  668. LIST_HEAD(rrq_list);
  669. if (phba->sli_rev != LPFC_SLI_REV4)
  670. return;
  671. if (!ndlp) {
  672. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  673. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  674. }
  675. spin_lock_irqsave(&phba->hbalock, iflags);
  676. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  677. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  678. list_move(&rrq->list, &rrq_list);
  679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  680. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  681. list_del(&rrq->list);
  682. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  683. }
  684. }
  685. /**
  686. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  687. * @phba: Pointer to HBA context object.
  688. *
  689. * Remove all rrqs from the phba->active_rrq_list and free them by
  690. * calling __lpfc_clr_active_rrq
  691. *
  692. **/
  693. void
  694. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  695. {
  696. struct lpfc_node_rrq *rrq;
  697. struct lpfc_node_rrq *nextrrq;
  698. unsigned long next_time;
  699. unsigned long iflags;
  700. LIST_HEAD(rrq_list);
  701. if (phba->sli_rev != LPFC_SLI_REV4)
  702. return;
  703. spin_lock_irqsave(&phba->hbalock, iflags);
  704. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  705. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  706. list_splice_init(&phba->active_rrq_list, &rrq_list);
  707. spin_unlock_irqrestore(&phba->hbalock, iflags);
  708. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  709. list_del(&rrq->list);
  710. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  711. }
  712. if (!list_empty(&phba->active_rrq_list))
  713. mod_timer(&phba->rrq_tmr, next_time);
  714. }
  715. /**
  716. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  717. * @phba: Pointer to HBA context object.
  718. * @ndlp: Targets nodelist pointer for this exchange.
  719. * @xritag the xri in the bitmap to test.
  720. *
  721. * This function is called with hbalock held. This function
  722. * returns 0 = rrq not active for this xri
  723. * 1 = rrq is valid for this xri.
  724. **/
  725. int
  726. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  727. uint16_t xritag)
  728. {
  729. uint16_t adj_xri;
  730. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  731. if (!ndlp)
  732. return 0;
  733. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  734. return 1;
  735. else
  736. return 0;
  737. }
  738. /**
  739. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  740. * @phba: Pointer to HBA context object.
  741. * @ndlp: nodelist pointer for this target.
  742. * @xritag: xri used in this exchange.
  743. * @rxid: Remote Exchange ID.
  744. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  745. *
  746. * This function takes the hbalock.
  747. * The active bit is always set in the active rrq xri_bitmap even
  748. * if there is no slot avaiable for the other rrq information.
  749. *
  750. * returns 0 rrq actived for this xri
  751. * < 0 No memory or invalid ndlp.
  752. **/
  753. int
  754. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  755. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  756. {
  757. int ret;
  758. unsigned long iflags;
  759. spin_lock_irqsave(&phba->hbalock, iflags);
  760. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  761. spin_unlock_irqrestore(&phba->hbalock, iflags);
  762. return ret;
  763. }
  764. /**
  765. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  766. * @phba: Pointer to HBA context object.
  767. * @piocb: Pointer to the iocbq.
  768. *
  769. * This function is called with hbalock held. This function
  770. * Gets a new driver sglq object from the sglq list. If the
  771. * list is not empty then it is successful, it returns pointer to the newly
  772. * allocated sglq object else it returns NULL.
  773. **/
  774. static struct lpfc_sglq *
  775. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  776. {
  777. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  778. struct lpfc_sglq *sglq = NULL;
  779. struct lpfc_sglq *start_sglq = NULL;
  780. uint16_t adj_xri;
  781. struct lpfc_scsi_buf *lpfc_cmd;
  782. struct lpfc_nodelist *ndlp;
  783. int found = 0;
  784. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  785. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  786. ndlp = lpfc_cmd->rdata->pnode;
  787. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  788. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  789. ndlp = piocbq->context_un.ndlp;
  790. else
  791. ndlp = piocbq->context1;
  792. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  793. start_sglq = sglq;
  794. while (!found) {
  795. if (!sglq)
  796. return NULL;
  797. adj_xri = sglq->sli4_xritag -
  798. phba->sli4_hba.max_cfg_param.xri_base;
  799. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  800. /* This xri has an rrq outstanding for this DID.
  801. * put it back in the list and get another xri.
  802. */
  803. list_add_tail(&sglq->list, lpfc_sgl_list);
  804. sglq = NULL;
  805. list_remove_head(lpfc_sgl_list, sglq,
  806. struct lpfc_sglq, list);
  807. if (sglq == start_sglq) {
  808. sglq = NULL;
  809. break;
  810. } else
  811. continue;
  812. }
  813. sglq->ndlp = ndlp;
  814. found = 1;
  815. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  816. sglq->state = SGL_ALLOCATED;
  817. }
  818. return sglq;
  819. }
  820. /**
  821. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  822. * @phba: Pointer to HBA context object.
  823. *
  824. * This function is called with no lock held. This function
  825. * allocates a new driver iocb object from the iocb pool. If the
  826. * allocation is successful, it returns pointer to the newly
  827. * allocated iocb object else it returns NULL.
  828. **/
  829. struct lpfc_iocbq *
  830. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  831. {
  832. struct lpfc_iocbq * iocbq = NULL;
  833. unsigned long iflags;
  834. spin_lock_irqsave(&phba->hbalock, iflags);
  835. iocbq = __lpfc_sli_get_iocbq(phba);
  836. spin_unlock_irqrestore(&phba->hbalock, iflags);
  837. return iocbq;
  838. }
  839. /**
  840. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  841. * @phba: Pointer to HBA context object.
  842. * @iocbq: Pointer to driver iocb object.
  843. *
  844. * This function is called with hbalock held to release driver
  845. * iocb object to the iocb pool. The iotag in the iocb object
  846. * does not change for each use of the iocb object. This function
  847. * clears all other fields of the iocb object when it is freed.
  848. * The sqlq structure that holds the xritag and phys and virtual
  849. * mappings for the scatter gather list is retrieved from the
  850. * active array of sglq. The get of the sglq pointer also clears
  851. * the entry in the array. If the status of the IO indiactes that
  852. * this IO was aborted then the sglq entry it put on the
  853. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  854. * IO has good status or fails for any other reason then the sglq
  855. * entry is added to the free list (lpfc_sgl_list).
  856. **/
  857. static void
  858. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  859. {
  860. struct lpfc_sglq *sglq;
  861. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  862. unsigned long iflag = 0;
  863. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  864. if (iocbq->sli4_xritag == NO_XRI)
  865. sglq = NULL;
  866. else
  867. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  868. if (sglq) {
  869. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  870. (sglq->state != SGL_XRI_ABORTED)) {
  871. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  872. iflag);
  873. list_add(&sglq->list,
  874. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  875. spin_unlock_irqrestore(
  876. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  877. } else {
  878. sglq->state = SGL_FREED;
  879. sglq->ndlp = NULL;
  880. list_add_tail(&sglq->list,
  881. &phba->sli4_hba.lpfc_sgl_list);
  882. /* Check if TXQ queue needs to be serviced */
  883. if (pring->txq_cnt)
  884. lpfc_worker_wake_up(phba);
  885. }
  886. }
  887. /*
  888. * Clean all volatile data fields, preserve iotag and node struct.
  889. */
  890. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  891. iocbq->sli4_xritag = NO_XRI;
  892. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  893. }
  894. /**
  895. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  896. * @phba: Pointer to HBA context object.
  897. * @iocbq: Pointer to driver iocb object.
  898. *
  899. * This function is called with hbalock held to release driver
  900. * iocb object to the iocb pool. The iotag in the iocb object
  901. * does not change for each use of the iocb object. This function
  902. * clears all other fields of the iocb object when it is freed.
  903. **/
  904. static void
  905. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  906. {
  907. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  908. /*
  909. * Clean all volatile data fields, preserve iotag and node struct.
  910. */
  911. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  912. iocbq->sli4_xritag = NO_XRI;
  913. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  914. }
  915. /**
  916. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  917. * @phba: Pointer to HBA context object.
  918. * @iocbq: Pointer to driver iocb object.
  919. *
  920. * This function is called with hbalock held to release driver
  921. * iocb object to the iocb pool. The iotag in the iocb object
  922. * does not change for each use of the iocb object. This function
  923. * clears all other fields of the iocb object when it is freed.
  924. **/
  925. static void
  926. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  927. {
  928. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  929. phba->iocb_cnt--;
  930. }
  931. /**
  932. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  933. * @phba: Pointer to HBA context object.
  934. * @iocbq: Pointer to driver iocb object.
  935. *
  936. * This function is called with no lock held to release the iocb to
  937. * iocb pool.
  938. **/
  939. void
  940. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  941. {
  942. unsigned long iflags;
  943. /*
  944. * Clean all volatile data fields, preserve iotag and node struct.
  945. */
  946. spin_lock_irqsave(&phba->hbalock, iflags);
  947. __lpfc_sli_release_iocbq(phba, iocbq);
  948. spin_unlock_irqrestore(&phba->hbalock, iflags);
  949. }
  950. /**
  951. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  952. * @phba: Pointer to HBA context object.
  953. * @iocblist: List of IOCBs.
  954. * @ulpstatus: ULP status in IOCB command field.
  955. * @ulpWord4: ULP word-4 in IOCB command field.
  956. *
  957. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  958. * on the list by invoking the complete callback function associated with the
  959. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  960. * fields.
  961. **/
  962. void
  963. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  964. uint32_t ulpstatus, uint32_t ulpWord4)
  965. {
  966. struct lpfc_iocbq *piocb;
  967. while (!list_empty(iocblist)) {
  968. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  969. if (!piocb->iocb_cmpl)
  970. lpfc_sli_release_iocbq(phba, piocb);
  971. else {
  972. piocb->iocb.ulpStatus = ulpstatus;
  973. piocb->iocb.un.ulpWord[4] = ulpWord4;
  974. (piocb->iocb_cmpl) (phba, piocb, piocb);
  975. }
  976. }
  977. return;
  978. }
  979. /**
  980. * lpfc_sli_iocb_cmd_type - Get the iocb type
  981. * @iocb_cmnd: iocb command code.
  982. *
  983. * This function is called by ring event handler function to get the iocb type.
  984. * This function translates the iocb command to an iocb command type used to
  985. * decide the final disposition of each completed IOCB.
  986. * The function returns
  987. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  988. * LPFC_SOL_IOCB if it is a solicited iocb completion
  989. * LPFC_ABORT_IOCB if it is an abort iocb
  990. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  991. *
  992. * The caller is not required to hold any lock.
  993. **/
  994. static lpfc_iocb_type
  995. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  996. {
  997. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  998. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  999. return 0;
  1000. switch (iocb_cmnd) {
  1001. case CMD_XMIT_SEQUENCE_CR:
  1002. case CMD_XMIT_SEQUENCE_CX:
  1003. case CMD_XMIT_BCAST_CN:
  1004. case CMD_XMIT_BCAST_CX:
  1005. case CMD_ELS_REQUEST_CR:
  1006. case CMD_ELS_REQUEST_CX:
  1007. case CMD_CREATE_XRI_CR:
  1008. case CMD_CREATE_XRI_CX:
  1009. case CMD_GET_RPI_CN:
  1010. case CMD_XMIT_ELS_RSP_CX:
  1011. case CMD_GET_RPI_CR:
  1012. case CMD_FCP_IWRITE_CR:
  1013. case CMD_FCP_IWRITE_CX:
  1014. case CMD_FCP_IREAD_CR:
  1015. case CMD_FCP_IREAD_CX:
  1016. case CMD_FCP_ICMND_CR:
  1017. case CMD_FCP_ICMND_CX:
  1018. case CMD_FCP_TSEND_CX:
  1019. case CMD_FCP_TRSP_CX:
  1020. case CMD_FCP_TRECEIVE_CX:
  1021. case CMD_FCP_AUTO_TRSP_CX:
  1022. case CMD_ADAPTER_MSG:
  1023. case CMD_ADAPTER_DUMP:
  1024. case CMD_XMIT_SEQUENCE64_CR:
  1025. case CMD_XMIT_SEQUENCE64_CX:
  1026. case CMD_XMIT_BCAST64_CN:
  1027. case CMD_XMIT_BCAST64_CX:
  1028. case CMD_ELS_REQUEST64_CR:
  1029. case CMD_ELS_REQUEST64_CX:
  1030. case CMD_FCP_IWRITE64_CR:
  1031. case CMD_FCP_IWRITE64_CX:
  1032. case CMD_FCP_IREAD64_CR:
  1033. case CMD_FCP_IREAD64_CX:
  1034. case CMD_FCP_ICMND64_CR:
  1035. case CMD_FCP_ICMND64_CX:
  1036. case CMD_FCP_TSEND64_CX:
  1037. case CMD_FCP_TRSP64_CX:
  1038. case CMD_FCP_TRECEIVE64_CX:
  1039. case CMD_GEN_REQUEST64_CR:
  1040. case CMD_GEN_REQUEST64_CX:
  1041. case CMD_XMIT_ELS_RSP64_CX:
  1042. case DSSCMD_IWRITE64_CR:
  1043. case DSSCMD_IWRITE64_CX:
  1044. case DSSCMD_IREAD64_CR:
  1045. case DSSCMD_IREAD64_CX:
  1046. type = LPFC_SOL_IOCB;
  1047. break;
  1048. case CMD_ABORT_XRI_CN:
  1049. case CMD_ABORT_XRI_CX:
  1050. case CMD_CLOSE_XRI_CN:
  1051. case CMD_CLOSE_XRI_CX:
  1052. case CMD_XRI_ABORTED_CX:
  1053. case CMD_ABORT_MXRI64_CN:
  1054. case CMD_XMIT_BLS_RSP64_CX:
  1055. type = LPFC_ABORT_IOCB;
  1056. break;
  1057. case CMD_RCV_SEQUENCE_CX:
  1058. case CMD_RCV_ELS_REQ_CX:
  1059. case CMD_RCV_SEQUENCE64_CX:
  1060. case CMD_RCV_ELS_REQ64_CX:
  1061. case CMD_ASYNC_STATUS:
  1062. case CMD_IOCB_RCV_SEQ64_CX:
  1063. case CMD_IOCB_RCV_ELS64_CX:
  1064. case CMD_IOCB_RCV_CONT64_CX:
  1065. case CMD_IOCB_RET_XRI64_CX:
  1066. type = LPFC_UNSOL_IOCB;
  1067. break;
  1068. case CMD_IOCB_XMIT_MSEQ64_CR:
  1069. case CMD_IOCB_XMIT_MSEQ64_CX:
  1070. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1071. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1072. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1073. case CMD_IOCB_ABORT_EXTENDED_CN:
  1074. case CMD_IOCB_RET_HBQE64_CN:
  1075. case CMD_IOCB_FCP_IBIDIR64_CR:
  1076. case CMD_IOCB_FCP_IBIDIR64_CX:
  1077. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1078. case CMD_IOCB_LOGENTRY_CN:
  1079. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1080. printk("%s - Unhandled SLI-3 Command x%x\n",
  1081. __func__, iocb_cmnd);
  1082. type = LPFC_UNKNOWN_IOCB;
  1083. break;
  1084. default:
  1085. type = LPFC_UNKNOWN_IOCB;
  1086. break;
  1087. }
  1088. return type;
  1089. }
  1090. /**
  1091. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1092. * @phba: Pointer to HBA context object.
  1093. *
  1094. * This function is called from SLI initialization code
  1095. * to configure every ring of the HBA's SLI interface. The
  1096. * caller is not required to hold any lock. This function issues
  1097. * a config_ring mailbox command for each ring.
  1098. * This function returns zero if successful else returns a negative
  1099. * error code.
  1100. **/
  1101. static int
  1102. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1103. {
  1104. struct lpfc_sli *psli = &phba->sli;
  1105. LPFC_MBOXQ_t *pmb;
  1106. MAILBOX_t *pmbox;
  1107. int i, rc, ret = 0;
  1108. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1109. if (!pmb)
  1110. return -ENOMEM;
  1111. pmbox = &pmb->u.mb;
  1112. phba->link_state = LPFC_INIT_MBX_CMDS;
  1113. for (i = 0; i < psli->num_rings; i++) {
  1114. lpfc_config_ring(phba, i, pmb);
  1115. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1116. if (rc != MBX_SUCCESS) {
  1117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1118. "0446 Adapter failed to init (%d), "
  1119. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1120. "ring %d\n",
  1121. rc, pmbox->mbxCommand,
  1122. pmbox->mbxStatus, i);
  1123. phba->link_state = LPFC_HBA_ERROR;
  1124. ret = -ENXIO;
  1125. break;
  1126. }
  1127. }
  1128. mempool_free(pmb, phba->mbox_mem_pool);
  1129. return ret;
  1130. }
  1131. /**
  1132. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1133. * @phba: Pointer to HBA context object.
  1134. * @pring: Pointer to driver SLI ring object.
  1135. * @piocb: Pointer to the driver iocb object.
  1136. *
  1137. * This function is called with hbalock held. The function adds the
  1138. * new iocb to txcmplq of the given ring. This function always returns
  1139. * 0. If this function is called for ELS ring, this function checks if
  1140. * there is a vport associated with the ELS command. This function also
  1141. * starts els_tmofunc timer if this is an ELS command.
  1142. **/
  1143. static int
  1144. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1145. struct lpfc_iocbq *piocb)
  1146. {
  1147. list_add_tail(&piocb->list, &pring->txcmplq);
  1148. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1149. pring->txcmplq_cnt++;
  1150. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1151. pring->txcmplq_max = pring->txcmplq_cnt;
  1152. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1153. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1154. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1155. if (!piocb->vport)
  1156. BUG();
  1157. else
  1158. mod_timer(&piocb->vport->els_tmofunc,
  1159. jiffies + HZ * (phba->fc_ratov << 1));
  1160. }
  1161. return 0;
  1162. }
  1163. /**
  1164. * lpfc_sli_ringtx_get - Get first element of the txq
  1165. * @phba: Pointer to HBA context object.
  1166. * @pring: Pointer to driver SLI ring object.
  1167. *
  1168. * This function is called with hbalock held to get next
  1169. * iocb in txq of the given ring. If there is any iocb in
  1170. * the txq, the function returns first iocb in the list after
  1171. * removing the iocb from the list, else it returns NULL.
  1172. **/
  1173. struct lpfc_iocbq *
  1174. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1175. {
  1176. struct lpfc_iocbq *cmd_iocb;
  1177. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1178. if (cmd_iocb != NULL)
  1179. pring->txq_cnt--;
  1180. return cmd_iocb;
  1181. }
  1182. /**
  1183. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1184. * @phba: Pointer to HBA context object.
  1185. * @pring: Pointer to driver SLI ring object.
  1186. *
  1187. * This function is called with hbalock held and the caller must post the
  1188. * iocb without releasing the lock. If the caller releases the lock,
  1189. * iocb slot returned by the function is not guaranteed to be available.
  1190. * The function returns pointer to the next available iocb slot if there
  1191. * is available slot in the ring, else it returns NULL.
  1192. * If the get index of the ring is ahead of the put index, the function
  1193. * will post an error attention event to the worker thread to take the
  1194. * HBA to offline state.
  1195. **/
  1196. static IOCB_t *
  1197. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1198. {
  1199. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1200. uint32_t max_cmd_idx = pring->numCiocb;
  1201. if ((pring->next_cmdidx == pring->cmdidx) &&
  1202. (++pring->next_cmdidx >= max_cmd_idx))
  1203. pring->next_cmdidx = 0;
  1204. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1205. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1206. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1207. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1208. "0315 Ring %d issue: portCmdGet %d "
  1209. "is bigger than cmd ring %d\n",
  1210. pring->ringno,
  1211. pring->local_getidx, max_cmd_idx);
  1212. phba->link_state = LPFC_HBA_ERROR;
  1213. /*
  1214. * All error attention handlers are posted to
  1215. * worker thread
  1216. */
  1217. phba->work_ha |= HA_ERATT;
  1218. phba->work_hs = HS_FFER3;
  1219. lpfc_worker_wake_up(phba);
  1220. return NULL;
  1221. }
  1222. if (pring->local_getidx == pring->next_cmdidx)
  1223. return NULL;
  1224. }
  1225. return lpfc_cmd_iocb(phba, pring);
  1226. }
  1227. /**
  1228. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1229. * @phba: Pointer to HBA context object.
  1230. * @iocbq: Pointer to driver iocb object.
  1231. *
  1232. * This function gets an iotag for the iocb. If there is no unused iotag and
  1233. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1234. * array and assigns a new iotag.
  1235. * The function returns the allocated iotag if successful, else returns zero.
  1236. * Zero is not a valid iotag.
  1237. * The caller is not required to hold any lock.
  1238. **/
  1239. uint16_t
  1240. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1241. {
  1242. struct lpfc_iocbq **new_arr;
  1243. struct lpfc_iocbq **old_arr;
  1244. size_t new_len;
  1245. struct lpfc_sli *psli = &phba->sli;
  1246. uint16_t iotag;
  1247. spin_lock_irq(&phba->hbalock);
  1248. iotag = psli->last_iotag;
  1249. if(++iotag < psli->iocbq_lookup_len) {
  1250. psli->last_iotag = iotag;
  1251. psli->iocbq_lookup[iotag] = iocbq;
  1252. spin_unlock_irq(&phba->hbalock);
  1253. iocbq->iotag = iotag;
  1254. return iotag;
  1255. } else if (psli->iocbq_lookup_len < (0xffff
  1256. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1257. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1258. spin_unlock_irq(&phba->hbalock);
  1259. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1260. GFP_KERNEL);
  1261. if (new_arr) {
  1262. spin_lock_irq(&phba->hbalock);
  1263. old_arr = psli->iocbq_lookup;
  1264. if (new_len <= psli->iocbq_lookup_len) {
  1265. /* highly unprobable case */
  1266. kfree(new_arr);
  1267. iotag = psli->last_iotag;
  1268. if(++iotag < psli->iocbq_lookup_len) {
  1269. psli->last_iotag = iotag;
  1270. psli->iocbq_lookup[iotag] = iocbq;
  1271. spin_unlock_irq(&phba->hbalock);
  1272. iocbq->iotag = iotag;
  1273. return iotag;
  1274. }
  1275. spin_unlock_irq(&phba->hbalock);
  1276. return 0;
  1277. }
  1278. if (psli->iocbq_lookup)
  1279. memcpy(new_arr, old_arr,
  1280. ((psli->last_iotag + 1) *
  1281. sizeof (struct lpfc_iocbq *)));
  1282. psli->iocbq_lookup = new_arr;
  1283. psli->iocbq_lookup_len = new_len;
  1284. psli->last_iotag = iotag;
  1285. psli->iocbq_lookup[iotag] = iocbq;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. iocbq->iotag = iotag;
  1288. kfree(old_arr);
  1289. return iotag;
  1290. }
  1291. } else
  1292. spin_unlock_irq(&phba->hbalock);
  1293. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1294. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1295. psli->last_iotag);
  1296. return 0;
  1297. }
  1298. /**
  1299. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1300. * @phba: Pointer to HBA context object.
  1301. * @pring: Pointer to driver SLI ring object.
  1302. * @iocb: Pointer to iocb slot in the ring.
  1303. * @nextiocb: Pointer to driver iocb object which need to be
  1304. * posted to firmware.
  1305. *
  1306. * This function is called with hbalock held to post a new iocb to
  1307. * the firmware. This function copies the new iocb to ring iocb slot and
  1308. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1309. * a completion call back for this iocb else the function will free the
  1310. * iocb object.
  1311. **/
  1312. static void
  1313. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1314. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1315. {
  1316. /*
  1317. * Set up an iotag
  1318. */
  1319. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1320. if (pring->ringno == LPFC_ELS_RING) {
  1321. lpfc_debugfs_slow_ring_trc(phba,
  1322. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1323. *(((uint32_t *) &nextiocb->iocb) + 4),
  1324. *(((uint32_t *) &nextiocb->iocb) + 6),
  1325. *(((uint32_t *) &nextiocb->iocb) + 7));
  1326. }
  1327. /*
  1328. * Issue iocb command to adapter
  1329. */
  1330. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1331. wmb();
  1332. pring->stats.iocb_cmd++;
  1333. /*
  1334. * If there is no completion routine to call, we can release the
  1335. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1336. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1337. */
  1338. if (nextiocb->iocb_cmpl)
  1339. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1340. else
  1341. __lpfc_sli_release_iocbq(phba, nextiocb);
  1342. /*
  1343. * Let the HBA know what IOCB slot will be the next one the
  1344. * driver will put a command into.
  1345. */
  1346. pring->cmdidx = pring->next_cmdidx;
  1347. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1348. }
  1349. /**
  1350. * lpfc_sli_update_full_ring - Update the chip attention register
  1351. * @phba: Pointer to HBA context object.
  1352. * @pring: Pointer to driver SLI ring object.
  1353. *
  1354. * The caller is not required to hold any lock for calling this function.
  1355. * This function updates the chip attention bits for the ring to inform firmware
  1356. * that there are pending work to be done for this ring and requests an
  1357. * interrupt when there is space available in the ring. This function is
  1358. * called when the driver is unable to post more iocbs to the ring due
  1359. * to unavailability of space in the ring.
  1360. **/
  1361. static void
  1362. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1363. {
  1364. int ringno = pring->ringno;
  1365. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1366. wmb();
  1367. /*
  1368. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1369. * The HBA will tell us when an IOCB entry is available.
  1370. */
  1371. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1372. readl(phba->CAregaddr); /* flush */
  1373. pring->stats.iocb_cmd_full++;
  1374. }
  1375. /**
  1376. * lpfc_sli_update_ring - Update chip attention register
  1377. * @phba: Pointer to HBA context object.
  1378. * @pring: Pointer to driver SLI ring object.
  1379. *
  1380. * This function updates the chip attention register bit for the
  1381. * given ring to inform HBA that there is more work to be done
  1382. * in this ring. The caller is not required to hold any lock.
  1383. **/
  1384. static void
  1385. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1386. {
  1387. int ringno = pring->ringno;
  1388. /*
  1389. * Tell the HBA that there is work to do in this ring.
  1390. */
  1391. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1392. wmb();
  1393. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1394. readl(phba->CAregaddr); /* flush */
  1395. }
  1396. }
  1397. /**
  1398. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1399. * @phba: Pointer to HBA context object.
  1400. * @pring: Pointer to driver SLI ring object.
  1401. *
  1402. * This function is called with hbalock held to post pending iocbs
  1403. * in the txq to the firmware. This function is called when driver
  1404. * detects space available in the ring.
  1405. **/
  1406. static void
  1407. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1408. {
  1409. IOCB_t *iocb;
  1410. struct lpfc_iocbq *nextiocb;
  1411. /*
  1412. * Check to see if:
  1413. * (a) there is anything on the txq to send
  1414. * (b) link is up
  1415. * (c) link attention events can be processed (fcp ring only)
  1416. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1417. */
  1418. if (pring->txq_cnt &&
  1419. lpfc_is_link_up(phba) &&
  1420. (pring->ringno != phba->sli.fcp_ring ||
  1421. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1422. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1423. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1424. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1425. if (iocb)
  1426. lpfc_sli_update_ring(phba, pring);
  1427. else
  1428. lpfc_sli_update_full_ring(phba, pring);
  1429. }
  1430. return;
  1431. }
  1432. /**
  1433. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1434. * @phba: Pointer to HBA context object.
  1435. * @hbqno: HBQ number.
  1436. *
  1437. * This function is called with hbalock held to get the next
  1438. * available slot for the given HBQ. If there is free slot
  1439. * available for the HBQ it will return pointer to the next available
  1440. * HBQ entry else it will return NULL.
  1441. **/
  1442. static struct lpfc_hbq_entry *
  1443. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1444. {
  1445. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1446. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1447. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1448. hbqp->next_hbqPutIdx = 0;
  1449. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1450. uint32_t raw_index = phba->hbq_get[hbqno];
  1451. uint32_t getidx = le32_to_cpu(raw_index);
  1452. hbqp->local_hbqGetIdx = getidx;
  1453. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1454. lpfc_printf_log(phba, KERN_ERR,
  1455. LOG_SLI | LOG_VPORT,
  1456. "1802 HBQ %d: local_hbqGetIdx "
  1457. "%u is > than hbqp->entry_count %u\n",
  1458. hbqno, hbqp->local_hbqGetIdx,
  1459. hbqp->entry_count);
  1460. phba->link_state = LPFC_HBA_ERROR;
  1461. return NULL;
  1462. }
  1463. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1464. return NULL;
  1465. }
  1466. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1467. hbqp->hbqPutIdx;
  1468. }
  1469. /**
  1470. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1471. * @phba: Pointer to HBA context object.
  1472. *
  1473. * This function is called with no lock held to free all the
  1474. * hbq buffers while uninitializing the SLI interface. It also
  1475. * frees the HBQ buffers returned by the firmware but not yet
  1476. * processed by the upper layers.
  1477. **/
  1478. void
  1479. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1480. {
  1481. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1482. struct hbq_dmabuf *hbq_buf;
  1483. unsigned long flags;
  1484. int i, hbq_count;
  1485. uint32_t hbqno;
  1486. hbq_count = lpfc_sli_hbq_count();
  1487. /* Return all memory used by all HBQs */
  1488. spin_lock_irqsave(&phba->hbalock, flags);
  1489. for (i = 0; i < hbq_count; ++i) {
  1490. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1491. &phba->hbqs[i].hbq_buffer_list, list) {
  1492. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1493. list_del(&hbq_buf->dbuf.list);
  1494. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1495. }
  1496. phba->hbqs[i].buffer_count = 0;
  1497. }
  1498. /* Return all HBQ buffer that are in-fly */
  1499. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1500. list) {
  1501. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1502. list_del(&hbq_buf->dbuf.list);
  1503. if (hbq_buf->tag == -1) {
  1504. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1505. (phba, hbq_buf);
  1506. } else {
  1507. hbqno = hbq_buf->tag >> 16;
  1508. if (hbqno >= LPFC_MAX_HBQS)
  1509. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1510. (phba, hbq_buf);
  1511. else
  1512. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1513. hbq_buf);
  1514. }
  1515. }
  1516. /* Mark the HBQs not in use */
  1517. phba->hbq_in_use = 0;
  1518. spin_unlock_irqrestore(&phba->hbalock, flags);
  1519. }
  1520. /**
  1521. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1522. * @phba: Pointer to HBA context object.
  1523. * @hbqno: HBQ number.
  1524. * @hbq_buf: Pointer to HBQ buffer.
  1525. *
  1526. * This function is called with the hbalock held to post a
  1527. * hbq buffer to the firmware. If the function finds an empty
  1528. * slot in the HBQ, it will post the buffer. The function will return
  1529. * pointer to the hbq entry if it successfully post the buffer
  1530. * else it will return NULL.
  1531. **/
  1532. static int
  1533. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1534. struct hbq_dmabuf *hbq_buf)
  1535. {
  1536. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1537. }
  1538. /**
  1539. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1540. * @phba: Pointer to HBA context object.
  1541. * @hbqno: HBQ number.
  1542. * @hbq_buf: Pointer to HBQ buffer.
  1543. *
  1544. * This function is called with the hbalock held to post a hbq buffer to the
  1545. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1546. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1547. * it successfully post the buffer else it will return an error.
  1548. **/
  1549. static int
  1550. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1551. struct hbq_dmabuf *hbq_buf)
  1552. {
  1553. struct lpfc_hbq_entry *hbqe;
  1554. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1555. /* Get next HBQ entry slot to use */
  1556. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1557. if (hbqe) {
  1558. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1559. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1560. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1561. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1562. hbqe->bde.tus.f.bdeFlags = 0;
  1563. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1564. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1565. /* Sync SLIM */
  1566. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1567. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1568. /* flush */
  1569. readl(phba->hbq_put + hbqno);
  1570. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1571. return 0;
  1572. } else
  1573. return -ENOMEM;
  1574. }
  1575. /**
  1576. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1577. * @phba: Pointer to HBA context object.
  1578. * @hbqno: HBQ number.
  1579. * @hbq_buf: Pointer to HBQ buffer.
  1580. *
  1581. * This function is called with the hbalock held to post an RQE to the SLI4
  1582. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1583. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1584. **/
  1585. static int
  1586. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1587. struct hbq_dmabuf *hbq_buf)
  1588. {
  1589. int rc;
  1590. struct lpfc_rqe hrqe;
  1591. struct lpfc_rqe drqe;
  1592. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1593. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1594. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1595. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1596. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1597. &hrqe, &drqe);
  1598. if (rc < 0)
  1599. return rc;
  1600. hbq_buf->tag = rc;
  1601. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1602. return 0;
  1603. }
  1604. /* HBQ for ELS and CT traffic. */
  1605. static struct lpfc_hbq_init lpfc_els_hbq = {
  1606. .rn = 1,
  1607. .entry_count = 256,
  1608. .mask_count = 0,
  1609. .profile = 0,
  1610. .ring_mask = (1 << LPFC_ELS_RING),
  1611. .buffer_count = 0,
  1612. .init_count = 40,
  1613. .add_count = 40,
  1614. };
  1615. /* HBQ for the extra ring if needed */
  1616. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1617. .rn = 1,
  1618. .entry_count = 200,
  1619. .mask_count = 0,
  1620. .profile = 0,
  1621. .ring_mask = (1 << LPFC_EXTRA_RING),
  1622. .buffer_count = 0,
  1623. .init_count = 0,
  1624. .add_count = 5,
  1625. };
  1626. /* Array of HBQs */
  1627. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1628. &lpfc_els_hbq,
  1629. &lpfc_extra_hbq,
  1630. };
  1631. /**
  1632. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1633. * @phba: Pointer to HBA context object.
  1634. * @hbqno: HBQ number.
  1635. * @count: Number of HBQ buffers to be posted.
  1636. *
  1637. * This function is called with no lock held to post more hbq buffers to the
  1638. * given HBQ. The function returns the number of HBQ buffers successfully
  1639. * posted.
  1640. **/
  1641. static int
  1642. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1643. {
  1644. uint32_t i, posted = 0;
  1645. unsigned long flags;
  1646. struct hbq_dmabuf *hbq_buffer;
  1647. LIST_HEAD(hbq_buf_list);
  1648. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1649. return 0;
  1650. if ((phba->hbqs[hbqno].buffer_count + count) >
  1651. lpfc_hbq_defs[hbqno]->entry_count)
  1652. count = lpfc_hbq_defs[hbqno]->entry_count -
  1653. phba->hbqs[hbqno].buffer_count;
  1654. if (!count)
  1655. return 0;
  1656. /* Allocate HBQ entries */
  1657. for (i = 0; i < count; i++) {
  1658. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1659. if (!hbq_buffer)
  1660. break;
  1661. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1662. }
  1663. /* Check whether HBQ is still in use */
  1664. spin_lock_irqsave(&phba->hbalock, flags);
  1665. if (!phba->hbq_in_use)
  1666. goto err;
  1667. while (!list_empty(&hbq_buf_list)) {
  1668. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1669. dbuf.list);
  1670. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1671. (hbqno << 16));
  1672. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1673. phba->hbqs[hbqno].buffer_count++;
  1674. posted++;
  1675. } else
  1676. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1677. }
  1678. spin_unlock_irqrestore(&phba->hbalock, flags);
  1679. return posted;
  1680. err:
  1681. spin_unlock_irqrestore(&phba->hbalock, flags);
  1682. while (!list_empty(&hbq_buf_list)) {
  1683. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1684. dbuf.list);
  1685. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1686. }
  1687. return 0;
  1688. }
  1689. /**
  1690. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1691. * @phba: Pointer to HBA context object.
  1692. * @qno: HBQ number.
  1693. *
  1694. * This function posts more buffers to the HBQ. This function
  1695. * is called with no lock held. The function returns the number of HBQ entries
  1696. * successfully allocated.
  1697. **/
  1698. int
  1699. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1700. {
  1701. if (phba->sli_rev == LPFC_SLI_REV4)
  1702. return 0;
  1703. else
  1704. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1705. lpfc_hbq_defs[qno]->add_count);
  1706. }
  1707. /**
  1708. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1709. * @phba: Pointer to HBA context object.
  1710. * @qno: HBQ queue number.
  1711. *
  1712. * This function is called from SLI initialization code path with
  1713. * no lock held to post initial HBQ buffers to firmware. The
  1714. * function returns the number of HBQ entries successfully allocated.
  1715. **/
  1716. static int
  1717. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1718. {
  1719. if (phba->sli_rev == LPFC_SLI_REV4)
  1720. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1721. lpfc_hbq_defs[qno]->entry_count);
  1722. else
  1723. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1724. lpfc_hbq_defs[qno]->init_count);
  1725. }
  1726. /**
  1727. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1728. * @phba: Pointer to HBA context object.
  1729. * @hbqno: HBQ number.
  1730. *
  1731. * This function removes the first hbq buffer on an hbq list and returns a
  1732. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1733. **/
  1734. static struct hbq_dmabuf *
  1735. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1736. {
  1737. struct lpfc_dmabuf *d_buf;
  1738. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1739. if (!d_buf)
  1740. return NULL;
  1741. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1742. }
  1743. /**
  1744. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1745. * @phba: Pointer to HBA context object.
  1746. * @tag: Tag of the hbq buffer.
  1747. *
  1748. * This function is called with hbalock held. This function searches
  1749. * for the hbq buffer associated with the given tag in the hbq buffer
  1750. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1751. * it returns NULL.
  1752. **/
  1753. static struct hbq_dmabuf *
  1754. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1755. {
  1756. struct lpfc_dmabuf *d_buf;
  1757. struct hbq_dmabuf *hbq_buf;
  1758. uint32_t hbqno;
  1759. hbqno = tag >> 16;
  1760. if (hbqno >= LPFC_MAX_HBQS)
  1761. return NULL;
  1762. spin_lock_irq(&phba->hbalock);
  1763. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1764. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1765. if (hbq_buf->tag == tag) {
  1766. spin_unlock_irq(&phba->hbalock);
  1767. return hbq_buf;
  1768. }
  1769. }
  1770. spin_unlock_irq(&phba->hbalock);
  1771. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1772. "1803 Bad hbq tag. Data: x%x x%x\n",
  1773. tag, phba->hbqs[tag >> 16].buffer_count);
  1774. return NULL;
  1775. }
  1776. /**
  1777. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1778. * @phba: Pointer to HBA context object.
  1779. * @hbq_buffer: Pointer to HBQ buffer.
  1780. *
  1781. * This function is called with hbalock. This function gives back
  1782. * the hbq buffer to firmware. If the HBQ does not have space to
  1783. * post the buffer, it will free the buffer.
  1784. **/
  1785. void
  1786. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1787. {
  1788. uint32_t hbqno;
  1789. if (hbq_buffer) {
  1790. hbqno = hbq_buffer->tag >> 16;
  1791. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1792. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1793. }
  1794. }
  1795. /**
  1796. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1797. * @mbxCommand: mailbox command code.
  1798. *
  1799. * This function is called by the mailbox event handler function to verify
  1800. * that the completed mailbox command is a legitimate mailbox command. If the
  1801. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1802. * and the mailbox event handler will take the HBA offline.
  1803. **/
  1804. static int
  1805. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1806. {
  1807. uint8_t ret;
  1808. switch (mbxCommand) {
  1809. case MBX_LOAD_SM:
  1810. case MBX_READ_NV:
  1811. case MBX_WRITE_NV:
  1812. case MBX_WRITE_VPARMS:
  1813. case MBX_RUN_BIU_DIAG:
  1814. case MBX_INIT_LINK:
  1815. case MBX_DOWN_LINK:
  1816. case MBX_CONFIG_LINK:
  1817. case MBX_CONFIG_RING:
  1818. case MBX_RESET_RING:
  1819. case MBX_READ_CONFIG:
  1820. case MBX_READ_RCONFIG:
  1821. case MBX_READ_SPARM:
  1822. case MBX_READ_STATUS:
  1823. case MBX_READ_RPI:
  1824. case MBX_READ_XRI:
  1825. case MBX_READ_REV:
  1826. case MBX_READ_LNK_STAT:
  1827. case MBX_REG_LOGIN:
  1828. case MBX_UNREG_LOGIN:
  1829. case MBX_CLEAR_LA:
  1830. case MBX_DUMP_MEMORY:
  1831. case MBX_DUMP_CONTEXT:
  1832. case MBX_RUN_DIAGS:
  1833. case MBX_RESTART:
  1834. case MBX_UPDATE_CFG:
  1835. case MBX_DOWN_LOAD:
  1836. case MBX_DEL_LD_ENTRY:
  1837. case MBX_RUN_PROGRAM:
  1838. case MBX_SET_MASK:
  1839. case MBX_SET_VARIABLE:
  1840. case MBX_UNREG_D_ID:
  1841. case MBX_KILL_BOARD:
  1842. case MBX_CONFIG_FARP:
  1843. case MBX_BEACON:
  1844. case MBX_LOAD_AREA:
  1845. case MBX_RUN_BIU_DIAG64:
  1846. case MBX_CONFIG_PORT:
  1847. case MBX_READ_SPARM64:
  1848. case MBX_READ_RPI64:
  1849. case MBX_REG_LOGIN64:
  1850. case MBX_READ_TOPOLOGY:
  1851. case MBX_WRITE_WWN:
  1852. case MBX_SET_DEBUG:
  1853. case MBX_LOAD_EXP_ROM:
  1854. case MBX_ASYNCEVT_ENABLE:
  1855. case MBX_REG_VPI:
  1856. case MBX_UNREG_VPI:
  1857. case MBX_HEARTBEAT:
  1858. case MBX_PORT_CAPABILITIES:
  1859. case MBX_PORT_IOV_CONTROL:
  1860. case MBX_SLI4_CONFIG:
  1861. case MBX_SLI4_REQ_FTRS:
  1862. case MBX_REG_FCFI:
  1863. case MBX_UNREG_FCFI:
  1864. case MBX_REG_VFI:
  1865. case MBX_UNREG_VFI:
  1866. case MBX_INIT_VPI:
  1867. case MBX_INIT_VFI:
  1868. case MBX_RESUME_RPI:
  1869. case MBX_READ_EVENT_LOG_STATUS:
  1870. case MBX_READ_EVENT_LOG:
  1871. case MBX_SECURITY_MGMT:
  1872. case MBX_AUTH_PORT:
  1873. ret = mbxCommand;
  1874. break;
  1875. default:
  1876. ret = MBX_SHUTDOWN;
  1877. break;
  1878. }
  1879. return ret;
  1880. }
  1881. /**
  1882. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1883. * @phba: Pointer to HBA context object.
  1884. * @pmboxq: Pointer to mailbox command.
  1885. *
  1886. * This is completion handler function for mailbox commands issued from
  1887. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1888. * mailbox event handler function with no lock held. This function
  1889. * will wake up thread waiting on the wait queue pointed by context1
  1890. * of the mailbox.
  1891. **/
  1892. void
  1893. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1894. {
  1895. wait_queue_head_t *pdone_q;
  1896. unsigned long drvr_flag;
  1897. /*
  1898. * If pdone_q is empty, the driver thread gave up waiting and
  1899. * continued running.
  1900. */
  1901. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1902. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1903. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1904. if (pdone_q)
  1905. wake_up_interruptible(pdone_q);
  1906. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1907. return;
  1908. }
  1909. /**
  1910. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1911. * @phba: Pointer to HBA context object.
  1912. * @pmb: Pointer to mailbox object.
  1913. *
  1914. * This function is the default mailbox completion handler. It
  1915. * frees the memory resources associated with the completed mailbox
  1916. * command. If the completed command is a REG_LOGIN mailbox command,
  1917. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1918. **/
  1919. void
  1920. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1921. {
  1922. struct lpfc_vport *vport = pmb->vport;
  1923. struct lpfc_dmabuf *mp;
  1924. struct lpfc_nodelist *ndlp;
  1925. struct Scsi_Host *shost;
  1926. uint16_t rpi, vpi;
  1927. int rc;
  1928. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1929. if (mp) {
  1930. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1931. kfree(mp);
  1932. }
  1933. /*
  1934. * If a REG_LOGIN succeeded after node is destroyed or node
  1935. * is in re-discovery driver need to cleanup the RPI.
  1936. */
  1937. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1938. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1939. !pmb->u.mb.mbxStatus) {
  1940. rpi = pmb->u.mb.un.varWords[0];
  1941. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1942. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1943. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1944. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1945. if (rc != MBX_NOT_FINISHED)
  1946. return;
  1947. }
  1948. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1949. !(phba->pport->load_flag & FC_UNLOADING) &&
  1950. !pmb->u.mb.mbxStatus) {
  1951. shost = lpfc_shost_from_vport(vport);
  1952. spin_lock_irq(shost->host_lock);
  1953. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1954. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1955. spin_unlock_irq(shost->host_lock);
  1956. }
  1957. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1958. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1959. lpfc_nlp_put(ndlp);
  1960. pmb->context2 = NULL;
  1961. }
  1962. /* Check security permission status on INIT_LINK mailbox command */
  1963. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1964. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1965. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1966. "2860 SLI authentication is required "
  1967. "for INIT_LINK but has not done yet\n");
  1968. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1969. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1970. else
  1971. mempool_free(pmb, phba->mbox_mem_pool);
  1972. }
  1973. /**
  1974. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1975. * @phba: Pointer to HBA context object.
  1976. *
  1977. * This function is called with no lock held. This function processes all
  1978. * the completed mailbox commands and gives it to upper layers. The interrupt
  1979. * service routine processes mailbox completion interrupt and adds completed
  1980. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1981. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1982. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1983. * function returns the mailbox commands to the upper layer by calling the
  1984. * completion handler function of each mailbox.
  1985. **/
  1986. int
  1987. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1988. {
  1989. MAILBOX_t *pmbox;
  1990. LPFC_MBOXQ_t *pmb;
  1991. int rc;
  1992. LIST_HEAD(cmplq);
  1993. phba->sli.slistat.mbox_event++;
  1994. /* Get all completed mailboxe buffers into the cmplq */
  1995. spin_lock_irq(&phba->hbalock);
  1996. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1997. spin_unlock_irq(&phba->hbalock);
  1998. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1999. do {
  2000. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2001. if (pmb == NULL)
  2002. break;
  2003. pmbox = &pmb->u.mb;
  2004. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2005. if (pmb->vport) {
  2006. lpfc_debugfs_disc_trc(pmb->vport,
  2007. LPFC_DISC_TRC_MBOX_VPORT,
  2008. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2009. (uint32_t)pmbox->mbxCommand,
  2010. pmbox->un.varWords[0],
  2011. pmbox->un.varWords[1]);
  2012. }
  2013. else {
  2014. lpfc_debugfs_disc_trc(phba->pport,
  2015. LPFC_DISC_TRC_MBOX,
  2016. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2017. (uint32_t)pmbox->mbxCommand,
  2018. pmbox->un.varWords[0],
  2019. pmbox->un.varWords[1]);
  2020. }
  2021. }
  2022. /*
  2023. * It is a fatal error if unknown mbox command completion.
  2024. */
  2025. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2026. MBX_SHUTDOWN) {
  2027. /* Unknown mailbox command compl */
  2028. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2029. "(%d):0323 Unknown Mailbox command "
  2030. "x%x (x%x) Cmpl\n",
  2031. pmb->vport ? pmb->vport->vpi : 0,
  2032. pmbox->mbxCommand,
  2033. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2034. phba->link_state = LPFC_HBA_ERROR;
  2035. phba->work_hs = HS_FFER3;
  2036. lpfc_handle_eratt(phba);
  2037. continue;
  2038. }
  2039. if (pmbox->mbxStatus) {
  2040. phba->sli.slistat.mbox_stat_err++;
  2041. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2042. /* Mbox cmd cmpl error - RETRYing */
  2043. lpfc_printf_log(phba, KERN_INFO,
  2044. LOG_MBOX | LOG_SLI,
  2045. "(%d):0305 Mbox cmd cmpl "
  2046. "error - RETRYing Data: x%x "
  2047. "(x%x) x%x x%x x%x\n",
  2048. pmb->vport ? pmb->vport->vpi :0,
  2049. pmbox->mbxCommand,
  2050. lpfc_sli4_mbox_opcode_get(phba,
  2051. pmb),
  2052. pmbox->mbxStatus,
  2053. pmbox->un.varWords[0],
  2054. pmb->vport->port_state);
  2055. pmbox->mbxStatus = 0;
  2056. pmbox->mbxOwner = OWN_HOST;
  2057. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2058. if (rc != MBX_NOT_FINISHED)
  2059. continue;
  2060. }
  2061. }
  2062. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2063. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2064. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2065. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2066. pmb->vport ? pmb->vport->vpi : 0,
  2067. pmbox->mbxCommand,
  2068. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2069. pmb->mbox_cmpl,
  2070. *((uint32_t *) pmbox),
  2071. pmbox->un.varWords[0],
  2072. pmbox->un.varWords[1],
  2073. pmbox->un.varWords[2],
  2074. pmbox->un.varWords[3],
  2075. pmbox->un.varWords[4],
  2076. pmbox->un.varWords[5],
  2077. pmbox->un.varWords[6],
  2078. pmbox->un.varWords[7]);
  2079. if (pmb->mbox_cmpl)
  2080. pmb->mbox_cmpl(phba,pmb);
  2081. } while (1);
  2082. return 0;
  2083. }
  2084. /**
  2085. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2086. * @phba: Pointer to HBA context object.
  2087. * @pring: Pointer to driver SLI ring object.
  2088. * @tag: buffer tag.
  2089. *
  2090. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2091. * is set in the tag the buffer is posted for a particular exchange,
  2092. * the function will return the buffer without replacing the buffer.
  2093. * If the buffer is for unsolicited ELS or CT traffic, this function
  2094. * returns the buffer and also posts another buffer to the firmware.
  2095. **/
  2096. static struct lpfc_dmabuf *
  2097. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2098. struct lpfc_sli_ring *pring,
  2099. uint32_t tag)
  2100. {
  2101. struct hbq_dmabuf *hbq_entry;
  2102. if (tag & QUE_BUFTAG_BIT)
  2103. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2104. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2105. if (!hbq_entry)
  2106. return NULL;
  2107. return &hbq_entry->dbuf;
  2108. }
  2109. /**
  2110. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2111. * @phba: Pointer to HBA context object.
  2112. * @pring: Pointer to driver SLI ring object.
  2113. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2114. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2115. * @fch_type: the type for the first frame of the sequence.
  2116. *
  2117. * This function is called with no lock held. This function uses the r_ctl and
  2118. * type of the received sequence to find the correct callback function to call
  2119. * to process the sequence.
  2120. **/
  2121. static int
  2122. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2123. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2124. uint32_t fch_type)
  2125. {
  2126. int i;
  2127. /* unSolicited Responses */
  2128. if (pring->prt[0].profile) {
  2129. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2130. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2131. saveq);
  2132. return 1;
  2133. }
  2134. /* We must search, based on rctl / type
  2135. for the right routine */
  2136. for (i = 0; i < pring->num_mask; i++) {
  2137. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2138. (pring->prt[i].type == fch_type)) {
  2139. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2140. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2141. (phba, pring, saveq);
  2142. return 1;
  2143. }
  2144. }
  2145. return 0;
  2146. }
  2147. /**
  2148. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2149. * @phba: Pointer to HBA context object.
  2150. * @pring: Pointer to driver SLI ring object.
  2151. * @saveq: Pointer to the unsolicited iocb.
  2152. *
  2153. * This function is called with no lock held by the ring event handler
  2154. * when there is an unsolicited iocb posted to the response ring by the
  2155. * firmware. This function gets the buffer associated with the iocbs
  2156. * and calls the event handler for the ring. This function handles both
  2157. * qring buffers and hbq buffers.
  2158. * When the function returns 1 the caller can free the iocb object otherwise
  2159. * upper layer functions will free the iocb objects.
  2160. **/
  2161. static int
  2162. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2163. struct lpfc_iocbq *saveq)
  2164. {
  2165. IOCB_t * irsp;
  2166. WORD5 * w5p;
  2167. uint32_t Rctl, Type;
  2168. uint32_t match;
  2169. struct lpfc_iocbq *iocbq;
  2170. struct lpfc_dmabuf *dmzbuf;
  2171. match = 0;
  2172. irsp = &(saveq->iocb);
  2173. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2174. if (pring->lpfc_sli_rcv_async_status)
  2175. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2176. else
  2177. lpfc_printf_log(phba,
  2178. KERN_WARNING,
  2179. LOG_SLI,
  2180. "0316 Ring %d handler: unexpected "
  2181. "ASYNC_STATUS iocb received evt_code "
  2182. "0x%x\n",
  2183. pring->ringno,
  2184. irsp->un.asyncstat.evt_code);
  2185. return 1;
  2186. }
  2187. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2188. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2189. if (irsp->ulpBdeCount > 0) {
  2190. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2191. irsp->un.ulpWord[3]);
  2192. lpfc_in_buf_free(phba, dmzbuf);
  2193. }
  2194. if (irsp->ulpBdeCount > 1) {
  2195. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2196. irsp->unsli3.sli3Words[3]);
  2197. lpfc_in_buf_free(phba, dmzbuf);
  2198. }
  2199. if (irsp->ulpBdeCount > 2) {
  2200. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2201. irsp->unsli3.sli3Words[7]);
  2202. lpfc_in_buf_free(phba, dmzbuf);
  2203. }
  2204. return 1;
  2205. }
  2206. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2207. if (irsp->ulpBdeCount != 0) {
  2208. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2209. irsp->un.ulpWord[3]);
  2210. if (!saveq->context2)
  2211. lpfc_printf_log(phba,
  2212. KERN_ERR,
  2213. LOG_SLI,
  2214. "0341 Ring %d Cannot find buffer for "
  2215. "an unsolicited iocb. tag 0x%x\n",
  2216. pring->ringno,
  2217. irsp->un.ulpWord[3]);
  2218. }
  2219. if (irsp->ulpBdeCount == 2) {
  2220. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2221. irsp->unsli3.sli3Words[7]);
  2222. if (!saveq->context3)
  2223. lpfc_printf_log(phba,
  2224. KERN_ERR,
  2225. LOG_SLI,
  2226. "0342 Ring %d Cannot find buffer for an"
  2227. " unsolicited iocb. tag 0x%x\n",
  2228. pring->ringno,
  2229. irsp->unsli3.sli3Words[7]);
  2230. }
  2231. list_for_each_entry(iocbq, &saveq->list, list) {
  2232. irsp = &(iocbq->iocb);
  2233. if (irsp->ulpBdeCount != 0) {
  2234. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2235. irsp->un.ulpWord[3]);
  2236. if (!iocbq->context2)
  2237. lpfc_printf_log(phba,
  2238. KERN_ERR,
  2239. LOG_SLI,
  2240. "0343 Ring %d Cannot find "
  2241. "buffer for an unsolicited iocb"
  2242. ". tag 0x%x\n", pring->ringno,
  2243. irsp->un.ulpWord[3]);
  2244. }
  2245. if (irsp->ulpBdeCount == 2) {
  2246. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2247. irsp->unsli3.sli3Words[7]);
  2248. if (!iocbq->context3)
  2249. lpfc_printf_log(phba,
  2250. KERN_ERR,
  2251. LOG_SLI,
  2252. "0344 Ring %d Cannot find "
  2253. "buffer for an unsolicited "
  2254. "iocb. tag 0x%x\n",
  2255. pring->ringno,
  2256. irsp->unsli3.sli3Words[7]);
  2257. }
  2258. }
  2259. }
  2260. if (irsp->ulpBdeCount != 0 &&
  2261. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2262. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2263. int found = 0;
  2264. /* search continue save q for same XRI */
  2265. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2266. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2267. list_add_tail(&saveq->list, &iocbq->list);
  2268. found = 1;
  2269. break;
  2270. }
  2271. }
  2272. if (!found)
  2273. list_add_tail(&saveq->clist,
  2274. &pring->iocb_continue_saveq);
  2275. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2276. list_del_init(&iocbq->clist);
  2277. saveq = iocbq;
  2278. irsp = &(saveq->iocb);
  2279. } else
  2280. return 0;
  2281. }
  2282. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2283. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2284. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2285. Rctl = FC_RCTL_ELS_REQ;
  2286. Type = FC_TYPE_ELS;
  2287. } else {
  2288. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2289. Rctl = w5p->hcsw.Rctl;
  2290. Type = w5p->hcsw.Type;
  2291. /* Firmware Workaround */
  2292. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2293. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2294. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2295. Rctl = FC_RCTL_ELS_REQ;
  2296. Type = FC_TYPE_ELS;
  2297. w5p->hcsw.Rctl = Rctl;
  2298. w5p->hcsw.Type = Type;
  2299. }
  2300. }
  2301. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2302. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2303. "0313 Ring %d handler: unexpected Rctl x%x "
  2304. "Type x%x received\n",
  2305. pring->ringno, Rctl, Type);
  2306. return 1;
  2307. }
  2308. /**
  2309. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2310. * @phba: Pointer to HBA context object.
  2311. * @pring: Pointer to driver SLI ring object.
  2312. * @prspiocb: Pointer to response iocb object.
  2313. *
  2314. * This function looks up the iocb_lookup table to get the command iocb
  2315. * corresponding to the given response iocb using the iotag of the
  2316. * response iocb. This function is called with the hbalock held.
  2317. * This function returns the command iocb object if it finds the command
  2318. * iocb else returns NULL.
  2319. **/
  2320. static struct lpfc_iocbq *
  2321. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2322. struct lpfc_sli_ring *pring,
  2323. struct lpfc_iocbq *prspiocb)
  2324. {
  2325. struct lpfc_iocbq *cmd_iocb = NULL;
  2326. uint16_t iotag;
  2327. iotag = prspiocb->iocb.ulpIoTag;
  2328. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2329. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2330. list_del_init(&cmd_iocb->list);
  2331. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2332. pring->txcmplq_cnt--;
  2333. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2334. }
  2335. return cmd_iocb;
  2336. }
  2337. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2338. "0317 iotag x%x is out off "
  2339. "range: max iotag x%x wd0 x%x\n",
  2340. iotag, phba->sli.last_iotag,
  2341. *(((uint32_t *) &prspiocb->iocb) + 7));
  2342. return NULL;
  2343. }
  2344. /**
  2345. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2346. * @phba: Pointer to HBA context object.
  2347. * @pring: Pointer to driver SLI ring object.
  2348. * @iotag: IOCB tag.
  2349. *
  2350. * This function looks up the iocb_lookup table to get the command iocb
  2351. * corresponding to the given iotag. This function is called with the
  2352. * hbalock held.
  2353. * This function returns the command iocb object if it finds the command
  2354. * iocb else returns NULL.
  2355. **/
  2356. static struct lpfc_iocbq *
  2357. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2358. struct lpfc_sli_ring *pring, uint16_t iotag)
  2359. {
  2360. struct lpfc_iocbq *cmd_iocb;
  2361. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2362. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2363. list_del_init(&cmd_iocb->list);
  2364. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2365. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2366. pring->txcmplq_cnt--;
  2367. }
  2368. return cmd_iocb;
  2369. }
  2370. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2371. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2372. iotag, phba->sli.last_iotag);
  2373. return NULL;
  2374. }
  2375. /**
  2376. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2377. * @phba: Pointer to HBA context object.
  2378. * @pring: Pointer to driver SLI ring object.
  2379. * @saveq: Pointer to the response iocb to be processed.
  2380. *
  2381. * This function is called by the ring event handler for non-fcp
  2382. * rings when there is a new response iocb in the response ring.
  2383. * The caller is not required to hold any locks. This function
  2384. * gets the command iocb associated with the response iocb and
  2385. * calls the completion handler for the command iocb. If there
  2386. * is no completion handler, the function will free the resources
  2387. * associated with command iocb. If the response iocb is for
  2388. * an already aborted command iocb, the status of the completion
  2389. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2390. * This function always returns 1.
  2391. **/
  2392. static int
  2393. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2394. struct lpfc_iocbq *saveq)
  2395. {
  2396. struct lpfc_iocbq *cmdiocbp;
  2397. int rc = 1;
  2398. unsigned long iflag;
  2399. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2400. spin_lock_irqsave(&phba->hbalock, iflag);
  2401. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2402. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2403. if (cmdiocbp) {
  2404. if (cmdiocbp->iocb_cmpl) {
  2405. /*
  2406. * If an ELS command failed send an event to mgmt
  2407. * application.
  2408. */
  2409. if (saveq->iocb.ulpStatus &&
  2410. (pring->ringno == LPFC_ELS_RING) &&
  2411. (cmdiocbp->iocb.ulpCommand ==
  2412. CMD_ELS_REQUEST64_CR))
  2413. lpfc_send_els_failure_event(phba,
  2414. cmdiocbp, saveq);
  2415. /*
  2416. * Post all ELS completions to the worker thread.
  2417. * All other are passed to the completion callback.
  2418. */
  2419. if (pring->ringno == LPFC_ELS_RING) {
  2420. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2421. (cmdiocbp->iocb_flag &
  2422. LPFC_DRIVER_ABORTED)) {
  2423. spin_lock_irqsave(&phba->hbalock,
  2424. iflag);
  2425. cmdiocbp->iocb_flag &=
  2426. ~LPFC_DRIVER_ABORTED;
  2427. spin_unlock_irqrestore(&phba->hbalock,
  2428. iflag);
  2429. saveq->iocb.ulpStatus =
  2430. IOSTAT_LOCAL_REJECT;
  2431. saveq->iocb.un.ulpWord[4] =
  2432. IOERR_SLI_ABORTED;
  2433. /* Firmware could still be in progress
  2434. * of DMAing payload, so don't free data
  2435. * buffer till after a hbeat.
  2436. */
  2437. spin_lock_irqsave(&phba->hbalock,
  2438. iflag);
  2439. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2440. spin_unlock_irqrestore(&phba->hbalock,
  2441. iflag);
  2442. }
  2443. if (phba->sli_rev == LPFC_SLI_REV4) {
  2444. if (saveq->iocb_flag &
  2445. LPFC_EXCHANGE_BUSY) {
  2446. /* Set cmdiocb flag for the
  2447. * exchange busy so sgl (xri)
  2448. * will not be released until
  2449. * the abort xri is received
  2450. * from hba.
  2451. */
  2452. spin_lock_irqsave(
  2453. &phba->hbalock, iflag);
  2454. cmdiocbp->iocb_flag |=
  2455. LPFC_EXCHANGE_BUSY;
  2456. spin_unlock_irqrestore(
  2457. &phba->hbalock, iflag);
  2458. }
  2459. if (cmdiocbp->iocb_flag &
  2460. LPFC_DRIVER_ABORTED) {
  2461. /*
  2462. * Clear LPFC_DRIVER_ABORTED
  2463. * bit in case it was driver
  2464. * initiated abort.
  2465. */
  2466. spin_lock_irqsave(
  2467. &phba->hbalock, iflag);
  2468. cmdiocbp->iocb_flag &=
  2469. ~LPFC_DRIVER_ABORTED;
  2470. spin_unlock_irqrestore(
  2471. &phba->hbalock, iflag);
  2472. cmdiocbp->iocb.ulpStatus =
  2473. IOSTAT_LOCAL_REJECT;
  2474. cmdiocbp->iocb.un.ulpWord[4] =
  2475. IOERR_ABORT_REQUESTED;
  2476. /*
  2477. * For SLI4, irsiocb contains
  2478. * NO_XRI in sli_xritag, it
  2479. * shall not affect releasing
  2480. * sgl (xri) process.
  2481. */
  2482. saveq->iocb.ulpStatus =
  2483. IOSTAT_LOCAL_REJECT;
  2484. saveq->iocb.un.ulpWord[4] =
  2485. IOERR_SLI_ABORTED;
  2486. spin_lock_irqsave(
  2487. &phba->hbalock, iflag);
  2488. saveq->iocb_flag |=
  2489. LPFC_DELAY_MEM_FREE;
  2490. spin_unlock_irqrestore(
  2491. &phba->hbalock, iflag);
  2492. }
  2493. }
  2494. }
  2495. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2496. } else
  2497. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2498. } else {
  2499. /*
  2500. * Unknown initiating command based on the response iotag.
  2501. * This could be the case on the ELS ring because of
  2502. * lpfc_els_abort().
  2503. */
  2504. if (pring->ringno != LPFC_ELS_RING) {
  2505. /*
  2506. * Ring <ringno> handler: unexpected completion IoTag
  2507. * <IoTag>
  2508. */
  2509. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2510. "0322 Ring %d handler: "
  2511. "unexpected completion IoTag x%x "
  2512. "Data: x%x x%x x%x x%x\n",
  2513. pring->ringno,
  2514. saveq->iocb.ulpIoTag,
  2515. saveq->iocb.ulpStatus,
  2516. saveq->iocb.un.ulpWord[4],
  2517. saveq->iocb.ulpCommand,
  2518. saveq->iocb.ulpContext);
  2519. }
  2520. }
  2521. return rc;
  2522. }
  2523. /**
  2524. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2525. * @phba: Pointer to HBA context object.
  2526. * @pring: Pointer to driver SLI ring object.
  2527. *
  2528. * This function is called from the iocb ring event handlers when
  2529. * put pointer is ahead of the get pointer for a ring. This function signal
  2530. * an error attention condition to the worker thread and the worker
  2531. * thread will transition the HBA to offline state.
  2532. **/
  2533. static void
  2534. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2535. {
  2536. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2537. /*
  2538. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2539. * rsp ring <portRspMax>
  2540. */
  2541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2542. "0312 Ring %d handler: portRspPut %d "
  2543. "is bigger than rsp ring %d\n",
  2544. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2545. pring->numRiocb);
  2546. phba->link_state = LPFC_HBA_ERROR;
  2547. /*
  2548. * All error attention handlers are posted to
  2549. * worker thread
  2550. */
  2551. phba->work_ha |= HA_ERATT;
  2552. phba->work_hs = HS_FFER3;
  2553. lpfc_worker_wake_up(phba);
  2554. return;
  2555. }
  2556. /**
  2557. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2558. * @ptr: Pointer to address of HBA context object.
  2559. *
  2560. * This function is invoked by the Error Attention polling timer when the
  2561. * timer times out. It will check the SLI Error Attention register for
  2562. * possible attention events. If so, it will post an Error Attention event
  2563. * and wake up worker thread to process it. Otherwise, it will set up the
  2564. * Error Attention polling timer for the next poll.
  2565. **/
  2566. void lpfc_poll_eratt(unsigned long ptr)
  2567. {
  2568. struct lpfc_hba *phba;
  2569. uint32_t eratt = 0;
  2570. phba = (struct lpfc_hba *)ptr;
  2571. /* Check chip HA register for error event */
  2572. eratt = lpfc_sli_check_eratt(phba);
  2573. if (eratt)
  2574. /* Tell the worker thread there is work to do */
  2575. lpfc_worker_wake_up(phba);
  2576. else
  2577. /* Restart the timer for next eratt poll */
  2578. mod_timer(&phba->eratt_poll, jiffies +
  2579. HZ * LPFC_ERATT_POLL_INTERVAL);
  2580. return;
  2581. }
  2582. /**
  2583. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2584. * @phba: Pointer to HBA context object.
  2585. * @pring: Pointer to driver SLI ring object.
  2586. * @mask: Host attention register mask for this ring.
  2587. *
  2588. * This function is called from the interrupt context when there is a ring
  2589. * event for the fcp ring. The caller does not hold any lock.
  2590. * The function processes each response iocb in the response ring until it
  2591. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2592. * LE bit set. The function will call the completion handler of the command iocb
  2593. * if the response iocb indicates a completion for a command iocb or it is
  2594. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2595. * function if this is an unsolicited iocb.
  2596. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2597. * to check it explicitly.
  2598. */
  2599. int
  2600. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2601. struct lpfc_sli_ring *pring, uint32_t mask)
  2602. {
  2603. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2604. IOCB_t *irsp = NULL;
  2605. IOCB_t *entry = NULL;
  2606. struct lpfc_iocbq *cmdiocbq = NULL;
  2607. struct lpfc_iocbq rspiocbq;
  2608. uint32_t status;
  2609. uint32_t portRspPut, portRspMax;
  2610. int rc = 1;
  2611. lpfc_iocb_type type;
  2612. unsigned long iflag;
  2613. uint32_t rsp_cmpl = 0;
  2614. spin_lock_irqsave(&phba->hbalock, iflag);
  2615. pring->stats.iocb_event++;
  2616. /*
  2617. * The next available response entry should never exceed the maximum
  2618. * entries. If it does, treat it as an adapter hardware error.
  2619. */
  2620. portRspMax = pring->numRiocb;
  2621. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2622. if (unlikely(portRspPut >= portRspMax)) {
  2623. lpfc_sli_rsp_pointers_error(phba, pring);
  2624. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2625. return 1;
  2626. }
  2627. if (phba->fcp_ring_in_use) {
  2628. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2629. return 1;
  2630. } else
  2631. phba->fcp_ring_in_use = 1;
  2632. rmb();
  2633. while (pring->rspidx != portRspPut) {
  2634. /*
  2635. * Fetch an entry off the ring and copy it into a local data
  2636. * structure. The copy involves a byte-swap since the
  2637. * network byte order and pci byte orders are different.
  2638. */
  2639. entry = lpfc_resp_iocb(phba, pring);
  2640. phba->last_completion_time = jiffies;
  2641. if (++pring->rspidx >= portRspMax)
  2642. pring->rspidx = 0;
  2643. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2644. (uint32_t *) &rspiocbq.iocb,
  2645. phba->iocb_rsp_size);
  2646. INIT_LIST_HEAD(&(rspiocbq.list));
  2647. irsp = &rspiocbq.iocb;
  2648. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2649. pring->stats.iocb_rsp++;
  2650. rsp_cmpl++;
  2651. if (unlikely(irsp->ulpStatus)) {
  2652. /*
  2653. * If resource errors reported from HBA, reduce
  2654. * queuedepths of the SCSI device.
  2655. */
  2656. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2657. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2658. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2659. phba->lpfc_rampdown_queue_depth(phba);
  2660. spin_lock_irqsave(&phba->hbalock, iflag);
  2661. }
  2662. /* Rsp ring <ringno> error: IOCB */
  2663. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2664. "0336 Rsp Ring %d error: IOCB Data: "
  2665. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2666. pring->ringno,
  2667. irsp->un.ulpWord[0],
  2668. irsp->un.ulpWord[1],
  2669. irsp->un.ulpWord[2],
  2670. irsp->un.ulpWord[3],
  2671. irsp->un.ulpWord[4],
  2672. irsp->un.ulpWord[5],
  2673. *(uint32_t *)&irsp->un1,
  2674. *((uint32_t *)&irsp->un1 + 1));
  2675. }
  2676. switch (type) {
  2677. case LPFC_ABORT_IOCB:
  2678. case LPFC_SOL_IOCB:
  2679. /*
  2680. * Idle exchange closed via ABTS from port. No iocb
  2681. * resources need to be recovered.
  2682. */
  2683. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2684. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2685. "0333 IOCB cmd 0x%x"
  2686. " processed. Skipping"
  2687. " completion\n",
  2688. irsp->ulpCommand);
  2689. break;
  2690. }
  2691. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2692. &rspiocbq);
  2693. if (unlikely(!cmdiocbq))
  2694. break;
  2695. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2696. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2697. if (cmdiocbq->iocb_cmpl) {
  2698. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2699. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2700. &rspiocbq);
  2701. spin_lock_irqsave(&phba->hbalock, iflag);
  2702. }
  2703. break;
  2704. case LPFC_UNSOL_IOCB:
  2705. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2706. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2707. spin_lock_irqsave(&phba->hbalock, iflag);
  2708. break;
  2709. default:
  2710. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2711. char adaptermsg[LPFC_MAX_ADPTMSG];
  2712. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2713. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2714. MAX_MSG_DATA);
  2715. dev_warn(&((phba->pcidev)->dev),
  2716. "lpfc%d: %s\n",
  2717. phba->brd_no, adaptermsg);
  2718. } else {
  2719. /* Unknown IOCB command */
  2720. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2721. "0334 Unknown IOCB command "
  2722. "Data: x%x, x%x x%x x%x x%x\n",
  2723. type, irsp->ulpCommand,
  2724. irsp->ulpStatus,
  2725. irsp->ulpIoTag,
  2726. irsp->ulpContext);
  2727. }
  2728. break;
  2729. }
  2730. /*
  2731. * The response IOCB has been processed. Update the ring
  2732. * pointer in SLIM. If the port response put pointer has not
  2733. * been updated, sync the pgp->rspPutInx and fetch the new port
  2734. * response put pointer.
  2735. */
  2736. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2737. if (pring->rspidx == portRspPut)
  2738. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2739. }
  2740. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2741. pring->stats.iocb_rsp_full++;
  2742. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2743. writel(status, phba->CAregaddr);
  2744. readl(phba->CAregaddr);
  2745. }
  2746. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2747. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2748. pring->stats.iocb_cmd_empty++;
  2749. /* Force update of the local copy of cmdGetInx */
  2750. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2751. lpfc_sli_resume_iocb(phba, pring);
  2752. if ((pring->lpfc_sli_cmd_available))
  2753. (pring->lpfc_sli_cmd_available) (phba, pring);
  2754. }
  2755. phba->fcp_ring_in_use = 0;
  2756. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2757. return rc;
  2758. }
  2759. /**
  2760. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2761. * @phba: Pointer to HBA context object.
  2762. * @pring: Pointer to driver SLI ring object.
  2763. * @rspiocbp: Pointer to driver response IOCB object.
  2764. *
  2765. * This function is called from the worker thread when there is a slow-path
  2766. * response IOCB to process. This function chains all the response iocbs until
  2767. * seeing the iocb with the LE bit set. The function will call
  2768. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2769. * completion of a command iocb. The function will call the
  2770. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2771. * The function frees the resources or calls the completion handler if this
  2772. * iocb is an abort completion. The function returns NULL when the response
  2773. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2774. * this function shall chain the iocb on to the iocb_continueq and return the
  2775. * response iocb passed in.
  2776. **/
  2777. static struct lpfc_iocbq *
  2778. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2779. struct lpfc_iocbq *rspiocbp)
  2780. {
  2781. struct lpfc_iocbq *saveq;
  2782. struct lpfc_iocbq *cmdiocbp;
  2783. struct lpfc_iocbq *next_iocb;
  2784. IOCB_t *irsp = NULL;
  2785. uint32_t free_saveq;
  2786. uint8_t iocb_cmd_type;
  2787. lpfc_iocb_type type;
  2788. unsigned long iflag;
  2789. int rc;
  2790. spin_lock_irqsave(&phba->hbalock, iflag);
  2791. /* First add the response iocb to the countinueq list */
  2792. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2793. pring->iocb_continueq_cnt++;
  2794. /* Now, determine whetehr the list is completed for processing */
  2795. irsp = &rspiocbp->iocb;
  2796. if (irsp->ulpLe) {
  2797. /*
  2798. * By default, the driver expects to free all resources
  2799. * associated with this iocb completion.
  2800. */
  2801. free_saveq = 1;
  2802. saveq = list_get_first(&pring->iocb_continueq,
  2803. struct lpfc_iocbq, list);
  2804. irsp = &(saveq->iocb);
  2805. list_del_init(&pring->iocb_continueq);
  2806. pring->iocb_continueq_cnt = 0;
  2807. pring->stats.iocb_rsp++;
  2808. /*
  2809. * If resource errors reported from HBA, reduce
  2810. * queuedepths of the SCSI device.
  2811. */
  2812. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2813. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2814. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2815. phba->lpfc_rampdown_queue_depth(phba);
  2816. spin_lock_irqsave(&phba->hbalock, iflag);
  2817. }
  2818. if (irsp->ulpStatus) {
  2819. /* Rsp ring <ringno> error: IOCB */
  2820. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2821. "0328 Rsp Ring %d error: "
  2822. "IOCB Data: "
  2823. "x%x x%x x%x x%x "
  2824. "x%x x%x x%x x%x "
  2825. "x%x x%x x%x x%x "
  2826. "x%x x%x x%x x%x\n",
  2827. pring->ringno,
  2828. irsp->un.ulpWord[0],
  2829. irsp->un.ulpWord[1],
  2830. irsp->un.ulpWord[2],
  2831. irsp->un.ulpWord[3],
  2832. irsp->un.ulpWord[4],
  2833. irsp->un.ulpWord[5],
  2834. *(((uint32_t *) irsp) + 6),
  2835. *(((uint32_t *) irsp) + 7),
  2836. *(((uint32_t *) irsp) + 8),
  2837. *(((uint32_t *) irsp) + 9),
  2838. *(((uint32_t *) irsp) + 10),
  2839. *(((uint32_t *) irsp) + 11),
  2840. *(((uint32_t *) irsp) + 12),
  2841. *(((uint32_t *) irsp) + 13),
  2842. *(((uint32_t *) irsp) + 14),
  2843. *(((uint32_t *) irsp) + 15));
  2844. }
  2845. /*
  2846. * Fetch the IOCB command type and call the correct completion
  2847. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2848. * get freed back to the lpfc_iocb_list by the discovery
  2849. * kernel thread.
  2850. */
  2851. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2852. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2853. switch (type) {
  2854. case LPFC_SOL_IOCB:
  2855. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2856. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2857. spin_lock_irqsave(&phba->hbalock, iflag);
  2858. break;
  2859. case LPFC_UNSOL_IOCB:
  2860. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2861. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2862. spin_lock_irqsave(&phba->hbalock, iflag);
  2863. if (!rc)
  2864. free_saveq = 0;
  2865. break;
  2866. case LPFC_ABORT_IOCB:
  2867. cmdiocbp = NULL;
  2868. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2869. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2870. saveq);
  2871. if (cmdiocbp) {
  2872. /* Call the specified completion routine */
  2873. if (cmdiocbp->iocb_cmpl) {
  2874. spin_unlock_irqrestore(&phba->hbalock,
  2875. iflag);
  2876. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2877. saveq);
  2878. spin_lock_irqsave(&phba->hbalock,
  2879. iflag);
  2880. } else
  2881. __lpfc_sli_release_iocbq(phba,
  2882. cmdiocbp);
  2883. }
  2884. break;
  2885. case LPFC_UNKNOWN_IOCB:
  2886. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2887. char adaptermsg[LPFC_MAX_ADPTMSG];
  2888. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2889. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2890. MAX_MSG_DATA);
  2891. dev_warn(&((phba->pcidev)->dev),
  2892. "lpfc%d: %s\n",
  2893. phba->brd_no, adaptermsg);
  2894. } else {
  2895. /* Unknown IOCB command */
  2896. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2897. "0335 Unknown IOCB "
  2898. "command Data: x%x "
  2899. "x%x x%x x%x\n",
  2900. irsp->ulpCommand,
  2901. irsp->ulpStatus,
  2902. irsp->ulpIoTag,
  2903. irsp->ulpContext);
  2904. }
  2905. break;
  2906. }
  2907. if (free_saveq) {
  2908. list_for_each_entry_safe(rspiocbp, next_iocb,
  2909. &saveq->list, list) {
  2910. list_del(&rspiocbp->list);
  2911. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2912. }
  2913. __lpfc_sli_release_iocbq(phba, saveq);
  2914. }
  2915. rspiocbp = NULL;
  2916. }
  2917. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2918. return rspiocbp;
  2919. }
  2920. /**
  2921. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2922. * @phba: Pointer to HBA context object.
  2923. * @pring: Pointer to driver SLI ring object.
  2924. * @mask: Host attention register mask for this ring.
  2925. *
  2926. * This routine wraps the actual slow_ring event process routine from the
  2927. * API jump table function pointer from the lpfc_hba struct.
  2928. **/
  2929. void
  2930. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2931. struct lpfc_sli_ring *pring, uint32_t mask)
  2932. {
  2933. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2934. }
  2935. /**
  2936. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2937. * @phba: Pointer to HBA context object.
  2938. * @pring: Pointer to driver SLI ring object.
  2939. * @mask: Host attention register mask for this ring.
  2940. *
  2941. * This function is called from the worker thread when there is a ring event
  2942. * for non-fcp rings. The caller does not hold any lock. The function will
  2943. * remove each response iocb in the response ring and calls the handle
  2944. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2945. **/
  2946. static void
  2947. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2948. struct lpfc_sli_ring *pring, uint32_t mask)
  2949. {
  2950. struct lpfc_pgp *pgp;
  2951. IOCB_t *entry;
  2952. IOCB_t *irsp = NULL;
  2953. struct lpfc_iocbq *rspiocbp = NULL;
  2954. uint32_t portRspPut, portRspMax;
  2955. unsigned long iflag;
  2956. uint32_t status;
  2957. pgp = &phba->port_gp[pring->ringno];
  2958. spin_lock_irqsave(&phba->hbalock, iflag);
  2959. pring->stats.iocb_event++;
  2960. /*
  2961. * The next available response entry should never exceed the maximum
  2962. * entries. If it does, treat it as an adapter hardware error.
  2963. */
  2964. portRspMax = pring->numRiocb;
  2965. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2966. if (portRspPut >= portRspMax) {
  2967. /*
  2968. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2969. * rsp ring <portRspMax>
  2970. */
  2971. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2972. "0303 Ring %d handler: portRspPut %d "
  2973. "is bigger than rsp ring %d\n",
  2974. pring->ringno, portRspPut, portRspMax);
  2975. phba->link_state = LPFC_HBA_ERROR;
  2976. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2977. phba->work_hs = HS_FFER3;
  2978. lpfc_handle_eratt(phba);
  2979. return;
  2980. }
  2981. rmb();
  2982. while (pring->rspidx != portRspPut) {
  2983. /*
  2984. * Build a completion list and call the appropriate handler.
  2985. * The process is to get the next available response iocb, get
  2986. * a free iocb from the list, copy the response data into the
  2987. * free iocb, insert to the continuation list, and update the
  2988. * next response index to slim. This process makes response
  2989. * iocb's in the ring available to DMA as fast as possible but
  2990. * pays a penalty for a copy operation. Since the iocb is
  2991. * only 32 bytes, this penalty is considered small relative to
  2992. * the PCI reads for register values and a slim write. When
  2993. * the ulpLe field is set, the entire Command has been
  2994. * received.
  2995. */
  2996. entry = lpfc_resp_iocb(phba, pring);
  2997. phba->last_completion_time = jiffies;
  2998. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2999. if (rspiocbp == NULL) {
  3000. printk(KERN_ERR "%s: out of buffers! Failing "
  3001. "completion.\n", __func__);
  3002. break;
  3003. }
  3004. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3005. phba->iocb_rsp_size);
  3006. irsp = &rspiocbp->iocb;
  3007. if (++pring->rspidx >= portRspMax)
  3008. pring->rspidx = 0;
  3009. if (pring->ringno == LPFC_ELS_RING) {
  3010. lpfc_debugfs_slow_ring_trc(phba,
  3011. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3012. *(((uint32_t *) irsp) + 4),
  3013. *(((uint32_t *) irsp) + 6),
  3014. *(((uint32_t *) irsp) + 7));
  3015. }
  3016. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3018. /* Handle the response IOCB */
  3019. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3020. spin_lock_irqsave(&phba->hbalock, iflag);
  3021. /*
  3022. * If the port response put pointer has not been updated, sync
  3023. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3024. * response put pointer.
  3025. */
  3026. if (pring->rspidx == portRspPut) {
  3027. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3028. }
  3029. } /* while (pring->rspidx != portRspPut) */
  3030. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3031. /* At least one response entry has been freed */
  3032. pring->stats.iocb_rsp_full++;
  3033. /* SET RxRE_RSP in Chip Att register */
  3034. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3035. writel(status, phba->CAregaddr);
  3036. readl(phba->CAregaddr); /* flush */
  3037. }
  3038. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3039. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3040. pring->stats.iocb_cmd_empty++;
  3041. /* Force update of the local copy of cmdGetInx */
  3042. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3043. lpfc_sli_resume_iocb(phba, pring);
  3044. if ((pring->lpfc_sli_cmd_available))
  3045. (pring->lpfc_sli_cmd_available) (phba, pring);
  3046. }
  3047. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3048. return;
  3049. }
  3050. /**
  3051. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3052. * @phba: Pointer to HBA context object.
  3053. * @pring: Pointer to driver SLI ring object.
  3054. * @mask: Host attention register mask for this ring.
  3055. *
  3056. * This function is called from the worker thread when there is a pending
  3057. * ELS response iocb on the driver internal slow-path response iocb worker
  3058. * queue. The caller does not hold any lock. The function will remove each
  3059. * response iocb from the response worker queue and calls the handle
  3060. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3061. **/
  3062. static void
  3063. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3064. struct lpfc_sli_ring *pring, uint32_t mask)
  3065. {
  3066. struct lpfc_iocbq *irspiocbq;
  3067. struct hbq_dmabuf *dmabuf;
  3068. struct lpfc_cq_event *cq_event;
  3069. unsigned long iflag;
  3070. spin_lock_irqsave(&phba->hbalock, iflag);
  3071. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3072. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3073. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3074. /* Get the response iocb from the head of work queue */
  3075. spin_lock_irqsave(&phba->hbalock, iflag);
  3076. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3077. cq_event, struct lpfc_cq_event, list);
  3078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3079. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3080. case CQE_CODE_COMPL_WQE:
  3081. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3082. cq_event);
  3083. /* Translate ELS WCQE to response IOCBQ */
  3084. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3085. irspiocbq);
  3086. if (irspiocbq)
  3087. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3088. irspiocbq);
  3089. break;
  3090. case CQE_CODE_RECEIVE:
  3091. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3092. cq_event);
  3093. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3094. break;
  3095. default:
  3096. break;
  3097. }
  3098. }
  3099. }
  3100. /**
  3101. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3102. * @phba: Pointer to HBA context object.
  3103. * @pring: Pointer to driver SLI ring object.
  3104. *
  3105. * This function aborts all iocbs in the given ring and frees all the iocb
  3106. * objects in txq. This function issues an abort iocb for all the iocb commands
  3107. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3108. * the return of this function. The caller is not required to hold any locks.
  3109. **/
  3110. void
  3111. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3112. {
  3113. LIST_HEAD(completions);
  3114. struct lpfc_iocbq *iocb, *next_iocb;
  3115. if (pring->ringno == LPFC_ELS_RING) {
  3116. lpfc_fabric_abort_hba(phba);
  3117. }
  3118. /* Error everything on txq and txcmplq
  3119. * First do the txq.
  3120. */
  3121. spin_lock_irq(&phba->hbalock);
  3122. list_splice_init(&pring->txq, &completions);
  3123. pring->txq_cnt = 0;
  3124. /* Next issue ABTS for everything on the txcmplq */
  3125. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3126. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3127. spin_unlock_irq(&phba->hbalock);
  3128. /* Cancel all the IOCBs from the completions list */
  3129. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3130. IOERR_SLI_ABORTED);
  3131. }
  3132. /**
  3133. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3134. * @phba: Pointer to HBA context object.
  3135. *
  3136. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3137. * objects in txq and txcmplq. This function will not issue abort iocbs
  3138. * for all the iocb commands in txcmplq, they will just be returned with
  3139. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3140. * slot has been permanently disabled.
  3141. **/
  3142. void
  3143. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3144. {
  3145. LIST_HEAD(txq);
  3146. LIST_HEAD(txcmplq);
  3147. struct lpfc_sli *psli = &phba->sli;
  3148. struct lpfc_sli_ring *pring;
  3149. /* Currently, only one fcp ring */
  3150. pring = &psli->ring[psli->fcp_ring];
  3151. spin_lock_irq(&phba->hbalock);
  3152. /* Retrieve everything on txq */
  3153. list_splice_init(&pring->txq, &txq);
  3154. pring->txq_cnt = 0;
  3155. /* Retrieve everything on the txcmplq */
  3156. list_splice_init(&pring->txcmplq, &txcmplq);
  3157. pring->txcmplq_cnt = 0;
  3158. spin_unlock_irq(&phba->hbalock);
  3159. /* Flush the txq */
  3160. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3161. IOERR_SLI_DOWN);
  3162. /* Flush the txcmpq */
  3163. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3164. IOERR_SLI_DOWN);
  3165. }
  3166. /**
  3167. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3168. * @phba: Pointer to HBA context object.
  3169. * @mask: Bit mask to be checked.
  3170. *
  3171. * This function reads the host status register and compares
  3172. * with the provided bit mask to check if HBA completed
  3173. * the restart. This function will wait in a loop for the
  3174. * HBA to complete restart. If the HBA does not restart within
  3175. * 15 iterations, the function will reset the HBA again. The
  3176. * function returns 1 when HBA fail to restart otherwise returns
  3177. * zero.
  3178. **/
  3179. static int
  3180. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3181. {
  3182. uint32_t status;
  3183. int i = 0;
  3184. int retval = 0;
  3185. /* Read the HBA Host Status Register */
  3186. status = readl(phba->HSregaddr);
  3187. /*
  3188. * Check status register every 100ms for 5 retries, then every
  3189. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3190. * every 2.5 sec for 4.
  3191. * Break our of the loop if errors occurred during init.
  3192. */
  3193. while (((status & mask) != mask) &&
  3194. !(status & HS_FFERM) &&
  3195. i++ < 20) {
  3196. if (i <= 5)
  3197. msleep(10);
  3198. else if (i <= 10)
  3199. msleep(500);
  3200. else
  3201. msleep(2500);
  3202. if (i == 15) {
  3203. /* Do post */
  3204. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3205. lpfc_sli_brdrestart(phba);
  3206. }
  3207. /* Read the HBA Host Status Register */
  3208. status = readl(phba->HSregaddr);
  3209. }
  3210. /* Check to see if any errors occurred during init */
  3211. if ((status & HS_FFERM) || (i >= 20)) {
  3212. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3213. "2751 Adapter failed to restart, "
  3214. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3215. status,
  3216. readl(phba->MBslimaddr + 0xa8),
  3217. readl(phba->MBslimaddr + 0xac));
  3218. phba->link_state = LPFC_HBA_ERROR;
  3219. retval = 1;
  3220. }
  3221. return retval;
  3222. }
  3223. /**
  3224. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3225. * @phba: Pointer to HBA context object.
  3226. * @mask: Bit mask to be checked.
  3227. *
  3228. * This function checks the host status register to check if HBA is
  3229. * ready. This function will wait in a loop for the HBA to be ready
  3230. * If the HBA is not ready , the function will will reset the HBA PCI
  3231. * function again. The function returns 1 when HBA fail to be ready
  3232. * otherwise returns zero.
  3233. **/
  3234. static int
  3235. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3236. {
  3237. uint32_t status;
  3238. int retval = 0;
  3239. /* Read the HBA Host Status Register */
  3240. status = lpfc_sli4_post_status_check(phba);
  3241. if (status) {
  3242. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3243. lpfc_sli_brdrestart(phba);
  3244. status = lpfc_sli4_post_status_check(phba);
  3245. }
  3246. /* Check to see if any errors occurred during init */
  3247. if (status) {
  3248. phba->link_state = LPFC_HBA_ERROR;
  3249. retval = 1;
  3250. } else
  3251. phba->sli4_hba.intr_enable = 0;
  3252. return retval;
  3253. }
  3254. /**
  3255. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3256. * @phba: Pointer to HBA context object.
  3257. * @mask: Bit mask to be checked.
  3258. *
  3259. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3260. * from the API jump table function pointer from the lpfc_hba struct.
  3261. **/
  3262. int
  3263. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3264. {
  3265. return phba->lpfc_sli_brdready(phba, mask);
  3266. }
  3267. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3268. /**
  3269. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3270. * @phba: Pointer to HBA context object.
  3271. *
  3272. * This function is called before resetting an HBA. This
  3273. * function requests HBA to quiesce DMAs before a reset.
  3274. **/
  3275. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3276. {
  3277. uint32_t __iomem *resp_buf;
  3278. uint32_t __iomem *mbox_buf;
  3279. volatile uint32_t mbox;
  3280. uint32_t hc_copy;
  3281. int i;
  3282. uint8_t hdrtype;
  3283. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3284. if (hdrtype != 0x80 ||
  3285. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3286. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3287. return;
  3288. /*
  3289. * Tell the other part of the chip to suspend temporarily all
  3290. * its DMA activity.
  3291. */
  3292. resp_buf = phba->MBslimaddr;
  3293. /* Disable the error attention */
  3294. hc_copy = readl(phba->HCregaddr);
  3295. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3296. readl(phba->HCregaddr); /* flush */
  3297. phba->link_flag |= LS_IGNORE_ERATT;
  3298. if (readl(phba->HAregaddr) & HA_ERATT) {
  3299. /* Clear Chip error bit */
  3300. writel(HA_ERATT, phba->HAregaddr);
  3301. phba->pport->stopped = 1;
  3302. }
  3303. mbox = 0;
  3304. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3305. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3306. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3307. mbox_buf = phba->MBslimaddr;
  3308. writel(mbox, mbox_buf);
  3309. for (i = 0;
  3310. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  3311. mdelay(1);
  3312. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  3313. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3314. phba->pport->stopped)
  3315. goto restore_hc;
  3316. else
  3317. goto clear_errat;
  3318. }
  3319. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3320. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  3321. mdelay(1);
  3322. clear_errat:
  3323. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3324. mdelay(1);
  3325. if (readl(phba->HAregaddr) & HA_ERATT) {
  3326. writel(HA_ERATT, phba->HAregaddr);
  3327. phba->pport->stopped = 1;
  3328. }
  3329. restore_hc:
  3330. phba->link_flag &= ~LS_IGNORE_ERATT;
  3331. writel(hc_copy, phba->HCregaddr);
  3332. readl(phba->HCregaddr); /* flush */
  3333. }
  3334. /**
  3335. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3336. * @phba: Pointer to HBA context object.
  3337. *
  3338. * This function issues a kill_board mailbox command and waits for
  3339. * the error attention interrupt. This function is called for stopping
  3340. * the firmware processing. The caller is not required to hold any
  3341. * locks. This function calls lpfc_hba_down_post function to free
  3342. * any pending commands after the kill. The function will return 1 when it
  3343. * fails to kill the board else will return 0.
  3344. **/
  3345. int
  3346. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3347. {
  3348. struct lpfc_sli *psli;
  3349. LPFC_MBOXQ_t *pmb;
  3350. uint32_t status;
  3351. uint32_t ha_copy;
  3352. int retval;
  3353. int i = 0;
  3354. psli = &phba->sli;
  3355. /* Kill HBA */
  3356. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3357. "0329 Kill HBA Data: x%x x%x\n",
  3358. phba->pport->port_state, psli->sli_flag);
  3359. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3360. if (!pmb)
  3361. return 1;
  3362. /* Disable the error attention */
  3363. spin_lock_irq(&phba->hbalock);
  3364. status = readl(phba->HCregaddr);
  3365. status &= ~HC_ERINT_ENA;
  3366. writel(status, phba->HCregaddr);
  3367. readl(phba->HCregaddr); /* flush */
  3368. phba->link_flag |= LS_IGNORE_ERATT;
  3369. spin_unlock_irq(&phba->hbalock);
  3370. lpfc_kill_board(phba, pmb);
  3371. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3372. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3373. if (retval != MBX_SUCCESS) {
  3374. if (retval != MBX_BUSY)
  3375. mempool_free(pmb, phba->mbox_mem_pool);
  3376. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3377. "2752 KILL_BOARD command failed retval %d\n",
  3378. retval);
  3379. spin_lock_irq(&phba->hbalock);
  3380. phba->link_flag &= ~LS_IGNORE_ERATT;
  3381. spin_unlock_irq(&phba->hbalock);
  3382. return 1;
  3383. }
  3384. spin_lock_irq(&phba->hbalock);
  3385. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3386. spin_unlock_irq(&phba->hbalock);
  3387. mempool_free(pmb, phba->mbox_mem_pool);
  3388. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3389. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3390. * 3 seconds we still set HBA_ERROR state because the status of the
  3391. * board is now undefined.
  3392. */
  3393. ha_copy = readl(phba->HAregaddr);
  3394. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3395. mdelay(100);
  3396. ha_copy = readl(phba->HAregaddr);
  3397. }
  3398. del_timer_sync(&psli->mbox_tmo);
  3399. if (ha_copy & HA_ERATT) {
  3400. writel(HA_ERATT, phba->HAregaddr);
  3401. phba->pport->stopped = 1;
  3402. }
  3403. spin_lock_irq(&phba->hbalock);
  3404. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3405. psli->mbox_active = NULL;
  3406. phba->link_flag &= ~LS_IGNORE_ERATT;
  3407. spin_unlock_irq(&phba->hbalock);
  3408. lpfc_hba_down_post(phba);
  3409. phba->link_state = LPFC_HBA_ERROR;
  3410. return ha_copy & HA_ERATT ? 0 : 1;
  3411. }
  3412. /**
  3413. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3414. * @phba: Pointer to HBA context object.
  3415. *
  3416. * This function resets the HBA by writing HC_INITFF to the control
  3417. * register. After the HBA resets, this function resets all the iocb ring
  3418. * indices. This function disables PCI layer parity checking during
  3419. * the reset.
  3420. * This function returns 0 always.
  3421. * The caller is not required to hold any locks.
  3422. **/
  3423. int
  3424. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3425. {
  3426. struct lpfc_sli *psli;
  3427. struct lpfc_sli_ring *pring;
  3428. uint16_t cfg_value;
  3429. int i;
  3430. psli = &phba->sli;
  3431. /* Reset HBA */
  3432. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3433. "0325 Reset HBA Data: x%x x%x\n",
  3434. phba->pport->port_state, psli->sli_flag);
  3435. /* perform board reset */
  3436. phba->fc_eventTag = 0;
  3437. phba->link_events = 0;
  3438. phba->pport->fc_myDID = 0;
  3439. phba->pport->fc_prevDID = 0;
  3440. /* Turn off parity checking and serr during the physical reset */
  3441. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3442. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3443. (cfg_value &
  3444. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3445. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3446. /* Now toggle INITFF bit in the Host Control Register */
  3447. writel(HC_INITFF, phba->HCregaddr);
  3448. mdelay(1);
  3449. readl(phba->HCregaddr); /* flush */
  3450. writel(0, phba->HCregaddr);
  3451. readl(phba->HCregaddr); /* flush */
  3452. /* Restore PCI cmd register */
  3453. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3454. /* Initialize relevant SLI info */
  3455. for (i = 0; i < psli->num_rings; i++) {
  3456. pring = &psli->ring[i];
  3457. pring->flag = 0;
  3458. pring->rspidx = 0;
  3459. pring->next_cmdidx = 0;
  3460. pring->local_getidx = 0;
  3461. pring->cmdidx = 0;
  3462. pring->missbufcnt = 0;
  3463. }
  3464. phba->link_state = LPFC_WARM_START;
  3465. return 0;
  3466. }
  3467. /**
  3468. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3469. * @phba: Pointer to HBA context object.
  3470. *
  3471. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3472. * checking during resets the device. The caller is not required to hold
  3473. * any locks.
  3474. *
  3475. * This function returns 0 always.
  3476. **/
  3477. int
  3478. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3479. {
  3480. struct lpfc_sli *psli = &phba->sli;
  3481. uint16_t cfg_value;
  3482. uint8_t qindx;
  3483. /* Reset HBA */
  3484. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3485. "0295 Reset HBA Data: x%x x%x\n",
  3486. phba->pport->port_state, psli->sli_flag);
  3487. /* perform board reset */
  3488. phba->fc_eventTag = 0;
  3489. phba->link_events = 0;
  3490. phba->pport->fc_myDID = 0;
  3491. phba->pport->fc_prevDID = 0;
  3492. spin_lock_irq(&phba->hbalock);
  3493. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3494. phba->fcf.fcf_flag = 0;
  3495. /* Clean up the child queue list for the CQs */
  3496. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3497. list_del_init(&phba->sli4_hba.els_wq->list);
  3498. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3499. list_del_init(&phba->sli4_hba.dat_rq->list);
  3500. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3501. list_del_init(&phba->sli4_hba.els_cq->list);
  3502. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3503. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3504. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3505. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3506. spin_unlock_irq(&phba->hbalock);
  3507. /* Now physically reset the device */
  3508. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3509. "0389 Performing PCI function reset!\n");
  3510. /* Turn off parity checking and serr during the physical reset */
  3511. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3512. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3513. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3514. /* Perform FCoE PCI function reset */
  3515. lpfc_pci_function_reset(phba);
  3516. /* Restore PCI cmd register */
  3517. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3518. return 0;
  3519. }
  3520. /**
  3521. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3522. * @phba: Pointer to HBA context object.
  3523. *
  3524. * This function is called in the SLI initialization code path to
  3525. * restart the HBA. The caller is not required to hold any lock.
  3526. * This function writes MBX_RESTART mailbox command to the SLIM and
  3527. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3528. * function to free any pending commands. The function enables
  3529. * POST only during the first initialization. The function returns zero.
  3530. * The function does not guarantee completion of MBX_RESTART mailbox
  3531. * command before the return of this function.
  3532. **/
  3533. static int
  3534. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3535. {
  3536. MAILBOX_t *mb;
  3537. struct lpfc_sli *psli;
  3538. volatile uint32_t word0;
  3539. void __iomem *to_slim;
  3540. uint32_t hba_aer_enabled;
  3541. spin_lock_irq(&phba->hbalock);
  3542. /* Take PCIe device Advanced Error Reporting (AER) state */
  3543. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3544. psli = &phba->sli;
  3545. /* Restart HBA */
  3546. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3547. "0337 Restart HBA Data: x%x x%x\n",
  3548. phba->pport->port_state, psli->sli_flag);
  3549. word0 = 0;
  3550. mb = (MAILBOX_t *) &word0;
  3551. mb->mbxCommand = MBX_RESTART;
  3552. mb->mbxHc = 1;
  3553. lpfc_reset_barrier(phba);
  3554. to_slim = phba->MBslimaddr;
  3555. writel(*(uint32_t *) mb, to_slim);
  3556. readl(to_slim); /* flush */
  3557. /* Only skip post after fc_ffinit is completed */
  3558. if (phba->pport->port_state)
  3559. word0 = 1; /* This is really setting up word1 */
  3560. else
  3561. word0 = 0; /* This is really setting up word1 */
  3562. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3563. writel(*(uint32_t *) mb, to_slim);
  3564. readl(to_slim); /* flush */
  3565. lpfc_sli_brdreset(phba);
  3566. phba->pport->stopped = 0;
  3567. phba->link_state = LPFC_INIT_START;
  3568. phba->hba_flag = 0;
  3569. spin_unlock_irq(&phba->hbalock);
  3570. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3571. psli->stats_start = get_seconds();
  3572. /* Give the INITFF and Post time to settle. */
  3573. mdelay(100);
  3574. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3575. if (hba_aer_enabled)
  3576. pci_disable_pcie_error_reporting(phba->pcidev);
  3577. lpfc_hba_down_post(phba);
  3578. return 0;
  3579. }
  3580. /**
  3581. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3582. * @phba: Pointer to HBA context object.
  3583. *
  3584. * This function is called in the SLI initialization code path to restart
  3585. * a SLI4 HBA. The caller is not required to hold any lock.
  3586. * At the end of the function, it calls lpfc_hba_down_post function to
  3587. * free any pending commands.
  3588. **/
  3589. static int
  3590. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3591. {
  3592. struct lpfc_sli *psli = &phba->sli;
  3593. uint32_t hba_aer_enabled;
  3594. /* Restart HBA */
  3595. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3596. "0296 Restart HBA Data: x%x x%x\n",
  3597. phba->pport->port_state, psli->sli_flag);
  3598. /* Take PCIe device Advanced Error Reporting (AER) state */
  3599. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3600. lpfc_sli4_brdreset(phba);
  3601. spin_lock_irq(&phba->hbalock);
  3602. phba->pport->stopped = 0;
  3603. phba->link_state = LPFC_INIT_START;
  3604. phba->hba_flag = 0;
  3605. spin_unlock_irq(&phba->hbalock);
  3606. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3607. psli->stats_start = get_seconds();
  3608. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3609. if (hba_aer_enabled)
  3610. pci_disable_pcie_error_reporting(phba->pcidev);
  3611. lpfc_hba_down_post(phba);
  3612. return 0;
  3613. }
  3614. /**
  3615. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3616. * @phba: Pointer to HBA context object.
  3617. *
  3618. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3619. * API jump table function pointer from the lpfc_hba struct.
  3620. **/
  3621. int
  3622. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3623. {
  3624. return phba->lpfc_sli_brdrestart(phba);
  3625. }
  3626. /**
  3627. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3628. * @phba: Pointer to HBA context object.
  3629. *
  3630. * This function is called after a HBA restart to wait for successful
  3631. * restart of the HBA. Successful restart of the HBA is indicated by
  3632. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3633. * iteration, the function will restart the HBA again. The function returns
  3634. * zero if HBA successfully restarted else returns negative error code.
  3635. **/
  3636. static int
  3637. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3638. {
  3639. uint32_t status, i = 0;
  3640. /* Read the HBA Host Status Register */
  3641. status = readl(phba->HSregaddr);
  3642. /* Check status register to see what current state is */
  3643. i = 0;
  3644. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3645. /* Check every 10ms for 10 retries, then every 100ms for 90
  3646. * retries, then every 1 sec for 50 retires for a total of
  3647. * ~60 seconds before reset the board again and check every
  3648. * 1 sec for 50 retries. The up to 60 seconds before the
  3649. * board ready is required by the Falcon FIPS zeroization
  3650. * complete, and any reset the board in between shall cause
  3651. * restart of zeroization, further delay the board ready.
  3652. */
  3653. if (i++ >= 200) {
  3654. /* Adapter failed to init, timeout, status reg
  3655. <status> */
  3656. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3657. "0436 Adapter failed to init, "
  3658. "timeout, status reg x%x, "
  3659. "FW Data: A8 x%x AC x%x\n", status,
  3660. readl(phba->MBslimaddr + 0xa8),
  3661. readl(phba->MBslimaddr + 0xac));
  3662. phba->link_state = LPFC_HBA_ERROR;
  3663. return -ETIMEDOUT;
  3664. }
  3665. /* Check to see if any errors occurred during init */
  3666. if (status & HS_FFERM) {
  3667. /* ERROR: During chipset initialization */
  3668. /* Adapter failed to init, chipset, status reg
  3669. <status> */
  3670. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3671. "0437 Adapter failed to init, "
  3672. "chipset, status reg x%x, "
  3673. "FW Data: A8 x%x AC x%x\n", status,
  3674. readl(phba->MBslimaddr + 0xa8),
  3675. readl(phba->MBslimaddr + 0xac));
  3676. phba->link_state = LPFC_HBA_ERROR;
  3677. return -EIO;
  3678. }
  3679. if (i <= 10)
  3680. msleep(10);
  3681. else if (i <= 100)
  3682. msleep(100);
  3683. else
  3684. msleep(1000);
  3685. if (i == 150) {
  3686. /* Do post */
  3687. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3688. lpfc_sli_brdrestart(phba);
  3689. }
  3690. /* Read the HBA Host Status Register */
  3691. status = readl(phba->HSregaddr);
  3692. }
  3693. /* Check to see if any errors occurred during init */
  3694. if (status & HS_FFERM) {
  3695. /* ERROR: During chipset initialization */
  3696. /* Adapter failed to init, chipset, status reg <status> */
  3697. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3698. "0438 Adapter failed to init, chipset, "
  3699. "status reg x%x, "
  3700. "FW Data: A8 x%x AC x%x\n", status,
  3701. readl(phba->MBslimaddr + 0xa8),
  3702. readl(phba->MBslimaddr + 0xac));
  3703. phba->link_state = LPFC_HBA_ERROR;
  3704. return -EIO;
  3705. }
  3706. /* Clear all interrupt enable conditions */
  3707. writel(0, phba->HCregaddr);
  3708. readl(phba->HCregaddr); /* flush */
  3709. /* setup host attn register */
  3710. writel(0xffffffff, phba->HAregaddr);
  3711. readl(phba->HAregaddr); /* flush */
  3712. return 0;
  3713. }
  3714. /**
  3715. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3716. *
  3717. * This function calculates and returns the number of HBQs required to be
  3718. * configured.
  3719. **/
  3720. int
  3721. lpfc_sli_hbq_count(void)
  3722. {
  3723. return ARRAY_SIZE(lpfc_hbq_defs);
  3724. }
  3725. /**
  3726. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3727. *
  3728. * This function adds the number of hbq entries in every HBQ to get
  3729. * the total number of hbq entries required for the HBA and returns
  3730. * the total count.
  3731. **/
  3732. static int
  3733. lpfc_sli_hbq_entry_count(void)
  3734. {
  3735. int hbq_count = lpfc_sli_hbq_count();
  3736. int count = 0;
  3737. int i;
  3738. for (i = 0; i < hbq_count; ++i)
  3739. count += lpfc_hbq_defs[i]->entry_count;
  3740. return count;
  3741. }
  3742. /**
  3743. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3744. *
  3745. * This function calculates amount of memory required for all hbq entries
  3746. * to be configured and returns the total memory required.
  3747. **/
  3748. int
  3749. lpfc_sli_hbq_size(void)
  3750. {
  3751. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3752. }
  3753. /**
  3754. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3755. * @phba: Pointer to HBA context object.
  3756. *
  3757. * This function is called during the SLI initialization to configure
  3758. * all the HBQs and post buffers to the HBQ. The caller is not
  3759. * required to hold any locks. This function will return zero if successful
  3760. * else it will return negative error code.
  3761. **/
  3762. static int
  3763. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3764. {
  3765. int hbq_count = lpfc_sli_hbq_count();
  3766. LPFC_MBOXQ_t *pmb;
  3767. MAILBOX_t *pmbox;
  3768. uint32_t hbqno;
  3769. uint32_t hbq_entry_index;
  3770. /* Get a Mailbox buffer to setup mailbox
  3771. * commands for HBA initialization
  3772. */
  3773. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3774. if (!pmb)
  3775. return -ENOMEM;
  3776. pmbox = &pmb->u.mb;
  3777. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3778. phba->link_state = LPFC_INIT_MBX_CMDS;
  3779. phba->hbq_in_use = 1;
  3780. hbq_entry_index = 0;
  3781. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3782. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3783. phba->hbqs[hbqno].hbqPutIdx = 0;
  3784. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3785. phba->hbqs[hbqno].entry_count =
  3786. lpfc_hbq_defs[hbqno]->entry_count;
  3787. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3788. hbq_entry_index, pmb);
  3789. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3790. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3791. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3792. mbxStatus <status>, ring <num> */
  3793. lpfc_printf_log(phba, KERN_ERR,
  3794. LOG_SLI | LOG_VPORT,
  3795. "1805 Adapter failed to init. "
  3796. "Data: x%x x%x x%x\n",
  3797. pmbox->mbxCommand,
  3798. pmbox->mbxStatus, hbqno);
  3799. phba->link_state = LPFC_HBA_ERROR;
  3800. mempool_free(pmb, phba->mbox_mem_pool);
  3801. return -ENXIO;
  3802. }
  3803. }
  3804. phba->hbq_count = hbq_count;
  3805. mempool_free(pmb, phba->mbox_mem_pool);
  3806. /* Initially populate or replenish the HBQs */
  3807. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3808. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3809. return 0;
  3810. }
  3811. /**
  3812. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3813. * @phba: Pointer to HBA context object.
  3814. *
  3815. * This function is called during the SLI initialization to configure
  3816. * all the HBQs and post buffers to the HBQ. The caller is not
  3817. * required to hold any locks. This function will return zero if successful
  3818. * else it will return negative error code.
  3819. **/
  3820. static int
  3821. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3822. {
  3823. phba->hbq_in_use = 1;
  3824. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3825. phba->hbq_count = 1;
  3826. /* Initially populate or replenish the HBQs */
  3827. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3828. return 0;
  3829. }
  3830. /**
  3831. * lpfc_sli_config_port - Issue config port mailbox command
  3832. * @phba: Pointer to HBA context object.
  3833. * @sli_mode: sli mode - 2/3
  3834. *
  3835. * This function is called by the sli intialization code path
  3836. * to issue config_port mailbox command. This function restarts the
  3837. * HBA firmware and issues a config_port mailbox command to configure
  3838. * the SLI interface in the sli mode specified by sli_mode
  3839. * variable. The caller is not required to hold any locks.
  3840. * The function returns 0 if successful, else returns negative error
  3841. * code.
  3842. **/
  3843. int
  3844. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3845. {
  3846. LPFC_MBOXQ_t *pmb;
  3847. uint32_t resetcount = 0, rc = 0, done = 0;
  3848. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3849. if (!pmb) {
  3850. phba->link_state = LPFC_HBA_ERROR;
  3851. return -ENOMEM;
  3852. }
  3853. phba->sli_rev = sli_mode;
  3854. while (resetcount < 2 && !done) {
  3855. spin_lock_irq(&phba->hbalock);
  3856. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3857. spin_unlock_irq(&phba->hbalock);
  3858. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3859. lpfc_sli_brdrestart(phba);
  3860. rc = lpfc_sli_chipset_init(phba);
  3861. if (rc)
  3862. break;
  3863. spin_lock_irq(&phba->hbalock);
  3864. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3865. spin_unlock_irq(&phba->hbalock);
  3866. resetcount++;
  3867. /* Call pre CONFIG_PORT mailbox command initialization. A
  3868. * value of 0 means the call was successful. Any other
  3869. * nonzero value is a failure, but if ERESTART is returned,
  3870. * the driver may reset the HBA and try again.
  3871. */
  3872. rc = lpfc_config_port_prep(phba);
  3873. if (rc == -ERESTART) {
  3874. phba->link_state = LPFC_LINK_UNKNOWN;
  3875. continue;
  3876. } else if (rc)
  3877. break;
  3878. phba->link_state = LPFC_INIT_MBX_CMDS;
  3879. lpfc_config_port(phba, pmb);
  3880. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3881. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3882. LPFC_SLI3_HBQ_ENABLED |
  3883. LPFC_SLI3_CRP_ENABLED |
  3884. LPFC_SLI3_BG_ENABLED |
  3885. LPFC_SLI3_DSS_ENABLED);
  3886. if (rc != MBX_SUCCESS) {
  3887. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3888. "0442 Adapter failed to init, mbxCmd x%x "
  3889. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3890. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3891. spin_lock_irq(&phba->hbalock);
  3892. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3893. spin_unlock_irq(&phba->hbalock);
  3894. rc = -ENXIO;
  3895. } else {
  3896. /* Allow asynchronous mailbox command to go through */
  3897. spin_lock_irq(&phba->hbalock);
  3898. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3899. spin_unlock_irq(&phba->hbalock);
  3900. done = 1;
  3901. }
  3902. }
  3903. if (!done) {
  3904. rc = -EINVAL;
  3905. goto do_prep_failed;
  3906. }
  3907. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3908. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3909. rc = -ENXIO;
  3910. goto do_prep_failed;
  3911. }
  3912. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3913. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3914. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3915. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3916. phba->max_vpi : phba->max_vports;
  3917. } else
  3918. phba->max_vpi = 0;
  3919. phba->fips_level = 0;
  3920. phba->fips_spec_rev = 0;
  3921. if (pmb->u.mb.un.varCfgPort.gdss) {
  3922. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3923. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3924. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3925. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3926. "2850 Security Crypto Active. FIPS x%d "
  3927. "(Spec Rev: x%d)",
  3928. phba->fips_level, phba->fips_spec_rev);
  3929. }
  3930. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3931. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3932. "2856 Config Port Security Crypto "
  3933. "Error: x%x ",
  3934. pmb->u.mb.un.varCfgPort.sec_err);
  3935. }
  3936. if (pmb->u.mb.un.varCfgPort.gerbm)
  3937. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3938. if (pmb->u.mb.un.varCfgPort.gcrp)
  3939. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3940. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3941. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3942. if (phba->cfg_enable_bg) {
  3943. if (pmb->u.mb.un.varCfgPort.gbg)
  3944. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3945. else
  3946. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3947. "0443 Adapter did not grant "
  3948. "BlockGuard\n");
  3949. }
  3950. } else {
  3951. phba->hbq_get = NULL;
  3952. phba->port_gp = phba->mbox->us.s2.port;
  3953. phba->max_vpi = 0;
  3954. }
  3955. do_prep_failed:
  3956. mempool_free(pmb, phba->mbox_mem_pool);
  3957. return rc;
  3958. }
  3959. /**
  3960. * lpfc_sli_hba_setup - SLI intialization function
  3961. * @phba: Pointer to HBA context object.
  3962. *
  3963. * This function is the main SLI intialization function. This function
  3964. * is called by the HBA intialization code, HBA reset code and HBA
  3965. * error attention handler code. Caller is not required to hold any
  3966. * locks. This function issues config_port mailbox command to configure
  3967. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3968. * calls the config_port_post function to issue init_link mailbox
  3969. * command and to start the discovery. The function will return zero
  3970. * if successful, else it will return negative error code.
  3971. **/
  3972. int
  3973. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3974. {
  3975. uint32_t rc;
  3976. int mode = 3;
  3977. switch (lpfc_sli_mode) {
  3978. case 2:
  3979. if (phba->cfg_enable_npiv) {
  3980. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3981. "1824 NPIV enabled: Override lpfc_sli_mode "
  3982. "parameter (%d) to auto (0).\n",
  3983. lpfc_sli_mode);
  3984. break;
  3985. }
  3986. mode = 2;
  3987. break;
  3988. case 0:
  3989. case 3:
  3990. break;
  3991. default:
  3992. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3993. "1819 Unrecognized lpfc_sli_mode "
  3994. "parameter: %d.\n", lpfc_sli_mode);
  3995. break;
  3996. }
  3997. rc = lpfc_sli_config_port(phba, mode);
  3998. if (rc && lpfc_sli_mode == 3)
  3999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4000. "1820 Unable to select SLI-3. "
  4001. "Not supported by adapter.\n");
  4002. if (rc && mode != 2)
  4003. rc = lpfc_sli_config_port(phba, 2);
  4004. if (rc)
  4005. goto lpfc_sli_hba_setup_error;
  4006. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4007. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4008. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4009. if (!rc) {
  4010. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4011. "2709 This device supports "
  4012. "Advanced Error Reporting (AER)\n");
  4013. spin_lock_irq(&phba->hbalock);
  4014. phba->hba_flag |= HBA_AER_ENABLED;
  4015. spin_unlock_irq(&phba->hbalock);
  4016. } else {
  4017. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4018. "2708 This device does not support "
  4019. "Advanced Error Reporting (AER)\n");
  4020. phba->cfg_aer_support = 0;
  4021. }
  4022. }
  4023. if (phba->sli_rev == 3) {
  4024. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4025. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4026. } else {
  4027. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4028. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4029. phba->sli3_options = 0;
  4030. }
  4031. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4032. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4033. phba->sli_rev, phba->max_vpi);
  4034. rc = lpfc_sli_ring_map(phba);
  4035. if (rc)
  4036. goto lpfc_sli_hba_setup_error;
  4037. /* Init HBQs */
  4038. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4039. rc = lpfc_sli_hbq_setup(phba);
  4040. if (rc)
  4041. goto lpfc_sli_hba_setup_error;
  4042. }
  4043. spin_lock_irq(&phba->hbalock);
  4044. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4045. spin_unlock_irq(&phba->hbalock);
  4046. rc = lpfc_config_port_post(phba);
  4047. if (rc)
  4048. goto lpfc_sli_hba_setup_error;
  4049. return rc;
  4050. lpfc_sli_hba_setup_error:
  4051. phba->link_state = LPFC_HBA_ERROR;
  4052. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4053. "0445 Firmware initialization failed\n");
  4054. return rc;
  4055. }
  4056. /**
  4057. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4058. * @phba: Pointer to HBA context object.
  4059. * @mboxq: mailbox pointer.
  4060. * This function issue a dump mailbox command to read config region
  4061. * 23 and parse the records in the region and populate driver
  4062. * data structure.
  4063. **/
  4064. static int
  4065. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4066. LPFC_MBOXQ_t *mboxq)
  4067. {
  4068. struct lpfc_dmabuf *mp;
  4069. struct lpfc_mqe *mqe;
  4070. uint32_t data_length;
  4071. int rc;
  4072. /* Program the default value of vlan_id and fc_map */
  4073. phba->valid_vlan = 0;
  4074. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4075. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4076. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4077. mqe = &mboxq->u.mqe;
  4078. if (lpfc_dump_fcoe_param(phba, mboxq))
  4079. return -ENOMEM;
  4080. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4081. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4082. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4083. "(%d):2571 Mailbox cmd x%x Status x%x "
  4084. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4085. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4086. "CQ: x%x x%x x%x x%x\n",
  4087. mboxq->vport ? mboxq->vport->vpi : 0,
  4088. bf_get(lpfc_mqe_command, mqe),
  4089. bf_get(lpfc_mqe_status, mqe),
  4090. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4091. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4092. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4093. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4094. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4095. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4096. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4097. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4098. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4099. mboxq->mcqe.word0,
  4100. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4101. mboxq->mcqe.trailer);
  4102. if (rc) {
  4103. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4104. kfree(mp);
  4105. return -EIO;
  4106. }
  4107. data_length = mqe->un.mb_words[5];
  4108. if (data_length > DMP_RGN23_SIZE) {
  4109. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4110. kfree(mp);
  4111. return -EIO;
  4112. }
  4113. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4114. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4115. kfree(mp);
  4116. return 0;
  4117. }
  4118. /**
  4119. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4120. * @phba: pointer to lpfc hba data structure.
  4121. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4122. * @vpd: pointer to the memory to hold resulting port vpd data.
  4123. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4124. * On output, the number of data bytes in @vpd.
  4125. *
  4126. * This routine executes a READ_REV SLI4 mailbox command. In
  4127. * addition, this routine gets the port vpd data.
  4128. *
  4129. * Return codes
  4130. * 0 - successful
  4131. * -ENOMEM - could not allocated memory.
  4132. **/
  4133. static int
  4134. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4135. uint8_t *vpd, uint32_t *vpd_size)
  4136. {
  4137. int rc = 0;
  4138. uint32_t dma_size;
  4139. struct lpfc_dmabuf *dmabuf;
  4140. struct lpfc_mqe *mqe;
  4141. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4142. if (!dmabuf)
  4143. return -ENOMEM;
  4144. /*
  4145. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4146. * mailbox command.
  4147. */
  4148. dma_size = *vpd_size;
  4149. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4150. dma_size,
  4151. &dmabuf->phys,
  4152. GFP_KERNEL);
  4153. if (!dmabuf->virt) {
  4154. kfree(dmabuf);
  4155. return -ENOMEM;
  4156. }
  4157. memset(dmabuf->virt, 0, dma_size);
  4158. /*
  4159. * The SLI4 implementation of READ_REV conflicts at word1,
  4160. * bits 31:16 and SLI4 adds vpd functionality not present
  4161. * in SLI3. This code corrects the conflicts.
  4162. */
  4163. lpfc_read_rev(phba, mboxq);
  4164. mqe = &mboxq->u.mqe;
  4165. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4166. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4167. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4168. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4169. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4170. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4171. if (rc) {
  4172. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4173. dmabuf->virt, dmabuf->phys);
  4174. kfree(dmabuf);
  4175. return -EIO;
  4176. }
  4177. /*
  4178. * The available vpd length cannot be bigger than the
  4179. * DMA buffer passed to the port. Catch the less than
  4180. * case and update the caller's size.
  4181. */
  4182. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4183. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4184. memcpy(vpd, dmabuf->virt, *vpd_size);
  4185. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4186. dmabuf->virt, dmabuf->phys);
  4187. kfree(dmabuf);
  4188. return 0;
  4189. }
  4190. /**
  4191. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4192. * @phba: pointer to lpfc hba data structure.
  4193. *
  4194. * This routine is called to explicitly arm the SLI4 device's completion and
  4195. * event queues
  4196. **/
  4197. static void
  4198. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4199. {
  4200. uint8_t fcp_eqidx;
  4201. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4202. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4203. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4204. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4205. LPFC_QUEUE_REARM);
  4206. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4207. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4208. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4209. LPFC_QUEUE_REARM);
  4210. }
  4211. /**
  4212. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4213. * @phba: Pointer to HBA context object.
  4214. *
  4215. * This function is the main SLI4 device intialization PCI function. This
  4216. * function is called by the HBA intialization code, HBA reset code and
  4217. * HBA error attention handler code. Caller is not required to hold any
  4218. * locks.
  4219. **/
  4220. int
  4221. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4222. {
  4223. int rc;
  4224. LPFC_MBOXQ_t *mboxq;
  4225. struct lpfc_mqe *mqe;
  4226. uint8_t *vpd;
  4227. uint32_t vpd_size;
  4228. uint32_t ftr_rsp = 0;
  4229. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4230. struct lpfc_vport *vport = phba->pport;
  4231. struct lpfc_dmabuf *mp;
  4232. /*
  4233. * TODO: Why does this routine execute these task in a different
  4234. * order from probe?
  4235. */
  4236. /* Perform a PCI function reset to start from clean */
  4237. rc = lpfc_pci_function_reset(phba);
  4238. if (unlikely(rc))
  4239. return -ENODEV;
  4240. /* Check the HBA Host Status Register for readyness */
  4241. rc = lpfc_sli4_post_status_check(phba);
  4242. if (unlikely(rc))
  4243. return -ENODEV;
  4244. else {
  4245. spin_lock_irq(&phba->hbalock);
  4246. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4247. spin_unlock_irq(&phba->hbalock);
  4248. }
  4249. /*
  4250. * Allocate a single mailbox container for initializing the
  4251. * port.
  4252. */
  4253. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4254. if (!mboxq)
  4255. return -ENOMEM;
  4256. /*
  4257. * Continue initialization with default values even if driver failed
  4258. * to read FCoE param config regions
  4259. */
  4260. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4261. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4262. "2570 Failed to read FCoE parameters\n");
  4263. /* Issue READ_REV to collect vpd and FW information. */
  4264. vpd_size = SLI4_PAGE_SIZE;
  4265. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4266. if (!vpd) {
  4267. rc = -ENOMEM;
  4268. goto out_free_mbox;
  4269. }
  4270. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4271. if (unlikely(rc)) {
  4272. kfree(vpd);
  4273. goto out_free_mbox;
  4274. }
  4275. mqe = &mboxq->u.mqe;
  4276. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4277. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4278. phba->hba_flag |= HBA_FCOE_MODE;
  4279. else
  4280. phba->hba_flag &= ~HBA_FCOE_MODE;
  4281. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4282. LPFC_DCBX_CEE_MODE)
  4283. phba->hba_flag |= HBA_FIP_SUPPORT;
  4284. else
  4285. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4286. if (phba->sli_rev != LPFC_SLI_REV4 ||
  4287. !(phba->hba_flag & HBA_FCOE_MODE)) {
  4288. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4289. "0376 READ_REV Error. SLI Level %d "
  4290. "FCoE enabled %d\n",
  4291. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4292. rc = -EIO;
  4293. kfree(vpd);
  4294. goto out_free_mbox;
  4295. }
  4296. /*
  4297. * Evaluate the read rev and vpd data. Populate the driver
  4298. * state with the results. If this routine fails, the failure
  4299. * is not fatal as the driver will use generic values.
  4300. */
  4301. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4302. if (unlikely(!rc)) {
  4303. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4304. "0377 Error %d parsing vpd. "
  4305. "Using defaults.\n", rc);
  4306. rc = 0;
  4307. }
  4308. kfree(vpd);
  4309. /* Save information as VPD data */
  4310. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4311. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4312. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4313. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4314. &mqe->un.read_rev);
  4315. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4316. &mqe->un.read_rev);
  4317. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4318. &mqe->un.read_rev);
  4319. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4320. &mqe->un.read_rev);
  4321. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4322. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4323. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4324. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4325. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4326. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4327. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4328. "(%d):0380 READ_REV Status x%x "
  4329. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4330. mboxq->vport ? mboxq->vport->vpi : 0,
  4331. bf_get(lpfc_mqe_status, mqe),
  4332. phba->vpd.rev.opFwName,
  4333. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4334. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4335. /*
  4336. * Discover the port's supported feature set and match it against the
  4337. * hosts requests.
  4338. */
  4339. lpfc_request_features(phba, mboxq);
  4340. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4341. if (unlikely(rc)) {
  4342. rc = -EIO;
  4343. goto out_free_mbox;
  4344. }
  4345. /*
  4346. * The port must support FCP initiator mode as this is the
  4347. * only mode running in the host.
  4348. */
  4349. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4350. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4351. "0378 No support for fcpi mode.\n");
  4352. ftr_rsp++;
  4353. }
  4354. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  4355. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  4356. else
  4357. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  4358. /*
  4359. * If the port cannot support the host's requested features
  4360. * then turn off the global config parameters to disable the
  4361. * feature in the driver. This is not a fatal error.
  4362. */
  4363. if ((phba->cfg_enable_bg) &&
  4364. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4365. ftr_rsp++;
  4366. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4367. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4368. ftr_rsp++;
  4369. if (ftr_rsp) {
  4370. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4371. "0379 Feature Mismatch Data: x%08x %08x "
  4372. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4373. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4374. phba->cfg_enable_npiv, phba->max_vpi);
  4375. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4376. phba->cfg_enable_bg = 0;
  4377. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4378. phba->cfg_enable_npiv = 0;
  4379. }
  4380. /* These SLI3 features are assumed in SLI4 */
  4381. spin_lock_irq(&phba->hbalock);
  4382. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4383. spin_unlock_irq(&phba->hbalock);
  4384. /* Read the port's service parameters. */
  4385. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4386. if (rc) {
  4387. phba->link_state = LPFC_HBA_ERROR;
  4388. rc = -ENOMEM;
  4389. goto out_free_mbox;
  4390. }
  4391. mboxq->vport = vport;
  4392. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4393. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4394. if (rc == MBX_SUCCESS) {
  4395. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4396. rc = 0;
  4397. }
  4398. /*
  4399. * This memory was allocated by the lpfc_read_sparam routine. Release
  4400. * it to the mbuf pool.
  4401. */
  4402. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4403. kfree(mp);
  4404. mboxq->context1 = NULL;
  4405. if (unlikely(rc)) {
  4406. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4407. "0382 READ_SPARAM command failed "
  4408. "status %d, mbxStatus x%x\n",
  4409. rc, bf_get(lpfc_mqe_status, mqe));
  4410. phba->link_state = LPFC_HBA_ERROR;
  4411. rc = -EIO;
  4412. goto out_free_mbox;
  4413. }
  4414. if (phba->cfg_soft_wwnn)
  4415. u64_to_wwn(phba->cfg_soft_wwnn,
  4416. vport->fc_sparam.nodeName.u.wwn);
  4417. if (phba->cfg_soft_wwpn)
  4418. u64_to_wwn(phba->cfg_soft_wwpn,
  4419. vport->fc_sparam.portName.u.wwn);
  4420. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4421. sizeof(struct lpfc_name));
  4422. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4423. sizeof(struct lpfc_name));
  4424. /* Update the fc_host data structures with new wwn. */
  4425. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4426. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4427. /* Register SGL pool to the device using non-embedded mailbox command */
  4428. rc = lpfc_sli4_post_sgl_list(phba);
  4429. if (unlikely(rc)) {
  4430. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4431. "0582 Error %d during sgl post operation\n",
  4432. rc);
  4433. rc = -ENODEV;
  4434. goto out_free_mbox;
  4435. }
  4436. /* Register SCSI SGL pool to the device */
  4437. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4438. if (unlikely(rc)) {
  4439. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4440. "0383 Error %d during scsi sgl post "
  4441. "operation\n", rc);
  4442. /* Some Scsi buffers were moved to the abort scsi list */
  4443. /* A pci function reset will repost them */
  4444. rc = -ENODEV;
  4445. goto out_free_mbox;
  4446. }
  4447. /* Post the rpi header region to the device. */
  4448. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4449. if (unlikely(rc)) {
  4450. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4451. "0393 Error %d during rpi post operation\n",
  4452. rc);
  4453. rc = -ENODEV;
  4454. goto out_free_mbox;
  4455. }
  4456. /* Set up all the queues to the device */
  4457. rc = lpfc_sli4_queue_setup(phba);
  4458. if (unlikely(rc)) {
  4459. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4460. "0381 Error %d during queue setup.\n ", rc);
  4461. goto out_stop_timers;
  4462. }
  4463. /* Arm the CQs and then EQs on device */
  4464. lpfc_sli4_arm_cqeq_intr(phba);
  4465. /* Indicate device interrupt mode */
  4466. phba->sli4_hba.intr_enable = 1;
  4467. /* Allow asynchronous mailbox command to go through */
  4468. spin_lock_irq(&phba->hbalock);
  4469. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4470. spin_unlock_irq(&phba->hbalock);
  4471. /* Post receive buffers to the device */
  4472. lpfc_sli4_rb_setup(phba);
  4473. /* Reset HBA FCF states after HBA reset */
  4474. phba->fcf.fcf_flag = 0;
  4475. phba->fcf.current_rec.flag = 0;
  4476. /* Start the ELS watchdog timer */
  4477. mod_timer(&vport->els_tmofunc,
  4478. jiffies + HZ * (phba->fc_ratov * 2));
  4479. /* Start heart beat timer */
  4480. mod_timer(&phba->hb_tmofunc,
  4481. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4482. phba->hb_outstanding = 0;
  4483. phba->last_completion_time = jiffies;
  4484. /* Start error attention (ERATT) polling timer */
  4485. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4486. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4487. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4488. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4489. if (!rc) {
  4490. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4491. "2829 This device supports "
  4492. "Advanced Error Reporting (AER)\n");
  4493. spin_lock_irq(&phba->hbalock);
  4494. phba->hba_flag |= HBA_AER_ENABLED;
  4495. spin_unlock_irq(&phba->hbalock);
  4496. } else {
  4497. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4498. "2830 This device does not support "
  4499. "Advanced Error Reporting (AER)\n");
  4500. phba->cfg_aer_support = 0;
  4501. }
  4502. }
  4503. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4504. /*
  4505. * The FC Port needs to register FCFI (index 0)
  4506. */
  4507. lpfc_reg_fcfi(phba, mboxq);
  4508. mboxq->vport = phba->pport;
  4509. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4510. if (rc == MBX_SUCCESS)
  4511. rc = 0;
  4512. else
  4513. goto out_unset_queue;
  4514. }
  4515. /*
  4516. * The port is ready, set the host's link state to LINK_DOWN
  4517. * in preparation for link interrupts.
  4518. */
  4519. spin_lock_irq(&phba->hbalock);
  4520. phba->link_state = LPFC_LINK_DOWN;
  4521. spin_unlock_irq(&phba->hbalock);
  4522. if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
  4523. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4524. out_unset_queue:
  4525. /* Unset all the queues set up in this routine when error out */
  4526. if (rc)
  4527. lpfc_sli4_queue_unset(phba);
  4528. out_stop_timers:
  4529. if (rc)
  4530. lpfc_stop_hba_timers(phba);
  4531. out_free_mbox:
  4532. mempool_free(mboxq, phba->mbox_mem_pool);
  4533. return rc;
  4534. }
  4535. /**
  4536. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4537. * @ptr: context object - pointer to hba structure.
  4538. *
  4539. * This is the callback function for mailbox timer. The mailbox
  4540. * timer is armed when a new mailbox command is issued and the timer
  4541. * is deleted when the mailbox complete. The function is called by
  4542. * the kernel timer code when a mailbox does not complete within
  4543. * expected time. This function wakes up the worker thread to
  4544. * process the mailbox timeout and returns. All the processing is
  4545. * done by the worker thread function lpfc_mbox_timeout_handler.
  4546. **/
  4547. void
  4548. lpfc_mbox_timeout(unsigned long ptr)
  4549. {
  4550. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4551. unsigned long iflag;
  4552. uint32_t tmo_posted;
  4553. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4554. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4555. if (!tmo_posted)
  4556. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4557. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4558. if (!tmo_posted)
  4559. lpfc_worker_wake_up(phba);
  4560. return;
  4561. }
  4562. /**
  4563. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4564. * @phba: Pointer to HBA context object.
  4565. *
  4566. * This function is called from worker thread when a mailbox command times out.
  4567. * The caller is not required to hold any locks. This function will reset the
  4568. * HBA and recover all the pending commands.
  4569. **/
  4570. void
  4571. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4572. {
  4573. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4574. MAILBOX_t *mb = &pmbox->u.mb;
  4575. struct lpfc_sli *psli = &phba->sli;
  4576. struct lpfc_sli_ring *pring;
  4577. /* Check the pmbox pointer first. There is a race condition
  4578. * between the mbox timeout handler getting executed in the
  4579. * worklist and the mailbox actually completing. When this
  4580. * race condition occurs, the mbox_active will be NULL.
  4581. */
  4582. spin_lock_irq(&phba->hbalock);
  4583. if (pmbox == NULL) {
  4584. lpfc_printf_log(phba, KERN_WARNING,
  4585. LOG_MBOX | LOG_SLI,
  4586. "0353 Active Mailbox cleared - mailbox timeout "
  4587. "exiting\n");
  4588. spin_unlock_irq(&phba->hbalock);
  4589. return;
  4590. }
  4591. /* Mbox cmd <mbxCommand> timeout */
  4592. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4593. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4594. mb->mbxCommand,
  4595. phba->pport->port_state,
  4596. phba->sli.sli_flag,
  4597. phba->sli.mbox_active);
  4598. spin_unlock_irq(&phba->hbalock);
  4599. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4600. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4601. * it to fail all oustanding SCSI IO.
  4602. */
  4603. spin_lock_irq(&phba->pport->work_port_lock);
  4604. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4605. spin_unlock_irq(&phba->pport->work_port_lock);
  4606. spin_lock_irq(&phba->hbalock);
  4607. phba->link_state = LPFC_LINK_UNKNOWN;
  4608. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4609. spin_unlock_irq(&phba->hbalock);
  4610. pring = &psli->ring[psli->fcp_ring];
  4611. lpfc_sli_abort_iocb_ring(phba, pring);
  4612. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4613. "0345 Resetting board due to mailbox timeout\n");
  4614. /* Reset the HBA device */
  4615. lpfc_reset_hba(phba);
  4616. }
  4617. /**
  4618. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4619. * @phba: Pointer to HBA context object.
  4620. * @pmbox: Pointer to mailbox object.
  4621. * @flag: Flag indicating how the mailbox need to be processed.
  4622. *
  4623. * This function is called by discovery code and HBA management code
  4624. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4625. * function gets the hbalock to protect the data structures.
  4626. * The mailbox command can be submitted in polling mode, in which case
  4627. * this function will wait in a polling loop for the completion of the
  4628. * mailbox.
  4629. * If the mailbox is submitted in no_wait mode (not polling) the
  4630. * function will submit the command and returns immediately without waiting
  4631. * for the mailbox completion. The no_wait is supported only when HBA
  4632. * is in SLI2/SLI3 mode - interrupts are enabled.
  4633. * The SLI interface allows only one mailbox pending at a time. If the
  4634. * mailbox is issued in polling mode and there is already a mailbox
  4635. * pending, then the function will return an error. If the mailbox is issued
  4636. * in NO_WAIT mode and there is a mailbox pending already, the function
  4637. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4638. * The sli layer owns the mailbox object until the completion of mailbox
  4639. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4640. * return codes the caller owns the mailbox command after the return of
  4641. * the function.
  4642. **/
  4643. static int
  4644. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4645. uint32_t flag)
  4646. {
  4647. MAILBOX_t *mb;
  4648. struct lpfc_sli *psli = &phba->sli;
  4649. uint32_t status, evtctr;
  4650. uint32_t ha_copy;
  4651. int i;
  4652. unsigned long timeout;
  4653. unsigned long drvr_flag = 0;
  4654. uint32_t word0, ldata;
  4655. void __iomem *to_slim;
  4656. int processing_queue = 0;
  4657. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4658. if (!pmbox) {
  4659. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4660. /* processing mbox queue from intr_handler */
  4661. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4662. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4663. return MBX_SUCCESS;
  4664. }
  4665. processing_queue = 1;
  4666. pmbox = lpfc_mbox_get(phba);
  4667. if (!pmbox) {
  4668. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4669. return MBX_SUCCESS;
  4670. }
  4671. }
  4672. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4673. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4674. if(!pmbox->vport) {
  4675. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4676. lpfc_printf_log(phba, KERN_ERR,
  4677. LOG_MBOX | LOG_VPORT,
  4678. "1806 Mbox x%x failed. No vport\n",
  4679. pmbox->u.mb.mbxCommand);
  4680. dump_stack();
  4681. goto out_not_finished;
  4682. }
  4683. }
  4684. /* If the PCI channel is in offline state, do not post mbox. */
  4685. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4686. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4687. goto out_not_finished;
  4688. }
  4689. /* If HBA has a deferred error attention, fail the iocb. */
  4690. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4691. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4692. goto out_not_finished;
  4693. }
  4694. psli = &phba->sli;
  4695. mb = &pmbox->u.mb;
  4696. status = MBX_SUCCESS;
  4697. if (phba->link_state == LPFC_HBA_ERROR) {
  4698. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4699. /* Mbox command <mbxCommand> cannot issue */
  4700. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4701. "(%d):0311 Mailbox command x%x cannot "
  4702. "issue Data: x%x x%x\n",
  4703. pmbox->vport ? pmbox->vport->vpi : 0,
  4704. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4705. goto out_not_finished;
  4706. }
  4707. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4708. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4709. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4710. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4711. "(%d):2528 Mailbox command x%x cannot "
  4712. "issue Data: x%x x%x\n",
  4713. pmbox->vport ? pmbox->vport->vpi : 0,
  4714. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4715. goto out_not_finished;
  4716. }
  4717. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4718. /* Polling for a mbox command when another one is already active
  4719. * is not allowed in SLI. Also, the driver must have established
  4720. * SLI2 mode to queue and process multiple mbox commands.
  4721. */
  4722. if (flag & MBX_POLL) {
  4723. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4724. /* Mbox command <mbxCommand> cannot issue */
  4725. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4726. "(%d):2529 Mailbox command x%x "
  4727. "cannot issue Data: x%x x%x\n",
  4728. pmbox->vport ? pmbox->vport->vpi : 0,
  4729. pmbox->u.mb.mbxCommand,
  4730. psli->sli_flag, flag);
  4731. goto out_not_finished;
  4732. }
  4733. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4734. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4735. /* Mbox command <mbxCommand> cannot issue */
  4736. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4737. "(%d):2530 Mailbox command x%x "
  4738. "cannot issue Data: x%x x%x\n",
  4739. pmbox->vport ? pmbox->vport->vpi : 0,
  4740. pmbox->u.mb.mbxCommand,
  4741. psli->sli_flag, flag);
  4742. goto out_not_finished;
  4743. }
  4744. /* Another mailbox command is still being processed, queue this
  4745. * command to be processed later.
  4746. */
  4747. lpfc_mbox_put(phba, pmbox);
  4748. /* Mbox cmd issue - BUSY */
  4749. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4750. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4751. "x%x x%x x%x x%x\n",
  4752. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4753. mb->mbxCommand, phba->pport->port_state,
  4754. psli->sli_flag, flag);
  4755. psli->slistat.mbox_busy++;
  4756. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4757. if (pmbox->vport) {
  4758. lpfc_debugfs_disc_trc(pmbox->vport,
  4759. LPFC_DISC_TRC_MBOX_VPORT,
  4760. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4761. (uint32_t)mb->mbxCommand,
  4762. mb->un.varWords[0], mb->un.varWords[1]);
  4763. }
  4764. else {
  4765. lpfc_debugfs_disc_trc(phba->pport,
  4766. LPFC_DISC_TRC_MBOX,
  4767. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4768. (uint32_t)mb->mbxCommand,
  4769. mb->un.varWords[0], mb->un.varWords[1]);
  4770. }
  4771. return MBX_BUSY;
  4772. }
  4773. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4774. /* If we are not polling, we MUST be in SLI2 mode */
  4775. if (flag != MBX_POLL) {
  4776. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4777. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4778. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4779. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4780. /* Mbox command <mbxCommand> cannot issue */
  4781. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4782. "(%d):2531 Mailbox command x%x "
  4783. "cannot issue Data: x%x x%x\n",
  4784. pmbox->vport ? pmbox->vport->vpi : 0,
  4785. pmbox->u.mb.mbxCommand,
  4786. psli->sli_flag, flag);
  4787. goto out_not_finished;
  4788. }
  4789. /* timeout active mbox command */
  4790. mod_timer(&psli->mbox_tmo, (jiffies +
  4791. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4792. }
  4793. /* Mailbox cmd <cmd> issue */
  4794. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4795. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4796. "x%x\n",
  4797. pmbox->vport ? pmbox->vport->vpi : 0,
  4798. mb->mbxCommand, phba->pport->port_state,
  4799. psli->sli_flag, flag);
  4800. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4801. if (pmbox->vport) {
  4802. lpfc_debugfs_disc_trc(pmbox->vport,
  4803. LPFC_DISC_TRC_MBOX_VPORT,
  4804. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4805. (uint32_t)mb->mbxCommand,
  4806. mb->un.varWords[0], mb->un.varWords[1]);
  4807. }
  4808. else {
  4809. lpfc_debugfs_disc_trc(phba->pport,
  4810. LPFC_DISC_TRC_MBOX,
  4811. "MBOX Send: cmd:x%x mb:x%x x%x",
  4812. (uint32_t)mb->mbxCommand,
  4813. mb->un.varWords[0], mb->un.varWords[1]);
  4814. }
  4815. }
  4816. psli->slistat.mbox_cmd++;
  4817. evtctr = psli->slistat.mbox_event;
  4818. /* next set own bit for the adapter and copy over command word */
  4819. mb->mbxOwner = OWN_CHIP;
  4820. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4821. /* Populate mbox extension offset word. */
  4822. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4823. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4824. = (uint8_t *)phba->mbox_ext
  4825. - (uint8_t *)phba->mbox;
  4826. }
  4827. /* Copy the mailbox extension data */
  4828. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4829. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4830. (uint8_t *)phba->mbox_ext,
  4831. pmbox->in_ext_byte_len);
  4832. }
  4833. /* Copy command data to host SLIM area */
  4834. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4835. } else {
  4836. /* Populate mbox extension offset word. */
  4837. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4838. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4839. = MAILBOX_HBA_EXT_OFFSET;
  4840. /* Copy the mailbox extension data */
  4841. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4842. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4843. MAILBOX_HBA_EXT_OFFSET,
  4844. pmbox->context2, pmbox->in_ext_byte_len);
  4845. }
  4846. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4847. /* copy command data into host mbox for cmpl */
  4848. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4849. }
  4850. /* First copy mbox command data to HBA SLIM, skip past first
  4851. word */
  4852. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4853. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4854. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4855. /* Next copy over first word, with mbxOwner set */
  4856. ldata = *((uint32_t *)mb);
  4857. to_slim = phba->MBslimaddr;
  4858. writel(ldata, to_slim);
  4859. readl(to_slim); /* flush */
  4860. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4861. /* switch over to host mailbox */
  4862. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4863. }
  4864. }
  4865. wmb();
  4866. switch (flag) {
  4867. case MBX_NOWAIT:
  4868. /* Set up reference to mailbox command */
  4869. psli->mbox_active = pmbox;
  4870. /* Interrupt board to do it */
  4871. writel(CA_MBATT, phba->CAregaddr);
  4872. readl(phba->CAregaddr); /* flush */
  4873. /* Don't wait for it to finish, just return */
  4874. break;
  4875. case MBX_POLL:
  4876. /* Set up null reference to mailbox command */
  4877. psli->mbox_active = NULL;
  4878. /* Interrupt board to do it */
  4879. writel(CA_MBATT, phba->CAregaddr);
  4880. readl(phba->CAregaddr); /* flush */
  4881. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4882. /* First read mbox status word */
  4883. word0 = *((uint32_t *)phba->mbox);
  4884. word0 = le32_to_cpu(word0);
  4885. } else {
  4886. /* First read mbox status word */
  4887. word0 = readl(phba->MBslimaddr);
  4888. }
  4889. /* Read the HBA Host Attention Register */
  4890. ha_copy = readl(phba->HAregaddr);
  4891. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4892. mb->mbxCommand) *
  4893. 1000) + jiffies;
  4894. i = 0;
  4895. /* Wait for command to complete */
  4896. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4897. (!(ha_copy & HA_MBATT) &&
  4898. (phba->link_state > LPFC_WARM_START))) {
  4899. if (time_after(jiffies, timeout)) {
  4900. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4901. spin_unlock_irqrestore(&phba->hbalock,
  4902. drvr_flag);
  4903. goto out_not_finished;
  4904. }
  4905. /* Check if we took a mbox interrupt while we were
  4906. polling */
  4907. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4908. && (evtctr != psli->slistat.mbox_event))
  4909. break;
  4910. if (i++ > 10) {
  4911. spin_unlock_irqrestore(&phba->hbalock,
  4912. drvr_flag);
  4913. msleep(1);
  4914. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4915. }
  4916. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4917. /* First copy command data */
  4918. word0 = *((uint32_t *)phba->mbox);
  4919. word0 = le32_to_cpu(word0);
  4920. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4921. MAILBOX_t *slimmb;
  4922. uint32_t slimword0;
  4923. /* Check real SLIM for any errors */
  4924. slimword0 = readl(phba->MBslimaddr);
  4925. slimmb = (MAILBOX_t *) & slimword0;
  4926. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4927. && slimmb->mbxStatus) {
  4928. psli->sli_flag &=
  4929. ~LPFC_SLI_ACTIVE;
  4930. word0 = slimword0;
  4931. }
  4932. }
  4933. } else {
  4934. /* First copy command data */
  4935. word0 = readl(phba->MBslimaddr);
  4936. }
  4937. /* Read the HBA Host Attention Register */
  4938. ha_copy = readl(phba->HAregaddr);
  4939. }
  4940. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4941. /* copy results back to user */
  4942. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4943. /* Copy the mailbox extension data */
  4944. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4945. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4946. pmbox->context2,
  4947. pmbox->out_ext_byte_len);
  4948. }
  4949. } else {
  4950. /* First copy command data */
  4951. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4952. MAILBOX_CMD_SIZE);
  4953. /* Copy the mailbox extension data */
  4954. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4955. lpfc_memcpy_from_slim(pmbox->context2,
  4956. phba->MBslimaddr +
  4957. MAILBOX_HBA_EXT_OFFSET,
  4958. pmbox->out_ext_byte_len);
  4959. }
  4960. }
  4961. writel(HA_MBATT, phba->HAregaddr);
  4962. readl(phba->HAregaddr); /* flush */
  4963. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4964. status = mb->mbxStatus;
  4965. }
  4966. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4967. return status;
  4968. out_not_finished:
  4969. if (processing_queue) {
  4970. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4971. lpfc_mbox_cmpl_put(phba, pmbox);
  4972. }
  4973. return MBX_NOT_FINISHED;
  4974. }
  4975. /**
  4976. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4977. * @phba: Pointer to HBA context object.
  4978. *
  4979. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4980. * the driver internal pending mailbox queue. It will then try to wait out the
  4981. * possible outstanding mailbox command before return.
  4982. *
  4983. * Returns:
  4984. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4985. * the outstanding mailbox command timed out.
  4986. **/
  4987. static int
  4988. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4989. {
  4990. struct lpfc_sli *psli = &phba->sli;
  4991. uint8_t actcmd = MBX_HEARTBEAT;
  4992. int rc = 0;
  4993. unsigned long timeout;
  4994. /* Mark the asynchronous mailbox command posting as blocked */
  4995. spin_lock_irq(&phba->hbalock);
  4996. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4997. if (phba->sli.mbox_active)
  4998. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4999. spin_unlock_irq(&phba->hbalock);
  5000. /* Determine how long we might wait for the active mailbox
  5001. * command to be gracefully completed by firmware.
  5002. */
  5003. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5004. jiffies;
  5005. /* Wait for the outstnading mailbox command to complete */
  5006. while (phba->sli.mbox_active) {
  5007. /* Check active mailbox complete status every 2ms */
  5008. msleep(2);
  5009. if (time_after(jiffies, timeout)) {
  5010. /* Timeout, marked the outstanding cmd not complete */
  5011. rc = 1;
  5012. break;
  5013. }
  5014. }
  5015. /* Can not cleanly block async mailbox command, fails it */
  5016. if (rc) {
  5017. spin_lock_irq(&phba->hbalock);
  5018. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5019. spin_unlock_irq(&phba->hbalock);
  5020. }
  5021. return rc;
  5022. }
  5023. /**
  5024. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5025. * @phba: Pointer to HBA context object.
  5026. *
  5027. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5028. * commands from the driver internal pending mailbox queue. It makes sure
  5029. * that there is no outstanding mailbox command before resuming posting
  5030. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5031. * mailbox command, it will try to wait it out before resuming asynchronous
  5032. * mailbox command posting.
  5033. **/
  5034. static void
  5035. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5036. {
  5037. struct lpfc_sli *psli = &phba->sli;
  5038. spin_lock_irq(&phba->hbalock);
  5039. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5040. /* Asynchronous mailbox posting is not blocked, do nothing */
  5041. spin_unlock_irq(&phba->hbalock);
  5042. return;
  5043. }
  5044. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5045. * successful or timeout, after timing-out the outstanding mailbox
  5046. * command shall always be removed, so just unblock posting async
  5047. * mailbox command and resume
  5048. */
  5049. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5050. spin_unlock_irq(&phba->hbalock);
  5051. /* wake up worker thread to post asynchronlous mailbox command */
  5052. lpfc_worker_wake_up(phba);
  5053. }
  5054. /**
  5055. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5056. * @phba: Pointer to HBA context object.
  5057. * @mboxq: Pointer to mailbox object.
  5058. *
  5059. * The function posts a mailbox to the port. The mailbox is expected
  5060. * to be comletely filled in and ready for the port to operate on it.
  5061. * This routine executes a synchronous completion operation on the
  5062. * mailbox by polling for its completion.
  5063. *
  5064. * The caller must not be holding any locks when calling this routine.
  5065. *
  5066. * Returns:
  5067. * MBX_SUCCESS - mailbox posted successfully
  5068. * Any of the MBX error values.
  5069. **/
  5070. static int
  5071. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5072. {
  5073. int rc = MBX_SUCCESS;
  5074. unsigned long iflag;
  5075. uint32_t db_ready;
  5076. uint32_t mcqe_status;
  5077. uint32_t mbx_cmnd;
  5078. unsigned long timeout;
  5079. struct lpfc_sli *psli = &phba->sli;
  5080. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5081. struct lpfc_bmbx_create *mbox_rgn;
  5082. struct dma_address *dma_address;
  5083. struct lpfc_register bmbx_reg;
  5084. /*
  5085. * Only one mailbox can be active to the bootstrap mailbox region
  5086. * at a time and there is no queueing provided.
  5087. */
  5088. spin_lock_irqsave(&phba->hbalock, iflag);
  5089. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5090. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5091. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5092. "(%d):2532 Mailbox command x%x (x%x) "
  5093. "cannot issue Data: x%x x%x\n",
  5094. mboxq->vport ? mboxq->vport->vpi : 0,
  5095. mboxq->u.mb.mbxCommand,
  5096. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5097. psli->sli_flag, MBX_POLL);
  5098. return MBXERR_ERROR;
  5099. }
  5100. /* The server grabs the token and owns it until release */
  5101. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5102. phba->sli.mbox_active = mboxq;
  5103. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5104. /*
  5105. * Initialize the bootstrap memory region to avoid stale data areas
  5106. * in the mailbox post. Then copy the caller's mailbox contents to
  5107. * the bmbx mailbox region.
  5108. */
  5109. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5110. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5111. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5112. sizeof(struct lpfc_mqe));
  5113. /* Post the high mailbox dma address to the port and wait for ready. */
  5114. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5115. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5116. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5117. * 1000) + jiffies;
  5118. do {
  5119. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5120. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5121. if (!db_ready)
  5122. msleep(2);
  5123. if (time_after(jiffies, timeout)) {
  5124. rc = MBXERR_ERROR;
  5125. goto exit;
  5126. }
  5127. } while (!db_ready);
  5128. /* Post the low mailbox dma address to the port. */
  5129. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5130. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5131. * 1000) + jiffies;
  5132. do {
  5133. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5134. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5135. if (!db_ready)
  5136. msleep(2);
  5137. if (time_after(jiffies, timeout)) {
  5138. rc = MBXERR_ERROR;
  5139. goto exit;
  5140. }
  5141. } while (!db_ready);
  5142. /*
  5143. * Read the CQ to ensure the mailbox has completed.
  5144. * If so, update the mailbox status so that the upper layers
  5145. * can complete the request normally.
  5146. */
  5147. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5148. sizeof(struct lpfc_mqe));
  5149. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5150. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5151. sizeof(struct lpfc_mcqe));
  5152. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5153. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  5154. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5155. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  5156. rc = MBXERR_ERROR;
  5157. } else
  5158. lpfc_sli4_swap_str(phba, mboxq);
  5159. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5160. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5161. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5162. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5163. mboxq->vport ? mboxq->vport->vpi : 0,
  5164. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5165. bf_get(lpfc_mqe_status, mb),
  5166. mb->un.mb_words[0], mb->un.mb_words[1],
  5167. mb->un.mb_words[2], mb->un.mb_words[3],
  5168. mb->un.mb_words[4], mb->un.mb_words[5],
  5169. mb->un.mb_words[6], mb->un.mb_words[7],
  5170. mb->un.mb_words[8], mb->un.mb_words[9],
  5171. mb->un.mb_words[10], mb->un.mb_words[11],
  5172. mb->un.mb_words[12], mboxq->mcqe.word0,
  5173. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5174. mboxq->mcqe.trailer);
  5175. exit:
  5176. /* We are holding the token, no needed for lock when release */
  5177. spin_lock_irqsave(&phba->hbalock, iflag);
  5178. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5179. phba->sli.mbox_active = NULL;
  5180. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5181. return rc;
  5182. }
  5183. /**
  5184. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5185. * @phba: Pointer to HBA context object.
  5186. * @pmbox: Pointer to mailbox object.
  5187. * @flag: Flag indicating how the mailbox need to be processed.
  5188. *
  5189. * This function is called by discovery code and HBA management code to submit
  5190. * a mailbox command to firmware with SLI-4 interface spec.
  5191. *
  5192. * Return codes the caller owns the mailbox command after the return of the
  5193. * function.
  5194. **/
  5195. static int
  5196. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5197. uint32_t flag)
  5198. {
  5199. struct lpfc_sli *psli = &phba->sli;
  5200. unsigned long iflags;
  5201. int rc;
  5202. rc = lpfc_mbox_dev_check(phba);
  5203. if (unlikely(rc)) {
  5204. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5205. "(%d):2544 Mailbox command x%x (x%x) "
  5206. "cannot issue Data: x%x x%x\n",
  5207. mboxq->vport ? mboxq->vport->vpi : 0,
  5208. mboxq->u.mb.mbxCommand,
  5209. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5210. psli->sli_flag, flag);
  5211. goto out_not_finished;
  5212. }
  5213. /* Detect polling mode and jump to a handler */
  5214. if (!phba->sli4_hba.intr_enable) {
  5215. if (flag == MBX_POLL)
  5216. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5217. else
  5218. rc = -EIO;
  5219. if (rc != MBX_SUCCESS)
  5220. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5221. "(%d):2541 Mailbox command x%x "
  5222. "(x%x) cannot issue Data: x%x x%x\n",
  5223. mboxq->vport ? mboxq->vport->vpi : 0,
  5224. mboxq->u.mb.mbxCommand,
  5225. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5226. psli->sli_flag, flag);
  5227. return rc;
  5228. } else if (flag == MBX_POLL) {
  5229. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5230. "(%d):2542 Try to issue mailbox command "
  5231. "x%x (x%x) synchronously ahead of async"
  5232. "mailbox command queue: x%x x%x\n",
  5233. mboxq->vport ? mboxq->vport->vpi : 0,
  5234. mboxq->u.mb.mbxCommand,
  5235. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5236. psli->sli_flag, flag);
  5237. /* Try to block the asynchronous mailbox posting */
  5238. rc = lpfc_sli4_async_mbox_block(phba);
  5239. if (!rc) {
  5240. /* Successfully blocked, now issue sync mbox cmd */
  5241. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5242. if (rc != MBX_SUCCESS)
  5243. lpfc_printf_log(phba, KERN_ERR,
  5244. LOG_MBOX | LOG_SLI,
  5245. "(%d):2597 Mailbox command "
  5246. "x%x (x%x) cannot issue "
  5247. "Data: x%x x%x\n",
  5248. mboxq->vport ?
  5249. mboxq->vport->vpi : 0,
  5250. mboxq->u.mb.mbxCommand,
  5251. lpfc_sli4_mbox_opcode_get(phba,
  5252. mboxq),
  5253. psli->sli_flag, flag);
  5254. /* Unblock the async mailbox posting afterward */
  5255. lpfc_sli4_async_mbox_unblock(phba);
  5256. }
  5257. return rc;
  5258. }
  5259. /* Now, interrupt mode asynchrous mailbox command */
  5260. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5261. if (rc) {
  5262. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5263. "(%d):2543 Mailbox command x%x (x%x) "
  5264. "cannot issue Data: x%x x%x\n",
  5265. mboxq->vport ? mboxq->vport->vpi : 0,
  5266. mboxq->u.mb.mbxCommand,
  5267. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5268. psli->sli_flag, flag);
  5269. goto out_not_finished;
  5270. }
  5271. /* Put the mailbox command to the driver internal FIFO */
  5272. psli->slistat.mbox_busy++;
  5273. spin_lock_irqsave(&phba->hbalock, iflags);
  5274. lpfc_mbox_put(phba, mboxq);
  5275. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5276. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5277. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5278. "x%x (x%x) x%x x%x x%x\n",
  5279. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5280. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5281. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5282. phba->pport->port_state,
  5283. psli->sli_flag, MBX_NOWAIT);
  5284. /* Wake up worker thread to transport mailbox command from head */
  5285. lpfc_worker_wake_up(phba);
  5286. return MBX_BUSY;
  5287. out_not_finished:
  5288. return MBX_NOT_FINISHED;
  5289. }
  5290. /**
  5291. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5292. * @phba: Pointer to HBA context object.
  5293. *
  5294. * This function is called by worker thread to send a mailbox command to
  5295. * SLI4 HBA firmware.
  5296. *
  5297. **/
  5298. int
  5299. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5300. {
  5301. struct lpfc_sli *psli = &phba->sli;
  5302. LPFC_MBOXQ_t *mboxq;
  5303. int rc = MBX_SUCCESS;
  5304. unsigned long iflags;
  5305. struct lpfc_mqe *mqe;
  5306. uint32_t mbx_cmnd;
  5307. /* Check interrupt mode before post async mailbox command */
  5308. if (unlikely(!phba->sli4_hba.intr_enable))
  5309. return MBX_NOT_FINISHED;
  5310. /* Check for mailbox command service token */
  5311. spin_lock_irqsave(&phba->hbalock, iflags);
  5312. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5313. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5314. return MBX_NOT_FINISHED;
  5315. }
  5316. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5317. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5318. return MBX_NOT_FINISHED;
  5319. }
  5320. if (unlikely(phba->sli.mbox_active)) {
  5321. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5322. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5323. "0384 There is pending active mailbox cmd\n");
  5324. return MBX_NOT_FINISHED;
  5325. }
  5326. /* Take the mailbox command service token */
  5327. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5328. /* Get the next mailbox command from head of queue */
  5329. mboxq = lpfc_mbox_get(phba);
  5330. /* If no more mailbox command waiting for post, we're done */
  5331. if (!mboxq) {
  5332. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5333. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5334. return MBX_SUCCESS;
  5335. }
  5336. phba->sli.mbox_active = mboxq;
  5337. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5338. /* Check device readiness for posting mailbox command */
  5339. rc = lpfc_mbox_dev_check(phba);
  5340. if (unlikely(rc))
  5341. /* Driver clean routine will clean up pending mailbox */
  5342. goto out_not_finished;
  5343. /* Prepare the mbox command to be posted */
  5344. mqe = &mboxq->u.mqe;
  5345. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5346. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5347. mod_timer(&psli->mbox_tmo, (jiffies +
  5348. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5349. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5350. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5351. "x%x x%x\n",
  5352. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5353. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5354. phba->pport->port_state, psli->sli_flag);
  5355. if (mbx_cmnd != MBX_HEARTBEAT) {
  5356. if (mboxq->vport) {
  5357. lpfc_debugfs_disc_trc(mboxq->vport,
  5358. LPFC_DISC_TRC_MBOX_VPORT,
  5359. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5360. mbx_cmnd, mqe->un.mb_words[0],
  5361. mqe->un.mb_words[1]);
  5362. } else {
  5363. lpfc_debugfs_disc_trc(phba->pport,
  5364. LPFC_DISC_TRC_MBOX,
  5365. "MBOX Send: cmd:x%x mb:x%x x%x",
  5366. mbx_cmnd, mqe->un.mb_words[0],
  5367. mqe->un.mb_words[1]);
  5368. }
  5369. }
  5370. psli->slistat.mbox_cmd++;
  5371. /* Post the mailbox command to the port */
  5372. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5373. if (rc != MBX_SUCCESS) {
  5374. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5375. "(%d):2533 Mailbox command x%x (x%x) "
  5376. "cannot issue Data: x%x x%x\n",
  5377. mboxq->vport ? mboxq->vport->vpi : 0,
  5378. mboxq->u.mb.mbxCommand,
  5379. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5380. psli->sli_flag, MBX_NOWAIT);
  5381. goto out_not_finished;
  5382. }
  5383. return rc;
  5384. out_not_finished:
  5385. spin_lock_irqsave(&phba->hbalock, iflags);
  5386. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5387. __lpfc_mbox_cmpl_put(phba, mboxq);
  5388. /* Release the token */
  5389. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5390. phba->sli.mbox_active = NULL;
  5391. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5392. return MBX_NOT_FINISHED;
  5393. }
  5394. /**
  5395. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5396. * @phba: Pointer to HBA context object.
  5397. * @pmbox: Pointer to mailbox object.
  5398. * @flag: Flag indicating how the mailbox need to be processed.
  5399. *
  5400. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5401. * the API jump table function pointer from the lpfc_hba struct.
  5402. *
  5403. * Return codes the caller owns the mailbox command after the return of the
  5404. * function.
  5405. **/
  5406. int
  5407. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5408. {
  5409. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5410. }
  5411. /**
  5412. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5413. * @phba: The hba struct for which this call is being executed.
  5414. * @dev_grp: The HBA PCI-Device group number.
  5415. *
  5416. * This routine sets up the mbox interface API function jump table in @phba
  5417. * struct.
  5418. * Returns: 0 - success, -ENODEV - failure.
  5419. **/
  5420. int
  5421. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5422. {
  5423. switch (dev_grp) {
  5424. case LPFC_PCI_DEV_LP:
  5425. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5426. phba->lpfc_sli_handle_slow_ring_event =
  5427. lpfc_sli_handle_slow_ring_event_s3;
  5428. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5429. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5430. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5431. break;
  5432. case LPFC_PCI_DEV_OC:
  5433. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5434. phba->lpfc_sli_handle_slow_ring_event =
  5435. lpfc_sli_handle_slow_ring_event_s4;
  5436. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5437. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5438. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5439. break;
  5440. default:
  5441. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5442. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5443. dev_grp);
  5444. return -ENODEV;
  5445. break;
  5446. }
  5447. return 0;
  5448. }
  5449. /**
  5450. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5451. * @phba: Pointer to HBA context object.
  5452. * @pring: Pointer to driver SLI ring object.
  5453. * @piocb: Pointer to address of newly added command iocb.
  5454. *
  5455. * This function is called with hbalock held to add a command
  5456. * iocb to the txq when SLI layer cannot submit the command iocb
  5457. * to the ring.
  5458. **/
  5459. void
  5460. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5461. struct lpfc_iocbq *piocb)
  5462. {
  5463. /* Insert the caller's iocb in the txq tail for later processing. */
  5464. list_add_tail(&piocb->list, &pring->txq);
  5465. pring->txq_cnt++;
  5466. }
  5467. /**
  5468. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5469. * @phba: Pointer to HBA context object.
  5470. * @pring: Pointer to driver SLI ring object.
  5471. * @piocb: Pointer to address of newly added command iocb.
  5472. *
  5473. * This function is called with hbalock held before a new
  5474. * iocb is submitted to the firmware. This function checks
  5475. * txq to flush the iocbs in txq to Firmware before
  5476. * submitting new iocbs to the Firmware.
  5477. * If there are iocbs in the txq which need to be submitted
  5478. * to firmware, lpfc_sli_next_iocb returns the first element
  5479. * of the txq after dequeuing it from txq.
  5480. * If there is no iocb in the txq then the function will return
  5481. * *piocb and *piocb is set to NULL. Caller needs to check
  5482. * *piocb to find if there are more commands in the txq.
  5483. **/
  5484. static struct lpfc_iocbq *
  5485. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5486. struct lpfc_iocbq **piocb)
  5487. {
  5488. struct lpfc_iocbq * nextiocb;
  5489. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5490. if (!nextiocb) {
  5491. nextiocb = *piocb;
  5492. *piocb = NULL;
  5493. }
  5494. return nextiocb;
  5495. }
  5496. /**
  5497. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5498. * @phba: Pointer to HBA context object.
  5499. * @ring_number: SLI ring number to issue iocb on.
  5500. * @piocb: Pointer to command iocb.
  5501. * @flag: Flag indicating if this command can be put into txq.
  5502. *
  5503. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5504. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5505. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5506. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5507. * this function allows only iocbs for posting buffers. This function finds
  5508. * next available slot in the command ring and posts the command to the
  5509. * available slot and writes the port attention register to request HBA start
  5510. * processing new iocb. If there is no slot available in the ring and
  5511. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5512. * the function returns IOCB_BUSY.
  5513. *
  5514. * This function is called with hbalock held. The function will return success
  5515. * after it successfully submit the iocb to firmware or after adding to the
  5516. * txq.
  5517. **/
  5518. static int
  5519. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5520. struct lpfc_iocbq *piocb, uint32_t flag)
  5521. {
  5522. struct lpfc_iocbq *nextiocb;
  5523. IOCB_t *iocb;
  5524. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5525. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5526. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5527. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5528. lpfc_printf_log(phba, KERN_ERR,
  5529. LOG_SLI | LOG_VPORT,
  5530. "1807 IOCB x%x failed. No vport\n",
  5531. piocb->iocb.ulpCommand);
  5532. dump_stack();
  5533. return IOCB_ERROR;
  5534. }
  5535. /* If the PCI channel is in offline state, do not post iocbs. */
  5536. if (unlikely(pci_channel_offline(phba->pcidev)))
  5537. return IOCB_ERROR;
  5538. /* If HBA has a deferred error attention, fail the iocb. */
  5539. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5540. return IOCB_ERROR;
  5541. /*
  5542. * We should never get an IOCB if we are in a < LINK_DOWN state
  5543. */
  5544. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5545. return IOCB_ERROR;
  5546. /*
  5547. * Check to see if we are blocking IOCB processing because of a
  5548. * outstanding event.
  5549. */
  5550. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5551. goto iocb_busy;
  5552. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5553. /*
  5554. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5555. * can be issued if the link is not up.
  5556. */
  5557. switch (piocb->iocb.ulpCommand) {
  5558. case CMD_GEN_REQUEST64_CR:
  5559. case CMD_GEN_REQUEST64_CX:
  5560. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5561. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5562. FC_RCTL_DD_UNSOL_CMD) ||
  5563. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5564. MENLO_TRANSPORT_TYPE))
  5565. goto iocb_busy;
  5566. break;
  5567. case CMD_QUE_RING_BUF_CN:
  5568. case CMD_QUE_RING_BUF64_CN:
  5569. /*
  5570. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5571. * completion, iocb_cmpl MUST be 0.
  5572. */
  5573. if (piocb->iocb_cmpl)
  5574. piocb->iocb_cmpl = NULL;
  5575. /*FALLTHROUGH*/
  5576. case CMD_CREATE_XRI_CR:
  5577. case CMD_CLOSE_XRI_CN:
  5578. case CMD_CLOSE_XRI_CX:
  5579. break;
  5580. default:
  5581. goto iocb_busy;
  5582. }
  5583. /*
  5584. * For FCP commands, we must be in a state where we can process link
  5585. * attention events.
  5586. */
  5587. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5588. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5589. goto iocb_busy;
  5590. }
  5591. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5592. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5593. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5594. if (iocb)
  5595. lpfc_sli_update_ring(phba, pring);
  5596. else
  5597. lpfc_sli_update_full_ring(phba, pring);
  5598. if (!piocb)
  5599. return IOCB_SUCCESS;
  5600. goto out_busy;
  5601. iocb_busy:
  5602. pring->stats.iocb_cmd_delay++;
  5603. out_busy:
  5604. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5605. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5606. return IOCB_SUCCESS;
  5607. }
  5608. return IOCB_BUSY;
  5609. }
  5610. /**
  5611. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5612. * @phba: Pointer to HBA context object.
  5613. * @piocb: Pointer to command iocb.
  5614. * @sglq: Pointer to the scatter gather queue object.
  5615. *
  5616. * This routine converts the bpl or bde that is in the IOCB
  5617. * to a sgl list for the sli4 hardware. The physical address
  5618. * of the bpl/bde is converted back to a virtual address.
  5619. * If the IOCB contains a BPL then the list of BDE's is
  5620. * converted to sli4_sge's. If the IOCB contains a single
  5621. * BDE then it is converted to a single sli_sge.
  5622. * The IOCB is still in cpu endianess so the contents of
  5623. * the bpl can be used without byte swapping.
  5624. *
  5625. * Returns valid XRI = Success, NO_XRI = Failure.
  5626. **/
  5627. static uint16_t
  5628. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5629. struct lpfc_sglq *sglq)
  5630. {
  5631. uint16_t xritag = NO_XRI;
  5632. struct ulp_bde64 *bpl = NULL;
  5633. struct ulp_bde64 bde;
  5634. struct sli4_sge *sgl = NULL;
  5635. IOCB_t *icmd;
  5636. int numBdes = 0;
  5637. int i = 0;
  5638. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5639. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5640. if (!piocbq || !sglq)
  5641. return xritag;
  5642. sgl = (struct sli4_sge *)sglq->sgl;
  5643. icmd = &piocbq->iocb;
  5644. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5645. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5646. sizeof(struct ulp_bde64);
  5647. /* The addrHigh and addrLow fields within the IOCB
  5648. * have not been byteswapped yet so there is no
  5649. * need to swap them back.
  5650. */
  5651. bpl = (struct ulp_bde64 *)
  5652. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5653. if (!bpl)
  5654. return xritag;
  5655. for (i = 0; i < numBdes; i++) {
  5656. /* Should already be byte swapped. */
  5657. sgl->addr_hi = bpl->addrHigh;
  5658. sgl->addr_lo = bpl->addrLow;
  5659. if ((i+1) == numBdes)
  5660. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5661. else
  5662. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5663. sgl->word2 = cpu_to_le32(sgl->word2);
  5664. /* swap the size field back to the cpu so we
  5665. * can assign it to the sgl.
  5666. */
  5667. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5668. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5669. /* The offsets in the sgl need to be accumulated
  5670. * separately for the request and reply lists.
  5671. * The request is always first, the reply follows.
  5672. */
  5673. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5674. /* add up the reply sg entries */
  5675. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5676. inbound++;
  5677. /* first inbound? reset the offset */
  5678. if (inbound == 1)
  5679. offset = 0;
  5680. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5681. offset += bde.tus.f.bdeSize;
  5682. }
  5683. bpl++;
  5684. sgl++;
  5685. }
  5686. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5687. /* The addrHigh and addrLow fields of the BDE have not
  5688. * been byteswapped yet so they need to be swapped
  5689. * before putting them in the sgl.
  5690. */
  5691. sgl->addr_hi =
  5692. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5693. sgl->addr_lo =
  5694. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5695. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5696. sgl->word2 = cpu_to_le32(sgl->word2);
  5697. sgl->sge_len =
  5698. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5699. }
  5700. return sglq->sli4_xritag;
  5701. }
  5702. /**
  5703. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5704. * @phba: Pointer to HBA context object.
  5705. *
  5706. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5707. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5708. * held.
  5709. *
  5710. * Return: index into SLI4 fast-path FCP queue index.
  5711. **/
  5712. static uint32_t
  5713. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5714. {
  5715. ++phba->fcp_qidx;
  5716. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5717. phba->fcp_qidx = 0;
  5718. return phba->fcp_qidx;
  5719. }
  5720. /**
  5721. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5722. * @phba: Pointer to HBA context object.
  5723. * @piocb: Pointer to command iocb.
  5724. * @wqe: Pointer to the work queue entry.
  5725. *
  5726. * This routine converts the iocb command to its Work Queue Entry
  5727. * equivalent. The wqe pointer should not have any fields set when
  5728. * this routine is called because it will memcpy over them.
  5729. * This routine does not set the CQ_ID or the WQEC bits in the
  5730. * wqe.
  5731. *
  5732. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5733. **/
  5734. static int
  5735. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5736. union lpfc_wqe *wqe)
  5737. {
  5738. uint32_t xmit_len = 0, total_len = 0;
  5739. uint8_t ct = 0;
  5740. uint32_t fip;
  5741. uint32_t abort_tag;
  5742. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5743. uint8_t cmnd;
  5744. uint16_t xritag;
  5745. uint16_t abrt_iotag;
  5746. struct lpfc_iocbq *abrtiocbq;
  5747. struct ulp_bde64 *bpl = NULL;
  5748. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5749. int numBdes, i;
  5750. struct ulp_bde64 bde;
  5751. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5752. /* The fcp commands will set command type */
  5753. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5754. command_type = FCP_COMMAND;
  5755. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5756. command_type = ELS_COMMAND_FIP;
  5757. else
  5758. command_type = ELS_COMMAND_NON_FIP;
  5759. /* Some of the fields are in the right position already */
  5760. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5761. abort_tag = (uint32_t) iocbq->iotag;
  5762. xritag = iocbq->sli4_xritag;
  5763. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5764. /* words0-2 bpl convert bde */
  5765. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5766. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5767. sizeof(struct ulp_bde64);
  5768. bpl = (struct ulp_bde64 *)
  5769. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5770. if (!bpl)
  5771. return IOCB_ERROR;
  5772. /* Should already be byte swapped. */
  5773. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5774. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5775. /* swap the size field back to the cpu so we
  5776. * can assign it to the sgl.
  5777. */
  5778. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5779. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5780. total_len = 0;
  5781. for (i = 0; i < numBdes; i++) {
  5782. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5783. total_len += bde.tus.f.bdeSize;
  5784. }
  5785. } else
  5786. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5787. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5788. cmnd = iocbq->iocb.ulpCommand;
  5789. switch (iocbq->iocb.ulpCommand) {
  5790. case CMD_ELS_REQUEST64_CR:
  5791. if (!iocbq->iocb.ulpLe) {
  5792. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5793. "2007 Only Limited Edition cmd Format"
  5794. " supported 0x%x\n",
  5795. iocbq->iocb.ulpCommand);
  5796. return IOCB_ERROR;
  5797. }
  5798. wqe->els_req.payload_len = xmit_len;
  5799. /* Els_reguest64 has a TMO */
  5800. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5801. iocbq->iocb.ulpTimeout);
  5802. /* Need a VF for word 4 set the vf bit*/
  5803. bf_set(els_req64_vf, &wqe->els_req, 0);
  5804. /* And a VFID for word 12 */
  5805. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5806. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5807. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5808. iocbq->iocb.ulpContext);
  5809. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5810. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5811. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5812. if (command_type == ELS_COMMAND_FIP) {
  5813. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5814. >> LPFC_FIP_ELS_ID_SHIFT);
  5815. }
  5816. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5817. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5818. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5819. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5820. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5821. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5822. break;
  5823. case CMD_XMIT_SEQUENCE64_CX:
  5824. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5825. iocbq->iocb.un.ulpWord[3]);
  5826. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5827. iocbq->iocb.ulpContext);
  5828. /* The entire sequence is transmitted for this IOCB */
  5829. xmit_len = total_len;
  5830. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5831. case CMD_XMIT_SEQUENCE64_CR:
  5832. /* word3 iocb=io_tag32 wqe=reserved */
  5833. wqe->xmit_sequence.rsvd3 = 0;
  5834. /* word4 relative_offset memcpy */
  5835. /* word5 r_ctl/df_ctl memcpy */
  5836. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5837. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5838. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5839. LPFC_WQE_IOD_WRITE);
  5840. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5841. LPFC_WQE_LENLOC_WORD12);
  5842. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5843. wqe->xmit_sequence.xmit_len = xmit_len;
  5844. command_type = OTHER_COMMAND;
  5845. break;
  5846. case CMD_XMIT_BCAST64_CN:
  5847. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5848. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5849. /* word4 iocb=rsvd wqe=rsvd */
  5850. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5851. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5852. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5853. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5854. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5855. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5856. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5857. LPFC_WQE_LENLOC_WORD3);
  5858. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5859. break;
  5860. case CMD_FCP_IWRITE64_CR:
  5861. command_type = FCP_COMMAND_DATA_OUT;
  5862. /* word3 iocb=iotag wqe=payload_offset_len */
  5863. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5864. wqe->fcp_iwrite.payload_offset_len =
  5865. xmit_len + sizeof(struct fcp_rsp);
  5866. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5867. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5868. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5869. iocbq->iocb.ulpFCP2Rcvy);
  5870. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5871. /* Always open the exchange */
  5872. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5873. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5874. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5875. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5876. LPFC_WQE_LENLOC_WORD4);
  5877. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5878. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5879. break;
  5880. case CMD_FCP_IREAD64_CR:
  5881. /* word3 iocb=iotag wqe=payload_offset_len */
  5882. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5883. wqe->fcp_iread.payload_offset_len =
  5884. xmit_len + sizeof(struct fcp_rsp);
  5885. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5886. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5887. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5888. iocbq->iocb.ulpFCP2Rcvy);
  5889. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5890. /* Always open the exchange */
  5891. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5892. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5893. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5894. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5895. LPFC_WQE_LENLOC_WORD4);
  5896. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5897. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5898. break;
  5899. case CMD_FCP_ICMND64_CR:
  5900. /* word3 iocb=IO_TAG wqe=reserved */
  5901. wqe->fcp_icmd.rsrvd3 = 0;
  5902. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5903. /* Always open the exchange */
  5904. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5905. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5906. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5907. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5908. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5909. LPFC_WQE_LENLOC_NONE);
  5910. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5911. break;
  5912. case CMD_GEN_REQUEST64_CR:
  5913. /* For this command calculate the xmit length of the
  5914. * request bde.
  5915. */
  5916. xmit_len = 0;
  5917. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5918. sizeof(struct ulp_bde64);
  5919. for (i = 0; i < numBdes; i++) {
  5920. if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5921. break;
  5922. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5923. xmit_len += bde.tus.f.bdeSize;
  5924. }
  5925. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5926. wqe->gen_req.request_payload_len = xmit_len;
  5927. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5928. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5929. /* word6 context tag copied in memcpy */
  5930. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5931. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5932. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5933. "2015 Invalid CT %x command 0x%x\n",
  5934. ct, iocbq->iocb.ulpCommand);
  5935. return IOCB_ERROR;
  5936. }
  5937. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5938. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5939. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5940. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5941. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5942. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5943. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5944. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5945. command_type = OTHER_COMMAND;
  5946. break;
  5947. case CMD_XMIT_ELS_RSP64_CX:
  5948. /* words0-2 BDE memcpy */
  5949. /* word3 iocb=iotag32 wqe=response_payload_len */
  5950. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  5951. /* word4 iocb=did wge=rsvd. */
  5952. wqe->xmit_els_rsp.rsvd4 = 0;
  5953. /* word5 iocb=rsvd wge=did */
  5954. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5955. iocbq->iocb.un.elsreq64.remoteID);
  5956. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  5957. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5958. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  5959. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5960. iocbq->iocb.ulpContext);
  5961. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5962. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5963. iocbq->vport->vpi + phba->vpi_base);
  5964. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  5965. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  5966. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  5967. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  5968. LPFC_WQE_LENLOC_WORD3);
  5969. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  5970. command_type = OTHER_COMMAND;
  5971. break;
  5972. case CMD_CLOSE_XRI_CN:
  5973. case CMD_ABORT_XRI_CN:
  5974. case CMD_ABORT_XRI_CX:
  5975. /* words 0-2 memcpy should be 0 rserved */
  5976. /* port will send abts */
  5977. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  5978. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  5979. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  5980. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  5981. } else
  5982. fip = 0;
  5983. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  5984. /*
  5985. * The link is down, or the command was ELS_FIP
  5986. * so the fw does not need to send abts
  5987. * on the wire.
  5988. */
  5989. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5990. else
  5991. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5992. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5993. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  5994. wqe->abort_cmd.rsrvd5 = 0;
  5995. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  5996. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5997. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5998. /*
  5999. * The abort handler will send us CMD_ABORT_XRI_CN or
  6000. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6001. */
  6002. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6003. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6004. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6005. LPFC_WQE_LENLOC_NONE);
  6006. cmnd = CMD_ABORT_XRI_CX;
  6007. command_type = OTHER_COMMAND;
  6008. xritag = 0;
  6009. break;
  6010. case CMD_XMIT_BLS_RSP64_CX:
  6011. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  6012. * we re-construct this WQE here based on information in
  6013. * iocbq from scratch.
  6014. */
  6015. memset(wqe, 0, sizeof(union lpfc_wqe));
  6016. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6017. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6018. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  6019. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  6020. LPFC_ABTS_UNSOL_INT) {
  6021. /* ABTS sent by initiator to CT exchange, the
  6022. * RX_ID field will be filled with the newly
  6023. * allocated responder XRI.
  6024. */
  6025. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6026. iocbq->sli4_xritag);
  6027. } else {
  6028. /* ABTS sent by responder to CT exchange, the
  6029. * RX_ID field will be filled with the responder
  6030. * RX_ID from ABTS.
  6031. */
  6032. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6033. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  6034. }
  6035. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6036. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6037. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6038. iocbq->iocb.ulpContext);
  6039. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6040. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6041. LPFC_WQE_LENLOC_NONE);
  6042. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6043. command_type = OTHER_COMMAND;
  6044. break;
  6045. case CMD_XRI_ABORTED_CX:
  6046. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6047. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6048. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6049. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6050. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6051. default:
  6052. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6053. "2014 Invalid command 0x%x\n",
  6054. iocbq->iocb.ulpCommand);
  6055. return IOCB_ERROR;
  6056. break;
  6057. }
  6058. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6059. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6060. wqe->generic.wqe_com.abort_tag = abort_tag;
  6061. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6062. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6063. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6064. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6065. return 0;
  6066. }
  6067. /**
  6068. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6069. * @phba: Pointer to HBA context object.
  6070. * @ring_number: SLI ring number to issue iocb on.
  6071. * @piocb: Pointer to command iocb.
  6072. * @flag: Flag indicating if this command can be put into txq.
  6073. *
  6074. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6075. * an iocb command to an HBA with SLI-4 interface spec.
  6076. *
  6077. * This function is called with hbalock held. The function will return success
  6078. * after it successfully submit the iocb to firmware or after adding to the
  6079. * txq.
  6080. **/
  6081. static int
  6082. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6083. struct lpfc_iocbq *piocb, uint32_t flag)
  6084. {
  6085. struct lpfc_sglq *sglq;
  6086. union lpfc_wqe wqe;
  6087. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6088. if (piocb->sli4_xritag == NO_XRI) {
  6089. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6090. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  6091. sglq = NULL;
  6092. else {
  6093. if (pring->txq_cnt) {
  6094. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6095. __lpfc_sli_ringtx_put(phba,
  6096. pring, piocb);
  6097. return IOCB_SUCCESS;
  6098. } else {
  6099. return IOCB_BUSY;
  6100. }
  6101. } else {
  6102. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6103. if (!sglq) {
  6104. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6105. __lpfc_sli_ringtx_put(phba,
  6106. pring,
  6107. piocb);
  6108. return IOCB_SUCCESS;
  6109. } else
  6110. return IOCB_BUSY;
  6111. }
  6112. }
  6113. }
  6114. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6115. sglq = NULL; /* These IO's already have an XRI and
  6116. * a mapped sgl.
  6117. */
  6118. } else {
  6119. /* This is a continuation of a commandi,(CX) so this
  6120. * sglq is on the active list
  6121. */
  6122. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6123. if (!sglq)
  6124. return IOCB_ERROR;
  6125. }
  6126. if (sglq) {
  6127. piocb->sli4_xritag = sglq->sli4_xritag;
  6128. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6129. return IOCB_ERROR;
  6130. }
  6131. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6132. return IOCB_ERROR;
  6133. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6134. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6135. /*
  6136. * For FCP command IOCB, get a new WQ index to distribute
  6137. * WQE across the WQsr. On the other hand, for abort IOCB,
  6138. * it carries the same WQ index to the original command
  6139. * IOCB.
  6140. */
  6141. if (piocb->iocb_flag & LPFC_IO_FCP)
  6142. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6143. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6144. &wqe))
  6145. return IOCB_ERROR;
  6146. } else {
  6147. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6148. return IOCB_ERROR;
  6149. }
  6150. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6151. return 0;
  6152. }
  6153. /**
  6154. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6155. *
  6156. * This routine wraps the actual lockless version for issusing IOCB function
  6157. * pointer from the lpfc_hba struct.
  6158. *
  6159. * Return codes:
  6160. * IOCB_ERROR - Error
  6161. * IOCB_SUCCESS - Success
  6162. * IOCB_BUSY - Busy
  6163. **/
  6164. int
  6165. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6166. struct lpfc_iocbq *piocb, uint32_t flag)
  6167. {
  6168. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6169. }
  6170. /**
  6171. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  6172. * @phba: The hba struct for which this call is being executed.
  6173. * @dev_grp: The HBA PCI-Device group number.
  6174. *
  6175. * This routine sets up the SLI interface API function jump table in @phba
  6176. * struct.
  6177. * Returns: 0 - success, -ENODEV - failure.
  6178. **/
  6179. int
  6180. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6181. {
  6182. switch (dev_grp) {
  6183. case LPFC_PCI_DEV_LP:
  6184. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6185. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6186. break;
  6187. case LPFC_PCI_DEV_OC:
  6188. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6189. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6190. break;
  6191. default:
  6192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6193. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6194. dev_grp);
  6195. return -ENODEV;
  6196. break;
  6197. }
  6198. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6199. return 0;
  6200. }
  6201. /**
  6202. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6203. * @phba: Pointer to HBA context object.
  6204. * @pring: Pointer to driver SLI ring object.
  6205. * @piocb: Pointer to command iocb.
  6206. * @flag: Flag indicating if this command can be put into txq.
  6207. *
  6208. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6209. * function. This function gets the hbalock and calls
  6210. * __lpfc_sli_issue_iocb function and will return the error returned
  6211. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6212. * functions which do not hold hbalock.
  6213. **/
  6214. int
  6215. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6216. struct lpfc_iocbq *piocb, uint32_t flag)
  6217. {
  6218. unsigned long iflags;
  6219. int rc;
  6220. spin_lock_irqsave(&phba->hbalock, iflags);
  6221. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6222. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6223. return rc;
  6224. }
  6225. /**
  6226. * lpfc_extra_ring_setup - Extra ring setup function
  6227. * @phba: Pointer to HBA context object.
  6228. *
  6229. * This function is called while driver attaches with the
  6230. * HBA to setup the extra ring. The extra ring is used
  6231. * only when driver needs to support target mode functionality
  6232. * or IP over FC functionalities.
  6233. *
  6234. * This function is called with no lock held.
  6235. **/
  6236. static int
  6237. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6238. {
  6239. struct lpfc_sli *psli;
  6240. struct lpfc_sli_ring *pring;
  6241. psli = &phba->sli;
  6242. /* Adjust cmd/rsp ring iocb entries more evenly */
  6243. /* Take some away from the FCP ring */
  6244. pring = &psli->ring[psli->fcp_ring];
  6245. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6246. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6247. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6248. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6249. /* and give them to the extra ring */
  6250. pring = &psli->ring[psli->extra_ring];
  6251. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6252. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6253. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6254. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6255. /* Setup default profile for this ring */
  6256. pring->iotag_max = 4096;
  6257. pring->num_mask = 1;
  6258. pring->prt[0].profile = 0; /* Mask 0 */
  6259. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6260. pring->prt[0].type = phba->cfg_multi_ring_type;
  6261. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6262. return 0;
  6263. }
  6264. /**
  6265. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6266. * @phba: Pointer to HBA context object.
  6267. * @pring: Pointer to driver SLI ring object.
  6268. * @iocbq: Pointer to iocb object.
  6269. *
  6270. * This function is called by the slow ring event handler
  6271. * function when there is an ASYNC event iocb in the ring.
  6272. * This function is called with no lock held.
  6273. * Currently this function handles only temperature related
  6274. * ASYNC events. The function decodes the temperature sensor
  6275. * event message and posts events for the management applications.
  6276. **/
  6277. static void
  6278. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6279. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6280. {
  6281. IOCB_t *icmd;
  6282. uint16_t evt_code;
  6283. uint16_t temp;
  6284. struct temp_event temp_event_data;
  6285. struct Scsi_Host *shost;
  6286. uint32_t *iocb_w;
  6287. icmd = &iocbq->iocb;
  6288. evt_code = icmd->un.asyncstat.evt_code;
  6289. temp = icmd->ulpContext;
  6290. if ((evt_code != ASYNC_TEMP_WARN) &&
  6291. (evt_code != ASYNC_TEMP_SAFE)) {
  6292. iocb_w = (uint32_t *) icmd;
  6293. lpfc_printf_log(phba,
  6294. KERN_ERR,
  6295. LOG_SLI,
  6296. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6297. " evt_code 0x%x\n"
  6298. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6299. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6300. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6301. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6302. pring->ringno,
  6303. icmd->un.asyncstat.evt_code,
  6304. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6305. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6306. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6307. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6308. return;
  6309. }
  6310. temp_event_data.data = (uint32_t)temp;
  6311. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6312. if (evt_code == ASYNC_TEMP_WARN) {
  6313. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6314. lpfc_printf_log(phba,
  6315. KERN_ERR,
  6316. LOG_TEMP,
  6317. "0347 Adapter is very hot, please take "
  6318. "corrective action. temperature : %d Celsius\n",
  6319. temp);
  6320. }
  6321. if (evt_code == ASYNC_TEMP_SAFE) {
  6322. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6323. lpfc_printf_log(phba,
  6324. KERN_ERR,
  6325. LOG_TEMP,
  6326. "0340 Adapter temperature is OK now. "
  6327. "temperature : %d Celsius\n",
  6328. temp);
  6329. }
  6330. /* Send temperature change event to applications */
  6331. shost = lpfc_shost_from_vport(phba->pport);
  6332. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6333. sizeof(temp_event_data), (char *) &temp_event_data,
  6334. LPFC_NL_VENDOR_ID);
  6335. }
  6336. /**
  6337. * lpfc_sli_setup - SLI ring setup function
  6338. * @phba: Pointer to HBA context object.
  6339. *
  6340. * lpfc_sli_setup sets up rings of the SLI interface with
  6341. * number of iocbs per ring and iotags. This function is
  6342. * called while driver attach to the HBA and before the
  6343. * interrupts are enabled. So there is no need for locking.
  6344. *
  6345. * This function always returns 0.
  6346. **/
  6347. int
  6348. lpfc_sli_setup(struct lpfc_hba *phba)
  6349. {
  6350. int i, totiocbsize = 0;
  6351. struct lpfc_sli *psli = &phba->sli;
  6352. struct lpfc_sli_ring *pring;
  6353. psli->num_rings = MAX_CONFIGURED_RINGS;
  6354. psli->sli_flag = 0;
  6355. psli->fcp_ring = LPFC_FCP_RING;
  6356. psli->next_ring = LPFC_FCP_NEXT_RING;
  6357. psli->extra_ring = LPFC_EXTRA_RING;
  6358. psli->iocbq_lookup = NULL;
  6359. psli->iocbq_lookup_len = 0;
  6360. psli->last_iotag = 0;
  6361. for (i = 0; i < psli->num_rings; i++) {
  6362. pring = &psli->ring[i];
  6363. switch (i) {
  6364. case LPFC_FCP_RING: /* ring 0 - FCP */
  6365. /* numCiocb and numRiocb are used in config_port */
  6366. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6367. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6368. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6369. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6370. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6371. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6372. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6373. SLI3_IOCB_CMD_SIZE :
  6374. SLI2_IOCB_CMD_SIZE;
  6375. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6376. SLI3_IOCB_RSP_SIZE :
  6377. SLI2_IOCB_RSP_SIZE;
  6378. pring->iotag_ctr = 0;
  6379. pring->iotag_max =
  6380. (phba->cfg_hba_queue_depth * 2);
  6381. pring->fast_iotag = pring->iotag_max;
  6382. pring->num_mask = 0;
  6383. break;
  6384. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6385. /* numCiocb and numRiocb are used in config_port */
  6386. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6387. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6388. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6389. SLI3_IOCB_CMD_SIZE :
  6390. SLI2_IOCB_CMD_SIZE;
  6391. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6392. SLI3_IOCB_RSP_SIZE :
  6393. SLI2_IOCB_RSP_SIZE;
  6394. pring->iotag_max = phba->cfg_hba_queue_depth;
  6395. pring->num_mask = 0;
  6396. break;
  6397. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6398. /* numCiocb and numRiocb are used in config_port */
  6399. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6400. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6401. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6402. SLI3_IOCB_CMD_SIZE :
  6403. SLI2_IOCB_CMD_SIZE;
  6404. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6405. SLI3_IOCB_RSP_SIZE :
  6406. SLI2_IOCB_RSP_SIZE;
  6407. pring->fast_iotag = 0;
  6408. pring->iotag_ctr = 0;
  6409. pring->iotag_max = 4096;
  6410. pring->lpfc_sli_rcv_async_status =
  6411. lpfc_sli_async_event_handler;
  6412. pring->num_mask = LPFC_MAX_RING_MASK;
  6413. pring->prt[0].profile = 0; /* Mask 0 */
  6414. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6415. pring->prt[0].type = FC_TYPE_ELS;
  6416. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6417. lpfc_els_unsol_event;
  6418. pring->prt[1].profile = 0; /* Mask 1 */
  6419. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6420. pring->prt[1].type = FC_TYPE_ELS;
  6421. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6422. lpfc_els_unsol_event;
  6423. pring->prt[2].profile = 0; /* Mask 2 */
  6424. /* NameServer Inquiry */
  6425. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6426. /* NameServer */
  6427. pring->prt[2].type = FC_TYPE_CT;
  6428. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6429. lpfc_ct_unsol_event;
  6430. pring->prt[3].profile = 0; /* Mask 3 */
  6431. /* NameServer response */
  6432. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6433. /* NameServer */
  6434. pring->prt[3].type = FC_TYPE_CT;
  6435. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6436. lpfc_ct_unsol_event;
  6437. /* abort unsolicited sequence */
  6438. pring->prt[4].profile = 0; /* Mask 4 */
  6439. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6440. pring->prt[4].type = FC_TYPE_BLS;
  6441. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6442. lpfc_sli4_ct_abort_unsol_event;
  6443. break;
  6444. }
  6445. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6446. (pring->numRiocb * pring->sizeRiocb);
  6447. }
  6448. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6449. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6450. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6451. "SLI2 SLIM Data: x%x x%lx\n",
  6452. phba->brd_no, totiocbsize,
  6453. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6454. }
  6455. if (phba->cfg_multi_ring_support == 2)
  6456. lpfc_extra_ring_setup(phba);
  6457. return 0;
  6458. }
  6459. /**
  6460. * lpfc_sli_queue_setup - Queue initialization function
  6461. * @phba: Pointer to HBA context object.
  6462. *
  6463. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6464. * ring. This function also initializes ring indices of each ring.
  6465. * This function is called during the initialization of the SLI
  6466. * interface of an HBA.
  6467. * This function is called with no lock held and always returns
  6468. * 1.
  6469. **/
  6470. int
  6471. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6472. {
  6473. struct lpfc_sli *psli;
  6474. struct lpfc_sli_ring *pring;
  6475. int i;
  6476. psli = &phba->sli;
  6477. spin_lock_irq(&phba->hbalock);
  6478. INIT_LIST_HEAD(&psli->mboxq);
  6479. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6480. /* Initialize list headers for txq and txcmplq as double linked lists */
  6481. for (i = 0; i < psli->num_rings; i++) {
  6482. pring = &psli->ring[i];
  6483. pring->ringno = i;
  6484. pring->next_cmdidx = 0;
  6485. pring->local_getidx = 0;
  6486. pring->cmdidx = 0;
  6487. INIT_LIST_HEAD(&pring->txq);
  6488. INIT_LIST_HEAD(&pring->txcmplq);
  6489. INIT_LIST_HEAD(&pring->iocb_continueq);
  6490. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6491. INIT_LIST_HEAD(&pring->postbufq);
  6492. }
  6493. spin_unlock_irq(&phba->hbalock);
  6494. return 1;
  6495. }
  6496. /**
  6497. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6498. * @phba: Pointer to HBA context object.
  6499. *
  6500. * This routine flushes the mailbox command subsystem. It will unconditionally
  6501. * flush all the mailbox commands in the three possible stages in the mailbox
  6502. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6503. * command; and completed mailbox command queue. It is caller's responsibility
  6504. * to make sure that the driver is in the proper state to flush the mailbox
  6505. * command sub-system. Namely, the posting of mailbox commands into the
  6506. * pending mailbox command queue from the various clients must be stopped;
  6507. * either the HBA is in a state that it will never works on the outstanding
  6508. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6509. * mailbox command has been completed.
  6510. **/
  6511. static void
  6512. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6513. {
  6514. LIST_HEAD(completions);
  6515. struct lpfc_sli *psli = &phba->sli;
  6516. LPFC_MBOXQ_t *pmb;
  6517. unsigned long iflag;
  6518. /* Flush all the mailbox commands in the mbox system */
  6519. spin_lock_irqsave(&phba->hbalock, iflag);
  6520. /* The pending mailbox command queue */
  6521. list_splice_init(&phba->sli.mboxq, &completions);
  6522. /* The outstanding active mailbox command */
  6523. if (psli->mbox_active) {
  6524. list_add_tail(&psli->mbox_active->list, &completions);
  6525. psli->mbox_active = NULL;
  6526. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6527. }
  6528. /* The completed mailbox command queue */
  6529. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6530. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6531. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6532. while (!list_empty(&completions)) {
  6533. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6534. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6535. if (pmb->mbox_cmpl)
  6536. pmb->mbox_cmpl(phba, pmb);
  6537. }
  6538. }
  6539. /**
  6540. * lpfc_sli_host_down - Vport cleanup function
  6541. * @vport: Pointer to virtual port object.
  6542. *
  6543. * lpfc_sli_host_down is called to clean up the resources
  6544. * associated with a vport before destroying virtual
  6545. * port data structures.
  6546. * This function does following operations:
  6547. * - Free discovery resources associated with this virtual
  6548. * port.
  6549. * - Free iocbs associated with this virtual port in
  6550. * the txq.
  6551. * - Send abort for all iocb commands associated with this
  6552. * vport in txcmplq.
  6553. *
  6554. * This function is called with no lock held and always returns 1.
  6555. **/
  6556. int
  6557. lpfc_sli_host_down(struct lpfc_vport *vport)
  6558. {
  6559. LIST_HEAD(completions);
  6560. struct lpfc_hba *phba = vport->phba;
  6561. struct lpfc_sli *psli = &phba->sli;
  6562. struct lpfc_sli_ring *pring;
  6563. struct lpfc_iocbq *iocb, *next_iocb;
  6564. int i;
  6565. unsigned long flags = 0;
  6566. uint16_t prev_pring_flag;
  6567. lpfc_cleanup_discovery_resources(vport);
  6568. spin_lock_irqsave(&phba->hbalock, flags);
  6569. for (i = 0; i < psli->num_rings; i++) {
  6570. pring = &psli->ring[i];
  6571. prev_pring_flag = pring->flag;
  6572. /* Only slow rings */
  6573. if (pring->ringno == LPFC_ELS_RING) {
  6574. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6575. /* Set the lpfc data pending flag */
  6576. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6577. }
  6578. /*
  6579. * Error everything on the txq since these iocbs have not been
  6580. * given to the FW yet.
  6581. */
  6582. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6583. if (iocb->vport != vport)
  6584. continue;
  6585. list_move_tail(&iocb->list, &completions);
  6586. pring->txq_cnt--;
  6587. }
  6588. /* Next issue ABTS for everything on the txcmplq */
  6589. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6590. list) {
  6591. if (iocb->vport != vport)
  6592. continue;
  6593. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6594. }
  6595. pring->flag = prev_pring_flag;
  6596. }
  6597. spin_unlock_irqrestore(&phba->hbalock, flags);
  6598. /* Cancel all the IOCBs from the completions list */
  6599. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6600. IOERR_SLI_DOWN);
  6601. return 1;
  6602. }
  6603. /**
  6604. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6605. * @phba: Pointer to HBA context object.
  6606. *
  6607. * This function cleans up all iocb, buffers, mailbox commands
  6608. * while shutting down the HBA. This function is called with no
  6609. * lock held and always returns 1.
  6610. * This function does the following to cleanup driver resources:
  6611. * - Free discovery resources for each virtual port
  6612. * - Cleanup any pending fabric iocbs
  6613. * - Iterate through the iocb txq and free each entry
  6614. * in the list.
  6615. * - Free up any buffer posted to the HBA
  6616. * - Free mailbox commands in the mailbox queue.
  6617. **/
  6618. int
  6619. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6620. {
  6621. LIST_HEAD(completions);
  6622. struct lpfc_sli *psli = &phba->sli;
  6623. struct lpfc_sli_ring *pring;
  6624. struct lpfc_dmabuf *buf_ptr;
  6625. unsigned long flags = 0;
  6626. int i;
  6627. /* Shutdown the mailbox command sub-system */
  6628. lpfc_sli_mbox_sys_shutdown(phba);
  6629. lpfc_hba_down_prep(phba);
  6630. lpfc_fabric_abort_hba(phba);
  6631. spin_lock_irqsave(&phba->hbalock, flags);
  6632. for (i = 0; i < psli->num_rings; i++) {
  6633. pring = &psli->ring[i];
  6634. /* Only slow rings */
  6635. if (pring->ringno == LPFC_ELS_RING) {
  6636. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6637. /* Set the lpfc data pending flag */
  6638. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6639. }
  6640. /*
  6641. * Error everything on the txq since these iocbs have not been
  6642. * given to the FW yet.
  6643. */
  6644. list_splice_init(&pring->txq, &completions);
  6645. pring->txq_cnt = 0;
  6646. }
  6647. spin_unlock_irqrestore(&phba->hbalock, flags);
  6648. /* Cancel all the IOCBs from the completions list */
  6649. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6650. IOERR_SLI_DOWN);
  6651. spin_lock_irqsave(&phba->hbalock, flags);
  6652. list_splice_init(&phba->elsbuf, &completions);
  6653. phba->elsbuf_cnt = 0;
  6654. phba->elsbuf_prev_cnt = 0;
  6655. spin_unlock_irqrestore(&phba->hbalock, flags);
  6656. while (!list_empty(&completions)) {
  6657. list_remove_head(&completions, buf_ptr,
  6658. struct lpfc_dmabuf, list);
  6659. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6660. kfree(buf_ptr);
  6661. }
  6662. /* Return any active mbox cmds */
  6663. del_timer_sync(&psli->mbox_tmo);
  6664. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6665. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6666. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6667. return 1;
  6668. }
  6669. /**
  6670. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6671. * @srcp: Source memory pointer.
  6672. * @destp: Destination memory pointer.
  6673. * @cnt: Number of words required to be copied.
  6674. *
  6675. * This function is used for copying data between driver memory
  6676. * and the SLI memory. This function also changes the endianness
  6677. * of each word if native endianness is different from SLI
  6678. * endianness. This function can be called with or without
  6679. * lock.
  6680. **/
  6681. void
  6682. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6683. {
  6684. uint32_t *src = srcp;
  6685. uint32_t *dest = destp;
  6686. uint32_t ldata;
  6687. int i;
  6688. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6689. ldata = *src;
  6690. ldata = le32_to_cpu(ldata);
  6691. *dest = ldata;
  6692. src++;
  6693. dest++;
  6694. }
  6695. }
  6696. /**
  6697. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6698. * @srcp: Source memory pointer.
  6699. * @destp: Destination memory pointer.
  6700. * @cnt: Number of words required to be copied.
  6701. *
  6702. * This function is used for copying data between a data structure
  6703. * with big endian representation to local endianness.
  6704. * This function can be called with or without lock.
  6705. **/
  6706. void
  6707. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6708. {
  6709. uint32_t *src = srcp;
  6710. uint32_t *dest = destp;
  6711. uint32_t ldata;
  6712. int i;
  6713. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6714. ldata = *src;
  6715. ldata = be32_to_cpu(ldata);
  6716. *dest = ldata;
  6717. src++;
  6718. dest++;
  6719. }
  6720. }
  6721. /**
  6722. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6723. * @phba: Pointer to HBA context object.
  6724. * @pring: Pointer to driver SLI ring object.
  6725. * @mp: Pointer to driver buffer object.
  6726. *
  6727. * This function is called with no lock held.
  6728. * It always return zero after adding the buffer to the postbufq
  6729. * buffer list.
  6730. **/
  6731. int
  6732. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6733. struct lpfc_dmabuf *mp)
  6734. {
  6735. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6736. later */
  6737. spin_lock_irq(&phba->hbalock);
  6738. list_add_tail(&mp->list, &pring->postbufq);
  6739. pring->postbufq_cnt++;
  6740. spin_unlock_irq(&phba->hbalock);
  6741. return 0;
  6742. }
  6743. /**
  6744. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6745. * @phba: Pointer to HBA context object.
  6746. *
  6747. * When HBQ is enabled, buffers are searched based on tags. This function
  6748. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6749. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6750. * does not conflict with tags of buffer posted for unsolicited events.
  6751. * The function returns the allocated tag. The function is called with
  6752. * no locks held.
  6753. **/
  6754. uint32_t
  6755. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6756. {
  6757. spin_lock_irq(&phba->hbalock);
  6758. phba->buffer_tag_count++;
  6759. /*
  6760. * Always set the QUE_BUFTAG_BIT to distiguish between
  6761. * a tag assigned by HBQ.
  6762. */
  6763. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6764. spin_unlock_irq(&phba->hbalock);
  6765. return phba->buffer_tag_count;
  6766. }
  6767. /**
  6768. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6769. * @phba: Pointer to HBA context object.
  6770. * @pring: Pointer to driver SLI ring object.
  6771. * @tag: Buffer tag.
  6772. *
  6773. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6774. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6775. * iocb is posted to the response ring with the tag of the buffer.
  6776. * This function searches the pring->postbufq list using the tag
  6777. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6778. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6779. * buffer is returned to the caller else NULL is returned.
  6780. * This function is called with no lock held.
  6781. **/
  6782. struct lpfc_dmabuf *
  6783. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6784. uint32_t tag)
  6785. {
  6786. struct lpfc_dmabuf *mp, *next_mp;
  6787. struct list_head *slp = &pring->postbufq;
  6788. /* Search postbufq, from the begining, looking for a match on tag */
  6789. spin_lock_irq(&phba->hbalock);
  6790. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6791. if (mp->buffer_tag == tag) {
  6792. list_del_init(&mp->list);
  6793. pring->postbufq_cnt--;
  6794. spin_unlock_irq(&phba->hbalock);
  6795. return mp;
  6796. }
  6797. }
  6798. spin_unlock_irq(&phba->hbalock);
  6799. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6800. "0402 Cannot find virtual addr for buffer tag on "
  6801. "ring %d Data x%lx x%p x%p x%x\n",
  6802. pring->ringno, (unsigned long) tag,
  6803. slp->next, slp->prev, pring->postbufq_cnt);
  6804. return NULL;
  6805. }
  6806. /**
  6807. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6808. * @phba: Pointer to HBA context object.
  6809. * @pring: Pointer to driver SLI ring object.
  6810. * @phys: DMA address of the buffer.
  6811. *
  6812. * This function searches the buffer list using the dma_address
  6813. * of unsolicited event to find the driver's lpfc_dmabuf object
  6814. * corresponding to the dma_address. The function returns the
  6815. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6816. * This function is called by the ct and els unsolicited event
  6817. * handlers to get the buffer associated with the unsolicited
  6818. * event.
  6819. *
  6820. * This function is called with no lock held.
  6821. **/
  6822. struct lpfc_dmabuf *
  6823. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6824. dma_addr_t phys)
  6825. {
  6826. struct lpfc_dmabuf *mp, *next_mp;
  6827. struct list_head *slp = &pring->postbufq;
  6828. /* Search postbufq, from the begining, looking for a match on phys */
  6829. spin_lock_irq(&phba->hbalock);
  6830. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6831. if (mp->phys == phys) {
  6832. list_del_init(&mp->list);
  6833. pring->postbufq_cnt--;
  6834. spin_unlock_irq(&phba->hbalock);
  6835. return mp;
  6836. }
  6837. }
  6838. spin_unlock_irq(&phba->hbalock);
  6839. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6840. "0410 Cannot find virtual addr for mapped buf on "
  6841. "ring %d Data x%llx x%p x%p x%x\n",
  6842. pring->ringno, (unsigned long long)phys,
  6843. slp->next, slp->prev, pring->postbufq_cnt);
  6844. return NULL;
  6845. }
  6846. /**
  6847. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6848. * @phba: Pointer to HBA context object.
  6849. * @cmdiocb: Pointer to driver command iocb object.
  6850. * @rspiocb: Pointer to driver response iocb object.
  6851. *
  6852. * This function is the completion handler for the abort iocbs for
  6853. * ELS commands. This function is called from the ELS ring event
  6854. * handler with no lock held. This function frees memory resources
  6855. * associated with the abort iocb.
  6856. **/
  6857. static void
  6858. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6859. struct lpfc_iocbq *rspiocb)
  6860. {
  6861. IOCB_t *irsp = &rspiocb->iocb;
  6862. uint16_t abort_iotag, abort_context;
  6863. struct lpfc_iocbq *abort_iocb;
  6864. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6865. abort_iocb = NULL;
  6866. if (irsp->ulpStatus) {
  6867. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6868. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6869. spin_lock_irq(&phba->hbalock);
  6870. if (phba->sli_rev < LPFC_SLI_REV4) {
  6871. if (abort_iotag != 0 &&
  6872. abort_iotag <= phba->sli.last_iotag)
  6873. abort_iocb =
  6874. phba->sli.iocbq_lookup[abort_iotag];
  6875. } else
  6876. /* For sli4 the abort_tag is the XRI,
  6877. * so the abort routine puts the iotag of the iocb
  6878. * being aborted in the context field of the abort
  6879. * IOCB.
  6880. */
  6881. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6882. /*
  6883. * If the iocb is not found in Firmware queue the iocb
  6884. * might have completed already. Do not free it again.
  6885. */
  6886. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6887. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6888. spin_unlock_irq(&phba->hbalock);
  6889. lpfc_sli_release_iocbq(phba, cmdiocb);
  6890. return;
  6891. }
  6892. /* For SLI4 the ulpContext field for abort IOCB
  6893. * holds the iotag of the IOCB being aborted so
  6894. * the local abort_context needs to be reset to
  6895. * match the aborted IOCBs ulpContext.
  6896. */
  6897. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6898. abort_context = abort_iocb->iocb.ulpContext;
  6899. }
  6900. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6901. "0327 Cannot abort els iocb %p "
  6902. "with tag %x context %x, abort status %x, "
  6903. "abort code %x\n",
  6904. abort_iocb, abort_iotag, abort_context,
  6905. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6906. /*
  6907. * make sure we have the right iocbq before taking it
  6908. * off the txcmplq and try to call completion routine.
  6909. */
  6910. if (!abort_iocb ||
  6911. abort_iocb->iocb.ulpContext != abort_context ||
  6912. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6913. spin_unlock_irq(&phba->hbalock);
  6914. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6915. /*
  6916. * leave the SLI4 aborted command on the txcmplq
  6917. * list and the command complete WCQE's XB bit
  6918. * will tell whether the SGL (XRI) can be released
  6919. * immediately or to the aborted SGL list for the
  6920. * following abort XRI from the HBA.
  6921. */
  6922. list_del_init(&abort_iocb->list);
  6923. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6924. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6925. pring->txcmplq_cnt--;
  6926. }
  6927. /* Firmware could still be in progress of DMAing
  6928. * payload, so don't free data buffer till after
  6929. * a hbeat.
  6930. */
  6931. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6932. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6933. spin_unlock_irq(&phba->hbalock);
  6934. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6935. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6936. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6937. } else
  6938. spin_unlock_irq(&phba->hbalock);
  6939. }
  6940. lpfc_sli_release_iocbq(phba, cmdiocb);
  6941. return;
  6942. }
  6943. /**
  6944. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6945. * @phba: Pointer to HBA context object.
  6946. * @cmdiocb: Pointer to driver command iocb object.
  6947. * @rspiocb: Pointer to driver response iocb object.
  6948. *
  6949. * The function is called from SLI ring event handler with no
  6950. * lock held. This function is the completion handler for ELS commands
  6951. * which are aborted. The function frees memory resources used for
  6952. * the aborted ELS commands.
  6953. **/
  6954. static void
  6955. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6956. struct lpfc_iocbq *rspiocb)
  6957. {
  6958. IOCB_t *irsp = &rspiocb->iocb;
  6959. /* ELS cmd tag <ulpIoTag> completes */
  6960. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6961. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6962. "x%x x%x x%x\n",
  6963. irsp->ulpIoTag, irsp->ulpStatus,
  6964. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6965. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6966. lpfc_ct_free_iocb(phba, cmdiocb);
  6967. else
  6968. lpfc_els_free_iocb(phba, cmdiocb);
  6969. return;
  6970. }
  6971. /**
  6972. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  6973. * @phba: Pointer to HBA context object.
  6974. * @pring: Pointer to driver SLI ring object.
  6975. * @cmdiocb: Pointer to driver command iocb object.
  6976. *
  6977. * This function issues an abort iocb for the provided command iocb down to
  6978. * the port. Other than the case the outstanding command iocb is an abort
  6979. * request, this function issues abort out unconditionally. This function is
  6980. * called with hbalock held. The function returns 0 when it fails due to
  6981. * memory allocation failure or when the command iocb is an abort request.
  6982. **/
  6983. static int
  6984. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6985. struct lpfc_iocbq *cmdiocb)
  6986. {
  6987. struct lpfc_vport *vport = cmdiocb->vport;
  6988. struct lpfc_iocbq *abtsiocbp;
  6989. IOCB_t *icmd = NULL;
  6990. IOCB_t *iabt = NULL;
  6991. int retval;
  6992. /*
  6993. * There are certain command types we don't want to abort. And we
  6994. * don't want to abort commands that are already in the process of
  6995. * being aborted.
  6996. */
  6997. icmd = &cmdiocb->iocb;
  6998. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6999. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7000. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7001. return 0;
  7002. /* issue ABTS for this IOCB based on iotag */
  7003. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7004. if (abtsiocbp == NULL)
  7005. return 0;
  7006. /* This signals the response to set the correct status
  7007. * before calling the completion handler
  7008. */
  7009. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7010. iabt = &abtsiocbp->iocb;
  7011. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7012. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7013. if (phba->sli_rev == LPFC_SLI_REV4) {
  7014. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7015. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7016. }
  7017. else
  7018. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7019. iabt->ulpLe = 1;
  7020. iabt->ulpClass = icmd->ulpClass;
  7021. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7022. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7023. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7024. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7025. if (phba->link_state >= LPFC_LINK_UP)
  7026. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7027. else
  7028. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7029. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7030. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7031. "0339 Abort xri x%x, original iotag x%x, "
  7032. "abort cmd iotag x%x\n",
  7033. iabt->un.acxri.abortIoTag,
  7034. iabt->un.acxri.abortContextTag,
  7035. abtsiocbp->iotag);
  7036. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7037. if (retval)
  7038. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7039. /*
  7040. * Caller to this routine should check for IOCB_ERROR
  7041. * and handle it properly. This routine no longer removes
  7042. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7043. */
  7044. return retval;
  7045. }
  7046. /**
  7047. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7048. * @phba: Pointer to HBA context object.
  7049. * @pring: Pointer to driver SLI ring object.
  7050. * @cmdiocb: Pointer to driver command iocb object.
  7051. *
  7052. * This function issues an abort iocb for the provided command iocb. In case
  7053. * of unloading, the abort iocb will not be issued to commands on the ELS
  7054. * ring. Instead, the callback function shall be changed to those commands
  7055. * so that nothing happens when them finishes. This function is called with
  7056. * hbalock held. The function returns 0 when the command iocb is an abort
  7057. * request.
  7058. **/
  7059. int
  7060. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7061. struct lpfc_iocbq *cmdiocb)
  7062. {
  7063. struct lpfc_vport *vport = cmdiocb->vport;
  7064. int retval = IOCB_ERROR;
  7065. IOCB_t *icmd = NULL;
  7066. /*
  7067. * There are certain command types we don't want to abort. And we
  7068. * don't want to abort commands that are already in the process of
  7069. * being aborted.
  7070. */
  7071. icmd = &cmdiocb->iocb;
  7072. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7073. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7074. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7075. return 0;
  7076. /*
  7077. * If we're unloading, don't abort iocb on the ELS ring, but change
  7078. * the callback so that nothing happens when it finishes.
  7079. */
  7080. if ((vport->load_flag & FC_UNLOADING) &&
  7081. (pring->ringno == LPFC_ELS_RING)) {
  7082. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7083. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7084. else
  7085. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7086. goto abort_iotag_exit;
  7087. }
  7088. /* Now, we try to issue the abort to the cmdiocb out */
  7089. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7090. abort_iotag_exit:
  7091. /*
  7092. * Caller to this routine should check for IOCB_ERROR
  7093. * and handle it properly. This routine no longer removes
  7094. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7095. */
  7096. return retval;
  7097. }
  7098. /**
  7099. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7100. * @phba: Pointer to HBA context object.
  7101. * @pring: Pointer to driver SLI ring object.
  7102. *
  7103. * This function aborts all iocbs in the given ring and frees all the iocb
  7104. * objects in txq. This function issues abort iocbs unconditionally for all
  7105. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7106. * to complete before the return of this function. The caller is not required
  7107. * to hold any locks.
  7108. **/
  7109. static void
  7110. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7111. {
  7112. LIST_HEAD(completions);
  7113. struct lpfc_iocbq *iocb, *next_iocb;
  7114. if (pring->ringno == LPFC_ELS_RING)
  7115. lpfc_fabric_abort_hba(phba);
  7116. spin_lock_irq(&phba->hbalock);
  7117. /* Take off all the iocbs on txq for cancelling */
  7118. list_splice_init(&pring->txq, &completions);
  7119. pring->txq_cnt = 0;
  7120. /* Next issue ABTS for everything on the txcmplq */
  7121. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7122. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7123. spin_unlock_irq(&phba->hbalock);
  7124. /* Cancel all the IOCBs from the completions list */
  7125. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7126. IOERR_SLI_ABORTED);
  7127. }
  7128. /**
  7129. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7130. * @phba: pointer to lpfc HBA data structure.
  7131. *
  7132. * This routine will abort all pending and outstanding iocbs to an HBA.
  7133. **/
  7134. void
  7135. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7136. {
  7137. struct lpfc_sli *psli = &phba->sli;
  7138. struct lpfc_sli_ring *pring;
  7139. int i;
  7140. for (i = 0; i < psli->num_rings; i++) {
  7141. pring = &psli->ring[i];
  7142. lpfc_sli_iocb_ring_abort(phba, pring);
  7143. }
  7144. }
  7145. /**
  7146. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7147. * @iocbq: Pointer to driver iocb object.
  7148. * @vport: Pointer to driver virtual port object.
  7149. * @tgt_id: SCSI ID of the target.
  7150. * @lun_id: LUN ID of the scsi device.
  7151. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7152. *
  7153. * This function acts as an iocb filter for functions which abort or count
  7154. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7155. * 0 if the filtering criteria is met for the given iocb and will return
  7156. * 1 if the filtering criteria is not met.
  7157. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7158. * given iocb is for the SCSI device specified by vport, tgt_id and
  7159. * lun_id parameter.
  7160. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7161. * given iocb is for the SCSI target specified by vport and tgt_id
  7162. * parameters.
  7163. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7164. * given iocb is for the SCSI host associated with the given vport.
  7165. * This function is called with no locks held.
  7166. **/
  7167. static int
  7168. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7169. uint16_t tgt_id, uint64_t lun_id,
  7170. lpfc_ctx_cmd ctx_cmd)
  7171. {
  7172. struct lpfc_scsi_buf *lpfc_cmd;
  7173. int rc = 1;
  7174. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7175. return rc;
  7176. if (iocbq->vport != vport)
  7177. return rc;
  7178. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7179. if (lpfc_cmd->pCmd == NULL)
  7180. return rc;
  7181. switch (ctx_cmd) {
  7182. case LPFC_CTX_LUN:
  7183. if ((lpfc_cmd->rdata->pnode) &&
  7184. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7185. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7186. rc = 0;
  7187. break;
  7188. case LPFC_CTX_TGT:
  7189. if ((lpfc_cmd->rdata->pnode) &&
  7190. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7191. rc = 0;
  7192. break;
  7193. case LPFC_CTX_HOST:
  7194. rc = 0;
  7195. break;
  7196. default:
  7197. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7198. __func__, ctx_cmd);
  7199. break;
  7200. }
  7201. return rc;
  7202. }
  7203. /**
  7204. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7205. * @vport: Pointer to virtual port.
  7206. * @tgt_id: SCSI ID of the target.
  7207. * @lun_id: LUN ID of the scsi device.
  7208. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7209. *
  7210. * This function returns number of FCP commands pending for the vport.
  7211. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7212. * commands pending on the vport associated with SCSI device specified
  7213. * by tgt_id and lun_id parameters.
  7214. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7215. * commands pending on the vport associated with SCSI target specified
  7216. * by tgt_id parameter.
  7217. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7218. * commands pending on the vport.
  7219. * This function returns the number of iocbs which satisfy the filter.
  7220. * This function is called without any lock held.
  7221. **/
  7222. int
  7223. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7224. lpfc_ctx_cmd ctx_cmd)
  7225. {
  7226. struct lpfc_hba *phba = vport->phba;
  7227. struct lpfc_iocbq *iocbq;
  7228. int sum, i;
  7229. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7230. iocbq = phba->sli.iocbq_lookup[i];
  7231. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7232. ctx_cmd) == 0)
  7233. sum++;
  7234. }
  7235. return sum;
  7236. }
  7237. /**
  7238. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7239. * @phba: Pointer to HBA context object
  7240. * @cmdiocb: Pointer to command iocb object.
  7241. * @rspiocb: Pointer to response iocb object.
  7242. *
  7243. * This function is called when an aborted FCP iocb completes. This
  7244. * function is called by the ring event handler with no lock held.
  7245. * This function frees the iocb.
  7246. **/
  7247. void
  7248. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7249. struct lpfc_iocbq *rspiocb)
  7250. {
  7251. lpfc_sli_release_iocbq(phba, cmdiocb);
  7252. return;
  7253. }
  7254. /**
  7255. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7256. * @vport: Pointer to virtual port.
  7257. * @pring: Pointer to driver SLI ring object.
  7258. * @tgt_id: SCSI ID of the target.
  7259. * @lun_id: LUN ID of the scsi device.
  7260. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7261. *
  7262. * This function sends an abort command for every SCSI command
  7263. * associated with the given virtual port pending on the ring
  7264. * filtered by lpfc_sli_validate_fcp_iocb function.
  7265. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7266. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7267. * parameters
  7268. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7269. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7270. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7271. * FCP iocbs associated with virtual port.
  7272. * This function returns number of iocbs it failed to abort.
  7273. * This function is called with no locks held.
  7274. **/
  7275. int
  7276. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7277. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7278. {
  7279. struct lpfc_hba *phba = vport->phba;
  7280. struct lpfc_iocbq *iocbq;
  7281. struct lpfc_iocbq *abtsiocb;
  7282. IOCB_t *cmd = NULL;
  7283. int errcnt = 0, ret_val = 0;
  7284. int i;
  7285. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7286. iocbq = phba->sli.iocbq_lookup[i];
  7287. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7288. abort_cmd) != 0)
  7289. continue;
  7290. /* issue ABTS for this IOCB based on iotag */
  7291. abtsiocb = lpfc_sli_get_iocbq(phba);
  7292. if (abtsiocb == NULL) {
  7293. errcnt++;
  7294. continue;
  7295. }
  7296. cmd = &iocbq->iocb;
  7297. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7298. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7299. if (phba->sli_rev == LPFC_SLI_REV4)
  7300. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7301. else
  7302. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7303. abtsiocb->iocb.ulpLe = 1;
  7304. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7305. abtsiocb->vport = phba->pport;
  7306. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7307. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7308. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7309. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7310. if (lpfc_is_link_up(phba))
  7311. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7312. else
  7313. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7314. /* Setup callback routine and issue the command. */
  7315. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7316. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7317. abtsiocb, 0);
  7318. if (ret_val == IOCB_ERROR) {
  7319. lpfc_sli_release_iocbq(phba, abtsiocb);
  7320. errcnt++;
  7321. continue;
  7322. }
  7323. }
  7324. return errcnt;
  7325. }
  7326. /**
  7327. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7328. * @phba: Pointer to HBA context object.
  7329. * @cmdiocbq: Pointer to command iocb.
  7330. * @rspiocbq: Pointer to response iocb.
  7331. *
  7332. * This function is the completion handler for iocbs issued using
  7333. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7334. * ring event handler function without any lock held. This function
  7335. * can be called from both worker thread context and interrupt
  7336. * context. This function also can be called from other thread which
  7337. * cleans up the SLI layer objects.
  7338. * This function copy the contents of the response iocb to the
  7339. * response iocb memory object provided by the caller of
  7340. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7341. * sleeps for the iocb completion.
  7342. **/
  7343. static void
  7344. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7345. struct lpfc_iocbq *cmdiocbq,
  7346. struct lpfc_iocbq *rspiocbq)
  7347. {
  7348. wait_queue_head_t *pdone_q;
  7349. unsigned long iflags;
  7350. struct lpfc_scsi_buf *lpfc_cmd;
  7351. spin_lock_irqsave(&phba->hbalock, iflags);
  7352. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7353. if (cmdiocbq->context2 && rspiocbq)
  7354. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7355. &rspiocbq->iocb, sizeof(IOCB_t));
  7356. /* Set the exchange busy flag for task management commands */
  7357. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7358. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7359. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7360. cur_iocbq);
  7361. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7362. }
  7363. pdone_q = cmdiocbq->context_un.wait_queue;
  7364. if (pdone_q)
  7365. wake_up(pdone_q);
  7366. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7367. return;
  7368. }
  7369. /**
  7370. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7371. * @phba: Pointer to HBA context object..
  7372. * @piocbq: Pointer to command iocb.
  7373. * @flag: Flag to test.
  7374. *
  7375. * This routine grabs the hbalock and then test the iocb_flag to
  7376. * see if the passed in flag is set.
  7377. * Returns:
  7378. * 1 if flag is set.
  7379. * 0 if flag is not set.
  7380. **/
  7381. static int
  7382. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7383. struct lpfc_iocbq *piocbq, uint32_t flag)
  7384. {
  7385. unsigned long iflags;
  7386. int ret;
  7387. spin_lock_irqsave(&phba->hbalock, iflags);
  7388. ret = piocbq->iocb_flag & flag;
  7389. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7390. return ret;
  7391. }
  7392. /**
  7393. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7394. * @phba: Pointer to HBA context object..
  7395. * @pring: Pointer to sli ring.
  7396. * @piocb: Pointer to command iocb.
  7397. * @prspiocbq: Pointer to response iocb.
  7398. * @timeout: Timeout in number of seconds.
  7399. *
  7400. * This function issues the iocb to firmware and waits for the
  7401. * iocb to complete. If the iocb command is not
  7402. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7403. * Caller should not free the iocb resources if this function
  7404. * returns IOCB_TIMEDOUT.
  7405. * The function waits for the iocb completion using an
  7406. * non-interruptible wait.
  7407. * This function will sleep while waiting for iocb completion.
  7408. * So, this function should not be called from any context which
  7409. * does not allow sleeping. Due to the same reason, this function
  7410. * cannot be called with interrupt disabled.
  7411. * This function assumes that the iocb completions occur while
  7412. * this function sleep. So, this function cannot be called from
  7413. * the thread which process iocb completion for this ring.
  7414. * This function clears the iocb_flag of the iocb object before
  7415. * issuing the iocb and the iocb completion handler sets this
  7416. * flag and wakes this thread when the iocb completes.
  7417. * The contents of the response iocb will be copied to prspiocbq
  7418. * by the completion handler when the command completes.
  7419. * This function returns IOCB_SUCCESS when success.
  7420. * This function is called with no lock held.
  7421. **/
  7422. int
  7423. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7424. uint32_t ring_number,
  7425. struct lpfc_iocbq *piocb,
  7426. struct lpfc_iocbq *prspiocbq,
  7427. uint32_t timeout)
  7428. {
  7429. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7430. long timeleft, timeout_req = 0;
  7431. int retval = IOCB_SUCCESS;
  7432. uint32_t creg_val;
  7433. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7434. /*
  7435. * If the caller has provided a response iocbq buffer, then context2
  7436. * is NULL or its an error.
  7437. */
  7438. if (prspiocbq) {
  7439. if (piocb->context2)
  7440. return IOCB_ERROR;
  7441. piocb->context2 = prspiocbq;
  7442. }
  7443. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7444. piocb->context_un.wait_queue = &done_q;
  7445. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7446. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7447. creg_val = readl(phba->HCregaddr);
  7448. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7449. writel(creg_val, phba->HCregaddr);
  7450. readl(phba->HCregaddr); /* flush */
  7451. }
  7452. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7453. SLI_IOCB_RET_IOCB);
  7454. if (retval == IOCB_SUCCESS) {
  7455. timeout_req = timeout * HZ;
  7456. timeleft = wait_event_timeout(done_q,
  7457. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7458. timeout_req);
  7459. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7460. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7461. "0331 IOCB wake signaled\n");
  7462. } else if (timeleft == 0) {
  7463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7464. "0338 IOCB wait timeout error - no "
  7465. "wake response Data x%x\n", timeout);
  7466. retval = IOCB_TIMEDOUT;
  7467. } else {
  7468. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7469. "0330 IOCB wake NOT set, "
  7470. "Data x%x x%lx\n",
  7471. timeout, (timeleft / jiffies));
  7472. retval = IOCB_TIMEDOUT;
  7473. }
  7474. } else if (retval == IOCB_BUSY) {
  7475. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7476. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7477. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7478. return retval;
  7479. } else {
  7480. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7481. "0332 IOCB wait issue failed, Data x%x\n",
  7482. retval);
  7483. retval = IOCB_ERROR;
  7484. }
  7485. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7486. creg_val = readl(phba->HCregaddr);
  7487. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7488. writel(creg_val, phba->HCregaddr);
  7489. readl(phba->HCregaddr); /* flush */
  7490. }
  7491. if (prspiocbq)
  7492. piocb->context2 = NULL;
  7493. piocb->context_un.wait_queue = NULL;
  7494. piocb->iocb_cmpl = NULL;
  7495. return retval;
  7496. }
  7497. /**
  7498. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7499. * @phba: Pointer to HBA context object.
  7500. * @pmboxq: Pointer to driver mailbox object.
  7501. * @timeout: Timeout in number of seconds.
  7502. *
  7503. * This function issues the mailbox to firmware and waits for the
  7504. * mailbox command to complete. If the mailbox command is not
  7505. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7506. * The function waits for the mailbox completion using an
  7507. * interruptible wait. If the thread is woken up due to a
  7508. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7509. * should not free the mailbox resources, if this function returns
  7510. * MBX_TIMEOUT.
  7511. * This function will sleep while waiting for mailbox completion.
  7512. * So, this function should not be called from any context which
  7513. * does not allow sleeping. Due to the same reason, this function
  7514. * cannot be called with interrupt disabled.
  7515. * This function assumes that the mailbox completion occurs while
  7516. * this function sleep. So, this function cannot be called from
  7517. * the worker thread which processes mailbox completion.
  7518. * This function is called in the context of HBA management
  7519. * applications.
  7520. * This function returns MBX_SUCCESS when successful.
  7521. * This function is called with no lock held.
  7522. **/
  7523. int
  7524. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7525. uint32_t timeout)
  7526. {
  7527. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7528. int retval;
  7529. unsigned long flag;
  7530. /* The caller must leave context1 empty. */
  7531. if (pmboxq->context1)
  7532. return MBX_NOT_FINISHED;
  7533. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7534. /* setup wake call as IOCB callback */
  7535. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7536. /* setup context field to pass wait_queue pointer to wake function */
  7537. pmboxq->context1 = &done_q;
  7538. /* now issue the command */
  7539. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7540. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7541. wait_event_interruptible_timeout(done_q,
  7542. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7543. timeout * HZ);
  7544. spin_lock_irqsave(&phba->hbalock, flag);
  7545. pmboxq->context1 = NULL;
  7546. /*
  7547. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7548. * else do not free the resources.
  7549. */
  7550. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7551. retval = MBX_SUCCESS;
  7552. lpfc_sli4_swap_str(phba, pmboxq);
  7553. } else {
  7554. retval = MBX_TIMEOUT;
  7555. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7556. }
  7557. spin_unlock_irqrestore(&phba->hbalock, flag);
  7558. }
  7559. return retval;
  7560. }
  7561. /**
  7562. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7563. * @phba: Pointer to HBA context.
  7564. *
  7565. * This function is called to shutdown the driver's mailbox sub-system.
  7566. * It first marks the mailbox sub-system is in a block state to prevent
  7567. * the asynchronous mailbox command from issued off the pending mailbox
  7568. * command queue. If the mailbox command sub-system shutdown is due to
  7569. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7570. * the mailbox sub-system flush routine to forcefully bring down the
  7571. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7572. * as with offline or HBA function reset), this routine will wait for the
  7573. * outstanding mailbox command to complete before invoking the mailbox
  7574. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7575. **/
  7576. void
  7577. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7578. {
  7579. struct lpfc_sli *psli = &phba->sli;
  7580. uint8_t actcmd = MBX_HEARTBEAT;
  7581. unsigned long timeout;
  7582. spin_lock_irq(&phba->hbalock);
  7583. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7584. spin_unlock_irq(&phba->hbalock);
  7585. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7586. spin_lock_irq(&phba->hbalock);
  7587. if (phba->sli.mbox_active)
  7588. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7589. spin_unlock_irq(&phba->hbalock);
  7590. /* Determine how long we might wait for the active mailbox
  7591. * command to be gracefully completed by firmware.
  7592. */
  7593. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7594. 1000) + jiffies;
  7595. while (phba->sli.mbox_active) {
  7596. /* Check active mailbox complete status every 2ms */
  7597. msleep(2);
  7598. if (time_after(jiffies, timeout))
  7599. /* Timeout, let the mailbox flush routine to
  7600. * forcefully release active mailbox command
  7601. */
  7602. break;
  7603. }
  7604. }
  7605. lpfc_sli_mbox_sys_flush(phba);
  7606. }
  7607. /**
  7608. * lpfc_sli_eratt_read - read sli-3 error attention events
  7609. * @phba: Pointer to HBA context.
  7610. *
  7611. * This function is called to read the SLI3 device error attention registers
  7612. * for possible error attention events. The caller must hold the hostlock
  7613. * with spin_lock_irq().
  7614. *
  7615. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7616. * Register and returns 0 otherwise.
  7617. **/
  7618. static int
  7619. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7620. {
  7621. uint32_t ha_copy;
  7622. /* Read chip Host Attention (HA) register */
  7623. ha_copy = readl(phba->HAregaddr);
  7624. if (ha_copy & HA_ERATT) {
  7625. /* Read host status register to retrieve error event */
  7626. lpfc_sli_read_hs(phba);
  7627. /* Check if there is a deferred error condition is active */
  7628. if ((HS_FFER1 & phba->work_hs) &&
  7629. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7630. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7631. phba->hba_flag |= DEFER_ERATT;
  7632. /* Clear all interrupt enable conditions */
  7633. writel(0, phba->HCregaddr);
  7634. readl(phba->HCregaddr);
  7635. }
  7636. /* Set the driver HA work bitmap */
  7637. phba->work_ha |= HA_ERATT;
  7638. /* Indicate polling handles this ERATT */
  7639. phba->hba_flag |= HBA_ERATT_HANDLED;
  7640. return 1;
  7641. }
  7642. return 0;
  7643. }
  7644. /**
  7645. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7646. * @phba: Pointer to HBA context.
  7647. *
  7648. * This function is called to read the SLI4 device error attention registers
  7649. * for possible error attention events. The caller must hold the hostlock
  7650. * with spin_lock_irq().
  7651. *
  7652. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7653. * Register and returns 0 otherwise.
  7654. **/
  7655. static int
  7656. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7657. {
  7658. uint32_t uerr_sta_hi, uerr_sta_lo;
  7659. uint32_t if_type, portsmphr;
  7660. struct lpfc_register portstat_reg;
  7661. /*
  7662. * For now, use the SLI4 device internal unrecoverable error
  7663. * registers for error attention. This can be changed later.
  7664. */
  7665. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7666. switch (if_type) {
  7667. case LPFC_SLI_INTF_IF_TYPE_0:
  7668. uerr_sta_lo = readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  7669. uerr_sta_hi = readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  7670. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7671. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7672. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7673. "1423 HBA Unrecoverable error: "
  7674. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7675. "ue_mask_lo_reg=0x%x, "
  7676. "ue_mask_hi_reg=0x%x\n",
  7677. uerr_sta_lo, uerr_sta_hi,
  7678. phba->sli4_hba.ue_mask_lo,
  7679. phba->sli4_hba.ue_mask_hi);
  7680. phba->work_status[0] = uerr_sta_lo;
  7681. phba->work_status[1] = uerr_sta_hi;
  7682. phba->work_ha |= HA_ERATT;
  7683. phba->hba_flag |= HBA_ERATT_HANDLED;
  7684. return 1;
  7685. }
  7686. break;
  7687. case LPFC_SLI_INTF_IF_TYPE_2:
  7688. portstat_reg.word0 =
  7689. readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
  7690. portsmphr = readl(phba->sli4_hba.PSMPHRregaddr);
  7691. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  7692. phba->work_status[0] =
  7693. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  7694. phba->work_status[1] =
  7695. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  7696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7697. "2885 Port Error Detected: "
  7698. "port status reg 0x%x, "
  7699. "port smphr reg 0x%x, "
  7700. "error 1=0x%x, error 2=0x%x\n",
  7701. portstat_reg.word0,
  7702. portsmphr,
  7703. phba->work_status[0],
  7704. phba->work_status[1]);
  7705. phba->work_ha |= HA_ERATT;
  7706. phba->hba_flag |= HBA_ERATT_HANDLED;
  7707. return 1;
  7708. }
  7709. break;
  7710. case LPFC_SLI_INTF_IF_TYPE_1:
  7711. default:
  7712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7713. "2886 HBA Error Attention on unsupported "
  7714. "if type %d.", if_type);
  7715. return 1;
  7716. }
  7717. return 0;
  7718. }
  7719. /**
  7720. * lpfc_sli_check_eratt - check error attention events
  7721. * @phba: Pointer to HBA context.
  7722. *
  7723. * This function is called from timer soft interrupt context to check HBA's
  7724. * error attention register bit for error attention events.
  7725. *
  7726. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7727. * Register and returns 0 otherwise.
  7728. **/
  7729. int
  7730. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7731. {
  7732. uint32_t ha_copy;
  7733. /* If somebody is waiting to handle an eratt, don't process it
  7734. * here. The brdkill function will do this.
  7735. */
  7736. if (phba->link_flag & LS_IGNORE_ERATT)
  7737. return 0;
  7738. /* Check if interrupt handler handles this ERATT */
  7739. spin_lock_irq(&phba->hbalock);
  7740. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7741. /* Interrupt handler has handled ERATT */
  7742. spin_unlock_irq(&phba->hbalock);
  7743. return 0;
  7744. }
  7745. /*
  7746. * If there is deferred error attention, do not check for error
  7747. * attention
  7748. */
  7749. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7750. spin_unlock_irq(&phba->hbalock);
  7751. return 0;
  7752. }
  7753. /* If PCI channel is offline, don't process it */
  7754. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7755. spin_unlock_irq(&phba->hbalock);
  7756. return 0;
  7757. }
  7758. switch (phba->sli_rev) {
  7759. case LPFC_SLI_REV2:
  7760. case LPFC_SLI_REV3:
  7761. /* Read chip Host Attention (HA) register */
  7762. ha_copy = lpfc_sli_eratt_read(phba);
  7763. break;
  7764. case LPFC_SLI_REV4:
  7765. /* Read device Uncoverable Error (UERR) registers */
  7766. ha_copy = lpfc_sli4_eratt_read(phba);
  7767. break;
  7768. default:
  7769. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7770. "0299 Invalid SLI revision (%d)\n",
  7771. phba->sli_rev);
  7772. ha_copy = 0;
  7773. break;
  7774. }
  7775. spin_unlock_irq(&phba->hbalock);
  7776. return ha_copy;
  7777. }
  7778. /**
  7779. * lpfc_intr_state_check - Check device state for interrupt handling
  7780. * @phba: Pointer to HBA context.
  7781. *
  7782. * This inline routine checks whether a device or its PCI slot is in a state
  7783. * that the interrupt should be handled.
  7784. *
  7785. * This function returns 0 if the device or the PCI slot is in a state that
  7786. * interrupt should be handled, otherwise -EIO.
  7787. */
  7788. static inline int
  7789. lpfc_intr_state_check(struct lpfc_hba *phba)
  7790. {
  7791. /* If the pci channel is offline, ignore all the interrupts */
  7792. if (unlikely(pci_channel_offline(phba->pcidev)))
  7793. return -EIO;
  7794. /* Update device level interrupt statistics */
  7795. phba->sli.slistat.sli_intr++;
  7796. /* Ignore all interrupts during initialization. */
  7797. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7798. return -EIO;
  7799. return 0;
  7800. }
  7801. /**
  7802. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7803. * @irq: Interrupt number.
  7804. * @dev_id: The device context pointer.
  7805. *
  7806. * This function is directly called from the PCI layer as an interrupt
  7807. * service routine when device with SLI-3 interface spec is enabled with
  7808. * MSI-X multi-message interrupt mode and there are slow-path events in
  7809. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7810. * interrupt mode, this function is called as part of the device-level
  7811. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7812. * is undergoing initialization, the interrupt handler will not process
  7813. * the interrupt. The link attention and ELS ring attention events are
  7814. * handled by the worker thread. The interrupt handler signals the worker
  7815. * thread and returns for these events. This function is called without
  7816. * any lock held. It gets the hbalock to access and update SLI data
  7817. * structures.
  7818. *
  7819. * This function returns IRQ_HANDLED when interrupt is handled else it
  7820. * returns IRQ_NONE.
  7821. **/
  7822. irqreturn_t
  7823. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7824. {
  7825. struct lpfc_hba *phba;
  7826. uint32_t ha_copy, hc_copy;
  7827. uint32_t work_ha_copy;
  7828. unsigned long status;
  7829. unsigned long iflag;
  7830. uint32_t control;
  7831. MAILBOX_t *mbox, *pmbox;
  7832. struct lpfc_vport *vport;
  7833. struct lpfc_nodelist *ndlp;
  7834. struct lpfc_dmabuf *mp;
  7835. LPFC_MBOXQ_t *pmb;
  7836. int rc;
  7837. /*
  7838. * Get the driver's phba structure from the dev_id and
  7839. * assume the HBA is not interrupting.
  7840. */
  7841. phba = (struct lpfc_hba *)dev_id;
  7842. if (unlikely(!phba))
  7843. return IRQ_NONE;
  7844. /*
  7845. * Stuff needs to be attented to when this function is invoked as an
  7846. * individual interrupt handler in MSI-X multi-message interrupt mode
  7847. */
  7848. if (phba->intr_type == MSIX) {
  7849. /* Check device state for handling interrupt */
  7850. if (lpfc_intr_state_check(phba))
  7851. return IRQ_NONE;
  7852. /* Need to read HA REG for slow-path events */
  7853. spin_lock_irqsave(&phba->hbalock, iflag);
  7854. ha_copy = readl(phba->HAregaddr);
  7855. /* If somebody is waiting to handle an eratt don't process it
  7856. * here. The brdkill function will do this.
  7857. */
  7858. if (phba->link_flag & LS_IGNORE_ERATT)
  7859. ha_copy &= ~HA_ERATT;
  7860. /* Check the need for handling ERATT in interrupt handler */
  7861. if (ha_copy & HA_ERATT) {
  7862. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7863. /* ERATT polling has handled ERATT */
  7864. ha_copy &= ~HA_ERATT;
  7865. else
  7866. /* Indicate interrupt handler handles ERATT */
  7867. phba->hba_flag |= HBA_ERATT_HANDLED;
  7868. }
  7869. /*
  7870. * If there is deferred error attention, do not check for any
  7871. * interrupt.
  7872. */
  7873. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7874. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7875. return IRQ_NONE;
  7876. }
  7877. /* Clear up only attention source related to slow-path */
  7878. hc_copy = readl(phba->HCregaddr);
  7879. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7880. HC_LAINT_ENA | HC_ERINT_ENA),
  7881. phba->HCregaddr);
  7882. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7883. phba->HAregaddr);
  7884. writel(hc_copy, phba->HCregaddr);
  7885. readl(phba->HAregaddr); /* flush */
  7886. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7887. } else
  7888. ha_copy = phba->ha_copy;
  7889. work_ha_copy = ha_copy & phba->work_ha_mask;
  7890. if (work_ha_copy) {
  7891. if (work_ha_copy & HA_LATT) {
  7892. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7893. /*
  7894. * Turn off Link Attention interrupts
  7895. * until CLEAR_LA done
  7896. */
  7897. spin_lock_irqsave(&phba->hbalock, iflag);
  7898. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7899. control = readl(phba->HCregaddr);
  7900. control &= ~HC_LAINT_ENA;
  7901. writel(control, phba->HCregaddr);
  7902. readl(phba->HCregaddr); /* flush */
  7903. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7904. }
  7905. else
  7906. work_ha_copy &= ~HA_LATT;
  7907. }
  7908. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7909. /*
  7910. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7911. * the only slow ring.
  7912. */
  7913. status = (work_ha_copy &
  7914. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7915. status >>= (4*LPFC_ELS_RING);
  7916. if (status & HA_RXMASK) {
  7917. spin_lock_irqsave(&phba->hbalock, iflag);
  7918. control = readl(phba->HCregaddr);
  7919. lpfc_debugfs_slow_ring_trc(phba,
  7920. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7921. control, status,
  7922. (uint32_t)phba->sli.slistat.sli_intr);
  7923. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7924. lpfc_debugfs_slow_ring_trc(phba,
  7925. "ISR Disable ring:"
  7926. "pwork:x%x hawork:x%x wait:x%x",
  7927. phba->work_ha, work_ha_copy,
  7928. (uint32_t)((unsigned long)
  7929. &phba->work_waitq));
  7930. control &=
  7931. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7932. writel(control, phba->HCregaddr);
  7933. readl(phba->HCregaddr); /* flush */
  7934. }
  7935. else {
  7936. lpfc_debugfs_slow_ring_trc(phba,
  7937. "ISR slow ring: pwork:"
  7938. "x%x hawork:x%x wait:x%x",
  7939. phba->work_ha, work_ha_copy,
  7940. (uint32_t)((unsigned long)
  7941. &phba->work_waitq));
  7942. }
  7943. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7944. }
  7945. }
  7946. spin_lock_irqsave(&phba->hbalock, iflag);
  7947. if (work_ha_copy & HA_ERATT) {
  7948. lpfc_sli_read_hs(phba);
  7949. /*
  7950. * Check if there is a deferred error condition
  7951. * is active
  7952. */
  7953. if ((HS_FFER1 & phba->work_hs) &&
  7954. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7955. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  7956. phba->work_hs)) {
  7957. phba->hba_flag |= DEFER_ERATT;
  7958. /* Clear all interrupt enable conditions */
  7959. writel(0, phba->HCregaddr);
  7960. readl(phba->HCregaddr);
  7961. }
  7962. }
  7963. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7964. pmb = phba->sli.mbox_active;
  7965. pmbox = &pmb->u.mb;
  7966. mbox = phba->mbox;
  7967. vport = pmb->vport;
  7968. /* First check out the status word */
  7969. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7970. if (pmbox->mbxOwner != OWN_HOST) {
  7971. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7972. /*
  7973. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7974. * mbxStatus <status>
  7975. */
  7976. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7977. LOG_SLI,
  7978. "(%d):0304 Stray Mailbox "
  7979. "Interrupt mbxCommand x%x "
  7980. "mbxStatus x%x\n",
  7981. (vport ? vport->vpi : 0),
  7982. pmbox->mbxCommand,
  7983. pmbox->mbxStatus);
  7984. /* clear mailbox attention bit */
  7985. work_ha_copy &= ~HA_MBATT;
  7986. } else {
  7987. phba->sli.mbox_active = NULL;
  7988. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7989. phba->last_completion_time = jiffies;
  7990. del_timer(&phba->sli.mbox_tmo);
  7991. if (pmb->mbox_cmpl) {
  7992. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7993. MAILBOX_CMD_SIZE);
  7994. if (pmb->out_ext_byte_len &&
  7995. pmb->context2)
  7996. lpfc_sli_pcimem_bcopy(
  7997. phba->mbox_ext,
  7998. pmb->context2,
  7999. pmb->out_ext_byte_len);
  8000. }
  8001. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8002. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8003. lpfc_debugfs_disc_trc(vport,
  8004. LPFC_DISC_TRC_MBOX_VPORT,
  8005. "MBOX dflt rpi: : "
  8006. "status:x%x rpi:x%x",
  8007. (uint32_t)pmbox->mbxStatus,
  8008. pmbox->un.varWords[0], 0);
  8009. if (!pmbox->mbxStatus) {
  8010. mp = (struct lpfc_dmabuf *)
  8011. (pmb->context1);
  8012. ndlp = (struct lpfc_nodelist *)
  8013. pmb->context2;
  8014. /* Reg_LOGIN of dflt RPI was
  8015. * successful. new lets get
  8016. * rid of the RPI using the
  8017. * same mbox buffer.
  8018. */
  8019. lpfc_unreg_login(phba,
  8020. vport->vpi,
  8021. pmbox->un.varWords[0],
  8022. pmb);
  8023. pmb->mbox_cmpl =
  8024. lpfc_mbx_cmpl_dflt_rpi;
  8025. pmb->context1 = mp;
  8026. pmb->context2 = ndlp;
  8027. pmb->vport = vport;
  8028. rc = lpfc_sli_issue_mbox(phba,
  8029. pmb,
  8030. MBX_NOWAIT);
  8031. if (rc != MBX_BUSY)
  8032. lpfc_printf_log(phba,
  8033. KERN_ERR,
  8034. LOG_MBOX | LOG_SLI,
  8035. "0350 rc should have"
  8036. "been MBX_BUSY\n");
  8037. if (rc != MBX_NOT_FINISHED)
  8038. goto send_current_mbox;
  8039. }
  8040. }
  8041. spin_lock_irqsave(
  8042. &phba->pport->work_port_lock,
  8043. iflag);
  8044. phba->pport->work_port_events &=
  8045. ~WORKER_MBOX_TMO;
  8046. spin_unlock_irqrestore(
  8047. &phba->pport->work_port_lock,
  8048. iflag);
  8049. lpfc_mbox_cmpl_put(phba, pmb);
  8050. }
  8051. } else
  8052. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8053. if ((work_ha_copy & HA_MBATT) &&
  8054. (phba->sli.mbox_active == NULL)) {
  8055. send_current_mbox:
  8056. /* Process next mailbox command if there is one */
  8057. do {
  8058. rc = lpfc_sli_issue_mbox(phba, NULL,
  8059. MBX_NOWAIT);
  8060. } while (rc == MBX_NOT_FINISHED);
  8061. if (rc != MBX_SUCCESS)
  8062. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8063. LOG_SLI, "0349 rc should be "
  8064. "MBX_SUCCESS\n");
  8065. }
  8066. spin_lock_irqsave(&phba->hbalock, iflag);
  8067. phba->work_ha |= work_ha_copy;
  8068. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8069. lpfc_worker_wake_up(phba);
  8070. }
  8071. return IRQ_HANDLED;
  8072. } /* lpfc_sli_sp_intr_handler */
  8073. /**
  8074. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8075. * @irq: Interrupt number.
  8076. * @dev_id: The device context pointer.
  8077. *
  8078. * This function is directly called from the PCI layer as an interrupt
  8079. * service routine when device with SLI-3 interface spec is enabled with
  8080. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8081. * ring event in the HBA. However, when the device is enabled with either
  8082. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8083. * device-level interrupt handler. When the PCI slot is in error recovery
  8084. * or the HBA is undergoing initialization, the interrupt handler will not
  8085. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8086. * the intrrupt context. This function is called without any lock held.
  8087. * It gets the hbalock to access and update SLI data structures.
  8088. *
  8089. * This function returns IRQ_HANDLED when interrupt is handled else it
  8090. * returns IRQ_NONE.
  8091. **/
  8092. irqreturn_t
  8093. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8094. {
  8095. struct lpfc_hba *phba;
  8096. uint32_t ha_copy;
  8097. unsigned long status;
  8098. unsigned long iflag;
  8099. /* Get the driver's phba structure from the dev_id and
  8100. * assume the HBA is not interrupting.
  8101. */
  8102. phba = (struct lpfc_hba *) dev_id;
  8103. if (unlikely(!phba))
  8104. return IRQ_NONE;
  8105. /*
  8106. * Stuff needs to be attented to when this function is invoked as an
  8107. * individual interrupt handler in MSI-X multi-message interrupt mode
  8108. */
  8109. if (phba->intr_type == MSIX) {
  8110. /* Check device state for handling interrupt */
  8111. if (lpfc_intr_state_check(phba))
  8112. return IRQ_NONE;
  8113. /* Need to read HA REG for FCP ring and other ring events */
  8114. ha_copy = readl(phba->HAregaddr);
  8115. /* Clear up only attention source related to fast-path */
  8116. spin_lock_irqsave(&phba->hbalock, iflag);
  8117. /*
  8118. * If there is deferred error attention, do not check for
  8119. * any interrupt.
  8120. */
  8121. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8122. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8123. return IRQ_NONE;
  8124. }
  8125. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8126. phba->HAregaddr);
  8127. readl(phba->HAregaddr); /* flush */
  8128. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8129. } else
  8130. ha_copy = phba->ha_copy;
  8131. /*
  8132. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8133. */
  8134. ha_copy &= ~(phba->work_ha_mask);
  8135. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8136. status >>= (4*LPFC_FCP_RING);
  8137. if (status & HA_RXMASK)
  8138. lpfc_sli_handle_fast_ring_event(phba,
  8139. &phba->sli.ring[LPFC_FCP_RING],
  8140. status);
  8141. if (phba->cfg_multi_ring_support == 2) {
  8142. /*
  8143. * Process all events on extra ring. Take the optimized path
  8144. * for extra ring IO.
  8145. */
  8146. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8147. status >>= (4*LPFC_EXTRA_RING);
  8148. if (status & HA_RXMASK) {
  8149. lpfc_sli_handle_fast_ring_event(phba,
  8150. &phba->sli.ring[LPFC_EXTRA_RING],
  8151. status);
  8152. }
  8153. }
  8154. return IRQ_HANDLED;
  8155. } /* lpfc_sli_fp_intr_handler */
  8156. /**
  8157. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8158. * @irq: Interrupt number.
  8159. * @dev_id: The device context pointer.
  8160. *
  8161. * This function is the HBA device-level interrupt handler to device with
  8162. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8163. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8164. * requires driver attention. This function invokes the slow-path interrupt
  8165. * attention handling function and fast-path interrupt attention handling
  8166. * function in turn to process the relevant HBA attention events. This
  8167. * function is called without any lock held. It gets the hbalock to access
  8168. * and update SLI data structures.
  8169. *
  8170. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8171. * returns IRQ_NONE.
  8172. **/
  8173. irqreturn_t
  8174. lpfc_sli_intr_handler(int irq, void *dev_id)
  8175. {
  8176. struct lpfc_hba *phba;
  8177. irqreturn_t sp_irq_rc, fp_irq_rc;
  8178. unsigned long status1, status2;
  8179. uint32_t hc_copy;
  8180. /*
  8181. * Get the driver's phba structure from the dev_id and
  8182. * assume the HBA is not interrupting.
  8183. */
  8184. phba = (struct lpfc_hba *) dev_id;
  8185. if (unlikely(!phba))
  8186. return IRQ_NONE;
  8187. /* Check device state for handling interrupt */
  8188. if (lpfc_intr_state_check(phba))
  8189. return IRQ_NONE;
  8190. spin_lock(&phba->hbalock);
  8191. phba->ha_copy = readl(phba->HAregaddr);
  8192. if (unlikely(!phba->ha_copy)) {
  8193. spin_unlock(&phba->hbalock);
  8194. return IRQ_NONE;
  8195. } else if (phba->ha_copy & HA_ERATT) {
  8196. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8197. /* ERATT polling has handled ERATT */
  8198. phba->ha_copy &= ~HA_ERATT;
  8199. else
  8200. /* Indicate interrupt handler handles ERATT */
  8201. phba->hba_flag |= HBA_ERATT_HANDLED;
  8202. }
  8203. /*
  8204. * If there is deferred error attention, do not check for any interrupt.
  8205. */
  8206. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8207. spin_unlock(&phba->hbalock);
  8208. return IRQ_NONE;
  8209. }
  8210. /* Clear attention sources except link and error attentions */
  8211. hc_copy = readl(phba->HCregaddr);
  8212. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8213. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8214. phba->HCregaddr);
  8215. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8216. writel(hc_copy, phba->HCregaddr);
  8217. readl(phba->HAregaddr); /* flush */
  8218. spin_unlock(&phba->hbalock);
  8219. /*
  8220. * Invokes slow-path host attention interrupt handling as appropriate.
  8221. */
  8222. /* status of events with mailbox and link attention */
  8223. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8224. /* status of events with ELS ring */
  8225. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8226. status2 >>= (4*LPFC_ELS_RING);
  8227. if (status1 || (status2 & HA_RXMASK))
  8228. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8229. else
  8230. sp_irq_rc = IRQ_NONE;
  8231. /*
  8232. * Invoke fast-path host attention interrupt handling as appropriate.
  8233. */
  8234. /* status of events with FCP ring */
  8235. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8236. status1 >>= (4*LPFC_FCP_RING);
  8237. /* status of events with extra ring */
  8238. if (phba->cfg_multi_ring_support == 2) {
  8239. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8240. status2 >>= (4*LPFC_EXTRA_RING);
  8241. } else
  8242. status2 = 0;
  8243. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8244. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8245. else
  8246. fp_irq_rc = IRQ_NONE;
  8247. /* Return device-level interrupt handling status */
  8248. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8249. } /* lpfc_sli_intr_handler */
  8250. /**
  8251. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8252. * @phba: pointer to lpfc hba data structure.
  8253. *
  8254. * This routine is invoked by the worker thread to process all the pending
  8255. * SLI4 FCP abort XRI events.
  8256. **/
  8257. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8258. {
  8259. struct lpfc_cq_event *cq_event;
  8260. /* First, declare the fcp xri abort event has been handled */
  8261. spin_lock_irq(&phba->hbalock);
  8262. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8263. spin_unlock_irq(&phba->hbalock);
  8264. /* Now, handle all the fcp xri abort events */
  8265. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8266. /* Get the first event from the head of the event queue */
  8267. spin_lock_irq(&phba->hbalock);
  8268. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8269. cq_event, struct lpfc_cq_event, list);
  8270. spin_unlock_irq(&phba->hbalock);
  8271. /* Notify aborted XRI for FCP work queue */
  8272. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8273. /* Free the event processed back to the free pool */
  8274. lpfc_sli4_cq_event_release(phba, cq_event);
  8275. }
  8276. }
  8277. /**
  8278. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8279. * @phba: pointer to lpfc hba data structure.
  8280. *
  8281. * This routine is invoked by the worker thread to process all the pending
  8282. * SLI4 els abort xri events.
  8283. **/
  8284. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8285. {
  8286. struct lpfc_cq_event *cq_event;
  8287. /* First, declare the els xri abort event has been handled */
  8288. spin_lock_irq(&phba->hbalock);
  8289. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8290. spin_unlock_irq(&phba->hbalock);
  8291. /* Now, handle all the els xri abort events */
  8292. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8293. /* Get the first event from the head of the event queue */
  8294. spin_lock_irq(&phba->hbalock);
  8295. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8296. cq_event, struct lpfc_cq_event, list);
  8297. spin_unlock_irq(&phba->hbalock);
  8298. /* Notify aborted XRI for ELS work queue */
  8299. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8300. /* Free the event processed back to the free pool */
  8301. lpfc_sli4_cq_event_release(phba, cq_event);
  8302. }
  8303. }
  8304. /**
  8305. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8306. * @phba: pointer to lpfc hba data structure
  8307. * @pIocbIn: pointer to the rspiocbq
  8308. * @pIocbOut: pointer to the cmdiocbq
  8309. * @wcqe: pointer to the complete wcqe
  8310. *
  8311. * This routine transfers the fields of a command iocbq to a response iocbq
  8312. * by copying all the IOCB fields from command iocbq and transferring the
  8313. * completion status information from the complete wcqe.
  8314. **/
  8315. static void
  8316. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8317. struct lpfc_iocbq *pIocbIn,
  8318. struct lpfc_iocbq *pIocbOut,
  8319. struct lpfc_wcqe_complete *wcqe)
  8320. {
  8321. unsigned long iflags;
  8322. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8323. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8324. sizeof(struct lpfc_iocbq) - offset);
  8325. /* Map WCQE parameters into irspiocb parameters */
  8326. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8327. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8328. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8329. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8330. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8331. wcqe->total_data_placed;
  8332. else
  8333. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8334. else {
  8335. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8336. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8337. }
  8338. /* Pick up HBA exchange busy condition */
  8339. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8340. spin_lock_irqsave(&phba->hbalock, iflags);
  8341. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8342. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8343. }
  8344. }
  8345. /**
  8346. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8347. * @phba: Pointer to HBA context object.
  8348. * @wcqe: Pointer to work-queue completion queue entry.
  8349. *
  8350. * This routine handles an ELS work-queue completion event and construct
  8351. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8352. * discovery engine to handle.
  8353. *
  8354. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8355. **/
  8356. static struct lpfc_iocbq *
  8357. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8358. struct lpfc_iocbq *irspiocbq)
  8359. {
  8360. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8361. struct lpfc_iocbq *cmdiocbq;
  8362. struct lpfc_wcqe_complete *wcqe;
  8363. unsigned long iflags;
  8364. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8365. spin_lock_irqsave(&phba->hbalock, iflags);
  8366. pring->stats.iocb_event++;
  8367. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8368. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8369. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8370. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8371. if (unlikely(!cmdiocbq)) {
  8372. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8373. "0386 ELS complete with no corresponding "
  8374. "cmdiocb: iotag (%d)\n",
  8375. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8376. lpfc_sli_release_iocbq(phba, irspiocbq);
  8377. return NULL;
  8378. }
  8379. /* Fake the irspiocbq and copy necessary response information */
  8380. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8381. return irspiocbq;
  8382. }
  8383. /**
  8384. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8385. * @phba: Pointer to HBA context object.
  8386. * @cqe: Pointer to mailbox completion queue entry.
  8387. *
  8388. * This routine process a mailbox completion queue entry with asynchrous
  8389. * event.
  8390. *
  8391. * Return: true if work posted to worker thread, otherwise false.
  8392. **/
  8393. static bool
  8394. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8395. {
  8396. struct lpfc_cq_event *cq_event;
  8397. unsigned long iflags;
  8398. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8399. "0392 Async Event: word0:x%x, word1:x%x, "
  8400. "word2:x%x, word3:x%x\n", mcqe->word0,
  8401. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8402. /* Allocate a new internal CQ_EVENT entry */
  8403. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8404. if (!cq_event) {
  8405. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8406. "0394 Failed to allocate CQ_EVENT entry\n");
  8407. return false;
  8408. }
  8409. /* Move the CQE into an asynchronous event entry */
  8410. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8411. spin_lock_irqsave(&phba->hbalock, iflags);
  8412. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8413. /* Set the async event flag */
  8414. phba->hba_flag |= ASYNC_EVENT;
  8415. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8416. return true;
  8417. }
  8418. /**
  8419. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8420. * @phba: Pointer to HBA context object.
  8421. * @cqe: Pointer to mailbox completion queue entry.
  8422. *
  8423. * This routine process a mailbox completion queue entry with mailbox
  8424. * completion event.
  8425. *
  8426. * Return: true if work posted to worker thread, otherwise false.
  8427. **/
  8428. static bool
  8429. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8430. {
  8431. uint32_t mcqe_status;
  8432. MAILBOX_t *mbox, *pmbox;
  8433. struct lpfc_mqe *mqe;
  8434. struct lpfc_vport *vport;
  8435. struct lpfc_nodelist *ndlp;
  8436. struct lpfc_dmabuf *mp;
  8437. unsigned long iflags;
  8438. LPFC_MBOXQ_t *pmb;
  8439. bool workposted = false;
  8440. int rc;
  8441. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8442. if (!bf_get(lpfc_trailer_completed, mcqe))
  8443. goto out_no_mqe_complete;
  8444. /* Get the reference to the active mbox command */
  8445. spin_lock_irqsave(&phba->hbalock, iflags);
  8446. pmb = phba->sli.mbox_active;
  8447. if (unlikely(!pmb)) {
  8448. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8449. "1832 No pending MBOX command to handle\n");
  8450. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8451. goto out_no_mqe_complete;
  8452. }
  8453. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8454. mqe = &pmb->u.mqe;
  8455. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8456. mbox = phba->mbox;
  8457. vport = pmb->vport;
  8458. /* Reset heartbeat timer */
  8459. phba->last_completion_time = jiffies;
  8460. del_timer(&phba->sli.mbox_tmo);
  8461. /* Move mbox data to caller's mailbox region, do endian swapping */
  8462. if (pmb->mbox_cmpl && mbox)
  8463. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8464. /* Set the mailbox status with SLI4 range 0x4000 */
  8465. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8466. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8467. bf_set(lpfc_mqe_status, mqe,
  8468. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8469. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8470. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8471. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8472. "MBOX dflt rpi: status:x%x rpi:x%x",
  8473. mcqe_status,
  8474. pmbox->un.varWords[0], 0);
  8475. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8476. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8477. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8478. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8479. * RID of the PPI using the same mbox buffer.
  8480. */
  8481. lpfc_unreg_login(phba, vport->vpi,
  8482. pmbox->un.varWords[0], pmb);
  8483. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8484. pmb->context1 = mp;
  8485. pmb->context2 = ndlp;
  8486. pmb->vport = vport;
  8487. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8488. if (rc != MBX_BUSY)
  8489. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8490. LOG_SLI, "0385 rc should "
  8491. "have been MBX_BUSY\n");
  8492. if (rc != MBX_NOT_FINISHED)
  8493. goto send_current_mbox;
  8494. }
  8495. }
  8496. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8497. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8498. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8499. /* There is mailbox completion work to do */
  8500. spin_lock_irqsave(&phba->hbalock, iflags);
  8501. __lpfc_mbox_cmpl_put(phba, pmb);
  8502. phba->work_ha |= HA_MBATT;
  8503. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8504. workposted = true;
  8505. send_current_mbox:
  8506. spin_lock_irqsave(&phba->hbalock, iflags);
  8507. /* Release the mailbox command posting token */
  8508. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8509. /* Setting active mailbox pointer need to be in sync to flag clear */
  8510. phba->sli.mbox_active = NULL;
  8511. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8512. /* Wake up worker thread to post the next pending mailbox command */
  8513. lpfc_worker_wake_up(phba);
  8514. out_no_mqe_complete:
  8515. if (bf_get(lpfc_trailer_consumed, mcqe))
  8516. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8517. return workposted;
  8518. }
  8519. /**
  8520. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8521. * @phba: Pointer to HBA context object.
  8522. * @cqe: Pointer to mailbox completion queue entry.
  8523. *
  8524. * This routine process a mailbox completion queue entry, it invokes the
  8525. * proper mailbox complete handling or asynchrous event handling routine
  8526. * according to the MCQE's async bit.
  8527. *
  8528. * Return: true if work posted to worker thread, otherwise false.
  8529. **/
  8530. static bool
  8531. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8532. {
  8533. struct lpfc_mcqe mcqe;
  8534. bool workposted;
  8535. /* Copy the mailbox MCQE and convert endian order as needed */
  8536. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8537. /* Invoke the proper event handling routine */
  8538. if (!bf_get(lpfc_trailer_async, &mcqe))
  8539. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8540. else
  8541. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8542. return workposted;
  8543. }
  8544. /**
  8545. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8546. * @phba: Pointer to HBA context object.
  8547. * @wcqe: Pointer to work-queue completion queue entry.
  8548. *
  8549. * This routine handles an ELS work-queue completion event.
  8550. *
  8551. * Return: true if work posted to worker thread, otherwise false.
  8552. **/
  8553. static bool
  8554. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8555. struct lpfc_wcqe_complete *wcqe)
  8556. {
  8557. struct lpfc_iocbq *irspiocbq;
  8558. unsigned long iflags;
  8559. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8560. /* Get an irspiocbq for later ELS response processing use */
  8561. irspiocbq = lpfc_sli_get_iocbq(phba);
  8562. if (!irspiocbq) {
  8563. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8564. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8565. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8566. pring->txq_cnt, phba->iocb_cnt,
  8567. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8568. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8569. return false;
  8570. }
  8571. /* Save off the slow-path queue event for work thread to process */
  8572. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8573. spin_lock_irqsave(&phba->hbalock, iflags);
  8574. list_add_tail(&irspiocbq->cq_event.list,
  8575. &phba->sli4_hba.sp_queue_event);
  8576. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8577. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8578. return true;
  8579. }
  8580. /**
  8581. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8582. * @phba: Pointer to HBA context object.
  8583. * @wcqe: Pointer to work-queue completion queue entry.
  8584. *
  8585. * This routine handles slow-path WQ entry comsumed event by invoking the
  8586. * proper WQ release routine to the slow-path WQ.
  8587. **/
  8588. static void
  8589. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8590. struct lpfc_wcqe_release *wcqe)
  8591. {
  8592. /* Check for the slow-path ELS work queue */
  8593. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8594. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8595. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8596. else
  8597. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8598. "2579 Slow-path wqe consume event carries "
  8599. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8600. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8601. phba->sli4_hba.els_wq->queue_id);
  8602. }
  8603. /**
  8604. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8605. * @phba: Pointer to HBA context object.
  8606. * @cq: Pointer to a WQ completion queue.
  8607. * @wcqe: Pointer to work-queue completion queue entry.
  8608. *
  8609. * This routine handles an XRI abort event.
  8610. *
  8611. * Return: true if work posted to worker thread, otherwise false.
  8612. **/
  8613. static bool
  8614. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8615. struct lpfc_queue *cq,
  8616. struct sli4_wcqe_xri_aborted *wcqe)
  8617. {
  8618. bool workposted = false;
  8619. struct lpfc_cq_event *cq_event;
  8620. unsigned long iflags;
  8621. /* Allocate a new internal CQ_EVENT entry */
  8622. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8623. if (!cq_event) {
  8624. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8625. "0602 Failed to allocate CQ_EVENT entry\n");
  8626. return false;
  8627. }
  8628. /* Move the CQE into the proper xri abort event list */
  8629. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8630. switch (cq->subtype) {
  8631. case LPFC_FCP:
  8632. spin_lock_irqsave(&phba->hbalock, iflags);
  8633. list_add_tail(&cq_event->list,
  8634. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8635. /* Set the fcp xri abort event flag */
  8636. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8637. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8638. workposted = true;
  8639. break;
  8640. case LPFC_ELS:
  8641. spin_lock_irqsave(&phba->hbalock, iflags);
  8642. list_add_tail(&cq_event->list,
  8643. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8644. /* Set the els xri abort event flag */
  8645. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8647. workposted = true;
  8648. break;
  8649. default:
  8650. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8651. "0603 Invalid work queue CQE subtype (x%x)\n",
  8652. cq->subtype);
  8653. workposted = false;
  8654. break;
  8655. }
  8656. return workposted;
  8657. }
  8658. /**
  8659. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8660. * @phba: Pointer to HBA context object.
  8661. * @rcqe: Pointer to receive-queue completion queue entry.
  8662. *
  8663. * This routine process a receive-queue completion queue entry.
  8664. *
  8665. * Return: true if work posted to worker thread, otherwise false.
  8666. **/
  8667. static bool
  8668. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8669. {
  8670. bool workposted = false;
  8671. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8672. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8673. struct hbq_dmabuf *dma_buf;
  8674. uint32_t status;
  8675. unsigned long iflags;
  8676. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8677. goto out;
  8678. status = bf_get(lpfc_rcqe_status, rcqe);
  8679. switch (status) {
  8680. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8681. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8682. "2537 Receive Frame Truncated!!\n");
  8683. case FC_STATUS_RQ_SUCCESS:
  8684. lpfc_sli4_rq_release(hrq, drq);
  8685. spin_lock_irqsave(&phba->hbalock, iflags);
  8686. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8687. if (!dma_buf) {
  8688. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8689. goto out;
  8690. }
  8691. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8692. /* save off the frame for the word thread to process */
  8693. list_add_tail(&dma_buf->cq_event.list,
  8694. &phba->sli4_hba.sp_queue_event);
  8695. /* Frame received */
  8696. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8697. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8698. workposted = true;
  8699. break;
  8700. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8701. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8702. /* Post more buffers if possible */
  8703. spin_lock_irqsave(&phba->hbalock, iflags);
  8704. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8705. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8706. workposted = true;
  8707. break;
  8708. }
  8709. out:
  8710. return workposted;
  8711. }
  8712. /**
  8713. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8714. * @phba: Pointer to HBA context object.
  8715. * @cq: Pointer to the completion queue.
  8716. * @wcqe: Pointer to a completion queue entry.
  8717. *
  8718. * This routine process a slow-path work-queue or recieve queue completion queue
  8719. * entry.
  8720. *
  8721. * Return: true if work posted to worker thread, otherwise false.
  8722. **/
  8723. static bool
  8724. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8725. struct lpfc_cqe *cqe)
  8726. {
  8727. struct lpfc_cqe cqevt;
  8728. bool workposted = false;
  8729. /* Copy the work queue CQE and convert endian order if needed */
  8730. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8731. /* Check and process for different type of WCQE and dispatch */
  8732. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8733. case CQE_CODE_COMPL_WQE:
  8734. /* Process the WQ/RQ complete event */
  8735. phba->last_completion_time = jiffies;
  8736. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8737. (struct lpfc_wcqe_complete *)&cqevt);
  8738. break;
  8739. case CQE_CODE_RELEASE_WQE:
  8740. /* Process the WQ release event */
  8741. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8742. (struct lpfc_wcqe_release *)&cqevt);
  8743. break;
  8744. case CQE_CODE_XRI_ABORTED:
  8745. /* Process the WQ XRI abort event */
  8746. phba->last_completion_time = jiffies;
  8747. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8748. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8749. break;
  8750. case CQE_CODE_RECEIVE:
  8751. /* Process the RQ event */
  8752. phba->last_completion_time = jiffies;
  8753. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8754. (struct lpfc_rcqe *)&cqevt);
  8755. break;
  8756. default:
  8757. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8758. "0388 Not a valid WCQE code: x%x\n",
  8759. bf_get(lpfc_cqe_code, &cqevt));
  8760. break;
  8761. }
  8762. return workposted;
  8763. }
  8764. /**
  8765. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8766. * @phba: Pointer to HBA context object.
  8767. * @eqe: Pointer to fast-path event queue entry.
  8768. *
  8769. * This routine process a event queue entry from the slow-path event queue.
  8770. * It will check the MajorCode and MinorCode to determine this is for a
  8771. * completion event on a completion queue, if not, an error shall be logged
  8772. * and just return. Otherwise, it will get to the corresponding completion
  8773. * queue and process all the entries on that completion queue, rearm the
  8774. * completion queue, and then return.
  8775. *
  8776. **/
  8777. static void
  8778. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8779. {
  8780. struct lpfc_queue *cq = NULL, *childq, *speq;
  8781. struct lpfc_cqe *cqe;
  8782. bool workposted = false;
  8783. int ecount = 0;
  8784. uint16_t cqid;
  8785. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8787. "0359 Not a valid slow-path completion "
  8788. "event: majorcode=x%x, minorcode=x%x\n",
  8789. bf_get_le32(lpfc_eqe_major_code, eqe),
  8790. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8791. return;
  8792. }
  8793. /* Get the reference to the corresponding CQ */
  8794. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8795. /* Search for completion queue pointer matching this cqid */
  8796. speq = phba->sli4_hba.sp_eq;
  8797. list_for_each_entry(childq, &speq->child_list, list) {
  8798. if (childq->queue_id == cqid) {
  8799. cq = childq;
  8800. break;
  8801. }
  8802. }
  8803. if (unlikely(!cq)) {
  8804. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8805. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8806. "0365 Slow-path CQ identifier "
  8807. "(%d) does not exist\n", cqid);
  8808. return;
  8809. }
  8810. /* Process all the entries to the CQ */
  8811. switch (cq->type) {
  8812. case LPFC_MCQ:
  8813. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8814. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8815. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8816. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8817. }
  8818. break;
  8819. case LPFC_WCQ:
  8820. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8821. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8822. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8823. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8824. }
  8825. break;
  8826. default:
  8827. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8828. "0370 Invalid completion queue type (%d)\n",
  8829. cq->type);
  8830. return;
  8831. }
  8832. /* Catch the no cq entry condition, log an error */
  8833. if (unlikely(ecount == 0))
  8834. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8835. "0371 No entry from the CQ: identifier "
  8836. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8837. /* In any case, flash and re-arm the RCQ */
  8838. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8839. /* wake up worker thread if there are works to be done */
  8840. if (workposted)
  8841. lpfc_worker_wake_up(phba);
  8842. }
  8843. /**
  8844. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8845. * @eqe: Pointer to fast-path completion queue entry.
  8846. *
  8847. * This routine process a fast-path work queue completion entry from fast-path
  8848. * event queue for FCP command response completion.
  8849. **/
  8850. static void
  8851. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8852. struct lpfc_wcqe_complete *wcqe)
  8853. {
  8854. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8855. struct lpfc_iocbq *cmdiocbq;
  8856. struct lpfc_iocbq irspiocbq;
  8857. unsigned long iflags;
  8858. spin_lock_irqsave(&phba->hbalock, iflags);
  8859. pring->stats.iocb_event++;
  8860. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8861. /* Check for response status */
  8862. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8863. /* If resource errors reported from HBA, reduce queue
  8864. * depth of the SCSI device.
  8865. */
  8866. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8867. IOSTAT_LOCAL_REJECT) &&
  8868. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8869. phba->lpfc_rampdown_queue_depth(phba);
  8870. }
  8871. /* Log the error status */
  8872. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8873. "0373 FCP complete error: status=x%x, "
  8874. "hw_status=x%x, total_data_specified=%d, "
  8875. "parameter=x%x, word3=x%x\n",
  8876. bf_get(lpfc_wcqe_c_status, wcqe),
  8877. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8878. wcqe->total_data_placed, wcqe->parameter,
  8879. wcqe->word3);
  8880. }
  8881. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8882. spin_lock_irqsave(&phba->hbalock, iflags);
  8883. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8884. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8885. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8886. if (unlikely(!cmdiocbq)) {
  8887. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8888. "0374 FCP complete with no corresponding "
  8889. "cmdiocb: iotag (%d)\n",
  8890. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8891. return;
  8892. }
  8893. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8894. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8895. "0375 FCP cmdiocb not callback function "
  8896. "iotag: (%d)\n",
  8897. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8898. return;
  8899. }
  8900. /* Fake the irspiocb and copy necessary response information */
  8901. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8902. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8903. spin_lock_irqsave(&phba->hbalock, iflags);
  8904. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8905. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8906. }
  8907. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8908. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8909. }
  8910. /**
  8911. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8912. * @phba: Pointer to HBA context object.
  8913. * @cq: Pointer to completion queue.
  8914. * @wcqe: Pointer to work-queue completion queue entry.
  8915. *
  8916. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8917. * proper WQ release routine to the slow-path WQ.
  8918. **/
  8919. static void
  8920. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8921. struct lpfc_wcqe_release *wcqe)
  8922. {
  8923. struct lpfc_queue *childwq;
  8924. bool wqid_matched = false;
  8925. uint16_t fcp_wqid;
  8926. /* Check for fast-path FCP work queue release */
  8927. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8928. list_for_each_entry(childwq, &cq->child_list, list) {
  8929. if (childwq->queue_id == fcp_wqid) {
  8930. lpfc_sli4_wq_release(childwq,
  8931. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8932. wqid_matched = true;
  8933. break;
  8934. }
  8935. }
  8936. /* Report warning log message if no match found */
  8937. if (wqid_matched != true)
  8938. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8939. "2580 Fast-path wqe consume event carries "
  8940. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8941. }
  8942. /**
  8943. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8944. * @cq: Pointer to the completion queue.
  8945. * @eqe: Pointer to fast-path completion queue entry.
  8946. *
  8947. * This routine process a fast-path work queue completion entry from fast-path
  8948. * event queue for FCP command response completion.
  8949. **/
  8950. static int
  8951. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8952. struct lpfc_cqe *cqe)
  8953. {
  8954. struct lpfc_wcqe_release wcqe;
  8955. bool workposted = false;
  8956. /* Copy the work queue CQE and convert endian order if needed */
  8957. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8958. /* Check and process for different type of WCQE and dispatch */
  8959. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8960. case CQE_CODE_COMPL_WQE:
  8961. /* Process the WQ complete event */
  8962. phba->last_completion_time = jiffies;
  8963. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8964. (struct lpfc_wcqe_complete *)&wcqe);
  8965. break;
  8966. case CQE_CODE_RELEASE_WQE:
  8967. /* Process the WQ release event */
  8968. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8969. (struct lpfc_wcqe_release *)&wcqe);
  8970. break;
  8971. case CQE_CODE_XRI_ABORTED:
  8972. /* Process the WQ XRI abort event */
  8973. phba->last_completion_time = jiffies;
  8974. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8975. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8976. break;
  8977. default:
  8978. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8979. "0144 Not a valid WCQE code: x%x\n",
  8980. bf_get(lpfc_wcqe_c_code, &wcqe));
  8981. break;
  8982. }
  8983. return workposted;
  8984. }
  8985. /**
  8986. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8987. * @phba: Pointer to HBA context object.
  8988. * @eqe: Pointer to fast-path event queue entry.
  8989. *
  8990. * This routine process a event queue entry from the fast-path event queue.
  8991. * It will check the MajorCode and MinorCode to determine this is for a
  8992. * completion event on a completion queue, if not, an error shall be logged
  8993. * and just return. Otherwise, it will get to the corresponding completion
  8994. * queue and process all the entries on the completion queue, rearm the
  8995. * completion queue, and then return.
  8996. **/
  8997. static void
  8998. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8999. uint32_t fcp_cqidx)
  9000. {
  9001. struct lpfc_queue *cq;
  9002. struct lpfc_cqe *cqe;
  9003. bool workposted = false;
  9004. uint16_t cqid;
  9005. int ecount = 0;
  9006. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  9007. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9008. "0366 Not a valid fast-path completion "
  9009. "event: majorcode=x%x, minorcode=x%x\n",
  9010. bf_get_le32(lpfc_eqe_major_code, eqe),
  9011. bf_get_le32(lpfc_eqe_minor_code, eqe));
  9012. return;
  9013. }
  9014. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  9015. if (unlikely(!cq)) {
  9016. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  9017. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9018. "0367 Fast-path completion queue "
  9019. "does not exist\n");
  9020. return;
  9021. }
  9022. /* Get the reference to the corresponding CQ */
  9023. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9024. if (unlikely(cqid != cq->queue_id)) {
  9025. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9026. "0368 Miss-matched fast-path completion "
  9027. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9028. cqid, cq->queue_id);
  9029. return;
  9030. }
  9031. /* Process all the entries to the CQ */
  9032. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9033. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9034. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9035. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9036. }
  9037. /* Catch the no cq entry condition */
  9038. if (unlikely(ecount == 0))
  9039. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9040. "0369 No entry from fast-path completion "
  9041. "queue fcpcqid=%d\n", cq->queue_id);
  9042. /* In any case, flash and re-arm the CQ */
  9043. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9044. /* wake up worker thread if there are works to be done */
  9045. if (workposted)
  9046. lpfc_worker_wake_up(phba);
  9047. }
  9048. static void
  9049. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9050. {
  9051. struct lpfc_eqe *eqe;
  9052. /* walk all the EQ entries and drop on the floor */
  9053. while ((eqe = lpfc_sli4_eq_get(eq)))
  9054. ;
  9055. /* Clear and re-arm the EQ */
  9056. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9057. }
  9058. /**
  9059. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9060. * @irq: Interrupt number.
  9061. * @dev_id: The device context pointer.
  9062. *
  9063. * This function is directly called from the PCI layer as an interrupt
  9064. * service routine when device with SLI-4 interface spec is enabled with
  9065. * MSI-X multi-message interrupt mode and there are slow-path events in
  9066. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9067. * interrupt mode, this function is called as part of the device-level
  9068. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9069. * undergoing initialization, the interrupt handler will not process the
  9070. * interrupt. The link attention and ELS ring attention events are handled
  9071. * by the worker thread. The interrupt handler signals the worker thread
  9072. * and returns for these events. This function is called without any lock
  9073. * held. It gets the hbalock to access and update SLI data structures.
  9074. *
  9075. * This function returns IRQ_HANDLED when interrupt is handled else it
  9076. * returns IRQ_NONE.
  9077. **/
  9078. irqreturn_t
  9079. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  9080. {
  9081. struct lpfc_hba *phba;
  9082. struct lpfc_queue *speq;
  9083. struct lpfc_eqe *eqe;
  9084. unsigned long iflag;
  9085. int ecount = 0;
  9086. /*
  9087. * Get the driver's phba structure from the dev_id
  9088. */
  9089. phba = (struct lpfc_hba *)dev_id;
  9090. if (unlikely(!phba))
  9091. return IRQ_NONE;
  9092. /* Get to the EQ struct associated with this vector */
  9093. speq = phba->sli4_hba.sp_eq;
  9094. /* Check device state for handling interrupt */
  9095. if (unlikely(lpfc_intr_state_check(phba))) {
  9096. /* Check again for link_state with lock held */
  9097. spin_lock_irqsave(&phba->hbalock, iflag);
  9098. if (phba->link_state < LPFC_LINK_DOWN)
  9099. /* Flush, clear interrupt, and rearm the EQ */
  9100. lpfc_sli4_eq_flush(phba, speq);
  9101. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9102. return IRQ_NONE;
  9103. }
  9104. /*
  9105. * Process all the event on FCP slow-path EQ
  9106. */
  9107. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9108. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9109. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9110. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9111. }
  9112. /* Always clear and re-arm the slow-path EQ */
  9113. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9114. /* Catch the no cq entry condition */
  9115. if (unlikely(ecount == 0)) {
  9116. if (phba->intr_type == MSIX)
  9117. /* MSI-X treated interrupt served as no EQ share INT */
  9118. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9119. "0357 MSI-X interrupt with no EQE\n");
  9120. else
  9121. /* Non MSI-X treated on interrupt as EQ share INT */
  9122. return IRQ_NONE;
  9123. }
  9124. return IRQ_HANDLED;
  9125. } /* lpfc_sli4_sp_intr_handler */
  9126. /**
  9127. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9128. * @irq: Interrupt number.
  9129. * @dev_id: The device context pointer.
  9130. *
  9131. * This function is directly called from the PCI layer as an interrupt
  9132. * service routine when device with SLI-4 interface spec is enabled with
  9133. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9134. * ring event in the HBA. However, when the device is enabled with either
  9135. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9136. * device-level interrupt handler. When the PCI slot is in error recovery
  9137. * or the HBA is undergoing initialization, the interrupt handler will not
  9138. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9139. * the intrrupt context. This function is called without any lock held.
  9140. * It gets the hbalock to access and update SLI data structures. Note that,
  9141. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9142. * equal to that of FCP CQ index.
  9143. *
  9144. * This function returns IRQ_HANDLED when interrupt is handled else it
  9145. * returns IRQ_NONE.
  9146. **/
  9147. irqreturn_t
  9148. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9149. {
  9150. struct lpfc_hba *phba;
  9151. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9152. struct lpfc_queue *fpeq;
  9153. struct lpfc_eqe *eqe;
  9154. unsigned long iflag;
  9155. int ecount = 0;
  9156. uint32_t fcp_eqidx;
  9157. /* Get the driver's phba structure from the dev_id */
  9158. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9159. phba = fcp_eq_hdl->phba;
  9160. fcp_eqidx = fcp_eq_hdl->idx;
  9161. if (unlikely(!phba))
  9162. return IRQ_NONE;
  9163. /* Get to the EQ struct associated with this vector */
  9164. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9165. /* Check device state for handling interrupt */
  9166. if (unlikely(lpfc_intr_state_check(phba))) {
  9167. /* Check again for link_state with lock held */
  9168. spin_lock_irqsave(&phba->hbalock, iflag);
  9169. if (phba->link_state < LPFC_LINK_DOWN)
  9170. /* Flush, clear interrupt, and rearm the EQ */
  9171. lpfc_sli4_eq_flush(phba, fpeq);
  9172. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9173. return IRQ_NONE;
  9174. }
  9175. /*
  9176. * Process all the event on FCP fast-path EQ
  9177. */
  9178. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9179. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9180. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9181. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9182. }
  9183. /* Always clear and re-arm the fast-path EQ */
  9184. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9185. if (unlikely(ecount == 0)) {
  9186. if (phba->intr_type == MSIX)
  9187. /* MSI-X treated interrupt served as no EQ share INT */
  9188. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9189. "0358 MSI-X interrupt with no EQE\n");
  9190. else
  9191. /* Non MSI-X treated on interrupt as EQ share INT */
  9192. return IRQ_NONE;
  9193. }
  9194. return IRQ_HANDLED;
  9195. } /* lpfc_sli4_fp_intr_handler */
  9196. /**
  9197. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9198. * @irq: Interrupt number.
  9199. * @dev_id: The device context pointer.
  9200. *
  9201. * This function is the device-level interrupt handler to device with SLI-4
  9202. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9203. * interrupt mode is enabled and there is an event in the HBA which requires
  9204. * driver attention. This function invokes the slow-path interrupt attention
  9205. * handling function and fast-path interrupt attention handling function in
  9206. * turn to process the relevant HBA attention events. This function is called
  9207. * without any lock held. It gets the hbalock to access and update SLI data
  9208. * structures.
  9209. *
  9210. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9211. * returns IRQ_NONE.
  9212. **/
  9213. irqreturn_t
  9214. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9215. {
  9216. struct lpfc_hba *phba;
  9217. irqreturn_t sp_irq_rc, fp_irq_rc;
  9218. bool fp_handled = false;
  9219. uint32_t fcp_eqidx;
  9220. /* Get the driver's phba structure from the dev_id */
  9221. phba = (struct lpfc_hba *)dev_id;
  9222. if (unlikely(!phba))
  9223. return IRQ_NONE;
  9224. /*
  9225. * Invokes slow-path host attention interrupt handling as appropriate.
  9226. */
  9227. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9228. /*
  9229. * Invoke fast-path host attention interrupt handling as appropriate.
  9230. */
  9231. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9232. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9233. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9234. if (fp_irq_rc == IRQ_HANDLED)
  9235. fp_handled |= true;
  9236. }
  9237. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9238. } /* lpfc_sli4_intr_handler */
  9239. /**
  9240. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9241. * @queue: The queue structure to free.
  9242. *
  9243. * This function frees a queue structure and the DMAable memory used for
  9244. * the host resident queue. This function must be called after destroying the
  9245. * queue on the HBA.
  9246. **/
  9247. void
  9248. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9249. {
  9250. struct lpfc_dmabuf *dmabuf;
  9251. if (!queue)
  9252. return;
  9253. while (!list_empty(&queue->page_list)) {
  9254. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9255. list);
  9256. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9257. dmabuf->virt, dmabuf->phys);
  9258. kfree(dmabuf);
  9259. }
  9260. kfree(queue);
  9261. return;
  9262. }
  9263. /**
  9264. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9265. * @phba: The HBA that this queue is being created on.
  9266. * @entry_size: The size of each queue entry for this queue.
  9267. * @entry count: The number of entries that this queue will handle.
  9268. *
  9269. * This function allocates a queue structure and the DMAable memory used for
  9270. * the host resident queue. This function must be called before creating the
  9271. * queue on the HBA.
  9272. **/
  9273. struct lpfc_queue *
  9274. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9275. uint32_t entry_count)
  9276. {
  9277. struct lpfc_queue *queue;
  9278. struct lpfc_dmabuf *dmabuf;
  9279. int x, total_qe_count;
  9280. void *dma_pointer;
  9281. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9282. if (!phba->sli4_hba.pc_sli4_params.supported)
  9283. hw_page_size = SLI4_PAGE_SIZE;
  9284. queue = kzalloc(sizeof(struct lpfc_queue) +
  9285. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9286. if (!queue)
  9287. return NULL;
  9288. queue->page_count = (ALIGN(entry_size * entry_count,
  9289. hw_page_size))/hw_page_size;
  9290. INIT_LIST_HEAD(&queue->list);
  9291. INIT_LIST_HEAD(&queue->page_list);
  9292. INIT_LIST_HEAD(&queue->child_list);
  9293. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9294. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9295. if (!dmabuf)
  9296. goto out_fail;
  9297. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9298. hw_page_size, &dmabuf->phys,
  9299. GFP_KERNEL);
  9300. if (!dmabuf->virt) {
  9301. kfree(dmabuf);
  9302. goto out_fail;
  9303. }
  9304. memset(dmabuf->virt, 0, hw_page_size);
  9305. dmabuf->buffer_tag = x;
  9306. list_add_tail(&dmabuf->list, &queue->page_list);
  9307. /* initialize queue's entry array */
  9308. dma_pointer = dmabuf->virt;
  9309. for (; total_qe_count < entry_count &&
  9310. dma_pointer < (hw_page_size + dmabuf->virt);
  9311. total_qe_count++, dma_pointer += entry_size) {
  9312. queue->qe[total_qe_count].address = dma_pointer;
  9313. }
  9314. }
  9315. queue->entry_size = entry_size;
  9316. queue->entry_count = entry_count;
  9317. queue->phba = phba;
  9318. return queue;
  9319. out_fail:
  9320. lpfc_sli4_queue_free(queue);
  9321. return NULL;
  9322. }
  9323. /**
  9324. * lpfc_eq_create - Create an Event Queue on the HBA
  9325. * @phba: HBA structure that indicates port to create a queue on.
  9326. * @eq: The queue structure to use to create the event queue.
  9327. * @imax: The maximum interrupt per second limit.
  9328. *
  9329. * This function creates an event queue, as detailed in @eq, on a port,
  9330. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9331. *
  9332. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9333. * is used to get the entry count and entry size that are necessary to
  9334. * determine the number of pages to allocate and use for this queue. This
  9335. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9336. * event queue. This function is asynchronous and will wait for the mailbox
  9337. * command to finish before continuing.
  9338. *
  9339. * On success this function will return a zero. If unable to allocate enough
  9340. * memory this function will return -ENOMEM. If the queue create mailbox command
  9341. * fails this function will return -ENXIO.
  9342. **/
  9343. uint32_t
  9344. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9345. {
  9346. struct lpfc_mbx_eq_create *eq_create;
  9347. LPFC_MBOXQ_t *mbox;
  9348. int rc, length, status = 0;
  9349. struct lpfc_dmabuf *dmabuf;
  9350. uint32_t shdr_status, shdr_add_status;
  9351. union lpfc_sli4_cfg_shdr *shdr;
  9352. uint16_t dmult;
  9353. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9354. if (!phba->sli4_hba.pc_sli4_params.supported)
  9355. hw_page_size = SLI4_PAGE_SIZE;
  9356. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9357. if (!mbox)
  9358. return -ENOMEM;
  9359. length = (sizeof(struct lpfc_mbx_eq_create) -
  9360. sizeof(struct lpfc_sli4_cfg_mhdr));
  9361. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9362. LPFC_MBOX_OPCODE_EQ_CREATE,
  9363. length, LPFC_SLI4_MBX_EMBED);
  9364. eq_create = &mbox->u.mqe.un.eq_create;
  9365. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9366. eq->page_count);
  9367. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9368. LPFC_EQE_SIZE);
  9369. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9370. /* Calculate delay multiper from maximum interrupt per second */
  9371. dmult = LPFC_DMULT_CONST/imax - 1;
  9372. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9373. dmult);
  9374. switch (eq->entry_count) {
  9375. default:
  9376. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9377. "0360 Unsupported EQ count. (%d)\n",
  9378. eq->entry_count);
  9379. if (eq->entry_count < 256)
  9380. return -EINVAL;
  9381. /* otherwise default to smallest count (drop through) */
  9382. case 256:
  9383. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9384. LPFC_EQ_CNT_256);
  9385. break;
  9386. case 512:
  9387. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9388. LPFC_EQ_CNT_512);
  9389. break;
  9390. case 1024:
  9391. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9392. LPFC_EQ_CNT_1024);
  9393. break;
  9394. case 2048:
  9395. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9396. LPFC_EQ_CNT_2048);
  9397. break;
  9398. case 4096:
  9399. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9400. LPFC_EQ_CNT_4096);
  9401. break;
  9402. }
  9403. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9404. memset(dmabuf->virt, 0, hw_page_size);
  9405. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9406. putPaddrLow(dmabuf->phys);
  9407. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9408. putPaddrHigh(dmabuf->phys);
  9409. }
  9410. mbox->vport = phba->pport;
  9411. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9412. mbox->context1 = NULL;
  9413. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9414. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9415. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9416. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9417. if (shdr_status || shdr_add_status || rc) {
  9418. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9419. "2500 EQ_CREATE mailbox failed with "
  9420. "status x%x add_status x%x, mbx status x%x\n",
  9421. shdr_status, shdr_add_status, rc);
  9422. status = -ENXIO;
  9423. }
  9424. eq->type = LPFC_EQ;
  9425. eq->subtype = LPFC_NONE;
  9426. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9427. if (eq->queue_id == 0xFFFF)
  9428. status = -ENXIO;
  9429. eq->host_index = 0;
  9430. eq->hba_index = 0;
  9431. mempool_free(mbox, phba->mbox_mem_pool);
  9432. return status;
  9433. }
  9434. /**
  9435. * lpfc_cq_create - Create a Completion Queue on the HBA
  9436. * @phba: HBA structure that indicates port to create a queue on.
  9437. * @cq: The queue structure to use to create the completion queue.
  9438. * @eq: The event queue to bind this completion queue to.
  9439. *
  9440. * This function creates a completion queue, as detailed in @wq, on a port,
  9441. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9442. *
  9443. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9444. * is used to get the entry count and entry size that are necessary to
  9445. * determine the number of pages to allocate and use for this queue. The @eq
  9446. * is used to indicate which event queue to bind this completion queue to. This
  9447. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9448. * completion queue. This function is asynchronous and will wait for the mailbox
  9449. * command to finish before continuing.
  9450. *
  9451. * On success this function will return a zero. If unable to allocate enough
  9452. * memory this function will return -ENOMEM. If the queue create mailbox command
  9453. * fails this function will return -ENXIO.
  9454. **/
  9455. uint32_t
  9456. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9457. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9458. {
  9459. struct lpfc_mbx_cq_create *cq_create;
  9460. struct lpfc_dmabuf *dmabuf;
  9461. LPFC_MBOXQ_t *mbox;
  9462. int rc, length, status = 0;
  9463. uint32_t shdr_status, shdr_add_status;
  9464. union lpfc_sli4_cfg_shdr *shdr;
  9465. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9466. if (!phba->sli4_hba.pc_sli4_params.supported)
  9467. hw_page_size = SLI4_PAGE_SIZE;
  9468. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9469. if (!mbox)
  9470. return -ENOMEM;
  9471. length = (sizeof(struct lpfc_mbx_cq_create) -
  9472. sizeof(struct lpfc_sli4_cfg_mhdr));
  9473. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9474. LPFC_MBOX_OPCODE_CQ_CREATE,
  9475. length, LPFC_SLI4_MBX_EMBED);
  9476. cq_create = &mbox->u.mqe.un.cq_create;
  9477. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9478. cq->page_count);
  9479. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9480. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9481. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  9482. switch (cq->entry_count) {
  9483. default:
  9484. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9485. "0361 Unsupported CQ count. (%d)\n",
  9486. cq->entry_count);
  9487. if (cq->entry_count < 256)
  9488. return -EINVAL;
  9489. /* otherwise default to smallest count (drop through) */
  9490. case 256:
  9491. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9492. LPFC_CQ_CNT_256);
  9493. break;
  9494. case 512:
  9495. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9496. LPFC_CQ_CNT_512);
  9497. break;
  9498. case 1024:
  9499. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9500. LPFC_CQ_CNT_1024);
  9501. break;
  9502. }
  9503. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9504. memset(dmabuf->virt, 0, hw_page_size);
  9505. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9506. putPaddrLow(dmabuf->phys);
  9507. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9508. putPaddrHigh(dmabuf->phys);
  9509. }
  9510. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9511. /* The IOCTL status is embedded in the mailbox subheader. */
  9512. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9513. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9514. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9515. if (shdr_status || shdr_add_status || rc) {
  9516. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9517. "2501 CQ_CREATE mailbox failed with "
  9518. "status x%x add_status x%x, mbx status x%x\n",
  9519. shdr_status, shdr_add_status, rc);
  9520. status = -ENXIO;
  9521. goto out;
  9522. }
  9523. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9524. if (cq->queue_id == 0xFFFF) {
  9525. status = -ENXIO;
  9526. goto out;
  9527. }
  9528. /* link the cq onto the parent eq child list */
  9529. list_add_tail(&cq->list, &eq->child_list);
  9530. /* Set up completion queue's type and subtype */
  9531. cq->type = type;
  9532. cq->subtype = subtype;
  9533. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9534. cq->host_index = 0;
  9535. cq->hba_index = 0;
  9536. out:
  9537. mempool_free(mbox, phba->mbox_mem_pool);
  9538. return status;
  9539. }
  9540. /**
  9541. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9542. * @phba: HBA structure that indicates port to create a queue on.
  9543. * @mq: The queue structure to use to create the mailbox queue.
  9544. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9545. * @cq: The completion queue to associate with this cq.
  9546. *
  9547. * This function provides failback (fb) functionality when the
  9548. * mq_create_ext fails on older FW generations. It's purpose is identical
  9549. * to mq_create_ext otherwise.
  9550. *
  9551. * This routine cannot fail as all attributes were previously accessed and
  9552. * initialized in mq_create_ext.
  9553. **/
  9554. static void
  9555. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9556. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9557. {
  9558. struct lpfc_mbx_mq_create *mq_create;
  9559. struct lpfc_dmabuf *dmabuf;
  9560. int length;
  9561. length = (sizeof(struct lpfc_mbx_mq_create) -
  9562. sizeof(struct lpfc_sli4_cfg_mhdr));
  9563. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9564. LPFC_MBOX_OPCODE_MQ_CREATE,
  9565. length, LPFC_SLI4_MBX_EMBED);
  9566. mq_create = &mbox->u.mqe.un.mq_create;
  9567. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9568. mq->page_count);
  9569. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9570. cq->queue_id);
  9571. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9572. switch (mq->entry_count) {
  9573. case 16:
  9574. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9575. LPFC_MQ_CNT_16);
  9576. break;
  9577. case 32:
  9578. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9579. LPFC_MQ_CNT_32);
  9580. break;
  9581. case 64:
  9582. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9583. LPFC_MQ_CNT_64);
  9584. break;
  9585. case 128:
  9586. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9587. LPFC_MQ_CNT_128);
  9588. break;
  9589. }
  9590. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9591. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9592. putPaddrLow(dmabuf->phys);
  9593. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9594. putPaddrHigh(dmabuf->phys);
  9595. }
  9596. }
  9597. /**
  9598. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9599. * @phba: HBA structure that indicates port to create a queue on.
  9600. * @mq: The queue structure to use to create the mailbox queue.
  9601. * @cq: The completion queue to associate with this cq.
  9602. * @subtype: The queue's subtype.
  9603. *
  9604. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9605. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9606. *
  9607. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9608. * is used to get the entry count and entry size that are necessary to
  9609. * determine the number of pages to allocate and use for this queue. This
  9610. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9611. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9612. * command to finish before continuing.
  9613. *
  9614. * On success this function will return a zero. If unable to allocate enough
  9615. * memory this function will return -ENOMEM. If the queue create mailbox command
  9616. * fails this function will return -ENXIO.
  9617. **/
  9618. int32_t
  9619. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9620. struct lpfc_queue *cq, uint32_t subtype)
  9621. {
  9622. struct lpfc_mbx_mq_create *mq_create;
  9623. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9624. struct lpfc_dmabuf *dmabuf;
  9625. LPFC_MBOXQ_t *mbox;
  9626. int rc, length, status = 0;
  9627. uint32_t shdr_status, shdr_add_status;
  9628. union lpfc_sli4_cfg_shdr *shdr;
  9629. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9630. if (!phba->sli4_hba.pc_sli4_params.supported)
  9631. hw_page_size = SLI4_PAGE_SIZE;
  9632. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9633. if (!mbox)
  9634. return -ENOMEM;
  9635. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9636. sizeof(struct lpfc_sli4_cfg_mhdr));
  9637. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9638. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9639. length, LPFC_SLI4_MBX_EMBED);
  9640. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9641. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  9642. &mq_create_ext->u.request, mq->page_count);
  9643. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  9644. &mq_create_ext->u.request, 1);
  9645. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  9646. &mq_create_ext->u.request, 1);
  9647. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9648. &mq_create_ext->u.request, 1);
  9649. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  9650. &mq_create_ext->u.request, 1);
  9651. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  9652. &mq_create_ext->u.request, 1);
  9653. bf_set(lpfc_mq_context_cq_id,
  9654. &mq_create_ext->u.request.context, cq->queue_id);
  9655. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9656. switch (mq->entry_count) {
  9657. default:
  9658. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9659. "0362 Unsupported MQ count. (%d)\n",
  9660. mq->entry_count);
  9661. if (mq->entry_count < 16)
  9662. return -EINVAL;
  9663. /* otherwise default to smallest count (drop through) */
  9664. case 16:
  9665. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9666. LPFC_MQ_CNT_16);
  9667. break;
  9668. case 32:
  9669. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9670. LPFC_MQ_CNT_32);
  9671. break;
  9672. case 64:
  9673. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9674. LPFC_MQ_CNT_64);
  9675. break;
  9676. case 128:
  9677. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9678. LPFC_MQ_CNT_128);
  9679. break;
  9680. }
  9681. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9682. memset(dmabuf->virt, 0, hw_page_size);
  9683. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9684. putPaddrLow(dmabuf->phys);
  9685. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9686. putPaddrHigh(dmabuf->phys);
  9687. }
  9688. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9689. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9690. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9691. &mq_create_ext->u.response);
  9692. if (rc != MBX_SUCCESS) {
  9693. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9694. "2795 MQ_CREATE_EXT failed with "
  9695. "status x%x. Failback to MQ_CREATE.\n",
  9696. rc);
  9697. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9698. mq_create = &mbox->u.mqe.un.mq_create;
  9699. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9700. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9701. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9702. &mq_create->u.response);
  9703. }
  9704. /* The IOCTL status is embedded in the mailbox subheader. */
  9705. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9706. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9707. if (shdr_status || shdr_add_status || rc) {
  9708. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9709. "2502 MQ_CREATE mailbox failed with "
  9710. "status x%x add_status x%x, mbx status x%x\n",
  9711. shdr_status, shdr_add_status, rc);
  9712. status = -ENXIO;
  9713. goto out;
  9714. }
  9715. if (mq->queue_id == 0xFFFF) {
  9716. status = -ENXIO;
  9717. goto out;
  9718. }
  9719. mq->type = LPFC_MQ;
  9720. mq->subtype = subtype;
  9721. mq->host_index = 0;
  9722. mq->hba_index = 0;
  9723. /* link the mq onto the parent cq child list */
  9724. list_add_tail(&mq->list, &cq->child_list);
  9725. out:
  9726. mempool_free(mbox, phba->mbox_mem_pool);
  9727. return status;
  9728. }
  9729. /**
  9730. * lpfc_wq_create - Create a Work Queue on the HBA
  9731. * @phba: HBA structure that indicates port to create a queue on.
  9732. * @wq: The queue structure to use to create the work queue.
  9733. * @cq: The completion queue to bind this work queue to.
  9734. * @subtype: The subtype of the work queue indicating its functionality.
  9735. *
  9736. * This function creates a work queue, as detailed in @wq, on a port, described
  9737. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9738. *
  9739. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9740. * is used to get the entry count and entry size that are necessary to
  9741. * determine the number of pages to allocate and use for this queue. The @cq
  9742. * is used to indicate which completion queue to bind this work queue to. This
  9743. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9744. * work queue. This function is asynchronous and will wait for the mailbox
  9745. * command to finish before continuing.
  9746. *
  9747. * On success this function will return a zero. If unable to allocate enough
  9748. * memory this function will return -ENOMEM. If the queue create mailbox command
  9749. * fails this function will return -ENXIO.
  9750. **/
  9751. uint32_t
  9752. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9753. struct lpfc_queue *cq, uint32_t subtype)
  9754. {
  9755. struct lpfc_mbx_wq_create *wq_create;
  9756. struct lpfc_dmabuf *dmabuf;
  9757. LPFC_MBOXQ_t *mbox;
  9758. int rc, length, status = 0;
  9759. uint32_t shdr_status, shdr_add_status;
  9760. union lpfc_sli4_cfg_shdr *shdr;
  9761. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9762. if (!phba->sli4_hba.pc_sli4_params.supported)
  9763. hw_page_size = SLI4_PAGE_SIZE;
  9764. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9765. if (!mbox)
  9766. return -ENOMEM;
  9767. length = (sizeof(struct lpfc_mbx_wq_create) -
  9768. sizeof(struct lpfc_sli4_cfg_mhdr));
  9769. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9770. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9771. length, LPFC_SLI4_MBX_EMBED);
  9772. wq_create = &mbox->u.mqe.un.wq_create;
  9773. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9774. wq->page_count);
  9775. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9776. cq->queue_id);
  9777. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9778. memset(dmabuf->virt, 0, hw_page_size);
  9779. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9780. putPaddrLow(dmabuf->phys);
  9781. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9782. putPaddrHigh(dmabuf->phys);
  9783. }
  9784. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9785. /* The IOCTL status is embedded in the mailbox subheader. */
  9786. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9787. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9788. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9789. if (shdr_status || shdr_add_status || rc) {
  9790. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9791. "2503 WQ_CREATE mailbox failed with "
  9792. "status x%x add_status x%x, mbx status x%x\n",
  9793. shdr_status, shdr_add_status, rc);
  9794. status = -ENXIO;
  9795. goto out;
  9796. }
  9797. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9798. if (wq->queue_id == 0xFFFF) {
  9799. status = -ENXIO;
  9800. goto out;
  9801. }
  9802. wq->type = LPFC_WQ;
  9803. wq->subtype = subtype;
  9804. wq->host_index = 0;
  9805. wq->hba_index = 0;
  9806. /* link the wq onto the parent cq child list */
  9807. list_add_tail(&wq->list, &cq->child_list);
  9808. out:
  9809. mempool_free(mbox, phba->mbox_mem_pool);
  9810. return status;
  9811. }
  9812. /**
  9813. * lpfc_rq_create - Create a Receive Queue on the HBA
  9814. * @phba: HBA structure that indicates port to create a queue on.
  9815. * @hrq: The queue structure to use to create the header receive queue.
  9816. * @drq: The queue structure to use to create the data receive queue.
  9817. * @cq: The completion queue to bind this work queue to.
  9818. *
  9819. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9820. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9821. * to the HBA.
  9822. *
  9823. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9824. * struct is used to get the entry count that is necessary to determine the
  9825. * number of pages to use for this queue. The @cq is used to indicate which
  9826. * completion queue to bind received buffers that are posted to these queues to.
  9827. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9828. * receive queue pair. This function is asynchronous and will wait for the
  9829. * mailbox command to finish before continuing.
  9830. *
  9831. * On success this function will return a zero. If unable to allocate enough
  9832. * memory this function will return -ENOMEM. If the queue create mailbox command
  9833. * fails this function will return -ENXIO.
  9834. **/
  9835. uint32_t
  9836. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9837. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9838. {
  9839. struct lpfc_mbx_rq_create *rq_create;
  9840. struct lpfc_dmabuf *dmabuf;
  9841. LPFC_MBOXQ_t *mbox;
  9842. int rc, length, status = 0;
  9843. uint32_t shdr_status, shdr_add_status;
  9844. union lpfc_sli4_cfg_shdr *shdr;
  9845. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9846. if (!phba->sli4_hba.pc_sli4_params.supported)
  9847. hw_page_size = SLI4_PAGE_SIZE;
  9848. if (hrq->entry_count != drq->entry_count)
  9849. return -EINVAL;
  9850. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9851. if (!mbox)
  9852. return -ENOMEM;
  9853. length = (sizeof(struct lpfc_mbx_rq_create) -
  9854. sizeof(struct lpfc_sli4_cfg_mhdr));
  9855. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9856. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9857. length, LPFC_SLI4_MBX_EMBED);
  9858. rq_create = &mbox->u.mqe.un.rq_create;
  9859. switch (hrq->entry_count) {
  9860. default:
  9861. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9862. "2535 Unsupported RQ count. (%d)\n",
  9863. hrq->entry_count);
  9864. if (hrq->entry_count < 512)
  9865. return -EINVAL;
  9866. /* otherwise default to smallest count (drop through) */
  9867. case 512:
  9868. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9869. LPFC_RQ_RING_SIZE_512);
  9870. break;
  9871. case 1024:
  9872. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9873. LPFC_RQ_RING_SIZE_1024);
  9874. break;
  9875. case 2048:
  9876. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9877. LPFC_RQ_RING_SIZE_2048);
  9878. break;
  9879. case 4096:
  9880. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9881. LPFC_RQ_RING_SIZE_4096);
  9882. break;
  9883. }
  9884. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9885. cq->queue_id);
  9886. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9887. hrq->page_count);
  9888. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9889. LPFC_HDR_BUF_SIZE);
  9890. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9891. memset(dmabuf->virt, 0, hw_page_size);
  9892. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9893. putPaddrLow(dmabuf->phys);
  9894. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9895. putPaddrHigh(dmabuf->phys);
  9896. }
  9897. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9898. /* The IOCTL status is embedded in the mailbox subheader. */
  9899. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9900. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9901. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9902. if (shdr_status || shdr_add_status || rc) {
  9903. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9904. "2504 RQ_CREATE mailbox failed with "
  9905. "status x%x add_status x%x, mbx status x%x\n",
  9906. shdr_status, shdr_add_status, rc);
  9907. status = -ENXIO;
  9908. goto out;
  9909. }
  9910. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9911. if (hrq->queue_id == 0xFFFF) {
  9912. status = -ENXIO;
  9913. goto out;
  9914. }
  9915. hrq->type = LPFC_HRQ;
  9916. hrq->subtype = subtype;
  9917. hrq->host_index = 0;
  9918. hrq->hba_index = 0;
  9919. /* now create the data queue */
  9920. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9921. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9922. length, LPFC_SLI4_MBX_EMBED);
  9923. switch (drq->entry_count) {
  9924. default:
  9925. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9926. "2536 Unsupported RQ count. (%d)\n",
  9927. drq->entry_count);
  9928. if (drq->entry_count < 512)
  9929. return -EINVAL;
  9930. /* otherwise default to smallest count (drop through) */
  9931. case 512:
  9932. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9933. LPFC_RQ_RING_SIZE_512);
  9934. break;
  9935. case 1024:
  9936. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9937. LPFC_RQ_RING_SIZE_1024);
  9938. break;
  9939. case 2048:
  9940. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9941. LPFC_RQ_RING_SIZE_2048);
  9942. break;
  9943. case 4096:
  9944. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9945. LPFC_RQ_RING_SIZE_4096);
  9946. break;
  9947. }
  9948. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9949. cq->queue_id);
  9950. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9951. drq->page_count);
  9952. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9953. LPFC_DATA_BUF_SIZE);
  9954. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9955. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9956. putPaddrLow(dmabuf->phys);
  9957. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9958. putPaddrHigh(dmabuf->phys);
  9959. }
  9960. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9961. /* The IOCTL status is embedded in the mailbox subheader. */
  9962. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9963. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9964. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9965. if (shdr_status || shdr_add_status || rc) {
  9966. status = -ENXIO;
  9967. goto out;
  9968. }
  9969. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9970. if (drq->queue_id == 0xFFFF) {
  9971. status = -ENXIO;
  9972. goto out;
  9973. }
  9974. drq->type = LPFC_DRQ;
  9975. drq->subtype = subtype;
  9976. drq->host_index = 0;
  9977. drq->hba_index = 0;
  9978. /* link the header and data RQs onto the parent cq child list */
  9979. list_add_tail(&hrq->list, &cq->child_list);
  9980. list_add_tail(&drq->list, &cq->child_list);
  9981. out:
  9982. mempool_free(mbox, phba->mbox_mem_pool);
  9983. return status;
  9984. }
  9985. /**
  9986. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9987. * @eq: The queue structure associated with the queue to destroy.
  9988. *
  9989. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9990. * command, specific to the type of queue, to the HBA.
  9991. *
  9992. * The @eq struct is used to get the queue ID of the queue to destroy.
  9993. *
  9994. * On success this function will return a zero. If the queue destroy mailbox
  9995. * command fails this function will return -ENXIO.
  9996. **/
  9997. uint32_t
  9998. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9999. {
  10000. LPFC_MBOXQ_t *mbox;
  10001. int rc, length, status = 0;
  10002. uint32_t shdr_status, shdr_add_status;
  10003. union lpfc_sli4_cfg_shdr *shdr;
  10004. if (!eq)
  10005. return -ENODEV;
  10006. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  10007. if (!mbox)
  10008. return -ENOMEM;
  10009. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  10010. sizeof(struct lpfc_sli4_cfg_mhdr));
  10011. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10012. LPFC_MBOX_OPCODE_EQ_DESTROY,
  10013. length, LPFC_SLI4_MBX_EMBED);
  10014. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  10015. eq->queue_id);
  10016. mbox->vport = eq->phba->pport;
  10017. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10018. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  10019. /* The IOCTL status is embedded in the mailbox subheader. */
  10020. shdr = (union lpfc_sli4_cfg_shdr *)
  10021. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  10022. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10023. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10024. if (shdr_status || shdr_add_status || rc) {
  10025. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10026. "2505 EQ_DESTROY mailbox failed with "
  10027. "status x%x add_status x%x, mbx status x%x\n",
  10028. shdr_status, shdr_add_status, rc);
  10029. status = -ENXIO;
  10030. }
  10031. /* Remove eq from any list */
  10032. list_del_init(&eq->list);
  10033. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10034. return status;
  10035. }
  10036. /**
  10037. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10038. * @cq: The queue structure associated with the queue to destroy.
  10039. *
  10040. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10041. * command, specific to the type of queue, to the HBA.
  10042. *
  10043. * The @cq struct is used to get the queue ID of the queue to destroy.
  10044. *
  10045. * On success this function will return a zero. If the queue destroy mailbox
  10046. * command fails this function will return -ENXIO.
  10047. **/
  10048. uint32_t
  10049. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10050. {
  10051. LPFC_MBOXQ_t *mbox;
  10052. int rc, length, status = 0;
  10053. uint32_t shdr_status, shdr_add_status;
  10054. union lpfc_sli4_cfg_shdr *shdr;
  10055. if (!cq)
  10056. return -ENODEV;
  10057. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10058. if (!mbox)
  10059. return -ENOMEM;
  10060. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10061. sizeof(struct lpfc_sli4_cfg_mhdr));
  10062. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10063. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10064. length, LPFC_SLI4_MBX_EMBED);
  10065. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10066. cq->queue_id);
  10067. mbox->vport = cq->phba->pport;
  10068. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10069. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10070. /* The IOCTL status is embedded in the mailbox subheader. */
  10071. shdr = (union lpfc_sli4_cfg_shdr *)
  10072. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10073. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10074. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10075. if (shdr_status || shdr_add_status || rc) {
  10076. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10077. "2506 CQ_DESTROY mailbox failed with "
  10078. "status x%x add_status x%x, mbx status x%x\n",
  10079. shdr_status, shdr_add_status, rc);
  10080. status = -ENXIO;
  10081. }
  10082. /* Remove cq from any list */
  10083. list_del_init(&cq->list);
  10084. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10085. return status;
  10086. }
  10087. /**
  10088. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10089. * @qm: The queue structure associated with the queue to destroy.
  10090. *
  10091. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10092. * command, specific to the type of queue, to the HBA.
  10093. *
  10094. * The @mq struct is used to get the queue ID of the queue to destroy.
  10095. *
  10096. * On success this function will return a zero. If the queue destroy mailbox
  10097. * command fails this function will return -ENXIO.
  10098. **/
  10099. uint32_t
  10100. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10101. {
  10102. LPFC_MBOXQ_t *mbox;
  10103. int rc, length, status = 0;
  10104. uint32_t shdr_status, shdr_add_status;
  10105. union lpfc_sli4_cfg_shdr *shdr;
  10106. if (!mq)
  10107. return -ENODEV;
  10108. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10109. if (!mbox)
  10110. return -ENOMEM;
  10111. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10112. sizeof(struct lpfc_sli4_cfg_mhdr));
  10113. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10114. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10115. length, LPFC_SLI4_MBX_EMBED);
  10116. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10117. mq->queue_id);
  10118. mbox->vport = mq->phba->pport;
  10119. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10120. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10121. /* The IOCTL status is embedded in the mailbox subheader. */
  10122. shdr = (union lpfc_sli4_cfg_shdr *)
  10123. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10124. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10125. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10126. if (shdr_status || shdr_add_status || rc) {
  10127. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10128. "2507 MQ_DESTROY mailbox failed with "
  10129. "status x%x add_status x%x, mbx status x%x\n",
  10130. shdr_status, shdr_add_status, rc);
  10131. status = -ENXIO;
  10132. }
  10133. /* Remove mq from any list */
  10134. list_del_init(&mq->list);
  10135. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10136. return status;
  10137. }
  10138. /**
  10139. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10140. * @wq: The queue structure associated with the queue to destroy.
  10141. *
  10142. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10143. * command, specific to the type of queue, to the HBA.
  10144. *
  10145. * The @wq struct is used to get the queue ID of the queue to destroy.
  10146. *
  10147. * On success this function will return a zero. If the queue destroy mailbox
  10148. * command fails this function will return -ENXIO.
  10149. **/
  10150. uint32_t
  10151. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10152. {
  10153. LPFC_MBOXQ_t *mbox;
  10154. int rc, length, status = 0;
  10155. uint32_t shdr_status, shdr_add_status;
  10156. union lpfc_sli4_cfg_shdr *shdr;
  10157. if (!wq)
  10158. return -ENODEV;
  10159. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10160. if (!mbox)
  10161. return -ENOMEM;
  10162. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10163. sizeof(struct lpfc_sli4_cfg_mhdr));
  10164. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10165. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10166. length, LPFC_SLI4_MBX_EMBED);
  10167. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10168. wq->queue_id);
  10169. mbox->vport = wq->phba->pport;
  10170. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10171. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10172. shdr = (union lpfc_sli4_cfg_shdr *)
  10173. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10174. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10175. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10176. if (shdr_status || shdr_add_status || rc) {
  10177. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10178. "2508 WQ_DESTROY mailbox failed with "
  10179. "status x%x add_status x%x, mbx status x%x\n",
  10180. shdr_status, shdr_add_status, rc);
  10181. status = -ENXIO;
  10182. }
  10183. /* Remove wq from any list */
  10184. list_del_init(&wq->list);
  10185. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10186. return status;
  10187. }
  10188. /**
  10189. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10190. * @rq: The queue structure associated with the queue to destroy.
  10191. *
  10192. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10193. * command, specific to the type of queue, to the HBA.
  10194. *
  10195. * The @rq struct is used to get the queue ID of the queue to destroy.
  10196. *
  10197. * On success this function will return a zero. If the queue destroy mailbox
  10198. * command fails this function will return -ENXIO.
  10199. **/
  10200. uint32_t
  10201. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10202. struct lpfc_queue *drq)
  10203. {
  10204. LPFC_MBOXQ_t *mbox;
  10205. int rc, length, status = 0;
  10206. uint32_t shdr_status, shdr_add_status;
  10207. union lpfc_sli4_cfg_shdr *shdr;
  10208. if (!hrq || !drq)
  10209. return -ENODEV;
  10210. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10211. if (!mbox)
  10212. return -ENOMEM;
  10213. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10214. sizeof(struct lpfc_sli4_cfg_mhdr));
  10215. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10216. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10217. length, LPFC_SLI4_MBX_EMBED);
  10218. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10219. hrq->queue_id);
  10220. mbox->vport = hrq->phba->pport;
  10221. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10222. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10223. /* The IOCTL status is embedded in the mailbox subheader. */
  10224. shdr = (union lpfc_sli4_cfg_shdr *)
  10225. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10226. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10227. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10228. if (shdr_status || shdr_add_status || rc) {
  10229. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10230. "2509 RQ_DESTROY mailbox failed with "
  10231. "status x%x add_status x%x, mbx status x%x\n",
  10232. shdr_status, shdr_add_status, rc);
  10233. if (rc != MBX_TIMEOUT)
  10234. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10235. return -ENXIO;
  10236. }
  10237. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10238. drq->queue_id);
  10239. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10240. shdr = (union lpfc_sli4_cfg_shdr *)
  10241. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10242. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10243. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10244. if (shdr_status || shdr_add_status || rc) {
  10245. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10246. "2510 RQ_DESTROY mailbox failed with "
  10247. "status x%x add_status x%x, mbx status x%x\n",
  10248. shdr_status, shdr_add_status, rc);
  10249. status = -ENXIO;
  10250. }
  10251. list_del_init(&hrq->list);
  10252. list_del_init(&drq->list);
  10253. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10254. return status;
  10255. }
  10256. /**
  10257. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10258. * @phba: The virtual port for which this call being executed.
  10259. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10260. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10261. * @xritag: the xritag that ties this io to the SGL pages.
  10262. *
  10263. * This routine will post the sgl pages for the IO that has the xritag
  10264. * that is in the iocbq structure. The xritag is assigned during iocbq
  10265. * creation and persists for as long as the driver is loaded.
  10266. * if the caller has fewer than 256 scatter gather segments to map then
  10267. * pdma_phys_addr1 should be 0.
  10268. * If the caller needs to map more than 256 scatter gather segment then
  10269. * pdma_phys_addr1 should be a valid physical address.
  10270. * physical address for SGLs must be 64 byte aligned.
  10271. * If you are going to map 2 SGL's then the first one must have 256 entries
  10272. * the second sgl can have between 1 and 256 entries.
  10273. *
  10274. * Return codes:
  10275. * 0 - Success
  10276. * -ENXIO, -ENOMEM - Failure
  10277. **/
  10278. int
  10279. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10280. dma_addr_t pdma_phys_addr0,
  10281. dma_addr_t pdma_phys_addr1,
  10282. uint16_t xritag)
  10283. {
  10284. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10285. LPFC_MBOXQ_t *mbox;
  10286. int rc;
  10287. uint32_t shdr_status, shdr_add_status;
  10288. union lpfc_sli4_cfg_shdr *shdr;
  10289. if (xritag == NO_XRI) {
  10290. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10291. "0364 Invalid param:\n");
  10292. return -EINVAL;
  10293. }
  10294. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10295. if (!mbox)
  10296. return -ENOMEM;
  10297. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10298. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10299. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10300. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  10301. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10302. &mbox->u.mqe.un.post_sgl_pages;
  10303. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10304. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10305. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10306. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10307. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10308. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10309. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10310. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10311. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10312. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10313. if (!phba->sli4_hba.intr_enable)
  10314. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10315. else
  10316. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10317. /* The IOCTL status is embedded in the mailbox subheader. */
  10318. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10319. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10320. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10321. if (rc != MBX_TIMEOUT)
  10322. mempool_free(mbox, phba->mbox_mem_pool);
  10323. if (shdr_status || shdr_add_status || rc) {
  10324. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10325. "2511 POST_SGL mailbox failed with "
  10326. "status x%x add_status x%x, mbx status x%x\n",
  10327. shdr_status, shdr_add_status, rc);
  10328. rc = -ENXIO;
  10329. }
  10330. return 0;
  10331. }
  10332. /**
  10333. * lpfc_sli4_next_xritag - Get an xritag for the io
  10334. * @phba: Pointer to HBA context object.
  10335. *
  10336. * This function gets an xritag for the iocb. If there is no unused xritag
  10337. * it will return 0xffff.
  10338. * The function returns the allocated xritag if successful, else returns zero.
  10339. * Zero is not a valid xritag.
  10340. * The caller is not required to hold any lock.
  10341. **/
  10342. uint16_t
  10343. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10344. {
  10345. uint16_t xritag;
  10346. spin_lock_irq(&phba->hbalock);
  10347. xritag = phba->sli4_hba.next_xri;
  10348. if ((xritag != (uint16_t) -1) && xritag <
  10349. (phba->sli4_hba.max_cfg_param.max_xri
  10350. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10351. phba->sli4_hba.next_xri++;
  10352. phba->sli4_hba.max_cfg_param.xri_used++;
  10353. spin_unlock_irq(&phba->hbalock);
  10354. return xritag;
  10355. }
  10356. spin_unlock_irq(&phba->hbalock);
  10357. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10358. "2004 Failed to allocate XRI.last XRITAG is %d"
  10359. " Max XRI is %d, Used XRI is %d\n",
  10360. phba->sli4_hba.next_xri,
  10361. phba->sli4_hba.max_cfg_param.max_xri,
  10362. phba->sli4_hba.max_cfg_param.xri_used);
  10363. return -1;
  10364. }
  10365. /**
  10366. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10367. * @phba: pointer to lpfc hba data structure.
  10368. *
  10369. * This routine is invoked to post a block of driver's sgl pages to the
  10370. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10371. * is only called when the driver is loading and after all IO has been
  10372. * stopped.
  10373. **/
  10374. int
  10375. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10376. {
  10377. struct lpfc_sglq *sglq_entry;
  10378. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10379. struct sgl_page_pairs *sgl_pg_pairs;
  10380. void *viraddr;
  10381. LPFC_MBOXQ_t *mbox;
  10382. uint32_t reqlen, alloclen, pg_pairs;
  10383. uint32_t mbox_tmo;
  10384. uint16_t xritag_start = 0;
  10385. int els_xri_cnt, rc = 0;
  10386. uint32_t shdr_status, shdr_add_status;
  10387. union lpfc_sli4_cfg_shdr *shdr;
  10388. /* The number of sgls to be posted */
  10389. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10390. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10391. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10392. if (reqlen > SLI4_PAGE_SIZE) {
  10393. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10394. "2559 Block sgl registration required DMA "
  10395. "size (%d) great than a page\n", reqlen);
  10396. return -ENOMEM;
  10397. }
  10398. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10399. if (!mbox) {
  10400. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10401. "2560 Failed to allocate mbox cmd memory\n");
  10402. return -ENOMEM;
  10403. }
  10404. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10405. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10406. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10407. LPFC_SLI4_MBX_NEMBED);
  10408. if (alloclen < reqlen) {
  10409. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10410. "0285 Allocated DMA memory size (%d) is "
  10411. "less than the requested DMA memory "
  10412. "size (%d)\n", alloclen, reqlen);
  10413. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10414. return -ENOMEM;
  10415. }
  10416. /* Get the first SGE entry from the non-embedded DMA memory */
  10417. viraddr = mbox->sge_array->addr[0];
  10418. /* Set up the SGL pages in the non-embedded DMA pages */
  10419. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10420. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10421. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10422. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10423. /* Set up the sge entry */
  10424. sgl_pg_pairs->sgl_pg0_addr_lo =
  10425. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10426. sgl_pg_pairs->sgl_pg0_addr_hi =
  10427. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10428. sgl_pg_pairs->sgl_pg1_addr_lo =
  10429. cpu_to_le32(putPaddrLow(0));
  10430. sgl_pg_pairs->sgl_pg1_addr_hi =
  10431. cpu_to_le32(putPaddrHigh(0));
  10432. /* Keep the first xritag on the list */
  10433. if (pg_pairs == 0)
  10434. xritag_start = sglq_entry->sli4_xritag;
  10435. sgl_pg_pairs++;
  10436. }
  10437. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10438. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10439. /* Perform endian conversion if necessary */
  10440. sgl->word0 = cpu_to_le32(sgl->word0);
  10441. if (!phba->sli4_hba.intr_enable)
  10442. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10443. else {
  10444. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10445. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10446. }
  10447. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10448. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10449. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10450. if (rc != MBX_TIMEOUT)
  10451. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10452. if (shdr_status || shdr_add_status || rc) {
  10453. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10454. "2513 POST_SGL_BLOCK mailbox command failed "
  10455. "status x%x add_status x%x mbx status x%x\n",
  10456. shdr_status, shdr_add_status, rc);
  10457. rc = -ENXIO;
  10458. }
  10459. return rc;
  10460. }
  10461. /**
  10462. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10463. * @phba: pointer to lpfc hba data structure.
  10464. * @sblist: pointer to scsi buffer list.
  10465. * @count: number of scsi buffers on the list.
  10466. *
  10467. * This routine is invoked to post a block of @count scsi sgl pages from a
  10468. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10469. * No Lock is held.
  10470. *
  10471. **/
  10472. int
  10473. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10474. int cnt)
  10475. {
  10476. struct lpfc_scsi_buf *psb;
  10477. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10478. struct sgl_page_pairs *sgl_pg_pairs;
  10479. void *viraddr;
  10480. LPFC_MBOXQ_t *mbox;
  10481. uint32_t reqlen, alloclen, pg_pairs;
  10482. uint32_t mbox_tmo;
  10483. uint16_t xritag_start = 0;
  10484. int rc = 0;
  10485. uint32_t shdr_status, shdr_add_status;
  10486. dma_addr_t pdma_phys_bpl1;
  10487. union lpfc_sli4_cfg_shdr *shdr;
  10488. /* Calculate the requested length of the dma memory */
  10489. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10490. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10491. if (reqlen > SLI4_PAGE_SIZE) {
  10492. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10493. "0217 Block sgl registration required DMA "
  10494. "size (%d) great than a page\n", reqlen);
  10495. return -ENOMEM;
  10496. }
  10497. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10498. if (!mbox) {
  10499. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10500. "0283 Failed to allocate mbox cmd memory\n");
  10501. return -ENOMEM;
  10502. }
  10503. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10504. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10505. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10506. LPFC_SLI4_MBX_NEMBED);
  10507. if (alloclen < reqlen) {
  10508. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10509. "2561 Allocated DMA memory size (%d) is "
  10510. "less than the requested DMA memory "
  10511. "size (%d)\n", alloclen, reqlen);
  10512. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10513. return -ENOMEM;
  10514. }
  10515. /* Get the first SGE entry from the non-embedded DMA memory */
  10516. viraddr = mbox->sge_array->addr[0];
  10517. /* Set up the SGL pages in the non-embedded DMA pages */
  10518. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10519. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10520. pg_pairs = 0;
  10521. list_for_each_entry(psb, sblist, list) {
  10522. /* Set up the sge entry */
  10523. sgl_pg_pairs->sgl_pg0_addr_lo =
  10524. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10525. sgl_pg_pairs->sgl_pg0_addr_hi =
  10526. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10527. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10528. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10529. else
  10530. pdma_phys_bpl1 = 0;
  10531. sgl_pg_pairs->sgl_pg1_addr_lo =
  10532. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10533. sgl_pg_pairs->sgl_pg1_addr_hi =
  10534. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10535. /* Keep the first xritag on the list */
  10536. if (pg_pairs == 0)
  10537. xritag_start = psb->cur_iocbq.sli4_xritag;
  10538. sgl_pg_pairs++;
  10539. pg_pairs++;
  10540. }
  10541. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10542. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10543. /* Perform endian conversion if necessary */
  10544. sgl->word0 = cpu_to_le32(sgl->word0);
  10545. if (!phba->sli4_hba.intr_enable)
  10546. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10547. else {
  10548. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10549. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10550. }
  10551. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10552. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10553. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10554. if (rc != MBX_TIMEOUT)
  10555. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10556. if (shdr_status || shdr_add_status || rc) {
  10557. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10558. "2564 POST_SGL_BLOCK mailbox command failed "
  10559. "status x%x add_status x%x mbx status x%x\n",
  10560. shdr_status, shdr_add_status, rc);
  10561. rc = -ENXIO;
  10562. }
  10563. return rc;
  10564. }
  10565. /**
  10566. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10567. * @phba: pointer to lpfc_hba struct that the frame was received on
  10568. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10569. *
  10570. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10571. * valid type of frame that the LPFC driver will handle. This function will
  10572. * return a zero if the frame is a valid frame or a non zero value when the
  10573. * frame does not pass the check.
  10574. **/
  10575. static int
  10576. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10577. {
  10578. /* make rctl_names static to save stack space */
  10579. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10580. char *type_names[] = FC_TYPE_NAMES_INIT;
  10581. struct fc_vft_header *fc_vft_hdr;
  10582. switch (fc_hdr->fh_r_ctl) {
  10583. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10584. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10585. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10586. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10587. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10588. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10589. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10590. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10591. case FC_RCTL_ELS_REQ: /* extended link services request */
  10592. case FC_RCTL_ELS_REP: /* extended link services reply */
  10593. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10594. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10595. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10596. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10597. case FC_RCTL_BA_RMC: /* remove connection */
  10598. case FC_RCTL_BA_ACC: /* basic accept */
  10599. case FC_RCTL_BA_RJT: /* basic reject */
  10600. case FC_RCTL_BA_PRMT:
  10601. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10602. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10603. case FC_RCTL_P_RJT: /* port reject */
  10604. case FC_RCTL_F_RJT: /* fabric reject */
  10605. case FC_RCTL_P_BSY: /* port busy */
  10606. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10607. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10608. case FC_RCTL_LCR: /* link credit reset */
  10609. case FC_RCTL_END: /* end */
  10610. break;
  10611. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10612. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10613. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10614. return lpfc_fc_frame_check(phba, fc_hdr);
  10615. default:
  10616. goto drop;
  10617. }
  10618. switch (fc_hdr->fh_type) {
  10619. case FC_TYPE_BLS:
  10620. case FC_TYPE_ELS:
  10621. case FC_TYPE_FCP:
  10622. case FC_TYPE_CT:
  10623. break;
  10624. case FC_TYPE_IP:
  10625. case FC_TYPE_ILS:
  10626. default:
  10627. goto drop;
  10628. }
  10629. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10630. "2538 Received frame rctl:%s type:%s\n",
  10631. rctl_names[fc_hdr->fh_r_ctl],
  10632. type_names[fc_hdr->fh_type]);
  10633. return 0;
  10634. drop:
  10635. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10636. "2539 Dropped frame rctl:%s type:%s\n",
  10637. rctl_names[fc_hdr->fh_r_ctl],
  10638. type_names[fc_hdr->fh_type]);
  10639. return 1;
  10640. }
  10641. /**
  10642. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10643. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10644. *
  10645. * This function processes the FC header to retrieve the VFI from the VF
  10646. * header, if one exists. This function will return the VFI if one exists
  10647. * or 0 if no VSAN Header exists.
  10648. **/
  10649. static uint32_t
  10650. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10651. {
  10652. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10653. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10654. return 0;
  10655. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10656. }
  10657. /**
  10658. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10659. * @phba: Pointer to the HBA structure to search for the vport on
  10660. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10661. * @fcfi: The FC Fabric ID that the frame came from
  10662. *
  10663. * This function searches the @phba for a vport that matches the content of the
  10664. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10665. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10666. * returns the matching vport pointer or NULL if unable to match frame to a
  10667. * vport.
  10668. **/
  10669. static struct lpfc_vport *
  10670. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10671. uint16_t fcfi)
  10672. {
  10673. struct lpfc_vport **vports;
  10674. struct lpfc_vport *vport = NULL;
  10675. int i;
  10676. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10677. fc_hdr->fh_d_id[1] << 8 |
  10678. fc_hdr->fh_d_id[2]);
  10679. vports = lpfc_create_vport_work_array(phba);
  10680. if (vports != NULL)
  10681. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10682. if (phba->fcf.fcfi == fcfi &&
  10683. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10684. vports[i]->fc_myDID == did) {
  10685. vport = vports[i];
  10686. break;
  10687. }
  10688. }
  10689. lpfc_destroy_vport_work_array(phba, vports);
  10690. return vport;
  10691. }
  10692. /**
  10693. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10694. * @vport: The vport to work on.
  10695. *
  10696. * This function updates the receive sequence time stamp for this vport. The
  10697. * receive sequence time stamp indicates the time that the last frame of the
  10698. * the sequence that has been idle for the longest amount of time was received.
  10699. * the driver uses this time stamp to indicate if any received sequences have
  10700. * timed out.
  10701. **/
  10702. void
  10703. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10704. {
  10705. struct lpfc_dmabuf *h_buf;
  10706. struct hbq_dmabuf *dmabuf = NULL;
  10707. /* get the oldest sequence on the rcv list */
  10708. h_buf = list_get_first(&vport->rcv_buffer_list,
  10709. struct lpfc_dmabuf, list);
  10710. if (!h_buf)
  10711. return;
  10712. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10713. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10714. }
  10715. /**
  10716. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10717. * @vport: The vport that the received sequences were sent to.
  10718. *
  10719. * This function cleans up all outstanding received sequences. This is called
  10720. * by the driver when a link event or user action invalidates all the received
  10721. * sequences.
  10722. **/
  10723. void
  10724. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10725. {
  10726. struct lpfc_dmabuf *h_buf, *hnext;
  10727. struct lpfc_dmabuf *d_buf, *dnext;
  10728. struct hbq_dmabuf *dmabuf = NULL;
  10729. /* start with the oldest sequence on the rcv list */
  10730. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10731. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10732. list_del_init(&dmabuf->hbuf.list);
  10733. list_for_each_entry_safe(d_buf, dnext,
  10734. &dmabuf->dbuf.list, list) {
  10735. list_del_init(&d_buf->list);
  10736. lpfc_in_buf_free(vport->phba, d_buf);
  10737. }
  10738. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10739. }
  10740. }
  10741. /**
  10742. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10743. * @vport: The vport that the received sequences were sent to.
  10744. *
  10745. * This function determines whether any received sequences have timed out by
  10746. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10747. * indicates that there is at least one timed out sequence this routine will
  10748. * go through the received sequences one at a time from most inactive to most
  10749. * active to determine which ones need to be cleaned up. Once it has determined
  10750. * that a sequence needs to be cleaned up it will simply free up the resources
  10751. * without sending an abort.
  10752. **/
  10753. void
  10754. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10755. {
  10756. struct lpfc_dmabuf *h_buf, *hnext;
  10757. struct lpfc_dmabuf *d_buf, *dnext;
  10758. struct hbq_dmabuf *dmabuf = NULL;
  10759. unsigned long timeout;
  10760. int abort_count = 0;
  10761. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10762. vport->rcv_buffer_time_stamp);
  10763. if (list_empty(&vport->rcv_buffer_list) ||
  10764. time_before(jiffies, timeout))
  10765. return;
  10766. /* start with the oldest sequence on the rcv list */
  10767. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10768. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10769. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10770. dmabuf->time_stamp);
  10771. if (time_before(jiffies, timeout))
  10772. break;
  10773. abort_count++;
  10774. list_del_init(&dmabuf->hbuf.list);
  10775. list_for_each_entry_safe(d_buf, dnext,
  10776. &dmabuf->dbuf.list, list) {
  10777. list_del_init(&d_buf->list);
  10778. lpfc_in_buf_free(vport->phba, d_buf);
  10779. }
  10780. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10781. }
  10782. if (abort_count)
  10783. lpfc_update_rcv_time_stamp(vport);
  10784. }
  10785. /**
  10786. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10787. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10788. *
  10789. * This function searches through the existing incomplete sequences that have
  10790. * been sent to this @vport. If the frame matches one of the incomplete
  10791. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10792. * make up that sequence. If no sequence is found that matches this frame then
  10793. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10794. * This function returns a pointer to the first dmabuf in the sequence list that
  10795. * the frame was linked to.
  10796. **/
  10797. static struct hbq_dmabuf *
  10798. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10799. {
  10800. struct fc_frame_header *new_hdr;
  10801. struct fc_frame_header *temp_hdr;
  10802. struct lpfc_dmabuf *d_buf;
  10803. struct lpfc_dmabuf *h_buf;
  10804. struct hbq_dmabuf *seq_dmabuf = NULL;
  10805. struct hbq_dmabuf *temp_dmabuf = NULL;
  10806. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10807. dmabuf->time_stamp = jiffies;
  10808. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10809. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10810. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10811. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10812. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10813. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10814. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10815. continue;
  10816. /* found a pending sequence that matches this frame */
  10817. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10818. break;
  10819. }
  10820. if (!seq_dmabuf) {
  10821. /*
  10822. * This indicates first frame received for this sequence.
  10823. * Queue the buffer on the vport's rcv_buffer_list.
  10824. */
  10825. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10826. lpfc_update_rcv_time_stamp(vport);
  10827. return dmabuf;
  10828. }
  10829. temp_hdr = seq_dmabuf->hbuf.virt;
  10830. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10831. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10832. list_del_init(&seq_dmabuf->hbuf.list);
  10833. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10834. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10835. lpfc_update_rcv_time_stamp(vport);
  10836. return dmabuf;
  10837. }
  10838. /* move this sequence to the tail to indicate a young sequence */
  10839. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10840. seq_dmabuf->time_stamp = jiffies;
  10841. lpfc_update_rcv_time_stamp(vport);
  10842. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10843. temp_hdr = dmabuf->hbuf.virt;
  10844. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10845. return seq_dmabuf;
  10846. }
  10847. /* find the correct place in the sequence to insert this frame */
  10848. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10849. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10850. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10851. /*
  10852. * If the frame's sequence count is greater than the frame on
  10853. * the list then insert the frame right after this frame
  10854. */
  10855. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10856. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10857. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10858. return seq_dmabuf;
  10859. }
  10860. }
  10861. return NULL;
  10862. }
  10863. /**
  10864. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10865. * @vport: pointer to a vitural port
  10866. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10867. *
  10868. * This function tries to abort from the partially assembed sequence, described
  10869. * by the information from basic abbort @dmabuf. It checks to see whether such
  10870. * partially assembled sequence held by the driver. If so, it shall free up all
  10871. * the frames from the partially assembled sequence.
  10872. *
  10873. * Return
  10874. * true -- if there is matching partially assembled sequence present and all
  10875. * the frames freed with the sequence;
  10876. * false -- if there is no matching partially assembled sequence present so
  10877. * nothing got aborted in the lower layer driver
  10878. **/
  10879. static bool
  10880. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10881. struct hbq_dmabuf *dmabuf)
  10882. {
  10883. struct fc_frame_header *new_hdr;
  10884. struct fc_frame_header *temp_hdr;
  10885. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10886. struct hbq_dmabuf *seq_dmabuf = NULL;
  10887. /* Use the hdr_buf to find the sequence that matches this frame */
  10888. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10889. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10890. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10891. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10892. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10893. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10894. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10895. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10896. continue;
  10897. /* found a pending sequence that matches this frame */
  10898. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10899. break;
  10900. }
  10901. /* Free up all the frames from the partially assembled sequence */
  10902. if (seq_dmabuf) {
  10903. list_for_each_entry_safe(d_buf, n_buf,
  10904. &seq_dmabuf->dbuf.list, list) {
  10905. list_del_init(&d_buf->list);
  10906. lpfc_in_buf_free(vport->phba, d_buf);
  10907. }
  10908. return true;
  10909. }
  10910. return false;
  10911. }
  10912. /**
  10913. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10914. * @phba: Pointer to HBA context object.
  10915. * @cmd_iocbq: pointer to the command iocbq structure.
  10916. * @rsp_iocbq: pointer to the response iocbq structure.
  10917. *
  10918. * This function handles the sequence abort accept iocb command complete
  10919. * event. It properly releases the memory allocated to the sequence abort
  10920. * accept iocb.
  10921. **/
  10922. static void
  10923. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10924. struct lpfc_iocbq *cmd_iocbq,
  10925. struct lpfc_iocbq *rsp_iocbq)
  10926. {
  10927. if (cmd_iocbq)
  10928. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10929. }
  10930. /**
  10931. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10932. * @phba: Pointer to HBA context object.
  10933. * @fc_hdr: pointer to a FC frame header.
  10934. *
  10935. * This function sends a basic accept to a previous unsol sequence abort
  10936. * event after aborting the sequence handling.
  10937. **/
  10938. static void
  10939. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10940. struct fc_frame_header *fc_hdr)
  10941. {
  10942. struct lpfc_iocbq *ctiocb = NULL;
  10943. struct lpfc_nodelist *ndlp;
  10944. uint16_t oxid, rxid;
  10945. uint32_t sid, fctl;
  10946. IOCB_t *icmd;
  10947. if (!lpfc_is_link_up(phba))
  10948. return;
  10949. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10950. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10951. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10952. ndlp = lpfc_findnode_did(phba->pport, sid);
  10953. if (!ndlp) {
  10954. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10955. "1268 Find ndlp returned NULL for oxid:x%x "
  10956. "SID:x%x\n", oxid, sid);
  10957. return;
  10958. }
  10959. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  10960. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  10961. + phba->sli4_hba.max_cfg_param.xri_base))
  10962. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  10963. /* Allocate buffer for acc iocb */
  10964. ctiocb = lpfc_sli_get_iocbq(phba);
  10965. if (!ctiocb)
  10966. return;
  10967. /* Extract the F_CTL field from FC_HDR */
  10968. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10969. icmd = &ctiocb->iocb;
  10970. icmd->un.xseq64.bdl.bdeSize = 0;
  10971. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10972. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10973. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10974. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10975. /* Fill in the rest of iocb fields */
  10976. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10977. icmd->ulpBdeCount = 0;
  10978. icmd->ulpLe = 1;
  10979. icmd->ulpClass = CLASS3;
  10980. icmd->ulpContext = ndlp->nlp_rpi;
  10981. ctiocb->context1 = ndlp;
  10982. ctiocb->iocb_cmpl = NULL;
  10983. ctiocb->vport = phba->pport;
  10984. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10985. if (fctl & FC_FC_EX_CTX) {
  10986. /* ABTS sent by responder to CT exchange, construction
  10987. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10988. * field and RX_ID from ABTS for RX_ID field.
  10989. */
  10990. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10991. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10992. ctiocb->sli4_xritag = oxid;
  10993. } else {
  10994. /* ABTS sent by initiator to CT exchange, construction
  10995. * of BA_ACC will need to allocate a new XRI as for the
  10996. * XRI_TAG and RX_ID fields.
  10997. */
  10998. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10999. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  11000. ctiocb->sli4_xritag = NO_XRI;
  11001. }
  11002. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  11003. /* Xmit CT abts accept on exchange <xid> */
  11004. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11005. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  11006. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  11007. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  11008. }
  11009. /**
  11010. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  11011. * @vport: Pointer to the vport on which this sequence was received
  11012. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11013. *
  11014. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  11015. * receive sequence is only partially assembed by the driver, it shall abort
  11016. * the partially assembled frames for the sequence. Otherwise, if the
  11017. * unsolicited receive sequence has been completely assembled and passed to
  11018. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  11019. * unsolicited sequence has been aborted. After that, it will issue a basic
  11020. * accept to accept the abort.
  11021. **/
  11022. void
  11023. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  11024. struct hbq_dmabuf *dmabuf)
  11025. {
  11026. struct lpfc_hba *phba = vport->phba;
  11027. struct fc_frame_header fc_hdr;
  11028. uint32_t fctl;
  11029. bool abts_par;
  11030. /* Make a copy of fc_hdr before the dmabuf being released */
  11031. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11032. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11033. if (fctl & FC_FC_EX_CTX) {
  11034. /*
  11035. * ABTS sent by responder to exchange, just free the buffer
  11036. */
  11037. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11038. } else {
  11039. /*
  11040. * ABTS sent by initiator to exchange, need to do cleanup
  11041. */
  11042. /* Try to abort partially assembled seq */
  11043. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11044. /* Send abort to ULP if partially seq abort failed */
  11045. if (abts_par == false)
  11046. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11047. else
  11048. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11049. }
  11050. /* Send basic accept (BA_ACC) to the abort requester */
  11051. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  11052. }
  11053. /**
  11054. * lpfc_seq_complete - Indicates if a sequence is complete
  11055. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11056. *
  11057. * This function checks the sequence, starting with the frame described by
  11058. * @dmabuf, to see if all the frames associated with this sequence are present.
  11059. * the frames associated with this sequence are linked to the @dmabuf using the
  11060. * dbuf list. This function looks for two major things. 1) That the first frame
  11061. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11062. * set. 3) That there are no holes in the sequence count. The function will
  11063. * return 1 when the sequence is complete, otherwise it will return 0.
  11064. **/
  11065. static int
  11066. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11067. {
  11068. struct fc_frame_header *hdr;
  11069. struct lpfc_dmabuf *d_buf;
  11070. struct hbq_dmabuf *seq_dmabuf;
  11071. uint32_t fctl;
  11072. int seq_count = 0;
  11073. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11074. /* make sure first fame of sequence has a sequence count of zero */
  11075. if (hdr->fh_seq_cnt != seq_count)
  11076. return 0;
  11077. fctl = (hdr->fh_f_ctl[0] << 16 |
  11078. hdr->fh_f_ctl[1] << 8 |
  11079. hdr->fh_f_ctl[2]);
  11080. /* If last frame of sequence we can return success. */
  11081. if (fctl & FC_FC_END_SEQ)
  11082. return 1;
  11083. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11084. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11085. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11086. /* If there is a hole in the sequence count then fail. */
  11087. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11088. return 0;
  11089. fctl = (hdr->fh_f_ctl[0] << 16 |
  11090. hdr->fh_f_ctl[1] << 8 |
  11091. hdr->fh_f_ctl[2]);
  11092. /* If last frame of sequence we can return success. */
  11093. if (fctl & FC_FC_END_SEQ)
  11094. return 1;
  11095. }
  11096. return 0;
  11097. }
  11098. /**
  11099. * lpfc_prep_seq - Prep sequence for ULP processing
  11100. * @vport: Pointer to the vport on which this sequence was received
  11101. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11102. *
  11103. * This function takes a sequence, described by a list of frames, and creates
  11104. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11105. * used to issue to the generic unsolicited sequence handler. This routine
  11106. * returns a pointer to the first iocbq in the list. If the function is unable
  11107. * to allocate an iocbq then it throw out the received frames that were not
  11108. * able to be described and return a pointer to the first iocbq. If unable to
  11109. * allocate any iocbqs (including the first) this function will return NULL.
  11110. **/
  11111. static struct lpfc_iocbq *
  11112. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11113. {
  11114. struct lpfc_dmabuf *d_buf, *n_buf;
  11115. struct lpfc_iocbq *first_iocbq, *iocbq;
  11116. struct fc_frame_header *fc_hdr;
  11117. uint32_t sid;
  11118. struct ulp_bde64 *pbde;
  11119. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11120. /* remove from receive buffer list */
  11121. list_del_init(&seq_dmabuf->hbuf.list);
  11122. lpfc_update_rcv_time_stamp(vport);
  11123. /* get the Remote Port's SID */
  11124. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11125. /* Get an iocbq struct to fill in. */
  11126. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11127. if (first_iocbq) {
  11128. /* Initialize the first IOCB. */
  11129. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11130. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11131. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11132. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11133. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11134. vport->vpi + vport->phba->vpi_base;
  11135. /* put the first buffer into the first IOCBq */
  11136. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11137. first_iocbq->context3 = NULL;
  11138. first_iocbq->iocb.ulpBdeCount = 1;
  11139. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11140. LPFC_DATA_BUF_SIZE;
  11141. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11142. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11143. bf_get(lpfc_rcqe_length,
  11144. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11145. }
  11146. iocbq = first_iocbq;
  11147. /*
  11148. * Each IOCBq can have two Buffers assigned, so go through the list
  11149. * of buffers for this sequence and save two buffers in each IOCBq
  11150. */
  11151. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11152. if (!iocbq) {
  11153. lpfc_in_buf_free(vport->phba, d_buf);
  11154. continue;
  11155. }
  11156. if (!iocbq->context3) {
  11157. iocbq->context3 = d_buf;
  11158. iocbq->iocb.ulpBdeCount++;
  11159. pbde = (struct ulp_bde64 *)
  11160. &iocbq->iocb.unsli3.sli3Words[4];
  11161. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11162. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11163. bf_get(lpfc_rcqe_length,
  11164. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11165. } else {
  11166. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11167. if (!iocbq) {
  11168. if (first_iocbq) {
  11169. first_iocbq->iocb.ulpStatus =
  11170. IOSTAT_FCP_RSP_ERROR;
  11171. first_iocbq->iocb.un.ulpWord[4] =
  11172. IOERR_NO_RESOURCES;
  11173. }
  11174. lpfc_in_buf_free(vport->phba, d_buf);
  11175. continue;
  11176. }
  11177. iocbq->context2 = d_buf;
  11178. iocbq->context3 = NULL;
  11179. iocbq->iocb.ulpBdeCount = 1;
  11180. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11181. LPFC_DATA_BUF_SIZE;
  11182. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11183. bf_get(lpfc_rcqe_length,
  11184. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11185. iocbq->iocb.un.rcvels.remoteID = sid;
  11186. list_add_tail(&iocbq->list, &first_iocbq->list);
  11187. }
  11188. }
  11189. return first_iocbq;
  11190. }
  11191. static void
  11192. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11193. struct hbq_dmabuf *seq_dmabuf)
  11194. {
  11195. struct fc_frame_header *fc_hdr;
  11196. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11197. struct lpfc_hba *phba = vport->phba;
  11198. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11199. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11200. if (!iocbq) {
  11201. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11202. "2707 Ring %d handler: Failed to allocate "
  11203. "iocb Rctl x%x Type x%x received\n",
  11204. LPFC_ELS_RING,
  11205. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11206. return;
  11207. }
  11208. if (!lpfc_complete_unsol_iocb(phba,
  11209. &phba->sli.ring[LPFC_ELS_RING],
  11210. iocbq, fc_hdr->fh_r_ctl,
  11211. fc_hdr->fh_type))
  11212. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11213. "2540 Ring %d handler: unexpected Rctl "
  11214. "x%x Type x%x received\n",
  11215. LPFC_ELS_RING,
  11216. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11217. /* Free iocb created in lpfc_prep_seq */
  11218. list_for_each_entry_safe(curr_iocb, next_iocb,
  11219. &iocbq->list, list) {
  11220. list_del_init(&curr_iocb->list);
  11221. lpfc_sli_release_iocbq(phba, curr_iocb);
  11222. }
  11223. lpfc_sli_release_iocbq(phba, iocbq);
  11224. }
  11225. /**
  11226. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11227. * @phba: Pointer to HBA context object.
  11228. *
  11229. * This function is called with no lock held. This function processes all
  11230. * the received buffers and gives it to upper layers when a received buffer
  11231. * indicates that it is the final frame in the sequence. The interrupt
  11232. * service routine processes received buffers at interrupt contexts and adds
  11233. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11234. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11235. * appropriate receive function when the final frame in a sequence is received.
  11236. **/
  11237. void
  11238. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11239. struct hbq_dmabuf *dmabuf)
  11240. {
  11241. struct hbq_dmabuf *seq_dmabuf;
  11242. struct fc_frame_header *fc_hdr;
  11243. struct lpfc_vport *vport;
  11244. uint32_t fcfi;
  11245. /* Process each received buffer */
  11246. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11247. /* check to see if this a valid type of frame */
  11248. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11249. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11250. return;
  11251. }
  11252. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11253. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11254. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11255. /* throw out the frame */
  11256. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11257. return;
  11258. }
  11259. /* Handle the basic abort sequence (BA_ABTS) event */
  11260. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11261. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11262. return;
  11263. }
  11264. /* Link this frame */
  11265. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11266. if (!seq_dmabuf) {
  11267. /* unable to add frame to vport - throw it out */
  11268. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11269. return;
  11270. }
  11271. /* If not last frame in sequence continue processing frames. */
  11272. if (!lpfc_seq_complete(seq_dmabuf))
  11273. return;
  11274. /* Send the complete sequence to the upper layer protocol */
  11275. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11276. }
  11277. /**
  11278. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11279. * @phba: pointer to lpfc hba data structure.
  11280. *
  11281. * This routine is invoked to post rpi header templates to the
  11282. * HBA consistent with the SLI-4 interface spec. This routine
  11283. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11284. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11285. *
  11286. * This routine does not require any locks. It's usage is expected
  11287. * to be driver load or reset recovery when the driver is
  11288. * sequential.
  11289. *
  11290. * Return codes
  11291. * 0 - successful
  11292. * -EIO - The mailbox failed to complete successfully.
  11293. * When this error occurs, the driver is not guaranteed
  11294. * to have any rpi regions posted to the device and
  11295. * must either attempt to repost the regions or take a
  11296. * fatal error.
  11297. **/
  11298. int
  11299. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11300. {
  11301. struct lpfc_rpi_hdr *rpi_page;
  11302. uint32_t rc = 0;
  11303. /* Post all rpi memory regions to the port. */
  11304. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11305. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11306. if (rc != MBX_SUCCESS) {
  11307. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11308. "2008 Error %d posting all rpi "
  11309. "headers\n", rc);
  11310. rc = -EIO;
  11311. break;
  11312. }
  11313. }
  11314. return rc;
  11315. }
  11316. /**
  11317. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11318. * @phba: pointer to lpfc hba data structure.
  11319. * @rpi_page: pointer to the rpi memory region.
  11320. *
  11321. * This routine is invoked to post a single rpi header to the
  11322. * HBA consistent with the SLI-4 interface spec. This memory region
  11323. * maps up to 64 rpi context regions.
  11324. *
  11325. * Return codes
  11326. * 0 - successful
  11327. * -ENOMEM - No available memory
  11328. * -EIO - The mailbox failed to complete successfully.
  11329. **/
  11330. int
  11331. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11332. {
  11333. LPFC_MBOXQ_t *mboxq;
  11334. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11335. uint32_t rc = 0;
  11336. uint32_t mbox_tmo;
  11337. uint32_t shdr_status, shdr_add_status;
  11338. union lpfc_sli4_cfg_shdr *shdr;
  11339. /* The port is notified of the header region via a mailbox command. */
  11340. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11341. if (!mboxq) {
  11342. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11343. "2001 Unable to allocate memory for issuing "
  11344. "SLI_CONFIG_SPECIAL mailbox command\n");
  11345. return -ENOMEM;
  11346. }
  11347. /* Post all rpi memory regions to the port. */
  11348. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11349. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11350. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11351. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11352. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11353. sizeof(struct lpfc_sli4_cfg_mhdr),
  11354. LPFC_SLI4_MBX_EMBED);
  11355. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11356. hdr_tmpl, rpi_page->page_count);
  11357. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11358. rpi_page->start_rpi);
  11359. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11360. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11361. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11362. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11363. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11364. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11365. if (rc != MBX_TIMEOUT)
  11366. mempool_free(mboxq, phba->mbox_mem_pool);
  11367. if (shdr_status || shdr_add_status || rc) {
  11368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11369. "2514 POST_RPI_HDR mailbox failed with "
  11370. "status x%x add_status x%x, mbx status x%x\n",
  11371. shdr_status, shdr_add_status, rc);
  11372. rc = -ENXIO;
  11373. }
  11374. return rc;
  11375. }
  11376. /**
  11377. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11378. * @phba: pointer to lpfc hba data structure.
  11379. *
  11380. * This routine is invoked to post rpi header templates to the
  11381. * HBA consistent with the SLI-4 interface spec. This routine
  11382. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11383. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11384. *
  11385. * Returns
  11386. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11387. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11388. **/
  11389. int
  11390. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11391. {
  11392. int rpi;
  11393. uint16_t max_rpi, rpi_base, rpi_limit;
  11394. uint16_t rpi_remaining;
  11395. struct lpfc_rpi_hdr *rpi_hdr;
  11396. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11397. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11398. rpi_limit = phba->sli4_hba.next_rpi;
  11399. /*
  11400. * The valid rpi range is not guaranteed to be zero-based. Start
  11401. * the search at the rpi_base as reported by the port.
  11402. */
  11403. spin_lock_irq(&phba->hbalock);
  11404. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11405. if (rpi >= rpi_limit || rpi < rpi_base)
  11406. rpi = LPFC_RPI_ALLOC_ERROR;
  11407. else {
  11408. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11409. phba->sli4_hba.max_cfg_param.rpi_used++;
  11410. phba->sli4_hba.rpi_count++;
  11411. }
  11412. /*
  11413. * Don't try to allocate more rpi header regions if the device limit
  11414. * on available rpis max has been exhausted.
  11415. */
  11416. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11417. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11418. spin_unlock_irq(&phba->hbalock);
  11419. return rpi;
  11420. }
  11421. /*
  11422. * If the driver is running low on rpi resources, allocate another
  11423. * page now. Note that the next_rpi value is used because
  11424. * it represents how many are actually in use whereas max_rpi notes
  11425. * how many are supported max by the device.
  11426. */
  11427. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11428. phba->sli4_hba.rpi_count;
  11429. spin_unlock_irq(&phba->hbalock);
  11430. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11431. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11432. if (!rpi_hdr) {
  11433. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11434. "2002 Error Could not grow rpi "
  11435. "count\n");
  11436. } else {
  11437. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11438. }
  11439. }
  11440. return rpi;
  11441. }
  11442. /**
  11443. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11444. * @phba: pointer to lpfc hba data structure.
  11445. *
  11446. * This routine is invoked to release an rpi to the pool of
  11447. * available rpis maintained by the driver.
  11448. **/
  11449. void
  11450. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11451. {
  11452. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11453. phba->sli4_hba.rpi_count--;
  11454. phba->sli4_hba.max_cfg_param.rpi_used--;
  11455. }
  11456. }
  11457. /**
  11458. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11459. * @phba: pointer to lpfc hba data structure.
  11460. *
  11461. * This routine is invoked to release an rpi to the pool of
  11462. * available rpis maintained by the driver.
  11463. **/
  11464. void
  11465. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11466. {
  11467. spin_lock_irq(&phba->hbalock);
  11468. __lpfc_sli4_free_rpi(phba, rpi);
  11469. spin_unlock_irq(&phba->hbalock);
  11470. }
  11471. /**
  11472. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11473. * @phba: pointer to lpfc hba data structure.
  11474. *
  11475. * This routine is invoked to remove the memory region that
  11476. * provided rpi via a bitmask.
  11477. **/
  11478. void
  11479. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11480. {
  11481. kfree(phba->sli4_hba.rpi_bmask);
  11482. }
  11483. /**
  11484. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11485. * @phba: pointer to lpfc hba data structure.
  11486. *
  11487. * This routine is invoked to remove the memory region that
  11488. * provided rpi via a bitmask.
  11489. **/
  11490. int
  11491. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11492. {
  11493. LPFC_MBOXQ_t *mboxq;
  11494. struct lpfc_hba *phba = ndlp->phba;
  11495. int rc;
  11496. /* The port is notified of the header region via a mailbox command. */
  11497. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11498. if (!mboxq)
  11499. return -ENOMEM;
  11500. /* Post all rpi memory regions to the port. */
  11501. lpfc_resume_rpi(mboxq, ndlp);
  11502. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11503. if (rc == MBX_NOT_FINISHED) {
  11504. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11505. "2010 Resume RPI Mailbox failed "
  11506. "status %d, mbxStatus x%x\n", rc,
  11507. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11508. mempool_free(mboxq, phba->mbox_mem_pool);
  11509. return -EIO;
  11510. }
  11511. return 0;
  11512. }
  11513. /**
  11514. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11515. * @vport: Pointer to the vport for which the vpi is being initialized
  11516. *
  11517. * This routine is invoked to activate a vpi with the port.
  11518. *
  11519. * Returns:
  11520. * 0 success
  11521. * -Evalue otherwise
  11522. **/
  11523. int
  11524. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11525. {
  11526. LPFC_MBOXQ_t *mboxq;
  11527. int rc = 0;
  11528. int retval = MBX_SUCCESS;
  11529. uint32_t mbox_tmo;
  11530. struct lpfc_hba *phba = vport->phba;
  11531. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11532. if (!mboxq)
  11533. return -ENOMEM;
  11534. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11535. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11536. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11537. if (rc != MBX_SUCCESS) {
  11538. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11539. "2022 INIT VPI Mailbox failed "
  11540. "status %d, mbxStatus x%x\n", rc,
  11541. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11542. retval = -EIO;
  11543. }
  11544. if (rc != MBX_TIMEOUT)
  11545. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11546. return retval;
  11547. }
  11548. /**
  11549. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11550. * @phba: pointer to lpfc hba data structure.
  11551. * @mboxq: Pointer to mailbox object.
  11552. *
  11553. * This routine is invoked to manually add a single FCF record. The caller
  11554. * must pass a completely initialized FCF_Record. This routine takes
  11555. * care of the nonembedded mailbox operations.
  11556. **/
  11557. static void
  11558. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11559. {
  11560. void *virt_addr;
  11561. union lpfc_sli4_cfg_shdr *shdr;
  11562. uint32_t shdr_status, shdr_add_status;
  11563. virt_addr = mboxq->sge_array->addr[0];
  11564. /* The IOCTL status is embedded in the mailbox subheader. */
  11565. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11566. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11567. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11568. if ((shdr_status || shdr_add_status) &&
  11569. (shdr_status != STATUS_FCF_IN_USE))
  11570. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11571. "2558 ADD_FCF_RECORD mailbox failed with "
  11572. "status x%x add_status x%x\n",
  11573. shdr_status, shdr_add_status);
  11574. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11575. }
  11576. /**
  11577. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11578. * @phba: pointer to lpfc hba data structure.
  11579. * @fcf_record: pointer to the initialized fcf record to add.
  11580. *
  11581. * This routine is invoked to manually add a single FCF record. The caller
  11582. * must pass a completely initialized FCF_Record. This routine takes
  11583. * care of the nonembedded mailbox operations.
  11584. **/
  11585. int
  11586. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11587. {
  11588. int rc = 0;
  11589. LPFC_MBOXQ_t *mboxq;
  11590. uint8_t *bytep;
  11591. void *virt_addr;
  11592. dma_addr_t phys_addr;
  11593. struct lpfc_mbx_sge sge;
  11594. uint32_t alloc_len, req_len;
  11595. uint32_t fcfindex;
  11596. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11597. if (!mboxq) {
  11598. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11599. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11600. return -ENOMEM;
  11601. }
  11602. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11603. sizeof(uint32_t);
  11604. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11605. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11606. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11607. req_len, LPFC_SLI4_MBX_NEMBED);
  11608. if (alloc_len < req_len) {
  11609. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11610. "2523 Allocated DMA memory size (x%x) is "
  11611. "less than the requested DMA memory "
  11612. "size (x%x)\n", alloc_len, req_len);
  11613. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11614. return -ENOMEM;
  11615. }
  11616. /*
  11617. * Get the first SGE entry from the non-embedded DMA memory. This
  11618. * routine only uses a single SGE.
  11619. */
  11620. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11621. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11622. virt_addr = mboxq->sge_array->addr[0];
  11623. /*
  11624. * Configure the FCF record for FCFI 0. This is the driver's
  11625. * hardcoded default and gets used in nonFIP mode.
  11626. */
  11627. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11628. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11629. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11630. /*
  11631. * Copy the fcf_index and the FCF Record Data. The data starts after
  11632. * the FCoE header plus word10. The data copy needs to be endian
  11633. * correct.
  11634. */
  11635. bytep += sizeof(uint32_t);
  11636. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11637. mboxq->vport = phba->pport;
  11638. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11639. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11640. if (rc == MBX_NOT_FINISHED) {
  11641. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11642. "2515 ADD_FCF_RECORD mailbox failed with "
  11643. "status 0x%x\n", rc);
  11644. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11645. rc = -EIO;
  11646. } else
  11647. rc = 0;
  11648. return rc;
  11649. }
  11650. /**
  11651. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11652. * @phba: pointer to lpfc hba data structure.
  11653. * @fcf_record: pointer to the fcf record to write the default data.
  11654. * @fcf_index: FCF table entry index.
  11655. *
  11656. * This routine is invoked to build the driver's default FCF record. The
  11657. * values used are hardcoded. This routine handles memory initialization.
  11658. *
  11659. **/
  11660. void
  11661. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11662. struct fcf_record *fcf_record,
  11663. uint16_t fcf_index)
  11664. {
  11665. memset(fcf_record, 0, sizeof(struct fcf_record));
  11666. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11667. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11668. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11669. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11670. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11671. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11672. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11673. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11674. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11675. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11676. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11677. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11678. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11679. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11680. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11681. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11682. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11683. /* Set the VLAN bit map */
  11684. if (phba->valid_vlan) {
  11685. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11686. = 1 << (phba->vlan_id % 8);
  11687. }
  11688. }
  11689. /**
  11690. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11691. * @phba: pointer to lpfc hba data structure.
  11692. * @fcf_index: FCF table entry offset.
  11693. *
  11694. * This routine is invoked to scan the entire FCF table by reading FCF
  11695. * record and processing it one at a time starting from the @fcf_index
  11696. * for initial FCF discovery or fast FCF failover rediscovery.
  11697. *
  11698. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11699. * otherwise.
  11700. **/
  11701. int
  11702. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11703. {
  11704. int rc = 0, error;
  11705. LPFC_MBOXQ_t *mboxq;
  11706. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11707. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11708. if (!mboxq) {
  11709. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11710. "2000 Failed to allocate mbox for "
  11711. "READ_FCF cmd\n");
  11712. error = -ENOMEM;
  11713. goto fail_fcf_scan;
  11714. }
  11715. /* Construct the read FCF record mailbox command */
  11716. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11717. if (rc) {
  11718. error = -EINVAL;
  11719. goto fail_fcf_scan;
  11720. }
  11721. /* Issue the mailbox command asynchronously */
  11722. mboxq->vport = phba->pport;
  11723. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11724. spin_lock_irq(&phba->hbalock);
  11725. phba->hba_flag |= FCF_TS_INPROG;
  11726. spin_unlock_irq(&phba->hbalock);
  11727. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11728. if (rc == MBX_NOT_FINISHED)
  11729. error = -EIO;
  11730. else {
  11731. /* Reset eligible FCF count for new scan */
  11732. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11733. phba->fcf.eligible_fcf_cnt = 0;
  11734. error = 0;
  11735. }
  11736. fail_fcf_scan:
  11737. if (error) {
  11738. if (mboxq)
  11739. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11740. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11741. spin_lock_irq(&phba->hbalock);
  11742. phba->hba_flag &= ~FCF_TS_INPROG;
  11743. spin_unlock_irq(&phba->hbalock);
  11744. }
  11745. return error;
  11746. }
  11747. /**
  11748. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11749. * @phba: pointer to lpfc hba data structure.
  11750. * @fcf_index: FCF table entry offset.
  11751. *
  11752. * This routine is invoked to read an FCF record indicated by @fcf_index
  11753. * and to use it for FLOGI roundrobin FCF failover.
  11754. *
  11755. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11756. * otherwise.
  11757. **/
  11758. int
  11759. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11760. {
  11761. int rc = 0, error;
  11762. LPFC_MBOXQ_t *mboxq;
  11763. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11764. if (!mboxq) {
  11765. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11766. "2763 Failed to allocate mbox for "
  11767. "READ_FCF cmd\n");
  11768. error = -ENOMEM;
  11769. goto fail_fcf_read;
  11770. }
  11771. /* Construct the read FCF record mailbox command */
  11772. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11773. if (rc) {
  11774. error = -EINVAL;
  11775. goto fail_fcf_read;
  11776. }
  11777. /* Issue the mailbox command asynchronously */
  11778. mboxq->vport = phba->pport;
  11779. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11780. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11781. if (rc == MBX_NOT_FINISHED)
  11782. error = -EIO;
  11783. else
  11784. error = 0;
  11785. fail_fcf_read:
  11786. if (error && mboxq)
  11787. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11788. return error;
  11789. }
  11790. /**
  11791. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11792. * @phba: pointer to lpfc hba data structure.
  11793. * @fcf_index: FCF table entry offset.
  11794. *
  11795. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11796. * determine whether it's eligible for FLOGI roundrobin failover list.
  11797. *
  11798. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11799. * otherwise.
  11800. **/
  11801. int
  11802. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11803. {
  11804. int rc = 0, error;
  11805. LPFC_MBOXQ_t *mboxq;
  11806. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11807. if (!mboxq) {
  11808. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11809. "2758 Failed to allocate mbox for "
  11810. "READ_FCF cmd\n");
  11811. error = -ENOMEM;
  11812. goto fail_fcf_read;
  11813. }
  11814. /* Construct the read FCF record mailbox command */
  11815. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11816. if (rc) {
  11817. error = -EINVAL;
  11818. goto fail_fcf_read;
  11819. }
  11820. /* Issue the mailbox command asynchronously */
  11821. mboxq->vport = phba->pport;
  11822. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11823. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11824. if (rc == MBX_NOT_FINISHED)
  11825. error = -EIO;
  11826. else
  11827. error = 0;
  11828. fail_fcf_read:
  11829. if (error && mboxq)
  11830. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11831. return error;
  11832. }
  11833. /**
  11834. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11835. * @phba: pointer to lpfc hba data structure.
  11836. *
  11837. * This routine is to get the next eligible FCF record index in a round
  11838. * robin fashion. If the next eligible FCF record index equals to the
  11839. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11840. * shall be returned, otherwise, the next eligible FCF record's index
  11841. * shall be returned.
  11842. **/
  11843. uint16_t
  11844. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11845. {
  11846. uint16_t next_fcf_index;
  11847. /* Search start from next bit of currently registered FCF index */
  11848. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11849. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11850. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11851. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11852. next_fcf_index);
  11853. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11854. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11855. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11856. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11857. /* Check roundrobin failover list empty condition */
  11858. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11859. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11860. "2844 No roundrobin failover FCF available\n");
  11861. return LPFC_FCOE_FCF_NEXT_NONE;
  11862. }
  11863. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11864. "2845 Get next roundrobin failover FCF (x%x)\n",
  11865. next_fcf_index);
  11866. return next_fcf_index;
  11867. }
  11868. /**
  11869. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11870. * @phba: pointer to lpfc hba data structure.
  11871. *
  11872. * This routine sets the FCF record index in to the eligible bmask for
  11873. * roundrobin failover search. It checks to make sure that the index
  11874. * does not go beyond the range of the driver allocated bmask dimension
  11875. * before setting the bit.
  11876. *
  11877. * Returns 0 if the index bit successfully set, otherwise, it returns
  11878. * -EINVAL.
  11879. **/
  11880. int
  11881. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11882. {
  11883. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11884. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11885. "2610 FCF (x%x) reached driver's book "
  11886. "keeping dimension:x%x\n",
  11887. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11888. return -EINVAL;
  11889. }
  11890. /* Set the eligible FCF record index bmask */
  11891. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11892. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11893. "2790 Set FCF (x%x) to roundrobin FCF failover "
  11894. "bmask\n", fcf_index);
  11895. return 0;
  11896. }
  11897. /**
  11898. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11899. * @phba: pointer to lpfc hba data structure.
  11900. *
  11901. * This routine clears the FCF record index from the eligible bmask for
  11902. * roundrobin failover search. It checks to make sure that the index
  11903. * does not go beyond the range of the driver allocated bmask dimension
  11904. * before clearing the bit.
  11905. **/
  11906. void
  11907. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11908. {
  11909. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11910. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11911. "2762 FCF (x%x) reached driver's book "
  11912. "keeping dimension:x%x\n",
  11913. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11914. return;
  11915. }
  11916. /* Clear the eligible FCF record index bmask */
  11917. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11918. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11919. "2791 Clear FCF (x%x) from roundrobin failover "
  11920. "bmask\n", fcf_index);
  11921. }
  11922. /**
  11923. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11924. * @phba: pointer to lpfc hba data structure.
  11925. *
  11926. * This routine is the completion routine for the rediscover FCF table mailbox
  11927. * command. If the mailbox command returned failure, it will try to stop the
  11928. * FCF rediscover wait timer.
  11929. **/
  11930. void
  11931. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11932. {
  11933. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11934. uint32_t shdr_status, shdr_add_status;
  11935. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11936. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11937. &redisc_fcf->header.cfg_shdr.response);
  11938. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11939. &redisc_fcf->header.cfg_shdr.response);
  11940. if (shdr_status || shdr_add_status) {
  11941. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11942. "2746 Requesting for FCF rediscovery failed "
  11943. "status x%x add_status x%x\n",
  11944. shdr_status, shdr_add_status);
  11945. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11946. spin_lock_irq(&phba->hbalock);
  11947. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11948. spin_unlock_irq(&phba->hbalock);
  11949. /*
  11950. * CVL event triggered FCF rediscover request failed,
  11951. * last resort to re-try current registered FCF entry.
  11952. */
  11953. lpfc_retry_pport_discovery(phba);
  11954. } else {
  11955. spin_lock_irq(&phba->hbalock);
  11956. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11957. spin_unlock_irq(&phba->hbalock);
  11958. /*
  11959. * DEAD FCF event triggered FCF rediscover request
  11960. * failed, last resort to fail over as a link down
  11961. * to FCF registration.
  11962. */
  11963. lpfc_sli4_fcf_dead_failthrough(phba);
  11964. }
  11965. } else {
  11966. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11967. "2775 Start FCF rediscover quiescent timer\n");
  11968. /*
  11969. * Start FCF rediscovery wait timer for pending FCF
  11970. * before rescan FCF record table.
  11971. */
  11972. lpfc_fcf_redisc_wait_start_timer(phba);
  11973. }
  11974. mempool_free(mbox, phba->mbox_mem_pool);
  11975. }
  11976. /**
  11977. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11978. * @phba: pointer to lpfc hba data structure.
  11979. *
  11980. * This routine is invoked to request for rediscovery of the entire FCF table
  11981. * by the port.
  11982. **/
  11983. int
  11984. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11985. {
  11986. LPFC_MBOXQ_t *mbox;
  11987. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11988. int rc, length;
  11989. /* Cancel retry delay timers to all vports before FCF rediscover */
  11990. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11991. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11992. if (!mbox) {
  11993. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11994. "2745 Failed to allocate mbox for "
  11995. "requesting FCF rediscover.\n");
  11996. return -ENOMEM;
  11997. }
  11998. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11999. sizeof(struct lpfc_sli4_cfg_mhdr));
  12000. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12001. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  12002. length, LPFC_SLI4_MBX_EMBED);
  12003. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12004. /* Set count to 0 for invalidating the entire FCF database */
  12005. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  12006. /* Issue the mailbox command asynchronously */
  12007. mbox->vport = phba->pport;
  12008. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  12009. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  12010. if (rc == MBX_NOT_FINISHED) {
  12011. mempool_free(mbox, phba->mbox_mem_pool);
  12012. return -EIO;
  12013. }
  12014. return 0;
  12015. }
  12016. /**
  12017. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  12018. * @phba: pointer to lpfc hba data structure.
  12019. *
  12020. * This function is the failover routine as a last resort to the FCF DEAD
  12021. * event when driver failed to perform fast FCF failover.
  12022. **/
  12023. void
  12024. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  12025. {
  12026. uint32_t link_state;
  12027. /*
  12028. * Last resort as FCF DEAD event failover will treat this as
  12029. * a link down, but save the link state because we don't want
  12030. * it to be changed to Link Down unless it is already down.
  12031. */
  12032. link_state = phba->link_state;
  12033. lpfc_linkdown(phba);
  12034. phba->link_state = link_state;
  12035. /* Unregister FCF if no devices connected to it */
  12036. lpfc_unregister_unused_fcf(phba);
  12037. }
  12038. /**
  12039. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12040. * @phba: pointer to lpfc hba data structure.
  12041. *
  12042. * This function read region 23 and parse TLV for port status to
  12043. * decide if the user disaled the port. If the TLV indicates the
  12044. * port is disabled, the hba_flag is set accordingly.
  12045. **/
  12046. void
  12047. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12048. {
  12049. LPFC_MBOXQ_t *pmb = NULL;
  12050. MAILBOX_t *mb;
  12051. uint8_t *rgn23_data = NULL;
  12052. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12053. int rc;
  12054. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12055. if (!pmb) {
  12056. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12057. "2600 lpfc_sli_read_serdes_param failed to"
  12058. " allocate mailbox memory\n");
  12059. goto out;
  12060. }
  12061. mb = &pmb->u.mb;
  12062. /* Get adapter Region 23 data */
  12063. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12064. if (!rgn23_data)
  12065. goto out;
  12066. do {
  12067. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12068. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12069. if (rc != MBX_SUCCESS) {
  12070. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12071. "2601 lpfc_sli_read_link_ste failed to"
  12072. " read config region 23 rc 0x%x Status 0x%x\n",
  12073. rc, mb->mbxStatus);
  12074. mb->un.varDmp.word_cnt = 0;
  12075. }
  12076. /*
  12077. * dump mem may return a zero when finished or we got a
  12078. * mailbox error, either way we are done.
  12079. */
  12080. if (mb->un.varDmp.word_cnt == 0)
  12081. break;
  12082. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12083. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12084. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12085. rgn23_data + offset,
  12086. mb->un.varDmp.word_cnt);
  12087. offset += mb->un.varDmp.word_cnt;
  12088. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12089. data_size = offset;
  12090. offset = 0;
  12091. if (!data_size)
  12092. goto out;
  12093. /* Check the region signature first */
  12094. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12095. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12096. "2619 Config region 23 has bad signature\n");
  12097. goto out;
  12098. }
  12099. offset += 4;
  12100. /* Check the data structure version */
  12101. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12102. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12103. "2620 Config region 23 has bad version\n");
  12104. goto out;
  12105. }
  12106. offset += 4;
  12107. /* Parse TLV entries in the region */
  12108. while (offset < data_size) {
  12109. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12110. break;
  12111. /*
  12112. * If the TLV is not driver specific TLV or driver id is
  12113. * not linux driver id, skip the record.
  12114. */
  12115. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12116. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12117. (rgn23_data[offset + 3] != 0)) {
  12118. offset += rgn23_data[offset + 1] * 4 + 4;
  12119. continue;
  12120. }
  12121. /* Driver found a driver specific TLV in the config region */
  12122. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12123. offset += 4;
  12124. tlv_offset = 0;
  12125. /*
  12126. * Search for configured port state sub-TLV.
  12127. */
  12128. while ((offset < data_size) &&
  12129. (tlv_offset < sub_tlv_len)) {
  12130. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12131. offset += 4;
  12132. tlv_offset += 4;
  12133. break;
  12134. }
  12135. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12136. offset += rgn23_data[offset + 1] * 4 + 4;
  12137. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12138. continue;
  12139. }
  12140. /* This HBA contains PORT_STE configured */
  12141. if (!rgn23_data[offset + 2])
  12142. phba->hba_flag |= LINK_DISABLED;
  12143. goto out;
  12144. }
  12145. }
  12146. out:
  12147. if (pmb)
  12148. mempool_free(pmb, phba->mbox_mem_pool);
  12149. kfree(rgn23_data);
  12150. return;
  12151. }
  12152. /**
  12153. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12154. * @vport: pointer to vport data structure.
  12155. *
  12156. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12157. * and REG_VPI mailbox commands associated with the vport. This function
  12158. * is called when driver want to restart discovery of the vport due to
  12159. * a Clear Virtual Link event.
  12160. **/
  12161. void
  12162. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12163. {
  12164. struct lpfc_hba *phba = vport->phba;
  12165. LPFC_MBOXQ_t *mb, *nextmb;
  12166. struct lpfc_dmabuf *mp;
  12167. struct lpfc_nodelist *ndlp;
  12168. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12169. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12170. LIST_HEAD(mbox_cmd_list);
  12171. uint8_t restart_loop;
  12172. /* Clean up internally queued mailbox commands with the vport */
  12173. spin_lock_irq(&phba->hbalock);
  12174. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12175. if (mb->vport != vport)
  12176. continue;
  12177. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12178. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12179. continue;
  12180. list_del(&mb->list);
  12181. list_add_tail(&mb->list, &mbox_cmd_list);
  12182. }
  12183. /* Clean up active mailbox command with the vport */
  12184. mb = phba->sli.mbox_active;
  12185. if (mb && (mb->vport == vport)) {
  12186. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12187. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12188. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12189. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12190. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12191. /* Put reference count for delayed processing */
  12192. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12193. /* Unregister the RPI when mailbox complete */
  12194. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12195. }
  12196. }
  12197. /* Cleanup any mailbox completions which are not yet processed */
  12198. do {
  12199. restart_loop = 0;
  12200. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12201. /*
  12202. * If this mailox is already processed or it is
  12203. * for another vport ignore it.
  12204. */
  12205. if ((mb->vport != vport) ||
  12206. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12207. continue;
  12208. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12209. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12210. continue;
  12211. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12212. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12213. ndlp = (struct lpfc_nodelist *)mb->context2;
  12214. /* Unregister the RPI when mailbox complete */
  12215. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12216. restart_loop = 1;
  12217. spin_unlock_irq(&phba->hbalock);
  12218. spin_lock(shost->host_lock);
  12219. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12220. spin_unlock(shost->host_lock);
  12221. spin_lock_irq(&phba->hbalock);
  12222. break;
  12223. }
  12224. }
  12225. } while (restart_loop);
  12226. spin_unlock_irq(&phba->hbalock);
  12227. /* Release the cleaned-up mailbox commands */
  12228. while (!list_empty(&mbox_cmd_list)) {
  12229. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12230. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12231. mp = (struct lpfc_dmabuf *) (mb->context1);
  12232. if (mp) {
  12233. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12234. kfree(mp);
  12235. }
  12236. ndlp = (struct lpfc_nodelist *) mb->context2;
  12237. mb->context2 = NULL;
  12238. if (ndlp) {
  12239. spin_lock(shost->host_lock);
  12240. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12241. spin_unlock(shost->host_lock);
  12242. lpfc_nlp_put(ndlp);
  12243. }
  12244. }
  12245. mempool_free(mb, phba->mbox_mem_pool);
  12246. }
  12247. /* Release the ndlp with the cleaned-up active mailbox command */
  12248. if (act_mbx_ndlp) {
  12249. spin_lock(shost->host_lock);
  12250. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12251. spin_unlock(shost->host_lock);
  12252. lpfc_nlp_put(act_mbx_ndlp);
  12253. }
  12254. }
  12255. /**
  12256. * lpfc_drain_txq - Drain the txq
  12257. * @phba: Pointer to HBA context object.
  12258. *
  12259. * This function attempt to submit IOCBs on the txq
  12260. * to the adapter. For SLI4 adapters, the txq contains
  12261. * ELS IOCBs that have been deferred because the there
  12262. * are no SGLs. This congestion can occur with large
  12263. * vport counts during node discovery.
  12264. **/
  12265. uint32_t
  12266. lpfc_drain_txq(struct lpfc_hba *phba)
  12267. {
  12268. LIST_HEAD(completions);
  12269. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12270. struct lpfc_iocbq *piocbq = 0;
  12271. unsigned long iflags = 0;
  12272. char *fail_msg = NULL;
  12273. struct lpfc_sglq *sglq;
  12274. union lpfc_wqe wqe;
  12275. spin_lock_irqsave(&phba->hbalock, iflags);
  12276. if (pring->txq_cnt > pring->txq_max)
  12277. pring->txq_max = pring->txq_cnt;
  12278. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12279. while (pring->txq_cnt) {
  12280. spin_lock_irqsave(&phba->hbalock, iflags);
  12281. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12282. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12283. if (!sglq) {
  12284. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12285. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12286. break;
  12287. } else {
  12288. if (!piocbq) {
  12289. /* The txq_cnt out of sync. This should
  12290. * never happen
  12291. */
  12292. sglq = __lpfc_clear_active_sglq(phba,
  12293. sglq->sli4_xritag);
  12294. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12295. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12296. "2823 txq empty and txq_cnt is %d\n ",
  12297. pring->txq_cnt);
  12298. break;
  12299. }
  12300. }
  12301. /* The xri and iocb resources secured,
  12302. * attempt to issue request
  12303. */
  12304. piocbq->sli4_xritag = sglq->sli4_xritag;
  12305. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12306. fail_msg = "to convert bpl to sgl";
  12307. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12308. fail_msg = "to convert iocb to wqe";
  12309. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12310. fail_msg = " - Wq is full";
  12311. else
  12312. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12313. if (fail_msg) {
  12314. /* Failed means we can't issue and need to cancel */
  12315. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12316. "2822 IOCB failed %s iotag 0x%x "
  12317. "xri 0x%x\n",
  12318. fail_msg,
  12319. piocbq->iotag, piocbq->sli4_xritag);
  12320. list_add_tail(&piocbq->list, &completions);
  12321. }
  12322. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12323. }
  12324. /* Cancel all the IOCBs that cannot be issued */
  12325. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12326. IOERR_SLI_ABORTED);
  12327. return pring->txq_cnt;
  12328. }