lpfc_sli.c 416 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  473. * @phba: Pointer to HBA context object.
  474. * @ndlp: nodelist pointer for this target.
  475. * @xritag: xri used in this exchange.
  476. * @rxid: Remote Exchange ID.
  477. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  478. *
  479. * This function is called with hbalock held.
  480. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  481. * rrq struct and adds it to the active_rrq_list.
  482. *
  483. * returns 0 for rrq slot for this xri
  484. * < 0 Were not able to get rrq mem or invalid parameter.
  485. **/
  486. static int
  487. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  488. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  489. {
  490. uint16_t adj_xri;
  491. struct lpfc_node_rrq *rrq;
  492. int empty;
  493. /*
  494. * set the active bit even if there is no mem available.
  495. */
  496. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  497. if (!ndlp)
  498. return -EINVAL;
  499. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  500. return -EINVAL;
  501. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  502. if (rrq) {
  503. rrq->send_rrq = send_rrq;
  504. rrq->xritag = xritag;
  505. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  506. rrq->ndlp = ndlp;
  507. rrq->nlp_DID = ndlp->nlp_DID;
  508. rrq->vport = ndlp->vport;
  509. rrq->rxid = rxid;
  510. empty = list_empty(&phba->active_rrq_list);
  511. if (phba->cfg_enable_rrq && send_rrq)
  512. /*
  513. * We need the xri before we can add this to the
  514. * phba active rrq list.
  515. */
  516. rrq->send_rrq = send_rrq;
  517. else
  518. rrq->send_rrq = 0;
  519. list_add_tail(&rrq->list, &phba->active_rrq_list);
  520. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  521. phba->hba_flag |= HBA_RRQ_ACTIVE;
  522. if (empty)
  523. lpfc_worker_wake_up(phba);
  524. }
  525. return 0;
  526. }
  527. return -ENOMEM;
  528. }
  529. /**
  530. * __lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  531. * @phba: Pointer to HBA context object.
  532. * @xritag: xri used in this exchange.
  533. * @rrq: The RRQ to be cleared.
  534. *
  535. * This function is called with hbalock held. This function
  536. **/
  537. static void
  538. __lpfc_clr_rrq_active(struct lpfc_hba *phba,
  539. uint16_t xritag,
  540. struct lpfc_node_rrq *rrq)
  541. {
  542. uint16_t adj_xri;
  543. struct lpfc_nodelist *ndlp;
  544. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  545. /* The target DID could have been swapped (cable swap)
  546. * we should use the ndlp from the findnode if it is
  547. * available.
  548. */
  549. if (!ndlp)
  550. ndlp = rrq->ndlp;
  551. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  552. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  553. rrq->send_rrq = 0;
  554. rrq->xritag = 0;
  555. rrq->rrq_stop_time = 0;
  556. }
  557. mempool_free(rrq, phba->rrq_pool);
  558. }
  559. /**
  560. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  561. * @phba: Pointer to HBA context object.
  562. *
  563. * This function is called with hbalock held. This function
  564. * Checks if stop_time (ratov from setting rrq active) has
  565. * been reached, if it has and the send_rrq flag is set then
  566. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  567. * then it will just call the routine to clear the rrq and
  568. * free the rrq resource.
  569. * The timer is set to the next rrq that is going to expire before
  570. * leaving the routine.
  571. *
  572. **/
  573. void
  574. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  575. {
  576. struct lpfc_node_rrq *rrq;
  577. struct lpfc_node_rrq *nextrrq;
  578. unsigned long next_time;
  579. unsigned long iflags;
  580. spin_lock_irqsave(&phba->hbalock, iflags);
  581. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  582. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  583. list_for_each_entry_safe(rrq, nextrrq,
  584. &phba->active_rrq_list, list) {
  585. if (time_after(jiffies, rrq->rrq_stop_time)) {
  586. list_del(&rrq->list);
  587. if (!rrq->send_rrq)
  588. /* this call will free the rrq */
  589. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  590. else {
  591. /* if we send the rrq then the completion handler
  592. * will clear the bit in the xribitmap.
  593. */
  594. spin_unlock_irqrestore(&phba->hbalock, iflags);
  595. if (lpfc_send_rrq(phba, rrq)) {
  596. lpfc_clr_rrq_active(phba, rrq->xritag,
  597. rrq);
  598. }
  599. spin_lock_irqsave(&phba->hbalock, iflags);
  600. }
  601. } else if (time_before(rrq->rrq_stop_time, next_time))
  602. next_time = rrq->rrq_stop_time;
  603. }
  604. spin_unlock_irqrestore(&phba->hbalock, iflags);
  605. if (!list_empty(&phba->active_rrq_list))
  606. mod_timer(&phba->rrq_tmr, next_time);
  607. }
  608. /**
  609. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  610. * @vport: Pointer to vport context object.
  611. * @xri: The xri used in the exchange.
  612. * @did: The targets DID for this exchange.
  613. *
  614. * returns NULL = rrq not found in the phba->active_rrq_list.
  615. * rrq = rrq for this xri and target.
  616. **/
  617. struct lpfc_node_rrq *
  618. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  619. {
  620. struct lpfc_hba *phba = vport->phba;
  621. struct lpfc_node_rrq *rrq;
  622. struct lpfc_node_rrq *nextrrq;
  623. unsigned long iflags;
  624. if (phba->sli_rev != LPFC_SLI_REV4)
  625. return NULL;
  626. spin_lock_irqsave(&phba->hbalock, iflags);
  627. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  628. if (rrq->vport == vport && rrq->xritag == xri &&
  629. rrq->nlp_DID == did){
  630. list_del(&rrq->list);
  631. spin_unlock_irqrestore(&phba->hbalock, iflags);
  632. return rrq;
  633. }
  634. }
  635. spin_unlock_irqrestore(&phba->hbalock, iflags);
  636. return NULL;
  637. }
  638. /**
  639. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  640. * @vport: Pointer to vport context object.
  641. *
  642. * Remove all active RRQs for this vport from the phba->active_rrq_list and
  643. * clear the rrq.
  644. **/
  645. void
  646. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport)
  647. {
  648. struct lpfc_hba *phba = vport->phba;
  649. struct lpfc_node_rrq *rrq;
  650. struct lpfc_node_rrq *nextrrq;
  651. unsigned long iflags;
  652. if (phba->sli_rev != LPFC_SLI_REV4)
  653. return;
  654. spin_lock_irqsave(&phba->hbalock, iflags);
  655. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  656. if (rrq->vport == vport) {
  657. list_del(&rrq->list);
  658. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  659. }
  660. }
  661. spin_unlock_irqrestore(&phba->hbalock, iflags);
  662. }
  663. /**
  664. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  665. * @phba: Pointer to HBA context object.
  666. *
  667. * Remove all rrqs from the phba->active_rrq_list and free them by
  668. * calling __lpfc_clr_active_rrq
  669. *
  670. **/
  671. void
  672. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  673. {
  674. struct lpfc_node_rrq *rrq;
  675. struct lpfc_node_rrq *nextrrq;
  676. unsigned long next_time;
  677. unsigned long iflags;
  678. if (phba->sli_rev != LPFC_SLI_REV4)
  679. return;
  680. spin_lock_irqsave(&phba->hbalock, iflags);
  681. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  682. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  683. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  684. list_del(&rrq->list);
  685. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  686. }
  687. spin_unlock_irqrestore(&phba->hbalock, iflags);
  688. if (!list_empty(&phba->active_rrq_list))
  689. mod_timer(&phba->rrq_tmr, next_time);
  690. }
  691. /**
  692. * __lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  693. * @phba: Pointer to HBA context object.
  694. * @ndlp: Targets nodelist pointer for this exchange.
  695. * @xritag the xri in the bitmap to test.
  696. *
  697. * This function is called with hbalock held. This function
  698. * returns 0 = rrq not active for this xri
  699. * 1 = rrq is valid for this xri.
  700. **/
  701. static int
  702. __lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  703. uint16_t xritag)
  704. {
  705. uint16_t adj_xri;
  706. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  707. if (!ndlp)
  708. return 0;
  709. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  710. return 1;
  711. else
  712. return 0;
  713. }
  714. /**
  715. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  716. * @phba: Pointer to HBA context object.
  717. * @ndlp: nodelist pointer for this target.
  718. * @xritag: xri used in this exchange.
  719. * @rxid: Remote Exchange ID.
  720. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  721. *
  722. * This function takes the hbalock.
  723. * The active bit is always set in the active rrq xri_bitmap even
  724. * if there is no slot avaiable for the other rrq information.
  725. *
  726. * returns 0 rrq actived for this xri
  727. * < 0 No memory or invalid ndlp.
  728. **/
  729. int
  730. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  731. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  732. {
  733. int ret;
  734. unsigned long iflags;
  735. spin_lock_irqsave(&phba->hbalock, iflags);
  736. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  737. spin_unlock_irqrestore(&phba->hbalock, iflags);
  738. return ret;
  739. }
  740. /**
  741. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  742. * @phba: Pointer to HBA context object.
  743. * @xritag: xri used in this exchange.
  744. * @rrq: The RRQ to be cleared.
  745. *
  746. * This function is takes the hbalock.
  747. **/
  748. void
  749. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  750. uint16_t xritag,
  751. struct lpfc_node_rrq *rrq)
  752. {
  753. unsigned long iflags;
  754. spin_lock_irqsave(&phba->hbalock, iflags);
  755. __lpfc_clr_rrq_active(phba, xritag, rrq);
  756. spin_unlock_irqrestore(&phba->hbalock, iflags);
  757. return;
  758. }
  759. /**
  760. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  761. * @phba: Pointer to HBA context object.
  762. * @ndlp: Targets nodelist pointer for this exchange.
  763. * @xritag the xri in the bitmap to test.
  764. *
  765. * This function takes the hbalock.
  766. * returns 0 = rrq not active for this xri
  767. * 1 = rrq is valid for this xri.
  768. **/
  769. int
  770. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  771. uint16_t xritag)
  772. {
  773. int ret;
  774. unsigned long iflags;
  775. spin_lock_irqsave(&phba->hbalock, iflags);
  776. ret = __lpfc_test_rrq_active(phba, ndlp, xritag);
  777. spin_unlock_irqrestore(&phba->hbalock, iflags);
  778. return ret;
  779. }
  780. /**
  781. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  782. * @phba: Pointer to HBA context object.
  783. * @piocb: Pointer to the iocbq.
  784. *
  785. * This function is called with hbalock held. This function
  786. * Gets a new driver sglq object from the sglq list. If the
  787. * list is not empty then it is successful, it returns pointer to the newly
  788. * allocated sglq object else it returns NULL.
  789. **/
  790. static struct lpfc_sglq *
  791. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  792. {
  793. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  794. struct lpfc_sglq *sglq = NULL;
  795. struct lpfc_sglq *start_sglq = NULL;
  796. uint16_t adj_xri;
  797. struct lpfc_scsi_buf *lpfc_cmd;
  798. struct lpfc_nodelist *ndlp;
  799. int found = 0;
  800. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  801. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  802. ndlp = lpfc_cmd->rdata->pnode;
  803. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  804. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  805. ndlp = piocbq->context_un.ndlp;
  806. else
  807. ndlp = piocbq->context1;
  808. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  809. start_sglq = sglq;
  810. while (!found) {
  811. if (!sglq)
  812. return NULL;
  813. adj_xri = sglq->sli4_xritag -
  814. phba->sli4_hba.max_cfg_param.xri_base;
  815. if (__lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  816. /* This xri has an rrq outstanding for this DID.
  817. * put it back in the list and get another xri.
  818. */
  819. list_add_tail(&sglq->list, lpfc_sgl_list);
  820. sglq = NULL;
  821. list_remove_head(lpfc_sgl_list, sglq,
  822. struct lpfc_sglq, list);
  823. if (sglq == start_sglq) {
  824. sglq = NULL;
  825. break;
  826. } else
  827. continue;
  828. }
  829. sglq->ndlp = ndlp;
  830. found = 1;
  831. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  832. sglq->state = SGL_ALLOCATED;
  833. }
  834. return sglq;
  835. }
  836. /**
  837. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  838. * @phba: Pointer to HBA context object.
  839. *
  840. * This function is called with no lock held. This function
  841. * allocates a new driver iocb object from the iocb pool. If the
  842. * allocation is successful, it returns pointer to the newly
  843. * allocated iocb object else it returns NULL.
  844. **/
  845. struct lpfc_iocbq *
  846. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  847. {
  848. struct lpfc_iocbq * iocbq = NULL;
  849. unsigned long iflags;
  850. spin_lock_irqsave(&phba->hbalock, iflags);
  851. iocbq = __lpfc_sli_get_iocbq(phba);
  852. spin_unlock_irqrestore(&phba->hbalock, iflags);
  853. return iocbq;
  854. }
  855. /**
  856. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  857. * @phba: Pointer to HBA context object.
  858. * @iocbq: Pointer to driver iocb object.
  859. *
  860. * This function is called with hbalock held to release driver
  861. * iocb object to the iocb pool. The iotag in the iocb object
  862. * does not change for each use of the iocb object. This function
  863. * clears all other fields of the iocb object when it is freed.
  864. * The sqlq structure that holds the xritag and phys and virtual
  865. * mappings for the scatter gather list is retrieved from the
  866. * active array of sglq. The get of the sglq pointer also clears
  867. * the entry in the array. If the status of the IO indiactes that
  868. * this IO was aborted then the sglq entry it put on the
  869. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  870. * IO has good status or fails for any other reason then the sglq
  871. * entry is added to the free list (lpfc_sgl_list).
  872. **/
  873. static void
  874. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  875. {
  876. struct lpfc_sglq *sglq;
  877. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  878. unsigned long iflag = 0;
  879. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  880. if (iocbq->sli4_xritag == NO_XRI)
  881. sglq = NULL;
  882. else
  883. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  884. if (sglq) {
  885. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  886. (sglq->state != SGL_XRI_ABORTED)) {
  887. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  888. iflag);
  889. list_add(&sglq->list,
  890. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  891. spin_unlock_irqrestore(
  892. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  893. } else {
  894. sglq->state = SGL_FREED;
  895. sglq->ndlp = NULL;
  896. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  897. /* Check if TXQ queue needs to be serviced */
  898. if (pring->txq_cnt)
  899. lpfc_worker_wake_up(phba);
  900. }
  901. }
  902. /*
  903. * Clean all volatile data fields, preserve iotag and node struct.
  904. */
  905. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  906. iocbq->sli4_xritag = NO_XRI;
  907. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  908. }
  909. /**
  910. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  911. * @phba: Pointer to HBA context object.
  912. * @iocbq: Pointer to driver iocb object.
  913. *
  914. * This function is called with hbalock held to release driver
  915. * iocb object to the iocb pool. The iotag in the iocb object
  916. * does not change for each use of the iocb object. This function
  917. * clears all other fields of the iocb object when it is freed.
  918. **/
  919. static void
  920. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  921. {
  922. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  923. /*
  924. * Clean all volatile data fields, preserve iotag and node struct.
  925. */
  926. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  927. iocbq->sli4_xritag = NO_XRI;
  928. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  929. }
  930. /**
  931. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  932. * @phba: Pointer to HBA context object.
  933. * @iocbq: Pointer to driver iocb object.
  934. *
  935. * This function is called with hbalock held to release driver
  936. * iocb object to the iocb pool. The iotag in the iocb object
  937. * does not change for each use of the iocb object. This function
  938. * clears all other fields of the iocb object when it is freed.
  939. **/
  940. static void
  941. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  942. {
  943. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  944. phba->iocb_cnt--;
  945. }
  946. /**
  947. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  948. * @phba: Pointer to HBA context object.
  949. * @iocbq: Pointer to driver iocb object.
  950. *
  951. * This function is called with no lock held to release the iocb to
  952. * iocb pool.
  953. **/
  954. void
  955. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  956. {
  957. unsigned long iflags;
  958. /*
  959. * Clean all volatile data fields, preserve iotag and node struct.
  960. */
  961. spin_lock_irqsave(&phba->hbalock, iflags);
  962. __lpfc_sli_release_iocbq(phba, iocbq);
  963. spin_unlock_irqrestore(&phba->hbalock, iflags);
  964. }
  965. /**
  966. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  967. * @phba: Pointer to HBA context object.
  968. * @iocblist: List of IOCBs.
  969. * @ulpstatus: ULP status in IOCB command field.
  970. * @ulpWord4: ULP word-4 in IOCB command field.
  971. *
  972. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  973. * on the list by invoking the complete callback function associated with the
  974. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  975. * fields.
  976. **/
  977. void
  978. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  979. uint32_t ulpstatus, uint32_t ulpWord4)
  980. {
  981. struct lpfc_iocbq *piocb;
  982. while (!list_empty(iocblist)) {
  983. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  984. if (!piocb->iocb_cmpl)
  985. lpfc_sli_release_iocbq(phba, piocb);
  986. else {
  987. piocb->iocb.ulpStatus = ulpstatus;
  988. piocb->iocb.un.ulpWord[4] = ulpWord4;
  989. (piocb->iocb_cmpl) (phba, piocb, piocb);
  990. }
  991. }
  992. return;
  993. }
  994. /**
  995. * lpfc_sli_iocb_cmd_type - Get the iocb type
  996. * @iocb_cmnd: iocb command code.
  997. *
  998. * This function is called by ring event handler function to get the iocb type.
  999. * This function translates the iocb command to an iocb command type used to
  1000. * decide the final disposition of each completed IOCB.
  1001. * The function returns
  1002. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1003. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1004. * LPFC_ABORT_IOCB if it is an abort iocb
  1005. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1006. *
  1007. * The caller is not required to hold any lock.
  1008. **/
  1009. static lpfc_iocb_type
  1010. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1011. {
  1012. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1013. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1014. return 0;
  1015. switch (iocb_cmnd) {
  1016. case CMD_XMIT_SEQUENCE_CR:
  1017. case CMD_XMIT_SEQUENCE_CX:
  1018. case CMD_XMIT_BCAST_CN:
  1019. case CMD_XMIT_BCAST_CX:
  1020. case CMD_ELS_REQUEST_CR:
  1021. case CMD_ELS_REQUEST_CX:
  1022. case CMD_CREATE_XRI_CR:
  1023. case CMD_CREATE_XRI_CX:
  1024. case CMD_GET_RPI_CN:
  1025. case CMD_XMIT_ELS_RSP_CX:
  1026. case CMD_GET_RPI_CR:
  1027. case CMD_FCP_IWRITE_CR:
  1028. case CMD_FCP_IWRITE_CX:
  1029. case CMD_FCP_IREAD_CR:
  1030. case CMD_FCP_IREAD_CX:
  1031. case CMD_FCP_ICMND_CR:
  1032. case CMD_FCP_ICMND_CX:
  1033. case CMD_FCP_TSEND_CX:
  1034. case CMD_FCP_TRSP_CX:
  1035. case CMD_FCP_TRECEIVE_CX:
  1036. case CMD_FCP_AUTO_TRSP_CX:
  1037. case CMD_ADAPTER_MSG:
  1038. case CMD_ADAPTER_DUMP:
  1039. case CMD_XMIT_SEQUENCE64_CR:
  1040. case CMD_XMIT_SEQUENCE64_CX:
  1041. case CMD_XMIT_BCAST64_CN:
  1042. case CMD_XMIT_BCAST64_CX:
  1043. case CMD_ELS_REQUEST64_CR:
  1044. case CMD_ELS_REQUEST64_CX:
  1045. case CMD_FCP_IWRITE64_CR:
  1046. case CMD_FCP_IWRITE64_CX:
  1047. case CMD_FCP_IREAD64_CR:
  1048. case CMD_FCP_IREAD64_CX:
  1049. case CMD_FCP_ICMND64_CR:
  1050. case CMD_FCP_ICMND64_CX:
  1051. case CMD_FCP_TSEND64_CX:
  1052. case CMD_FCP_TRSP64_CX:
  1053. case CMD_FCP_TRECEIVE64_CX:
  1054. case CMD_GEN_REQUEST64_CR:
  1055. case CMD_GEN_REQUEST64_CX:
  1056. case CMD_XMIT_ELS_RSP64_CX:
  1057. case DSSCMD_IWRITE64_CR:
  1058. case DSSCMD_IWRITE64_CX:
  1059. case DSSCMD_IREAD64_CR:
  1060. case DSSCMD_IREAD64_CX:
  1061. type = LPFC_SOL_IOCB;
  1062. break;
  1063. case CMD_ABORT_XRI_CN:
  1064. case CMD_ABORT_XRI_CX:
  1065. case CMD_CLOSE_XRI_CN:
  1066. case CMD_CLOSE_XRI_CX:
  1067. case CMD_XRI_ABORTED_CX:
  1068. case CMD_ABORT_MXRI64_CN:
  1069. case CMD_XMIT_BLS_RSP64_CX:
  1070. type = LPFC_ABORT_IOCB;
  1071. break;
  1072. case CMD_RCV_SEQUENCE_CX:
  1073. case CMD_RCV_ELS_REQ_CX:
  1074. case CMD_RCV_SEQUENCE64_CX:
  1075. case CMD_RCV_ELS_REQ64_CX:
  1076. case CMD_ASYNC_STATUS:
  1077. case CMD_IOCB_RCV_SEQ64_CX:
  1078. case CMD_IOCB_RCV_ELS64_CX:
  1079. case CMD_IOCB_RCV_CONT64_CX:
  1080. case CMD_IOCB_RET_XRI64_CX:
  1081. type = LPFC_UNSOL_IOCB;
  1082. break;
  1083. case CMD_IOCB_XMIT_MSEQ64_CR:
  1084. case CMD_IOCB_XMIT_MSEQ64_CX:
  1085. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1086. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1087. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1088. case CMD_IOCB_ABORT_EXTENDED_CN:
  1089. case CMD_IOCB_RET_HBQE64_CN:
  1090. case CMD_IOCB_FCP_IBIDIR64_CR:
  1091. case CMD_IOCB_FCP_IBIDIR64_CX:
  1092. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1093. case CMD_IOCB_LOGENTRY_CN:
  1094. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1095. printk("%s - Unhandled SLI-3 Command x%x\n",
  1096. __func__, iocb_cmnd);
  1097. type = LPFC_UNKNOWN_IOCB;
  1098. break;
  1099. default:
  1100. type = LPFC_UNKNOWN_IOCB;
  1101. break;
  1102. }
  1103. return type;
  1104. }
  1105. /**
  1106. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1107. * @phba: Pointer to HBA context object.
  1108. *
  1109. * This function is called from SLI initialization code
  1110. * to configure every ring of the HBA's SLI interface. The
  1111. * caller is not required to hold any lock. This function issues
  1112. * a config_ring mailbox command for each ring.
  1113. * This function returns zero if successful else returns a negative
  1114. * error code.
  1115. **/
  1116. static int
  1117. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1118. {
  1119. struct lpfc_sli *psli = &phba->sli;
  1120. LPFC_MBOXQ_t *pmb;
  1121. MAILBOX_t *pmbox;
  1122. int i, rc, ret = 0;
  1123. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1124. if (!pmb)
  1125. return -ENOMEM;
  1126. pmbox = &pmb->u.mb;
  1127. phba->link_state = LPFC_INIT_MBX_CMDS;
  1128. for (i = 0; i < psli->num_rings; i++) {
  1129. lpfc_config_ring(phba, i, pmb);
  1130. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1131. if (rc != MBX_SUCCESS) {
  1132. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1133. "0446 Adapter failed to init (%d), "
  1134. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1135. "ring %d\n",
  1136. rc, pmbox->mbxCommand,
  1137. pmbox->mbxStatus, i);
  1138. phba->link_state = LPFC_HBA_ERROR;
  1139. ret = -ENXIO;
  1140. break;
  1141. }
  1142. }
  1143. mempool_free(pmb, phba->mbox_mem_pool);
  1144. return ret;
  1145. }
  1146. /**
  1147. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1148. * @phba: Pointer to HBA context object.
  1149. * @pring: Pointer to driver SLI ring object.
  1150. * @piocb: Pointer to the driver iocb object.
  1151. *
  1152. * This function is called with hbalock held. The function adds the
  1153. * new iocb to txcmplq of the given ring. This function always returns
  1154. * 0. If this function is called for ELS ring, this function checks if
  1155. * there is a vport associated with the ELS command. This function also
  1156. * starts els_tmofunc timer if this is an ELS command.
  1157. **/
  1158. static int
  1159. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1160. struct lpfc_iocbq *piocb)
  1161. {
  1162. list_add_tail(&piocb->list, &pring->txcmplq);
  1163. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1164. pring->txcmplq_cnt++;
  1165. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1166. pring->txcmplq_max = pring->txcmplq_cnt;
  1167. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1168. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1169. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1170. if (!piocb->vport)
  1171. BUG();
  1172. else
  1173. mod_timer(&piocb->vport->els_tmofunc,
  1174. jiffies + HZ * (phba->fc_ratov << 1));
  1175. }
  1176. return 0;
  1177. }
  1178. /**
  1179. * lpfc_sli_ringtx_get - Get first element of the txq
  1180. * @phba: Pointer to HBA context object.
  1181. * @pring: Pointer to driver SLI ring object.
  1182. *
  1183. * This function is called with hbalock held to get next
  1184. * iocb in txq of the given ring. If there is any iocb in
  1185. * the txq, the function returns first iocb in the list after
  1186. * removing the iocb from the list, else it returns NULL.
  1187. **/
  1188. struct lpfc_iocbq *
  1189. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1190. {
  1191. struct lpfc_iocbq *cmd_iocb;
  1192. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1193. if (cmd_iocb != NULL)
  1194. pring->txq_cnt--;
  1195. return cmd_iocb;
  1196. }
  1197. /**
  1198. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1199. * @phba: Pointer to HBA context object.
  1200. * @pring: Pointer to driver SLI ring object.
  1201. *
  1202. * This function is called with hbalock held and the caller must post the
  1203. * iocb without releasing the lock. If the caller releases the lock,
  1204. * iocb slot returned by the function is not guaranteed to be available.
  1205. * The function returns pointer to the next available iocb slot if there
  1206. * is available slot in the ring, else it returns NULL.
  1207. * If the get index of the ring is ahead of the put index, the function
  1208. * will post an error attention event to the worker thread to take the
  1209. * HBA to offline state.
  1210. **/
  1211. static IOCB_t *
  1212. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1213. {
  1214. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1215. uint32_t max_cmd_idx = pring->numCiocb;
  1216. if ((pring->next_cmdidx == pring->cmdidx) &&
  1217. (++pring->next_cmdidx >= max_cmd_idx))
  1218. pring->next_cmdidx = 0;
  1219. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1220. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1221. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1222. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1223. "0315 Ring %d issue: portCmdGet %d "
  1224. "is bigger than cmd ring %d\n",
  1225. pring->ringno,
  1226. pring->local_getidx, max_cmd_idx);
  1227. phba->link_state = LPFC_HBA_ERROR;
  1228. /*
  1229. * All error attention handlers are posted to
  1230. * worker thread
  1231. */
  1232. phba->work_ha |= HA_ERATT;
  1233. phba->work_hs = HS_FFER3;
  1234. lpfc_worker_wake_up(phba);
  1235. return NULL;
  1236. }
  1237. if (pring->local_getidx == pring->next_cmdidx)
  1238. return NULL;
  1239. }
  1240. return lpfc_cmd_iocb(phba, pring);
  1241. }
  1242. /**
  1243. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1244. * @phba: Pointer to HBA context object.
  1245. * @iocbq: Pointer to driver iocb object.
  1246. *
  1247. * This function gets an iotag for the iocb. If there is no unused iotag and
  1248. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1249. * array and assigns a new iotag.
  1250. * The function returns the allocated iotag if successful, else returns zero.
  1251. * Zero is not a valid iotag.
  1252. * The caller is not required to hold any lock.
  1253. **/
  1254. uint16_t
  1255. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1256. {
  1257. struct lpfc_iocbq **new_arr;
  1258. struct lpfc_iocbq **old_arr;
  1259. size_t new_len;
  1260. struct lpfc_sli *psli = &phba->sli;
  1261. uint16_t iotag;
  1262. spin_lock_irq(&phba->hbalock);
  1263. iotag = psli->last_iotag;
  1264. if(++iotag < psli->iocbq_lookup_len) {
  1265. psli->last_iotag = iotag;
  1266. psli->iocbq_lookup[iotag] = iocbq;
  1267. spin_unlock_irq(&phba->hbalock);
  1268. iocbq->iotag = iotag;
  1269. return iotag;
  1270. } else if (psli->iocbq_lookup_len < (0xffff
  1271. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1272. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1273. spin_unlock_irq(&phba->hbalock);
  1274. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1275. GFP_KERNEL);
  1276. if (new_arr) {
  1277. spin_lock_irq(&phba->hbalock);
  1278. old_arr = psli->iocbq_lookup;
  1279. if (new_len <= psli->iocbq_lookup_len) {
  1280. /* highly unprobable case */
  1281. kfree(new_arr);
  1282. iotag = psli->last_iotag;
  1283. if(++iotag < psli->iocbq_lookup_len) {
  1284. psli->last_iotag = iotag;
  1285. psli->iocbq_lookup[iotag] = iocbq;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. iocbq->iotag = iotag;
  1288. return iotag;
  1289. }
  1290. spin_unlock_irq(&phba->hbalock);
  1291. return 0;
  1292. }
  1293. if (psli->iocbq_lookup)
  1294. memcpy(new_arr, old_arr,
  1295. ((psli->last_iotag + 1) *
  1296. sizeof (struct lpfc_iocbq *)));
  1297. psli->iocbq_lookup = new_arr;
  1298. psli->iocbq_lookup_len = new_len;
  1299. psli->last_iotag = iotag;
  1300. psli->iocbq_lookup[iotag] = iocbq;
  1301. spin_unlock_irq(&phba->hbalock);
  1302. iocbq->iotag = iotag;
  1303. kfree(old_arr);
  1304. return iotag;
  1305. }
  1306. } else
  1307. spin_unlock_irq(&phba->hbalock);
  1308. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1309. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1310. psli->last_iotag);
  1311. return 0;
  1312. }
  1313. /**
  1314. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1315. * @phba: Pointer to HBA context object.
  1316. * @pring: Pointer to driver SLI ring object.
  1317. * @iocb: Pointer to iocb slot in the ring.
  1318. * @nextiocb: Pointer to driver iocb object which need to be
  1319. * posted to firmware.
  1320. *
  1321. * This function is called with hbalock held to post a new iocb to
  1322. * the firmware. This function copies the new iocb to ring iocb slot and
  1323. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1324. * a completion call back for this iocb else the function will free the
  1325. * iocb object.
  1326. **/
  1327. static void
  1328. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1329. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1330. {
  1331. /*
  1332. * Set up an iotag
  1333. */
  1334. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1335. if (pring->ringno == LPFC_ELS_RING) {
  1336. lpfc_debugfs_slow_ring_trc(phba,
  1337. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1338. *(((uint32_t *) &nextiocb->iocb) + 4),
  1339. *(((uint32_t *) &nextiocb->iocb) + 6),
  1340. *(((uint32_t *) &nextiocb->iocb) + 7));
  1341. }
  1342. /*
  1343. * Issue iocb command to adapter
  1344. */
  1345. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1346. wmb();
  1347. pring->stats.iocb_cmd++;
  1348. /*
  1349. * If there is no completion routine to call, we can release the
  1350. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1351. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1352. */
  1353. if (nextiocb->iocb_cmpl)
  1354. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1355. else
  1356. __lpfc_sli_release_iocbq(phba, nextiocb);
  1357. /*
  1358. * Let the HBA know what IOCB slot will be the next one the
  1359. * driver will put a command into.
  1360. */
  1361. pring->cmdidx = pring->next_cmdidx;
  1362. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1363. }
  1364. /**
  1365. * lpfc_sli_update_full_ring - Update the chip attention register
  1366. * @phba: Pointer to HBA context object.
  1367. * @pring: Pointer to driver SLI ring object.
  1368. *
  1369. * The caller is not required to hold any lock for calling this function.
  1370. * This function updates the chip attention bits for the ring to inform firmware
  1371. * that there are pending work to be done for this ring and requests an
  1372. * interrupt when there is space available in the ring. This function is
  1373. * called when the driver is unable to post more iocbs to the ring due
  1374. * to unavailability of space in the ring.
  1375. **/
  1376. static void
  1377. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1378. {
  1379. int ringno = pring->ringno;
  1380. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1381. wmb();
  1382. /*
  1383. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1384. * The HBA will tell us when an IOCB entry is available.
  1385. */
  1386. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1387. readl(phba->CAregaddr); /* flush */
  1388. pring->stats.iocb_cmd_full++;
  1389. }
  1390. /**
  1391. * lpfc_sli_update_ring - Update chip attention register
  1392. * @phba: Pointer to HBA context object.
  1393. * @pring: Pointer to driver SLI ring object.
  1394. *
  1395. * This function updates the chip attention register bit for the
  1396. * given ring to inform HBA that there is more work to be done
  1397. * in this ring. The caller is not required to hold any lock.
  1398. **/
  1399. static void
  1400. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1401. {
  1402. int ringno = pring->ringno;
  1403. /*
  1404. * Tell the HBA that there is work to do in this ring.
  1405. */
  1406. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1407. wmb();
  1408. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1409. readl(phba->CAregaddr); /* flush */
  1410. }
  1411. }
  1412. /**
  1413. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1414. * @phba: Pointer to HBA context object.
  1415. * @pring: Pointer to driver SLI ring object.
  1416. *
  1417. * This function is called with hbalock held to post pending iocbs
  1418. * in the txq to the firmware. This function is called when driver
  1419. * detects space available in the ring.
  1420. **/
  1421. static void
  1422. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1423. {
  1424. IOCB_t *iocb;
  1425. struct lpfc_iocbq *nextiocb;
  1426. /*
  1427. * Check to see if:
  1428. * (a) there is anything on the txq to send
  1429. * (b) link is up
  1430. * (c) link attention events can be processed (fcp ring only)
  1431. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1432. */
  1433. if (pring->txq_cnt &&
  1434. lpfc_is_link_up(phba) &&
  1435. (pring->ringno != phba->sli.fcp_ring ||
  1436. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1437. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1438. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1439. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1440. if (iocb)
  1441. lpfc_sli_update_ring(phba, pring);
  1442. else
  1443. lpfc_sli_update_full_ring(phba, pring);
  1444. }
  1445. return;
  1446. }
  1447. /**
  1448. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1449. * @phba: Pointer to HBA context object.
  1450. * @hbqno: HBQ number.
  1451. *
  1452. * This function is called with hbalock held to get the next
  1453. * available slot for the given HBQ. If there is free slot
  1454. * available for the HBQ it will return pointer to the next available
  1455. * HBQ entry else it will return NULL.
  1456. **/
  1457. static struct lpfc_hbq_entry *
  1458. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1459. {
  1460. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1461. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1462. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1463. hbqp->next_hbqPutIdx = 0;
  1464. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1465. uint32_t raw_index = phba->hbq_get[hbqno];
  1466. uint32_t getidx = le32_to_cpu(raw_index);
  1467. hbqp->local_hbqGetIdx = getidx;
  1468. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1469. lpfc_printf_log(phba, KERN_ERR,
  1470. LOG_SLI | LOG_VPORT,
  1471. "1802 HBQ %d: local_hbqGetIdx "
  1472. "%u is > than hbqp->entry_count %u\n",
  1473. hbqno, hbqp->local_hbqGetIdx,
  1474. hbqp->entry_count);
  1475. phba->link_state = LPFC_HBA_ERROR;
  1476. return NULL;
  1477. }
  1478. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1479. return NULL;
  1480. }
  1481. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1482. hbqp->hbqPutIdx;
  1483. }
  1484. /**
  1485. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1486. * @phba: Pointer to HBA context object.
  1487. *
  1488. * This function is called with no lock held to free all the
  1489. * hbq buffers while uninitializing the SLI interface. It also
  1490. * frees the HBQ buffers returned by the firmware but not yet
  1491. * processed by the upper layers.
  1492. **/
  1493. void
  1494. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1495. {
  1496. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1497. struct hbq_dmabuf *hbq_buf;
  1498. unsigned long flags;
  1499. int i, hbq_count;
  1500. uint32_t hbqno;
  1501. hbq_count = lpfc_sli_hbq_count();
  1502. /* Return all memory used by all HBQs */
  1503. spin_lock_irqsave(&phba->hbalock, flags);
  1504. for (i = 0; i < hbq_count; ++i) {
  1505. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1506. &phba->hbqs[i].hbq_buffer_list, list) {
  1507. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1508. list_del(&hbq_buf->dbuf.list);
  1509. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1510. }
  1511. phba->hbqs[i].buffer_count = 0;
  1512. }
  1513. /* Return all HBQ buffer that are in-fly */
  1514. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1515. list) {
  1516. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1517. list_del(&hbq_buf->dbuf.list);
  1518. if (hbq_buf->tag == -1) {
  1519. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1520. (phba, hbq_buf);
  1521. } else {
  1522. hbqno = hbq_buf->tag >> 16;
  1523. if (hbqno >= LPFC_MAX_HBQS)
  1524. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1525. (phba, hbq_buf);
  1526. else
  1527. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1528. hbq_buf);
  1529. }
  1530. }
  1531. /* Mark the HBQs not in use */
  1532. phba->hbq_in_use = 0;
  1533. spin_unlock_irqrestore(&phba->hbalock, flags);
  1534. }
  1535. /**
  1536. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1537. * @phba: Pointer to HBA context object.
  1538. * @hbqno: HBQ number.
  1539. * @hbq_buf: Pointer to HBQ buffer.
  1540. *
  1541. * This function is called with the hbalock held to post a
  1542. * hbq buffer to the firmware. If the function finds an empty
  1543. * slot in the HBQ, it will post the buffer. The function will return
  1544. * pointer to the hbq entry if it successfully post the buffer
  1545. * else it will return NULL.
  1546. **/
  1547. static int
  1548. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1549. struct hbq_dmabuf *hbq_buf)
  1550. {
  1551. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1552. }
  1553. /**
  1554. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1555. * @phba: Pointer to HBA context object.
  1556. * @hbqno: HBQ number.
  1557. * @hbq_buf: Pointer to HBQ buffer.
  1558. *
  1559. * This function is called with the hbalock held to post a hbq buffer to the
  1560. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1561. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1562. * it successfully post the buffer else it will return an error.
  1563. **/
  1564. static int
  1565. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1566. struct hbq_dmabuf *hbq_buf)
  1567. {
  1568. struct lpfc_hbq_entry *hbqe;
  1569. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1570. /* Get next HBQ entry slot to use */
  1571. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1572. if (hbqe) {
  1573. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1574. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1575. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1576. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1577. hbqe->bde.tus.f.bdeFlags = 0;
  1578. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1579. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1580. /* Sync SLIM */
  1581. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1582. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1583. /* flush */
  1584. readl(phba->hbq_put + hbqno);
  1585. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1586. return 0;
  1587. } else
  1588. return -ENOMEM;
  1589. }
  1590. /**
  1591. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1592. * @phba: Pointer to HBA context object.
  1593. * @hbqno: HBQ number.
  1594. * @hbq_buf: Pointer to HBQ buffer.
  1595. *
  1596. * This function is called with the hbalock held to post an RQE to the SLI4
  1597. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1598. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1599. **/
  1600. static int
  1601. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1602. struct hbq_dmabuf *hbq_buf)
  1603. {
  1604. int rc;
  1605. struct lpfc_rqe hrqe;
  1606. struct lpfc_rqe drqe;
  1607. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1608. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1609. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1610. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1611. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1612. &hrqe, &drqe);
  1613. if (rc < 0)
  1614. return rc;
  1615. hbq_buf->tag = rc;
  1616. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1617. return 0;
  1618. }
  1619. /* HBQ for ELS and CT traffic. */
  1620. static struct lpfc_hbq_init lpfc_els_hbq = {
  1621. .rn = 1,
  1622. .entry_count = 256,
  1623. .mask_count = 0,
  1624. .profile = 0,
  1625. .ring_mask = (1 << LPFC_ELS_RING),
  1626. .buffer_count = 0,
  1627. .init_count = 40,
  1628. .add_count = 40,
  1629. };
  1630. /* HBQ for the extra ring if needed */
  1631. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1632. .rn = 1,
  1633. .entry_count = 200,
  1634. .mask_count = 0,
  1635. .profile = 0,
  1636. .ring_mask = (1 << LPFC_EXTRA_RING),
  1637. .buffer_count = 0,
  1638. .init_count = 0,
  1639. .add_count = 5,
  1640. };
  1641. /* Array of HBQs */
  1642. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1643. &lpfc_els_hbq,
  1644. &lpfc_extra_hbq,
  1645. };
  1646. /**
  1647. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1648. * @phba: Pointer to HBA context object.
  1649. * @hbqno: HBQ number.
  1650. * @count: Number of HBQ buffers to be posted.
  1651. *
  1652. * This function is called with no lock held to post more hbq buffers to the
  1653. * given HBQ. The function returns the number of HBQ buffers successfully
  1654. * posted.
  1655. **/
  1656. static int
  1657. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1658. {
  1659. uint32_t i, posted = 0;
  1660. unsigned long flags;
  1661. struct hbq_dmabuf *hbq_buffer;
  1662. LIST_HEAD(hbq_buf_list);
  1663. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1664. return 0;
  1665. if ((phba->hbqs[hbqno].buffer_count + count) >
  1666. lpfc_hbq_defs[hbqno]->entry_count)
  1667. count = lpfc_hbq_defs[hbqno]->entry_count -
  1668. phba->hbqs[hbqno].buffer_count;
  1669. if (!count)
  1670. return 0;
  1671. /* Allocate HBQ entries */
  1672. for (i = 0; i < count; i++) {
  1673. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1674. if (!hbq_buffer)
  1675. break;
  1676. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1677. }
  1678. /* Check whether HBQ is still in use */
  1679. spin_lock_irqsave(&phba->hbalock, flags);
  1680. if (!phba->hbq_in_use)
  1681. goto err;
  1682. while (!list_empty(&hbq_buf_list)) {
  1683. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1684. dbuf.list);
  1685. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1686. (hbqno << 16));
  1687. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1688. phba->hbqs[hbqno].buffer_count++;
  1689. posted++;
  1690. } else
  1691. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1692. }
  1693. spin_unlock_irqrestore(&phba->hbalock, flags);
  1694. return posted;
  1695. err:
  1696. spin_unlock_irqrestore(&phba->hbalock, flags);
  1697. while (!list_empty(&hbq_buf_list)) {
  1698. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1699. dbuf.list);
  1700. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1701. }
  1702. return 0;
  1703. }
  1704. /**
  1705. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1706. * @phba: Pointer to HBA context object.
  1707. * @qno: HBQ number.
  1708. *
  1709. * This function posts more buffers to the HBQ. This function
  1710. * is called with no lock held. The function returns the number of HBQ entries
  1711. * successfully allocated.
  1712. **/
  1713. int
  1714. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1715. {
  1716. if (phba->sli_rev == LPFC_SLI_REV4)
  1717. return 0;
  1718. else
  1719. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1720. lpfc_hbq_defs[qno]->add_count);
  1721. }
  1722. /**
  1723. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1724. * @phba: Pointer to HBA context object.
  1725. * @qno: HBQ queue number.
  1726. *
  1727. * This function is called from SLI initialization code path with
  1728. * no lock held to post initial HBQ buffers to firmware. The
  1729. * function returns the number of HBQ entries successfully allocated.
  1730. **/
  1731. static int
  1732. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1733. {
  1734. if (phba->sli_rev == LPFC_SLI_REV4)
  1735. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1736. lpfc_hbq_defs[qno]->entry_count);
  1737. else
  1738. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1739. lpfc_hbq_defs[qno]->init_count);
  1740. }
  1741. /**
  1742. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1743. * @phba: Pointer to HBA context object.
  1744. * @hbqno: HBQ number.
  1745. *
  1746. * This function removes the first hbq buffer on an hbq list and returns a
  1747. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1748. **/
  1749. static struct hbq_dmabuf *
  1750. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1751. {
  1752. struct lpfc_dmabuf *d_buf;
  1753. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1754. if (!d_buf)
  1755. return NULL;
  1756. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1757. }
  1758. /**
  1759. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1760. * @phba: Pointer to HBA context object.
  1761. * @tag: Tag of the hbq buffer.
  1762. *
  1763. * This function is called with hbalock held. This function searches
  1764. * for the hbq buffer associated with the given tag in the hbq buffer
  1765. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1766. * it returns NULL.
  1767. **/
  1768. static struct hbq_dmabuf *
  1769. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1770. {
  1771. struct lpfc_dmabuf *d_buf;
  1772. struct hbq_dmabuf *hbq_buf;
  1773. uint32_t hbqno;
  1774. hbqno = tag >> 16;
  1775. if (hbqno >= LPFC_MAX_HBQS)
  1776. return NULL;
  1777. spin_lock_irq(&phba->hbalock);
  1778. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1779. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1780. if (hbq_buf->tag == tag) {
  1781. spin_unlock_irq(&phba->hbalock);
  1782. return hbq_buf;
  1783. }
  1784. }
  1785. spin_unlock_irq(&phba->hbalock);
  1786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1787. "1803 Bad hbq tag. Data: x%x x%x\n",
  1788. tag, phba->hbqs[tag >> 16].buffer_count);
  1789. return NULL;
  1790. }
  1791. /**
  1792. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1793. * @phba: Pointer to HBA context object.
  1794. * @hbq_buffer: Pointer to HBQ buffer.
  1795. *
  1796. * This function is called with hbalock. This function gives back
  1797. * the hbq buffer to firmware. If the HBQ does not have space to
  1798. * post the buffer, it will free the buffer.
  1799. **/
  1800. void
  1801. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1802. {
  1803. uint32_t hbqno;
  1804. if (hbq_buffer) {
  1805. hbqno = hbq_buffer->tag >> 16;
  1806. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1807. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1808. }
  1809. }
  1810. /**
  1811. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1812. * @mbxCommand: mailbox command code.
  1813. *
  1814. * This function is called by the mailbox event handler function to verify
  1815. * that the completed mailbox command is a legitimate mailbox command. If the
  1816. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1817. * and the mailbox event handler will take the HBA offline.
  1818. **/
  1819. static int
  1820. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1821. {
  1822. uint8_t ret;
  1823. switch (mbxCommand) {
  1824. case MBX_LOAD_SM:
  1825. case MBX_READ_NV:
  1826. case MBX_WRITE_NV:
  1827. case MBX_WRITE_VPARMS:
  1828. case MBX_RUN_BIU_DIAG:
  1829. case MBX_INIT_LINK:
  1830. case MBX_DOWN_LINK:
  1831. case MBX_CONFIG_LINK:
  1832. case MBX_CONFIG_RING:
  1833. case MBX_RESET_RING:
  1834. case MBX_READ_CONFIG:
  1835. case MBX_READ_RCONFIG:
  1836. case MBX_READ_SPARM:
  1837. case MBX_READ_STATUS:
  1838. case MBX_READ_RPI:
  1839. case MBX_READ_XRI:
  1840. case MBX_READ_REV:
  1841. case MBX_READ_LNK_STAT:
  1842. case MBX_REG_LOGIN:
  1843. case MBX_UNREG_LOGIN:
  1844. case MBX_CLEAR_LA:
  1845. case MBX_DUMP_MEMORY:
  1846. case MBX_DUMP_CONTEXT:
  1847. case MBX_RUN_DIAGS:
  1848. case MBX_RESTART:
  1849. case MBX_UPDATE_CFG:
  1850. case MBX_DOWN_LOAD:
  1851. case MBX_DEL_LD_ENTRY:
  1852. case MBX_RUN_PROGRAM:
  1853. case MBX_SET_MASK:
  1854. case MBX_SET_VARIABLE:
  1855. case MBX_UNREG_D_ID:
  1856. case MBX_KILL_BOARD:
  1857. case MBX_CONFIG_FARP:
  1858. case MBX_BEACON:
  1859. case MBX_LOAD_AREA:
  1860. case MBX_RUN_BIU_DIAG64:
  1861. case MBX_CONFIG_PORT:
  1862. case MBX_READ_SPARM64:
  1863. case MBX_READ_RPI64:
  1864. case MBX_REG_LOGIN64:
  1865. case MBX_READ_TOPOLOGY:
  1866. case MBX_WRITE_WWN:
  1867. case MBX_SET_DEBUG:
  1868. case MBX_LOAD_EXP_ROM:
  1869. case MBX_ASYNCEVT_ENABLE:
  1870. case MBX_REG_VPI:
  1871. case MBX_UNREG_VPI:
  1872. case MBX_HEARTBEAT:
  1873. case MBX_PORT_CAPABILITIES:
  1874. case MBX_PORT_IOV_CONTROL:
  1875. case MBX_SLI4_CONFIG:
  1876. case MBX_SLI4_REQ_FTRS:
  1877. case MBX_REG_FCFI:
  1878. case MBX_UNREG_FCFI:
  1879. case MBX_REG_VFI:
  1880. case MBX_UNREG_VFI:
  1881. case MBX_INIT_VPI:
  1882. case MBX_INIT_VFI:
  1883. case MBX_RESUME_RPI:
  1884. case MBX_READ_EVENT_LOG_STATUS:
  1885. case MBX_READ_EVENT_LOG:
  1886. case MBX_SECURITY_MGMT:
  1887. case MBX_AUTH_PORT:
  1888. ret = mbxCommand;
  1889. break;
  1890. default:
  1891. ret = MBX_SHUTDOWN;
  1892. break;
  1893. }
  1894. return ret;
  1895. }
  1896. /**
  1897. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1898. * @phba: Pointer to HBA context object.
  1899. * @pmboxq: Pointer to mailbox command.
  1900. *
  1901. * This is completion handler function for mailbox commands issued from
  1902. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1903. * mailbox event handler function with no lock held. This function
  1904. * will wake up thread waiting on the wait queue pointed by context1
  1905. * of the mailbox.
  1906. **/
  1907. void
  1908. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1909. {
  1910. wait_queue_head_t *pdone_q;
  1911. unsigned long drvr_flag;
  1912. /*
  1913. * If pdone_q is empty, the driver thread gave up waiting and
  1914. * continued running.
  1915. */
  1916. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1917. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1918. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1919. if (pdone_q)
  1920. wake_up_interruptible(pdone_q);
  1921. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1922. return;
  1923. }
  1924. /**
  1925. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1926. * @phba: Pointer to HBA context object.
  1927. * @pmb: Pointer to mailbox object.
  1928. *
  1929. * This function is the default mailbox completion handler. It
  1930. * frees the memory resources associated with the completed mailbox
  1931. * command. If the completed command is a REG_LOGIN mailbox command,
  1932. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1933. **/
  1934. void
  1935. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1936. {
  1937. struct lpfc_vport *vport = pmb->vport;
  1938. struct lpfc_dmabuf *mp;
  1939. struct lpfc_nodelist *ndlp;
  1940. struct Scsi_Host *shost;
  1941. uint16_t rpi, vpi;
  1942. int rc;
  1943. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1944. if (mp) {
  1945. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1946. kfree(mp);
  1947. }
  1948. /*
  1949. * If a REG_LOGIN succeeded after node is destroyed or node
  1950. * is in re-discovery driver need to cleanup the RPI.
  1951. */
  1952. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1953. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1954. !pmb->u.mb.mbxStatus) {
  1955. rpi = pmb->u.mb.un.varWords[0];
  1956. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1957. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1958. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1959. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1960. if (rc != MBX_NOT_FINISHED)
  1961. return;
  1962. }
  1963. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1964. !(phba->pport->load_flag & FC_UNLOADING) &&
  1965. !pmb->u.mb.mbxStatus) {
  1966. shost = lpfc_shost_from_vport(vport);
  1967. spin_lock_irq(shost->host_lock);
  1968. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1969. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1970. spin_unlock_irq(shost->host_lock);
  1971. }
  1972. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1973. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1974. lpfc_nlp_put(ndlp);
  1975. pmb->context2 = NULL;
  1976. }
  1977. /* Check security permission status on INIT_LINK mailbox command */
  1978. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1979. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1980. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1981. "2860 SLI authentication is required "
  1982. "for INIT_LINK but has not done yet\n");
  1983. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1984. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1985. else
  1986. mempool_free(pmb, phba->mbox_mem_pool);
  1987. }
  1988. /**
  1989. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1990. * @phba: Pointer to HBA context object.
  1991. *
  1992. * This function is called with no lock held. This function processes all
  1993. * the completed mailbox commands and gives it to upper layers. The interrupt
  1994. * service routine processes mailbox completion interrupt and adds completed
  1995. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1996. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1997. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1998. * function returns the mailbox commands to the upper layer by calling the
  1999. * completion handler function of each mailbox.
  2000. **/
  2001. int
  2002. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2003. {
  2004. MAILBOX_t *pmbox;
  2005. LPFC_MBOXQ_t *pmb;
  2006. int rc;
  2007. LIST_HEAD(cmplq);
  2008. phba->sli.slistat.mbox_event++;
  2009. /* Get all completed mailboxe buffers into the cmplq */
  2010. spin_lock_irq(&phba->hbalock);
  2011. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2012. spin_unlock_irq(&phba->hbalock);
  2013. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2014. do {
  2015. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2016. if (pmb == NULL)
  2017. break;
  2018. pmbox = &pmb->u.mb;
  2019. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2020. if (pmb->vport) {
  2021. lpfc_debugfs_disc_trc(pmb->vport,
  2022. LPFC_DISC_TRC_MBOX_VPORT,
  2023. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2024. (uint32_t)pmbox->mbxCommand,
  2025. pmbox->un.varWords[0],
  2026. pmbox->un.varWords[1]);
  2027. }
  2028. else {
  2029. lpfc_debugfs_disc_trc(phba->pport,
  2030. LPFC_DISC_TRC_MBOX,
  2031. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2032. (uint32_t)pmbox->mbxCommand,
  2033. pmbox->un.varWords[0],
  2034. pmbox->un.varWords[1]);
  2035. }
  2036. }
  2037. /*
  2038. * It is a fatal error if unknown mbox command completion.
  2039. */
  2040. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2041. MBX_SHUTDOWN) {
  2042. /* Unknown mailbox command compl */
  2043. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2044. "(%d):0323 Unknown Mailbox command "
  2045. "x%x (x%x) Cmpl\n",
  2046. pmb->vport ? pmb->vport->vpi : 0,
  2047. pmbox->mbxCommand,
  2048. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2049. phba->link_state = LPFC_HBA_ERROR;
  2050. phba->work_hs = HS_FFER3;
  2051. lpfc_handle_eratt(phba);
  2052. continue;
  2053. }
  2054. if (pmbox->mbxStatus) {
  2055. phba->sli.slistat.mbox_stat_err++;
  2056. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2057. /* Mbox cmd cmpl error - RETRYing */
  2058. lpfc_printf_log(phba, KERN_INFO,
  2059. LOG_MBOX | LOG_SLI,
  2060. "(%d):0305 Mbox cmd cmpl "
  2061. "error - RETRYing Data: x%x "
  2062. "(x%x) x%x x%x x%x\n",
  2063. pmb->vport ? pmb->vport->vpi :0,
  2064. pmbox->mbxCommand,
  2065. lpfc_sli4_mbox_opcode_get(phba,
  2066. pmb),
  2067. pmbox->mbxStatus,
  2068. pmbox->un.varWords[0],
  2069. pmb->vport->port_state);
  2070. pmbox->mbxStatus = 0;
  2071. pmbox->mbxOwner = OWN_HOST;
  2072. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2073. if (rc != MBX_NOT_FINISHED)
  2074. continue;
  2075. }
  2076. }
  2077. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2078. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2079. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2080. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2081. pmb->vport ? pmb->vport->vpi : 0,
  2082. pmbox->mbxCommand,
  2083. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2084. pmb->mbox_cmpl,
  2085. *((uint32_t *) pmbox),
  2086. pmbox->un.varWords[0],
  2087. pmbox->un.varWords[1],
  2088. pmbox->un.varWords[2],
  2089. pmbox->un.varWords[3],
  2090. pmbox->un.varWords[4],
  2091. pmbox->un.varWords[5],
  2092. pmbox->un.varWords[6],
  2093. pmbox->un.varWords[7]);
  2094. if (pmb->mbox_cmpl)
  2095. pmb->mbox_cmpl(phba,pmb);
  2096. } while (1);
  2097. return 0;
  2098. }
  2099. /**
  2100. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2101. * @phba: Pointer to HBA context object.
  2102. * @pring: Pointer to driver SLI ring object.
  2103. * @tag: buffer tag.
  2104. *
  2105. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2106. * is set in the tag the buffer is posted for a particular exchange,
  2107. * the function will return the buffer without replacing the buffer.
  2108. * If the buffer is for unsolicited ELS or CT traffic, this function
  2109. * returns the buffer and also posts another buffer to the firmware.
  2110. **/
  2111. static struct lpfc_dmabuf *
  2112. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2113. struct lpfc_sli_ring *pring,
  2114. uint32_t tag)
  2115. {
  2116. struct hbq_dmabuf *hbq_entry;
  2117. if (tag & QUE_BUFTAG_BIT)
  2118. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2119. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2120. if (!hbq_entry)
  2121. return NULL;
  2122. return &hbq_entry->dbuf;
  2123. }
  2124. /**
  2125. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2126. * @phba: Pointer to HBA context object.
  2127. * @pring: Pointer to driver SLI ring object.
  2128. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2129. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2130. * @fch_type: the type for the first frame of the sequence.
  2131. *
  2132. * This function is called with no lock held. This function uses the r_ctl and
  2133. * type of the received sequence to find the correct callback function to call
  2134. * to process the sequence.
  2135. **/
  2136. static int
  2137. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2138. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2139. uint32_t fch_type)
  2140. {
  2141. int i;
  2142. /* unSolicited Responses */
  2143. if (pring->prt[0].profile) {
  2144. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2145. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2146. saveq);
  2147. return 1;
  2148. }
  2149. /* We must search, based on rctl / type
  2150. for the right routine */
  2151. for (i = 0; i < pring->num_mask; i++) {
  2152. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2153. (pring->prt[i].type == fch_type)) {
  2154. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2155. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2156. (phba, pring, saveq);
  2157. return 1;
  2158. }
  2159. }
  2160. return 0;
  2161. }
  2162. /**
  2163. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2164. * @phba: Pointer to HBA context object.
  2165. * @pring: Pointer to driver SLI ring object.
  2166. * @saveq: Pointer to the unsolicited iocb.
  2167. *
  2168. * This function is called with no lock held by the ring event handler
  2169. * when there is an unsolicited iocb posted to the response ring by the
  2170. * firmware. This function gets the buffer associated with the iocbs
  2171. * and calls the event handler for the ring. This function handles both
  2172. * qring buffers and hbq buffers.
  2173. * When the function returns 1 the caller can free the iocb object otherwise
  2174. * upper layer functions will free the iocb objects.
  2175. **/
  2176. static int
  2177. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2178. struct lpfc_iocbq *saveq)
  2179. {
  2180. IOCB_t * irsp;
  2181. WORD5 * w5p;
  2182. uint32_t Rctl, Type;
  2183. uint32_t match;
  2184. struct lpfc_iocbq *iocbq;
  2185. struct lpfc_dmabuf *dmzbuf;
  2186. match = 0;
  2187. irsp = &(saveq->iocb);
  2188. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2189. if (pring->lpfc_sli_rcv_async_status)
  2190. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2191. else
  2192. lpfc_printf_log(phba,
  2193. KERN_WARNING,
  2194. LOG_SLI,
  2195. "0316 Ring %d handler: unexpected "
  2196. "ASYNC_STATUS iocb received evt_code "
  2197. "0x%x\n",
  2198. pring->ringno,
  2199. irsp->un.asyncstat.evt_code);
  2200. return 1;
  2201. }
  2202. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2203. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2204. if (irsp->ulpBdeCount > 0) {
  2205. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2206. irsp->un.ulpWord[3]);
  2207. lpfc_in_buf_free(phba, dmzbuf);
  2208. }
  2209. if (irsp->ulpBdeCount > 1) {
  2210. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2211. irsp->unsli3.sli3Words[3]);
  2212. lpfc_in_buf_free(phba, dmzbuf);
  2213. }
  2214. if (irsp->ulpBdeCount > 2) {
  2215. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2216. irsp->unsli3.sli3Words[7]);
  2217. lpfc_in_buf_free(phba, dmzbuf);
  2218. }
  2219. return 1;
  2220. }
  2221. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2222. if (irsp->ulpBdeCount != 0) {
  2223. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2224. irsp->un.ulpWord[3]);
  2225. if (!saveq->context2)
  2226. lpfc_printf_log(phba,
  2227. KERN_ERR,
  2228. LOG_SLI,
  2229. "0341 Ring %d Cannot find buffer for "
  2230. "an unsolicited iocb. tag 0x%x\n",
  2231. pring->ringno,
  2232. irsp->un.ulpWord[3]);
  2233. }
  2234. if (irsp->ulpBdeCount == 2) {
  2235. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2236. irsp->unsli3.sli3Words[7]);
  2237. if (!saveq->context3)
  2238. lpfc_printf_log(phba,
  2239. KERN_ERR,
  2240. LOG_SLI,
  2241. "0342 Ring %d Cannot find buffer for an"
  2242. " unsolicited iocb. tag 0x%x\n",
  2243. pring->ringno,
  2244. irsp->unsli3.sli3Words[7]);
  2245. }
  2246. list_for_each_entry(iocbq, &saveq->list, list) {
  2247. irsp = &(iocbq->iocb);
  2248. if (irsp->ulpBdeCount != 0) {
  2249. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2250. irsp->un.ulpWord[3]);
  2251. if (!iocbq->context2)
  2252. lpfc_printf_log(phba,
  2253. KERN_ERR,
  2254. LOG_SLI,
  2255. "0343 Ring %d Cannot find "
  2256. "buffer for an unsolicited iocb"
  2257. ". tag 0x%x\n", pring->ringno,
  2258. irsp->un.ulpWord[3]);
  2259. }
  2260. if (irsp->ulpBdeCount == 2) {
  2261. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2262. irsp->unsli3.sli3Words[7]);
  2263. if (!iocbq->context3)
  2264. lpfc_printf_log(phba,
  2265. KERN_ERR,
  2266. LOG_SLI,
  2267. "0344 Ring %d Cannot find "
  2268. "buffer for an unsolicited "
  2269. "iocb. tag 0x%x\n",
  2270. pring->ringno,
  2271. irsp->unsli3.sli3Words[7]);
  2272. }
  2273. }
  2274. }
  2275. if (irsp->ulpBdeCount != 0 &&
  2276. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2277. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2278. int found = 0;
  2279. /* search continue save q for same XRI */
  2280. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2281. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2282. list_add_tail(&saveq->list, &iocbq->list);
  2283. found = 1;
  2284. break;
  2285. }
  2286. }
  2287. if (!found)
  2288. list_add_tail(&saveq->clist,
  2289. &pring->iocb_continue_saveq);
  2290. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2291. list_del_init(&iocbq->clist);
  2292. saveq = iocbq;
  2293. irsp = &(saveq->iocb);
  2294. } else
  2295. return 0;
  2296. }
  2297. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2298. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2299. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2300. Rctl = FC_RCTL_ELS_REQ;
  2301. Type = FC_TYPE_ELS;
  2302. } else {
  2303. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2304. Rctl = w5p->hcsw.Rctl;
  2305. Type = w5p->hcsw.Type;
  2306. /* Firmware Workaround */
  2307. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2308. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2309. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2310. Rctl = FC_RCTL_ELS_REQ;
  2311. Type = FC_TYPE_ELS;
  2312. w5p->hcsw.Rctl = Rctl;
  2313. w5p->hcsw.Type = Type;
  2314. }
  2315. }
  2316. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2317. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2318. "0313 Ring %d handler: unexpected Rctl x%x "
  2319. "Type x%x received\n",
  2320. pring->ringno, Rctl, Type);
  2321. return 1;
  2322. }
  2323. /**
  2324. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2325. * @phba: Pointer to HBA context object.
  2326. * @pring: Pointer to driver SLI ring object.
  2327. * @prspiocb: Pointer to response iocb object.
  2328. *
  2329. * This function looks up the iocb_lookup table to get the command iocb
  2330. * corresponding to the given response iocb using the iotag of the
  2331. * response iocb. This function is called with the hbalock held.
  2332. * This function returns the command iocb object if it finds the command
  2333. * iocb else returns NULL.
  2334. **/
  2335. static struct lpfc_iocbq *
  2336. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2337. struct lpfc_sli_ring *pring,
  2338. struct lpfc_iocbq *prspiocb)
  2339. {
  2340. struct lpfc_iocbq *cmd_iocb = NULL;
  2341. uint16_t iotag;
  2342. iotag = prspiocb->iocb.ulpIoTag;
  2343. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2344. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2345. list_del_init(&cmd_iocb->list);
  2346. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2347. pring->txcmplq_cnt--;
  2348. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2349. }
  2350. return cmd_iocb;
  2351. }
  2352. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2353. "0317 iotag x%x is out off "
  2354. "range: max iotag x%x wd0 x%x\n",
  2355. iotag, phba->sli.last_iotag,
  2356. *(((uint32_t *) &prspiocb->iocb) + 7));
  2357. return NULL;
  2358. }
  2359. /**
  2360. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2361. * @phba: Pointer to HBA context object.
  2362. * @pring: Pointer to driver SLI ring object.
  2363. * @iotag: IOCB tag.
  2364. *
  2365. * This function looks up the iocb_lookup table to get the command iocb
  2366. * corresponding to the given iotag. This function is called with the
  2367. * hbalock held.
  2368. * This function returns the command iocb object if it finds the command
  2369. * iocb else returns NULL.
  2370. **/
  2371. static struct lpfc_iocbq *
  2372. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2373. struct lpfc_sli_ring *pring, uint16_t iotag)
  2374. {
  2375. struct lpfc_iocbq *cmd_iocb;
  2376. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2377. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2378. list_del_init(&cmd_iocb->list);
  2379. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2380. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2381. pring->txcmplq_cnt--;
  2382. }
  2383. return cmd_iocb;
  2384. }
  2385. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2386. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2387. iotag, phba->sli.last_iotag);
  2388. return NULL;
  2389. }
  2390. /**
  2391. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2392. * @phba: Pointer to HBA context object.
  2393. * @pring: Pointer to driver SLI ring object.
  2394. * @saveq: Pointer to the response iocb to be processed.
  2395. *
  2396. * This function is called by the ring event handler for non-fcp
  2397. * rings when there is a new response iocb in the response ring.
  2398. * The caller is not required to hold any locks. This function
  2399. * gets the command iocb associated with the response iocb and
  2400. * calls the completion handler for the command iocb. If there
  2401. * is no completion handler, the function will free the resources
  2402. * associated with command iocb. If the response iocb is for
  2403. * an already aborted command iocb, the status of the completion
  2404. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2405. * This function always returns 1.
  2406. **/
  2407. static int
  2408. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2409. struct lpfc_iocbq *saveq)
  2410. {
  2411. struct lpfc_iocbq *cmdiocbp;
  2412. int rc = 1;
  2413. unsigned long iflag;
  2414. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2415. spin_lock_irqsave(&phba->hbalock, iflag);
  2416. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2417. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2418. if (cmdiocbp) {
  2419. if (cmdiocbp->iocb_cmpl) {
  2420. /*
  2421. * If an ELS command failed send an event to mgmt
  2422. * application.
  2423. */
  2424. if (saveq->iocb.ulpStatus &&
  2425. (pring->ringno == LPFC_ELS_RING) &&
  2426. (cmdiocbp->iocb.ulpCommand ==
  2427. CMD_ELS_REQUEST64_CR))
  2428. lpfc_send_els_failure_event(phba,
  2429. cmdiocbp, saveq);
  2430. /*
  2431. * Post all ELS completions to the worker thread.
  2432. * All other are passed to the completion callback.
  2433. */
  2434. if (pring->ringno == LPFC_ELS_RING) {
  2435. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2436. (cmdiocbp->iocb_flag &
  2437. LPFC_DRIVER_ABORTED)) {
  2438. spin_lock_irqsave(&phba->hbalock,
  2439. iflag);
  2440. cmdiocbp->iocb_flag &=
  2441. ~LPFC_DRIVER_ABORTED;
  2442. spin_unlock_irqrestore(&phba->hbalock,
  2443. iflag);
  2444. saveq->iocb.ulpStatus =
  2445. IOSTAT_LOCAL_REJECT;
  2446. saveq->iocb.un.ulpWord[4] =
  2447. IOERR_SLI_ABORTED;
  2448. /* Firmware could still be in progress
  2449. * of DMAing payload, so don't free data
  2450. * buffer till after a hbeat.
  2451. */
  2452. spin_lock_irqsave(&phba->hbalock,
  2453. iflag);
  2454. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2455. spin_unlock_irqrestore(&phba->hbalock,
  2456. iflag);
  2457. }
  2458. if (phba->sli_rev == LPFC_SLI_REV4) {
  2459. if (saveq->iocb_flag &
  2460. LPFC_EXCHANGE_BUSY) {
  2461. /* Set cmdiocb flag for the
  2462. * exchange busy so sgl (xri)
  2463. * will not be released until
  2464. * the abort xri is received
  2465. * from hba.
  2466. */
  2467. spin_lock_irqsave(
  2468. &phba->hbalock, iflag);
  2469. cmdiocbp->iocb_flag |=
  2470. LPFC_EXCHANGE_BUSY;
  2471. spin_unlock_irqrestore(
  2472. &phba->hbalock, iflag);
  2473. }
  2474. if (cmdiocbp->iocb_flag &
  2475. LPFC_DRIVER_ABORTED) {
  2476. /*
  2477. * Clear LPFC_DRIVER_ABORTED
  2478. * bit in case it was driver
  2479. * initiated abort.
  2480. */
  2481. spin_lock_irqsave(
  2482. &phba->hbalock, iflag);
  2483. cmdiocbp->iocb_flag &=
  2484. ~LPFC_DRIVER_ABORTED;
  2485. spin_unlock_irqrestore(
  2486. &phba->hbalock, iflag);
  2487. cmdiocbp->iocb.ulpStatus =
  2488. IOSTAT_LOCAL_REJECT;
  2489. cmdiocbp->iocb.un.ulpWord[4] =
  2490. IOERR_ABORT_REQUESTED;
  2491. /*
  2492. * For SLI4, irsiocb contains
  2493. * NO_XRI in sli_xritag, it
  2494. * shall not affect releasing
  2495. * sgl (xri) process.
  2496. */
  2497. saveq->iocb.ulpStatus =
  2498. IOSTAT_LOCAL_REJECT;
  2499. saveq->iocb.un.ulpWord[4] =
  2500. IOERR_SLI_ABORTED;
  2501. spin_lock_irqsave(
  2502. &phba->hbalock, iflag);
  2503. saveq->iocb_flag |=
  2504. LPFC_DELAY_MEM_FREE;
  2505. spin_unlock_irqrestore(
  2506. &phba->hbalock, iflag);
  2507. }
  2508. }
  2509. }
  2510. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2511. } else
  2512. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2513. } else {
  2514. /*
  2515. * Unknown initiating command based on the response iotag.
  2516. * This could be the case on the ELS ring because of
  2517. * lpfc_els_abort().
  2518. */
  2519. if (pring->ringno != LPFC_ELS_RING) {
  2520. /*
  2521. * Ring <ringno> handler: unexpected completion IoTag
  2522. * <IoTag>
  2523. */
  2524. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2525. "0322 Ring %d handler: "
  2526. "unexpected completion IoTag x%x "
  2527. "Data: x%x x%x x%x x%x\n",
  2528. pring->ringno,
  2529. saveq->iocb.ulpIoTag,
  2530. saveq->iocb.ulpStatus,
  2531. saveq->iocb.un.ulpWord[4],
  2532. saveq->iocb.ulpCommand,
  2533. saveq->iocb.ulpContext);
  2534. }
  2535. }
  2536. return rc;
  2537. }
  2538. /**
  2539. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2540. * @phba: Pointer to HBA context object.
  2541. * @pring: Pointer to driver SLI ring object.
  2542. *
  2543. * This function is called from the iocb ring event handlers when
  2544. * put pointer is ahead of the get pointer for a ring. This function signal
  2545. * an error attention condition to the worker thread and the worker
  2546. * thread will transition the HBA to offline state.
  2547. **/
  2548. static void
  2549. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2550. {
  2551. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2552. /*
  2553. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2554. * rsp ring <portRspMax>
  2555. */
  2556. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2557. "0312 Ring %d handler: portRspPut %d "
  2558. "is bigger than rsp ring %d\n",
  2559. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2560. pring->numRiocb);
  2561. phba->link_state = LPFC_HBA_ERROR;
  2562. /*
  2563. * All error attention handlers are posted to
  2564. * worker thread
  2565. */
  2566. phba->work_ha |= HA_ERATT;
  2567. phba->work_hs = HS_FFER3;
  2568. lpfc_worker_wake_up(phba);
  2569. return;
  2570. }
  2571. /**
  2572. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2573. * @ptr: Pointer to address of HBA context object.
  2574. *
  2575. * This function is invoked by the Error Attention polling timer when the
  2576. * timer times out. It will check the SLI Error Attention register for
  2577. * possible attention events. If so, it will post an Error Attention event
  2578. * and wake up worker thread to process it. Otherwise, it will set up the
  2579. * Error Attention polling timer for the next poll.
  2580. **/
  2581. void lpfc_poll_eratt(unsigned long ptr)
  2582. {
  2583. struct lpfc_hba *phba;
  2584. uint32_t eratt = 0;
  2585. phba = (struct lpfc_hba *)ptr;
  2586. /* Check chip HA register for error event */
  2587. eratt = lpfc_sli_check_eratt(phba);
  2588. if (eratt)
  2589. /* Tell the worker thread there is work to do */
  2590. lpfc_worker_wake_up(phba);
  2591. else
  2592. /* Restart the timer for next eratt poll */
  2593. mod_timer(&phba->eratt_poll, jiffies +
  2594. HZ * LPFC_ERATT_POLL_INTERVAL);
  2595. return;
  2596. }
  2597. /**
  2598. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2599. * @phba: Pointer to HBA context object.
  2600. * @pring: Pointer to driver SLI ring object.
  2601. * @mask: Host attention register mask for this ring.
  2602. *
  2603. * This function is called from the interrupt context when there is a ring
  2604. * event for the fcp ring. The caller does not hold any lock.
  2605. * The function processes each response iocb in the response ring until it
  2606. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2607. * LE bit set. The function will call the completion handler of the command iocb
  2608. * if the response iocb indicates a completion for a command iocb or it is
  2609. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2610. * function if this is an unsolicited iocb.
  2611. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2612. * to check it explicitly.
  2613. */
  2614. int
  2615. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2616. struct lpfc_sli_ring *pring, uint32_t mask)
  2617. {
  2618. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2619. IOCB_t *irsp = NULL;
  2620. IOCB_t *entry = NULL;
  2621. struct lpfc_iocbq *cmdiocbq = NULL;
  2622. struct lpfc_iocbq rspiocbq;
  2623. uint32_t status;
  2624. uint32_t portRspPut, portRspMax;
  2625. int rc = 1;
  2626. lpfc_iocb_type type;
  2627. unsigned long iflag;
  2628. uint32_t rsp_cmpl = 0;
  2629. spin_lock_irqsave(&phba->hbalock, iflag);
  2630. pring->stats.iocb_event++;
  2631. /*
  2632. * The next available response entry should never exceed the maximum
  2633. * entries. If it does, treat it as an adapter hardware error.
  2634. */
  2635. portRspMax = pring->numRiocb;
  2636. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2637. if (unlikely(portRspPut >= portRspMax)) {
  2638. lpfc_sli_rsp_pointers_error(phba, pring);
  2639. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2640. return 1;
  2641. }
  2642. if (phba->fcp_ring_in_use) {
  2643. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2644. return 1;
  2645. } else
  2646. phba->fcp_ring_in_use = 1;
  2647. rmb();
  2648. while (pring->rspidx != portRspPut) {
  2649. /*
  2650. * Fetch an entry off the ring and copy it into a local data
  2651. * structure. The copy involves a byte-swap since the
  2652. * network byte order and pci byte orders are different.
  2653. */
  2654. entry = lpfc_resp_iocb(phba, pring);
  2655. phba->last_completion_time = jiffies;
  2656. if (++pring->rspidx >= portRspMax)
  2657. pring->rspidx = 0;
  2658. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2659. (uint32_t *) &rspiocbq.iocb,
  2660. phba->iocb_rsp_size);
  2661. INIT_LIST_HEAD(&(rspiocbq.list));
  2662. irsp = &rspiocbq.iocb;
  2663. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2664. pring->stats.iocb_rsp++;
  2665. rsp_cmpl++;
  2666. if (unlikely(irsp->ulpStatus)) {
  2667. /*
  2668. * If resource errors reported from HBA, reduce
  2669. * queuedepths of the SCSI device.
  2670. */
  2671. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2672. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2673. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2674. phba->lpfc_rampdown_queue_depth(phba);
  2675. spin_lock_irqsave(&phba->hbalock, iflag);
  2676. }
  2677. /* Rsp ring <ringno> error: IOCB */
  2678. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2679. "0336 Rsp Ring %d error: IOCB Data: "
  2680. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2681. pring->ringno,
  2682. irsp->un.ulpWord[0],
  2683. irsp->un.ulpWord[1],
  2684. irsp->un.ulpWord[2],
  2685. irsp->un.ulpWord[3],
  2686. irsp->un.ulpWord[4],
  2687. irsp->un.ulpWord[5],
  2688. *(uint32_t *)&irsp->un1,
  2689. *((uint32_t *)&irsp->un1 + 1));
  2690. }
  2691. switch (type) {
  2692. case LPFC_ABORT_IOCB:
  2693. case LPFC_SOL_IOCB:
  2694. /*
  2695. * Idle exchange closed via ABTS from port. No iocb
  2696. * resources need to be recovered.
  2697. */
  2698. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2699. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2700. "0333 IOCB cmd 0x%x"
  2701. " processed. Skipping"
  2702. " completion\n",
  2703. irsp->ulpCommand);
  2704. break;
  2705. }
  2706. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2707. &rspiocbq);
  2708. if (unlikely(!cmdiocbq))
  2709. break;
  2710. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2711. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2712. if (cmdiocbq->iocb_cmpl) {
  2713. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2714. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2715. &rspiocbq);
  2716. spin_lock_irqsave(&phba->hbalock, iflag);
  2717. }
  2718. break;
  2719. case LPFC_UNSOL_IOCB:
  2720. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2721. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2722. spin_lock_irqsave(&phba->hbalock, iflag);
  2723. break;
  2724. default:
  2725. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2726. char adaptermsg[LPFC_MAX_ADPTMSG];
  2727. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2728. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2729. MAX_MSG_DATA);
  2730. dev_warn(&((phba->pcidev)->dev),
  2731. "lpfc%d: %s\n",
  2732. phba->brd_no, adaptermsg);
  2733. } else {
  2734. /* Unknown IOCB command */
  2735. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2736. "0334 Unknown IOCB command "
  2737. "Data: x%x, x%x x%x x%x x%x\n",
  2738. type, irsp->ulpCommand,
  2739. irsp->ulpStatus,
  2740. irsp->ulpIoTag,
  2741. irsp->ulpContext);
  2742. }
  2743. break;
  2744. }
  2745. /*
  2746. * The response IOCB has been processed. Update the ring
  2747. * pointer in SLIM. If the port response put pointer has not
  2748. * been updated, sync the pgp->rspPutInx and fetch the new port
  2749. * response put pointer.
  2750. */
  2751. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2752. if (pring->rspidx == portRspPut)
  2753. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2754. }
  2755. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2756. pring->stats.iocb_rsp_full++;
  2757. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2758. writel(status, phba->CAregaddr);
  2759. readl(phba->CAregaddr);
  2760. }
  2761. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2762. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2763. pring->stats.iocb_cmd_empty++;
  2764. /* Force update of the local copy of cmdGetInx */
  2765. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2766. lpfc_sli_resume_iocb(phba, pring);
  2767. if ((pring->lpfc_sli_cmd_available))
  2768. (pring->lpfc_sli_cmd_available) (phba, pring);
  2769. }
  2770. phba->fcp_ring_in_use = 0;
  2771. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2772. return rc;
  2773. }
  2774. /**
  2775. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2776. * @phba: Pointer to HBA context object.
  2777. * @pring: Pointer to driver SLI ring object.
  2778. * @rspiocbp: Pointer to driver response IOCB object.
  2779. *
  2780. * This function is called from the worker thread when there is a slow-path
  2781. * response IOCB to process. This function chains all the response iocbs until
  2782. * seeing the iocb with the LE bit set. The function will call
  2783. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2784. * completion of a command iocb. The function will call the
  2785. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2786. * The function frees the resources or calls the completion handler if this
  2787. * iocb is an abort completion. The function returns NULL when the response
  2788. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2789. * this function shall chain the iocb on to the iocb_continueq and return the
  2790. * response iocb passed in.
  2791. **/
  2792. static struct lpfc_iocbq *
  2793. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2794. struct lpfc_iocbq *rspiocbp)
  2795. {
  2796. struct lpfc_iocbq *saveq;
  2797. struct lpfc_iocbq *cmdiocbp;
  2798. struct lpfc_iocbq *next_iocb;
  2799. IOCB_t *irsp = NULL;
  2800. uint32_t free_saveq;
  2801. uint8_t iocb_cmd_type;
  2802. lpfc_iocb_type type;
  2803. unsigned long iflag;
  2804. int rc;
  2805. spin_lock_irqsave(&phba->hbalock, iflag);
  2806. /* First add the response iocb to the countinueq list */
  2807. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2808. pring->iocb_continueq_cnt++;
  2809. /* Now, determine whetehr the list is completed for processing */
  2810. irsp = &rspiocbp->iocb;
  2811. if (irsp->ulpLe) {
  2812. /*
  2813. * By default, the driver expects to free all resources
  2814. * associated with this iocb completion.
  2815. */
  2816. free_saveq = 1;
  2817. saveq = list_get_first(&pring->iocb_continueq,
  2818. struct lpfc_iocbq, list);
  2819. irsp = &(saveq->iocb);
  2820. list_del_init(&pring->iocb_continueq);
  2821. pring->iocb_continueq_cnt = 0;
  2822. pring->stats.iocb_rsp++;
  2823. /*
  2824. * If resource errors reported from HBA, reduce
  2825. * queuedepths of the SCSI device.
  2826. */
  2827. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2828. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2829. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2830. phba->lpfc_rampdown_queue_depth(phba);
  2831. spin_lock_irqsave(&phba->hbalock, iflag);
  2832. }
  2833. if (irsp->ulpStatus) {
  2834. /* Rsp ring <ringno> error: IOCB */
  2835. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2836. "0328 Rsp Ring %d error: "
  2837. "IOCB Data: "
  2838. "x%x x%x x%x x%x "
  2839. "x%x x%x x%x x%x "
  2840. "x%x x%x x%x x%x "
  2841. "x%x x%x x%x x%x\n",
  2842. pring->ringno,
  2843. irsp->un.ulpWord[0],
  2844. irsp->un.ulpWord[1],
  2845. irsp->un.ulpWord[2],
  2846. irsp->un.ulpWord[3],
  2847. irsp->un.ulpWord[4],
  2848. irsp->un.ulpWord[5],
  2849. *(((uint32_t *) irsp) + 6),
  2850. *(((uint32_t *) irsp) + 7),
  2851. *(((uint32_t *) irsp) + 8),
  2852. *(((uint32_t *) irsp) + 9),
  2853. *(((uint32_t *) irsp) + 10),
  2854. *(((uint32_t *) irsp) + 11),
  2855. *(((uint32_t *) irsp) + 12),
  2856. *(((uint32_t *) irsp) + 13),
  2857. *(((uint32_t *) irsp) + 14),
  2858. *(((uint32_t *) irsp) + 15));
  2859. }
  2860. /*
  2861. * Fetch the IOCB command type and call the correct completion
  2862. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2863. * get freed back to the lpfc_iocb_list by the discovery
  2864. * kernel thread.
  2865. */
  2866. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2867. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2868. switch (type) {
  2869. case LPFC_SOL_IOCB:
  2870. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2871. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2872. spin_lock_irqsave(&phba->hbalock, iflag);
  2873. break;
  2874. case LPFC_UNSOL_IOCB:
  2875. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2876. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2877. spin_lock_irqsave(&phba->hbalock, iflag);
  2878. if (!rc)
  2879. free_saveq = 0;
  2880. break;
  2881. case LPFC_ABORT_IOCB:
  2882. cmdiocbp = NULL;
  2883. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2884. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2885. saveq);
  2886. if (cmdiocbp) {
  2887. /* Call the specified completion routine */
  2888. if (cmdiocbp->iocb_cmpl) {
  2889. spin_unlock_irqrestore(&phba->hbalock,
  2890. iflag);
  2891. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2892. saveq);
  2893. spin_lock_irqsave(&phba->hbalock,
  2894. iflag);
  2895. } else
  2896. __lpfc_sli_release_iocbq(phba,
  2897. cmdiocbp);
  2898. }
  2899. break;
  2900. case LPFC_UNKNOWN_IOCB:
  2901. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2902. char adaptermsg[LPFC_MAX_ADPTMSG];
  2903. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2904. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2905. MAX_MSG_DATA);
  2906. dev_warn(&((phba->pcidev)->dev),
  2907. "lpfc%d: %s\n",
  2908. phba->brd_no, adaptermsg);
  2909. } else {
  2910. /* Unknown IOCB command */
  2911. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2912. "0335 Unknown IOCB "
  2913. "command Data: x%x "
  2914. "x%x x%x x%x\n",
  2915. irsp->ulpCommand,
  2916. irsp->ulpStatus,
  2917. irsp->ulpIoTag,
  2918. irsp->ulpContext);
  2919. }
  2920. break;
  2921. }
  2922. if (free_saveq) {
  2923. list_for_each_entry_safe(rspiocbp, next_iocb,
  2924. &saveq->list, list) {
  2925. list_del(&rspiocbp->list);
  2926. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2927. }
  2928. __lpfc_sli_release_iocbq(phba, saveq);
  2929. }
  2930. rspiocbp = NULL;
  2931. }
  2932. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2933. return rspiocbp;
  2934. }
  2935. /**
  2936. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2937. * @phba: Pointer to HBA context object.
  2938. * @pring: Pointer to driver SLI ring object.
  2939. * @mask: Host attention register mask for this ring.
  2940. *
  2941. * This routine wraps the actual slow_ring event process routine from the
  2942. * API jump table function pointer from the lpfc_hba struct.
  2943. **/
  2944. void
  2945. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2946. struct lpfc_sli_ring *pring, uint32_t mask)
  2947. {
  2948. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2949. }
  2950. /**
  2951. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2952. * @phba: Pointer to HBA context object.
  2953. * @pring: Pointer to driver SLI ring object.
  2954. * @mask: Host attention register mask for this ring.
  2955. *
  2956. * This function is called from the worker thread when there is a ring event
  2957. * for non-fcp rings. The caller does not hold any lock. The function will
  2958. * remove each response iocb in the response ring and calls the handle
  2959. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2960. **/
  2961. static void
  2962. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2963. struct lpfc_sli_ring *pring, uint32_t mask)
  2964. {
  2965. struct lpfc_pgp *pgp;
  2966. IOCB_t *entry;
  2967. IOCB_t *irsp = NULL;
  2968. struct lpfc_iocbq *rspiocbp = NULL;
  2969. uint32_t portRspPut, portRspMax;
  2970. unsigned long iflag;
  2971. uint32_t status;
  2972. pgp = &phba->port_gp[pring->ringno];
  2973. spin_lock_irqsave(&phba->hbalock, iflag);
  2974. pring->stats.iocb_event++;
  2975. /*
  2976. * The next available response entry should never exceed the maximum
  2977. * entries. If it does, treat it as an adapter hardware error.
  2978. */
  2979. portRspMax = pring->numRiocb;
  2980. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2981. if (portRspPut >= portRspMax) {
  2982. /*
  2983. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2984. * rsp ring <portRspMax>
  2985. */
  2986. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2987. "0303 Ring %d handler: portRspPut %d "
  2988. "is bigger than rsp ring %d\n",
  2989. pring->ringno, portRspPut, portRspMax);
  2990. phba->link_state = LPFC_HBA_ERROR;
  2991. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2992. phba->work_hs = HS_FFER3;
  2993. lpfc_handle_eratt(phba);
  2994. return;
  2995. }
  2996. rmb();
  2997. while (pring->rspidx != portRspPut) {
  2998. /*
  2999. * Build a completion list and call the appropriate handler.
  3000. * The process is to get the next available response iocb, get
  3001. * a free iocb from the list, copy the response data into the
  3002. * free iocb, insert to the continuation list, and update the
  3003. * next response index to slim. This process makes response
  3004. * iocb's in the ring available to DMA as fast as possible but
  3005. * pays a penalty for a copy operation. Since the iocb is
  3006. * only 32 bytes, this penalty is considered small relative to
  3007. * the PCI reads for register values and a slim write. When
  3008. * the ulpLe field is set, the entire Command has been
  3009. * received.
  3010. */
  3011. entry = lpfc_resp_iocb(phba, pring);
  3012. phba->last_completion_time = jiffies;
  3013. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3014. if (rspiocbp == NULL) {
  3015. printk(KERN_ERR "%s: out of buffers! Failing "
  3016. "completion.\n", __func__);
  3017. break;
  3018. }
  3019. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3020. phba->iocb_rsp_size);
  3021. irsp = &rspiocbp->iocb;
  3022. if (++pring->rspidx >= portRspMax)
  3023. pring->rspidx = 0;
  3024. if (pring->ringno == LPFC_ELS_RING) {
  3025. lpfc_debugfs_slow_ring_trc(phba,
  3026. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3027. *(((uint32_t *) irsp) + 4),
  3028. *(((uint32_t *) irsp) + 6),
  3029. *(((uint32_t *) irsp) + 7));
  3030. }
  3031. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3032. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3033. /* Handle the response IOCB */
  3034. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3035. spin_lock_irqsave(&phba->hbalock, iflag);
  3036. /*
  3037. * If the port response put pointer has not been updated, sync
  3038. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3039. * response put pointer.
  3040. */
  3041. if (pring->rspidx == portRspPut) {
  3042. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3043. }
  3044. } /* while (pring->rspidx != portRspPut) */
  3045. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3046. /* At least one response entry has been freed */
  3047. pring->stats.iocb_rsp_full++;
  3048. /* SET RxRE_RSP in Chip Att register */
  3049. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3050. writel(status, phba->CAregaddr);
  3051. readl(phba->CAregaddr); /* flush */
  3052. }
  3053. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3054. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3055. pring->stats.iocb_cmd_empty++;
  3056. /* Force update of the local copy of cmdGetInx */
  3057. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3058. lpfc_sli_resume_iocb(phba, pring);
  3059. if ((pring->lpfc_sli_cmd_available))
  3060. (pring->lpfc_sli_cmd_available) (phba, pring);
  3061. }
  3062. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3063. return;
  3064. }
  3065. /**
  3066. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3067. * @phba: Pointer to HBA context object.
  3068. * @pring: Pointer to driver SLI ring object.
  3069. * @mask: Host attention register mask for this ring.
  3070. *
  3071. * This function is called from the worker thread when there is a pending
  3072. * ELS response iocb on the driver internal slow-path response iocb worker
  3073. * queue. The caller does not hold any lock. The function will remove each
  3074. * response iocb from the response worker queue and calls the handle
  3075. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3076. **/
  3077. static void
  3078. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3079. struct lpfc_sli_ring *pring, uint32_t mask)
  3080. {
  3081. struct lpfc_iocbq *irspiocbq;
  3082. struct hbq_dmabuf *dmabuf;
  3083. struct lpfc_cq_event *cq_event;
  3084. unsigned long iflag;
  3085. spin_lock_irqsave(&phba->hbalock, iflag);
  3086. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3087. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3088. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3089. /* Get the response iocb from the head of work queue */
  3090. spin_lock_irqsave(&phba->hbalock, iflag);
  3091. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3092. cq_event, struct lpfc_cq_event, list);
  3093. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3094. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3095. case CQE_CODE_COMPL_WQE:
  3096. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3097. cq_event);
  3098. /* Translate ELS WCQE to response IOCBQ */
  3099. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3100. irspiocbq);
  3101. if (irspiocbq)
  3102. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3103. irspiocbq);
  3104. break;
  3105. case CQE_CODE_RECEIVE:
  3106. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3107. cq_event);
  3108. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3109. break;
  3110. default:
  3111. break;
  3112. }
  3113. }
  3114. }
  3115. /**
  3116. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3117. * @phba: Pointer to HBA context object.
  3118. * @pring: Pointer to driver SLI ring object.
  3119. *
  3120. * This function aborts all iocbs in the given ring and frees all the iocb
  3121. * objects in txq. This function issues an abort iocb for all the iocb commands
  3122. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3123. * the return of this function. The caller is not required to hold any locks.
  3124. **/
  3125. void
  3126. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3127. {
  3128. LIST_HEAD(completions);
  3129. struct lpfc_iocbq *iocb, *next_iocb;
  3130. if (pring->ringno == LPFC_ELS_RING) {
  3131. lpfc_fabric_abort_hba(phba);
  3132. }
  3133. /* Error everything on txq and txcmplq
  3134. * First do the txq.
  3135. */
  3136. spin_lock_irq(&phba->hbalock);
  3137. list_splice_init(&pring->txq, &completions);
  3138. pring->txq_cnt = 0;
  3139. /* Next issue ABTS for everything on the txcmplq */
  3140. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3141. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3142. spin_unlock_irq(&phba->hbalock);
  3143. /* Cancel all the IOCBs from the completions list */
  3144. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3145. IOERR_SLI_ABORTED);
  3146. }
  3147. /**
  3148. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3149. * @phba: Pointer to HBA context object.
  3150. *
  3151. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3152. * objects in txq and txcmplq. This function will not issue abort iocbs
  3153. * for all the iocb commands in txcmplq, they will just be returned with
  3154. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3155. * slot has been permanently disabled.
  3156. **/
  3157. void
  3158. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3159. {
  3160. LIST_HEAD(txq);
  3161. LIST_HEAD(txcmplq);
  3162. struct lpfc_sli *psli = &phba->sli;
  3163. struct lpfc_sli_ring *pring;
  3164. /* Currently, only one fcp ring */
  3165. pring = &psli->ring[psli->fcp_ring];
  3166. spin_lock_irq(&phba->hbalock);
  3167. /* Retrieve everything on txq */
  3168. list_splice_init(&pring->txq, &txq);
  3169. pring->txq_cnt = 0;
  3170. /* Retrieve everything on the txcmplq */
  3171. list_splice_init(&pring->txcmplq, &txcmplq);
  3172. pring->txcmplq_cnt = 0;
  3173. spin_unlock_irq(&phba->hbalock);
  3174. /* Flush the txq */
  3175. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3176. IOERR_SLI_DOWN);
  3177. /* Flush the txcmpq */
  3178. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3179. IOERR_SLI_DOWN);
  3180. }
  3181. /**
  3182. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3183. * @phba: Pointer to HBA context object.
  3184. * @mask: Bit mask to be checked.
  3185. *
  3186. * This function reads the host status register and compares
  3187. * with the provided bit mask to check if HBA completed
  3188. * the restart. This function will wait in a loop for the
  3189. * HBA to complete restart. If the HBA does not restart within
  3190. * 15 iterations, the function will reset the HBA again. The
  3191. * function returns 1 when HBA fail to restart otherwise returns
  3192. * zero.
  3193. **/
  3194. static int
  3195. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3196. {
  3197. uint32_t status;
  3198. int i = 0;
  3199. int retval = 0;
  3200. /* Read the HBA Host Status Register */
  3201. status = readl(phba->HSregaddr);
  3202. /*
  3203. * Check status register every 100ms for 5 retries, then every
  3204. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3205. * every 2.5 sec for 4.
  3206. * Break our of the loop if errors occurred during init.
  3207. */
  3208. while (((status & mask) != mask) &&
  3209. !(status & HS_FFERM) &&
  3210. i++ < 20) {
  3211. if (i <= 5)
  3212. msleep(10);
  3213. else if (i <= 10)
  3214. msleep(500);
  3215. else
  3216. msleep(2500);
  3217. if (i == 15) {
  3218. /* Do post */
  3219. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3220. lpfc_sli_brdrestart(phba);
  3221. }
  3222. /* Read the HBA Host Status Register */
  3223. status = readl(phba->HSregaddr);
  3224. }
  3225. /* Check to see if any errors occurred during init */
  3226. if ((status & HS_FFERM) || (i >= 20)) {
  3227. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3228. "2751 Adapter failed to restart, "
  3229. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3230. status,
  3231. readl(phba->MBslimaddr + 0xa8),
  3232. readl(phba->MBslimaddr + 0xac));
  3233. phba->link_state = LPFC_HBA_ERROR;
  3234. retval = 1;
  3235. }
  3236. return retval;
  3237. }
  3238. /**
  3239. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3240. * @phba: Pointer to HBA context object.
  3241. * @mask: Bit mask to be checked.
  3242. *
  3243. * This function checks the host status register to check if HBA is
  3244. * ready. This function will wait in a loop for the HBA to be ready
  3245. * If the HBA is not ready , the function will will reset the HBA PCI
  3246. * function again. The function returns 1 when HBA fail to be ready
  3247. * otherwise returns zero.
  3248. **/
  3249. static int
  3250. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3251. {
  3252. uint32_t status;
  3253. int retval = 0;
  3254. /* Read the HBA Host Status Register */
  3255. status = lpfc_sli4_post_status_check(phba);
  3256. if (status) {
  3257. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3258. lpfc_sli_brdrestart(phba);
  3259. status = lpfc_sli4_post_status_check(phba);
  3260. }
  3261. /* Check to see if any errors occurred during init */
  3262. if (status) {
  3263. phba->link_state = LPFC_HBA_ERROR;
  3264. retval = 1;
  3265. } else
  3266. phba->sli4_hba.intr_enable = 0;
  3267. return retval;
  3268. }
  3269. /**
  3270. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3271. * @phba: Pointer to HBA context object.
  3272. * @mask: Bit mask to be checked.
  3273. *
  3274. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3275. * from the API jump table function pointer from the lpfc_hba struct.
  3276. **/
  3277. int
  3278. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3279. {
  3280. return phba->lpfc_sli_brdready(phba, mask);
  3281. }
  3282. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3283. /**
  3284. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3285. * @phba: Pointer to HBA context object.
  3286. *
  3287. * This function is called before resetting an HBA. This
  3288. * function requests HBA to quiesce DMAs before a reset.
  3289. **/
  3290. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3291. {
  3292. uint32_t __iomem *resp_buf;
  3293. uint32_t __iomem *mbox_buf;
  3294. volatile uint32_t mbox;
  3295. uint32_t hc_copy;
  3296. int i;
  3297. uint8_t hdrtype;
  3298. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3299. if (hdrtype != 0x80 ||
  3300. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3301. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3302. return;
  3303. /*
  3304. * Tell the other part of the chip to suspend temporarily all
  3305. * its DMA activity.
  3306. */
  3307. resp_buf = phba->MBslimaddr;
  3308. /* Disable the error attention */
  3309. hc_copy = readl(phba->HCregaddr);
  3310. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3311. readl(phba->HCregaddr); /* flush */
  3312. phba->link_flag |= LS_IGNORE_ERATT;
  3313. if (readl(phba->HAregaddr) & HA_ERATT) {
  3314. /* Clear Chip error bit */
  3315. writel(HA_ERATT, phba->HAregaddr);
  3316. phba->pport->stopped = 1;
  3317. }
  3318. mbox = 0;
  3319. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3320. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3321. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3322. mbox_buf = phba->MBslimaddr;
  3323. writel(mbox, mbox_buf);
  3324. for (i = 0;
  3325. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  3326. mdelay(1);
  3327. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  3328. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3329. phba->pport->stopped)
  3330. goto restore_hc;
  3331. else
  3332. goto clear_errat;
  3333. }
  3334. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3335. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  3336. mdelay(1);
  3337. clear_errat:
  3338. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3339. mdelay(1);
  3340. if (readl(phba->HAregaddr) & HA_ERATT) {
  3341. writel(HA_ERATT, phba->HAregaddr);
  3342. phba->pport->stopped = 1;
  3343. }
  3344. restore_hc:
  3345. phba->link_flag &= ~LS_IGNORE_ERATT;
  3346. writel(hc_copy, phba->HCregaddr);
  3347. readl(phba->HCregaddr); /* flush */
  3348. }
  3349. /**
  3350. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3351. * @phba: Pointer to HBA context object.
  3352. *
  3353. * This function issues a kill_board mailbox command and waits for
  3354. * the error attention interrupt. This function is called for stopping
  3355. * the firmware processing. The caller is not required to hold any
  3356. * locks. This function calls lpfc_hba_down_post function to free
  3357. * any pending commands after the kill. The function will return 1 when it
  3358. * fails to kill the board else will return 0.
  3359. **/
  3360. int
  3361. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3362. {
  3363. struct lpfc_sli *psli;
  3364. LPFC_MBOXQ_t *pmb;
  3365. uint32_t status;
  3366. uint32_t ha_copy;
  3367. int retval;
  3368. int i = 0;
  3369. psli = &phba->sli;
  3370. /* Kill HBA */
  3371. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3372. "0329 Kill HBA Data: x%x x%x\n",
  3373. phba->pport->port_state, psli->sli_flag);
  3374. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3375. if (!pmb)
  3376. return 1;
  3377. /* Disable the error attention */
  3378. spin_lock_irq(&phba->hbalock);
  3379. status = readl(phba->HCregaddr);
  3380. status &= ~HC_ERINT_ENA;
  3381. writel(status, phba->HCregaddr);
  3382. readl(phba->HCregaddr); /* flush */
  3383. phba->link_flag |= LS_IGNORE_ERATT;
  3384. spin_unlock_irq(&phba->hbalock);
  3385. lpfc_kill_board(phba, pmb);
  3386. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3387. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3388. if (retval != MBX_SUCCESS) {
  3389. if (retval != MBX_BUSY)
  3390. mempool_free(pmb, phba->mbox_mem_pool);
  3391. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3392. "2752 KILL_BOARD command failed retval %d\n",
  3393. retval);
  3394. spin_lock_irq(&phba->hbalock);
  3395. phba->link_flag &= ~LS_IGNORE_ERATT;
  3396. spin_unlock_irq(&phba->hbalock);
  3397. return 1;
  3398. }
  3399. spin_lock_irq(&phba->hbalock);
  3400. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3401. spin_unlock_irq(&phba->hbalock);
  3402. mempool_free(pmb, phba->mbox_mem_pool);
  3403. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3404. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3405. * 3 seconds we still set HBA_ERROR state because the status of the
  3406. * board is now undefined.
  3407. */
  3408. ha_copy = readl(phba->HAregaddr);
  3409. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3410. mdelay(100);
  3411. ha_copy = readl(phba->HAregaddr);
  3412. }
  3413. del_timer_sync(&psli->mbox_tmo);
  3414. if (ha_copy & HA_ERATT) {
  3415. writel(HA_ERATT, phba->HAregaddr);
  3416. phba->pport->stopped = 1;
  3417. }
  3418. spin_lock_irq(&phba->hbalock);
  3419. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3420. psli->mbox_active = NULL;
  3421. phba->link_flag &= ~LS_IGNORE_ERATT;
  3422. spin_unlock_irq(&phba->hbalock);
  3423. lpfc_hba_down_post(phba);
  3424. phba->link_state = LPFC_HBA_ERROR;
  3425. return ha_copy & HA_ERATT ? 0 : 1;
  3426. }
  3427. /**
  3428. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3429. * @phba: Pointer to HBA context object.
  3430. *
  3431. * This function resets the HBA by writing HC_INITFF to the control
  3432. * register. After the HBA resets, this function resets all the iocb ring
  3433. * indices. This function disables PCI layer parity checking during
  3434. * the reset.
  3435. * This function returns 0 always.
  3436. * The caller is not required to hold any locks.
  3437. **/
  3438. int
  3439. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3440. {
  3441. struct lpfc_sli *psli;
  3442. struct lpfc_sli_ring *pring;
  3443. uint16_t cfg_value;
  3444. int i;
  3445. psli = &phba->sli;
  3446. /* Reset HBA */
  3447. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3448. "0325 Reset HBA Data: x%x x%x\n",
  3449. phba->pport->port_state, psli->sli_flag);
  3450. /* perform board reset */
  3451. phba->fc_eventTag = 0;
  3452. phba->link_events = 0;
  3453. phba->pport->fc_myDID = 0;
  3454. phba->pport->fc_prevDID = 0;
  3455. /* Turn off parity checking and serr during the physical reset */
  3456. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3457. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3458. (cfg_value &
  3459. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3460. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3461. /* Now toggle INITFF bit in the Host Control Register */
  3462. writel(HC_INITFF, phba->HCregaddr);
  3463. mdelay(1);
  3464. readl(phba->HCregaddr); /* flush */
  3465. writel(0, phba->HCregaddr);
  3466. readl(phba->HCregaddr); /* flush */
  3467. /* Restore PCI cmd register */
  3468. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3469. /* Initialize relevant SLI info */
  3470. for (i = 0; i < psli->num_rings; i++) {
  3471. pring = &psli->ring[i];
  3472. pring->flag = 0;
  3473. pring->rspidx = 0;
  3474. pring->next_cmdidx = 0;
  3475. pring->local_getidx = 0;
  3476. pring->cmdidx = 0;
  3477. pring->missbufcnt = 0;
  3478. }
  3479. phba->link_state = LPFC_WARM_START;
  3480. return 0;
  3481. }
  3482. /**
  3483. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3484. * @phba: Pointer to HBA context object.
  3485. *
  3486. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3487. * checking during resets the device. The caller is not required to hold
  3488. * any locks.
  3489. *
  3490. * This function returns 0 always.
  3491. **/
  3492. int
  3493. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3494. {
  3495. struct lpfc_sli *psli = &phba->sli;
  3496. uint16_t cfg_value;
  3497. uint8_t qindx;
  3498. /* Reset HBA */
  3499. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3500. "0295 Reset HBA Data: x%x x%x\n",
  3501. phba->pport->port_state, psli->sli_flag);
  3502. /* perform board reset */
  3503. phba->fc_eventTag = 0;
  3504. phba->link_events = 0;
  3505. phba->pport->fc_myDID = 0;
  3506. phba->pport->fc_prevDID = 0;
  3507. spin_lock_irq(&phba->hbalock);
  3508. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3509. phba->fcf.fcf_flag = 0;
  3510. /* Clean up the child queue list for the CQs */
  3511. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3512. list_del_init(&phba->sli4_hba.els_wq->list);
  3513. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3514. list_del_init(&phba->sli4_hba.dat_rq->list);
  3515. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3516. list_del_init(&phba->sli4_hba.els_cq->list);
  3517. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3518. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3519. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3520. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3521. spin_unlock_irq(&phba->hbalock);
  3522. /* Now physically reset the device */
  3523. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3524. "0389 Performing PCI function reset!\n");
  3525. /* Turn off parity checking and serr during the physical reset */
  3526. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3527. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3528. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3529. /* Perform FCoE PCI function reset */
  3530. lpfc_pci_function_reset(phba);
  3531. /* Restore PCI cmd register */
  3532. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3533. return 0;
  3534. }
  3535. /**
  3536. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3537. * @phba: Pointer to HBA context object.
  3538. *
  3539. * This function is called in the SLI initialization code path to
  3540. * restart the HBA. The caller is not required to hold any lock.
  3541. * This function writes MBX_RESTART mailbox command to the SLIM and
  3542. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3543. * function to free any pending commands. The function enables
  3544. * POST only during the first initialization. The function returns zero.
  3545. * The function does not guarantee completion of MBX_RESTART mailbox
  3546. * command before the return of this function.
  3547. **/
  3548. static int
  3549. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3550. {
  3551. MAILBOX_t *mb;
  3552. struct lpfc_sli *psli;
  3553. volatile uint32_t word0;
  3554. void __iomem *to_slim;
  3555. uint32_t hba_aer_enabled;
  3556. spin_lock_irq(&phba->hbalock);
  3557. /* Take PCIe device Advanced Error Reporting (AER) state */
  3558. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3559. psli = &phba->sli;
  3560. /* Restart HBA */
  3561. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3562. "0337 Restart HBA Data: x%x x%x\n",
  3563. phba->pport->port_state, psli->sli_flag);
  3564. word0 = 0;
  3565. mb = (MAILBOX_t *) &word0;
  3566. mb->mbxCommand = MBX_RESTART;
  3567. mb->mbxHc = 1;
  3568. lpfc_reset_barrier(phba);
  3569. to_slim = phba->MBslimaddr;
  3570. writel(*(uint32_t *) mb, to_slim);
  3571. readl(to_slim); /* flush */
  3572. /* Only skip post after fc_ffinit is completed */
  3573. if (phba->pport->port_state)
  3574. word0 = 1; /* This is really setting up word1 */
  3575. else
  3576. word0 = 0; /* This is really setting up word1 */
  3577. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3578. writel(*(uint32_t *) mb, to_slim);
  3579. readl(to_slim); /* flush */
  3580. lpfc_sli_brdreset(phba);
  3581. phba->pport->stopped = 0;
  3582. phba->link_state = LPFC_INIT_START;
  3583. phba->hba_flag = 0;
  3584. spin_unlock_irq(&phba->hbalock);
  3585. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3586. psli->stats_start = get_seconds();
  3587. /* Give the INITFF and Post time to settle. */
  3588. mdelay(100);
  3589. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3590. if (hba_aer_enabled)
  3591. pci_disable_pcie_error_reporting(phba->pcidev);
  3592. lpfc_hba_down_post(phba);
  3593. return 0;
  3594. }
  3595. /**
  3596. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3597. * @phba: Pointer to HBA context object.
  3598. *
  3599. * This function is called in the SLI initialization code path to restart
  3600. * a SLI4 HBA. The caller is not required to hold any lock.
  3601. * At the end of the function, it calls lpfc_hba_down_post function to
  3602. * free any pending commands.
  3603. **/
  3604. static int
  3605. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3606. {
  3607. struct lpfc_sli *psli = &phba->sli;
  3608. uint32_t hba_aer_enabled;
  3609. /* Restart HBA */
  3610. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3611. "0296 Restart HBA Data: x%x x%x\n",
  3612. phba->pport->port_state, psli->sli_flag);
  3613. /* Take PCIe device Advanced Error Reporting (AER) state */
  3614. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3615. lpfc_sli4_brdreset(phba);
  3616. spin_lock_irq(&phba->hbalock);
  3617. phba->pport->stopped = 0;
  3618. phba->link_state = LPFC_INIT_START;
  3619. phba->hba_flag = 0;
  3620. spin_unlock_irq(&phba->hbalock);
  3621. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3622. psli->stats_start = get_seconds();
  3623. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3624. if (hba_aer_enabled)
  3625. pci_disable_pcie_error_reporting(phba->pcidev);
  3626. lpfc_hba_down_post(phba);
  3627. return 0;
  3628. }
  3629. /**
  3630. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3631. * @phba: Pointer to HBA context object.
  3632. *
  3633. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3634. * API jump table function pointer from the lpfc_hba struct.
  3635. **/
  3636. int
  3637. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3638. {
  3639. return phba->lpfc_sli_brdrestart(phba);
  3640. }
  3641. /**
  3642. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3643. * @phba: Pointer to HBA context object.
  3644. *
  3645. * This function is called after a HBA restart to wait for successful
  3646. * restart of the HBA. Successful restart of the HBA is indicated by
  3647. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3648. * iteration, the function will restart the HBA again. The function returns
  3649. * zero if HBA successfully restarted else returns negative error code.
  3650. **/
  3651. static int
  3652. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3653. {
  3654. uint32_t status, i = 0;
  3655. /* Read the HBA Host Status Register */
  3656. status = readl(phba->HSregaddr);
  3657. /* Check status register to see what current state is */
  3658. i = 0;
  3659. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3660. /* Check every 10ms for 10 retries, then every 100ms for 90
  3661. * retries, then every 1 sec for 50 retires for a total of
  3662. * ~60 seconds before reset the board again and check every
  3663. * 1 sec for 50 retries. The up to 60 seconds before the
  3664. * board ready is required by the Falcon FIPS zeroization
  3665. * complete, and any reset the board in between shall cause
  3666. * restart of zeroization, further delay the board ready.
  3667. */
  3668. if (i++ >= 200) {
  3669. /* Adapter failed to init, timeout, status reg
  3670. <status> */
  3671. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3672. "0436 Adapter failed to init, "
  3673. "timeout, status reg x%x, "
  3674. "FW Data: A8 x%x AC x%x\n", status,
  3675. readl(phba->MBslimaddr + 0xa8),
  3676. readl(phba->MBslimaddr + 0xac));
  3677. phba->link_state = LPFC_HBA_ERROR;
  3678. return -ETIMEDOUT;
  3679. }
  3680. /* Check to see if any errors occurred during init */
  3681. if (status & HS_FFERM) {
  3682. /* ERROR: During chipset initialization */
  3683. /* Adapter failed to init, chipset, status reg
  3684. <status> */
  3685. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3686. "0437 Adapter failed to init, "
  3687. "chipset, status reg x%x, "
  3688. "FW Data: A8 x%x AC x%x\n", status,
  3689. readl(phba->MBslimaddr + 0xa8),
  3690. readl(phba->MBslimaddr + 0xac));
  3691. phba->link_state = LPFC_HBA_ERROR;
  3692. return -EIO;
  3693. }
  3694. if (i <= 10)
  3695. msleep(10);
  3696. else if (i <= 100)
  3697. msleep(100);
  3698. else
  3699. msleep(1000);
  3700. if (i == 150) {
  3701. /* Do post */
  3702. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3703. lpfc_sli_brdrestart(phba);
  3704. }
  3705. /* Read the HBA Host Status Register */
  3706. status = readl(phba->HSregaddr);
  3707. }
  3708. /* Check to see if any errors occurred during init */
  3709. if (status & HS_FFERM) {
  3710. /* ERROR: During chipset initialization */
  3711. /* Adapter failed to init, chipset, status reg <status> */
  3712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3713. "0438 Adapter failed to init, chipset, "
  3714. "status reg x%x, "
  3715. "FW Data: A8 x%x AC x%x\n", status,
  3716. readl(phba->MBslimaddr + 0xa8),
  3717. readl(phba->MBslimaddr + 0xac));
  3718. phba->link_state = LPFC_HBA_ERROR;
  3719. return -EIO;
  3720. }
  3721. /* Clear all interrupt enable conditions */
  3722. writel(0, phba->HCregaddr);
  3723. readl(phba->HCregaddr); /* flush */
  3724. /* setup host attn register */
  3725. writel(0xffffffff, phba->HAregaddr);
  3726. readl(phba->HAregaddr); /* flush */
  3727. return 0;
  3728. }
  3729. /**
  3730. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3731. *
  3732. * This function calculates and returns the number of HBQs required to be
  3733. * configured.
  3734. **/
  3735. int
  3736. lpfc_sli_hbq_count(void)
  3737. {
  3738. return ARRAY_SIZE(lpfc_hbq_defs);
  3739. }
  3740. /**
  3741. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3742. *
  3743. * This function adds the number of hbq entries in every HBQ to get
  3744. * the total number of hbq entries required for the HBA and returns
  3745. * the total count.
  3746. **/
  3747. static int
  3748. lpfc_sli_hbq_entry_count(void)
  3749. {
  3750. int hbq_count = lpfc_sli_hbq_count();
  3751. int count = 0;
  3752. int i;
  3753. for (i = 0; i < hbq_count; ++i)
  3754. count += lpfc_hbq_defs[i]->entry_count;
  3755. return count;
  3756. }
  3757. /**
  3758. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3759. *
  3760. * This function calculates amount of memory required for all hbq entries
  3761. * to be configured and returns the total memory required.
  3762. **/
  3763. int
  3764. lpfc_sli_hbq_size(void)
  3765. {
  3766. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3767. }
  3768. /**
  3769. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3770. * @phba: Pointer to HBA context object.
  3771. *
  3772. * This function is called during the SLI initialization to configure
  3773. * all the HBQs and post buffers to the HBQ. The caller is not
  3774. * required to hold any locks. This function will return zero if successful
  3775. * else it will return negative error code.
  3776. **/
  3777. static int
  3778. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3779. {
  3780. int hbq_count = lpfc_sli_hbq_count();
  3781. LPFC_MBOXQ_t *pmb;
  3782. MAILBOX_t *pmbox;
  3783. uint32_t hbqno;
  3784. uint32_t hbq_entry_index;
  3785. /* Get a Mailbox buffer to setup mailbox
  3786. * commands for HBA initialization
  3787. */
  3788. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3789. if (!pmb)
  3790. return -ENOMEM;
  3791. pmbox = &pmb->u.mb;
  3792. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3793. phba->link_state = LPFC_INIT_MBX_CMDS;
  3794. phba->hbq_in_use = 1;
  3795. hbq_entry_index = 0;
  3796. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3797. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3798. phba->hbqs[hbqno].hbqPutIdx = 0;
  3799. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3800. phba->hbqs[hbqno].entry_count =
  3801. lpfc_hbq_defs[hbqno]->entry_count;
  3802. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3803. hbq_entry_index, pmb);
  3804. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3805. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3806. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3807. mbxStatus <status>, ring <num> */
  3808. lpfc_printf_log(phba, KERN_ERR,
  3809. LOG_SLI | LOG_VPORT,
  3810. "1805 Adapter failed to init. "
  3811. "Data: x%x x%x x%x\n",
  3812. pmbox->mbxCommand,
  3813. pmbox->mbxStatus, hbqno);
  3814. phba->link_state = LPFC_HBA_ERROR;
  3815. mempool_free(pmb, phba->mbox_mem_pool);
  3816. return -ENXIO;
  3817. }
  3818. }
  3819. phba->hbq_count = hbq_count;
  3820. mempool_free(pmb, phba->mbox_mem_pool);
  3821. /* Initially populate or replenish the HBQs */
  3822. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3823. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3824. return 0;
  3825. }
  3826. /**
  3827. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3828. * @phba: Pointer to HBA context object.
  3829. *
  3830. * This function is called during the SLI initialization to configure
  3831. * all the HBQs and post buffers to the HBQ. The caller is not
  3832. * required to hold any locks. This function will return zero if successful
  3833. * else it will return negative error code.
  3834. **/
  3835. static int
  3836. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3837. {
  3838. phba->hbq_in_use = 1;
  3839. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3840. phba->hbq_count = 1;
  3841. /* Initially populate or replenish the HBQs */
  3842. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3843. return 0;
  3844. }
  3845. /**
  3846. * lpfc_sli_config_port - Issue config port mailbox command
  3847. * @phba: Pointer to HBA context object.
  3848. * @sli_mode: sli mode - 2/3
  3849. *
  3850. * This function is called by the sli intialization code path
  3851. * to issue config_port mailbox command. This function restarts the
  3852. * HBA firmware and issues a config_port mailbox command to configure
  3853. * the SLI interface in the sli mode specified by sli_mode
  3854. * variable. The caller is not required to hold any locks.
  3855. * The function returns 0 if successful, else returns negative error
  3856. * code.
  3857. **/
  3858. int
  3859. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3860. {
  3861. LPFC_MBOXQ_t *pmb;
  3862. uint32_t resetcount = 0, rc = 0, done = 0;
  3863. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3864. if (!pmb) {
  3865. phba->link_state = LPFC_HBA_ERROR;
  3866. return -ENOMEM;
  3867. }
  3868. phba->sli_rev = sli_mode;
  3869. while (resetcount < 2 && !done) {
  3870. spin_lock_irq(&phba->hbalock);
  3871. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3872. spin_unlock_irq(&phba->hbalock);
  3873. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3874. lpfc_sli_brdrestart(phba);
  3875. rc = lpfc_sli_chipset_init(phba);
  3876. if (rc)
  3877. break;
  3878. spin_lock_irq(&phba->hbalock);
  3879. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3880. spin_unlock_irq(&phba->hbalock);
  3881. resetcount++;
  3882. /* Call pre CONFIG_PORT mailbox command initialization. A
  3883. * value of 0 means the call was successful. Any other
  3884. * nonzero value is a failure, but if ERESTART is returned,
  3885. * the driver may reset the HBA and try again.
  3886. */
  3887. rc = lpfc_config_port_prep(phba);
  3888. if (rc == -ERESTART) {
  3889. phba->link_state = LPFC_LINK_UNKNOWN;
  3890. continue;
  3891. } else if (rc)
  3892. break;
  3893. phba->link_state = LPFC_INIT_MBX_CMDS;
  3894. lpfc_config_port(phba, pmb);
  3895. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3896. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3897. LPFC_SLI3_HBQ_ENABLED |
  3898. LPFC_SLI3_CRP_ENABLED |
  3899. LPFC_SLI3_BG_ENABLED |
  3900. LPFC_SLI3_DSS_ENABLED);
  3901. if (rc != MBX_SUCCESS) {
  3902. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3903. "0442 Adapter failed to init, mbxCmd x%x "
  3904. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3905. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3906. spin_lock_irq(&phba->hbalock);
  3907. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3908. spin_unlock_irq(&phba->hbalock);
  3909. rc = -ENXIO;
  3910. } else {
  3911. /* Allow asynchronous mailbox command to go through */
  3912. spin_lock_irq(&phba->hbalock);
  3913. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3914. spin_unlock_irq(&phba->hbalock);
  3915. done = 1;
  3916. }
  3917. }
  3918. if (!done) {
  3919. rc = -EINVAL;
  3920. goto do_prep_failed;
  3921. }
  3922. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3923. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3924. rc = -ENXIO;
  3925. goto do_prep_failed;
  3926. }
  3927. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3928. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3929. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3930. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3931. phba->max_vpi : phba->max_vports;
  3932. } else
  3933. phba->max_vpi = 0;
  3934. phba->fips_level = 0;
  3935. phba->fips_spec_rev = 0;
  3936. if (pmb->u.mb.un.varCfgPort.gdss) {
  3937. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3938. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3939. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3940. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3941. "2850 Security Crypto Active. FIPS x%d "
  3942. "(Spec Rev: x%d)",
  3943. phba->fips_level, phba->fips_spec_rev);
  3944. }
  3945. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3946. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3947. "2856 Config Port Security Crypto "
  3948. "Error: x%x ",
  3949. pmb->u.mb.un.varCfgPort.sec_err);
  3950. }
  3951. if (pmb->u.mb.un.varCfgPort.gerbm)
  3952. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3953. if (pmb->u.mb.un.varCfgPort.gcrp)
  3954. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3955. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3956. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3957. if (phba->cfg_enable_bg) {
  3958. if (pmb->u.mb.un.varCfgPort.gbg)
  3959. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3960. else
  3961. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3962. "0443 Adapter did not grant "
  3963. "BlockGuard\n");
  3964. }
  3965. } else {
  3966. phba->hbq_get = NULL;
  3967. phba->port_gp = phba->mbox->us.s2.port;
  3968. phba->max_vpi = 0;
  3969. }
  3970. do_prep_failed:
  3971. mempool_free(pmb, phba->mbox_mem_pool);
  3972. return rc;
  3973. }
  3974. /**
  3975. * lpfc_sli_hba_setup - SLI intialization function
  3976. * @phba: Pointer to HBA context object.
  3977. *
  3978. * This function is the main SLI intialization function. This function
  3979. * is called by the HBA intialization code, HBA reset code and HBA
  3980. * error attention handler code. Caller is not required to hold any
  3981. * locks. This function issues config_port mailbox command to configure
  3982. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3983. * calls the config_port_post function to issue init_link mailbox
  3984. * command and to start the discovery. The function will return zero
  3985. * if successful, else it will return negative error code.
  3986. **/
  3987. int
  3988. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3989. {
  3990. uint32_t rc;
  3991. int mode = 3;
  3992. switch (lpfc_sli_mode) {
  3993. case 2:
  3994. if (phba->cfg_enable_npiv) {
  3995. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3996. "1824 NPIV enabled: Override lpfc_sli_mode "
  3997. "parameter (%d) to auto (0).\n",
  3998. lpfc_sli_mode);
  3999. break;
  4000. }
  4001. mode = 2;
  4002. break;
  4003. case 0:
  4004. case 3:
  4005. break;
  4006. default:
  4007. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4008. "1819 Unrecognized lpfc_sli_mode "
  4009. "parameter: %d.\n", lpfc_sli_mode);
  4010. break;
  4011. }
  4012. rc = lpfc_sli_config_port(phba, mode);
  4013. if (rc && lpfc_sli_mode == 3)
  4014. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4015. "1820 Unable to select SLI-3. "
  4016. "Not supported by adapter.\n");
  4017. if (rc && mode != 2)
  4018. rc = lpfc_sli_config_port(phba, 2);
  4019. if (rc)
  4020. goto lpfc_sli_hba_setup_error;
  4021. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4022. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4023. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4024. if (!rc) {
  4025. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4026. "2709 This device supports "
  4027. "Advanced Error Reporting (AER)\n");
  4028. spin_lock_irq(&phba->hbalock);
  4029. phba->hba_flag |= HBA_AER_ENABLED;
  4030. spin_unlock_irq(&phba->hbalock);
  4031. } else {
  4032. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4033. "2708 This device does not support "
  4034. "Advanced Error Reporting (AER)\n");
  4035. phba->cfg_aer_support = 0;
  4036. }
  4037. }
  4038. if (phba->sli_rev == 3) {
  4039. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4040. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4041. } else {
  4042. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4043. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4044. phba->sli3_options = 0;
  4045. }
  4046. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4047. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4048. phba->sli_rev, phba->max_vpi);
  4049. rc = lpfc_sli_ring_map(phba);
  4050. if (rc)
  4051. goto lpfc_sli_hba_setup_error;
  4052. /* Init HBQs */
  4053. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4054. rc = lpfc_sli_hbq_setup(phba);
  4055. if (rc)
  4056. goto lpfc_sli_hba_setup_error;
  4057. }
  4058. spin_lock_irq(&phba->hbalock);
  4059. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4060. spin_unlock_irq(&phba->hbalock);
  4061. rc = lpfc_config_port_post(phba);
  4062. if (rc)
  4063. goto lpfc_sli_hba_setup_error;
  4064. return rc;
  4065. lpfc_sli_hba_setup_error:
  4066. phba->link_state = LPFC_HBA_ERROR;
  4067. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4068. "0445 Firmware initialization failed\n");
  4069. return rc;
  4070. }
  4071. /**
  4072. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4073. * @phba: Pointer to HBA context object.
  4074. * @mboxq: mailbox pointer.
  4075. * This function issue a dump mailbox command to read config region
  4076. * 23 and parse the records in the region and populate driver
  4077. * data structure.
  4078. **/
  4079. static int
  4080. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4081. LPFC_MBOXQ_t *mboxq)
  4082. {
  4083. struct lpfc_dmabuf *mp;
  4084. struct lpfc_mqe *mqe;
  4085. uint32_t data_length;
  4086. int rc;
  4087. /* Program the default value of vlan_id and fc_map */
  4088. phba->valid_vlan = 0;
  4089. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4090. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4091. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4092. mqe = &mboxq->u.mqe;
  4093. if (lpfc_dump_fcoe_param(phba, mboxq))
  4094. return -ENOMEM;
  4095. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4096. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4097. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4098. "(%d):2571 Mailbox cmd x%x Status x%x "
  4099. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4100. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4101. "CQ: x%x x%x x%x x%x\n",
  4102. mboxq->vport ? mboxq->vport->vpi : 0,
  4103. bf_get(lpfc_mqe_command, mqe),
  4104. bf_get(lpfc_mqe_status, mqe),
  4105. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4106. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4107. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4108. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4109. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4110. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4111. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4112. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4113. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4114. mboxq->mcqe.word0,
  4115. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4116. mboxq->mcqe.trailer);
  4117. if (rc) {
  4118. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4119. kfree(mp);
  4120. return -EIO;
  4121. }
  4122. data_length = mqe->un.mb_words[5];
  4123. if (data_length > DMP_RGN23_SIZE) {
  4124. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4125. kfree(mp);
  4126. return -EIO;
  4127. }
  4128. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4129. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4130. kfree(mp);
  4131. return 0;
  4132. }
  4133. /**
  4134. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4135. * @phba: pointer to lpfc hba data structure.
  4136. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4137. * @vpd: pointer to the memory to hold resulting port vpd data.
  4138. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4139. * On output, the number of data bytes in @vpd.
  4140. *
  4141. * This routine executes a READ_REV SLI4 mailbox command. In
  4142. * addition, this routine gets the port vpd data.
  4143. *
  4144. * Return codes
  4145. * 0 - successful
  4146. * -ENOMEM - could not allocated memory.
  4147. **/
  4148. static int
  4149. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4150. uint8_t *vpd, uint32_t *vpd_size)
  4151. {
  4152. int rc = 0;
  4153. uint32_t dma_size;
  4154. struct lpfc_dmabuf *dmabuf;
  4155. struct lpfc_mqe *mqe;
  4156. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4157. if (!dmabuf)
  4158. return -ENOMEM;
  4159. /*
  4160. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4161. * mailbox command.
  4162. */
  4163. dma_size = *vpd_size;
  4164. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4165. dma_size,
  4166. &dmabuf->phys,
  4167. GFP_KERNEL);
  4168. if (!dmabuf->virt) {
  4169. kfree(dmabuf);
  4170. return -ENOMEM;
  4171. }
  4172. memset(dmabuf->virt, 0, dma_size);
  4173. /*
  4174. * The SLI4 implementation of READ_REV conflicts at word1,
  4175. * bits 31:16 and SLI4 adds vpd functionality not present
  4176. * in SLI3. This code corrects the conflicts.
  4177. */
  4178. lpfc_read_rev(phba, mboxq);
  4179. mqe = &mboxq->u.mqe;
  4180. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4181. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4182. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4183. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4184. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4185. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4186. if (rc) {
  4187. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4188. dmabuf->virt, dmabuf->phys);
  4189. kfree(dmabuf);
  4190. return -EIO;
  4191. }
  4192. /*
  4193. * The available vpd length cannot be bigger than the
  4194. * DMA buffer passed to the port. Catch the less than
  4195. * case and update the caller's size.
  4196. */
  4197. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4198. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4199. memcpy(vpd, dmabuf->virt, *vpd_size);
  4200. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4201. dmabuf->virt, dmabuf->phys);
  4202. kfree(dmabuf);
  4203. return 0;
  4204. }
  4205. /**
  4206. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4207. * @phba: pointer to lpfc hba data structure.
  4208. *
  4209. * This routine is called to explicitly arm the SLI4 device's completion and
  4210. * event queues
  4211. **/
  4212. static void
  4213. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4214. {
  4215. uint8_t fcp_eqidx;
  4216. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4217. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4218. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4219. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4220. LPFC_QUEUE_REARM);
  4221. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4222. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4223. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4224. LPFC_QUEUE_REARM);
  4225. }
  4226. /**
  4227. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4228. * @phba: Pointer to HBA context object.
  4229. *
  4230. * This function is the main SLI4 device intialization PCI function. This
  4231. * function is called by the HBA intialization code, HBA reset code and
  4232. * HBA error attention handler code. Caller is not required to hold any
  4233. * locks.
  4234. **/
  4235. int
  4236. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4237. {
  4238. int rc;
  4239. LPFC_MBOXQ_t *mboxq;
  4240. struct lpfc_mqe *mqe;
  4241. uint8_t *vpd;
  4242. uint32_t vpd_size;
  4243. uint32_t ftr_rsp = 0;
  4244. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4245. struct lpfc_vport *vport = phba->pport;
  4246. struct lpfc_dmabuf *mp;
  4247. /*
  4248. * TODO: Why does this routine execute these task in a different
  4249. * order from probe?
  4250. */
  4251. /* Perform a PCI function reset to start from clean */
  4252. rc = lpfc_pci_function_reset(phba);
  4253. if (unlikely(rc))
  4254. return -ENODEV;
  4255. /* Check the HBA Host Status Register for readyness */
  4256. rc = lpfc_sli4_post_status_check(phba);
  4257. if (unlikely(rc))
  4258. return -ENODEV;
  4259. else {
  4260. spin_lock_irq(&phba->hbalock);
  4261. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4262. spin_unlock_irq(&phba->hbalock);
  4263. }
  4264. /*
  4265. * Allocate a single mailbox container for initializing the
  4266. * port.
  4267. */
  4268. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4269. if (!mboxq)
  4270. return -ENOMEM;
  4271. /*
  4272. * Continue initialization with default values even if driver failed
  4273. * to read FCoE param config regions
  4274. */
  4275. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4276. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4277. "2570 Failed to read FCoE parameters\n");
  4278. /* Issue READ_REV to collect vpd and FW information. */
  4279. vpd_size = SLI4_PAGE_SIZE;
  4280. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4281. if (!vpd) {
  4282. rc = -ENOMEM;
  4283. goto out_free_mbox;
  4284. }
  4285. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4286. if (unlikely(rc)) {
  4287. kfree(vpd);
  4288. goto out_free_mbox;
  4289. }
  4290. mqe = &mboxq->u.mqe;
  4291. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4292. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4293. phba->hba_flag |= HBA_FCOE_MODE;
  4294. else
  4295. phba->hba_flag &= ~HBA_FCOE_MODE;
  4296. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4297. LPFC_DCBX_CEE_MODE)
  4298. phba->hba_flag |= HBA_FIP_SUPPORT;
  4299. else
  4300. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4301. if (phba->sli_rev != LPFC_SLI_REV4 ||
  4302. !(phba->hba_flag & HBA_FCOE_MODE)) {
  4303. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4304. "0376 READ_REV Error. SLI Level %d "
  4305. "FCoE enabled %d\n",
  4306. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4307. rc = -EIO;
  4308. kfree(vpd);
  4309. goto out_free_mbox;
  4310. }
  4311. /*
  4312. * Evaluate the read rev and vpd data. Populate the driver
  4313. * state with the results. If this routine fails, the failure
  4314. * is not fatal as the driver will use generic values.
  4315. */
  4316. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4317. if (unlikely(!rc)) {
  4318. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4319. "0377 Error %d parsing vpd. "
  4320. "Using defaults.\n", rc);
  4321. rc = 0;
  4322. }
  4323. kfree(vpd);
  4324. /* Save information as VPD data */
  4325. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4326. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4327. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4328. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4329. &mqe->un.read_rev);
  4330. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4331. &mqe->un.read_rev);
  4332. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4333. &mqe->un.read_rev);
  4334. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4335. &mqe->un.read_rev);
  4336. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4337. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4338. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4339. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4340. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4341. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4342. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4343. "(%d):0380 READ_REV Status x%x "
  4344. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4345. mboxq->vport ? mboxq->vport->vpi : 0,
  4346. bf_get(lpfc_mqe_status, mqe),
  4347. phba->vpd.rev.opFwName,
  4348. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4349. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4350. /*
  4351. * Discover the port's supported feature set and match it against the
  4352. * hosts requests.
  4353. */
  4354. lpfc_request_features(phba, mboxq);
  4355. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4356. if (unlikely(rc)) {
  4357. rc = -EIO;
  4358. goto out_free_mbox;
  4359. }
  4360. /*
  4361. * The port must support FCP initiator mode as this is the
  4362. * only mode running in the host.
  4363. */
  4364. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4365. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4366. "0378 No support for fcpi mode.\n");
  4367. ftr_rsp++;
  4368. }
  4369. /*
  4370. * If the port cannot support the host's requested features
  4371. * then turn off the global config parameters to disable the
  4372. * feature in the driver. This is not a fatal error.
  4373. */
  4374. if ((phba->cfg_enable_bg) &&
  4375. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4376. ftr_rsp++;
  4377. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4378. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4379. ftr_rsp++;
  4380. if (ftr_rsp) {
  4381. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4382. "0379 Feature Mismatch Data: x%08x %08x "
  4383. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4384. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4385. phba->cfg_enable_npiv, phba->max_vpi);
  4386. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4387. phba->cfg_enable_bg = 0;
  4388. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4389. phba->cfg_enable_npiv = 0;
  4390. }
  4391. /* These SLI3 features are assumed in SLI4 */
  4392. spin_lock_irq(&phba->hbalock);
  4393. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4394. spin_unlock_irq(&phba->hbalock);
  4395. /* Read the port's service parameters. */
  4396. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4397. if (rc) {
  4398. phba->link_state = LPFC_HBA_ERROR;
  4399. rc = -ENOMEM;
  4400. goto out_free_mbox;
  4401. }
  4402. mboxq->vport = vport;
  4403. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4404. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4405. if (rc == MBX_SUCCESS) {
  4406. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4407. rc = 0;
  4408. }
  4409. /*
  4410. * This memory was allocated by the lpfc_read_sparam routine. Release
  4411. * it to the mbuf pool.
  4412. */
  4413. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4414. kfree(mp);
  4415. mboxq->context1 = NULL;
  4416. if (unlikely(rc)) {
  4417. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4418. "0382 READ_SPARAM command failed "
  4419. "status %d, mbxStatus x%x\n",
  4420. rc, bf_get(lpfc_mqe_status, mqe));
  4421. phba->link_state = LPFC_HBA_ERROR;
  4422. rc = -EIO;
  4423. goto out_free_mbox;
  4424. }
  4425. if (phba->cfg_soft_wwnn)
  4426. u64_to_wwn(phba->cfg_soft_wwnn,
  4427. vport->fc_sparam.nodeName.u.wwn);
  4428. if (phba->cfg_soft_wwpn)
  4429. u64_to_wwn(phba->cfg_soft_wwpn,
  4430. vport->fc_sparam.portName.u.wwn);
  4431. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4432. sizeof(struct lpfc_name));
  4433. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4434. sizeof(struct lpfc_name));
  4435. /* Update the fc_host data structures with new wwn. */
  4436. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4437. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4438. /* Register SGL pool to the device using non-embedded mailbox command */
  4439. rc = lpfc_sli4_post_sgl_list(phba);
  4440. if (unlikely(rc)) {
  4441. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4442. "0582 Error %d during sgl post operation\n",
  4443. rc);
  4444. rc = -ENODEV;
  4445. goto out_free_mbox;
  4446. }
  4447. /* Register SCSI SGL pool to the device */
  4448. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4449. if (unlikely(rc)) {
  4450. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4451. "0383 Error %d during scsi sgl post "
  4452. "operation\n", rc);
  4453. /* Some Scsi buffers were moved to the abort scsi list */
  4454. /* A pci function reset will repost them */
  4455. rc = -ENODEV;
  4456. goto out_free_mbox;
  4457. }
  4458. /* Post the rpi header region to the device. */
  4459. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4460. if (unlikely(rc)) {
  4461. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4462. "0393 Error %d during rpi post operation\n",
  4463. rc);
  4464. rc = -ENODEV;
  4465. goto out_free_mbox;
  4466. }
  4467. /* Set up all the queues to the device */
  4468. rc = lpfc_sli4_queue_setup(phba);
  4469. if (unlikely(rc)) {
  4470. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4471. "0381 Error %d during queue setup.\n ", rc);
  4472. goto out_stop_timers;
  4473. }
  4474. /* Arm the CQs and then EQs on device */
  4475. lpfc_sli4_arm_cqeq_intr(phba);
  4476. /* Indicate device interrupt mode */
  4477. phba->sli4_hba.intr_enable = 1;
  4478. /* Allow asynchronous mailbox command to go through */
  4479. spin_lock_irq(&phba->hbalock);
  4480. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4481. spin_unlock_irq(&phba->hbalock);
  4482. /* Post receive buffers to the device */
  4483. lpfc_sli4_rb_setup(phba);
  4484. /* Reset HBA FCF states after HBA reset */
  4485. phba->fcf.fcf_flag = 0;
  4486. phba->fcf.current_rec.flag = 0;
  4487. /* Start the ELS watchdog timer */
  4488. mod_timer(&vport->els_tmofunc,
  4489. jiffies + HZ * (phba->fc_ratov * 2));
  4490. /* Start heart beat timer */
  4491. mod_timer(&phba->hb_tmofunc,
  4492. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4493. phba->hb_outstanding = 0;
  4494. phba->last_completion_time = jiffies;
  4495. /* Start error attention (ERATT) polling timer */
  4496. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4497. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4498. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4499. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4500. if (!rc) {
  4501. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4502. "2829 This device supports "
  4503. "Advanced Error Reporting (AER)\n");
  4504. spin_lock_irq(&phba->hbalock);
  4505. phba->hba_flag |= HBA_AER_ENABLED;
  4506. spin_unlock_irq(&phba->hbalock);
  4507. } else {
  4508. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4509. "2830 This device does not support "
  4510. "Advanced Error Reporting (AER)\n");
  4511. phba->cfg_aer_support = 0;
  4512. }
  4513. }
  4514. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4515. /*
  4516. * The FC Port needs to register FCFI (index 0)
  4517. */
  4518. lpfc_reg_fcfi(phba, mboxq);
  4519. mboxq->vport = phba->pport;
  4520. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4521. if (rc == MBX_SUCCESS)
  4522. rc = 0;
  4523. else
  4524. goto out_unset_queue;
  4525. }
  4526. /*
  4527. * The port is ready, set the host's link state to LINK_DOWN
  4528. * in preparation for link interrupts.
  4529. */
  4530. spin_lock_irq(&phba->hbalock);
  4531. phba->link_state = LPFC_LINK_DOWN;
  4532. spin_unlock_irq(&phba->hbalock);
  4533. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4534. out_unset_queue:
  4535. /* Unset all the queues set up in this routine when error out */
  4536. if (rc)
  4537. lpfc_sli4_queue_unset(phba);
  4538. out_stop_timers:
  4539. if (rc)
  4540. lpfc_stop_hba_timers(phba);
  4541. out_free_mbox:
  4542. mempool_free(mboxq, phba->mbox_mem_pool);
  4543. return rc;
  4544. }
  4545. /**
  4546. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4547. * @ptr: context object - pointer to hba structure.
  4548. *
  4549. * This is the callback function for mailbox timer. The mailbox
  4550. * timer is armed when a new mailbox command is issued and the timer
  4551. * is deleted when the mailbox complete. The function is called by
  4552. * the kernel timer code when a mailbox does not complete within
  4553. * expected time. This function wakes up the worker thread to
  4554. * process the mailbox timeout and returns. All the processing is
  4555. * done by the worker thread function lpfc_mbox_timeout_handler.
  4556. **/
  4557. void
  4558. lpfc_mbox_timeout(unsigned long ptr)
  4559. {
  4560. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4561. unsigned long iflag;
  4562. uint32_t tmo_posted;
  4563. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4564. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4565. if (!tmo_posted)
  4566. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4567. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4568. if (!tmo_posted)
  4569. lpfc_worker_wake_up(phba);
  4570. return;
  4571. }
  4572. /**
  4573. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4574. * @phba: Pointer to HBA context object.
  4575. *
  4576. * This function is called from worker thread when a mailbox command times out.
  4577. * The caller is not required to hold any locks. This function will reset the
  4578. * HBA and recover all the pending commands.
  4579. **/
  4580. void
  4581. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4582. {
  4583. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4584. MAILBOX_t *mb = &pmbox->u.mb;
  4585. struct lpfc_sli *psli = &phba->sli;
  4586. struct lpfc_sli_ring *pring;
  4587. /* Check the pmbox pointer first. There is a race condition
  4588. * between the mbox timeout handler getting executed in the
  4589. * worklist and the mailbox actually completing. When this
  4590. * race condition occurs, the mbox_active will be NULL.
  4591. */
  4592. spin_lock_irq(&phba->hbalock);
  4593. if (pmbox == NULL) {
  4594. lpfc_printf_log(phba, KERN_WARNING,
  4595. LOG_MBOX | LOG_SLI,
  4596. "0353 Active Mailbox cleared - mailbox timeout "
  4597. "exiting\n");
  4598. spin_unlock_irq(&phba->hbalock);
  4599. return;
  4600. }
  4601. /* Mbox cmd <mbxCommand> timeout */
  4602. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4603. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4604. mb->mbxCommand,
  4605. phba->pport->port_state,
  4606. phba->sli.sli_flag,
  4607. phba->sli.mbox_active);
  4608. spin_unlock_irq(&phba->hbalock);
  4609. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4610. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4611. * it to fail all oustanding SCSI IO.
  4612. */
  4613. spin_lock_irq(&phba->pport->work_port_lock);
  4614. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4615. spin_unlock_irq(&phba->pport->work_port_lock);
  4616. spin_lock_irq(&phba->hbalock);
  4617. phba->link_state = LPFC_LINK_UNKNOWN;
  4618. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4619. spin_unlock_irq(&phba->hbalock);
  4620. pring = &psli->ring[psli->fcp_ring];
  4621. lpfc_sli_abort_iocb_ring(phba, pring);
  4622. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4623. "0345 Resetting board due to mailbox timeout\n");
  4624. /* Reset the HBA device */
  4625. lpfc_reset_hba(phba);
  4626. }
  4627. /**
  4628. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4629. * @phba: Pointer to HBA context object.
  4630. * @pmbox: Pointer to mailbox object.
  4631. * @flag: Flag indicating how the mailbox need to be processed.
  4632. *
  4633. * This function is called by discovery code and HBA management code
  4634. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4635. * function gets the hbalock to protect the data structures.
  4636. * The mailbox command can be submitted in polling mode, in which case
  4637. * this function will wait in a polling loop for the completion of the
  4638. * mailbox.
  4639. * If the mailbox is submitted in no_wait mode (not polling) the
  4640. * function will submit the command and returns immediately without waiting
  4641. * for the mailbox completion. The no_wait is supported only when HBA
  4642. * is in SLI2/SLI3 mode - interrupts are enabled.
  4643. * The SLI interface allows only one mailbox pending at a time. If the
  4644. * mailbox is issued in polling mode and there is already a mailbox
  4645. * pending, then the function will return an error. If the mailbox is issued
  4646. * in NO_WAIT mode and there is a mailbox pending already, the function
  4647. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4648. * The sli layer owns the mailbox object until the completion of mailbox
  4649. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4650. * return codes the caller owns the mailbox command after the return of
  4651. * the function.
  4652. **/
  4653. static int
  4654. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4655. uint32_t flag)
  4656. {
  4657. MAILBOX_t *mb;
  4658. struct lpfc_sli *psli = &phba->sli;
  4659. uint32_t status, evtctr;
  4660. uint32_t ha_copy;
  4661. int i;
  4662. unsigned long timeout;
  4663. unsigned long drvr_flag = 0;
  4664. uint32_t word0, ldata;
  4665. void __iomem *to_slim;
  4666. int processing_queue = 0;
  4667. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4668. if (!pmbox) {
  4669. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4670. /* processing mbox queue from intr_handler */
  4671. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4672. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4673. return MBX_SUCCESS;
  4674. }
  4675. processing_queue = 1;
  4676. pmbox = lpfc_mbox_get(phba);
  4677. if (!pmbox) {
  4678. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4679. return MBX_SUCCESS;
  4680. }
  4681. }
  4682. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4683. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4684. if(!pmbox->vport) {
  4685. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4686. lpfc_printf_log(phba, KERN_ERR,
  4687. LOG_MBOX | LOG_VPORT,
  4688. "1806 Mbox x%x failed. No vport\n",
  4689. pmbox->u.mb.mbxCommand);
  4690. dump_stack();
  4691. goto out_not_finished;
  4692. }
  4693. }
  4694. /* If the PCI channel is in offline state, do not post mbox. */
  4695. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4696. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4697. goto out_not_finished;
  4698. }
  4699. /* If HBA has a deferred error attention, fail the iocb. */
  4700. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4701. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4702. goto out_not_finished;
  4703. }
  4704. psli = &phba->sli;
  4705. mb = &pmbox->u.mb;
  4706. status = MBX_SUCCESS;
  4707. if (phba->link_state == LPFC_HBA_ERROR) {
  4708. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4709. /* Mbox command <mbxCommand> cannot issue */
  4710. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4711. "(%d):0311 Mailbox command x%x cannot "
  4712. "issue Data: x%x x%x\n",
  4713. pmbox->vport ? pmbox->vport->vpi : 0,
  4714. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4715. goto out_not_finished;
  4716. }
  4717. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4718. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4719. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4720. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4721. "(%d):2528 Mailbox command x%x cannot "
  4722. "issue Data: x%x x%x\n",
  4723. pmbox->vport ? pmbox->vport->vpi : 0,
  4724. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4725. goto out_not_finished;
  4726. }
  4727. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4728. /* Polling for a mbox command when another one is already active
  4729. * is not allowed in SLI. Also, the driver must have established
  4730. * SLI2 mode to queue and process multiple mbox commands.
  4731. */
  4732. if (flag & MBX_POLL) {
  4733. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4734. /* Mbox command <mbxCommand> cannot issue */
  4735. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4736. "(%d):2529 Mailbox command x%x "
  4737. "cannot issue Data: x%x x%x\n",
  4738. pmbox->vport ? pmbox->vport->vpi : 0,
  4739. pmbox->u.mb.mbxCommand,
  4740. psli->sli_flag, flag);
  4741. goto out_not_finished;
  4742. }
  4743. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4744. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4745. /* Mbox command <mbxCommand> cannot issue */
  4746. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4747. "(%d):2530 Mailbox command x%x "
  4748. "cannot issue Data: x%x x%x\n",
  4749. pmbox->vport ? pmbox->vport->vpi : 0,
  4750. pmbox->u.mb.mbxCommand,
  4751. psli->sli_flag, flag);
  4752. goto out_not_finished;
  4753. }
  4754. /* Another mailbox command is still being processed, queue this
  4755. * command to be processed later.
  4756. */
  4757. lpfc_mbox_put(phba, pmbox);
  4758. /* Mbox cmd issue - BUSY */
  4759. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4760. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4761. "x%x x%x x%x x%x\n",
  4762. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4763. mb->mbxCommand, phba->pport->port_state,
  4764. psli->sli_flag, flag);
  4765. psli->slistat.mbox_busy++;
  4766. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4767. if (pmbox->vport) {
  4768. lpfc_debugfs_disc_trc(pmbox->vport,
  4769. LPFC_DISC_TRC_MBOX_VPORT,
  4770. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4771. (uint32_t)mb->mbxCommand,
  4772. mb->un.varWords[0], mb->un.varWords[1]);
  4773. }
  4774. else {
  4775. lpfc_debugfs_disc_trc(phba->pport,
  4776. LPFC_DISC_TRC_MBOX,
  4777. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4778. (uint32_t)mb->mbxCommand,
  4779. mb->un.varWords[0], mb->un.varWords[1]);
  4780. }
  4781. return MBX_BUSY;
  4782. }
  4783. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4784. /* If we are not polling, we MUST be in SLI2 mode */
  4785. if (flag != MBX_POLL) {
  4786. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4787. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4788. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4789. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4790. /* Mbox command <mbxCommand> cannot issue */
  4791. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4792. "(%d):2531 Mailbox command x%x "
  4793. "cannot issue Data: x%x x%x\n",
  4794. pmbox->vport ? pmbox->vport->vpi : 0,
  4795. pmbox->u.mb.mbxCommand,
  4796. psli->sli_flag, flag);
  4797. goto out_not_finished;
  4798. }
  4799. /* timeout active mbox command */
  4800. mod_timer(&psli->mbox_tmo, (jiffies +
  4801. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4802. }
  4803. /* Mailbox cmd <cmd> issue */
  4804. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4805. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4806. "x%x\n",
  4807. pmbox->vport ? pmbox->vport->vpi : 0,
  4808. mb->mbxCommand, phba->pport->port_state,
  4809. psli->sli_flag, flag);
  4810. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4811. if (pmbox->vport) {
  4812. lpfc_debugfs_disc_trc(pmbox->vport,
  4813. LPFC_DISC_TRC_MBOX_VPORT,
  4814. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4815. (uint32_t)mb->mbxCommand,
  4816. mb->un.varWords[0], mb->un.varWords[1]);
  4817. }
  4818. else {
  4819. lpfc_debugfs_disc_trc(phba->pport,
  4820. LPFC_DISC_TRC_MBOX,
  4821. "MBOX Send: cmd:x%x mb:x%x x%x",
  4822. (uint32_t)mb->mbxCommand,
  4823. mb->un.varWords[0], mb->un.varWords[1]);
  4824. }
  4825. }
  4826. psli->slistat.mbox_cmd++;
  4827. evtctr = psli->slistat.mbox_event;
  4828. /* next set own bit for the adapter and copy over command word */
  4829. mb->mbxOwner = OWN_CHIP;
  4830. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4831. /* Populate mbox extension offset word. */
  4832. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4833. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4834. = (uint8_t *)phba->mbox_ext
  4835. - (uint8_t *)phba->mbox;
  4836. }
  4837. /* Copy the mailbox extension data */
  4838. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4839. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4840. (uint8_t *)phba->mbox_ext,
  4841. pmbox->in_ext_byte_len);
  4842. }
  4843. /* Copy command data to host SLIM area */
  4844. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4845. } else {
  4846. /* Populate mbox extension offset word. */
  4847. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4848. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4849. = MAILBOX_HBA_EXT_OFFSET;
  4850. /* Copy the mailbox extension data */
  4851. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4852. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4853. MAILBOX_HBA_EXT_OFFSET,
  4854. pmbox->context2, pmbox->in_ext_byte_len);
  4855. }
  4856. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4857. /* copy command data into host mbox for cmpl */
  4858. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4859. }
  4860. /* First copy mbox command data to HBA SLIM, skip past first
  4861. word */
  4862. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4863. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4864. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4865. /* Next copy over first word, with mbxOwner set */
  4866. ldata = *((uint32_t *)mb);
  4867. to_slim = phba->MBslimaddr;
  4868. writel(ldata, to_slim);
  4869. readl(to_slim); /* flush */
  4870. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4871. /* switch over to host mailbox */
  4872. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4873. }
  4874. }
  4875. wmb();
  4876. switch (flag) {
  4877. case MBX_NOWAIT:
  4878. /* Set up reference to mailbox command */
  4879. psli->mbox_active = pmbox;
  4880. /* Interrupt board to do it */
  4881. writel(CA_MBATT, phba->CAregaddr);
  4882. readl(phba->CAregaddr); /* flush */
  4883. /* Don't wait for it to finish, just return */
  4884. break;
  4885. case MBX_POLL:
  4886. /* Set up null reference to mailbox command */
  4887. psli->mbox_active = NULL;
  4888. /* Interrupt board to do it */
  4889. writel(CA_MBATT, phba->CAregaddr);
  4890. readl(phba->CAregaddr); /* flush */
  4891. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4892. /* First read mbox status word */
  4893. word0 = *((uint32_t *)phba->mbox);
  4894. word0 = le32_to_cpu(word0);
  4895. } else {
  4896. /* First read mbox status word */
  4897. word0 = readl(phba->MBslimaddr);
  4898. }
  4899. /* Read the HBA Host Attention Register */
  4900. ha_copy = readl(phba->HAregaddr);
  4901. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4902. mb->mbxCommand) *
  4903. 1000) + jiffies;
  4904. i = 0;
  4905. /* Wait for command to complete */
  4906. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4907. (!(ha_copy & HA_MBATT) &&
  4908. (phba->link_state > LPFC_WARM_START))) {
  4909. if (time_after(jiffies, timeout)) {
  4910. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4911. spin_unlock_irqrestore(&phba->hbalock,
  4912. drvr_flag);
  4913. goto out_not_finished;
  4914. }
  4915. /* Check if we took a mbox interrupt while we were
  4916. polling */
  4917. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4918. && (evtctr != psli->slistat.mbox_event))
  4919. break;
  4920. if (i++ > 10) {
  4921. spin_unlock_irqrestore(&phba->hbalock,
  4922. drvr_flag);
  4923. msleep(1);
  4924. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4925. }
  4926. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4927. /* First copy command data */
  4928. word0 = *((uint32_t *)phba->mbox);
  4929. word0 = le32_to_cpu(word0);
  4930. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4931. MAILBOX_t *slimmb;
  4932. uint32_t slimword0;
  4933. /* Check real SLIM for any errors */
  4934. slimword0 = readl(phba->MBslimaddr);
  4935. slimmb = (MAILBOX_t *) & slimword0;
  4936. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4937. && slimmb->mbxStatus) {
  4938. psli->sli_flag &=
  4939. ~LPFC_SLI_ACTIVE;
  4940. word0 = slimword0;
  4941. }
  4942. }
  4943. } else {
  4944. /* First copy command data */
  4945. word0 = readl(phba->MBslimaddr);
  4946. }
  4947. /* Read the HBA Host Attention Register */
  4948. ha_copy = readl(phba->HAregaddr);
  4949. }
  4950. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4951. /* copy results back to user */
  4952. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4953. /* Copy the mailbox extension data */
  4954. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4955. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4956. pmbox->context2,
  4957. pmbox->out_ext_byte_len);
  4958. }
  4959. } else {
  4960. /* First copy command data */
  4961. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4962. MAILBOX_CMD_SIZE);
  4963. /* Copy the mailbox extension data */
  4964. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4965. lpfc_memcpy_from_slim(pmbox->context2,
  4966. phba->MBslimaddr +
  4967. MAILBOX_HBA_EXT_OFFSET,
  4968. pmbox->out_ext_byte_len);
  4969. }
  4970. }
  4971. writel(HA_MBATT, phba->HAregaddr);
  4972. readl(phba->HAregaddr); /* flush */
  4973. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4974. status = mb->mbxStatus;
  4975. }
  4976. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4977. return status;
  4978. out_not_finished:
  4979. if (processing_queue) {
  4980. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4981. lpfc_mbox_cmpl_put(phba, pmbox);
  4982. }
  4983. return MBX_NOT_FINISHED;
  4984. }
  4985. /**
  4986. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4987. * @phba: Pointer to HBA context object.
  4988. *
  4989. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4990. * the driver internal pending mailbox queue. It will then try to wait out the
  4991. * possible outstanding mailbox command before return.
  4992. *
  4993. * Returns:
  4994. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4995. * the outstanding mailbox command timed out.
  4996. **/
  4997. static int
  4998. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4999. {
  5000. struct lpfc_sli *psli = &phba->sli;
  5001. uint8_t actcmd = MBX_HEARTBEAT;
  5002. int rc = 0;
  5003. unsigned long timeout;
  5004. /* Mark the asynchronous mailbox command posting as blocked */
  5005. spin_lock_irq(&phba->hbalock);
  5006. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  5007. if (phba->sli.mbox_active)
  5008. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  5009. spin_unlock_irq(&phba->hbalock);
  5010. /* Determine how long we might wait for the active mailbox
  5011. * command to be gracefully completed by firmware.
  5012. */
  5013. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5014. jiffies;
  5015. /* Wait for the outstnading mailbox command to complete */
  5016. while (phba->sli.mbox_active) {
  5017. /* Check active mailbox complete status every 2ms */
  5018. msleep(2);
  5019. if (time_after(jiffies, timeout)) {
  5020. /* Timeout, marked the outstanding cmd not complete */
  5021. rc = 1;
  5022. break;
  5023. }
  5024. }
  5025. /* Can not cleanly block async mailbox command, fails it */
  5026. if (rc) {
  5027. spin_lock_irq(&phba->hbalock);
  5028. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5029. spin_unlock_irq(&phba->hbalock);
  5030. }
  5031. return rc;
  5032. }
  5033. /**
  5034. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5035. * @phba: Pointer to HBA context object.
  5036. *
  5037. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5038. * commands from the driver internal pending mailbox queue. It makes sure
  5039. * that there is no outstanding mailbox command before resuming posting
  5040. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5041. * mailbox command, it will try to wait it out before resuming asynchronous
  5042. * mailbox command posting.
  5043. **/
  5044. static void
  5045. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5046. {
  5047. struct lpfc_sli *psli = &phba->sli;
  5048. spin_lock_irq(&phba->hbalock);
  5049. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5050. /* Asynchronous mailbox posting is not blocked, do nothing */
  5051. spin_unlock_irq(&phba->hbalock);
  5052. return;
  5053. }
  5054. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5055. * successful or timeout, after timing-out the outstanding mailbox
  5056. * command shall always be removed, so just unblock posting async
  5057. * mailbox command and resume
  5058. */
  5059. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5060. spin_unlock_irq(&phba->hbalock);
  5061. /* wake up worker thread to post asynchronlous mailbox command */
  5062. lpfc_worker_wake_up(phba);
  5063. }
  5064. /**
  5065. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5066. * @phba: Pointer to HBA context object.
  5067. * @mboxq: Pointer to mailbox object.
  5068. *
  5069. * The function posts a mailbox to the port. The mailbox is expected
  5070. * to be comletely filled in and ready for the port to operate on it.
  5071. * This routine executes a synchronous completion operation on the
  5072. * mailbox by polling for its completion.
  5073. *
  5074. * The caller must not be holding any locks when calling this routine.
  5075. *
  5076. * Returns:
  5077. * MBX_SUCCESS - mailbox posted successfully
  5078. * Any of the MBX error values.
  5079. **/
  5080. static int
  5081. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5082. {
  5083. int rc = MBX_SUCCESS;
  5084. unsigned long iflag;
  5085. uint32_t db_ready;
  5086. uint32_t mcqe_status;
  5087. uint32_t mbx_cmnd;
  5088. unsigned long timeout;
  5089. struct lpfc_sli *psli = &phba->sli;
  5090. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5091. struct lpfc_bmbx_create *mbox_rgn;
  5092. struct dma_address *dma_address;
  5093. struct lpfc_register bmbx_reg;
  5094. /*
  5095. * Only one mailbox can be active to the bootstrap mailbox region
  5096. * at a time and there is no queueing provided.
  5097. */
  5098. spin_lock_irqsave(&phba->hbalock, iflag);
  5099. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5100. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5101. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5102. "(%d):2532 Mailbox command x%x (x%x) "
  5103. "cannot issue Data: x%x x%x\n",
  5104. mboxq->vport ? mboxq->vport->vpi : 0,
  5105. mboxq->u.mb.mbxCommand,
  5106. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5107. psli->sli_flag, MBX_POLL);
  5108. return MBXERR_ERROR;
  5109. }
  5110. /* The server grabs the token and owns it until release */
  5111. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5112. phba->sli.mbox_active = mboxq;
  5113. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5114. /*
  5115. * Initialize the bootstrap memory region to avoid stale data areas
  5116. * in the mailbox post. Then copy the caller's mailbox contents to
  5117. * the bmbx mailbox region.
  5118. */
  5119. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5120. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5121. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5122. sizeof(struct lpfc_mqe));
  5123. /* Post the high mailbox dma address to the port and wait for ready. */
  5124. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5125. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5126. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5127. * 1000) + jiffies;
  5128. do {
  5129. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5130. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5131. if (!db_ready)
  5132. msleep(2);
  5133. if (time_after(jiffies, timeout)) {
  5134. rc = MBXERR_ERROR;
  5135. goto exit;
  5136. }
  5137. } while (!db_ready);
  5138. /* Post the low mailbox dma address to the port. */
  5139. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5140. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5141. * 1000) + jiffies;
  5142. do {
  5143. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5144. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5145. if (!db_ready)
  5146. msleep(2);
  5147. if (time_after(jiffies, timeout)) {
  5148. rc = MBXERR_ERROR;
  5149. goto exit;
  5150. }
  5151. } while (!db_ready);
  5152. /*
  5153. * Read the CQ to ensure the mailbox has completed.
  5154. * If so, update the mailbox status so that the upper layers
  5155. * can complete the request normally.
  5156. */
  5157. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5158. sizeof(struct lpfc_mqe));
  5159. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5160. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5161. sizeof(struct lpfc_mcqe));
  5162. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5163. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  5164. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5165. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  5166. rc = MBXERR_ERROR;
  5167. } else
  5168. lpfc_sli4_swap_str(phba, mboxq);
  5169. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5170. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5171. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5172. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5173. mboxq->vport ? mboxq->vport->vpi : 0,
  5174. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5175. bf_get(lpfc_mqe_status, mb),
  5176. mb->un.mb_words[0], mb->un.mb_words[1],
  5177. mb->un.mb_words[2], mb->un.mb_words[3],
  5178. mb->un.mb_words[4], mb->un.mb_words[5],
  5179. mb->un.mb_words[6], mb->un.mb_words[7],
  5180. mb->un.mb_words[8], mb->un.mb_words[9],
  5181. mb->un.mb_words[10], mb->un.mb_words[11],
  5182. mb->un.mb_words[12], mboxq->mcqe.word0,
  5183. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5184. mboxq->mcqe.trailer);
  5185. exit:
  5186. /* We are holding the token, no needed for lock when release */
  5187. spin_lock_irqsave(&phba->hbalock, iflag);
  5188. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5189. phba->sli.mbox_active = NULL;
  5190. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5191. return rc;
  5192. }
  5193. /**
  5194. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5195. * @phba: Pointer to HBA context object.
  5196. * @pmbox: Pointer to mailbox object.
  5197. * @flag: Flag indicating how the mailbox need to be processed.
  5198. *
  5199. * This function is called by discovery code and HBA management code to submit
  5200. * a mailbox command to firmware with SLI-4 interface spec.
  5201. *
  5202. * Return codes the caller owns the mailbox command after the return of the
  5203. * function.
  5204. **/
  5205. static int
  5206. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5207. uint32_t flag)
  5208. {
  5209. struct lpfc_sli *psli = &phba->sli;
  5210. unsigned long iflags;
  5211. int rc;
  5212. rc = lpfc_mbox_dev_check(phba);
  5213. if (unlikely(rc)) {
  5214. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5215. "(%d):2544 Mailbox command x%x (x%x) "
  5216. "cannot issue Data: x%x x%x\n",
  5217. mboxq->vport ? mboxq->vport->vpi : 0,
  5218. mboxq->u.mb.mbxCommand,
  5219. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5220. psli->sli_flag, flag);
  5221. goto out_not_finished;
  5222. }
  5223. /* Detect polling mode and jump to a handler */
  5224. if (!phba->sli4_hba.intr_enable) {
  5225. if (flag == MBX_POLL)
  5226. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5227. else
  5228. rc = -EIO;
  5229. if (rc != MBX_SUCCESS)
  5230. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5231. "(%d):2541 Mailbox command x%x "
  5232. "(x%x) cannot issue Data: x%x x%x\n",
  5233. mboxq->vport ? mboxq->vport->vpi : 0,
  5234. mboxq->u.mb.mbxCommand,
  5235. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5236. psli->sli_flag, flag);
  5237. return rc;
  5238. } else if (flag == MBX_POLL) {
  5239. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5240. "(%d):2542 Try to issue mailbox command "
  5241. "x%x (x%x) synchronously ahead of async"
  5242. "mailbox command queue: x%x x%x\n",
  5243. mboxq->vport ? mboxq->vport->vpi : 0,
  5244. mboxq->u.mb.mbxCommand,
  5245. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5246. psli->sli_flag, flag);
  5247. /* Try to block the asynchronous mailbox posting */
  5248. rc = lpfc_sli4_async_mbox_block(phba);
  5249. if (!rc) {
  5250. /* Successfully blocked, now issue sync mbox cmd */
  5251. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5252. if (rc != MBX_SUCCESS)
  5253. lpfc_printf_log(phba, KERN_ERR,
  5254. LOG_MBOX | LOG_SLI,
  5255. "(%d):2597 Mailbox command "
  5256. "x%x (x%x) cannot issue "
  5257. "Data: x%x x%x\n",
  5258. mboxq->vport ?
  5259. mboxq->vport->vpi : 0,
  5260. mboxq->u.mb.mbxCommand,
  5261. lpfc_sli4_mbox_opcode_get(phba,
  5262. mboxq),
  5263. psli->sli_flag, flag);
  5264. /* Unblock the async mailbox posting afterward */
  5265. lpfc_sli4_async_mbox_unblock(phba);
  5266. }
  5267. return rc;
  5268. }
  5269. /* Now, interrupt mode asynchrous mailbox command */
  5270. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5271. if (rc) {
  5272. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5273. "(%d):2543 Mailbox command x%x (x%x) "
  5274. "cannot issue Data: x%x x%x\n",
  5275. mboxq->vport ? mboxq->vport->vpi : 0,
  5276. mboxq->u.mb.mbxCommand,
  5277. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5278. psli->sli_flag, flag);
  5279. goto out_not_finished;
  5280. }
  5281. /* Put the mailbox command to the driver internal FIFO */
  5282. psli->slistat.mbox_busy++;
  5283. spin_lock_irqsave(&phba->hbalock, iflags);
  5284. lpfc_mbox_put(phba, mboxq);
  5285. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5286. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5287. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5288. "x%x (x%x) x%x x%x x%x\n",
  5289. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5290. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5291. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5292. phba->pport->port_state,
  5293. psli->sli_flag, MBX_NOWAIT);
  5294. /* Wake up worker thread to transport mailbox command from head */
  5295. lpfc_worker_wake_up(phba);
  5296. return MBX_BUSY;
  5297. out_not_finished:
  5298. return MBX_NOT_FINISHED;
  5299. }
  5300. /**
  5301. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5302. * @phba: Pointer to HBA context object.
  5303. *
  5304. * This function is called by worker thread to send a mailbox command to
  5305. * SLI4 HBA firmware.
  5306. *
  5307. **/
  5308. int
  5309. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5310. {
  5311. struct lpfc_sli *psli = &phba->sli;
  5312. LPFC_MBOXQ_t *mboxq;
  5313. int rc = MBX_SUCCESS;
  5314. unsigned long iflags;
  5315. struct lpfc_mqe *mqe;
  5316. uint32_t mbx_cmnd;
  5317. /* Check interrupt mode before post async mailbox command */
  5318. if (unlikely(!phba->sli4_hba.intr_enable))
  5319. return MBX_NOT_FINISHED;
  5320. /* Check for mailbox command service token */
  5321. spin_lock_irqsave(&phba->hbalock, iflags);
  5322. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5323. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5324. return MBX_NOT_FINISHED;
  5325. }
  5326. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5327. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5328. return MBX_NOT_FINISHED;
  5329. }
  5330. if (unlikely(phba->sli.mbox_active)) {
  5331. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5332. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5333. "0384 There is pending active mailbox cmd\n");
  5334. return MBX_NOT_FINISHED;
  5335. }
  5336. /* Take the mailbox command service token */
  5337. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5338. /* Get the next mailbox command from head of queue */
  5339. mboxq = lpfc_mbox_get(phba);
  5340. /* If no more mailbox command waiting for post, we're done */
  5341. if (!mboxq) {
  5342. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5343. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5344. return MBX_SUCCESS;
  5345. }
  5346. phba->sli.mbox_active = mboxq;
  5347. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5348. /* Check device readiness for posting mailbox command */
  5349. rc = lpfc_mbox_dev_check(phba);
  5350. if (unlikely(rc))
  5351. /* Driver clean routine will clean up pending mailbox */
  5352. goto out_not_finished;
  5353. /* Prepare the mbox command to be posted */
  5354. mqe = &mboxq->u.mqe;
  5355. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5356. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5357. mod_timer(&psli->mbox_tmo, (jiffies +
  5358. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5359. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5360. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5361. "x%x x%x\n",
  5362. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5363. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5364. phba->pport->port_state, psli->sli_flag);
  5365. if (mbx_cmnd != MBX_HEARTBEAT) {
  5366. if (mboxq->vport) {
  5367. lpfc_debugfs_disc_trc(mboxq->vport,
  5368. LPFC_DISC_TRC_MBOX_VPORT,
  5369. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5370. mbx_cmnd, mqe->un.mb_words[0],
  5371. mqe->un.mb_words[1]);
  5372. } else {
  5373. lpfc_debugfs_disc_trc(phba->pport,
  5374. LPFC_DISC_TRC_MBOX,
  5375. "MBOX Send: cmd:x%x mb:x%x x%x",
  5376. mbx_cmnd, mqe->un.mb_words[0],
  5377. mqe->un.mb_words[1]);
  5378. }
  5379. }
  5380. psli->slistat.mbox_cmd++;
  5381. /* Post the mailbox command to the port */
  5382. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5383. if (rc != MBX_SUCCESS) {
  5384. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5385. "(%d):2533 Mailbox command x%x (x%x) "
  5386. "cannot issue Data: x%x x%x\n",
  5387. mboxq->vport ? mboxq->vport->vpi : 0,
  5388. mboxq->u.mb.mbxCommand,
  5389. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5390. psli->sli_flag, MBX_NOWAIT);
  5391. goto out_not_finished;
  5392. }
  5393. return rc;
  5394. out_not_finished:
  5395. spin_lock_irqsave(&phba->hbalock, iflags);
  5396. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5397. __lpfc_mbox_cmpl_put(phba, mboxq);
  5398. /* Release the token */
  5399. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5400. phba->sli.mbox_active = NULL;
  5401. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5402. return MBX_NOT_FINISHED;
  5403. }
  5404. /**
  5405. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5406. * @phba: Pointer to HBA context object.
  5407. * @pmbox: Pointer to mailbox object.
  5408. * @flag: Flag indicating how the mailbox need to be processed.
  5409. *
  5410. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5411. * the API jump table function pointer from the lpfc_hba struct.
  5412. *
  5413. * Return codes the caller owns the mailbox command after the return of the
  5414. * function.
  5415. **/
  5416. int
  5417. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5418. {
  5419. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5420. }
  5421. /**
  5422. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5423. * @phba: The hba struct for which this call is being executed.
  5424. * @dev_grp: The HBA PCI-Device group number.
  5425. *
  5426. * This routine sets up the mbox interface API function jump table in @phba
  5427. * struct.
  5428. * Returns: 0 - success, -ENODEV - failure.
  5429. **/
  5430. int
  5431. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5432. {
  5433. switch (dev_grp) {
  5434. case LPFC_PCI_DEV_LP:
  5435. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5436. phba->lpfc_sli_handle_slow_ring_event =
  5437. lpfc_sli_handle_slow_ring_event_s3;
  5438. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5439. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5440. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5441. break;
  5442. case LPFC_PCI_DEV_OC:
  5443. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5444. phba->lpfc_sli_handle_slow_ring_event =
  5445. lpfc_sli_handle_slow_ring_event_s4;
  5446. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5447. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5448. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5449. break;
  5450. default:
  5451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5452. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5453. dev_grp);
  5454. return -ENODEV;
  5455. break;
  5456. }
  5457. return 0;
  5458. }
  5459. /**
  5460. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5461. * @phba: Pointer to HBA context object.
  5462. * @pring: Pointer to driver SLI ring object.
  5463. * @piocb: Pointer to address of newly added command iocb.
  5464. *
  5465. * This function is called with hbalock held to add a command
  5466. * iocb to the txq when SLI layer cannot submit the command iocb
  5467. * to the ring.
  5468. **/
  5469. void
  5470. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5471. struct lpfc_iocbq *piocb)
  5472. {
  5473. /* Insert the caller's iocb in the txq tail for later processing. */
  5474. list_add_tail(&piocb->list, &pring->txq);
  5475. pring->txq_cnt++;
  5476. }
  5477. /**
  5478. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5479. * @phba: Pointer to HBA context object.
  5480. * @pring: Pointer to driver SLI ring object.
  5481. * @piocb: Pointer to address of newly added command iocb.
  5482. *
  5483. * This function is called with hbalock held before a new
  5484. * iocb is submitted to the firmware. This function checks
  5485. * txq to flush the iocbs in txq to Firmware before
  5486. * submitting new iocbs to the Firmware.
  5487. * If there are iocbs in the txq which need to be submitted
  5488. * to firmware, lpfc_sli_next_iocb returns the first element
  5489. * of the txq after dequeuing it from txq.
  5490. * If there is no iocb in the txq then the function will return
  5491. * *piocb and *piocb is set to NULL. Caller needs to check
  5492. * *piocb to find if there are more commands in the txq.
  5493. **/
  5494. static struct lpfc_iocbq *
  5495. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5496. struct lpfc_iocbq **piocb)
  5497. {
  5498. struct lpfc_iocbq * nextiocb;
  5499. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5500. if (!nextiocb) {
  5501. nextiocb = *piocb;
  5502. *piocb = NULL;
  5503. }
  5504. return nextiocb;
  5505. }
  5506. /**
  5507. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5508. * @phba: Pointer to HBA context object.
  5509. * @ring_number: SLI ring number to issue iocb on.
  5510. * @piocb: Pointer to command iocb.
  5511. * @flag: Flag indicating if this command can be put into txq.
  5512. *
  5513. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5514. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5515. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5516. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5517. * this function allows only iocbs for posting buffers. This function finds
  5518. * next available slot in the command ring and posts the command to the
  5519. * available slot and writes the port attention register to request HBA start
  5520. * processing new iocb. If there is no slot available in the ring and
  5521. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5522. * the function returns IOCB_BUSY.
  5523. *
  5524. * This function is called with hbalock held. The function will return success
  5525. * after it successfully submit the iocb to firmware or after adding to the
  5526. * txq.
  5527. **/
  5528. static int
  5529. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5530. struct lpfc_iocbq *piocb, uint32_t flag)
  5531. {
  5532. struct lpfc_iocbq *nextiocb;
  5533. IOCB_t *iocb;
  5534. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5535. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5536. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5537. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5538. lpfc_printf_log(phba, KERN_ERR,
  5539. LOG_SLI | LOG_VPORT,
  5540. "1807 IOCB x%x failed. No vport\n",
  5541. piocb->iocb.ulpCommand);
  5542. dump_stack();
  5543. return IOCB_ERROR;
  5544. }
  5545. /* If the PCI channel is in offline state, do not post iocbs. */
  5546. if (unlikely(pci_channel_offline(phba->pcidev)))
  5547. return IOCB_ERROR;
  5548. /* If HBA has a deferred error attention, fail the iocb. */
  5549. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5550. return IOCB_ERROR;
  5551. /*
  5552. * We should never get an IOCB if we are in a < LINK_DOWN state
  5553. */
  5554. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5555. return IOCB_ERROR;
  5556. /*
  5557. * Check to see if we are blocking IOCB processing because of a
  5558. * outstanding event.
  5559. */
  5560. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5561. goto iocb_busy;
  5562. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5563. /*
  5564. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5565. * can be issued if the link is not up.
  5566. */
  5567. switch (piocb->iocb.ulpCommand) {
  5568. case CMD_GEN_REQUEST64_CR:
  5569. case CMD_GEN_REQUEST64_CX:
  5570. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5571. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5572. FC_RCTL_DD_UNSOL_CMD) ||
  5573. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5574. MENLO_TRANSPORT_TYPE))
  5575. goto iocb_busy;
  5576. break;
  5577. case CMD_QUE_RING_BUF_CN:
  5578. case CMD_QUE_RING_BUF64_CN:
  5579. /*
  5580. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5581. * completion, iocb_cmpl MUST be 0.
  5582. */
  5583. if (piocb->iocb_cmpl)
  5584. piocb->iocb_cmpl = NULL;
  5585. /*FALLTHROUGH*/
  5586. case CMD_CREATE_XRI_CR:
  5587. case CMD_CLOSE_XRI_CN:
  5588. case CMD_CLOSE_XRI_CX:
  5589. break;
  5590. default:
  5591. goto iocb_busy;
  5592. }
  5593. /*
  5594. * For FCP commands, we must be in a state where we can process link
  5595. * attention events.
  5596. */
  5597. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5598. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5599. goto iocb_busy;
  5600. }
  5601. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5602. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5603. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5604. if (iocb)
  5605. lpfc_sli_update_ring(phba, pring);
  5606. else
  5607. lpfc_sli_update_full_ring(phba, pring);
  5608. if (!piocb)
  5609. return IOCB_SUCCESS;
  5610. goto out_busy;
  5611. iocb_busy:
  5612. pring->stats.iocb_cmd_delay++;
  5613. out_busy:
  5614. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5615. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5616. return IOCB_SUCCESS;
  5617. }
  5618. return IOCB_BUSY;
  5619. }
  5620. /**
  5621. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5622. * @phba: Pointer to HBA context object.
  5623. * @piocb: Pointer to command iocb.
  5624. * @sglq: Pointer to the scatter gather queue object.
  5625. *
  5626. * This routine converts the bpl or bde that is in the IOCB
  5627. * to a sgl list for the sli4 hardware. The physical address
  5628. * of the bpl/bde is converted back to a virtual address.
  5629. * If the IOCB contains a BPL then the list of BDE's is
  5630. * converted to sli4_sge's. If the IOCB contains a single
  5631. * BDE then it is converted to a single sli_sge.
  5632. * The IOCB is still in cpu endianess so the contents of
  5633. * the bpl can be used without byte swapping.
  5634. *
  5635. * Returns valid XRI = Success, NO_XRI = Failure.
  5636. **/
  5637. static uint16_t
  5638. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5639. struct lpfc_sglq *sglq)
  5640. {
  5641. uint16_t xritag = NO_XRI;
  5642. struct ulp_bde64 *bpl = NULL;
  5643. struct ulp_bde64 bde;
  5644. struct sli4_sge *sgl = NULL;
  5645. IOCB_t *icmd;
  5646. int numBdes = 0;
  5647. int i = 0;
  5648. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5649. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5650. if (!piocbq || !sglq)
  5651. return xritag;
  5652. sgl = (struct sli4_sge *)sglq->sgl;
  5653. icmd = &piocbq->iocb;
  5654. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5655. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5656. sizeof(struct ulp_bde64);
  5657. /* The addrHigh and addrLow fields within the IOCB
  5658. * have not been byteswapped yet so there is no
  5659. * need to swap them back.
  5660. */
  5661. bpl = (struct ulp_bde64 *)
  5662. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5663. if (!bpl)
  5664. return xritag;
  5665. for (i = 0; i < numBdes; i++) {
  5666. /* Should already be byte swapped. */
  5667. sgl->addr_hi = bpl->addrHigh;
  5668. sgl->addr_lo = bpl->addrLow;
  5669. if ((i+1) == numBdes)
  5670. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5671. else
  5672. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5673. sgl->word2 = cpu_to_le32(sgl->word2);
  5674. /* swap the size field back to the cpu so we
  5675. * can assign it to the sgl.
  5676. */
  5677. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5678. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5679. /* The offsets in the sgl need to be accumulated
  5680. * separately for the request and reply lists.
  5681. * The request is always first, the reply follows.
  5682. */
  5683. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5684. /* add up the reply sg entries */
  5685. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5686. inbound++;
  5687. /* first inbound? reset the offset */
  5688. if (inbound == 1)
  5689. offset = 0;
  5690. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5691. offset += bde.tus.f.bdeSize;
  5692. }
  5693. bpl++;
  5694. sgl++;
  5695. }
  5696. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5697. /* The addrHigh and addrLow fields of the BDE have not
  5698. * been byteswapped yet so they need to be swapped
  5699. * before putting them in the sgl.
  5700. */
  5701. sgl->addr_hi =
  5702. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5703. sgl->addr_lo =
  5704. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5705. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5706. sgl->word2 = cpu_to_le32(sgl->word2);
  5707. sgl->sge_len =
  5708. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5709. }
  5710. return sglq->sli4_xritag;
  5711. }
  5712. /**
  5713. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5714. * @phba: Pointer to HBA context object.
  5715. *
  5716. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5717. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5718. * held.
  5719. *
  5720. * Return: index into SLI4 fast-path FCP queue index.
  5721. **/
  5722. static uint32_t
  5723. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5724. {
  5725. ++phba->fcp_qidx;
  5726. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5727. phba->fcp_qidx = 0;
  5728. return phba->fcp_qidx;
  5729. }
  5730. /**
  5731. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5732. * @phba: Pointer to HBA context object.
  5733. * @piocb: Pointer to command iocb.
  5734. * @wqe: Pointer to the work queue entry.
  5735. *
  5736. * This routine converts the iocb command to its Work Queue Entry
  5737. * equivalent. The wqe pointer should not have any fields set when
  5738. * this routine is called because it will memcpy over them.
  5739. * This routine does not set the CQ_ID or the WQEC bits in the
  5740. * wqe.
  5741. *
  5742. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5743. **/
  5744. static int
  5745. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5746. union lpfc_wqe *wqe)
  5747. {
  5748. uint32_t xmit_len = 0, total_len = 0;
  5749. uint8_t ct = 0;
  5750. uint32_t fip;
  5751. uint32_t abort_tag;
  5752. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5753. uint8_t cmnd;
  5754. uint16_t xritag;
  5755. uint16_t abrt_iotag;
  5756. struct lpfc_iocbq *abrtiocbq;
  5757. struct ulp_bde64 *bpl = NULL;
  5758. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5759. int numBdes, i;
  5760. struct ulp_bde64 bde;
  5761. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5762. /* The fcp commands will set command type */
  5763. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5764. command_type = FCP_COMMAND;
  5765. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5766. command_type = ELS_COMMAND_FIP;
  5767. else
  5768. command_type = ELS_COMMAND_NON_FIP;
  5769. /* Some of the fields are in the right position already */
  5770. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5771. abort_tag = (uint32_t) iocbq->iotag;
  5772. xritag = iocbq->sli4_xritag;
  5773. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5774. /* words0-2 bpl convert bde */
  5775. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5776. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5777. sizeof(struct ulp_bde64);
  5778. bpl = (struct ulp_bde64 *)
  5779. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5780. if (!bpl)
  5781. return IOCB_ERROR;
  5782. /* Should already be byte swapped. */
  5783. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5784. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5785. /* swap the size field back to the cpu so we
  5786. * can assign it to the sgl.
  5787. */
  5788. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5789. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5790. total_len = 0;
  5791. for (i = 0; i < numBdes; i++) {
  5792. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5793. total_len += bde.tus.f.bdeSize;
  5794. }
  5795. } else
  5796. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5797. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5798. cmnd = iocbq->iocb.ulpCommand;
  5799. switch (iocbq->iocb.ulpCommand) {
  5800. case CMD_ELS_REQUEST64_CR:
  5801. if (!iocbq->iocb.ulpLe) {
  5802. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5803. "2007 Only Limited Edition cmd Format"
  5804. " supported 0x%x\n",
  5805. iocbq->iocb.ulpCommand);
  5806. return IOCB_ERROR;
  5807. }
  5808. wqe->els_req.payload_len = xmit_len;
  5809. /* Els_reguest64 has a TMO */
  5810. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5811. iocbq->iocb.ulpTimeout);
  5812. /* Need a VF for word 4 set the vf bit*/
  5813. bf_set(els_req64_vf, &wqe->els_req, 0);
  5814. /* And a VFID for word 12 */
  5815. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5816. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5817. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5818. iocbq->iocb.ulpContext);
  5819. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5820. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5821. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5822. if (command_type == ELS_COMMAND_FIP) {
  5823. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5824. >> LPFC_FIP_ELS_ID_SHIFT);
  5825. }
  5826. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5827. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5828. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5829. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5830. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5831. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5832. break;
  5833. case CMD_XMIT_SEQUENCE64_CX:
  5834. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5835. iocbq->iocb.un.ulpWord[3]);
  5836. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5837. iocbq->iocb.ulpContext);
  5838. /* The entire sequence is transmitted for this IOCB */
  5839. xmit_len = total_len;
  5840. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5841. case CMD_XMIT_SEQUENCE64_CR:
  5842. /* word3 iocb=io_tag32 wqe=reserved */
  5843. wqe->xmit_sequence.rsvd3 = 0;
  5844. /* word4 relative_offset memcpy */
  5845. /* word5 r_ctl/df_ctl memcpy */
  5846. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5847. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5848. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5849. LPFC_WQE_IOD_WRITE);
  5850. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5851. LPFC_WQE_LENLOC_WORD12);
  5852. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5853. wqe->xmit_sequence.xmit_len = xmit_len;
  5854. command_type = OTHER_COMMAND;
  5855. break;
  5856. case CMD_XMIT_BCAST64_CN:
  5857. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5858. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5859. /* word4 iocb=rsvd wqe=rsvd */
  5860. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5861. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5862. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5863. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5864. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5865. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5866. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5867. LPFC_WQE_LENLOC_WORD3);
  5868. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5869. break;
  5870. case CMD_FCP_IWRITE64_CR:
  5871. command_type = FCP_COMMAND_DATA_OUT;
  5872. /* word3 iocb=iotag wqe=payload_offset_len */
  5873. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5874. wqe->fcp_iwrite.payload_offset_len =
  5875. xmit_len + sizeof(struct fcp_rsp);
  5876. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5877. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5878. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5879. iocbq->iocb.ulpFCP2Rcvy);
  5880. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5881. /* Always open the exchange */
  5882. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5883. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5884. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5885. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5886. LPFC_WQE_LENLOC_WORD4);
  5887. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5888. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5889. break;
  5890. case CMD_FCP_IREAD64_CR:
  5891. /* word3 iocb=iotag wqe=payload_offset_len */
  5892. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5893. wqe->fcp_iread.payload_offset_len =
  5894. xmit_len + sizeof(struct fcp_rsp);
  5895. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5896. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5897. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5898. iocbq->iocb.ulpFCP2Rcvy);
  5899. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5900. /* Always open the exchange */
  5901. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5902. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5903. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5904. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5905. LPFC_WQE_LENLOC_WORD4);
  5906. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5907. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5908. break;
  5909. case CMD_FCP_ICMND64_CR:
  5910. /* word3 iocb=IO_TAG wqe=reserved */
  5911. wqe->fcp_icmd.rsrvd3 = 0;
  5912. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5913. /* Always open the exchange */
  5914. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5915. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5916. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5917. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5918. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5919. LPFC_WQE_LENLOC_NONE);
  5920. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5921. break;
  5922. case CMD_GEN_REQUEST64_CR:
  5923. /* For this command calculate the xmit length of the
  5924. * request bde.
  5925. */
  5926. xmit_len = 0;
  5927. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5928. sizeof(struct ulp_bde64);
  5929. for (i = 0; i < numBdes; i++) {
  5930. if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5931. break;
  5932. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5933. xmit_len += bde.tus.f.bdeSize;
  5934. }
  5935. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5936. wqe->gen_req.request_payload_len = xmit_len;
  5937. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5938. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5939. /* word6 context tag copied in memcpy */
  5940. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5941. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5942. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5943. "2015 Invalid CT %x command 0x%x\n",
  5944. ct, iocbq->iocb.ulpCommand);
  5945. return IOCB_ERROR;
  5946. }
  5947. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5948. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5949. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5950. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5951. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5952. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5953. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5954. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5955. command_type = OTHER_COMMAND;
  5956. break;
  5957. case CMD_XMIT_ELS_RSP64_CX:
  5958. /* words0-2 BDE memcpy */
  5959. /* word3 iocb=iotag32 wqe=response_payload_len */
  5960. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  5961. /* word4 iocb=did wge=rsvd. */
  5962. wqe->xmit_els_rsp.rsvd4 = 0;
  5963. /* word5 iocb=rsvd wge=did */
  5964. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5965. iocbq->iocb.un.elsreq64.remoteID);
  5966. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  5967. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5968. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  5969. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5970. iocbq->iocb.ulpContext);
  5971. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5972. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5973. iocbq->vport->vpi + phba->vpi_base);
  5974. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  5975. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  5976. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  5977. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  5978. LPFC_WQE_LENLOC_WORD3);
  5979. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  5980. command_type = OTHER_COMMAND;
  5981. break;
  5982. case CMD_CLOSE_XRI_CN:
  5983. case CMD_ABORT_XRI_CN:
  5984. case CMD_ABORT_XRI_CX:
  5985. /* words 0-2 memcpy should be 0 rserved */
  5986. /* port will send abts */
  5987. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  5988. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  5989. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  5990. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  5991. } else
  5992. fip = 0;
  5993. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  5994. /*
  5995. * The link is down, or the command was ELS_FIP
  5996. * so the fw does not need to send abts
  5997. * on the wire.
  5998. */
  5999. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  6000. else
  6001. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  6002. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  6003. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  6004. wqe->abort_cmd.rsrvd5 = 0;
  6005. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  6006. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6007. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  6008. /*
  6009. * The abort handler will send us CMD_ABORT_XRI_CN or
  6010. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6011. */
  6012. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6013. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6014. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6015. LPFC_WQE_LENLOC_NONE);
  6016. cmnd = CMD_ABORT_XRI_CX;
  6017. command_type = OTHER_COMMAND;
  6018. xritag = 0;
  6019. break;
  6020. case CMD_XMIT_BLS_RSP64_CX:
  6021. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  6022. * we re-construct this WQE here based on information in
  6023. * iocbq from scratch.
  6024. */
  6025. memset(wqe, 0, sizeof(union lpfc_wqe));
  6026. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6027. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6028. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  6029. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  6030. LPFC_ABTS_UNSOL_INT) {
  6031. /* ABTS sent by initiator to CT exchange, the
  6032. * RX_ID field will be filled with the newly
  6033. * allocated responder XRI.
  6034. */
  6035. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6036. iocbq->sli4_xritag);
  6037. } else {
  6038. /* ABTS sent by responder to CT exchange, the
  6039. * RX_ID field will be filled with the responder
  6040. * RX_ID from ABTS.
  6041. */
  6042. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6043. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  6044. }
  6045. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6046. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6047. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6048. iocbq->iocb.ulpContext);
  6049. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6050. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6051. LPFC_WQE_LENLOC_NONE);
  6052. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6053. command_type = OTHER_COMMAND;
  6054. break;
  6055. case CMD_XRI_ABORTED_CX:
  6056. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6057. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6058. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6059. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6060. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6061. default:
  6062. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6063. "2014 Invalid command 0x%x\n",
  6064. iocbq->iocb.ulpCommand);
  6065. return IOCB_ERROR;
  6066. break;
  6067. }
  6068. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6069. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6070. wqe->generic.wqe_com.abort_tag = abort_tag;
  6071. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6072. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6073. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6074. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6075. return 0;
  6076. }
  6077. /**
  6078. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6079. * @phba: Pointer to HBA context object.
  6080. * @ring_number: SLI ring number to issue iocb on.
  6081. * @piocb: Pointer to command iocb.
  6082. * @flag: Flag indicating if this command can be put into txq.
  6083. *
  6084. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6085. * an iocb command to an HBA with SLI-4 interface spec.
  6086. *
  6087. * This function is called with hbalock held. The function will return success
  6088. * after it successfully submit the iocb to firmware or after adding to the
  6089. * txq.
  6090. **/
  6091. static int
  6092. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6093. struct lpfc_iocbq *piocb, uint32_t flag)
  6094. {
  6095. struct lpfc_sglq *sglq;
  6096. union lpfc_wqe wqe;
  6097. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6098. if (piocb->sli4_xritag == NO_XRI) {
  6099. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6100. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  6101. sglq = NULL;
  6102. else {
  6103. if (pring->txq_cnt) {
  6104. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6105. __lpfc_sli_ringtx_put(phba,
  6106. pring, piocb);
  6107. return IOCB_SUCCESS;
  6108. } else {
  6109. return IOCB_BUSY;
  6110. }
  6111. } else {
  6112. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6113. if (!sglq) {
  6114. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6115. __lpfc_sli_ringtx_put(phba,
  6116. pring,
  6117. piocb);
  6118. return IOCB_SUCCESS;
  6119. } else
  6120. return IOCB_BUSY;
  6121. }
  6122. }
  6123. }
  6124. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6125. sglq = NULL; /* These IO's already have an XRI and
  6126. * a mapped sgl.
  6127. */
  6128. } else {
  6129. /* This is a continuation of a commandi,(CX) so this
  6130. * sglq is on the active list
  6131. */
  6132. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6133. if (!sglq)
  6134. return IOCB_ERROR;
  6135. }
  6136. if (sglq) {
  6137. piocb->sli4_xritag = sglq->sli4_xritag;
  6138. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6139. return IOCB_ERROR;
  6140. }
  6141. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6142. return IOCB_ERROR;
  6143. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6144. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6145. /*
  6146. * For FCP command IOCB, get a new WQ index to distribute
  6147. * WQE across the WQsr. On the other hand, for abort IOCB,
  6148. * it carries the same WQ index to the original command
  6149. * IOCB.
  6150. */
  6151. if (piocb->iocb_flag & LPFC_IO_FCP)
  6152. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6153. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6154. &wqe))
  6155. return IOCB_ERROR;
  6156. } else {
  6157. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6158. return IOCB_ERROR;
  6159. }
  6160. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6161. return 0;
  6162. }
  6163. /**
  6164. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6165. *
  6166. * This routine wraps the actual lockless version for issusing IOCB function
  6167. * pointer from the lpfc_hba struct.
  6168. *
  6169. * Return codes:
  6170. * IOCB_ERROR - Error
  6171. * IOCB_SUCCESS - Success
  6172. * IOCB_BUSY - Busy
  6173. **/
  6174. int
  6175. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6176. struct lpfc_iocbq *piocb, uint32_t flag)
  6177. {
  6178. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6179. }
  6180. /**
  6181. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  6182. * @phba: The hba struct for which this call is being executed.
  6183. * @dev_grp: The HBA PCI-Device group number.
  6184. *
  6185. * This routine sets up the SLI interface API function jump table in @phba
  6186. * struct.
  6187. * Returns: 0 - success, -ENODEV - failure.
  6188. **/
  6189. int
  6190. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6191. {
  6192. switch (dev_grp) {
  6193. case LPFC_PCI_DEV_LP:
  6194. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6195. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6196. break;
  6197. case LPFC_PCI_DEV_OC:
  6198. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6199. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6200. break;
  6201. default:
  6202. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6203. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6204. dev_grp);
  6205. return -ENODEV;
  6206. break;
  6207. }
  6208. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6209. return 0;
  6210. }
  6211. /**
  6212. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6213. * @phba: Pointer to HBA context object.
  6214. * @pring: Pointer to driver SLI ring object.
  6215. * @piocb: Pointer to command iocb.
  6216. * @flag: Flag indicating if this command can be put into txq.
  6217. *
  6218. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6219. * function. This function gets the hbalock and calls
  6220. * __lpfc_sli_issue_iocb function and will return the error returned
  6221. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6222. * functions which do not hold hbalock.
  6223. **/
  6224. int
  6225. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6226. struct lpfc_iocbq *piocb, uint32_t flag)
  6227. {
  6228. unsigned long iflags;
  6229. int rc;
  6230. spin_lock_irqsave(&phba->hbalock, iflags);
  6231. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6232. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6233. return rc;
  6234. }
  6235. /**
  6236. * lpfc_extra_ring_setup - Extra ring setup function
  6237. * @phba: Pointer to HBA context object.
  6238. *
  6239. * This function is called while driver attaches with the
  6240. * HBA to setup the extra ring. The extra ring is used
  6241. * only when driver needs to support target mode functionality
  6242. * or IP over FC functionalities.
  6243. *
  6244. * This function is called with no lock held.
  6245. **/
  6246. static int
  6247. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6248. {
  6249. struct lpfc_sli *psli;
  6250. struct lpfc_sli_ring *pring;
  6251. psli = &phba->sli;
  6252. /* Adjust cmd/rsp ring iocb entries more evenly */
  6253. /* Take some away from the FCP ring */
  6254. pring = &psli->ring[psli->fcp_ring];
  6255. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6256. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6257. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6258. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6259. /* and give them to the extra ring */
  6260. pring = &psli->ring[psli->extra_ring];
  6261. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6262. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6263. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6264. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6265. /* Setup default profile for this ring */
  6266. pring->iotag_max = 4096;
  6267. pring->num_mask = 1;
  6268. pring->prt[0].profile = 0; /* Mask 0 */
  6269. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6270. pring->prt[0].type = phba->cfg_multi_ring_type;
  6271. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6272. return 0;
  6273. }
  6274. /**
  6275. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6276. * @phba: Pointer to HBA context object.
  6277. * @pring: Pointer to driver SLI ring object.
  6278. * @iocbq: Pointer to iocb object.
  6279. *
  6280. * This function is called by the slow ring event handler
  6281. * function when there is an ASYNC event iocb in the ring.
  6282. * This function is called with no lock held.
  6283. * Currently this function handles only temperature related
  6284. * ASYNC events. The function decodes the temperature sensor
  6285. * event message and posts events for the management applications.
  6286. **/
  6287. static void
  6288. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6289. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6290. {
  6291. IOCB_t *icmd;
  6292. uint16_t evt_code;
  6293. uint16_t temp;
  6294. struct temp_event temp_event_data;
  6295. struct Scsi_Host *shost;
  6296. uint32_t *iocb_w;
  6297. icmd = &iocbq->iocb;
  6298. evt_code = icmd->un.asyncstat.evt_code;
  6299. temp = icmd->ulpContext;
  6300. if ((evt_code != ASYNC_TEMP_WARN) &&
  6301. (evt_code != ASYNC_TEMP_SAFE)) {
  6302. iocb_w = (uint32_t *) icmd;
  6303. lpfc_printf_log(phba,
  6304. KERN_ERR,
  6305. LOG_SLI,
  6306. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6307. " evt_code 0x%x\n"
  6308. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6309. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6310. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6311. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6312. pring->ringno,
  6313. icmd->un.asyncstat.evt_code,
  6314. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6315. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6316. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6317. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6318. return;
  6319. }
  6320. temp_event_data.data = (uint32_t)temp;
  6321. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6322. if (evt_code == ASYNC_TEMP_WARN) {
  6323. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6324. lpfc_printf_log(phba,
  6325. KERN_ERR,
  6326. LOG_TEMP,
  6327. "0347 Adapter is very hot, please take "
  6328. "corrective action. temperature : %d Celsius\n",
  6329. temp);
  6330. }
  6331. if (evt_code == ASYNC_TEMP_SAFE) {
  6332. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6333. lpfc_printf_log(phba,
  6334. KERN_ERR,
  6335. LOG_TEMP,
  6336. "0340 Adapter temperature is OK now. "
  6337. "temperature : %d Celsius\n",
  6338. temp);
  6339. }
  6340. /* Send temperature change event to applications */
  6341. shost = lpfc_shost_from_vport(phba->pport);
  6342. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6343. sizeof(temp_event_data), (char *) &temp_event_data,
  6344. LPFC_NL_VENDOR_ID);
  6345. }
  6346. /**
  6347. * lpfc_sli_setup - SLI ring setup function
  6348. * @phba: Pointer to HBA context object.
  6349. *
  6350. * lpfc_sli_setup sets up rings of the SLI interface with
  6351. * number of iocbs per ring and iotags. This function is
  6352. * called while driver attach to the HBA and before the
  6353. * interrupts are enabled. So there is no need for locking.
  6354. *
  6355. * This function always returns 0.
  6356. **/
  6357. int
  6358. lpfc_sli_setup(struct lpfc_hba *phba)
  6359. {
  6360. int i, totiocbsize = 0;
  6361. struct lpfc_sli *psli = &phba->sli;
  6362. struct lpfc_sli_ring *pring;
  6363. psli->num_rings = MAX_CONFIGURED_RINGS;
  6364. psli->sli_flag = 0;
  6365. psli->fcp_ring = LPFC_FCP_RING;
  6366. psli->next_ring = LPFC_FCP_NEXT_RING;
  6367. psli->extra_ring = LPFC_EXTRA_RING;
  6368. psli->iocbq_lookup = NULL;
  6369. psli->iocbq_lookup_len = 0;
  6370. psli->last_iotag = 0;
  6371. for (i = 0; i < psli->num_rings; i++) {
  6372. pring = &psli->ring[i];
  6373. switch (i) {
  6374. case LPFC_FCP_RING: /* ring 0 - FCP */
  6375. /* numCiocb and numRiocb are used in config_port */
  6376. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6377. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6378. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6379. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6380. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6381. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6382. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6383. SLI3_IOCB_CMD_SIZE :
  6384. SLI2_IOCB_CMD_SIZE;
  6385. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6386. SLI3_IOCB_RSP_SIZE :
  6387. SLI2_IOCB_RSP_SIZE;
  6388. pring->iotag_ctr = 0;
  6389. pring->iotag_max =
  6390. (phba->cfg_hba_queue_depth * 2);
  6391. pring->fast_iotag = pring->iotag_max;
  6392. pring->num_mask = 0;
  6393. break;
  6394. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6395. /* numCiocb and numRiocb are used in config_port */
  6396. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6397. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6398. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6399. SLI3_IOCB_CMD_SIZE :
  6400. SLI2_IOCB_CMD_SIZE;
  6401. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6402. SLI3_IOCB_RSP_SIZE :
  6403. SLI2_IOCB_RSP_SIZE;
  6404. pring->iotag_max = phba->cfg_hba_queue_depth;
  6405. pring->num_mask = 0;
  6406. break;
  6407. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6408. /* numCiocb and numRiocb are used in config_port */
  6409. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6410. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6411. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6412. SLI3_IOCB_CMD_SIZE :
  6413. SLI2_IOCB_CMD_SIZE;
  6414. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6415. SLI3_IOCB_RSP_SIZE :
  6416. SLI2_IOCB_RSP_SIZE;
  6417. pring->fast_iotag = 0;
  6418. pring->iotag_ctr = 0;
  6419. pring->iotag_max = 4096;
  6420. pring->lpfc_sli_rcv_async_status =
  6421. lpfc_sli_async_event_handler;
  6422. pring->num_mask = LPFC_MAX_RING_MASK;
  6423. pring->prt[0].profile = 0; /* Mask 0 */
  6424. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6425. pring->prt[0].type = FC_TYPE_ELS;
  6426. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6427. lpfc_els_unsol_event;
  6428. pring->prt[1].profile = 0; /* Mask 1 */
  6429. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6430. pring->prt[1].type = FC_TYPE_ELS;
  6431. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6432. lpfc_els_unsol_event;
  6433. pring->prt[2].profile = 0; /* Mask 2 */
  6434. /* NameServer Inquiry */
  6435. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6436. /* NameServer */
  6437. pring->prt[2].type = FC_TYPE_CT;
  6438. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6439. lpfc_ct_unsol_event;
  6440. pring->prt[3].profile = 0; /* Mask 3 */
  6441. /* NameServer response */
  6442. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6443. /* NameServer */
  6444. pring->prt[3].type = FC_TYPE_CT;
  6445. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6446. lpfc_ct_unsol_event;
  6447. /* abort unsolicited sequence */
  6448. pring->prt[4].profile = 0; /* Mask 4 */
  6449. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6450. pring->prt[4].type = FC_TYPE_BLS;
  6451. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6452. lpfc_sli4_ct_abort_unsol_event;
  6453. break;
  6454. }
  6455. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6456. (pring->numRiocb * pring->sizeRiocb);
  6457. }
  6458. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6459. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6460. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6461. "SLI2 SLIM Data: x%x x%lx\n",
  6462. phba->brd_no, totiocbsize,
  6463. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6464. }
  6465. if (phba->cfg_multi_ring_support == 2)
  6466. lpfc_extra_ring_setup(phba);
  6467. return 0;
  6468. }
  6469. /**
  6470. * lpfc_sli_queue_setup - Queue initialization function
  6471. * @phba: Pointer to HBA context object.
  6472. *
  6473. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6474. * ring. This function also initializes ring indices of each ring.
  6475. * This function is called during the initialization of the SLI
  6476. * interface of an HBA.
  6477. * This function is called with no lock held and always returns
  6478. * 1.
  6479. **/
  6480. int
  6481. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6482. {
  6483. struct lpfc_sli *psli;
  6484. struct lpfc_sli_ring *pring;
  6485. int i;
  6486. psli = &phba->sli;
  6487. spin_lock_irq(&phba->hbalock);
  6488. INIT_LIST_HEAD(&psli->mboxq);
  6489. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6490. /* Initialize list headers for txq and txcmplq as double linked lists */
  6491. for (i = 0; i < psli->num_rings; i++) {
  6492. pring = &psli->ring[i];
  6493. pring->ringno = i;
  6494. pring->next_cmdidx = 0;
  6495. pring->local_getidx = 0;
  6496. pring->cmdidx = 0;
  6497. INIT_LIST_HEAD(&pring->txq);
  6498. INIT_LIST_HEAD(&pring->txcmplq);
  6499. INIT_LIST_HEAD(&pring->iocb_continueq);
  6500. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6501. INIT_LIST_HEAD(&pring->postbufq);
  6502. }
  6503. spin_unlock_irq(&phba->hbalock);
  6504. return 1;
  6505. }
  6506. /**
  6507. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6508. * @phba: Pointer to HBA context object.
  6509. *
  6510. * This routine flushes the mailbox command subsystem. It will unconditionally
  6511. * flush all the mailbox commands in the three possible stages in the mailbox
  6512. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6513. * command; and completed mailbox command queue. It is caller's responsibility
  6514. * to make sure that the driver is in the proper state to flush the mailbox
  6515. * command sub-system. Namely, the posting of mailbox commands into the
  6516. * pending mailbox command queue from the various clients must be stopped;
  6517. * either the HBA is in a state that it will never works on the outstanding
  6518. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6519. * mailbox command has been completed.
  6520. **/
  6521. static void
  6522. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6523. {
  6524. LIST_HEAD(completions);
  6525. struct lpfc_sli *psli = &phba->sli;
  6526. LPFC_MBOXQ_t *pmb;
  6527. unsigned long iflag;
  6528. /* Flush all the mailbox commands in the mbox system */
  6529. spin_lock_irqsave(&phba->hbalock, iflag);
  6530. /* The pending mailbox command queue */
  6531. list_splice_init(&phba->sli.mboxq, &completions);
  6532. /* The outstanding active mailbox command */
  6533. if (psli->mbox_active) {
  6534. list_add_tail(&psli->mbox_active->list, &completions);
  6535. psli->mbox_active = NULL;
  6536. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6537. }
  6538. /* The completed mailbox command queue */
  6539. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6540. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6541. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6542. while (!list_empty(&completions)) {
  6543. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6544. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6545. if (pmb->mbox_cmpl)
  6546. pmb->mbox_cmpl(phba, pmb);
  6547. }
  6548. }
  6549. /**
  6550. * lpfc_sli_host_down - Vport cleanup function
  6551. * @vport: Pointer to virtual port object.
  6552. *
  6553. * lpfc_sli_host_down is called to clean up the resources
  6554. * associated with a vport before destroying virtual
  6555. * port data structures.
  6556. * This function does following operations:
  6557. * - Free discovery resources associated with this virtual
  6558. * port.
  6559. * - Free iocbs associated with this virtual port in
  6560. * the txq.
  6561. * - Send abort for all iocb commands associated with this
  6562. * vport in txcmplq.
  6563. *
  6564. * This function is called with no lock held and always returns 1.
  6565. **/
  6566. int
  6567. lpfc_sli_host_down(struct lpfc_vport *vport)
  6568. {
  6569. LIST_HEAD(completions);
  6570. struct lpfc_hba *phba = vport->phba;
  6571. struct lpfc_sli *psli = &phba->sli;
  6572. struct lpfc_sli_ring *pring;
  6573. struct lpfc_iocbq *iocb, *next_iocb;
  6574. int i;
  6575. unsigned long flags = 0;
  6576. uint16_t prev_pring_flag;
  6577. lpfc_cleanup_discovery_resources(vport);
  6578. spin_lock_irqsave(&phba->hbalock, flags);
  6579. for (i = 0; i < psli->num_rings; i++) {
  6580. pring = &psli->ring[i];
  6581. prev_pring_flag = pring->flag;
  6582. /* Only slow rings */
  6583. if (pring->ringno == LPFC_ELS_RING) {
  6584. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6585. /* Set the lpfc data pending flag */
  6586. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6587. }
  6588. /*
  6589. * Error everything on the txq since these iocbs have not been
  6590. * given to the FW yet.
  6591. */
  6592. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6593. if (iocb->vport != vport)
  6594. continue;
  6595. list_move_tail(&iocb->list, &completions);
  6596. pring->txq_cnt--;
  6597. }
  6598. /* Next issue ABTS for everything on the txcmplq */
  6599. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6600. list) {
  6601. if (iocb->vport != vport)
  6602. continue;
  6603. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6604. }
  6605. pring->flag = prev_pring_flag;
  6606. }
  6607. spin_unlock_irqrestore(&phba->hbalock, flags);
  6608. /* Cancel all the IOCBs from the completions list */
  6609. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6610. IOERR_SLI_DOWN);
  6611. return 1;
  6612. }
  6613. /**
  6614. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6615. * @phba: Pointer to HBA context object.
  6616. *
  6617. * This function cleans up all iocb, buffers, mailbox commands
  6618. * while shutting down the HBA. This function is called with no
  6619. * lock held and always returns 1.
  6620. * This function does the following to cleanup driver resources:
  6621. * - Free discovery resources for each virtual port
  6622. * - Cleanup any pending fabric iocbs
  6623. * - Iterate through the iocb txq and free each entry
  6624. * in the list.
  6625. * - Free up any buffer posted to the HBA
  6626. * - Free mailbox commands in the mailbox queue.
  6627. **/
  6628. int
  6629. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6630. {
  6631. LIST_HEAD(completions);
  6632. struct lpfc_sli *psli = &phba->sli;
  6633. struct lpfc_sli_ring *pring;
  6634. struct lpfc_dmabuf *buf_ptr;
  6635. unsigned long flags = 0;
  6636. int i;
  6637. /* Shutdown the mailbox command sub-system */
  6638. lpfc_sli_mbox_sys_shutdown(phba);
  6639. lpfc_hba_down_prep(phba);
  6640. lpfc_fabric_abort_hba(phba);
  6641. spin_lock_irqsave(&phba->hbalock, flags);
  6642. for (i = 0; i < psli->num_rings; i++) {
  6643. pring = &psli->ring[i];
  6644. /* Only slow rings */
  6645. if (pring->ringno == LPFC_ELS_RING) {
  6646. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6647. /* Set the lpfc data pending flag */
  6648. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6649. }
  6650. /*
  6651. * Error everything on the txq since these iocbs have not been
  6652. * given to the FW yet.
  6653. */
  6654. list_splice_init(&pring->txq, &completions);
  6655. pring->txq_cnt = 0;
  6656. }
  6657. spin_unlock_irqrestore(&phba->hbalock, flags);
  6658. /* Cancel all the IOCBs from the completions list */
  6659. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6660. IOERR_SLI_DOWN);
  6661. spin_lock_irqsave(&phba->hbalock, flags);
  6662. list_splice_init(&phba->elsbuf, &completions);
  6663. phba->elsbuf_cnt = 0;
  6664. phba->elsbuf_prev_cnt = 0;
  6665. spin_unlock_irqrestore(&phba->hbalock, flags);
  6666. while (!list_empty(&completions)) {
  6667. list_remove_head(&completions, buf_ptr,
  6668. struct lpfc_dmabuf, list);
  6669. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6670. kfree(buf_ptr);
  6671. }
  6672. /* Return any active mbox cmds */
  6673. del_timer_sync(&psli->mbox_tmo);
  6674. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6675. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6676. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6677. return 1;
  6678. }
  6679. /**
  6680. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6681. * @srcp: Source memory pointer.
  6682. * @destp: Destination memory pointer.
  6683. * @cnt: Number of words required to be copied.
  6684. *
  6685. * This function is used for copying data between driver memory
  6686. * and the SLI memory. This function also changes the endianness
  6687. * of each word if native endianness is different from SLI
  6688. * endianness. This function can be called with or without
  6689. * lock.
  6690. **/
  6691. void
  6692. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6693. {
  6694. uint32_t *src = srcp;
  6695. uint32_t *dest = destp;
  6696. uint32_t ldata;
  6697. int i;
  6698. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6699. ldata = *src;
  6700. ldata = le32_to_cpu(ldata);
  6701. *dest = ldata;
  6702. src++;
  6703. dest++;
  6704. }
  6705. }
  6706. /**
  6707. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6708. * @srcp: Source memory pointer.
  6709. * @destp: Destination memory pointer.
  6710. * @cnt: Number of words required to be copied.
  6711. *
  6712. * This function is used for copying data between a data structure
  6713. * with big endian representation to local endianness.
  6714. * This function can be called with or without lock.
  6715. **/
  6716. void
  6717. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6718. {
  6719. uint32_t *src = srcp;
  6720. uint32_t *dest = destp;
  6721. uint32_t ldata;
  6722. int i;
  6723. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6724. ldata = *src;
  6725. ldata = be32_to_cpu(ldata);
  6726. *dest = ldata;
  6727. src++;
  6728. dest++;
  6729. }
  6730. }
  6731. /**
  6732. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6733. * @phba: Pointer to HBA context object.
  6734. * @pring: Pointer to driver SLI ring object.
  6735. * @mp: Pointer to driver buffer object.
  6736. *
  6737. * This function is called with no lock held.
  6738. * It always return zero after adding the buffer to the postbufq
  6739. * buffer list.
  6740. **/
  6741. int
  6742. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6743. struct lpfc_dmabuf *mp)
  6744. {
  6745. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6746. later */
  6747. spin_lock_irq(&phba->hbalock);
  6748. list_add_tail(&mp->list, &pring->postbufq);
  6749. pring->postbufq_cnt++;
  6750. spin_unlock_irq(&phba->hbalock);
  6751. return 0;
  6752. }
  6753. /**
  6754. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6755. * @phba: Pointer to HBA context object.
  6756. *
  6757. * When HBQ is enabled, buffers are searched based on tags. This function
  6758. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6759. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6760. * does not conflict with tags of buffer posted for unsolicited events.
  6761. * The function returns the allocated tag. The function is called with
  6762. * no locks held.
  6763. **/
  6764. uint32_t
  6765. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6766. {
  6767. spin_lock_irq(&phba->hbalock);
  6768. phba->buffer_tag_count++;
  6769. /*
  6770. * Always set the QUE_BUFTAG_BIT to distiguish between
  6771. * a tag assigned by HBQ.
  6772. */
  6773. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6774. spin_unlock_irq(&phba->hbalock);
  6775. return phba->buffer_tag_count;
  6776. }
  6777. /**
  6778. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6779. * @phba: Pointer to HBA context object.
  6780. * @pring: Pointer to driver SLI ring object.
  6781. * @tag: Buffer tag.
  6782. *
  6783. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6784. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6785. * iocb is posted to the response ring with the tag of the buffer.
  6786. * This function searches the pring->postbufq list using the tag
  6787. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6788. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6789. * buffer is returned to the caller else NULL is returned.
  6790. * This function is called with no lock held.
  6791. **/
  6792. struct lpfc_dmabuf *
  6793. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6794. uint32_t tag)
  6795. {
  6796. struct lpfc_dmabuf *mp, *next_mp;
  6797. struct list_head *slp = &pring->postbufq;
  6798. /* Search postbufq, from the begining, looking for a match on tag */
  6799. spin_lock_irq(&phba->hbalock);
  6800. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6801. if (mp->buffer_tag == tag) {
  6802. list_del_init(&mp->list);
  6803. pring->postbufq_cnt--;
  6804. spin_unlock_irq(&phba->hbalock);
  6805. return mp;
  6806. }
  6807. }
  6808. spin_unlock_irq(&phba->hbalock);
  6809. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6810. "0402 Cannot find virtual addr for buffer tag on "
  6811. "ring %d Data x%lx x%p x%p x%x\n",
  6812. pring->ringno, (unsigned long) tag,
  6813. slp->next, slp->prev, pring->postbufq_cnt);
  6814. return NULL;
  6815. }
  6816. /**
  6817. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6818. * @phba: Pointer to HBA context object.
  6819. * @pring: Pointer to driver SLI ring object.
  6820. * @phys: DMA address of the buffer.
  6821. *
  6822. * This function searches the buffer list using the dma_address
  6823. * of unsolicited event to find the driver's lpfc_dmabuf object
  6824. * corresponding to the dma_address. The function returns the
  6825. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6826. * This function is called by the ct and els unsolicited event
  6827. * handlers to get the buffer associated with the unsolicited
  6828. * event.
  6829. *
  6830. * This function is called with no lock held.
  6831. **/
  6832. struct lpfc_dmabuf *
  6833. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6834. dma_addr_t phys)
  6835. {
  6836. struct lpfc_dmabuf *mp, *next_mp;
  6837. struct list_head *slp = &pring->postbufq;
  6838. /* Search postbufq, from the begining, looking for a match on phys */
  6839. spin_lock_irq(&phba->hbalock);
  6840. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6841. if (mp->phys == phys) {
  6842. list_del_init(&mp->list);
  6843. pring->postbufq_cnt--;
  6844. spin_unlock_irq(&phba->hbalock);
  6845. return mp;
  6846. }
  6847. }
  6848. spin_unlock_irq(&phba->hbalock);
  6849. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6850. "0410 Cannot find virtual addr for mapped buf on "
  6851. "ring %d Data x%llx x%p x%p x%x\n",
  6852. pring->ringno, (unsigned long long)phys,
  6853. slp->next, slp->prev, pring->postbufq_cnt);
  6854. return NULL;
  6855. }
  6856. /**
  6857. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6858. * @phba: Pointer to HBA context object.
  6859. * @cmdiocb: Pointer to driver command iocb object.
  6860. * @rspiocb: Pointer to driver response iocb object.
  6861. *
  6862. * This function is the completion handler for the abort iocbs for
  6863. * ELS commands. This function is called from the ELS ring event
  6864. * handler with no lock held. This function frees memory resources
  6865. * associated with the abort iocb.
  6866. **/
  6867. static void
  6868. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6869. struct lpfc_iocbq *rspiocb)
  6870. {
  6871. IOCB_t *irsp = &rspiocb->iocb;
  6872. uint16_t abort_iotag, abort_context;
  6873. struct lpfc_iocbq *abort_iocb;
  6874. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6875. abort_iocb = NULL;
  6876. if (irsp->ulpStatus) {
  6877. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6878. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6879. spin_lock_irq(&phba->hbalock);
  6880. if (phba->sli_rev < LPFC_SLI_REV4) {
  6881. if (abort_iotag != 0 &&
  6882. abort_iotag <= phba->sli.last_iotag)
  6883. abort_iocb =
  6884. phba->sli.iocbq_lookup[abort_iotag];
  6885. } else
  6886. /* For sli4 the abort_tag is the XRI,
  6887. * so the abort routine puts the iotag of the iocb
  6888. * being aborted in the context field of the abort
  6889. * IOCB.
  6890. */
  6891. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6892. /*
  6893. * If the iocb is not found in Firmware queue the iocb
  6894. * might have completed already. Do not free it again.
  6895. */
  6896. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6897. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6898. spin_unlock_irq(&phba->hbalock);
  6899. lpfc_sli_release_iocbq(phba, cmdiocb);
  6900. return;
  6901. }
  6902. /* For SLI4 the ulpContext field for abort IOCB
  6903. * holds the iotag of the IOCB being aborted so
  6904. * the local abort_context needs to be reset to
  6905. * match the aborted IOCBs ulpContext.
  6906. */
  6907. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6908. abort_context = abort_iocb->iocb.ulpContext;
  6909. }
  6910. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6911. "0327 Cannot abort els iocb %p "
  6912. "with tag %x context %x, abort status %x, "
  6913. "abort code %x\n",
  6914. abort_iocb, abort_iotag, abort_context,
  6915. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6916. /*
  6917. * make sure we have the right iocbq before taking it
  6918. * off the txcmplq and try to call completion routine.
  6919. */
  6920. if (!abort_iocb ||
  6921. abort_iocb->iocb.ulpContext != abort_context ||
  6922. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6923. spin_unlock_irq(&phba->hbalock);
  6924. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6925. /*
  6926. * leave the SLI4 aborted command on the txcmplq
  6927. * list and the command complete WCQE's XB bit
  6928. * will tell whether the SGL (XRI) can be released
  6929. * immediately or to the aborted SGL list for the
  6930. * following abort XRI from the HBA.
  6931. */
  6932. list_del_init(&abort_iocb->list);
  6933. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6934. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6935. pring->txcmplq_cnt--;
  6936. }
  6937. /* Firmware could still be in progress of DMAing
  6938. * payload, so don't free data buffer till after
  6939. * a hbeat.
  6940. */
  6941. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6942. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6943. spin_unlock_irq(&phba->hbalock);
  6944. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6945. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6946. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6947. } else
  6948. spin_unlock_irq(&phba->hbalock);
  6949. }
  6950. lpfc_sli_release_iocbq(phba, cmdiocb);
  6951. return;
  6952. }
  6953. /**
  6954. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6955. * @phba: Pointer to HBA context object.
  6956. * @cmdiocb: Pointer to driver command iocb object.
  6957. * @rspiocb: Pointer to driver response iocb object.
  6958. *
  6959. * The function is called from SLI ring event handler with no
  6960. * lock held. This function is the completion handler for ELS commands
  6961. * which are aborted. The function frees memory resources used for
  6962. * the aborted ELS commands.
  6963. **/
  6964. static void
  6965. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6966. struct lpfc_iocbq *rspiocb)
  6967. {
  6968. IOCB_t *irsp = &rspiocb->iocb;
  6969. /* ELS cmd tag <ulpIoTag> completes */
  6970. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6971. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6972. "x%x x%x x%x\n",
  6973. irsp->ulpIoTag, irsp->ulpStatus,
  6974. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6975. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6976. lpfc_ct_free_iocb(phba, cmdiocb);
  6977. else
  6978. lpfc_els_free_iocb(phba, cmdiocb);
  6979. return;
  6980. }
  6981. /**
  6982. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  6983. * @phba: Pointer to HBA context object.
  6984. * @pring: Pointer to driver SLI ring object.
  6985. * @cmdiocb: Pointer to driver command iocb object.
  6986. *
  6987. * This function issues an abort iocb for the provided command iocb down to
  6988. * the port. Other than the case the outstanding command iocb is an abort
  6989. * request, this function issues abort out unconditionally. This function is
  6990. * called with hbalock held. The function returns 0 when it fails due to
  6991. * memory allocation failure or when the command iocb is an abort request.
  6992. **/
  6993. static int
  6994. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6995. struct lpfc_iocbq *cmdiocb)
  6996. {
  6997. struct lpfc_vport *vport = cmdiocb->vport;
  6998. struct lpfc_iocbq *abtsiocbp;
  6999. IOCB_t *icmd = NULL;
  7000. IOCB_t *iabt = NULL;
  7001. int retval;
  7002. /*
  7003. * There are certain command types we don't want to abort. And we
  7004. * don't want to abort commands that are already in the process of
  7005. * being aborted.
  7006. */
  7007. icmd = &cmdiocb->iocb;
  7008. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7009. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7010. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7011. return 0;
  7012. /* issue ABTS for this IOCB based on iotag */
  7013. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7014. if (abtsiocbp == NULL)
  7015. return 0;
  7016. /* This signals the response to set the correct status
  7017. * before calling the completion handler
  7018. */
  7019. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7020. iabt = &abtsiocbp->iocb;
  7021. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7022. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7023. if (phba->sli_rev == LPFC_SLI_REV4) {
  7024. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7025. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7026. }
  7027. else
  7028. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7029. iabt->ulpLe = 1;
  7030. iabt->ulpClass = icmd->ulpClass;
  7031. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7032. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7033. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7034. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7035. if (phba->link_state >= LPFC_LINK_UP)
  7036. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7037. else
  7038. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7039. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7040. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7041. "0339 Abort xri x%x, original iotag x%x, "
  7042. "abort cmd iotag x%x\n",
  7043. iabt->un.acxri.abortIoTag,
  7044. iabt->un.acxri.abortContextTag,
  7045. abtsiocbp->iotag);
  7046. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7047. if (retval)
  7048. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7049. /*
  7050. * Caller to this routine should check for IOCB_ERROR
  7051. * and handle it properly. This routine no longer removes
  7052. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7053. */
  7054. return retval;
  7055. }
  7056. /**
  7057. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7058. * @phba: Pointer to HBA context object.
  7059. * @pring: Pointer to driver SLI ring object.
  7060. * @cmdiocb: Pointer to driver command iocb object.
  7061. *
  7062. * This function issues an abort iocb for the provided command iocb. In case
  7063. * of unloading, the abort iocb will not be issued to commands on the ELS
  7064. * ring. Instead, the callback function shall be changed to those commands
  7065. * so that nothing happens when them finishes. This function is called with
  7066. * hbalock held. The function returns 0 when the command iocb is an abort
  7067. * request.
  7068. **/
  7069. int
  7070. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7071. struct lpfc_iocbq *cmdiocb)
  7072. {
  7073. struct lpfc_vport *vport = cmdiocb->vport;
  7074. int retval = IOCB_ERROR;
  7075. IOCB_t *icmd = NULL;
  7076. /*
  7077. * There are certain command types we don't want to abort. And we
  7078. * don't want to abort commands that are already in the process of
  7079. * being aborted.
  7080. */
  7081. icmd = &cmdiocb->iocb;
  7082. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7083. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7084. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7085. return 0;
  7086. /*
  7087. * If we're unloading, don't abort iocb on the ELS ring, but change
  7088. * the callback so that nothing happens when it finishes.
  7089. */
  7090. if ((vport->load_flag & FC_UNLOADING) &&
  7091. (pring->ringno == LPFC_ELS_RING)) {
  7092. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7093. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7094. else
  7095. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7096. goto abort_iotag_exit;
  7097. }
  7098. /* Now, we try to issue the abort to the cmdiocb out */
  7099. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7100. abort_iotag_exit:
  7101. /*
  7102. * Caller to this routine should check for IOCB_ERROR
  7103. * and handle it properly. This routine no longer removes
  7104. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7105. */
  7106. return retval;
  7107. }
  7108. /**
  7109. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7110. * @phba: Pointer to HBA context object.
  7111. * @pring: Pointer to driver SLI ring object.
  7112. *
  7113. * This function aborts all iocbs in the given ring and frees all the iocb
  7114. * objects in txq. This function issues abort iocbs unconditionally for all
  7115. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7116. * to complete before the return of this function. The caller is not required
  7117. * to hold any locks.
  7118. **/
  7119. static void
  7120. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7121. {
  7122. LIST_HEAD(completions);
  7123. struct lpfc_iocbq *iocb, *next_iocb;
  7124. if (pring->ringno == LPFC_ELS_RING)
  7125. lpfc_fabric_abort_hba(phba);
  7126. spin_lock_irq(&phba->hbalock);
  7127. /* Take off all the iocbs on txq for cancelling */
  7128. list_splice_init(&pring->txq, &completions);
  7129. pring->txq_cnt = 0;
  7130. /* Next issue ABTS for everything on the txcmplq */
  7131. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7132. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7133. spin_unlock_irq(&phba->hbalock);
  7134. /* Cancel all the IOCBs from the completions list */
  7135. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7136. IOERR_SLI_ABORTED);
  7137. }
  7138. /**
  7139. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7140. * @phba: pointer to lpfc HBA data structure.
  7141. *
  7142. * This routine will abort all pending and outstanding iocbs to an HBA.
  7143. **/
  7144. void
  7145. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7146. {
  7147. struct lpfc_sli *psli = &phba->sli;
  7148. struct lpfc_sli_ring *pring;
  7149. int i;
  7150. for (i = 0; i < psli->num_rings; i++) {
  7151. pring = &psli->ring[i];
  7152. lpfc_sli_iocb_ring_abort(phba, pring);
  7153. }
  7154. }
  7155. /**
  7156. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7157. * @iocbq: Pointer to driver iocb object.
  7158. * @vport: Pointer to driver virtual port object.
  7159. * @tgt_id: SCSI ID of the target.
  7160. * @lun_id: LUN ID of the scsi device.
  7161. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7162. *
  7163. * This function acts as an iocb filter for functions which abort or count
  7164. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7165. * 0 if the filtering criteria is met for the given iocb and will return
  7166. * 1 if the filtering criteria is not met.
  7167. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7168. * given iocb is for the SCSI device specified by vport, tgt_id and
  7169. * lun_id parameter.
  7170. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7171. * given iocb is for the SCSI target specified by vport and tgt_id
  7172. * parameters.
  7173. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7174. * given iocb is for the SCSI host associated with the given vport.
  7175. * This function is called with no locks held.
  7176. **/
  7177. static int
  7178. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7179. uint16_t tgt_id, uint64_t lun_id,
  7180. lpfc_ctx_cmd ctx_cmd)
  7181. {
  7182. struct lpfc_scsi_buf *lpfc_cmd;
  7183. int rc = 1;
  7184. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7185. return rc;
  7186. if (iocbq->vport != vport)
  7187. return rc;
  7188. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7189. if (lpfc_cmd->pCmd == NULL)
  7190. return rc;
  7191. switch (ctx_cmd) {
  7192. case LPFC_CTX_LUN:
  7193. if ((lpfc_cmd->rdata->pnode) &&
  7194. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7195. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7196. rc = 0;
  7197. break;
  7198. case LPFC_CTX_TGT:
  7199. if ((lpfc_cmd->rdata->pnode) &&
  7200. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7201. rc = 0;
  7202. break;
  7203. case LPFC_CTX_HOST:
  7204. rc = 0;
  7205. break;
  7206. default:
  7207. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7208. __func__, ctx_cmd);
  7209. break;
  7210. }
  7211. return rc;
  7212. }
  7213. /**
  7214. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7215. * @vport: Pointer to virtual port.
  7216. * @tgt_id: SCSI ID of the target.
  7217. * @lun_id: LUN ID of the scsi device.
  7218. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7219. *
  7220. * This function returns number of FCP commands pending for the vport.
  7221. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7222. * commands pending on the vport associated with SCSI device specified
  7223. * by tgt_id and lun_id parameters.
  7224. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7225. * commands pending on the vport associated with SCSI target specified
  7226. * by tgt_id parameter.
  7227. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7228. * commands pending on the vport.
  7229. * This function returns the number of iocbs which satisfy the filter.
  7230. * This function is called without any lock held.
  7231. **/
  7232. int
  7233. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7234. lpfc_ctx_cmd ctx_cmd)
  7235. {
  7236. struct lpfc_hba *phba = vport->phba;
  7237. struct lpfc_iocbq *iocbq;
  7238. int sum, i;
  7239. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7240. iocbq = phba->sli.iocbq_lookup[i];
  7241. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7242. ctx_cmd) == 0)
  7243. sum++;
  7244. }
  7245. return sum;
  7246. }
  7247. /**
  7248. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7249. * @phba: Pointer to HBA context object
  7250. * @cmdiocb: Pointer to command iocb object.
  7251. * @rspiocb: Pointer to response iocb object.
  7252. *
  7253. * This function is called when an aborted FCP iocb completes. This
  7254. * function is called by the ring event handler with no lock held.
  7255. * This function frees the iocb.
  7256. **/
  7257. void
  7258. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7259. struct lpfc_iocbq *rspiocb)
  7260. {
  7261. lpfc_sli_release_iocbq(phba, cmdiocb);
  7262. return;
  7263. }
  7264. /**
  7265. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7266. * @vport: Pointer to virtual port.
  7267. * @pring: Pointer to driver SLI ring object.
  7268. * @tgt_id: SCSI ID of the target.
  7269. * @lun_id: LUN ID of the scsi device.
  7270. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7271. *
  7272. * This function sends an abort command for every SCSI command
  7273. * associated with the given virtual port pending on the ring
  7274. * filtered by lpfc_sli_validate_fcp_iocb function.
  7275. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7276. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7277. * parameters
  7278. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7279. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7280. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7281. * FCP iocbs associated with virtual port.
  7282. * This function returns number of iocbs it failed to abort.
  7283. * This function is called with no locks held.
  7284. **/
  7285. int
  7286. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7287. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7288. {
  7289. struct lpfc_hba *phba = vport->phba;
  7290. struct lpfc_iocbq *iocbq;
  7291. struct lpfc_iocbq *abtsiocb;
  7292. IOCB_t *cmd = NULL;
  7293. int errcnt = 0, ret_val = 0;
  7294. int i;
  7295. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7296. iocbq = phba->sli.iocbq_lookup[i];
  7297. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7298. abort_cmd) != 0)
  7299. continue;
  7300. /* issue ABTS for this IOCB based on iotag */
  7301. abtsiocb = lpfc_sli_get_iocbq(phba);
  7302. if (abtsiocb == NULL) {
  7303. errcnt++;
  7304. continue;
  7305. }
  7306. cmd = &iocbq->iocb;
  7307. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7308. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7309. if (phba->sli_rev == LPFC_SLI_REV4)
  7310. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7311. else
  7312. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7313. abtsiocb->iocb.ulpLe = 1;
  7314. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7315. abtsiocb->vport = phba->pport;
  7316. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7317. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7318. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7319. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7320. if (lpfc_is_link_up(phba))
  7321. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7322. else
  7323. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7324. /* Setup callback routine and issue the command. */
  7325. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7326. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7327. abtsiocb, 0);
  7328. if (ret_val == IOCB_ERROR) {
  7329. lpfc_sli_release_iocbq(phba, abtsiocb);
  7330. errcnt++;
  7331. continue;
  7332. }
  7333. }
  7334. return errcnt;
  7335. }
  7336. /**
  7337. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7338. * @phba: Pointer to HBA context object.
  7339. * @cmdiocbq: Pointer to command iocb.
  7340. * @rspiocbq: Pointer to response iocb.
  7341. *
  7342. * This function is the completion handler for iocbs issued using
  7343. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7344. * ring event handler function without any lock held. This function
  7345. * can be called from both worker thread context and interrupt
  7346. * context. This function also can be called from other thread which
  7347. * cleans up the SLI layer objects.
  7348. * This function copy the contents of the response iocb to the
  7349. * response iocb memory object provided by the caller of
  7350. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7351. * sleeps for the iocb completion.
  7352. **/
  7353. static void
  7354. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7355. struct lpfc_iocbq *cmdiocbq,
  7356. struct lpfc_iocbq *rspiocbq)
  7357. {
  7358. wait_queue_head_t *pdone_q;
  7359. unsigned long iflags;
  7360. struct lpfc_scsi_buf *lpfc_cmd;
  7361. spin_lock_irqsave(&phba->hbalock, iflags);
  7362. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7363. if (cmdiocbq->context2 && rspiocbq)
  7364. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7365. &rspiocbq->iocb, sizeof(IOCB_t));
  7366. /* Set the exchange busy flag for task management commands */
  7367. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7368. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7369. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7370. cur_iocbq);
  7371. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7372. }
  7373. pdone_q = cmdiocbq->context_un.wait_queue;
  7374. if (pdone_q)
  7375. wake_up(pdone_q);
  7376. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7377. return;
  7378. }
  7379. /**
  7380. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7381. * @phba: Pointer to HBA context object..
  7382. * @piocbq: Pointer to command iocb.
  7383. * @flag: Flag to test.
  7384. *
  7385. * This routine grabs the hbalock and then test the iocb_flag to
  7386. * see if the passed in flag is set.
  7387. * Returns:
  7388. * 1 if flag is set.
  7389. * 0 if flag is not set.
  7390. **/
  7391. static int
  7392. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7393. struct lpfc_iocbq *piocbq, uint32_t flag)
  7394. {
  7395. unsigned long iflags;
  7396. int ret;
  7397. spin_lock_irqsave(&phba->hbalock, iflags);
  7398. ret = piocbq->iocb_flag & flag;
  7399. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7400. return ret;
  7401. }
  7402. /**
  7403. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7404. * @phba: Pointer to HBA context object..
  7405. * @pring: Pointer to sli ring.
  7406. * @piocb: Pointer to command iocb.
  7407. * @prspiocbq: Pointer to response iocb.
  7408. * @timeout: Timeout in number of seconds.
  7409. *
  7410. * This function issues the iocb to firmware and waits for the
  7411. * iocb to complete. If the iocb command is not
  7412. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7413. * Caller should not free the iocb resources if this function
  7414. * returns IOCB_TIMEDOUT.
  7415. * The function waits for the iocb completion using an
  7416. * non-interruptible wait.
  7417. * This function will sleep while waiting for iocb completion.
  7418. * So, this function should not be called from any context which
  7419. * does not allow sleeping. Due to the same reason, this function
  7420. * cannot be called with interrupt disabled.
  7421. * This function assumes that the iocb completions occur while
  7422. * this function sleep. So, this function cannot be called from
  7423. * the thread which process iocb completion for this ring.
  7424. * This function clears the iocb_flag of the iocb object before
  7425. * issuing the iocb and the iocb completion handler sets this
  7426. * flag and wakes this thread when the iocb completes.
  7427. * The contents of the response iocb will be copied to prspiocbq
  7428. * by the completion handler when the command completes.
  7429. * This function returns IOCB_SUCCESS when success.
  7430. * This function is called with no lock held.
  7431. **/
  7432. int
  7433. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7434. uint32_t ring_number,
  7435. struct lpfc_iocbq *piocb,
  7436. struct lpfc_iocbq *prspiocbq,
  7437. uint32_t timeout)
  7438. {
  7439. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7440. long timeleft, timeout_req = 0;
  7441. int retval = IOCB_SUCCESS;
  7442. uint32_t creg_val;
  7443. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7444. /*
  7445. * If the caller has provided a response iocbq buffer, then context2
  7446. * is NULL or its an error.
  7447. */
  7448. if (prspiocbq) {
  7449. if (piocb->context2)
  7450. return IOCB_ERROR;
  7451. piocb->context2 = prspiocbq;
  7452. }
  7453. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7454. piocb->context_un.wait_queue = &done_q;
  7455. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7456. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7457. creg_val = readl(phba->HCregaddr);
  7458. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7459. writel(creg_val, phba->HCregaddr);
  7460. readl(phba->HCregaddr); /* flush */
  7461. }
  7462. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7463. SLI_IOCB_RET_IOCB);
  7464. if (retval == IOCB_SUCCESS) {
  7465. timeout_req = timeout * HZ;
  7466. timeleft = wait_event_timeout(done_q,
  7467. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7468. timeout_req);
  7469. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7470. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7471. "0331 IOCB wake signaled\n");
  7472. } else if (timeleft == 0) {
  7473. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7474. "0338 IOCB wait timeout error - no "
  7475. "wake response Data x%x\n", timeout);
  7476. retval = IOCB_TIMEDOUT;
  7477. } else {
  7478. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7479. "0330 IOCB wake NOT set, "
  7480. "Data x%x x%lx\n",
  7481. timeout, (timeleft / jiffies));
  7482. retval = IOCB_TIMEDOUT;
  7483. }
  7484. } else if (retval == IOCB_BUSY) {
  7485. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7486. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7487. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7488. return retval;
  7489. } else {
  7490. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7491. "0332 IOCB wait issue failed, Data x%x\n",
  7492. retval);
  7493. retval = IOCB_ERROR;
  7494. }
  7495. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7496. creg_val = readl(phba->HCregaddr);
  7497. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7498. writel(creg_val, phba->HCregaddr);
  7499. readl(phba->HCregaddr); /* flush */
  7500. }
  7501. if (prspiocbq)
  7502. piocb->context2 = NULL;
  7503. piocb->context_un.wait_queue = NULL;
  7504. piocb->iocb_cmpl = NULL;
  7505. return retval;
  7506. }
  7507. /**
  7508. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7509. * @phba: Pointer to HBA context object.
  7510. * @pmboxq: Pointer to driver mailbox object.
  7511. * @timeout: Timeout in number of seconds.
  7512. *
  7513. * This function issues the mailbox to firmware and waits for the
  7514. * mailbox command to complete. If the mailbox command is not
  7515. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7516. * The function waits for the mailbox completion using an
  7517. * interruptible wait. If the thread is woken up due to a
  7518. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7519. * should not free the mailbox resources, if this function returns
  7520. * MBX_TIMEOUT.
  7521. * This function will sleep while waiting for mailbox completion.
  7522. * So, this function should not be called from any context which
  7523. * does not allow sleeping. Due to the same reason, this function
  7524. * cannot be called with interrupt disabled.
  7525. * This function assumes that the mailbox completion occurs while
  7526. * this function sleep. So, this function cannot be called from
  7527. * the worker thread which processes mailbox completion.
  7528. * This function is called in the context of HBA management
  7529. * applications.
  7530. * This function returns MBX_SUCCESS when successful.
  7531. * This function is called with no lock held.
  7532. **/
  7533. int
  7534. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7535. uint32_t timeout)
  7536. {
  7537. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7538. int retval;
  7539. unsigned long flag;
  7540. /* The caller must leave context1 empty. */
  7541. if (pmboxq->context1)
  7542. return MBX_NOT_FINISHED;
  7543. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7544. /* setup wake call as IOCB callback */
  7545. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7546. /* setup context field to pass wait_queue pointer to wake function */
  7547. pmboxq->context1 = &done_q;
  7548. /* now issue the command */
  7549. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7550. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7551. wait_event_interruptible_timeout(done_q,
  7552. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7553. timeout * HZ);
  7554. spin_lock_irqsave(&phba->hbalock, flag);
  7555. pmboxq->context1 = NULL;
  7556. /*
  7557. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7558. * else do not free the resources.
  7559. */
  7560. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7561. retval = MBX_SUCCESS;
  7562. lpfc_sli4_swap_str(phba, pmboxq);
  7563. } else {
  7564. retval = MBX_TIMEOUT;
  7565. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7566. }
  7567. spin_unlock_irqrestore(&phba->hbalock, flag);
  7568. }
  7569. return retval;
  7570. }
  7571. /**
  7572. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7573. * @phba: Pointer to HBA context.
  7574. *
  7575. * This function is called to shutdown the driver's mailbox sub-system.
  7576. * It first marks the mailbox sub-system is in a block state to prevent
  7577. * the asynchronous mailbox command from issued off the pending mailbox
  7578. * command queue. If the mailbox command sub-system shutdown is due to
  7579. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7580. * the mailbox sub-system flush routine to forcefully bring down the
  7581. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7582. * as with offline or HBA function reset), this routine will wait for the
  7583. * outstanding mailbox command to complete before invoking the mailbox
  7584. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7585. **/
  7586. void
  7587. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7588. {
  7589. struct lpfc_sli *psli = &phba->sli;
  7590. uint8_t actcmd = MBX_HEARTBEAT;
  7591. unsigned long timeout;
  7592. spin_lock_irq(&phba->hbalock);
  7593. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7594. spin_unlock_irq(&phba->hbalock);
  7595. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7596. spin_lock_irq(&phba->hbalock);
  7597. if (phba->sli.mbox_active)
  7598. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7599. spin_unlock_irq(&phba->hbalock);
  7600. /* Determine how long we might wait for the active mailbox
  7601. * command to be gracefully completed by firmware.
  7602. */
  7603. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7604. 1000) + jiffies;
  7605. while (phba->sli.mbox_active) {
  7606. /* Check active mailbox complete status every 2ms */
  7607. msleep(2);
  7608. if (time_after(jiffies, timeout))
  7609. /* Timeout, let the mailbox flush routine to
  7610. * forcefully release active mailbox command
  7611. */
  7612. break;
  7613. }
  7614. }
  7615. lpfc_sli_mbox_sys_flush(phba);
  7616. }
  7617. /**
  7618. * lpfc_sli_eratt_read - read sli-3 error attention events
  7619. * @phba: Pointer to HBA context.
  7620. *
  7621. * This function is called to read the SLI3 device error attention registers
  7622. * for possible error attention events. The caller must hold the hostlock
  7623. * with spin_lock_irq().
  7624. *
  7625. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7626. * Register and returns 0 otherwise.
  7627. **/
  7628. static int
  7629. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7630. {
  7631. uint32_t ha_copy;
  7632. /* Read chip Host Attention (HA) register */
  7633. ha_copy = readl(phba->HAregaddr);
  7634. if (ha_copy & HA_ERATT) {
  7635. /* Read host status register to retrieve error event */
  7636. lpfc_sli_read_hs(phba);
  7637. /* Check if there is a deferred error condition is active */
  7638. if ((HS_FFER1 & phba->work_hs) &&
  7639. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7640. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7641. phba->hba_flag |= DEFER_ERATT;
  7642. /* Clear all interrupt enable conditions */
  7643. writel(0, phba->HCregaddr);
  7644. readl(phba->HCregaddr);
  7645. }
  7646. /* Set the driver HA work bitmap */
  7647. phba->work_ha |= HA_ERATT;
  7648. /* Indicate polling handles this ERATT */
  7649. phba->hba_flag |= HBA_ERATT_HANDLED;
  7650. return 1;
  7651. }
  7652. return 0;
  7653. }
  7654. /**
  7655. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7656. * @phba: Pointer to HBA context.
  7657. *
  7658. * This function is called to read the SLI4 device error attention registers
  7659. * for possible error attention events. The caller must hold the hostlock
  7660. * with spin_lock_irq().
  7661. *
  7662. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7663. * Register and returns 0 otherwise.
  7664. **/
  7665. static int
  7666. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7667. {
  7668. uint32_t uerr_sta_hi, uerr_sta_lo;
  7669. uint32_t if_type, portsmphr;
  7670. struct lpfc_register portstat_reg;
  7671. /*
  7672. * For now, use the SLI4 device internal unrecoverable error
  7673. * registers for error attention. This can be changed later.
  7674. */
  7675. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7676. switch (if_type) {
  7677. case LPFC_SLI_INTF_IF_TYPE_0:
  7678. uerr_sta_lo = readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  7679. uerr_sta_hi = readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  7680. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7681. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7682. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7683. "1423 HBA Unrecoverable error: "
  7684. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7685. "ue_mask_lo_reg=0x%x, "
  7686. "ue_mask_hi_reg=0x%x\n",
  7687. uerr_sta_lo, uerr_sta_hi,
  7688. phba->sli4_hba.ue_mask_lo,
  7689. phba->sli4_hba.ue_mask_hi);
  7690. phba->work_status[0] = uerr_sta_lo;
  7691. phba->work_status[1] = uerr_sta_hi;
  7692. phba->work_ha |= HA_ERATT;
  7693. phba->hba_flag |= HBA_ERATT_HANDLED;
  7694. return 1;
  7695. }
  7696. break;
  7697. case LPFC_SLI_INTF_IF_TYPE_2:
  7698. portstat_reg.word0 =
  7699. readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
  7700. portsmphr = readl(phba->sli4_hba.PSMPHRregaddr);
  7701. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  7702. phba->work_status[0] =
  7703. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  7704. phba->work_status[1] =
  7705. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  7706. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7707. "2885 Port Error Detected: "
  7708. "port status reg 0x%x, "
  7709. "port smphr reg 0x%x, "
  7710. "error 1=0x%x, error 2=0x%x\n",
  7711. portstat_reg.word0,
  7712. portsmphr,
  7713. phba->work_status[0],
  7714. phba->work_status[1]);
  7715. phba->work_ha |= HA_ERATT;
  7716. phba->hba_flag |= HBA_ERATT_HANDLED;
  7717. return 1;
  7718. }
  7719. break;
  7720. case LPFC_SLI_INTF_IF_TYPE_1:
  7721. default:
  7722. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7723. "2886 HBA Error Attention on unsupported "
  7724. "if type %d.", if_type);
  7725. return 1;
  7726. }
  7727. return 0;
  7728. }
  7729. /**
  7730. * lpfc_sli_check_eratt - check error attention events
  7731. * @phba: Pointer to HBA context.
  7732. *
  7733. * This function is called from timer soft interrupt context to check HBA's
  7734. * error attention register bit for error attention events.
  7735. *
  7736. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7737. * Register and returns 0 otherwise.
  7738. **/
  7739. int
  7740. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7741. {
  7742. uint32_t ha_copy;
  7743. /* If somebody is waiting to handle an eratt, don't process it
  7744. * here. The brdkill function will do this.
  7745. */
  7746. if (phba->link_flag & LS_IGNORE_ERATT)
  7747. return 0;
  7748. /* Check if interrupt handler handles this ERATT */
  7749. spin_lock_irq(&phba->hbalock);
  7750. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7751. /* Interrupt handler has handled ERATT */
  7752. spin_unlock_irq(&phba->hbalock);
  7753. return 0;
  7754. }
  7755. /*
  7756. * If there is deferred error attention, do not check for error
  7757. * attention
  7758. */
  7759. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7760. spin_unlock_irq(&phba->hbalock);
  7761. return 0;
  7762. }
  7763. /* If PCI channel is offline, don't process it */
  7764. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7765. spin_unlock_irq(&phba->hbalock);
  7766. return 0;
  7767. }
  7768. switch (phba->sli_rev) {
  7769. case LPFC_SLI_REV2:
  7770. case LPFC_SLI_REV3:
  7771. /* Read chip Host Attention (HA) register */
  7772. ha_copy = lpfc_sli_eratt_read(phba);
  7773. break;
  7774. case LPFC_SLI_REV4:
  7775. /* Read device Uncoverable Error (UERR) registers */
  7776. ha_copy = lpfc_sli4_eratt_read(phba);
  7777. break;
  7778. default:
  7779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7780. "0299 Invalid SLI revision (%d)\n",
  7781. phba->sli_rev);
  7782. ha_copy = 0;
  7783. break;
  7784. }
  7785. spin_unlock_irq(&phba->hbalock);
  7786. return ha_copy;
  7787. }
  7788. /**
  7789. * lpfc_intr_state_check - Check device state for interrupt handling
  7790. * @phba: Pointer to HBA context.
  7791. *
  7792. * This inline routine checks whether a device or its PCI slot is in a state
  7793. * that the interrupt should be handled.
  7794. *
  7795. * This function returns 0 if the device or the PCI slot is in a state that
  7796. * interrupt should be handled, otherwise -EIO.
  7797. */
  7798. static inline int
  7799. lpfc_intr_state_check(struct lpfc_hba *phba)
  7800. {
  7801. /* If the pci channel is offline, ignore all the interrupts */
  7802. if (unlikely(pci_channel_offline(phba->pcidev)))
  7803. return -EIO;
  7804. /* Update device level interrupt statistics */
  7805. phba->sli.slistat.sli_intr++;
  7806. /* Ignore all interrupts during initialization. */
  7807. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7808. return -EIO;
  7809. return 0;
  7810. }
  7811. /**
  7812. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7813. * @irq: Interrupt number.
  7814. * @dev_id: The device context pointer.
  7815. *
  7816. * This function is directly called from the PCI layer as an interrupt
  7817. * service routine when device with SLI-3 interface spec is enabled with
  7818. * MSI-X multi-message interrupt mode and there are slow-path events in
  7819. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7820. * interrupt mode, this function is called as part of the device-level
  7821. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7822. * is undergoing initialization, the interrupt handler will not process
  7823. * the interrupt. The link attention and ELS ring attention events are
  7824. * handled by the worker thread. The interrupt handler signals the worker
  7825. * thread and returns for these events. This function is called without
  7826. * any lock held. It gets the hbalock to access and update SLI data
  7827. * structures.
  7828. *
  7829. * This function returns IRQ_HANDLED when interrupt is handled else it
  7830. * returns IRQ_NONE.
  7831. **/
  7832. irqreturn_t
  7833. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7834. {
  7835. struct lpfc_hba *phba;
  7836. uint32_t ha_copy, hc_copy;
  7837. uint32_t work_ha_copy;
  7838. unsigned long status;
  7839. unsigned long iflag;
  7840. uint32_t control;
  7841. MAILBOX_t *mbox, *pmbox;
  7842. struct lpfc_vport *vport;
  7843. struct lpfc_nodelist *ndlp;
  7844. struct lpfc_dmabuf *mp;
  7845. LPFC_MBOXQ_t *pmb;
  7846. int rc;
  7847. /*
  7848. * Get the driver's phba structure from the dev_id and
  7849. * assume the HBA is not interrupting.
  7850. */
  7851. phba = (struct lpfc_hba *)dev_id;
  7852. if (unlikely(!phba))
  7853. return IRQ_NONE;
  7854. /*
  7855. * Stuff needs to be attented to when this function is invoked as an
  7856. * individual interrupt handler in MSI-X multi-message interrupt mode
  7857. */
  7858. if (phba->intr_type == MSIX) {
  7859. /* Check device state for handling interrupt */
  7860. if (lpfc_intr_state_check(phba))
  7861. return IRQ_NONE;
  7862. /* Need to read HA REG for slow-path events */
  7863. spin_lock_irqsave(&phba->hbalock, iflag);
  7864. ha_copy = readl(phba->HAregaddr);
  7865. /* If somebody is waiting to handle an eratt don't process it
  7866. * here. The brdkill function will do this.
  7867. */
  7868. if (phba->link_flag & LS_IGNORE_ERATT)
  7869. ha_copy &= ~HA_ERATT;
  7870. /* Check the need for handling ERATT in interrupt handler */
  7871. if (ha_copy & HA_ERATT) {
  7872. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7873. /* ERATT polling has handled ERATT */
  7874. ha_copy &= ~HA_ERATT;
  7875. else
  7876. /* Indicate interrupt handler handles ERATT */
  7877. phba->hba_flag |= HBA_ERATT_HANDLED;
  7878. }
  7879. /*
  7880. * If there is deferred error attention, do not check for any
  7881. * interrupt.
  7882. */
  7883. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7884. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7885. return IRQ_NONE;
  7886. }
  7887. /* Clear up only attention source related to slow-path */
  7888. hc_copy = readl(phba->HCregaddr);
  7889. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7890. HC_LAINT_ENA | HC_ERINT_ENA),
  7891. phba->HCregaddr);
  7892. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7893. phba->HAregaddr);
  7894. writel(hc_copy, phba->HCregaddr);
  7895. readl(phba->HAregaddr); /* flush */
  7896. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7897. } else
  7898. ha_copy = phba->ha_copy;
  7899. work_ha_copy = ha_copy & phba->work_ha_mask;
  7900. if (work_ha_copy) {
  7901. if (work_ha_copy & HA_LATT) {
  7902. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7903. /*
  7904. * Turn off Link Attention interrupts
  7905. * until CLEAR_LA done
  7906. */
  7907. spin_lock_irqsave(&phba->hbalock, iflag);
  7908. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7909. control = readl(phba->HCregaddr);
  7910. control &= ~HC_LAINT_ENA;
  7911. writel(control, phba->HCregaddr);
  7912. readl(phba->HCregaddr); /* flush */
  7913. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7914. }
  7915. else
  7916. work_ha_copy &= ~HA_LATT;
  7917. }
  7918. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7919. /*
  7920. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7921. * the only slow ring.
  7922. */
  7923. status = (work_ha_copy &
  7924. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7925. status >>= (4*LPFC_ELS_RING);
  7926. if (status & HA_RXMASK) {
  7927. spin_lock_irqsave(&phba->hbalock, iflag);
  7928. control = readl(phba->HCregaddr);
  7929. lpfc_debugfs_slow_ring_trc(phba,
  7930. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7931. control, status,
  7932. (uint32_t)phba->sli.slistat.sli_intr);
  7933. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7934. lpfc_debugfs_slow_ring_trc(phba,
  7935. "ISR Disable ring:"
  7936. "pwork:x%x hawork:x%x wait:x%x",
  7937. phba->work_ha, work_ha_copy,
  7938. (uint32_t)((unsigned long)
  7939. &phba->work_waitq));
  7940. control &=
  7941. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7942. writel(control, phba->HCregaddr);
  7943. readl(phba->HCregaddr); /* flush */
  7944. }
  7945. else {
  7946. lpfc_debugfs_slow_ring_trc(phba,
  7947. "ISR slow ring: pwork:"
  7948. "x%x hawork:x%x wait:x%x",
  7949. phba->work_ha, work_ha_copy,
  7950. (uint32_t)((unsigned long)
  7951. &phba->work_waitq));
  7952. }
  7953. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7954. }
  7955. }
  7956. spin_lock_irqsave(&phba->hbalock, iflag);
  7957. if (work_ha_copy & HA_ERATT) {
  7958. lpfc_sli_read_hs(phba);
  7959. /*
  7960. * Check if there is a deferred error condition
  7961. * is active
  7962. */
  7963. if ((HS_FFER1 & phba->work_hs) &&
  7964. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7965. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  7966. phba->work_hs)) {
  7967. phba->hba_flag |= DEFER_ERATT;
  7968. /* Clear all interrupt enable conditions */
  7969. writel(0, phba->HCregaddr);
  7970. readl(phba->HCregaddr);
  7971. }
  7972. }
  7973. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7974. pmb = phba->sli.mbox_active;
  7975. pmbox = &pmb->u.mb;
  7976. mbox = phba->mbox;
  7977. vport = pmb->vport;
  7978. /* First check out the status word */
  7979. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7980. if (pmbox->mbxOwner != OWN_HOST) {
  7981. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7982. /*
  7983. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7984. * mbxStatus <status>
  7985. */
  7986. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7987. LOG_SLI,
  7988. "(%d):0304 Stray Mailbox "
  7989. "Interrupt mbxCommand x%x "
  7990. "mbxStatus x%x\n",
  7991. (vport ? vport->vpi : 0),
  7992. pmbox->mbxCommand,
  7993. pmbox->mbxStatus);
  7994. /* clear mailbox attention bit */
  7995. work_ha_copy &= ~HA_MBATT;
  7996. } else {
  7997. phba->sli.mbox_active = NULL;
  7998. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7999. phba->last_completion_time = jiffies;
  8000. del_timer(&phba->sli.mbox_tmo);
  8001. if (pmb->mbox_cmpl) {
  8002. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  8003. MAILBOX_CMD_SIZE);
  8004. if (pmb->out_ext_byte_len &&
  8005. pmb->context2)
  8006. lpfc_sli_pcimem_bcopy(
  8007. phba->mbox_ext,
  8008. pmb->context2,
  8009. pmb->out_ext_byte_len);
  8010. }
  8011. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8012. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8013. lpfc_debugfs_disc_trc(vport,
  8014. LPFC_DISC_TRC_MBOX_VPORT,
  8015. "MBOX dflt rpi: : "
  8016. "status:x%x rpi:x%x",
  8017. (uint32_t)pmbox->mbxStatus,
  8018. pmbox->un.varWords[0], 0);
  8019. if (!pmbox->mbxStatus) {
  8020. mp = (struct lpfc_dmabuf *)
  8021. (pmb->context1);
  8022. ndlp = (struct lpfc_nodelist *)
  8023. pmb->context2;
  8024. /* Reg_LOGIN of dflt RPI was
  8025. * successful. new lets get
  8026. * rid of the RPI using the
  8027. * same mbox buffer.
  8028. */
  8029. lpfc_unreg_login(phba,
  8030. vport->vpi,
  8031. pmbox->un.varWords[0],
  8032. pmb);
  8033. pmb->mbox_cmpl =
  8034. lpfc_mbx_cmpl_dflt_rpi;
  8035. pmb->context1 = mp;
  8036. pmb->context2 = ndlp;
  8037. pmb->vport = vport;
  8038. rc = lpfc_sli_issue_mbox(phba,
  8039. pmb,
  8040. MBX_NOWAIT);
  8041. if (rc != MBX_BUSY)
  8042. lpfc_printf_log(phba,
  8043. KERN_ERR,
  8044. LOG_MBOX | LOG_SLI,
  8045. "0350 rc should have"
  8046. "been MBX_BUSY\n");
  8047. if (rc != MBX_NOT_FINISHED)
  8048. goto send_current_mbox;
  8049. }
  8050. }
  8051. spin_lock_irqsave(
  8052. &phba->pport->work_port_lock,
  8053. iflag);
  8054. phba->pport->work_port_events &=
  8055. ~WORKER_MBOX_TMO;
  8056. spin_unlock_irqrestore(
  8057. &phba->pport->work_port_lock,
  8058. iflag);
  8059. lpfc_mbox_cmpl_put(phba, pmb);
  8060. }
  8061. } else
  8062. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8063. if ((work_ha_copy & HA_MBATT) &&
  8064. (phba->sli.mbox_active == NULL)) {
  8065. send_current_mbox:
  8066. /* Process next mailbox command if there is one */
  8067. do {
  8068. rc = lpfc_sli_issue_mbox(phba, NULL,
  8069. MBX_NOWAIT);
  8070. } while (rc == MBX_NOT_FINISHED);
  8071. if (rc != MBX_SUCCESS)
  8072. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8073. LOG_SLI, "0349 rc should be "
  8074. "MBX_SUCCESS\n");
  8075. }
  8076. spin_lock_irqsave(&phba->hbalock, iflag);
  8077. phba->work_ha |= work_ha_copy;
  8078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8079. lpfc_worker_wake_up(phba);
  8080. }
  8081. return IRQ_HANDLED;
  8082. } /* lpfc_sli_sp_intr_handler */
  8083. /**
  8084. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8085. * @irq: Interrupt number.
  8086. * @dev_id: The device context pointer.
  8087. *
  8088. * This function is directly called from the PCI layer as an interrupt
  8089. * service routine when device with SLI-3 interface spec is enabled with
  8090. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8091. * ring event in the HBA. However, when the device is enabled with either
  8092. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8093. * device-level interrupt handler. When the PCI slot is in error recovery
  8094. * or the HBA is undergoing initialization, the interrupt handler will not
  8095. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8096. * the intrrupt context. This function is called without any lock held.
  8097. * It gets the hbalock to access and update SLI data structures.
  8098. *
  8099. * This function returns IRQ_HANDLED when interrupt is handled else it
  8100. * returns IRQ_NONE.
  8101. **/
  8102. irqreturn_t
  8103. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8104. {
  8105. struct lpfc_hba *phba;
  8106. uint32_t ha_copy;
  8107. unsigned long status;
  8108. unsigned long iflag;
  8109. /* Get the driver's phba structure from the dev_id and
  8110. * assume the HBA is not interrupting.
  8111. */
  8112. phba = (struct lpfc_hba *) dev_id;
  8113. if (unlikely(!phba))
  8114. return IRQ_NONE;
  8115. /*
  8116. * Stuff needs to be attented to when this function is invoked as an
  8117. * individual interrupt handler in MSI-X multi-message interrupt mode
  8118. */
  8119. if (phba->intr_type == MSIX) {
  8120. /* Check device state for handling interrupt */
  8121. if (lpfc_intr_state_check(phba))
  8122. return IRQ_NONE;
  8123. /* Need to read HA REG for FCP ring and other ring events */
  8124. ha_copy = readl(phba->HAregaddr);
  8125. /* Clear up only attention source related to fast-path */
  8126. spin_lock_irqsave(&phba->hbalock, iflag);
  8127. /*
  8128. * If there is deferred error attention, do not check for
  8129. * any interrupt.
  8130. */
  8131. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8132. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8133. return IRQ_NONE;
  8134. }
  8135. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8136. phba->HAregaddr);
  8137. readl(phba->HAregaddr); /* flush */
  8138. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8139. } else
  8140. ha_copy = phba->ha_copy;
  8141. /*
  8142. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8143. */
  8144. ha_copy &= ~(phba->work_ha_mask);
  8145. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8146. status >>= (4*LPFC_FCP_RING);
  8147. if (status & HA_RXMASK)
  8148. lpfc_sli_handle_fast_ring_event(phba,
  8149. &phba->sli.ring[LPFC_FCP_RING],
  8150. status);
  8151. if (phba->cfg_multi_ring_support == 2) {
  8152. /*
  8153. * Process all events on extra ring. Take the optimized path
  8154. * for extra ring IO.
  8155. */
  8156. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8157. status >>= (4*LPFC_EXTRA_RING);
  8158. if (status & HA_RXMASK) {
  8159. lpfc_sli_handle_fast_ring_event(phba,
  8160. &phba->sli.ring[LPFC_EXTRA_RING],
  8161. status);
  8162. }
  8163. }
  8164. return IRQ_HANDLED;
  8165. } /* lpfc_sli_fp_intr_handler */
  8166. /**
  8167. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8168. * @irq: Interrupt number.
  8169. * @dev_id: The device context pointer.
  8170. *
  8171. * This function is the HBA device-level interrupt handler to device with
  8172. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8173. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8174. * requires driver attention. This function invokes the slow-path interrupt
  8175. * attention handling function and fast-path interrupt attention handling
  8176. * function in turn to process the relevant HBA attention events. This
  8177. * function is called without any lock held. It gets the hbalock to access
  8178. * and update SLI data structures.
  8179. *
  8180. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8181. * returns IRQ_NONE.
  8182. **/
  8183. irqreturn_t
  8184. lpfc_sli_intr_handler(int irq, void *dev_id)
  8185. {
  8186. struct lpfc_hba *phba;
  8187. irqreturn_t sp_irq_rc, fp_irq_rc;
  8188. unsigned long status1, status2;
  8189. uint32_t hc_copy;
  8190. /*
  8191. * Get the driver's phba structure from the dev_id and
  8192. * assume the HBA is not interrupting.
  8193. */
  8194. phba = (struct lpfc_hba *) dev_id;
  8195. if (unlikely(!phba))
  8196. return IRQ_NONE;
  8197. /* Check device state for handling interrupt */
  8198. if (lpfc_intr_state_check(phba))
  8199. return IRQ_NONE;
  8200. spin_lock(&phba->hbalock);
  8201. phba->ha_copy = readl(phba->HAregaddr);
  8202. if (unlikely(!phba->ha_copy)) {
  8203. spin_unlock(&phba->hbalock);
  8204. return IRQ_NONE;
  8205. } else if (phba->ha_copy & HA_ERATT) {
  8206. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8207. /* ERATT polling has handled ERATT */
  8208. phba->ha_copy &= ~HA_ERATT;
  8209. else
  8210. /* Indicate interrupt handler handles ERATT */
  8211. phba->hba_flag |= HBA_ERATT_HANDLED;
  8212. }
  8213. /*
  8214. * If there is deferred error attention, do not check for any interrupt.
  8215. */
  8216. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8217. spin_unlock(&phba->hbalock);
  8218. return IRQ_NONE;
  8219. }
  8220. /* Clear attention sources except link and error attentions */
  8221. hc_copy = readl(phba->HCregaddr);
  8222. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8223. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8224. phba->HCregaddr);
  8225. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8226. writel(hc_copy, phba->HCregaddr);
  8227. readl(phba->HAregaddr); /* flush */
  8228. spin_unlock(&phba->hbalock);
  8229. /*
  8230. * Invokes slow-path host attention interrupt handling as appropriate.
  8231. */
  8232. /* status of events with mailbox and link attention */
  8233. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8234. /* status of events with ELS ring */
  8235. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8236. status2 >>= (4*LPFC_ELS_RING);
  8237. if (status1 || (status2 & HA_RXMASK))
  8238. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8239. else
  8240. sp_irq_rc = IRQ_NONE;
  8241. /*
  8242. * Invoke fast-path host attention interrupt handling as appropriate.
  8243. */
  8244. /* status of events with FCP ring */
  8245. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8246. status1 >>= (4*LPFC_FCP_RING);
  8247. /* status of events with extra ring */
  8248. if (phba->cfg_multi_ring_support == 2) {
  8249. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8250. status2 >>= (4*LPFC_EXTRA_RING);
  8251. } else
  8252. status2 = 0;
  8253. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8254. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8255. else
  8256. fp_irq_rc = IRQ_NONE;
  8257. /* Return device-level interrupt handling status */
  8258. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8259. } /* lpfc_sli_intr_handler */
  8260. /**
  8261. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8262. * @phba: pointer to lpfc hba data structure.
  8263. *
  8264. * This routine is invoked by the worker thread to process all the pending
  8265. * SLI4 FCP abort XRI events.
  8266. **/
  8267. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8268. {
  8269. struct lpfc_cq_event *cq_event;
  8270. /* First, declare the fcp xri abort event has been handled */
  8271. spin_lock_irq(&phba->hbalock);
  8272. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8273. spin_unlock_irq(&phba->hbalock);
  8274. /* Now, handle all the fcp xri abort events */
  8275. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8276. /* Get the first event from the head of the event queue */
  8277. spin_lock_irq(&phba->hbalock);
  8278. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8279. cq_event, struct lpfc_cq_event, list);
  8280. spin_unlock_irq(&phba->hbalock);
  8281. /* Notify aborted XRI for FCP work queue */
  8282. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8283. /* Free the event processed back to the free pool */
  8284. lpfc_sli4_cq_event_release(phba, cq_event);
  8285. }
  8286. }
  8287. /**
  8288. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8289. * @phba: pointer to lpfc hba data structure.
  8290. *
  8291. * This routine is invoked by the worker thread to process all the pending
  8292. * SLI4 els abort xri events.
  8293. **/
  8294. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8295. {
  8296. struct lpfc_cq_event *cq_event;
  8297. /* First, declare the els xri abort event has been handled */
  8298. spin_lock_irq(&phba->hbalock);
  8299. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8300. spin_unlock_irq(&phba->hbalock);
  8301. /* Now, handle all the els xri abort events */
  8302. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8303. /* Get the first event from the head of the event queue */
  8304. spin_lock_irq(&phba->hbalock);
  8305. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8306. cq_event, struct lpfc_cq_event, list);
  8307. spin_unlock_irq(&phba->hbalock);
  8308. /* Notify aborted XRI for ELS work queue */
  8309. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8310. /* Free the event processed back to the free pool */
  8311. lpfc_sli4_cq_event_release(phba, cq_event);
  8312. }
  8313. }
  8314. /**
  8315. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8316. * @phba: pointer to lpfc hba data structure
  8317. * @pIocbIn: pointer to the rspiocbq
  8318. * @pIocbOut: pointer to the cmdiocbq
  8319. * @wcqe: pointer to the complete wcqe
  8320. *
  8321. * This routine transfers the fields of a command iocbq to a response iocbq
  8322. * by copying all the IOCB fields from command iocbq and transferring the
  8323. * completion status information from the complete wcqe.
  8324. **/
  8325. static void
  8326. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8327. struct lpfc_iocbq *pIocbIn,
  8328. struct lpfc_iocbq *pIocbOut,
  8329. struct lpfc_wcqe_complete *wcqe)
  8330. {
  8331. unsigned long iflags;
  8332. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8333. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8334. sizeof(struct lpfc_iocbq) - offset);
  8335. /* Map WCQE parameters into irspiocb parameters */
  8336. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8337. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8338. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8339. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8340. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8341. wcqe->total_data_placed;
  8342. else
  8343. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8344. else {
  8345. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8346. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8347. }
  8348. /* Pick up HBA exchange busy condition */
  8349. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8350. spin_lock_irqsave(&phba->hbalock, iflags);
  8351. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8352. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8353. }
  8354. }
  8355. /**
  8356. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8357. * @phba: Pointer to HBA context object.
  8358. * @wcqe: Pointer to work-queue completion queue entry.
  8359. *
  8360. * This routine handles an ELS work-queue completion event and construct
  8361. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8362. * discovery engine to handle.
  8363. *
  8364. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8365. **/
  8366. static struct lpfc_iocbq *
  8367. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8368. struct lpfc_iocbq *irspiocbq)
  8369. {
  8370. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8371. struct lpfc_iocbq *cmdiocbq;
  8372. struct lpfc_wcqe_complete *wcqe;
  8373. unsigned long iflags;
  8374. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8375. spin_lock_irqsave(&phba->hbalock, iflags);
  8376. pring->stats.iocb_event++;
  8377. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8378. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8379. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8380. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8381. if (unlikely(!cmdiocbq)) {
  8382. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8383. "0386 ELS complete with no corresponding "
  8384. "cmdiocb: iotag (%d)\n",
  8385. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8386. lpfc_sli_release_iocbq(phba, irspiocbq);
  8387. return NULL;
  8388. }
  8389. /* Fake the irspiocbq and copy necessary response information */
  8390. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8391. return irspiocbq;
  8392. }
  8393. /**
  8394. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8395. * @phba: Pointer to HBA context object.
  8396. * @cqe: Pointer to mailbox completion queue entry.
  8397. *
  8398. * This routine process a mailbox completion queue entry with asynchrous
  8399. * event.
  8400. *
  8401. * Return: true if work posted to worker thread, otherwise false.
  8402. **/
  8403. static bool
  8404. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8405. {
  8406. struct lpfc_cq_event *cq_event;
  8407. unsigned long iflags;
  8408. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8409. "0392 Async Event: word0:x%x, word1:x%x, "
  8410. "word2:x%x, word3:x%x\n", mcqe->word0,
  8411. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8412. /* Allocate a new internal CQ_EVENT entry */
  8413. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8414. if (!cq_event) {
  8415. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8416. "0394 Failed to allocate CQ_EVENT entry\n");
  8417. return false;
  8418. }
  8419. /* Move the CQE into an asynchronous event entry */
  8420. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8421. spin_lock_irqsave(&phba->hbalock, iflags);
  8422. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8423. /* Set the async event flag */
  8424. phba->hba_flag |= ASYNC_EVENT;
  8425. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8426. return true;
  8427. }
  8428. /**
  8429. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8430. * @phba: Pointer to HBA context object.
  8431. * @cqe: Pointer to mailbox completion queue entry.
  8432. *
  8433. * This routine process a mailbox completion queue entry with mailbox
  8434. * completion event.
  8435. *
  8436. * Return: true if work posted to worker thread, otherwise false.
  8437. **/
  8438. static bool
  8439. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8440. {
  8441. uint32_t mcqe_status;
  8442. MAILBOX_t *mbox, *pmbox;
  8443. struct lpfc_mqe *mqe;
  8444. struct lpfc_vport *vport;
  8445. struct lpfc_nodelist *ndlp;
  8446. struct lpfc_dmabuf *mp;
  8447. unsigned long iflags;
  8448. LPFC_MBOXQ_t *pmb;
  8449. bool workposted = false;
  8450. int rc;
  8451. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8452. if (!bf_get(lpfc_trailer_completed, mcqe))
  8453. goto out_no_mqe_complete;
  8454. /* Get the reference to the active mbox command */
  8455. spin_lock_irqsave(&phba->hbalock, iflags);
  8456. pmb = phba->sli.mbox_active;
  8457. if (unlikely(!pmb)) {
  8458. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8459. "1832 No pending MBOX command to handle\n");
  8460. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8461. goto out_no_mqe_complete;
  8462. }
  8463. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8464. mqe = &pmb->u.mqe;
  8465. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8466. mbox = phba->mbox;
  8467. vport = pmb->vport;
  8468. /* Reset heartbeat timer */
  8469. phba->last_completion_time = jiffies;
  8470. del_timer(&phba->sli.mbox_tmo);
  8471. /* Move mbox data to caller's mailbox region, do endian swapping */
  8472. if (pmb->mbox_cmpl && mbox)
  8473. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8474. /* Set the mailbox status with SLI4 range 0x4000 */
  8475. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8476. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8477. bf_set(lpfc_mqe_status, mqe,
  8478. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8479. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8480. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8481. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8482. "MBOX dflt rpi: status:x%x rpi:x%x",
  8483. mcqe_status,
  8484. pmbox->un.varWords[0], 0);
  8485. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8486. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8487. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8488. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8489. * RID of the PPI using the same mbox buffer.
  8490. */
  8491. lpfc_unreg_login(phba, vport->vpi,
  8492. pmbox->un.varWords[0], pmb);
  8493. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8494. pmb->context1 = mp;
  8495. pmb->context2 = ndlp;
  8496. pmb->vport = vport;
  8497. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8498. if (rc != MBX_BUSY)
  8499. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8500. LOG_SLI, "0385 rc should "
  8501. "have been MBX_BUSY\n");
  8502. if (rc != MBX_NOT_FINISHED)
  8503. goto send_current_mbox;
  8504. }
  8505. }
  8506. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8507. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8508. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8509. /* There is mailbox completion work to do */
  8510. spin_lock_irqsave(&phba->hbalock, iflags);
  8511. __lpfc_mbox_cmpl_put(phba, pmb);
  8512. phba->work_ha |= HA_MBATT;
  8513. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8514. workposted = true;
  8515. send_current_mbox:
  8516. spin_lock_irqsave(&phba->hbalock, iflags);
  8517. /* Release the mailbox command posting token */
  8518. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8519. /* Setting active mailbox pointer need to be in sync to flag clear */
  8520. phba->sli.mbox_active = NULL;
  8521. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8522. /* Wake up worker thread to post the next pending mailbox command */
  8523. lpfc_worker_wake_up(phba);
  8524. out_no_mqe_complete:
  8525. if (bf_get(lpfc_trailer_consumed, mcqe))
  8526. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8527. return workposted;
  8528. }
  8529. /**
  8530. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8531. * @phba: Pointer to HBA context object.
  8532. * @cqe: Pointer to mailbox completion queue entry.
  8533. *
  8534. * This routine process a mailbox completion queue entry, it invokes the
  8535. * proper mailbox complete handling or asynchrous event handling routine
  8536. * according to the MCQE's async bit.
  8537. *
  8538. * Return: true if work posted to worker thread, otherwise false.
  8539. **/
  8540. static bool
  8541. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8542. {
  8543. struct lpfc_mcqe mcqe;
  8544. bool workposted;
  8545. /* Copy the mailbox MCQE and convert endian order as needed */
  8546. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8547. /* Invoke the proper event handling routine */
  8548. if (!bf_get(lpfc_trailer_async, &mcqe))
  8549. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8550. else
  8551. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8552. return workposted;
  8553. }
  8554. /**
  8555. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8556. * @phba: Pointer to HBA context object.
  8557. * @wcqe: Pointer to work-queue completion queue entry.
  8558. *
  8559. * This routine handles an ELS work-queue completion event.
  8560. *
  8561. * Return: true if work posted to worker thread, otherwise false.
  8562. **/
  8563. static bool
  8564. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8565. struct lpfc_wcqe_complete *wcqe)
  8566. {
  8567. struct lpfc_iocbq *irspiocbq;
  8568. unsigned long iflags;
  8569. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8570. /* Get an irspiocbq for later ELS response processing use */
  8571. irspiocbq = lpfc_sli_get_iocbq(phba);
  8572. if (!irspiocbq) {
  8573. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8574. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8575. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8576. pring->txq_cnt, phba->iocb_cnt,
  8577. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8578. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8579. return false;
  8580. }
  8581. /* Save off the slow-path queue event for work thread to process */
  8582. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8583. spin_lock_irqsave(&phba->hbalock, iflags);
  8584. list_add_tail(&irspiocbq->cq_event.list,
  8585. &phba->sli4_hba.sp_queue_event);
  8586. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8587. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8588. return true;
  8589. }
  8590. /**
  8591. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8592. * @phba: Pointer to HBA context object.
  8593. * @wcqe: Pointer to work-queue completion queue entry.
  8594. *
  8595. * This routine handles slow-path WQ entry comsumed event by invoking the
  8596. * proper WQ release routine to the slow-path WQ.
  8597. **/
  8598. static void
  8599. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8600. struct lpfc_wcqe_release *wcqe)
  8601. {
  8602. /* Check for the slow-path ELS work queue */
  8603. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8604. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8605. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8606. else
  8607. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8608. "2579 Slow-path wqe consume event carries "
  8609. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8610. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8611. phba->sli4_hba.els_wq->queue_id);
  8612. }
  8613. /**
  8614. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8615. * @phba: Pointer to HBA context object.
  8616. * @cq: Pointer to a WQ completion queue.
  8617. * @wcqe: Pointer to work-queue completion queue entry.
  8618. *
  8619. * This routine handles an XRI abort event.
  8620. *
  8621. * Return: true if work posted to worker thread, otherwise false.
  8622. **/
  8623. static bool
  8624. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8625. struct lpfc_queue *cq,
  8626. struct sli4_wcqe_xri_aborted *wcqe)
  8627. {
  8628. bool workposted = false;
  8629. struct lpfc_cq_event *cq_event;
  8630. unsigned long iflags;
  8631. /* Allocate a new internal CQ_EVENT entry */
  8632. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8633. if (!cq_event) {
  8634. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8635. "0602 Failed to allocate CQ_EVENT entry\n");
  8636. return false;
  8637. }
  8638. /* Move the CQE into the proper xri abort event list */
  8639. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8640. switch (cq->subtype) {
  8641. case LPFC_FCP:
  8642. spin_lock_irqsave(&phba->hbalock, iflags);
  8643. list_add_tail(&cq_event->list,
  8644. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8645. /* Set the fcp xri abort event flag */
  8646. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8647. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8648. workposted = true;
  8649. break;
  8650. case LPFC_ELS:
  8651. spin_lock_irqsave(&phba->hbalock, iflags);
  8652. list_add_tail(&cq_event->list,
  8653. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8654. /* Set the els xri abort event flag */
  8655. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8656. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8657. workposted = true;
  8658. break;
  8659. default:
  8660. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8661. "0603 Invalid work queue CQE subtype (x%x)\n",
  8662. cq->subtype);
  8663. workposted = false;
  8664. break;
  8665. }
  8666. return workposted;
  8667. }
  8668. /**
  8669. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8670. * @phba: Pointer to HBA context object.
  8671. * @rcqe: Pointer to receive-queue completion queue entry.
  8672. *
  8673. * This routine process a receive-queue completion queue entry.
  8674. *
  8675. * Return: true if work posted to worker thread, otherwise false.
  8676. **/
  8677. static bool
  8678. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8679. {
  8680. bool workposted = false;
  8681. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8682. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8683. struct hbq_dmabuf *dma_buf;
  8684. uint32_t status;
  8685. unsigned long iflags;
  8686. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8687. goto out;
  8688. status = bf_get(lpfc_rcqe_status, rcqe);
  8689. switch (status) {
  8690. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8691. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8692. "2537 Receive Frame Truncated!!\n");
  8693. case FC_STATUS_RQ_SUCCESS:
  8694. lpfc_sli4_rq_release(hrq, drq);
  8695. spin_lock_irqsave(&phba->hbalock, iflags);
  8696. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8697. if (!dma_buf) {
  8698. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8699. goto out;
  8700. }
  8701. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8702. /* save off the frame for the word thread to process */
  8703. list_add_tail(&dma_buf->cq_event.list,
  8704. &phba->sli4_hba.sp_queue_event);
  8705. /* Frame received */
  8706. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8707. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8708. workposted = true;
  8709. break;
  8710. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8711. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8712. /* Post more buffers if possible */
  8713. spin_lock_irqsave(&phba->hbalock, iflags);
  8714. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8715. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8716. workposted = true;
  8717. break;
  8718. }
  8719. out:
  8720. return workposted;
  8721. }
  8722. /**
  8723. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8724. * @phba: Pointer to HBA context object.
  8725. * @cq: Pointer to the completion queue.
  8726. * @wcqe: Pointer to a completion queue entry.
  8727. *
  8728. * This routine process a slow-path work-queue or recieve queue completion queue
  8729. * entry.
  8730. *
  8731. * Return: true if work posted to worker thread, otherwise false.
  8732. **/
  8733. static bool
  8734. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8735. struct lpfc_cqe *cqe)
  8736. {
  8737. struct lpfc_cqe cqevt;
  8738. bool workposted = false;
  8739. /* Copy the work queue CQE and convert endian order if needed */
  8740. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8741. /* Check and process for different type of WCQE and dispatch */
  8742. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8743. case CQE_CODE_COMPL_WQE:
  8744. /* Process the WQ/RQ complete event */
  8745. phba->last_completion_time = jiffies;
  8746. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8747. (struct lpfc_wcqe_complete *)&cqevt);
  8748. break;
  8749. case CQE_CODE_RELEASE_WQE:
  8750. /* Process the WQ release event */
  8751. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8752. (struct lpfc_wcqe_release *)&cqevt);
  8753. break;
  8754. case CQE_CODE_XRI_ABORTED:
  8755. /* Process the WQ XRI abort event */
  8756. phba->last_completion_time = jiffies;
  8757. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8758. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8759. break;
  8760. case CQE_CODE_RECEIVE:
  8761. /* Process the RQ event */
  8762. phba->last_completion_time = jiffies;
  8763. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8764. (struct lpfc_rcqe *)&cqevt);
  8765. break;
  8766. default:
  8767. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8768. "0388 Not a valid WCQE code: x%x\n",
  8769. bf_get(lpfc_cqe_code, &cqevt));
  8770. break;
  8771. }
  8772. return workposted;
  8773. }
  8774. /**
  8775. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8776. * @phba: Pointer to HBA context object.
  8777. * @eqe: Pointer to fast-path event queue entry.
  8778. *
  8779. * This routine process a event queue entry from the slow-path event queue.
  8780. * It will check the MajorCode and MinorCode to determine this is for a
  8781. * completion event on a completion queue, if not, an error shall be logged
  8782. * and just return. Otherwise, it will get to the corresponding completion
  8783. * queue and process all the entries on that completion queue, rearm the
  8784. * completion queue, and then return.
  8785. *
  8786. **/
  8787. static void
  8788. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8789. {
  8790. struct lpfc_queue *cq = NULL, *childq, *speq;
  8791. struct lpfc_cqe *cqe;
  8792. bool workposted = false;
  8793. int ecount = 0;
  8794. uint16_t cqid;
  8795. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8796. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8797. "0359 Not a valid slow-path completion "
  8798. "event: majorcode=x%x, minorcode=x%x\n",
  8799. bf_get_le32(lpfc_eqe_major_code, eqe),
  8800. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8801. return;
  8802. }
  8803. /* Get the reference to the corresponding CQ */
  8804. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8805. /* Search for completion queue pointer matching this cqid */
  8806. speq = phba->sli4_hba.sp_eq;
  8807. list_for_each_entry(childq, &speq->child_list, list) {
  8808. if (childq->queue_id == cqid) {
  8809. cq = childq;
  8810. break;
  8811. }
  8812. }
  8813. if (unlikely(!cq)) {
  8814. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8815. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8816. "0365 Slow-path CQ identifier "
  8817. "(%d) does not exist\n", cqid);
  8818. return;
  8819. }
  8820. /* Process all the entries to the CQ */
  8821. switch (cq->type) {
  8822. case LPFC_MCQ:
  8823. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8824. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8825. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8826. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8827. }
  8828. break;
  8829. case LPFC_WCQ:
  8830. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8831. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8832. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8833. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8834. }
  8835. break;
  8836. default:
  8837. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8838. "0370 Invalid completion queue type (%d)\n",
  8839. cq->type);
  8840. return;
  8841. }
  8842. /* Catch the no cq entry condition, log an error */
  8843. if (unlikely(ecount == 0))
  8844. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8845. "0371 No entry from the CQ: identifier "
  8846. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8847. /* In any case, flash and re-arm the RCQ */
  8848. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8849. /* wake up worker thread if there are works to be done */
  8850. if (workposted)
  8851. lpfc_worker_wake_up(phba);
  8852. }
  8853. /**
  8854. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8855. * @eqe: Pointer to fast-path completion queue entry.
  8856. *
  8857. * This routine process a fast-path work queue completion entry from fast-path
  8858. * event queue for FCP command response completion.
  8859. **/
  8860. static void
  8861. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8862. struct lpfc_wcqe_complete *wcqe)
  8863. {
  8864. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8865. struct lpfc_iocbq *cmdiocbq;
  8866. struct lpfc_iocbq irspiocbq;
  8867. unsigned long iflags;
  8868. spin_lock_irqsave(&phba->hbalock, iflags);
  8869. pring->stats.iocb_event++;
  8870. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8871. /* Check for response status */
  8872. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8873. /* If resource errors reported from HBA, reduce queue
  8874. * depth of the SCSI device.
  8875. */
  8876. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8877. IOSTAT_LOCAL_REJECT) &&
  8878. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8879. phba->lpfc_rampdown_queue_depth(phba);
  8880. }
  8881. /* Log the error status */
  8882. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8883. "0373 FCP complete error: status=x%x, "
  8884. "hw_status=x%x, total_data_specified=%d, "
  8885. "parameter=x%x, word3=x%x\n",
  8886. bf_get(lpfc_wcqe_c_status, wcqe),
  8887. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8888. wcqe->total_data_placed, wcqe->parameter,
  8889. wcqe->word3);
  8890. }
  8891. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8892. spin_lock_irqsave(&phba->hbalock, iflags);
  8893. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8894. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8895. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8896. if (unlikely(!cmdiocbq)) {
  8897. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8898. "0374 FCP complete with no corresponding "
  8899. "cmdiocb: iotag (%d)\n",
  8900. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8901. return;
  8902. }
  8903. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8904. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8905. "0375 FCP cmdiocb not callback function "
  8906. "iotag: (%d)\n",
  8907. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8908. return;
  8909. }
  8910. /* Fake the irspiocb and copy necessary response information */
  8911. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8912. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8913. spin_lock_irqsave(&phba->hbalock, iflags);
  8914. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8915. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8916. }
  8917. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8918. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8919. }
  8920. /**
  8921. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8922. * @phba: Pointer to HBA context object.
  8923. * @cq: Pointer to completion queue.
  8924. * @wcqe: Pointer to work-queue completion queue entry.
  8925. *
  8926. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8927. * proper WQ release routine to the slow-path WQ.
  8928. **/
  8929. static void
  8930. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8931. struct lpfc_wcqe_release *wcqe)
  8932. {
  8933. struct lpfc_queue *childwq;
  8934. bool wqid_matched = false;
  8935. uint16_t fcp_wqid;
  8936. /* Check for fast-path FCP work queue release */
  8937. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8938. list_for_each_entry(childwq, &cq->child_list, list) {
  8939. if (childwq->queue_id == fcp_wqid) {
  8940. lpfc_sli4_wq_release(childwq,
  8941. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8942. wqid_matched = true;
  8943. break;
  8944. }
  8945. }
  8946. /* Report warning log message if no match found */
  8947. if (wqid_matched != true)
  8948. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8949. "2580 Fast-path wqe consume event carries "
  8950. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8951. }
  8952. /**
  8953. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8954. * @cq: Pointer to the completion queue.
  8955. * @eqe: Pointer to fast-path completion queue entry.
  8956. *
  8957. * This routine process a fast-path work queue completion entry from fast-path
  8958. * event queue for FCP command response completion.
  8959. **/
  8960. static int
  8961. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8962. struct lpfc_cqe *cqe)
  8963. {
  8964. struct lpfc_wcqe_release wcqe;
  8965. bool workposted = false;
  8966. /* Copy the work queue CQE and convert endian order if needed */
  8967. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8968. /* Check and process for different type of WCQE and dispatch */
  8969. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8970. case CQE_CODE_COMPL_WQE:
  8971. /* Process the WQ complete event */
  8972. phba->last_completion_time = jiffies;
  8973. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8974. (struct lpfc_wcqe_complete *)&wcqe);
  8975. break;
  8976. case CQE_CODE_RELEASE_WQE:
  8977. /* Process the WQ release event */
  8978. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8979. (struct lpfc_wcqe_release *)&wcqe);
  8980. break;
  8981. case CQE_CODE_XRI_ABORTED:
  8982. /* Process the WQ XRI abort event */
  8983. phba->last_completion_time = jiffies;
  8984. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8985. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8986. break;
  8987. default:
  8988. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8989. "0144 Not a valid WCQE code: x%x\n",
  8990. bf_get(lpfc_wcqe_c_code, &wcqe));
  8991. break;
  8992. }
  8993. return workposted;
  8994. }
  8995. /**
  8996. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8997. * @phba: Pointer to HBA context object.
  8998. * @eqe: Pointer to fast-path event queue entry.
  8999. *
  9000. * This routine process a event queue entry from the fast-path event queue.
  9001. * It will check the MajorCode and MinorCode to determine this is for a
  9002. * completion event on a completion queue, if not, an error shall be logged
  9003. * and just return. Otherwise, it will get to the corresponding completion
  9004. * queue and process all the entries on the completion queue, rearm the
  9005. * completion queue, and then return.
  9006. **/
  9007. static void
  9008. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  9009. uint32_t fcp_cqidx)
  9010. {
  9011. struct lpfc_queue *cq;
  9012. struct lpfc_cqe *cqe;
  9013. bool workposted = false;
  9014. uint16_t cqid;
  9015. int ecount = 0;
  9016. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  9017. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9018. "0366 Not a valid fast-path completion "
  9019. "event: majorcode=x%x, minorcode=x%x\n",
  9020. bf_get_le32(lpfc_eqe_major_code, eqe),
  9021. bf_get_le32(lpfc_eqe_minor_code, eqe));
  9022. return;
  9023. }
  9024. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  9025. if (unlikely(!cq)) {
  9026. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  9027. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9028. "0367 Fast-path completion queue "
  9029. "does not exist\n");
  9030. return;
  9031. }
  9032. /* Get the reference to the corresponding CQ */
  9033. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9034. if (unlikely(cqid != cq->queue_id)) {
  9035. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9036. "0368 Miss-matched fast-path completion "
  9037. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9038. cqid, cq->queue_id);
  9039. return;
  9040. }
  9041. /* Process all the entries to the CQ */
  9042. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9043. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9044. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9045. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9046. }
  9047. /* Catch the no cq entry condition */
  9048. if (unlikely(ecount == 0))
  9049. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9050. "0369 No entry from fast-path completion "
  9051. "queue fcpcqid=%d\n", cq->queue_id);
  9052. /* In any case, flash and re-arm the CQ */
  9053. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9054. /* wake up worker thread if there are works to be done */
  9055. if (workposted)
  9056. lpfc_worker_wake_up(phba);
  9057. }
  9058. static void
  9059. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9060. {
  9061. struct lpfc_eqe *eqe;
  9062. /* walk all the EQ entries and drop on the floor */
  9063. while ((eqe = lpfc_sli4_eq_get(eq)))
  9064. ;
  9065. /* Clear and re-arm the EQ */
  9066. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9067. }
  9068. /**
  9069. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9070. * @irq: Interrupt number.
  9071. * @dev_id: The device context pointer.
  9072. *
  9073. * This function is directly called from the PCI layer as an interrupt
  9074. * service routine when device with SLI-4 interface spec is enabled with
  9075. * MSI-X multi-message interrupt mode and there are slow-path events in
  9076. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9077. * interrupt mode, this function is called as part of the device-level
  9078. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9079. * undergoing initialization, the interrupt handler will not process the
  9080. * interrupt. The link attention and ELS ring attention events are handled
  9081. * by the worker thread. The interrupt handler signals the worker thread
  9082. * and returns for these events. This function is called without any lock
  9083. * held. It gets the hbalock to access and update SLI data structures.
  9084. *
  9085. * This function returns IRQ_HANDLED when interrupt is handled else it
  9086. * returns IRQ_NONE.
  9087. **/
  9088. irqreturn_t
  9089. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  9090. {
  9091. struct lpfc_hba *phba;
  9092. struct lpfc_queue *speq;
  9093. struct lpfc_eqe *eqe;
  9094. unsigned long iflag;
  9095. int ecount = 0;
  9096. /*
  9097. * Get the driver's phba structure from the dev_id
  9098. */
  9099. phba = (struct lpfc_hba *)dev_id;
  9100. if (unlikely(!phba))
  9101. return IRQ_NONE;
  9102. /* Get to the EQ struct associated with this vector */
  9103. speq = phba->sli4_hba.sp_eq;
  9104. /* Check device state for handling interrupt */
  9105. if (unlikely(lpfc_intr_state_check(phba))) {
  9106. /* Check again for link_state with lock held */
  9107. spin_lock_irqsave(&phba->hbalock, iflag);
  9108. if (phba->link_state < LPFC_LINK_DOWN)
  9109. /* Flush, clear interrupt, and rearm the EQ */
  9110. lpfc_sli4_eq_flush(phba, speq);
  9111. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9112. return IRQ_NONE;
  9113. }
  9114. /*
  9115. * Process all the event on FCP slow-path EQ
  9116. */
  9117. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9118. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9119. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9120. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9121. }
  9122. /* Always clear and re-arm the slow-path EQ */
  9123. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9124. /* Catch the no cq entry condition */
  9125. if (unlikely(ecount == 0)) {
  9126. if (phba->intr_type == MSIX)
  9127. /* MSI-X treated interrupt served as no EQ share INT */
  9128. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9129. "0357 MSI-X interrupt with no EQE\n");
  9130. else
  9131. /* Non MSI-X treated on interrupt as EQ share INT */
  9132. return IRQ_NONE;
  9133. }
  9134. return IRQ_HANDLED;
  9135. } /* lpfc_sli4_sp_intr_handler */
  9136. /**
  9137. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9138. * @irq: Interrupt number.
  9139. * @dev_id: The device context pointer.
  9140. *
  9141. * This function is directly called from the PCI layer as an interrupt
  9142. * service routine when device with SLI-4 interface spec is enabled with
  9143. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9144. * ring event in the HBA. However, when the device is enabled with either
  9145. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9146. * device-level interrupt handler. When the PCI slot is in error recovery
  9147. * or the HBA is undergoing initialization, the interrupt handler will not
  9148. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9149. * the intrrupt context. This function is called without any lock held.
  9150. * It gets the hbalock to access and update SLI data structures. Note that,
  9151. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9152. * equal to that of FCP CQ index.
  9153. *
  9154. * This function returns IRQ_HANDLED when interrupt is handled else it
  9155. * returns IRQ_NONE.
  9156. **/
  9157. irqreturn_t
  9158. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9159. {
  9160. struct lpfc_hba *phba;
  9161. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9162. struct lpfc_queue *fpeq;
  9163. struct lpfc_eqe *eqe;
  9164. unsigned long iflag;
  9165. int ecount = 0;
  9166. uint32_t fcp_eqidx;
  9167. /* Get the driver's phba structure from the dev_id */
  9168. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9169. phba = fcp_eq_hdl->phba;
  9170. fcp_eqidx = fcp_eq_hdl->idx;
  9171. if (unlikely(!phba))
  9172. return IRQ_NONE;
  9173. /* Get to the EQ struct associated with this vector */
  9174. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9175. /* Check device state for handling interrupt */
  9176. if (unlikely(lpfc_intr_state_check(phba))) {
  9177. /* Check again for link_state with lock held */
  9178. spin_lock_irqsave(&phba->hbalock, iflag);
  9179. if (phba->link_state < LPFC_LINK_DOWN)
  9180. /* Flush, clear interrupt, and rearm the EQ */
  9181. lpfc_sli4_eq_flush(phba, fpeq);
  9182. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9183. return IRQ_NONE;
  9184. }
  9185. /*
  9186. * Process all the event on FCP fast-path EQ
  9187. */
  9188. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9189. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9190. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9191. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9192. }
  9193. /* Always clear and re-arm the fast-path EQ */
  9194. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9195. if (unlikely(ecount == 0)) {
  9196. if (phba->intr_type == MSIX)
  9197. /* MSI-X treated interrupt served as no EQ share INT */
  9198. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9199. "0358 MSI-X interrupt with no EQE\n");
  9200. else
  9201. /* Non MSI-X treated on interrupt as EQ share INT */
  9202. return IRQ_NONE;
  9203. }
  9204. return IRQ_HANDLED;
  9205. } /* lpfc_sli4_fp_intr_handler */
  9206. /**
  9207. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9208. * @irq: Interrupt number.
  9209. * @dev_id: The device context pointer.
  9210. *
  9211. * This function is the device-level interrupt handler to device with SLI-4
  9212. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9213. * interrupt mode is enabled and there is an event in the HBA which requires
  9214. * driver attention. This function invokes the slow-path interrupt attention
  9215. * handling function and fast-path interrupt attention handling function in
  9216. * turn to process the relevant HBA attention events. This function is called
  9217. * without any lock held. It gets the hbalock to access and update SLI data
  9218. * structures.
  9219. *
  9220. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9221. * returns IRQ_NONE.
  9222. **/
  9223. irqreturn_t
  9224. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9225. {
  9226. struct lpfc_hba *phba;
  9227. irqreturn_t sp_irq_rc, fp_irq_rc;
  9228. bool fp_handled = false;
  9229. uint32_t fcp_eqidx;
  9230. /* Get the driver's phba structure from the dev_id */
  9231. phba = (struct lpfc_hba *)dev_id;
  9232. if (unlikely(!phba))
  9233. return IRQ_NONE;
  9234. /*
  9235. * Invokes slow-path host attention interrupt handling as appropriate.
  9236. */
  9237. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9238. /*
  9239. * Invoke fast-path host attention interrupt handling as appropriate.
  9240. */
  9241. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9242. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9243. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9244. if (fp_irq_rc == IRQ_HANDLED)
  9245. fp_handled |= true;
  9246. }
  9247. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9248. } /* lpfc_sli4_intr_handler */
  9249. /**
  9250. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9251. * @queue: The queue structure to free.
  9252. *
  9253. * This function frees a queue structure and the DMAable memory used for
  9254. * the host resident queue. This function must be called after destroying the
  9255. * queue on the HBA.
  9256. **/
  9257. void
  9258. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9259. {
  9260. struct lpfc_dmabuf *dmabuf;
  9261. if (!queue)
  9262. return;
  9263. while (!list_empty(&queue->page_list)) {
  9264. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9265. list);
  9266. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9267. dmabuf->virt, dmabuf->phys);
  9268. kfree(dmabuf);
  9269. }
  9270. kfree(queue);
  9271. return;
  9272. }
  9273. /**
  9274. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9275. * @phba: The HBA that this queue is being created on.
  9276. * @entry_size: The size of each queue entry for this queue.
  9277. * @entry count: The number of entries that this queue will handle.
  9278. *
  9279. * This function allocates a queue structure and the DMAable memory used for
  9280. * the host resident queue. This function must be called before creating the
  9281. * queue on the HBA.
  9282. **/
  9283. struct lpfc_queue *
  9284. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9285. uint32_t entry_count)
  9286. {
  9287. struct lpfc_queue *queue;
  9288. struct lpfc_dmabuf *dmabuf;
  9289. int x, total_qe_count;
  9290. void *dma_pointer;
  9291. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9292. if (!phba->sli4_hba.pc_sli4_params.supported)
  9293. hw_page_size = SLI4_PAGE_SIZE;
  9294. queue = kzalloc(sizeof(struct lpfc_queue) +
  9295. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9296. if (!queue)
  9297. return NULL;
  9298. queue->page_count = (ALIGN(entry_size * entry_count,
  9299. hw_page_size))/hw_page_size;
  9300. INIT_LIST_HEAD(&queue->list);
  9301. INIT_LIST_HEAD(&queue->page_list);
  9302. INIT_LIST_HEAD(&queue->child_list);
  9303. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9304. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9305. if (!dmabuf)
  9306. goto out_fail;
  9307. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9308. hw_page_size, &dmabuf->phys,
  9309. GFP_KERNEL);
  9310. if (!dmabuf->virt) {
  9311. kfree(dmabuf);
  9312. goto out_fail;
  9313. }
  9314. memset(dmabuf->virt, 0, hw_page_size);
  9315. dmabuf->buffer_tag = x;
  9316. list_add_tail(&dmabuf->list, &queue->page_list);
  9317. /* initialize queue's entry array */
  9318. dma_pointer = dmabuf->virt;
  9319. for (; total_qe_count < entry_count &&
  9320. dma_pointer < (hw_page_size + dmabuf->virt);
  9321. total_qe_count++, dma_pointer += entry_size) {
  9322. queue->qe[total_qe_count].address = dma_pointer;
  9323. }
  9324. }
  9325. queue->entry_size = entry_size;
  9326. queue->entry_count = entry_count;
  9327. queue->phba = phba;
  9328. return queue;
  9329. out_fail:
  9330. lpfc_sli4_queue_free(queue);
  9331. return NULL;
  9332. }
  9333. /**
  9334. * lpfc_eq_create - Create an Event Queue on the HBA
  9335. * @phba: HBA structure that indicates port to create a queue on.
  9336. * @eq: The queue structure to use to create the event queue.
  9337. * @imax: The maximum interrupt per second limit.
  9338. *
  9339. * This function creates an event queue, as detailed in @eq, on a port,
  9340. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9341. *
  9342. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9343. * is used to get the entry count and entry size that are necessary to
  9344. * determine the number of pages to allocate and use for this queue. This
  9345. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9346. * event queue. This function is asynchronous and will wait for the mailbox
  9347. * command to finish before continuing.
  9348. *
  9349. * On success this function will return a zero. If unable to allocate enough
  9350. * memory this function will return -ENOMEM. If the queue create mailbox command
  9351. * fails this function will return -ENXIO.
  9352. **/
  9353. uint32_t
  9354. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9355. {
  9356. struct lpfc_mbx_eq_create *eq_create;
  9357. LPFC_MBOXQ_t *mbox;
  9358. int rc, length, status = 0;
  9359. struct lpfc_dmabuf *dmabuf;
  9360. uint32_t shdr_status, shdr_add_status;
  9361. union lpfc_sli4_cfg_shdr *shdr;
  9362. uint16_t dmult;
  9363. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9364. if (!phba->sli4_hba.pc_sli4_params.supported)
  9365. hw_page_size = SLI4_PAGE_SIZE;
  9366. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9367. if (!mbox)
  9368. return -ENOMEM;
  9369. length = (sizeof(struct lpfc_mbx_eq_create) -
  9370. sizeof(struct lpfc_sli4_cfg_mhdr));
  9371. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9372. LPFC_MBOX_OPCODE_EQ_CREATE,
  9373. length, LPFC_SLI4_MBX_EMBED);
  9374. eq_create = &mbox->u.mqe.un.eq_create;
  9375. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9376. eq->page_count);
  9377. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9378. LPFC_EQE_SIZE);
  9379. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9380. /* Calculate delay multiper from maximum interrupt per second */
  9381. dmult = LPFC_DMULT_CONST/imax - 1;
  9382. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9383. dmult);
  9384. switch (eq->entry_count) {
  9385. default:
  9386. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9387. "0360 Unsupported EQ count. (%d)\n",
  9388. eq->entry_count);
  9389. if (eq->entry_count < 256)
  9390. return -EINVAL;
  9391. /* otherwise default to smallest count (drop through) */
  9392. case 256:
  9393. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9394. LPFC_EQ_CNT_256);
  9395. break;
  9396. case 512:
  9397. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9398. LPFC_EQ_CNT_512);
  9399. break;
  9400. case 1024:
  9401. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9402. LPFC_EQ_CNT_1024);
  9403. break;
  9404. case 2048:
  9405. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9406. LPFC_EQ_CNT_2048);
  9407. break;
  9408. case 4096:
  9409. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9410. LPFC_EQ_CNT_4096);
  9411. break;
  9412. }
  9413. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9414. memset(dmabuf->virt, 0, hw_page_size);
  9415. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9416. putPaddrLow(dmabuf->phys);
  9417. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9418. putPaddrHigh(dmabuf->phys);
  9419. }
  9420. mbox->vport = phba->pport;
  9421. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9422. mbox->context1 = NULL;
  9423. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9424. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9425. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9426. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9427. if (shdr_status || shdr_add_status || rc) {
  9428. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9429. "2500 EQ_CREATE mailbox failed with "
  9430. "status x%x add_status x%x, mbx status x%x\n",
  9431. shdr_status, shdr_add_status, rc);
  9432. status = -ENXIO;
  9433. }
  9434. eq->type = LPFC_EQ;
  9435. eq->subtype = LPFC_NONE;
  9436. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9437. if (eq->queue_id == 0xFFFF)
  9438. status = -ENXIO;
  9439. eq->host_index = 0;
  9440. eq->hba_index = 0;
  9441. mempool_free(mbox, phba->mbox_mem_pool);
  9442. return status;
  9443. }
  9444. /**
  9445. * lpfc_cq_create - Create a Completion Queue on the HBA
  9446. * @phba: HBA structure that indicates port to create a queue on.
  9447. * @cq: The queue structure to use to create the completion queue.
  9448. * @eq: The event queue to bind this completion queue to.
  9449. *
  9450. * This function creates a completion queue, as detailed in @wq, on a port,
  9451. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9452. *
  9453. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9454. * is used to get the entry count and entry size that are necessary to
  9455. * determine the number of pages to allocate and use for this queue. The @eq
  9456. * is used to indicate which event queue to bind this completion queue to. This
  9457. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9458. * completion queue. This function is asynchronous and will wait for the mailbox
  9459. * command to finish before continuing.
  9460. *
  9461. * On success this function will return a zero. If unable to allocate enough
  9462. * memory this function will return -ENOMEM. If the queue create mailbox command
  9463. * fails this function will return -ENXIO.
  9464. **/
  9465. uint32_t
  9466. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9467. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9468. {
  9469. struct lpfc_mbx_cq_create *cq_create;
  9470. struct lpfc_dmabuf *dmabuf;
  9471. LPFC_MBOXQ_t *mbox;
  9472. int rc, length, status = 0;
  9473. uint32_t shdr_status, shdr_add_status;
  9474. union lpfc_sli4_cfg_shdr *shdr;
  9475. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9476. if (!phba->sli4_hba.pc_sli4_params.supported)
  9477. hw_page_size = SLI4_PAGE_SIZE;
  9478. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9479. if (!mbox)
  9480. return -ENOMEM;
  9481. length = (sizeof(struct lpfc_mbx_cq_create) -
  9482. sizeof(struct lpfc_sli4_cfg_mhdr));
  9483. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9484. LPFC_MBOX_OPCODE_CQ_CREATE,
  9485. length, LPFC_SLI4_MBX_EMBED);
  9486. cq_create = &mbox->u.mqe.un.cq_create;
  9487. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9488. cq->page_count);
  9489. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9490. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9491. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  9492. switch (cq->entry_count) {
  9493. default:
  9494. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9495. "0361 Unsupported CQ count. (%d)\n",
  9496. cq->entry_count);
  9497. if (cq->entry_count < 256)
  9498. return -EINVAL;
  9499. /* otherwise default to smallest count (drop through) */
  9500. case 256:
  9501. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9502. LPFC_CQ_CNT_256);
  9503. break;
  9504. case 512:
  9505. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9506. LPFC_CQ_CNT_512);
  9507. break;
  9508. case 1024:
  9509. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9510. LPFC_CQ_CNT_1024);
  9511. break;
  9512. }
  9513. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9514. memset(dmabuf->virt, 0, hw_page_size);
  9515. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9516. putPaddrLow(dmabuf->phys);
  9517. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9518. putPaddrHigh(dmabuf->phys);
  9519. }
  9520. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9521. /* The IOCTL status is embedded in the mailbox subheader. */
  9522. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9523. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9524. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9525. if (shdr_status || shdr_add_status || rc) {
  9526. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9527. "2501 CQ_CREATE mailbox failed with "
  9528. "status x%x add_status x%x, mbx status x%x\n",
  9529. shdr_status, shdr_add_status, rc);
  9530. status = -ENXIO;
  9531. goto out;
  9532. }
  9533. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9534. if (cq->queue_id == 0xFFFF) {
  9535. status = -ENXIO;
  9536. goto out;
  9537. }
  9538. /* link the cq onto the parent eq child list */
  9539. list_add_tail(&cq->list, &eq->child_list);
  9540. /* Set up completion queue's type and subtype */
  9541. cq->type = type;
  9542. cq->subtype = subtype;
  9543. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9544. cq->host_index = 0;
  9545. cq->hba_index = 0;
  9546. out:
  9547. mempool_free(mbox, phba->mbox_mem_pool);
  9548. return status;
  9549. }
  9550. /**
  9551. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9552. * @phba: HBA structure that indicates port to create a queue on.
  9553. * @mq: The queue structure to use to create the mailbox queue.
  9554. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9555. * @cq: The completion queue to associate with this cq.
  9556. *
  9557. * This function provides failback (fb) functionality when the
  9558. * mq_create_ext fails on older FW generations. It's purpose is identical
  9559. * to mq_create_ext otherwise.
  9560. *
  9561. * This routine cannot fail as all attributes were previously accessed and
  9562. * initialized in mq_create_ext.
  9563. **/
  9564. static void
  9565. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9566. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9567. {
  9568. struct lpfc_mbx_mq_create *mq_create;
  9569. struct lpfc_dmabuf *dmabuf;
  9570. int length;
  9571. length = (sizeof(struct lpfc_mbx_mq_create) -
  9572. sizeof(struct lpfc_sli4_cfg_mhdr));
  9573. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9574. LPFC_MBOX_OPCODE_MQ_CREATE,
  9575. length, LPFC_SLI4_MBX_EMBED);
  9576. mq_create = &mbox->u.mqe.un.mq_create;
  9577. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9578. mq->page_count);
  9579. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9580. cq->queue_id);
  9581. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9582. switch (mq->entry_count) {
  9583. case 16:
  9584. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9585. LPFC_MQ_CNT_16);
  9586. break;
  9587. case 32:
  9588. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9589. LPFC_MQ_CNT_32);
  9590. break;
  9591. case 64:
  9592. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9593. LPFC_MQ_CNT_64);
  9594. break;
  9595. case 128:
  9596. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9597. LPFC_MQ_CNT_128);
  9598. break;
  9599. }
  9600. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9601. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9602. putPaddrLow(dmabuf->phys);
  9603. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9604. putPaddrHigh(dmabuf->phys);
  9605. }
  9606. }
  9607. /**
  9608. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9609. * @phba: HBA structure that indicates port to create a queue on.
  9610. * @mq: The queue structure to use to create the mailbox queue.
  9611. * @cq: The completion queue to associate with this cq.
  9612. * @subtype: The queue's subtype.
  9613. *
  9614. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9615. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9616. *
  9617. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9618. * is used to get the entry count and entry size that are necessary to
  9619. * determine the number of pages to allocate and use for this queue. This
  9620. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9621. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9622. * command to finish before continuing.
  9623. *
  9624. * On success this function will return a zero. If unable to allocate enough
  9625. * memory this function will return -ENOMEM. If the queue create mailbox command
  9626. * fails this function will return -ENXIO.
  9627. **/
  9628. int32_t
  9629. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9630. struct lpfc_queue *cq, uint32_t subtype)
  9631. {
  9632. struct lpfc_mbx_mq_create *mq_create;
  9633. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9634. struct lpfc_dmabuf *dmabuf;
  9635. LPFC_MBOXQ_t *mbox;
  9636. int rc, length, status = 0;
  9637. uint32_t shdr_status, shdr_add_status;
  9638. union lpfc_sli4_cfg_shdr *shdr;
  9639. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9640. if (!phba->sli4_hba.pc_sli4_params.supported)
  9641. hw_page_size = SLI4_PAGE_SIZE;
  9642. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9643. if (!mbox)
  9644. return -ENOMEM;
  9645. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9646. sizeof(struct lpfc_sli4_cfg_mhdr));
  9647. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9648. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9649. length, LPFC_SLI4_MBX_EMBED);
  9650. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9651. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  9652. &mq_create_ext->u.request, mq->page_count);
  9653. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  9654. &mq_create_ext->u.request, 1);
  9655. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  9656. &mq_create_ext->u.request, 1);
  9657. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9658. &mq_create_ext->u.request, 1);
  9659. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  9660. &mq_create_ext->u.request, 1);
  9661. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  9662. &mq_create_ext->u.request, 1);
  9663. bf_set(lpfc_mq_context_cq_id,
  9664. &mq_create_ext->u.request.context, cq->queue_id);
  9665. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9666. switch (mq->entry_count) {
  9667. default:
  9668. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9669. "0362 Unsupported MQ count. (%d)\n",
  9670. mq->entry_count);
  9671. if (mq->entry_count < 16)
  9672. return -EINVAL;
  9673. /* otherwise default to smallest count (drop through) */
  9674. case 16:
  9675. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9676. LPFC_MQ_CNT_16);
  9677. break;
  9678. case 32:
  9679. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9680. LPFC_MQ_CNT_32);
  9681. break;
  9682. case 64:
  9683. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9684. LPFC_MQ_CNT_64);
  9685. break;
  9686. case 128:
  9687. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9688. LPFC_MQ_CNT_128);
  9689. break;
  9690. }
  9691. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9692. memset(dmabuf->virt, 0, hw_page_size);
  9693. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9694. putPaddrLow(dmabuf->phys);
  9695. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9696. putPaddrHigh(dmabuf->phys);
  9697. }
  9698. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9699. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9700. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9701. &mq_create_ext->u.response);
  9702. if (rc != MBX_SUCCESS) {
  9703. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9704. "2795 MQ_CREATE_EXT failed with "
  9705. "status x%x. Failback to MQ_CREATE.\n",
  9706. rc);
  9707. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9708. mq_create = &mbox->u.mqe.un.mq_create;
  9709. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9710. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9711. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9712. &mq_create->u.response);
  9713. }
  9714. /* The IOCTL status is embedded in the mailbox subheader. */
  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 (shdr_status || shdr_add_status || rc) {
  9718. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9719. "2502 MQ_CREATE mailbox failed with "
  9720. "status x%x add_status x%x, mbx status x%x\n",
  9721. shdr_status, shdr_add_status, rc);
  9722. status = -ENXIO;
  9723. goto out;
  9724. }
  9725. if (mq->queue_id == 0xFFFF) {
  9726. status = -ENXIO;
  9727. goto out;
  9728. }
  9729. mq->type = LPFC_MQ;
  9730. mq->subtype = subtype;
  9731. mq->host_index = 0;
  9732. mq->hba_index = 0;
  9733. /* link the mq onto the parent cq child list */
  9734. list_add_tail(&mq->list, &cq->child_list);
  9735. out:
  9736. mempool_free(mbox, phba->mbox_mem_pool);
  9737. return status;
  9738. }
  9739. /**
  9740. * lpfc_wq_create - Create a Work Queue on the HBA
  9741. * @phba: HBA structure that indicates port to create a queue on.
  9742. * @wq: The queue structure to use to create the work queue.
  9743. * @cq: The completion queue to bind this work queue to.
  9744. * @subtype: The subtype of the work queue indicating its functionality.
  9745. *
  9746. * This function creates a work queue, as detailed in @wq, on a port, described
  9747. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9748. *
  9749. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9750. * is used to get the entry count and entry size that are necessary to
  9751. * determine the number of pages to allocate and use for this queue. The @cq
  9752. * is used to indicate which completion queue to bind this work queue to. This
  9753. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9754. * work queue. This function is asynchronous and will wait for the mailbox
  9755. * command to finish before continuing.
  9756. *
  9757. * On success this function will return a zero. If unable to allocate enough
  9758. * memory this function will return -ENOMEM. If the queue create mailbox command
  9759. * fails this function will return -ENXIO.
  9760. **/
  9761. uint32_t
  9762. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9763. struct lpfc_queue *cq, uint32_t subtype)
  9764. {
  9765. struct lpfc_mbx_wq_create *wq_create;
  9766. struct lpfc_dmabuf *dmabuf;
  9767. LPFC_MBOXQ_t *mbox;
  9768. int rc, length, status = 0;
  9769. uint32_t shdr_status, shdr_add_status;
  9770. union lpfc_sli4_cfg_shdr *shdr;
  9771. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9772. if (!phba->sli4_hba.pc_sli4_params.supported)
  9773. hw_page_size = SLI4_PAGE_SIZE;
  9774. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9775. if (!mbox)
  9776. return -ENOMEM;
  9777. length = (sizeof(struct lpfc_mbx_wq_create) -
  9778. sizeof(struct lpfc_sli4_cfg_mhdr));
  9779. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9780. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9781. length, LPFC_SLI4_MBX_EMBED);
  9782. wq_create = &mbox->u.mqe.un.wq_create;
  9783. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9784. wq->page_count);
  9785. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9786. cq->queue_id);
  9787. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9788. memset(dmabuf->virt, 0, hw_page_size);
  9789. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9790. putPaddrLow(dmabuf->phys);
  9791. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9792. putPaddrHigh(dmabuf->phys);
  9793. }
  9794. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9795. /* The IOCTL status is embedded in the mailbox subheader. */
  9796. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9797. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9798. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9799. if (shdr_status || shdr_add_status || rc) {
  9800. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9801. "2503 WQ_CREATE mailbox failed with "
  9802. "status x%x add_status x%x, mbx status x%x\n",
  9803. shdr_status, shdr_add_status, rc);
  9804. status = -ENXIO;
  9805. goto out;
  9806. }
  9807. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9808. if (wq->queue_id == 0xFFFF) {
  9809. status = -ENXIO;
  9810. goto out;
  9811. }
  9812. wq->type = LPFC_WQ;
  9813. wq->subtype = subtype;
  9814. wq->host_index = 0;
  9815. wq->hba_index = 0;
  9816. /* link the wq onto the parent cq child list */
  9817. list_add_tail(&wq->list, &cq->child_list);
  9818. out:
  9819. mempool_free(mbox, phba->mbox_mem_pool);
  9820. return status;
  9821. }
  9822. /**
  9823. * lpfc_rq_create - Create a Receive Queue on the HBA
  9824. * @phba: HBA structure that indicates port to create a queue on.
  9825. * @hrq: The queue structure to use to create the header receive queue.
  9826. * @drq: The queue structure to use to create the data receive queue.
  9827. * @cq: The completion queue to bind this work queue to.
  9828. *
  9829. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9830. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9831. * to the HBA.
  9832. *
  9833. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9834. * struct is used to get the entry count that is necessary to determine the
  9835. * number of pages to use for this queue. The @cq is used to indicate which
  9836. * completion queue to bind received buffers that are posted to these queues to.
  9837. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9838. * receive queue pair. This function is asynchronous and will wait for the
  9839. * mailbox command to finish before continuing.
  9840. *
  9841. * On success this function will return a zero. If unable to allocate enough
  9842. * memory this function will return -ENOMEM. If the queue create mailbox command
  9843. * fails this function will return -ENXIO.
  9844. **/
  9845. uint32_t
  9846. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9847. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9848. {
  9849. struct lpfc_mbx_rq_create *rq_create;
  9850. struct lpfc_dmabuf *dmabuf;
  9851. LPFC_MBOXQ_t *mbox;
  9852. int rc, length, status = 0;
  9853. uint32_t shdr_status, shdr_add_status;
  9854. union lpfc_sli4_cfg_shdr *shdr;
  9855. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9856. if (!phba->sli4_hba.pc_sli4_params.supported)
  9857. hw_page_size = SLI4_PAGE_SIZE;
  9858. if (hrq->entry_count != drq->entry_count)
  9859. return -EINVAL;
  9860. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9861. if (!mbox)
  9862. return -ENOMEM;
  9863. length = (sizeof(struct lpfc_mbx_rq_create) -
  9864. sizeof(struct lpfc_sli4_cfg_mhdr));
  9865. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9866. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9867. length, LPFC_SLI4_MBX_EMBED);
  9868. rq_create = &mbox->u.mqe.un.rq_create;
  9869. switch (hrq->entry_count) {
  9870. default:
  9871. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9872. "2535 Unsupported RQ count. (%d)\n",
  9873. hrq->entry_count);
  9874. if (hrq->entry_count < 512)
  9875. return -EINVAL;
  9876. /* otherwise default to smallest count (drop through) */
  9877. case 512:
  9878. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9879. LPFC_RQ_RING_SIZE_512);
  9880. break;
  9881. case 1024:
  9882. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9883. LPFC_RQ_RING_SIZE_1024);
  9884. break;
  9885. case 2048:
  9886. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9887. LPFC_RQ_RING_SIZE_2048);
  9888. break;
  9889. case 4096:
  9890. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9891. LPFC_RQ_RING_SIZE_4096);
  9892. break;
  9893. }
  9894. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9895. cq->queue_id);
  9896. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9897. hrq->page_count);
  9898. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9899. LPFC_HDR_BUF_SIZE);
  9900. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9901. memset(dmabuf->virt, 0, hw_page_size);
  9902. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9903. putPaddrLow(dmabuf->phys);
  9904. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9905. putPaddrHigh(dmabuf->phys);
  9906. }
  9907. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9908. /* The IOCTL status is embedded in the mailbox subheader. */
  9909. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9910. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9911. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9912. if (shdr_status || shdr_add_status || rc) {
  9913. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9914. "2504 RQ_CREATE mailbox failed with "
  9915. "status x%x add_status x%x, mbx status x%x\n",
  9916. shdr_status, shdr_add_status, rc);
  9917. status = -ENXIO;
  9918. goto out;
  9919. }
  9920. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9921. if (hrq->queue_id == 0xFFFF) {
  9922. status = -ENXIO;
  9923. goto out;
  9924. }
  9925. hrq->type = LPFC_HRQ;
  9926. hrq->subtype = subtype;
  9927. hrq->host_index = 0;
  9928. hrq->hba_index = 0;
  9929. /* now create the data queue */
  9930. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9931. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9932. length, LPFC_SLI4_MBX_EMBED);
  9933. switch (drq->entry_count) {
  9934. default:
  9935. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9936. "2536 Unsupported RQ count. (%d)\n",
  9937. drq->entry_count);
  9938. if (drq->entry_count < 512)
  9939. return -EINVAL;
  9940. /* otherwise default to smallest count (drop through) */
  9941. case 512:
  9942. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9943. LPFC_RQ_RING_SIZE_512);
  9944. break;
  9945. case 1024:
  9946. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9947. LPFC_RQ_RING_SIZE_1024);
  9948. break;
  9949. case 2048:
  9950. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9951. LPFC_RQ_RING_SIZE_2048);
  9952. break;
  9953. case 4096:
  9954. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9955. LPFC_RQ_RING_SIZE_4096);
  9956. break;
  9957. }
  9958. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9959. cq->queue_id);
  9960. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9961. drq->page_count);
  9962. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9963. LPFC_DATA_BUF_SIZE);
  9964. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9965. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9966. putPaddrLow(dmabuf->phys);
  9967. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9968. putPaddrHigh(dmabuf->phys);
  9969. }
  9970. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9971. /* The IOCTL status is embedded in the mailbox subheader. */
  9972. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9973. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9974. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9975. if (shdr_status || shdr_add_status || rc) {
  9976. status = -ENXIO;
  9977. goto out;
  9978. }
  9979. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9980. if (drq->queue_id == 0xFFFF) {
  9981. status = -ENXIO;
  9982. goto out;
  9983. }
  9984. drq->type = LPFC_DRQ;
  9985. drq->subtype = subtype;
  9986. drq->host_index = 0;
  9987. drq->hba_index = 0;
  9988. /* link the header and data RQs onto the parent cq child list */
  9989. list_add_tail(&hrq->list, &cq->child_list);
  9990. list_add_tail(&drq->list, &cq->child_list);
  9991. out:
  9992. mempool_free(mbox, phba->mbox_mem_pool);
  9993. return status;
  9994. }
  9995. /**
  9996. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9997. * @eq: The queue structure associated with the queue to destroy.
  9998. *
  9999. * This function destroys a queue, as detailed in @eq by sending an mailbox
  10000. * command, specific to the type of queue, to the HBA.
  10001. *
  10002. * The @eq struct is used to get the queue ID of the queue to destroy.
  10003. *
  10004. * On success this function will return a zero. If the queue destroy mailbox
  10005. * command fails this function will return -ENXIO.
  10006. **/
  10007. uint32_t
  10008. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10009. {
  10010. LPFC_MBOXQ_t *mbox;
  10011. int rc, length, status = 0;
  10012. uint32_t shdr_status, shdr_add_status;
  10013. union lpfc_sli4_cfg_shdr *shdr;
  10014. if (!eq)
  10015. return -ENODEV;
  10016. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  10017. if (!mbox)
  10018. return -ENOMEM;
  10019. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  10020. sizeof(struct lpfc_sli4_cfg_mhdr));
  10021. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10022. LPFC_MBOX_OPCODE_EQ_DESTROY,
  10023. length, LPFC_SLI4_MBX_EMBED);
  10024. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  10025. eq->queue_id);
  10026. mbox->vport = eq->phba->pport;
  10027. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10028. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  10029. /* The IOCTL status is embedded in the mailbox subheader. */
  10030. shdr = (union lpfc_sli4_cfg_shdr *)
  10031. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  10032. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10033. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10034. if (shdr_status || shdr_add_status || rc) {
  10035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10036. "2505 EQ_DESTROY mailbox failed with "
  10037. "status x%x add_status x%x, mbx status x%x\n",
  10038. shdr_status, shdr_add_status, rc);
  10039. status = -ENXIO;
  10040. }
  10041. /* Remove eq from any list */
  10042. list_del_init(&eq->list);
  10043. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10044. return status;
  10045. }
  10046. /**
  10047. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10048. * @cq: The queue structure associated with the queue to destroy.
  10049. *
  10050. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10051. * command, specific to the type of queue, to the HBA.
  10052. *
  10053. * The @cq struct is used to get the queue ID of the queue to destroy.
  10054. *
  10055. * On success this function will return a zero. If the queue destroy mailbox
  10056. * command fails this function will return -ENXIO.
  10057. **/
  10058. uint32_t
  10059. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10060. {
  10061. LPFC_MBOXQ_t *mbox;
  10062. int rc, length, status = 0;
  10063. uint32_t shdr_status, shdr_add_status;
  10064. union lpfc_sli4_cfg_shdr *shdr;
  10065. if (!cq)
  10066. return -ENODEV;
  10067. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10068. if (!mbox)
  10069. return -ENOMEM;
  10070. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10071. sizeof(struct lpfc_sli4_cfg_mhdr));
  10072. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10073. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10074. length, LPFC_SLI4_MBX_EMBED);
  10075. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10076. cq->queue_id);
  10077. mbox->vport = cq->phba->pport;
  10078. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10079. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10080. /* The IOCTL status is embedded in the mailbox subheader. */
  10081. shdr = (union lpfc_sli4_cfg_shdr *)
  10082. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10083. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10084. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10085. if (shdr_status || shdr_add_status || rc) {
  10086. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10087. "2506 CQ_DESTROY mailbox failed with "
  10088. "status x%x add_status x%x, mbx status x%x\n",
  10089. shdr_status, shdr_add_status, rc);
  10090. status = -ENXIO;
  10091. }
  10092. /* Remove cq from any list */
  10093. list_del_init(&cq->list);
  10094. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10095. return status;
  10096. }
  10097. /**
  10098. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10099. * @qm: The queue structure associated with the queue to destroy.
  10100. *
  10101. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10102. * command, specific to the type of queue, to the HBA.
  10103. *
  10104. * The @mq struct is used to get the queue ID of the queue to destroy.
  10105. *
  10106. * On success this function will return a zero. If the queue destroy mailbox
  10107. * command fails this function will return -ENXIO.
  10108. **/
  10109. uint32_t
  10110. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10111. {
  10112. LPFC_MBOXQ_t *mbox;
  10113. int rc, length, status = 0;
  10114. uint32_t shdr_status, shdr_add_status;
  10115. union lpfc_sli4_cfg_shdr *shdr;
  10116. if (!mq)
  10117. return -ENODEV;
  10118. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10119. if (!mbox)
  10120. return -ENOMEM;
  10121. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10122. sizeof(struct lpfc_sli4_cfg_mhdr));
  10123. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10124. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10125. length, LPFC_SLI4_MBX_EMBED);
  10126. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10127. mq->queue_id);
  10128. mbox->vport = mq->phba->pport;
  10129. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10130. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10131. /* The IOCTL status is embedded in the mailbox subheader. */
  10132. shdr = (union lpfc_sli4_cfg_shdr *)
  10133. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10134. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10135. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10136. if (shdr_status || shdr_add_status || rc) {
  10137. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10138. "2507 MQ_DESTROY mailbox failed with "
  10139. "status x%x add_status x%x, mbx status x%x\n",
  10140. shdr_status, shdr_add_status, rc);
  10141. status = -ENXIO;
  10142. }
  10143. /* Remove mq from any list */
  10144. list_del_init(&mq->list);
  10145. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10146. return status;
  10147. }
  10148. /**
  10149. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10150. * @wq: The queue structure associated with the queue to destroy.
  10151. *
  10152. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10153. * command, specific to the type of queue, to the HBA.
  10154. *
  10155. * The @wq struct is used to get the queue ID of the queue to destroy.
  10156. *
  10157. * On success this function will return a zero. If the queue destroy mailbox
  10158. * command fails this function will return -ENXIO.
  10159. **/
  10160. uint32_t
  10161. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10162. {
  10163. LPFC_MBOXQ_t *mbox;
  10164. int rc, length, status = 0;
  10165. uint32_t shdr_status, shdr_add_status;
  10166. union lpfc_sli4_cfg_shdr *shdr;
  10167. if (!wq)
  10168. return -ENODEV;
  10169. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10170. if (!mbox)
  10171. return -ENOMEM;
  10172. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10173. sizeof(struct lpfc_sli4_cfg_mhdr));
  10174. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10175. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10176. length, LPFC_SLI4_MBX_EMBED);
  10177. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10178. wq->queue_id);
  10179. mbox->vport = wq->phba->pport;
  10180. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10181. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10182. shdr = (union lpfc_sli4_cfg_shdr *)
  10183. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10184. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10185. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10186. if (shdr_status || shdr_add_status || rc) {
  10187. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10188. "2508 WQ_DESTROY mailbox failed with "
  10189. "status x%x add_status x%x, mbx status x%x\n",
  10190. shdr_status, shdr_add_status, rc);
  10191. status = -ENXIO;
  10192. }
  10193. /* Remove wq from any list */
  10194. list_del_init(&wq->list);
  10195. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10196. return status;
  10197. }
  10198. /**
  10199. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10200. * @rq: The queue structure associated with the queue to destroy.
  10201. *
  10202. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10203. * command, specific to the type of queue, to the HBA.
  10204. *
  10205. * The @rq struct is used to get the queue ID of the queue to destroy.
  10206. *
  10207. * On success this function will return a zero. If the queue destroy mailbox
  10208. * command fails this function will return -ENXIO.
  10209. **/
  10210. uint32_t
  10211. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10212. struct lpfc_queue *drq)
  10213. {
  10214. LPFC_MBOXQ_t *mbox;
  10215. int rc, length, status = 0;
  10216. uint32_t shdr_status, shdr_add_status;
  10217. union lpfc_sli4_cfg_shdr *shdr;
  10218. if (!hrq || !drq)
  10219. return -ENODEV;
  10220. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10221. if (!mbox)
  10222. return -ENOMEM;
  10223. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10224. sizeof(struct mbox_header));
  10225. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10226. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10227. length, LPFC_SLI4_MBX_EMBED);
  10228. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10229. hrq->queue_id);
  10230. mbox->vport = hrq->phba->pport;
  10231. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10232. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10233. /* The IOCTL status is embedded in the mailbox subheader. */
  10234. shdr = (union lpfc_sli4_cfg_shdr *)
  10235. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10236. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10237. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10238. if (shdr_status || shdr_add_status || rc) {
  10239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10240. "2509 RQ_DESTROY mailbox failed with "
  10241. "status x%x add_status x%x, mbx status x%x\n",
  10242. shdr_status, shdr_add_status, rc);
  10243. if (rc != MBX_TIMEOUT)
  10244. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10245. return -ENXIO;
  10246. }
  10247. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10248. drq->queue_id);
  10249. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10250. shdr = (union lpfc_sli4_cfg_shdr *)
  10251. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10252. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10253. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10254. if (shdr_status || shdr_add_status || rc) {
  10255. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10256. "2510 RQ_DESTROY mailbox failed with "
  10257. "status x%x add_status x%x, mbx status x%x\n",
  10258. shdr_status, shdr_add_status, rc);
  10259. status = -ENXIO;
  10260. }
  10261. list_del_init(&hrq->list);
  10262. list_del_init(&drq->list);
  10263. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10264. return status;
  10265. }
  10266. /**
  10267. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10268. * @phba: The virtual port for which this call being executed.
  10269. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10270. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10271. * @xritag: the xritag that ties this io to the SGL pages.
  10272. *
  10273. * This routine will post the sgl pages for the IO that has the xritag
  10274. * that is in the iocbq structure. The xritag is assigned during iocbq
  10275. * creation and persists for as long as the driver is loaded.
  10276. * if the caller has fewer than 256 scatter gather segments to map then
  10277. * pdma_phys_addr1 should be 0.
  10278. * If the caller needs to map more than 256 scatter gather segment then
  10279. * pdma_phys_addr1 should be a valid physical address.
  10280. * physical address for SGLs must be 64 byte aligned.
  10281. * If you are going to map 2 SGL's then the first one must have 256 entries
  10282. * the second sgl can have between 1 and 256 entries.
  10283. *
  10284. * Return codes:
  10285. * 0 - Success
  10286. * -ENXIO, -ENOMEM - Failure
  10287. **/
  10288. int
  10289. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10290. dma_addr_t pdma_phys_addr0,
  10291. dma_addr_t pdma_phys_addr1,
  10292. uint16_t xritag)
  10293. {
  10294. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10295. LPFC_MBOXQ_t *mbox;
  10296. int rc;
  10297. uint32_t shdr_status, shdr_add_status;
  10298. union lpfc_sli4_cfg_shdr *shdr;
  10299. if (xritag == NO_XRI) {
  10300. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10301. "0364 Invalid param:\n");
  10302. return -EINVAL;
  10303. }
  10304. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10305. if (!mbox)
  10306. return -ENOMEM;
  10307. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10308. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10309. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10310. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10311. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10312. &mbox->u.mqe.un.post_sgl_pages;
  10313. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10314. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10315. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10316. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10317. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10318. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10319. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10320. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10321. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10322. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10323. if (!phba->sli4_hba.intr_enable)
  10324. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10325. else
  10326. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10327. /* The IOCTL status is embedded in the mailbox subheader. */
  10328. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10329. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10330. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10331. if (rc != MBX_TIMEOUT)
  10332. mempool_free(mbox, phba->mbox_mem_pool);
  10333. if (shdr_status || shdr_add_status || rc) {
  10334. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10335. "2511 POST_SGL mailbox failed with "
  10336. "status x%x add_status x%x, mbx status x%x\n",
  10337. shdr_status, shdr_add_status, rc);
  10338. rc = -ENXIO;
  10339. }
  10340. return 0;
  10341. }
  10342. /**
  10343. * lpfc_sli4_next_xritag - Get an xritag for the io
  10344. * @phba: Pointer to HBA context object.
  10345. *
  10346. * This function gets an xritag for the iocb. If there is no unused xritag
  10347. * it will return 0xffff.
  10348. * The function returns the allocated xritag if successful, else returns zero.
  10349. * Zero is not a valid xritag.
  10350. * The caller is not required to hold any lock.
  10351. **/
  10352. uint16_t
  10353. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10354. {
  10355. uint16_t xritag;
  10356. spin_lock_irq(&phba->hbalock);
  10357. xritag = phba->sli4_hba.next_xri;
  10358. if ((xritag != (uint16_t) -1) && xritag <
  10359. (phba->sli4_hba.max_cfg_param.max_xri
  10360. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10361. phba->sli4_hba.next_xri++;
  10362. phba->sli4_hba.max_cfg_param.xri_used++;
  10363. spin_unlock_irq(&phba->hbalock);
  10364. return xritag;
  10365. }
  10366. spin_unlock_irq(&phba->hbalock);
  10367. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10368. "2004 Failed to allocate XRI.last XRITAG is %d"
  10369. " Max XRI is %d, Used XRI is %d\n",
  10370. phba->sli4_hba.next_xri,
  10371. phba->sli4_hba.max_cfg_param.max_xri,
  10372. phba->sli4_hba.max_cfg_param.xri_used);
  10373. return -1;
  10374. }
  10375. /**
  10376. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10377. * @phba: pointer to lpfc hba data structure.
  10378. *
  10379. * This routine is invoked to post a block of driver's sgl pages to the
  10380. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10381. * is only called when the driver is loading and after all IO has been
  10382. * stopped.
  10383. **/
  10384. int
  10385. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10386. {
  10387. struct lpfc_sglq *sglq_entry;
  10388. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10389. struct sgl_page_pairs *sgl_pg_pairs;
  10390. void *viraddr;
  10391. LPFC_MBOXQ_t *mbox;
  10392. uint32_t reqlen, alloclen, pg_pairs;
  10393. uint32_t mbox_tmo;
  10394. uint16_t xritag_start = 0;
  10395. int els_xri_cnt, rc = 0;
  10396. uint32_t shdr_status, shdr_add_status;
  10397. union lpfc_sli4_cfg_shdr *shdr;
  10398. /* The number of sgls to be posted */
  10399. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10400. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10401. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10402. if (reqlen > SLI4_PAGE_SIZE) {
  10403. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10404. "2559 Block sgl registration required DMA "
  10405. "size (%d) great than a page\n", reqlen);
  10406. return -ENOMEM;
  10407. }
  10408. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10409. if (!mbox) {
  10410. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10411. "2560 Failed to allocate mbox cmd memory\n");
  10412. return -ENOMEM;
  10413. }
  10414. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10415. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10416. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10417. LPFC_SLI4_MBX_NEMBED);
  10418. if (alloclen < reqlen) {
  10419. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10420. "0285 Allocated DMA memory size (%d) is "
  10421. "less than the requested DMA memory "
  10422. "size (%d)\n", alloclen, reqlen);
  10423. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10424. return -ENOMEM;
  10425. }
  10426. /* Get the first SGE entry from the non-embedded DMA memory */
  10427. viraddr = mbox->sge_array->addr[0];
  10428. /* Set up the SGL pages in the non-embedded DMA pages */
  10429. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10430. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10431. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10432. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10433. /* Set up the sge entry */
  10434. sgl_pg_pairs->sgl_pg0_addr_lo =
  10435. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10436. sgl_pg_pairs->sgl_pg0_addr_hi =
  10437. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10438. sgl_pg_pairs->sgl_pg1_addr_lo =
  10439. cpu_to_le32(putPaddrLow(0));
  10440. sgl_pg_pairs->sgl_pg1_addr_hi =
  10441. cpu_to_le32(putPaddrHigh(0));
  10442. /* Keep the first xritag on the list */
  10443. if (pg_pairs == 0)
  10444. xritag_start = sglq_entry->sli4_xritag;
  10445. sgl_pg_pairs++;
  10446. }
  10447. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10448. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10449. /* Perform endian conversion if necessary */
  10450. sgl->word0 = cpu_to_le32(sgl->word0);
  10451. if (!phba->sli4_hba.intr_enable)
  10452. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10453. else {
  10454. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10455. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10456. }
  10457. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10458. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10459. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10460. if (rc != MBX_TIMEOUT)
  10461. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10462. if (shdr_status || shdr_add_status || rc) {
  10463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10464. "2513 POST_SGL_BLOCK mailbox command failed "
  10465. "status x%x add_status x%x mbx status x%x\n",
  10466. shdr_status, shdr_add_status, rc);
  10467. rc = -ENXIO;
  10468. }
  10469. return rc;
  10470. }
  10471. /**
  10472. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10473. * @phba: pointer to lpfc hba data structure.
  10474. * @sblist: pointer to scsi buffer list.
  10475. * @count: number of scsi buffers on the list.
  10476. *
  10477. * This routine is invoked to post a block of @count scsi sgl pages from a
  10478. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10479. * No Lock is held.
  10480. *
  10481. **/
  10482. int
  10483. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10484. int cnt)
  10485. {
  10486. struct lpfc_scsi_buf *psb;
  10487. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10488. struct sgl_page_pairs *sgl_pg_pairs;
  10489. void *viraddr;
  10490. LPFC_MBOXQ_t *mbox;
  10491. uint32_t reqlen, alloclen, pg_pairs;
  10492. uint32_t mbox_tmo;
  10493. uint16_t xritag_start = 0;
  10494. int rc = 0;
  10495. uint32_t shdr_status, shdr_add_status;
  10496. dma_addr_t pdma_phys_bpl1;
  10497. union lpfc_sli4_cfg_shdr *shdr;
  10498. /* Calculate the requested length of the dma memory */
  10499. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10500. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10501. if (reqlen > SLI4_PAGE_SIZE) {
  10502. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10503. "0217 Block sgl registration required DMA "
  10504. "size (%d) great than a page\n", reqlen);
  10505. return -ENOMEM;
  10506. }
  10507. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10508. if (!mbox) {
  10509. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10510. "0283 Failed to allocate mbox cmd memory\n");
  10511. return -ENOMEM;
  10512. }
  10513. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10514. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10515. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10516. LPFC_SLI4_MBX_NEMBED);
  10517. if (alloclen < reqlen) {
  10518. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10519. "2561 Allocated DMA memory size (%d) is "
  10520. "less than the requested DMA memory "
  10521. "size (%d)\n", alloclen, reqlen);
  10522. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10523. return -ENOMEM;
  10524. }
  10525. /* Get the first SGE entry from the non-embedded DMA memory */
  10526. viraddr = mbox->sge_array->addr[0];
  10527. /* Set up the SGL pages in the non-embedded DMA pages */
  10528. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10529. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10530. pg_pairs = 0;
  10531. list_for_each_entry(psb, sblist, list) {
  10532. /* Set up the sge entry */
  10533. sgl_pg_pairs->sgl_pg0_addr_lo =
  10534. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10535. sgl_pg_pairs->sgl_pg0_addr_hi =
  10536. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10537. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10538. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10539. else
  10540. pdma_phys_bpl1 = 0;
  10541. sgl_pg_pairs->sgl_pg1_addr_lo =
  10542. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10543. sgl_pg_pairs->sgl_pg1_addr_hi =
  10544. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10545. /* Keep the first xritag on the list */
  10546. if (pg_pairs == 0)
  10547. xritag_start = psb->cur_iocbq.sli4_xritag;
  10548. sgl_pg_pairs++;
  10549. pg_pairs++;
  10550. }
  10551. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10552. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10553. /* Perform endian conversion if necessary */
  10554. sgl->word0 = cpu_to_le32(sgl->word0);
  10555. if (!phba->sli4_hba.intr_enable)
  10556. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10557. else {
  10558. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10559. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10560. }
  10561. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10562. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10563. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10564. if (rc != MBX_TIMEOUT)
  10565. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10566. if (shdr_status || shdr_add_status || rc) {
  10567. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10568. "2564 POST_SGL_BLOCK mailbox command failed "
  10569. "status x%x add_status x%x mbx status x%x\n",
  10570. shdr_status, shdr_add_status, rc);
  10571. rc = -ENXIO;
  10572. }
  10573. return rc;
  10574. }
  10575. /**
  10576. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10577. * @phba: pointer to lpfc_hba struct that the frame was received on
  10578. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10579. *
  10580. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10581. * valid type of frame that the LPFC driver will handle. This function will
  10582. * return a zero if the frame is a valid frame or a non zero value when the
  10583. * frame does not pass the check.
  10584. **/
  10585. static int
  10586. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10587. {
  10588. /* make rctl_names static to save stack space */
  10589. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10590. char *type_names[] = FC_TYPE_NAMES_INIT;
  10591. struct fc_vft_header *fc_vft_hdr;
  10592. switch (fc_hdr->fh_r_ctl) {
  10593. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10594. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10595. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10596. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10597. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10598. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10599. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10600. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10601. case FC_RCTL_ELS_REQ: /* extended link services request */
  10602. case FC_RCTL_ELS_REP: /* extended link services reply */
  10603. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10604. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10605. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10606. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10607. case FC_RCTL_BA_RMC: /* remove connection */
  10608. case FC_RCTL_BA_ACC: /* basic accept */
  10609. case FC_RCTL_BA_RJT: /* basic reject */
  10610. case FC_RCTL_BA_PRMT:
  10611. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10612. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10613. case FC_RCTL_P_RJT: /* port reject */
  10614. case FC_RCTL_F_RJT: /* fabric reject */
  10615. case FC_RCTL_P_BSY: /* port busy */
  10616. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10617. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10618. case FC_RCTL_LCR: /* link credit reset */
  10619. case FC_RCTL_END: /* end */
  10620. break;
  10621. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10622. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10623. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10624. return lpfc_fc_frame_check(phba, fc_hdr);
  10625. default:
  10626. goto drop;
  10627. }
  10628. switch (fc_hdr->fh_type) {
  10629. case FC_TYPE_BLS:
  10630. case FC_TYPE_ELS:
  10631. case FC_TYPE_FCP:
  10632. case FC_TYPE_CT:
  10633. break;
  10634. case FC_TYPE_IP:
  10635. case FC_TYPE_ILS:
  10636. default:
  10637. goto drop;
  10638. }
  10639. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10640. "2538 Received frame rctl:%s type:%s\n",
  10641. rctl_names[fc_hdr->fh_r_ctl],
  10642. type_names[fc_hdr->fh_type]);
  10643. return 0;
  10644. drop:
  10645. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10646. "2539 Dropped frame rctl:%s type:%s\n",
  10647. rctl_names[fc_hdr->fh_r_ctl],
  10648. type_names[fc_hdr->fh_type]);
  10649. return 1;
  10650. }
  10651. /**
  10652. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10653. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10654. *
  10655. * This function processes the FC header to retrieve the VFI from the VF
  10656. * header, if one exists. This function will return the VFI if one exists
  10657. * or 0 if no VSAN Header exists.
  10658. **/
  10659. static uint32_t
  10660. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10661. {
  10662. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10663. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10664. return 0;
  10665. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10666. }
  10667. /**
  10668. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10669. * @phba: Pointer to the HBA structure to search for the vport on
  10670. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10671. * @fcfi: The FC Fabric ID that the frame came from
  10672. *
  10673. * This function searches the @phba for a vport that matches the content of the
  10674. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10675. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10676. * returns the matching vport pointer or NULL if unable to match frame to a
  10677. * vport.
  10678. **/
  10679. static struct lpfc_vport *
  10680. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10681. uint16_t fcfi)
  10682. {
  10683. struct lpfc_vport **vports;
  10684. struct lpfc_vport *vport = NULL;
  10685. int i;
  10686. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10687. fc_hdr->fh_d_id[1] << 8 |
  10688. fc_hdr->fh_d_id[2]);
  10689. vports = lpfc_create_vport_work_array(phba);
  10690. if (vports != NULL)
  10691. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10692. if (phba->fcf.fcfi == fcfi &&
  10693. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10694. vports[i]->fc_myDID == did) {
  10695. vport = vports[i];
  10696. break;
  10697. }
  10698. }
  10699. lpfc_destroy_vport_work_array(phba, vports);
  10700. return vport;
  10701. }
  10702. /**
  10703. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10704. * @vport: The vport to work on.
  10705. *
  10706. * This function updates the receive sequence time stamp for this vport. The
  10707. * receive sequence time stamp indicates the time that the last frame of the
  10708. * the sequence that has been idle for the longest amount of time was received.
  10709. * the driver uses this time stamp to indicate if any received sequences have
  10710. * timed out.
  10711. **/
  10712. void
  10713. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10714. {
  10715. struct lpfc_dmabuf *h_buf;
  10716. struct hbq_dmabuf *dmabuf = NULL;
  10717. /* get the oldest sequence on the rcv list */
  10718. h_buf = list_get_first(&vport->rcv_buffer_list,
  10719. struct lpfc_dmabuf, list);
  10720. if (!h_buf)
  10721. return;
  10722. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10723. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10724. }
  10725. /**
  10726. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10727. * @vport: The vport that the received sequences were sent to.
  10728. *
  10729. * This function cleans up all outstanding received sequences. This is called
  10730. * by the driver when a link event or user action invalidates all the received
  10731. * sequences.
  10732. **/
  10733. void
  10734. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10735. {
  10736. struct lpfc_dmabuf *h_buf, *hnext;
  10737. struct lpfc_dmabuf *d_buf, *dnext;
  10738. struct hbq_dmabuf *dmabuf = NULL;
  10739. /* start with the oldest sequence on the rcv list */
  10740. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10741. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10742. list_del_init(&dmabuf->hbuf.list);
  10743. list_for_each_entry_safe(d_buf, dnext,
  10744. &dmabuf->dbuf.list, list) {
  10745. list_del_init(&d_buf->list);
  10746. lpfc_in_buf_free(vport->phba, d_buf);
  10747. }
  10748. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10749. }
  10750. }
  10751. /**
  10752. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10753. * @vport: The vport that the received sequences were sent to.
  10754. *
  10755. * This function determines whether any received sequences have timed out by
  10756. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10757. * indicates that there is at least one timed out sequence this routine will
  10758. * go through the received sequences one at a time from most inactive to most
  10759. * active to determine which ones need to be cleaned up. Once it has determined
  10760. * that a sequence needs to be cleaned up it will simply free up the resources
  10761. * without sending an abort.
  10762. **/
  10763. void
  10764. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10765. {
  10766. struct lpfc_dmabuf *h_buf, *hnext;
  10767. struct lpfc_dmabuf *d_buf, *dnext;
  10768. struct hbq_dmabuf *dmabuf = NULL;
  10769. unsigned long timeout;
  10770. int abort_count = 0;
  10771. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10772. vport->rcv_buffer_time_stamp);
  10773. if (list_empty(&vport->rcv_buffer_list) ||
  10774. time_before(jiffies, timeout))
  10775. return;
  10776. /* start with the oldest sequence on the rcv list */
  10777. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10778. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10779. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10780. dmabuf->time_stamp);
  10781. if (time_before(jiffies, timeout))
  10782. break;
  10783. abort_count++;
  10784. list_del_init(&dmabuf->hbuf.list);
  10785. list_for_each_entry_safe(d_buf, dnext,
  10786. &dmabuf->dbuf.list, list) {
  10787. list_del_init(&d_buf->list);
  10788. lpfc_in_buf_free(vport->phba, d_buf);
  10789. }
  10790. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10791. }
  10792. if (abort_count)
  10793. lpfc_update_rcv_time_stamp(vport);
  10794. }
  10795. /**
  10796. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10797. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10798. *
  10799. * This function searches through the existing incomplete sequences that have
  10800. * been sent to this @vport. If the frame matches one of the incomplete
  10801. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10802. * make up that sequence. If no sequence is found that matches this frame then
  10803. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10804. * This function returns a pointer to the first dmabuf in the sequence list that
  10805. * the frame was linked to.
  10806. **/
  10807. static struct hbq_dmabuf *
  10808. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10809. {
  10810. struct fc_frame_header *new_hdr;
  10811. struct fc_frame_header *temp_hdr;
  10812. struct lpfc_dmabuf *d_buf;
  10813. struct lpfc_dmabuf *h_buf;
  10814. struct hbq_dmabuf *seq_dmabuf = NULL;
  10815. struct hbq_dmabuf *temp_dmabuf = NULL;
  10816. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10817. dmabuf->time_stamp = jiffies;
  10818. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10819. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10820. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10821. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10822. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10823. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10824. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10825. continue;
  10826. /* found a pending sequence that matches this frame */
  10827. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10828. break;
  10829. }
  10830. if (!seq_dmabuf) {
  10831. /*
  10832. * This indicates first frame received for this sequence.
  10833. * Queue the buffer on the vport's rcv_buffer_list.
  10834. */
  10835. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10836. lpfc_update_rcv_time_stamp(vport);
  10837. return dmabuf;
  10838. }
  10839. temp_hdr = seq_dmabuf->hbuf.virt;
  10840. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10841. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10842. list_del_init(&seq_dmabuf->hbuf.list);
  10843. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10844. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10845. lpfc_update_rcv_time_stamp(vport);
  10846. return dmabuf;
  10847. }
  10848. /* move this sequence to the tail to indicate a young sequence */
  10849. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10850. seq_dmabuf->time_stamp = jiffies;
  10851. lpfc_update_rcv_time_stamp(vport);
  10852. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10853. temp_hdr = dmabuf->hbuf.virt;
  10854. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10855. return seq_dmabuf;
  10856. }
  10857. /* find the correct place in the sequence to insert this frame */
  10858. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10859. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10860. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10861. /*
  10862. * If the frame's sequence count is greater than the frame on
  10863. * the list then insert the frame right after this frame
  10864. */
  10865. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10866. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10867. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10868. return seq_dmabuf;
  10869. }
  10870. }
  10871. return NULL;
  10872. }
  10873. /**
  10874. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10875. * @vport: pointer to a vitural port
  10876. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10877. *
  10878. * This function tries to abort from the partially assembed sequence, described
  10879. * by the information from basic abbort @dmabuf. It checks to see whether such
  10880. * partially assembled sequence held by the driver. If so, it shall free up all
  10881. * the frames from the partially assembled sequence.
  10882. *
  10883. * Return
  10884. * true -- if there is matching partially assembled sequence present and all
  10885. * the frames freed with the sequence;
  10886. * false -- if there is no matching partially assembled sequence present so
  10887. * nothing got aborted in the lower layer driver
  10888. **/
  10889. static bool
  10890. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10891. struct hbq_dmabuf *dmabuf)
  10892. {
  10893. struct fc_frame_header *new_hdr;
  10894. struct fc_frame_header *temp_hdr;
  10895. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10896. struct hbq_dmabuf *seq_dmabuf = NULL;
  10897. /* Use the hdr_buf to find the sequence that matches this frame */
  10898. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10899. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10900. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10901. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10902. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10903. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10904. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10905. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10906. continue;
  10907. /* found a pending sequence that matches this frame */
  10908. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10909. break;
  10910. }
  10911. /* Free up all the frames from the partially assembled sequence */
  10912. if (seq_dmabuf) {
  10913. list_for_each_entry_safe(d_buf, n_buf,
  10914. &seq_dmabuf->dbuf.list, list) {
  10915. list_del_init(&d_buf->list);
  10916. lpfc_in_buf_free(vport->phba, d_buf);
  10917. }
  10918. return true;
  10919. }
  10920. return false;
  10921. }
  10922. /**
  10923. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10924. * @phba: Pointer to HBA context object.
  10925. * @cmd_iocbq: pointer to the command iocbq structure.
  10926. * @rsp_iocbq: pointer to the response iocbq structure.
  10927. *
  10928. * This function handles the sequence abort accept iocb command complete
  10929. * event. It properly releases the memory allocated to the sequence abort
  10930. * accept iocb.
  10931. **/
  10932. static void
  10933. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10934. struct lpfc_iocbq *cmd_iocbq,
  10935. struct lpfc_iocbq *rsp_iocbq)
  10936. {
  10937. if (cmd_iocbq)
  10938. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10939. }
  10940. /**
  10941. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10942. * @phba: Pointer to HBA context object.
  10943. * @fc_hdr: pointer to a FC frame header.
  10944. *
  10945. * This function sends a basic accept to a previous unsol sequence abort
  10946. * event after aborting the sequence handling.
  10947. **/
  10948. static void
  10949. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10950. struct fc_frame_header *fc_hdr)
  10951. {
  10952. struct lpfc_iocbq *ctiocb = NULL;
  10953. struct lpfc_nodelist *ndlp;
  10954. uint16_t oxid, rxid;
  10955. uint32_t sid, fctl;
  10956. IOCB_t *icmd;
  10957. if (!lpfc_is_link_up(phba))
  10958. return;
  10959. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10960. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10961. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10962. ndlp = lpfc_findnode_did(phba->pport, sid);
  10963. if (!ndlp) {
  10964. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10965. "1268 Find ndlp returned NULL for oxid:x%x "
  10966. "SID:x%x\n", oxid, sid);
  10967. return;
  10968. }
  10969. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  10970. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  10971. + phba->sli4_hba.max_cfg_param.xri_base))
  10972. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  10973. /* Allocate buffer for acc iocb */
  10974. ctiocb = lpfc_sli_get_iocbq(phba);
  10975. if (!ctiocb)
  10976. return;
  10977. /* Extract the F_CTL field from FC_HDR */
  10978. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10979. icmd = &ctiocb->iocb;
  10980. icmd->un.xseq64.bdl.bdeSize = 0;
  10981. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10982. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10983. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10984. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10985. /* Fill in the rest of iocb fields */
  10986. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10987. icmd->ulpBdeCount = 0;
  10988. icmd->ulpLe = 1;
  10989. icmd->ulpClass = CLASS3;
  10990. icmd->ulpContext = ndlp->nlp_rpi;
  10991. ctiocb->context1 = ndlp;
  10992. ctiocb->iocb_cmpl = NULL;
  10993. ctiocb->vport = phba->pport;
  10994. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10995. if (fctl & FC_FC_EX_CTX) {
  10996. /* ABTS sent by responder to CT exchange, construction
  10997. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10998. * field and RX_ID from ABTS for RX_ID field.
  10999. */
  11000. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  11001. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  11002. ctiocb->sli4_xritag = oxid;
  11003. } else {
  11004. /* ABTS sent by initiator to CT exchange, construction
  11005. * of BA_ACC will need to allocate a new XRI as for the
  11006. * XRI_TAG and RX_ID fields.
  11007. */
  11008. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  11009. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  11010. ctiocb->sli4_xritag = NO_XRI;
  11011. }
  11012. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  11013. /* Xmit CT abts accept on exchange <xid> */
  11014. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11015. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  11016. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  11017. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  11018. }
  11019. /**
  11020. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  11021. * @vport: Pointer to the vport on which this sequence was received
  11022. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11023. *
  11024. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  11025. * receive sequence is only partially assembed by the driver, it shall abort
  11026. * the partially assembled frames for the sequence. Otherwise, if the
  11027. * unsolicited receive sequence has been completely assembled and passed to
  11028. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  11029. * unsolicited sequence has been aborted. After that, it will issue a basic
  11030. * accept to accept the abort.
  11031. **/
  11032. void
  11033. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  11034. struct hbq_dmabuf *dmabuf)
  11035. {
  11036. struct lpfc_hba *phba = vport->phba;
  11037. struct fc_frame_header fc_hdr;
  11038. uint32_t fctl;
  11039. bool abts_par;
  11040. /* Make a copy of fc_hdr before the dmabuf being released */
  11041. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11042. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11043. if (fctl & FC_FC_EX_CTX) {
  11044. /*
  11045. * ABTS sent by responder to exchange, just free the buffer
  11046. */
  11047. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11048. } else {
  11049. /*
  11050. * ABTS sent by initiator to exchange, need to do cleanup
  11051. */
  11052. /* Try to abort partially assembled seq */
  11053. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11054. /* Send abort to ULP if partially seq abort failed */
  11055. if (abts_par == false)
  11056. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11057. else
  11058. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11059. }
  11060. /* Send basic accept (BA_ACC) to the abort requester */
  11061. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  11062. }
  11063. /**
  11064. * lpfc_seq_complete - Indicates if a sequence is complete
  11065. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11066. *
  11067. * This function checks the sequence, starting with the frame described by
  11068. * @dmabuf, to see if all the frames associated with this sequence are present.
  11069. * the frames associated with this sequence are linked to the @dmabuf using the
  11070. * dbuf list. This function looks for two major things. 1) That the first frame
  11071. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11072. * set. 3) That there are no holes in the sequence count. The function will
  11073. * return 1 when the sequence is complete, otherwise it will return 0.
  11074. **/
  11075. static int
  11076. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11077. {
  11078. struct fc_frame_header *hdr;
  11079. struct lpfc_dmabuf *d_buf;
  11080. struct hbq_dmabuf *seq_dmabuf;
  11081. uint32_t fctl;
  11082. int seq_count = 0;
  11083. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11084. /* make sure first fame of sequence has a sequence count of zero */
  11085. if (hdr->fh_seq_cnt != seq_count)
  11086. return 0;
  11087. fctl = (hdr->fh_f_ctl[0] << 16 |
  11088. hdr->fh_f_ctl[1] << 8 |
  11089. hdr->fh_f_ctl[2]);
  11090. /* If last frame of sequence we can return success. */
  11091. if (fctl & FC_FC_END_SEQ)
  11092. return 1;
  11093. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11094. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11095. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11096. /* If there is a hole in the sequence count then fail. */
  11097. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11098. return 0;
  11099. fctl = (hdr->fh_f_ctl[0] << 16 |
  11100. hdr->fh_f_ctl[1] << 8 |
  11101. hdr->fh_f_ctl[2]);
  11102. /* If last frame of sequence we can return success. */
  11103. if (fctl & FC_FC_END_SEQ)
  11104. return 1;
  11105. }
  11106. return 0;
  11107. }
  11108. /**
  11109. * lpfc_prep_seq - Prep sequence for ULP processing
  11110. * @vport: Pointer to the vport on which this sequence was received
  11111. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11112. *
  11113. * This function takes a sequence, described by a list of frames, and creates
  11114. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11115. * used to issue to the generic unsolicited sequence handler. This routine
  11116. * returns a pointer to the first iocbq in the list. If the function is unable
  11117. * to allocate an iocbq then it throw out the received frames that were not
  11118. * able to be described and return a pointer to the first iocbq. If unable to
  11119. * allocate any iocbqs (including the first) this function will return NULL.
  11120. **/
  11121. static struct lpfc_iocbq *
  11122. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11123. {
  11124. struct lpfc_dmabuf *d_buf, *n_buf;
  11125. struct lpfc_iocbq *first_iocbq, *iocbq;
  11126. struct fc_frame_header *fc_hdr;
  11127. uint32_t sid;
  11128. struct ulp_bde64 *pbde;
  11129. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11130. /* remove from receive buffer list */
  11131. list_del_init(&seq_dmabuf->hbuf.list);
  11132. lpfc_update_rcv_time_stamp(vport);
  11133. /* get the Remote Port's SID */
  11134. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11135. /* Get an iocbq struct to fill in. */
  11136. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11137. if (first_iocbq) {
  11138. /* Initialize the first IOCB. */
  11139. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11140. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11141. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11142. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11143. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11144. vport->vpi + vport->phba->vpi_base;
  11145. /* put the first buffer into the first IOCBq */
  11146. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11147. first_iocbq->context3 = NULL;
  11148. first_iocbq->iocb.ulpBdeCount = 1;
  11149. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11150. LPFC_DATA_BUF_SIZE;
  11151. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11152. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11153. bf_get(lpfc_rcqe_length,
  11154. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11155. }
  11156. iocbq = first_iocbq;
  11157. /*
  11158. * Each IOCBq can have two Buffers assigned, so go through the list
  11159. * of buffers for this sequence and save two buffers in each IOCBq
  11160. */
  11161. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11162. if (!iocbq) {
  11163. lpfc_in_buf_free(vport->phba, d_buf);
  11164. continue;
  11165. }
  11166. if (!iocbq->context3) {
  11167. iocbq->context3 = d_buf;
  11168. iocbq->iocb.ulpBdeCount++;
  11169. pbde = (struct ulp_bde64 *)
  11170. &iocbq->iocb.unsli3.sli3Words[4];
  11171. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11172. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11173. bf_get(lpfc_rcqe_length,
  11174. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11175. } else {
  11176. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11177. if (!iocbq) {
  11178. if (first_iocbq) {
  11179. first_iocbq->iocb.ulpStatus =
  11180. IOSTAT_FCP_RSP_ERROR;
  11181. first_iocbq->iocb.un.ulpWord[4] =
  11182. IOERR_NO_RESOURCES;
  11183. }
  11184. lpfc_in_buf_free(vport->phba, d_buf);
  11185. continue;
  11186. }
  11187. iocbq->context2 = d_buf;
  11188. iocbq->context3 = NULL;
  11189. iocbq->iocb.ulpBdeCount = 1;
  11190. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11191. LPFC_DATA_BUF_SIZE;
  11192. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11193. bf_get(lpfc_rcqe_length,
  11194. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11195. iocbq->iocb.un.rcvels.remoteID = sid;
  11196. list_add_tail(&iocbq->list, &first_iocbq->list);
  11197. }
  11198. }
  11199. return first_iocbq;
  11200. }
  11201. static void
  11202. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11203. struct hbq_dmabuf *seq_dmabuf)
  11204. {
  11205. struct fc_frame_header *fc_hdr;
  11206. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11207. struct lpfc_hba *phba = vport->phba;
  11208. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11209. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11210. if (!iocbq) {
  11211. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11212. "2707 Ring %d handler: Failed to allocate "
  11213. "iocb Rctl x%x Type x%x received\n",
  11214. LPFC_ELS_RING,
  11215. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11216. return;
  11217. }
  11218. if (!lpfc_complete_unsol_iocb(phba,
  11219. &phba->sli.ring[LPFC_ELS_RING],
  11220. iocbq, fc_hdr->fh_r_ctl,
  11221. fc_hdr->fh_type))
  11222. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11223. "2540 Ring %d handler: unexpected Rctl "
  11224. "x%x Type x%x received\n",
  11225. LPFC_ELS_RING,
  11226. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11227. /* Free iocb created in lpfc_prep_seq */
  11228. list_for_each_entry_safe(curr_iocb, next_iocb,
  11229. &iocbq->list, list) {
  11230. list_del_init(&curr_iocb->list);
  11231. lpfc_sli_release_iocbq(phba, curr_iocb);
  11232. }
  11233. lpfc_sli_release_iocbq(phba, iocbq);
  11234. }
  11235. /**
  11236. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11237. * @phba: Pointer to HBA context object.
  11238. *
  11239. * This function is called with no lock held. This function processes all
  11240. * the received buffers and gives it to upper layers when a received buffer
  11241. * indicates that it is the final frame in the sequence. The interrupt
  11242. * service routine processes received buffers at interrupt contexts and adds
  11243. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11244. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11245. * appropriate receive function when the final frame in a sequence is received.
  11246. **/
  11247. void
  11248. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11249. struct hbq_dmabuf *dmabuf)
  11250. {
  11251. struct hbq_dmabuf *seq_dmabuf;
  11252. struct fc_frame_header *fc_hdr;
  11253. struct lpfc_vport *vport;
  11254. uint32_t fcfi;
  11255. /* Process each received buffer */
  11256. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11257. /* check to see if this a valid type of frame */
  11258. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11259. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11260. return;
  11261. }
  11262. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11263. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11264. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11265. /* throw out the frame */
  11266. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11267. return;
  11268. }
  11269. /* Handle the basic abort sequence (BA_ABTS) event */
  11270. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11271. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11272. return;
  11273. }
  11274. /* Link this frame */
  11275. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11276. if (!seq_dmabuf) {
  11277. /* unable to add frame to vport - throw it out */
  11278. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11279. return;
  11280. }
  11281. /* If not last frame in sequence continue processing frames. */
  11282. if (!lpfc_seq_complete(seq_dmabuf))
  11283. return;
  11284. /* Send the complete sequence to the upper layer protocol */
  11285. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11286. }
  11287. /**
  11288. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11289. * @phba: pointer to lpfc hba data structure.
  11290. *
  11291. * This routine is invoked to post rpi header templates to the
  11292. * HBA consistent with the SLI-4 interface spec. This routine
  11293. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11294. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11295. *
  11296. * This routine does not require any locks. It's usage is expected
  11297. * to be driver load or reset recovery when the driver is
  11298. * sequential.
  11299. *
  11300. * Return codes
  11301. * 0 - successful
  11302. * -EIO - The mailbox failed to complete successfully.
  11303. * When this error occurs, the driver is not guaranteed
  11304. * to have any rpi regions posted to the device and
  11305. * must either attempt to repost the regions or take a
  11306. * fatal error.
  11307. **/
  11308. int
  11309. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11310. {
  11311. struct lpfc_rpi_hdr *rpi_page;
  11312. uint32_t rc = 0;
  11313. /* Post all rpi memory regions to the port. */
  11314. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11315. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11316. if (rc != MBX_SUCCESS) {
  11317. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11318. "2008 Error %d posting all rpi "
  11319. "headers\n", rc);
  11320. rc = -EIO;
  11321. break;
  11322. }
  11323. }
  11324. return rc;
  11325. }
  11326. /**
  11327. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11328. * @phba: pointer to lpfc hba data structure.
  11329. * @rpi_page: pointer to the rpi memory region.
  11330. *
  11331. * This routine is invoked to post a single rpi header to the
  11332. * HBA consistent with the SLI-4 interface spec. This memory region
  11333. * maps up to 64 rpi context regions.
  11334. *
  11335. * Return codes
  11336. * 0 - successful
  11337. * -ENOMEM - No available memory
  11338. * -EIO - The mailbox failed to complete successfully.
  11339. **/
  11340. int
  11341. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11342. {
  11343. LPFC_MBOXQ_t *mboxq;
  11344. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11345. uint32_t rc = 0;
  11346. uint32_t mbox_tmo;
  11347. uint32_t shdr_status, shdr_add_status;
  11348. union lpfc_sli4_cfg_shdr *shdr;
  11349. /* The port is notified of the header region via a mailbox command. */
  11350. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11351. if (!mboxq) {
  11352. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11353. "2001 Unable to allocate memory for issuing "
  11354. "SLI_CONFIG_SPECIAL mailbox command\n");
  11355. return -ENOMEM;
  11356. }
  11357. /* Post all rpi memory regions to the port. */
  11358. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11359. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11360. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11361. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11362. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11363. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  11364. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11365. hdr_tmpl, rpi_page->page_count);
  11366. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11367. rpi_page->start_rpi);
  11368. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11369. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11370. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11371. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11372. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11373. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11374. if (rc != MBX_TIMEOUT)
  11375. mempool_free(mboxq, phba->mbox_mem_pool);
  11376. if (shdr_status || shdr_add_status || rc) {
  11377. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11378. "2514 POST_RPI_HDR mailbox failed with "
  11379. "status x%x add_status x%x, mbx status x%x\n",
  11380. shdr_status, shdr_add_status, rc);
  11381. rc = -ENXIO;
  11382. }
  11383. return rc;
  11384. }
  11385. /**
  11386. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11387. * @phba: pointer to lpfc hba data structure.
  11388. *
  11389. * This routine is invoked to post rpi header templates to the
  11390. * HBA consistent with the SLI-4 interface spec. This routine
  11391. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11392. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11393. *
  11394. * Returns
  11395. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11396. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11397. **/
  11398. int
  11399. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11400. {
  11401. int rpi;
  11402. uint16_t max_rpi, rpi_base, rpi_limit;
  11403. uint16_t rpi_remaining;
  11404. struct lpfc_rpi_hdr *rpi_hdr;
  11405. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11406. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11407. rpi_limit = phba->sli4_hba.next_rpi;
  11408. /*
  11409. * The valid rpi range is not guaranteed to be zero-based. Start
  11410. * the search at the rpi_base as reported by the port.
  11411. */
  11412. spin_lock_irq(&phba->hbalock);
  11413. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11414. if (rpi >= rpi_limit || rpi < rpi_base)
  11415. rpi = LPFC_RPI_ALLOC_ERROR;
  11416. else {
  11417. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11418. phba->sli4_hba.max_cfg_param.rpi_used++;
  11419. phba->sli4_hba.rpi_count++;
  11420. }
  11421. /*
  11422. * Don't try to allocate more rpi header regions if the device limit
  11423. * on available rpis max has been exhausted.
  11424. */
  11425. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11426. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11427. spin_unlock_irq(&phba->hbalock);
  11428. return rpi;
  11429. }
  11430. /*
  11431. * If the driver is running low on rpi resources, allocate another
  11432. * page now. Note that the next_rpi value is used because
  11433. * it represents how many are actually in use whereas max_rpi notes
  11434. * how many are supported max by the device.
  11435. */
  11436. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11437. phba->sli4_hba.rpi_count;
  11438. spin_unlock_irq(&phba->hbalock);
  11439. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11440. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11441. if (!rpi_hdr) {
  11442. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11443. "2002 Error Could not grow rpi "
  11444. "count\n");
  11445. } else {
  11446. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11447. }
  11448. }
  11449. return rpi;
  11450. }
  11451. /**
  11452. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11453. * @phba: pointer to lpfc hba data structure.
  11454. *
  11455. * This routine is invoked to release an rpi to the pool of
  11456. * available rpis maintained by the driver.
  11457. **/
  11458. void
  11459. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11460. {
  11461. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11462. phba->sli4_hba.rpi_count--;
  11463. phba->sli4_hba.max_cfg_param.rpi_used--;
  11464. }
  11465. }
  11466. /**
  11467. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11468. * @phba: pointer to lpfc hba data structure.
  11469. *
  11470. * This routine is invoked to release an rpi to the pool of
  11471. * available rpis maintained by the driver.
  11472. **/
  11473. void
  11474. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11475. {
  11476. spin_lock_irq(&phba->hbalock);
  11477. __lpfc_sli4_free_rpi(phba, rpi);
  11478. spin_unlock_irq(&phba->hbalock);
  11479. }
  11480. /**
  11481. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11482. * @phba: pointer to lpfc hba data structure.
  11483. *
  11484. * This routine is invoked to remove the memory region that
  11485. * provided rpi via a bitmask.
  11486. **/
  11487. void
  11488. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11489. {
  11490. kfree(phba->sli4_hba.rpi_bmask);
  11491. }
  11492. /**
  11493. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11494. * @phba: pointer to lpfc hba data structure.
  11495. *
  11496. * This routine is invoked to remove the memory region that
  11497. * provided rpi via a bitmask.
  11498. **/
  11499. int
  11500. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11501. {
  11502. LPFC_MBOXQ_t *mboxq;
  11503. struct lpfc_hba *phba = ndlp->phba;
  11504. int rc;
  11505. /* The port is notified of the header region via a mailbox command. */
  11506. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11507. if (!mboxq)
  11508. return -ENOMEM;
  11509. /* Post all rpi memory regions to the port. */
  11510. lpfc_resume_rpi(mboxq, ndlp);
  11511. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11512. if (rc == MBX_NOT_FINISHED) {
  11513. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11514. "2010 Resume RPI Mailbox failed "
  11515. "status %d, mbxStatus x%x\n", rc,
  11516. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11517. mempool_free(mboxq, phba->mbox_mem_pool);
  11518. return -EIO;
  11519. }
  11520. return 0;
  11521. }
  11522. /**
  11523. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11524. * @vport: Pointer to the vport for which the vpi is being initialized
  11525. *
  11526. * This routine is invoked to activate a vpi with the port.
  11527. *
  11528. * Returns:
  11529. * 0 success
  11530. * -Evalue otherwise
  11531. **/
  11532. int
  11533. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11534. {
  11535. LPFC_MBOXQ_t *mboxq;
  11536. int rc = 0;
  11537. int retval = MBX_SUCCESS;
  11538. uint32_t mbox_tmo;
  11539. struct lpfc_hba *phba = vport->phba;
  11540. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11541. if (!mboxq)
  11542. return -ENOMEM;
  11543. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11544. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11545. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11546. if (rc != MBX_SUCCESS) {
  11547. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11548. "2022 INIT VPI Mailbox failed "
  11549. "status %d, mbxStatus x%x\n", rc,
  11550. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11551. retval = -EIO;
  11552. }
  11553. if (rc != MBX_TIMEOUT)
  11554. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11555. return retval;
  11556. }
  11557. /**
  11558. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11559. * @phba: pointer to lpfc hba data structure.
  11560. * @mboxq: Pointer to mailbox object.
  11561. *
  11562. * This routine is invoked to manually add a single FCF record. The caller
  11563. * must pass a completely initialized FCF_Record. This routine takes
  11564. * care of the nonembedded mailbox operations.
  11565. **/
  11566. static void
  11567. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11568. {
  11569. void *virt_addr;
  11570. union lpfc_sli4_cfg_shdr *shdr;
  11571. uint32_t shdr_status, shdr_add_status;
  11572. virt_addr = mboxq->sge_array->addr[0];
  11573. /* The IOCTL status is embedded in the mailbox subheader. */
  11574. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11575. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11576. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11577. if ((shdr_status || shdr_add_status) &&
  11578. (shdr_status != STATUS_FCF_IN_USE))
  11579. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11580. "2558 ADD_FCF_RECORD mailbox failed with "
  11581. "status x%x add_status x%x\n",
  11582. shdr_status, shdr_add_status);
  11583. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11584. }
  11585. /**
  11586. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11587. * @phba: pointer to lpfc hba data structure.
  11588. * @fcf_record: pointer to the initialized fcf record to add.
  11589. *
  11590. * This routine is invoked to manually add a single FCF record. The caller
  11591. * must pass a completely initialized FCF_Record. This routine takes
  11592. * care of the nonembedded mailbox operations.
  11593. **/
  11594. int
  11595. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11596. {
  11597. int rc = 0;
  11598. LPFC_MBOXQ_t *mboxq;
  11599. uint8_t *bytep;
  11600. void *virt_addr;
  11601. dma_addr_t phys_addr;
  11602. struct lpfc_mbx_sge sge;
  11603. uint32_t alloc_len, req_len;
  11604. uint32_t fcfindex;
  11605. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11606. if (!mboxq) {
  11607. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11608. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11609. return -ENOMEM;
  11610. }
  11611. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11612. sizeof(uint32_t);
  11613. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11614. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11615. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11616. req_len, LPFC_SLI4_MBX_NEMBED);
  11617. if (alloc_len < req_len) {
  11618. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11619. "2523 Allocated DMA memory size (x%x) is "
  11620. "less than the requested DMA memory "
  11621. "size (x%x)\n", alloc_len, req_len);
  11622. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11623. return -ENOMEM;
  11624. }
  11625. /*
  11626. * Get the first SGE entry from the non-embedded DMA memory. This
  11627. * routine only uses a single SGE.
  11628. */
  11629. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11630. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11631. virt_addr = mboxq->sge_array->addr[0];
  11632. /*
  11633. * Configure the FCF record for FCFI 0. This is the driver's
  11634. * hardcoded default and gets used in nonFIP mode.
  11635. */
  11636. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11637. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11638. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11639. /*
  11640. * Copy the fcf_index and the FCF Record Data. The data starts after
  11641. * the FCoE header plus word10. The data copy needs to be endian
  11642. * correct.
  11643. */
  11644. bytep += sizeof(uint32_t);
  11645. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11646. mboxq->vport = phba->pport;
  11647. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11648. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11649. if (rc == MBX_NOT_FINISHED) {
  11650. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11651. "2515 ADD_FCF_RECORD mailbox failed with "
  11652. "status 0x%x\n", rc);
  11653. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11654. rc = -EIO;
  11655. } else
  11656. rc = 0;
  11657. return rc;
  11658. }
  11659. /**
  11660. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11661. * @phba: pointer to lpfc hba data structure.
  11662. * @fcf_record: pointer to the fcf record to write the default data.
  11663. * @fcf_index: FCF table entry index.
  11664. *
  11665. * This routine is invoked to build the driver's default FCF record. The
  11666. * values used are hardcoded. This routine handles memory initialization.
  11667. *
  11668. **/
  11669. void
  11670. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11671. struct fcf_record *fcf_record,
  11672. uint16_t fcf_index)
  11673. {
  11674. memset(fcf_record, 0, sizeof(struct fcf_record));
  11675. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11676. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11677. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11678. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11679. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11680. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11681. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11682. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11683. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11684. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11685. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11686. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11687. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11688. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11689. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11690. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11691. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11692. /* Set the VLAN bit map */
  11693. if (phba->valid_vlan) {
  11694. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11695. = 1 << (phba->vlan_id % 8);
  11696. }
  11697. }
  11698. /**
  11699. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11700. * @phba: pointer to lpfc hba data structure.
  11701. * @fcf_index: FCF table entry offset.
  11702. *
  11703. * This routine is invoked to scan the entire FCF table by reading FCF
  11704. * record and processing it one at a time starting from the @fcf_index
  11705. * for initial FCF discovery or fast FCF failover rediscovery.
  11706. *
  11707. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11708. * otherwise.
  11709. **/
  11710. int
  11711. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11712. {
  11713. int rc = 0, error;
  11714. LPFC_MBOXQ_t *mboxq;
  11715. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11716. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11717. if (!mboxq) {
  11718. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11719. "2000 Failed to allocate mbox for "
  11720. "READ_FCF cmd\n");
  11721. error = -ENOMEM;
  11722. goto fail_fcf_scan;
  11723. }
  11724. /* Construct the read FCF record mailbox command */
  11725. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11726. if (rc) {
  11727. error = -EINVAL;
  11728. goto fail_fcf_scan;
  11729. }
  11730. /* Issue the mailbox command asynchronously */
  11731. mboxq->vport = phba->pport;
  11732. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11733. spin_lock_irq(&phba->hbalock);
  11734. phba->hba_flag |= FCF_TS_INPROG;
  11735. spin_unlock_irq(&phba->hbalock);
  11736. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11737. if (rc == MBX_NOT_FINISHED)
  11738. error = -EIO;
  11739. else {
  11740. /* Reset eligible FCF count for new scan */
  11741. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11742. phba->fcf.eligible_fcf_cnt = 0;
  11743. error = 0;
  11744. }
  11745. fail_fcf_scan:
  11746. if (error) {
  11747. if (mboxq)
  11748. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11749. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11750. spin_lock_irq(&phba->hbalock);
  11751. phba->hba_flag &= ~FCF_TS_INPROG;
  11752. spin_unlock_irq(&phba->hbalock);
  11753. }
  11754. return error;
  11755. }
  11756. /**
  11757. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11758. * @phba: pointer to lpfc hba data structure.
  11759. * @fcf_index: FCF table entry offset.
  11760. *
  11761. * This routine is invoked to read an FCF record indicated by @fcf_index
  11762. * and to use it for FLOGI roundrobin FCF failover.
  11763. *
  11764. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11765. * otherwise.
  11766. **/
  11767. int
  11768. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11769. {
  11770. int rc = 0, error;
  11771. LPFC_MBOXQ_t *mboxq;
  11772. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11773. if (!mboxq) {
  11774. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11775. "2763 Failed to allocate mbox for "
  11776. "READ_FCF cmd\n");
  11777. error = -ENOMEM;
  11778. goto fail_fcf_read;
  11779. }
  11780. /* Construct the read FCF record mailbox command */
  11781. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11782. if (rc) {
  11783. error = -EINVAL;
  11784. goto fail_fcf_read;
  11785. }
  11786. /* Issue the mailbox command asynchronously */
  11787. mboxq->vport = phba->pport;
  11788. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11789. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11790. if (rc == MBX_NOT_FINISHED)
  11791. error = -EIO;
  11792. else
  11793. error = 0;
  11794. fail_fcf_read:
  11795. if (error && mboxq)
  11796. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11797. return error;
  11798. }
  11799. /**
  11800. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11801. * @phba: pointer to lpfc hba data structure.
  11802. * @fcf_index: FCF table entry offset.
  11803. *
  11804. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11805. * determine whether it's eligible for FLOGI roundrobin failover list.
  11806. *
  11807. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11808. * otherwise.
  11809. **/
  11810. int
  11811. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11812. {
  11813. int rc = 0, error;
  11814. LPFC_MBOXQ_t *mboxq;
  11815. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11816. if (!mboxq) {
  11817. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11818. "2758 Failed to allocate mbox for "
  11819. "READ_FCF cmd\n");
  11820. error = -ENOMEM;
  11821. goto fail_fcf_read;
  11822. }
  11823. /* Construct the read FCF record mailbox command */
  11824. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11825. if (rc) {
  11826. error = -EINVAL;
  11827. goto fail_fcf_read;
  11828. }
  11829. /* Issue the mailbox command asynchronously */
  11830. mboxq->vport = phba->pport;
  11831. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11832. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11833. if (rc == MBX_NOT_FINISHED)
  11834. error = -EIO;
  11835. else
  11836. error = 0;
  11837. fail_fcf_read:
  11838. if (error && mboxq)
  11839. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11840. return error;
  11841. }
  11842. /**
  11843. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11844. * @phba: pointer to lpfc hba data structure.
  11845. *
  11846. * This routine is to get the next eligible FCF record index in a round
  11847. * robin fashion. If the next eligible FCF record index equals to the
  11848. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11849. * shall be returned, otherwise, the next eligible FCF record's index
  11850. * shall be returned.
  11851. **/
  11852. uint16_t
  11853. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11854. {
  11855. uint16_t next_fcf_index;
  11856. /* Search start from next bit of currently registered FCF index */
  11857. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11858. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11859. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11860. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11861. next_fcf_index);
  11862. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11863. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11864. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11865. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11866. /* Check roundrobin failover list empty condition */
  11867. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11868. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11869. "2844 No roundrobin failover FCF available\n");
  11870. return LPFC_FCOE_FCF_NEXT_NONE;
  11871. }
  11872. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11873. "2845 Get next roundrobin failover FCF (x%x)\n",
  11874. next_fcf_index);
  11875. return next_fcf_index;
  11876. }
  11877. /**
  11878. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11879. * @phba: pointer to lpfc hba data structure.
  11880. *
  11881. * This routine sets the FCF record index in to the eligible bmask for
  11882. * roundrobin failover search. It checks to make sure that the index
  11883. * does not go beyond the range of the driver allocated bmask dimension
  11884. * before setting the bit.
  11885. *
  11886. * Returns 0 if the index bit successfully set, otherwise, it returns
  11887. * -EINVAL.
  11888. **/
  11889. int
  11890. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11891. {
  11892. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11893. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11894. "2610 FCF (x%x) reached driver's book "
  11895. "keeping dimension:x%x\n",
  11896. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11897. return -EINVAL;
  11898. }
  11899. /* Set the eligible FCF record index bmask */
  11900. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11901. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11902. "2790 Set FCF (x%x) to roundrobin FCF failover "
  11903. "bmask\n", fcf_index);
  11904. return 0;
  11905. }
  11906. /**
  11907. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11908. * @phba: pointer to lpfc hba data structure.
  11909. *
  11910. * This routine clears the FCF record index from the eligible bmask for
  11911. * roundrobin failover search. It checks to make sure that the index
  11912. * does not go beyond the range of the driver allocated bmask dimension
  11913. * before clearing the bit.
  11914. **/
  11915. void
  11916. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11917. {
  11918. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11919. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11920. "2762 FCF (x%x) reached driver's book "
  11921. "keeping dimension:x%x\n",
  11922. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11923. return;
  11924. }
  11925. /* Clear the eligible FCF record index bmask */
  11926. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11927. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11928. "2791 Clear FCF (x%x) from roundrobin failover "
  11929. "bmask\n", fcf_index);
  11930. }
  11931. /**
  11932. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11933. * @phba: pointer to lpfc hba data structure.
  11934. *
  11935. * This routine is the completion routine for the rediscover FCF table mailbox
  11936. * command. If the mailbox command returned failure, it will try to stop the
  11937. * FCF rediscover wait timer.
  11938. **/
  11939. void
  11940. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11941. {
  11942. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11943. uint32_t shdr_status, shdr_add_status;
  11944. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11945. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11946. &redisc_fcf->header.cfg_shdr.response);
  11947. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11948. &redisc_fcf->header.cfg_shdr.response);
  11949. if (shdr_status || shdr_add_status) {
  11950. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11951. "2746 Requesting for FCF rediscovery failed "
  11952. "status x%x add_status x%x\n",
  11953. shdr_status, shdr_add_status);
  11954. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11955. spin_lock_irq(&phba->hbalock);
  11956. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11957. spin_unlock_irq(&phba->hbalock);
  11958. /*
  11959. * CVL event triggered FCF rediscover request failed,
  11960. * last resort to re-try current registered FCF entry.
  11961. */
  11962. lpfc_retry_pport_discovery(phba);
  11963. } else {
  11964. spin_lock_irq(&phba->hbalock);
  11965. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11966. spin_unlock_irq(&phba->hbalock);
  11967. /*
  11968. * DEAD FCF event triggered FCF rediscover request
  11969. * failed, last resort to fail over as a link down
  11970. * to FCF registration.
  11971. */
  11972. lpfc_sli4_fcf_dead_failthrough(phba);
  11973. }
  11974. } else {
  11975. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11976. "2775 Start FCF rediscover quiescent timer\n");
  11977. /*
  11978. * Start FCF rediscovery wait timer for pending FCF
  11979. * before rescan FCF record table.
  11980. */
  11981. lpfc_fcf_redisc_wait_start_timer(phba);
  11982. }
  11983. mempool_free(mbox, phba->mbox_mem_pool);
  11984. }
  11985. /**
  11986. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11987. * @phba: pointer to lpfc hba data structure.
  11988. *
  11989. * This routine is invoked to request for rediscovery of the entire FCF table
  11990. * by the port.
  11991. **/
  11992. int
  11993. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11994. {
  11995. LPFC_MBOXQ_t *mbox;
  11996. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11997. int rc, length;
  11998. /* Cancel retry delay timers to all vports before FCF rediscover */
  11999. lpfc_cancel_all_vport_retry_delay_timer(phba);
  12000. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12001. if (!mbox) {
  12002. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12003. "2745 Failed to allocate mbox for "
  12004. "requesting FCF rediscover.\n");
  12005. return -ENOMEM;
  12006. }
  12007. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  12008. sizeof(struct lpfc_sli4_cfg_mhdr));
  12009. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12010. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  12011. length, LPFC_SLI4_MBX_EMBED);
  12012. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12013. /* Set count to 0 for invalidating the entire FCF database */
  12014. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  12015. /* Issue the mailbox command asynchronously */
  12016. mbox->vport = phba->pport;
  12017. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  12018. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  12019. if (rc == MBX_NOT_FINISHED) {
  12020. mempool_free(mbox, phba->mbox_mem_pool);
  12021. return -EIO;
  12022. }
  12023. return 0;
  12024. }
  12025. /**
  12026. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  12027. * @phba: pointer to lpfc hba data structure.
  12028. *
  12029. * This function is the failover routine as a last resort to the FCF DEAD
  12030. * event when driver failed to perform fast FCF failover.
  12031. **/
  12032. void
  12033. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  12034. {
  12035. uint32_t link_state;
  12036. /*
  12037. * Last resort as FCF DEAD event failover will treat this as
  12038. * a link down, but save the link state because we don't want
  12039. * it to be changed to Link Down unless it is already down.
  12040. */
  12041. link_state = phba->link_state;
  12042. lpfc_linkdown(phba);
  12043. phba->link_state = link_state;
  12044. /* Unregister FCF if no devices connected to it */
  12045. lpfc_unregister_unused_fcf(phba);
  12046. }
  12047. /**
  12048. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12049. * @phba: pointer to lpfc hba data structure.
  12050. *
  12051. * This function read region 23 and parse TLV for port status to
  12052. * decide if the user disaled the port. If the TLV indicates the
  12053. * port is disabled, the hba_flag is set accordingly.
  12054. **/
  12055. void
  12056. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12057. {
  12058. LPFC_MBOXQ_t *pmb = NULL;
  12059. MAILBOX_t *mb;
  12060. uint8_t *rgn23_data = NULL;
  12061. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12062. int rc;
  12063. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12064. if (!pmb) {
  12065. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12066. "2600 lpfc_sli_read_serdes_param failed to"
  12067. " allocate mailbox memory\n");
  12068. goto out;
  12069. }
  12070. mb = &pmb->u.mb;
  12071. /* Get adapter Region 23 data */
  12072. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12073. if (!rgn23_data)
  12074. goto out;
  12075. do {
  12076. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12077. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12078. if (rc != MBX_SUCCESS) {
  12079. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12080. "2601 lpfc_sli_read_link_ste failed to"
  12081. " read config region 23 rc 0x%x Status 0x%x\n",
  12082. rc, mb->mbxStatus);
  12083. mb->un.varDmp.word_cnt = 0;
  12084. }
  12085. /*
  12086. * dump mem may return a zero when finished or we got a
  12087. * mailbox error, either way we are done.
  12088. */
  12089. if (mb->un.varDmp.word_cnt == 0)
  12090. break;
  12091. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12092. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12093. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12094. rgn23_data + offset,
  12095. mb->un.varDmp.word_cnt);
  12096. offset += mb->un.varDmp.word_cnt;
  12097. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12098. data_size = offset;
  12099. offset = 0;
  12100. if (!data_size)
  12101. goto out;
  12102. /* Check the region signature first */
  12103. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12105. "2619 Config region 23 has bad signature\n");
  12106. goto out;
  12107. }
  12108. offset += 4;
  12109. /* Check the data structure version */
  12110. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12111. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12112. "2620 Config region 23 has bad version\n");
  12113. goto out;
  12114. }
  12115. offset += 4;
  12116. /* Parse TLV entries in the region */
  12117. while (offset < data_size) {
  12118. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12119. break;
  12120. /*
  12121. * If the TLV is not driver specific TLV or driver id is
  12122. * not linux driver id, skip the record.
  12123. */
  12124. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12125. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12126. (rgn23_data[offset + 3] != 0)) {
  12127. offset += rgn23_data[offset + 1] * 4 + 4;
  12128. continue;
  12129. }
  12130. /* Driver found a driver specific TLV in the config region */
  12131. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12132. offset += 4;
  12133. tlv_offset = 0;
  12134. /*
  12135. * Search for configured port state sub-TLV.
  12136. */
  12137. while ((offset < data_size) &&
  12138. (tlv_offset < sub_tlv_len)) {
  12139. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12140. offset += 4;
  12141. tlv_offset += 4;
  12142. break;
  12143. }
  12144. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12145. offset += rgn23_data[offset + 1] * 4 + 4;
  12146. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12147. continue;
  12148. }
  12149. /* This HBA contains PORT_STE configured */
  12150. if (!rgn23_data[offset + 2])
  12151. phba->hba_flag |= LINK_DISABLED;
  12152. goto out;
  12153. }
  12154. }
  12155. out:
  12156. if (pmb)
  12157. mempool_free(pmb, phba->mbox_mem_pool);
  12158. kfree(rgn23_data);
  12159. return;
  12160. }
  12161. /**
  12162. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12163. * @vport: pointer to vport data structure.
  12164. *
  12165. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12166. * and REG_VPI mailbox commands associated with the vport. This function
  12167. * is called when driver want to restart discovery of the vport due to
  12168. * a Clear Virtual Link event.
  12169. **/
  12170. void
  12171. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12172. {
  12173. struct lpfc_hba *phba = vport->phba;
  12174. LPFC_MBOXQ_t *mb, *nextmb;
  12175. struct lpfc_dmabuf *mp;
  12176. struct lpfc_nodelist *ndlp;
  12177. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12178. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12179. LIST_HEAD(mbox_cmd_list);
  12180. uint8_t restart_loop;
  12181. /* Clean up internally queued mailbox commands with the vport */
  12182. spin_lock_irq(&phba->hbalock);
  12183. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12184. if (mb->vport != vport)
  12185. continue;
  12186. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12187. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12188. continue;
  12189. list_del(&mb->list);
  12190. list_add_tail(&mb->list, &mbox_cmd_list);
  12191. }
  12192. /* Clean up active mailbox command with the vport */
  12193. mb = phba->sli.mbox_active;
  12194. if (mb && (mb->vport == vport)) {
  12195. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12196. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12197. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12198. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12199. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12200. /* Put reference count for delayed processing */
  12201. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12202. /* Unregister the RPI when mailbox complete */
  12203. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12204. }
  12205. }
  12206. /* Cleanup any mailbox completions which are not yet processed */
  12207. do {
  12208. restart_loop = 0;
  12209. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12210. /*
  12211. * If this mailox is already processed or it is
  12212. * for another vport ignore it.
  12213. */
  12214. if ((mb->vport != vport) ||
  12215. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12216. continue;
  12217. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12218. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12219. continue;
  12220. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12221. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12222. ndlp = (struct lpfc_nodelist *)mb->context2;
  12223. /* Unregister the RPI when mailbox complete */
  12224. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12225. restart_loop = 1;
  12226. spin_unlock_irq(&phba->hbalock);
  12227. spin_lock(shost->host_lock);
  12228. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12229. spin_unlock(shost->host_lock);
  12230. spin_lock_irq(&phba->hbalock);
  12231. break;
  12232. }
  12233. }
  12234. } while (restart_loop);
  12235. spin_unlock_irq(&phba->hbalock);
  12236. /* Release the cleaned-up mailbox commands */
  12237. while (!list_empty(&mbox_cmd_list)) {
  12238. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12239. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12240. mp = (struct lpfc_dmabuf *) (mb->context1);
  12241. if (mp) {
  12242. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12243. kfree(mp);
  12244. }
  12245. ndlp = (struct lpfc_nodelist *) mb->context2;
  12246. mb->context2 = NULL;
  12247. if (ndlp) {
  12248. spin_lock(shost->host_lock);
  12249. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12250. spin_unlock(shost->host_lock);
  12251. lpfc_nlp_put(ndlp);
  12252. }
  12253. }
  12254. mempool_free(mb, phba->mbox_mem_pool);
  12255. }
  12256. /* Release the ndlp with the cleaned-up active mailbox command */
  12257. if (act_mbx_ndlp) {
  12258. spin_lock(shost->host_lock);
  12259. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12260. spin_unlock(shost->host_lock);
  12261. lpfc_nlp_put(act_mbx_ndlp);
  12262. }
  12263. }
  12264. /**
  12265. * lpfc_drain_txq - Drain the txq
  12266. * @phba: Pointer to HBA context object.
  12267. *
  12268. * This function attempt to submit IOCBs on the txq
  12269. * to the adapter. For SLI4 adapters, the txq contains
  12270. * ELS IOCBs that have been deferred because the there
  12271. * are no SGLs. This congestion can occur with large
  12272. * vport counts during node discovery.
  12273. **/
  12274. uint32_t
  12275. lpfc_drain_txq(struct lpfc_hba *phba)
  12276. {
  12277. LIST_HEAD(completions);
  12278. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12279. struct lpfc_iocbq *piocbq = 0;
  12280. unsigned long iflags = 0;
  12281. char *fail_msg = NULL;
  12282. struct lpfc_sglq *sglq;
  12283. union lpfc_wqe wqe;
  12284. spin_lock_irqsave(&phba->hbalock, iflags);
  12285. if (pring->txq_cnt > pring->txq_max)
  12286. pring->txq_max = pring->txq_cnt;
  12287. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12288. while (pring->txq_cnt) {
  12289. spin_lock_irqsave(&phba->hbalock, iflags);
  12290. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12291. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12292. if (!sglq) {
  12293. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12294. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12295. break;
  12296. } else {
  12297. if (!piocbq) {
  12298. /* The txq_cnt out of sync. This should
  12299. * never happen
  12300. */
  12301. sglq = __lpfc_clear_active_sglq(phba,
  12302. sglq->sli4_xritag);
  12303. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12304. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12305. "2823 txq empty and txq_cnt is %d\n ",
  12306. pring->txq_cnt);
  12307. break;
  12308. }
  12309. }
  12310. /* The xri and iocb resources secured,
  12311. * attempt to issue request
  12312. */
  12313. piocbq->sli4_xritag = sglq->sli4_xritag;
  12314. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12315. fail_msg = "to convert bpl to sgl";
  12316. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12317. fail_msg = "to convert iocb to wqe";
  12318. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12319. fail_msg = " - Wq is full";
  12320. else
  12321. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12322. if (fail_msg) {
  12323. /* Failed means we can't issue and need to cancel */
  12324. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12325. "2822 IOCB failed %s iotag 0x%x "
  12326. "xri 0x%x\n",
  12327. fail_msg,
  12328. piocbq->iotag, piocbq->sli4_xritag);
  12329. list_add_tail(&piocbq->list, &completions);
  12330. }
  12331. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12332. }
  12333. /* Cancel all the IOCBs that cannot be issued */
  12334. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12335. IOERR_SLI_ABORTED);
  12336. return pring->txq_cnt;
  12337. }