lpfc_sli.c 372 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include <linux/aer.h>
  32. #include "lpfc_hw4.h"
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_sli4.h"
  36. #include "lpfc_nl.h"
  37. #include "lpfc_disc.h"
  38. #include "lpfc_scsi.h"
  39. #include "lpfc.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_logmsg.h"
  42. #include "lpfc_compat.h"
  43. #include "lpfc_debugfs.h"
  44. #include "lpfc_vport.h"
  45. /* There are only four IOCB completion types. */
  46. typedef enum _lpfc_iocb_type {
  47. LPFC_UNKNOWN_IOCB,
  48. LPFC_UNSOL_IOCB,
  49. LPFC_SOL_IOCB,
  50. LPFC_ABORT_IOCB
  51. } lpfc_iocb_type;
  52. /* Provide function prototypes local to this module. */
  53. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  54. uint32_t);
  55. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  56. uint8_t *, uint32_t *);
  57. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  58. struct lpfc_iocbq *);
  59. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  60. struct hbq_dmabuf *);
  61. static IOCB_t *
  62. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  63. {
  64. return &iocbq->iocb;
  65. }
  66. /**
  67. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  68. * @q: The Work Queue to operate on.
  69. * @wqe: The work Queue Entry to put on the Work queue.
  70. *
  71. * This routine will copy the contents of @wqe to the next available entry on
  72. * the @q. This function will then ring the Work Queue Doorbell to signal the
  73. * HBA to start processing the Work Queue Entry. This function returns 0 if
  74. * successful. If no entries are available on @q then this function will return
  75. * -ENOMEM.
  76. * The caller is expected to hold the hbalock when calling this routine.
  77. **/
  78. static uint32_t
  79. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  80. {
  81. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  82. struct lpfc_register doorbell;
  83. uint32_t host_index;
  84. /* If the host has not yet processed the next entry then we are done */
  85. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  86. return -ENOMEM;
  87. /* set consumption flag every once in a while */
  88. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  89. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  90. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  91. /* Update the host index before invoking device */
  92. host_index = q->host_index;
  93. q->host_index = ((q->host_index + 1) % q->entry_count);
  94. /* Ring Doorbell */
  95. doorbell.word0 = 0;
  96. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  97. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  98. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  99. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  100. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  101. return 0;
  102. }
  103. /**
  104. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  105. * @q: The Work Queue to operate on.
  106. * @index: The index to advance the hba index to.
  107. *
  108. * This routine will update the HBA index of a queue to reflect consumption of
  109. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  110. * an entry the host calls this function to update the queue's internal
  111. * pointers. This routine returns the number of entries that were consumed by
  112. * the HBA.
  113. **/
  114. static uint32_t
  115. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  116. {
  117. uint32_t released = 0;
  118. if (q->hba_index == index)
  119. return 0;
  120. do {
  121. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  122. released++;
  123. } while (q->hba_index != index);
  124. return released;
  125. }
  126. /**
  127. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  128. * @q: The Mailbox Queue to operate on.
  129. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  130. *
  131. * This routine will copy the contents of @mqe to the next available entry on
  132. * the @q. This function will then ring the Work Queue Doorbell to signal the
  133. * HBA to start processing the Work Queue Entry. This function returns 0 if
  134. * successful. If no entries are available on @q then this function will return
  135. * -ENOMEM.
  136. * The caller is expected to hold the hbalock when calling this routine.
  137. **/
  138. static uint32_t
  139. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  140. {
  141. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  142. struct lpfc_register doorbell;
  143. uint32_t host_index;
  144. /* If the host has not yet processed the next entry then we are done */
  145. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  146. return -ENOMEM;
  147. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  148. /* Save off the mailbox pointer for completion */
  149. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  150. /* Update the host index before invoking device */
  151. host_index = q->host_index;
  152. q->host_index = ((q->host_index + 1) % q->entry_count);
  153. /* Ring Doorbell */
  154. doorbell.word0 = 0;
  155. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  156. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  157. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  158. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  159. return 0;
  160. }
  161. /**
  162. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  163. * @q: The Mailbox Queue to operate on.
  164. *
  165. * This routine will update the HBA index of a queue to reflect consumption of
  166. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  167. * an entry the host calls this function to update the queue's internal
  168. * pointers. This routine returns the number of entries that were consumed by
  169. * the HBA.
  170. **/
  171. static uint32_t
  172. lpfc_sli4_mq_release(struct lpfc_queue *q)
  173. {
  174. /* Clear the mailbox pointer for completion */
  175. q->phba->mbox = NULL;
  176. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  177. return 1;
  178. }
  179. /**
  180. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  181. * @q: The Event Queue to get the first valid EQE from
  182. *
  183. * This routine will get the first valid Event Queue Entry from @q, update
  184. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  185. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  186. * processed, but not popped back to the HBA then this routine will return NULL.
  187. **/
  188. static struct lpfc_eqe *
  189. lpfc_sli4_eq_get(struct lpfc_queue *q)
  190. {
  191. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  192. /* If the next EQE is not valid then we are done */
  193. if (!bf_get(lpfc_eqe_valid, eqe))
  194. return NULL;
  195. /* If the host has not yet processed the next entry then we are done */
  196. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  197. return NULL;
  198. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  199. return eqe;
  200. }
  201. /**
  202. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  203. * @q: The Event Queue that the host has completed processing for.
  204. * @arm: Indicates whether the host wants to arms this CQ.
  205. *
  206. * This routine will mark all Event Queue Entries on @q, from the last
  207. * known completed entry to the last entry that was processed, as completed
  208. * by clearing the valid bit for each completion queue entry. Then it will
  209. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  210. * The internal host index in the @q will be updated by this routine to indicate
  211. * that the host has finished processing the entries. The @arm parameter
  212. * indicates that the queue should be rearmed when ringing the doorbell.
  213. *
  214. * This function will return the number of EQEs that were popped.
  215. **/
  216. uint32_t
  217. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  218. {
  219. uint32_t released = 0;
  220. struct lpfc_eqe *temp_eqe;
  221. struct lpfc_register doorbell;
  222. /* while there are valid entries */
  223. while (q->hba_index != q->host_index) {
  224. temp_eqe = q->qe[q->host_index].eqe;
  225. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  226. released++;
  227. q->host_index = ((q->host_index + 1) % q->entry_count);
  228. }
  229. if (unlikely(released == 0 && !arm))
  230. return 0;
  231. /* ring doorbell for number popped */
  232. doorbell.word0 = 0;
  233. if (arm) {
  234. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  235. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  236. }
  237. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  238. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  239. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  240. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  241. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  242. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  243. readl(q->phba->sli4_hba.EQCQDBregaddr);
  244. return released;
  245. }
  246. /**
  247. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  248. * @q: The Completion Queue to get the first valid CQE from
  249. *
  250. * This routine will get the first valid Completion Queue Entry from @q, update
  251. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  252. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  253. * processed, but not popped back to the HBA then this routine will return NULL.
  254. **/
  255. static struct lpfc_cqe *
  256. lpfc_sli4_cq_get(struct lpfc_queue *q)
  257. {
  258. struct lpfc_cqe *cqe;
  259. /* If the next CQE is not valid then we are done */
  260. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  261. return NULL;
  262. /* If the host has not yet processed the next entry then we are done */
  263. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  264. return NULL;
  265. cqe = q->qe[q->hba_index].cqe;
  266. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  267. return cqe;
  268. }
  269. /**
  270. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  271. * @q: The Completion Queue that the host has completed processing for.
  272. * @arm: Indicates whether the host wants to arms this CQ.
  273. *
  274. * This routine will mark all Completion queue entries on @q, from the last
  275. * known completed entry to the last entry that was processed, as completed
  276. * by clearing the valid bit for each completion queue entry. Then it will
  277. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  278. * The internal host index in the @q will be updated by this routine to indicate
  279. * that the host has finished processing the entries. The @arm parameter
  280. * indicates that the queue should be rearmed when ringing the doorbell.
  281. *
  282. * This function will return the number of CQEs that were released.
  283. **/
  284. uint32_t
  285. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  286. {
  287. uint32_t released = 0;
  288. struct lpfc_cqe *temp_qe;
  289. struct lpfc_register doorbell;
  290. /* while there are valid entries */
  291. while (q->hba_index != q->host_index) {
  292. temp_qe = q->qe[q->host_index].cqe;
  293. bf_set(lpfc_cqe_valid, temp_qe, 0);
  294. released++;
  295. q->host_index = ((q->host_index + 1) % q->entry_count);
  296. }
  297. if (unlikely(released == 0 && !arm))
  298. return 0;
  299. /* ring doorbell for number popped */
  300. doorbell.word0 = 0;
  301. if (arm)
  302. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  303. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  304. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  305. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  306. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  307. return released;
  308. }
  309. /**
  310. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  311. * @q: The Header Receive Queue to operate on.
  312. * @wqe: The Receive Queue Entry to put on the Receive queue.
  313. *
  314. * This routine will copy the contents of @wqe to the next available entry on
  315. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  316. * HBA to start processing the Receive Queue Entry. This function returns the
  317. * index that the rqe was copied to if successful. If no entries are available
  318. * on @q then this function will return -ENOMEM.
  319. * The caller is expected to hold the hbalock when calling this routine.
  320. **/
  321. static int
  322. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  323. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  324. {
  325. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  326. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  327. struct lpfc_register doorbell;
  328. int put_index = hq->host_index;
  329. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  330. return -EINVAL;
  331. if (hq->host_index != dq->host_index)
  332. return -EINVAL;
  333. /* If the host has not yet processed the next entry then we are done */
  334. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  335. return -EBUSY;
  336. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  337. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  338. /* Update the host index to point to the next slot */
  339. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  340. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  341. /* Ring The Header Receive Queue Doorbell */
  342. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  343. doorbell.word0 = 0;
  344. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  345. LPFC_RQ_POST_BATCH);
  346. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  347. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  348. }
  349. return put_index;
  350. }
  351. /**
  352. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  353. * @q: The Header Receive Queue to operate on.
  354. *
  355. * This routine will update the HBA index of a queue to reflect consumption of
  356. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  357. * consumed an entry the host calls this function to update the queue's
  358. * internal pointers. This routine returns the number of entries that were
  359. * consumed by the HBA.
  360. **/
  361. static uint32_t
  362. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  363. {
  364. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  365. return 0;
  366. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  367. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  368. return 1;
  369. }
  370. /**
  371. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  372. * @phba: Pointer to HBA context object.
  373. * @pring: Pointer to driver SLI ring object.
  374. *
  375. * This function returns pointer to next command iocb entry
  376. * in the command ring. The caller must hold hbalock to prevent
  377. * other threads consume the next command iocb.
  378. * SLI-2/SLI-3 provide different sized iocbs.
  379. **/
  380. static inline IOCB_t *
  381. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  382. {
  383. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  384. pring->cmdidx * phba->iocb_cmd_size);
  385. }
  386. /**
  387. * lpfc_resp_iocb - Get next response iocb entry in the ring
  388. * @phba: Pointer to HBA context object.
  389. * @pring: Pointer to driver SLI ring object.
  390. *
  391. * This function returns pointer to next response iocb entry
  392. * in the response ring. The caller must hold hbalock to make sure
  393. * that no other thread consume the next response iocb.
  394. * SLI-2/SLI-3 provide different sized iocbs.
  395. **/
  396. static inline IOCB_t *
  397. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  398. {
  399. return (IOCB_t *) (((char *) pring->rspringaddr) +
  400. pring->rspidx * phba->iocb_rsp_size);
  401. }
  402. /**
  403. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  404. * @phba: Pointer to HBA context object.
  405. *
  406. * This function is called with hbalock held. This function
  407. * allocates a new driver iocb object from the iocb pool. If the
  408. * allocation is successful, it returns pointer to the newly
  409. * allocated iocb object else it returns NULL.
  410. **/
  411. static struct lpfc_iocbq *
  412. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  413. {
  414. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  415. struct lpfc_iocbq * iocbq = NULL;
  416. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  417. return iocbq;
  418. }
  419. /**
  420. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  421. * @phba: Pointer to HBA context object.
  422. * @xritag: XRI value.
  423. *
  424. * This function clears the sglq pointer from the array of acive
  425. * sglq's. The xritag that is passed in is used to index into the
  426. * array. Before the xritag can be used it needs to be adjusted
  427. * by subtracting the xribase.
  428. *
  429. * Returns sglq ponter = success, NULL = Failure.
  430. **/
  431. static struct lpfc_sglq *
  432. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  433. {
  434. uint16_t adj_xri;
  435. struct lpfc_sglq *sglq;
  436. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  437. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  438. return NULL;
  439. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  440. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  441. return sglq;
  442. }
  443. /**
  444. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  445. * @phba: Pointer to HBA context object.
  446. * @xritag: XRI value.
  447. *
  448. * This function returns the sglq pointer from the array of acive
  449. * sglq's. The xritag that is passed in is used to index into the
  450. * array. Before the xritag can be used it needs to be adjusted
  451. * by subtracting the xribase.
  452. *
  453. * Returns sglq ponter = success, NULL = Failure.
  454. **/
  455. static struct lpfc_sglq *
  456. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  457. {
  458. uint16_t adj_xri;
  459. struct lpfc_sglq *sglq;
  460. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  461. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  462. return NULL;
  463. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  464. return sglq;
  465. }
  466. /**
  467. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  468. * @phba: Pointer to HBA context object.
  469. *
  470. * This function is called with hbalock held. This function
  471. * Gets a new driver sglq object from the sglq list. If the
  472. * list is not empty then it is successful, it returns pointer to the newly
  473. * allocated sglq object else it returns NULL.
  474. **/
  475. static struct lpfc_sglq *
  476. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  477. {
  478. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  479. struct lpfc_sglq *sglq = NULL;
  480. uint16_t adj_xri;
  481. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  482. if (!sglq)
  483. return NULL;
  484. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  485. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  486. return sglq;
  487. }
  488. /**
  489. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  490. * @phba: Pointer to HBA context object.
  491. *
  492. * This function is called with no lock held. This function
  493. * allocates a new driver iocb object from the iocb pool. If the
  494. * allocation is successful, it returns pointer to the newly
  495. * allocated iocb object else it returns NULL.
  496. **/
  497. struct lpfc_iocbq *
  498. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  499. {
  500. struct lpfc_iocbq * iocbq = NULL;
  501. unsigned long iflags;
  502. spin_lock_irqsave(&phba->hbalock, iflags);
  503. iocbq = __lpfc_sli_get_iocbq(phba);
  504. spin_unlock_irqrestore(&phba->hbalock, iflags);
  505. return iocbq;
  506. }
  507. /**
  508. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  509. * @phba: Pointer to HBA context object.
  510. * @iocbq: Pointer to driver iocb object.
  511. *
  512. * This function is called with hbalock held to release driver
  513. * iocb object to the iocb pool. The iotag in the iocb object
  514. * does not change for each use of the iocb object. This function
  515. * clears all other fields of the iocb object when it is freed.
  516. * The sqlq structure that holds the xritag and phys and virtual
  517. * mappings for the scatter gather list is retrieved from the
  518. * active array of sglq. The get of the sglq pointer also clears
  519. * the entry in the array. If the status of the IO indiactes that
  520. * this IO was aborted then the sglq entry it put on the
  521. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  522. * IO has good status or fails for any other reason then the sglq
  523. * entry is added to the free list (lpfc_sgl_list).
  524. **/
  525. static void
  526. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  527. {
  528. struct lpfc_sglq *sglq;
  529. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  530. unsigned long iflag;
  531. if (iocbq->sli4_xritag == NO_XRI)
  532. sglq = NULL;
  533. else
  534. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  535. if (sglq) {
  536. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
  537. && ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  538. && (iocbq->iocb.un.ulpWord[4]
  539. == IOERR_ABORT_REQUESTED))) {
  540. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  541. iflag);
  542. list_add(&sglq->list,
  543. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  544. spin_unlock_irqrestore(
  545. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  546. } else
  547. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  548. }
  549. /*
  550. * Clean all volatile data fields, preserve iotag and node struct.
  551. */
  552. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  553. iocbq->sli4_xritag = NO_XRI;
  554. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  555. }
  556. /**
  557. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  558. * @phba: Pointer to HBA context object.
  559. * @iocbq: Pointer to driver iocb object.
  560. *
  561. * This function is called with hbalock held to release driver
  562. * iocb object to the iocb pool. The iotag in the iocb object
  563. * does not change for each use of the iocb object. This function
  564. * clears all other fields of the iocb object when it is freed.
  565. **/
  566. static void
  567. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  568. {
  569. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  570. /*
  571. * Clean all volatile data fields, preserve iotag and node struct.
  572. */
  573. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  574. iocbq->sli4_xritag = NO_XRI;
  575. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  576. }
  577. /**
  578. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  579. * @phba: Pointer to HBA context object.
  580. * @iocbq: Pointer to driver iocb object.
  581. *
  582. * This function is called with hbalock held to release driver
  583. * iocb object to the iocb pool. The iotag in the iocb object
  584. * does not change for each use of the iocb object. This function
  585. * clears all other fields of the iocb object when it is freed.
  586. **/
  587. static void
  588. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  589. {
  590. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  591. }
  592. /**
  593. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  594. * @phba: Pointer to HBA context object.
  595. * @iocbq: Pointer to driver iocb object.
  596. *
  597. * This function is called with no lock held to release the iocb to
  598. * iocb pool.
  599. **/
  600. void
  601. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  602. {
  603. unsigned long iflags;
  604. /*
  605. * Clean all volatile data fields, preserve iotag and node struct.
  606. */
  607. spin_lock_irqsave(&phba->hbalock, iflags);
  608. __lpfc_sli_release_iocbq(phba, iocbq);
  609. spin_unlock_irqrestore(&phba->hbalock, iflags);
  610. }
  611. /**
  612. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  613. * @phba: Pointer to HBA context object.
  614. * @iocblist: List of IOCBs.
  615. * @ulpstatus: ULP status in IOCB command field.
  616. * @ulpWord4: ULP word-4 in IOCB command field.
  617. *
  618. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  619. * on the list by invoking the complete callback function associated with the
  620. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  621. * fields.
  622. **/
  623. void
  624. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  625. uint32_t ulpstatus, uint32_t ulpWord4)
  626. {
  627. struct lpfc_iocbq *piocb;
  628. while (!list_empty(iocblist)) {
  629. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  630. if (!piocb->iocb_cmpl)
  631. lpfc_sli_release_iocbq(phba, piocb);
  632. else {
  633. piocb->iocb.ulpStatus = ulpstatus;
  634. piocb->iocb.un.ulpWord[4] = ulpWord4;
  635. (piocb->iocb_cmpl) (phba, piocb, piocb);
  636. }
  637. }
  638. return;
  639. }
  640. /**
  641. * lpfc_sli_iocb_cmd_type - Get the iocb type
  642. * @iocb_cmnd: iocb command code.
  643. *
  644. * This function is called by ring event handler function to get the iocb type.
  645. * This function translates the iocb command to an iocb command type used to
  646. * decide the final disposition of each completed IOCB.
  647. * The function returns
  648. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  649. * LPFC_SOL_IOCB if it is a solicited iocb completion
  650. * LPFC_ABORT_IOCB if it is an abort iocb
  651. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  652. *
  653. * The caller is not required to hold any lock.
  654. **/
  655. static lpfc_iocb_type
  656. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  657. {
  658. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  659. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  660. return 0;
  661. switch (iocb_cmnd) {
  662. case CMD_XMIT_SEQUENCE_CR:
  663. case CMD_XMIT_SEQUENCE_CX:
  664. case CMD_XMIT_BCAST_CN:
  665. case CMD_XMIT_BCAST_CX:
  666. case CMD_ELS_REQUEST_CR:
  667. case CMD_ELS_REQUEST_CX:
  668. case CMD_CREATE_XRI_CR:
  669. case CMD_CREATE_XRI_CX:
  670. case CMD_GET_RPI_CN:
  671. case CMD_XMIT_ELS_RSP_CX:
  672. case CMD_GET_RPI_CR:
  673. case CMD_FCP_IWRITE_CR:
  674. case CMD_FCP_IWRITE_CX:
  675. case CMD_FCP_IREAD_CR:
  676. case CMD_FCP_IREAD_CX:
  677. case CMD_FCP_ICMND_CR:
  678. case CMD_FCP_ICMND_CX:
  679. case CMD_FCP_TSEND_CX:
  680. case CMD_FCP_TRSP_CX:
  681. case CMD_FCP_TRECEIVE_CX:
  682. case CMD_FCP_AUTO_TRSP_CX:
  683. case CMD_ADAPTER_MSG:
  684. case CMD_ADAPTER_DUMP:
  685. case CMD_XMIT_SEQUENCE64_CR:
  686. case CMD_XMIT_SEQUENCE64_CX:
  687. case CMD_XMIT_BCAST64_CN:
  688. case CMD_XMIT_BCAST64_CX:
  689. case CMD_ELS_REQUEST64_CR:
  690. case CMD_ELS_REQUEST64_CX:
  691. case CMD_FCP_IWRITE64_CR:
  692. case CMD_FCP_IWRITE64_CX:
  693. case CMD_FCP_IREAD64_CR:
  694. case CMD_FCP_IREAD64_CX:
  695. case CMD_FCP_ICMND64_CR:
  696. case CMD_FCP_ICMND64_CX:
  697. case CMD_FCP_TSEND64_CX:
  698. case CMD_FCP_TRSP64_CX:
  699. case CMD_FCP_TRECEIVE64_CX:
  700. case CMD_GEN_REQUEST64_CR:
  701. case CMD_GEN_REQUEST64_CX:
  702. case CMD_XMIT_ELS_RSP64_CX:
  703. case DSSCMD_IWRITE64_CR:
  704. case DSSCMD_IWRITE64_CX:
  705. case DSSCMD_IREAD64_CR:
  706. case DSSCMD_IREAD64_CX:
  707. case DSSCMD_INVALIDATE_DEK:
  708. case DSSCMD_SET_KEK:
  709. case DSSCMD_GET_KEK_ID:
  710. case DSSCMD_GEN_XFER:
  711. type = LPFC_SOL_IOCB;
  712. break;
  713. case CMD_ABORT_XRI_CN:
  714. case CMD_ABORT_XRI_CX:
  715. case CMD_CLOSE_XRI_CN:
  716. case CMD_CLOSE_XRI_CX:
  717. case CMD_XRI_ABORTED_CX:
  718. case CMD_ABORT_MXRI64_CN:
  719. case CMD_XMIT_BLS_RSP64_CX:
  720. type = LPFC_ABORT_IOCB;
  721. break;
  722. case CMD_RCV_SEQUENCE_CX:
  723. case CMD_RCV_ELS_REQ_CX:
  724. case CMD_RCV_SEQUENCE64_CX:
  725. case CMD_RCV_ELS_REQ64_CX:
  726. case CMD_ASYNC_STATUS:
  727. case CMD_IOCB_RCV_SEQ64_CX:
  728. case CMD_IOCB_RCV_ELS64_CX:
  729. case CMD_IOCB_RCV_CONT64_CX:
  730. case CMD_IOCB_RET_XRI64_CX:
  731. type = LPFC_UNSOL_IOCB;
  732. break;
  733. case CMD_IOCB_XMIT_MSEQ64_CR:
  734. case CMD_IOCB_XMIT_MSEQ64_CX:
  735. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  736. case CMD_IOCB_RCV_ELS_LIST64_CX:
  737. case CMD_IOCB_CLOSE_EXTENDED_CN:
  738. case CMD_IOCB_ABORT_EXTENDED_CN:
  739. case CMD_IOCB_RET_HBQE64_CN:
  740. case CMD_IOCB_FCP_IBIDIR64_CR:
  741. case CMD_IOCB_FCP_IBIDIR64_CX:
  742. case CMD_IOCB_FCP_ITASKMGT64_CX:
  743. case CMD_IOCB_LOGENTRY_CN:
  744. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  745. printk("%s - Unhandled SLI-3 Command x%x\n",
  746. __func__, iocb_cmnd);
  747. type = LPFC_UNKNOWN_IOCB;
  748. break;
  749. default:
  750. type = LPFC_UNKNOWN_IOCB;
  751. break;
  752. }
  753. return type;
  754. }
  755. /**
  756. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  757. * @phba: Pointer to HBA context object.
  758. *
  759. * This function is called from SLI initialization code
  760. * to configure every ring of the HBA's SLI interface. The
  761. * caller is not required to hold any lock. This function issues
  762. * a config_ring mailbox command for each ring.
  763. * This function returns zero if successful else returns a negative
  764. * error code.
  765. **/
  766. static int
  767. lpfc_sli_ring_map(struct lpfc_hba *phba)
  768. {
  769. struct lpfc_sli *psli = &phba->sli;
  770. LPFC_MBOXQ_t *pmb;
  771. MAILBOX_t *pmbox;
  772. int i, rc, ret = 0;
  773. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  774. if (!pmb)
  775. return -ENOMEM;
  776. pmbox = &pmb->u.mb;
  777. phba->link_state = LPFC_INIT_MBX_CMDS;
  778. for (i = 0; i < psli->num_rings; i++) {
  779. lpfc_config_ring(phba, i, pmb);
  780. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  781. if (rc != MBX_SUCCESS) {
  782. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  783. "0446 Adapter failed to init (%d), "
  784. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  785. "ring %d\n",
  786. rc, pmbox->mbxCommand,
  787. pmbox->mbxStatus, i);
  788. phba->link_state = LPFC_HBA_ERROR;
  789. ret = -ENXIO;
  790. break;
  791. }
  792. }
  793. mempool_free(pmb, phba->mbox_mem_pool);
  794. return ret;
  795. }
  796. /**
  797. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  798. * @phba: Pointer to HBA context object.
  799. * @pring: Pointer to driver SLI ring object.
  800. * @piocb: Pointer to the driver iocb object.
  801. *
  802. * This function is called with hbalock held. The function adds the
  803. * new iocb to txcmplq of the given ring. This function always returns
  804. * 0. If this function is called for ELS ring, this function checks if
  805. * there is a vport associated with the ELS command. This function also
  806. * starts els_tmofunc timer if this is an ELS command.
  807. **/
  808. static int
  809. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  810. struct lpfc_iocbq *piocb)
  811. {
  812. list_add_tail(&piocb->list, &pring->txcmplq);
  813. pring->txcmplq_cnt++;
  814. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  815. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  816. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  817. if (!piocb->vport)
  818. BUG();
  819. else
  820. mod_timer(&piocb->vport->els_tmofunc,
  821. jiffies + HZ * (phba->fc_ratov << 1));
  822. }
  823. return 0;
  824. }
  825. /**
  826. * lpfc_sli_ringtx_get - Get first element of the txq
  827. * @phba: Pointer to HBA context object.
  828. * @pring: Pointer to driver SLI ring object.
  829. *
  830. * This function is called with hbalock held to get next
  831. * iocb in txq of the given ring. If there is any iocb in
  832. * the txq, the function returns first iocb in the list after
  833. * removing the iocb from the list, else it returns NULL.
  834. **/
  835. static struct lpfc_iocbq *
  836. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  837. {
  838. struct lpfc_iocbq *cmd_iocb;
  839. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  840. if (cmd_iocb != NULL)
  841. pring->txq_cnt--;
  842. return cmd_iocb;
  843. }
  844. /**
  845. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  846. * @phba: Pointer to HBA context object.
  847. * @pring: Pointer to driver SLI ring object.
  848. *
  849. * This function is called with hbalock held and the caller must post the
  850. * iocb without releasing the lock. If the caller releases the lock,
  851. * iocb slot returned by the function is not guaranteed to be available.
  852. * The function returns pointer to the next available iocb slot if there
  853. * is available slot in the ring, else it returns NULL.
  854. * If the get index of the ring is ahead of the put index, the function
  855. * will post an error attention event to the worker thread to take the
  856. * HBA to offline state.
  857. **/
  858. static IOCB_t *
  859. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  860. {
  861. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  862. uint32_t max_cmd_idx = pring->numCiocb;
  863. if ((pring->next_cmdidx == pring->cmdidx) &&
  864. (++pring->next_cmdidx >= max_cmd_idx))
  865. pring->next_cmdidx = 0;
  866. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  867. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  868. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  869. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  870. "0315 Ring %d issue: portCmdGet %d "
  871. "is bigger than cmd ring %d\n",
  872. pring->ringno,
  873. pring->local_getidx, max_cmd_idx);
  874. phba->link_state = LPFC_HBA_ERROR;
  875. /*
  876. * All error attention handlers are posted to
  877. * worker thread
  878. */
  879. phba->work_ha |= HA_ERATT;
  880. phba->work_hs = HS_FFER3;
  881. lpfc_worker_wake_up(phba);
  882. return NULL;
  883. }
  884. if (pring->local_getidx == pring->next_cmdidx)
  885. return NULL;
  886. }
  887. return lpfc_cmd_iocb(phba, pring);
  888. }
  889. /**
  890. * lpfc_sli_next_iotag - Get an iotag for the iocb
  891. * @phba: Pointer to HBA context object.
  892. * @iocbq: Pointer to driver iocb object.
  893. *
  894. * This function gets an iotag for the iocb. If there is no unused iotag and
  895. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  896. * array and assigns a new iotag.
  897. * The function returns the allocated iotag if successful, else returns zero.
  898. * Zero is not a valid iotag.
  899. * The caller is not required to hold any lock.
  900. **/
  901. uint16_t
  902. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  903. {
  904. struct lpfc_iocbq **new_arr;
  905. struct lpfc_iocbq **old_arr;
  906. size_t new_len;
  907. struct lpfc_sli *psli = &phba->sli;
  908. uint16_t iotag;
  909. spin_lock_irq(&phba->hbalock);
  910. iotag = psli->last_iotag;
  911. if(++iotag < psli->iocbq_lookup_len) {
  912. psli->last_iotag = iotag;
  913. psli->iocbq_lookup[iotag] = iocbq;
  914. spin_unlock_irq(&phba->hbalock);
  915. iocbq->iotag = iotag;
  916. return iotag;
  917. } else if (psli->iocbq_lookup_len < (0xffff
  918. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  919. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  920. spin_unlock_irq(&phba->hbalock);
  921. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  922. GFP_KERNEL);
  923. if (new_arr) {
  924. spin_lock_irq(&phba->hbalock);
  925. old_arr = psli->iocbq_lookup;
  926. if (new_len <= psli->iocbq_lookup_len) {
  927. /* highly unprobable case */
  928. kfree(new_arr);
  929. iotag = psli->last_iotag;
  930. if(++iotag < psli->iocbq_lookup_len) {
  931. psli->last_iotag = iotag;
  932. psli->iocbq_lookup[iotag] = iocbq;
  933. spin_unlock_irq(&phba->hbalock);
  934. iocbq->iotag = iotag;
  935. return iotag;
  936. }
  937. spin_unlock_irq(&phba->hbalock);
  938. return 0;
  939. }
  940. if (psli->iocbq_lookup)
  941. memcpy(new_arr, old_arr,
  942. ((psli->last_iotag + 1) *
  943. sizeof (struct lpfc_iocbq *)));
  944. psli->iocbq_lookup = new_arr;
  945. psli->iocbq_lookup_len = new_len;
  946. psli->last_iotag = iotag;
  947. psli->iocbq_lookup[iotag] = iocbq;
  948. spin_unlock_irq(&phba->hbalock);
  949. iocbq->iotag = iotag;
  950. kfree(old_arr);
  951. return iotag;
  952. }
  953. } else
  954. spin_unlock_irq(&phba->hbalock);
  955. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  956. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  957. psli->last_iotag);
  958. return 0;
  959. }
  960. /**
  961. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  962. * @phba: Pointer to HBA context object.
  963. * @pring: Pointer to driver SLI ring object.
  964. * @iocb: Pointer to iocb slot in the ring.
  965. * @nextiocb: Pointer to driver iocb object which need to be
  966. * posted to firmware.
  967. *
  968. * This function is called with hbalock held to post a new iocb to
  969. * the firmware. This function copies the new iocb to ring iocb slot and
  970. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  971. * a completion call back for this iocb else the function will free the
  972. * iocb object.
  973. **/
  974. static void
  975. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  976. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  977. {
  978. /*
  979. * Set up an iotag
  980. */
  981. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  982. if (pring->ringno == LPFC_ELS_RING) {
  983. lpfc_debugfs_slow_ring_trc(phba,
  984. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  985. *(((uint32_t *) &nextiocb->iocb) + 4),
  986. *(((uint32_t *) &nextiocb->iocb) + 6),
  987. *(((uint32_t *) &nextiocb->iocb) + 7));
  988. }
  989. /*
  990. * Issue iocb command to adapter
  991. */
  992. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  993. wmb();
  994. pring->stats.iocb_cmd++;
  995. /*
  996. * If there is no completion routine to call, we can release the
  997. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  998. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  999. */
  1000. if (nextiocb->iocb_cmpl)
  1001. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1002. else
  1003. __lpfc_sli_release_iocbq(phba, nextiocb);
  1004. /*
  1005. * Let the HBA know what IOCB slot will be the next one the
  1006. * driver will put a command into.
  1007. */
  1008. pring->cmdidx = pring->next_cmdidx;
  1009. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1010. }
  1011. /**
  1012. * lpfc_sli_update_full_ring - Update the chip attention register
  1013. * @phba: Pointer to HBA context object.
  1014. * @pring: Pointer to driver SLI ring object.
  1015. *
  1016. * The caller is not required to hold any lock for calling this function.
  1017. * This function updates the chip attention bits for the ring to inform firmware
  1018. * that there are pending work to be done for this ring and requests an
  1019. * interrupt when there is space available in the ring. This function is
  1020. * called when the driver is unable to post more iocbs to the ring due
  1021. * to unavailability of space in the ring.
  1022. **/
  1023. static void
  1024. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1025. {
  1026. int ringno = pring->ringno;
  1027. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1028. wmb();
  1029. /*
  1030. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1031. * The HBA will tell us when an IOCB entry is available.
  1032. */
  1033. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1034. readl(phba->CAregaddr); /* flush */
  1035. pring->stats.iocb_cmd_full++;
  1036. }
  1037. /**
  1038. * lpfc_sli_update_ring - Update chip attention register
  1039. * @phba: Pointer to HBA context object.
  1040. * @pring: Pointer to driver SLI ring object.
  1041. *
  1042. * This function updates the chip attention register bit for the
  1043. * given ring to inform HBA that there is more work to be done
  1044. * in this ring. The caller is not required to hold any lock.
  1045. **/
  1046. static void
  1047. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1048. {
  1049. int ringno = pring->ringno;
  1050. /*
  1051. * Tell the HBA that there is work to do in this ring.
  1052. */
  1053. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1054. wmb();
  1055. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1056. readl(phba->CAregaddr); /* flush */
  1057. }
  1058. }
  1059. /**
  1060. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1061. * @phba: Pointer to HBA context object.
  1062. * @pring: Pointer to driver SLI ring object.
  1063. *
  1064. * This function is called with hbalock held to post pending iocbs
  1065. * in the txq to the firmware. This function is called when driver
  1066. * detects space available in the ring.
  1067. **/
  1068. static void
  1069. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1070. {
  1071. IOCB_t *iocb;
  1072. struct lpfc_iocbq *nextiocb;
  1073. /*
  1074. * Check to see if:
  1075. * (a) there is anything on the txq to send
  1076. * (b) link is up
  1077. * (c) link attention events can be processed (fcp ring only)
  1078. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1079. */
  1080. if (pring->txq_cnt &&
  1081. lpfc_is_link_up(phba) &&
  1082. (pring->ringno != phba->sli.fcp_ring ||
  1083. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1084. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1085. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1086. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1087. if (iocb)
  1088. lpfc_sli_update_ring(phba, pring);
  1089. else
  1090. lpfc_sli_update_full_ring(phba, pring);
  1091. }
  1092. return;
  1093. }
  1094. /**
  1095. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1096. * @phba: Pointer to HBA context object.
  1097. * @hbqno: HBQ number.
  1098. *
  1099. * This function is called with hbalock held to get the next
  1100. * available slot for the given HBQ. If there is free slot
  1101. * available for the HBQ it will return pointer to the next available
  1102. * HBQ entry else it will return NULL.
  1103. **/
  1104. static struct lpfc_hbq_entry *
  1105. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1106. {
  1107. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1108. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1109. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1110. hbqp->next_hbqPutIdx = 0;
  1111. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1112. uint32_t raw_index = phba->hbq_get[hbqno];
  1113. uint32_t getidx = le32_to_cpu(raw_index);
  1114. hbqp->local_hbqGetIdx = getidx;
  1115. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1116. lpfc_printf_log(phba, KERN_ERR,
  1117. LOG_SLI | LOG_VPORT,
  1118. "1802 HBQ %d: local_hbqGetIdx "
  1119. "%u is > than hbqp->entry_count %u\n",
  1120. hbqno, hbqp->local_hbqGetIdx,
  1121. hbqp->entry_count);
  1122. phba->link_state = LPFC_HBA_ERROR;
  1123. return NULL;
  1124. }
  1125. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1126. return NULL;
  1127. }
  1128. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1129. hbqp->hbqPutIdx;
  1130. }
  1131. /**
  1132. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1133. * @phba: Pointer to HBA context object.
  1134. *
  1135. * This function is called with no lock held to free all the
  1136. * hbq buffers while uninitializing the SLI interface. It also
  1137. * frees the HBQ buffers returned by the firmware but not yet
  1138. * processed by the upper layers.
  1139. **/
  1140. void
  1141. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1142. {
  1143. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1144. struct hbq_dmabuf *hbq_buf;
  1145. unsigned long flags;
  1146. int i, hbq_count;
  1147. uint32_t hbqno;
  1148. hbq_count = lpfc_sli_hbq_count();
  1149. /* Return all memory used by all HBQs */
  1150. spin_lock_irqsave(&phba->hbalock, flags);
  1151. for (i = 0; i < hbq_count; ++i) {
  1152. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1153. &phba->hbqs[i].hbq_buffer_list, list) {
  1154. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1155. list_del(&hbq_buf->dbuf.list);
  1156. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1157. }
  1158. phba->hbqs[i].buffer_count = 0;
  1159. }
  1160. /* Return all HBQ buffer that are in-fly */
  1161. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1162. list) {
  1163. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1164. list_del(&hbq_buf->dbuf.list);
  1165. if (hbq_buf->tag == -1) {
  1166. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1167. (phba, hbq_buf);
  1168. } else {
  1169. hbqno = hbq_buf->tag >> 16;
  1170. if (hbqno >= LPFC_MAX_HBQS)
  1171. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1172. (phba, hbq_buf);
  1173. else
  1174. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1175. hbq_buf);
  1176. }
  1177. }
  1178. /* Mark the HBQs not in use */
  1179. phba->hbq_in_use = 0;
  1180. spin_unlock_irqrestore(&phba->hbalock, flags);
  1181. }
  1182. /**
  1183. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1184. * @phba: Pointer to HBA context object.
  1185. * @hbqno: HBQ number.
  1186. * @hbq_buf: Pointer to HBQ buffer.
  1187. *
  1188. * This function is called with the hbalock held to post a
  1189. * hbq buffer to the firmware. If the function finds an empty
  1190. * slot in the HBQ, it will post the buffer. The function will return
  1191. * pointer to the hbq entry if it successfully post the buffer
  1192. * else it will return NULL.
  1193. **/
  1194. static int
  1195. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1196. struct hbq_dmabuf *hbq_buf)
  1197. {
  1198. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1199. }
  1200. /**
  1201. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1202. * @phba: Pointer to HBA context object.
  1203. * @hbqno: HBQ number.
  1204. * @hbq_buf: Pointer to HBQ buffer.
  1205. *
  1206. * This function is called with the hbalock held to post a hbq buffer to the
  1207. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1208. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1209. * it successfully post the buffer else it will return an error.
  1210. **/
  1211. static int
  1212. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1213. struct hbq_dmabuf *hbq_buf)
  1214. {
  1215. struct lpfc_hbq_entry *hbqe;
  1216. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1217. /* Get next HBQ entry slot to use */
  1218. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1219. if (hbqe) {
  1220. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1221. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1222. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1223. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1224. hbqe->bde.tus.f.bdeFlags = 0;
  1225. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1226. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1227. /* Sync SLIM */
  1228. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1229. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1230. /* flush */
  1231. readl(phba->hbq_put + hbqno);
  1232. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1233. return 0;
  1234. } else
  1235. return -ENOMEM;
  1236. }
  1237. /**
  1238. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1239. * @phba: Pointer to HBA context object.
  1240. * @hbqno: HBQ number.
  1241. * @hbq_buf: Pointer to HBQ buffer.
  1242. *
  1243. * This function is called with the hbalock held to post an RQE to the SLI4
  1244. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1245. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1246. **/
  1247. static int
  1248. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1249. struct hbq_dmabuf *hbq_buf)
  1250. {
  1251. int rc;
  1252. struct lpfc_rqe hrqe;
  1253. struct lpfc_rqe drqe;
  1254. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1255. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1256. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1257. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1258. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1259. &hrqe, &drqe);
  1260. if (rc < 0)
  1261. return rc;
  1262. hbq_buf->tag = rc;
  1263. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1264. return 0;
  1265. }
  1266. /* HBQ for ELS and CT traffic. */
  1267. static struct lpfc_hbq_init lpfc_els_hbq = {
  1268. .rn = 1,
  1269. .entry_count = 200,
  1270. .mask_count = 0,
  1271. .profile = 0,
  1272. .ring_mask = (1 << LPFC_ELS_RING),
  1273. .buffer_count = 0,
  1274. .init_count = 40,
  1275. .add_count = 40,
  1276. };
  1277. /* HBQ for the extra ring if needed */
  1278. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1279. .rn = 1,
  1280. .entry_count = 200,
  1281. .mask_count = 0,
  1282. .profile = 0,
  1283. .ring_mask = (1 << LPFC_EXTRA_RING),
  1284. .buffer_count = 0,
  1285. .init_count = 0,
  1286. .add_count = 5,
  1287. };
  1288. /* Array of HBQs */
  1289. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1290. &lpfc_els_hbq,
  1291. &lpfc_extra_hbq,
  1292. };
  1293. /**
  1294. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1295. * @phba: Pointer to HBA context object.
  1296. * @hbqno: HBQ number.
  1297. * @count: Number of HBQ buffers to be posted.
  1298. *
  1299. * This function is called with no lock held to post more hbq buffers to the
  1300. * given HBQ. The function returns the number of HBQ buffers successfully
  1301. * posted.
  1302. **/
  1303. static int
  1304. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1305. {
  1306. uint32_t i, posted = 0;
  1307. unsigned long flags;
  1308. struct hbq_dmabuf *hbq_buffer;
  1309. LIST_HEAD(hbq_buf_list);
  1310. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1311. return 0;
  1312. if ((phba->hbqs[hbqno].buffer_count + count) >
  1313. lpfc_hbq_defs[hbqno]->entry_count)
  1314. count = lpfc_hbq_defs[hbqno]->entry_count -
  1315. phba->hbqs[hbqno].buffer_count;
  1316. if (!count)
  1317. return 0;
  1318. /* Allocate HBQ entries */
  1319. for (i = 0; i < count; i++) {
  1320. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1321. if (!hbq_buffer)
  1322. break;
  1323. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1324. }
  1325. /* Check whether HBQ is still in use */
  1326. spin_lock_irqsave(&phba->hbalock, flags);
  1327. if (!phba->hbq_in_use)
  1328. goto err;
  1329. while (!list_empty(&hbq_buf_list)) {
  1330. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1331. dbuf.list);
  1332. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1333. (hbqno << 16));
  1334. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1335. phba->hbqs[hbqno].buffer_count++;
  1336. posted++;
  1337. } else
  1338. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1339. }
  1340. spin_unlock_irqrestore(&phba->hbalock, flags);
  1341. return posted;
  1342. err:
  1343. spin_unlock_irqrestore(&phba->hbalock, flags);
  1344. while (!list_empty(&hbq_buf_list)) {
  1345. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1346. dbuf.list);
  1347. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1348. }
  1349. return 0;
  1350. }
  1351. /**
  1352. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1353. * @phba: Pointer to HBA context object.
  1354. * @qno: HBQ number.
  1355. *
  1356. * This function posts more buffers to the HBQ. This function
  1357. * is called with no lock held. The function returns the number of HBQ entries
  1358. * successfully allocated.
  1359. **/
  1360. int
  1361. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1362. {
  1363. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1364. lpfc_hbq_defs[qno]->add_count));
  1365. }
  1366. /**
  1367. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1368. * @phba: Pointer to HBA context object.
  1369. * @qno: HBQ queue number.
  1370. *
  1371. * This function is called from SLI initialization code path with
  1372. * no lock held to post initial HBQ buffers to firmware. The
  1373. * function returns the number of HBQ entries successfully allocated.
  1374. **/
  1375. static int
  1376. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1377. {
  1378. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1379. lpfc_hbq_defs[qno]->init_count));
  1380. }
  1381. /**
  1382. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1383. * @phba: Pointer to HBA context object.
  1384. * @hbqno: HBQ number.
  1385. *
  1386. * This function removes the first hbq buffer on an hbq list and returns a
  1387. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1388. **/
  1389. static struct hbq_dmabuf *
  1390. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1391. {
  1392. struct lpfc_dmabuf *d_buf;
  1393. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1394. if (!d_buf)
  1395. return NULL;
  1396. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1397. }
  1398. /**
  1399. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1400. * @phba: Pointer to HBA context object.
  1401. * @tag: Tag of the hbq buffer.
  1402. *
  1403. * This function is called with hbalock held. This function searches
  1404. * for the hbq buffer associated with the given tag in the hbq buffer
  1405. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1406. * it returns NULL.
  1407. **/
  1408. static struct hbq_dmabuf *
  1409. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1410. {
  1411. struct lpfc_dmabuf *d_buf;
  1412. struct hbq_dmabuf *hbq_buf;
  1413. uint32_t hbqno;
  1414. hbqno = tag >> 16;
  1415. if (hbqno >= LPFC_MAX_HBQS)
  1416. return NULL;
  1417. spin_lock_irq(&phba->hbalock);
  1418. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1419. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1420. if (hbq_buf->tag == tag) {
  1421. spin_unlock_irq(&phba->hbalock);
  1422. return hbq_buf;
  1423. }
  1424. }
  1425. spin_unlock_irq(&phba->hbalock);
  1426. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1427. "1803 Bad hbq tag. Data: x%x x%x\n",
  1428. tag, phba->hbqs[tag >> 16].buffer_count);
  1429. return NULL;
  1430. }
  1431. /**
  1432. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1433. * @phba: Pointer to HBA context object.
  1434. * @hbq_buffer: Pointer to HBQ buffer.
  1435. *
  1436. * This function is called with hbalock. This function gives back
  1437. * the hbq buffer to firmware. If the HBQ does not have space to
  1438. * post the buffer, it will free the buffer.
  1439. **/
  1440. void
  1441. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1442. {
  1443. uint32_t hbqno;
  1444. if (hbq_buffer) {
  1445. hbqno = hbq_buffer->tag >> 16;
  1446. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1447. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1448. }
  1449. }
  1450. /**
  1451. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1452. * @mbxCommand: mailbox command code.
  1453. *
  1454. * This function is called by the mailbox event handler function to verify
  1455. * that the completed mailbox command is a legitimate mailbox command. If the
  1456. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1457. * and the mailbox event handler will take the HBA offline.
  1458. **/
  1459. static int
  1460. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1461. {
  1462. uint8_t ret;
  1463. switch (mbxCommand) {
  1464. case MBX_LOAD_SM:
  1465. case MBX_READ_NV:
  1466. case MBX_WRITE_NV:
  1467. case MBX_WRITE_VPARMS:
  1468. case MBX_RUN_BIU_DIAG:
  1469. case MBX_INIT_LINK:
  1470. case MBX_DOWN_LINK:
  1471. case MBX_CONFIG_LINK:
  1472. case MBX_CONFIG_RING:
  1473. case MBX_RESET_RING:
  1474. case MBX_READ_CONFIG:
  1475. case MBX_READ_RCONFIG:
  1476. case MBX_READ_SPARM:
  1477. case MBX_READ_STATUS:
  1478. case MBX_READ_RPI:
  1479. case MBX_READ_XRI:
  1480. case MBX_READ_REV:
  1481. case MBX_READ_LNK_STAT:
  1482. case MBX_REG_LOGIN:
  1483. case MBX_UNREG_LOGIN:
  1484. case MBX_READ_LA:
  1485. case MBX_CLEAR_LA:
  1486. case MBX_DUMP_MEMORY:
  1487. case MBX_DUMP_CONTEXT:
  1488. case MBX_RUN_DIAGS:
  1489. case MBX_RESTART:
  1490. case MBX_UPDATE_CFG:
  1491. case MBX_DOWN_LOAD:
  1492. case MBX_DEL_LD_ENTRY:
  1493. case MBX_RUN_PROGRAM:
  1494. case MBX_SET_MASK:
  1495. case MBX_SET_VARIABLE:
  1496. case MBX_UNREG_D_ID:
  1497. case MBX_KILL_BOARD:
  1498. case MBX_CONFIG_FARP:
  1499. case MBX_BEACON:
  1500. case MBX_LOAD_AREA:
  1501. case MBX_RUN_BIU_DIAG64:
  1502. case MBX_CONFIG_PORT:
  1503. case MBX_READ_SPARM64:
  1504. case MBX_READ_RPI64:
  1505. case MBX_REG_LOGIN64:
  1506. case MBX_READ_LA64:
  1507. case MBX_WRITE_WWN:
  1508. case MBX_SET_DEBUG:
  1509. case MBX_LOAD_EXP_ROM:
  1510. case MBX_ASYNCEVT_ENABLE:
  1511. case MBX_REG_VPI:
  1512. case MBX_UNREG_VPI:
  1513. case MBX_HEARTBEAT:
  1514. case MBX_PORT_CAPABILITIES:
  1515. case MBX_PORT_IOV_CONTROL:
  1516. case MBX_SLI4_CONFIG:
  1517. case MBX_SLI4_REQ_FTRS:
  1518. case MBX_REG_FCFI:
  1519. case MBX_UNREG_FCFI:
  1520. case MBX_REG_VFI:
  1521. case MBX_UNREG_VFI:
  1522. case MBX_INIT_VPI:
  1523. case MBX_INIT_VFI:
  1524. case MBX_RESUME_RPI:
  1525. ret = mbxCommand;
  1526. break;
  1527. default:
  1528. ret = MBX_SHUTDOWN;
  1529. break;
  1530. }
  1531. return ret;
  1532. }
  1533. /**
  1534. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1535. * @phba: Pointer to HBA context object.
  1536. * @pmboxq: Pointer to mailbox command.
  1537. *
  1538. * This is completion handler function for mailbox commands issued from
  1539. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1540. * mailbox event handler function with no lock held. This function
  1541. * will wake up thread waiting on the wait queue pointed by context1
  1542. * of the mailbox.
  1543. **/
  1544. void
  1545. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1546. {
  1547. wait_queue_head_t *pdone_q;
  1548. unsigned long drvr_flag;
  1549. /*
  1550. * If pdone_q is empty, the driver thread gave up waiting and
  1551. * continued running.
  1552. */
  1553. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1554. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1555. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1556. if (pdone_q)
  1557. wake_up_interruptible(pdone_q);
  1558. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1559. return;
  1560. }
  1561. /**
  1562. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1563. * @phba: Pointer to HBA context object.
  1564. * @pmb: Pointer to mailbox object.
  1565. *
  1566. * This function is the default mailbox completion handler. It
  1567. * frees the memory resources associated with the completed mailbox
  1568. * command. If the completed command is a REG_LOGIN mailbox command,
  1569. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1570. **/
  1571. void
  1572. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1573. {
  1574. struct lpfc_dmabuf *mp;
  1575. uint16_t rpi, vpi;
  1576. int rc;
  1577. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1578. if (mp) {
  1579. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1580. kfree(mp);
  1581. }
  1582. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1583. (phba->sli_rev == LPFC_SLI_REV4))
  1584. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1585. /*
  1586. * If a REG_LOGIN succeeded after node is destroyed or node
  1587. * is in re-discovery driver need to cleanup the RPI.
  1588. */
  1589. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1590. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1591. !pmb->u.mb.mbxStatus) {
  1592. rpi = pmb->u.mb.un.varWords[0];
  1593. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1594. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1595. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1596. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1597. if (rc != MBX_NOT_FINISHED)
  1598. return;
  1599. }
  1600. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1601. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1602. else
  1603. mempool_free(pmb, phba->mbox_mem_pool);
  1604. }
  1605. /**
  1606. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1607. * @phba: Pointer to HBA context object.
  1608. *
  1609. * This function is called with no lock held. This function processes all
  1610. * the completed mailbox commands and gives it to upper layers. The interrupt
  1611. * service routine processes mailbox completion interrupt and adds completed
  1612. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1613. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1614. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1615. * function returns the mailbox commands to the upper layer by calling the
  1616. * completion handler function of each mailbox.
  1617. **/
  1618. int
  1619. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1620. {
  1621. MAILBOX_t *pmbox;
  1622. LPFC_MBOXQ_t *pmb;
  1623. int rc;
  1624. LIST_HEAD(cmplq);
  1625. phba->sli.slistat.mbox_event++;
  1626. /* Get all completed mailboxe buffers into the cmplq */
  1627. spin_lock_irq(&phba->hbalock);
  1628. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1629. spin_unlock_irq(&phba->hbalock);
  1630. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1631. do {
  1632. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1633. if (pmb == NULL)
  1634. break;
  1635. pmbox = &pmb->u.mb;
  1636. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1637. if (pmb->vport) {
  1638. lpfc_debugfs_disc_trc(pmb->vport,
  1639. LPFC_DISC_TRC_MBOX_VPORT,
  1640. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1641. (uint32_t)pmbox->mbxCommand,
  1642. pmbox->un.varWords[0],
  1643. pmbox->un.varWords[1]);
  1644. }
  1645. else {
  1646. lpfc_debugfs_disc_trc(phba->pport,
  1647. LPFC_DISC_TRC_MBOX,
  1648. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1649. (uint32_t)pmbox->mbxCommand,
  1650. pmbox->un.varWords[0],
  1651. pmbox->un.varWords[1]);
  1652. }
  1653. }
  1654. /*
  1655. * It is a fatal error if unknown mbox command completion.
  1656. */
  1657. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1658. MBX_SHUTDOWN) {
  1659. /* Unknown mailbox command compl */
  1660. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1661. "(%d):0323 Unknown Mailbox command "
  1662. "x%x (x%x) Cmpl\n",
  1663. pmb->vport ? pmb->vport->vpi : 0,
  1664. pmbox->mbxCommand,
  1665. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1666. phba->link_state = LPFC_HBA_ERROR;
  1667. phba->work_hs = HS_FFER3;
  1668. lpfc_handle_eratt(phba);
  1669. continue;
  1670. }
  1671. if (pmbox->mbxStatus) {
  1672. phba->sli.slistat.mbox_stat_err++;
  1673. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1674. /* Mbox cmd cmpl error - RETRYing */
  1675. lpfc_printf_log(phba, KERN_INFO,
  1676. LOG_MBOX | LOG_SLI,
  1677. "(%d):0305 Mbox cmd cmpl "
  1678. "error - RETRYing Data: x%x "
  1679. "(x%x) x%x x%x x%x\n",
  1680. pmb->vport ? pmb->vport->vpi :0,
  1681. pmbox->mbxCommand,
  1682. lpfc_sli4_mbox_opcode_get(phba,
  1683. pmb),
  1684. pmbox->mbxStatus,
  1685. pmbox->un.varWords[0],
  1686. pmb->vport->port_state);
  1687. pmbox->mbxStatus = 0;
  1688. pmbox->mbxOwner = OWN_HOST;
  1689. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1690. if (rc != MBX_NOT_FINISHED)
  1691. continue;
  1692. }
  1693. }
  1694. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1695. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1696. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1697. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1698. pmb->vport ? pmb->vport->vpi : 0,
  1699. pmbox->mbxCommand,
  1700. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1701. pmb->mbox_cmpl,
  1702. *((uint32_t *) pmbox),
  1703. pmbox->un.varWords[0],
  1704. pmbox->un.varWords[1],
  1705. pmbox->un.varWords[2],
  1706. pmbox->un.varWords[3],
  1707. pmbox->un.varWords[4],
  1708. pmbox->un.varWords[5],
  1709. pmbox->un.varWords[6],
  1710. pmbox->un.varWords[7]);
  1711. if (pmb->mbox_cmpl)
  1712. pmb->mbox_cmpl(phba,pmb);
  1713. } while (1);
  1714. return 0;
  1715. }
  1716. /**
  1717. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1718. * @phba: Pointer to HBA context object.
  1719. * @pring: Pointer to driver SLI ring object.
  1720. * @tag: buffer tag.
  1721. *
  1722. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1723. * is set in the tag the buffer is posted for a particular exchange,
  1724. * the function will return the buffer without replacing the buffer.
  1725. * If the buffer is for unsolicited ELS or CT traffic, this function
  1726. * returns the buffer and also posts another buffer to the firmware.
  1727. **/
  1728. static struct lpfc_dmabuf *
  1729. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1730. struct lpfc_sli_ring *pring,
  1731. uint32_t tag)
  1732. {
  1733. struct hbq_dmabuf *hbq_entry;
  1734. if (tag & QUE_BUFTAG_BIT)
  1735. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1736. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1737. if (!hbq_entry)
  1738. return NULL;
  1739. return &hbq_entry->dbuf;
  1740. }
  1741. /**
  1742. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1743. * @phba: Pointer to HBA context object.
  1744. * @pring: Pointer to driver SLI ring object.
  1745. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1746. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1747. * @fch_type: the type for the first frame of the sequence.
  1748. *
  1749. * This function is called with no lock held. This function uses the r_ctl and
  1750. * type of the received sequence to find the correct callback function to call
  1751. * to process the sequence.
  1752. **/
  1753. static int
  1754. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1755. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1756. uint32_t fch_type)
  1757. {
  1758. int i;
  1759. /* unSolicited Responses */
  1760. if (pring->prt[0].profile) {
  1761. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1762. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1763. saveq);
  1764. return 1;
  1765. }
  1766. /* We must search, based on rctl / type
  1767. for the right routine */
  1768. for (i = 0; i < pring->num_mask; i++) {
  1769. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1770. (pring->prt[i].type == fch_type)) {
  1771. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1772. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1773. (phba, pring, saveq);
  1774. return 1;
  1775. }
  1776. }
  1777. return 0;
  1778. }
  1779. /**
  1780. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1781. * @phba: Pointer to HBA context object.
  1782. * @pring: Pointer to driver SLI ring object.
  1783. * @saveq: Pointer to the unsolicited iocb.
  1784. *
  1785. * This function is called with no lock held by the ring event handler
  1786. * when there is an unsolicited iocb posted to the response ring by the
  1787. * firmware. This function gets the buffer associated with the iocbs
  1788. * and calls the event handler for the ring. This function handles both
  1789. * qring buffers and hbq buffers.
  1790. * When the function returns 1 the caller can free the iocb object otherwise
  1791. * upper layer functions will free the iocb objects.
  1792. **/
  1793. static int
  1794. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1795. struct lpfc_iocbq *saveq)
  1796. {
  1797. IOCB_t * irsp;
  1798. WORD5 * w5p;
  1799. uint32_t Rctl, Type;
  1800. uint32_t match;
  1801. struct lpfc_iocbq *iocbq;
  1802. struct lpfc_dmabuf *dmzbuf;
  1803. match = 0;
  1804. irsp = &(saveq->iocb);
  1805. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1806. if (pring->lpfc_sli_rcv_async_status)
  1807. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1808. else
  1809. lpfc_printf_log(phba,
  1810. KERN_WARNING,
  1811. LOG_SLI,
  1812. "0316 Ring %d handler: unexpected "
  1813. "ASYNC_STATUS iocb received evt_code "
  1814. "0x%x\n",
  1815. pring->ringno,
  1816. irsp->un.asyncstat.evt_code);
  1817. return 1;
  1818. }
  1819. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1820. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1821. if (irsp->ulpBdeCount > 0) {
  1822. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1823. irsp->un.ulpWord[3]);
  1824. lpfc_in_buf_free(phba, dmzbuf);
  1825. }
  1826. if (irsp->ulpBdeCount > 1) {
  1827. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1828. irsp->unsli3.sli3Words[3]);
  1829. lpfc_in_buf_free(phba, dmzbuf);
  1830. }
  1831. if (irsp->ulpBdeCount > 2) {
  1832. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1833. irsp->unsli3.sli3Words[7]);
  1834. lpfc_in_buf_free(phba, dmzbuf);
  1835. }
  1836. return 1;
  1837. }
  1838. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1839. if (irsp->ulpBdeCount != 0) {
  1840. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1841. irsp->un.ulpWord[3]);
  1842. if (!saveq->context2)
  1843. lpfc_printf_log(phba,
  1844. KERN_ERR,
  1845. LOG_SLI,
  1846. "0341 Ring %d Cannot find buffer for "
  1847. "an unsolicited iocb. tag 0x%x\n",
  1848. pring->ringno,
  1849. irsp->un.ulpWord[3]);
  1850. }
  1851. if (irsp->ulpBdeCount == 2) {
  1852. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1853. irsp->unsli3.sli3Words[7]);
  1854. if (!saveq->context3)
  1855. lpfc_printf_log(phba,
  1856. KERN_ERR,
  1857. LOG_SLI,
  1858. "0342 Ring %d Cannot find buffer for an"
  1859. " unsolicited iocb. tag 0x%x\n",
  1860. pring->ringno,
  1861. irsp->unsli3.sli3Words[7]);
  1862. }
  1863. list_for_each_entry(iocbq, &saveq->list, list) {
  1864. irsp = &(iocbq->iocb);
  1865. if (irsp->ulpBdeCount != 0) {
  1866. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1867. irsp->un.ulpWord[3]);
  1868. if (!iocbq->context2)
  1869. lpfc_printf_log(phba,
  1870. KERN_ERR,
  1871. LOG_SLI,
  1872. "0343 Ring %d Cannot find "
  1873. "buffer for an unsolicited iocb"
  1874. ". tag 0x%x\n", pring->ringno,
  1875. irsp->un.ulpWord[3]);
  1876. }
  1877. if (irsp->ulpBdeCount == 2) {
  1878. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1879. irsp->unsli3.sli3Words[7]);
  1880. if (!iocbq->context3)
  1881. lpfc_printf_log(phba,
  1882. KERN_ERR,
  1883. LOG_SLI,
  1884. "0344 Ring %d Cannot find "
  1885. "buffer for an unsolicited "
  1886. "iocb. tag 0x%x\n",
  1887. pring->ringno,
  1888. irsp->unsli3.sli3Words[7]);
  1889. }
  1890. }
  1891. }
  1892. if (irsp->ulpBdeCount != 0 &&
  1893. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1894. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1895. int found = 0;
  1896. /* search continue save q for same XRI */
  1897. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1898. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1899. list_add_tail(&saveq->list, &iocbq->list);
  1900. found = 1;
  1901. break;
  1902. }
  1903. }
  1904. if (!found)
  1905. list_add_tail(&saveq->clist,
  1906. &pring->iocb_continue_saveq);
  1907. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1908. list_del_init(&iocbq->clist);
  1909. saveq = iocbq;
  1910. irsp = &(saveq->iocb);
  1911. } else
  1912. return 0;
  1913. }
  1914. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1915. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1916. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1917. Rctl = FC_RCTL_ELS_REQ;
  1918. Type = FC_TYPE_ELS;
  1919. } else {
  1920. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1921. Rctl = w5p->hcsw.Rctl;
  1922. Type = w5p->hcsw.Type;
  1923. /* Firmware Workaround */
  1924. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1925. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1926. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1927. Rctl = FC_RCTL_ELS_REQ;
  1928. Type = FC_TYPE_ELS;
  1929. w5p->hcsw.Rctl = Rctl;
  1930. w5p->hcsw.Type = Type;
  1931. }
  1932. }
  1933. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1934. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1935. "0313 Ring %d handler: unexpected Rctl x%x "
  1936. "Type x%x received\n",
  1937. pring->ringno, Rctl, Type);
  1938. return 1;
  1939. }
  1940. /**
  1941. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1942. * @phba: Pointer to HBA context object.
  1943. * @pring: Pointer to driver SLI ring object.
  1944. * @prspiocb: Pointer to response iocb object.
  1945. *
  1946. * This function looks up the iocb_lookup table to get the command iocb
  1947. * corresponding to the given response iocb using the iotag of the
  1948. * response iocb. This function is called with the hbalock held.
  1949. * This function returns the command iocb object if it finds the command
  1950. * iocb else returns NULL.
  1951. **/
  1952. static struct lpfc_iocbq *
  1953. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1954. struct lpfc_sli_ring *pring,
  1955. struct lpfc_iocbq *prspiocb)
  1956. {
  1957. struct lpfc_iocbq *cmd_iocb = NULL;
  1958. uint16_t iotag;
  1959. iotag = prspiocb->iocb.ulpIoTag;
  1960. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1961. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1962. list_del_init(&cmd_iocb->list);
  1963. pring->txcmplq_cnt--;
  1964. return cmd_iocb;
  1965. }
  1966. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1967. "0317 iotag x%x is out off "
  1968. "range: max iotag x%x wd0 x%x\n",
  1969. iotag, phba->sli.last_iotag,
  1970. *(((uint32_t *) &prspiocb->iocb) + 7));
  1971. return NULL;
  1972. }
  1973. /**
  1974. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1975. * @phba: Pointer to HBA context object.
  1976. * @pring: Pointer to driver SLI ring object.
  1977. * @iotag: IOCB tag.
  1978. *
  1979. * This function looks up the iocb_lookup table to get the command iocb
  1980. * corresponding to the given iotag. This function is called with the
  1981. * hbalock held.
  1982. * This function returns the command iocb object if it finds the command
  1983. * iocb else returns NULL.
  1984. **/
  1985. static struct lpfc_iocbq *
  1986. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1987. struct lpfc_sli_ring *pring, uint16_t iotag)
  1988. {
  1989. struct lpfc_iocbq *cmd_iocb;
  1990. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1991. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1992. list_del_init(&cmd_iocb->list);
  1993. pring->txcmplq_cnt--;
  1994. return cmd_iocb;
  1995. }
  1996. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1997. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  1998. iotag, phba->sli.last_iotag);
  1999. return NULL;
  2000. }
  2001. /**
  2002. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2003. * @phba: Pointer to HBA context object.
  2004. * @pring: Pointer to driver SLI ring object.
  2005. * @saveq: Pointer to the response iocb to be processed.
  2006. *
  2007. * This function is called by the ring event handler for non-fcp
  2008. * rings when there is a new response iocb in the response ring.
  2009. * The caller is not required to hold any locks. This function
  2010. * gets the command iocb associated with the response iocb and
  2011. * calls the completion handler for the command iocb. If there
  2012. * is no completion handler, the function will free the resources
  2013. * associated with command iocb. If the response iocb is for
  2014. * an already aborted command iocb, the status of the completion
  2015. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2016. * This function always returns 1.
  2017. **/
  2018. static int
  2019. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2020. struct lpfc_iocbq *saveq)
  2021. {
  2022. struct lpfc_iocbq *cmdiocbp;
  2023. int rc = 1;
  2024. unsigned long iflag;
  2025. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2026. spin_lock_irqsave(&phba->hbalock, iflag);
  2027. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2028. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2029. if (cmdiocbp) {
  2030. if (cmdiocbp->iocb_cmpl) {
  2031. /*
  2032. * If an ELS command failed send an event to mgmt
  2033. * application.
  2034. */
  2035. if (saveq->iocb.ulpStatus &&
  2036. (pring->ringno == LPFC_ELS_RING) &&
  2037. (cmdiocbp->iocb.ulpCommand ==
  2038. CMD_ELS_REQUEST64_CR))
  2039. lpfc_send_els_failure_event(phba,
  2040. cmdiocbp, saveq);
  2041. /*
  2042. * Post all ELS completions to the worker thread.
  2043. * All other are passed to the completion callback.
  2044. */
  2045. if (pring->ringno == LPFC_ELS_RING) {
  2046. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  2047. cmdiocbp->iocb_flag &=
  2048. ~LPFC_DRIVER_ABORTED;
  2049. saveq->iocb.ulpStatus =
  2050. IOSTAT_LOCAL_REJECT;
  2051. saveq->iocb.un.ulpWord[4] =
  2052. IOERR_SLI_ABORTED;
  2053. /* Firmware could still be in progress
  2054. * of DMAing payload, so don't free data
  2055. * buffer till after a hbeat.
  2056. */
  2057. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2058. }
  2059. }
  2060. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2061. } else
  2062. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2063. } else {
  2064. /*
  2065. * Unknown initiating command based on the response iotag.
  2066. * This could be the case on the ELS ring because of
  2067. * lpfc_els_abort().
  2068. */
  2069. if (pring->ringno != LPFC_ELS_RING) {
  2070. /*
  2071. * Ring <ringno> handler: unexpected completion IoTag
  2072. * <IoTag>
  2073. */
  2074. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2075. "0322 Ring %d handler: "
  2076. "unexpected completion IoTag x%x "
  2077. "Data: x%x x%x x%x x%x\n",
  2078. pring->ringno,
  2079. saveq->iocb.ulpIoTag,
  2080. saveq->iocb.ulpStatus,
  2081. saveq->iocb.un.ulpWord[4],
  2082. saveq->iocb.ulpCommand,
  2083. saveq->iocb.ulpContext);
  2084. }
  2085. }
  2086. return rc;
  2087. }
  2088. /**
  2089. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2090. * @phba: Pointer to HBA context object.
  2091. * @pring: Pointer to driver SLI ring object.
  2092. *
  2093. * This function is called from the iocb ring event handlers when
  2094. * put pointer is ahead of the get pointer for a ring. This function signal
  2095. * an error attention condition to the worker thread and the worker
  2096. * thread will transition the HBA to offline state.
  2097. **/
  2098. static void
  2099. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2100. {
  2101. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2102. /*
  2103. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2104. * rsp ring <portRspMax>
  2105. */
  2106. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2107. "0312 Ring %d handler: portRspPut %d "
  2108. "is bigger than rsp ring %d\n",
  2109. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2110. pring->numRiocb);
  2111. phba->link_state = LPFC_HBA_ERROR;
  2112. /*
  2113. * All error attention handlers are posted to
  2114. * worker thread
  2115. */
  2116. phba->work_ha |= HA_ERATT;
  2117. phba->work_hs = HS_FFER3;
  2118. lpfc_worker_wake_up(phba);
  2119. return;
  2120. }
  2121. /**
  2122. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2123. * @ptr: Pointer to address of HBA context object.
  2124. *
  2125. * This function is invoked by the Error Attention polling timer when the
  2126. * timer times out. It will check the SLI Error Attention register for
  2127. * possible attention events. If so, it will post an Error Attention event
  2128. * and wake up worker thread to process it. Otherwise, it will set up the
  2129. * Error Attention polling timer for the next poll.
  2130. **/
  2131. void lpfc_poll_eratt(unsigned long ptr)
  2132. {
  2133. struct lpfc_hba *phba;
  2134. uint32_t eratt = 0;
  2135. phba = (struct lpfc_hba *)ptr;
  2136. /* Check chip HA register for error event */
  2137. eratt = lpfc_sli_check_eratt(phba);
  2138. if (eratt)
  2139. /* Tell the worker thread there is work to do */
  2140. lpfc_worker_wake_up(phba);
  2141. else
  2142. /* Restart the timer for next eratt poll */
  2143. mod_timer(&phba->eratt_poll, jiffies +
  2144. HZ * LPFC_ERATT_POLL_INTERVAL);
  2145. return;
  2146. }
  2147. /**
  2148. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2149. * @phba: Pointer to HBA context object.
  2150. * @pring: Pointer to driver SLI ring object.
  2151. * @mask: Host attention register mask for this ring.
  2152. *
  2153. * This function is called from the interrupt context when there is a ring
  2154. * event for the fcp ring. The caller does not hold any lock.
  2155. * The function processes each response iocb in the response ring until it
  2156. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2157. * LE bit set. The function will call the completion handler of the command iocb
  2158. * if the response iocb indicates a completion for a command iocb or it is
  2159. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2160. * function if this is an unsolicited iocb.
  2161. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2162. * to check it explicitly.
  2163. */
  2164. int
  2165. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2166. struct lpfc_sli_ring *pring, uint32_t mask)
  2167. {
  2168. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2169. IOCB_t *irsp = NULL;
  2170. IOCB_t *entry = NULL;
  2171. struct lpfc_iocbq *cmdiocbq = NULL;
  2172. struct lpfc_iocbq rspiocbq;
  2173. uint32_t status;
  2174. uint32_t portRspPut, portRspMax;
  2175. int rc = 1;
  2176. lpfc_iocb_type type;
  2177. unsigned long iflag;
  2178. uint32_t rsp_cmpl = 0;
  2179. spin_lock_irqsave(&phba->hbalock, iflag);
  2180. pring->stats.iocb_event++;
  2181. /*
  2182. * The next available response entry should never exceed the maximum
  2183. * entries. If it does, treat it as an adapter hardware error.
  2184. */
  2185. portRspMax = pring->numRiocb;
  2186. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2187. if (unlikely(portRspPut >= portRspMax)) {
  2188. lpfc_sli_rsp_pointers_error(phba, pring);
  2189. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2190. return 1;
  2191. }
  2192. if (phba->fcp_ring_in_use) {
  2193. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2194. return 1;
  2195. } else
  2196. phba->fcp_ring_in_use = 1;
  2197. rmb();
  2198. while (pring->rspidx != portRspPut) {
  2199. /*
  2200. * Fetch an entry off the ring and copy it into a local data
  2201. * structure. The copy involves a byte-swap since the
  2202. * network byte order and pci byte orders are different.
  2203. */
  2204. entry = lpfc_resp_iocb(phba, pring);
  2205. phba->last_completion_time = jiffies;
  2206. if (++pring->rspidx >= portRspMax)
  2207. pring->rspidx = 0;
  2208. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2209. (uint32_t *) &rspiocbq.iocb,
  2210. phba->iocb_rsp_size);
  2211. INIT_LIST_HEAD(&(rspiocbq.list));
  2212. irsp = &rspiocbq.iocb;
  2213. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2214. pring->stats.iocb_rsp++;
  2215. rsp_cmpl++;
  2216. if (unlikely(irsp->ulpStatus)) {
  2217. /*
  2218. * If resource errors reported from HBA, reduce
  2219. * queuedepths of the SCSI device.
  2220. */
  2221. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2222. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2223. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2224. phba->lpfc_rampdown_queue_depth(phba);
  2225. spin_lock_irqsave(&phba->hbalock, iflag);
  2226. }
  2227. /* Rsp ring <ringno> error: IOCB */
  2228. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2229. "0336 Rsp Ring %d error: IOCB Data: "
  2230. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2231. pring->ringno,
  2232. irsp->un.ulpWord[0],
  2233. irsp->un.ulpWord[1],
  2234. irsp->un.ulpWord[2],
  2235. irsp->un.ulpWord[3],
  2236. irsp->un.ulpWord[4],
  2237. irsp->un.ulpWord[5],
  2238. *(uint32_t *)&irsp->un1,
  2239. *((uint32_t *)&irsp->un1 + 1));
  2240. }
  2241. switch (type) {
  2242. case LPFC_ABORT_IOCB:
  2243. case LPFC_SOL_IOCB:
  2244. /*
  2245. * Idle exchange closed via ABTS from port. No iocb
  2246. * resources need to be recovered.
  2247. */
  2248. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2249. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2250. "0333 IOCB cmd 0x%x"
  2251. " processed. Skipping"
  2252. " completion\n",
  2253. irsp->ulpCommand);
  2254. break;
  2255. }
  2256. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2257. &rspiocbq);
  2258. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2259. spin_unlock_irqrestore(&phba->hbalock,
  2260. iflag);
  2261. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2262. &rspiocbq);
  2263. spin_lock_irqsave(&phba->hbalock,
  2264. iflag);
  2265. }
  2266. break;
  2267. case LPFC_UNSOL_IOCB:
  2268. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2269. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2270. spin_lock_irqsave(&phba->hbalock, iflag);
  2271. break;
  2272. default:
  2273. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2274. char adaptermsg[LPFC_MAX_ADPTMSG];
  2275. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2276. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2277. MAX_MSG_DATA);
  2278. dev_warn(&((phba->pcidev)->dev),
  2279. "lpfc%d: %s\n",
  2280. phba->brd_no, adaptermsg);
  2281. } else {
  2282. /* Unknown IOCB command */
  2283. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2284. "0334 Unknown IOCB command "
  2285. "Data: x%x, x%x x%x x%x x%x\n",
  2286. type, irsp->ulpCommand,
  2287. irsp->ulpStatus,
  2288. irsp->ulpIoTag,
  2289. irsp->ulpContext);
  2290. }
  2291. break;
  2292. }
  2293. /*
  2294. * The response IOCB has been processed. Update the ring
  2295. * pointer in SLIM. If the port response put pointer has not
  2296. * been updated, sync the pgp->rspPutInx and fetch the new port
  2297. * response put pointer.
  2298. */
  2299. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2300. if (pring->rspidx == portRspPut)
  2301. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2302. }
  2303. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2304. pring->stats.iocb_rsp_full++;
  2305. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2306. writel(status, phba->CAregaddr);
  2307. readl(phba->CAregaddr);
  2308. }
  2309. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2310. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2311. pring->stats.iocb_cmd_empty++;
  2312. /* Force update of the local copy of cmdGetInx */
  2313. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2314. lpfc_sli_resume_iocb(phba, pring);
  2315. if ((pring->lpfc_sli_cmd_available))
  2316. (pring->lpfc_sli_cmd_available) (phba, pring);
  2317. }
  2318. phba->fcp_ring_in_use = 0;
  2319. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2320. return rc;
  2321. }
  2322. /**
  2323. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2324. * @phba: Pointer to HBA context object.
  2325. * @pring: Pointer to driver SLI ring object.
  2326. * @rspiocbp: Pointer to driver response IOCB object.
  2327. *
  2328. * This function is called from the worker thread when there is a slow-path
  2329. * response IOCB to process. This function chains all the response iocbs until
  2330. * seeing the iocb with the LE bit set. The function will call
  2331. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2332. * completion of a command iocb. The function will call the
  2333. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2334. * The function frees the resources or calls the completion handler if this
  2335. * iocb is an abort completion. The function returns NULL when the response
  2336. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2337. * this function shall chain the iocb on to the iocb_continueq and return the
  2338. * response iocb passed in.
  2339. **/
  2340. static struct lpfc_iocbq *
  2341. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2342. struct lpfc_iocbq *rspiocbp)
  2343. {
  2344. struct lpfc_iocbq *saveq;
  2345. struct lpfc_iocbq *cmdiocbp;
  2346. struct lpfc_iocbq *next_iocb;
  2347. IOCB_t *irsp = NULL;
  2348. uint32_t free_saveq;
  2349. uint8_t iocb_cmd_type;
  2350. lpfc_iocb_type type;
  2351. unsigned long iflag;
  2352. int rc;
  2353. spin_lock_irqsave(&phba->hbalock, iflag);
  2354. /* First add the response iocb to the countinueq list */
  2355. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2356. pring->iocb_continueq_cnt++;
  2357. /* Now, determine whetehr the list is completed for processing */
  2358. irsp = &rspiocbp->iocb;
  2359. if (irsp->ulpLe) {
  2360. /*
  2361. * By default, the driver expects to free all resources
  2362. * associated with this iocb completion.
  2363. */
  2364. free_saveq = 1;
  2365. saveq = list_get_first(&pring->iocb_continueq,
  2366. struct lpfc_iocbq, list);
  2367. irsp = &(saveq->iocb);
  2368. list_del_init(&pring->iocb_continueq);
  2369. pring->iocb_continueq_cnt = 0;
  2370. pring->stats.iocb_rsp++;
  2371. /*
  2372. * If resource errors reported from HBA, reduce
  2373. * queuedepths of the SCSI device.
  2374. */
  2375. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2376. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2377. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2378. phba->lpfc_rampdown_queue_depth(phba);
  2379. spin_lock_irqsave(&phba->hbalock, iflag);
  2380. }
  2381. if (irsp->ulpStatus) {
  2382. /* Rsp ring <ringno> error: IOCB */
  2383. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2384. "0328 Rsp Ring %d error: "
  2385. "IOCB Data: "
  2386. "x%x x%x x%x x%x "
  2387. "x%x x%x x%x x%x "
  2388. "x%x x%x x%x x%x "
  2389. "x%x x%x x%x x%x\n",
  2390. pring->ringno,
  2391. irsp->un.ulpWord[0],
  2392. irsp->un.ulpWord[1],
  2393. irsp->un.ulpWord[2],
  2394. irsp->un.ulpWord[3],
  2395. irsp->un.ulpWord[4],
  2396. irsp->un.ulpWord[5],
  2397. *(((uint32_t *) irsp) + 6),
  2398. *(((uint32_t *) irsp) + 7),
  2399. *(((uint32_t *) irsp) + 8),
  2400. *(((uint32_t *) irsp) + 9),
  2401. *(((uint32_t *) irsp) + 10),
  2402. *(((uint32_t *) irsp) + 11),
  2403. *(((uint32_t *) irsp) + 12),
  2404. *(((uint32_t *) irsp) + 13),
  2405. *(((uint32_t *) irsp) + 14),
  2406. *(((uint32_t *) irsp) + 15));
  2407. }
  2408. /*
  2409. * Fetch the IOCB command type and call the correct completion
  2410. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2411. * get freed back to the lpfc_iocb_list by the discovery
  2412. * kernel thread.
  2413. */
  2414. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2415. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2416. switch (type) {
  2417. case LPFC_SOL_IOCB:
  2418. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2419. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2420. spin_lock_irqsave(&phba->hbalock, iflag);
  2421. break;
  2422. case LPFC_UNSOL_IOCB:
  2423. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2424. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2425. spin_lock_irqsave(&phba->hbalock, iflag);
  2426. if (!rc)
  2427. free_saveq = 0;
  2428. break;
  2429. case LPFC_ABORT_IOCB:
  2430. cmdiocbp = NULL;
  2431. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2432. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2433. saveq);
  2434. if (cmdiocbp) {
  2435. /* Call the specified completion routine */
  2436. if (cmdiocbp->iocb_cmpl) {
  2437. spin_unlock_irqrestore(&phba->hbalock,
  2438. iflag);
  2439. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2440. saveq);
  2441. spin_lock_irqsave(&phba->hbalock,
  2442. iflag);
  2443. } else
  2444. __lpfc_sli_release_iocbq(phba,
  2445. cmdiocbp);
  2446. }
  2447. break;
  2448. case LPFC_UNKNOWN_IOCB:
  2449. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2450. char adaptermsg[LPFC_MAX_ADPTMSG];
  2451. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2452. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2453. MAX_MSG_DATA);
  2454. dev_warn(&((phba->pcidev)->dev),
  2455. "lpfc%d: %s\n",
  2456. phba->brd_no, adaptermsg);
  2457. } else {
  2458. /* Unknown IOCB command */
  2459. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2460. "0335 Unknown IOCB "
  2461. "command Data: x%x "
  2462. "x%x x%x x%x\n",
  2463. irsp->ulpCommand,
  2464. irsp->ulpStatus,
  2465. irsp->ulpIoTag,
  2466. irsp->ulpContext);
  2467. }
  2468. break;
  2469. }
  2470. if (free_saveq) {
  2471. list_for_each_entry_safe(rspiocbp, next_iocb,
  2472. &saveq->list, list) {
  2473. list_del(&rspiocbp->list);
  2474. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2475. }
  2476. __lpfc_sli_release_iocbq(phba, saveq);
  2477. }
  2478. rspiocbp = NULL;
  2479. }
  2480. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2481. return rspiocbp;
  2482. }
  2483. /**
  2484. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2485. * @phba: Pointer to HBA context object.
  2486. * @pring: Pointer to driver SLI ring object.
  2487. * @mask: Host attention register mask for this ring.
  2488. *
  2489. * This routine wraps the actual slow_ring event process routine from the
  2490. * API jump table function pointer from the lpfc_hba struct.
  2491. **/
  2492. void
  2493. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2494. struct lpfc_sli_ring *pring, uint32_t mask)
  2495. {
  2496. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2497. }
  2498. /**
  2499. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2500. * @phba: Pointer to HBA context object.
  2501. * @pring: Pointer to driver SLI ring object.
  2502. * @mask: Host attention register mask for this ring.
  2503. *
  2504. * This function is called from the worker thread when there is a ring event
  2505. * for non-fcp rings. The caller does not hold any lock. The function will
  2506. * remove each response iocb in the response ring and calls the handle
  2507. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2508. **/
  2509. static void
  2510. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2511. struct lpfc_sli_ring *pring, uint32_t mask)
  2512. {
  2513. struct lpfc_pgp *pgp;
  2514. IOCB_t *entry;
  2515. IOCB_t *irsp = NULL;
  2516. struct lpfc_iocbq *rspiocbp = NULL;
  2517. uint32_t portRspPut, portRspMax;
  2518. unsigned long iflag;
  2519. uint32_t status;
  2520. pgp = &phba->port_gp[pring->ringno];
  2521. spin_lock_irqsave(&phba->hbalock, iflag);
  2522. pring->stats.iocb_event++;
  2523. /*
  2524. * The next available response entry should never exceed the maximum
  2525. * entries. If it does, treat it as an adapter hardware error.
  2526. */
  2527. portRspMax = pring->numRiocb;
  2528. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2529. if (portRspPut >= portRspMax) {
  2530. /*
  2531. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2532. * rsp ring <portRspMax>
  2533. */
  2534. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2535. "0303 Ring %d handler: portRspPut %d "
  2536. "is bigger than rsp ring %d\n",
  2537. pring->ringno, portRspPut, portRspMax);
  2538. phba->link_state = LPFC_HBA_ERROR;
  2539. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2540. phba->work_hs = HS_FFER3;
  2541. lpfc_handle_eratt(phba);
  2542. return;
  2543. }
  2544. rmb();
  2545. while (pring->rspidx != portRspPut) {
  2546. /*
  2547. * Build a completion list and call the appropriate handler.
  2548. * The process is to get the next available response iocb, get
  2549. * a free iocb from the list, copy the response data into the
  2550. * free iocb, insert to the continuation list, and update the
  2551. * next response index to slim. This process makes response
  2552. * iocb's in the ring available to DMA as fast as possible but
  2553. * pays a penalty for a copy operation. Since the iocb is
  2554. * only 32 bytes, this penalty is considered small relative to
  2555. * the PCI reads for register values and a slim write. When
  2556. * the ulpLe field is set, the entire Command has been
  2557. * received.
  2558. */
  2559. entry = lpfc_resp_iocb(phba, pring);
  2560. phba->last_completion_time = jiffies;
  2561. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2562. if (rspiocbp == NULL) {
  2563. printk(KERN_ERR "%s: out of buffers! Failing "
  2564. "completion.\n", __func__);
  2565. break;
  2566. }
  2567. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2568. phba->iocb_rsp_size);
  2569. irsp = &rspiocbp->iocb;
  2570. if (++pring->rspidx >= portRspMax)
  2571. pring->rspidx = 0;
  2572. if (pring->ringno == LPFC_ELS_RING) {
  2573. lpfc_debugfs_slow_ring_trc(phba,
  2574. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2575. *(((uint32_t *) irsp) + 4),
  2576. *(((uint32_t *) irsp) + 6),
  2577. *(((uint32_t *) irsp) + 7));
  2578. }
  2579. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2580. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2581. /* Handle the response IOCB */
  2582. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2583. spin_lock_irqsave(&phba->hbalock, iflag);
  2584. /*
  2585. * If the port response put pointer has not been updated, sync
  2586. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2587. * response put pointer.
  2588. */
  2589. if (pring->rspidx == portRspPut) {
  2590. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2591. }
  2592. } /* while (pring->rspidx != portRspPut) */
  2593. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2594. /* At least one response entry has been freed */
  2595. pring->stats.iocb_rsp_full++;
  2596. /* SET RxRE_RSP in Chip Att register */
  2597. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2598. writel(status, phba->CAregaddr);
  2599. readl(phba->CAregaddr); /* flush */
  2600. }
  2601. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2602. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2603. pring->stats.iocb_cmd_empty++;
  2604. /* Force update of the local copy of cmdGetInx */
  2605. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2606. lpfc_sli_resume_iocb(phba, pring);
  2607. if ((pring->lpfc_sli_cmd_available))
  2608. (pring->lpfc_sli_cmd_available) (phba, pring);
  2609. }
  2610. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2611. return;
  2612. }
  2613. /**
  2614. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2615. * @phba: Pointer to HBA context object.
  2616. * @pring: Pointer to driver SLI ring object.
  2617. * @mask: Host attention register mask for this ring.
  2618. *
  2619. * This function is called from the worker thread when there is a pending
  2620. * ELS response iocb on the driver internal slow-path response iocb worker
  2621. * queue. The caller does not hold any lock. The function will remove each
  2622. * response iocb from the response worker queue and calls the handle
  2623. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2624. **/
  2625. static void
  2626. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2627. struct lpfc_sli_ring *pring, uint32_t mask)
  2628. {
  2629. struct lpfc_iocbq *irspiocbq;
  2630. struct hbq_dmabuf *dmabuf;
  2631. struct lpfc_cq_event *cq_event;
  2632. unsigned long iflag;
  2633. spin_lock_irqsave(&phba->hbalock, iflag);
  2634. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2635. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2636. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2637. /* Get the response iocb from the head of work queue */
  2638. spin_lock_irqsave(&phba->hbalock, iflag);
  2639. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2640. cq_event, struct lpfc_cq_event, list);
  2641. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2642. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2643. case CQE_CODE_COMPL_WQE:
  2644. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2645. cq_event);
  2646. /* Translate ELS WCQE to response IOCBQ */
  2647. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2648. irspiocbq);
  2649. if (irspiocbq)
  2650. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2651. irspiocbq);
  2652. break;
  2653. case CQE_CODE_RECEIVE:
  2654. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2655. cq_event);
  2656. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2657. break;
  2658. default:
  2659. break;
  2660. }
  2661. }
  2662. }
  2663. /**
  2664. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2665. * @phba: Pointer to HBA context object.
  2666. * @pring: Pointer to driver SLI ring object.
  2667. *
  2668. * This function aborts all iocbs in the given ring and frees all the iocb
  2669. * objects in txq. This function issues an abort iocb for all the iocb commands
  2670. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2671. * the return of this function. The caller is not required to hold any locks.
  2672. **/
  2673. void
  2674. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2675. {
  2676. LIST_HEAD(completions);
  2677. struct lpfc_iocbq *iocb, *next_iocb;
  2678. if (pring->ringno == LPFC_ELS_RING) {
  2679. lpfc_fabric_abort_hba(phba);
  2680. }
  2681. /* Error everything on txq and txcmplq
  2682. * First do the txq.
  2683. */
  2684. spin_lock_irq(&phba->hbalock);
  2685. list_splice_init(&pring->txq, &completions);
  2686. pring->txq_cnt = 0;
  2687. /* Next issue ABTS for everything on the txcmplq */
  2688. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2689. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2690. spin_unlock_irq(&phba->hbalock);
  2691. /* Cancel all the IOCBs from the completions list */
  2692. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2693. IOERR_SLI_ABORTED);
  2694. }
  2695. /**
  2696. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2697. * @phba: Pointer to HBA context object.
  2698. *
  2699. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2700. * objects in txq and txcmplq. This function will not issue abort iocbs
  2701. * for all the iocb commands in txcmplq, they will just be returned with
  2702. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2703. * slot has been permanently disabled.
  2704. **/
  2705. void
  2706. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2707. {
  2708. LIST_HEAD(txq);
  2709. LIST_HEAD(txcmplq);
  2710. struct lpfc_sli *psli = &phba->sli;
  2711. struct lpfc_sli_ring *pring;
  2712. /* Currently, only one fcp ring */
  2713. pring = &psli->ring[psli->fcp_ring];
  2714. spin_lock_irq(&phba->hbalock);
  2715. /* Retrieve everything on txq */
  2716. list_splice_init(&pring->txq, &txq);
  2717. pring->txq_cnt = 0;
  2718. /* Retrieve everything on the txcmplq */
  2719. list_splice_init(&pring->txcmplq, &txcmplq);
  2720. pring->txcmplq_cnt = 0;
  2721. spin_unlock_irq(&phba->hbalock);
  2722. /* Flush the txq */
  2723. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2724. IOERR_SLI_DOWN);
  2725. /* Flush the txcmpq */
  2726. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2727. IOERR_SLI_DOWN);
  2728. }
  2729. /**
  2730. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2731. * @phba: Pointer to HBA context object.
  2732. * @mask: Bit mask to be checked.
  2733. *
  2734. * This function reads the host status register and compares
  2735. * with the provided bit mask to check if HBA completed
  2736. * the restart. This function will wait in a loop for the
  2737. * HBA to complete restart. If the HBA does not restart within
  2738. * 15 iterations, the function will reset the HBA again. The
  2739. * function returns 1 when HBA fail to restart otherwise returns
  2740. * zero.
  2741. **/
  2742. static int
  2743. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2744. {
  2745. uint32_t status;
  2746. int i = 0;
  2747. int retval = 0;
  2748. /* Read the HBA Host Status Register */
  2749. status = readl(phba->HSregaddr);
  2750. /*
  2751. * Check status register every 100ms for 5 retries, then every
  2752. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2753. * every 2.5 sec for 4.
  2754. * Break our of the loop if errors occurred during init.
  2755. */
  2756. while (((status & mask) != mask) &&
  2757. !(status & HS_FFERM) &&
  2758. i++ < 20) {
  2759. if (i <= 5)
  2760. msleep(10);
  2761. else if (i <= 10)
  2762. msleep(500);
  2763. else
  2764. msleep(2500);
  2765. if (i == 15) {
  2766. /* Do post */
  2767. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2768. lpfc_sli_brdrestart(phba);
  2769. }
  2770. /* Read the HBA Host Status Register */
  2771. status = readl(phba->HSregaddr);
  2772. }
  2773. /* Check to see if any errors occurred during init */
  2774. if ((status & HS_FFERM) || (i >= 20)) {
  2775. phba->link_state = LPFC_HBA_ERROR;
  2776. retval = 1;
  2777. }
  2778. return retval;
  2779. }
  2780. /**
  2781. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2782. * @phba: Pointer to HBA context object.
  2783. * @mask: Bit mask to be checked.
  2784. *
  2785. * This function checks the host status register to check if HBA is
  2786. * ready. This function will wait in a loop for the HBA to be ready
  2787. * If the HBA is not ready , the function will will reset the HBA PCI
  2788. * function again. The function returns 1 when HBA fail to be ready
  2789. * otherwise returns zero.
  2790. **/
  2791. static int
  2792. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2793. {
  2794. uint32_t status;
  2795. int retval = 0;
  2796. /* Read the HBA Host Status Register */
  2797. status = lpfc_sli4_post_status_check(phba);
  2798. if (status) {
  2799. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2800. lpfc_sli_brdrestart(phba);
  2801. status = lpfc_sli4_post_status_check(phba);
  2802. }
  2803. /* Check to see if any errors occurred during init */
  2804. if (status) {
  2805. phba->link_state = LPFC_HBA_ERROR;
  2806. retval = 1;
  2807. } else
  2808. phba->sli4_hba.intr_enable = 0;
  2809. return retval;
  2810. }
  2811. /**
  2812. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2813. * @phba: Pointer to HBA context object.
  2814. * @mask: Bit mask to be checked.
  2815. *
  2816. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2817. * from the API jump table function pointer from the lpfc_hba struct.
  2818. **/
  2819. int
  2820. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2821. {
  2822. return phba->lpfc_sli_brdready(phba, mask);
  2823. }
  2824. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2825. /**
  2826. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2827. * @phba: Pointer to HBA context object.
  2828. *
  2829. * This function is called before resetting an HBA. This
  2830. * function requests HBA to quiesce DMAs before a reset.
  2831. **/
  2832. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2833. {
  2834. uint32_t __iomem *resp_buf;
  2835. uint32_t __iomem *mbox_buf;
  2836. volatile uint32_t mbox;
  2837. uint32_t hc_copy;
  2838. int i;
  2839. uint8_t hdrtype;
  2840. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2841. if (hdrtype != 0x80 ||
  2842. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2843. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2844. return;
  2845. /*
  2846. * Tell the other part of the chip to suspend temporarily all
  2847. * its DMA activity.
  2848. */
  2849. resp_buf = phba->MBslimaddr;
  2850. /* Disable the error attention */
  2851. hc_copy = readl(phba->HCregaddr);
  2852. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2853. readl(phba->HCregaddr); /* flush */
  2854. phba->link_flag |= LS_IGNORE_ERATT;
  2855. if (readl(phba->HAregaddr) & HA_ERATT) {
  2856. /* Clear Chip error bit */
  2857. writel(HA_ERATT, phba->HAregaddr);
  2858. phba->pport->stopped = 1;
  2859. }
  2860. mbox = 0;
  2861. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2862. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2863. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2864. mbox_buf = phba->MBslimaddr;
  2865. writel(mbox, mbox_buf);
  2866. for (i = 0;
  2867. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2868. mdelay(1);
  2869. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2870. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2871. phba->pport->stopped)
  2872. goto restore_hc;
  2873. else
  2874. goto clear_errat;
  2875. }
  2876. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2877. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2878. mdelay(1);
  2879. clear_errat:
  2880. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2881. mdelay(1);
  2882. if (readl(phba->HAregaddr) & HA_ERATT) {
  2883. writel(HA_ERATT, phba->HAregaddr);
  2884. phba->pport->stopped = 1;
  2885. }
  2886. restore_hc:
  2887. phba->link_flag &= ~LS_IGNORE_ERATT;
  2888. writel(hc_copy, phba->HCregaddr);
  2889. readl(phba->HCregaddr); /* flush */
  2890. }
  2891. /**
  2892. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2893. * @phba: Pointer to HBA context object.
  2894. *
  2895. * This function issues a kill_board mailbox command and waits for
  2896. * the error attention interrupt. This function is called for stopping
  2897. * the firmware processing. The caller is not required to hold any
  2898. * locks. This function calls lpfc_hba_down_post function to free
  2899. * any pending commands after the kill. The function will return 1 when it
  2900. * fails to kill the board else will return 0.
  2901. **/
  2902. int
  2903. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2904. {
  2905. struct lpfc_sli *psli;
  2906. LPFC_MBOXQ_t *pmb;
  2907. uint32_t status;
  2908. uint32_t ha_copy;
  2909. int retval;
  2910. int i = 0;
  2911. psli = &phba->sli;
  2912. /* Kill HBA */
  2913. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2914. "0329 Kill HBA Data: x%x x%x\n",
  2915. phba->pport->port_state, psli->sli_flag);
  2916. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2917. if (!pmb)
  2918. return 1;
  2919. /* Disable the error attention */
  2920. spin_lock_irq(&phba->hbalock);
  2921. status = readl(phba->HCregaddr);
  2922. status &= ~HC_ERINT_ENA;
  2923. writel(status, phba->HCregaddr);
  2924. readl(phba->HCregaddr); /* flush */
  2925. phba->link_flag |= LS_IGNORE_ERATT;
  2926. spin_unlock_irq(&phba->hbalock);
  2927. lpfc_kill_board(phba, pmb);
  2928. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2929. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2930. if (retval != MBX_SUCCESS) {
  2931. if (retval != MBX_BUSY)
  2932. mempool_free(pmb, phba->mbox_mem_pool);
  2933. spin_lock_irq(&phba->hbalock);
  2934. phba->link_flag &= ~LS_IGNORE_ERATT;
  2935. spin_unlock_irq(&phba->hbalock);
  2936. return 1;
  2937. }
  2938. spin_lock_irq(&phba->hbalock);
  2939. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  2940. spin_unlock_irq(&phba->hbalock);
  2941. mempool_free(pmb, phba->mbox_mem_pool);
  2942. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  2943. * attention every 100ms for 3 seconds. If we don't get ERATT after
  2944. * 3 seconds we still set HBA_ERROR state because the status of the
  2945. * board is now undefined.
  2946. */
  2947. ha_copy = readl(phba->HAregaddr);
  2948. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  2949. mdelay(100);
  2950. ha_copy = readl(phba->HAregaddr);
  2951. }
  2952. del_timer_sync(&psli->mbox_tmo);
  2953. if (ha_copy & HA_ERATT) {
  2954. writel(HA_ERATT, phba->HAregaddr);
  2955. phba->pport->stopped = 1;
  2956. }
  2957. spin_lock_irq(&phba->hbalock);
  2958. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2959. psli->mbox_active = NULL;
  2960. phba->link_flag &= ~LS_IGNORE_ERATT;
  2961. spin_unlock_irq(&phba->hbalock);
  2962. lpfc_hba_down_post(phba);
  2963. phba->link_state = LPFC_HBA_ERROR;
  2964. return ha_copy & HA_ERATT ? 0 : 1;
  2965. }
  2966. /**
  2967. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  2968. * @phba: Pointer to HBA context object.
  2969. *
  2970. * This function resets the HBA by writing HC_INITFF to the control
  2971. * register. After the HBA resets, this function resets all the iocb ring
  2972. * indices. This function disables PCI layer parity checking during
  2973. * the reset.
  2974. * This function returns 0 always.
  2975. * The caller is not required to hold any locks.
  2976. **/
  2977. int
  2978. lpfc_sli_brdreset(struct lpfc_hba *phba)
  2979. {
  2980. struct lpfc_sli *psli;
  2981. struct lpfc_sli_ring *pring;
  2982. uint16_t cfg_value;
  2983. int i;
  2984. psli = &phba->sli;
  2985. /* Reset HBA */
  2986. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2987. "0325 Reset HBA Data: x%x x%x\n",
  2988. phba->pport->port_state, psli->sli_flag);
  2989. /* perform board reset */
  2990. phba->fc_eventTag = 0;
  2991. phba->link_events = 0;
  2992. phba->pport->fc_myDID = 0;
  2993. phba->pport->fc_prevDID = 0;
  2994. /* Turn off parity checking and serr during the physical reset */
  2995. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  2996. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  2997. (cfg_value &
  2998. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  2999. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3000. /* Now toggle INITFF bit in the Host Control Register */
  3001. writel(HC_INITFF, phba->HCregaddr);
  3002. mdelay(1);
  3003. readl(phba->HCregaddr); /* flush */
  3004. writel(0, phba->HCregaddr);
  3005. readl(phba->HCregaddr); /* flush */
  3006. /* Restore PCI cmd register */
  3007. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3008. /* Initialize relevant SLI info */
  3009. for (i = 0; i < psli->num_rings; i++) {
  3010. pring = &psli->ring[i];
  3011. pring->flag = 0;
  3012. pring->rspidx = 0;
  3013. pring->next_cmdidx = 0;
  3014. pring->local_getidx = 0;
  3015. pring->cmdidx = 0;
  3016. pring->missbufcnt = 0;
  3017. }
  3018. phba->link_state = LPFC_WARM_START;
  3019. return 0;
  3020. }
  3021. /**
  3022. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3023. * @phba: Pointer to HBA context object.
  3024. *
  3025. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3026. * checking during resets the device. The caller is not required to hold
  3027. * any locks.
  3028. *
  3029. * This function returns 0 always.
  3030. **/
  3031. int
  3032. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3033. {
  3034. struct lpfc_sli *psli = &phba->sli;
  3035. uint16_t cfg_value;
  3036. uint8_t qindx;
  3037. /* Reset HBA */
  3038. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3039. "0295 Reset HBA Data: x%x x%x\n",
  3040. phba->pport->port_state, psli->sli_flag);
  3041. /* perform board reset */
  3042. phba->fc_eventTag = 0;
  3043. phba->link_events = 0;
  3044. phba->pport->fc_myDID = 0;
  3045. phba->pport->fc_prevDID = 0;
  3046. /* Turn off parity checking and serr during the physical reset */
  3047. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3048. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3049. (cfg_value &
  3050. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3051. spin_lock_irq(&phba->hbalock);
  3052. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3053. phba->fcf.fcf_flag = 0;
  3054. /* Clean up the child queue list for the CQs */
  3055. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3056. list_del_init(&phba->sli4_hba.els_wq->list);
  3057. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3058. list_del_init(&phba->sli4_hba.dat_rq->list);
  3059. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3060. list_del_init(&phba->sli4_hba.els_cq->list);
  3061. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3062. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3063. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3064. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3065. spin_unlock_irq(&phba->hbalock);
  3066. /* Now physically reset the device */
  3067. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3068. "0389 Performing PCI function reset!\n");
  3069. /* Perform FCoE PCI function reset */
  3070. lpfc_pci_function_reset(phba);
  3071. return 0;
  3072. }
  3073. /**
  3074. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3075. * @phba: Pointer to HBA context object.
  3076. *
  3077. * This function is called in the SLI initialization code path to
  3078. * restart the HBA. The caller is not required to hold any lock.
  3079. * This function writes MBX_RESTART mailbox command to the SLIM and
  3080. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3081. * function to free any pending commands. The function enables
  3082. * POST only during the first initialization. The function returns zero.
  3083. * The function does not guarantee completion of MBX_RESTART mailbox
  3084. * command before the return of this function.
  3085. **/
  3086. static int
  3087. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3088. {
  3089. MAILBOX_t *mb;
  3090. struct lpfc_sli *psli;
  3091. volatile uint32_t word0;
  3092. void __iomem *to_slim;
  3093. uint32_t hba_aer_enabled;
  3094. spin_lock_irq(&phba->hbalock);
  3095. /* Take PCIe device Advanced Error Reporting (AER) state */
  3096. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3097. psli = &phba->sli;
  3098. /* Restart HBA */
  3099. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3100. "0337 Restart HBA Data: x%x x%x\n",
  3101. phba->pport->port_state, psli->sli_flag);
  3102. word0 = 0;
  3103. mb = (MAILBOX_t *) &word0;
  3104. mb->mbxCommand = MBX_RESTART;
  3105. mb->mbxHc = 1;
  3106. lpfc_reset_barrier(phba);
  3107. to_slim = phba->MBslimaddr;
  3108. writel(*(uint32_t *) mb, to_slim);
  3109. readl(to_slim); /* flush */
  3110. /* Only skip post after fc_ffinit is completed */
  3111. if (phba->pport->port_state)
  3112. word0 = 1; /* This is really setting up word1 */
  3113. else
  3114. word0 = 0; /* This is really setting up word1 */
  3115. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3116. writel(*(uint32_t *) mb, to_slim);
  3117. readl(to_slim); /* flush */
  3118. lpfc_sli_brdreset(phba);
  3119. phba->pport->stopped = 0;
  3120. phba->link_state = LPFC_INIT_START;
  3121. phba->hba_flag = 0;
  3122. spin_unlock_irq(&phba->hbalock);
  3123. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3124. psli->stats_start = get_seconds();
  3125. /* Give the INITFF and Post time to settle. */
  3126. mdelay(100);
  3127. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3128. if (hba_aer_enabled)
  3129. pci_disable_pcie_error_reporting(phba->pcidev);
  3130. lpfc_hba_down_post(phba);
  3131. return 0;
  3132. }
  3133. /**
  3134. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3135. * @phba: Pointer to HBA context object.
  3136. *
  3137. * This function is called in the SLI initialization code path to restart
  3138. * a SLI4 HBA. The caller is not required to hold any lock.
  3139. * At the end of the function, it calls lpfc_hba_down_post function to
  3140. * free any pending commands.
  3141. **/
  3142. static int
  3143. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3144. {
  3145. struct lpfc_sli *psli = &phba->sli;
  3146. /* Restart HBA */
  3147. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3148. "0296 Restart HBA Data: x%x x%x\n",
  3149. phba->pport->port_state, psli->sli_flag);
  3150. lpfc_sli4_brdreset(phba);
  3151. spin_lock_irq(&phba->hbalock);
  3152. phba->pport->stopped = 0;
  3153. phba->link_state = LPFC_INIT_START;
  3154. phba->hba_flag = 0;
  3155. spin_unlock_irq(&phba->hbalock);
  3156. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3157. psli->stats_start = get_seconds();
  3158. lpfc_hba_down_post(phba);
  3159. return 0;
  3160. }
  3161. /**
  3162. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3163. * @phba: Pointer to HBA context object.
  3164. *
  3165. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3166. * API jump table function pointer from the lpfc_hba struct.
  3167. **/
  3168. int
  3169. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3170. {
  3171. return phba->lpfc_sli_brdrestart(phba);
  3172. }
  3173. /**
  3174. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3175. * @phba: Pointer to HBA context object.
  3176. *
  3177. * This function is called after a HBA restart to wait for successful
  3178. * restart of the HBA. Successful restart of the HBA is indicated by
  3179. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3180. * iteration, the function will restart the HBA again. The function returns
  3181. * zero if HBA successfully restarted else returns negative error code.
  3182. **/
  3183. static int
  3184. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3185. {
  3186. uint32_t status, i = 0;
  3187. /* Read the HBA Host Status Register */
  3188. status = readl(phba->HSregaddr);
  3189. /* Check status register to see what current state is */
  3190. i = 0;
  3191. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3192. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3193. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3194. * 4.
  3195. */
  3196. if (i++ >= 20) {
  3197. /* Adapter failed to init, timeout, status reg
  3198. <status> */
  3199. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3200. "0436 Adapter failed to init, "
  3201. "timeout, status reg x%x, "
  3202. "FW Data: A8 x%x AC x%x\n", status,
  3203. readl(phba->MBslimaddr + 0xa8),
  3204. readl(phba->MBslimaddr + 0xac));
  3205. phba->link_state = LPFC_HBA_ERROR;
  3206. return -ETIMEDOUT;
  3207. }
  3208. /* Check to see if any errors occurred during init */
  3209. if (status & HS_FFERM) {
  3210. /* ERROR: During chipset initialization */
  3211. /* Adapter failed to init, chipset, status reg
  3212. <status> */
  3213. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3214. "0437 Adapter failed to init, "
  3215. "chipset, status reg x%x, "
  3216. "FW Data: A8 x%x AC x%x\n", status,
  3217. readl(phba->MBslimaddr + 0xa8),
  3218. readl(phba->MBslimaddr + 0xac));
  3219. phba->link_state = LPFC_HBA_ERROR;
  3220. return -EIO;
  3221. }
  3222. if (i <= 5) {
  3223. msleep(10);
  3224. } else if (i <= 10) {
  3225. msleep(500);
  3226. } else {
  3227. msleep(2500);
  3228. }
  3229. if (i == 15) {
  3230. /* Do post */
  3231. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3232. lpfc_sli_brdrestart(phba);
  3233. }
  3234. /* Read the HBA Host Status Register */
  3235. status = readl(phba->HSregaddr);
  3236. }
  3237. /* Check to see if any errors occurred during init */
  3238. if (status & HS_FFERM) {
  3239. /* ERROR: During chipset initialization */
  3240. /* Adapter failed to init, chipset, status reg <status> */
  3241. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3242. "0438 Adapter failed to init, chipset, "
  3243. "status reg x%x, "
  3244. "FW Data: A8 x%x AC x%x\n", status,
  3245. readl(phba->MBslimaddr + 0xa8),
  3246. readl(phba->MBslimaddr + 0xac));
  3247. phba->link_state = LPFC_HBA_ERROR;
  3248. return -EIO;
  3249. }
  3250. /* Clear all interrupt enable conditions */
  3251. writel(0, phba->HCregaddr);
  3252. readl(phba->HCregaddr); /* flush */
  3253. /* setup host attn register */
  3254. writel(0xffffffff, phba->HAregaddr);
  3255. readl(phba->HAregaddr); /* flush */
  3256. return 0;
  3257. }
  3258. /**
  3259. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3260. *
  3261. * This function calculates and returns the number of HBQs required to be
  3262. * configured.
  3263. **/
  3264. int
  3265. lpfc_sli_hbq_count(void)
  3266. {
  3267. return ARRAY_SIZE(lpfc_hbq_defs);
  3268. }
  3269. /**
  3270. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3271. *
  3272. * This function adds the number of hbq entries in every HBQ to get
  3273. * the total number of hbq entries required for the HBA and returns
  3274. * the total count.
  3275. **/
  3276. static int
  3277. lpfc_sli_hbq_entry_count(void)
  3278. {
  3279. int hbq_count = lpfc_sli_hbq_count();
  3280. int count = 0;
  3281. int i;
  3282. for (i = 0; i < hbq_count; ++i)
  3283. count += lpfc_hbq_defs[i]->entry_count;
  3284. return count;
  3285. }
  3286. /**
  3287. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3288. *
  3289. * This function calculates amount of memory required for all hbq entries
  3290. * to be configured and returns the total memory required.
  3291. **/
  3292. int
  3293. lpfc_sli_hbq_size(void)
  3294. {
  3295. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3296. }
  3297. /**
  3298. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3299. * @phba: Pointer to HBA context object.
  3300. *
  3301. * This function is called during the SLI initialization to configure
  3302. * all the HBQs and post buffers to the HBQ. The caller is not
  3303. * required to hold any locks. This function will return zero if successful
  3304. * else it will return negative error code.
  3305. **/
  3306. static int
  3307. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3308. {
  3309. int hbq_count = lpfc_sli_hbq_count();
  3310. LPFC_MBOXQ_t *pmb;
  3311. MAILBOX_t *pmbox;
  3312. uint32_t hbqno;
  3313. uint32_t hbq_entry_index;
  3314. /* Get a Mailbox buffer to setup mailbox
  3315. * commands for HBA initialization
  3316. */
  3317. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3318. if (!pmb)
  3319. return -ENOMEM;
  3320. pmbox = &pmb->u.mb;
  3321. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3322. phba->link_state = LPFC_INIT_MBX_CMDS;
  3323. phba->hbq_in_use = 1;
  3324. hbq_entry_index = 0;
  3325. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3326. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3327. phba->hbqs[hbqno].hbqPutIdx = 0;
  3328. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3329. phba->hbqs[hbqno].entry_count =
  3330. lpfc_hbq_defs[hbqno]->entry_count;
  3331. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3332. hbq_entry_index, pmb);
  3333. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3334. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3335. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3336. mbxStatus <status>, ring <num> */
  3337. lpfc_printf_log(phba, KERN_ERR,
  3338. LOG_SLI | LOG_VPORT,
  3339. "1805 Adapter failed to init. "
  3340. "Data: x%x x%x x%x\n",
  3341. pmbox->mbxCommand,
  3342. pmbox->mbxStatus, hbqno);
  3343. phba->link_state = LPFC_HBA_ERROR;
  3344. mempool_free(pmb, phba->mbox_mem_pool);
  3345. return ENXIO;
  3346. }
  3347. }
  3348. phba->hbq_count = hbq_count;
  3349. mempool_free(pmb, phba->mbox_mem_pool);
  3350. /* Initially populate or replenish the HBQs */
  3351. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3352. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3353. return 0;
  3354. }
  3355. /**
  3356. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3357. * @phba: Pointer to HBA context object.
  3358. *
  3359. * This function is called during the SLI initialization to configure
  3360. * all the HBQs and post buffers to the HBQ. The caller is not
  3361. * required to hold any locks. This function will return zero if successful
  3362. * else it will return negative error code.
  3363. **/
  3364. static int
  3365. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3366. {
  3367. phba->hbq_in_use = 1;
  3368. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3369. phba->hbq_count = 1;
  3370. /* Initially populate or replenish the HBQs */
  3371. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3372. return 0;
  3373. }
  3374. /**
  3375. * lpfc_sli_config_port - Issue config port mailbox command
  3376. * @phba: Pointer to HBA context object.
  3377. * @sli_mode: sli mode - 2/3
  3378. *
  3379. * This function is called by the sli intialization code path
  3380. * to issue config_port mailbox command. This function restarts the
  3381. * HBA firmware and issues a config_port mailbox command to configure
  3382. * the SLI interface in the sli mode specified by sli_mode
  3383. * variable. The caller is not required to hold any locks.
  3384. * The function returns 0 if successful, else returns negative error
  3385. * code.
  3386. **/
  3387. int
  3388. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3389. {
  3390. LPFC_MBOXQ_t *pmb;
  3391. uint32_t resetcount = 0, rc = 0, done = 0;
  3392. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3393. if (!pmb) {
  3394. phba->link_state = LPFC_HBA_ERROR;
  3395. return -ENOMEM;
  3396. }
  3397. phba->sli_rev = sli_mode;
  3398. while (resetcount < 2 && !done) {
  3399. spin_lock_irq(&phba->hbalock);
  3400. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3401. spin_unlock_irq(&phba->hbalock);
  3402. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3403. lpfc_sli_brdrestart(phba);
  3404. rc = lpfc_sli_chipset_init(phba);
  3405. if (rc)
  3406. break;
  3407. spin_lock_irq(&phba->hbalock);
  3408. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3409. spin_unlock_irq(&phba->hbalock);
  3410. resetcount++;
  3411. /* Call pre CONFIG_PORT mailbox command initialization. A
  3412. * value of 0 means the call was successful. Any other
  3413. * nonzero value is a failure, but if ERESTART is returned,
  3414. * the driver may reset the HBA and try again.
  3415. */
  3416. rc = lpfc_config_port_prep(phba);
  3417. if (rc == -ERESTART) {
  3418. phba->link_state = LPFC_LINK_UNKNOWN;
  3419. continue;
  3420. } else if (rc)
  3421. break;
  3422. phba->link_state = LPFC_INIT_MBX_CMDS;
  3423. lpfc_config_port(phba, pmb);
  3424. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3425. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3426. LPFC_SLI3_HBQ_ENABLED |
  3427. LPFC_SLI3_CRP_ENABLED |
  3428. LPFC_SLI3_INB_ENABLED |
  3429. LPFC_SLI3_BG_ENABLED);
  3430. if (rc != MBX_SUCCESS) {
  3431. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3432. "0442 Adapter failed to init, mbxCmd x%x "
  3433. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3434. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3435. spin_lock_irq(&phba->hbalock);
  3436. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3437. spin_unlock_irq(&phba->hbalock);
  3438. rc = -ENXIO;
  3439. } else {
  3440. /* Allow asynchronous mailbox command to go through */
  3441. spin_lock_irq(&phba->hbalock);
  3442. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3443. spin_unlock_irq(&phba->hbalock);
  3444. done = 1;
  3445. }
  3446. }
  3447. if (!done) {
  3448. rc = -EINVAL;
  3449. goto do_prep_failed;
  3450. }
  3451. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3452. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3453. rc = -ENXIO;
  3454. goto do_prep_failed;
  3455. }
  3456. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3457. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3458. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3459. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3460. phba->max_vpi : phba->max_vports;
  3461. } else
  3462. phba->max_vpi = 0;
  3463. if (pmb->u.mb.un.varCfgPort.gdss)
  3464. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3465. if (pmb->u.mb.un.varCfgPort.gerbm)
  3466. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3467. if (pmb->u.mb.un.varCfgPort.gcrp)
  3468. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3469. if (pmb->u.mb.un.varCfgPort.ginb) {
  3470. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3471. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3472. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3473. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3474. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3475. phba->inb_last_counter =
  3476. phba->mbox->us.s3_inb_pgp.counter;
  3477. } else {
  3478. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3479. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3480. phba->inb_ha_copy = NULL;
  3481. phba->inb_counter = NULL;
  3482. }
  3483. if (phba->cfg_enable_bg) {
  3484. if (pmb->u.mb.un.varCfgPort.gbg)
  3485. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3486. else
  3487. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3488. "0443 Adapter did not grant "
  3489. "BlockGuard\n");
  3490. }
  3491. } else {
  3492. phba->hbq_get = NULL;
  3493. phba->port_gp = phba->mbox->us.s2.port;
  3494. phba->inb_ha_copy = NULL;
  3495. phba->inb_counter = NULL;
  3496. phba->max_vpi = 0;
  3497. }
  3498. do_prep_failed:
  3499. mempool_free(pmb, phba->mbox_mem_pool);
  3500. return rc;
  3501. }
  3502. /**
  3503. * lpfc_sli_hba_setup - SLI intialization function
  3504. * @phba: Pointer to HBA context object.
  3505. *
  3506. * This function is the main SLI intialization function. This function
  3507. * is called by the HBA intialization code, HBA reset code and HBA
  3508. * error attention handler code. Caller is not required to hold any
  3509. * locks. This function issues config_port mailbox command to configure
  3510. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3511. * calls the config_port_post function to issue init_link mailbox
  3512. * command and to start the discovery. The function will return zero
  3513. * if successful, else it will return negative error code.
  3514. **/
  3515. int
  3516. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3517. {
  3518. uint32_t rc;
  3519. int mode = 3;
  3520. switch (lpfc_sli_mode) {
  3521. case 2:
  3522. if (phba->cfg_enable_npiv) {
  3523. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3524. "1824 NPIV enabled: Override lpfc_sli_mode "
  3525. "parameter (%d) to auto (0).\n",
  3526. lpfc_sli_mode);
  3527. break;
  3528. }
  3529. mode = 2;
  3530. break;
  3531. case 0:
  3532. case 3:
  3533. break;
  3534. default:
  3535. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3536. "1819 Unrecognized lpfc_sli_mode "
  3537. "parameter: %d.\n", lpfc_sli_mode);
  3538. break;
  3539. }
  3540. rc = lpfc_sli_config_port(phba, mode);
  3541. if (rc && lpfc_sli_mode == 3)
  3542. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3543. "1820 Unable to select SLI-3. "
  3544. "Not supported by adapter.\n");
  3545. if (rc && mode != 2)
  3546. rc = lpfc_sli_config_port(phba, 2);
  3547. if (rc)
  3548. goto lpfc_sli_hba_setup_error;
  3549. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3550. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3551. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3552. if (!rc) {
  3553. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3554. "2709 This device supports "
  3555. "Advanced Error Reporting (AER)\n");
  3556. spin_lock_irq(&phba->hbalock);
  3557. phba->hba_flag |= HBA_AER_ENABLED;
  3558. spin_unlock_irq(&phba->hbalock);
  3559. } else {
  3560. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3561. "2708 This device does not support "
  3562. "Advanced Error Reporting (AER)\n");
  3563. phba->cfg_aer_support = 0;
  3564. }
  3565. }
  3566. if (phba->sli_rev == 3) {
  3567. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3568. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3569. } else {
  3570. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3571. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3572. phba->sli3_options = 0;
  3573. }
  3574. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3575. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3576. phba->sli_rev, phba->max_vpi);
  3577. rc = lpfc_sli_ring_map(phba);
  3578. if (rc)
  3579. goto lpfc_sli_hba_setup_error;
  3580. /* Init HBQs */
  3581. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3582. rc = lpfc_sli_hbq_setup(phba);
  3583. if (rc)
  3584. goto lpfc_sli_hba_setup_error;
  3585. }
  3586. spin_lock_irq(&phba->hbalock);
  3587. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3588. spin_unlock_irq(&phba->hbalock);
  3589. rc = lpfc_config_port_post(phba);
  3590. if (rc)
  3591. goto lpfc_sli_hba_setup_error;
  3592. return rc;
  3593. lpfc_sli_hba_setup_error:
  3594. phba->link_state = LPFC_HBA_ERROR;
  3595. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3596. "0445 Firmware initialization failed\n");
  3597. return rc;
  3598. }
  3599. /**
  3600. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3601. * @phba: Pointer to HBA context object.
  3602. * @mboxq: mailbox pointer.
  3603. * This function issue a dump mailbox command to read config region
  3604. * 23 and parse the records in the region and populate driver
  3605. * data structure.
  3606. **/
  3607. static int
  3608. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3609. LPFC_MBOXQ_t *mboxq)
  3610. {
  3611. struct lpfc_dmabuf *mp;
  3612. struct lpfc_mqe *mqe;
  3613. uint32_t data_length;
  3614. int rc;
  3615. /* Program the default value of vlan_id and fc_map */
  3616. phba->valid_vlan = 0;
  3617. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3618. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3619. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3620. mqe = &mboxq->u.mqe;
  3621. if (lpfc_dump_fcoe_param(phba, mboxq))
  3622. return -ENOMEM;
  3623. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3624. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3625. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3626. "(%d):2571 Mailbox cmd x%x Status x%x "
  3627. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3628. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3629. "CQ: x%x x%x x%x x%x\n",
  3630. mboxq->vport ? mboxq->vport->vpi : 0,
  3631. bf_get(lpfc_mqe_command, mqe),
  3632. bf_get(lpfc_mqe_status, mqe),
  3633. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3634. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3635. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3636. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3637. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3638. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3639. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3640. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3641. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3642. mboxq->mcqe.word0,
  3643. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3644. mboxq->mcqe.trailer);
  3645. if (rc) {
  3646. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3647. kfree(mp);
  3648. return -EIO;
  3649. }
  3650. data_length = mqe->un.mb_words[5];
  3651. if (data_length > DMP_RGN23_SIZE) {
  3652. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3653. kfree(mp);
  3654. return -EIO;
  3655. }
  3656. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3657. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3658. kfree(mp);
  3659. return 0;
  3660. }
  3661. /**
  3662. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3663. * @phba: pointer to lpfc hba data structure.
  3664. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3665. * @vpd: pointer to the memory to hold resulting port vpd data.
  3666. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3667. * On output, the number of data bytes in @vpd.
  3668. *
  3669. * This routine executes a READ_REV SLI4 mailbox command. In
  3670. * addition, this routine gets the port vpd data.
  3671. *
  3672. * Return codes
  3673. * 0 - successful
  3674. * ENOMEM - could not allocated memory.
  3675. **/
  3676. static int
  3677. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3678. uint8_t *vpd, uint32_t *vpd_size)
  3679. {
  3680. int rc = 0;
  3681. uint32_t dma_size;
  3682. struct lpfc_dmabuf *dmabuf;
  3683. struct lpfc_mqe *mqe;
  3684. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3685. if (!dmabuf)
  3686. return -ENOMEM;
  3687. /*
  3688. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3689. * mailbox command.
  3690. */
  3691. dma_size = *vpd_size;
  3692. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3693. dma_size,
  3694. &dmabuf->phys,
  3695. GFP_KERNEL);
  3696. if (!dmabuf->virt) {
  3697. kfree(dmabuf);
  3698. return -ENOMEM;
  3699. }
  3700. memset(dmabuf->virt, 0, dma_size);
  3701. /*
  3702. * The SLI4 implementation of READ_REV conflicts at word1,
  3703. * bits 31:16 and SLI4 adds vpd functionality not present
  3704. * in SLI3. This code corrects the conflicts.
  3705. */
  3706. lpfc_read_rev(phba, mboxq);
  3707. mqe = &mboxq->u.mqe;
  3708. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3709. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3710. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3711. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3712. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3713. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3714. if (rc) {
  3715. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3716. dmabuf->virt, dmabuf->phys);
  3717. return -EIO;
  3718. }
  3719. /*
  3720. * The available vpd length cannot be bigger than the
  3721. * DMA buffer passed to the port. Catch the less than
  3722. * case and update the caller's size.
  3723. */
  3724. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3725. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3726. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3727. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3728. dmabuf->virt, dmabuf->phys);
  3729. kfree(dmabuf);
  3730. return 0;
  3731. }
  3732. /**
  3733. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3734. * @phba: pointer to lpfc hba data structure.
  3735. *
  3736. * This routine is called to explicitly arm the SLI4 device's completion and
  3737. * event queues
  3738. **/
  3739. static void
  3740. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3741. {
  3742. uint8_t fcp_eqidx;
  3743. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3744. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3745. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3746. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3747. LPFC_QUEUE_REARM);
  3748. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3749. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3750. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3751. LPFC_QUEUE_REARM);
  3752. }
  3753. /**
  3754. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3755. * @phba: Pointer to HBA context object.
  3756. *
  3757. * This function is the main SLI4 device intialization PCI function. This
  3758. * function is called by the HBA intialization code, HBA reset code and
  3759. * HBA error attention handler code. Caller is not required to hold any
  3760. * locks.
  3761. **/
  3762. int
  3763. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3764. {
  3765. int rc;
  3766. LPFC_MBOXQ_t *mboxq;
  3767. struct lpfc_mqe *mqe;
  3768. uint8_t *vpd;
  3769. uint32_t vpd_size;
  3770. uint32_t ftr_rsp = 0;
  3771. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3772. struct lpfc_vport *vport = phba->pport;
  3773. struct lpfc_dmabuf *mp;
  3774. /* Perform a PCI function reset to start from clean */
  3775. rc = lpfc_pci_function_reset(phba);
  3776. if (unlikely(rc))
  3777. return -ENODEV;
  3778. /* Check the HBA Host Status Register for readyness */
  3779. rc = lpfc_sli4_post_status_check(phba);
  3780. if (unlikely(rc))
  3781. return -ENODEV;
  3782. else {
  3783. spin_lock_irq(&phba->hbalock);
  3784. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3785. spin_unlock_irq(&phba->hbalock);
  3786. }
  3787. /*
  3788. * Allocate a single mailbox container for initializing the
  3789. * port.
  3790. */
  3791. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3792. if (!mboxq)
  3793. return -ENOMEM;
  3794. /*
  3795. * Continue initialization with default values even if driver failed
  3796. * to read FCoE param config regions
  3797. */
  3798. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3799. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3800. "2570 Failed to read FCoE parameters\n");
  3801. /* Issue READ_REV to collect vpd and FW information. */
  3802. vpd_size = PAGE_SIZE;
  3803. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3804. if (!vpd) {
  3805. rc = -ENOMEM;
  3806. goto out_free_mbox;
  3807. }
  3808. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3809. if (unlikely(rc))
  3810. goto out_free_vpd;
  3811. mqe = &mboxq->u.mqe;
  3812. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3813. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3814. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3815. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3816. LPFC_DCBX_CEE_MODE)
  3817. phba->hba_flag |= HBA_FIP_SUPPORT;
  3818. else
  3819. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3820. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3821. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3822. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3823. "0376 READ_REV Error. SLI Level %d "
  3824. "FCoE enabled %d\n",
  3825. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3826. rc = -EIO;
  3827. goto out_free_vpd;
  3828. }
  3829. /*
  3830. * Evaluate the read rev and vpd data. Populate the driver
  3831. * state with the results. If this routine fails, the failure
  3832. * is not fatal as the driver will use generic values.
  3833. */
  3834. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3835. if (unlikely(!rc)) {
  3836. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3837. "0377 Error %d parsing vpd. "
  3838. "Using defaults.\n", rc);
  3839. rc = 0;
  3840. }
  3841. /* Save information as VPD data */
  3842. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3843. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3844. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3845. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3846. &mqe->un.read_rev);
  3847. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3848. &mqe->un.read_rev);
  3849. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3850. &mqe->un.read_rev);
  3851. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3852. &mqe->un.read_rev);
  3853. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3854. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3855. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3856. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3857. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3858. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3859. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3860. "(%d):0380 READ_REV Status x%x "
  3861. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3862. mboxq->vport ? mboxq->vport->vpi : 0,
  3863. bf_get(lpfc_mqe_status, mqe),
  3864. phba->vpd.rev.opFwName,
  3865. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3866. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3867. /*
  3868. * Discover the port's supported feature set and match it against the
  3869. * hosts requests.
  3870. */
  3871. lpfc_request_features(phba, mboxq);
  3872. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3873. if (unlikely(rc)) {
  3874. rc = -EIO;
  3875. goto out_free_vpd;
  3876. }
  3877. /*
  3878. * The port must support FCP initiator mode as this is the
  3879. * only mode running in the host.
  3880. */
  3881. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3882. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3883. "0378 No support for fcpi mode.\n");
  3884. ftr_rsp++;
  3885. }
  3886. /*
  3887. * If the port cannot support the host's requested features
  3888. * then turn off the global config parameters to disable the
  3889. * feature in the driver. This is not a fatal error.
  3890. */
  3891. if ((phba->cfg_enable_bg) &&
  3892. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3893. ftr_rsp++;
  3894. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3895. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3896. ftr_rsp++;
  3897. if (ftr_rsp) {
  3898. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3899. "0379 Feature Mismatch Data: x%08x %08x "
  3900. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3901. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3902. phba->cfg_enable_npiv, phba->max_vpi);
  3903. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3904. phba->cfg_enable_bg = 0;
  3905. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3906. phba->cfg_enable_npiv = 0;
  3907. }
  3908. /* These SLI3 features are assumed in SLI4 */
  3909. spin_lock_irq(&phba->hbalock);
  3910. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3911. spin_unlock_irq(&phba->hbalock);
  3912. /* Read the port's service parameters. */
  3913. lpfc_read_sparam(phba, mboxq, vport->vpi);
  3914. mboxq->vport = vport;
  3915. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3916. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3917. if (rc == MBX_SUCCESS) {
  3918. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  3919. rc = 0;
  3920. }
  3921. /*
  3922. * This memory was allocated by the lpfc_read_sparam routine. Release
  3923. * it to the mbuf pool.
  3924. */
  3925. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3926. kfree(mp);
  3927. mboxq->context1 = NULL;
  3928. if (unlikely(rc)) {
  3929. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3930. "0382 READ_SPARAM command failed "
  3931. "status %d, mbxStatus x%x\n",
  3932. rc, bf_get(lpfc_mqe_status, mqe));
  3933. phba->link_state = LPFC_HBA_ERROR;
  3934. rc = -EIO;
  3935. goto out_free_vpd;
  3936. }
  3937. if (phba->cfg_soft_wwnn)
  3938. u64_to_wwn(phba->cfg_soft_wwnn,
  3939. vport->fc_sparam.nodeName.u.wwn);
  3940. if (phba->cfg_soft_wwpn)
  3941. u64_to_wwn(phba->cfg_soft_wwpn,
  3942. vport->fc_sparam.portName.u.wwn);
  3943. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  3944. sizeof(struct lpfc_name));
  3945. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  3946. sizeof(struct lpfc_name));
  3947. /* Update the fc_host data structures with new wwn. */
  3948. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  3949. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  3950. /* Register SGL pool to the device using non-embedded mailbox command */
  3951. rc = lpfc_sli4_post_sgl_list(phba);
  3952. if (unlikely(rc)) {
  3953. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3954. "0582 Error %d during sgl post operation\n",
  3955. rc);
  3956. rc = -ENODEV;
  3957. goto out_free_vpd;
  3958. }
  3959. /* Register SCSI SGL pool to the device */
  3960. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  3961. if (unlikely(rc)) {
  3962. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3963. "0383 Error %d during scsi sgl post "
  3964. "operation\n", rc);
  3965. /* Some Scsi buffers were moved to the abort scsi list */
  3966. /* A pci function reset will repost them */
  3967. rc = -ENODEV;
  3968. goto out_free_vpd;
  3969. }
  3970. /* Post the rpi header region to the device. */
  3971. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  3972. if (unlikely(rc)) {
  3973. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3974. "0393 Error %d during rpi post operation\n",
  3975. rc);
  3976. rc = -ENODEV;
  3977. goto out_free_vpd;
  3978. }
  3979. /* Set up all the queues to the device */
  3980. rc = lpfc_sli4_queue_setup(phba);
  3981. if (unlikely(rc)) {
  3982. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3983. "0381 Error %d during queue setup.\n ", rc);
  3984. goto out_stop_timers;
  3985. }
  3986. /* Arm the CQs and then EQs on device */
  3987. lpfc_sli4_arm_cqeq_intr(phba);
  3988. /* Indicate device interrupt mode */
  3989. phba->sli4_hba.intr_enable = 1;
  3990. /* Allow asynchronous mailbox command to go through */
  3991. spin_lock_irq(&phba->hbalock);
  3992. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3993. spin_unlock_irq(&phba->hbalock);
  3994. /* Post receive buffers to the device */
  3995. lpfc_sli4_rb_setup(phba);
  3996. /* Start the ELS watchdog timer */
  3997. mod_timer(&vport->els_tmofunc,
  3998. jiffies + HZ * (phba->fc_ratov * 2));
  3999. /* Start heart beat timer */
  4000. mod_timer(&phba->hb_tmofunc,
  4001. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4002. phba->hb_outstanding = 0;
  4003. phba->last_completion_time = jiffies;
  4004. /* Start error attention (ERATT) polling timer */
  4005. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4006. /*
  4007. * The port is ready, set the host's link state to LINK_DOWN
  4008. * in preparation for link interrupts.
  4009. */
  4010. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4011. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4012. lpfc_set_loopback_flag(phba);
  4013. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4014. spin_lock_irq(&phba->hbalock);
  4015. phba->link_state = LPFC_LINK_DOWN;
  4016. spin_unlock_irq(&phba->hbalock);
  4017. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4018. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4019. kfree(vpd);
  4020. return 0;
  4021. } else
  4022. rc = -EIO;
  4023. /* Unset all the queues set up in this routine when error out */
  4024. if (rc)
  4025. lpfc_sli4_queue_unset(phba);
  4026. out_stop_timers:
  4027. if (rc)
  4028. lpfc_stop_hba_timers(phba);
  4029. out_free_vpd:
  4030. kfree(vpd);
  4031. out_free_mbox:
  4032. mempool_free(mboxq, phba->mbox_mem_pool);
  4033. return rc;
  4034. }
  4035. /**
  4036. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4037. * @ptr: context object - pointer to hba structure.
  4038. *
  4039. * This is the callback function for mailbox timer. The mailbox
  4040. * timer is armed when a new mailbox command is issued and the timer
  4041. * is deleted when the mailbox complete. The function is called by
  4042. * the kernel timer code when a mailbox does not complete within
  4043. * expected time. This function wakes up the worker thread to
  4044. * process the mailbox timeout and returns. All the processing is
  4045. * done by the worker thread function lpfc_mbox_timeout_handler.
  4046. **/
  4047. void
  4048. lpfc_mbox_timeout(unsigned long ptr)
  4049. {
  4050. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4051. unsigned long iflag;
  4052. uint32_t tmo_posted;
  4053. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4054. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4055. if (!tmo_posted)
  4056. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4057. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4058. if (!tmo_posted)
  4059. lpfc_worker_wake_up(phba);
  4060. return;
  4061. }
  4062. /**
  4063. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4064. * @phba: Pointer to HBA context object.
  4065. *
  4066. * This function is called from worker thread when a mailbox command times out.
  4067. * The caller is not required to hold any locks. This function will reset the
  4068. * HBA and recover all the pending commands.
  4069. **/
  4070. void
  4071. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4072. {
  4073. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4074. MAILBOX_t *mb = &pmbox->u.mb;
  4075. struct lpfc_sli *psli = &phba->sli;
  4076. struct lpfc_sli_ring *pring;
  4077. /* Check the pmbox pointer first. There is a race condition
  4078. * between the mbox timeout handler getting executed in the
  4079. * worklist and the mailbox actually completing. When this
  4080. * race condition occurs, the mbox_active will be NULL.
  4081. */
  4082. spin_lock_irq(&phba->hbalock);
  4083. if (pmbox == NULL) {
  4084. lpfc_printf_log(phba, KERN_WARNING,
  4085. LOG_MBOX | LOG_SLI,
  4086. "0353 Active Mailbox cleared - mailbox timeout "
  4087. "exiting\n");
  4088. spin_unlock_irq(&phba->hbalock);
  4089. return;
  4090. }
  4091. /* Mbox cmd <mbxCommand> timeout */
  4092. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4093. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4094. mb->mbxCommand,
  4095. phba->pport->port_state,
  4096. phba->sli.sli_flag,
  4097. phba->sli.mbox_active);
  4098. spin_unlock_irq(&phba->hbalock);
  4099. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4100. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4101. * it to fail all oustanding SCSI IO.
  4102. */
  4103. spin_lock_irq(&phba->pport->work_port_lock);
  4104. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4105. spin_unlock_irq(&phba->pport->work_port_lock);
  4106. spin_lock_irq(&phba->hbalock);
  4107. phba->link_state = LPFC_LINK_UNKNOWN;
  4108. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4109. spin_unlock_irq(&phba->hbalock);
  4110. pring = &psli->ring[psli->fcp_ring];
  4111. lpfc_sli_abort_iocb_ring(phba, pring);
  4112. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4113. "0345 Resetting board due to mailbox timeout\n");
  4114. /* Reset the HBA device */
  4115. lpfc_reset_hba(phba);
  4116. }
  4117. /**
  4118. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4119. * @phba: Pointer to HBA context object.
  4120. * @pmbox: Pointer to mailbox object.
  4121. * @flag: Flag indicating how the mailbox need to be processed.
  4122. *
  4123. * This function is called by discovery code and HBA management code
  4124. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4125. * function gets the hbalock to protect the data structures.
  4126. * The mailbox command can be submitted in polling mode, in which case
  4127. * this function will wait in a polling loop for the completion of the
  4128. * mailbox.
  4129. * If the mailbox is submitted in no_wait mode (not polling) the
  4130. * function will submit the command and returns immediately without waiting
  4131. * for the mailbox completion. The no_wait is supported only when HBA
  4132. * is in SLI2/SLI3 mode - interrupts are enabled.
  4133. * The SLI interface allows only one mailbox pending at a time. If the
  4134. * mailbox is issued in polling mode and there is already a mailbox
  4135. * pending, then the function will return an error. If the mailbox is issued
  4136. * in NO_WAIT mode and there is a mailbox pending already, the function
  4137. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4138. * The sli layer owns the mailbox object until the completion of mailbox
  4139. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4140. * return codes the caller owns the mailbox command after the return of
  4141. * the function.
  4142. **/
  4143. static int
  4144. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4145. uint32_t flag)
  4146. {
  4147. MAILBOX_t *mb;
  4148. struct lpfc_sli *psli = &phba->sli;
  4149. uint32_t status, evtctr;
  4150. uint32_t ha_copy;
  4151. int i;
  4152. unsigned long timeout;
  4153. unsigned long drvr_flag = 0;
  4154. uint32_t word0, ldata;
  4155. void __iomem *to_slim;
  4156. int processing_queue = 0;
  4157. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4158. if (!pmbox) {
  4159. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4160. /* processing mbox queue from intr_handler */
  4161. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4162. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4163. return MBX_SUCCESS;
  4164. }
  4165. processing_queue = 1;
  4166. pmbox = lpfc_mbox_get(phba);
  4167. if (!pmbox) {
  4168. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4169. return MBX_SUCCESS;
  4170. }
  4171. }
  4172. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4173. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4174. if(!pmbox->vport) {
  4175. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4176. lpfc_printf_log(phba, KERN_ERR,
  4177. LOG_MBOX | LOG_VPORT,
  4178. "1806 Mbox x%x failed. No vport\n",
  4179. pmbox->u.mb.mbxCommand);
  4180. dump_stack();
  4181. goto out_not_finished;
  4182. }
  4183. }
  4184. /* If the PCI channel is in offline state, do not post mbox. */
  4185. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4186. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4187. goto out_not_finished;
  4188. }
  4189. /* If HBA has a deferred error attention, fail the iocb. */
  4190. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4191. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4192. goto out_not_finished;
  4193. }
  4194. psli = &phba->sli;
  4195. mb = &pmbox->u.mb;
  4196. status = MBX_SUCCESS;
  4197. if (phba->link_state == LPFC_HBA_ERROR) {
  4198. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4199. /* Mbox command <mbxCommand> cannot issue */
  4200. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4201. "(%d):0311 Mailbox command x%x cannot "
  4202. "issue Data: x%x x%x\n",
  4203. pmbox->vport ? pmbox->vport->vpi : 0,
  4204. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4205. goto out_not_finished;
  4206. }
  4207. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4208. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4209. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4210. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4211. "(%d):2528 Mailbox command x%x cannot "
  4212. "issue Data: x%x x%x\n",
  4213. pmbox->vport ? pmbox->vport->vpi : 0,
  4214. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4215. goto out_not_finished;
  4216. }
  4217. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4218. /* Polling for a mbox command when another one is already active
  4219. * is not allowed in SLI. Also, the driver must have established
  4220. * SLI2 mode to queue and process multiple mbox commands.
  4221. */
  4222. if (flag & MBX_POLL) {
  4223. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4224. /* Mbox command <mbxCommand> cannot issue */
  4225. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4226. "(%d):2529 Mailbox command x%x "
  4227. "cannot issue Data: x%x x%x\n",
  4228. pmbox->vport ? pmbox->vport->vpi : 0,
  4229. pmbox->u.mb.mbxCommand,
  4230. psli->sli_flag, flag);
  4231. goto out_not_finished;
  4232. }
  4233. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4234. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4235. /* Mbox command <mbxCommand> cannot issue */
  4236. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4237. "(%d):2530 Mailbox command x%x "
  4238. "cannot issue Data: x%x x%x\n",
  4239. pmbox->vport ? pmbox->vport->vpi : 0,
  4240. pmbox->u.mb.mbxCommand,
  4241. psli->sli_flag, flag);
  4242. goto out_not_finished;
  4243. }
  4244. /* Another mailbox command is still being processed, queue this
  4245. * command to be processed later.
  4246. */
  4247. lpfc_mbox_put(phba, pmbox);
  4248. /* Mbox cmd issue - BUSY */
  4249. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4250. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4251. "x%x x%x x%x x%x\n",
  4252. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4253. mb->mbxCommand, phba->pport->port_state,
  4254. psli->sli_flag, flag);
  4255. psli->slistat.mbox_busy++;
  4256. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4257. if (pmbox->vport) {
  4258. lpfc_debugfs_disc_trc(pmbox->vport,
  4259. LPFC_DISC_TRC_MBOX_VPORT,
  4260. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4261. (uint32_t)mb->mbxCommand,
  4262. mb->un.varWords[0], mb->un.varWords[1]);
  4263. }
  4264. else {
  4265. lpfc_debugfs_disc_trc(phba->pport,
  4266. LPFC_DISC_TRC_MBOX,
  4267. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4268. (uint32_t)mb->mbxCommand,
  4269. mb->un.varWords[0], mb->un.varWords[1]);
  4270. }
  4271. return MBX_BUSY;
  4272. }
  4273. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4274. /* If we are not polling, we MUST be in SLI2 mode */
  4275. if (flag != MBX_POLL) {
  4276. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4277. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4278. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4279. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4280. /* Mbox command <mbxCommand> cannot issue */
  4281. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4282. "(%d):2531 Mailbox command x%x "
  4283. "cannot issue Data: x%x x%x\n",
  4284. pmbox->vport ? pmbox->vport->vpi : 0,
  4285. pmbox->u.mb.mbxCommand,
  4286. psli->sli_flag, flag);
  4287. goto out_not_finished;
  4288. }
  4289. /* timeout active mbox command */
  4290. mod_timer(&psli->mbox_tmo, (jiffies +
  4291. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4292. }
  4293. /* Mailbox cmd <cmd> issue */
  4294. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4295. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4296. "x%x\n",
  4297. pmbox->vport ? pmbox->vport->vpi : 0,
  4298. mb->mbxCommand, phba->pport->port_state,
  4299. psli->sli_flag, flag);
  4300. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4301. if (pmbox->vport) {
  4302. lpfc_debugfs_disc_trc(pmbox->vport,
  4303. LPFC_DISC_TRC_MBOX_VPORT,
  4304. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4305. (uint32_t)mb->mbxCommand,
  4306. mb->un.varWords[0], mb->un.varWords[1]);
  4307. }
  4308. else {
  4309. lpfc_debugfs_disc_trc(phba->pport,
  4310. LPFC_DISC_TRC_MBOX,
  4311. "MBOX Send: cmd:x%x mb:x%x x%x",
  4312. (uint32_t)mb->mbxCommand,
  4313. mb->un.varWords[0], mb->un.varWords[1]);
  4314. }
  4315. }
  4316. psli->slistat.mbox_cmd++;
  4317. evtctr = psli->slistat.mbox_event;
  4318. /* next set own bit for the adapter and copy over command word */
  4319. mb->mbxOwner = OWN_CHIP;
  4320. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4321. /* First copy command data to host SLIM area */
  4322. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4323. } else {
  4324. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4325. /* copy command data into host mbox for cmpl */
  4326. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4327. }
  4328. /* First copy mbox command data to HBA SLIM, skip past first
  4329. word */
  4330. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4331. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4332. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4333. /* Next copy over first word, with mbxOwner set */
  4334. ldata = *((uint32_t *)mb);
  4335. to_slim = phba->MBslimaddr;
  4336. writel(ldata, to_slim);
  4337. readl(to_slim); /* flush */
  4338. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4339. /* switch over to host mailbox */
  4340. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4341. }
  4342. }
  4343. wmb();
  4344. switch (flag) {
  4345. case MBX_NOWAIT:
  4346. /* Set up reference to mailbox command */
  4347. psli->mbox_active = pmbox;
  4348. /* Interrupt board to do it */
  4349. writel(CA_MBATT, phba->CAregaddr);
  4350. readl(phba->CAregaddr); /* flush */
  4351. /* Don't wait for it to finish, just return */
  4352. break;
  4353. case MBX_POLL:
  4354. /* Set up null reference to mailbox command */
  4355. psli->mbox_active = NULL;
  4356. /* Interrupt board to do it */
  4357. writel(CA_MBATT, phba->CAregaddr);
  4358. readl(phba->CAregaddr); /* flush */
  4359. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4360. /* First read mbox status word */
  4361. word0 = *((uint32_t *)phba->mbox);
  4362. word0 = le32_to_cpu(word0);
  4363. } else {
  4364. /* First read mbox status word */
  4365. word0 = readl(phba->MBslimaddr);
  4366. }
  4367. /* Read the HBA Host Attention Register */
  4368. ha_copy = readl(phba->HAregaddr);
  4369. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4370. mb->mbxCommand) *
  4371. 1000) + jiffies;
  4372. i = 0;
  4373. /* Wait for command to complete */
  4374. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4375. (!(ha_copy & HA_MBATT) &&
  4376. (phba->link_state > LPFC_WARM_START))) {
  4377. if (time_after(jiffies, timeout)) {
  4378. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4379. spin_unlock_irqrestore(&phba->hbalock,
  4380. drvr_flag);
  4381. goto out_not_finished;
  4382. }
  4383. /* Check if we took a mbox interrupt while we were
  4384. polling */
  4385. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4386. && (evtctr != psli->slistat.mbox_event))
  4387. break;
  4388. if (i++ > 10) {
  4389. spin_unlock_irqrestore(&phba->hbalock,
  4390. drvr_flag);
  4391. msleep(1);
  4392. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4393. }
  4394. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4395. /* First copy command data */
  4396. word0 = *((uint32_t *)phba->mbox);
  4397. word0 = le32_to_cpu(word0);
  4398. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4399. MAILBOX_t *slimmb;
  4400. uint32_t slimword0;
  4401. /* Check real SLIM for any errors */
  4402. slimword0 = readl(phba->MBslimaddr);
  4403. slimmb = (MAILBOX_t *) & slimword0;
  4404. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4405. && slimmb->mbxStatus) {
  4406. psli->sli_flag &=
  4407. ~LPFC_SLI_ACTIVE;
  4408. word0 = slimword0;
  4409. }
  4410. }
  4411. } else {
  4412. /* First copy command data */
  4413. word0 = readl(phba->MBslimaddr);
  4414. }
  4415. /* Read the HBA Host Attention Register */
  4416. ha_copy = readl(phba->HAregaddr);
  4417. }
  4418. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4419. /* copy results back to user */
  4420. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4421. } else {
  4422. /* First copy command data */
  4423. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4424. MAILBOX_CMD_SIZE);
  4425. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4426. pmbox->context2) {
  4427. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4428. phba->MBslimaddr + DMP_RSP_OFFSET,
  4429. mb->un.varDmp.word_cnt);
  4430. }
  4431. }
  4432. writel(HA_MBATT, phba->HAregaddr);
  4433. readl(phba->HAregaddr); /* flush */
  4434. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4435. status = mb->mbxStatus;
  4436. }
  4437. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4438. return status;
  4439. out_not_finished:
  4440. if (processing_queue) {
  4441. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4442. lpfc_mbox_cmpl_put(phba, pmbox);
  4443. }
  4444. return MBX_NOT_FINISHED;
  4445. }
  4446. /**
  4447. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4448. * @phba: Pointer to HBA context object.
  4449. *
  4450. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4451. * the driver internal pending mailbox queue. It will then try to wait out the
  4452. * possible outstanding mailbox command before return.
  4453. *
  4454. * Returns:
  4455. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4456. * the outstanding mailbox command timed out.
  4457. **/
  4458. static int
  4459. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4460. {
  4461. struct lpfc_sli *psli = &phba->sli;
  4462. uint8_t actcmd = MBX_HEARTBEAT;
  4463. int rc = 0;
  4464. unsigned long timeout;
  4465. /* Mark the asynchronous mailbox command posting as blocked */
  4466. spin_lock_irq(&phba->hbalock);
  4467. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4468. if (phba->sli.mbox_active)
  4469. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4470. spin_unlock_irq(&phba->hbalock);
  4471. /* Determine how long we might wait for the active mailbox
  4472. * command to be gracefully completed by firmware.
  4473. */
  4474. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4475. jiffies;
  4476. /* Wait for the outstnading mailbox command to complete */
  4477. while (phba->sli.mbox_active) {
  4478. /* Check active mailbox complete status every 2ms */
  4479. msleep(2);
  4480. if (time_after(jiffies, timeout)) {
  4481. /* Timeout, marked the outstanding cmd not complete */
  4482. rc = 1;
  4483. break;
  4484. }
  4485. }
  4486. /* Can not cleanly block async mailbox command, fails it */
  4487. if (rc) {
  4488. spin_lock_irq(&phba->hbalock);
  4489. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4490. spin_unlock_irq(&phba->hbalock);
  4491. }
  4492. return rc;
  4493. }
  4494. /**
  4495. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4496. * @phba: Pointer to HBA context object.
  4497. *
  4498. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4499. * commands from the driver internal pending mailbox queue. It makes sure
  4500. * that there is no outstanding mailbox command before resuming posting
  4501. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4502. * mailbox command, it will try to wait it out before resuming asynchronous
  4503. * mailbox command posting.
  4504. **/
  4505. static void
  4506. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4507. {
  4508. struct lpfc_sli *psli = &phba->sli;
  4509. spin_lock_irq(&phba->hbalock);
  4510. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4511. /* Asynchronous mailbox posting is not blocked, do nothing */
  4512. spin_unlock_irq(&phba->hbalock);
  4513. return;
  4514. }
  4515. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4516. * successful or timeout, after timing-out the outstanding mailbox
  4517. * command shall always be removed, so just unblock posting async
  4518. * mailbox command and resume
  4519. */
  4520. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4521. spin_unlock_irq(&phba->hbalock);
  4522. /* wake up worker thread to post asynchronlous mailbox command */
  4523. lpfc_worker_wake_up(phba);
  4524. }
  4525. /**
  4526. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4527. * @phba: Pointer to HBA context object.
  4528. * @mboxq: Pointer to mailbox object.
  4529. *
  4530. * The function posts a mailbox to the port. The mailbox is expected
  4531. * to be comletely filled in and ready for the port to operate on it.
  4532. * This routine executes a synchronous completion operation on the
  4533. * mailbox by polling for its completion.
  4534. *
  4535. * The caller must not be holding any locks when calling this routine.
  4536. *
  4537. * Returns:
  4538. * MBX_SUCCESS - mailbox posted successfully
  4539. * Any of the MBX error values.
  4540. **/
  4541. static int
  4542. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4543. {
  4544. int rc = MBX_SUCCESS;
  4545. unsigned long iflag;
  4546. uint32_t db_ready;
  4547. uint32_t mcqe_status;
  4548. uint32_t mbx_cmnd;
  4549. unsigned long timeout;
  4550. struct lpfc_sli *psli = &phba->sli;
  4551. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4552. struct lpfc_bmbx_create *mbox_rgn;
  4553. struct dma_address *dma_address;
  4554. struct lpfc_register bmbx_reg;
  4555. /*
  4556. * Only one mailbox can be active to the bootstrap mailbox region
  4557. * at a time and there is no queueing provided.
  4558. */
  4559. spin_lock_irqsave(&phba->hbalock, iflag);
  4560. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4561. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4562. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4563. "(%d):2532 Mailbox command x%x (x%x) "
  4564. "cannot issue Data: x%x x%x\n",
  4565. mboxq->vport ? mboxq->vport->vpi : 0,
  4566. mboxq->u.mb.mbxCommand,
  4567. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4568. psli->sli_flag, MBX_POLL);
  4569. return MBXERR_ERROR;
  4570. }
  4571. /* The server grabs the token and owns it until release */
  4572. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4573. phba->sli.mbox_active = mboxq;
  4574. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4575. /*
  4576. * Initialize the bootstrap memory region to avoid stale data areas
  4577. * in the mailbox post. Then copy the caller's mailbox contents to
  4578. * the bmbx mailbox region.
  4579. */
  4580. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4581. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4582. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4583. sizeof(struct lpfc_mqe));
  4584. /* Post the high mailbox dma address to the port and wait for ready. */
  4585. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4586. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4587. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4588. * 1000) + jiffies;
  4589. do {
  4590. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4591. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4592. if (!db_ready)
  4593. msleep(2);
  4594. if (time_after(jiffies, timeout)) {
  4595. rc = MBXERR_ERROR;
  4596. goto exit;
  4597. }
  4598. } while (!db_ready);
  4599. /* Post the low mailbox dma address to the port. */
  4600. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4601. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4602. * 1000) + jiffies;
  4603. do {
  4604. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4605. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4606. if (!db_ready)
  4607. msleep(2);
  4608. if (time_after(jiffies, timeout)) {
  4609. rc = MBXERR_ERROR;
  4610. goto exit;
  4611. }
  4612. } while (!db_ready);
  4613. /*
  4614. * Read the CQ to ensure the mailbox has completed.
  4615. * If so, update the mailbox status so that the upper layers
  4616. * can complete the request normally.
  4617. */
  4618. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4619. sizeof(struct lpfc_mqe));
  4620. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4621. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4622. sizeof(struct lpfc_mcqe));
  4623. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4624. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4625. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4626. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4627. rc = MBXERR_ERROR;
  4628. }
  4629. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4630. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4631. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4632. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4633. mboxq->vport ? mboxq->vport->vpi : 0,
  4634. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4635. bf_get(lpfc_mqe_status, mb),
  4636. mb->un.mb_words[0], mb->un.mb_words[1],
  4637. mb->un.mb_words[2], mb->un.mb_words[3],
  4638. mb->un.mb_words[4], mb->un.mb_words[5],
  4639. mb->un.mb_words[6], mb->un.mb_words[7],
  4640. mb->un.mb_words[8], mb->un.mb_words[9],
  4641. mb->un.mb_words[10], mb->un.mb_words[11],
  4642. mb->un.mb_words[12], mboxq->mcqe.word0,
  4643. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4644. mboxq->mcqe.trailer);
  4645. exit:
  4646. /* We are holding the token, no needed for lock when release */
  4647. spin_lock_irqsave(&phba->hbalock, iflag);
  4648. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4649. phba->sli.mbox_active = NULL;
  4650. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4651. return rc;
  4652. }
  4653. /**
  4654. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4655. * @phba: Pointer to HBA context object.
  4656. * @pmbox: Pointer to mailbox object.
  4657. * @flag: Flag indicating how the mailbox need to be processed.
  4658. *
  4659. * This function is called by discovery code and HBA management code to submit
  4660. * a mailbox command to firmware with SLI-4 interface spec.
  4661. *
  4662. * Return codes the caller owns the mailbox command after the return of the
  4663. * function.
  4664. **/
  4665. static int
  4666. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4667. uint32_t flag)
  4668. {
  4669. struct lpfc_sli *psli = &phba->sli;
  4670. unsigned long iflags;
  4671. int rc;
  4672. rc = lpfc_mbox_dev_check(phba);
  4673. if (unlikely(rc)) {
  4674. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4675. "(%d):2544 Mailbox command x%x (x%x) "
  4676. "cannot issue Data: x%x x%x\n",
  4677. mboxq->vport ? mboxq->vport->vpi : 0,
  4678. mboxq->u.mb.mbxCommand,
  4679. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4680. psli->sli_flag, flag);
  4681. goto out_not_finished;
  4682. }
  4683. /* Detect polling mode and jump to a handler */
  4684. if (!phba->sli4_hba.intr_enable) {
  4685. if (flag == MBX_POLL)
  4686. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4687. else
  4688. rc = -EIO;
  4689. if (rc != MBX_SUCCESS)
  4690. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4691. "(%d):2541 Mailbox command x%x "
  4692. "(x%x) cannot issue Data: x%x x%x\n",
  4693. mboxq->vport ? mboxq->vport->vpi : 0,
  4694. mboxq->u.mb.mbxCommand,
  4695. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4696. psli->sli_flag, flag);
  4697. return rc;
  4698. } else if (flag == MBX_POLL) {
  4699. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4700. "(%d):2542 Try to issue mailbox command "
  4701. "x%x (x%x) synchronously ahead of async"
  4702. "mailbox command queue: x%x x%x\n",
  4703. mboxq->vport ? mboxq->vport->vpi : 0,
  4704. mboxq->u.mb.mbxCommand,
  4705. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4706. psli->sli_flag, flag);
  4707. /* Try to block the asynchronous mailbox posting */
  4708. rc = lpfc_sli4_async_mbox_block(phba);
  4709. if (!rc) {
  4710. /* Successfully blocked, now issue sync mbox cmd */
  4711. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4712. if (rc != MBX_SUCCESS)
  4713. lpfc_printf_log(phba, KERN_ERR,
  4714. LOG_MBOX | LOG_SLI,
  4715. "(%d):2597 Mailbox command "
  4716. "x%x (x%x) cannot issue "
  4717. "Data: x%x x%x\n",
  4718. mboxq->vport ?
  4719. mboxq->vport->vpi : 0,
  4720. mboxq->u.mb.mbxCommand,
  4721. lpfc_sli4_mbox_opcode_get(phba,
  4722. mboxq),
  4723. psli->sli_flag, flag);
  4724. /* Unblock the async mailbox posting afterward */
  4725. lpfc_sli4_async_mbox_unblock(phba);
  4726. }
  4727. return rc;
  4728. }
  4729. /* Now, interrupt mode asynchrous mailbox command */
  4730. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4731. if (rc) {
  4732. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4733. "(%d):2543 Mailbox command x%x (x%x) "
  4734. "cannot issue Data: x%x x%x\n",
  4735. mboxq->vport ? mboxq->vport->vpi : 0,
  4736. mboxq->u.mb.mbxCommand,
  4737. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4738. psli->sli_flag, flag);
  4739. goto out_not_finished;
  4740. }
  4741. /* Put the mailbox command to the driver internal FIFO */
  4742. psli->slistat.mbox_busy++;
  4743. spin_lock_irqsave(&phba->hbalock, iflags);
  4744. lpfc_mbox_put(phba, mboxq);
  4745. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4746. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4747. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4748. "x%x (x%x) x%x x%x x%x\n",
  4749. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4750. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4751. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4752. phba->pport->port_state,
  4753. psli->sli_flag, MBX_NOWAIT);
  4754. /* Wake up worker thread to transport mailbox command from head */
  4755. lpfc_worker_wake_up(phba);
  4756. return MBX_BUSY;
  4757. out_not_finished:
  4758. return MBX_NOT_FINISHED;
  4759. }
  4760. /**
  4761. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4762. * @phba: Pointer to HBA context object.
  4763. *
  4764. * This function is called by worker thread to send a mailbox command to
  4765. * SLI4 HBA firmware.
  4766. *
  4767. **/
  4768. int
  4769. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4770. {
  4771. struct lpfc_sli *psli = &phba->sli;
  4772. LPFC_MBOXQ_t *mboxq;
  4773. int rc = MBX_SUCCESS;
  4774. unsigned long iflags;
  4775. struct lpfc_mqe *mqe;
  4776. uint32_t mbx_cmnd;
  4777. /* Check interrupt mode before post async mailbox command */
  4778. if (unlikely(!phba->sli4_hba.intr_enable))
  4779. return MBX_NOT_FINISHED;
  4780. /* Check for mailbox command service token */
  4781. spin_lock_irqsave(&phba->hbalock, iflags);
  4782. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4783. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4784. return MBX_NOT_FINISHED;
  4785. }
  4786. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4787. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4788. return MBX_NOT_FINISHED;
  4789. }
  4790. if (unlikely(phba->sli.mbox_active)) {
  4791. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4792. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4793. "0384 There is pending active mailbox cmd\n");
  4794. return MBX_NOT_FINISHED;
  4795. }
  4796. /* Take the mailbox command service token */
  4797. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4798. /* Get the next mailbox command from head of queue */
  4799. mboxq = lpfc_mbox_get(phba);
  4800. /* If no more mailbox command waiting for post, we're done */
  4801. if (!mboxq) {
  4802. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4803. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4804. return MBX_SUCCESS;
  4805. }
  4806. phba->sli.mbox_active = mboxq;
  4807. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4808. /* Check device readiness for posting mailbox command */
  4809. rc = lpfc_mbox_dev_check(phba);
  4810. if (unlikely(rc))
  4811. /* Driver clean routine will clean up pending mailbox */
  4812. goto out_not_finished;
  4813. /* Prepare the mbox command to be posted */
  4814. mqe = &mboxq->u.mqe;
  4815. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4816. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4817. mod_timer(&psli->mbox_tmo, (jiffies +
  4818. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4819. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4820. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4821. "x%x x%x\n",
  4822. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4823. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4824. phba->pport->port_state, psli->sli_flag);
  4825. if (mbx_cmnd != MBX_HEARTBEAT) {
  4826. if (mboxq->vport) {
  4827. lpfc_debugfs_disc_trc(mboxq->vport,
  4828. LPFC_DISC_TRC_MBOX_VPORT,
  4829. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4830. mbx_cmnd, mqe->un.mb_words[0],
  4831. mqe->un.mb_words[1]);
  4832. } else {
  4833. lpfc_debugfs_disc_trc(phba->pport,
  4834. LPFC_DISC_TRC_MBOX,
  4835. "MBOX Send: cmd:x%x mb:x%x x%x",
  4836. mbx_cmnd, mqe->un.mb_words[0],
  4837. mqe->un.mb_words[1]);
  4838. }
  4839. }
  4840. psli->slistat.mbox_cmd++;
  4841. /* Post the mailbox command to the port */
  4842. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4843. if (rc != MBX_SUCCESS) {
  4844. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4845. "(%d):2533 Mailbox command x%x (x%x) "
  4846. "cannot issue Data: x%x x%x\n",
  4847. mboxq->vport ? mboxq->vport->vpi : 0,
  4848. mboxq->u.mb.mbxCommand,
  4849. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4850. psli->sli_flag, MBX_NOWAIT);
  4851. goto out_not_finished;
  4852. }
  4853. return rc;
  4854. out_not_finished:
  4855. spin_lock_irqsave(&phba->hbalock, iflags);
  4856. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4857. __lpfc_mbox_cmpl_put(phba, mboxq);
  4858. /* Release the token */
  4859. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4860. phba->sli.mbox_active = NULL;
  4861. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4862. return MBX_NOT_FINISHED;
  4863. }
  4864. /**
  4865. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4866. * @phba: Pointer to HBA context object.
  4867. * @pmbox: Pointer to mailbox object.
  4868. * @flag: Flag indicating how the mailbox need to be processed.
  4869. *
  4870. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4871. * the API jump table function pointer from the lpfc_hba struct.
  4872. *
  4873. * Return codes the caller owns the mailbox command after the return of the
  4874. * function.
  4875. **/
  4876. int
  4877. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4878. {
  4879. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4880. }
  4881. /**
  4882. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4883. * @phba: The hba struct for which this call is being executed.
  4884. * @dev_grp: The HBA PCI-Device group number.
  4885. *
  4886. * This routine sets up the mbox interface API function jump table in @phba
  4887. * struct.
  4888. * Returns: 0 - success, -ENODEV - failure.
  4889. **/
  4890. int
  4891. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4892. {
  4893. switch (dev_grp) {
  4894. case LPFC_PCI_DEV_LP:
  4895. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4896. phba->lpfc_sli_handle_slow_ring_event =
  4897. lpfc_sli_handle_slow_ring_event_s3;
  4898. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4899. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4900. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4901. break;
  4902. case LPFC_PCI_DEV_OC:
  4903. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4904. phba->lpfc_sli_handle_slow_ring_event =
  4905. lpfc_sli_handle_slow_ring_event_s4;
  4906. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4907. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  4908. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  4909. break;
  4910. default:
  4911. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4912. "1420 Invalid HBA PCI-device group: 0x%x\n",
  4913. dev_grp);
  4914. return -ENODEV;
  4915. break;
  4916. }
  4917. return 0;
  4918. }
  4919. /**
  4920. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  4921. * @phba: Pointer to HBA context object.
  4922. * @pring: Pointer to driver SLI ring object.
  4923. * @piocb: Pointer to address of newly added command iocb.
  4924. *
  4925. * This function is called with hbalock held to add a command
  4926. * iocb to the txq when SLI layer cannot submit the command iocb
  4927. * to the ring.
  4928. **/
  4929. static void
  4930. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4931. struct lpfc_iocbq *piocb)
  4932. {
  4933. /* Insert the caller's iocb in the txq tail for later processing. */
  4934. list_add_tail(&piocb->list, &pring->txq);
  4935. pring->txq_cnt++;
  4936. }
  4937. /**
  4938. * lpfc_sli_next_iocb - Get the next iocb in the txq
  4939. * @phba: Pointer to HBA context object.
  4940. * @pring: Pointer to driver SLI ring object.
  4941. * @piocb: Pointer to address of newly added command iocb.
  4942. *
  4943. * This function is called with hbalock held before a new
  4944. * iocb is submitted to the firmware. This function checks
  4945. * txq to flush the iocbs in txq to Firmware before
  4946. * submitting new iocbs to the Firmware.
  4947. * If there are iocbs in the txq which need to be submitted
  4948. * to firmware, lpfc_sli_next_iocb returns the first element
  4949. * of the txq after dequeuing it from txq.
  4950. * If there is no iocb in the txq then the function will return
  4951. * *piocb and *piocb is set to NULL. Caller needs to check
  4952. * *piocb to find if there are more commands in the txq.
  4953. **/
  4954. static struct lpfc_iocbq *
  4955. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4956. struct lpfc_iocbq **piocb)
  4957. {
  4958. struct lpfc_iocbq * nextiocb;
  4959. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  4960. if (!nextiocb) {
  4961. nextiocb = *piocb;
  4962. *piocb = NULL;
  4963. }
  4964. return nextiocb;
  4965. }
  4966. /**
  4967. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  4968. * @phba: Pointer to HBA context object.
  4969. * @ring_number: SLI ring number to issue iocb on.
  4970. * @piocb: Pointer to command iocb.
  4971. * @flag: Flag indicating if this command can be put into txq.
  4972. *
  4973. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  4974. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  4975. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  4976. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  4977. * this function allows only iocbs for posting buffers. This function finds
  4978. * next available slot in the command ring and posts the command to the
  4979. * available slot and writes the port attention register to request HBA start
  4980. * processing new iocb. If there is no slot available in the ring and
  4981. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  4982. * the function returns IOCB_BUSY.
  4983. *
  4984. * This function is called with hbalock held. The function will return success
  4985. * after it successfully submit the iocb to firmware or after adding to the
  4986. * txq.
  4987. **/
  4988. static int
  4989. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  4990. struct lpfc_iocbq *piocb, uint32_t flag)
  4991. {
  4992. struct lpfc_iocbq *nextiocb;
  4993. IOCB_t *iocb;
  4994. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  4995. if (piocb->iocb_cmpl && (!piocb->vport) &&
  4996. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  4997. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  4998. lpfc_printf_log(phba, KERN_ERR,
  4999. LOG_SLI | LOG_VPORT,
  5000. "1807 IOCB x%x failed. No vport\n",
  5001. piocb->iocb.ulpCommand);
  5002. dump_stack();
  5003. return IOCB_ERROR;
  5004. }
  5005. /* If the PCI channel is in offline state, do not post iocbs. */
  5006. if (unlikely(pci_channel_offline(phba->pcidev)))
  5007. return IOCB_ERROR;
  5008. /* If HBA has a deferred error attention, fail the iocb. */
  5009. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5010. return IOCB_ERROR;
  5011. /*
  5012. * We should never get an IOCB if we are in a < LINK_DOWN state
  5013. */
  5014. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5015. return IOCB_ERROR;
  5016. /*
  5017. * Check to see if we are blocking IOCB processing because of a
  5018. * outstanding event.
  5019. */
  5020. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5021. goto iocb_busy;
  5022. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5023. /*
  5024. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5025. * can be issued if the link is not up.
  5026. */
  5027. switch (piocb->iocb.ulpCommand) {
  5028. case CMD_GEN_REQUEST64_CR:
  5029. case CMD_GEN_REQUEST64_CX:
  5030. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5031. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5032. FC_RCTL_DD_UNSOL_CMD) ||
  5033. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5034. MENLO_TRANSPORT_TYPE))
  5035. goto iocb_busy;
  5036. break;
  5037. case CMD_QUE_RING_BUF_CN:
  5038. case CMD_QUE_RING_BUF64_CN:
  5039. /*
  5040. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5041. * completion, iocb_cmpl MUST be 0.
  5042. */
  5043. if (piocb->iocb_cmpl)
  5044. piocb->iocb_cmpl = NULL;
  5045. /*FALLTHROUGH*/
  5046. case CMD_CREATE_XRI_CR:
  5047. case CMD_CLOSE_XRI_CN:
  5048. case CMD_CLOSE_XRI_CX:
  5049. break;
  5050. default:
  5051. goto iocb_busy;
  5052. }
  5053. /*
  5054. * For FCP commands, we must be in a state where we can process link
  5055. * attention events.
  5056. */
  5057. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5058. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5059. goto iocb_busy;
  5060. }
  5061. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5062. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5063. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5064. if (iocb)
  5065. lpfc_sli_update_ring(phba, pring);
  5066. else
  5067. lpfc_sli_update_full_ring(phba, pring);
  5068. if (!piocb)
  5069. return IOCB_SUCCESS;
  5070. goto out_busy;
  5071. iocb_busy:
  5072. pring->stats.iocb_cmd_delay++;
  5073. out_busy:
  5074. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5075. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5076. return IOCB_SUCCESS;
  5077. }
  5078. return IOCB_BUSY;
  5079. }
  5080. /**
  5081. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5082. * @phba: Pointer to HBA context object.
  5083. * @piocb: Pointer to command iocb.
  5084. * @sglq: Pointer to the scatter gather queue object.
  5085. *
  5086. * This routine converts the bpl or bde that is in the IOCB
  5087. * to a sgl list for the sli4 hardware. The physical address
  5088. * of the bpl/bde is converted back to a virtual address.
  5089. * If the IOCB contains a BPL then the list of BDE's is
  5090. * converted to sli4_sge's. If the IOCB contains a single
  5091. * BDE then it is converted to a single sli_sge.
  5092. * The IOCB is still in cpu endianess so the contents of
  5093. * the bpl can be used without byte swapping.
  5094. *
  5095. * Returns valid XRI = Success, NO_XRI = Failure.
  5096. **/
  5097. static uint16_t
  5098. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5099. struct lpfc_sglq *sglq)
  5100. {
  5101. uint16_t xritag = NO_XRI;
  5102. struct ulp_bde64 *bpl = NULL;
  5103. struct ulp_bde64 bde;
  5104. struct sli4_sge *sgl = NULL;
  5105. IOCB_t *icmd;
  5106. int numBdes = 0;
  5107. int i = 0;
  5108. if (!piocbq || !sglq)
  5109. return xritag;
  5110. sgl = (struct sli4_sge *)sglq->sgl;
  5111. icmd = &piocbq->iocb;
  5112. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5113. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5114. sizeof(struct ulp_bde64);
  5115. /* The addrHigh and addrLow fields within the IOCB
  5116. * have not been byteswapped yet so there is no
  5117. * need to swap them back.
  5118. */
  5119. bpl = (struct ulp_bde64 *)
  5120. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5121. if (!bpl)
  5122. return xritag;
  5123. for (i = 0; i < numBdes; i++) {
  5124. /* Should already be byte swapped. */
  5125. sgl->addr_hi = bpl->addrHigh;
  5126. sgl->addr_lo = bpl->addrLow;
  5127. /* swap the size field back to the cpu so we
  5128. * can assign it to the sgl.
  5129. */
  5130. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5131. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5132. if ((i+1) == numBdes)
  5133. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5134. else
  5135. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5136. sgl->word2 = cpu_to_le32(sgl->word2);
  5137. sgl->word3 = cpu_to_le32(sgl->word3);
  5138. bpl++;
  5139. sgl++;
  5140. }
  5141. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5142. /* The addrHigh and addrLow fields of the BDE have not
  5143. * been byteswapped yet so they need to be swapped
  5144. * before putting them in the sgl.
  5145. */
  5146. sgl->addr_hi =
  5147. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5148. sgl->addr_lo =
  5149. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5150. bf_set(lpfc_sli4_sge_len, sgl,
  5151. icmd->un.genreq64.bdl.bdeSize);
  5152. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5153. sgl->word2 = cpu_to_le32(sgl->word2);
  5154. sgl->word3 = cpu_to_le32(sgl->word3);
  5155. }
  5156. return sglq->sli4_xritag;
  5157. }
  5158. /**
  5159. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5160. * @phba: Pointer to HBA context object.
  5161. *
  5162. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5163. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5164. * held.
  5165. *
  5166. * Return: index into SLI4 fast-path FCP queue index.
  5167. **/
  5168. static uint32_t
  5169. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5170. {
  5171. ++phba->fcp_qidx;
  5172. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5173. phba->fcp_qidx = 0;
  5174. return phba->fcp_qidx;
  5175. }
  5176. /**
  5177. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5178. * @phba: Pointer to HBA context object.
  5179. * @piocb: Pointer to command iocb.
  5180. * @wqe: Pointer to the work queue entry.
  5181. *
  5182. * This routine converts the iocb command to its Work Queue Entry
  5183. * equivalent. The wqe pointer should not have any fields set when
  5184. * this routine is called because it will memcpy over them.
  5185. * This routine does not set the CQ_ID or the WQEC bits in the
  5186. * wqe.
  5187. *
  5188. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5189. **/
  5190. static int
  5191. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5192. union lpfc_wqe *wqe)
  5193. {
  5194. uint32_t xmit_len = 0, total_len = 0;
  5195. uint8_t ct = 0;
  5196. uint32_t fip;
  5197. uint32_t abort_tag;
  5198. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5199. uint8_t cmnd;
  5200. uint16_t xritag;
  5201. struct ulp_bde64 *bpl = NULL;
  5202. uint32_t els_id = ELS_ID_DEFAULT;
  5203. int numBdes, i;
  5204. struct ulp_bde64 bde;
  5205. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5206. /* The fcp commands will set command type */
  5207. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5208. command_type = FCP_COMMAND;
  5209. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5210. command_type = ELS_COMMAND_FIP;
  5211. else
  5212. command_type = ELS_COMMAND_NON_FIP;
  5213. /* Some of the fields are in the right position already */
  5214. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5215. abort_tag = (uint32_t) iocbq->iotag;
  5216. xritag = iocbq->sli4_xritag;
  5217. wqe->words[7] = 0; /* The ct field has moved so reset */
  5218. /* words0-2 bpl convert bde */
  5219. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5220. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5221. sizeof(struct ulp_bde64);
  5222. bpl = (struct ulp_bde64 *)
  5223. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5224. if (!bpl)
  5225. return IOCB_ERROR;
  5226. /* Should already be byte swapped. */
  5227. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5228. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5229. /* swap the size field back to the cpu so we
  5230. * can assign it to the sgl.
  5231. */
  5232. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5233. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5234. total_len = 0;
  5235. for (i = 0; i < numBdes; i++) {
  5236. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5237. total_len += bde.tus.f.bdeSize;
  5238. }
  5239. } else
  5240. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5241. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5242. cmnd = iocbq->iocb.ulpCommand;
  5243. switch (iocbq->iocb.ulpCommand) {
  5244. case CMD_ELS_REQUEST64_CR:
  5245. if (!iocbq->iocb.ulpLe) {
  5246. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5247. "2007 Only Limited Edition cmd Format"
  5248. " supported 0x%x\n",
  5249. iocbq->iocb.ulpCommand);
  5250. return IOCB_ERROR;
  5251. }
  5252. wqe->els_req.payload_len = xmit_len;
  5253. /* Els_reguest64 has a TMO */
  5254. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5255. iocbq->iocb.ulpTimeout);
  5256. /* Need a VF for word 4 set the vf bit*/
  5257. bf_set(els_req64_vf, &wqe->els_req, 0);
  5258. /* And a VFID for word 12 */
  5259. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5260. /*
  5261. * Set ct field to 3, indicates that the context_tag field
  5262. * contains the FCFI and remote N_Port_ID is
  5263. * in word 5.
  5264. */
  5265. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5266. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5267. iocbq->iocb.ulpContext);
  5268. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5269. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5270. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5271. if (command_type == ELS_COMMAND_FIP) {
  5272. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5273. >> LPFC_FIP_ELS_ID_SHIFT);
  5274. }
  5275. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5276. break;
  5277. case CMD_XMIT_SEQUENCE64_CX:
  5278. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5279. iocbq->iocb.un.ulpWord[3]);
  5280. wqe->generic.word3 = 0;
  5281. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5282. bf_set(wqe_xc, &wqe->generic, 1);
  5283. /* The entire sequence is transmitted for this IOCB */
  5284. xmit_len = total_len;
  5285. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5286. case CMD_XMIT_SEQUENCE64_CR:
  5287. /* word3 iocb=io_tag32 wqe=payload_offset */
  5288. /* payload offset used for multilpe outstanding
  5289. * sequences on the same exchange
  5290. */
  5291. wqe->words[3] = 0;
  5292. /* word4 relative_offset memcpy */
  5293. /* word5 r_ctl/df_ctl memcpy */
  5294. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5295. wqe->xmit_sequence.xmit_len = xmit_len;
  5296. command_type = OTHER_COMMAND;
  5297. break;
  5298. case CMD_XMIT_BCAST64_CN:
  5299. /* word3 iocb=iotag32 wqe=payload_len */
  5300. wqe->words[3] = 0; /* no definition for this in wqe */
  5301. /* word4 iocb=rsvd wqe=rsvd */
  5302. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5303. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5304. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5305. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5306. break;
  5307. case CMD_FCP_IWRITE64_CR:
  5308. command_type = FCP_COMMAND_DATA_OUT;
  5309. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5310. * confusing.
  5311. * word3 is payload_len: byte offset to the sgl entry for the
  5312. * fcp_command.
  5313. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5314. * word5 is initial xfer len 0 = wait for xfer-ready
  5315. */
  5316. /* Always wait for xfer-ready before sending data */
  5317. wqe->fcp_iwrite.initial_xfer_len = 0;
  5318. /* word 4 (xfer length) should have been set on the memcpy */
  5319. /* allow write to fall through to read */
  5320. case CMD_FCP_IREAD64_CR:
  5321. /* FCP_CMD is always the 1st sgl entry */
  5322. wqe->fcp_iread.payload_len =
  5323. xmit_len + sizeof(struct fcp_rsp);
  5324. /* word 4 (xfer length) should have been set on the memcpy */
  5325. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5326. iocbq->iocb.ulpFCP2Rcvy);
  5327. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5328. /* The XC bit and the XS bit are similar. The driver never
  5329. * tracked whether or not the exchange was previouslly open.
  5330. * XC = Exchange create, 0 is create. 1 is already open.
  5331. * XS = link cmd: 1 do not close the exchange after command.
  5332. * XS = 0 close exchange when command completes.
  5333. * The only time we would not set the XC bit is when the XS bit
  5334. * is set and we are sending our 2nd or greater command on
  5335. * this exchange.
  5336. */
  5337. /* Always open the exchange */
  5338. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5339. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5340. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5341. break;
  5342. case CMD_FCP_ICMND64_CR:
  5343. /* Always open the exchange */
  5344. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5345. wqe->words[4] = 0;
  5346. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5347. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5348. break;
  5349. case CMD_GEN_REQUEST64_CR:
  5350. /* word3 command length is described as byte offset to the
  5351. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5352. * sgl[0] = cmnd
  5353. * sgl[1] = rsp.
  5354. *
  5355. */
  5356. wqe->gen_req.command_len = xmit_len;
  5357. /* Word4 parameter copied in the memcpy */
  5358. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5359. /* word6 context tag copied in memcpy */
  5360. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5361. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5362. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5363. "2015 Invalid CT %x command 0x%x\n",
  5364. ct, iocbq->iocb.ulpCommand);
  5365. return IOCB_ERROR;
  5366. }
  5367. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5368. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5369. iocbq->iocb.ulpTimeout);
  5370. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5371. command_type = OTHER_COMMAND;
  5372. break;
  5373. case CMD_XMIT_ELS_RSP64_CX:
  5374. /* words0-2 BDE memcpy */
  5375. /* word3 iocb=iotag32 wqe=rsvd */
  5376. wqe->words[3] = 0;
  5377. /* word4 iocb=did wge=rsvd. */
  5378. wqe->words[4] = 0;
  5379. /* word5 iocb=rsvd wge=did */
  5380. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5381. iocbq->iocb.un.elsreq64.remoteID);
  5382. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5383. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5384. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5385. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5386. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5387. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5388. iocbq->vport->vpi + phba->vpi_base);
  5389. command_type = OTHER_COMMAND;
  5390. break;
  5391. case CMD_CLOSE_XRI_CN:
  5392. case CMD_ABORT_XRI_CN:
  5393. case CMD_ABORT_XRI_CX:
  5394. /* words 0-2 memcpy should be 0 rserved */
  5395. /* port will send abts */
  5396. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5397. /*
  5398. * The link is down so the fw does not need to send abts
  5399. * on the wire.
  5400. */
  5401. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5402. else
  5403. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5404. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5405. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5406. wqe->words[5] = 0;
  5407. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5408. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5409. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5410. wqe->generic.abort_tag = abort_tag;
  5411. /*
  5412. * The abort handler will send us CMD_ABORT_XRI_CN or
  5413. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5414. */
  5415. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5416. cmnd = CMD_ABORT_XRI_CX;
  5417. command_type = OTHER_COMMAND;
  5418. xritag = 0;
  5419. break;
  5420. case CMD_XMIT_BLS_RSP64_CX:
  5421. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5422. * we re-construct this WQE here based on information in
  5423. * iocbq from scratch.
  5424. */
  5425. memset(wqe, 0, sizeof(union lpfc_wqe));
  5426. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5427. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5428. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5429. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5430. LPFC_ABTS_UNSOL_INT) {
  5431. /* ABTS sent by initiator to CT exchange, the
  5432. * RX_ID field will be filled with the newly
  5433. * allocated responder XRI.
  5434. */
  5435. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5436. iocbq->sli4_xritag);
  5437. } else {
  5438. /* ABTS sent by responder to CT exchange, the
  5439. * RX_ID field will be filled with the responder
  5440. * RX_ID from ABTS.
  5441. */
  5442. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5443. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5444. }
  5445. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5446. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5447. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5448. iocbq->iocb.ulpContext);
  5449. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5450. command_type = OTHER_COMMAND;
  5451. break;
  5452. case CMD_XRI_ABORTED_CX:
  5453. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5454. /* words0-2 are all 0's no bde */
  5455. /* word3 and word4 are rsvrd */
  5456. wqe->words[3] = 0;
  5457. wqe->words[4] = 0;
  5458. /* word5 iocb=rsvd wge=did */
  5459. /* There is no remote port id in the IOCB? */
  5460. /* Let this fall through and fail */
  5461. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5462. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5463. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5464. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5465. default:
  5466. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5467. "2014 Invalid command 0x%x\n",
  5468. iocbq->iocb.ulpCommand);
  5469. return IOCB_ERROR;
  5470. break;
  5471. }
  5472. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5473. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5474. wqe->generic.abort_tag = abort_tag;
  5475. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5476. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5477. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5478. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5479. return 0;
  5480. }
  5481. /**
  5482. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5483. * @phba: Pointer to HBA context object.
  5484. * @ring_number: SLI ring number to issue iocb on.
  5485. * @piocb: Pointer to command iocb.
  5486. * @flag: Flag indicating if this command can be put into txq.
  5487. *
  5488. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5489. * an iocb command to an HBA with SLI-4 interface spec.
  5490. *
  5491. * This function is called with hbalock held. The function will return success
  5492. * after it successfully submit the iocb to firmware or after adding to the
  5493. * txq.
  5494. **/
  5495. static int
  5496. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5497. struct lpfc_iocbq *piocb, uint32_t flag)
  5498. {
  5499. struct lpfc_sglq *sglq;
  5500. uint16_t xritag;
  5501. union lpfc_wqe wqe;
  5502. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5503. if (piocb->sli4_xritag == NO_XRI) {
  5504. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5505. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5506. sglq = NULL;
  5507. else {
  5508. sglq = __lpfc_sli_get_sglq(phba);
  5509. if (!sglq)
  5510. return IOCB_ERROR;
  5511. piocb->sli4_xritag = sglq->sli4_xritag;
  5512. }
  5513. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5514. sglq = NULL; /* These IO's already have an XRI and
  5515. * a mapped sgl.
  5516. */
  5517. } else {
  5518. /* This is a continuation of a commandi,(CX) so this
  5519. * sglq is on the active list
  5520. */
  5521. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5522. if (!sglq)
  5523. return IOCB_ERROR;
  5524. }
  5525. if (sglq) {
  5526. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5527. if (xritag != sglq->sli4_xritag)
  5528. return IOCB_ERROR;
  5529. }
  5530. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5531. return IOCB_ERROR;
  5532. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5533. /*
  5534. * For FCP command IOCB, get a new WQ index to distribute
  5535. * WQE across the WQsr. On the other hand, for abort IOCB,
  5536. * it carries the same WQ index to the original command
  5537. * IOCB.
  5538. */
  5539. if ((piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5540. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN))
  5541. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5542. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5543. &wqe))
  5544. return IOCB_ERROR;
  5545. } else {
  5546. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5547. return IOCB_ERROR;
  5548. }
  5549. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5550. return 0;
  5551. }
  5552. /**
  5553. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5554. *
  5555. * This routine wraps the actual lockless version for issusing IOCB function
  5556. * pointer from the lpfc_hba struct.
  5557. *
  5558. * Return codes:
  5559. * IOCB_ERROR - Error
  5560. * IOCB_SUCCESS - Success
  5561. * IOCB_BUSY - Busy
  5562. **/
  5563. static inline int
  5564. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5565. struct lpfc_iocbq *piocb, uint32_t flag)
  5566. {
  5567. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5568. }
  5569. /**
  5570. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5571. * @phba: The hba struct for which this call is being executed.
  5572. * @dev_grp: The HBA PCI-Device group number.
  5573. *
  5574. * This routine sets up the SLI interface API function jump table in @phba
  5575. * struct.
  5576. * Returns: 0 - success, -ENODEV - failure.
  5577. **/
  5578. int
  5579. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5580. {
  5581. switch (dev_grp) {
  5582. case LPFC_PCI_DEV_LP:
  5583. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5584. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5585. break;
  5586. case LPFC_PCI_DEV_OC:
  5587. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5588. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5589. break;
  5590. default:
  5591. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5592. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5593. dev_grp);
  5594. return -ENODEV;
  5595. break;
  5596. }
  5597. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5598. return 0;
  5599. }
  5600. /**
  5601. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5602. * @phba: Pointer to HBA context object.
  5603. * @pring: Pointer to driver SLI ring object.
  5604. * @piocb: Pointer to command iocb.
  5605. * @flag: Flag indicating if this command can be put into txq.
  5606. *
  5607. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5608. * function. This function gets the hbalock and calls
  5609. * __lpfc_sli_issue_iocb function and will return the error returned
  5610. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5611. * functions which do not hold hbalock.
  5612. **/
  5613. int
  5614. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5615. struct lpfc_iocbq *piocb, uint32_t flag)
  5616. {
  5617. unsigned long iflags;
  5618. int rc;
  5619. spin_lock_irqsave(&phba->hbalock, iflags);
  5620. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5621. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5622. return rc;
  5623. }
  5624. /**
  5625. * lpfc_extra_ring_setup - Extra ring setup function
  5626. * @phba: Pointer to HBA context object.
  5627. *
  5628. * This function is called while driver attaches with the
  5629. * HBA to setup the extra ring. The extra ring is used
  5630. * only when driver needs to support target mode functionality
  5631. * or IP over FC functionalities.
  5632. *
  5633. * This function is called with no lock held.
  5634. **/
  5635. static int
  5636. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5637. {
  5638. struct lpfc_sli *psli;
  5639. struct lpfc_sli_ring *pring;
  5640. psli = &phba->sli;
  5641. /* Adjust cmd/rsp ring iocb entries more evenly */
  5642. /* Take some away from the FCP ring */
  5643. pring = &psli->ring[psli->fcp_ring];
  5644. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5645. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5646. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5647. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5648. /* and give them to the extra ring */
  5649. pring = &psli->ring[psli->extra_ring];
  5650. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5651. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5652. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5653. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5654. /* Setup default profile for this ring */
  5655. pring->iotag_max = 4096;
  5656. pring->num_mask = 1;
  5657. pring->prt[0].profile = 0; /* Mask 0 */
  5658. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5659. pring->prt[0].type = phba->cfg_multi_ring_type;
  5660. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5661. return 0;
  5662. }
  5663. /**
  5664. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5665. * @phba: Pointer to HBA context object.
  5666. * @pring: Pointer to driver SLI ring object.
  5667. * @iocbq: Pointer to iocb object.
  5668. *
  5669. * This function is called by the slow ring event handler
  5670. * function when there is an ASYNC event iocb in the ring.
  5671. * This function is called with no lock held.
  5672. * Currently this function handles only temperature related
  5673. * ASYNC events. The function decodes the temperature sensor
  5674. * event message and posts events for the management applications.
  5675. **/
  5676. static void
  5677. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5678. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5679. {
  5680. IOCB_t *icmd;
  5681. uint16_t evt_code;
  5682. uint16_t temp;
  5683. struct temp_event temp_event_data;
  5684. struct Scsi_Host *shost;
  5685. uint32_t *iocb_w;
  5686. icmd = &iocbq->iocb;
  5687. evt_code = icmd->un.asyncstat.evt_code;
  5688. temp = icmd->ulpContext;
  5689. if ((evt_code != ASYNC_TEMP_WARN) &&
  5690. (evt_code != ASYNC_TEMP_SAFE)) {
  5691. iocb_w = (uint32_t *) icmd;
  5692. lpfc_printf_log(phba,
  5693. KERN_ERR,
  5694. LOG_SLI,
  5695. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5696. " evt_code 0x%x\n"
  5697. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5698. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5699. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5700. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5701. pring->ringno,
  5702. icmd->un.asyncstat.evt_code,
  5703. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5704. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5705. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5706. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5707. return;
  5708. }
  5709. temp_event_data.data = (uint32_t)temp;
  5710. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5711. if (evt_code == ASYNC_TEMP_WARN) {
  5712. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5713. lpfc_printf_log(phba,
  5714. KERN_ERR,
  5715. LOG_TEMP,
  5716. "0347 Adapter is very hot, please take "
  5717. "corrective action. temperature : %d Celsius\n",
  5718. temp);
  5719. }
  5720. if (evt_code == ASYNC_TEMP_SAFE) {
  5721. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5722. lpfc_printf_log(phba,
  5723. KERN_ERR,
  5724. LOG_TEMP,
  5725. "0340 Adapter temperature is OK now. "
  5726. "temperature : %d Celsius\n",
  5727. temp);
  5728. }
  5729. /* Send temperature change event to applications */
  5730. shost = lpfc_shost_from_vport(phba->pport);
  5731. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5732. sizeof(temp_event_data), (char *) &temp_event_data,
  5733. LPFC_NL_VENDOR_ID);
  5734. }
  5735. /**
  5736. * lpfc_sli_setup - SLI ring setup function
  5737. * @phba: Pointer to HBA context object.
  5738. *
  5739. * lpfc_sli_setup sets up rings of the SLI interface with
  5740. * number of iocbs per ring and iotags. This function is
  5741. * called while driver attach to the HBA and before the
  5742. * interrupts are enabled. So there is no need for locking.
  5743. *
  5744. * This function always returns 0.
  5745. **/
  5746. int
  5747. lpfc_sli_setup(struct lpfc_hba *phba)
  5748. {
  5749. int i, totiocbsize = 0;
  5750. struct lpfc_sli *psli = &phba->sli;
  5751. struct lpfc_sli_ring *pring;
  5752. psli->num_rings = MAX_CONFIGURED_RINGS;
  5753. psli->sli_flag = 0;
  5754. psli->fcp_ring = LPFC_FCP_RING;
  5755. psli->next_ring = LPFC_FCP_NEXT_RING;
  5756. psli->extra_ring = LPFC_EXTRA_RING;
  5757. psli->iocbq_lookup = NULL;
  5758. psli->iocbq_lookup_len = 0;
  5759. psli->last_iotag = 0;
  5760. for (i = 0; i < psli->num_rings; i++) {
  5761. pring = &psli->ring[i];
  5762. switch (i) {
  5763. case LPFC_FCP_RING: /* ring 0 - FCP */
  5764. /* numCiocb and numRiocb are used in config_port */
  5765. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5766. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5767. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5768. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5769. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5770. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5771. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5772. SLI3_IOCB_CMD_SIZE :
  5773. SLI2_IOCB_CMD_SIZE;
  5774. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5775. SLI3_IOCB_RSP_SIZE :
  5776. SLI2_IOCB_RSP_SIZE;
  5777. pring->iotag_ctr = 0;
  5778. pring->iotag_max =
  5779. (phba->cfg_hba_queue_depth * 2);
  5780. pring->fast_iotag = pring->iotag_max;
  5781. pring->num_mask = 0;
  5782. break;
  5783. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5784. /* numCiocb and numRiocb are used in config_port */
  5785. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5786. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5787. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5788. SLI3_IOCB_CMD_SIZE :
  5789. SLI2_IOCB_CMD_SIZE;
  5790. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5791. SLI3_IOCB_RSP_SIZE :
  5792. SLI2_IOCB_RSP_SIZE;
  5793. pring->iotag_max = phba->cfg_hba_queue_depth;
  5794. pring->num_mask = 0;
  5795. break;
  5796. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5797. /* numCiocb and numRiocb are used in config_port */
  5798. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5799. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5800. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5801. SLI3_IOCB_CMD_SIZE :
  5802. SLI2_IOCB_CMD_SIZE;
  5803. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5804. SLI3_IOCB_RSP_SIZE :
  5805. SLI2_IOCB_RSP_SIZE;
  5806. pring->fast_iotag = 0;
  5807. pring->iotag_ctr = 0;
  5808. pring->iotag_max = 4096;
  5809. pring->lpfc_sli_rcv_async_status =
  5810. lpfc_sli_async_event_handler;
  5811. pring->num_mask = LPFC_MAX_RING_MASK;
  5812. pring->prt[0].profile = 0; /* Mask 0 */
  5813. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5814. pring->prt[0].type = FC_TYPE_ELS;
  5815. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5816. lpfc_els_unsol_event;
  5817. pring->prt[1].profile = 0; /* Mask 1 */
  5818. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5819. pring->prt[1].type = FC_TYPE_ELS;
  5820. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5821. lpfc_els_unsol_event;
  5822. pring->prt[2].profile = 0; /* Mask 2 */
  5823. /* NameServer Inquiry */
  5824. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5825. /* NameServer */
  5826. pring->prt[2].type = FC_TYPE_CT;
  5827. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5828. lpfc_ct_unsol_event;
  5829. pring->prt[3].profile = 0; /* Mask 3 */
  5830. /* NameServer response */
  5831. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5832. /* NameServer */
  5833. pring->prt[3].type = FC_TYPE_CT;
  5834. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5835. lpfc_ct_unsol_event;
  5836. /* abort unsolicited sequence */
  5837. pring->prt[4].profile = 0; /* Mask 4 */
  5838. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5839. pring->prt[4].type = FC_TYPE_BLS;
  5840. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5841. lpfc_sli4_ct_abort_unsol_event;
  5842. break;
  5843. }
  5844. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5845. (pring->numRiocb * pring->sizeRiocb);
  5846. }
  5847. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5848. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5849. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5850. "SLI2 SLIM Data: x%x x%lx\n",
  5851. phba->brd_no, totiocbsize,
  5852. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5853. }
  5854. if (phba->cfg_multi_ring_support == 2)
  5855. lpfc_extra_ring_setup(phba);
  5856. return 0;
  5857. }
  5858. /**
  5859. * lpfc_sli_queue_setup - Queue initialization function
  5860. * @phba: Pointer to HBA context object.
  5861. *
  5862. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5863. * ring. This function also initializes ring indices of each ring.
  5864. * This function is called during the initialization of the SLI
  5865. * interface of an HBA.
  5866. * This function is called with no lock held and always returns
  5867. * 1.
  5868. **/
  5869. int
  5870. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5871. {
  5872. struct lpfc_sli *psli;
  5873. struct lpfc_sli_ring *pring;
  5874. int i;
  5875. psli = &phba->sli;
  5876. spin_lock_irq(&phba->hbalock);
  5877. INIT_LIST_HEAD(&psli->mboxq);
  5878. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5879. /* Initialize list headers for txq and txcmplq as double linked lists */
  5880. for (i = 0; i < psli->num_rings; i++) {
  5881. pring = &psli->ring[i];
  5882. pring->ringno = i;
  5883. pring->next_cmdidx = 0;
  5884. pring->local_getidx = 0;
  5885. pring->cmdidx = 0;
  5886. INIT_LIST_HEAD(&pring->txq);
  5887. INIT_LIST_HEAD(&pring->txcmplq);
  5888. INIT_LIST_HEAD(&pring->iocb_continueq);
  5889. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5890. INIT_LIST_HEAD(&pring->postbufq);
  5891. }
  5892. spin_unlock_irq(&phba->hbalock);
  5893. return 1;
  5894. }
  5895. /**
  5896. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5897. * @phba: Pointer to HBA context object.
  5898. *
  5899. * This routine flushes the mailbox command subsystem. It will unconditionally
  5900. * flush all the mailbox commands in the three possible stages in the mailbox
  5901. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5902. * command; and completed mailbox command queue. It is caller's responsibility
  5903. * to make sure that the driver is in the proper state to flush the mailbox
  5904. * command sub-system. Namely, the posting of mailbox commands into the
  5905. * pending mailbox command queue from the various clients must be stopped;
  5906. * either the HBA is in a state that it will never works on the outstanding
  5907. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5908. * mailbox command has been completed.
  5909. **/
  5910. static void
  5911. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5912. {
  5913. LIST_HEAD(completions);
  5914. struct lpfc_sli *psli = &phba->sli;
  5915. LPFC_MBOXQ_t *pmb;
  5916. unsigned long iflag;
  5917. /* Flush all the mailbox commands in the mbox system */
  5918. spin_lock_irqsave(&phba->hbalock, iflag);
  5919. /* The pending mailbox command queue */
  5920. list_splice_init(&phba->sli.mboxq, &completions);
  5921. /* The outstanding active mailbox command */
  5922. if (psli->mbox_active) {
  5923. list_add_tail(&psli->mbox_active->list, &completions);
  5924. psli->mbox_active = NULL;
  5925. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5926. }
  5927. /* The completed mailbox command queue */
  5928. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5929. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5930. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5931. while (!list_empty(&completions)) {
  5932. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5933. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5934. if (pmb->mbox_cmpl)
  5935. pmb->mbox_cmpl(phba, pmb);
  5936. }
  5937. }
  5938. /**
  5939. * lpfc_sli_host_down - Vport cleanup function
  5940. * @vport: Pointer to virtual port object.
  5941. *
  5942. * lpfc_sli_host_down is called to clean up the resources
  5943. * associated with a vport before destroying virtual
  5944. * port data structures.
  5945. * This function does following operations:
  5946. * - Free discovery resources associated with this virtual
  5947. * port.
  5948. * - Free iocbs associated with this virtual port in
  5949. * the txq.
  5950. * - Send abort for all iocb commands associated with this
  5951. * vport in txcmplq.
  5952. *
  5953. * This function is called with no lock held and always returns 1.
  5954. **/
  5955. int
  5956. lpfc_sli_host_down(struct lpfc_vport *vport)
  5957. {
  5958. LIST_HEAD(completions);
  5959. struct lpfc_hba *phba = vport->phba;
  5960. struct lpfc_sli *psli = &phba->sli;
  5961. struct lpfc_sli_ring *pring;
  5962. struct lpfc_iocbq *iocb, *next_iocb;
  5963. int i;
  5964. unsigned long flags = 0;
  5965. uint16_t prev_pring_flag;
  5966. lpfc_cleanup_discovery_resources(vport);
  5967. spin_lock_irqsave(&phba->hbalock, flags);
  5968. for (i = 0; i < psli->num_rings; i++) {
  5969. pring = &psli->ring[i];
  5970. prev_pring_flag = pring->flag;
  5971. /* Only slow rings */
  5972. if (pring->ringno == LPFC_ELS_RING) {
  5973. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5974. /* Set the lpfc data pending flag */
  5975. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5976. }
  5977. /*
  5978. * Error everything on the txq since these iocbs have not been
  5979. * given to the FW yet.
  5980. */
  5981. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  5982. if (iocb->vport != vport)
  5983. continue;
  5984. list_move_tail(&iocb->list, &completions);
  5985. pring->txq_cnt--;
  5986. }
  5987. /* Next issue ABTS for everything on the txcmplq */
  5988. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  5989. list) {
  5990. if (iocb->vport != vport)
  5991. continue;
  5992. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  5993. }
  5994. pring->flag = prev_pring_flag;
  5995. }
  5996. spin_unlock_irqrestore(&phba->hbalock, flags);
  5997. /* Cancel all the IOCBs from the completions list */
  5998. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5999. IOERR_SLI_DOWN);
  6000. return 1;
  6001. }
  6002. /**
  6003. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6004. * @phba: Pointer to HBA context object.
  6005. *
  6006. * This function cleans up all iocb, buffers, mailbox commands
  6007. * while shutting down the HBA. This function is called with no
  6008. * lock held and always returns 1.
  6009. * This function does the following to cleanup driver resources:
  6010. * - Free discovery resources for each virtual port
  6011. * - Cleanup any pending fabric iocbs
  6012. * - Iterate through the iocb txq and free each entry
  6013. * in the list.
  6014. * - Free up any buffer posted to the HBA
  6015. * - Free mailbox commands in the mailbox queue.
  6016. **/
  6017. int
  6018. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6019. {
  6020. LIST_HEAD(completions);
  6021. struct lpfc_sli *psli = &phba->sli;
  6022. struct lpfc_sli_ring *pring;
  6023. struct lpfc_dmabuf *buf_ptr;
  6024. unsigned long flags = 0;
  6025. int i;
  6026. /* Shutdown the mailbox command sub-system */
  6027. lpfc_sli_mbox_sys_shutdown(phba);
  6028. lpfc_hba_down_prep(phba);
  6029. lpfc_fabric_abort_hba(phba);
  6030. spin_lock_irqsave(&phba->hbalock, flags);
  6031. for (i = 0; i < psli->num_rings; i++) {
  6032. pring = &psli->ring[i];
  6033. /* Only slow rings */
  6034. if (pring->ringno == LPFC_ELS_RING) {
  6035. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6036. /* Set the lpfc data pending flag */
  6037. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6038. }
  6039. /*
  6040. * Error everything on the txq since these iocbs have not been
  6041. * given to the FW yet.
  6042. */
  6043. list_splice_init(&pring->txq, &completions);
  6044. pring->txq_cnt = 0;
  6045. }
  6046. spin_unlock_irqrestore(&phba->hbalock, flags);
  6047. /* Cancel all the IOCBs from the completions list */
  6048. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6049. IOERR_SLI_DOWN);
  6050. spin_lock_irqsave(&phba->hbalock, flags);
  6051. list_splice_init(&phba->elsbuf, &completions);
  6052. phba->elsbuf_cnt = 0;
  6053. phba->elsbuf_prev_cnt = 0;
  6054. spin_unlock_irqrestore(&phba->hbalock, flags);
  6055. while (!list_empty(&completions)) {
  6056. list_remove_head(&completions, buf_ptr,
  6057. struct lpfc_dmabuf, list);
  6058. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6059. kfree(buf_ptr);
  6060. }
  6061. /* Return any active mbox cmds */
  6062. del_timer_sync(&psli->mbox_tmo);
  6063. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6064. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6065. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6066. return 1;
  6067. }
  6068. /**
  6069. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6070. * @phba: Pointer to HBA context object.
  6071. *
  6072. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6073. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6074. * lock held and always returns 1.
  6075. *
  6076. * This function does the following to cleanup driver FCoE function resources:
  6077. * - Free discovery resources for each virtual port
  6078. * - Cleanup any pending fabric iocbs
  6079. * - Iterate through the iocb txq and free each entry in the list.
  6080. * - Free up any buffer posted to the HBA.
  6081. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6082. * - Free mailbox commands in the mailbox queue.
  6083. **/
  6084. int
  6085. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6086. {
  6087. /* Stop the SLI4 device port */
  6088. lpfc_stop_port(phba);
  6089. /* Tear down the queues in the HBA */
  6090. lpfc_sli4_queue_unset(phba);
  6091. /* unregister default FCFI from the HBA */
  6092. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6093. return 1;
  6094. }
  6095. /**
  6096. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6097. * @srcp: Source memory pointer.
  6098. * @destp: Destination memory pointer.
  6099. * @cnt: Number of words required to be copied.
  6100. *
  6101. * This function is used for copying data between driver memory
  6102. * and the SLI memory. This function also changes the endianness
  6103. * of each word if native endianness is different from SLI
  6104. * endianness. This function can be called with or without
  6105. * lock.
  6106. **/
  6107. void
  6108. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6109. {
  6110. uint32_t *src = srcp;
  6111. uint32_t *dest = destp;
  6112. uint32_t ldata;
  6113. int i;
  6114. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6115. ldata = *src;
  6116. ldata = le32_to_cpu(ldata);
  6117. *dest = ldata;
  6118. src++;
  6119. dest++;
  6120. }
  6121. }
  6122. /**
  6123. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6124. * @srcp: Source memory pointer.
  6125. * @destp: Destination memory pointer.
  6126. * @cnt: Number of words required to be copied.
  6127. *
  6128. * This function is used for copying data between a data structure
  6129. * with big endian representation to local endianness.
  6130. * This function can be called with or without lock.
  6131. **/
  6132. void
  6133. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6134. {
  6135. uint32_t *src = srcp;
  6136. uint32_t *dest = destp;
  6137. uint32_t ldata;
  6138. int i;
  6139. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6140. ldata = *src;
  6141. ldata = be32_to_cpu(ldata);
  6142. *dest = ldata;
  6143. src++;
  6144. dest++;
  6145. }
  6146. }
  6147. /**
  6148. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6149. * @phba: Pointer to HBA context object.
  6150. * @pring: Pointer to driver SLI ring object.
  6151. * @mp: Pointer to driver buffer object.
  6152. *
  6153. * This function is called with no lock held.
  6154. * It always return zero after adding the buffer to the postbufq
  6155. * buffer list.
  6156. **/
  6157. int
  6158. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6159. struct lpfc_dmabuf *mp)
  6160. {
  6161. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6162. later */
  6163. spin_lock_irq(&phba->hbalock);
  6164. list_add_tail(&mp->list, &pring->postbufq);
  6165. pring->postbufq_cnt++;
  6166. spin_unlock_irq(&phba->hbalock);
  6167. return 0;
  6168. }
  6169. /**
  6170. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6171. * @phba: Pointer to HBA context object.
  6172. *
  6173. * When HBQ is enabled, buffers are searched based on tags. This function
  6174. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6175. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6176. * does not conflict with tags of buffer posted for unsolicited events.
  6177. * The function returns the allocated tag. The function is called with
  6178. * no locks held.
  6179. **/
  6180. uint32_t
  6181. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6182. {
  6183. spin_lock_irq(&phba->hbalock);
  6184. phba->buffer_tag_count++;
  6185. /*
  6186. * Always set the QUE_BUFTAG_BIT to distiguish between
  6187. * a tag assigned by HBQ.
  6188. */
  6189. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6190. spin_unlock_irq(&phba->hbalock);
  6191. return phba->buffer_tag_count;
  6192. }
  6193. /**
  6194. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6195. * @phba: Pointer to HBA context object.
  6196. * @pring: Pointer to driver SLI ring object.
  6197. * @tag: Buffer tag.
  6198. *
  6199. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6200. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6201. * iocb is posted to the response ring with the tag of the buffer.
  6202. * This function searches the pring->postbufq list using the tag
  6203. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6204. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6205. * buffer is returned to the caller else NULL is returned.
  6206. * This function is called with no lock held.
  6207. **/
  6208. struct lpfc_dmabuf *
  6209. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6210. uint32_t tag)
  6211. {
  6212. struct lpfc_dmabuf *mp, *next_mp;
  6213. struct list_head *slp = &pring->postbufq;
  6214. /* Search postbufq, from the begining, looking for a match on tag */
  6215. spin_lock_irq(&phba->hbalock);
  6216. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6217. if (mp->buffer_tag == tag) {
  6218. list_del_init(&mp->list);
  6219. pring->postbufq_cnt--;
  6220. spin_unlock_irq(&phba->hbalock);
  6221. return mp;
  6222. }
  6223. }
  6224. spin_unlock_irq(&phba->hbalock);
  6225. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6226. "0402 Cannot find virtual addr for buffer tag on "
  6227. "ring %d Data x%lx x%p x%p x%x\n",
  6228. pring->ringno, (unsigned long) tag,
  6229. slp->next, slp->prev, pring->postbufq_cnt);
  6230. return NULL;
  6231. }
  6232. /**
  6233. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6234. * @phba: Pointer to HBA context object.
  6235. * @pring: Pointer to driver SLI ring object.
  6236. * @phys: DMA address of the buffer.
  6237. *
  6238. * This function searches the buffer list using the dma_address
  6239. * of unsolicited event to find the driver's lpfc_dmabuf object
  6240. * corresponding to the dma_address. The function returns the
  6241. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6242. * This function is called by the ct and els unsolicited event
  6243. * handlers to get the buffer associated with the unsolicited
  6244. * event.
  6245. *
  6246. * This function is called with no lock held.
  6247. **/
  6248. struct lpfc_dmabuf *
  6249. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6250. dma_addr_t phys)
  6251. {
  6252. struct lpfc_dmabuf *mp, *next_mp;
  6253. struct list_head *slp = &pring->postbufq;
  6254. /* Search postbufq, from the begining, looking for a match on phys */
  6255. spin_lock_irq(&phba->hbalock);
  6256. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6257. if (mp->phys == phys) {
  6258. list_del_init(&mp->list);
  6259. pring->postbufq_cnt--;
  6260. spin_unlock_irq(&phba->hbalock);
  6261. return mp;
  6262. }
  6263. }
  6264. spin_unlock_irq(&phba->hbalock);
  6265. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6266. "0410 Cannot find virtual addr for mapped buf on "
  6267. "ring %d Data x%llx x%p x%p x%x\n",
  6268. pring->ringno, (unsigned long long)phys,
  6269. slp->next, slp->prev, pring->postbufq_cnt);
  6270. return NULL;
  6271. }
  6272. /**
  6273. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6274. * @phba: Pointer to HBA context object.
  6275. * @cmdiocb: Pointer to driver command iocb object.
  6276. * @rspiocb: Pointer to driver response iocb object.
  6277. *
  6278. * This function is the completion handler for the abort iocbs for
  6279. * ELS commands. This function is called from the ELS ring event
  6280. * handler with no lock held. This function frees memory resources
  6281. * associated with the abort iocb.
  6282. **/
  6283. static void
  6284. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6285. struct lpfc_iocbq *rspiocb)
  6286. {
  6287. IOCB_t *irsp = &rspiocb->iocb;
  6288. uint16_t abort_iotag, abort_context;
  6289. struct lpfc_iocbq *abort_iocb;
  6290. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6291. abort_iocb = NULL;
  6292. if (irsp->ulpStatus) {
  6293. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6294. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6295. spin_lock_irq(&phba->hbalock);
  6296. if (phba->sli_rev < LPFC_SLI_REV4) {
  6297. if (abort_iotag != 0 &&
  6298. abort_iotag <= phba->sli.last_iotag)
  6299. abort_iocb =
  6300. phba->sli.iocbq_lookup[abort_iotag];
  6301. } else
  6302. /* For sli4 the abort_tag is the XRI,
  6303. * so the abort routine puts the iotag of the iocb
  6304. * being aborted in the context field of the abort
  6305. * IOCB.
  6306. */
  6307. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6308. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6309. "0327 Cannot abort els iocb %p "
  6310. "with tag %x context %x, abort status %x, "
  6311. "abort code %x\n",
  6312. abort_iocb, abort_iotag, abort_context,
  6313. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6314. /*
  6315. * If the iocb is not found in Firmware queue the iocb
  6316. * might have completed already. Do not free it again.
  6317. */
  6318. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6319. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6320. spin_unlock_irq(&phba->hbalock);
  6321. lpfc_sli_release_iocbq(phba, cmdiocb);
  6322. return;
  6323. }
  6324. /* For SLI4 the ulpContext field for abort IOCB
  6325. * holds the iotag of the IOCB being aborted so
  6326. * the local abort_context needs to be reset to
  6327. * match the aborted IOCBs ulpContext.
  6328. */
  6329. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6330. abort_context = abort_iocb->iocb.ulpContext;
  6331. }
  6332. /*
  6333. * make sure we have the right iocbq before taking it
  6334. * off the txcmplq and try to call completion routine.
  6335. */
  6336. if (!abort_iocb ||
  6337. abort_iocb->iocb.ulpContext != abort_context ||
  6338. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6339. spin_unlock_irq(&phba->hbalock);
  6340. else {
  6341. list_del_init(&abort_iocb->list);
  6342. pring->txcmplq_cnt--;
  6343. spin_unlock_irq(&phba->hbalock);
  6344. /* Firmware could still be in progress of DMAing
  6345. * payload, so don't free data buffer till after
  6346. * a hbeat.
  6347. */
  6348. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6349. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6350. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6351. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6352. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6353. }
  6354. }
  6355. lpfc_sli_release_iocbq(phba, cmdiocb);
  6356. return;
  6357. }
  6358. /**
  6359. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6360. * @phba: Pointer to HBA context object.
  6361. * @cmdiocb: Pointer to driver command iocb object.
  6362. * @rspiocb: Pointer to driver response iocb object.
  6363. *
  6364. * The function is called from SLI ring event handler with no
  6365. * lock held. This function is the completion handler for ELS commands
  6366. * which are aborted. The function frees memory resources used for
  6367. * the aborted ELS commands.
  6368. **/
  6369. static void
  6370. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6371. struct lpfc_iocbq *rspiocb)
  6372. {
  6373. IOCB_t *irsp = &rspiocb->iocb;
  6374. /* ELS cmd tag <ulpIoTag> completes */
  6375. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6376. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6377. "x%x x%x x%x\n",
  6378. irsp->ulpIoTag, irsp->ulpStatus,
  6379. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6380. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6381. lpfc_ct_free_iocb(phba, cmdiocb);
  6382. else
  6383. lpfc_els_free_iocb(phba, cmdiocb);
  6384. return;
  6385. }
  6386. /**
  6387. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6388. * @phba: Pointer to HBA context object.
  6389. * @pring: Pointer to driver SLI ring object.
  6390. * @cmdiocb: Pointer to driver command iocb object.
  6391. *
  6392. * This function issues an abort iocb for the provided command
  6393. * iocb. This function is called with hbalock held.
  6394. * The function returns 0 when it fails due to memory allocation
  6395. * failure or when the command iocb is an abort request.
  6396. **/
  6397. int
  6398. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6399. struct lpfc_iocbq *cmdiocb)
  6400. {
  6401. struct lpfc_vport *vport = cmdiocb->vport;
  6402. struct lpfc_iocbq *abtsiocbp;
  6403. IOCB_t *icmd = NULL;
  6404. IOCB_t *iabt = NULL;
  6405. int retval = IOCB_ERROR;
  6406. /*
  6407. * There are certain command types we don't want to abort. And we
  6408. * don't want to abort commands that are already in the process of
  6409. * being aborted.
  6410. */
  6411. icmd = &cmdiocb->iocb;
  6412. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6413. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6414. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6415. return 0;
  6416. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6417. * callback so that nothing happens when it finishes.
  6418. */
  6419. if ((vport->load_flag & FC_UNLOADING) &&
  6420. (pring->ringno == LPFC_ELS_RING)) {
  6421. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6422. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6423. else
  6424. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6425. goto abort_iotag_exit;
  6426. }
  6427. /* issue ABTS for this IOCB based on iotag */
  6428. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6429. if (abtsiocbp == NULL)
  6430. return 0;
  6431. /* This signals the response to set the correct status
  6432. * before calling the completion handler.
  6433. */
  6434. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6435. iabt = &abtsiocbp->iocb;
  6436. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6437. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6438. if (phba->sli_rev == LPFC_SLI_REV4) {
  6439. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6440. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6441. }
  6442. else
  6443. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6444. iabt->ulpLe = 1;
  6445. iabt->ulpClass = icmd->ulpClass;
  6446. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6447. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6448. if (phba->link_state >= LPFC_LINK_UP)
  6449. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6450. else
  6451. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6452. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6453. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6454. "0339 Abort xri x%x, original iotag x%x, "
  6455. "abort cmd iotag x%x\n",
  6456. iabt->un.acxri.abortContextTag,
  6457. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6458. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6459. if (retval)
  6460. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6461. abort_iotag_exit:
  6462. /*
  6463. * Caller to this routine should check for IOCB_ERROR
  6464. * and handle it properly. This routine no longer removes
  6465. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6466. */
  6467. return retval;
  6468. }
  6469. /**
  6470. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6471. * @iocbq: Pointer to driver iocb object.
  6472. * @vport: Pointer to driver virtual port object.
  6473. * @tgt_id: SCSI ID of the target.
  6474. * @lun_id: LUN ID of the scsi device.
  6475. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6476. *
  6477. * This function acts as an iocb filter for functions which abort or count
  6478. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6479. * 0 if the filtering criteria is met for the given iocb and will return
  6480. * 1 if the filtering criteria is not met.
  6481. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6482. * given iocb is for the SCSI device specified by vport, tgt_id and
  6483. * lun_id parameter.
  6484. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6485. * given iocb is for the SCSI target specified by vport and tgt_id
  6486. * parameters.
  6487. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6488. * given iocb is for the SCSI host associated with the given vport.
  6489. * This function is called with no locks held.
  6490. **/
  6491. static int
  6492. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6493. uint16_t tgt_id, uint64_t lun_id,
  6494. lpfc_ctx_cmd ctx_cmd)
  6495. {
  6496. struct lpfc_scsi_buf *lpfc_cmd;
  6497. int rc = 1;
  6498. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6499. return rc;
  6500. if (iocbq->vport != vport)
  6501. return rc;
  6502. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6503. if (lpfc_cmd->pCmd == NULL)
  6504. return rc;
  6505. switch (ctx_cmd) {
  6506. case LPFC_CTX_LUN:
  6507. if ((lpfc_cmd->rdata->pnode) &&
  6508. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6509. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6510. rc = 0;
  6511. break;
  6512. case LPFC_CTX_TGT:
  6513. if ((lpfc_cmd->rdata->pnode) &&
  6514. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6515. rc = 0;
  6516. break;
  6517. case LPFC_CTX_HOST:
  6518. rc = 0;
  6519. break;
  6520. default:
  6521. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6522. __func__, ctx_cmd);
  6523. break;
  6524. }
  6525. return rc;
  6526. }
  6527. /**
  6528. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6529. * @vport: Pointer to virtual port.
  6530. * @tgt_id: SCSI ID of the target.
  6531. * @lun_id: LUN ID of the scsi device.
  6532. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6533. *
  6534. * This function returns number of FCP commands pending for the vport.
  6535. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6536. * commands pending on the vport associated with SCSI device specified
  6537. * by tgt_id and lun_id parameters.
  6538. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6539. * commands pending on the vport associated with SCSI target specified
  6540. * by tgt_id parameter.
  6541. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6542. * commands pending on the vport.
  6543. * This function returns the number of iocbs which satisfy the filter.
  6544. * This function is called without any lock held.
  6545. **/
  6546. int
  6547. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6548. lpfc_ctx_cmd ctx_cmd)
  6549. {
  6550. struct lpfc_hba *phba = vport->phba;
  6551. struct lpfc_iocbq *iocbq;
  6552. int sum, i;
  6553. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6554. iocbq = phba->sli.iocbq_lookup[i];
  6555. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6556. ctx_cmd) == 0)
  6557. sum++;
  6558. }
  6559. return sum;
  6560. }
  6561. /**
  6562. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6563. * @phba: Pointer to HBA context object
  6564. * @cmdiocb: Pointer to command iocb object.
  6565. * @rspiocb: Pointer to response iocb object.
  6566. *
  6567. * This function is called when an aborted FCP iocb completes. This
  6568. * function is called by the ring event handler with no lock held.
  6569. * This function frees the iocb.
  6570. **/
  6571. void
  6572. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6573. struct lpfc_iocbq *rspiocb)
  6574. {
  6575. lpfc_sli_release_iocbq(phba, cmdiocb);
  6576. return;
  6577. }
  6578. /**
  6579. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6580. * @vport: Pointer to virtual port.
  6581. * @pring: Pointer to driver SLI ring object.
  6582. * @tgt_id: SCSI ID of the target.
  6583. * @lun_id: LUN ID of the scsi device.
  6584. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6585. *
  6586. * This function sends an abort command for every SCSI command
  6587. * associated with the given virtual port pending on the ring
  6588. * filtered by lpfc_sli_validate_fcp_iocb function.
  6589. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6590. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6591. * parameters
  6592. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6593. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6594. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6595. * FCP iocbs associated with virtual port.
  6596. * This function returns number of iocbs it failed to abort.
  6597. * This function is called with no locks held.
  6598. **/
  6599. int
  6600. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6601. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6602. {
  6603. struct lpfc_hba *phba = vport->phba;
  6604. struct lpfc_iocbq *iocbq;
  6605. struct lpfc_iocbq *abtsiocb;
  6606. IOCB_t *cmd = NULL;
  6607. int errcnt = 0, ret_val = 0;
  6608. int i;
  6609. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6610. iocbq = phba->sli.iocbq_lookup[i];
  6611. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6612. abort_cmd) != 0)
  6613. continue;
  6614. /* issue ABTS for this IOCB based on iotag */
  6615. abtsiocb = lpfc_sli_get_iocbq(phba);
  6616. if (abtsiocb == NULL) {
  6617. errcnt++;
  6618. continue;
  6619. }
  6620. cmd = &iocbq->iocb;
  6621. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6622. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6623. if (phba->sli_rev == LPFC_SLI_REV4)
  6624. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6625. else
  6626. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6627. abtsiocb->iocb.ulpLe = 1;
  6628. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6629. abtsiocb->vport = phba->pport;
  6630. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6631. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6632. if (lpfc_is_link_up(phba))
  6633. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6634. else
  6635. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6636. /* Setup callback routine and issue the command. */
  6637. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6638. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6639. abtsiocb, 0);
  6640. if (ret_val == IOCB_ERROR) {
  6641. lpfc_sli_release_iocbq(phba, abtsiocb);
  6642. errcnt++;
  6643. continue;
  6644. }
  6645. }
  6646. return errcnt;
  6647. }
  6648. /**
  6649. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6650. * @phba: Pointer to HBA context object.
  6651. * @cmdiocbq: Pointer to command iocb.
  6652. * @rspiocbq: Pointer to response iocb.
  6653. *
  6654. * This function is the completion handler for iocbs issued using
  6655. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6656. * ring event handler function without any lock held. This function
  6657. * can be called from both worker thread context and interrupt
  6658. * context. This function also can be called from other thread which
  6659. * cleans up the SLI layer objects.
  6660. * This function copy the contents of the response iocb to the
  6661. * response iocb memory object provided by the caller of
  6662. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6663. * sleeps for the iocb completion.
  6664. **/
  6665. static void
  6666. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6667. struct lpfc_iocbq *cmdiocbq,
  6668. struct lpfc_iocbq *rspiocbq)
  6669. {
  6670. wait_queue_head_t *pdone_q;
  6671. unsigned long iflags;
  6672. spin_lock_irqsave(&phba->hbalock, iflags);
  6673. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6674. if (cmdiocbq->context2 && rspiocbq)
  6675. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6676. &rspiocbq->iocb, sizeof(IOCB_t));
  6677. pdone_q = cmdiocbq->context_un.wait_queue;
  6678. if (pdone_q)
  6679. wake_up(pdone_q);
  6680. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6681. return;
  6682. }
  6683. /**
  6684. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6685. * @phba: Pointer to HBA context object..
  6686. * @piocbq: Pointer to command iocb.
  6687. * @flag: Flag to test.
  6688. *
  6689. * This routine grabs the hbalock and then test the iocb_flag to
  6690. * see if the passed in flag is set.
  6691. * Returns:
  6692. * 1 if flag is set.
  6693. * 0 if flag is not set.
  6694. **/
  6695. static int
  6696. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6697. struct lpfc_iocbq *piocbq, uint32_t flag)
  6698. {
  6699. unsigned long iflags;
  6700. int ret;
  6701. spin_lock_irqsave(&phba->hbalock, iflags);
  6702. ret = piocbq->iocb_flag & flag;
  6703. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6704. return ret;
  6705. }
  6706. /**
  6707. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6708. * @phba: Pointer to HBA context object..
  6709. * @pring: Pointer to sli ring.
  6710. * @piocb: Pointer to command iocb.
  6711. * @prspiocbq: Pointer to response iocb.
  6712. * @timeout: Timeout in number of seconds.
  6713. *
  6714. * This function issues the iocb to firmware and waits for the
  6715. * iocb to complete. If the iocb command is not
  6716. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6717. * Caller should not free the iocb resources if this function
  6718. * returns IOCB_TIMEDOUT.
  6719. * The function waits for the iocb completion using an
  6720. * non-interruptible wait.
  6721. * This function will sleep while waiting for iocb completion.
  6722. * So, this function should not be called from any context which
  6723. * does not allow sleeping. Due to the same reason, this function
  6724. * cannot be called with interrupt disabled.
  6725. * This function assumes that the iocb completions occur while
  6726. * this function sleep. So, this function cannot be called from
  6727. * the thread which process iocb completion for this ring.
  6728. * This function clears the iocb_flag of the iocb object before
  6729. * issuing the iocb and the iocb completion handler sets this
  6730. * flag and wakes this thread when the iocb completes.
  6731. * The contents of the response iocb will be copied to prspiocbq
  6732. * by the completion handler when the command completes.
  6733. * This function returns IOCB_SUCCESS when success.
  6734. * This function is called with no lock held.
  6735. **/
  6736. int
  6737. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6738. uint32_t ring_number,
  6739. struct lpfc_iocbq *piocb,
  6740. struct lpfc_iocbq *prspiocbq,
  6741. uint32_t timeout)
  6742. {
  6743. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6744. long timeleft, timeout_req = 0;
  6745. int retval = IOCB_SUCCESS;
  6746. uint32_t creg_val;
  6747. /*
  6748. * If the caller has provided a response iocbq buffer, then context2
  6749. * is NULL or its an error.
  6750. */
  6751. if (prspiocbq) {
  6752. if (piocb->context2)
  6753. return IOCB_ERROR;
  6754. piocb->context2 = prspiocbq;
  6755. }
  6756. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6757. piocb->context_un.wait_queue = &done_q;
  6758. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6759. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6760. creg_val = readl(phba->HCregaddr);
  6761. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6762. writel(creg_val, phba->HCregaddr);
  6763. readl(phba->HCregaddr); /* flush */
  6764. }
  6765. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6766. if (retval == IOCB_SUCCESS) {
  6767. timeout_req = timeout * HZ;
  6768. timeleft = wait_event_timeout(done_q,
  6769. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6770. timeout_req);
  6771. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6772. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6773. "0331 IOCB wake signaled\n");
  6774. } else if (timeleft == 0) {
  6775. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6776. "0338 IOCB wait timeout error - no "
  6777. "wake response Data x%x\n", timeout);
  6778. retval = IOCB_TIMEDOUT;
  6779. } else {
  6780. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6781. "0330 IOCB wake NOT set, "
  6782. "Data x%x x%lx\n",
  6783. timeout, (timeleft / jiffies));
  6784. retval = IOCB_TIMEDOUT;
  6785. }
  6786. } else {
  6787. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6788. "0332 IOCB wait issue failed, Data x%x\n",
  6789. retval);
  6790. retval = IOCB_ERROR;
  6791. }
  6792. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6793. creg_val = readl(phba->HCregaddr);
  6794. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6795. writel(creg_val, phba->HCregaddr);
  6796. readl(phba->HCregaddr); /* flush */
  6797. }
  6798. if (prspiocbq)
  6799. piocb->context2 = NULL;
  6800. piocb->context_un.wait_queue = NULL;
  6801. piocb->iocb_cmpl = NULL;
  6802. return retval;
  6803. }
  6804. /**
  6805. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6806. * @phba: Pointer to HBA context object.
  6807. * @pmboxq: Pointer to driver mailbox object.
  6808. * @timeout: Timeout in number of seconds.
  6809. *
  6810. * This function issues the mailbox to firmware and waits for the
  6811. * mailbox command to complete. If the mailbox command is not
  6812. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6813. * The function waits for the mailbox completion using an
  6814. * interruptible wait. If the thread is woken up due to a
  6815. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6816. * should not free the mailbox resources, if this function returns
  6817. * MBX_TIMEOUT.
  6818. * This function will sleep while waiting for mailbox completion.
  6819. * So, this function should not be called from any context which
  6820. * does not allow sleeping. Due to the same reason, this function
  6821. * cannot be called with interrupt disabled.
  6822. * This function assumes that the mailbox completion occurs while
  6823. * this function sleep. So, this function cannot be called from
  6824. * the worker thread which processes mailbox completion.
  6825. * This function is called in the context of HBA management
  6826. * applications.
  6827. * This function returns MBX_SUCCESS when successful.
  6828. * This function is called with no lock held.
  6829. **/
  6830. int
  6831. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6832. uint32_t timeout)
  6833. {
  6834. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6835. int retval;
  6836. unsigned long flag;
  6837. /* The caller must leave context1 empty. */
  6838. if (pmboxq->context1)
  6839. return MBX_NOT_FINISHED;
  6840. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6841. /* setup wake call as IOCB callback */
  6842. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6843. /* setup context field to pass wait_queue pointer to wake function */
  6844. pmboxq->context1 = &done_q;
  6845. /* now issue the command */
  6846. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6847. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6848. wait_event_interruptible_timeout(done_q,
  6849. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6850. timeout * HZ);
  6851. spin_lock_irqsave(&phba->hbalock, flag);
  6852. pmboxq->context1 = NULL;
  6853. /*
  6854. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6855. * else do not free the resources.
  6856. */
  6857. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6858. retval = MBX_SUCCESS;
  6859. else {
  6860. retval = MBX_TIMEOUT;
  6861. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6862. }
  6863. spin_unlock_irqrestore(&phba->hbalock, flag);
  6864. }
  6865. return retval;
  6866. }
  6867. /**
  6868. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6869. * @phba: Pointer to HBA context.
  6870. *
  6871. * This function is called to shutdown the driver's mailbox sub-system.
  6872. * It first marks the mailbox sub-system is in a block state to prevent
  6873. * the asynchronous mailbox command from issued off the pending mailbox
  6874. * command queue. If the mailbox command sub-system shutdown is due to
  6875. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6876. * the mailbox sub-system flush routine to forcefully bring down the
  6877. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6878. * as with offline or HBA function reset), this routine will wait for the
  6879. * outstanding mailbox command to complete before invoking the mailbox
  6880. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6881. **/
  6882. void
  6883. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6884. {
  6885. struct lpfc_sli *psli = &phba->sli;
  6886. uint8_t actcmd = MBX_HEARTBEAT;
  6887. unsigned long timeout;
  6888. spin_lock_irq(&phba->hbalock);
  6889. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6890. spin_unlock_irq(&phba->hbalock);
  6891. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6892. spin_lock_irq(&phba->hbalock);
  6893. if (phba->sli.mbox_active)
  6894. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6895. spin_unlock_irq(&phba->hbalock);
  6896. /* Determine how long we might wait for the active mailbox
  6897. * command to be gracefully completed by firmware.
  6898. */
  6899. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6900. 1000) + jiffies;
  6901. while (phba->sli.mbox_active) {
  6902. /* Check active mailbox complete status every 2ms */
  6903. msleep(2);
  6904. if (time_after(jiffies, timeout))
  6905. /* Timeout, let the mailbox flush routine to
  6906. * forcefully release active mailbox command
  6907. */
  6908. break;
  6909. }
  6910. }
  6911. lpfc_sli_mbox_sys_flush(phba);
  6912. }
  6913. /**
  6914. * lpfc_sli_eratt_read - read sli-3 error attention events
  6915. * @phba: Pointer to HBA context.
  6916. *
  6917. * This function is called to read the SLI3 device error attention registers
  6918. * for possible error attention events. The caller must hold the hostlock
  6919. * with spin_lock_irq().
  6920. *
  6921. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6922. * Register and returns 0 otherwise.
  6923. **/
  6924. static int
  6925. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6926. {
  6927. uint32_t ha_copy;
  6928. /* Read chip Host Attention (HA) register */
  6929. ha_copy = readl(phba->HAregaddr);
  6930. if (ha_copy & HA_ERATT) {
  6931. /* Read host status register to retrieve error event */
  6932. lpfc_sli_read_hs(phba);
  6933. /* Check if there is a deferred error condition is active */
  6934. if ((HS_FFER1 & phba->work_hs) &&
  6935. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6936. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6937. phba->hba_flag |= DEFER_ERATT;
  6938. /* Clear all interrupt enable conditions */
  6939. writel(0, phba->HCregaddr);
  6940. readl(phba->HCregaddr);
  6941. }
  6942. /* Set the driver HA work bitmap */
  6943. phba->work_ha |= HA_ERATT;
  6944. /* Indicate polling handles this ERATT */
  6945. phba->hba_flag |= HBA_ERATT_HANDLED;
  6946. return 1;
  6947. }
  6948. return 0;
  6949. }
  6950. /**
  6951. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6952. * @phba: Pointer to HBA context.
  6953. *
  6954. * This function is called to read the SLI4 device error attention registers
  6955. * for possible error attention events. The caller must hold the hostlock
  6956. * with spin_lock_irq().
  6957. *
  6958. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6959. * Register and returns 0 otherwise.
  6960. **/
  6961. static int
  6962. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6963. {
  6964. uint32_t uerr_sta_hi, uerr_sta_lo;
  6965. /* For now, use the SLI4 device internal unrecoverable error
  6966. * registers for error attention. This can be changed later.
  6967. */
  6968. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  6969. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  6970. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  6971. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  6972. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6973. "1423 HBA Unrecoverable error: "
  6974. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  6975. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  6976. uerr_sta_lo, uerr_sta_hi,
  6977. phba->sli4_hba.ue_mask_lo,
  6978. phba->sli4_hba.ue_mask_hi);
  6979. phba->work_status[0] = uerr_sta_lo;
  6980. phba->work_status[1] = uerr_sta_hi;
  6981. /* Set the driver HA work bitmap */
  6982. phba->work_ha |= HA_ERATT;
  6983. /* Indicate polling handles this ERATT */
  6984. phba->hba_flag |= HBA_ERATT_HANDLED;
  6985. return 1;
  6986. }
  6987. return 0;
  6988. }
  6989. /**
  6990. * lpfc_sli_check_eratt - check error attention events
  6991. * @phba: Pointer to HBA context.
  6992. *
  6993. * This function is called from timer soft interrupt context to check HBA's
  6994. * error attention register bit for error attention events.
  6995. *
  6996. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6997. * Register and returns 0 otherwise.
  6998. **/
  6999. int
  7000. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7001. {
  7002. uint32_t ha_copy;
  7003. /* If somebody is waiting to handle an eratt, don't process it
  7004. * here. The brdkill function will do this.
  7005. */
  7006. if (phba->link_flag & LS_IGNORE_ERATT)
  7007. return 0;
  7008. /* Check if interrupt handler handles this ERATT */
  7009. spin_lock_irq(&phba->hbalock);
  7010. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7011. /* Interrupt handler has handled ERATT */
  7012. spin_unlock_irq(&phba->hbalock);
  7013. return 0;
  7014. }
  7015. /*
  7016. * If there is deferred error attention, do not check for error
  7017. * attention
  7018. */
  7019. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7020. spin_unlock_irq(&phba->hbalock);
  7021. return 0;
  7022. }
  7023. /* If PCI channel is offline, don't process it */
  7024. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7025. spin_unlock_irq(&phba->hbalock);
  7026. return 0;
  7027. }
  7028. switch (phba->sli_rev) {
  7029. case LPFC_SLI_REV2:
  7030. case LPFC_SLI_REV3:
  7031. /* Read chip Host Attention (HA) register */
  7032. ha_copy = lpfc_sli_eratt_read(phba);
  7033. break;
  7034. case LPFC_SLI_REV4:
  7035. /* Read devcie Uncoverable Error (UERR) registers */
  7036. ha_copy = lpfc_sli4_eratt_read(phba);
  7037. break;
  7038. default:
  7039. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7040. "0299 Invalid SLI revision (%d)\n",
  7041. phba->sli_rev);
  7042. ha_copy = 0;
  7043. break;
  7044. }
  7045. spin_unlock_irq(&phba->hbalock);
  7046. return ha_copy;
  7047. }
  7048. /**
  7049. * lpfc_intr_state_check - Check device state for interrupt handling
  7050. * @phba: Pointer to HBA context.
  7051. *
  7052. * This inline routine checks whether a device or its PCI slot is in a state
  7053. * that the interrupt should be handled.
  7054. *
  7055. * This function returns 0 if the device or the PCI slot is in a state that
  7056. * interrupt should be handled, otherwise -EIO.
  7057. */
  7058. static inline int
  7059. lpfc_intr_state_check(struct lpfc_hba *phba)
  7060. {
  7061. /* If the pci channel is offline, ignore all the interrupts */
  7062. if (unlikely(pci_channel_offline(phba->pcidev)))
  7063. return -EIO;
  7064. /* Update device level interrupt statistics */
  7065. phba->sli.slistat.sli_intr++;
  7066. /* Ignore all interrupts during initialization. */
  7067. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7068. return -EIO;
  7069. return 0;
  7070. }
  7071. /**
  7072. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7073. * @irq: Interrupt number.
  7074. * @dev_id: The device context pointer.
  7075. *
  7076. * This function is directly called from the PCI layer as an interrupt
  7077. * service routine when device with SLI-3 interface spec is enabled with
  7078. * MSI-X multi-message interrupt mode and there are slow-path events in
  7079. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7080. * interrupt mode, this function is called as part of the device-level
  7081. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7082. * is undergoing initialization, the interrupt handler will not process
  7083. * the interrupt. The link attention and ELS ring attention events are
  7084. * handled by the worker thread. The interrupt handler signals the worker
  7085. * thread and returns for these events. This function is called without
  7086. * any lock held. It gets the hbalock to access and update SLI data
  7087. * structures.
  7088. *
  7089. * This function returns IRQ_HANDLED when interrupt is handled else it
  7090. * returns IRQ_NONE.
  7091. **/
  7092. irqreturn_t
  7093. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7094. {
  7095. struct lpfc_hba *phba;
  7096. uint32_t ha_copy, hc_copy;
  7097. uint32_t work_ha_copy;
  7098. unsigned long status;
  7099. unsigned long iflag;
  7100. uint32_t control;
  7101. MAILBOX_t *mbox, *pmbox;
  7102. struct lpfc_vport *vport;
  7103. struct lpfc_nodelist *ndlp;
  7104. struct lpfc_dmabuf *mp;
  7105. LPFC_MBOXQ_t *pmb;
  7106. int rc;
  7107. /*
  7108. * Get the driver's phba structure from the dev_id and
  7109. * assume the HBA is not interrupting.
  7110. */
  7111. phba = (struct lpfc_hba *)dev_id;
  7112. if (unlikely(!phba))
  7113. return IRQ_NONE;
  7114. /*
  7115. * Stuff needs to be attented to when this function is invoked as an
  7116. * individual interrupt handler in MSI-X multi-message interrupt mode
  7117. */
  7118. if (phba->intr_type == MSIX) {
  7119. /* Check device state for handling interrupt */
  7120. if (lpfc_intr_state_check(phba))
  7121. return IRQ_NONE;
  7122. /* Need to read HA REG for slow-path events */
  7123. spin_lock_irqsave(&phba->hbalock, iflag);
  7124. ha_copy = readl(phba->HAregaddr);
  7125. /* If somebody is waiting to handle an eratt don't process it
  7126. * here. The brdkill function will do this.
  7127. */
  7128. if (phba->link_flag & LS_IGNORE_ERATT)
  7129. ha_copy &= ~HA_ERATT;
  7130. /* Check the need for handling ERATT in interrupt handler */
  7131. if (ha_copy & HA_ERATT) {
  7132. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7133. /* ERATT polling has handled ERATT */
  7134. ha_copy &= ~HA_ERATT;
  7135. else
  7136. /* Indicate interrupt handler handles ERATT */
  7137. phba->hba_flag |= HBA_ERATT_HANDLED;
  7138. }
  7139. /*
  7140. * If there is deferred error attention, do not check for any
  7141. * interrupt.
  7142. */
  7143. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7144. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7145. return IRQ_NONE;
  7146. }
  7147. /* Clear up only attention source related to slow-path */
  7148. hc_copy = readl(phba->HCregaddr);
  7149. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7150. HC_LAINT_ENA | HC_ERINT_ENA),
  7151. phba->HCregaddr);
  7152. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7153. phba->HAregaddr);
  7154. writel(hc_copy, phba->HCregaddr);
  7155. readl(phba->HAregaddr); /* flush */
  7156. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7157. } else
  7158. ha_copy = phba->ha_copy;
  7159. work_ha_copy = ha_copy & phba->work_ha_mask;
  7160. if (work_ha_copy) {
  7161. if (work_ha_copy & HA_LATT) {
  7162. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7163. /*
  7164. * Turn off Link Attention interrupts
  7165. * until CLEAR_LA done
  7166. */
  7167. spin_lock_irqsave(&phba->hbalock, iflag);
  7168. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7169. control = readl(phba->HCregaddr);
  7170. control &= ~HC_LAINT_ENA;
  7171. writel(control, phba->HCregaddr);
  7172. readl(phba->HCregaddr); /* flush */
  7173. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7174. }
  7175. else
  7176. work_ha_copy &= ~HA_LATT;
  7177. }
  7178. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7179. /*
  7180. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7181. * the only slow ring.
  7182. */
  7183. status = (work_ha_copy &
  7184. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7185. status >>= (4*LPFC_ELS_RING);
  7186. if (status & HA_RXMASK) {
  7187. spin_lock_irqsave(&phba->hbalock, iflag);
  7188. control = readl(phba->HCregaddr);
  7189. lpfc_debugfs_slow_ring_trc(phba,
  7190. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7191. control, status,
  7192. (uint32_t)phba->sli.slistat.sli_intr);
  7193. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7194. lpfc_debugfs_slow_ring_trc(phba,
  7195. "ISR Disable ring:"
  7196. "pwork:x%x hawork:x%x wait:x%x",
  7197. phba->work_ha, work_ha_copy,
  7198. (uint32_t)((unsigned long)
  7199. &phba->work_waitq));
  7200. control &=
  7201. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7202. writel(control, phba->HCregaddr);
  7203. readl(phba->HCregaddr); /* flush */
  7204. }
  7205. else {
  7206. lpfc_debugfs_slow_ring_trc(phba,
  7207. "ISR slow ring: pwork:"
  7208. "x%x hawork:x%x wait:x%x",
  7209. phba->work_ha, work_ha_copy,
  7210. (uint32_t)((unsigned long)
  7211. &phba->work_waitq));
  7212. }
  7213. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7214. }
  7215. }
  7216. spin_lock_irqsave(&phba->hbalock, iflag);
  7217. if (work_ha_copy & HA_ERATT) {
  7218. lpfc_sli_read_hs(phba);
  7219. /*
  7220. * Check if there is a deferred error condition
  7221. * is active
  7222. */
  7223. if ((HS_FFER1 & phba->work_hs) &&
  7224. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7225. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7226. phba->hba_flag |= DEFER_ERATT;
  7227. /* Clear all interrupt enable conditions */
  7228. writel(0, phba->HCregaddr);
  7229. readl(phba->HCregaddr);
  7230. }
  7231. }
  7232. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7233. pmb = phba->sli.mbox_active;
  7234. pmbox = &pmb->u.mb;
  7235. mbox = phba->mbox;
  7236. vport = pmb->vport;
  7237. /* First check out the status word */
  7238. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7239. if (pmbox->mbxOwner != OWN_HOST) {
  7240. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7241. /*
  7242. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7243. * mbxStatus <status>
  7244. */
  7245. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7246. LOG_SLI,
  7247. "(%d):0304 Stray Mailbox "
  7248. "Interrupt mbxCommand x%x "
  7249. "mbxStatus x%x\n",
  7250. (vport ? vport->vpi : 0),
  7251. pmbox->mbxCommand,
  7252. pmbox->mbxStatus);
  7253. /* clear mailbox attention bit */
  7254. work_ha_copy &= ~HA_MBATT;
  7255. } else {
  7256. phba->sli.mbox_active = NULL;
  7257. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7258. phba->last_completion_time = jiffies;
  7259. del_timer(&phba->sli.mbox_tmo);
  7260. if (pmb->mbox_cmpl) {
  7261. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7262. MAILBOX_CMD_SIZE);
  7263. }
  7264. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7265. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7266. lpfc_debugfs_disc_trc(vport,
  7267. LPFC_DISC_TRC_MBOX_VPORT,
  7268. "MBOX dflt rpi: : "
  7269. "status:x%x rpi:x%x",
  7270. (uint32_t)pmbox->mbxStatus,
  7271. pmbox->un.varWords[0], 0);
  7272. if (!pmbox->mbxStatus) {
  7273. mp = (struct lpfc_dmabuf *)
  7274. (pmb->context1);
  7275. ndlp = (struct lpfc_nodelist *)
  7276. pmb->context2;
  7277. /* Reg_LOGIN of dflt RPI was
  7278. * successful. new lets get
  7279. * rid of the RPI using the
  7280. * same mbox buffer.
  7281. */
  7282. lpfc_unreg_login(phba,
  7283. vport->vpi,
  7284. pmbox->un.varWords[0],
  7285. pmb);
  7286. pmb->mbox_cmpl =
  7287. lpfc_mbx_cmpl_dflt_rpi;
  7288. pmb->context1 = mp;
  7289. pmb->context2 = ndlp;
  7290. pmb->vport = vport;
  7291. rc = lpfc_sli_issue_mbox(phba,
  7292. pmb,
  7293. MBX_NOWAIT);
  7294. if (rc != MBX_BUSY)
  7295. lpfc_printf_log(phba,
  7296. KERN_ERR,
  7297. LOG_MBOX | LOG_SLI,
  7298. "0350 rc should have"
  7299. "been MBX_BUSY\n");
  7300. if (rc != MBX_NOT_FINISHED)
  7301. goto send_current_mbox;
  7302. }
  7303. }
  7304. spin_lock_irqsave(
  7305. &phba->pport->work_port_lock,
  7306. iflag);
  7307. phba->pport->work_port_events &=
  7308. ~WORKER_MBOX_TMO;
  7309. spin_unlock_irqrestore(
  7310. &phba->pport->work_port_lock,
  7311. iflag);
  7312. lpfc_mbox_cmpl_put(phba, pmb);
  7313. }
  7314. } else
  7315. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7316. if ((work_ha_copy & HA_MBATT) &&
  7317. (phba->sli.mbox_active == NULL)) {
  7318. send_current_mbox:
  7319. /* Process next mailbox command if there is one */
  7320. do {
  7321. rc = lpfc_sli_issue_mbox(phba, NULL,
  7322. MBX_NOWAIT);
  7323. } while (rc == MBX_NOT_FINISHED);
  7324. if (rc != MBX_SUCCESS)
  7325. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7326. LOG_SLI, "0349 rc should be "
  7327. "MBX_SUCCESS\n");
  7328. }
  7329. spin_lock_irqsave(&phba->hbalock, iflag);
  7330. phba->work_ha |= work_ha_copy;
  7331. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7332. lpfc_worker_wake_up(phba);
  7333. }
  7334. return IRQ_HANDLED;
  7335. } /* lpfc_sli_sp_intr_handler */
  7336. /**
  7337. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7338. * @irq: Interrupt number.
  7339. * @dev_id: The device context pointer.
  7340. *
  7341. * This function is directly called from the PCI layer as an interrupt
  7342. * service routine when device with SLI-3 interface spec is enabled with
  7343. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7344. * ring event in the HBA. However, when the device is enabled with either
  7345. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7346. * device-level interrupt handler. When the PCI slot is in error recovery
  7347. * or the HBA is undergoing initialization, the interrupt handler will not
  7348. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7349. * the intrrupt context. This function is called without any lock held.
  7350. * It gets the hbalock to access and update SLI data structures.
  7351. *
  7352. * This function returns IRQ_HANDLED when interrupt is handled else it
  7353. * returns IRQ_NONE.
  7354. **/
  7355. irqreturn_t
  7356. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7357. {
  7358. struct lpfc_hba *phba;
  7359. uint32_t ha_copy;
  7360. unsigned long status;
  7361. unsigned long iflag;
  7362. /* Get the driver's phba structure from the dev_id and
  7363. * assume the HBA is not interrupting.
  7364. */
  7365. phba = (struct lpfc_hba *) dev_id;
  7366. if (unlikely(!phba))
  7367. return IRQ_NONE;
  7368. /*
  7369. * Stuff needs to be attented to when this function is invoked as an
  7370. * individual interrupt handler in MSI-X multi-message interrupt mode
  7371. */
  7372. if (phba->intr_type == MSIX) {
  7373. /* Check device state for handling interrupt */
  7374. if (lpfc_intr_state_check(phba))
  7375. return IRQ_NONE;
  7376. /* Need to read HA REG for FCP ring and other ring events */
  7377. ha_copy = readl(phba->HAregaddr);
  7378. /* Clear up only attention source related to fast-path */
  7379. spin_lock_irqsave(&phba->hbalock, iflag);
  7380. /*
  7381. * If there is deferred error attention, do not check for
  7382. * any interrupt.
  7383. */
  7384. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7385. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7386. return IRQ_NONE;
  7387. }
  7388. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7389. phba->HAregaddr);
  7390. readl(phba->HAregaddr); /* flush */
  7391. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7392. } else
  7393. ha_copy = phba->ha_copy;
  7394. /*
  7395. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7396. */
  7397. ha_copy &= ~(phba->work_ha_mask);
  7398. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7399. status >>= (4*LPFC_FCP_RING);
  7400. if (status & HA_RXMASK)
  7401. lpfc_sli_handle_fast_ring_event(phba,
  7402. &phba->sli.ring[LPFC_FCP_RING],
  7403. status);
  7404. if (phba->cfg_multi_ring_support == 2) {
  7405. /*
  7406. * Process all events on extra ring. Take the optimized path
  7407. * for extra ring IO.
  7408. */
  7409. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7410. status >>= (4*LPFC_EXTRA_RING);
  7411. if (status & HA_RXMASK) {
  7412. lpfc_sli_handle_fast_ring_event(phba,
  7413. &phba->sli.ring[LPFC_EXTRA_RING],
  7414. status);
  7415. }
  7416. }
  7417. return IRQ_HANDLED;
  7418. } /* lpfc_sli_fp_intr_handler */
  7419. /**
  7420. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7421. * @irq: Interrupt number.
  7422. * @dev_id: The device context pointer.
  7423. *
  7424. * This function is the HBA device-level interrupt handler to device with
  7425. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7426. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7427. * requires driver attention. This function invokes the slow-path interrupt
  7428. * attention handling function and fast-path interrupt attention handling
  7429. * function in turn to process the relevant HBA attention events. This
  7430. * function is called without any lock held. It gets the hbalock to access
  7431. * and update SLI data structures.
  7432. *
  7433. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7434. * returns IRQ_NONE.
  7435. **/
  7436. irqreturn_t
  7437. lpfc_sli_intr_handler(int irq, void *dev_id)
  7438. {
  7439. struct lpfc_hba *phba;
  7440. irqreturn_t sp_irq_rc, fp_irq_rc;
  7441. unsigned long status1, status2;
  7442. uint32_t hc_copy;
  7443. /*
  7444. * Get the driver's phba structure from the dev_id and
  7445. * assume the HBA is not interrupting.
  7446. */
  7447. phba = (struct lpfc_hba *) dev_id;
  7448. if (unlikely(!phba))
  7449. return IRQ_NONE;
  7450. /* Check device state for handling interrupt */
  7451. if (lpfc_intr_state_check(phba))
  7452. return IRQ_NONE;
  7453. spin_lock(&phba->hbalock);
  7454. phba->ha_copy = readl(phba->HAregaddr);
  7455. if (unlikely(!phba->ha_copy)) {
  7456. spin_unlock(&phba->hbalock);
  7457. return IRQ_NONE;
  7458. } else if (phba->ha_copy & HA_ERATT) {
  7459. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7460. /* ERATT polling has handled ERATT */
  7461. phba->ha_copy &= ~HA_ERATT;
  7462. else
  7463. /* Indicate interrupt handler handles ERATT */
  7464. phba->hba_flag |= HBA_ERATT_HANDLED;
  7465. }
  7466. /*
  7467. * If there is deferred error attention, do not check for any interrupt.
  7468. */
  7469. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7470. spin_unlock_irq(&phba->hbalock);
  7471. return IRQ_NONE;
  7472. }
  7473. /* Clear attention sources except link and error attentions */
  7474. hc_copy = readl(phba->HCregaddr);
  7475. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7476. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7477. phba->HCregaddr);
  7478. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7479. writel(hc_copy, phba->HCregaddr);
  7480. readl(phba->HAregaddr); /* flush */
  7481. spin_unlock(&phba->hbalock);
  7482. /*
  7483. * Invokes slow-path host attention interrupt handling as appropriate.
  7484. */
  7485. /* status of events with mailbox and link attention */
  7486. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7487. /* status of events with ELS ring */
  7488. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7489. status2 >>= (4*LPFC_ELS_RING);
  7490. if (status1 || (status2 & HA_RXMASK))
  7491. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7492. else
  7493. sp_irq_rc = IRQ_NONE;
  7494. /*
  7495. * Invoke fast-path host attention interrupt handling as appropriate.
  7496. */
  7497. /* status of events with FCP ring */
  7498. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7499. status1 >>= (4*LPFC_FCP_RING);
  7500. /* status of events with extra ring */
  7501. if (phba->cfg_multi_ring_support == 2) {
  7502. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7503. status2 >>= (4*LPFC_EXTRA_RING);
  7504. } else
  7505. status2 = 0;
  7506. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7507. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7508. else
  7509. fp_irq_rc = IRQ_NONE;
  7510. /* Return device-level interrupt handling status */
  7511. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7512. } /* lpfc_sli_intr_handler */
  7513. /**
  7514. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7515. * @phba: pointer to lpfc hba data structure.
  7516. *
  7517. * This routine is invoked by the worker thread to process all the pending
  7518. * SLI4 FCP abort XRI events.
  7519. **/
  7520. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7521. {
  7522. struct lpfc_cq_event *cq_event;
  7523. /* First, declare the fcp xri abort event has been handled */
  7524. spin_lock_irq(&phba->hbalock);
  7525. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7526. spin_unlock_irq(&phba->hbalock);
  7527. /* Now, handle all the fcp xri abort events */
  7528. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7529. /* Get the first event from the head of the event queue */
  7530. spin_lock_irq(&phba->hbalock);
  7531. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7532. cq_event, struct lpfc_cq_event, list);
  7533. spin_unlock_irq(&phba->hbalock);
  7534. /* Notify aborted XRI for FCP work queue */
  7535. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7536. /* Free the event processed back to the free pool */
  7537. lpfc_sli4_cq_event_release(phba, cq_event);
  7538. }
  7539. }
  7540. /**
  7541. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7542. * @phba: pointer to lpfc hba data structure.
  7543. *
  7544. * This routine is invoked by the worker thread to process all the pending
  7545. * SLI4 els abort xri events.
  7546. **/
  7547. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7548. {
  7549. struct lpfc_cq_event *cq_event;
  7550. /* First, declare the els xri abort event has been handled */
  7551. spin_lock_irq(&phba->hbalock);
  7552. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7553. spin_unlock_irq(&phba->hbalock);
  7554. /* Now, handle all the els xri abort events */
  7555. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7556. /* Get the first event from the head of the event queue */
  7557. spin_lock_irq(&phba->hbalock);
  7558. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7559. cq_event, struct lpfc_cq_event, list);
  7560. spin_unlock_irq(&phba->hbalock);
  7561. /* Notify aborted XRI for ELS work queue */
  7562. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7563. /* Free the event processed back to the free pool */
  7564. lpfc_sli4_cq_event_release(phba, cq_event);
  7565. }
  7566. }
  7567. static void
  7568. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7569. struct lpfc_iocbq *pIocbOut,
  7570. struct lpfc_wcqe_complete *wcqe)
  7571. {
  7572. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7573. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7574. sizeof(struct lpfc_iocbq) - offset);
  7575. /* Map WCQE parameters into irspiocb parameters */
  7576. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7577. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7578. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7579. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7580. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7581. wcqe->total_data_placed;
  7582. else
  7583. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7584. else
  7585. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7586. }
  7587. /**
  7588. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7589. * @phba: Pointer to HBA context object.
  7590. * @wcqe: Pointer to work-queue completion queue entry.
  7591. *
  7592. * This routine handles an ELS work-queue completion event and construct
  7593. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7594. * discovery engine to handle.
  7595. *
  7596. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7597. **/
  7598. static struct lpfc_iocbq *
  7599. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7600. struct lpfc_iocbq *irspiocbq)
  7601. {
  7602. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7603. struct lpfc_iocbq *cmdiocbq;
  7604. struct lpfc_wcqe_complete *wcqe;
  7605. unsigned long iflags;
  7606. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7607. spin_lock_irqsave(&phba->hbalock, iflags);
  7608. pring->stats.iocb_event++;
  7609. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7610. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7611. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7612. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7613. if (unlikely(!cmdiocbq)) {
  7614. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7615. "0386 ELS complete with no corresponding "
  7616. "cmdiocb: iotag (%d)\n",
  7617. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7618. lpfc_sli_release_iocbq(phba, irspiocbq);
  7619. return NULL;
  7620. }
  7621. /* Fake the irspiocbq and copy necessary response information */
  7622. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7623. return irspiocbq;
  7624. }
  7625. /**
  7626. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7627. * @phba: Pointer to HBA context object.
  7628. * @cqe: Pointer to mailbox completion queue entry.
  7629. *
  7630. * This routine process a mailbox completion queue entry with asynchrous
  7631. * event.
  7632. *
  7633. * Return: true if work posted to worker thread, otherwise false.
  7634. **/
  7635. static bool
  7636. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7637. {
  7638. struct lpfc_cq_event *cq_event;
  7639. unsigned long iflags;
  7640. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7641. "0392 Async Event: word0:x%x, word1:x%x, "
  7642. "word2:x%x, word3:x%x\n", mcqe->word0,
  7643. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7644. /* Allocate a new internal CQ_EVENT entry */
  7645. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7646. if (!cq_event) {
  7647. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7648. "0394 Failed to allocate CQ_EVENT entry\n");
  7649. return false;
  7650. }
  7651. /* Move the CQE into an asynchronous event entry */
  7652. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7653. spin_lock_irqsave(&phba->hbalock, iflags);
  7654. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7655. /* Set the async event flag */
  7656. phba->hba_flag |= ASYNC_EVENT;
  7657. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7658. return true;
  7659. }
  7660. /**
  7661. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7662. * @phba: Pointer to HBA context object.
  7663. * @cqe: Pointer to mailbox completion queue entry.
  7664. *
  7665. * This routine process a mailbox completion queue entry with mailbox
  7666. * completion event.
  7667. *
  7668. * Return: true if work posted to worker thread, otherwise false.
  7669. **/
  7670. static bool
  7671. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7672. {
  7673. uint32_t mcqe_status;
  7674. MAILBOX_t *mbox, *pmbox;
  7675. struct lpfc_mqe *mqe;
  7676. struct lpfc_vport *vport;
  7677. struct lpfc_nodelist *ndlp;
  7678. struct lpfc_dmabuf *mp;
  7679. unsigned long iflags;
  7680. LPFC_MBOXQ_t *pmb;
  7681. bool workposted = false;
  7682. int rc;
  7683. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7684. if (!bf_get(lpfc_trailer_completed, mcqe))
  7685. goto out_no_mqe_complete;
  7686. /* Get the reference to the active mbox command */
  7687. spin_lock_irqsave(&phba->hbalock, iflags);
  7688. pmb = phba->sli.mbox_active;
  7689. if (unlikely(!pmb)) {
  7690. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7691. "1832 No pending MBOX command to handle\n");
  7692. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7693. goto out_no_mqe_complete;
  7694. }
  7695. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7696. mqe = &pmb->u.mqe;
  7697. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7698. mbox = phba->mbox;
  7699. vport = pmb->vport;
  7700. /* Reset heartbeat timer */
  7701. phba->last_completion_time = jiffies;
  7702. del_timer(&phba->sli.mbox_tmo);
  7703. /* Move mbox data to caller's mailbox region, do endian swapping */
  7704. if (pmb->mbox_cmpl && mbox)
  7705. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7706. /* Set the mailbox status with SLI4 range 0x4000 */
  7707. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7708. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7709. bf_set(lpfc_mqe_status, mqe,
  7710. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7711. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7712. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7713. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7714. "MBOX dflt rpi: status:x%x rpi:x%x",
  7715. mcqe_status,
  7716. pmbox->un.varWords[0], 0);
  7717. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7718. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7719. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7720. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7721. * RID of the PPI using the same mbox buffer.
  7722. */
  7723. lpfc_unreg_login(phba, vport->vpi,
  7724. pmbox->un.varWords[0], pmb);
  7725. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7726. pmb->context1 = mp;
  7727. pmb->context2 = ndlp;
  7728. pmb->vport = vport;
  7729. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7730. if (rc != MBX_BUSY)
  7731. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7732. LOG_SLI, "0385 rc should "
  7733. "have been MBX_BUSY\n");
  7734. if (rc != MBX_NOT_FINISHED)
  7735. goto send_current_mbox;
  7736. }
  7737. }
  7738. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7739. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7740. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7741. /* There is mailbox completion work to do */
  7742. spin_lock_irqsave(&phba->hbalock, iflags);
  7743. __lpfc_mbox_cmpl_put(phba, pmb);
  7744. phba->work_ha |= HA_MBATT;
  7745. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7746. workposted = true;
  7747. send_current_mbox:
  7748. spin_lock_irqsave(&phba->hbalock, iflags);
  7749. /* Release the mailbox command posting token */
  7750. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7751. /* Setting active mailbox pointer need to be in sync to flag clear */
  7752. phba->sli.mbox_active = NULL;
  7753. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7754. /* Wake up worker thread to post the next pending mailbox command */
  7755. lpfc_worker_wake_up(phba);
  7756. out_no_mqe_complete:
  7757. if (bf_get(lpfc_trailer_consumed, mcqe))
  7758. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7759. return workposted;
  7760. }
  7761. /**
  7762. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7763. * @phba: Pointer to HBA context object.
  7764. * @cqe: Pointer to mailbox completion queue entry.
  7765. *
  7766. * This routine process a mailbox completion queue entry, it invokes the
  7767. * proper mailbox complete handling or asynchrous event handling routine
  7768. * according to the MCQE's async bit.
  7769. *
  7770. * Return: true if work posted to worker thread, otherwise false.
  7771. **/
  7772. static bool
  7773. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7774. {
  7775. struct lpfc_mcqe mcqe;
  7776. bool workposted;
  7777. /* Copy the mailbox MCQE and convert endian order as needed */
  7778. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7779. /* Invoke the proper event handling routine */
  7780. if (!bf_get(lpfc_trailer_async, &mcqe))
  7781. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7782. else
  7783. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7784. return workposted;
  7785. }
  7786. /**
  7787. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7788. * @phba: Pointer to HBA context object.
  7789. * @wcqe: Pointer to work-queue completion queue entry.
  7790. *
  7791. * This routine handles an ELS work-queue completion event.
  7792. *
  7793. * Return: true if work posted to worker thread, otherwise false.
  7794. **/
  7795. static bool
  7796. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7797. struct lpfc_wcqe_complete *wcqe)
  7798. {
  7799. struct lpfc_iocbq *irspiocbq;
  7800. unsigned long iflags;
  7801. /* Get an irspiocbq for later ELS response processing use */
  7802. irspiocbq = lpfc_sli_get_iocbq(phba);
  7803. if (!irspiocbq) {
  7804. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7805. "0387 Failed to allocate an iocbq\n");
  7806. return false;
  7807. }
  7808. /* Save off the slow-path queue event for work thread to process */
  7809. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7810. spin_lock_irqsave(&phba->hbalock, iflags);
  7811. list_add_tail(&irspiocbq->cq_event.list,
  7812. &phba->sli4_hba.sp_queue_event);
  7813. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7814. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7815. return true;
  7816. }
  7817. /**
  7818. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7819. * @phba: Pointer to HBA context object.
  7820. * @wcqe: Pointer to work-queue completion queue entry.
  7821. *
  7822. * This routine handles slow-path WQ entry comsumed event by invoking the
  7823. * proper WQ release routine to the slow-path WQ.
  7824. **/
  7825. static void
  7826. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7827. struct lpfc_wcqe_release *wcqe)
  7828. {
  7829. /* Check for the slow-path ELS work queue */
  7830. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7831. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7832. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7833. else
  7834. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7835. "2579 Slow-path wqe consume event carries "
  7836. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7837. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7838. phba->sli4_hba.els_wq->queue_id);
  7839. }
  7840. /**
  7841. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7842. * @phba: Pointer to HBA context object.
  7843. * @cq: Pointer to a WQ completion queue.
  7844. * @wcqe: Pointer to work-queue completion queue entry.
  7845. *
  7846. * This routine handles an XRI abort event.
  7847. *
  7848. * Return: true if work posted to worker thread, otherwise false.
  7849. **/
  7850. static bool
  7851. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7852. struct lpfc_queue *cq,
  7853. struct sli4_wcqe_xri_aborted *wcqe)
  7854. {
  7855. bool workposted = false;
  7856. struct lpfc_cq_event *cq_event;
  7857. unsigned long iflags;
  7858. /* Allocate a new internal CQ_EVENT entry */
  7859. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7860. if (!cq_event) {
  7861. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7862. "0602 Failed to allocate CQ_EVENT entry\n");
  7863. return false;
  7864. }
  7865. /* Move the CQE into the proper xri abort event list */
  7866. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7867. switch (cq->subtype) {
  7868. case LPFC_FCP:
  7869. spin_lock_irqsave(&phba->hbalock, iflags);
  7870. list_add_tail(&cq_event->list,
  7871. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7872. /* Set the fcp xri abort event flag */
  7873. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7874. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7875. workposted = true;
  7876. break;
  7877. case LPFC_ELS:
  7878. spin_lock_irqsave(&phba->hbalock, iflags);
  7879. list_add_tail(&cq_event->list,
  7880. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7881. /* Set the els xri abort event flag */
  7882. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7883. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7884. workposted = true;
  7885. break;
  7886. default:
  7887. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7888. "0603 Invalid work queue CQE subtype (x%x)\n",
  7889. cq->subtype);
  7890. workposted = false;
  7891. break;
  7892. }
  7893. return workposted;
  7894. }
  7895. /**
  7896. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7897. * @phba: Pointer to HBA context object.
  7898. * @rcqe: Pointer to receive-queue completion queue entry.
  7899. *
  7900. * This routine process a receive-queue completion queue entry.
  7901. *
  7902. * Return: true if work posted to worker thread, otherwise false.
  7903. **/
  7904. static bool
  7905. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  7906. {
  7907. bool workposted = false;
  7908. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7909. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7910. struct hbq_dmabuf *dma_buf;
  7911. uint32_t status;
  7912. unsigned long iflags;
  7913. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  7914. goto out;
  7915. status = bf_get(lpfc_rcqe_status, rcqe);
  7916. switch (status) {
  7917. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  7918. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7919. "2537 Receive Frame Truncated!!\n");
  7920. case FC_STATUS_RQ_SUCCESS:
  7921. lpfc_sli4_rq_release(hrq, drq);
  7922. spin_lock_irqsave(&phba->hbalock, iflags);
  7923. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7924. if (!dma_buf) {
  7925. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7926. goto out;
  7927. }
  7928. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  7929. /* save off the frame for the word thread to process */
  7930. list_add_tail(&dma_buf->cq_event.list,
  7931. &phba->sli4_hba.sp_queue_event);
  7932. /* Frame received */
  7933. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7934. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7935. workposted = true;
  7936. break;
  7937. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7938. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7939. /* Post more buffers if possible */
  7940. spin_lock_irqsave(&phba->hbalock, iflags);
  7941. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7942. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7943. workposted = true;
  7944. break;
  7945. }
  7946. out:
  7947. return workposted;
  7948. }
  7949. /**
  7950. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  7951. * @phba: Pointer to HBA context object.
  7952. * @cq: Pointer to the completion queue.
  7953. * @wcqe: Pointer to a completion queue entry.
  7954. *
  7955. * This routine process a slow-path work-queue or recieve queue completion queue
  7956. * entry.
  7957. *
  7958. * Return: true if work posted to worker thread, otherwise false.
  7959. **/
  7960. static bool
  7961. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7962. struct lpfc_cqe *cqe)
  7963. {
  7964. struct lpfc_cqe cqevt;
  7965. bool workposted = false;
  7966. /* Copy the work queue CQE and convert endian order if needed */
  7967. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  7968. /* Check and process for different type of WCQE and dispatch */
  7969. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  7970. case CQE_CODE_COMPL_WQE:
  7971. /* Process the WQ/RQ complete event */
  7972. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7973. (struct lpfc_wcqe_complete *)&cqevt);
  7974. break;
  7975. case CQE_CODE_RELEASE_WQE:
  7976. /* Process the WQ release event */
  7977. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7978. (struct lpfc_wcqe_release *)&cqevt);
  7979. break;
  7980. case CQE_CODE_XRI_ABORTED:
  7981. /* Process the WQ XRI abort event */
  7982. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7983. (struct sli4_wcqe_xri_aborted *)&cqevt);
  7984. break;
  7985. case CQE_CODE_RECEIVE:
  7986. /* Process the RQ event */
  7987. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  7988. (struct lpfc_rcqe *)&cqevt);
  7989. break;
  7990. default:
  7991. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7992. "0388 Not a valid WCQE code: x%x\n",
  7993. bf_get(lpfc_cqe_code, &cqevt));
  7994. break;
  7995. }
  7996. return workposted;
  7997. }
  7998. /**
  7999. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8000. * @phba: Pointer to HBA context object.
  8001. * @eqe: Pointer to fast-path event queue entry.
  8002. *
  8003. * This routine process a event queue entry from the slow-path event queue.
  8004. * It will check the MajorCode and MinorCode to determine this is for a
  8005. * completion event on a completion queue, if not, an error shall be logged
  8006. * and just return. Otherwise, it will get to the corresponding completion
  8007. * queue and process all the entries on that completion queue, rearm the
  8008. * completion queue, and then return.
  8009. *
  8010. **/
  8011. static void
  8012. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8013. {
  8014. struct lpfc_queue *cq = NULL, *childq, *speq;
  8015. struct lpfc_cqe *cqe;
  8016. bool workposted = false;
  8017. int ecount = 0;
  8018. uint16_t cqid;
  8019. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  8020. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  8021. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8022. "0359 Not a valid slow-path completion "
  8023. "event: majorcode=x%x, minorcode=x%x\n",
  8024. bf_get(lpfc_eqe_major_code, eqe),
  8025. bf_get(lpfc_eqe_minor_code, eqe));
  8026. return;
  8027. }
  8028. /* Get the reference to the corresponding CQ */
  8029. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8030. /* Search for completion queue pointer matching this cqid */
  8031. speq = phba->sli4_hba.sp_eq;
  8032. list_for_each_entry(childq, &speq->child_list, list) {
  8033. if (childq->queue_id == cqid) {
  8034. cq = childq;
  8035. break;
  8036. }
  8037. }
  8038. if (unlikely(!cq)) {
  8039. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8040. "0365 Slow-path CQ identifier (%d) does "
  8041. "not exist\n", cqid);
  8042. return;
  8043. }
  8044. /* Process all the entries to the CQ */
  8045. switch (cq->type) {
  8046. case LPFC_MCQ:
  8047. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8048. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8049. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8050. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8051. }
  8052. break;
  8053. case LPFC_WCQ:
  8054. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8055. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8056. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8057. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8058. }
  8059. break;
  8060. default:
  8061. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8062. "0370 Invalid completion queue type (%d)\n",
  8063. cq->type);
  8064. return;
  8065. }
  8066. /* Catch the no cq entry condition, log an error */
  8067. if (unlikely(ecount == 0))
  8068. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8069. "0371 No entry from the CQ: identifier "
  8070. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8071. /* In any case, flash and re-arm the RCQ */
  8072. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8073. /* wake up worker thread if there are works to be done */
  8074. if (workposted)
  8075. lpfc_worker_wake_up(phba);
  8076. }
  8077. /**
  8078. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8079. * @eqe: Pointer to fast-path completion queue entry.
  8080. *
  8081. * This routine process a fast-path work queue completion entry from fast-path
  8082. * event queue for FCP command response completion.
  8083. **/
  8084. static void
  8085. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8086. struct lpfc_wcqe_complete *wcqe)
  8087. {
  8088. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8089. struct lpfc_iocbq *cmdiocbq;
  8090. struct lpfc_iocbq irspiocbq;
  8091. unsigned long iflags;
  8092. spin_lock_irqsave(&phba->hbalock, iflags);
  8093. pring->stats.iocb_event++;
  8094. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8095. /* Check for response status */
  8096. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8097. /* If resource errors reported from HBA, reduce queue
  8098. * depth of the SCSI device.
  8099. */
  8100. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8101. IOSTAT_LOCAL_REJECT) &&
  8102. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8103. phba->lpfc_rampdown_queue_depth(phba);
  8104. }
  8105. /* Log the error status */
  8106. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8107. "0373 FCP complete error: status=x%x, "
  8108. "hw_status=x%x, total_data_specified=%d, "
  8109. "parameter=x%x, word3=x%x\n",
  8110. bf_get(lpfc_wcqe_c_status, wcqe),
  8111. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8112. wcqe->total_data_placed, wcqe->parameter,
  8113. wcqe->word3);
  8114. }
  8115. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8116. spin_lock_irqsave(&phba->hbalock, iflags);
  8117. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8118. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8119. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8120. if (unlikely(!cmdiocbq)) {
  8121. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8122. "0374 FCP complete with no corresponding "
  8123. "cmdiocb: iotag (%d)\n",
  8124. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8125. return;
  8126. }
  8127. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8128. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8129. "0375 FCP cmdiocb not callback function "
  8130. "iotag: (%d)\n",
  8131. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8132. return;
  8133. }
  8134. /* Fake the irspiocb and copy necessary response information */
  8135. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  8136. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8137. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8138. }
  8139. /**
  8140. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8141. * @phba: Pointer to HBA context object.
  8142. * @cq: Pointer to completion queue.
  8143. * @wcqe: Pointer to work-queue completion queue entry.
  8144. *
  8145. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8146. * proper WQ release routine to the slow-path WQ.
  8147. **/
  8148. static void
  8149. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8150. struct lpfc_wcqe_release *wcqe)
  8151. {
  8152. struct lpfc_queue *childwq;
  8153. bool wqid_matched = false;
  8154. uint16_t fcp_wqid;
  8155. /* Check for fast-path FCP work queue release */
  8156. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8157. list_for_each_entry(childwq, &cq->child_list, list) {
  8158. if (childwq->queue_id == fcp_wqid) {
  8159. lpfc_sli4_wq_release(childwq,
  8160. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8161. wqid_matched = true;
  8162. break;
  8163. }
  8164. }
  8165. /* Report warning log message if no match found */
  8166. if (wqid_matched != true)
  8167. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8168. "2580 Fast-path wqe consume event carries "
  8169. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8170. }
  8171. /**
  8172. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8173. * @cq: Pointer to the completion queue.
  8174. * @eqe: Pointer to fast-path completion queue entry.
  8175. *
  8176. * This routine process a fast-path work queue completion entry from fast-path
  8177. * event queue for FCP command response completion.
  8178. **/
  8179. static int
  8180. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8181. struct lpfc_cqe *cqe)
  8182. {
  8183. struct lpfc_wcqe_release wcqe;
  8184. bool workposted = false;
  8185. /* Copy the work queue CQE and convert endian order if needed */
  8186. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8187. /* Check and process for different type of WCQE and dispatch */
  8188. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8189. case CQE_CODE_COMPL_WQE:
  8190. /* Process the WQ complete event */
  8191. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8192. (struct lpfc_wcqe_complete *)&wcqe);
  8193. break;
  8194. case CQE_CODE_RELEASE_WQE:
  8195. /* Process the WQ release event */
  8196. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8197. (struct lpfc_wcqe_release *)&wcqe);
  8198. break;
  8199. case CQE_CODE_XRI_ABORTED:
  8200. /* Process the WQ XRI abort event */
  8201. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8202. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8203. break;
  8204. default:
  8205. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8206. "0144 Not a valid WCQE code: x%x\n",
  8207. bf_get(lpfc_wcqe_c_code, &wcqe));
  8208. break;
  8209. }
  8210. return workposted;
  8211. }
  8212. /**
  8213. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8214. * @phba: Pointer to HBA context object.
  8215. * @eqe: Pointer to fast-path event queue entry.
  8216. *
  8217. * This routine process a event queue entry from the fast-path event queue.
  8218. * It will check the MajorCode and MinorCode to determine this is for a
  8219. * completion event on a completion queue, if not, an error shall be logged
  8220. * and just return. Otherwise, it will get to the corresponding completion
  8221. * queue and process all the entries on the completion queue, rearm the
  8222. * completion queue, and then return.
  8223. **/
  8224. static void
  8225. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8226. uint32_t fcp_cqidx)
  8227. {
  8228. struct lpfc_queue *cq;
  8229. struct lpfc_cqe *cqe;
  8230. bool workposted = false;
  8231. uint16_t cqid;
  8232. int ecount = 0;
  8233. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8234. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8235. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8236. "0366 Not a valid fast-path completion "
  8237. "event: majorcode=x%x, minorcode=x%x\n",
  8238. bf_get(lpfc_eqe_major_code, eqe),
  8239. bf_get(lpfc_eqe_minor_code, eqe));
  8240. return;
  8241. }
  8242. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8243. if (unlikely(!cq)) {
  8244. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8245. "0367 Fast-path completion queue does not "
  8246. "exist\n");
  8247. return;
  8248. }
  8249. /* Get the reference to the corresponding CQ */
  8250. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8251. if (unlikely(cqid != cq->queue_id)) {
  8252. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8253. "0368 Miss-matched fast-path completion "
  8254. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8255. cqid, cq->queue_id);
  8256. return;
  8257. }
  8258. /* Process all the entries to the CQ */
  8259. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8260. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8261. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8262. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8263. }
  8264. /* Catch the no cq entry condition */
  8265. if (unlikely(ecount == 0))
  8266. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8267. "0369 No entry from fast-path completion "
  8268. "queue fcpcqid=%d\n", cq->queue_id);
  8269. /* In any case, flash and re-arm the CQ */
  8270. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8271. /* wake up worker thread if there are works to be done */
  8272. if (workposted)
  8273. lpfc_worker_wake_up(phba);
  8274. }
  8275. static void
  8276. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8277. {
  8278. struct lpfc_eqe *eqe;
  8279. /* walk all the EQ entries and drop on the floor */
  8280. while ((eqe = lpfc_sli4_eq_get(eq)))
  8281. ;
  8282. /* Clear and re-arm the EQ */
  8283. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8284. }
  8285. /**
  8286. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8287. * @irq: Interrupt number.
  8288. * @dev_id: The device context pointer.
  8289. *
  8290. * This function is directly called from the PCI layer as an interrupt
  8291. * service routine when device with SLI-4 interface spec is enabled with
  8292. * MSI-X multi-message interrupt mode and there are slow-path events in
  8293. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8294. * interrupt mode, this function is called as part of the device-level
  8295. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8296. * undergoing initialization, the interrupt handler will not process the
  8297. * interrupt. The link attention and ELS ring attention events are handled
  8298. * by the worker thread. The interrupt handler signals the worker thread
  8299. * and returns for these events. This function is called without any lock
  8300. * held. It gets the hbalock to access and update SLI data structures.
  8301. *
  8302. * This function returns IRQ_HANDLED when interrupt is handled else it
  8303. * returns IRQ_NONE.
  8304. **/
  8305. irqreturn_t
  8306. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8307. {
  8308. struct lpfc_hba *phba;
  8309. struct lpfc_queue *speq;
  8310. struct lpfc_eqe *eqe;
  8311. unsigned long iflag;
  8312. int ecount = 0;
  8313. /*
  8314. * Get the driver's phba structure from the dev_id
  8315. */
  8316. phba = (struct lpfc_hba *)dev_id;
  8317. if (unlikely(!phba))
  8318. return IRQ_NONE;
  8319. /* Get to the EQ struct associated with this vector */
  8320. speq = phba->sli4_hba.sp_eq;
  8321. /* Check device state for handling interrupt */
  8322. if (unlikely(lpfc_intr_state_check(phba))) {
  8323. /* Check again for link_state with lock held */
  8324. spin_lock_irqsave(&phba->hbalock, iflag);
  8325. if (phba->link_state < LPFC_LINK_DOWN)
  8326. /* Flush, clear interrupt, and rearm the EQ */
  8327. lpfc_sli4_eq_flush(phba, speq);
  8328. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8329. return IRQ_NONE;
  8330. }
  8331. /*
  8332. * Process all the event on FCP slow-path EQ
  8333. */
  8334. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8335. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8336. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8337. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8338. }
  8339. /* Always clear and re-arm the slow-path EQ */
  8340. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8341. /* Catch the no cq entry condition */
  8342. if (unlikely(ecount == 0)) {
  8343. if (phba->intr_type == MSIX)
  8344. /* MSI-X treated interrupt served as no EQ share INT */
  8345. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8346. "0357 MSI-X interrupt with no EQE\n");
  8347. else
  8348. /* Non MSI-X treated on interrupt as EQ share INT */
  8349. return IRQ_NONE;
  8350. }
  8351. return IRQ_HANDLED;
  8352. } /* lpfc_sli4_sp_intr_handler */
  8353. /**
  8354. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8355. * @irq: Interrupt number.
  8356. * @dev_id: The device context pointer.
  8357. *
  8358. * This function is directly called from the PCI layer as an interrupt
  8359. * service routine when device with SLI-4 interface spec is enabled with
  8360. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8361. * ring event in the HBA. However, when the device is enabled with either
  8362. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8363. * device-level interrupt handler. When the PCI slot is in error recovery
  8364. * or the HBA is undergoing initialization, the interrupt handler will not
  8365. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8366. * the intrrupt context. This function is called without any lock held.
  8367. * It gets the hbalock to access and update SLI data structures. Note that,
  8368. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8369. * equal to that of FCP CQ index.
  8370. *
  8371. * This function returns IRQ_HANDLED when interrupt is handled else it
  8372. * returns IRQ_NONE.
  8373. **/
  8374. irqreturn_t
  8375. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8376. {
  8377. struct lpfc_hba *phba;
  8378. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8379. struct lpfc_queue *fpeq;
  8380. struct lpfc_eqe *eqe;
  8381. unsigned long iflag;
  8382. int ecount = 0;
  8383. uint32_t fcp_eqidx;
  8384. /* Get the driver's phba structure from the dev_id */
  8385. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8386. phba = fcp_eq_hdl->phba;
  8387. fcp_eqidx = fcp_eq_hdl->idx;
  8388. if (unlikely(!phba))
  8389. return IRQ_NONE;
  8390. /* Get to the EQ struct associated with this vector */
  8391. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8392. /* Check device state for handling interrupt */
  8393. if (unlikely(lpfc_intr_state_check(phba))) {
  8394. /* Check again for link_state with lock held */
  8395. spin_lock_irqsave(&phba->hbalock, iflag);
  8396. if (phba->link_state < LPFC_LINK_DOWN)
  8397. /* Flush, clear interrupt, and rearm the EQ */
  8398. lpfc_sli4_eq_flush(phba, fpeq);
  8399. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8400. return IRQ_NONE;
  8401. }
  8402. /*
  8403. * Process all the event on FCP fast-path EQ
  8404. */
  8405. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8406. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8407. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8408. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8409. }
  8410. /* Always clear and re-arm the fast-path EQ */
  8411. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8412. if (unlikely(ecount == 0)) {
  8413. if (phba->intr_type == MSIX)
  8414. /* MSI-X treated interrupt served as no EQ share INT */
  8415. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8416. "0358 MSI-X interrupt with no EQE\n");
  8417. else
  8418. /* Non MSI-X treated on interrupt as EQ share INT */
  8419. return IRQ_NONE;
  8420. }
  8421. return IRQ_HANDLED;
  8422. } /* lpfc_sli4_fp_intr_handler */
  8423. /**
  8424. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8425. * @irq: Interrupt number.
  8426. * @dev_id: The device context pointer.
  8427. *
  8428. * This function is the device-level interrupt handler to device with SLI-4
  8429. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8430. * interrupt mode is enabled and there is an event in the HBA which requires
  8431. * driver attention. This function invokes the slow-path interrupt attention
  8432. * handling function and fast-path interrupt attention handling function in
  8433. * turn to process the relevant HBA attention events. This function is called
  8434. * without any lock held. It gets the hbalock to access and update SLI data
  8435. * structures.
  8436. *
  8437. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8438. * returns IRQ_NONE.
  8439. **/
  8440. irqreturn_t
  8441. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8442. {
  8443. struct lpfc_hba *phba;
  8444. irqreturn_t sp_irq_rc, fp_irq_rc;
  8445. bool fp_handled = false;
  8446. uint32_t fcp_eqidx;
  8447. /* Get the driver's phba structure from the dev_id */
  8448. phba = (struct lpfc_hba *)dev_id;
  8449. if (unlikely(!phba))
  8450. return IRQ_NONE;
  8451. /*
  8452. * Invokes slow-path host attention interrupt handling as appropriate.
  8453. */
  8454. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8455. /*
  8456. * Invoke fast-path host attention interrupt handling as appropriate.
  8457. */
  8458. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8459. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8460. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8461. if (fp_irq_rc == IRQ_HANDLED)
  8462. fp_handled |= true;
  8463. }
  8464. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8465. } /* lpfc_sli4_intr_handler */
  8466. /**
  8467. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8468. * @queue: The queue structure to free.
  8469. *
  8470. * This function frees a queue structure and the DMAable memeory used for
  8471. * the host resident queue. This function must be called after destroying the
  8472. * queue on the HBA.
  8473. **/
  8474. void
  8475. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8476. {
  8477. struct lpfc_dmabuf *dmabuf;
  8478. if (!queue)
  8479. return;
  8480. while (!list_empty(&queue->page_list)) {
  8481. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8482. list);
  8483. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8484. dmabuf->virt, dmabuf->phys);
  8485. kfree(dmabuf);
  8486. }
  8487. kfree(queue);
  8488. return;
  8489. }
  8490. /**
  8491. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8492. * @phba: The HBA that this queue is being created on.
  8493. * @entry_size: The size of each queue entry for this queue.
  8494. * @entry count: The number of entries that this queue will handle.
  8495. *
  8496. * This function allocates a queue structure and the DMAable memory used for
  8497. * the host resident queue. This function must be called before creating the
  8498. * queue on the HBA.
  8499. **/
  8500. struct lpfc_queue *
  8501. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8502. uint32_t entry_count)
  8503. {
  8504. struct lpfc_queue *queue;
  8505. struct lpfc_dmabuf *dmabuf;
  8506. int x, total_qe_count;
  8507. void *dma_pointer;
  8508. queue = kzalloc(sizeof(struct lpfc_queue) +
  8509. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8510. if (!queue)
  8511. return NULL;
  8512. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8513. INIT_LIST_HEAD(&queue->list);
  8514. INIT_LIST_HEAD(&queue->page_list);
  8515. INIT_LIST_HEAD(&queue->child_list);
  8516. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8517. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8518. if (!dmabuf)
  8519. goto out_fail;
  8520. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8521. PAGE_SIZE, &dmabuf->phys,
  8522. GFP_KERNEL);
  8523. if (!dmabuf->virt) {
  8524. kfree(dmabuf);
  8525. goto out_fail;
  8526. }
  8527. memset(dmabuf->virt, 0, PAGE_SIZE);
  8528. dmabuf->buffer_tag = x;
  8529. list_add_tail(&dmabuf->list, &queue->page_list);
  8530. /* initialize queue's entry array */
  8531. dma_pointer = dmabuf->virt;
  8532. for (; total_qe_count < entry_count &&
  8533. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8534. total_qe_count++, dma_pointer += entry_size) {
  8535. queue->qe[total_qe_count].address = dma_pointer;
  8536. }
  8537. }
  8538. queue->entry_size = entry_size;
  8539. queue->entry_count = entry_count;
  8540. queue->phba = phba;
  8541. return queue;
  8542. out_fail:
  8543. lpfc_sli4_queue_free(queue);
  8544. return NULL;
  8545. }
  8546. /**
  8547. * lpfc_eq_create - Create an Event Queue on the HBA
  8548. * @phba: HBA structure that indicates port to create a queue on.
  8549. * @eq: The queue structure to use to create the event queue.
  8550. * @imax: The maximum interrupt per second limit.
  8551. *
  8552. * This function creates an event queue, as detailed in @eq, on a port,
  8553. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8554. *
  8555. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8556. * is used to get the entry count and entry size that are necessary to
  8557. * determine the number of pages to allocate and use for this queue. This
  8558. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8559. * event queue. This function is asynchronous and will wait for the mailbox
  8560. * command to finish before continuing.
  8561. *
  8562. * On success this function will return a zero. If unable to allocate enough
  8563. * memory this function will return ENOMEM. If the queue create mailbox command
  8564. * fails this function will return ENXIO.
  8565. **/
  8566. uint32_t
  8567. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8568. {
  8569. struct lpfc_mbx_eq_create *eq_create;
  8570. LPFC_MBOXQ_t *mbox;
  8571. int rc, length, status = 0;
  8572. struct lpfc_dmabuf *dmabuf;
  8573. uint32_t shdr_status, shdr_add_status;
  8574. union lpfc_sli4_cfg_shdr *shdr;
  8575. uint16_t dmult;
  8576. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8577. if (!mbox)
  8578. return -ENOMEM;
  8579. length = (sizeof(struct lpfc_mbx_eq_create) -
  8580. sizeof(struct lpfc_sli4_cfg_mhdr));
  8581. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8582. LPFC_MBOX_OPCODE_EQ_CREATE,
  8583. length, LPFC_SLI4_MBX_EMBED);
  8584. eq_create = &mbox->u.mqe.un.eq_create;
  8585. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8586. eq->page_count);
  8587. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8588. LPFC_EQE_SIZE);
  8589. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8590. /* Calculate delay multiper from maximum interrupt per second */
  8591. dmult = LPFC_DMULT_CONST/imax - 1;
  8592. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8593. dmult);
  8594. switch (eq->entry_count) {
  8595. default:
  8596. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8597. "0360 Unsupported EQ count. (%d)\n",
  8598. eq->entry_count);
  8599. if (eq->entry_count < 256)
  8600. return -EINVAL;
  8601. /* otherwise default to smallest count (drop through) */
  8602. case 256:
  8603. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8604. LPFC_EQ_CNT_256);
  8605. break;
  8606. case 512:
  8607. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8608. LPFC_EQ_CNT_512);
  8609. break;
  8610. case 1024:
  8611. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8612. LPFC_EQ_CNT_1024);
  8613. break;
  8614. case 2048:
  8615. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8616. LPFC_EQ_CNT_2048);
  8617. break;
  8618. case 4096:
  8619. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8620. LPFC_EQ_CNT_4096);
  8621. break;
  8622. }
  8623. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8624. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8625. putPaddrLow(dmabuf->phys);
  8626. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8627. putPaddrHigh(dmabuf->phys);
  8628. }
  8629. mbox->vport = phba->pport;
  8630. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8631. mbox->context1 = NULL;
  8632. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8633. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8634. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8635. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8636. if (shdr_status || shdr_add_status || rc) {
  8637. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8638. "2500 EQ_CREATE mailbox failed with "
  8639. "status x%x add_status x%x, mbx status x%x\n",
  8640. shdr_status, shdr_add_status, rc);
  8641. status = -ENXIO;
  8642. }
  8643. eq->type = LPFC_EQ;
  8644. eq->subtype = LPFC_NONE;
  8645. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8646. if (eq->queue_id == 0xFFFF)
  8647. status = -ENXIO;
  8648. eq->host_index = 0;
  8649. eq->hba_index = 0;
  8650. mempool_free(mbox, phba->mbox_mem_pool);
  8651. return status;
  8652. }
  8653. /**
  8654. * lpfc_cq_create - Create a Completion Queue on the HBA
  8655. * @phba: HBA structure that indicates port to create a queue on.
  8656. * @cq: The queue structure to use to create the completion queue.
  8657. * @eq: The event queue to bind this completion queue to.
  8658. *
  8659. * This function creates a completion queue, as detailed in @wq, on a port,
  8660. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8661. *
  8662. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8663. * is used to get the entry count and entry size that are necessary to
  8664. * determine the number of pages to allocate and use for this queue. The @eq
  8665. * is used to indicate which event queue to bind this completion queue to. This
  8666. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8667. * completion queue. This function is asynchronous and will wait for the mailbox
  8668. * command to finish before continuing.
  8669. *
  8670. * On success this function will return a zero. If unable to allocate enough
  8671. * memory this function will return ENOMEM. If the queue create mailbox command
  8672. * fails this function will return ENXIO.
  8673. **/
  8674. uint32_t
  8675. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8676. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8677. {
  8678. struct lpfc_mbx_cq_create *cq_create;
  8679. struct lpfc_dmabuf *dmabuf;
  8680. LPFC_MBOXQ_t *mbox;
  8681. int rc, length, status = 0;
  8682. uint32_t shdr_status, shdr_add_status;
  8683. union lpfc_sli4_cfg_shdr *shdr;
  8684. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8685. if (!mbox)
  8686. return -ENOMEM;
  8687. length = (sizeof(struct lpfc_mbx_cq_create) -
  8688. sizeof(struct lpfc_sli4_cfg_mhdr));
  8689. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8690. LPFC_MBOX_OPCODE_CQ_CREATE,
  8691. length, LPFC_SLI4_MBX_EMBED);
  8692. cq_create = &mbox->u.mqe.un.cq_create;
  8693. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8694. cq->page_count);
  8695. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8696. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8697. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8698. switch (cq->entry_count) {
  8699. default:
  8700. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8701. "0361 Unsupported CQ count. (%d)\n",
  8702. cq->entry_count);
  8703. if (cq->entry_count < 256)
  8704. return -EINVAL;
  8705. /* otherwise default to smallest count (drop through) */
  8706. case 256:
  8707. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8708. LPFC_CQ_CNT_256);
  8709. break;
  8710. case 512:
  8711. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8712. LPFC_CQ_CNT_512);
  8713. break;
  8714. case 1024:
  8715. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8716. LPFC_CQ_CNT_1024);
  8717. break;
  8718. }
  8719. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8720. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8721. putPaddrLow(dmabuf->phys);
  8722. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8723. putPaddrHigh(dmabuf->phys);
  8724. }
  8725. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8726. /* The IOCTL status is embedded in the mailbox subheader. */
  8727. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8728. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8729. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8730. if (shdr_status || shdr_add_status || rc) {
  8731. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8732. "2501 CQ_CREATE mailbox failed with "
  8733. "status x%x add_status x%x, mbx status x%x\n",
  8734. shdr_status, shdr_add_status, rc);
  8735. status = -ENXIO;
  8736. goto out;
  8737. }
  8738. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8739. if (cq->queue_id == 0xFFFF) {
  8740. status = -ENXIO;
  8741. goto out;
  8742. }
  8743. /* link the cq onto the parent eq child list */
  8744. list_add_tail(&cq->list, &eq->child_list);
  8745. /* Set up completion queue's type and subtype */
  8746. cq->type = type;
  8747. cq->subtype = subtype;
  8748. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8749. cq->host_index = 0;
  8750. cq->hba_index = 0;
  8751. out:
  8752. mempool_free(mbox, phba->mbox_mem_pool);
  8753. return status;
  8754. }
  8755. /**
  8756. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8757. * @phba: HBA structure that indicates port to create a queue on.
  8758. * @mq: The queue structure to use to create the mailbox queue.
  8759. *
  8760. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8761. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8762. *
  8763. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8764. * is used to get the entry count and entry size that are necessary to
  8765. * determine the number of pages to allocate and use for this queue. This
  8766. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8767. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8768. * command to finish before continuing.
  8769. *
  8770. * On success this function will return a zero. If unable to allocate enough
  8771. * memory this function will return ENOMEM. If the queue create mailbox command
  8772. * fails this function will return ENXIO.
  8773. **/
  8774. uint32_t
  8775. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8776. struct lpfc_queue *cq, uint32_t subtype)
  8777. {
  8778. struct lpfc_mbx_mq_create *mq_create;
  8779. struct lpfc_dmabuf *dmabuf;
  8780. LPFC_MBOXQ_t *mbox;
  8781. int rc, length, status = 0;
  8782. uint32_t shdr_status, shdr_add_status;
  8783. union lpfc_sli4_cfg_shdr *shdr;
  8784. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8785. if (!mbox)
  8786. return -ENOMEM;
  8787. length = (sizeof(struct lpfc_mbx_mq_create) -
  8788. sizeof(struct lpfc_sli4_cfg_mhdr));
  8789. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8790. LPFC_MBOX_OPCODE_MQ_CREATE,
  8791. length, LPFC_SLI4_MBX_EMBED);
  8792. mq_create = &mbox->u.mqe.un.mq_create;
  8793. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8794. mq->page_count);
  8795. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8796. cq->queue_id);
  8797. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8798. switch (mq->entry_count) {
  8799. default:
  8800. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8801. "0362 Unsupported MQ count. (%d)\n",
  8802. mq->entry_count);
  8803. if (mq->entry_count < 16)
  8804. return -EINVAL;
  8805. /* otherwise default to smallest count (drop through) */
  8806. case 16:
  8807. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8808. LPFC_MQ_CNT_16);
  8809. break;
  8810. case 32:
  8811. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8812. LPFC_MQ_CNT_32);
  8813. break;
  8814. case 64:
  8815. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8816. LPFC_MQ_CNT_64);
  8817. break;
  8818. case 128:
  8819. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8820. LPFC_MQ_CNT_128);
  8821. break;
  8822. }
  8823. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8824. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8825. putPaddrLow(dmabuf->phys);
  8826. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8827. putPaddrHigh(dmabuf->phys);
  8828. }
  8829. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8830. /* The IOCTL status is embedded in the mailbox subheader. */
  8831. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8832. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8833. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8834. if (shdr_status || shdr_add_status || rc) {
  8835. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8836. "2502 MQ_CREATE mailbox failed with "
  8837. "status x%x add_status x%x, mbx status x%x\n",
  8838. shdr_status, shdr_add_status, rc);
  8839. status = -ENXIO;
  8840. goto out;
  8841. }
  8842. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8843. if (mq->queue_id == 0xFFFF) {
  8844. status = -ENXIO;
  8845. goto out;
  8846. }
  8847. mq->type = LPFC_MQ;
  8848. mq->subtype = subtype;
  8849. mq->host_index = 0;
  8850. mq->hba_index = 0;
  8851. /* link the mq onto the parent cq child list */
  8852. list_add_tail(&mq->list, &cq->child_list);
  8853. out:
  8854. mempool_free(mbox, phba->mbox_mem_pool);
  8855. return status;
  8856. }
  8857. /**
  8858. * lpfc_wq_create - Create a Work Queue on the HBA
  8859. * @phba: HBA structure that indicates port to create a queue on.
  8860. * @wq: The queue structure to use to create the work queue.
  8861. * @cq: The completion queue to bind this work queue to.
  8862. * @subtype: The subtype of the work queue indicating its functionality.
  8863. *
  8864. * This function creates a work queue, as detailed in @wq, on a port, described
  8865. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8866. *
  8867. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8868. * is used to get the entry count and entry size that are necessary to
  8869. * determine the number of pages to allocate and use for this queue. The @cq
  8870. * is used to indicate which completion queue to bind this work queue to. This
  8871. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8872. * work queue. This function is asynchronous and will wait for the mailbox
  8873. * command to finish before continuing.
  8874. *
  8875. * On success this function will return a zero. If unable to allocate enough
  8876. * memory this function will return ENOMEM. If the queue create mailbox command
  8877. * fails this function will return ENXIO.
  8878. **/
  8879. uint32_t
  8880. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8881. struct lpfc_queue *cq, uint32_t subtype)
  8882. {
  8883. struct lpfc_mbx_wq_create *wq_create;
  8884. struct lpfc_dmabuf *dmabuf;
  8885. LPFC_MBOXQ_t *mbox;
  8886. int rc, length, status = 0;
  8887. uint32_t shdr_status, shdr_add_status;
  8888. union lpfc_sli4_cfg_shdr *shdr;
  8889. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8890. if (!mbox)
  8891. return -ENOMEM;
  8892. length = (sizeof(struct lpfc_mbx_wq_create) -
  8893. sizeof(struct lpfc_sli4_cfg_mhdr));
  8894. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8895. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8896. length, LPFC_SLI4_MBX_EMBED);
  8897. wq_create = &mbox->u.mqe.un.wq_create;
  8898. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8899. wq->page_count);
  8900. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8901. cq->queue_id);
  8902. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8903. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8904. putPaddrLow(dmabuf->phys);
  8905. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8906. putPaddrHigh(dmabuf->phys);
  8907. }
  8908. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8909. /* The IOCTL status is embedded in the mailbox subheader. */
  8910. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8911. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8912. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8913. if (shdr_status || shdr_add_status || rc) {
  8914. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8915. "2503 WQ_CREATE mailbox failed with "
  8916. "status x%x add_status x%x, mbx status x%x\n",
  8917. shdr_status, shdr_add_status, rc);
  8918. status = -ENXIO;
  8919. goto out;
  8920. }
  8921. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8922. if (wq->queue_id == 0xFFFF) {
  8923. status = -ENXIO;
  8924. goto out;
  8925. }
  8926. wq->type = LPFC_WQ;
  8927. wq->subtype = subtype;
  8928. wq->host_index = 0;
  8929. wq->hba_index = 0;
  8930. /* link the wq onto the parent cq child list */
  8931. list_add_tail(&wq->list, &cq->child_list);
  8932. out:
  8933. mempool_free(mbox, phba->mbox_mem_pool);
  8934. return status;
  8935. }
  8936. /**
  8937. * lpfc_rq_create - Create a Receive Queue on the HBA
  8938. * @phba: HBA structure that indicates port to create a queue on.
  8939. * @hrq: The queue structure to use to create the header receive queue.
  8940. * @drq: The queue structure to use to create the data receive queue.
  8941. * @cq: The completion queue to bind this work queue to.
  8942. *
  8943. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8944. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8945. * to the HBA.
  8946. *
  8947. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8948. * struct is used to get the entry count that is necessary to determine the
  8949. * number of pages to use for this queue. The @cq is used to indicate which
  8950. * completion queue to bind received buffers that are posted to these queues to.
  8951. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8952. * receive queue pair. This function is asynchronous and will wait for the
  8953. * mailbox command to finish before continuing.
  8954. *
  8955. * On success this function will return a zero. If unable to allocate enough
  8956. * memory this function will return ENOMEM. If the queue create mailbox command
  8957. * fails this function will return ENXIO.
  8958. **/
  8959. uint32_t
  8960. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8961. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8962. {
  8963. struct lpfc_mbx_rq_create *rq_create;
  8964. struct lpfc_dmabuf *dmabuf;
  8965. LPFC_MBOXQ_t *mbox;
  8966. int rc, length, status = 0;
  8967. uint32_t shdr_status, shdr_add_status;
  8968. union lpfc_sli4_cfg_shdr *shdr;
  8969. if (hrq->entry_count != drq->entry_count)
  8970. return -EINVAL;
  8971. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8972. if (!mbox)
  8973. return -ENOMEM;
  8974. length = (sizeof(struct lpfc_mbx_rq_create) -
  8975. sizeof(struct lpfc_sli4_cfg_mhdr));
  8976. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8977. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8978. length, LPFC_SLI4_MBX_EMBED);
  8979. rq_create = &mbox->u.mqe.un.rq_create;
  8980. switch (hrq->entry_count) {
  8981. default:
  8982. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8983. "2535 Unsupported RQ count. (%d)\n",
  8984. hrq->entry_count);
  8985. if (hrq->entry_count < 512)
  8986. return -EINVAL;
  8987. /* otherwise default to smallest count (drop through) */
  8988. case 512:
  8989. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8990. LPFC_RQ_RING_SIZE_512);
  8991. break;
  8992. case 1024:
  8993. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8994. LPFC_RQ_RING_SIZE_1024);
  8995. break;
  8996. case 2048:
  8997. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8998. LPFC_RQ_RING_SIZE_2048);
  8999. break;
  9000. case 4096:
  9001. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9002. LPFC_RQ_RING_SIZE_4096);
  9003. break;
  9004. }
  9005. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9006. cq->queue_id);
  9007. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9008. hrq->page_count);
  9009. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9010. LPFC_HDR_BUF_SIZE);
  9011. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9012. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9013. putPaddrLow(dmabuf->phys);
  9014. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9015. putPaddrHigh(dmabuf->phys);
  9016. }
  9017. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9018. /* The IOCTL status is embedded in the mailbox subheader. */
  9019. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9020. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9021. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9022. if (shdr_status || shdr_add_status || rc) {
  9023. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9024. "2504 RQ_CREATE mailbox failed with "
  9025. "status x%x add_status x%x, mbx status x%x\n",
  9026. shdr_status, shdr_add_status, rc);
  9027. status = -ENXIO;
  9028. goto out;
  9029. }
  9030. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9031. if (hrq->queue_id == 0xFFFF) {
  9032. status = -ENXIO;
  9033. goto out;
  9034. }
  9035. hrq->type = LPFC_HRQ;
  9036. hrq->subtype = subtype;
  9037. hrq->host_index = 0;
  9038. hrq->hba_index = 0;
  9039. /* now create the data queue */
  9040. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9041. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9042. length, LPFC_SLI4_MBX_EMBED);
  9043. switch (drq->entry_count) {
  9044. default:
  9045. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9046. "2536 Unsupported RQ count. (%d)\n",
  9047. drq->entry_count);
  9048. if (drq->entry_count < 512)
  9049. return -EINVAL;
  9050. /* otherwise default to smallest count (drop through) */
  9051. case 512:
  9052. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9053. LPFC_RQ_RING_SIZE_512);
  9054. break;
  9055. case 1024:
  9056. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9057. LPFC_RQ_RING_SIZE_1024);
  9058. break;
  9059. case 2048:
  9060. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9061. LPFC_RQ_RING_SIZE_2048);
  9062. break;
  9063. case 4096:
  9064. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9065. LPFC_RQ_RING_SIZE_4096);
  9066. break;
  9067. }
  9068. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9069. cq->queue_id);
  9070. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9071. drq->page_count);
  9072. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9073. LPFC_DATA_BUF_SIZE);
  9074. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9075. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9076. putPaddrLow(dmabuf->phys);
  9077. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9078. putPaddrHigh(dmabuf->phys);
  9079. }
  9080. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9081. /* The IOCTL status is embedded in the mailbox subheader. */
  9082. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9083. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9084. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9085. if (shdr_status || shdr_add_status || rc) {
  9086. status = -ENXIO;
  9087. goto out;
  9088. }
  9089. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9090. if (drq->queue_id == 0xFFFF) {
  9091. status = -ENXIO;
  9092. goto out;
  9093. }
  9094. drq->type = LPFC_DRQ;
  9095. drq->subtype = subtype;
  9096. drq->host_index = 0;
  9097. drq->hba_index = 0;
  9098. /* link the header and data RQs onto the parent cq child list */
  9099. list_add_tail(&hrq->list, &cq->child_list);
  9100. list_add_tail(&drq->list, &cq->child_list);
  9101. out:
  9102. mempool_free(mbox, phba->mbox_mem_pool);
  9103. return status;
  9104. }
  9105. /**
  9106. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9107. * @eq: The queue structure associated with the queue to destroy.
  9108. *
  9109. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9110. * command, specific to the type of queue, to the HBA.
  9111. *
  9112. * The @eq struct is used to get the queue ID of the queue to destroy.
  9113. *
  9114. * On success this function will return a zero. If the queue destroy mailbox
  9115. * command fails this function will return ENXIO.
  9116. **/
  9117. uint32_t
  9118. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9119. {
  9120. LPFC_MBOXQ_t *mbox;
  9121. int rc, length, status = 0;
  9122. uint32_t shdr_status, shdr_add_status;
  9123. union lpfc_sli4_cfg_shdr *shdr;
  9124. if (!eq)
  9125. return -ENODEV;
  9126. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9127. if (!mbox)
  9128. return -ENOMEM;
  9129. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9130. sizeof(struct lpfc_sli4_cfg_mhdr));
  9131. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9132. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9133. length, LPFC_SLI4_MBX_EMBED);
  9134. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9135. eq->queue_id);
  9136. mbox->vport = eq->phba->pport;
  9137. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9138. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9139. /* The IOCTL status is embedded in the mailbox subheader. */
  9140. shdr = (union lpfc_sli4_cfg_shdr *)
  9141. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9142. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9143. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9144. if (shdr_status || shdr_add_status || rc) {
  9145. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9146. "2505 EQ_DESTROY mailbox failed with "
  9147. "status x%x add_status x%x, mbx status x%x\n",
  9148. shdr_status, shdr_add_status, rc);
  9149. status = -ENXIO;
  9150. }
  9151. /* Remove eq from any list */
  9152. list_del_init(&eq->list);
  9153. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9154. return status;
  9155. }
  9156. /**
  9157. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9158. * @cq: The queue structure associated with the queue to destroy.
  9159. *
  9160. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9161. * command, specific to the type of queue, to the HBA.
  9162. *
  9163. * The @cq struct is used to get the queue ID of the queue to destroy.
  9164. *
  9165. * On success this function will return a zero. If the queue destroy mailbox
  9166. * command fails this function will return ENXIO.
  9167. **/
  9168. uint32_t
  9169. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9170. {
  9171. LPFC_MBOXQ_t *mbox;
  9172. int rc, length, status = 0;
  9173. uint32_t shdr_status, shdr_add_status;
  9174. union lpfc_sli4_cfg_shdr *shdr;
  9175. if (!cq)
  9176. return -ENODEV;
  9177. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9178. if (!mbox)
  9179. return -ENOMEM;
  9180. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9181. sizeof(struct lpfc_sli4_cfg_mhdr));
  9182. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9183. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9184. length, LPFC_SLI4_MBX_EMBED);
  9185. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9186. cq->queue_id);
  9187. mbox->vport = cq->phba->pport;
  9188. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9189. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9190. /* The IOCTL status is embedded in the mailbox subheader. */
  9191. shdr = (union lpfc_sli4_cfg_shdr *)
  9192. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9193. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9194. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9195. if (shdr_status || shdr_add_status || rc) {
  9196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9197. "2506 CQ_DESTROY mailbox failed with "
  9198. "status x%x add_status x%x, mbx status x%x\n",
  9199. shdr_status, shdr_add_status, rc);
  9200. status = -ENXIO;
  9201. }
  9202. /* Remove cq from any list */
  9203. list_del_init(&cq->list);
  9204. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9205. return status;
  9206. }
  9207. /**
  9208. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9209. * @qm: The queue structure associated with the queue to destroy.
  9210. *
  9211. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9212. * command, specific to the type of queue, to the HBA.
  9213. *
  9214. * The @mq struct is used to get the queue ID of the queue to destroy.
  9215. *
  9216. * On success this function will return a zero. If the queue destroy mailbox
  9217. * command fails this function will return ENXIO.
  9218. **/
  9219. uint32_t
  9220. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9221. {
  9222. LPFC_MBOXQ_t *mbox;
  9223. int rc, length, status = 0;
  9224. uint32_t shdr_status, shdr_add_status;
  9225. union lpfc_sli4_cfg_shdr *shdr;
  9226. if (!mq)
  9227. return -ENODEV;
  9228. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9229. if (!mbox)
  9230. return -ENOMEM;
  9231. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9232. sizeof(struct lpfc_sli4_cfg_mhdr));
  9233. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9234. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9235. length, LPFC_SLI4_MBX_EMBED);
  9236. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9237. mq->queue_id);
  9238. mbox->vport = mq->phba->pport;
  9239. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9240. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9241. /* The IOCTL status is embedded in the mailbox subheader. */
  9242. shdr = (union lpfc_sli4_cfg_shdr *)
  9243. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9244. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9245. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9246. if (shdr_status || shdr_add_status || rc) {
  9247. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9248. "2507 MQ_DESTROY mailbox failed with "
  9249. "status x%x add_status x%x, mbx status x%x\n",
  9250. shdr_status, shdr_add_status, rc);
  9251. status = -ENXIO;
  9252. }
  9253. /* Remove mq from any list */
  9254. list_del_init(&mq->list);
  9255. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9256. return status;
  9257. }
  9258. /**
  9259. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9260. * @wq: The queue structure associated with the queue to destroy.
  9261. *
  9262. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9263. * command, specific to the type of queue, to the HBA.
  9264. *
  9265. * The @wq struct is used to get the queue ID of the queue to destroy.
  9266. *
  9267. * On success this function will return a zero. If the queue destroy mailbox
  9268. * command fails this function will return ENXIO.
  9269. **/
  9270. uint32_t
  9271. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9272. {
  9273. LPFC_MBOXQ_t *mbox;
  9274. int rc, length, status = 0;
  9275. uint32_t shdr_status, shdr_add_status;
  9276. union lpfc_sli4_cfg_shdr *shdr;
  9277. if (!wq)
  9278. return -ENODEV;
  9279. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9280. if (!mbox)
  9281. return -ENOMEM;
  9282. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9283. sizeof(struct lpfc_sli4_cfg_mhdr));
  9284. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9285. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9286. length, LPFC_SLI4_MBX_EMBED);
  9287. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9288. wq->queue_id);
  9289. mbox->vport = wq->phba->pport;
  9290. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9291. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9292. shdr = (union lpfc_sli4_cfg_shdr *)
  9293. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9294. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9295. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9296. if (shdr_status || shdr_add_status || rc) {
  9297. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9298. "2508 WQ_DESTROY mailbox failed with "
  9299. "status x%x add_status x%x, mbx status x%x\n",
  9300. shdr_status, shdr_add_status, rc);
  9301. status = -ENXIO;
  9302. }
  9303. /* Remove wq from any list */
  9304. list_del_init(&wq->list);
  9305. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9306. return status;
  9307. }
  9308. /**
  9309. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9310. * @rq: The queue structure associated with the queue to destroy.
  9311. *
  9312. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9313. * command, specific to the type of queue, to the HBA.
  9314. *
  9315. * The @rq struct is used to get the queue ID of the queue to destroy.
  9316. *
  9317. * On success this function will return a zero. If the queue destroy mailbox
  9318. * command fails this function will return ENXIO.
  9319. **/
  9320. uint32_t
  9321. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9322. struct lpfc_queue *drq)
  9323. {
  9324. LPFC_MBOXQ_t *mbox;
  9325. int rc, length, status = 0;
  9326. uint32_t shdr_status, shdr_add_status;
  9327. union lpfc_sli4_cfg_shdr *shdr;
  9328. if (!hrq || !drq)
  9329. return -ENODEV;
  9330. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9331. if (!mbox)
  9332. return -ENOMEM;
  9333. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9334. sizeof(struct mbox_header));
  9335. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9336. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9337. length, LPFC_SLI4_MBX_EMBED);
  9338. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9339. hrq->queue_id);
  9340. mbox->vport = hrq->phba->pport;
  9341. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9342. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9343. /* The IOCTL status is embedded in the mailbox subheader. */
  9344. shdr = (union lpfc_sli4_cfg_shdr *)
  9345. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9346. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9347. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9348. if (shdr_status || shdr_add_status || rc) {
  9349. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9350. "2509 RQ_DESTROY mailbox failed with "
  9351. "status x%x add_status x%x, mbx status x%x\n",
  9352. shdr_status, shdr_add_status, rc);
  9353. if (rc != MBX_TIMEOUT)
  9354. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9355. return -ENXIO;
  9356. }
  9357. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9358. drq->queue_id);
  9359. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9360. shdr = (union lpfc_sli4_cfg_shdr *)
  9361. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9362. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9363. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9364. if (shdr_status || shdr_add_status || rc) {
  9365. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9366. "2510 RQ_DESTROY mailbox failed with "
  9367. "status x%x add_status x%x, mbx status x%x\n",
  9368. shdr_status, shdr_add_status, rc);
  9369. status = -ENXIO;
  9370. }
  9371. list_del_init(&hrq->list);
  9372. list_del_init(&drq->list);
  9373. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9374. return status;
  9375. }
  9376. /**
  9377. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9378. * @phba: The virtual port for which this call being executed.
  9379. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9380. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9381. * @xritag: the xritag that ties this io to the SGL pages.
  9382. *
  9383. * This routine will post the sgl pages for the IO that has the xritag
  9384. * that is in the iocbq structure. The xritag is assigned during iocbq
  9385. * creation and persists for as long as the driver is loaded.
  9386. * if the caller has fewer than 256 scatter gather segments to map then
  9387. * pdma_phys_addr1 should be 0.
  9388. * If the caller needs to map more than 256 scatter gather segment then
  9389. * pdma_phys_addr1 should be a valid physical address.
  9390. * physical address for SGLs must be 64 byte aligned.
  9391. * If you are going to map 2 SGL's then the first one must have 256 entries
  9392. * the second sgl can have between 1 and 256 entries.
  9393. *
  9394. * Return codes:
  9395. * 0 - Success
  9396. * -ENXIO, -ENOMEM - Failure
  9397. **/
  9398. int
  9399. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9400. dma_addr_t pdma_phys_addr0,
  9401. dma_addr_t pdma_phys_addr1,
  9402. uint16_t xritag)
  9403. {
  9404. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9405. LPFC_MBOXQ_t *mbox;
  9406. int rc;
  9407. uint32_t shdr_status, shdr_add_status;
  9408. union lpfc_sli4_cfg_shdr *shdr;
  9409. if (xritag == NO_XRI) {
  9410. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9411. "0364 Invalid param:\n");
  9412. return -EINVAL;
  9413. }
  9414. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9415. if (!mbox)
  9416. return -ENOMEM;
  9417. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9418. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9419. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9420. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9421. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9422. &mbox->u.mqe.un.post_sgl_pages;
  9423. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9424. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9425. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9426. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9427. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9428. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9429. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9430. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9431. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9432. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9433. if (!phba->sli4_hba.intr_enable)
  9434. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9435. else
  9436. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9437. /* The IOCTL status is embedded in the mailbox subheader. */
  9438. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9439. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9440. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9441. if (rc != MBX_TIMEOUT)
  9442. mempool_free(mbox, phba->mbox_mem_pool);
  9443. if (shdr_status || shdr_add_status || rc) {
  9444. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9445. "2511 POST_SGL mailbox failed with "
  9446. "status x%x add_status x%x, mbx status x%x\n",
  9447. shdr_status, shdr_add_status, rc);
  9448. rc = -ENXIO;
  9449. }
  9450. return 0;
  9451. }
  9452. /**
  9453. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9454. * @phba: The virtual port for which this call being executed.
  9455. *
  9456. * This routine will remove all of the sgl pages registered with the hba.
  9457. *
  9458. * Return codes:
  9459. * 0 - Success
  9460. * -ENXIO, -ENOMEM - Failure
  9461. **/
  9462. int
  9463. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9464. {
  9465. LPFC_MBOXQ_t *mbox;
  9466. int rc;
  9467. uint32_t shdr_status, shdr_add_status;
  9468. union lpfc_sli4_cfg_shdr *shdr;
  9469. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9470. if (!mbox)
  9471. return -ENOMEM;
  9472. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9473. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9474. LPFC_SLI4_MBX_EMBED);
  9475. if (!phba->sli4_hba.intr_enable)
  9476. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9477. else
  9478. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9479. /* The IOCTL status is embedded in the mailbox subheader. */
  9480. shdr = (union lpfc_sli4_cfg_shdr *)
  9481. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9482. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9483. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9484. if (rc != MBX_TIMEOUT)
  9485. mempool_free(mbox, phba->mbox_mem_pool);
  9486. if (shdr_status || shdr_add_status || rc) {
  9487. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9488. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9489. "status x%x add_status x%x, mbx status x%x\n",
  9490. shdr_status, shdr_add_status, rc);
  9491. rc = -ENXIO;
  9492. }
  9493. return rc;
  9494. }
  9495. /**
  9496. * lpfc_sli4_next_xritag - Get an xritag for the io
  9497. * @phba: Pointer to HBA context object.
  9498. *
  9499. * This function gets an xritag for the iocb. If there is no unused xritag
  9500. * it will return 0xffff.
  9501. * The function returns the allocated xritag if successful, else returns zero.
  9502. * Zero is not a valid xritag.
  9503. * The caller is not required to hold any lock.
  9504. **/
  9505. uint16_t
  9506. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9507. {
  9508. uint16_t xritag;
  9509. spin_lock_irq(&phba->hbalock);
  9510. xritag = phba->sli4_hba.next_xri;
  9511. if ((xritag != (uint16_t) -1) && xritag <
  9512. (phba->sli4_hba.max_cfg_param.max_xri
  9513. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9514. phba->sli4_hba.next_xri++;
  9515. phba->sli4_hba.max_cfg_param.xri_used++;
  9516. spin_unlock_irq(&phba->hbalock);
  9517. return xritag;
  9518. }
  9519. spin_unlock_irq(&phba->hbalock);
  9520. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9521. "2004 Failed to allocate XRI.last XRITAG is %d"
  9522. " Max XRI is %d, Used XRI is %d\n",
  9523. phba->sli4_hba.next_xri,
  9524. phba->sli4_hba.max_cfg_param.max_xri,
  9525. phba->sli4_hba.max_cfg_param.xri_used);
  9526. return -1;
  9527. }
  9528. /**
  9529. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9530. * @phba: pointer to lpfc hba data structure.
  9531. *
  9532. * This routine is invoked to post a block of driver's sgl pages to the
  9533. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9534. * is only called when the driver is loading and after all IO has been
  9535. * stopped.
  9536. **/
  9537. int
  9538. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9539. {
  9540. struct lpfc_sglq *sglq_entry;
  9541. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9542. struct sgl_page_pairs *sgl_pg_pairs;
  9543. void *viraddr;
  9544. LPFC_MBOXQ_t *mbox;
  9545. uint32_t reqlen, alloclen, pg_pairs;
  9546. uint32_t mbox_tmo;
  9547. uint16_t xritag_start = 0;
  9548. int els_xri_cnt, rc = 0;
  9549. uint32_t shdr_status, shdr_add_status;
  9550. union lpfc_sli4_cfg_shdr *shdr;
  9551. /* The number of sgls to be posted */
  9552. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9553. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9554. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9555. if (reqlen > PAGE_SIZE) {
  9556. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9557. "2559 Block sgl registration required DMA "
  9558. "size (%d) great than a page\n", reqlen);
  9559. return -ENOMEM;
  9560. }
  9561. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9562. if (!mbox) {
  9563. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9564. "2560 Failed to allocate mbox cmd memory\n");
  9565. return -ENOMEM;
  9566. }
  9567. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9568. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9569. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9570. LPFC_SLI4_MBX_NEMBED);
  9571. if (alloclen < reqlen) {
  9572. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9573. "0285 Allocated DMA memory size (%d) is "
  9574. "less than the requested DMA memory "
  9575. "size (%d)\n", alloclen, reqlen);
  9576. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9577. return -ENOMEM;
  9578. }
  9579. /* Get the first SGE entry from the non-embedded DMA memory */
  9580. viraddr = mbox->sge_array->addr[0];
  9581. /* Set up the SGL pages in the non-embedded DMA pages */
  9582. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9583. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9584. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9585. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9586. /* Set up the sge entry */
  9587. sgl_pg_pairs->sgl_pg0_addr_lo =
  9588. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9589. sgl_pg_pairs->sgl_pg0_addr_hi =
  9590. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9591. sgl_pg_pairs->sgl_pg1_addr_lo =
  9592. cpu_to_le32(putPaddrLow(0));
  9593. sgl_pg_pairs->sgl_pg1_addr_hi =
  9594. cpu_to_le32(putPaddrHigh(0));
  9595. /* Keep the first xritag on the list */
  9596. if (pg_pairs == 0)
  9597. xritag_start = sglq_entry->sli4_xritag;
  9598. sgl_pg_pairs++;
  9599. }
  9600. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9601. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9602. /* Perform endian conversion if necessary */
  9603. sgl->word0 = cpu_to_le32(sgl->word0);
  9604. if (!phba->sli4_hba.intr_enable)
  9605. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9606. else {
  9607. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9608. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9609. }
  9610. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9611. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9612. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9613. if (rc != MBX_TIMEOUT)
  9614. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9615. if (shdr_status || shdr_add_status || rc) {
  9616. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9617. "2513 POST_SGL_BLOCK mailbox command failed "
  9618. "status x%x add_status x%x mbx status x%x\n",
  9619. shdr_status, shdr_add_status, rc);
  9620. rc = -ENXIO;
  9621. }
  9622. return rc;
  9623. }
  9624. /**
  9625. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9626. * @phba: pointer to lpfc hba data structure.
  9627. * @sblist: pointer to scsi buffer list.
  9628. * @count: number of scsi buffers on the list.
  9629. *
  9630. * This routine is invoked to post a block of @count scsi sgl pages from a
  9631. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9632. * No Lock is held.
  9633. *
  9634. **/
  9635. int
  9636. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9637. int cnt)
  9638. {
  9639. struct lpfc_scsi_buf *psb;
  9640. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9641. struct sgl_page_pairs *sgl_pg_pairs;
  9642. void *viraddr;
  9643. LPFC_MBOXQ_t *mbox;
  9644. uint32_t reqlen, alloclen, pg_pairs;
  9645. uint32_t mbox_tmo;
  9646. uint16_t xritag_start = 0;
  9647. int rc = 0;
  9648. uint32_t shdr_status, shdr_add_status;
  9649. dma_addr_t pdma_phys_bpl1;
  9650. union lpfc_sli4_cfg_shdr *shdr;
  9651. /* Calculate the requested length of the dma memory */
  9652. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9653. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9654. if (reqlen > PAGE_SIZE) {
  9655. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9656. "0217 Block sgl registration required DMA "
  9657. "size (%d) great than a page\n", reqlen);
  9658. return -ENOMEM;
  9659. }
  9660. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9661. if (!mbox) {
  9662. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9663. "0283 Failed to allocate mbox cmd memory\n");
  9664. return -ENOMEM;
  9665. }
  9666. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9667. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9668. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9669. LPFC_SLI4_MBX_NEMBED);
  9670. if (alloclen < reqlen) {
  9671. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9672. "2561 Allocated DMA memory size (%d) is "
  9673. "less than the requested DMA memory "
  9674. "size (%d)\n", alloclen, reqlen);
  9675. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9676. return -ENOMEM;
  9677. }
  9678. /* Get the first SGE entry from the non-embedded DMA memory */
  9679. viraddr = mbox->sge_array->addr[0];
  9680. /* Set up the SGL pages in the non-embedded DMA pages */
  9681. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9682. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9683. pg_pairs = 0;
  9684. list_for_each_entry(psb, sblist, list) {
  9685. /* Set up the sge entry */
  9686. sgl_pg_pairs->sgl_pg0_addr_lo =
  9687. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9688. sgl_pg_pairs->sgl_pg0_addr_hi =
  9689. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9690. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9691. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9692. else
  9693. pdma_phys_bpl1 = 0;
  9694. sgl_pg_pairs->sgl_pg1_addr_lo =
  9695. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9696. sgl_pg_pairs->sgl_pg1_addr_hi =
  9697. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9698. /* Keep the first xritag on the list */
  9699. if (pg_pairs == 0)
  9700. xritag_start = psb->cur_iocbq.sli4_xritag;
  9701. sgl_pg_pairs++;
  9702. pg_pairs++;
  9703. }
  9704. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9705. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9706. /* Perform endian conversion if necessary */
  9707. sgl->word0 = cpu_to_le32(sgl->word0);
  9708. if (!phba->sli4_hba.intr_enable)
  9709. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9710. else {
  9711. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9712. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9713. }
  9714. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9715. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9716. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9717. if (rc != MBX_TIMEOUT)
  9718. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9719. if (shdr_status || shdr_add_status || rc) {
  9720. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9721. "2564 POST_SGL_BLOCK mailbox command failed "
  9722. "status x%x add_status x%x mbx status x%x\n",
  9723. shdr_status, shdr_add_status, rc);
  9724. rc = -ENXIO;
  9725. }
  9726. return rc;
  9727. }
  9728. /**
  9729. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9730. * @phba: pointer to lpfc_hba struct that the frame was received on
  9731. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9732. *
  9733. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9734. * valid type of frame that the LPFC driver will handle. This function will
  9735. * return a zero if the frame is a valid frame or a non zero value when the
  9736. * frame does not pass the check.
  9737. **/
  9738. static int
  9739. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9740. {
  9741. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9742. char *type_names[] = FC_TYPE_NAMES_INIT;
  9743. struct fc_vft_header *fc_vft_hdr;
  9744. switch (fc_hdr->fh_r_ctl) {
  9745. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9746. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9747. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9748. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9749. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9750. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9751. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9752. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9753. case FC_RCTL_ELS_REQ: /* extended link services request */
  9754. case FC_RCTL_ELS_REP: /* extended link services reply */
  9755. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9756. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9757. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9758. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9759. case FC_RCTL_BA_RMC: /* remove connection */
  9760. case FC_RCTL_BA_ACC: /* basic accept */
  9761. case FC_RCTL_BA_RJT: /* basic reject */
  9762. case FC_RCTL_BA_PRMT:
  9763. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9764. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9765. case FC_RCTL_P_RJT: /* port reject */
  9766. case FC_RCTL_F_RJT: /* fabric reject */
  9767. case FC_RCTL_P_BSY: /* port busy */
  9768. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9769. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9770. case FC_RCTL_LCR: /* link credit reset */
  9771. case FC_RCTL_END: /* end */
  9772. break;
  9773. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9774. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9775. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9776. return lpfc_fc_frame_check(phba, fc_hdr);
  9777. default:
  9778. goto drop;
  9779. }
  9780. switch (fc_hdr->fh_type) {
  9781. case FC_TYPE_BLS:
  9782. case FC_TYPE_ELS:
  9783. case FC_TYPE_FCP:
  9784. case FC_TYPE_CT:
  9785. break;
  9786. case FC_TYPE_IP:
  9787. case FC_TYPE_ILS:
  9788. default:
  9789. goto drop;
  9790. }
  9791. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9792. "2538 Received frame rctl:%s type:%s\n",
  9793. rctl_names[fc_hdr->fh_r_ctl],
  9794. type_names[fc_hdr->fh_type]);
  9795. return 0;
  9796. drop:
  9797. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9798. "2539 Dropped frame rctl:%s type:%s\n",
  9799. rctl_names[fc_hdr->fh_r_ctl],
  9800. type_names[fc_hdr->fh_type]);
  9801. return 1;
  9802. }
  9803. /**
  9804. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9805. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9806. *
  9807. * This function processes the FC header to retrieve the VFI from the VF
  9808. * header, if one exists. This function will return the VFI if one exists
  9809. * or 0 if no VSAN Header exists.
  9810. **/
  9811. static uint32_t
  9812. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9813. {
  9814. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9815. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9816. return 0;
  9817. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9818. }
  9819. /**
  9820. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9821. * @phba: Pointer to the HBA structure to search for the vport on
  9822. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9823. * @fcfi: The FC Fabric ID that the frame came from
  9824. *
  9825. * This function searches the @phba for a vport that matches the content of the
  9826. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9827. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9828. * returns the matching vport pointer or NULL if unable to match frame to a
  9829. * vport.
  9830. **/
  9831. static struct lpfc_vport *
  9832. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9833. uint16_t fcfi)
  9834. {
  9835. struct lpfc_vport **vports;
  9836. struct lpfc_vport *vport = NULL;
  9837. int i;
  9838. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9839. fc_hdr->fh_d_id[1] << 8 |
  9840. fc_hdr->fh_d_id[2]);
  9841. vports = lpfc_create_vport_work_array(phba);
  9842. if (vports != NULL)
  9843. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9844. if (phba->fcf.fcfi == fcfi &&
  9845. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9846. vports[i]->fc_myDID == did) {
  9847. vport = vports[i];
  9848. break;
  9849. }
  9850. }
  9851. lpfc_destroy_vport_work_array(phba, vports);
  9852. return vport;
  9853. }
  9854. /**
  9855. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  9856. * @vport: The vport to work on.
  9857. *
  9858. * This function updates the receive sequence time stamp for this vport. The
  9859. * receive sequence time stamp indicates the time that the last frame of the
  9860. * the sequence that has been idle for the longest amount of time was received.
  9861. * the driver uses this time stamp to indicate if any received sequences have
  9862. * timed out.
  9863. **/
  9864. void
  9865. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  9866. {
  9867. struct lpfc_dmabuf *h_buf;
  9868. struct hbq_dmabuf *dmabuf = NULL;
  9869. /* get the oldest sequence on the rcv list */
  9870. h_buf = list_get_first(&vport->rcv_buffer_list,
  9871. struct lpfc_dmabuf, list);
  9872. if (!h_buf)
  9873. return;
  9874. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9875. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  9876. }
  9877. /**
  9878. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  9879. * @vport: The vport that the received sequences were sent to.
  9880. *
  9881. * This function cleans up all outstanding received sequences. This is called
  9882. * by the driver when a link event or user action invalidates all the received
  9883. * sequences.
  9884. **/
  9885. void
  9886. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  9887. {
  9888. struct lpfc_dmabuf *h_buf, *hnext;
  9889. struct lpfc_dmabuf *d_buf, *dnext;
  9890. struct hbq_dmabuf *dmabuf = NULL;
  9891. /* start with the oldest sequence on the rcv list */
  9892. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9893. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9894. list_del_init(&dmabuf->hbuf.list);
  9895. list_for_each_entry_safe(d_buf, dnext,
  9896. &dmabuf->dbuf.list, list) {
  9897. list_del_init(&d_buf->list);
  9898. lpfc_in_buf_free(vport->phba, d_buf);
  9899. }
  9900. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  9901. }
  9902. }
  9903. /**
  9904. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  9905. * @vport: The vport that the received sequences were sent to.
  9906. *
  9907. * This function determines whether any received sequences have timed out by
  9908. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  9909. * indicates that there is at least one timed out sequence this routine will
  9910. * go through the received sequences one at a time from most inactive to most
  9911. * active to determine which ones need to be cleaned up. Once it has determined
  9912. * that a sequence needs to be cleaned up it will simply free up the resources
  9913. * without sending an abort.
  9914. **/
  9915. void
  9916. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  9917. {
  9918. struct lpfc_dmabuf *h_buf, *hnext;
  9919. struct lpfc_dmabuf *d_buf, *dnext;
  9920. struct hbq_dmabuf *dmabuf = NULL;
  9921. unsigned long timeout;
  9922. int abort_count = 0;
  9923. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  9924. vport->rcv_buffer_time_stamp);
  9925. if (list_empty(&vport->rcv_buffer_list) ||
  9926. time_before(jiffies, timeout))
  9927. return;
  9928. /* start with the oldest sequence on the rcv list */
  9929. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9930. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9931. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  9932. dmabuf->time_stamp);
  9933. if (time_before(jiffies, timeout))
  9934. break;
  9935. abort_count++;
  9936. list_del_init(&dmabuf->hbuf.list);
  9937. list_for_each_entry_safe(d_buf, dnext,
  9938. &dmabuf->dbuf.list, list) {
  9939. list_del_init(&d_buf->list);
  9940. lpfc_in_buf_free(vport->phba, d_buf);
  9941. }
  9942. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  9943. }
  9944. if (abort_count)
  9945. lpfc_update_rcv_time_stamp(vport);
  9946. }
  9947. /**
  9948. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9949. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9950. *
  9951. * This function searches through the existing incomplete sequences that have
  9952. * been sent to this @vport. If the frame matches one of the incomplete
  9953. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9954. * make up that sequence. If no sequence is found that matches this frame then
  9955. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9956. * This function returns a pointer to the first dmabuf in the sequence list that
  9957. * the frame was linked to.
  9958. **/
  9959. static struct hbq_dmabuf *
  9960. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9961. {
  9962. struct fc_frame_header *new_hdr;
  9963. struct fc_frame_header *temp_hdr;
  9964. struct lpfc_dmabuf *d_buf;
  9965. struct lpfc_dmabuf *h_buf;
  9966. struct hbq_dmabuf *seq_dmabuf = NULL;
  9967. struct hbq_dmabuf *temp_dmabuf = NULL;
  9968. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  9969. dmabuf->time_stamp = jiffies;
  9970. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9971. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9972. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9973. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9974. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9975. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9976. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9977. continue;
  9978. /* found a pending sequence that matches this frame */
  9979. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9980. break;
  9981. }
  9982. if (!seq_dmabuf) {
  9983. /*
  9984. * This indicates first frame received for this sequence.
  9985. * Queue the buffer on the vport's rcv_buffer_list.
  9986. */
  9987. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9988. lpfc_update_rcv_time_stamp(vport);
  9989. return dmabuf;
  9990. }
  9991. temp_hdr = seq_dmabuf->hbuf.virt;
  9992. if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
  9993. list_del_init(&seq_dmabuf->hbuf.list);
  9994. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9995. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  9996. lpfc_update_rcv_time_stamp(vport);
  9997. return dmabuf;
  9998. }
  9999. /* move this sequence to the tail to indicate a young sequence */
  10000. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10001. seq_dmabuf->time_stamp = jiffies;
  10002. lpfc_update_rcv_time_stamp(vport);
  10003. /* find the correct place in the sequence to insert this frame */
  10004. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10005. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10006. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10007. /*
  10008. * If the frame's sequence count is greater than the frame on
  10009. * the list then insert the frame right after this frame
  10010. */
  10011. if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
  10012. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10013. return seq_dmabuf;
  10014. }
  10015. }
  10016. return NULL;
  10017. }
  10018. /**
  10019. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10020. * @vport: pointer to a vitural port
  10021. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10022. *
  10023. * This function tries to abort from the partially assembed sequence, described
  10024. * by the information from basic abbort @dmabuf. It checks to see whether such
  10025. * partially assembled sequence held by the driver. If so, it shall free up all
  10026. * the frames from the partially assembled sequence.
  10027. *
  10028. * Return
  10029. * true -- if there is matching partially assembled sequence present and all
  10030. * the frames freed with the sequence;
  10031. * false -- if there is no matching partially assembled sequence present so
  10032. * nothing got aborted in the lower layer driver
  10033. **/
  10034. static bool
  10035. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10036. struct hbq_dmabuf *dmabuf)
  10037. {
  10038. struct fc_frame_header *new_hdr;
  10039. struct fc_frame_header *temp_hdr;
  10040. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10041. struct hbq_dmabuf *seq_dmabuf = NULL;
  10042. /* Use the hdr_buf to find the sequence that matches this frame */
  10043. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10044. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10045. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10046. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10047. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10048. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10049. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10050. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10051. continue;
  10052. /* found a pending sequence that matches this frame */
  10053. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10054. break;
  10055. }
  10056. /* Free up all the frames from the partially assembled sequence */
  10057. if (seq_dmabuf) {
  10058. list_for_each_entry_safe(d_buf, n_buf,
  10059. &seq_dmabuf->dbuf.list, list) {
  10060. list_del_init(&d_buf->list);
  10061. lpfc_in_buf_free(vport->phba, d_buf);
  10062. }
  10063. return true;
  10064. }
  10065. return false;
  10066. }
  10067. /**
  10068. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10069. * @phba: Pointer to HBA context object.
  10070. * @cmd_iocbq: pointer to the command iocbq structure.
  10071. * @rsp_iocbq: pointer to the response iocbq structure.
  10072. *
  10073. * This function handles the sequence abort accept iocb command complete
  10074. * event. It properly releases the memory allocated to the sequence abort
  10075. * accept iocb.
  10076. **/
  10077. static void
  10078. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10079. struct lpfc_iocbq *cmd_iocbq,
  10080. struct lpfc_iocbq *rsp_iocbq)
  10081. {
  10082. if (cmd_iocbq)
  10083. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10084. }
  10085. /**
  10086. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10087. * @phba: Pointer to HBA context object.
  10088. * @fc_hdr: pointer to a FC frame header.
  10089. *
  10090. * This function sends a basic accept to a previous unsol sequence abort
  10091. * event after aborting the sequence handling.
  10092. **/
  10093. static void
  10094. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10095. struct fc_frame_header *fc_hdr)
  10096. {
  10097. struct lpfc_iocbq *ctiocb = NULL;
  10098. struct lpfc_nodelist *ndlp;
  10099. uint16_t oxid, rxid;
  10100. uint32_t sid, fctl;
  10101. IOCB_t *icmd;
  10102. if (!lpfc_is_link_up(phba))
  10103. return;
  10104. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10105. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10106. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10107. ndlp = lpfc_findnode_did(phba->pport, sid);
  10108. if (!ndlp) {
  10109. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10110. "1268 Find ndlp returned NULL for oxid:x%x "
  10111. "SID:x%x\n", oxid, sid);
  10112. return;
  10113. }
  10114. /* Allocate buffer for acc iocb */
  10115. ctiocb = lpfc_sli_get_iocbq(phba);
  10116. if (!ctiocb)
  10117. return;
  10118. /* Extract the F_CTL field from FC_HDR */
  10119. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10120. icmd = &ctiocb->iocb;
  10121. icmd->un.xseq64.bdl.bdeSize = 0;
  10122. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10123. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10124. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10125. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10126. /* Fill in the rest of iocb fields */
  10127. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10128. icmd->ulpBdeCount = 0;
  10129. icmd->ulpLe = 1;
  10130. icmd->ulpClass = CLASS3;
  10131. icmd->ulpContext = ndlp->nlp_rpi;
  10132. ctiocb->iocb_cmpl = NULL;
  10133. ctiocb->vport = phba->pport;
  10134. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10135. if (fctl & FC_FC_EX_CTX) {
  10136. /* ABTS sent by responder to CT exchange, construction
  10137. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10138. * field and RX_ID from ABTS for RX_ID field.
  10139. */
  10140. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10141. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10142. ctiocb->sli4_xritag = oxid;
  10143. } else {
  10144. /* ABTS sent by initiator to CT exchange, construction
  10145. * of BA_ACC will need to allocate a new XRI as for the
  10146. * XRI_TAG and RX_ID fields.
  10147. */
  10148. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10149. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10150. ctiocb->sli4_xritag = NO_XRI;
  10151. }
  10152. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10153. /* Xmit CT abts accept on exchange <xid> */
  10154. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10155. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10156. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10157. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10158. }
  10159. /**
  10160. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10161. * @vport: Pointer to the vport on which this sequence was received
  10162. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10163. *
  10164. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10165. * receive sequence is only partially assembed by the driver, it shall abort
  10166. * the partially assembled frames for the sequence. Otherwise, if the
  10167. * unsolicited receive sequence has been completely assembled and passed to
  10168. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10169. * unsolicited sequence has been aborted. After that, it will issue a basic
  10170. * accept to accept the abort.
  10171. **/
  10172. void
  10173. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10174. struct hbq_dmabuf *dmabuf)
  10175. {
  10176. struct lpfc_hba *phba = vport->phba;
  10177. struct fc_frame_header fc_hdr;
  10178. uint32_t fctl;
  10179. bool abts_par;
  10180. /* Make a copy of fc_hdr before the dmabuf being released */
  10181. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10182. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10183. if (fctl & FC_FC_EX_CTX) {
  10184. /*
  10185. * ABTS sent by responder to exchange, just free the buffer
  10186. */
  10187. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10188. } else {
  10189. /*
  10190. * ABTS sent by initiator to exchange, need to do cleanup
  10191. */
  10192. /* Try to abort partially assembled seq */
  10193. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10194. /* Send abort to ULP if partially seq abort failed */
  10195. if (abts_par == false)
  10196. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10197. else
  10198. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10199. }
  10200. /* Send basic accept (BA_ACC) to the abort requester */
  10201. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10202. }
  10203. /**
  10204. * lpfc_seq_complete - Indicates if a sequence is complete
  10205. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10206. *
  10207. * This function checks the sequence, starting with the frame described by
  10208. * @dmabuf, to see if all the frames associated with this sequence are present.
  10209. * the frames associated with this sequence are linked to the @dmabuf using the
  10210. * dbuf list. This function looks for two major things. 1) That the first frame
  10211. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10212. * set. 3) That there are no holes in the sequence count. The function will
  10213. * return 1 when the sequence is complete, otherwise it will return 0.
  10214. **/
  10215. static int
  10216. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10217. {
  10218. struct fc_frame_header *hdr;
  10219. struct lpfc_dmabuf *d_buf;
  10220. struct hbq_dmabuf *seq_dmabuf;
  10221. uint32_t fctl;
  10222. int seq_count = 0;
  10223. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10224. /* make sure first fame of sequence has a sequence count of zero */
  10225. if (hdr->fh_seq_cnt != seq_count)
  10226. return 0;
  10227. fctl = (hdr->fh_f_ctl[0] << 16 |
  10228. hdr->fh_f_ctl[1] << 8 |
  10229. hdr->fh_f_ctl[2]);
  10230. /* If last frame of sequence we can return success. */
  10231. if (fctl & FC_FC_END_SEQ)
  10232. return 1;
  10233. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10234. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10235. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10236. /* If there is a hole in the sequence count then fail. */
  10237. if (++seq_count != hdr->fh_seq_cnt)
  10238. return 0;
  10239. fctl = (hdr->fh_f_ctl[0] << 16 |
  10240. hdr->fh_f_ctl[1] << 8 |
  10241. hdr->fh_f_ctl[2]);
  10242. /* If last frame of sequence we can return success. */
  10243. if (fctl & FC_FC_END_SEQ)
  10244. return 1;
  10245. }
  10246. return 0;
  10247. }
  10248. /**
  10249. * lpfc_prep_seq - Prep sequence for ULP processing
  10250. * @vport: Pointer to the vport on which this sequence was received
  10251. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10252. *
  10253. * This function takes a sequence, described by a list of frames, and creates
  10254. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10255. * used to issue to the generic unsolicited sequence handler. This routine
  10256. * returns a pointer to the first iocbq in the list. If the function is unable
  10257. * to allocate an iocbq then it throw out the received frames that were not
  10258. * able to be described and return a pointer to the first iocbq. If unable to
  10259. * allocate any iocbqs (including the first) this function will return NULL.
  10260. **/
  10261. static struct lpfc_iocbq *
  10262. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10263. {
  10264. struct lpfc_dmabuf *d_buf, *n_buf;
  10265. struct lpfc_iocbq *first_iocbq, *iocbq;
  10266. struct fc_frame_header *fc_hdr;
  10267. uint32_t sid;
  10268. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10269. /* remove from receive buffer list */
  10270. list_del_init(&seq_dmabuf->hbuf.list);
  10271. lpfc_update_rcv_time_stamp(vport);
  10272. /* get the Remote Port's SID */
  10273. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10274. /* Get an iocbq struct to fill in. */
  10275. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10276. if (first_iocbq) {
  10277. /* Initialize the first IOCB. */
  10278. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10279. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10280. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10281. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10282. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10283. vport->vpi + vport->phba->vpi_base;
  10284. /* put the first buffer into the first IOCBq */
  10285. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10286. first_iocbq->context3 = NULL;
  10287. first_iocbq->iocb.ulpBdeCount = 1;
  10288. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10289. LPFC_DATA_BUF_SIZE;
  10290. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10291. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10292. bf_get(lpfc_rcqe_length,
  10293. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10294. }
  10295. iocbq = first_iocbq;
  10296. /*
  10297. * Each IOCBq can have two Buffers assigned, so go through the list
  10298. * of buffers for this sequence and save two buffers in each IOCBq
  10299. */
  10300. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10301. if (!iocbq) {
  10302. lpfc_in_buf_free(vport->phba, d_buf);
  10303. continue;
  10304. }
  10305. if (!iocbq->context3) {
  10306. iocbq->context3 = d_buf;
  10307. iocbq->iocb.ulpBdeCount++;
  10308. iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
  10309. LPFC_DATA_BUF_SIZE;
  10310. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10311. bf_get(lpfc_rcqe_length,
  10312. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10313. } else {
  10314. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10315. if (!iocbq) {
  10316. if (first_iocbq) {
  10317. first_iocbq->iocb.ulpStatus =
  10318. IOSTAT_FCP_RSP_ERROR;
  10319. first_iocbq->iocb.un.ulpWord[4] =
  10320. IOERR_NO_RESOURCES;
  10321. }
  10322. lpfc_in_buf_free(vport->phba, d_buf);
  10323. continue;
  10324. }
  10325. iocbq->context2 = d_buf;
  10326. iocbq->context3 = NULL;
  10327. iocbq->iocb.ulpBdeCount = 1;
  10328. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10329. LPFC_DATA_BUF_SIZE;
  10330. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10331. bf_get(lpfc_rcqe_length,
  10332. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10333. iocbq->iocb.un.rcvels.remoteID = sid;
  10334. list_add_tail(&iocbq->list, &first_iocbq->list);
  10335. }
  10336. }
  10337. return first_iocbq;
  10338. }
  10339. static void
  10340. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10341. struct hbq_dmabuf *seq_dmabuf)
  10342. {
  10343. struct fc_frame_header *fc_hdr;
  10344. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10345. struct lpfc_hba *phba = vport->phba;
  10346. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10347. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10348. if (!iocbq) {
  10349. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10350. "2707 Ring %d handler: Failed to allocate "
  10351. "iocb Rctl x%x Type x%x received\n",
  10352. LPFC_ELS_RING,
  10353. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10354. return;
  10355. }
  10356. if (!lpfc_complete_unsol_iocb(phba,
  10357. &phba->sli.ring[LPFC_ELS_RING],
  10358. iocbq, fc_hdr->fh_r_ctl,
  10359. fc_hdr->fh_type))
  10360. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10361. "2540 Ring %d handler: unexpected Rctl "
  10362. "x%x Type x%x received\n",
  10363. LPFC_ELS_RING,
  10364. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10365. /* Free iocb created in lpfc_prep_seq */
  10366. list_for_each_entry_safe(curr_iocb, next_iocb,
  10367. &iocbq->list, list) {
  10368. list_del_init(&curr_iocb->list);
  10369. lpfc_sli_release_iocbq(phba, curr_iocb);
  10370. }
  10371. lpfc_sli_release_iocbq(phba, iocbq);
  10372. }
  10373. /**
  10374. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10375. * @phba: Pointer to HBA context object.
  10376. *
  10377. * This function is called with no lock held. This function processes all
  10378. * the received buffers and gives it to upper layers when a received buffer
  10379. * indicates that it is the final frame in the sequence. The interrupt
  10380. * service routine processes received buffers at interrupt contexts and adds
  10381. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10382. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10383. * appropriate receive function when the final frame in a sequence is received.
  10384. **/
  10385. void
  10386. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10387. struct hbq_dmabuf *dmabuf)
  10388. {
  10389. struct hbq_dmabuf *seq_dmabuf;
  10390. struct fc_frame_header *fc_hdr;
  10391. struct lpfc_vport *vport;
  10392. uint32_t fcfi;
  10393. /* Process each received buffer */
  10394. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10395. /* check to see if this a valid type of frame */
  10396. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10397. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10398. return;
  10399. }
  10400. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10401. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10402. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10403. /* throw out the frame */
  10404. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10405. return;
  10406. }
  10407. /* Handle the basic abort sequence (BA_ABTS) event */
  10408. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10409. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10410. return;
  10411. }
  10412. /* Link this frame */
  10413. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10414. if (!seq_dmabuf) {
  10415. /* unable to add frame to vport - throw it out */
  10416. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10417. return;
  10418. }
  10419. /* If not last frame in sequence continue processing frames. */
  10420. if (!lpfc_seq_complete(seq_dmabuf)) {
  10421. /*
  10422. * When saving off frames post a new one and mark this
  10423. * frame to be freed when it is finished.
  10424. **/
  10425. lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
  10426. dmabuf->tag = -1;
  10427. return;
  10428. }
  10429. /* Send the complete sequence to the upper layer protocol */
  10430. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10431. }
  10432. /**
  10433. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10434. * @phba: pointer to lpfc hba data structure.
  10435. *
  10436. * This routine is invoked to post rpi header templates to the
  10437. * HBA consistent with the SLI-4 interface spec. This routine
  10438. * posts a PAGE_SIZE memory region to the port to hold up to
  10439. * PAGE_SIZE modulo 64 rpi context headers.
  10440. *
  10441. * This routine does not require any locks. It's usage is expected
  10442. * to be driver load or reset recovery when the driver is
  10443. * sequential.
  10444. *
  10445. * Return codes
  10446. * 0 - successful
  10447. * EIO - The mailbox failed to complete successfully.
  10448. * When this error occurs, the driver is not guaranteed
  10449. * to have any rpi regions posted to the device and
  10450. * must either attempt to repost the regions or take a
  10451. * fatal error.
  10452. **/
  10453. int
  10454. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10455. {
  10456. struct lpfc_rpi_hdr *rpi_page;
  10457. uint32_t rc = 0;
  10458. /* Post all rpi memory regions to the port. */
  10459. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10460. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10461. if (rc != MBX_SUCCESS) {
  10462. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10463. "2008 Error %d posting all rpi "
  10464. "headers\n", rc);
  10465. rc = -EIO;
  10466. break;
  10467. }
  10468. }
  10469. return rc;
  10470. }
  10471. /**
  10472. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10473. * @phba: pointer to lpfc hba data structure.
  10474. * @rpi_page: pointer to the rpi memory region.
  10475. *
  10476. * This routine is invoked to post a single rpi header to the
  10477. * HBA consistent with the SLI-4 interface spec. This memory region
  10478. * maps up to 64 rpi context regions.
  10479. *
  10480. * Return codes
  10481. * 0 - successful
  10482. * ENOMEM - No available memory
  10483. * EIO - The mailbox failed to complete successfully.
  10484. **/
  10485. int
  10486. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10487. {
  10488. LPFC_MBOXQ_t *mboxq;
  10489. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10490. uint32_t rc = 0;
  10491. uint32_t mbox_tmo;
  10492. uint32_t shdr_status, shdr_add_status;
  10493. union lpfc_sli4_cfg_shdr *shdr;
  10494. /* The port is notified of the header region via a mailbox command. */
  10495. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10496. if (!mboxq) {
  10497. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10498. "2001 Unable to allocate memory for issuing "
  10499. "SLI_CONFIG_SPECIAL mailbox command\n");
  10500. return -ENOMEM;
  10501. }
  10502. /* Post all rpi memory regions to the port. */
  10503. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10504. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10505. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10506. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10507. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10508. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10509. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10510. hdr_tmpl, rpi_page->page_count);
  10511. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10512. rpi_page->start_rpi);
  10513. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10514. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10515. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10516. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10517. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10518. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10519. if (rc != MBX_TIMEOUT)
  10520. mempool_free(mboxq, phba->mbox_mem_pool);
  10521. if (shdr_status || shdr_add_status || rc) {
  10522. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10523. "2514 POST_RPI_HDR mailbox failed with "
  10524. "status x%x add_status x%x, mbx status x%x\n",
  10525. shdr_status, shdr_add_status, rc);
  10526. rc = -ENXIO;
  10527. }
  10528. return rc;
  10529. }
  10530. /**
  10531. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10532. * @phba: pointer to lpfc hba data structure.
  10533. *
  10534. * This routine is invoked to post rpi header templates to the
  10535. * HBA consistent with the SLI-4 interface spec. This routine
  10536. * posts a PAGE_SIZE memory region to the port to hold up to
  10537. * PAGE_SIZE modulo 64 rpi context headers.
  10538. *
  10539. * Returns
  10540. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10541. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10542. **/
  10543. int
  10544. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10545. {
  10546. int rpi;
  10547. uint16_t max_rpi, rpi_base, rpi_limit;
  10548. uint16_t rpi_remaining;
  10549. struct lpfc_rpi_hdr *rpi_hdr;
  10550. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10551. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10552. rpi_limit = phba->sli4_hba.next_rpi;
  10553. /*
  10554. * The valid rpi range is not guaranteed to be zero-based. Start
  10555. * the search at the rpi_base as reported by the port.
  10556. */
  10557. spin_lock_irq(&phba->hbalock);
  10558. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10559. if (rpi >= rpi_limit || rpi < rpi_base)
  10560. rpi = LPFC_RPI_ALLOC_ERROR;
  10561. else {
  10562. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10563. phba->sli4_hba.max_cfg_param.rpi_used++;
  10564. phba->sli4_hba.rpi_count++;
  10565. }
  10566. /*
  10567. * Don't try to allocate more rpi header regions if the device limit
  10568. * on available rpis max has been exhausted.
  10569. */
  10570. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10571. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10572. spin_unlock_irq(&phba->hbalock);
  10573. return rpi;
  10574. }
  10575. /*
  10576. * If the driver is running low on rpi resources, allocate another
  10577. * page now. Note that the next_rpi value is used because
  10578. * it represents how many are actually in use whereas max_rpi notes
  10579. * how many are supported max by the device.
  10580. */
  10581. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10582. phba->sli4_hba.rpi_count;
  10583. spin_unlock_irq(&phba->hbalock);
  10584. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10585. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10586. if (!rpi_hdr) {
  10587. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10588. "2002 Error Could not grow rpi "
  10589. "count\n");
  10590. } else {
  10591. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10592. }
  10593. }
  10594. return rpi;
  10595. }
  10596. /**
  10597. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10598. * @phba: pointer to lpfc hba data structure.
  10599. *
  10600. * This routine is invoked to release an rpi to the pool of
  10601. * available rpis maintained by the driver.
  10602. **/
  10603. void
  10604. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10605. {
  10606. spin_lock_irq(&phba->hbalock);
  10607. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10608. phba->sli4_hba.rpi_count--;
  10609. phba->sli4_hba.max_cfg_param.rpi_used--;
  10610. spin_unlock_irq(&phba->hbalock);
  10611. }
  10612. /**
  10613. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10614. * @phba: pointer to lpfc hba data structure.
  10615. *
  10616. * This routine is invoked to remove the memory region that
  10617. * provided rpi via a bitmask.
  10618. **/
  10619. void
  10620. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10621. {
  10622. kfree(phba->sli4_hba.rpi_bmask);
  10623. }
  10624. /**
  10625. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10626. * @phba: pointer to lpfc hba data structure.
  10627. *
  10628. * This routine is invoked to remove the memory region that
  10629. * provided rpi via a bitmask.
  10630. **/
  10631. int
  10632. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10633. {
  10634. LPFC_MBOXQ_t *mboxq;
  10635. struct lpfc_hba *phba = ndlp->phba;
  10636. int rc;
  10637. /* The port is notified of the header region via a mailbox command. */
  10638. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10639. if (!mboxq)
  10640. return -ENOMEM;
  10641. /* Post all rpi memory regions to the port. */
  10642. lpfc_resume_rpi(mboxq, ndlp);
  10643. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10644. if (rc == MBX_NOT_FINISHED) {
  10645. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10646. "2010 Resume RPI Mailbox failed "
  10647. "status %d, mbxStatus x%x\n", rc,
  10648. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10649. mempool_free(mboxq, phba->mbox_mem_pool);
  10650. return -EIO;
  10651. }
  10652. return 0;
  10653. }
  10654. /**
  10655. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10656. * @phba: pointer to lpfc hba data structure.
  10657. * @vpi: vpi value to activate with the port.
  10658. *
  10659. * This routine is invoked to activate a vpi with the
  10660. * port when the host intends to use vports with a
  10661. * nonzero vpi.
  10662. *
  10663. * Returns:
  10664. * 0 success
  10665. * -Evalue otherwise
  10666. **/
  10667. int
  10668. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10669. {
  10670. LPFC_MBOXQ_t *mboxq;
  10671. int rc = 0;
  10672. int retval = MBX_SUCCESS;
  10673. uint32_t mbox_tmo;
  10674. if (vpi == 0)
  10675. return -EINVAL;
  10676. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10677. if (!mboxq)
  10678. return -ENOMEM;
  10679. lpfc_init_vpi(phba, mboxq, vpi);
  10680. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10681. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10682. if (rc != MBX_SUCCESS) {
  10683. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10684. "2022 INIT VPI Mailbox failed "
  10685. "status %d, mbxStatus x%x\n", rc,
  10686. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10687. retval = -EIO;
  10688. }
  10689. if (rc != MBX_TIMEOUT)
  10690. mempool_free(mboxq, phba->mbox_mem_pool);
  10691. return retval;
  10692. }
  10693. /**
  10694. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10695. * @phba: pointer to lpfc hba data structure.
  10696. * @mboxq: Pointer to mailbox object.
  10697. *
  10698. * This routine is invoked to manually add a single FCF record. The caller
  10699. * must pass a completely initialized FCF_Record. This routine takes
  10700. * care of the nonembedded mailbox operations.
  10701. **/
  10702. static void
  10703. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10704. {
  10705. void *virt_addr;
  10706. union lpfc_sli4_cfg_shdr *shdr;
  10707. uint32_t shdr_status, shdr_add_status;
  10708. virt_addr = mboxq->sge_array->addr[0];
  10709. /* The IOCTL status is embedded in the mailbox subheader. */
  10710. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10711. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10712. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10713. if ((shdr_status || shdr_add_status) &&
  10714. (shdr_status != STATUS_FCF_IN_USE))
  10715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10716. "2558 ADD_FCF_RECORD mailbox failed with "
  10717. "status x%x add_status x%x\n",
  10718. shdr_status, shdr_add_status);
  10719. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10720. }
  10721. /**
  10722. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10723. * @phba: pointer to lpfc hba data structure.
  10724. * @fcf_record: pointer to the initialized fcf record to add.
  10725. *
  10726. * This routine is invoked to manually add a single FCF record. The caller
  10727. * must pass a completely initialized FCF_Record. This routine takes
  10728. * care of the nonembedded mailbox operations.
  10729. **/
  10730. int
  10731. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10732. {
  10733. int rc = 0;
  10734. LPFC_MBOXQ_t *mboxq;
  10735. uint8_t *bytep;
  10736. void *virt_addr;
  10737. dma_addr_t phys_addr;
  10738. struct lpfc_mbx_sge sge;
  10739. uint32_t alloc_len, req_len;
  10740. uint32_t fcfindex;
  10741. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10742. if (!mboxq) {
  10743. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10744. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10745. return -ENOMEM;
  10746. }
  10747. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10748. sizeof(uint32_t);
  10749. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10750. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10751. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10752. req_len, LPFC_SLI4_MBX_NEMBED);
  10753. if (alloc_len < req_len) {
  10754. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10755. "2523 Allocated DMA memory size (x%x) is "
  10756. "less than the requested DMA memory "
  10757. "size (x%x)\n", alloc_len, req_len);
  10758. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10759. return -ENOMEM;
  10760. }
  10761. /*
  10762. * Get the first SGE entry from the non-embedded DMA memory. This
  10763. * routine only uses a single SGE.
  10764. */
  10765. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10766. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10767. virt_addr = mboxq->sge_array->addr[0];
  10768. /*
  10769. * Configure the FCF record for FCFI 0. This is the driver's
  10770. * hardcoded default and gets used in nonFIP mode.
  10771. */
  10772. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10773. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10774. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10775. /*
  10776. * Copy the fcf_index and the FCF Record Data. The data starts after
  10777. * the FCoE header plus word10. The data copy needs to be endian
  10778. * correct.
  10779. */
  10780. bytep += sizeof(uint32_t);
  10781. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10782. mboxq->vport = phba->pport;
  10783. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10784. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10785. if (rc == MBX_NOT_FINISHED) {
  10786. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10787. "2515 ADD_FCF_RECORD mailbox failed with "
  10788. "status 0x%x\n", rc);
  10789. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10790. rc = -EIO;
  10791. } else
  10792. rc = 0;
  10793. return rc;
  10794. }
  10795. /**
  10796. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10797. * @phba: pointer to lpfc hba data structure.
  10798. * @fcf_record: pointer to the fcf record to write the default data.
  10799. * @fcf_index: FCF table entry index.
  10800. *
  10801. * This routine is invoked to build the driver's default FCF record. The
  10802. * values used are hardcoded. This routine handles memory initialization.
  10803. *
  10804. **/
  10805. void
  10806. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10807. struct fcf_record *fcf_record,
  10808. uint16_t fcf_index)
  10809. {
  10810. memset(fcf_record, 0, sizeof(struct fcf_record));
  10811. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10812. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10813. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10814. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10815. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10816. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10817. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10818. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10819. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10820. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10821. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10822. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10823. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10824. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10825. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10826. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10827. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10828. /* Set the VLAN bit map */
  10829. if (phba->valid_vlan) {
  10830. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10831. = 1 << (phba->vlan_id % 8);
  10832. }
  10833. }
  10834. /**
  10835. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10836. * @phba: pointer to lpfc hba data structure.
  10837. * @fcf_index: FCF table entry offset.
  10838. *
  10839. * This routine is invoked to read up to @fcf_num of FCF record from the
  10840. * device starting with the given @fcf_index.
  10841. **/
  10842. int
  10843. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10844. {
  10845. int rc = 0, error;
  10846. LPFC_MBOXQ_t *mboxq;
  10847. void *virt_addr;
  10848. dma_addr_t phys_addr;
  10849. uint8_t *bytep;
  10850. struct lpfc_mbx_sge sge;
  10851. uint32_t alloc_len, req_len;
  10852. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10853. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10854. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10855. if (!mboxq) {
  10856. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10857. "2000 Failed to allocate mbox for "
  10858. "READ_FCF cmd\n");
  10859. error = -ENOMEM;
  10860. goto fail_fcfscan;
  10861. }
  10862. req_len = sizeof(struct fcf_record) +
  10863. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10864. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10865. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10866. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10867. LPFC_SLI4_MBX_NEMBED);
  10868. if (alloc_len < req_len) {
  10869. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10870. "0291 Allocated DMA memory size (x%x) is "
  10871. "less than the requested DMA memory "
  10872. "size (x%x)\n", alloc_len, req_len);
  10873. error = -ENOMEM;
  10874. goto fail_fcfscan;
  10875. }
  10876. /* Get the first SGE entry from the non-embedded DMA memory. This
  10877. * routine only uses a single SGE.
  10878. */
  10879. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10880. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10881. virt_addr = mboxq->sge_array->addr[0];
  10882. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10883. /* Set up command fields */
  10884. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10885. /* Perform necessary endian conversion */
  10886. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10887. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10888. mboxq->vport = phba->pport;
  10889. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10890. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10891. if (rc == MBX_NOT_FINISHED) {
  10892. error = -EIO;
  10893. } else {
  10894. spin_lock_irq(&phba->hbalock);
  10895. phba->hba_flag |= FCF_DISC_INPROGRESS;
  10896. spin_unlock_irq(&phba->hbalock);
  10897. error = 0;
  10898. }
  10899. fail_fcfscan:
  10900. if (error) {
  10901. if (mboxq)
  10902. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10903. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  10904. spin_lock_irq(&phba->hbalock);
  10905. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  10906. spin_unlock_irq(&phba->hbalock);
  10907. }
  10908. return error;
  10909. }
  10910. /**
  10911. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  10912. * @phba: pointer to lpfc hba data structure.
  10913. *
  10914. * This function read region 23 and parse TLV for port status to
  10915. * decide if the user disaled the port. If the TLV indicates the
  10916. * port is disabled, the hba_flag is set accordingly.
  10917. **/
  10918. void
  10919. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  10920. {
  10921. LPFC_MBOXQ_t *pmb = NULL;
  10922. MAILBOX_t *mb;
  10923. uint8_t *rgn23_data = NULL;
  10924. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  10925. int rc;
  10926. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10927. if (!pmb) {
  10928. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10929. "2600 lpfc_sli_read_serdes_param failed to"
  10930. " allocate mailbox memory\n");
  10931. goto out;
  10932. }
  10933. mb = &pmb->u.mb;
  10934. /* Get adapter Region 23 data */
  10935. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  10936. if (!rgn23_data)
  10937. goto out;
  10938. do {
  10939. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  10940. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  10941. if (rc != MBX_SUCCESS) {
  10942. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10943. "2601 lpfc_sli_read_link_ste failed to"
  10944. " read config region 23 rc 0x%x Status 0x%x\n",
  10945. rc, mb->mbxStatus);
  10946. mb->un.varDmp.word_cnt = 0;
  10947. }
  10948. /*
  10949. * dump mem may return a zero when finished or we got a
  10950. * mailbox error, either way we are done.
  10951. */
  10952. if (mb->un.varDmp.word_cnt == 0)
  10953. break;
  10954. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  10955. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  10956. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  10957. rgn23_data + offset,
  10958. mb->un.varDmp.word_cnt);
  10959. offset += mb->un.varDmp.word_cnt;
  10960. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  10961. data_size = offset;
  10962. offset = 0;
  10963. if (!data_size)
  10964. goto out;
  10965. /* Check the region signature first */
  10966. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  10967. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10968. "2619 Config region 23 has bad signature\n");
  10969. goto out;
  10970. }
  10971. offset += 4;
  10972. /* Check the data structure version */
  10973. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  10974. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10975. "2620 Config region 23 has bad version\n");
  10976. goto out;
  10977. }
  10978. offset += 4;
  10979. /* Parse TLV entries in the region */
  10980. while (offset < data_size) {
  10981. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  10982. break;
  10983. /*
  10984. * If the TLV is not driver specific TLV or driver id is
  10985. * not linux driver id, skip the record.
  10986. */
  10987. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  10988. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  10989. (rgn23_data[offset + 3] != 0)) {
  10990. offset += rgn23_data[offset + 1] * 4 + 4;
  10991. continue;
  10992. }
  10993. /* Driver found a driver specific TLV in the config region */
  10994. sub_tlv_len = rgn23_data[offset + 1] * 4;
  10995. offset += 4;
  10996. tlv_offset = 0;
  10997. /*
  10998. * Search for configured port state sub-TLV.
  10999. */
  11000. while ((offset < data_size) &&
  11001. (tlv_offset < sub_tlv_len)) {
  11002. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11003. offset += 4;
  11004. tlv_offset += 4;
  11005. break;
  11006. }
  11007. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11008. offset += rgn23_data[offset + 1] * 4 + 4;
  11009. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11010. continue;
  11011. }
  11012. /* This HBA contains PORT_STE configured */
  11013. if (!rgn23_data[offset + 2])
  11014. phba->hba_flag |= LINK_DISABLED;
  11015. goto out;
  11016. }
  11017. }
  11018. out:
  11019. if (pmb)
  11020. mempool_free(pmb, phba->mbox_mem_pool);
  11021. kfree(rgn23_data);
  11022. return;
  11023. }