lpfc_sli.c 398 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  473. * @phba: Pointer to HBA context object.
  474. *
  475. * This function is called with hbalock held. This function
  476. * Gets a new driver sglq object from the sglq list. If the
  477. * list is not empty then it is successful, it returns pointer to the newly
  478. * allocated sglq object else it returns NULL.
  479. **/
  480. static struct lpfc_sglq *
  481. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  482. {
  483. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  484. struct lpfc_sglq *sglq = NULL;
  485. uint16_t adj_xri;
  486. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  487. if (!sglq)
  488. return NULL;
  489. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  490. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  491. sglq->state = SGL_ALLOCATED;
  492. return sglq;
  493. }
  494. /**
  495. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  496. * @phba: Pointer to HBA context object.
  497. *
  498. * This function is called with no lock held. This function
  499. * allocates a new driver iocb object from the iocb pool. If the
  500. * allocation is successful, it returns pointer to the newly
  501. * allocated iocb object else it returns NULL.
  502. **/
  503. struct lpfc_iocbq *
  504. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  505. {
  506. struct lpfc_iocbq * iocbq = NULL;
  507. unsigned long iflags;
  508. spin_lock_irqsave(&phba->hbalock, iflags);
  509. iocbq = __lpfc_sli_get_iocbq(phba);
  510. spin_unlock_irqrestore(&phba->hbalock, iflags);
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  515. * @phba: Pointer to HBA context object.
  516. * @iocbq: Pointer to driver iocb object.
  517. *
  518. * This function is called with hbalock held to release driver
  519. * iocb object to the iocb pool. The iotag in the iocb object
  520. * does not change for each use of the iocb object. This function
  521. * clears all other fields of the iocb object when it is freed.
  522. * The sqlq structure that holds the xritag and phys and virtual
  523. * mappings for the scatter gather list is retrieved from the
  524. * active array of sglq. The get of the sglq pointer also clears
  525. * the entry in the array. If the status of the IO indiactes that
  526. * this IO was aborted then the sglq entry it put on the
  527. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  528. * IO has good status or fails for any other reason then the sglq
  529. * entry is added to the free list (lpfc_sgl_list).
  530. **/
  531. static void
  532. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  533. {
  534. struct lpfc_sglq *sglq;
  535. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  536. unsigned long iflag = 0;
  537. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  538. if (iocbq->sli4_xritag == NO_XRI)
  539. sglq = NULL;
  540. else
  541. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  542. if (sglq) {
  543. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  544. (sglq->state != SGL_XRI_ABORTED)) {
  545. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  546. iflag);
  547. list_add(&sglq->list,
  548. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  549. spin_unlock_irqrestore(
  550. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  551. } else {
  552. sglq->state = SGL_FREED;
  553. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  554. /* Check if TXQ queue needs to be serviced */
  555. if (pring->txq_cnt)
  556. lpfc_worker_wake_up(phba);
  557. }
  558. }
  559. /*
  560. * Clean all volatile data fields, preserve iotag and node struct.
  561. */
  562. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  563. iocbq->sli4_xritag = NO_XRI;
  564. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  565. }
  566. /**
  567. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  568. * @phba: Pointer to HBA context object.
  569. * @iocbq: Pointer to driver iocb object.
  570. *
  571. * This function is called with hbalock held to release driver
  572. * iocb object to the iocb pool. The iotag in the iocb object
  573. * does not change for each use of the iocb object. This function
  574. * clears all other fields of the iocb object when it is freed.
  575. **/
  576. static void
  577. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  578. {
  579. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  580. /*
  581. * Clean all volatile data fields, preserve iotag and node struct.
  582. */
  583. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  584. iocbq->sli4_xritag = NO_XRI;
  585. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  586. }
  587. /**
  588. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  589. * @phba: Pointer to HBA context object.
  590. * @iocbq: Pointer to driver iocb object.
  591. *
  592. * This function is called with hbalock held to release driver
  593. * iocb object to the iocb pool. The iotag in the iocb object
  594. * does not change for each use of the iocb object. This function
  595. * clears all other fields of the iocb object when it is freed.
  596. **/
  597. static void
  598. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  599. {
  600. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  601. phba->iocb_cnt--;
  602. }
  603. /**
  604. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  605. * @phba: Pointer to HBA context object.
  606. * @iocbq: Pointer to driver iocb object.
  607. *
  608. * This function is called with no lock held to release the iocb to
  609. * iocb pool.
  610. **/
  611. void
  612. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  613. {
  614. unsigned long iflags;
  615. /*
  616. * Clean all volatile data fields, preserve iotag and node struct.
  617. */
  618. spin_lock_irqsave(&phba->hbalock, iflags);
  619. __lpfc_sli_release_iocbq(phba, iocbq);
  620. spin_unlock_irqrestore(&phba->hbalock, iflags);
  621. }
  622. /**
  623. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  624. * @phba: Pointer to HBA context object.
  625. * @iocblist: List of IOCBs.
  626. * @ulpstatus: ULP status in IOCB command field.
  627. * @ulpWord4: ULP word-4 in IOCB command field.
  628. *
  629. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  630. * on the list by invoking the complete callback function associated with the
  631. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  632. * fields.
  633. **/
  634. void
  635. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  636. uint32_t ulpstatus, uint32_t ulpWord4)
  637. {
  638. struct lpfc_iocbq *piocb;
  639. while (!list_empty(iocblist)) {
  640. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  641. if (!piocb->iocb_cmpl)
  642. lpfc_sli_release_iocbq(phba, piocb);
  643. else {
  644. piocb->iocb.ulpStatus = ulpstatus;
  645. piocb->iocb.un.ulpWord[4] = ulpWord4;
  646. (piocb->iocb_cmpl) (phba, piocb, piocb);
  647. }
  648. }
  649. return;
  650. }
  651. /**
  652. * lpfc_sli_iocb_cmd_type - Get the iocb type
  653. * @iocb_cmnd: iocb command code.
  654. *
  655. * This function is called by ring event handler function to get the iocb type.
  656. * This function translates the iocb command to an iocb command type used to
  657. * decide the final disposition of each completed IOCB.
  658. * The function returns
  659. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  660. * LPFC_SOL_IOCB if it is a solicited iocb completion
  661. * LPFC_ABORT_IOCB if it is an abort iocb
  662. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  663. *
  664. * The caller is not required to hold any lock.
  665. **/
  666. static lpfc_iocb_type
  667. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  668. {
  669. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  670. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  671. return 0;
  672. switch (iocb_cmnd) {
  673. case CMD_XMIT_SEQUENCE_CR:
  674. case CMD_XMIT_SEQUENCE_CX:
  675. case CMD_XMIT_BCAST_CN:
  676. case CMD_XMIT_BCAST_CX:
  677. case CMD_ELS_REQUEST_CR:
  678. case CMD_ELS_REQUEST_CX:
  679. case CMD_CREATE_XRI_CR:
  680. case CMD_CREATE_XRI_CX:
  681. case CMD_GET_RPI_CN:
  682. case CMD_XMIT_ELS_RSP_CX:
  683. case CMD_GET_RPI_CR:
  684. case CMD_FCP_IWRITE_CR:
  685. case CMD_FCP_IWRITE_CX:
  686. case CMD_FCP_IREAD_CR:
  687. case CMD_FCP_IREAD_CX:
  688. case CMD_FCP_ICMND_CR:
  689. case CMD_FCP_ICMND_CX:
  690. case CMD_FCP_TSEND_CX:
  691. case CMD_FCP_TRSP_CX:
  692. case CMD_FCP_TRECEIVE_CX:
  693. case CMD_FCP_AUTO_TRSP_CX:
  694. case CMD_ADAPTER_MSG:
  695. case CMD_ADAPTER_DUMP:
  696. case CMD_XMIT_SEQUENCE64_CR:
  697. case CMD_XMIT_SEQUENCE64_CX:
  698. case CMD_XMIT_BCAST64_CN:
  699. case CMD_XMIT_BCAST64_CX:
  700. case CMD_ELS_REQUEST64_CR:
  701. case CMD_ELS_REQUEST64_CX:
  702. case CMD_FCP_IWRITE64_CR:
  703. case CMD_FCP_IWRITE64_CX:
  704. case CMD_FCP_IREAD64_CR:
  705. case CMD_FCP_IREAD64_CX:
  706. case CMD_FCP_ICMND64_CR:
  707. case CMD_FCP_ICMND64_CX:
  708. case CMD_FCP_TSEND64_CX:
  709. case CMD_FCP_TRSP64_CX:
  710. case CMD_FCP_TRECEIVE64_CX:
  711. case CMD_GEN_REQUEST64_CR:
  712. case CMD_GEN_REQUEST64_CX:
  713. case CMD_XMIT_ELS_RSP64_CX:
  714. case DSSCMD_IWRITE64_CR:
  715. case DSSCMD_IWRITE64_CX:
  716. case DSSCMD_IREAD64_CR:
  717. case DSSCMD_IREAD64_CX:
  718. type = LPFC_SOL_IOCB;
  719. break;
  720. case CMD_ABORT_XRI_CN:
  721. case CMD_ABORT_XRI_CX:
  722. case CMD_CLOSE_XRI_CN:
  723. case CMD_CLOSE_XRI_CX:
  724. case CMD_XRI_ABORTED_CX:
  725. case CMD_ABORT_MXRI64_CN:
  726. case CMD_XMIT_BLS_RSP64_CX:
  727. type = LPFC_ABORT_IOCB;
  728. break;
  729. case CMD_RCV_SEQUENCE_CX:
  730. case CMD_RCV_ELS_REQ_CX:
  731. case CMD_RCV_SEQUENCE64_CX:
  732. case CMD_RCV_ELS_REQ64_CX:
  733. case CMD_ASYNC_STATUS:
  734. case CMD_IOCB_RCV_SEQ64_CX:
  735. case CMD_IOCB_RCV_ELS64_CX:
  736. case CMD_IOCB_RCV_CONT64_CX:
  737. case CMD_IOCB_RET_XRI64_CX:
  738. type = LPFC_UNSOL_IOCB;
  739. break;
  740. case CMD_IOCB_XMIT_MSEQ64_CR:
  741. case CMD_IOCB_XMIT_MSEQ64_CX:
  742. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  743. case CMD_IOCB_RCV_ELS_LIST64_CX:
  744. case CMD_IOCB_CLOSE_EXTENDED_CN:
  745. case CMD_IOCB_ABORT_EXTENDED_CN:
  746. case CMD_IOCB_RET_HBQE64_CN:
  747. case CMD_IOCB_FCP_IBIDIR64_CR:
  748. case CMD_IOCB_FCP_IBIDIR64_CX:
  749. case CMD_IOCB_FCP_ITASKMGT64_CX:
  750. case CMD_IOCB_LOGENTRY_CN:
  751. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  752. printk("%s - Unhandled SLI-3 Command x%x\n",
  753. __func__, iocb_cmnd);
  754. type = LPFC_UNKNOWN_IOCB;
  755. break;
  756. default:
  757. type = LPFC_UNKNOWN_IOCB;
  758. break;
  759. }
  760. return type;
  761. }
  762. /**
  763. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  764. * @phba: Pointer to HBA context object.
  765. *
  766. * This function is called from SLI initialization code
  767. * to configure every ring of the HBA's SLI interface. The
  768. * caller is not required to hold any lock. This function issues
  769. * a config_ring mailbox command for each ring.
  770. * This function returns zero if successful else returns a negative
  771. * error code.
  772. **/
  773. static int
  774. lpfc_sli_ring_map(struct lpfc_hba *phba)
  775. {
  776. struct lpfc_sli *psli = &phba->sli;
  777. LPFC_MBOXQ_t *pmb;
  778. MAILBOX_t *pmbox;
  779. int i, rc, ret = 0;
  780. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  781. if (!pmb)
  782. return -ENOMEM;
  783. pmbox = &pmb->u.mb;
  784. phba->link_state = LPFC_INIT_MBX_CMDS;
  785. for (i = 0; i < psli->num_rings; i++) {
  786. lpfc_config_ring(phba, i, pmb);
  787. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  788. if (rc != MBX_SUCCESS) {
  789. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  790. "0446 Adapter failed to init (%d), "
  791. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  792. "ring %d\n",
  793. rc, pmbox->mbxCommand,
  794. pmbox->mbxStatus, i);
  795. phba->link_state = LPFC_HBA_ERROR;
  796. ret = -ENXIO;
  797. break;
  798. }
  799. }
  800. mempool_free(pmb, phba->mbox_mem_pool);
  801. return ret;
  802. }
  803. /**
  804. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  805. * @phba: Pointer to HBA context object.
  806. * @pring: Pointer to driver SLI ring object.
  807. * @piocb: Pointer to the driver iocb object.
  808. *
  809. * This function is called with hbalock held. The function adds the
  810. * new iocb to txcmplq of the given ring. This function always returns
  811. * 0. If this function is called for ELS ring, this function checks if
  812. * there is a vport associated with the ELS command. This function also
  813. * starts els_tmofunc timer if this is an ELS command.
  814. **/
  815. static int
  816. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  817. struct lpfc_iocbq *piocb)
  818. {
  819. list_add_tail(&piocb->list, &pring->txcmplq);
  820. piocb->iocb_flag |= LPFC_IO_ON_Q;
  821. pring->txcmplq_cnt++;
  822. if (pring->txcmplq_cnt > pring->txcmplq_max)
  823. pring->txcmplq_max = pring->txcmplq_cnt;
  824. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  825. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  826. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  827. if (!piocb->vport)
  828. BUG();
  829. else
  830. mod_timer(&piocb->vport->els_tmofunc,
  831. jiffies + HZ * (phba->fc_ratov << 1));
  832. }
  833. return 0;
  834. }
  835. /**
  836. * lpfc_sli_ringtx_get - Get first element of the txq
  837. * @phba: Pointer to HBA context object.
  838. * @pring: Pointer to driver SLI ring object.
  839. *
  840. * This function is called with hbalock held to get next
  841. * iocb in txq of the given ring. If there is any iocb in
  842. * the txq, the function returns first iocb in the list after
  843. * removing the iocb from the list, else it returns NULL.
  844. **/
  845. struct lpfc_iocbq *
  846. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  847. {
  848. struct lpfc_iocbq *cmd_iocb;
  849. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  850. if (cmd_iocb != NULL)
  851. pring->txq_cnt--;
  852. return cmd_iocb;
  853. }
  854. /**
  855. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  856. * @phba: Pointer to HBA context object.
  857. * @pring: Pointer to driver SLI ring object.
  858. *
  859. * This function is called with hbalock held and the caller must post the
  860. * iocb without releasing the lock. If the caller releases the lock,
  861. * iocb slot returned by the function is not guaranteed to be available.
  862. * The function returns pointer to the next available iocb slot if there
  863. * is available slot in the ring, else it returns NULL.
  864. * If the get index of the ring is ahead of the put index, the function
  865. * will post an error attention event to the worker thread to take the
  866. * HBA to offline state.
  867. **/
  868. static IOCB_t *
  869. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  870. {
  871. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  872. uint32_t max_cmd_idx = pring->numCiocb;
  873. if ((pring->next_cmdidx == pring->cmdidx) &&
  874. (++pring->next_cmdidx >= max_cmd_idx))
  875. pring->next_cmdidx = 0;
  876. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  877. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  878. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  879. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  880. "0315 Ring %d issue: portCmdGet %d "
  881. "is bigger than cmd ring %d\n",
  882. pring->ringno,
  883. pring->local_getidx, max_cmd_idx);
  884. phba->link_state = LPFC_HBA_ERROR;
  885. /*
  886. * All error attention handlers are posted to
  887. * worker thread
  888. */
  889. phba->work_ha |= HA_ERATT;
  890. phba->work_hs = HS_FFER3;
  891. lpfc_worker_wake_up(phba);
  892. return NULL;
  893. }
  894. if (pring->local_getidx == pring->next_cmdidx)
  895. return NULL;
  896. }
  897. return lpfc_cmd_iocb(phba, pring);
  898. }
  899. /**
  900. * lpfc_sli_next_iotag - Get an iotag for the iocb
  901. * @phba: Pointer to HBA context object.
  902. * @iocbq: Pointer to driver iocb object.
  903. *
  904. * This function gets an iotag for the iocb. If there is no unused iotag and
  905. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  906. * array and assigns a new iotag.
  907. * The function returns the allocated iotag if successful, else returns zero.
  908. * Zero is not a valid iotag.
  909. * The caller is not required to hold any lock.
  910. **/
  911. uint16_t
  912. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  913. {
  914. struct lpfc_iocbq **new_arr;
  915. struct lpfc_iocbq **old_arr;
  916. size_t new_len;
  917. struct lpfc_sli *psli = &phba->sli;
  918. uint16_t iotag;
  919. spin_lock_irq(&phba->hbalock);
  920. iotag = psli->last_iotag;
  921. if(++iotag < psli->iocbq_lookup_len) {
  922. psli->last_iotag = iotag;
  923. psli->iocbq_lookup[iotag] = iocbq;
  924. spin_unlock_irq(&phba->hbalock);
  925. iocbq->iotag = iotag;
  926. return iotag;
  927. } else if (psli->iocbq_lookup_len < (0xffff
  928. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  929. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  930. spin_unlock_irq(&phba->hbalock);
  931. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  932. GFP_KERNEL);
  933. if (new_arr) {
  934. spin_lock_irq(&phba->hbalock);
  935. old_arr = psli->iocbq_lookup;
  936. if (new_len <= psli->iocbq_lookup_len) {
  937. /* highly unprobable case */
  938. kfree(new_arr);
  939. iotag = psli->last_iotag;
  940. if(++iotag < psli->iocbq_lookup_len) {
  941. psli->last_iotag = iotag;
  942. psli->iocbq_lookup[iotag] = iocbq;
  943. spin_unlock_irq(&phba->hbalock);
  944. iocbq->iotag = iotag;
  945. return iotag;
  946. }
  947. spin_unlock_irq(&phba->hbalock);
  948. return 0;
  949. }
  950. if (psli->iocbq_lookup)
  951. memcpy(new_arr, old_arr,
  952. ((psli->last_iotag + 1) *
  953. sizeof (struct lpfc_iocbq *)));
  954. psli->iocbq_lookup = new_arr;
  955. psli->iocbq_lookup_len = new_len;
  956. psli->last_iotag = iotag;
  957. psli->iocbq_lookup[iotag] = iocbq;
  958. spin_unlock_irq(&phba->hbalock);
  959. iocbq->iotag = iotag;
  960. kfree(old_arr);
  961. return iotag;
  962. }
  963. } else
  964. spin_unlock_irq(&phba->hbalock);
  965. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  966. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  967. psli->last_iotag);
  968. return 0;
  969. }
  970. /**
  971. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  972. * @phba: Pointer to HBA context object.
  973. * @pring: Pointer to driver SLI ring object.
  974. * @iocb: Pointer to iocb slot in the ring.
  975. * @nextiocb: Pointer to driver iocb object which need to be
  976. * posted to firmware.
  977. *
  978. * This function is called with hbalock held to post a new iocb to
  979. * the firmware. This function copies the new iocb to ring iocb slot and
  980. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  981. * a completion call back for this iocb else the function will free the
  982. * iocb object.
  983. **/
  984. static void
  985. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  986. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  987. {
  988. /*
  989. * Set up an iotag
  990. */
  991. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  992. if (pring->ringno == LPFC_ELS_RING) {
  993. lpfc_debugfs_slow_ring_trc(phba,
  994. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  995. *(((uint32_t *) &nextiocb->iocb) + 4),
  996. *(((uint32_t *) &nextiocb->iocb) + 6),
  997. *(((uint32_t *) &nextiocb->iocb) + 7));
  998. }
  999. /*
  1000. * Issue iocb command to adapter
  1001. */
  1002. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1003. wmb();
  1004. pring->stats.iocb_cmd++;
  1005. /*
  1006. * If there is no completion routine to call, we can release the
  1007. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1008. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1009. */
  1010. if (nextiocb->iocb_cmpl)
  1011. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1012. else
  1013. __lpfc_sli_release_iocbq(phba, nextiocb);
  1014. /*
  1015. * Let the HBA know what IOCB slot will be the next one the
  1016. * driver will put a command into.
  1017. */
  1018. pring->cmdidx = pring->next_cmdidx;
  1019. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1020. }
  1021. /**
  1022. * lpfc_sli_update_full_ring - Update the chip attention register
  1023. * @phba: Pointer to HBA context object.
  1024. * @pring: Pointer to driver SLI ring object.
  1025. *
  1026. * The caller is not required to hold any lock for calling this function.
  1027. * This function updates the chip attention bits for the ring to inform firmware
  1028. * that there are pending work to be done for this ring and requests an
  1029. * interrupt when there is space available in the ring. This function is
  1030. * called when the driver is unable to post more iocbs to the ring due
  1031. * to unavailability of space in the ring.
  1032. **/
  1033. static void
  1034. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1035. {
  1036. int ringno = pring->ringno;
  1037. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1038. wmb();
  1039. /*
  1040. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1041. * The HBA will tell us when an IOCB entry is available.
  1042. */
  1043. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1044. readl(phba->CAregaddr); /* flush */
  1045. pring->stats.iocb_cmd_full++;
  1046. }
  1047. /**
  1048. * lpfc_sli_update_ring - Update chip attention register
  1049. * @phba: Pointer to HBA context object.
  1050. * @pring: Pointer to driver SLI ring object.
  1051. *
  1052. * This function updates the chip attention register bit for the
  1053. * given ring to inform HBA that there is more work to be done
  1054. * in this ring. The caller is not required to hold any lock.
  1055. **/
  1056. static void
  1057. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1058. {
  1059. int ringno = pring->ringno;
  1060. /*
  1061. * Tell the HBA that there is work to do in this ring.
  1062. */
  1063. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1064. wmb();
  1065. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1066. readl(phba->CAregaddr); /* flush */
  1067. }
  1068. }
  1069. /**
  1070. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1071. * @phba: Pointer to HBA context object.
  1072. * @pring: Pointer to driver SLI ring object.
  1073. *
  1074. * This function is called with hbalock held to post pending iocbs
  1075. * in the txq to the firmware. This function is called when driver
  1076. * detects space available in the ring.
  1077. **/
  1078. static void
  1079. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1080. {
  1081. IOCB_t *iocb;
  1082. struct lpfc_iocbq *nextiocb;
  1083. /*
  1084. * Check to see if:
  1085. * (a) there is anything on the txq to send
  1086. * (b) link is up
  1087. * (c) link attention events can be processed (fcp ring only)
  1088. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1089. */
  1090. if (pring->txq_cnt &&
  1091. lpfc_is_link_up(phba) &&
  1092. (pring->ringno != phba->sli.fcp_ring ||
  1093. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1094. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1095. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1096. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1097. if (iocb)
  1098. lpfc_sli_update_ring(phba, pring);
  1099. else
  1100. lpfc_sli_update_full_ring(phba, pring);
  1101. }
  1102. return;
  1103. }
  1104. /**
  1105. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1106. * @phba: Pointer to HBA context object.
  1107. * @hbqno: HBQ number.
  1108. *
  1109. * This function is called with hbalock held to get the next
  1110. * available slot for the given HBQ. If there is free slot
  1111. * available for the HBQ it will return pointer to the next available
  1112. * HBQ entry else it will return NULL.
  1113. **/
  1114. static struct lpfc_hbq_entry *
  1115. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1116. {
  1117. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1118. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1119. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1120. hbqp->next_hbqPutIdx = 0;
  1121. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1122. uint32_t raw_index = phba->hbq_get[hbqno];
  1123. uint32_t getidx = le32_to_cpu(raw_index);
  1124. hbqp->local_hbqGetIdx = getidx;
  1125. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1126. lpfc_printf_log(phba, KERN_ERR,
  1127. LOG_SLI | LOG_VPORT,
  1128. "1802 HBQ %d: local_hbqGetIdx "
  1129. "%u is > than hbqp->entry_count %u\n",
  1130. hbqno, hbqp->local_hbqGetIdx,
  1131. hbqp->entry_count);
  1132. phba->link_state = LPFC_HBA_ERROR;
  1133. return NULL;
  1134. }
  1135. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1136. return NULL;
  1137. }
  1138. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1139. hbqp->hbqPutIdx;
  1140. }
  1141. /**
  1142. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1143. * @phba: Pointer to HBA context object.
  1144. *
  1145. * This function is called with no lock held to free all the
  1146. * hbq buffers while uninitializing the SLI interface. It also
  1147. * frees the HBQ buffers returned by the firmware but not yet
  1148. * processed by the upper layers.
  1149. **/
  1150. void
  1151. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1152. {
  1153. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1154. struct hbq_dmabuf *hbq_buf;
  1155. unsigned long flags;
  1156. int i, hbq_count;
  1157. uint32_t hbqno;
  1158. hbq_count = lpfc_sli_hbq_count();
  1159. /* Return all memory used by all HBQs */
  1160. spin_lock_irqsave(&phba->hbalock, flags);
  1161. for (i = 0; i < hbq_count; ++i) {
  1162. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1163. &phba->hbqs[i].hbq_buffer_list, list) {
  1164. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1165. list_del(&hbq_buf->dbuf.list);
  1166. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1167. }
  1168. phba->hbqs[i].buffer_count = 0;
  1169. }
  1170. /* Return all HBQ buffer that are in-fly */
  1171. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1172. list) {
  1173. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1174. list_del(&hbq_buf->dbuf.list);
  1175. if (hbq_buf->tag == -1) {
  1176. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1177. (phba, hbq_buf);
  1178. } else {
  1179. hbqno = hbq_buf->tag >> 16;
  1180. if (hbqno >= LPFC_MAX_HBQS)
  1181. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1182. (phba, hbq_buf);
  1183. else
  1184. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1185. hbq_buf);
  1186. }
  1187. }
  1188. /* Mark the HBQs not in use */
  1189. phba->hbq_in_use = 0;
  1190. spin_unlock_irqrestore(&phba->hbalock, flags);
  1191. }
  1192. /**
  1193. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1194. * @phba: Pointer to HBA context object.
  1195. * @hbqno: HBQ number.
  1196. * @hbq_buf: Pointer to HBQ buffer.
  1197. *
  1198. * This function is called with the hbalock held to post a
  1199. * hbq buffer to the firmware. If the function finds an empty
  1200. * slot in the HBQ, it will post the buffer. The function will return
  1201. * pointer to the hbq entry if it successfully post the buffer
  1202. * else it will return NULL.
  1203. **/
  1204. static int
  1205. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1206. struct hbq_dmabuf *hbq_buf)
  1207. {
  1208. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1209. }
  1210. /**
  1211. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1212. * @phba: Pointer to HBA context object.
  1213. * @hbqno: HBQ number.
  1214. * @hbq_buf: Pointer to HBQ buffer.
  1215. *
  1216. * This function is called with the hbalock held to post a hbq buffer to the
  1217. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1218. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1219. * it successfully post the buffer else it will return an error.
  1220. **/
  1221. static int
  1222. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1223. struct hbq_dmabuf *hbq_buf)
  1224. {
  1225. struct lpfc_hbq_entry *hbqe;
  1226. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1227. /* Get next HBQ entry slot to use */
  1228. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1229. if (hbqe) {
  1230. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1231. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1232. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1233. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1234. hbqe->bde.tus.f.bdeFlags = 0;
  1235. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1236. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1237. /* Sync SLIM */
  1238. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1239. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1240. /* flush */
  1241. readl(phba->hbq_put + hbqno);
  1242. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1243. return 0;
  1244. } else
  1245. return -ENOMEM;
  1246. }
  1247. /**
  1248. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1249. * @phba: Pointer to HBA context object.
  1250. * @hbqno: HBQ number.
  1251. * @hbq_buf: Pointer to HBQ buffer.
  1252. *
  1253. * This function is called with the hbalock held to post an RQE to the SLI4
  1254. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1255. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1256. **/
  1257. static int
  1258. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1259. struct hbq_dmabuf *hbq_buf)
  1260. {
  1261. int rc;
  1262. struct lpfc_rqe hrqe;
  1263. struct lpfc_rqe drqe;
  1264. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1265. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1266. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1267. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1268. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1269. &hrqe, &drqe);
  1270. if (rc < 0)
  1271. return rc;
  1272. hbq_buf->tag = rc;
  1273. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1274. return 0;
  1275. }
  1276. /* HBQ for ELS and CT traffic. */
  1277. static struct lpfc_hbq_init lpfc_els_hbq = {
  1278. .rn = 1,
  1279. .entry_count = 256,
  1280. .mask_count = 0,
  1281. .profile = 0,
  1282. .ring_mask = (1 << LPFC_ELS_RING),
  1283. .buffer_count = 0,
  1284. .init_count = 40,
  1285. .add_count = 40,
  1286. };
  1287. /* HBQ for the extra ring if needed */
  1288. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1289. .rn = 1,
  1290. .entry_count = 200,
  1291. .mask_count = 0,
  1292. .profile = 0,
  1293. .ring_mask = (1 << LPFC_EXTRA_RING),
  1294. .buffer_count = 0,
  1295. .init_count = 0,
  1296. .add_count = 5,
  1297. };
  1298. /* Array of HBQs */
  1299. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1300. &lpfc_els_hbq,
  1301. &lpfc_extra_hbq,
  1302. };
  1303. /**
  1304. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1305. * @phba: Pointer to HBA context object.
  1306. * @hbqno: HBQ number.
  1307. * @count: Number of HBQ buffers to be posted.
  1308. *
  1309. * This function is called with no lock held to post more hbq buffers to the
  1310. * given HBQ. The function returns the number of HBQ buffers successfully
  1311. * posted.
  1312. **/
  1313. static int
  1314. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1315. {
  1316. uint32_t i, posted = 0;
  1317. unsigned long flags;
  1318. struct hbq_dmabuf *hbq_buffer;
  1319. LIST_HEAD(hbq_buf_list);
  1320. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1321. return 0;
  1322. if ((phba->hbqs[hbqno].buffer_count + count) >
  1323. lpfc_hbq_defs[hbqno]->entry_count)
  1324. count = lpfc_hbq_defs[hbqno]->entry_count -
  1325. phba->hbqs[hbqno].buffer_count;
  1326. if (!count)
  1327. return 0;
  1328. /* Allocate HBQ entries */
  1329. for (i = 0; i < count; i++) {
  1330. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1331. if (!hbq_buffer)
  1332. break;
  1333. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1334. }
  1335. /* Check whether HBQ is still in use */
  1336. spin_lock_irqsave(&phba->hbalock, flags);
  1337. if (!phba->hbq_in_use)
  1338. goto err;
  1339. while (!list_empty(&hbq_buf_list)) {
  1340. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1341. dbuf.list);
  1342. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1343. (hbqno << 16));
  1344. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1345. phba->hbqs[hbqno].buffer_count++;
  1346. posted++;
  1347. } else
  1348. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1349. }
  1350. spin_unlock_irqrestore(&phba->hbalock, flags);
  1351. return posted;
  1352. err:
  1353. spin_unlock_irqrestore(&phba->hbalock, flags);
  1354. while (!list_empty(&hbq_buf_list)) {
  1355. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1356. dbuf.list);
  1357. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1358. }
  1359. return 0;
  1360. }
  1361. /**
  1362. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1363. * @phba: Pointer to HBA context object.
  1364. * @qno: HBQ number.
  1365. *
  1366. * This function posts more buffers to the HBQ. This function
  1367. * is called with no lock held. The function returns the number of HBQ entries
  1368. * successfully allocated.
  1369. **/
  1370. int
  1371. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1372. {
  1373. if (phba->sli_rev == LPFC_SLI_REV4)
  1374. return 0;
  1375. else
  1376. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1377. lpfc_hbq_defs[qno]->add_count);
  1378. }
  1379. /**
  1380. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1381. * @phba: Pointer to HBA context object.
  1382. * @qno: HBQ queue number.
  1383. *
  1384. * This function is called from SLI initialization code path with
  1385. * no lock held to post initial HBQ buffers to firmware. The
  1386. * function returns the number of HBQ entries successfully allocated.
  1387. **/
  1388. static int
  1389. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1390. {
  1391. if (phba->sli_rev == LPFC_SLI_REV4)
  1392. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1393. lpfc_hbq_defs[qno]->entry_count);
  1394. else
  1395. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1396. lpfc_hbq_defs[qno]->init_count);
  1397. }
  1398. /**
  1399. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1400. * @phba: Pointer to HBA context object.
  1401. * @hbqno: HBQ number.
  1402. *
  1403. * This function removes the first hbq buffer on an hbq list and returns a
  1404. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1405. **/
  1406. static struct hbq_dmabuf *
  1407. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1408. {
  1409. struct lpfc_dmabuf *d_buf;
  1410. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1411. if (!d_buf)
  1412. return NULL;
  1413. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1414. }
  1415. /**
  1416. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1417. * @phba: Pointer to HBA context object.
  1418. * @tag: Tag of the hbq buffer.
  1419. *
  1420. * This function is called with hbalock held. This function searches
  1421. * for the hbq buffer associated with the given tag in the hbq buffer
  1422. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1423. * it returns NULL.
  1424. **/
  1425. static struct hbq_dmabuf *
  1426. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1427. {
  1428. struct lpfc_dmabuf *d_buf;
  1429. struct hbq_dmabuf *hbq_buf;
  1430. uint32_t hbqno;
  1431. hbqno = tag >> 16;
  1432. if (hbqno >= LPFC_MAX_HBQS)
  1433. return NULL;
  1434. spin_lock_irq(&phba->hbalock);
  1435. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1436. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1437. if (hbq_buf->tag == tag) {
  1438. spin_unlock_irq(&phba->hbalock);
  1439. return hbq_buf;
  1440. }
  1441. }
  1442. spin_unlock_irq(&phba->hbalock);
  1443. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1444. "1803 Bad hbq tag. Data: x%x x%x\n",
  1445. tag, phba->hbqs[tag >> 16].buffer_count);
  1446. return NULL;
  1447. }
  1448. /**
  1449. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1450. * @phba: Pointer to HBA context object.
  1451. * @hbq_buffer: Pointer to HBQ buffer.
  1452. *
  1453. * This function is called with hbalock. This function gives back
  1454. * the hbq buffer to firmware. If the HBQ does not have space to
  1455. * post the buffer, it will free the buffer.
  1456. **/
  1457. void
  1458. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1459. {
  1460. uint32_t hbqno;
  1461. if (hbq_buffer) {
  1462. hbqno = hbq_buffer->tag >> 16;
  1463. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1464. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1465. }
  1466. }
  1467. /**
  1468. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1469. * @mbxCommand: mailbox command code.
  1470. *
  1471. * This function is called by the mailbox event handler function to verify
  1472. * that the completed mailbox command is a legitimate mailbox command. If the
  1473. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1474. * and the mailbox event handler will take the HBA offline.
  1475. **/
  1476. static int
  1477. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1478. {
  1479. uint8_t ret;
  1480. switch (mbxCommand) {
  1481. case MBX_LOAD_SM:
  1482. case MBX_READ_NV:
  1483. case MBX_WRITE_NV:
  1484. case MBX_WRITE_VPARMS:
  1485. case MBX_RUN_BIU_DIAG:
  1486. case MBX_INIT_LINK:
  1487. case MBX_DOWN_LINK:
  1488. case MBX_CONFIG_LINK:
  1489. case MBX_CONFIG_RING:
  1490. case MBX_RESET_RING:
  1491. case MBX_READ_CONFIG:
  1492. case MBX_READ_RCONFIG:
  1493. case MBX_READ_SPARM:
  1494. case MBX_READ_STATUS:
  1495. case MBX_READ_RPI:
  1496. case MBX_READ_XRI:
  1497. case MBX_READ_REV:
  1498. case MBX_READ_LNK_STAT:
  1499. case MBX_REG_LOGIN:
  1500. case MBX_UNREG_LOGIN:
  1501. case MBX_READ_LA:
  1502. case MBX_CLEAR_LA:
  1503. case MBX_DUMP_MEMORY:
  1504. case MBX_DUMP_CONTEXT:
  1505. case MBX_RUN_DIAGS:
  1506. case MBX_RESTART:
  1507. case MBX_UPDATE_CFG:
  1508. case MBX_DOWN_LOAD:
  1509. case MBX_DEL_LD_ENTRY:
  1510. case MBX_RUN_PROGRAM:
  1511. case MBX_SET_MASK:
  1512. case MBX_SET_VARIABLE:
  1513. case MBX_UNREG_D_ID:
  1514. case MBX_KILL_BOARD:
  1515. case MBX_CONFIG_FARP:
  1516. case MBX_BEACON:
  1517. case MBX_LOAD_AREA:
  1518. case MBX_RUN_BIU_DIAG64:
  1519. case MBX_CONFIG_PORT:
  1520. case MBX_READ_SPARM64:
  1521. case MBX_READ_RPI64:
  1522. case MBX_REG_LOGIN64:
  1523. case MBX_READ_LA64:
  1524. case MBX_WRITE_WWN:
  1525. case MBX_SET_DEBUG:
  1526. case MBX_LOAD_EXP_ROM:
  1527. case MBX_ASYNCEVT_ENABLE:
  1528. case MBX_REG_VPI:
  1529. case MBX_UNREG_VPI:
  1530. case MBX_HEARTBEAT:
  1531. case MBX_PORT_CAPABILITIES:
  1532. case MBX_PORT_IOV_CONTROL:
  1533. case MBX_SLI4_CONFIG:
  1534. case MBX_SLI4_REQ_FTRS:
  1535. case MBX_REG_FCFI:
  1536. case MBX_UNREG_FCFI:
  1537. case MBX_REG_VFI:
  1538. case MBX_UNREG_VFI:
  1539. case MBX_INIT_VPI:
  1540. case MBX_INIT_VFI:
  1541. case MBX_RESUME_RPI:
  1542. case MBX_READ_EVENT_LOG_STATUS:
  1543. case MBX_READ_EVENT_LOG:
  1544. ret = mbxCommand;
  1545. break;
  1546. default:
  1547. ret = MBX_SHUTDOWN;
  1548. break;
  1549. }
  1550. return ret;
  1551. }
  1552. /**
  1553. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1554. * @phba: Pointer to HBA context object.
  1555. * @pmboxq: Pointer to mailbox command.
  1556. *
  1557. * This is completion handler function for mailbox commands issued from
  1558. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1559. * mailbox event handler function with no lock held. This function
  1560. * will wake up thread waiting on the wait queue pointed by context1
  1561. * of the mailbox.
  1562. **/
  1563. void
  1564. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1565. {
  1566. wait_queue_head_t *pdone_q;
  1567. unsigned long drvr_flag;
  1568. /*
  1569. * If pdone_q is empty, the driver thread gave up waiting and
  1570. * continued running.
  1571. */
  1572. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1573. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1574. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1575. if (pdone_q)
  1576. wake_up_interruptible(pdone_q);
  1577. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1578. return;
  1579. }
  1580. /**
  1581. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1582. * @phba: Pointer to HBA context object.
  1583. * @pmb: Pointer to mailbox object.
  1584. *
  1585. * This function is the default mailbox completion handler. It
  1586. * frees the memory resources associated with the completed mailbox
  1587. * command. If the completed command is a REG_LOGIN mailbox command,
  1588. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1589. **/
  1590. void
  1591. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1592. {
  1593. struct lpfc_dmabuf *mp;
  1594. uint16_t rpi, vpi;
  1595. int rc;
  1596. struct lpfc_vport *vport = pmb->vport;
  1597. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1598. if (mp) {
  1599. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1600. kfree(mp);
  1601. }
  1602. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1603. (phba->sli_rev == LPFC_SLI_REV4))
  1604. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1605. /*
  1606. * If a REG_LOGIN succeeded after node is destroyed or node
  1607. * is in re-discovery driver need to cleanup the RPI.
  1608. */
  1609. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1610. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1611. !pmb->u.mb.mbxStatus) {
  1612. rpi = pmb->u.mb.un.varWords[0];
  1613. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1614. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1615. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1616. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1617. if (rc != MBX_NOT_FINISHED)
  1618. return;
  1619. }
  1620. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1621. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1622. !(phba->pport->load_flag & FC_UNLOADING) &&
  1623. !pmb->u.mb.mbxStatus) {
  1624. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1625. pmb->vport = vport;
  1626. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1627. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1628. if (rc != MBX_NOT_FINISHED)
  1629. return;
  1630. }
  1631. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1632. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1633. else
  1634. mempool_free(pmb, phba->mbox_mem_pool);
  1635. }
  1636. /**
  1637. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1638. * @phba: Pointer to HBA context object.
  1639. *
  1640. * This function is called with no lock held. This function processes all
  1641. * the completed mailbox commands and gives it to upper layers. The interrupt
  1642. * service routine processes mailbox completion interrupt and adds completed
  1643. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1644. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1645. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1646. * function returns the mailbox commands to the upper layer by calling the
  1647. * completion handler function of each mailbox.
  1648. **/
  1649. int
  1650. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1651. {
  1652. MAILBOX_t *pmbox;
  1653. LPFC_MBOXQ_t *pmb;
  1654. int rc;
  1655. LIST_HEAD(cmplq);
  1656. phba->sli.slistat.mbox_event++;
  1657. /* Get all completed mailboxe buffers into the cmplq */
  1658. spin_lock_irq(&phba->hbalock);
  1659. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1660. spin_unlock_irq(&phba->hbalock);
  1661. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1662. do {
  1663. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1664. if (pmb == NULL)
  1665. break;
  1666. pmbox = &pmb->u.mb;
  1667. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1668. if (pmb->vport) {
  1669. lpfc_debugfs_disc_trc(pmb->vport,
  1670. LPFC_DISC_TRC_MBOX_VPORT,
  1671. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1672. (uint32_t)pmbox->mbxCommand,
  1673. pmbox->un.varWords[0],
  1674. pmbox->un.varWords[1]);
  1675. }
  1676. else {
  1677. lpfc_debugfs_disc_trc(phba->pport,
  1678. LPFC_DISC_TRC_MBOX,
  1679. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1680. (uint32_t)pmbox->mbxCommand,
  1681. pmbox->un.varWords[0],
  1682. pmbox->un.varWords[1]);
  1683. }
  1684. }
  1685. /*
  1686. * It is a fatal error if unknown mbox command completion.
  1687. */
  1688. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1689. MBX_SHUTDOWN) {
  1690. /* Unknown mailbox command compl */
  1691. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1692. "(%d):0323 Unknown Mailbox command "
  1693. "x%x (x%x) Cmpl\n",
  1694. pmb->vport ? pmb->vport->vpi : 0,
  1695. pmbox->mbxCommand,
  1696. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1697. phba->link_state = LPFC_HBA_ERROR;
  1698. phba->work_hs = HS_FFER3;
  1699. lpfc_handle_eratt(phba);
  1700. continue;
  1701. }
  1702. if (pmbox->mbxStatus) {
  1703. phba->sli.slistat.mbox_stat_err++;
  1704. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1705. /* Mbox cmd cmpl error - RETRYing */
  1706. lpfc_printf_log(phba, KERN_INFO,
  1707. LOG_MBOX | LOG_SLI,
  1708. "(%d):0305 Mbox cmd cmpl "
  1709. "error - RETRYing Data: x%x "
  1710. "(x%x) x%x x%x x%x\n",
  1711. pmb->vport ? pmb->vport->vpi :0,
  1712. pmbox->mbxCommand,
  1713. lpfc_sli4_mbox_opcode_get(phba,
  1714. pmb),
  1715. pmbox->mbxStatus,
  1716. pmbox->un.varWords[0],
  1717. pmb->vport->port_state);
  1718. pmbox->mbxStatus = 0;
  1719. pmbox->mbxOwner = OWN_HOST;
  1720. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1721. if (rc != MBX_NOT_FINISHED)
  1722. continue;
  1723. }
  1724. }
  1725. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1726. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1727. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1728. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1729. pmb->vport ? pmb->vport->vpi : 0,
  1730. pmbox->mbxCommand,
  1731. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1732. pmb->mbox_cmpl,
  1733. *((uint32_t *) pmbox),
  1734. pmbox->un.varWords[0],
  1735. pmbox->un.varWords[1],
  1736. pmbox->un.varWords[2],
  1737. pmbox->un.varWords[3],
  1738. pmbox->un.varWords[4],
  1739. pmbox->un.varWords[5],
  1740. pmbox->un.varWords[6],
  1741. pmbox->un.varWords[7]);
  1742. if (pmb->mbox_cmpl)
  1743. pmb->mbox_cmpl(phba,pmb);
  1744. } while (1);
  1745. return 0;
  1746. }
  1747. /**
  1748. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1749. * @phba: Pointer to HBA context object.
  1750. * @pring: Pointer to driver SLI ring object.
  1751. * @tag: buffer tag.
  1752. *
  1753. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1754. * is set in the tag the buffer is posted for a particular exchange,
  1755. * the function will return the buffer without replacing the buffer.
  1756. * If the buffer is for unsolicited ELS or CT traffic, this function
  1757. * returns the buffer and also posts another buffer to the firmware.
  1758. **/
  1759. static struct lpfc_dmabuf *
  1760. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1761. struct lpfc_sli_ring *pring,
  1762. uint32_t tag)
  1763. {
  1764. struct hbq_dmabuf *hbq_entry;
  1765. if (tag & QUE_BUFTAG_BIT)
  1766. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1767. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1768. if (!hbq_entry)
  1769. return NULL;
  1770. return &hbq_entry->dbuf;
  1771. }
  1772. /**
  1773. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1774. * @phba: Pointer to HBA context object.
  1775. * @pring: Pointer to driver SLI ring object.
  1776. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1777. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1778. * @fch_type: the type for the first frame of the sequence.
  1779. *
  1780. * This function is called with no lock held. This function uses the r_ctl and
  1781. * type of the received sequence to find the correct callback function to call
  1782. * to process the sequence.
  1783. **/
  1784. static int
  1785. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1786. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1787. uint32_t fch_type)
  1788. {
  1789. int i;
  1790. /* unSolicited Responses */
  1791. if (pring->prt[0].profile) {
  1792. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1793. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1794. saveq);
  1795. return 1;
  1796. }
  1797. /* We must search, based on rctl / type
  1798. for the right routine */
  1799. for (i = 0; i < pring->num_mask; i++) {
  1800. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1801. (pring->prt[i].type == fch_type)) {
  1802. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1803. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1804. (phba, pring, saveq);
  1805. return 1;
  1806. }
  1807. }
  1808. return 0;
  1809. }
  1810. /**
  1811. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1812. * @phba: Pointer to HBA context object.
  1813. * @pring: Pointer to driver SLI ring object.
  1814. * @saveq: Pointer to the unsolicited iocb.
  1815. *
  1816. * This function is called with no lock held by the ring event handler
  1817. * when there is an unsolicited iocb posted to the response ring by the
  1818. * firmware. This function gets the buffer associated with the iocbs
  1819. * and calls the event handler for the ring. This function handles both
  1820. * qring buffers and hbq buffers.
  1821. * When the function returns 1 the caller can free the iocb object otherwise
  1822. * upper layer functions will free the iocb objects.
  1823. **/
  1824. static int
  1825. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1826. struct lpfc_iocbq *saveq)
  1827. {
  1828. IOCB_t * irsp;
  1829. WORD5 * w5p;
  1830. uint32_t Rctl, Type;
  1831. uint32_t match;
  1832. struct lpfc_iocbq *iocbq;
  1833. struct lpfc_dmabuf *dmzbuf;
  1834. match = 0;
  1835. irsp = &(saveq->iocb);
  1836. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1837. if (pring->lpfc_sli_rcv_async_status)
  1838. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1839. else
  1840. lpfc_printf_log(phba,
  1841. KERN_WARNING,
  1842. LOG_SLI,
  1843. "0316 Ring %d handler: unexpected "
  1844. "ASYNC_STATUS iocb received evt_code "
  1845. "0x%x\n",
  1846. pring->ringno,
  1847. irsp->un.asyncstat.evt_code);
  1848. return 1;
  1849. }
  1850. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1851. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1852. if (irsp->ulpBdeCount > 0) {
  1853. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1854. irsp->un.ulpWord[3]);
  1855. lpfc_in_buf_free(phba, dmzbuf);
  1856. }
  1857. if (irsp->ulpBdeCount > 1) {
  1858. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1859. irsp->unsli3.sli3Words[3]);
  1860. lpfc_in_buf_free(phba, dmzbuf);
  1861. }
  1862. if (irsp->ulpBdeCount > 2) {
  1863. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1864. irsp->unsli3.sli3Words[7]);
  1865. lpfc_in_buf_free(phba, dmzbuf);
  1866. }
  1867. return 1;
  1868. }
  1869. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1870. if (irsp->ulpBdeCount != 0) {
  1871. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1872. irsp->un.ulpWord[3]);
  1873. if (!saveq->context2)
  1874. lpfc_printf_log(phba,
  1875. KERN_ERR,
  1876. LOG_SLI,
  1877. "0341 Ring %d Cannot find buffer for "
  1878. "an unsolicited iocb. tag 0x%x\n",
  1879. pring->ringno,
  1880. irsp->un.ulpWord[3]);
  1881. }
  1882. if (irsp->ulpBdeCount == 2) {
  1883. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1884. irsp->unsli3.sli3Words[7]);
  1885. if (!saveq->context3)
  1886. lpfc_printf_log(phba,
  1887. KERN_ERR,
  1888. LOG_SLI,
  1889. "0342 Ring %d Cannot find buffer for an"
  1890. " unsolicited iocb. tag 0x%x\n",
  1891. pring->ringno,
  1892. irsp->unsli3.sli3Words[7]);
  1893. }
  1894. list_for_each_entry(iocbq, &saveq->list, list) {
  1895. irsp = &(iocbq->iocb);
  1896. if (irsp->ulpBdeCount != 0) {
  1897. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1898. irsp->un.ulpWord[3]);
  1899. if (!iocbq->context2)
  1900. lpfc_printf_log(phba,
  1901. KERN_ERR,
  1902. LOG_SLI,
  1903. "0343 Ring %d Cannot find "
  1904. "buffer for an unsolicited iocb"
  1905. ". tag 0x%x\n", pring->ringno,
  1906. irsp->un.ulpWord[3]);
  1907. }
  1908. if (irsp->ulpBdeCount == 2) {
  1909. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1910. irsp->unsli3.sli3Words[7]);
  1911. if (!iocbq->context3)
  1912. lpfc_printf_log(phba,
  1913. KERN_ERR,
  1914. LOG_SLI,
  1915. "0344 Ring %d Cannot find "
  1916. "buffer for an unsolicited "
  1917. "iocb. tag 0x%x\n",
  1918. pring->ringno,
  1919. irsp->unsli3.sli3Words[7]);
  1920. }
  1921. }
  1922. }
  1923. if (irsp->ulpBdeCount != 0 &&
  1924. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1925. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1926. int found = 0;
  1927. /* search continue save q for same XRI */
  1928. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1929. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1930. list_add_tail(&saveq->list, &iocbq->list);
  1931. found = 1;
  1932. break;
  1933. }
  1934. }
  1935. if (!found)
  1936. list_add_tail(&saveq->clist,
  1937. &pring->iocb_continue_saveq);
  1938. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1939. list_del_init(&iocbq->clist);
  1940. saveq = iocbq;
  1941. irsp = &(saveq->iocb);
  1942. } else
  1943. return 0;
  1944. }
  1945. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1946. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1947. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1948. Rctl = FC_RCTL_ELS_REQ;
  1949. Type = FC_TYPE_ELS;
  1950. } else {
  1951. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1952. Rctl = w5p->hcsw.Rctl;
  1953. Type = w5p->hcsw.Type;
  1954. /* Firmware Workaround */
  1955. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1956. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1957. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1958. Rctl = FC_RCTL_ELS_REQ;
  1959. Type = FC_TYPE_ELS;
  1960. w5p->hcsw.Rctl = Rctl;
  1961. w5p->hcsw.Type = Type;
  1962. }
  1963. }
  1964. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1965. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1966. "0313 Ring %d handler: unexpected Rctl x%x "
  1967. "Type x%x received\n",
  1968. pring->ringno, Rctl, Type);
  1969. return 1;
  1970. }
  1971. /**
  1972. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1973. * @phba: Pointer to HBA context object.
  1974. * @pring: Pointer to driver SLI ring object.
  1975. * @prspiocb: Pointer to response iocb object.
  1976. *
  1977. * This function looks up the iocb_lookup table to get the command iocb
  1978. * corresponding to the given response iocb using the iotag of the
  1979. * response iocb. This function is called with the hbalock held.
  1980. * This function returns the command iocb object if it finds the command
  1981. * iocb else returns NULL.
  1982. **/
  1983. static struct lpfc_iocbq *
  1984. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1985. struct lpfc_sli_ring *pring,
  1986. struct lpfc_iocbq *prspiocb)
  1987. {
  1988. struct lpfc_iocbq *cmd_iocb = NULL;
  1989. uint16_t iotag;
  1990. iotag = prspiocb->iocb.ulpIoTag;
  1991. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1992. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1993. list_del_init(&cmd_iocb->list);
  1994. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  1995. pring->txcmplq_cnt--;
  1996. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  1997. }
  1998. return cmd_iocb;
  1999. }
  2000. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2001. "0317 iotag x%x is out off "
  2002. "range: max iotag x%x wd0 x%x\n",
  2003. iotag, phba->sli.last_iotag,
  2004. *(((uint32_t *) &prspiocb->iocb) + 7));
  2005. return NULL;
  2006. }
  2007. /**
  2008. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2009. * @phba: Pointer to HBA context object.
  2010. * @pring: Pointer to driver SLI ring object.
  2011. * @iotag: IOCB tag.
  2012. *
  2013. * This function looks up the iocb_lookup table to get the command iocb
  2014. * corresponding to the given iotag. This function is called with the
  2015. * hbalock held.
  2016. * This function returns the command iocb object if it finds the command
  2017. * iocb else returns NULL.
  2018. **/
  2019. static struct lpfc_iocbq *
  2020. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2021. struct lpfc_sli_ring *pring, uint16_t iotag)
  2022. {
  2023. struct lpfc_iocbq *cmd_iocb;
  2024. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2025. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2026. list_del_init(&cmd_iocb->list);
  2027. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2028. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2029. pring->txcmplq_cnt--;
  2030. }
  2031. return cmd_iocb;
  2032. }
  2033. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2034. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2035. iotag, phba->sli.last_iotag);
  2036. return NULL;
  2037. }
  2038. /**
  2039. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2040. * @phba: Pointer to HBA context object.
  2041. * @pring: Pointer to driver SLI ring object.
  2042. * @saveq: Pointer to the response iocb to be processed.
  2043. *
  2044. * This function is called by the ring event handler for non-fcp
  2045. * rings when there is a new response iocb in the response ring.
  2046. * The caller is not required to hold any locks. This function
  2047. * gets the command iocb associated with the response iocb and
  2048. * calls the completion handler for the command iocb. If there
  2049. * is no completion handler, the function will free the resources
  2050. * associated with command iocb. If the response iocb is for
  2051. * an already aborted command iocb, the status of the completion
  2052. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2053. * This function always returns 1.
  2054. **/
  2055. static int
  2056. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2057. struct lpfc_iocbq *saveq)
  2058. {
  2059. struct lpfc_iocbq *cmdiocbp;
  2060. int rc = 1;
  2061. unsigned long iflag;
  2062. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2063. spin_lock_irqsave(&phba->hbalock, iflag);
  2064. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2065. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2066. if (cmdiocbp) {
  2067. if (cmdiocbp->iocb_cmpl) {
  2068. /*
  2069. * If an ELS command failed send an event to mgmt
  2070. * application.
  2071. */
  2072. if (saveq->iocb.ulpStatus &&
  2073. (pring->ringno == LPFC_ELS_RING) &&
  2074. (cmdiocbp->iocb.ulpCommand ==
  2075. CMD_ELS_REQUEST64_CR))
  2076. lpfc_send_els_failure_event(phba,
  2077. cmdiocbp, saveq);
  2078. /*
  2079. * Post all ELS completions to the worker thread.
  2080. * All other are passed to the completion callback.
  2081. */
  2082. if (pring->ringno == LPFC_ELS_RING) {
  2083. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2084. (cmdiocbp->iocb_flag &
  2085. LPFC_DRIVER_ABORTED)) {
  2086. spin_lock_irqsave(&phba->hbalock,
  2087. iflag);
  2088. cmdiocbp->iocb_flag &=
  2089. ~LPFC_DRIVER_ABORTED;
  2090. spin_unlock_irqrestore(&phba->hbalock,
  2091. iflag);
  2092. saveq->iocb.ulpStatus =
  2093. IOSTAT_LOCAL_REJECT;
  2094. saveq->iocb.un.ulpWord[4] =
  2095. IOERR_SLI_ABORTED;
  2096. /* Firmware could still be in progress
  2097. * of DMAing payload, so don't free data
  2098. * buffer till after a hbeat.
  2099. */
  2100. spin_lock_irqsave(&phba->hbalock,
  2101. iflag);
  2102. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2103. spin_unlock_irqrestore(&phba->hbalock,
  2104. iflag);
  2105. }
  2106. if (phba->sli_rev == LPFC_SLI_REV4) {
  2107. if (saveq->iocb_flag &
  2108. LPFC_EXCHANGE_BUSY) {
  2109. /* Set cmdiocb flag for the
  2110. * exchange busy so sgl (xri)
  2111. * will not be released until
  2112. * the abort xri is received
  2113. * from hba.
  2114. */
  2115. spin_lock_irqsave(
  2116. &phba->hbalock, iflag);
  2117. cmdiocbp->iocb_flag |=
  2118. LPFC_EXCHANGE_BUSY;
  2119. spin_unlock_irqrestore(
  2120. &phba->hbalock, iflag);
  2121. }
  2122. if (cmdiocbp->iocb_flag &
  2123. LPFC_DRIVER_ABORTED) {
  2124. /*
  2125. * Clear LPFC_DRIVER_ABORTED
  2126. * bit in case it was driver
  2127. * initiated abort.
  2128. */
  2129. spin_lock_irqsave(
  2130. &phba->hbalock, iflag);
  2131. cmdiocbp->iocb_flag &=
  2132. ~LPFC_DRIVER_ABORTED;
  2133. spin_unlock_irqrestore(
  2134. &phba->hbalock, iflag);
  2135. cmdiocbp->iocb.ulpStatus =
  2136. IOSTAT_LOCAL_REJECT;
  2137. cmdiocbp->iocb.un.ulpWord[4] =
  2138. IOERR_ABORT_REQUESTED;
  2139. /*
  2140. * For SLI4, irsiocb contains
  2141. * NO_XRI in sli_xritag, it
  2142. * shall not affect releasing
  2143. * sgl (xri) process.
  2144. */
  2145. saveq->iocb.ulpStatus =
  2146. IOSTAT_LOCAL_REJECT;
  2147. saveq->iocb.un.ulpWord[4] =
  2148. IOERR_SLI_ABORTED;
  2149. spin_lock_irqsave(
  2150. &phba->hbalock, iflag);
  2151. saveq->iocb_flag |=
  2152. LPFC_DELAY_MEM_FREE;
  2153. spin_unlock_irqrestore(
  2154. &phba->hbalock, iflag);
  2155. }
  2156. }
  2157. }
  2158. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2159. } else
  2160. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2161. } else {
  2162. /*
  2163. * Unknown initiating command based on the response iotag.
  2164. * This could be the case on the ELS ring because of
  2165. * lpfc_els_abort().
  2166. */
  2167. if (pring->ringno != LPFC_ELS_RING) {
  2168. /*
  2169. * Ring <ringno> handler: unexpected completion IoTag
  2170. * <IoTag>
  2171. */
  2172. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2173. "0322 Ring %d handler: "
  2174. "unexpected completion IoTag x%x "
  2175. "Data: x%x x%x x%x x%x\n",
  2176. pring->ringno,
  2177. saveq->iocb.ulpIoTag,
  2178. saveq->iocb.ulpStatus,
  2179. saveq->iocb.un.ulpWord[4],
  2180. saveq->iocb.ulpCommand,
  2181. saveq->iocb.ulpContext);
  2182. }
  2183. }
  2184. return rc;
  2185. }
  2186. /**
  2187. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2188. * @phba: Pointer to HBA context object.
  2189. * @pring: Pointer to driver SLI ring object.
  2190. *
  2191. * This function is called from the iocb ring event handlers when
  2192. * put pointer is ahead of the get pointer for a ring. This function signal
  2193. * an error attention condition to the worker thread and the worker
  2194. * thread will transition the HBA to offline state.
  2195. **/
  2196. static void
  2197. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2198. {
  2199. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2200. /*
  2201. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2202. * rsp ring <portRspMax>
  2203. */
  2204. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2205. "0312 Ring %d handler: portRspPut %d "
  2206. "is bigger than rsp ring %d\n",
  2207. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2208. pring->numRiocb);
  2209. phba->link_state = LPFC_HBA_ERROR;
  2210. /*
  2211. * All error attention handlers are posted to
  2212. * worker thread
  2213. */
  2214. phba->work_ha |= HA_ERATT;
  2215. phba->work_hs = HS_FFER3;
  2216. lpfc_worker_wake_up(phba);
  2217. return;
  2218. }
  2219. /**
  2220. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2221. * @ptr: Pointer to address of HBA context object.
  2222. *
  2223. * This function is invoked by the Error Attention polling timer when the
  2224. * timer times out. It will check the SLI Error Attention register for
  2225. * possible attention events. If so, it will post an Error Attention event
  2226. * and wake up worker thread to process it. Otherwise, it will set up the
  2227. * Error Attention polling timer for the next poll.
  2228. **/
  2229. void lpfc_poll_eratt(unsigned long ptr)
  2230. {
  2231. struct lpfc_hba *phba;
  2232. uint32_t eratt = 0;
  2233. phba = (struct lpfc_hba *)ptr;
  2234. /* Check chip HA register for error event */
  2235. eratt = lpfc_sli_check_eratt(phba);
  2236. if (eratt)
  2237. /* Tell the worker thread there is work to do */
  2238. lpfc_worker_wake_up(phba);
  2239. else
  2240. /* Restart the timer for next eratt poll */
  2241. mod_timer(&phba->eratt_poll, jiffies +
  2242. HZ * LPFC_ERATT_POLL_INTERVAL);
  2243. return;
  2244. }
  2245. /**
  2246. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2247. * @phba: Pointer to HBA context object.
  2248. * @pring: Pointer to driver SLI ring object.
  2249. * @mask: Host attention register mask for this ring.
  2250. *
  2251. * This function is called from the interrupt context when there is a ring
  2252. * event for the fcp ring. The caller does not hold any lock.
  2253. * The function processes each response iocb in the response ring until it
  2254. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2255. * LE bit set. The function will call the completion handler of the command iocb
  2256. * if the response iocb indicates a completion for a command iocb or it is
  2257. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2258. * function if this is an unsolicited iocb.
  2259. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2260. * to check it explicitly.
  2261. */
  2262. int
  2263. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2264. struct lpfc_sli_ring *pring, uint32_t mask)
  2265. {
  2266. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2267. IOCB_t *irsp = NULL;
  2268. IOCB_t *entry = NULL;
  2269. struct lpfc_iocbq *cmdiocbq = NULL;
  2270. struct lpfc_iocbq rspiocbq;
  2271. uint32_t status;
  2272. uint32_t portRspPut, portRspMax;
  2273. int rc = 1;
  2274. lpfc_iocb_type type;
  2275. unsigned long iflag;
  2276. uint32_t rsp_cmpl = 0;
  2277. spin_lock_irqsave(&phba->hbalock, iflag);
  2278. pring->stats.iocb_event++;
  2279. /*
  2280. * The next available response entry should never exceed the maximum
  2281. * entries. If it does, treat it as an adapter hardware error.
  2282. */
  2283. portRspMax = pring->numRiocb;
  2284. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2285. if (unlikely(portRspPut >= portRspMax)) {
  2286. lpfc_sli_rsp_pointers_error(phba, pring);
  2287. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2288. return 1;
  2289. }
  2290. if (phba->fcp_ring_in_use) {
  2291. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2292. return 1;
  2293. } else
  2294. phba->fcp_ring_in_use = 1;
  2295. rmb();
  2296. while (pring->rspidx != portRspPut) {
  2297. /*
  2298. * Fetch an entry off the ring and copy it into a local data
  2299. * structure. The copy involves a byte-swap since the
  2300. * network byte order and pci byte orders are different.
  2301. */
  2302. entry = lpfc_resp_iocb(phba, pring);
  2303. phba->last_completion_time = jiffies;
  2304. if (++pring->rspidx >= portRspMax)
  2305. pring->rspidx = 0;
  2306. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2307. (uint32_t *) &rspiocbq.iocb,
  2308. phba->iocb_rsp_size);
  2309. INIT_LIST_HEAD(&(rspiocbq.list));
  2310. irsp = &rspiocbq.iocb;
  2311. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2312. pring->stats.iocb_rsp++;
  2313. rsp_cmpl++;
  2314. if (unlikely(irsp->ulpStatus)) {
  2315. /*
  2316. * If resource errors reported from HBA, reduce
  2317. * queuedepths of the SCSI device.
  2318. */
  2319. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2320. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2321. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2322. phba->lpfc_rampdown_queue_depth(phba);
  2323. spin_lock_irqsave(&phba->hbalock, iflag);
  2324. }
  2325. /* Rsp ring <ringno> error: IOCB */
  2326. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2327. "0336 Rsp Ring %d error: IOCB Data: "
  2328. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2329. pring->ringno,
  2330. irsp->un.ulpWord[0],
  2331. irsp->un.ulpWord[1],
  2332. irsp->un.ulpWord[2],
  2333. irsp->un.ulpWord[3],
  2334. irsp->un.ulpWord[4],
  2335. irsp->un.ulpWord[5],
  2336. *(uint32_t *)&irsp->un1,
  2337. *((uint32_t *)&irsp->un1 + 1));
  2338. }
  2339. switch (type) {
  2340. case LPFC_ABORT_IOCB:
  2341. case LPFC_SOL_IOCB:
  2342. /*
  2343. * Idle exchange closed via ABTS from port. No iocb
  2344. * resources need to be recovered.
  2345. */
  2346. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2347. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2348. "0333 IOCB cmd 0x%x"
  2349. " processed. Skipping"
  2350. " completion\n",
  2351. irsp->ulpCommand);
  2352. break;
  2353. }
  2354. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2355. &rspiocbq);
  2356. if (unlikely(!cmdiocbq))
  2357. break;
  2358. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2359. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2360. if (cmdiocbq->iocb_cmpl) {
  2361. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2362. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2363. &rspiocbq);
  2364. spin_lock_irqsave(&phba->hbalock, iflag);
  2365. }
  2366. break;
  2367. case LPFC_UNSOL_IOCB:
  2368. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2369. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2370. spin_lock_irqsave(&phba->hbalock, iflag);
  2371. break;
  2372. default:
  2373. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2374. char adaptermsg[LPFC_MAX_ADPTMSG];
  2375. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2376. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2377. MAX_MSG_DATA);
  2378. dev_warn(&((phba->pcidev)->dev),
  2379. "lpfc%d: %s\n",
  2380. phba->brd_no, adaptermsg);
  2381. } else {
  2382. /* Unknown IOCB command */
  2383. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2384. "0334 Unknown IOCB command "
  2385. "Data: x%x, x%x x%x x%x x%x\n",
  2386. type, irsp->ulpCommand,
  2387. irsp->ulpStatus,
  2388. irsp->ulpIoTag,
  2389. irsp->ulpContext);
  2390. }
  2391. break;
  2392. }
  2393. /*
  2394. * The response IOCB has been processed. Update the ring
  2395. * pointer in SLIM. If the port response put pointer has not
  2396. * been updated, sync the pgp->rspPutInx and fetch the new port
  2397. * response put pointer.
  2398. */
  2399. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2400. if (pring->rspidx == portRspPut)
  2401. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2402. }
  2403. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2404. pring->stats.iocb_rsp_full++;
  2405. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2406. writel(status, phba->CAregaddr);
  2407. readl(phba->CAregaddr);
  2408. }
  2409. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2410. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2411. pring->stats.iocb_cmd_empty++;
  2412. /* Force update of the local copy of cmdGetInx */
  2413. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2414. lpfc_sli_resume_iocb(phba, pring);
  2415. if ((pring->lpfc_sli_cmd_available))
  2416. (pring->lpfc_sli_cmd_available) (phba, pring);
  2417. }
  2418. phba->fcp_ring_in_use = 0;
  2419. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2420. return rc;
  2421. }
  2422. /**
  2423. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2424. * @phba: Pointer to HBA context object.
  2425. * @pring: Pointer to driver SLI ring object.
  2426. * @rspiocbp: Pointer to driver response IOCB object.
  2427. *
  2428. * This function is called from the worker thread when there is a slow-path
  2429. * response IOCB to process. This function chains all the response iocbs until
  2430. * seeing the iocb with the LE bit set. The function will call
  2431. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2432. * completion of a command iocb. The function will call the
  2433. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2434. * The function frees the resources or calls the completion handler if this
  2435. * iocb is an abort completion. The function returns NULL when the response
  2436. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2437. * this function shall chain the iocb on to the iocb_continueq and return the
  2438. * response iocb passed in.
  2439. **/
  2440. static struct lpfc_iocbq *
  2441. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2442. struct lpfc_iocbq *rspiocbp)
  2443. {
  2444. struct lpfc_iocbq *saveq;
  2445. struct lpfc_iocbq *cmdiocbp;
  2446. struct lpfc_iocbq *next_iocb;
  2447. IOCB_t *irsp = NULL;
  2448. uint32_t free_saveq;
  2449. uint8_t iocb_cmd_type;
  2450. lpfc_iocb_type type;
  2451. unsigned long iflag;
  2452. int rc;
  2453. spin_lock_irqsave(&phba->hbalock, iflag);
  2454. /* First add the response iocb to the countinueq list */
  2455. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2456. pring->iocb_continueq_cnt++;
  2457. /* Now, determine whetehr the list is completed for processing */
  2458. irsp = &rspiocbp->iocb;
  2459. if (irsp->ulpLe) {
  2460. /*
  2461. * By default, the driver expects to free all resources
  2462. * associated with this iocb completion.
  2463. */
  2464. free_saveq = 1;
  2465. saveq = list_get_first(&pring->iocb_continueq,
  2466. struct lpfc_iocbq, list);
  2467. irsp = &(saveq->iocb);
  2468. list_del_init(&pring->iocb_continueq);
  2469. pring->iocb_continueq_cnt = 0;
  2470. pring->stats.iocb_rsp++;
  2471. /*
  2472. * If resource errors reported from HBA, reduce
  2473. * queuedepths of the SCSI device.
  2474. */
  2475. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2476. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2477. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2478. phba->lpfc_rampdown_queue_depth(phba);
  2479. spin_lock_irqsave(&phba->hbalock, iflag);
  2480. }
  2481. if (irsp->ulpStatus) {
  2482. /* Rsp ring <ringno> error: IOCB */
  2483. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2484. "0328 Rsp Ring %d error: "
  2485. "IOCB Data: "
  2486. "x%x x%x x%x x%x "
  2487. "x%x x%x x%x x%x "
  2488. "x%x x%x x%x x%x "
  2489. "x%x x%x x%x x%x\n",
  2490. pring->ringno,
  2491. irsp->un.ulpWord[0],
  2492. irsp->un.ulpWord[1],
  2493. irsp->un.ulpWord[2],
  2494. irsp->un.ulpWord[3],
  2495. irsp->un.ulpWord[4],
  2496. irsp->un.ulpWord[5],
  2497. *(((uint32_t *) irsp) + 6),
  2498. *(((uint32_t *) irsp) + 7),
  2499. *(((uint32_t *) irsp) + 8),
  2500. *(((uint32_t *) irsp) + 9),
  2501. *(((uint32_t *) irsp) + 10),
  2502. *(((uint32_t *) irsp) + 11),
  2503. *(((uint32_t *) irsp) + 12),
  2504. *(((uint32_t *) irsp) + 13),
  2505. *(((uint32_t *) irsp) + 14),
  2506. *(((uint32_t *) irsp) + 15));
  2507. }
  2508. /*
  2509. * Fetch the IOCB command type and call the correct completion
  2510. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2511. * get freed back to the lpfc_iocb_list by the discovery
  2512. * kernel thread.
  2513. */
  2514. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2515. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2516. switch (type) {
  2517. case LPFC_SOL_IOCB:
  2518. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2519. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2520. spin_lock_irqsave(&phba->hbalock, iflag);
  2521. break;
  2522. case LPFC_UNSOL_IOCB:
  2523. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2524. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2525. spin_lock_irqsave(&phba->hbalock, iflag);
  2526. if (!rc)
  2527. free_saveq = 0;
  2528. break;
  2529. case LPFC_ABORT_IOCB:
  2530. cmdiocbp = NULL;
  2531. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2532. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2533. saveq);
  2534. if (cmdiocbp) {
  2535. /* Call the specified completion routine */
  2536. if (cmdiocbp->iocb_cmpl) {
  2537. spin_unlock_irqrestore(&phba->hbalock,
  2538. iflag);
  2539. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2540. saveq);
  2541. spin_lock_irqsave(&phba->hbalock,
  2542. iflag);
  2543. } else
  2544. __lpfc_sli_release_iocbq(phba,
  2545. cmdiocbp);
  2546. }
  2547. break;
  2548. case LPFC_UNKNOWN_IOCB:
  2549. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2550. char adaptermsg[LPFC_MAX_ADPTMSG];
  2551. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2552. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2553. MAX_MSG_DATA);
  2554. dev_warn(&((phba->pcidev)->dev),
  2555. "lpfc%d: %s\n",
  2556. phba->brd_no, adaptermsg);
  2557. } else {
  2558. /* Unknown IOCB command */
  2559. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2560. "0335 Unknown IOCB "
  2561. "command Data: x%x "
  2562. "x%x x%x x%x\n",
  2563. irsp->ulpCommand,
  2564. irsp->ulpStatus,
  2565. irsp->ulpIoTag,
  2566. irsp->ulpContext);
  2567. }
  2568. break;
  2569. }
  2570. if (free_saveq) {
  2571. list_for_each_entry_safe(rspiocbp, next_iocb,
  2572. &saveq->list, list) {
  2573. list_del(&rspiocbp->list);
  2574. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2575. }
  2576. __lpfc_sli_release_iocbq(phba, saveq);
  2577. }
  2578. rspiocbp = NULL;
  2579. }
  2580. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2581. return rspiocbp;
  2582. }
  2583. /**
  2584. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2585. * @phba: Pointer to HBA context object.
  2586. * @pring: Pointer to driver SLI ring object.
  2587. * @mask: Host attention register mask for this ring.
  2588. *
  2589. * This routine wraps the actual slow_ring event process routine from the
  2590. * API jump table function pointer from the lpfc_hba struct.
  2591. **/
  2592. void
  2593. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2594. struct lpfc_sli_ring *pring, uint32_t mask)
  2595. {
  2596. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2597. }
  2598. /**
  2599. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2600. * @phba: Pointer to HBA context object.
  2601. * @pring: Pointer to driver SLI ring object.
  2602. * @mask: Host attention register mask for this ring.
  2603. *
  2604. * This function is called from the worker thread when there is a ring event
  2605. * for non-fcp rings. The caller does not hold any lock. The function will
  2606. * remove each response iocb in the response ring and calls the handle
  2607. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2608. **/
  2609. static void
  2610. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2611. struct lpfc_sli_ring *pring, uint32_t mask)
  2612. {
  2613. struct lpfc_pgp *pgp;
  2614. IOCB_t *entry;
  2615. IOCB_t *irsp = NULL;
  2616. struct lpfc_iocbq *rspiocbp = NULL;
  2617. uint32_t portRspPut, portRspMax;
  2618. unsigned long iflag;
  2619. uint32_t status;
  2620. pgp = &phba->port_gp[pring->ringno];
  2621. spin_lock_irqsave(&phba->hbalock, iflag);
  2622. pring->stats.iocb_event++;
  2623. /*
  2624. * The next available response entry should never exceed the maximum
  2625. * entries. If it does, treat it as an adapter hardware error.
  2626. */
  2627. portRspMax = pring->numRiocb;
  2628. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2629. if (portRspPut >= portRspMax) {
  2630. /*
  2631. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2632. * rsp ring <portRspMax>
  2633. */
  2634. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2635. "0303 Ring %d handler: portRspPut %d "
  2636. "is bigger than rsp ring %d\n",
  2637. pring->ringno, portRspPut, portRspMax);
  2638. phba->link_state = LPFC_HBA_ERROR;
  2639. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2640. phba->work_hs = HS_FFER3;
  2641. lpfc_handle_eratt(phba);
  2642. return;
  2643. }
  2644. rmb();
  2645. while (pring->rspidx != portRspPut) {
  2646. /*
  2647. * Build a completion list and call the appropriate handler.
  2648. * The process is to get the next available response iocb, get
  2649. * a free iocb from the list, copy the response data into the
  2650. * free iocb, insert to the continuation list, and update the
  2651. * next response index to slim. This process makes response
  2652. * iocb's in the ring available to DMA as fast as possible but
  2653. * pays a penalty for a copy operation. Since the iocb is
  2654. * only 32 bytes, this penalty is considered small relative to
  2655. * the PCI reads for register values and a slim write. When
  2656. * the ulpLe field is set, the entire Command has been
  2657. * received.
  2658. */
  2659. entry = lpfc_resp_iocb(phba, pring);
  2660. phba->last_completion_time = jiffies;
  2661. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2662. if (rspiocbp == NULL) {
  2663. printk(KERN_ERR "%s: out of buffers! Failing "
  2664. "completion.\n", __func__);
  2665. break;
  2666. }
  2667. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2668. phba->iocb_rsp_size);
  2669. irsp = &rspiocbp->iocb;
  2670. if (++pring->rspidx >= portRspMax)
  2671. pring->rspidx = 0;
  2672. if (pring->ringno == LPFC_ELS_RING) {
  2673. lpfc_debugfs_slow_ring_trc(phba,
  2674. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2675. *(((uint32_t *) irsp) + 4),
  2676. *(((uint32_t *) irsp) + 6),
  2677. *(((uint32_t *) irsp) + 7));
  2678. }
  2679. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2680. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2681. /* Handle the response IOCB */
  2682. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2683. spin_lock_irqsave(&phba->hbalock, iflag);
  2684. /*
  2685. * If the port response put pointer has not been updated, sync
  2686. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2687. * response put pointer.
  2688. */
  2689. if (pring->rspidx == portRspPut) {
  2690. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2691. }
  2692. } /* while (pring->rspidx != portRspPut) */
  2693. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2694. /* At least one response entry has been freed */
  2695. pring->stats.iocb_rsp_full++;
  2696. /* SET RxRE_RSP in Chip Att register */
  2697. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2698. writel(status, phba->CAregaddr);
  2699. readl(phba->CAregaddr); /* flush */
  2700. }
  2701. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2702. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2703. pring->stats.iocb_cmd_empty++;
  2704. /* Force update of the local copy of cmdGetInx */
  2705. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2706. lpfc_sli_resume_iocb(phba, pring);
  2707. if ((pring->lpfc_sli_cmd_available))
  2708. (pring->lpfc_sli_cmd_available) (phba, pring);
  2709. }
  2710. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2711. return;
  2712. }
  2713. /**
  2714. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2715. * @phba: Pointer to HBA context object.
  2716. * @pring: Pointer to driver SLI ring object.
  2717. * @mask: Host attention register mask for this ring.
  2718. *
  2719. * This function is called from the worker thread when there is a pending
  2720. * ELS response iocb on the driver internal slow-path response iocb worker
  2721. * queue. The caller does not hold any lock. The function will remove each
  2722. * response iocb from the response worker queue and calls the handle
  2723. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2724. **/
  2725. static void
  2726. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2727. struct lpfc_sli_ring *pring, uint32_t mask)
  2728. {
  2729. struct lpfc_iocbq *irspiocbq;
  2730. struct hbq_dmabuf *dmabuf;
  2731. struct lpfc_cq_event *cq_event;
  2732. unsigned long iflag;
  2733. spin_lock_irqsave(&phba->hbalock, iflag);
  2734. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2735. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2736. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2737. /* Get the response iocb from the head of work queue */
  2738. spin_lock_irqsave(&phba->hbalock, iflag);
  2739. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2740. cq_event, struct lpfc_cq_event, list);
  2741. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2742. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2743. case CQE_CODE_COMPL_WQE:
  2744. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2745. cq_event);
  2746. /* Translate ELS WCQE to response IOCBQ */
  2747. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2748. irspiocbq);
  2749. if (irspiocbq)
  2750. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2751. irspiocbq);
  2752. break;
  2753. case CQE_CODE_RECEIVE:
  2754. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2755. cq_event);
  2756. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2757. break;
  2758. default:
  2759. break;
  2760. }
  2761. }
  2762. }
  2763. /**
  2764. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2765. * @phba: Pointer to HBA context object.
  2766. * @pring: Pointer to driver SLI ring object.
  2767. *
  2768. * This function aborts all iocbs in the given ring and frees all the iocb
  2769. * objects in txq. This function issues an abort iocb for all the iocb commands
  2770. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2771. * the return of this function. The caller is not required to hold any locks.
  2772. **/
  2773. void
  2774. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2775. {
  2776. LIST_HEAD(completions);
  2777. struct lpfc_iocbq *iocb, *next_iocb;
  2778. if (pring->ringno == LPFC_ELS_RING) {
  2779. lpfc_fabric_abort_hba(phba);
  2780. }
  2781. /* Error everything on txq and txcmplq
  2782. * First do the txq.
  2783. */
  2784. spin_lock_irq(&phba->hbalock);
  2785. list_splice_init(&pring->txq, &completions);
  2786. pring->txq_cnt = 0;
  2787. /* Next issue ABTS for everything on the txcmplq */
  2788. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2789. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2790. spin_unlock_irq(&phba->hbalock);
  2791. /* Cancel all the IOCBs from the completions list */
  2792. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2793. IOERR_SLI_ABORTED);
  2794. }
  2795. /**
  2796. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2797. * @phba: Pointer to HBA context object.
  2798. *
  2799. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2800. * objects in txq and txcmplq. This function will not issue abort iocbs
  2801. * for all the iocb commands in txcmplq, they will just be returned with
  2802. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2803. * slot has been permanently disabled.
  2804. **/
  2805. void
  2806. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2807. {
  2808. LIST_HEAD(txq);
  2809. LIST_HEAD(txcmplq);
  2810. struct lpfc_sli *psli = &phba->sli;
  2811. struct lpfc_sli_ring *pring;
  2812. /* Currently, only one fcp ring */
  2813. pring = &psli->ring[psli->fcp_ring];
  2814. spin_lock_irq(&phba->hbalock);
  2815. /* Retrieve everything on txq */
  2816. list_splice_init(&pring->txq, &txq);
  2817. pring->txq_cnt = 0;
  2818. /* Retrieve everything on the txcmplq */
  2819. list_splice_init(&pring->txcmplq, &txcmplq);
  2820. pring->txcmplq_cnt = 0;
  2821. spin_unlock_irq(&phba->hbalock);
  2822. /* Flush the txq */
  2823. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2824. IOERR_SLI_DOWN);
  2825. /* Flush the txcmpq */
  2826. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2827. IOERR_SLI_DOWN);
  2828. }
  2829. /**
  2830. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2831. * @phba: Pointer to HBA context object.
  2832. * @mask: Bit mask to be checked.
  2833. *
  2834. * This function reads the host status register and compares
  2835. * with the provided bit mask to check if HBA completed
  2836. * the restart. This function will wait in a loop for the
  2837. * HBA to complete restart. If the HBA does not restart within
  2838. * 15 iterations, the function will reset the HBA again. The
  2839. * function returns 1 when HBA fail to restart otherwise returns
  2840. * zero.
  2841. **/
  2842. static int
  2843. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2844. {
  2845. uint32_t status;
  2846. int i = 0;
  2847. int retval = 0;
  2848. /* Read the HBA Host Status Register */
  2849. status = readl(phba->HSregaddr);
  2850. /*
  2851. * Check status register every 100ms for 5 retries, then every
  2852. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2853. * every 2.5 sec for 4.
  2854. * Break our of the loop if errors occurred during init.
  2855. */
  2856. while (((status & mask) != mask) &&
  2857. !(status & HS_FFERM) &&
  2858. i++ < 20) {
  2859. if (i <= 5)
  2860. msleep(10);
  2861. else if (i <= 10)
  2862. msleep(500);
  2863. else
  2864. msleep(2500);
  2865. if (i == 15) {
  2866. /* Do post */
  2867. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2868. lpfc_sli_brdrestart(phba);
  2869. }
  2870. /* Read the HBA Host Status Register */
  2871. status = readl(phba->HSregaddr);
  2872. }
  2873. /* Check to see if any errors occurred during init */
  2874. if ((status & HS_FFERM) || (i >= 20)) {
  2875. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2876. "2751 Adapter failed to restart, "
  2877. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2878. status,
  2879. readl(phba->MBslimaddr + 0xa8),
  2880. readl(phba->MBslimaddr + 0xac));
  2881. phba->link_state = LPFC_HBA_ERROR;
  2882. retval = 1;
  2883. }
  2884. return retval;
  2885. }
  2886. /**
  2887. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2888. * @phba: Pointer to HBA context object.
  2889. * @mask: Bit mask to be checked.
  2890. *
  2891. * This function checks the host status register to check if HBA is
  2892. * ready. This function will wait in a loop for the HBA to be ready
  2893. * If the HBA is not ready , the function will will reset the HBA PCI
  2894. * function again. The function returns 1 when HBA fail to be ready
  2895. * otherwise returns zero.
  2896. **/
  2897. static int
  2898. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2899. {
  2900. uint32_t status;
  2901. int retval = 0;
  2902. /* Read the HBA Host Status Register */
  2903. status = lpfc_sli4_post_status_check(phba);
  2904. if (status) {
  2905. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2906. lpfc_sli_brdrestart(phba);
  2907. status = lpfc_sli4_post_status_check(phba);
  2908. }
  2909. /* Check to see if any errors occurred during init */
  2910. if (status) {
  2911. phba->link_state = LPFC_HBA_ERROR;
  2912. retval = 1;
  2913. } else
  2914. phba->sli4_hba.intr_enable = 0;
  2915. return retval;
  2916. }
  2917. /**
  2918. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2919. * @phba: Pointer to HBA context object.
  2920. * @mask: Bit mask to be checked.
  2921. *
  2922. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2923. * from the API jump table function pointer from the lpfc_hba struct.
  2924. **/
  2925. int
  2926. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2927. {
  2928. return phba->lpfc_sli_brdready(phba, mask);
  2929. }
  2930. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2931. /**
  2932. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2933. * @phba: Pointer to HBA context object.
  2934. *
  2935. * This function is called before resetting an HBA. This
  2936. * function requests HBA to quiesce DMAs before a reset.
  2937. **/
  2938. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2939. {
  2940. uint32_t __iomem *resp_buf;
  2941. uint32_t __iomem *mbox_buf;
  2942. volatile uint32_t mbox;
  2943. uint32_t hc_copy;
  2944. int i;
  2945. uint8_t hdrtype;
  2946. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2947. if (hdrtype != 0x80 ||
  2948. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2949. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2950. return;
  2951. /*
  2952. * Tell the other part of the chip to suspend temporarily all
  2953. * its DMA activity.
  2954. */
  2955. resp_buf = phba->MBslimaddr;
  2956. /* Disable the error attention */
  2957. hc_copy = readl(phba->HCregaddr);
  2958. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2959. readl(phba->HCregaddr); /* flush */
  2960. phba->link_flag |= LS_IGNORE_ERATT;
  2961. if (readl(phba->HAregaddr) & HA_ERATT) {
  2962. /* Clear Chip error bit */
  2963. writel(HA_ERATT, phba->HAregaddr);
  2964. phba->pport->stopped = 1;
  2965. }
  2966. mbox = 0;
  2967. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2968. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2969. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2970. mbox_buf = phba->MBslimaddr;
  2971. writel(mbox, mbox_buf);
  2972. for (i = 0;
  2973. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2974. mdelay(1);
  2975. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2976. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2977. phba->pport->stopped)
  2978. goto restore_hc;
  2979. else
  2980. goto clear_errat;
  2981. }
  2982. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2983. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2984. mdelay(1);
  2985. clear_errat:
  2986. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2987. mdelay(1);
  2988. if (readl(phba->HAregaddr) & HA_ERATT) {
  2989. writel(HA_ERATT, phba->HAregaddr);
  2990. phba->pport->stopped = 1;
  2991. }
  2992. restore_hc:
  2993. phba->link_flag &= ~LS_IGNORE_ERATT;
  2994. writel(hc_copy, phba->HCregaddr);
  2995. readl(phba->HCregaddr); /* flush */
  2996. }
  2997. /**
  2998. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2999. * @phba: Pointer to HBA context object.
  3000. *
  3001. * This function issues a kill_board mailbox command and waits for
  3002. * the error attention interrupt. This function is called for stopping
  3003. * the firmware processing. The caller is not required to hold any
  3004. * locks. This function calls lpfc_hba_down_post function to free
  3005. * any pending commands after the kill. The function will return 1 when it
  3006. * fails to kill the board else will return 0.
  3007. **/
  3008. int
  3009. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3010. {
  3011. struct lpfc_sli *psli;
  3012. LPFC_MBOXQ_t *pmb;
  3013. uint32_t status;
  3014. uint32_t ha_copy;
  3015. int retval;
  3016. int i = 0;
  3017. psli = &phba->sli;
  3018. /* Kill HBA */
  3019. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3020. "0329 Kill HBA Data: x%x x%x\n",
  3021. phba->pport->port_state, psli->sli_flag);
  3022. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3023. if (!pmb)
  3024. return 1;
  3025. /* Disable the error attention */
  3026. spin_lock_irq(&phba->hbalock);
  3027. status = readl(phba->HCregaddr);
  3028. status &= ~HC_ERINT_ENA;
  3029. writel(status, phba->HCregaddr);
  3030. readl(phba->HCregaddr); /* flush */
  3031. phba->link_flag |= LS_IGNORE_ERATT;
  3032. spin_unlock_irq(&phba->hbalock);
  3033. lpfc_kill_board(phba, pmb);
  3034. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3035. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3036. if (retval != MBX_SUCCESS) {
  3037. if (retval != MBX_BUSY)
  3038. mempool_free(pmb, phba->mbox_mem_pool);
  3039. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3040. "2752 KILL_BOARD command failed retval %d\n",
  3041. retval);
  3042. spin_lock_irq(&phba->hbalock);
  3043. phba->link_flag &= ~LS_IGNORE_ERATT;
  3044. spin_unlock_irq(&phba->hbalock);
  3045. return 1;
  3046. }
  3047. spin_lock_irq(&phba->hbalock);
  3048. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3049. spin_unlock_irq(&phba->hbalock);
  3050. mempool_free(pmb, phba->mbox_mem_pool);
  3051. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3052. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3053. * 3 seconds we still set HBA_ERROR state because the status of the
  3054. * board is now undefined.
  3055. */
  3056. ha_copy = readl(phba->HAregaddr);
  3057. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3058. mdelay(100);
  3059. ha_copy = readl(phba->HAregaddr);
  3060. }
  3061. del_timer_sync(&psli->mbox_tmo);
  3062. if (ha_copy & HA_ERATT) {
  3063. writel(HA_ERATT, phba->HAregaddr);
  3064. phba->pport->stopped = 1;
  3065. }
  3066. spin_lock_irq(&phba->hbalock);
  3067. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3068. psli->mbox_active = NULL;
  3069. phba->link_flag &= ~LS_IGNORE_ERATT;
  3070. spin_unlock_irq(&phba->hbalock);
  3071. lpfc_hba_down_post(phba);
  3072. phba->link_state = LPFC_HBA_ERROR;
  3073. return ha_copy & HA_ERATT ? 0 : 1;
  3074. }
  3075. /**
  3076. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3077. * @phba: Pointer to HBA context object.
  3078. *
  3079. * This function resets the HBA by writing HC_INITFF to the control
  3080. * register. After the HBA resets, this function resets all the iocb ring
  3081. * indices. This function disables PCI layer parity checking during
  3082. * the reset.
  3083. * This function returns 0 always.
  3084. * The caller is not required to hold any locks.
  3085. **/
  3086. int
  3087. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3088. {
  3089. struct lpfc_sli *psli;
  3090. struct lpfc_sli_ring *pring;
  3091. uint16_t cfg_value;
  3092. int i;
  3093. psli = &phba->sli;
  3094. /* Reset HBA */
  3095. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3096. "0325 Reset HBA Data: x%x x%x\n",
  3097. phba->pport->port_state, psli->sli_flag);
  3098. /* perform board reset */
  3099. phba->fc_eventTag = 0;
  3100. phba->link_events = 0;
  3101. phba->pport->fc_myDID = 0;
  3102. phba->pport->fc_prevDID = 0;
  3103. /* Turn off parity checking and serr during the physical reset */
  3104. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3105. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3106. (cfg_value &
  3107. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3108. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3109. /* Now toggle INITFF bit in the Host Control Register */
  3110. writel(HC_INITFF, phba->HCregaddr);
  3111. mdelay(1);
  3112. readl(phba->HCregaddr); /* flush */
  3113. writel(0, phba->HCregaddr);
  3114. readl(phba->HCregaddr); /* flush */
  3115. /* Restore PCI cmd register */
  3116. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3117. /* Initialize relevant SLI info */
  3118. for (i = 0; i < psli->num_rings; i++) {
  3119. pring = &psli->ring[i];
  3120. pring->flag = 0;
  3121. pring->rspidx = 0;
  3122. pring->next_cmdidx = 0;
  3123. pring->local_getidx = 0;
  3124. pring->cmdidx = 0;
  3125. pring->missbufcnt = 0;
  3126. }
  3127. phba->link_state = LPFC_WARM_START;
  3128. return 0;
  3129. }
  3130. /**
  3131. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3132. * @phba: Pointer to HBA context object.
  3133. *
  3134. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3135. * checking during resets the device. The caller is not required to hold
  3136. * any locks.
  3137. *
  3138. * This function returns 0 always.
  3139. **/
  3140. int
  3141. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3142. {
  3143. struct lpfc_sli *psli = &phba->sli;
  3144. uint16_t cfg_value;
  3145. uint8_t qindx;
  3146. /* Reset HBA */
  3147. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3148. "0295 Reset HBA Data: x%x x%x\n",
  3149. phba->pport->port_state, psli->sli_flag);
  3150. /* perform board reset */
  3151. phba->fc_eventTag = 0;
  3152. phba->link_events = 0;
  3153. phba->pport->fc_myDID = 0;
  3154. phba->pport->fc_prevDID = 0;
  3155. /* Turn off parity checking and serr during the physical reset */
  3156. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3157. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3158. (cfg_value &
  3159. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3160. spin_lock_irq(&phba->hbalock);
  3161. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3162. phba->fcf.fcf_flag = 0;
  3163. /* Clean up the child queue list for the CQs */
  3164. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3165. list_del_init(&phba->sli4_hba.els_wq->list);
  3166. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3167. list_del_init(&phba->sli4_hba.dat_rq->list);
  3168. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3169. list_del_init(&phba->sli4_hba.els_cq->list);
  3170. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3171. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3172. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3173. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3174. spin_unlock_irq(&phba->hbalock);
  3175. /* Now physically reset the device */
  3176. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3177. "0389 Performing PCI function reset!\n");
  3178. /* Perform FCoE PCI function reset */
  3179. lpfc_pci_function_reset(phba);
  3180. return 0;
  3181. }
  3182. /**
  3183. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3184. * @phba: Pointer to HBA context object.
  3185. *
  3186. * This function is called in the SLI initialization code path to
  3187. * restart the HBA. The caller is not required to hold any lock.
  3188. * This function writes MBX_RESTART mailbox command to the SLIM and
  3189. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3190. * function to free any pending commands. The function enables
  3191. * POST only during the first initialization. The function returns zero.
  3192. * The function does not guarantee completion of MBX_RESTART mailbox
  3193. * command before the return of this function.
  3194. **/
  3195. static int
  3196. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3197. {
  3198. MAILBOX_t *mb;
  3199. struct lpfc_sli *psli;
  3200. volatile uint32_t word0;
  3201. void __iomem *to_slim;
  3202. uint32_t hba_aer_enabled;
  3203. spin_lock_irq(&phba->hbalock);
  3204. /* Take PCIe device Advanced Error Reporting (AER) state */
  3205. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3206. psli = &phba->sli;
  3207. /* Restart HBA */
  3208. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3209. "0337 Restart HBA Data: x%x x%x\n",
  3210. phba->pport->port_state, psli->sli_flag);
  3211. word0 = 0;
  3212. mb = (MAILBOX_t *) &word0;
  3213. mb->mbxCommand = MBX_RESTART;
  3214. mb->mbxHc = 1;
  3215. lpfc_reset_barrier(phba);
  3216. to_slim = phba->MBslimaddr;
  3217. writel(*(uint32_t *) mb, to_slim);
  3218. readl(to_slim); /* flush */
  3219. /* Only skip post after fc_ffinit is completed */
  3220. if (phba->pport->port_state)
  3221. word0 = 1; /* This is really setting up word1 */
  3222. else
  3223. word0 = 0; /* This is really setting up word1 */
  3224. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3225. writel(*(uint32_t *) mb, to_slim);
  3226. readl(to_slim); /* flush */
  3227. lpfc_sli_brdreset(phba);
  3228. phba->pport->stopped = 0;
  3229. phba->link_state = LPFC_INIT_START;
  3230. phba->hba_flag = 0;
  3231. spin_unlock_irq(&phba->hbalock);
  3232. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3233. psli->stats_start = get_seconds();
  3234. /* Give the INITFF and Post time to settle. */
  3235. mdelay(100);
  3236. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3237. if (hba_aer_enabled)
  3238. pci_disable_pcie_error_reporting(phba->pcidev);
  3239. lpfc_hba_down_post(phba);
  3240. return 0;
  3241. }
  3242. /**
  3243. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3244. * @phba: Pointer to HBA context object.
  3245. *
  3246. * This function is called in the SLI initialization code path to restart
  3247. * a SLI4 HBA. The caller is not required to hold any lock.
  3248. * At the end of the function, it calls lpfc_hba_down_post function to
  3249. * free any pending commands.
  3250. **/
  3251. static int
  3252. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3253. {
  3254. struct lpfc_sli *psli = &phba->sli;
  3255. uint32_t hba_aer_enabled;
  3256. /* Restart HBA */
  3257. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3258. "0296 Restart HBA Data: x%x x%x\n",
  3259. phba->pport->port_state, psli->sli_flag);
  3260. /* Take PCIe device Advanced Error Reporting (AER) state */
  3261. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3262. lpfc_sli4_brdreset(phba);
  3263. spin_lock_irq(&phba->hbalock);
  3264. phba->pport->stopped = 0;
  3265. phba->link_state = LPFC_INIT_START;
  3266. phba->hba_flag = 0;
  3267. spin_unlock_irq(&phba->hbalock);
  3268. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3269. psli->stats_start = get_seconds();
  3270. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3271. if (hba_aer_enabled)
  3272. pci_disable_pcie_error_reporting(phba->pcidev);
  3273. lpfc_hba_down_post(phba);
  3274. return 0;
  3275. }
  3276. /**
  3277. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3278. * @phba: Pointer to HBA context object.
  3279. *
  3280. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3281. * API jump table function pointer from the lpfc_hba struct.
  3282. **/
  3283. int
  3284. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3285. {
  3286. return phba->lpfc_sli_brdrestart(phba);
  3287. }
  3288. /**
  3289. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3290. * @phba: Pointer to HBA context object.
  3291. *
  3292. * This function is called after a HBA restart to wait for successful
  3293. * restart of the HBA. Successful restart of the HBA is indicated by
  3294. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3295. * iteration, the function will restart the HBA again. The function returns
  3296. * zero if HBA successfully restarted else returns negative error code.
  3297. **/
  3298. static int
  3299. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3300. {
  3301. uint32_t status, i = 0;
  3302. /* Read the HBA Host Status Register */
  3303. status = readl(phba->HSregaddr);
  3304. /* Check status register to see what current state is */
  3305. i = 0;
  3306. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3307. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3308. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3309. * 4.
  3310. */
  3311. if (i++ >= 20) {
  3312. /* Adapter failed to init, timeout, status reg
  3313. <status> */
  3314. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3315. "0436 Adapter failed to init, "
  3316. "timeout, status reg x%x, "
  3317. "FW Data: A8 x%x AC x%x\n", status,
  3318. readl(phba->MBslimaddr + 0xa8),
  3319. readl(phba->MBslimaddr + 0xac));
  3320. phba->link_state = LPFC_HBA_ERROR;
  3321. return -ETIMEDOUT;
  3322. }
  3323. /* Check to see if any errors occurred during init */
  3324. if (status & HS_FFERM) {
  3325. /* ERROR: During chipset initialization */
  3326. /* Adapter failed to init, chipset, status reg
  3327. <status> */
  3328. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3329. "0437 Adapter failed to init, "
  3330. "chipset, status reg x%x, "
  3331. "FW Data: A8 x%x AC x%x\n", status,
  3332. readl(phba->MBslimaddr + 0xa8),
  3333. readl(phba->MBslimaddr + 0xac));
  3334. phba->link_state = LPFC_HBA_ERROR;
  3335. return -EIO;
  3336. }
  3337. if (i <= 5) {
  3338. msleep(10);
  3339. } else if (i <= 10) {
  3340. msleep(500);
  3341. } else {
  3342. msleep(2500);
  3343. }
  3344. if (i == 15) {
  3345. /* Do post */
  3346. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3347. lpfc_sli_brdrestart(phba);
  3348. }
  3349. /* Read the HBA Host Status Register */
  3350. status = readl(phba->HSregaddr);
  3351. }
  3352. /* Check to see if any errors occurred during init */
  3353. if (status & HS_FFERM) {
  3354. /* ERROR: During chipset initialization */
  3355. /* Adapter failed to init, chipset, status reg <status> */
  3356. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3357. "0438 Adapter failed to init, chipset, "
  3358. "status reg x%x, "
  3359. "FW Data: A8 x%x AC x%x\n", status,
  3360. readl(phba->MBslimaddr + 0xa8),
  3361. readl(phba->MBslimaddr + 0xac));
  3362. phba->link_state = LPFC_HBA_ERROR;
  3363. return -EIO;
  3364. }
  3365. /* Clear all interrupt enable conditions */
  3366. writel(0, phba->HCregaddr);
  3367. readl(phba->HCregaddr); /* flush */
  3368. /* setup host attn register */
  3369. writel(0xffffffff, phba->HAregaddr);
  3370. readl(phba->HAregaddr); /* flush */
  3371. return 0;
  3372. }
  3373. /**
  3374. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3375. *
  3376. * This function calculates and returns the number of HBQs required to be
  3377. * configured.
  3378. **/
  3379. int
  3380. lpfc_sli_hbq_count(void)
  3381. {
  3382. return ARRAY_SIZE(lpfc_hbq_defs);
  3383. }
  3384. /**
  3385. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3386. *
  3387. * This function adds the number of hbq entries in every HBQ to get
  3388. * the total number of hbq entries required for the HBA and returns
  3389. * the total count.
  3390. **/
  3391. static int
  3392. lpfc_sli_hbq_entry_count(void)
  3393. {
  3394. int hbq_count = lpfc_sli_hbq_count();
  3395. int count = 0;
  3396. int i;
  3397. for (i = 0; i < hbq_count; ++i)
  3398. count += lpfc_hbq_defs[i]->entry_count;
  3399. return count;
  3400. }
  3401. /**
  3402. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3403. *
  3404. * This function calculates amount of memory required for all hbq entries
  3405. * to be configured and returns the total memory required.
  3406. **/
  3407. int
  3408. lpfc_sli_hbq_size(void)
  3409. {
  3410. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3411. }
  3412. /**
  3413. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3414. * @phba: Pointer to HBA context object.
  3415. *
  3416. * This function is called during the SLI initialization to configure
  3417. * all the HBQs and post buffers to the HBQ. The caller is not
  3418. * required to hold any locks. This function will return zero if successful
  3419. * else it will return negative error code.
  3420. **/
  3421. static int
  3422. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3423. {
  3424. int hbq_count = lpfc_sli_hbq_count();
  3425. LPFC_MBOXQ_t *pmb;
  3426. MAILBOX_t *pmbox;
  3427. uint32_t hbqno;
  3428. uint32_t hbq_entry_index;
  3429. /* Get a Mailbox buffer to setup mailbox
  3430. * commands for HBA initialization
  3431. */
  3432. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3433. if (!pmb)
  3434. return -ENOMEM;
  3435. pmbox = &pmb->u.mb;
  3436. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3437. phba->link_state = LPFC_INIT_MBX_CMDS;
  3438. phba->hbq_in_use = 1;
  3439. hbq_entry_index = 0;
  3440. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3441. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3442. phba->hbqs[hbqno].hbqPutIdx = 0;
  3443. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3444. phba->hbqs[hbqno].entry_count =
  3445. lpfc_hbq_defs[hbqno]->entry_count;
  3446. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3447. hbq_entry_index, pmb);
  3448. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3449. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3450. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3451. mbxStatus <status>, ring <num> */
  3452. lpfc_printf_log(phba, KERN_ERR,
  3453. LOG_SLI | LOG_VPORT,
  3454. "1805 Adapter failed to init. "
  3455. "Data: x%x x%x x%x\n",
  3456. pmbox->mbxCommand,
  3457. pmbox->mbxStatus, hbqno);
  3458. phba->link_state = LPFC_HBA_ERROR;
  3459. mempool_free(pmb, phba->mbox_mem_pool);
  3460. return -ENXIO;
  3461. }
  3462. }
  3463. phba->hbq_count = hbq_count;
  3464. mempool_free(pmb, phba->mbox_mem_pool);
  3465. /* Initially populate or replenish the HBQs */
  3466. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3467. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3468. return 0;
  3469. }
  3470. /**
  3471. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3472. * @phba: Pointer to HBA context object.
  3473. *
  3474. * This function is called during the SLI initialization to configure
  3475. * all the HBQs and post buffers to the HBQ. The caller is not
  3476. * required to hold any locks. This function will return zero if successful
  3477. * else it will return negative error code.
  3478. **/
  3479. static int
  3480. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3481. {
  3482. phba->hbq_in_use = 1;
  3483. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3484. phba->hbq_count = 1;
  3485. /* Initially populate or replenish the HBQs */
  3486. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3487. return 0;
  3488. }
  3489. /**
  3490. * lpfc_sli_config_port - Issue config port mailbox command
  3491. * @phba: Pointer to HBA context object.
  3492. * @sli_mode: sli mode - 2/3
  3493. *
  3494. * This function is called by the sli intialization code path
  3495. * to issue config_port mailbox command. This function restarts the
  3496. * HBA firmware and issues a config_port mailbox command to configure
  3497. * the SLI interface in the sli mode specified by sli_mode
  3498. * variable. The caller is not required to hold any locks.
  3499. * The function returns 0 if successful, else returns negative error
  3500. * code.
  3501. **/
  3502. int
  3503. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3504. {
  3505. LPFC_MBOXQ_t *pmb;
  3506. uint32_t resetcount = 0, rc = 0, done = 0;
  3507. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3508. if (!pmb) {
  3509. phba->link_state = LPFC_HBA_ERROR;
  3510. return -ENOMEM;
  3511. }
  3512. phba->sli_rev = sli_mode;
  3513. while (resetcount < 2 && !done) {
  3514. spin_lock_irq(&phba->hbalock);
  3515. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3516. spin_unlock_irq(&phba->hbalock);
  3517. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3518. lpfc_sli_brdrestart(phba);
  3519. rc = lpfc_sli_chipset_init(phba);
  3520. if (rc)
  3521. break;
  3522. spin_lock_irq(&phba->hbalock);
  3523. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3524. spin_unlock_irq(&phba->hbalock);
  3525. resetcount++;
  3526. /* Call pre CONFIG_PORT mailbox command initialization. A
  3527. * value of 0 means the call was successful. Any other
  3528. * nonzero value is a failure, but if ERESTART is returned,
  3529. * the driver may reset the HBA and try again.
  3530. */
  3531. rc = lpfc_config_port_prep(phba);
  3532. if (rc == -ERESTART) {
  3533. phba->link_state = LPFC_LINK_UNKNOWN;
  3534. continue;
  3535. } else if (rc)
  3536. break;
  3537. phba->link_state = LPFC_INIT_MBX_CMDS;
  3538. lpfc_config_port(phba, pmb);
  3539. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3540. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3541. LPFC_SLI3_HBQ_ENABLED |
  3542. LPFC_SLI3_CRP_ENABLED |
  3543. LPFC_SLI3_BG_ENABLED);
  3544. if (rc != MBX_SUCCESS) {
  3545. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3546. "0442 Adapter failed to init, mbxCmd x%x "
  3547. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3548. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3549. spin_lock_irq(&phba->hbalock);
  3550. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3551. spin_unlock_irq(&phba->hbalock);
  3552. rc = -ENXIO;
  3553. } else {
  3554. /* Allow asynchronous mailbox command to go through */
  3555. spin_lock_irq(&phba->hbalock);
  3556. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3557. spin_unlock_irq(&phba->hbalock);
  3558. done = 1;
  3559. }
  3560. }
  3561. if (!done) {
  3562. rc = -EINVAL;
  3563. goto do_prep_failed;
  3564. }
  3565. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3566. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3567. rc = -ENXIO;
  3568. goto do_prep_failed;
  3569. }
  3570. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3571. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3572. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3573. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3574. phba->max_vpi : phba->max_vports;
  3575. } else
  3576. phba->max_vpi = 0;
  3577. if (pmb->u.mb.un.varCfgPort.gdss)
  3578. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3579. if (pmb->u.mb.un.varCfgPort.gerbm)
  3580. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3581. if (pmb->u.mb.un.varCfgPort.gcrp)
  3582. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3583. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3584. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3585. if (phba->cfg_enable_bg) {
  3586. if (pmb->u.mb.un.varCfgPort.gbg)
  3587. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3588. else
  3589. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3590. "0443 Adapter did not grant "
  3591. "BlockGuard\n");
  3592. }
  3593. } else {
  3594. phba->hbq_get = NULL;
  3595. phba->port_gp = phba->mbox->us.s2.port;
  3596. phba->max_vpi = 0;
  3597. }
  3598. do_prep_failed:
  3599. mempool_free(pmb, phba->mbox_mem_pool);
  3600. return rc;
  3601. }
  3602. /**
  3603. * lpfc_sli_hba_setup - SLI intialization function
  3604. * @phba: Pointer to HBA context object.
  3605. *
  3606. * This function is the main SLI intialization function. This function
  3607. * is called by the HBA intialization code, HBA reset code and HBA
  3608. * error attention handler code. Caller is not required to hold any
  3609. * locks. This function issues config_port mailbox command to configure
  3610. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3611. * calls the config_port_post function to issue init_link mailbox
  3612. * command and to start the discovery. The function will return zero
  3613. * if successful, else it will return negative error code.
  3614. **/
  3615. int
  3616. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3617. {
  3618. uint32_t rc;
  3619. int mode = 3;
  3620. switch (lpfc_sli_mode) {
  3621. case 2:
  3622. if (phba->cfg_enable_npiv) {
  3623. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3624. "1824 NPIV enabled: Override lpfc_sli_mode "
  3625. "parameter (%d) to auto (0).\n",
  3626. lpfc_sli_mode);
  3627. break;
  3628. }
  3629. mode = 2;
  3630. break;
  3631. case 0:
  3632. case 3:
  3633. break;
  3634. default:
  3635. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3636. "1819 Unrecognized lpfc_sli_mode "
  3637. "parameter: %d.\n", lpfc_sli_mode);
  3638. break;
  3639. }
  3640. rc = lpfc_sli_config_port(phba, mode);
  3641. if (rc && lpfc_sli_mode == 3)
  3642. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3643. "1820 Unable to select SLI-3. "
  3644. "Not supported by adapter.\n");
  3645. if (rc && mode != 2)
  3646. rc = lpfc_sli_config_port(phba, 2);
  3647. if (rc)
  3648. goto lpfc_sli_hba_setup_error;
  3649. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3650. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3651. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3652. if (!rc) {
  3653. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3654. "2709 This device supports "
  3655. "Advanced Error Reporting (AER)\n");
  3656. spin_lock_irq(&phba->hbalock);
  3657. phba->hba_flag |= HBA_AER_ENABLED;
  3658. spin_unlock_irq(&phba->hbalock);
  3659. } else {
  3660. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3661. "2708 This device does not support "
  3662. "Advanced Error Reporting (AER)\n");
  3663. phba->cfg_aer_support = 0;
  3664. }
  3665. }
  3666. if (phba->sli_rev == 3) {
  3667. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3668. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3669. } else {
  3670. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3671. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3672. phba->sli3_options = 0;
  3673. }
  3674. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3675. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3676. phba->sli_rev, phba->max_vpi);
  3677. rc = lpfc_sli_ring_map(phba);
  3678. if (rc)
  3679. goto lpfc_sli_hba_setup_error;
  3680. /* Init HBQs */
  3681. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3682. rc = lpfc_sli_hbq_setup(phba);
  3683. if (rc)
  3684. goto lpfc_sli_hba_setup_error;
  3685. }
  3686. spin_lock_irq(&phba->hbalock);
  3687. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3688. spin_unlock_irq(&phba->hbalock);
  3689. rc = lpfc_config_port_post(phba);
  3690. if (rc)
  3691. goto lpfc_sli_hba_setup_error;
  3692. return rc;
  3693. lpfc_sli_hba_setup_error:
  3694. phba->link_state = LPFC_HBA_ERROR;
  3695. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3696. "0445 Firmware initialization failed\n");
  3697. return rc;
  3698. }
  3699. /**
  3700. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3701. * @phba: Pointer to HBA context object.
  3702. * @mboxq: mailbox pointer.
  3703. * This function issue a dump mailbox command to read config region
  3704. * 23 and parse the records in the region and populate driver
  3705. * data structure.
  3706. **/
  3707. static int
  3708. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3709. LPFC_MBOXQ_t *mboxq)
  3710. {
  3711. struct lpfc_dmabuf *mp;
  3712. struct lpfc_mqe *mqe;
  3713. uint32_t data_length;
  3714. int rc;
  3715. /* Program the default value of vlan_id and fc_map */
  3716. phba->valid_vlan = 0;
  3717. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3718. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3719. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3720. mqe = &mboxq->u.mqe;
  3721. if (lpfc_dump_fcoe_param(phba, mboxq))
  3722. return -ENOMEM;
  3723. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3724. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3725. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3726. "(%d):2571 Mailbox cmd x%x Status x%x "
  3727. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3728. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3729. "CQ: x%x x%x x%x x%x\n",
  3730. mboxq->vport ? mboxq->vport->vpi : 0,
  3731. bf_get(lpfc_mqe_command, mqe),
  3732. bf_get(lpfc_mqe_status, mqe),
  3733. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3734. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3735. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3736. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3737. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3738. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3739. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3740. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3741. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3742. mboxq->mcqe.word0,
  3743. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3744. mboxq->mcqe.trailer);
  3745. if (rc) {
  3746. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3747. kfree(mp);
  3748. return -EIO;
  3749. }
  3750. data_length = mqe->un.mb_words[5];
  3751. if (data_length > DMP_RGN23_SIZE) {
  3752. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3753. kfree(mp);
  3754. return -EIO;
  3755. }
  3756. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3757. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3758. kfree(mp);
  3759. return 0;
  3760. }
  3761. /**
  3762. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3763. * @phba: pointer to lpfc hba data structure.
  3764. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3765. * @vpd: pointer to the memory to hold resulting port vpd data.
  3766. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3767. * On output, the number of data bytes in @vpd.
  3768. *
  3769. * This routine executes a READ_REV SLI4 mailbox command. In
  3770. * addition, this routine gets the port vpd data.
  3771. *
  3772. * Return codes
  3773. * 0 - successful
  3774. * ENOMEM - could not allocated memory.
  3775. **/
  3776. static int
  3777. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3778. uint8_t *vpd, uint32_t *vpd_size)
  3779. {
  3780. int rc = 0;
  3781. uint32_t dma_size;
  3782. struct lpfc_dmabuf *dmabuf;
  3783. struct lpfc_mqe *mqe;
  3784. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3785. if (!dmabuf)
  3786. return -ENOMEM;
  3787. /*
  3788. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3789. * mailbox command.
  3790. */
  3791. dma_size = *vpd_size;
  3792. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3793. dma_size,
  3794. &dmabuf->phys,
  3795. GFP_KERNEL);
  3796. if (!dmabuf->virt) {
  3797. kfree(dmabuf);
  3798. return -ENOMEM;
  3799. }
  3800. memset(dmabuf->virt, 0, dma_size);
  3801. /*
  3802. * The SLI4 implementation of READ_REV conflicts at word1,
  3803. * bits 31:16 and SLI4 adds vpd functionality not present
  3804. * in SLI3. This code corrects the conflicts.
  3805. */
  3806. lpfc_read_rev(phba, mboxq);
  3807. mqe = &mboxq->u.mqe;
  3808. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3809. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3810. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3811. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3812. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3813. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3814. if (rc) {
  3815. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3816. dmabuf->virt, dmabuf->phys);
  3817. kfree(dmabuf);
  3818. return -EIO;
  3819. }
  3820. /*
  3821. * The available vpd length cannot be bigger than the
  3822. * DMA buffer passed to the port. Catch the less than
  3823. * case and update the caller's size.
  3824. */
  3825. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3826. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3827. memcpy(vpd, dmabuf->virt, *vpd_size);
  3828. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3829. dmabuf->virt, dmabuf->phys);
  3830. kfree(dmabuf);
  3831. return 0;
  3832. }
  3833. /**
  3834. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3835. * @phba: pointer to lpfc hba data structure.
  3836. *
  3837. * This routine is called to explicitly arm the SLI4 device's completion and
  3838. * event queues
  3839. **/
  3840. static void
  3841. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3842. {
  3843. uint8_t fcp_eqidx;
  3844. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3845. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3846. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3847. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3848. LPFC_QUEUE_REARM);
  3849. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3850. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3851. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3852. LPFC_QUEUE_REARM);
  3853. }
  3854. /**
  3855. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3856. * @phba: Pointer to HBA context object.
  3857. *
  3858. * This function is the main SLI4 device intialization PCI function. This
  3859. * function is called by the HBA intialization code, HBA reset code and
  3860. * HBA error attention handler code. Caller is not required to hold any
  3861. * locks.
  3862. **/
  3863. int
  3864. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3865. {
  3866. int rc;
  3867. LPFC_MBOXQ_t *mboxq;
  3868. struct lpfc_mqe *mqe;
  3869. uint8_t *vpd;
  3870. uint32_t vpd_size;
  3871. uint32_t ftr_rsp = 0;
  3872. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3873. struct lpfc_vport *vport = phba->pport;
  3874. struct lpfc_dmabuf *mp;
  3875. /* Perform a PCI function reset to start from clean */
  3876. rc = lpfc_pci_function_reset(phba);
  3877. if (unlikely(rc))
  3878. return -ENODEV;
  3879. /* Check the HBA Host Status Register for readyness */
  3880. rc = lpfc_sli4_post_status_check(phba);
  3881. if (unlikely(rc))
  3882. return -ENODEV;
  3883. else {
  3884. spin_lock_irq(&phba->hbalock);
  3885. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3886. spin_unlock_irq(&phba->hbalock);
  3887. }
  3888. /*
  3889. * Allocate a single mailbox container for initializing the
  3890. * port.
  3891. */
  3892. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3893. if (!mboxq)
  3894. return -ENOMEM;
  3895. /*
  3896. * Continue initialization with default values even if driver failed
  3897. * to read FCoE param config regions
  3898. */
  3899. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3900. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3901. "2570 Failed to read FCoE parameters\n");
  3902. /* Issue READ_REV to collect vpd and FW information. */
  3903. vpd_size = SLI4_PAGE_SIZE;
  3904. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3905. if (!vpd) {
  3906. rc = -ENOMEM;
  3907. goto out_free_mbox;
  3908. }
  3909. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3910. if (unlikely(rc))
  3911. goto out_free_vpd;
  3912. mqe = &mboxq->u.mqe;
  3913. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3914. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3915. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3916. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3917. LPFC_DCBX_CEE_MODE)
  3918. phba->hba_flag |= HBA_FIP_SUPPORT;
  3919. else
  3920. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3921. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3922. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3923. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3924. "0376 READ_REV Error. SLI Level %d "
  3925. "FCoE enabled %d\n",
  3926. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3927. rc = -EIO;
  3928. goto out_free_vpd;
  3929. }
  3930. /*
  3931. * Evaluate the read rev and vpd data. Populate the driver
  3932. * state with the results. If this routine fails, the failure
  3933. * is not fatal as the driver will use generic values.
  3934. */
  3935. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3936. if (unlikely(!rc)) {
  3937. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3938. "0377 Error %d parsing vpd. "
  3939. "Using defaults.\n", rc);
  3940. rc = 0;
  3941. }
  3942. /* Save information as VPD data */
  3943. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3944. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3945. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3946. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3947. &mqe->un.read_rev);
  3948. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3949. &mqe->un.read_rev);
  3950. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3951. &mqe->un.read_rev);
  3952. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3953. &mqe->un.read_rev);
  3954. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3955. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3956. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3957. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3958. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3959. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3960. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3961. "(%d):0380 READ_REV Status x%x "
  3962. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3963. mboxq->vport ? mboxq->vport->vpi : 0,
  3964. bf_get(lpfc_mqe_status, mqe),
  3965. phba->vpd.rev.opFwName,
  3966. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3967. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3968. /*
  3969. * Discover the port's supported feature set and match it against the
  3970. * hosts requests.
  3971. */
  3972. lpfc_request_features(phba, mboxq);
  3973. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3974. if (unlikely(rc)) {
  3975. rc = -EIO;
  3976. goto out_free_vpd;
  3977. }
  3978. /*
  3979. * The port must support FCP initiator mode as this is the
  3980. * only mode running in the host.
  3981. */
  3982. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3983. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3984. "0378 No support for fcpi mode.\n");
  3985. ftr_rsp++;
  3986. }
  3987. /*
  3988. * If the port cannot support the host's requested features
  3989. * then turn off the global config parameters to disable the
  3990. * feature in the driver. This is not a fatal error.
  3991. */
  3992. if ((phba->cfg_enable_bg) &&
  3993. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3994. ftr_rsp++;
  3995. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3996. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3997. ftr_rsp++;
  3998. if (ftr_rsp) {
  3999. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4000. "0379 Feature Mismatch Data: x%08x %08x "
  4001. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4002. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4003. phba->cfg_enable_npiv, phba->max_vpi);
  4004. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4005. phba->cfg_enable_bg = 0;
  4006. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4007. phba->cfg_enable_npiv = 0;
  4008. }
  4009. /* These SLI3 features are assumed in SLI4 */
  4010. spin_lock_irq(&phba->hbalock);
  4011. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4012. spin_unlock_irq(&phba->hbalock);
  4013. /* Read the port's service parameters. */
  4014. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4015. if (rc) {
  4016. phba->link_state = LPFC_HBA_ERROR;
  4017. rc = -ENOMEM;
  4018. goto out_free_vpd;
  4019. }
  4020. mboxq->vport = vport;
  4021. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4022. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4023. if (rc == MBX_SUCCESS) {
  4024. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4025. rc = 0;
  4026. }
  4027. /*
  4028. * This memory was allocated by the lpfc_read_sparam routine. Release
  4029. * it to the mbuf pool.
  4030. */
  4031. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4032. kfree(mp);
  4033. mboxq->context1 = NULL;
  4034. if (unlikely(rc)) {
  4035. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4036. "0382 READ_SPARAM command failed "
  4037. "status %d, mbxStatus x%x\n",
  4038. rc, bf_get(lpfc_mqe_status, mqe));
  4039. phba->link_state = LPFC_HBA_ERROR;
  4040. rc = -EIO;
  4041. goto out_free_vpd;
  4042. }
  4043. if (phba->cfg_soft_wwnn)
  4044. u64_to_wwn(phba->cfg_soft_wwnn,
  4045. vport->fc_sparam.nodeName.u.wwn);
  4046. if (phba->cfg_soft_wwpn)
  4047. u64_to_wwn(phba->cfg_soft_wwpn,
  4048. vport->fc_sparam.portName.u.wwn);
  4049. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4050. sizeof(struct lpfc_name));
  4051. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4052. sizeof(struct lpfc_name));
  4053. /* Update the fc_host data structures with new wwn. */
  4054. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4055. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4056. /* Register SGL pool to the device using non-embedded mailbox command */
  4057. rc = lpfc_sli4_post_sgl_list(phba);
  4058. if (unlikely(rc)) {
  4059. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4060. "0582 Error %d during sgl post operation\n",
  4061. rc);
  4062. rc = -ENODEV;
  4063. goto out_free_vpd;
  4064. }
  4065. /* Register SCSI SGL pool to the device */
  4066. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4067. if (unlikely(rc)) {
  4068. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4069. "0383 Error %d during scsi sgl post "
  4070. "operation\n", rc);
  4071. /* Some Scsi buffers were moved to the abort scsi list */
  4072. /* A pci function reset will repost them */
  4073. rc = -ENODEV;
  4074. goto out_free_vpd;
  4075. }
  4076. /* Post the rpi header region to the device. */
  4077. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4078. if (unlikely(rc)) {
  4079. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4080. "0393 Error %d during rpi post operation\n",
  4081. rc);
  4082. rc = -ENODEV;
  4083. goto out_free_vpd;
  4084. }
  4085. /* Set up all the queues to the device */
  4086. rc = lpfc_sli4_queue_setup(phba);
  4087. if (unlikely(rc)) {
  4088. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4089. "0381 Error %d during queue setup.\n ", rc);
  4090. goto out_stop_timers;
  4091. }
  4092. /* Arm the CQs and then EQs on device */
  4093. lpfc_sli4_arm_cqeq_intr(phba);
  4094. /* Indicate device interrupt mode */
  4095. phba->sli4_hba.intr_enable = 1;
  4096. /* Allow asynchronous mailbox command to go through */
  4097. spin_lock_irq(&phba->hbalock);
  4098. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4099. spin_unlock_irq(&phba->hbalock);
  4100. /* Post receive buffers to the device */
  4101. lpfc_sli4_rb_setup(phba);
  4102. /* Reset HBA FCF states after HBA reset */
  4103. phba->fcf.fcf_flag = 0;
  4104. phba->fcf.current_rec.flag = 0;
  4105. /* Start the ELS watchdog timer */
  4106. mod_timer(&vport->els_tmofunc,
  4107. jiffies + HZ * (phba->fc_ratov * 2));
  4108. /* Start heart beat timer */
  4109. mod_timer(&phba->hb_tmofunc,
  4110. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4111. phba->hb_outstanding = 0;
  4112. phba->last_completion_time = jiffies;
  4113. /* Start error attention (ERATT) polling timer */
  4114. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4115. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4116. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4117. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4118. if (!rc) {
  4119. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4120. "2829 This device supports "
  4121. "Advanced Error Reporting (AER)\n");
  4122. spin_lock_irq(&phba->hbalock);
  4123. phba->hba_flag |= HBA_AER_ENABLED;
  4124. spin_unlock_irq(&phba->hbalock);
  4125. } else {
  4126. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4127. "2830 This device does not support "
  4128. "Advanced Error Reporting (AER)\n");
  4129. phba->cfg_aer_support = 0;
  4130. }
  4131. }
  4132. /*
  4133. * The port is ready, set the host's link state to LINK_DOWN
  4134. * in preparation for link interrupts.
  4135. */
  4136. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4137. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4138. lpfc_set_loopback_flag(phba);
  4139. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4140. spin_lock_irq(&phba->hbalock);
  4141. phba->link_state = LPFC_LINK_DOWN;
  4142. spin_unlock_irq(&phba->hbalock);
  4143. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4144. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4145. kfree(vpd);
  4146. return 0;
  4147. } else
  4148. rc = -EIO;
  4149. /* Unset all the queues set up in this routine when error out */
  4150. if (rc)
  4151. lpfc_sli4_queue_unset(phba);
  4152. out_stop_timers:
  4153. if (rc)
  4154. lpfc_stop_hba_timers(phba);
  4155. out_free_vpd:
  4156. kfree(vpd);
  4157. out_free_mbox:
  4158. mempool_free(mboxq, phba->mbox_mem_pool);
  4159. return rc;
  4160. }
  4161. /**
  4162. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4163. * @ptr: context object - pointer to hba structure.
  4164. *
  4165. * This is the callback function for mailbox timer. The mailbox
  4166. * timer is armed when a new mailbox command is issued and the timer
  4167. * is deleted when the mailbox complete. The function is called by
  4168. * the kernel timer code when a mailbox does not complete within
  4169. * expected time. This function wakes up the worker thread to
  4170. * process the mailbox timeout and returns. All the processing is
  4171. * done by the worker thread function lpfc_mbox_timeout_handler.
  4172. **/
  4173. void
  4174. lpfc_mbox_timeout(unsigned long ptr)
  4175. {
  4176. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4177. unsigned long iflag;
  4178. uint32_t tmo_posted;
  4179. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4180. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4181. if (!tmo_posted)
  4182. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4183. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4184. if (!tmo_posted)
  4185. lpfc_worker_wake_up(phba);
  4186. return;
  4187. }
  4188. /**
  4189. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4190. * @phba: Pointer to HBA context object.
  4191. *
  4192. * This function is called from worker thread when a mailbox command times out.
  4193. * The caller is not required to hold any locks. This function will reset the
  4194. * HBA and recover all the pending commands.
  4195. **/
  4196. void
  4197. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4198. {
  4199. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4200. MAILBOX_t *mb = &pmbox->u.mb;
  4201. struct lpfc_sli *psli = &phba->sli;
  4202. struct lpfc_sli_ring *pring;
  4203. /* Check the pmbox pointer first. There is a race condition
  4204. * between the mbox timeout handler getting executed in the
  4205. * worklist and the mailbox actually completing. When this
  4206. * race condition occurs, the mbox_active will be NULL.
  4207. */
  4208. spin_lock_irq(&phba->hbalock);
  4209. if (pmbox == NULL) {
  4210. lpfc_printf_log(phba, KERN_WARNING,
  4211. LOG_MBOX | LOG_SLI,
  4212. "0353 Active Mailbox cleared - mailbox timeout "
  4213. "exiting\n");
  4214. spin_unlock_irq(&phba->hbalock);
  4215. return;
  4216. }
  4217. /* Mbox cmd <mbxCommand> timeout */
  4218. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4219. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4220. mb->mbxCommand,
  4221. phba->pport->port_state,
  4222. phba->sli.sli_flag,
  4223. phba->sli.mbox_active);
  4224. spin_unlock_irq(&phba->hbalock);
  4225. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4226. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4227. * it to fail all oustanding SCSI IO.
  4228. */
  4229. spin_lock_irq(&phba->pport->work_port_lock);
  4230. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4231. spin_unlock_irq(&phba->pport->work_port_lock);
  4232. spin_lock_irq(&phba->hbalock);
  4233. phba->link_state = LPFC_LINK_UNKNOWN;
  4234. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4235. spin_unlock_irq(&phba->hbalock);
  4236. pring = &psli->ring[psli->fcp_ring];
  4237. lpfc_sli_abort_iocb_ring(phba, pring);
  4238. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4239. "0345 Resetting board due to mailbox timeout\n");
  4240. /* Reset the HBA device */
  4241. lpfc_reset_hba(phba);
  4242. }
  4243. /**
  4244. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4245. * @phba: Pointer to HBA context object.
  4246. * @pmbox: Pointer to mailbox object.
  4247. * @flag: Flag indicating how the mailbox need to be processed.
  4248. *
  4249. * This function is called by discovery code and HBA management code
  4250. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4251. * function gets the hbalock to protect the data structures.
  4252. * The mailbox command can be submitted in polling mode, in which case
  4253. * this function will wait in a polling loop for the completion of the
  4254. * mailbox.
  4255. * If the mailbox is submitted in no_wait mode (not polling) the
  4256. * function will submit the command and returns immediately without waiting
  4257. * for the mailbox completion. The no_wait is supported only when HBA
  4258. * is in SLI2/SLI3 mode - interrupts are enabled.
  4259. * The SLI interface allows only one mailbox pending at a time. If the
  4260. * mailbox is issued in polling mode and there is already a mailbox
  4261. * pending, then the function will return an error. If the mailbox is issued
  4262. * in NO_WAIT mode and there is a mailbox pending already, the function
  4263. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4264. * The sli layer owns the mailbox object until the completion of mailbox
  4265. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4266. * return codes the caller owns the mailbox command after the return of
  4267. * the function.
  4268. **/
  4269. static int
  4270. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4271. uint32_t flag)
  4272. {
  4273. MAILBOX_t *mb;
  4274. struct lpfc_sli *psli = &phba->sli;
  4275. uint32_t status, evtctr;
  4276. uint32_t ha_copy;
  4277. int i;
  4278. unsigned long timeout;
  4279. unsigned long drvr_flag = 0;
  4280. uint32_t word0, ldata;
  4281. void __iomem *to_slim;
  4282. int processing_queue = 0;
  4283. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4284. if (!pmbox) {
  4285. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4286. /* processing mbox queue from intr_handler */
  4287. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4288. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4289. return MBX_SUCCESS;
  4290. }
  4291. processing_queue = 1;
  4292. pmbox = lpfc_mbox_get(phba);
  4293. if (!pmbox) {
  4294. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4295. return MBX_SUCCESS;
  4296. }
  4297. }
  4298. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4299. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4300. if(!pmbox->vport) {
  4301. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4302. lpfc_printf_log(phba, KERN_ERR,
  4303. LOG_MBOX | LOG_VPORT,
  4304. "1806 Mbox x%x failed. No vport\n",
  4305. pmbox->u.mb.mbxCommand);
  4306. dump_stack();
  4307. goto out_not_finished;
  4308. }
  4309. }
  4310. /* If the PCI channel is in offline state, do not post mbox. */
  4311. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4312. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4313. goto out_not_finished;
  4314. }
  4315. /* If HBA has a deferred error attention, fail the iocb. */
  4316. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4317. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4318. goto out_not_finished;
  4319. }
  4320. psli = &phba->sli;
  4321. mb = &pmbox->u.mb;
  4322. status = MBX_SUCCESS;
  4323. if (phba->link_state == LPFC_HBA_ERROR) {
  4324. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4325. /* Mbox command <mbxCommand> cannot issue */
  4326. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4327. "(%d):0311 Mailbox command x%x cannot "
  4328. "issue Data: x%x x%x\n",
  4329. pmbox->vport ? pmbox->vport->vpi : 0,
  4330. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4331. goto out_not_finished;
  4332. }
  4333. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4334. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4335. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4336. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4337. "(%d):2528 Mailbox command x%x cannot "
  4338. "issue Data: x%x x%x\n",
  4339. pmbox->vport ? pmbox->vport->vpi : 0,
  4340. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4341. goto out_not_finished;
  4342. }
  4343. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4344. /* Polling for a mbox command when another one is already active
  4345. * is not allowed in SLI. Also, the driver must have established
  4346. * SLI2 mode to queue and process multiple mbox commands.
  4347. */
  4348. if (flag & MBX_POLL) {
  4349. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4350. /* Mbox command <mbxCommand> cannot issue */
  4351. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4352. "(%d):2529 Mailbox command x%x "
  4353. "cannot issue Data: x%x x%x\n",
  4354. pmbox->vport ? pmbox->vport->vpi : 0,
  4355. pmbox->u.mb.mbxCommand,
  4356. psli->sli_flag, flag);
  4357. goto out_not_finished;
  4358. }
  4359. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4360. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4361. /* Mbox command <mbxCommand> cannot issue */
  4362. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4363. "(%d):2530 Mailbox command x%x "
  4364. "cannot issue Data: x%x x%x\n",
  4365. pmbox->vport ? pmbox->vport->vpi : 0,
  4366. pmbox->u.mb.mbxCommand,
  4367. psli->sli_flag, flag);
  4368. goto out_not_finished;
  4369. }
  4370. /* Another mailbox command is still being processed, queue this
  4371. * command to be processed later.
  4372. */
  4373. lpfc_mbox_put(phba, pmbox);
  4374. /* Mbox cmd issue - BUSY */
  4375. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4376. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4377. "x%x x%x x%x x%x\n",
  4378. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4379. mb->mbxCommand, phba->pport->port_state,
  4380. psli->sli_flag, flag);
  4381. psli->slistat.mbox_busy++;
  4382. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4383. if (pmbox->vport) {
  4384. lpfc_debugfs_disc_trc(pmbox->vport,
  4385. LPFC_DISC_TRC_MBOX_VPORT,
  4386. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4387. (uint32_t)mb->mbxCommand,
  4388. mb->un.varWords[0], mb->un.varWords[1]);
  4389. }
  4390. else {
  4391. lpfc_debugfs_disc_trc(phba->pport,
  4392. LPFC_DISC_TRC_MBOX,
  4393. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4394. (uint32_t)mb->mbxCommand,
  4395. mb->un.varWords[0], mb->un.varWords[1]);
  4396. }
  4397. return MBX_BUSY;
  4398. }
  4399. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4400. /* If we are not polling, we MUST be in SLI2 mode */
  4401. if (flag != MBX_POLL) {
  4402. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4403. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4404. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4405. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4406. /* Mbox command <mbxCommand> cannot issue */
  4407. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4408. "(%d):2531 Mailbox command x%x "
  4409. "cannot issue Data: x%x x%x\n",
  4410. pmbox->vport ? pmbox->vport->vpi : 0,
  4411. pmbox->u.mb.mbxCommand,
  4412. psli->sli_flag, flag);
  4413. goto out_not_finished;
  4414. }
  4415. /* timeout active mbox command */
  4416. mod_timer(&psli->mbox_tmo, (jiffies +
  4417. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4418. }
  4419. /* Mailbox cmd <cmd> issue */
  4420. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4421. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4422. "x%x\n",
  4423. pmbox->vport ? pmbox->vport->vpi : 0,
  4424. mb->mbxCommand, phba->pport->port_state,
  4425. psli->sli_flag, flag);
  4426. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4427. if (pmbox->vport) {
  4428. lpfc_debugfs_disc_trc(pmbox->vport,
  4429. LPFC_DISC_TRC_MBOX_VPORT,
  4430. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4431. (uint32_t)mb->mbxCommand,
  4432. mb->un.varWords[0], mb->un.varWords[1]);
  4433. }
  4434. else {
  4435. lpfc_debugfs_disc_trc(phba->pport,
  4436. LPFC_DISC_TRC_MBOX,
  4437. "MBOX Send: cmd:x%x mb:x%x x%x",
  4438. (uint32_t)mb->mbxCommand,
  4439. mb->un.varWords[0], mb->un.varWords[1]);
  4440. }
  4441. }
  4442. psli->slistat.mbox_cmd++;
  4443. evtctr = psli->slistat.mbox_event;
  4444. /* next set own bit for the adapter and copy over command word */
  4445. mb->mbxOwner = OWN_CHIP;
  4446. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4447. /* Populate mbox extension offset word. */
  4448. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4449. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4450. = (uint8_t *)phba->mbox_ext
  4451. - (uint8_t *)phba->mbox;
  4452. }
  4453. /* Copy the mailbox extension data */
  4454. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4455. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4456. (uint8_t *)phba->mbox_ext,
  4457. pmbox->in_ext_byte_len);
  4458. }
  4459. /* Copy command data to host SLIM area */
  4460. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4461. } else {
  4462. /* Populate mbox extension offset word. */
  4463. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4464. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4465. = MAILBOX_HBA_EXT_OFFSET;
  4466. /* Copy the mailbox extension data */
  4467. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4468. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4469. MAILBOX_HBA_EXT_OFFSET,
  4470. pmbox->context2, pmbox->in_ext_byte_len);
  4471. }
  4472. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4473. /* copy command data into host mbox for cmpl */
  4474. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4475. }
  4476. /* First copy mbox command data to HBA SLIM, skip past first
  4477. word */
  4478. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4479. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4480. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4481. /* Next copy over first word, with mbxOwner set */
  4482. ldata = *((uint32_t *)mb);
  4483. to_slim = phba->MBslimaddr;
  4484. writel(ldata, to_slim);
  4485. readl(to_slim); /* flush */
  4486. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4487. /* switch over to host mailbox */
  4488. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4489. }
  4490. }
  4491. wmb();
  4492. switch (flag) {
  4493. case MBX_NOWAIT:
  4494. /* Set up reference to mailbox command */
  4495. psli->mbox_active = pmbox;
  4496. /* Interrupt board to do it */
  4497. writel(CA_MBATT, phba->CAregaddr);
  4498. readl(phba->CAregaddr); /* flush */
  4499. /* Don't wait for it to finish, just return */
  4500. break;
  4501. case MBX_POLL:
  4502. /* Set up null reference to mailbox command */
  4503. psli->mbox_active = NULL;
  4504. /* Interrupt board to do it */
  4505. writel(CA_MBATT, phba->CAregaddr);
  4506. readl(phba->CAregaddr); /* flush */
  4507. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4508. /* First read mbox status word */
  4509. word0 = *((uint32_t *)phba->mbox);
  4510. word0 = le32_to_cpu(word0);
  4511. } else {
  4512. /* First read mbox status word */
  4513. word0 = readl(phba->MBslimaddr);
  4514. }
  4515. /* Read the HBA Host Attention Register */
  4516. ha_copy = readl(phba->HAregaddr);
  4517. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4518. mb->mbxCommand) *
  4519. 1000) + jiffies;
  4520. i = 0;
  4521. /* Wait for command to complete */
  4522. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4523. (!(ha_copy & HA_MBATT) &&
  4524. (phba->link_state > LPFC_WARM_START))) {
  4525. if (time_after(jiffies, timeout)) {
  4526. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4527. spin_unlock_irqrestore(&phba->hbalock,
  4528. drvr_flag);
  4529. goto out_not_finished;
  4530. }
  4531. /* Check if we took a mbox interrupt while we were
  4532. polling */
  4533. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4534. && (evtctr != psli->slistat.mbox_event))
  4535. break;
  4536. if (i++ > 10) {
  4537. spin_unlock_irqrestore(&phba->hbalock,
  4538. drvr_flag);
  4539. msleep(1);
  4540. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4541. }
  4542. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4543. /* First copy command data */
  4544. word0 = *((uint32_t *)phba->mbox);
  4545. word0 = le32_to_cpu(word0);
  4546. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4547. MAILBOX_t *slimmb;
  4548. uint32_t slimword0;
  4549. /* Check real SLIM for any errors */
  4550. slimword0 = readl(phba->MBslimaddr);
  4551. slimmb = (MAILBOX_t *) & slimword0;
  4552. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4553. && slimmb->mbxStatus) {
  4554. psli->sli_flag &=
  4555. ~LPFC_SLI_ACTIVE;
  4556. word0 = slimword0;
  4557. }
  4558. }
  4559. } else {
  4560. /* First copy command data */
  4561. word0 = readl(phba->MBslimaddr);
  4562. }
  4563. /* Read the HBA Host Attention Register */
  4564. ha_copy = readl(phba->HAregaddr);
  4565. }
  4566. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4567. /* copy results back to user */
  4568. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4569. /* Copy the mailbox extension data */
  4570. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4571. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4572. pmbox->context2,
  4573. pmbox->out_ext_byte_len);
  4574. }
  4575. } else {
  4576. /* First copy command data */
  4577. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4578. MAILBOX_CMD_SIZE);
  4579. /* Copy the mailbox extension data */
  4580. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4581. lpfc_memcpy_from_slim(pmbox->context2,
  4582. phba->MBslimaddr +
  4583. MAILBOX_HBA_EXT_OFFSET,
  4584. pmbox->out_ext_byte_len);
  4585. }
  4586. }
  4587. writel(HA_MBATT, phba->HAregaddr);
  4588. readl(phba->HAregaddr); /* flush */
  4589. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4590. status = mb->mbxStatus;
  4591. }
  4592. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4593. return status;
  4594. out_not_finished:
  4595. if (processing_queue) {
  4596. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4597. lpfc_mbox_cmpl_put(phba, pmbox);
  4598. }
  4599. return MBX_NOT_FINISHED;
  4600. }
  4601. /**
  4602. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4603. * @phba: Pointer to HBA context object.
  4604. *
  4605. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4606. * the driver internal pending mailbox queue. It will then try to wait out the
  4607. * possible outstanding mailbox command before return.
  4608. *
  4609. * Returns:
  4610. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4611. * the outstanding mailbox command timed out.
  4612. **/
  4613. static int
  4614. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4615. {
  4616. struct lpfc_sli *psli = &phba->sli;
  4617. uint8_t actcmd = MBX_HEARTBEAT;
  4618. int rc = 0;
  4619. unsigned long timeout;
  4620. /* Mark the asynchronous mailbox command posting as blocked */
  4621. spin_lock_irq(&phba->hbalock);
  4622. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4623. if (phba->sli.mbox_active)
  4624. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4625. spin_unlock_irq(&phba->hbalock);
  4626. /* Determine how long we might wait for the active mailbox
  4627. * command to be gracefully completed by firmware.
  4628. */
  4629. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4630. jiffies;
  4631. /* Wait for the outstnading mailbox command to complete */
  4632. while (phba->sli.mbox_active) {
  4633. /* Check active mailbox complete status every 2ms */
  4634. msleep(2);
  4635. if (time_after(jiffies, timeout)) {
  4636. /* Timeout, marked the outstanding cmd not complete */
  4637. rc = 1;
  4638. break;
  4639. }
  4640. }
  4641. /* Can not cleanly block async mailbox command, fails it */
  4642. if (rc) {
  4643. spin_lock_irq(&phba->hbalock);
  4644. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4645. spin_unlock_irq(&phba->hbalock);
  4646. }
  4647. return rc;
  4648. }
  4649. /**
  4650. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4651. * @phba: Pointer to HBA context object.
  4652. *
  4653. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4654. * commands from the driver internal pending mailbox queue. It makes sure
  4655. * that there is no outstanding mailbox command before resuming posting
  4656. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4657. * mailbox command, it will try to wait it out before resuming asynchronous
  4658. * mailbox command posting.
  4659. **/
  4660. static void
  4661. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4662. {
  4663. struct lpfc_sli *psli = &phba->sli;
  4664. spin_lock_irq(&phba->hbalock);
  4665. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4666. /* Asynchronous mailbox posting is not blocked, do nothing */
  4667. spin_unlock_irq(&phba->hbalock);
  4668. return;
  4669. }
  4670. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4671. * successful or timeout, after timing-out the outstanding mailbox
  4672. * command shall always be removed, so just unblock posting async
  4673. * mailbox command and resume
  4674. */
  4675. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4676. spin_unlock_irq(&phba->hbalock);
  4677. /* wake up worker thread to post asynchronlous mailbox command */
  4678. lpfc_worker_wake_up(phba);
  4679. }
  4680. /**
  4681. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4682. * @phba: Pointer to HBA context object.
  4683. * @mboxq: Pointer to mailbox object.
  4684. *
  4685. * The function posts a mailbox to the port. The mailbox is expected
  4686. * to be comletely filled in and ready for the port to operate on it.
  4687. * This routine executes a synchronous completion operation on the
  4688. * mailbox by polling for its completion.
  4689. *
  4690. * The caller must not be holding any locks when calling this routine.
  4691. *
  4692. * Returns:
  4693. * MBX_SUCCESS - mailbox posted successfully
  4694. * Any of the MBX error values.
  4695. **/
  4696. static int
  4697. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4698. {
  4699. int rc = MBX_SUCCESS;
  4700. unsigned long iflag;
  4701. uint32_t db_ready;
  4702. uint32_t mcqe_status;
  4703. uint32_t mbx_cmnd;
  4704. unsigned long timeout;
  4705. struct lpfc_sli *psli = &phba->sli;
  4706. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4707. struct lpfc_bmbx_create *mbox_rgn;
  4708. struct dma_address *dma_address;
  4709. struct lpfc_register bmbx_reg;
  4710. /*
  4711. * Only one mailbox can be active to the bootstrap mailbox region
  4712. * at a time and there is no queueing provided.
  4713. */
  4714. spin_lock_irqsave(&phba->hbalock, iflag);
  4715. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4716. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4717. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4718. "(%d):2532 Mailbox command x%x (x%x) "
  4719. "cannot issue Data: x%x x%x\n",
  4720. mboxq->vport ? mboxq->vport->vpi : 0,
  4721. mboxq->u.mb.mbxCommand,
  4722. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4723. psli->sli_flag, MBX_POLL);
  4724. return MBXERR_ERROR;
  4725. }
  4726. /* The server grabs the token and owns it until release */
  4727. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4728. phba->sli.mbox_active = mboxq;
  4729. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4730. /*
  4731. * Initialize the bootstrap memory region to avoid stale data areas
  4732. * in the mailbox post. Then copy the caller's mailbox contents to
  4733. * the bmbx mailbox region.
  4734. */
  4735. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4736. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4737. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4738. sizeof(struct lpfc_mqe));
  4739. /* Post the high mailbox dma address to the port and wait for ready. */
  4740. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4741. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4742. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4743. * 1000) + jiffies;
  4744. do {
  4745. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4746. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4747. if (!db_ready)
  4748. msleep(2);
  4749. if (time_after(jiffies, timeout)) {
  4750. rc = MBXERR_ERROR;
  4751. goto exit;
  4752. }
  4753. } while (!db_ready);
  4754. /* Post the low mailbox dma address to the port. */
  4755. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4756. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4757. * 1000) + jiffies;
  4758. do {
  4759. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4760. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4761. if (!db_ready)
  4762. msleep(2);
  4763. if (time_after(jiffies, timeout)) {
  4764. rc = MBXERR_ERROR;
  4765. goto exit;
  4766. }
  4767. } while (!db_ready);
  4768. /*
  4769. * Read the CQ to ensure the mailbox has completed.
  4770. * If so, update the mailbox status so that the upper layers
  4771. * can complete the request normally.
  4772. */
  4773. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4774. sizeof(struct lpfc_mqe));
  4775. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4776. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4777. sizeof(struct lpfc_mcqe));
  4778. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4779. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4780. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4781. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4782. rc = MBXERR_ERROR;
  4783. } else
  4784. lpfc_sli4_swap_str(phba, mboxq);
  4785. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4786. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4787. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4788. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4789. mboxq->vport ? mboxq->vport->vpi : 0,
  4790. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4791. bf_get(lpfc_mqe_status, mb),
  4792. mb->un.mb_words[0], mb->un.mb_words[1],
  4793. mb->un.mb_words[2], mb->un.mb_words[3],
  4794. mb->un.mb_words[4], mb->un.mb_words[5],
  4795. mb->un.mb_words[6], mb->un.mb_words[7],
  4796. mb->un.mb_words[8], mb->un.mb_words[9],
  4797. mb->un.mb_words[10], mb->un.mb_words[11],
  4798. mb->un.mb_words[12], mboxq->mcqe.word0,
  4799. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4800. mboxq->mcqe.trailer);
  4801. exit:
  4802. /* We are holding the token, no needed for lock when release */
  4803. spin_lock_irqsave(&phba->hbalock, iflag);
  4804. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4805. phba->sli.mbox_active = NULL;
  4806. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4807. return rc;
  4808. }
  4809. /**
  4810. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4811. * @phba: Pointer to HBA context object.
  4812. * @pmbox: Pointer to mailbox object.
  4813. * @flag: Flag indicating how the mailbox need to be processed.
  4814. *
  4815. * This function is called by discovery code and HBA management code to submit
  4816. * a mailbox command to firmware with SLI-4 interface spec.
  4817. *
  4818. * Return codes the caller owns the mailbox command after the return of the
  4819. * function.
  4820. **/
  4821. static int
  4822. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4823. uint32_t flag)
  4824. {
  4825. struct lpfc_sli *psli = &phba->sli;
  4826. unsigned long iflags;
  4827. int rc;
  4828. rc = lpfc_mbox_dev_check(phba);
  4829. if (unlikely(rc)) {
  4830. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4831. "(%d):2544 Mailbox command x%x (x%x) "
  4832. "cannot issue Data: x%x x%x\n",
  4833. mboxq->vport ? mboxq->vport->vpi : 0,
  4834. mboxq->u.mb.mbxCommand,
  4835. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4836. psli->sli_flag, flag);
  4837. goto out_not_finished;
  4838. }
  4839. /* Detect polling mode and jump to a handler */
  4840. if (!phba->sli4_hba.intr_enable) {
  4841. if (flag == MBX_POLL)
  4842. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4843. else
  4844. rc = -EIO;
  4845. if (rc != MBX_SUCCESS)
  4846. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4847. "(%d):2541 Mailbox command x%x "
  4848. "(x%x) cannot issue Data: x%x x%x\n",
  4849. mboxq->vport ? mboxq->vport->vpi : 0,
  4850. mboxq->u.mb.mbxCommand,
  4851. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4852. psli->sli_flag, flag);
  4853. return rc;
  4854. } else if (flag == MBX_POLL) {
  4855. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4856. "(%d):2542 Try to issue mailbox command "
  4857. "x%x (x%x) synchronously ahead of async"
  4858. "mailbox command queue: x%x x%x\n",
  4859. mboxq->vport ? mboxq->vport->vpi : 0,
  4860. mboxq->u.mb.mbxCommand,
  4861. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4862. psli->sli_flag, flag);
  4863. /* Try to block the asynchronous mailbox posting */
  4864. rc = lpfc_sli4_async_mbox_block(phba);
  4865. if (!rc) {
  4866. /* Successfully blocked, now issue sync mbox cmd */
  4867. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4868. if (rc != MBX_SUCCESS)
  4869. lpfc_printf_log(phba, KERN_ERR,
  4870. LOG_MBOX | LOG_SLI,
  4871. "(%d):2597 Mailbox command "
  4872. "x%x (x%x) cannot issue "
  4873. "Data: x%x x%x\n",
  4874. mboxq->vport ?
  4875. mboxq->vport->vpi : 0,
  4876. mboxq->u.mb.mbxCommand,
  4877. lpfc_sli4_mbox_opcode_get(phba,
  4878. mboxq),
  4879. psli->sli_flag, flag);
  4880. /* Unblock the async mailbox posting afterward */
  4881. lpfc_sli4_async_mbox_unblock(phba);
  4882. }
  4883. return rc;
  4884. }
  4885. /* Now, interrupt mode asynchrous mailbox command */
  4886. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4887. if (rc) {
  4888. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4889. "(%d):2543 Mailbox command x%x (x%x) "
  4890. "cannot issue Data: x%x x%x\n",
  4891. mboxq->vport ? mboxq->vport->vpi : 0,
  4892. mboxq->u.mb.mbxCommand,
  4893. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4894. psli->sli_flag, flag);
  4895. goto out_not_finished;
  4896. }
  4897. /* Put the mailbox command to the driver internal FIFO */
  4898. psli->slistat.mbox_busy++;
  4899. spin_lock_irqsave(&phba->hbalock, iflags);
  4900. lpfc_mbox_put(phba, mboxq);
  4901. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4902. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4903. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4904. "x%x (x%x) x%x x%x x%x\n",
  4905. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4906. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4907. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4908. phba->pport->port_state,
  4909. psli->sli_flag, MBX_NOWAIT);
  4910. /* Wake up worker thread to transport mailbox command from head */
  4911. lpfc_worker_wake_up(phba);
  4912. return MBX_BUSY;
  4913. out_not_finished:
  4914. return MBX_NOT_FINISHED;
  4915. }
  4916. /**
  4917. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4918. * @phba: Pointer to HBA context object.
  4919. *
  4920. * This function is called by worker thread to send a mailbox command to
  4921. * SLI4 HBA firmware.
  4922. *
  4923. **/
  4924. int
  4925. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4926. {
  4927. struct lpfc_sli *psli = &phba->sli;
  4928. LPFC_MBOXQ_t *mboxq;
  4929. int rc = MBX_SUCCESS;
  4930. unsigned long iflags;
  4931. struct lpfc_mqe *mqe;
  4932. uint32_t mbx_cmnd;
  4933. /* Check interrupt mode before post async mailbox command */
  4934. if (unlikely(!phba->sli4_hba.intr_enable))
  4935. return MBX_NOT_FINISHED;
  4936. /* Check for mailbox command service token */
  4937. spin_lock_irqsave(&phba->hbalock, iflags);
  4938. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4939. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4940. return MBX_NOT_FINISHED;
  4941. }
  4942. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4943. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4944. return MBX_NOT_FINISHED;
  4945. }
  4946. if (unlikely(phba->sli.mbox_active)) {
  4947. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4948. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4949. "0384 There is pending active mailbox cmd\n");
  4950. return MBX_NOT_FINISHED;
  4951. }
  4952. /* Take the mailbox command service token */
  4953. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4954. /* Get the next mailbox command from head of queue */
  4955. mboxq = lpfc_mbox_get(phba);
  4956. /* If no more mailbox command waiting for post, we're done */
  4957. if (!mboxq) {
  4958. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4959. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4960. return MBX_SUCCESS;
  4961. }
  4962. phba->sli.mbox_active = mboxq;
  4963. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4964. /* Check device readiness for posting mailbox command */
  4965. rc = lpfc_mbox_dev_check(phba);
  4966. if (unlikely(rc))
  4967. /* Driver clean routine will clean up pending mailbox */
  4968. goto out_not_finished;
  4969. /* Prepare the mbox command to be posted */
  4970. mqe = &mboxq->u.mqe;
  4971. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4972. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4973. mod_timer(&psli->mbox_tmo, (jiffies +
  4974. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4975. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4976. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4977. "x%x x%x\n",
  4978. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4979. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4980. phba->pport->port_state, psli->sli_flag);
  4981. if (mbx_cmnd != MBX_HEARTBEAT) {
  4982. if (mboxq->vport) {
  4983. lpfc_debugfs_disc_trc(mboxq->vport,
  4984. LPFC_DISC_TRC_MBOX_VPORT,
  4985. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4986. mbx_cmnd, mqe->un.mb_words[0],
  4987. mqe->un.mb_words[1]);
  4988. } else {
  4989. lpfc_debugfs_disc_trc(phba->pport,
  4990. LPFC_DISC_TRC_MBOX,
  4991. "MBOX Send: cmd:x%x mb:x%x x%x",
  4992. mbx_cmnd, mqe->un.mb_words[0],
  4993. mqe->un.mb_words[1]);
  4994. }
  4995. }
  4996. psli->slistat.mbox_cmd++;
  4997. /* Post the mailbox command to the port */
  4998. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4999. if (rc != MBX_SUCCESS) {
  5000. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5001. "(%d):2533 Mailbox command x%x (x%x) "
  5002. "cannot issue Data: x%x x%x\n",
  5003. mboxq->vport ? mboxq->vport->vpi : 0,
  5004. mboxq->u.mb.mbxCommand,
  5005. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5006. psli->sli_flag, MBX_NOWAIT);
  5007. goto out_not_finished;
  5008. }
  5009. return rc;
  5010. out_not_finished:
  5011. spin_lock_irqsave(&phba->hbalock, iflags);
  5012. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5013. __lpfc_mbox_cmpl_put(phba, mboxq);
  5014. /* Release the token */
  5015. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5016. phba->sli.mbox_active = NULL;
  5017. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5018. return MBX_NOT_FINISHED;
  5019. }
  5020. /**
  5021. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5022. * @phba: Pointer to HBA context object.
  5023. * @pmbox: Pointer to mailbox object.
  5024. * @flag: Flag indicating how the mailbox need to be processed.
  5025. *
  5026. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5027. * the API jump table function pointer from the lpfc_hba struct.
  5028. *
  5029. * Return codes the caller owns the mailbox command after the return of the
  5030. * function.
  5031. **/
  5032. int
  5033. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5034. {
  5035. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5036. }
  5037. /**
  5038. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5039. * @phba: The hba struct for which this call is being executed.
  5040. * @dev_grp: The HBA PCI-Device group number.
  5041. *
  5042. * This routine sets up the mbox interface API function jump table in @phba
  5043. * struct.
  5044. * Returns: 0 - success, -ENODEV - failure.
  5045. **/
  5046. int
  5047. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5048. {
  5049. switch (dev_grp) {
  5050. case LPFC_PCI_DEV_LP:
  5051. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5052. phba->lpfc_sli_handle_slow_ring_event =
  5053. lpfc_sli_handle_slow_ring_event_s3;
  5054. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5055. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5056. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5057. break;
  5058. case LPFC_PCI_DEV_OC:
  5059. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5060. phba->lpfc_sli_handle_slow_ring_event =
  5061. lpfc_sli_handle_slow_ring_event_s4;
  5062. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5063. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5064. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5065. break;
  5066. default:
  5067. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5068. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5069. dev_grp);
  5070. return -ENODEV;
  5071. break;
  5072. }
  5073. return 0;
  5074. }
  5075. /**
  5076. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5077. * @phba: Pointer to HBA context object.
  5078. * @pring: Pointer to driver SLI ring object.
  5079. * @piocb: Pointer to address of newly added command iocb.
  5080. *
  5081. * This function is called with hbalock held to add a command
  5082. * iocb to the txq when SLI layer cannot submit the command iocb
  5083. * to the ring.
  5084. **/
  5085. void
  5086. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5087. struct lpfc_iocbq *piocb)
  5088. {
  5089. /* Insert the caller's iocb in the txq tail for later processing. */
  5090. list_add_tail(&piocb->list, &pring->txq);
  5091. pring->txq_cnt++;
  5092. }
  5093. /**
  5094. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5095. * @phba: Pointer to HBA context object.
  5096. * @pring: Pointer to driver SLI ring object.
  5097. * @piocb: Pointer to address of newly added command iocb.
  5098. *
  5099. * This function is called with hbalock held before a new
  5100. * iocb is submitted to the firmware. This function checks
  5101. * txq to flush the iocbs in txq to Firmware before
  5102. * submitting new iocbs to the Firmware.
  5103. * If there are iocbs in the txq which need to be submitted
  5104. * to firmware, lpfc_sli_next_iocb returns the first element
  5105. * of the txq after dequeuing it from txq.
  5106. * If there is no iocb in the txq then the function will return
  5107. * *piocb and *piocb is set to NULL. Caller needs to check
  5108. * *piocb to find if there are more commands in the txq.
  5109. **/
  5110. static struct lpfc_iocbq *
  5111. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5112. struct lpfc_iocbq **piocb)
  5113. {
  5114. struct lpfc_iocbq * nextiocb;
  5115. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5116. if (!nextiocb) {
  5117. nextiocb = *piocb;
  5118. *piocb = NULL;
  5119. }
  5120. return nextiocb;
  5121. }
  5122. /**
  5123. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5124. * @phba: Pointer to HBA context object.
  5125. * @ring_number: SLI ring number to issue iocb on.
  5126. * @piocb: Pointer to command iocb.
  5127. * @flag: Flag indicating if this command can be put into txq.
  5128. *
  5129. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5130. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5131. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5132. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5133. * this function allows only iocbs for posting buffers. This function finds
  5134. * next available slot in the command ring and posts the command to the
  5135. * available slot and writes the port attention register to request HBA start
  5136. * processing new iocb. If there is no slot available in the ring and
  5137. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5138. * the function returns IOCB_BUSY.
  5139. *
  5140. * This function is called with hbalock held. The function will return success
  5141. * after it successfully submit the iocb to firmware or after adding to the
  5142. * txq.
  5143. **/
  5144. static int
  5145. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5146. struct lpfc_iocbq *piocb, uint32_t flag)
  5147. {
  5148. struct lpfc_iocbq *nextiocb;
  5149. IOCB_t *iocb;
  5150. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5151. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5152. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5153. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5154. lpfc_printf_log(phba, KERN_ERR,
  5155. LOG_SLI | LOG_VPORT,
  5156. "1807 IOCB x%x failed. No vport\n",
  5157. piocb->iocb.ulpCommand);
  5158. dump_stack();
  5159. return IOCB_ERROR;
  5160. }
  5161. /* If the PCI channel is in offline state, do not post iocbs. */
  5162. if (unlikely(pci_channel_offline(phba->pcidev)))
  5163. return IOCB_ERROR;
  5164. /* If HBA has a deferred error attention, fail the iocb. */
  5165. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5166. return IOCB_ERROR;
  5167. /*
  5168. * We should never get an IOCB if we are in a < LINK_DOWN state
  5169. */
  5170. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5171. return IOCB_ERROR;
  5172. /*
  5173. * Check to see if we are blocking IOCB processing because of a
  5174. * outstanding event.
  5175. */
  5176. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5177. goto iocb_busy;
  5178. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5179. /*
  5180. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5181. * can be issued if the link is not up.
  5182. */
  5183. switch (piocb->iocb.ulpCommand) {
  5184. case CMD_GEN_REQUEST64_CR:
  5185. case CMD_GEN_REQUEST64_CX:
  5186. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5187. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5188. FC_RCTL_DD_UNSOL_CMD) ||
  5189. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5190. MENLO_TRANSPORT_TYPE))
  5191. goto iocb_busy;
  5192. break;
  5193. case CMD_QUE_RING_BUF_CN:
  5194. case CMD_QUE_RING_BUF64_CN:
  5195. /*
  5196. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5197. * completion, iocb_cmpl MUST be 0.
  5198. */
  5199. if (piocb->iocb_cmpl)
  5200. piocb->iocb_cmpl = NULL;
  5201. /*FALLTHROUGH*/
  5202. case CMD_CREATE_XRI_CR:
  5203. case CMD_CLOSE_XRI_CN:
  5204. case CMD_CLOSE_XRI_CX:
  5205. break;
  5206. default:
  5207. goto iocb_busy;
  5208. }
  5209. /*
  5210. * For FCP commands, we must be in a state where we can process link
  5211. * attention events.
  5212. */
  5213. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5214. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5215. goto iocb_busy;
  5216. }
  5217. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5218. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5219. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5220. if (iocb)
  5221. lpfc_sli_update_ring(phba, pring);
  5222. else
  5223. lpfc_sli_update_full_ring(phba, pring);
  5224. if (!piocb)
  5225. return IOCB_SUCCESS;
  5226. goto out_busy;
  5227. iocb_busy:
  5228. pring->stats.iocb_cmd_delay++;
  5229. out_busy:
  5230. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5231. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5232. return IOCB_SUCCESS;
  5233. }
  5234. return IOCB_BUSY;
  5235. }
  5236. /**
  5237. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5238. * @phba: Pointer to HBA context object.
  5239. * @piocb: Pointer to command iocb.
  5240. * @sglq: Pointer to the scatter gather queue object.
  5241. *
  5242. * This routine converts the bpl or bde that is in the IOCB
  5243. * to a sgl list for the sli4 hardware. The physical address
  5244. * of the bpl/bde is converted back to a virtual address.
  5245. * If the IOCB contains a BPL then the list of BDE's is
  5246. * converted to sli4_sge's. If the IOCB contains a single
  5247. * BDE then it is converted to a single sli_sge.
  5248. * The IOCB is still in cpu endianess so the contents of
  5249. * the bpl can be used without byte swapping.
  5250. *
  5251. * Returns valid XRI = Success, NO_XRI = Failure.
  5252. **/
  5253. static uint16_t
  5254. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5255. struct lpfc_sglq *sglq)
  5256. {
  5257. uint16_t xritag = NO_XRI;
  5258. struct ulp_bde64 *bpl = NULL;
  5259. struct ulp_bde64 bde;
  5260. struct sli4_sge *sgl = NULL;
  5261. IOCB_t *icmd;
  5262. int numBdes = 0;
  5263. int i = 0;
  5264. if (!piocbq || !sglq)
  5265. return xritag;
  5266. sgl = (struct sli4_sge *)sglq->sgl;
  5267. icmd = &piocbq->iocb;
  5268. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5269. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5270. sizeof(struct ulp_bde64);
  5271. /* The addrHigh and addrLow fields within the IOCB
  5272. * have not been byteswapped yet so there is no
  5273. * need to swap them back.
  5274. */
  5275. bpl = (struct ulp_bde64 *)
  5276. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5277. if (!bpl)
  5278. return xritag;
  5279. for (i = 0; i < numBdes; i++) {
  5280. /* Should already be byte swapped. */
  5281. sgl->addr_hi = bpl->addrHigh;
  5282. sgl->addr_lo = bpl->addrLow;
  5283. if ((i+1) == numBdes)
  5284. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5285. else
  5286. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5287. sgl->word2 = cpu_to_le32(sgl->word2);
  5288. /* swap the size field back to the cpu so we
  5289. * can assign it to the sgl.
  5290. */
  5291. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5292. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5293. bpl++;
  5294. sgl++;
  5295. }
  5296. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5297. /* The addrHigh and addrLow fields of the BDE have not
  5298. * been byteswapped yet so they need to be swapped
  5299. * before putting them in the sgl.
  5300. */
  5301. sgl->addr_hi =
  5302. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5303. sgl->addr_lo =
  5304. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5305. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5306. sgl->word2 = cpu_to_le32(sgl->word2);
  5307. sgl->sge_len =
  5308. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5309. }
  5310. return sglq->sli4_xritag;
  5311. }
  5312. /**
  5313. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5314. * @phba: Pointer to HBA context object.
  5315. *
  5316. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5317. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5318. * held.
  5319. *
  5320. * Return: index into SLI4 fast-path FCP queue index.
  5321. **/
  5322. static uint32_t
  5323. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5324. {
  5325. ++phba->fcp_qidx;
  5326. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5327. phba->fcp_qidx = 0;
  5328. return phba->fcp_qidx;
  5329. }
  5330. /**
  5331. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5332. * @phba: Pointer to HBA context object.
  5333. * @piocb: Pointer to command iocb.
  5334. * @wqe: Pointer to the work queue entry.
  5335. *
  5336. * This routine converts the iocb command to its Work Queue Entry
  5337. * equivalent. The wqe pointer should not have any fields set when
  5338. * this routine is called because it will memcpy over them.
  5339. * This routine does not set the CQ_ID or the WQEC bits in the
  5340. * wqe.
  5341. *
  5342. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5343. **/
  5344. static int
  5345. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5346. union lpfc_wqe *wqe)
  5347. {
  5348. uint32_t xmit_len = 0, total_len = 0;
  5349. uint8_t ct = 0;
  5350. uint32_t fip;
  5351. uint32_t abort_tag;
  5352. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5353. uint8_t cmnd;
  5354. uint16_t xritag;
  5355. struct ulp_bde64 *bpl = NULL;
  5356. uint32_t els_id = ELS_ID_DEFAULT;
  5357. int numBdes, i;
  5358. struct ulp_bde64 bde;
  5359. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5360. /* The fcp commands will set command type */
  5361. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5362. command_type = FCP_COMMAND;
  5363. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5364. command_type = ELS_COMMAND_FIP;
  5365. else
  5366. command_type = ELS_COMMAND_NON_FIP;
  5367. /* Some of the fields are in the right position already */
  5368. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5369. abort_tag = (uint32_t) iocbq->iotag;
  5370. xritag = iocbq->sli4_xritag;
  5371. wqe->words[7] = 0; /* The ct field has moved so reset */
  5372. /* words0-2 bpl convert bde */
  5373. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5374. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5375. sizeof(struct ulp_bde64);
  5376. bpl = (struct ulp_bde64 *)
  5377. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5378. if (!bpl)
  5379. return IOCB_ERROR;
  5380. /* Should already be byte swapped. */
  5381. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5382. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5383. /* swap the size field back to the cpu so we
  5384. * can assign it to the sgl.
  5385. */
  5386. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5387. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5388. total_len = 0;
  5389. for (i = 0; i < numBdes; i++) {
  5390. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5391. total_len += bde.tus.f.bdeSize;
  5392. }
  5393. } else
  5394. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5395. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5396. cmnd = iocbq->iocb.ulpCommand;
  5397. switch (iocbq->iocb.ulpCommand) {
  5398. case CMD_ELS_REQUEST64_CR:
  5399. if (!iocbq->iocb.ulpLe) {
  5400. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5401. "2007 Only Limited Edition cmd Format"
  5402. " supported 0x%x\n",
  5403. iocbq->iocb.ulpCommand);
  5404. return IOCB_ERROR;
  5405. }
  5406. wqe->els_req.payload_len = xmit_len;
  5407. /* Els_reguest64 has a TMO */
  5408. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5409. iocbq->iocb.ulpTimeout);
  5410. /* Need a VF for word 4 set the vf bit*/
  5411. bf_set(els_req64_vf, &wqe->els_req, 0);
  5412. /* And a VFID for word 12 */
  5413. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5414. /*
  5415. * Set ct field to 3, indicates that the context_tag field
  5416. * contains the FCFI and remote N_Port_ID is
  5417. * in word 5.
  5418. */
  5419. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5420. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5421. iocbq->iocb.ulpContext);
  5422. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5423. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5424. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5425. if (command_type == ELS_COMMAND_FIP) {
  5426. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5427. >> LPFC_FIP_ELS_ID_SHIFT);
  5428. }
  5429. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5430. break;
  5431. case CMD_XMIT_SEQUENCE64_CX:
  5432. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5433. iocbq->iocb.un.ulpWord[3]);
  5434. wqe->generic.word3 = 0;
  5435. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5436. /* The entire sequence is transmitted for this IOCB */
  5437. xmit_len = total_len;
  5438. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5439. case CMD_XMIT_SEQUENCE64_CR:
  5440. /* word3 iocb=io_tag32 wqe=payload_offset */
  5441. /* payload offset used for multilpe outstanding
  5442. * sequences on the same exchange
  5443. */
  5444. wqe->words[3] = 0;
  5445. /* word4 relative_offset memcpy */
  5446. /* word5 r_ctl/df_ctl memcpy */
  5447. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5448. wqe->xmit_sequence.xmit_len = xmit_len;
  5449. command_type = OTHER_COMMAND;
  5450. break;
  5451. case CMD_XMIT_BCAST64_CN:
  5452. /* word3 iocb=iotag32 wqe=payload_len */
  5453. wqe->words[3] = 0; /* no definition for this in wqe */
  5454. /* word4 iocb=rsvd wqe=rsvd */
  5455. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5456. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5457. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5458. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5459. break;
  5460. case CMD_FCP_IWRITE64_CR:
  5461. command_type = FCP_COMMAND_DATA_OUT;
  5462. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5463. * confusing.
  5464. * word3 is payload_len: byte offset to the sgl entry for the
  5465. * fcp_command.
  5466. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5467. * word5 is initial xfer len 0 = wait for xfer-ready
  5468. */
  5469. /* Always wait for xfer-ready before sending data */
  5470. wqe->fcp_iwrite.initial_xfer_len = 0;
  5471. /* word 4 (xfer length) should have been set on the memcpy */
  5472. /* allow write to fall through to read */
  5473. case CMD_FCP_IREAD64_CR:
  5474. /* FCP_CMD is always the 1st sgl entry */
  5475. wqe->fcp_iread.payload_len =
  5476. xmit_len + sizeof(struct fcp_rsp);
  5477. /* word 4 (xfer length) should have been set on the memcpy */
  5478. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5479. iocbq->iocb.ulpFCP2Rcvy);
  5480. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5481. /* The XC bit and the XS bit are similar. The driver never
  5482. * tracked whether or not the exchange was previouslly open.
  5483. * XC = Exchange create, 0 is create. 1 is already open.
  5484. * XS = link cmd: 1 do not close the exchange after command.
  5485. * XS = 0 close exchange when command completes.
  5486. * The only time we would not set the XC bit is when the XS bit
  5487. * is set and we are sending our 2nd or greater command on
  5488. * this exchange.
  5489. */
  5490. /* Always open the exchange */
  5491. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5492. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5493. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5494. break;
  5495. case CMD_FCP_ICMND64_CR:
  5496. /* Always open the exchange */
  5497. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5498. wqe->words[4] = 0;
  5499. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5500. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5501. break;
  5502. case CMD_GEN_REQUEST64_CR:
  5503. /* word3 command length is described as byte offset to the
  5504. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5505. * sgl[0] = cmnd
  5506. * sgl[1] = rsp.
  5507. *
  5508. */
  5509. wqe->gen_req.command_len = xmit_len;
  5510. /* Word4 parameter copied in the memcpy */
  5511. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5512. /* word6 context tag copied in memcpy */
  5513. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5514. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5515. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5516. "2015 Invalid CT %x command 0x%x\n",
  5517. ct, iocbq->iocb.ulpCommand);
  5518. return IOCB_ERROR;
  5519. }
  5520. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5521. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5522. iocbq->iocb.ulpTimeout);
  5523. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5524. command_type = OTHER_COMMAND;
  5525. break;
  5526. case CMD_XMIT_ELS_RSP64_CX:
  5527. /* words0-2 BDE memcpy */
  5528. /* word3 iocb=iotag32 wqe=rsvd */
  5529. wqe->words[3] = 0;
  5530. /* word4 iocb=did wge=rsvd. */
  5531. wqe->words[4] = 0;
  5532. /* word5 iocb=rsvd wge=did */
  5533. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5534. iocbq->iocb.un.elsreq64.remoteID);
  5535. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5536. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5537. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5538. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5539. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5540. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5541. iocbq->vport->vpi + phba->vpi_base);
  5542. command_type = OTHER_COMMAND;
  5543. break;
  5544. case CMD_CLOSE_XRI_CN:
  5545. case CMD_ABORT_XRI_CN:
  5546. case CMD_ABORT_XRI_CX:
  5547. /* words 0-2 memcpy should be 0 rserved */
  5548. /* port will send abts */
  5549. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5550. /*
  5551. * The link is down so the fw does not need to send abts
  5552. * on the wire.
  5553. */
  5554. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5555. else
  5556. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5557. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5558. wqe->words[5] = 0;
  5559. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5560. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5561. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5562. /*
  5563. * The abort handler will send us CMD_ABORT_XRI_CN or
  5564. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5565. */
  5566. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5567. cmnd = CMD_ABORT_XRI_CX;
  5568. command_type = OTHER_COMMAND;
  5569. xritag = 0;
  5570. break;
  5571. case CMD_XMIT_BLS_RSP64_CX:
  5572. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5573. * we re-construct this WQE here based on information in
  5574. * iocbq from scratch.
  5575. */
  5576. memset(wqe, 0, sizeof(union lpfc_wqe));
  5577. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5578. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5579. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5580. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5581. LPFC_ABTS_UNSOL_INT) {
  5582. /* ABTS sent by initiator to CT exchange, the
  5583. * RX_ID field will be filled with the newly
  5584. * allocated responder XRI.
  5585. */
  5586. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5587. iocbq->sli4_xritag);
  5588. } else {
  5589. /* ABTS sent by responder to CT exchange, the
  5590. * RX_ID field will be filled with the responder
  5591. * RX_ID from ABTS.
  5592. */
  5593. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5594. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5595. }
  5596. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5597. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5598. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5599. iocbq->iocb.ulpContext);
  5600. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5601. command_type = OTHER_COMMAND;
  5602. break;
  5603. case CMD_XRI_ABORTED_CX:
  5604. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5605. /* words0-2 are all 0's no bde */
  5606. /* word3 and word4 are rsvrd */
  5607. wqe->words[3] = 0;
  5608. wqe->words[4] = 0;
  5609. /* word5 iocb=rsvd wge=did */
  5610. /* There is no remote port id in the IOCB? */
  5611. /* Let this fall through and fail */
  5612. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5613. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5614. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5615. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5616. default:
  5617. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5618. "2014 Invalid command 0x%x\n",
  5619. iocbq->iocb.ulpCommand);
  5620. return IOCB_ERROR;
  5621. break;
  5622. }
  5623. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5624. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5625. wqe->generic.abort_tag = abort_tag;
  5626. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5627. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5628. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5629. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5630. return 0;
  5631. }
  5632. /**
  5633. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5634. * @phba: Pointer to HBA context object.
  5635. * @ring_number: SLI ring number to issue iocb on.
  5636. * @piocb: Pointer to command iocb.
  5637. * @flag: Flag indicating if this command can be put into txq.
  5638. *
  5639. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5640. * an iocb command to an HBA with SLI-4 interface spec.
  5641. *
  5642. * This function is called with hbalock held. The function will return success
  5643. * after it successfully submit the iocb to firmware or after adding to the
  5644. * txq.
  5645. **/
  5646. static int
  5647. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5648. struct lpfc_iocbq *piocb, uint32_t flag)
  5649. {
  5650. struct lpfc_sglq *sglq;
  5651. union lpfc_wqe wqe;
  5652. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5653. if (piocb->sli4_xritag == NO_XRI) {
  5654. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5655. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5656. sglq = NULL;
  5657. else {
  5658. if (pring->txq_cnt) {
  5659. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5660. __lpfc_sli_ringtx_put(phba,
  5661. pring, piocb);
  5662. return IOCB_SUCCESS;
  5663. } else {
  5664. return IOCB_BUSY;
  5665. }
  5666. } else {
  5667. sglq = __lpfc_sli_get_sglq(phba);
  5668. if (!sglq) {
  5669. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5670. __lpfc_sli_ringtx_put(phba,
  5671. pring,
  5672. piocb);
  5673. return IOCB_SUCCESS;
  5674. } else
  5675. return IOCB_BUSY;
  5676. }
  5677. }
  5678. }
  5679. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5680. sglq = NULL; /* These IO's already have an XRI and
  5681. * a mapped sgl.
  5682. */
  5683. } else {
  5684. /* This is a continuation of a commandi,(CX) so this
  5685. * sglq is on the active list
  5686. */
  5687. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5688. if (!sglq)
  5689. return IOCB_ERROR;
  5690. }
  5691. if (sglq) {
  5692. piocb->sli4_xritag = sglq->sli4_xritag;
  5693. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  5694. return IOCB_ERROR;
  5695. }
  5696. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5697. return IOCB_ERROR;
  5698. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5699. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5700. /*
  5701. * For FCP command IOCB, get a new WQ index to distribute
  5702. * WQE across the WQsr. On the other hand, for abort IOCB,
  5703. * it carries the same WQ index to the original command
  5704. * IOCB.
  5705. */
  5706. if (piocb->iocb_flag & LPFC_IO_FCP)
  5707. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5708. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5709. &wqe))
  5710. return IOCB_ERROR;
  5711. } else {
  5712. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5713. return IOCB_ERROR;
  5714. }
  5715. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5716. return 0;
  5717. }
  5718. /**
  5719. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5720. *
  5721. * This routine wraps the actual lockless version for issusing IOCB function
  5722. * pointer from the lpfc_hba struct.
  5723. *
  5724. * Return codes:
  5725. * IOCB_ERROR - Error
  5726. * IOCB_SUCCESS - Success
  5727. * IOCB_BUSY - Busy
  5728. **/
  5729. int
  5730. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5731. struct lpfc_iocbq *piocb, uint32_t flag)
  5732. {
  5733. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5734. }
  5735. /**
  5736. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5737. * @phba: The hba struct for which this call is being executed.
  5738. * @dev_grp: The HBA PCI-Device group number.
  5739. *
  5740. * This routine sets up the SLI interface API function jump table in @phba
  5741. * struct.
  5742. * Returns: 0 - success, -ENODEV - failure.
  5743. **/
  5744. int
  5745. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5746. {
  5747. switch (dev_grp) {
  5748. case LPFC_PCI_DEV_LP:
  5749. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5750. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5751. break;
  5752. case LPFC_PCI_DEV_OC:
  5753. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5754. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5755. break;
  5756. default:
  5757. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5758. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5759. dev_grp);
  5760. return -ENODEV;
  5761. break;
  5762. }
  5763. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5764. return 0;
  5765. }
  5766. /**
  5767. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5768. * @phba: Pointer to HBA context object.
  5769. * @pring: Pointer to driver SLI ring object.
  5770. * @piocb: Pointer to command iocb.
  5771. * @flag: Flag indicating if this command can be put into txq.
  5772. *
  5773. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5774. * function. This function gets the hbalock and calls
  5775. * __lpfc_sli_issue_iocb function and will return the error returned
  5776. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5777. * functions which do not hold hbalock.
  5778. **/
  5779. int
  5780. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5781. struct lpfc_iocbq *piocb, uint32_t flag)
  5782. {
  5783. unsigned long iflags;
  5784. int rc;
  5785. spin_lock_irqsave(&phba->hbalock, iflags);
  5786. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5787. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5788. return rc;
  5789. }
  5790. /**
  5791. * lpfc_extra_ring_setup - Extra ring setup function
  5792. * @phba: Pointer to HBA context object.
  5793. *
  5794. * This function is called while driver attaches with the
  5795. * HBA to setup the extra ring. The extra ring is used
  5796. * only when driver needs to support target mode functionality
  5797. * or IP over FC functionalities.
  5798. *
  5799. * This function is called with no lock held.
  5800. **/
  5801. static int
  5802. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5803. {
  5804. struct lpfc_sli *psli;
  5805. struct lpfc_sli_ring *pring;
  5806. psli = &phba->sli;
  5807. /* Adjust cmd/rsp ring iocb entries more evenly */
  5808. /* Take some away from the FCP ring */
  5809. pring = &psli->ring[psli->fcp_ring];
  5810. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5811. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5812. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5813. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5814. /* and give them to the extra ring */
  5815. pring = &psli->ring[psli->extra_ring];
  5816. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5817. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5818. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5819. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5820. /* Setup default profile for this ring */
  5821. pring->iotag_max = 4096;
  5822. pring->num_mask = 1;
  5823. pring->prt[0].profile = 0; /* Mask 0 */
  5824. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5825. pring->prt[0].type = phba->cfg_multi_ring_type;
  5826. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5827. return 0;
  5828. }
  5829. /**
  5830. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5831. * @phba: Pointer to HBA context object.
  5832. * @pring: Pointer to driver SLI ring object.
  5833. * @iocbq: Pointer to iocb object.
  5834. *
  5835. * This function is called by the slow ring event handler
  5836. * function when there is an ASYNC event iocb in the ring.
  5837. * This function is called with no lock held.
  5838. * Currently this function handles only temperature related
  5839. * ASYNC events. The function decodes the temperature sensor
  5840. * event message and posts events for the management applications.
  5841. **/
  5842. static void
  5843. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5844. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5845. {
  5846. IOCB_t *icmd;
  5847. uint16_t evt_code;
  5848. uint16_t temp;
  5849. struct temp_event temp_event_data;
  5850. struct Scsi_Host *shost;
  5851. uint32_t *iocb_w;
  5852. icmd = &iocbq->iocb;
  5853. evt_code = icmd->un.asyncstat.evt_code;
  5854. temp = icmd->ulpContext;
  5855. if ((evt_code != ASYNC_TEMP_WARN) &&
  5856. (evt_code != ASYNC_TEMP_SAFE)) {
  5857. iocb_w = (uint32_t *) icmd;
  5858. lpfc_printf_log(phba,
  5859. KERN_ERR,
  5860. LOG_SLI,
  5861. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5862. " evt_code 0x%x\n"
  5863. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5864. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5865. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5866. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5867. pring->ringno,
  5868. icmd->un.asyncstat.evt_code,
  5869. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5870. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5871. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5872. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5873. return;
  5874. }
  5875. temp_event_data.data = (uint32_t)temp;
  5876. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5877. if (evt_code == ASYNC_TEMP_WARN) {
  5878. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5879. lpfc_printf_log(phba,
  5880. KERN_ERR,
  5881. LOG_TEMP,
  5882. "0347 Adapter is very hot, please take "
  5883. "corrective action. temperature : %d Celsius\n",
  5884. temp);
  5885. }
  5886. if (evt_code == ASYNC_TEMP_SAFE) {
  5887. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5888. lpfc_printf_log(phba,
  5889. KERN_ERR,
  5890. LOG_TEMP,
  5891. "0340 Adapter temperature is OK now. "
  5892. "temperature : %d Celsius\n",
  5893. temp);
  5894. }
  5895. /* Send temperature change event to applications */
  5896. shost = lpfc_shost_from_vport(phba->pport);
  5897. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5898. sizeof(temp_event_data), (char *) &temp_event_data,
  5899. LPFC_NL_VENDOR_ID);
  5900. }
  5901. /**
  5902. * lpfc_sli_setup - SLI ring setup function
  5903. * @phba: Pointer to HBA context object.
  5904. *
  5905. * lpfc_sli_setup sets up rings of the SLI interface with
  5906. * number of iocbs per ring and iotags. This function is
  5907. * called while driver attach to the HBA and before the
  5908. * interrupts are enabled. So there is no need for locking.
  5909. *
  5910. * This function always returns 0.
  5911. **/
  5912. int
  5913. lpfc_sli_setup(struct lpfc_hba *phba)
  5914. {
  5915. int i, totiocbsize = 0;
  5916. struct lpfc_sli *psli = &phba->sli;
  5917. struct lpfc_sli_ring *pring;
  5918. psli->num_rings = MAX_CONFIGURED_RINGS;
  5919. psli->sli_flag = 0;
  5920. psli->fcp_ring = LPFC_FCP_RING;
  5921. psli->next_ring = LPFC_FCP_NEXT_RING;
  5922. psli->extra_ring = LPFC_EXTRA_RING;
  5923. psli->iocbq_lookup = NULL;
  5924. psli->iocbq_lookup_len = 0;
  5925. psli->last_iotag = 0;
  5926. for (i = 0; i < psli->num_rings; i++) {
  5927. pring = &psli->ring[i];
  5928. switch (i) {
  5929. case LPFC_FCP_RING: /* ring 0 - FCP */
  5930. /* numCiocb and numRiocb are used in config_port */
  5931. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5932. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5933. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5934. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5935. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5936. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5937. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5938. SLI3_IOCB_CMD_SIZE :
  5939. SLI2_IOCB_CMD_SIZE;
  5940. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5941. SLI3_IOCB_RSP_SIZE :
  5942. SLI2_IOCB_RSP_SIZE;
  5943. pring->iotag_ctr = 0;
  5944. pring->iotag_max =
  5945. (phba->cfg_hba_queue_depth * 2);
  5946. pring->fast_iotag = pring->iotag_max;
  5947. pring->num_mask = 0;
  5948. break;
  5949. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5950. /* numCiocb and numRiocb are used in config_port */
  5951. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5952. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5953. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5954. SLI3_IOCB_CMD_SIZE :
  5955. SLI2_IOCB_CMD_SIZE;
  5956. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5957. SLI3_IOCB_RSP_SIZE :
  5958. SLI2_IOCB_RSP_SIZE;
  5959. pring->iotag_max = phba->cfg_hba_queue_depth;
  5960. pring->num_mask = 0;
  5961. break;
  5962. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5963. /* numCiocb and numRiocb are used in config_port */
  5964. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5965. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5966. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5967. SLI3_IOCB_CMD_SIZE :
  5968. SLI2_IOCB_CMD_SIZE;
  5969. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5970. SLI3_IOCB_RSP_SIZE :
  5971. SLI2_IOCB_RSP_SIZE;
  5972. pring->fast_iotag = 0;
  5973. pring->iotag_ctr = 0;
  5974. pring->iotag_max = 4096;
  5975. pring->lpfc_sli_rcv_async_status =
  5976. lpfc_sli_async_event_handler;
  5977. pring->num_mask = LPFC_MAX_RING_MASK;
  5978. pring->prt[0].profile = 0; /* Mask 0 */
  5979. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5980. pring->prt[0].type = FC_TYPE_ELS;
  5981. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5982. lpfc_els_unsol_event;
  5983. pring->prt[1].profile = 0; /* Mask 1 */
  5984. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5985. pring->prt[1].type = FC_TYPE_ELS;
  5986. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5987. lpfc_els_unsol_event;
  5988. pring->prt[2].profile = 0; /* Mask 2 */
  5989. /* NameServer Inquiry */
  5990. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5991. /* NameServer */
  5992. pring->prt[2].type = FC_TYPE_CT;
  5993. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5994. lpfc_ct_unsol_event;
  5995. pring->prt[3].profile = 0; /* Mask 3 */
  5996. /* NameServer response */
  5997. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5998. /* NameServer */
  5999. pring->prt[3].type = FC_TYPE_CT;
  6000. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6001. lpfc_ct_unsol_event;
  6002. /* abort unsolicited sequence */
  6003. pring->prt[4].profile = 0; /* Mask 4 */
  6004. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6005. pring->prt[4].type = FC_TYPE_BLS;
  6006. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6007. lpfc_sli4_ct_abort_unsol_event;
  6008. break;
  6009. }
  6010. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6011. (pring->numRiocb * pring->sizeRiocb);
  6012. }
  6013. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6014. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6015. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6016. "SLI2 SLIM Data: x%x x%lx\n",
  6017. phba->brd_no, totiocbsize,
  6018. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6019. }
  6020. if (phba->cfg_multi_ring_support == 2)
  6021. lpfc_extra_ring_setup(phba);
  6022. return 0;
  6023. }
  6024. /**
  6025. * lpfc_sli_queue_setup - Queue initialization function
  6026. * @phba: Pointer to HBA context object.
  6027. *
  6028. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6029. * ring. This function also initializes ring indices of each ring.
  6030. * This function is called during the initialization of the SLI
  6031. * interface of an HBA.
  6032. * This function is called with no lock held and always returns
  6033. * 1.
  6034. **/
  6035. int
  6036. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6037. {
  6038. struct lpfc_sli *psli;
  6039. struct lpfc_sli_ring *pring;
  6040. int i;
  6041. psli = &phba->sli;
  6042. spin_lock_irq(&phba->hbalock);
  6043. INIT_LIST_HEAD(&psli->mboxq);
  6044. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6045. /* Initialize list headers for txq and txcmplq as double linked lists */
  6046. for (i = 0; i < psli->num_rings; i++) {
  6047. pring = &psli->ring[i];
  6048. pring->ringno = i;
  6049. pring->next_cmdidx = 0;
  6050. pring->local_getidx = 0;
  6051. pring->cmdidx = 0;
  6052. INIT_LIST_HEAD(&pring->txq);
  6053. INIT_LIST_HEAD(&pring->txcmplq);
  6054. INIT_LIST_HEAD(&pring->iocb_continueq);
  6055. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6056. INIT_LIST_HEAD(&pring->postbufq);
  6057. }
  6058. spin_unlock_irq(&phba->hbalock);
  6059. return 1;
  6060. }
  6061. /**
  6062. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6063. * @phba: Pointer to HBA context object.
  6064. *
  6065. * This routine flushes the mailbox command subsystem. It will unconditionally
  6066. * flush all the mailbox commands in the three possible stages in the mailbox
  6067. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6068. * command; and completed mailbox command queue. It is caller's responsibility
  6069. * to make sure that the driver is in the proper state to flush the mailbox
  6070. * command sub-system. Namely, the posting of mailbox commands into the
  6071. * pending mailbox command queue from the various clients must be stopped;
  6072. * either the HBA is in a state that it will never works on the outstanding
  6073. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6074. * mailbox command has been completed.
  6075. **/
  6076. static void
  6077. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6078. {
  6079. LIST_HEAD(completions);
  6080. struct lpfc_sli *psli = &phba->sli;
  6081. LPFC_MBOXQ_t *pmb;
  6082. unsigned long iflag;
  6083. /* Flush all the mailbox commands in the mbox system */
  6084. spin_lock_irqsave(&phba->hbalock, iflag);
  6085. /* The pending mailbox command queue */
  6086. list_splice_init(&phba->sli.mboxq, &completions);
  6087. /* The outstanding active mailbox command */
  6088. if (psli->mbox_active) {
  6089. list_add_tail(&psli->mbox_active->list, &completions);
  6090. psli->mbox_active = NULL;
  6091. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6092. }
  6093. /* The completed mailbox command queue */
  6094. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6095. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6096. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6097. while (!list_empty(&completions)) {
  6098. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6099. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6100. if (pmb->mbox_cmpl)
  6101. pmb->mbox_cmpl(phba, pmb);
  6102. }
  6103. }
  6104. /**
  6105. * lpfc_sli_host_down - Vport cleanup function
  6106. * @vport: Pointer to virtual port object.
  6107. *
  6108. * lpfc_sli_host_down is called to clean up the resources
  6109. * associated with a vport before destroying virtual
  6110. * port data structures.
  6111. * This function does following operations:
  6112. * - Free discovery resources associated with this virtual
  6113. * port.
  6114. * - Free iocbs associated with this virtual port in
  6115. * the txq.
  6116. * - Send abort for all iocb commands associated with this
  6117. * vport in txcmplq.
  6118. *
  6119. * This function is called with no lock held and always returns 1.
  6120. **/
  6121. int
  6122. lpfc_sli_host_down(struct lpfc_vport *vport)
  6123. {
  6124. LIST_HEAD(completions);
  6125. struct lpfc_hba *phba = vport->phba;
  6126. struct lpfc_sli *psli = &phba->sli;
  6127. struct lpfc_sli_ring *pring;
  6128. struct lpfc_iocbq *iocb, *next_iocb;
  6129. int i;
  6130. unsigned long flags = 0;
  6131. uint16_t prev_pring_flag;
  6132. lpfc_cleanup_discovery_resources(vport);
  6133. spin_lock_irqsave(&phba->hbalock, flags);
  6134. for (i = 0; i < psli->num_rings; i++) {
  6135. pring = &psli->ring[i];
  6136. prev_pring_flag = pring->flag;
  6137. /* Only slow rings */
  6138. if (pring->ringno == LPFC_ELS_RING) {
  6139. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6140. /* Set the lpfc data pending flag */
  6141. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6142. }
  6143. /*
  6144. * Error everything on the txq since these iocbs have not been
  6145. * given to the FW yet.
  6146. */
  6147. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6148. if (iocb->vport != vport)
  6149. continue;
  6150. list_move_tail(&iocb->list, &completions);
  6151. pring->txq_cnt--;
  6152. }
  6153. /* Next issue ABTS for everything on the txcmplq */
  6154. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6155. list) {
  6156. if (iocb->vport != vport)
  6157. continue;
  6158. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6159. }
  6160. pring->flag = prev_pring_flag;
  6161. }
  6162. spin_unlock_irqrestore(&phba->hbalock, flags);
  6163. /* Cancel all the IOCBs from the completions list */
  6164. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6165. IOERR_SLI_DOWN);
  6166. return 1;
  6167. }
  6168. /**
  6169. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6170. * @phba: Pointer to HBA context object.
  6171. *
  6172. * This function cleans up all iocb, buffers, mailbox commands
  6173. * while shutting down the HBA. This function is called with no
  6174. * lock held and always returns 1.
  6175. * This function does the following to cleanup driver resources:
  6176. * - Free discovery resources for each virtual port
  6177. * - Cleanup any pending fabric iocbs
  6178. * - Iterate through the iocb txq and free each entry
  6179. * in the list.
  6180. * - Free up any buffer posted to the HBA
  6181. * - Free mailbox commands in the mailbox queue.
  6182. **/
  6183. int
  6184. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6185. {
  6186. LIST_HEAD(completions);
  6187. struct lpfc_sli *psli = &phba->sli;
  6188. struct lpfc_sli_ring *pring;
  6189. struct lpfc_dmabuf *buf_ptr;
  6190. unsigned long flags = 0;
  6191. int i;
  6192. /* Shutdown the mailbox command sub-system */
  6193. lpfc_sli_mbox_sys_shutdown(phba);
  6194. lpfc_hba_down_prep(phba);
  6195. lpfc_fabric_abort_hba(phba);
  6196. spin_lock_irqsave(&phba->hbalock, flags);
  6197. for (i = 0; i < psli->num_rings; i++) {
  6198. pring = &psli->ring[i];
  6199. /* Only slow rings */
  6200. if (pring->ringno == LPFC_ELS_RING) {
  6201. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6202. /* Set the lpfc data pending flag */
  6203. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6204. }
  6205. /*
  6206. * Error everything on the txq since these iocbs have not been
  6207. * given to the FW yet.
  6208. */
  6209. list_splice_init(&pring->txq, &completions);
  6210. pring->txq_cnt = 0;
  6211. }
  6212. spin_unlock_irqrestore(&phba->hbalock, flags);
  6213. /* Cancel all the IOCBs from the completions list */
  6214. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6215. IOERR_SLI_DOWN);
  6216. spin_lock_irqsave(&phba->hbalock, flags);
  6217. list_splice_init(&phba->elsbuf, &completions);
  6218. phba->elsbuf_cnt = 0;
  6219. phba->elsbuf_prev_cnt = 0;
  6220. spin_unlock_irqrestore(&phba->hbalock, flags);
  6221. while (!list_empty(&completions)) {
  6222. list_remove_head(&completions, buf_ptr,
  6223. struct lpfc_dmabuf, list);
  6224. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6225. kfree(buf_ptr);
  6226. }
  6227. /* Return any active mbox cmds */
  6228. del_timer_sync(&psli->mbox_tmo);
  6229. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6230. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6231. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6232. return 1;
  6233. }
  6234. /**
  6235. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6236. * @phba: Pointer to HBA context object.
  6237. *
  6238. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6239. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6240. * lock held and always returns 1.
  6241. *
  6242. * This function does the following to cleanup driver FCoE function resources:
  6243. * - Free discovery resources for each virtual port
  6244. * - Cleanup any pending fabric iocbs
  6245. * - Iterate through the iocb txq and free each entry in the list.
  6246. * - Free up any buffer posted to the HBA.
  6247. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6248. * - Free mailbox commands in the mailbox queue.
  6249. **/
  6250. int
  6251. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6252. {
  6253. /* Stop the SLI4 device port */
  6254. lpfc_stop_port(phba);
  6255. /* Tear down the queues in the HBA */
  6256. lpfc_sli4_queue_unset(phba);
  6257. /* unregister default FCFI from the HBA */
  6258. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6259. return 1;
  6260. }
  6261. /**
  6262. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6263. * @srcp: Source memory pointer.
  6264. * @destp: Destination memory pointer.
  6265. * @cnt: Number of words required to be copied.
  6266. *
  6267. * This function is used for copying data between driver memory
  6268. * and the SLI memory. This function also changes the endianness
  6269. * of each word if native endianness is different from SLI
  6270. * endianness. This function can be called with or without
  6271. * lock.
  6272. **/
  6273. void
  6274. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6275. {
  6276. uint32_t *src = srcp;
  6277. uint32_t *dest = destp;
  6278. uint32_t ldata;
  6279. int i;
  6280. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6281. ldata = *src;
  6282. ldata = le32_to_cpu(ldata);
  6283. *dest = ldata;
  6284. src++;
  6285. dest++;
  6286. }
  6287. }
  6288. /**
  6289. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6290. * @srcp: Source memory pointer.
  6291. * @destp: Destination memory pointer.
  6292. * @cnt: Number of words required to be copied.
  6293. *
  6294. * This function is used for copying data between a data structure
  6295. * with big endian representation to local endianness.
  6296. * This function can be called with or without lock.
  6297. **/
  6298. void
  6299. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6300. {
  6301. uint32_t *src = srcp;
  6302. uint32_t *dest = destp;
  6303. uint32_t ldata;
  6304. int i;
  6305. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6306. ldata = *src;
  6307. ldata = be32_to_cpu(ldata);
  6308. *dest = ldata;
  6309. src++;
  6310. dest++;
  6311. }
  6312. }
  6313. /**
  6314. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6315. * @phba: Pointer to HBA context object.
  6316. * @pring: Pointer to driver SLI ring object.
  6317. * @mp: Pointer to driver buffer object.
  6318. *
  6319. * This function is called with no lock held.
  6320. * It always return zero after adding the buffer to the postbufq
  6321. * buffer list.
  6322. **/
  6323. int
  6324. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6325. struct lpfc_dmabuf *mp)
  6326. {
  6327. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6328. later */
  6329. spin_lock_irq(&phba->hbalock);
  6330. list_add_tail(&mp->list, &pring->postbufq);
  6331. pring->postbufq_cnt++;
  6332. spin_unlock_irq(&phba->hbalock);
  6333. return 0;
  6334. }
  6335. /**
  6336. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6337. * @phba: Pointer to HBA context object.
  6338. *
  6339. * When HBQ is enabled, buffers are searched based on tags. This function
  6340. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6341. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6342. * does not conflict with tags of buffer posted for unsolicited events.
  6343. * The function returns the allocated tag. The function is called with
  6344. * no locks held.
  6345. **/
  6346. uint32_t
  6347. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6348. {
  6349. spin_lock_irq(&phba->hbalock);
  6350. phba->buffer_tag_count++;
  6351. /*
  6352. * Always set the QUE_BUFTAG_BIT to distiguish between
  6353. * a tag assigned by HBQ.
  6354. */
  6355. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6356. spin_unlock_irq(&phba->hbalock);
  6357. return phba->buffer_tag_count;
  6358. }
  6359. /**
  6360. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6361. * @phba: Pointer to HBA context object.
  6362. * @pring: Pointer to driver SLI ring object.
  6363. * @tag: Buffer tag.
  6364. *
  6365. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6366. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6367. * iocb is posted to the response ring with the tag of the buffer.
  6368. * This function searches the pring->postbufq list using the tag
  6369. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6370. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6371. * buffer is returned to the caller else NULL is returned.
  6372. * This function is called with no lock held.
  6373. **/
  6374. struct lpfc_dmabuf *
  6375. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6376. uint32_t tag)
  6377. {
  6378. struct lpfc_dmabuf *mp, *next_mp;
  6379. struct list_head *slp = &pring->postbufq;
  6380. /* Search postbufq, from the begining, looking for a match on tag */
  6381. spin_lock_irq(&phba->hbalock);
  6382. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6383. if (mp->buffer_tag == tag) {
  6384. list_del_init(&mp->list);
  6385. pring->postbufq_cnt--;
  6386. spin_unlock_irq(&phba->hbalock);
  6387. return mp;
  6388. }
  6389. }
  6390. spin_unlock_irq(&phba->hbalock);
  6391. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6392. "0402 Cannot find virtual addr for buffer tag on "
  6393. "ring %d Data x%lx x%p x%p x%x\n",
  6394. pring->ringno, (unsigned long) tag,
  6395. slp->next, slp->prev, pring->postbufq_cnt);
  6396. return NULL;
  6397. }
  6398. /**
  6399. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6400. * @phba: Pointer to HBA context object.
  6401. * @pring: Pointer to driver SLI ring object.
  6402. * @phys: DMA address of the buffer.
  6403. *
  6404. * This function searches the buffer list using the dma_address
  6405. * of unsolicited event to find the driver's lpfc_dmabuf object
  6406. * corresponding to the dma_address. The function returns the
  6407. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6408. * This function is called by the ct and els unsolicited event
  6409. * handlers to get the buffer associated with the unsolicited
  6410. * event.
  6411. *
  6412. * This function is called with no lock held.
  6413. **/
  6414. struct lpfc_dmabuf *
  6415. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6416. dma_addr_t phys)
  6417. {
  6418. struct lpfc_dmabuf *mp, *next_mp;
  6419. struct list_head *slp = &pring->postbufq;
  6420. /* Search postbufq, from the begining, looking for a match on phys */
  6421. spin_lock_irq(&phba->hbalock);
  6422. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6423. if (mp->phys == phys) {
  6424. list_del_init(&mp->list);
  6425. pring->postbufq_cnt--;
  6426. spin_unlock_irq(&phba->hbalock);
  6427. return mp;
  6428. }
  6429. }
  6430. spin_unlock_irq(&phba->hbalock);
  6431. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6432. "0410 Cannot find virtual addr for mapped buf on "
  6433. "ring %d Data x%llx x%p x%p x%x\n",
  6434. pring->ringno, (unsigned long long)phys,
  6435. slp->next, slp->prev, pring->postbufq_cnt);
  6436. return NULL;
  6437. }
  6438. /**
  6439. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6440. * @phba: Pointer to HBA context object.
  6441. * @cmdiocb: Pointer to driver command iocb object.
  6442. * @rspiocb: Pointer to driver response iocb object.
  6443. *
  6444. * This function is the completion handler for the abort iocbs for
  6445. * ELS commands. This function is called from the ELS ring event
  6446. * handler with no lock held. This function frees memory resources
  6447. * associated with the abort iocb.
  6448. **/
  6449. static void
  6450. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6451. struct lpfc_iocbq *rspiocb)
  6452. {
  6453. IOCB_t *irsp = &rspiocb->iocb;
  6454. uint16_t abort_iotag, abort_context;
  6455. struct lpfc_iocbq *abort_iocb;
  6456. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6457. abort_iocb = NULL;
  6458. if (irsp->ulpStatus) {
  6459. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6460. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6461. spin_lock_irq(&phba->hbalock);
  6462. if (phba->sli_rev < LPFC_SLI_REV4) {
  6463. if (abort_iotag != 0 &&
  6464. abort_iotag <= phba->sli.last_iotag)
  6465. abort_iocb =
  6466. phba->sli.iocbq_lookup[abort_iotag];
  6467. } else
  6468. /* For sli4 the abort_tag is the XRI,
  6469. * so the abort routine puts the iotag of the iocb
  6470. * being aborted in the context field of the abort
  6471. * IOCB.
  6472. */
  6473. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6474. /*
  6475. * If the iocb is not found in Firmware queue the iocb
  6476. * might have completed already. Do not free it again.
  6477. */
  6478. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6479. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6480. spin_unlock_irq(&phba->hbalock);
  6481. lpfc_sli_release_iocbq(phba, cmdiocb);
  6482. return;
  6483. }
  6484. /* For SLI4 the ulpContext field for abort IOCB
  6485. * holds the iotag of the IOCB being aborted so
  6486. * the local abort_context needs to be reset to
  6487. * match the aborted IOCBs ulpContext.
  6488. */
  6489. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6490. abort_context = abort_iocb->iocb.ulpContext;
  6491. }
  6492. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6493. "0327 Cannot abort els iocb %p "
  6494. "with tag %x context %x, abort status %x, "
  6495. "abort code %x\n",
  6496. abort_iocb, abort_iotag, abort_context,
  6497. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6498. /*
  6499. * make sure we have the right iocbq before taking it
  6500. * off the txcmplq and try to call completion routine.
  6501. */
  6502. if (!abort_iocb ||
  6503. abort_iocb->iocb.ulpContext != abort_context ||
  6504. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6505. spin_unlock_irq(&phba->hbalock);
  6506. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6507. /*
  6508. * leave the SLI4 aborted command on the txcmplq
  6509. * list and the command complete WCQE's XB bit
  6510. * will tell whether the SGL (XRI) can be released
  6511. * immediately or to the aborted SGL list for the
  6512. * following abort XRI from the HBA.
  6513. */
  6514. list_del_init(&abort_iocb->list);
  6515. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6516. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6517. pring->txcmplq_cnt--;
  6518. }
  6519. /* Firmware could still be in progress of DMAing
  6520. * payload, so don't free data buffer till after
  6521. * a hbeat.
  6522. */
  6523. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6524. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6525. spin_unlock_irq(&phba->hbalock);
  6526. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6527. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6528. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6529. } else
  6530. spin_unlock_irq(&phba->hbalock);
  6531. }
  6532. lpfc_sli_release_iocbq(phba, cmdiocb);
  6533. return;
  6534. }
  6535. /**
  6536. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6537. * @phba: Pointer to HBA context object.
  6538. * @cmdiocb: Pointer to driver command iocb object.
  6539. * @rspiocb: Pointer to driver response iocb object.
  6540. *
  6541. * The function is called from SLI ring event handler with no
  6542. * lock held. This function is the completion handler for ELS commands
  6543. * which are aborted. The function frees memory resources used for
  6544. * the aborted ELS commands.
  6545. **/
  6546. static void
  6547. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6548. struct lpfc_iocbq *rspiocb)
  6549. {
  6550. IOCB_t *irsp = &rspiocb->iocb;
  6551. /* ELS cmd tag <ulpIoTag> completes */
  6552. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6553. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6554. "x%x x%x x%x\n",
  6555. irsp->ulpIoTag, irsp->ulpStatus,
  6556. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6557. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6558. lpfc_ct_free_iocb(phba, cmdiocb);
  6559. else
  6560. lpfc_els_free_iocb(phba, cmdiocb);
  6561. return;
  6562. }
  6563. /**
  6564. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6565. * @phba: Pointer to HBA context object.
  6566. * @pring: Pointer to driver SLI ring object.
  6567. * @cmdiocb: Pointer to driver command iocb object.
  6568. *
  6569. * This function issues an abort iocb for the provided command
  6570. * iocb. This function is called with hbalock held.
  6571. * The function returns 0 when it fails due to memory allocation
  6572. * failure or when the command iocb is an abort request.
  6573. **/
  6574. int
  6575. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6576. struct lpfc_iocbq *cmdiocb)
  6577. {
  6578. struct lpfc_vport *vport = cmdiocb->vport;
  6579. struct lpfc_iocbq *abtsiocbp;
  6580. IOCB_t *icmd = NULL;
  6581. IOCB_t *iabt = NULL;
  6582. int retval = IOCB_ERROR;
  6583. /*
  6584. * There are certain command types we don't want to abort. And we
  6585. * don't want to abort commands that are already in the process of
  6586. * being aborted.
  6587. */
  6588. icmd = &cmdiocb->iocb;
  6589. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6590. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6591. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6592. return 0;
  6593. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6594. * callback so that nothing happens when it finishes.
  6595. */
  6596. if ((vport->load_flag & FC_UNLOADING) &&
  6597. (pring->ringno == LPFC_ELS_RING)) {
  6598. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6599. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6600. else
  6601. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6602. goto abort_iotag_exit;
  6603. }
  6604. /* issue ABTS for this IOCB based on iotag */
  6605. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6606. if (abtsiocbp == NULL)
  6607. return 0;
  6608. /* This signals the response to set the correct status
  6609. * before calling the completion handler
  6610. */
  6611. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6612. iabt = &abtsiocbp->iocb;
  6613. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6614. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6615. if (phba->sli_rev == LPFC_SLI_REV4) {
  6616. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6617. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6618. }
  6619. else
  6620. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6621. iabt->ulpLe = 1;
  6622. iabt->ulpClass = icmd->ulpClass;
  6623. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6624. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6625. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6626. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6627. if (phba->link_state >= LPFC_LINK_UP)
  6628. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6629. else
  6630. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6631. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6632. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6633. "0339 Abort xri x%x, original iotag x%x, "
  6634. "abort cmd iotag x%x\n",
  6635. iabt->un.acxri.abortIoTag,
  6636. iabt->un.acxri.abortContextTag,
  6637. abtsiocbp->iotag);
  6638. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6639. if (retval)
  6640. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6641. abort_iotag_exit:
  6642. /*
  6643. * Caller to this routine should check for IOCB_ERROR
  6644. * and handle it properly. This routine no longer removes
  6645. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6646. */
  6647. return retval;
  6648. }
  6649. /**
  6650. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6651. * @iocbq: Pointer to driver iocb object.
  6652. * @vport: Pointer to driver virtual port object.
  6653. * @tgt_id: SCSI ID of the target.
  6654. * @lun_id: LUN ID of the scsi device.
  6655. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6656. *
  6657. * This function acts as an iocb filter for functions which abort or count
  6658. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6659. * 0 if the filtering criteria is met for the given iocb and will return
  6660. * 1 if the filtering criteria is not met.
  6661. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6662. * given iocb is for the SCSI device specified by vport, tgt_id and
  6663. * lun_id parameter.
  6664. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6665. * given iocb is for the SCSI target specified by vport and tgt_id
  6666. * parameters.
  6667. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6668. * given iocb is for the SCSI host associated with the given vport.
  6669. * This function is called with no locks held.
  6670. **/
  6671. static int
  6672. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6673. uint16_t tgt_id, uint64_t lun_id,
  6674. lpfc_ctx_cmd ctx_cmd)
  6675. {
  6676. struct lpfc_scsi_buf *lpfc_cmd;
  6677. int rc = 1;
  6678. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6679. return rc;
  6680. if (iocbq->vport != vport)
  6681. return rc;
  6682. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6683. if (lpfc_cmd->pCmd == NULL)
  6684. return rc;
  6685. switch (ctx_cmd) {
  6686. case LPFC_CTX_LUN:
  6687. if ((lpfc_cmd->rdata->pnode) &&
  6688. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6689. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6690. rc = 0;
  6691. break;
  6692. case LPFC_CTX_TGT:
  6693. if ((lpfc_cmd->rdata->pnode) &&
  6694. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6695. rc = 0;
  6696. break;
  6697. case LPFC_CTX_HOST:
  6698. rc = 0;
  6699. break;
  6700. default:
  6701. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6702. __func__, ctx_cmd);
  6703. break;
  6704. }
  6705. return rc;
  6706. }
  6707. /**
  6708. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6709. * @vport: Pointer to virtual port.
  6710. * @tgt_id: SCSI ID of the target.
  6711. * @lun_id: LUN ID of the scsi device.
  6712. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6713. *
  6714. * This function returns number of FCP commands pending for the vport.
  6715. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6716. * commands pending on the vport associated with SCSI device specified
  6717. * by tgt_id and lun_id parameters.
  6718. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6719. * commands pending on the vport associated with SCSI target specified
  6720. * by tgt_id parameter.
  6721. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6722. * commands pending on the vport.
  6723. * This function returns the number of iocbs which satisfy the filter.
  6724. * This function is called without any lock held.
  6725. **/
  6726. int
  6727. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6728. lpfc_ctx_cmd ctx_cmd)
  6729. {
  6730. struct lpfc_hba *phba = vport->phba;
  6731. struct lpfc_iocbq *iocbq;
  6732. int sum, i;
  6733. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6734. iocbq = phba->sli.iocbq_lookup[i];
  6735. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6736. ctx_cmd) == 0)
  6737. sum++;
  6738. }
  6739. return sum;
  6740. }
  6741. /**
  6742. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6743. * @phba: Pointer to HBA context object
  6744. * @cmdiocb: Pointer to command iocb object.
  6745. * @rspiocb: Pointer to response iocb object.
  6746. *
  6747. * This function is called when an aborted FCP iocb completes. This
  6748. * function is called by the ring event handler with no lock held.
  6749. * This function frees the iocb.
  6750. **/
  6751. void
  6752. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6753. struct lpfc_iocbq *rspiocb)
  6754. {
  6755. lpfc_sli_release_iocbq(phba, cmdiocb);
  6756. return;
  6757. }
  6758. /**
  6759. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6760. * @vport: Pointer to virtual port.
  6761. * @pring: Pointer to driver SLI ring object.
  6762. * @tgt_id: SCSI ID of the target.
  6763. * @lun_id: LUN ID of the scsi device.
  6764. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6765. *
  6766. * This function sends an abort command for every SCSI command
  6767. * associated with the given virtual port pending on the ring
  6768. * filtered by lpfc_sli_validate_fcp_iocb function.
  6769. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6770. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6771. * parameters
  6772. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6773. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6774. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6775. * FCP iocbs associated with virtual port.
  6776. * This function returns number of iocbs it failed to abort.
  6777. * This function is called with no locks held.
  6778. **/
  6779. int
  6780. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6781. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6782. {
  6783. struct lpfc_hba *phba = vport->phba;
  6784. struct lpfc_iocbq *iocbq;
  6785. struct lpfc_iocbq *abtsiocb;
  6786. IOCB_t *cmd = NULL;
  6787. int errcnt = 0, ret_val = 0;
  6788. int i;
  6789. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6790. iocbq = phba->sli.iocbq_lookup[i];
  6791. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6792. abort_cmd) != 0)
  6793. continue;
  6794. /* issue ABTS for this IOCB based on iotag */
  6795. abtsiocb = lpfc_sli_get_iocbq(phba);
  6796. if (abtsiocb == NULL) {
  6797. errcnt++;
  6798. continue;
  6799. }
  6800. cmd = &iocbq->iocb;
  6801. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6802. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6803. if (phba->sli_rev == LPFC_SLI_REV4)
  6804. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6805. else
  6806. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6807. abtsiocb->iocb.ulpLe = 1;
  6808. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6809. abtsiocb->vport = phba->pport;
  6810. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6811. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6812. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6813. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6814. if (lpfc_is_link_up(phba))
  6815. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6816. else
  6817. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6818. /* Setup callback routine and issue the command. */
  6819. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6820. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6821. abtsiocb, 0);
  6822. if (ret_val == IOCB_ERROR) {
  6823. lpfc_sli_release_iocbq(phba, abtsiocb);
  6824. errcnt++;
  6825. continue;
  6826. }
  6827. }
  6828. return errcnt;
  6829. }
  6830. /**
  6831. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6832. * @phba: Pointer to HBA context object.
  6833. * @cmdiocbq: Pointer to command iocb.
  6834. * @rspiocbq: Pointer to response iocb.
  6835. *
  6836. * This function is the completion handler for iocbs issued using
  6837. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6838. * ring event handler function without any lock held. This function
  6839. * can be called from both worker thread context and interrupt
  6840. * context. This function also can be called from other thread which
  6841. * cleans up the SLI layer objects.
  6842. * This function copy the contents of the response iocb to the
  6843. * response iocb memory object provided by the caller of
  6844. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6845. * sleeps for the iocb completion.
  6846. **/
  6847. static void
  6848. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6849. struct lpfc_iocbq *cmdiocbq,
  6850. struct lpfc_iocbq *rspiocbq)
  6851. {
  6852. wait_queue_head_t *pdone_q;
  6853. unsigned long iflags;
  6854. struct lpfc_scsi_buf *lpfc_cmd;
  6855. spin_lock_irqsave(&phba->hbalock, iflags);
  6856. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6857. if (cmdiocbq->context2 && rspiocbq)
  6858. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6859. &rspiocbq->iocb, sizeof(IOCB_t));
  6860. /* Set the exchange busy flag for task management commands */
  6861. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6862. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6863. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6864. cur_iocbq);
  6865. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6866. }
  6867. pdone_q = cmdiocbq->context_un.wait_queue;
  6868. if (pdone_q)
  6869. wake_up(pdone_q);
  6870. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6871. return;
  6872. }
  6873. /**
  6874. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6875. * @phba: Pointer to HBA context object..
  6876. * @piocbq: Pointer to command iocb.
  6877. * @flag: Flag to test.
  6878. *
  6879. * This routine grabs the hbalock and then test the iocb_flag to
  6880. * see if the passed in flag is set.
  6881. * Returns:
  6882. * 1 if flag is set.
  6883. * 0 if flag is not set.
  6884. **/
  6885. static int
  6886. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6887. struct lpfc_iocbq *piocbq, uint32_t flag)
  6888. {
  6889. unsigned long iflags;
  6890. int ret;
  6891. spin_lock_irqsave(&phba->hbalock, iflags);
  6892. ret = piocbq->iocb_flag & flag;
  6893. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6894. return ret;
  6895. }
  6896. /**
  6897. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6898. * @phba: Pointer to HBA context object..
  6899. * @pring: Pointer to sli ring.
  6900. * @piocb: Pointer to command iocb.
  6901. * @prspiocbq: Pointer to response iocb.
  6902. * @timeout: Timeout in number of seconds.
  6903. *
  6904. * This function issues the iocb to firmware and waits for the
  6905. * iocb to complete. If the iocb command is not
  6906. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6907. * Caller should not free the iocb resources if this function
  6908. * returns IOCB_TIMEDOUT.
  6909. * The function waits for the iocb completion using an
  6910. * non-interruptible wait.
  6911. * This function will sleep while waiting for iocb completion.
  6912. * So, this function should not be called from any context which
  6913. * does not allow sleeping. Due to the same reason, this function
  6914. * cannot be called with interrupt disabled.
  6915. * This function assumes that the iocb completions occur while
  6916. * this function sleep. So, this function cannot be called from
  6917. * the thread which process iocb completion for this ring.
  6918. * This function clears the iocb_flag of the iocb object before
  6919. * issuing the iocb and the iocb completion handler sets this
  6920. * flag and wakes this thread when the iocb completes.
  6921. * The contents of the response iocb will be copied to prspiocbq
  6922. * by the completion handler when the command completes.
  6923. * This function returns IOCB_SUCCESS when success.
  6924. * This function is called with no lock held.
  6925. **/
  6926. int
  6927. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6928. uint32_t ring_number,
  6929. struct lpfc_iocbq *piocb,
  6930. struct lpfc_iocbq *prspiocbq,
  6931. uint32_t timeout)
  6932. {
  6933. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6934. long timeleft, timeout_req = 0;
  6935. int retval = IOCB_SUCCESS;
  6936. uint32_t creg_val;
  6937. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6938. /*
  6939. * If the caller has provided a response iocbq buffer, then context2
  6940. * is NULL or its an error.
  6941. */
  6942. if (prspiocbq) {
  6943. if (piocb->context2)
  6944. return IOCB_ERROR;
  6945. piocb->context2 = prspiocbq;
  6946. }
  6947. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6948. piocb->context_un.wait_queue = &done_q;
  6949. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6950. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6951. creg_val = readl(phba->HCregaddr);
  6952. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6953. writel(creg_val, phba->HCregaddr);
  6954. readl(phba->HCregaddr); /* flush */
  6955. }
  6956. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  6957. SLI_IOCB_RET_IOCB);
  6958. if (retval == IOCB_SUCCESS) {
  6959. timeout_req = timeout * HZ;
  6960. timeleft = wait_event_timeout(done_q,
  6961. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6962. timeout_req);
  6963. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6964. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6965. "0331 IOCB wake signaled\n");
  6966. } else if (timeleft == 0) {
  6967. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6968. "0338 IOCB wait timeout error - no "
  6969. "wake response Data x%x\n", timeout);
  6970. retval = IOCB_TIMEDOUT;
  6971. } else {
  6972. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6973. "0330 IOCB wake NOT set, "
  6974. "Data x%x x%lx\n",
  6975. timeout, (timeleft / jiffies));
  6976. retval = IOCB_TIMEDOUT;
  6977. }
  6978. } else if (retval == IOCB_BUSY) {
  6979. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6980. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  6981. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  6982. return retval;
  6983. } else {
  6984. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6985. "0332 IOCB wait issue failed, Data x%x\n",
  6986. retval);
  6987. retval = IOCB_ERROR;
  6988. }
  6989. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6990. creg_val = readl(phba->HCregaddr);
  6991. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6992. writel(creg_val, phba->HCregaddr);
  6993. readl(phba->HCregaddr); /* flush */
  6994. }
  6995. if (prspiocbq)
  6996. piocb->context2 = NULL;
  6997. piocb->context_un.wait_queue = NULL;
  6998. piocb->iocb_cmpl = NULL;
  6999. return retval;
  7000. }
  7001. /**
  7002. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7003. * @phba: Pointer to HBA context object.
  7004. * @pmboxq: Pointer to driver mailbox object.
  7005. * @timeout: Timeout in number of seconds.
  7006. *
  7007. * This function issues the mailbox to firmware and waits for the
  7008. * mailbox command to complete. If the mailbox command is not
  7009. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7010. * The function waits for the mailbox completion using an
  7011. * interruptible wait. If the thread is woken up due to a
  7012. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7013. * should not free the mailbox resources, if this function returns
  7014. * MBX_TIMEOUT.
  7015. * This function will sleep while waiting for mailbox completion.
  7016. * So, this function should not be called from any context which
  7017. * does not allow sleeping. Due to the same reason, this function
  7018. * cannot be called with interrupt disabled.
  7019. * This function assumes that the mailbox completion occurs while
  7020. * this function sleep. So, this function cannot be called from
  7021. * the worker thread which processes mailbox completion.
  7022. * This function is called in the context of HBA management
  7023. * applications.
  7024. * This function returns MBX_SUCCESS when successful.
  7025. * This function is called with no lock held.
  7026. **/
  7027. int
  7028. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7029. uint32_t timeout)
  7030. {
  7031. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7032. int retval;
  7033. unsigned long flag;
  7034. /* The caller must leave context1 empty. */
  7035. if (pmboxq->context1)
  7036. return MBX_NOT_FINISHED;
  7037. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7038. /* setup wake call as IOCB callback */
  7039. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7040. /* setup context field to pass wait_queue pointer to wake function */
  7041. pmboxq->context1 = &done_q;
  7042. /* now issue the command */
  7043. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7044. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7045. wait_event_interruptible_timeout(done_q,
  7046. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7047. timeout * HZ);
  7048. spin_lock_irqsave(&phba->hbalock, flag);
  7049. pmboxq->context1 = NULL;
  7050. /*
  7051. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7052. * else do not free the resources.
  7053. */
  7054. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7055. retval = MBX_SUCCESS;
  7056. lpfc_sli4_swap_str(phba, pmboxq);
  7057. } else {
  7058. retval = MBX_TIMEOUT;
  7059. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7060. }
  7061. spin_unlock_irqrestore(&phba->hbalock, flag);
  7062. }
  7063. return retval;
  7064. }
  7065. /**
  7066. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7067. * @phba: Pointer to HBA context.
  7068. *
  7069. * This function is called to shutdown the driver's mailbox sub-system.
  7070. * It first marks the mailbox sub-system is in a block state to prevent
  7071. * the asynchronous mailbox command from issued off the pending mailbox
  7072. * command queue. If the mailbox command sub-system shutdown is due to
  7073. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7074. * the mailbox sub-system flush routine to forcefully bring down the
  7075. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7076. * as with offline or HBA function reset), this routine will wait for the
  7077. * outstanding mailbox command to complete before invoking the mailbox
  7078. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7079. **/
  7080. void
  7081. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7082. {
  7083. struct lpfc_sli *psli = &phba->sli;
  7084. uint8_t actcmd = MBX_HEARTBEAT;
  7085. unsigned long timeout;
  7086. spin_lock_irq(&phba->hbalock);
  7087. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7088. spin_unlock_irq(&phba->hbalock);
  7089. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7090. spin_lock_irq(&phba->hbalock);
  7091. if (phba->sli.mbox_active)
  7092. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7093. spin_unlock_irq(&phba->hbalock);
  7094. /* Determine how long we might wait for the active mailbox
  7095. * command to be gracefully completed by firmware.
  7096. */
  7097. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7098. 1000) + jiffies;
  7099. while (phba->sli.mbox_active) {
  7100. /* Check active mailbox complete status every 2ms */
  7101. msleep(2);
  7102. if (time_after(jiffies, timeout))
  7103. /* Timeout, let the mailbox flush routine to
  7104. * forcefully release active mailbox command
  7105. */
  7106. break;
  7107. }
  7108. }
  7109. lpfc_sli_mbox_sys_flush(phba);
  7110. }
  7111. /**
  7112. * lpfc_sli_eratt_read - read sli-3 error attention events
  7113. * @phba: Pointer to HBA context.
  7114. *
  7115. * This function is called to read the SLI3 device error attention registers
  7116. * for possible error attention events. The caller must hold the hostlock
  7117. * with spin_lock_irq().
  7118. *
  7119. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7120. * Register and returns 0 otherwise.
  7121. **/
  7122. static int
  7123. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7124. {
  7125. uint32_t ha_copy;
  7126. /* Read chip Host Attention (HA) register */
  7127. ha_copy = readl(phba->HAregaddr);
  7128. if (ha_copy & HA_ERATT) {
  7129. /* Read host status register to retrieve error event */
  7130. lpfc_sli_read_hs(phba);
  7131. /* Check if there is a deferred error condition is active */
  7132. if ((HS_FFER1 & phba->work_hs) &&
  7133. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7134. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7135. phba->hba_flag |= DEFER_ERATT;
  7136. /* Clear all interrupt enable conditions */
  7137. writel(0, phba->HCregaddr);
  7138. readl(phba->HCregaddr);
  7139. }
  7140. /* Set the driver HA work bitmap */
  7141. phba->work_ha |= HA_ERATT;
  7142. /* Indicate polling handles this ERATT */
  7143. phba->hba_flag |= HBA_ERATT_HANDLED;
  7144. return 1;
  7145. }
  7146. return 0;
  7147. }
  7148. /**
  7149. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7150. * @phba: Pointer to HBA context.
  7151. *
  7152. * This function is called to read the SLI4 device error attention registers
  7153. * for possible error attention events. The caller must hold the hostlock
  7154. * with spin_lock_irq().
  7155. *
  7156. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7157. * Register and returns 0 otherwise.
  7158. **/
  7159. static int
  7160. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7161. {
  7162. uint32_t uerr_sta_hi, uerr_sta_lo;
  7163. /* For now, use the SLI4 device internal unrecoverable error
  7164. * registers for error attention. This can be changed later.
  7165. */
  7166. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7167. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7168. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7169. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7170. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7171. "1423 HBA Unrecoverable error: "
  7172. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7173. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7174. uerr_sta_lo, uerr_sta_hi,
  7175. phba->sli4_hba.ue_mask_lo,
  7176. phba->sli4_hba.ue_mask_hi);
  7177. phba->work_status[0] = uerr_sta_lo;
  7178. phba->work_status[1] = uerr_sta_hi;
  7179. /* Set the driver HA work bitmap */
  7180. phba->work_ha |= HA_ERATT;
  7181. /* Indicate polling handles this ERATT */
  7182. phba->hba_flag |= HBA_ERATT_HANDLED;
  7183. return 1;
  7184. }
  7185. return 0;
  7186. }
  7187. /**
  7188. * lpfc_sli_check_eratt - check error attention events
  7189. * @phba: Pointer to HBA context.
  7190. *
  7191. * This function is called from timer soft interrupt context to check HBA's
  7192. * error attention register bit for error attention events.
  7193. *
  7194. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7195. * Register and returns 0 otherwise.
  7196. **/
  7197. int
  7198. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7199. {
  7200. uint32_t ha_copy;
  7201. /* If somebody is waiting to handle an eratt, don't process it
  7202. * here. The brdkill function will do this.
  7203. */
  7204. if (phba->link_flag & LS_IGNORE_ERATT)
  7205. return 0;
  7206. /* Check if interrupt handler handles this ERATT */
  7207. spin_lock_irq(&phba->hbalock);
  7208. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7209. /* Interrupt handler has handled ERATT */
  7210. spin_unlock_irq(&phba->hbalock);
  7211. return 0;
  7212. }
  7213. /*
  7214. * If there is deferred error attention, do not check for error
  7215. * attention
  7216. */
  7217. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7218. spin_unlock_irq(&phba->hbalock);
  7219. return 0;
  7220. }
  7221. /* If PCI channel is offline, don't process it */
  7222. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7223. spin_unlock_irq(&phba->hbalock);
  7224. return 0;
  7225. }
  7226. switch (phba->sli_rev) {
  7227. case LPFC_SLI_REV2:
  7228. case LPFC_SLI_REV3:
  7229. /* Read chip Host Attention (HA) register */
  7230. ha_copy = lpfc_sli_eratt_read(phba);
  7231. break;
  7232. case LPFC_SLI_REV4:
  7233. /* Read devcie Uncoverable Error (UERR) registers */
  7234. ha_copy = lpfc_sli4_eratt_read(phba);
  7235. break;
  7236. default:
  7237. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7238. "0299 Invalid SLI revision (%d)\n",
  7239. phba->sli_rev);
  7240. ha_copy = 0;
  7241. break;
  7242. }
  7243. spin_unlock_irq(&phba->hbalock);
  7244. return ha_copy;
  7245. }
  7246. /**
  7247. * lpfc_intr_state_check - Check device state for interrupt handling
  7248. * @phba: Pointer to HBA context.
  7249. *
  7250. * This inline routine checks whether a device or its PCI slot is in a state
  7251. * that the interrupt should be handled.
  7252. *
  7253. * This function returns 0 if the device or the PCI slot is in a state that
  7254. * interrupt should be handled, otherwise -EIO.
  7255. */
  7256. static inline int
  7257. lpfc_intr_state_check(struct lpfc_hba *phba)
  7258. {
  7259. /* If the pci channel is offline, ignore all the interrupts */
  7260. if (unlikely(pci_channel_offline(phba->pcidev)))
  7261. return -EIO;
  7262. /* Update device level interrupt statistics */
  7263. phba->sli.slistat.sli_intr++;
  7264. /* Ignore all interrupts during initialization. */
  7265. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7266. return -EIO;
  7267. return 0;
  7268. }
  7269. /**
  7270. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7271. * @irq: Interrupt number.
  7272. * @dev_id: The device context pointer.
  7273. *
  7274. * This function is directly called from the PCI layer as an interrupt
  7275. * service routine when device with SLI-3 interface spec is enabled with
  7276. * MSI-X multi-message interrupt mode and there are slow-path events in
  7277. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7278. * interrupt mode, this function is called as part of the device-level
  7279. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7280. * is undergoing initialization, the interrupt handler will not process
  7281. * the interrupt. The link attention and ELS ring attention events are
  7282. * handled by the worker thread. The interrupt handler signals the worker
  7283. * thread and returns for these events. This function is called without
  7284. * any lock held. It gets the hbalock to access and update SLI data
  7285. * structures.
  7286. *
  7287. * This function returns IRQ_HANDLED when interrupt is handled else it
  7288. * returns IRQ_NONE.
  7289. **/
  7290. irqreturn_t
  7291. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7292. {
  7293. struct lpfc_hba *phba;
  7294. uint32_t ha_copy, hc_copy;
  7295. uint32_t work_ha_copy;
  7296. unsigned long status;
  7297. unsigned long iflag;
  7298. uint32_t control;
  7299. MAILBOX_t *mbox, *pmbox;
  7300. struct lpfc_vport *vport;
  7301. struct lpfc_nodelist *ndlp;
  7302. struct lpfc_dmabuf *mp;
  7303. LPFC_MBOXQ_t *pmb;
  7304. int rc;
  7305. /*
  7306. * Get the driver's phba structure from the dev_id and
  7307. * assume the HBA is not interrupting.
  7308. */
  7309. phba = (struct lpfc_hba *)dev_id;
  7310. if (unlikely(!phba))
  7311. return IRQ_NONE;
  7312. /*
  7313. * Stuff needs to be attented to when this function is invoked as an
  7314. * individual interrupt handler in MSI-X multi-message interrupt mode
  7315. */
  7316. if (phba->intr_type == MSIX) {
  7317. /* Check device state for handling interrupt */
  7318. if (lpfc_intr_state_check(phba))
  7319. return IRQ_NONE;
  7320. /* Need to read HA REG for slow-path events */
  7321. spin_lock_irqsave(&phba->hbalock, iflag);
  7322. ha_copy = readl(phba->HAregaddr);
  7323. /* If somebody is waiting to handle an eratt don't process it
  7324. * here. The brdkill function will do this.
  7325. */
  7326. if (phba->link_flag & LS_IGNORE_ERATT)
  7327. ha_copy &= ~HA_ERATT;
  7328. /* Check the need for handling ERATT in interrupt handler */
  7329. if (ha_copy & HA_ERATT) {
  7330. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7331. /* ERATT polling has handled ERATT */
  7332. ha_copy &= ~HA_ERATT;
  7333. else
  7334. /* Indicate interrupt handler handles ERATT */
  7335. phba->hba_flag |= HBA_ERATT_HANDLED;
  7336. }
  7337. /*
  7338. * If there is deferred error attention, do not check for any
  7339. * interrupt.
  7340. */
  7341. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7342. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7343. return IRQ_NONE;
  7344. }
  7345. /* Clear up only attention source related to slow-path */
  7346. hc_copy = readl(phba->HCregaddr);
  7347. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7348. HC_LAINT_ENA | HC_ERINT_ENA),
  7349. phba->HCregaddr);
  7350. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7351. phba->HAregaddr);
  7352. writel(hc_copy, phba->HCregaddr);
  7353. readl(phba->HAregaddr); /* flush */
  7354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7355. } else
  7356. ha_copy = phba->ha_copy;
  7357. work_ha_copy = ha_copy & phba->work_ha_mask;
  7358. if (work_ha_copy) {
  7359. if (work_ha_copy & HA_LATT) {
  7360. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7361. /*
  7362. * Turn off Link Attention interrupts
  7363. * until CLEAR_LA done
  7364. */
  7365. spin_lock_irqsave(&phba->hbalock, iflag);
  7366. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7367. control = readl(phba->HCregaddr);
  7368. control &= ~HC_LAINT_ENA;
  7369. writel(control, phba->HCregaddr);
  7370. readl(phba->HCregaddr); /* flush */
  7371. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7372. }
  7373. else
  7374. work_ha_copy &= ~HA_LATT;
  7375. }
  7376. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7377. /*
  7378. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7379. * the only slow ring.
  7380. */
  7381. status = (work_ha_copy &
  7382. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7383. status >>= (4*LPFC_ELS_RING);
  7384. if (status & HA_RXMASK) {
  7385. spin_lock_irqsave(&phba->hbalock, iflag);
  7386. control = readl(phba->HCregaddr);
  7387. lpfc_debugfs_slow_ring_trc(phba,
  7388. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7389. control, status,
  7390. (uint32_t)phba->sli.slistat.sli_intr);
  7391. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7392. lpfc_debugfs_slow_ring_trc(phba,
  7393. "ISR Disable ring:"
  7394. "pwork:x%x hawork:x%x wait:x%x",
  7395. phba->work_ha, work_ha_copy,
  7396. (uint32_t)((unsigned long)
  7397. &phba->work_waitq));
  7398. control &=
  7399. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7400. writel(control, phba->HCregaddr);
  7401. readl(phba->HCregaddr); /* flush */
  7402. }
  7403. else {
  7404. lpfc_debugfs_slow_ring_trc(phba,
  7405. "ISR slow ring: pwork:"
  7406. "x%x hawork:x%x wait:x%x",
  7407. phba->work_ha, work_ha_copy,
  7408. (uint32_t)((unsigned long)
  7409. &phba->work_waitq));
  7410. }
  7411. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7412. }
  7413. }
  7414. spin_lock_irqsave(&phba->hbalock, iflag);
  7415. if (work_ha_copy & HA_ERATT) {
  7416. lpfc_sli_read_hs(phba);
  7417. /*
  7418. * Check if there is a deferred error condition
  7419. * is active
  7420. */
  7421. if ((HS_FFER1 & phba->work_hs) &&
  7422. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7423. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7424. phba->hba_flag |= DEFER_ERATT;
  7425. /* Clear all interrupt enable conditions */
  7426. writel(0, phba->HCregaddr);
  7427. readl(phba->HCregaddr);
  7428. }
  7429. }
  7430. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7431. pmb = phba->sli.mbox_active;
  7432. pmbox = &pmb->u.mb;
  7433. mbox = phba->mbox;
  7434. vport = pmb->vport;
  7435. /* First check out the status word */
  7436. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7437. if (pmbox->mbxOwner != OWN_HOST) {
  7438. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7439. /*
  7440. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7441. * mbxStatus <status>
  7442. */
  7443. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7444. LOG_SLI,
  7445. "(%d):0304 Stray Mailbox "
  7446. "Interrupt mbxCommand x%x "
  7447. "mbxStatus x%x\n",
  7448. (vport ? vport->vpi : 0),
  7449. pmbox->mbxCommand,
  7450. pmbox->mbxStatus);
  7451. /* clear mailbox attention bit */
  7452. work_ha_copy &= ~HA_MBATT;
  7453. } else {
  7454. phba->sli.mbox_active = NULL;
  7455. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7456. phba->last_completion_time = jiffies;
  7457. del_timer(&phba->sli.mbox_tmo);
  7458. if (pmb->mbox_cmpl) {
  7459. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7460. MAILBOX_CMD_SIZE);
  7461. if (pmb->out_ext_byte_len &&
  7462. pmb->context2)
  7463. lpfc_sli_pcimem_bcopy(
  7464. phba->mbox_ext,
  7465. pmb->context2,
  7466. pmb->out_ext_byte_len);
  7467. }
  7468. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7469. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7470. lpfc_debugfs_disc_trc(vport,
  7471. LPFC_DISC_TRC_MBOX_VPORT,
  7472. "MBOX dflt rpi: : "
  7473. "status:x%x rpi:x%x",
  7474. (uint32_t)pmbox->mbxStatus,
  7475. pmbox->un.varWords[0], 0);
  7476. if (!pmbox->mbxStatus) {
  7477. mp = (struct lpfc_dmabuf *)
  7478. (pmb->context1);
  7479. ndlp = (struct lpfc_nodelist *)
  7480. pmb->context2;
  7481. /* Reg_LOGIN of dflt RPI was
  7482. * successful. new lets get
  7483. * rid of the RPI using the
  7484. * same mbox buffer.
  7485. */
  7486. lpfc_unreg_login(phba,
  7487. vport->vpi,
  7488. pmbox->un.varWords[0],
  7489. pmb);
  7490. pmb->mbox_cmpl =
  7491. lpfc_mbx_cmpl_dflt_rpi;
  7492. pmb->context1 = mp;
  7493. pmb->context2 = ndlp;
  7494. pmb->vport = vport;
  7495. rc = lpfc_sli_issue_mbox(phba,
  7496. pmb,
  7497. MBX_NOWAIT);
  7498. if (rc != MBX_BUSY)
  7499. lpfc_printf_log(phba,
  7500. KERN_ERR,
  7501. LOG_MBOX | LOG_SLI,
  7502. "0350 rc should have"
  7503. "been MBX_BUSY\n");
  7504. if (rc != MBX_NOT_FINISHED)
  7505. goto send_current_mbox;
  7506. }
  7507. }
  7508. spin_lock_irqsave(
  7509. &phba->pport->work_port_lock,
  7510. iflag);
  7511. phba->pport->work_port_events &=
  7512. ~WORKER_MBOX_TMO;
  7513. spin_unlock_irqrestore(
  7514. &phba->pport->work_port_lock,
  7515. iflag);
  7516. lpfc_mbox_cmpl_put(phba, pmb);
  7517. }
  7518. } else
  7519. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7520. if ((work_ha_copy & HA_MBATT) &&
  7521. (phba->sli.mbox_active == NULL)) {
  7522. send_current_mbox:
  7523. /* Process next mailbox command if there is one */
  7524. do {
  7525. rc = lpfc_sli_issue_mbox(phba, NULL,
  7526. MBX_NOWAIT);
  7527. } while (rc == MBX_NOT_FINISHED);
  7528. if (rc != MBX_SUCCESS)
  7529. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7530. LOG_SLI, "0349 rc should be "
  7531. "MBX_SUCCESS\n");
  7532. }
  7533. spin_lock_irqsave(&phba->hbalock, iflag);
  7534. phba->work_ha |= work_ha_copy;
  7535. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7536. lpfc_worker_wake_up(phba);
  7537. }
  7538. return IRQ_HANDLED;
  7539. } /* lpfc_sli_sp_intr_handler */
  7540. /**
  7541. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7542. * @irq: Interrupt number.
  7543. * @dev_id: The device context pointer.
  7544. *
  7545. * This function is directly called from the PCI layer as an interrupt
  7546. * service routine when device with SLI-3 interface spec is enabled with
  7547. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7548. * ring event in the HBA. However, when the device is enabled with either
  7549. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7550. * device-level interrupt handler. When the PCI slot is in error recovery
  7551. * or the HBA is undergoing initialization, the interrupt handler will not
  7552. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7553. * the intrrupt context. This function is called without any lock held.
  7554. * It gets the hbalock to access and update SLI data structures.
  7555. *
  7556. * This function returns IRQ_HANDLED when interrupt is handled else it
  7557. * returns IRQ_NONE.
  7558. **/
  7559. irqreturn_t
  7560. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7561. {
  7562. struct lpfc_hba *phba;
  7563. uint32_t ha_copy;
  7564. unsigned long status;
  7565. unsigned long iflag;
  7566. /* Get the driver's phba structure from the dev_id and
  7567. * assume the HBA is not interrupting.
  7568. */
  7569. phba = (struct lpfc_hba *) dev_id;
  7570. if (unlikely(!phba))
  7571. return IRQ_NONE;
  7572. /*
  7573. * Stuff needs to be attented to when this function is invoked as an
  7574. * individual interrupt handler in MSI-X multi-message interrupt mode
  7575. */
  7576. if (phba->intr_type == MSIX) {
  7577. /* Check device state for handling interrupt */
  7578. if (lpfc_intr_state_check(phba))
  7579. return IRQ_NONE;
  7580. /* Need to read HA REG for FCP ring and other ring events */
  7581. ha_copy = readl(phba->HAregaddr);
  7582. /* Clear up only attention source related to fast-path */
  7583. spin_lock_irqsave(&phba->hbalock, iflag);
  7584. /*
  7585. * If there is deferred error attention, do not check for
  7586. * any interrupt.
  7587. */
  7588. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7589. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7590. return IRQ_NONE;
  7591. }
  7592. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7593. phba->HAregaddr);
  7594. readl(phba->HAregaddr); /* flush */
  7595. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7596. } else
  7597. ha_copy = phba->ha_copy;
  7598. /*
  7599. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7600. */
  7601. ha_copy &= ~(phba->work_ha_mask);
  7602. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7603. status >>= (4*LPFC_FCP_RING);
  7604. if (status & HA_RXMASK)
  7605. lpfc_sli_handle_fast_ring_event(phba,
  7606. &phba->sli.ring[LPFC_FCP_RING],
  7607. status);
  7608. if (phba->cfg_multi_ring_support == 2) {
  7609. /*
  7610. * Process all events on extra ring. Take the optimized path
  7611. * for extra ring IO.
  7612. */
  7613. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7614. status >>= (4*LPFC_EXTRA_RING);
  7615. if (status & HA_RXMASK) {
  7616. lpfc_sli_handle_fast_ring_event(phba,
  7617. &phba->sli.ring[LPFC_EXTRA_RING],
  7618. status);
  7619. }
  7620. }
  7621. return IRQ_HANDLED;
  7622. } /* lpfc_sli_fp_intr_handler */
  7623. /**
  7624. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7625. * @irq: Interrupt number.
  7626. * @dev_id: The device context pointer.
  7627. *
  7628. * This function is the HBA device-level interrupt handler to device with
  7629. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7630. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7631. * requires driver attention. This function invokes the slow-path interrupt
  7632. * attention handling function and fast-path interrupt attention handling
  7633. * function in turn to process the relevant HBA attention events. This
  7634. * function is called without any lock held. It gets the hbalock to access
  7635. * and update SLI data structures.
  7636. *
  7637. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7638. * returns IRQ_NONE.
  7639. **/
  7640. irqreturn_t
  7641. lpfc_sli_intr_handler(int irq, void *dev_id)
  7642. {
  7643. struct lpfc_hba *phba;
  7644. irqreturn_t sp_irq_rc, fp_irq_rc;
  7645. unsigned long status1, status2;
  7646. uint32_t hc_copy;
  7647. /*
  7648. * Get the driver's phba structure from the dev_id and
  7649. * assume the HBA is not interrupting.
  7650. */
  7651. phba = (struct lpfc_hba *) dev_id;
  7652. if (unlikely(!phba))
  7653. return IRQ_NONE;
  7654. /* Check device state for handling interrupt */
  7655. if (lpfc_intr_state_check(phba))
  7656. return IRQ_NONE;
  7657. spin_lock(&phba->hbalock);
  7658. phba->ha_copy = readl(phba->HAregaddr);
  7659. if (unlikely(!phba->ha_copy)) {
  7660. spin_unlock(&phba->hbalock);
  7661. return IRQ_NONE;
  7662. } else if (phba->ha_copy & HA_ERATT) {
  7663. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7664. /* ERATT polling has handled ERATT */
  7665. phba->ha_copy &= ~HA_ERATT;
  7666. else
  7667. /* Indicate interrupt handler handles ERATT */
  7668. phba->hba_flag |= HBA_ERATT_HANDLED;
  7669. }
  7670. /*
  7671. * If there is deferred error attention, do not check for any interrupt.
  7672. */
  7673. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7674. spin_unlock_irq(&phba->hbalock);
  7675. return IRQ_NONE;
  7676. }
  7677. /* Clear attention sources except link and error attentions */
  7678. hc_copy = readl(phba->HCregaddr);
  7679. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7680. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7681. phba->HCregaddr);
  7682. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7683. writel(hc_copy, phba->HCregaddr);
  7684. readl(phba->HAregaddr); /* flush */
  7685. spin_unlock(&phba->hbalock);
  7686. /*
  7687. * Invokes slow-path host attention interrupt handling as appropriate.
  7688. */
  7689. /* status of events with mailbox and link attention */
  7690. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7691. /* status of events with ELS ring */
  7692. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7693. status2 >>= (4*LPFC_ELS_RING);
  7694. if (status1 || (status2 & HA_RXMASK))
  7695. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7696. else
  7697. sp_irq_rc = IRQ_NONE;
  7698. /*
  7699. * Invoke fast-path host attention interrupt handling as appropriate.
  7700. */
  7701. /* status of events with FCP ring */
  7702. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7703. status1 >>= (4*LPFC_FCP_RING);
  7704. /* status of events with extra ring */
  7705. if (phba->cfg_multi_ring_support == 2) {
  7706. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7707. status2 >>= (4*LPFC_EXTRA_RING);
  7708. } else
  7709. status2 = 0;
  7710. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7711. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7712. else
  7713. fp_irq_rc = IRQ_NONE;
  7714. /* Return device-level interrupt handling status */
  7715. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7716. } /* lpfc_sli_intr_handler */
  7717. /**
  7718. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7719. * @phba: pointer to lpfc hba data structure.
  7720. *
  7721. * This routine is invoked by the worker thread to process all the pending
  7722. * SLI4 FCP abort XRI events.
  7723. **/
  7724. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7725. {
  7726. struct lpfc_cq_event *cq_event;
  7727. /* First, declare the fcp xri abort event has been handled */
  7728. spin_lock_irq(&phba->hbalock);
  7729. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7730. spin_unlock_irq(&phba->hbalock);
  7731. /* Now, handle all the fcp xri abort events */
  7732. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7733. /* Get the first event from the head of the event queue */
  7734. spin_lock_irq(&phba->hbalock);
  7735. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7736. cq_event, struct lpfc_cq_event, list);
  7737. spin_unlock_irq(&phba->hbalock);
  7738. /* Notify aborted XRI for FCP work queue */
  7739. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7740. /* Free the event processed back to the free pool */
  7741. lpfc_sli4_cq_event_release(phba, cq_event);
  7742. }
  7743. }
  7744. /**
  7745. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7746. * @phba: pointer to lpfc hba data structure.
  7747. *
  7748. * This routine is invoked by the worker thread to process all the pending
  7749. * SLI4 els abort xri events.
  7750. **/
  7751. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7752. {
  7753. struct lpfc_cq_event *cq_event;
  7754. /* First, declare the els xri abort event has been handled */
  7755. spin_lock_irq(&phba->hbalock);
  7756. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7757. spin_unlock_irq(&phba->hbalock);
  7758. /* Now, handle all the els xri abort events */
  7759. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7760. /* Get the first event from the head of the event queue */
  7761. spin_lock_irq(&phba->hbalock);
  7762. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7763. cq_event, struct lpfc_cq_event, list);
  7764. spin_unlock_irq(&phba->hbalock);
  7765. /* Notify aborted XRI for ELS work queue */
  7766. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7767. /* Free the event processed back to the free pool */
  7768. lpfc_sli4_cq_event_release(phba, cq_event);
  7769. }
  7770. }
  7771. /**
  7772. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7773. * @phba: pointer to lpfc hba data structure
  7774. * @pIocbIn: pointer to the rspiocbq
  7775. * @pIocbOut: pointer to the cmdiocbq
  7776. * @wcqe: pointer to the complete wcqe
  7777. *
  7778. * This routine transfers the fields of a command iocbq to a response iocbq
  7779. * by copying all the IOCB fields from command iocbq and transferring the
  7780. * completion status information from the complete wcqe.
  7781. **/
  7782. static void
  7783. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7784. struct lpfc_iocbq *pIocbIn,
  7785. struct lpfc_iocbq *pIocbOut,
  7786. struct lpfc_wcqe_complete *wcqe)
  7787. {
  7788. unsigned long iflags;
  7789. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7790. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7791. sizeof(struct lpfc_iocbq) - offset);
  7792. /* Map WCQE parameters into irspiocb parameters */
  7793. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7794. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7795. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7796. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7797. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7798. wcqe->total_data_placed;
  7799. else
  7800. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7801. else {
  7802. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7803. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7804. }
  7805. /* Pick up HBA exchange busy condition */
  7806. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7807. spin_lock_irqsave(&phba->hbalock, iflags);
  7808. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7809. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7810. }
  7811. }
  7812. /**
  7813. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7814. * @phba: Pointer to HBA context object.
  7815. * @wcqe: Pointer to work-queue completion queue entry.
  7816. *
  7817. * This routine handles an ELS work-queue completion event and construct
  7818. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7819. * discovery engine to handle.
  7820. *
  7821. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7822. **/
  7823. static struct lpfc_iocbq *
  7824. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7825. struct lpfc_iocbq *irspiocbq)
  7826. {
  7827. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7828. struct lpfc_iocbq *cmdiocbq;
  7829. struct lpfc_wcqe_complete *wcqe;
  7830. unsigned long iflags;
  7831. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7832. spin_lock_irqsave(&phba->hbalock, iflags);
  7833. pring->stats.iocb_event++;
  7834. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7835. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7836. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7837. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7838. if (unlikely(!cmdiocbq)) {
  7839. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7840. "0386 ELS complete with no corresponding "
  7841. "cmdiocb: iotag (%d)\n",
  7842. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7843. lpfc_sli_release_iocbq(phba, irspiocbq);
  7844. return NULL;
  7845. }
  7846. /* Fake the irspiocbq and copy necessary response information */
  7847. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7848. return irspiocbq;
  7849. }
  7850. /**
  7851. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7852. * @phba: Pointer to HBA context object.
  7853. * @cqe: Pointer to mailbox completion queue entry.
  7854. *
  7855. * This routine process a mailbox completion queue entry with asynchrous
  7856. * event.
  7857. *
  7858. * Return: true if work posted to worker thread, otherwise false.
  7859. **/
  7860. static bool
  7861. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7862. {
  7863. struct lpfc_cq_event *cq_event;
  7864. unsigned long iflags;
  7865. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7866. "0392 Async Event: word0:x%x, word1:x%x, "
  7867. "word2:x%x, word3:x%x\n", mcqe->word0,
  7868. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7869. /* Allocate a new internal CQ_EVENT entry */
  7870. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7871. if (!cq_event) {
  7872. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7873. "0394 Failed to allocate CQ_EVENT entry\n");
  7874. return false;
  7875. }
  7876. /* Move the CQE into an asynchronous event entry */
  7877. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7878. spin_lock_irqsave(&phba->hbalock, iflags);
  7879. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7880. /* Set the async event flag */
  7881. phba->hba_flag |= ASYNC_EVENT;
  7882. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7883. return true;
  7884. }
  7885. /**
  7886. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7887. * @phba: Pointer to HBA context object.
  7888. * @cqe: Pointer to mailbox completion queue entry.
  7889. *
  7890. * This routine process a mailbox completion queue entry with mailbox
  7891. * completion event.
  7892. *
  7893. * Return: true if work posted to worker thread, otherwise false.
  7894. **/
  7895. static bool
  7896. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7897. {
  7898. uint32_t mcqe_status;
  7899. MAILBOX_t *mbox, *pmbox;
  7900. struct lpfc_mqe *mqe;
  7901. struct lpfc_vport *vport;
  7902. struct lpfc_nodelist *ndlp;
  7903. struct lpfc_dmabuf *mp;
  7904. unsigned long iflags;
  7905. LPFC_MBOXQ_t *pmb;
  7906. bool workposted = false;
  7907. int rc;
  7908. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7909. if (!bf_get(lpfc_trailer_completed, mcqe))
  7910. goto out_no_mqe_complete;
  7911. /* Get the reference to the active mbox command */
  7912. spin_lock_irqsave(&phba->hbalock, iflags);
  7913. pmb = phba->sli.mbox_active;
  7914. if (unlikely(!pmb)) {
  7915. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7916. "1832 No pending MBOX command to handle\n");
  7917. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7918. goto out_no_mqe_complete;
  7919. }
  7920. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7921. mqe = &pmb->u.mqe;
  7922. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7923. mbox = phba->mbox;
  7924. vport = pmb->vport;
  7925. /* Reset heartbeat timer */
  7926. phba->last_completion_time = jiffies;
  7927. del_timer(&phba->sli.mbox_tmo);
  7928. /* Move mbox data to caller's mailbox region, do endian swapping */
  7929. if (pmb->mbox_cmpl && mbox)
  7930. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7931. /* Set the mailbox status with SLI4 range 0x4000 */
  7932. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7933. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7934. bf_set(lpfc_mqe_status, mqe,
  7935. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7936. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7937. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7938. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7939. "MBOX dflt rpi: status:x%x rpi:x%x",
  7940. mcqe_status,
  7941. pmbox->un.varWords[0], 0);
  7942. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7943. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7944. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7945. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7946. * RID of the PPI using the same mbox buffer.
  7947. */
  7948. lpfc_unreg_login(phba, vport->vpi,
  7949. pmbox->un.varWords[0], pmb);
  7950. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7951. pmb->context1 = mp;
  7952. pmb->context2 = ndlp;
  7953. pmb->vport = vport;
  7954. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7955. if (rc != MBX_BUSY)
  7956. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7957. LOG_SLI, "0385 rc should "
  7958. "have been MBX_BUSY\n");
  7959. if (rc != MBX_NOT_FINISHED)
  7960. goto send_current_mbox;
  7961. }
  7962. }
  7963. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7964. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7965. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7966. /* There is mailbox completion work to do */
  7967. spin_lock_irqsave(&phba->hbalock, iflags);
  7968. __lpfc_mbox_cmpl_put(phba, pmb);
  7969. phba->work_ha |= HA_MBATT;
  7970. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7971. workposted = true;
  7972. send_current_mbox:
  7973. spin_lock_irqsave(&phba->hbalock, iflags);
  7974. /* Release the mailbox command posting token */
  7975. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7976. /* Setting active mailbox pointer need to be in sync to flag clear */
  7977. phba->sli.mbox_active = NULL;
  7978. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7979. /* Wake up worker thread to post the next pending mailbox command */
  7980. lpfc_worker_wake_up(phba);
  7981. out_no_mqe_complete:
  7982. if (bf_get(lpfc_trailer_consumed, mcqe))
  7983. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7984. return workposted;
  7985. }
  7986. /**
  7987. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7988. * @phba: Pointer to HBA context object.
  7989. * @cqe: Pointer to mailbox completion queue entry.
  7990. *
  7991. * This routine process a mailbox completion queue entry, it invokes the
  7992. * proper mailbox complete handling or asynchrous event handling routine
  7993. * according to the MCQE's async bit.
  7994. *
  7995. * Return: true if work posted to worker thread, otherwise false.
  7996. **/
  7997. static bool
  7998. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7999. {
  8000. struct lpfc_mcqe mcqe;
  8001. bool workposted;
  8002. /* Copy the mailbox MCQE and convert endian order as needed */
  8003. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8004. /* Invoke the proper event handling routine */
  8005. if (!bf_get(lpfc_trailer_async, &mcqe))
  8006. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8007. else
  8008. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8009. return workposted;
  8010. }
  8011. /**
  8012. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8013. * @phba: Pointer to HBA context object.
  8014. * @wcqe: Pointer to work-queue completion queue entry.
  8015. *
  8016. * This routine handles an ELS work-queue completion event.
  8017. *
  8018. * Return: true if work posted to worker thread, otherwise false.
  8019. **/
  8020. static bool
  8021. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8022. struct lpfc_wcqe_complete *wcqe)
  8023. {
  8024. struct lpfc_iocbq *irspiocbq;
  8025. unsigned long iflags;
  8026. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8027. /* Get an irspiocbq for later ELS response processing use */
  8028. irspiocbq = lpfc_sli_get_iocbq(phba);
  8029. if (!irspiocbq) {
  8030. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8031. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8032. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8033. pring->txq_cnt, phba->iocb_cnt,
  8034. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8035. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8036. return false;
  8037. }
  8038. /* Save off the slow-path queue event for work thread to process */
  8039. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8040. spin_lock_irqsave(&phba->hbalock, iflags);
  8041. list_add_tail(&irspiocbq->cq_event.list,
  8042. &phba->sli4_hba.sp_queue_event);
  8043. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8044. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8045. return true;
  8046. }
  8047. /**
  8048. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8049. * @phba: Pointer to HBA context object.
  8050. * @wcqe: Pointer to work-queue completion queue entry.
  8051. *
  8052. * This routine handles slow-path WQ entry comsumed event by invoking the
  8053. * proper WQ release routine to the slow-path WQ.
  8054. **/
  8055. static void
  8056. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8057. struct lpfc_wcqe_release *wcqe)
  8058. {
  8059. /* Check for the slow-path ELS work queue */
  8060. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8061. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8062. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8063. else
  8064. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8065. "2579 Slow-path wqe consume event carries "
  8066. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8067. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8068. phba->sli4_hba.els_wq->queue_id);
  8069. }
  8070. /**
  8071. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8072. * @phba: Pointer to HBA context object.
  8073. * @cq: Pointer to a WQ completion queue.
  8074. * @wcqe: Pointer to work-queue completion queue entry.
  8075. *
  8076. * This routine handles an XRI abort event.
  8077. *
  8078. * Return: true if work posted to worker thread, otherwise false.
  8079. **/
  8080. static bool
  8081. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8082. struct lpfc_queue *cq,
  8083. struct sli4_wcqe_xri_aborted *wcqe)
  8084. {
  8085. bool workposted = false;
  8086. struct lpfc_cq_event *cq_event;
  8087. unsigned long iflags;
  8088. /* Allocate a new internal CQ_EVENT entry */
  8089. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8090. if (!cq_event) {
  8091. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8092. "0602 Failed to allocate CQ_EVENT entry\n");
  8093. return false;
  8094. }
  8095. /* Move the CQE into the proper xri abort event list */
  8096. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8097. switch (cq->subtype) {
  8098. case LPFC_FCP:
  8099. spin_lock_irqsave(&phba->hbalock, iflags);
  8100. list_add_tail(&cq_event->list,
  8101. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8102. /* Set the fcp xri abort event flag */
  8103. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8104. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8105. workposted = true;
  8106. break;
  8107. case LPFC_ELS:
  8108. spin_lock_irqsave(&phba->hbalock, iflags);
  8109. list_add_tail(&cq_event->list,
  8110. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8111. /* Set the els xri abort event flag */
  8112. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8113. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8114. workposted = true;
  8115. break;
  8116. default:
  8117. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8118. "0603 Invalid work queue CQE subtype (x%x)\n",
  8119. cq->subtype);
  8120. workposted = false;
  8121. break;
  8122. }
  8123. return workposted;
  8124. }
  8125. /**
  8126. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8127. * @phba: Pointer to HBA context object.
  8128. * @rcqe: Pointer to receive-queue completion queue entry.
  8129. *
  8130. * This routine process a receive-queue completion queue entry.
  8131. *
  8132. * Return: true if work posted to worker thread, otherwise false.
  8133. **/
  8134. static bool
  8135. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8136. {
  8137. bool workposted = false;
  8138. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8139. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8140. struct hbq_dmabuf *dma_buf;
  8141. uint32_t status;
  8142. unsigned long iflags;
  8143. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8144. goto out;
  8145. status = bf_get(lpfc_rcqe_status, rcqe);
  8146. switch (status) {
  8147. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8148. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8149. "2537 Receive Frame Truncated!!\n");
  8150. case FC_STATUS_RQ_SUCCESS:
  8151. lpfc_sli4_rq_release(hrq, drq);
  8152. spin_lock_irqsave(&phba->hbalock, iflags);
  8153. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8154. if (!dma_buf) {
  8155. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8156. goto out;
  8157. }
  8158. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8159. /* save off the frame for the word thread to process */
  8160. list_add_tail(&dma_buf->cq_event.list,
  8161. &phba->sli4_hba.sp_queue_event);
  8162. /* Frame received */
  8163. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8164. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8165. workposted = true;
  8166. break;
  8167. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8168. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8169. /* Post more buffers if possible */
  8170. spin_lock_irqsave(&phba->hbalock, iflags);
  8171. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8172. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8173. workposted = true;
  8174. break;
  8175. }
  8176. out:
  8177. return workposted;
  8178. }
  8179. /**
  8180. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8181. * @phba: Pointer to HBA context object.
  8182. * @cq: Pointer to the completion queue.
  8183. * @wcqe: Pointer to a completion queue entry.
  8184. *
  8185. * This routine process a slow-path work-queue or recieve queue completion queue
  8186. * entry.
  8187. *
  8188. * Return: true if work posted to worker thread, otherwise false.
  8189. **/
  8190. static bool
  8191. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8192. struct lpfc_cqe *cqe)
  8193. {
  8194. struct lpfc_cqe cqevt;
  8195. bool workposted = false;
  8196. /* Copy the work queue CQE and convert endian order if needed */
  8197. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8198. /* Check and process for different type of WCQE and dispatch */
  8199. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8200. case CQE_CODE_COMPL_WQE:
  8201. /* Process the WQ/RQ complete event */
  8202. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8203. (struct lpfc_wcqe_complete *)&cqevt);
  8204. break;
  8205. case CQE_CODE_RELEASE_WQE:
  8206. /* Process the WQ release event */
  8207. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8208. (struct lpfc_wcqe_release *)&cqevt);
  8209. break;
  8210. case CQE_CODE_XRI_ABORTED:
  8211. /* Process the WQ XRI abort event */
  8212. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8213. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8214. break;
  8215. case CQE_CODE_RECEIVE:
  8216. /* Process the RQ event */
  8217. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8218. (struct lpfc_rcqe *)&cqevt);
  8219. break;
  8220. default:
  8221. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8222. "0388 Not a valid WCQE code: x%x\n",
  8223. bf_get(lpfc_cqe_code, &cqevt));
  8224. break;
  8225. }
  8226. return workposted;
  8227. }
  8228. /**
  8229. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8230. * @phba: Pointer to HBA context object.
  8231. * @eqe: Pointer to fast-path event queue entry.
  8232. *
  8233. * This routine process a event queue entry from the slow-path event queue.
  8234. * It will check the MajorCode and MinorCode to determine this is for a
  8235. * completion event on a completion queue, if not, an error shall be logged
  8236. * and just return. Otherwise, it will get to the corresponding completion
  8237. * queue and process all the entries on that completion queue, rearm the
  8238. * completion queue, and then return.
  8239. *
  8240. **/
  8241. static void
  8242. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8243. {
  8244. struct lpfc_queue *cq = NULL, *childq, *speq;
  8245. struct lpfc_cqe *cqe;
  8246. bool workposted = false;
  8247. int ecount = 0;
  8248. uint16_t cqid;
  8249. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8250. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8251. "0359 Not a valid slow-path completion "
  8252. "event: majorcode=x%x, minorcode=x%x\n",
  8253. bf_get_le32(lpfc_eqe_major_code, eqe),
  8254. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8255. return;
  8256. }
  8257. /* Get the reference to the corresponding CQ */
  8258. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8259. /* Search for completion queue pointer matching this cqid */
  8260. speq = phba->sli4_hba.sp_eq;
  8261. list_for_each_entry(childq, &speq->child_list, list) {
  8262. if (childq->queue_id == cqid) {
  8263. cq = childq;
  8264. break;
  8265. }
  8266. }
  8267. if (unlikely(!cq)) {
  8268. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8269. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8270. "0365 Slow-path CQ identifier "
  8271. "(%d) does not exist\n", cqid);
  8272. return;
  8273. }
  8274. /* Process all the entries to the CQ */
  8275. switch (cq->type) {
  8276. case LPFC_MCQ:
  8277. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8278. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8279. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8280. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8281. }
  8282. break;
  8283. case LPFC_WCQ:
  8284. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8285. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8286. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8287. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8288. }
  8289. break;
  8290. default:
  8291. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8292. "0370 Invalid completion queue type (%d)\n",
  8293. cq->type);
  8294. return;
  8295. }
  8296. /* Catch the no cq entry condition, log an error */
  8297. if (unlikely(ecount == 0))
  8298. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8299. "0371 No entry from the CQ: identifier "
  8300. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8301. /* In any case, flash and re-arm the RCQ */
  8302. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8303. /* wake up worker thread if there are works to be done */
  8304. if (workposted)
  8305. lpfc_worker_wake_up(phba);
  8306. }
  8307. /**
  8308. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8309. * @eqe: Pointer to fast-path completion queue entry.
  8310. *
  8311. * This routine process a fast-path work queue completion entry from fast-path
  8312. * event queue for FCP command response completion.
  8313. **/
  8314. static void
  8315. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8316. struct lpfc_wcqe_complete *wcqe)
  8317. {
  8318. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8319. struct lpfc_iocbq *cmdiocbq;
  8320. struct lpfc_iocbq irspiocbq;
  8321. unsigned long iflags;
  8322. spin_lock_irqsave(&phba->hbalock, iflags);
  8323. pring->stats.iocb_event++;
  8324. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8325. /* Check for response status */
  8326. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8327. /* If resource errors reported from HBA, reduce queue
  8328. * depth of the SCSI device.
  8329. */
  8330. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8331. IOSTAT_LOCAL_REJECT) &&
  8332. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8333. phba->lpfc_rampdown_queue_depth(phba);
  8334. }
  8335. /* Log the error status */
  8336. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8337. "0373 FCP complete error: status=x%x, "
  8338. "hw_status=x%x, total_data_specified=%d, "
  8339. "parameter=x%x, word3=x%x\n",
  8340. bf_get(lpfc_wcqe_c_status, wcqe),
  8341. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8342. wcqe->total_data_placed, wcqe->parameter,
  8343. wcqe->word3);
  8344. }
  8345. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8346. spin_lock_irqsave(&phba->hbalock, iflags);
  8347. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8348. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8349. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8350. if (unlikely(!cmdiocbq)) {
  8351. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8352. "0374 FCP complete with no corresponding "
  8353. "cmdiocb: iotag (%d)\n",
  8354. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8355. return;
  8356. }
  8357. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8358. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8359. "0375 FCP cmdiocb not callback function "
  8360. "iotag: (%d)\n",
  8361. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8362. return;
  8363. }
  8364. /* Fake the irspiocb and copy necessary response information */
  8365. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8366. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8367. spin_lock_irqsave(&phba->hbalock, iflags);
  8368. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8369. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8370. }
  8371. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8372. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8373. }
  8374. /**
  8375. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8376. * @phba: Pointer to HBA context object.
  8377. * @cq: Pointer to completion queue.
  8378. * @wcqe: Pointer to work-queue completion queue entry.
  8379. *
  8380. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8381. * proper WQ release routine to the slow-path WQ.
  8382. **/
  8383. static void
  8384. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8385. struct lpfc_wcqe_release *wcqe)
  8386. {
  8387. struct lpfc_queue *childwq;
  8388. bool wqid_matched = false;
  8389. uint16_t fcp_wqid;
  8390. /* Check for fast-path FCP work queue release */
  8391. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8392. list_for_each_entry(childwq, &cq->child_list, list) {
  8393. if (childwq->queue_id == fcp_wqid) {
  8394. lpfc_sli4_wq_release(childwq,
  8395. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8396. wqid_matched = true;
  8397. break;
  8398. }
  8399. }
  8400. /* Report warning log message if no match found */
  8401. if (wqid_matched != true)
  8402. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8403. "2580 Fast-path wqe consume event carries "
  8404. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8405. }
  8406. /**
  8407. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8408. * @cq: Pointer to the completion queue.
  8409. * @eqe: Pointer to fast-path completion queue entry.
  8410. *
  8411. * This routine process a fast-path work queue completion entry from fast-path
  8412. * event queue for FCP command response completion.
  8413. **/
  8414. static int
  8415. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8416. struct lpfc_cqe *cqe)
  8417. {
  8418. struct lpfc_wcqe_release wcqe;
  8419. bool workposted = false;
  8420. unsigned long iflag;
  8421. /* Copy the work queue CQE and convert endian order if needed */
  8422. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8423. /* Check and process for different type of WCQE and dispatch */
  8424. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8425. case CQE_CODE_COMPL_WQE:
  8426. /* Process the WQ complete event */
  8427. spin_lock_irqsave(&phba->hbalock, iflag);
  8428. phba->last_completion_time = jiffies;
  8429. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8430. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8431. (struct lpfc_wcqe_complete *)&wcqe);
  8432. break;
  8433. case CQE_CODE_RELEASE_WQE:
  8434. /* Process the WQ release event */
  8435. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8436. (struct lpfc_wcqe_release *)&wcqe);
  8437. break;
  8438. case CQE_CODE_XRI_ABORTED:
  8439. /* Process the WQ XRI abort event */
  8440. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8441. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8442. break;
  8443. default:
  8444. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8445. "0144 Not a valid WCQE code: x%x\n",
  8446. bf_get(lpfc_wcqe_c_code, &wcqe));
  8447. break;
  8448. }
  8449. return workposted;
  8450. }
  8451. /**
  8452. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8453. * @phba: Pointer to HBA context object.
  8454. * @eqe: Pointer to fast-path event queue entry.
  8455. *
  8456. * This routine process a event queue entry from the fast-path event queue.
  8457. * It will check the MajorCode and MinorCode to determine this is for a
  8458. * completion event on a completion queue, if not, an error shall be logged
  8459. * and just return. Otherwise, it will get to the corresponding completion
  8460. * queue and process all the entries on the completion queue, rearm the
  8461. * completion queue, and then return.
  8462. **/
  8463. static void
  8464. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8465. uint32_t fcp_cqidx)
  8466. {
  8467. struct lpfc_queue *cq;
  8468. struct lpfc_cqe *cqe;
  8469. bool workposted = false;
  8470. uint16_t cqid;
  8471. int ecount = 0;
  8472. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8473. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8474. "0366 Not a valid fast-path completion "
  8475. "event: majorcode=x%x, minorcode=x%x\n",
  8476. bf_get_le32(lpfc_eqe_major_code, eqe),
  8477. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8478. return;
  8479. }
  8480. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8481. if (unlikely(!cq)) {
  8482. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8483. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8484. "0367 Fast-path completion queue "
  8485. "does not exist\n");
  8486. return;
  8487. }
  8488. /* Get the reference to the corresponding CQ */
  8489. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8490. if (unlikely(cqid != cq->queue_id)) {
  8491. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8492. "0368 Miss-matched fast-path completion "
  8493. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8494. cqid, cq->queue_id);
  8495. return;
  8496. }
  8497. /* Process all the entries to the CQ */
  8498. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8499. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8500. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8501. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8502. }
  8503. /* Catch the no cq entry condition */
  8504. if (unlikely(ecount == 0))
  8505. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8506. "0369 No entry from fast-path completion "
  8507. "queue fcpcqid=%d\n", cq->queue_id);
  8508. /* In any case, flash and re-arm the CQ */
  8509. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8510. /* wake up worker thread if there are works to be done */
  8511. if (workposted)
  8512. lpfc_worker_wake_up(phba);
  8513. }
  8514. static void
  8515. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8516. {
  8517. struct lpfc_eqe *eqe;
  8518. /* walk all the EQ entries and drop on the floor */
  8519. while ((eqe = lpfc_sli4_eq_get(eq)))
  8520. ;
  8521. /* Clear and re-arm the EQ */
  8522. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8523. }
  8524. /**
  8525. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8526. * @irq: Interrupt number.
  8527. * @dev_id: The device context pointer.
  8528. *
  8529. * This function is directly called from the PCI layer as an interrupt
  8530. * service routine when device with SLI-4 interface spec is enabled with
  8531. * MSI-X multi-message interrupt mode and there are slow-path events in
  8532. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8533. * interrupt mode, this function is called as part of the device-level
  8534. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8535. * undergoing initialization, the interrupt handler will not process the
  8536. * interrupt. The link attention and ELS ring attention events are handled
  8537. * by the worker thread. The interrupt handler signals the worker thread
  8538. * and returns for these events. This function is called without any lock
  8539. * held. It gets the hbalock to access and update SLI data structures.
  8540. *
  8541. * This function returns IRQ_HANDLED when interrupt is handled else it
  8542. * returns IRQ_NONE.
  8543. **/
  8544. irqreturn_t
  8545. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8546. {
  8547. struct lpfc_hba *phba;
  8548. struct lpfc_queue *speq;
  8549. struct lpfc_eqe *eqe;
  8550. unsigned long iflag;
  8551. int ecount = 0;
  8552. /*
  8553. * Get the driver's phba structure from the dev_id
  8554. */
  8555. phba = (struct lpfc_hba *)dev_id;
  8556. if (unlikely(!phba))
  8557. return IRQ_NONE;
  8558. /* Get to the EQ struct associated with this vector */
  8559. speq = phba->sli4_hba.sp_eq;
  8560. /* Check device state for handling interrupt */
  8561. if (unlikely(lpfc_intr_state_check(phba))) {
  8562. /* Check again for link_state with lock held */
  8563. spin_lock_irqsave(&phba->hbalock, iflag);
  8564. if (phba->link_state < LPFC_LINK_DOWN)
  8565. /* Flush, clear interrupt, and rearm the EQ */
  8566. lpfc_sli4_eq_flush(phba, speq);
  8567. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8568. return IRQ_NONE;
  8569. }
  8570. /*
  8571. * Process all the event on FCP slow-path EQ
  8572. */
  8573. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8574. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8575. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8576. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8577. }
  8578. /* Always clear and re-arm the slow-path EQ */
  8579. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8580. /* Catch the no cq entry condition */
  8581. if (unlikely(ecount == 0)) {
  8582. if (phba->intr_type == MSIX)
  8583. /* MSI-X treated interrupt served as no EQ share INT */
  8584. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8585. "0357 MSI-X interrupt with no EQE\n");
  8586. else
  8587. /* Non MSI-X treated on interrupt as EQ share INT */
  8588. return IRQ_NONE;
  8589. }
  8590. return IRQ_HANDLED;
  8591. } /* lpfc_sli4_sp_intr_handler */
  8592. /**
  8593. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8594. * @irq: Interrupt number.
  8595. * @dev_id: The device context pointer.
  8596. *
  8597. * This function is directly called from the PCI layer as an interrupt
  8598. * service routine when device with SLI-4 interface spec is enabled with
  8599. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8600. * ring event in the HBA. However, when the device is enabled with either
  8601. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8602. * device-level interrupt handler. When the PCI slot is in error recovery
  8603. * or the HBA is undergoing initialization, the interrupt handler will not
  8604. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8605. * the intrrupt context. This function is called without any lock held.
  8606. * It gets the hbalock to access and update SLI data structures. Note that,
  8607. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8608. * equal to that of FCP CQ index.
  8609. *
  8610. * This function returns IRQ_HANDLED when interrupt is handled else it
  8611. * returns IRQ_NONE.
  8612. **/
  8613. irqreturn_t
  8614. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8615. {
  8616. struct lpfc_hba *phba;
  8617. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8618. struct lpfc_queue *fpeq;
  8619. struct lpfc_eqe *eqe;
  8620. unsigned long iflag;
  8621. int ecount = 0;
  8622. uint32_t fcp_eqidx;
  8623. /* Get the driver's phba structure from the dev_id */
  8624. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8625. phba = fcp_eq_hdl->phba;
  8626. fcp_eqidx = fcp_eq_hdl->idx;
  8627. if (unlikely(!phba))
  8628. return IRQ_NONE;
  8629. /* Get to the EQ struct associated with this vector */
  8630. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8631. /* Check device state for handling interrupt */
  8632. if (unlikely(lpfc_intr_state_check(phba))) {
  8633. /* Check again for link_state with lock held */
  8634. spin_lock_irqsave(&phba->hbalock, iflag);
  8635. if (phba->link_state < LPFC_LINK_DOWN)
  8636. /* Flush, clear interrupt, and rearm the EQ */
  8637. lpfc_sli4_eq_flush(phba, fpeq);
  8638. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8639. return IRQ_NONE;
  8640. }
  8641. /*
  8642. * Process all the event on FCP fast-path EQ
  8643. */
  8644. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8645. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8646. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8647. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8648. }
  8649. /* Always clear and re-arm the fast-path EQ */
  8650. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8651. if (unlikely(ecount == 0)) {
  8652. if (phba->intr_type == MSIX)
  8653. /* MSI-X treated interrupt served as no EQ share INT */
  8654. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8655. "0358 MSI-X interrupt with no EQE\n");
  8656. else
  8657. /* Non MSI-X treated on interrupt as EQ share INT */
  8658. return IRQ_NONE;
  8659. }
  8660. return IRQ_HANDLED;
  8661. } /* lpfc_sli4_fp_intr_handler */
  8662. /**
  8663. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8664. * @irq: Interrupt number.
  8665. * @dev_id: The device context pointer.
  8666. *
  8667. * This function is the device-level interrupt handler to device with SLI-4
  8668. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8669. * interrupt mode is enabled and there is an event in the HBA which requires
  8670. * driver attention. This function invokes the slow-path interrupt attention
  8671. * handling function and fast-path interrupt attention handling function in
  8672. * turn to process the relevant HBA attention events. This function is called
  8673. * without any lock held. It gets the hbalock to access and update SLI data
  8674. * structures.
  8675. *
  8676. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8677. * returns IRQ_NONE.
  8678. **/
  8679. irqreturn_t
  8680. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8681. {
  8682. struct lpfc_hba *phba;
  8683. irqreturn_t sp_irq_rc, fp_irq_rc;
  8684. bool fp_handled = false;
  8685. uint32_t fcp_eqidx;
  8686. /* Get the driver's phba structure from the dev_id */
  8687. phba = (struct lpfc_hba *)dev_id;
  8688. if (unlikely(!phba))
  8689. return IRQ_NONE;
  8690. /*
  8691. * Invokes slow-path host attention interrupt handling as appropriate.
  8692. */
  8693. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8694. /*
  8695. * Invoke fast-path host attention interrupt handling as appropriate.
  8696. */
  8697. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8698. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8699. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8700. if (fp_irq_rc == IRQ_HANDLED)
  8701. fp_handled |= true;
  8702. }
  8703. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8704. } /* lpfc_sli4_intr_handler */
  8705. /**
  8706. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8707. * @queue: The queue structure to free.
  8708. *
  8709. * This function frees a queue structure and the DMAable memeory used for
  8710. * the host resident queue. This function must be called after destroying the
  8711. * queue on the HBA.
  8712. **/
  8713. void
  8714. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8715. {
  8716. struct lpfc_dmabuf *dmabuf;
  8717. if (!queue)
  8718. return;
  8719. while (!list_empty(&queue->page_list)) {
  8720. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8721. list);
  8722. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8723. dmabuf->virt, dmabuf->phys);
  8724. kfree(dmabuf);
  8725. }
  8726. kfree(queue);
  8727. return;
  8728. }
  8729. /**
  8730. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8731. * @phba: The HBA that this queue is being created on.
  8732. * @entry_size: The size of each queue entry for this queue.
  8733. * @entry count: The number of entries that this queue will handle.
  8734. *
  8735. * This function allocates a queue structure and the DMAable memory used for
  8736. * the host resident queue. This function must be called before creating the
  8737. * queue on the HBA.
  8738. **/
  8739. struct lpfc_queue *
  8740. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8741. uint32_t entry_count)
  8742. {
  8743. struct lpfc_queue *queue;
  8744. struct lpfc_dmabuf *dmabuf;
  8745. int x, total_qe_count;
  8746. void *dma_pointer;
  8747. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8748. if (!phba->sli4_hba.pc_sli4_params.supported)
  8749. hw_page_size = SLI4_PAGE_SIZE;
  8750. queue = kzalloc(sizeof(struct lpfc_queue) +
  8751. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8752. if (!queue)
  8753. return NULL;
  8754. queue->page_count = (ALIGN(entry_size * entry_count,
  8755. hw_page_size))/hw_page_size;
  8756. INIT_LIST_HEAD(&queue->list);
  8757. INIT_LIST_HEAD(&queue->page_list);
  8758. INIT_LIST_HEAD(&queue->child_list);
  8759. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8760. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8761. if (!dmabuf)
  8762. goto out_fail;
  8763. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8764. hw_page_size, &dmabuf->phys,
  8765. GFP_KERNEL);
  8766. if (!dmabuf->virt) {
  8767. kfree(dmabuf);
  8768. goto out_fail;
  8769. }
  8770. memset(dmabuf->virt, 0, hw_page_size);
  8771. dmabuf->buffer_tag = x;
  8772. list_add_tail(&dmabuf->list, &queue->page_list);
  8773. /* initialize queue's entry array */
  8774. dma_pointer = dmabuf->virt;
  8775. for (; total_qe_count < entry_count &&
  8776. dma_pointer < (hw_page_size + dmabuf->virt);
  8777. total_qe_count++, dma_pointer += entry_size) {
  8778. queue->qe[total_qe_count].address = dma_pointer;
  8779. }
  8780. }
  8781. queue->entry_size = entry_size;
  8782. queue->entry_count = entry_count;
  8783. queue->phba = phba;
  8784. return queue;
  8785. out_fail:
  8786. lpfc_sli4_queue_free(queue);
  8787. return NULL;
  8788. }
  8789. /**
  8790. * lpfc_eq_create - Create an Event Queue on the HBA
  8791. * @phba: HBA structure that indicates port to create a queue on.
  8792. * @eq: The queue structure to use to create the event queue.
  8793. * @imax: The maximum interrupt per second limit.
  8794. *
  8795. * This function creates an event queue, as detailed in @eq, on a port,
  8796. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8797. *
  8798. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8799. * is used to get the entry count and entry size that are necessary to
  8800. * determine the number of pages to allocate and use for this queue. This
  8801. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8802. * event queue. This function is asynchronous and will wait for the mailbox
  8803. * command to finish before continuing.
  8804. *
  8805. * On success this function will return a zero. If unable to allocate enough
  8806. * memory this function will return ENOMEM. If the queue create mailbox command
  8807. * fails this function will return ENXIO.
  8808. **/
  8809. uint32_t
  8810. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8811. {
  8812. struct lpfc_mbx_eq_create *eq_create;
  8813. LPFC_MBOXQ_t *mbox;
  8814. int rc, length, status = 0;
  8815. struct lpfc_dmabuf *dmabuf;
  8816. uint32_t shdr_status, shdr_add_status;
  8817. union lpfc_sli4_cfg_shdr *shdr;
  8818. uint16_t dmult;
  8819. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8820. if (!phba->sli4_hba.pc_sli4_params.supported)
  8821. hw_page_size = SLI4_PAGE_SIZE;
  8822. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8823. if (!mbox)
  8824. return -ENOMEM;
  8825. length = (sizeof(struct lpfc_mbx_eq_create) -
  8826. sizeof(struct lpfc_sli4_cfg_mhdr));
  8827. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8828. LPFC_MBOX_OPCODE_EQ_CREATE,
  8829. length, LPFC_SLI4_MBX_EMBED);
  8830. eq_create = &mbox->u.mqe.un.eq_create;
  8831. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8832. eq->page_count);
  8833. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8834. LPFC_EQE_SIZE);
  8835. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8836. /* Calculate delay multiper from maximum interrupt per second */
  8837. dmult = LPFC_DMULT_CONST/imax - 1;
  8838. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8839. dmult);
  8840. switch (eq->entry_count) {
  8841. default:
  8842. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8843. "0360 Unsupported EQ count. (%d)\n",
  8844. eq->entry_count);
  8845. if (eq->entry_count < 256)
  8846. return -EINVAL;
  8847. /* otherwise default to smallest count (drop through) */
  8848. case 256:
  8849. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8850. LPFC_EQ_CNT_256);
  8851. break;
  8852. case 512:
  8853. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8854. LPFC_EQ_CNT_512);
  8855. break;
  8856. case 1024:
  8857. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8858. LPFC_EQ_CNT_1024);
  8859. break;
  8860. case 2048:
  8861. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8862. LPFC_EQ_CNT_2048);
  8863. break;
  8864. case 4096:
  8865. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8866. LPFC_EQ_CNT_4096);
  8867. break;
  8868. }
  8869. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8870. memset(dmabuf->virt, 0, hw_page_size);
  8871. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8872. putPaddrLow(dmabuf->phys);
  8873. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8874. putPaddrHigh(dmabuf->phys);
  8875. }
  8876. mbox->vport = phba->pport;
  8877. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8878. mbox->context1 = NULL;
  8879. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8880. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8881. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8882. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8883. if (shdr_status || shdr_add_status || rc) {
  8884. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8885. "2500 EQ_CREATE mailbox failed with "
  8886. "status x%x add_status x%x, mbx status x%x\n",
  8887. shdr_status, shdr_add_status, rc);
  8888. status = -ENXIO;
  8889. }
  8890. eq->type = LPFC_EQ;
  8891. eq->subtype = LPFC_NONE;
  8892. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8893. if (eq->queue_id == 0xFFFF)
  8894. status = -ENXIO;
  8895. eq->host_index = 0;
  8896. eq->hba_index = 0;
  8897. mempool_free(mbox, phba->mbox_mem_pool);
  8898. return status;
  8899. }
  8900. /**
  8901. * lpfc_cq_create - Create a Completion Queue on the HBA
  8902. * @phba: HBA structure that indicates port to create a queue on.
  8903. * @cq: The queue structure to use to create the completion queue.
  8904. * @eq: The event queue to bind this completion queue to.
  8905. *
  8906. * This function creates a completion queue, as detailed in @wq, on a port,
  8907. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8908. *
  8909. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8910. * is used to get the entry count and entry size that are necessary to
  8911. * determine the number of pages to allocate and use for this queue. The @eq
  8912. * is used to indicate which event queue to bind this completion queue to. This
  8913. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8914. * completion queue. This function is asynchronous and will wait for the mailbox
  8915. * command to finish before continuing.
  8916. *
  8917. * On success this function will return a zero. If unable to allocate enough
  8918. * memory this function will return ENOMEM. If the queue create mailbox command
  8919. * fails this function will return ENXIO.
  8920. **/
  8921. uint32_t
  8922. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8923. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8924. {
  8925. struct lpfc_mbx_cq_create *cq_create;
  8926. struct lpfc_dmabuf *dmabuf;
  8927. LPFC_MBOXQ_t *mbox;
  8928. int rc, length, status = 0;
  8929. uint32_t shdr_status, shdr_add_status;
  8930. union lpfc_sli4_cfg_shdr *shdr;
  8931. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8932. if (!phba->sli4_hba.pc_sli4_params.supported)
  8933. hw_page_size = SLI4_PAGE_SIZE;
  8934. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8935. if (!mbox)
  8936. return -ENOMEM;
  8937. length = (sizeof(struct lpfc_mbx_cq_create) -
  8938. sizeof(struct lpfc_sli4_cfg_mhdr));
  8939. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8940. LPFC_MBOX_OPCODE_CQ_CREATE,
  8941. length, LPFC_SLI4_MBX_EMBED);
  8942. cq_create = &mbox->u.mqe.un.cq_create;
  8943. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8944. cq->page_count);
  8945. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8946. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8947. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8948. switch (cq->entry_count) {
  8949. default:
  8950. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8951. "0361 Unsupported CQ count. (%d)\n",
  8952. cq->entry_count);
  8953. if (cq->entry_count < 256)
  8954. return -EINVAL;
  8955. /* otherwise default to smallest count (drop through) */
  8956. case 256:
  8957. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8958. LPFC_CQ_CNT_256);
  8959. break;
  8960. case 512:
  8961. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8962. LPFC_CQ_CNT_512);
  8963. break;
  8964. case 1024:
  8965. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8966. LPFC_CQ_CNT_1024);
  8967. break;
  8968. }
  8969. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8970. memset(dmabuf->virt, 0, hw_page_size);
  8971. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8972. putPaddrLow(dmabuf->phys);
  8973. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8974. putPaddrHigh(dmabuf->phys);
  8975. }
  8976. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8977. /* The IOCTL status is embedded in the mailbox subheader. */
  8978. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8979. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8980. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8981. if (shdr_status || shdr_add_status || rc) {
  8982. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8983. "2501 CQ_CREATE mailbox failed with "
  8984. "status x%x add_status x%x, mbx status x%x\n",
  8985. shdr_status, shdr_add_status, rc);
  8986. status = -ENXIO;
  8987. goto out;
  8988. }
  8989. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8990. if (cq->queue_id == 0xFFFF) {
  8991. status = -ENXIO;
  8992. goto out;
  8993. }
  8994. /* link the cq onto the parent eq child list */
  8995. list_add_tail(&cq->list, &eq->child_list);
  8996. /* Set up completion queue's type and subtype */
  8997. cq->type = type;
  8998. cq->subtype = subtype;
  8999. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9000. cq->host_index = 0;
  9001. cq->hba_index = 0;
  9002. out:
  9003. mempool_free(mbox, phba->mbox_mem_pool);
  9004. return status;
  9005. }
  9006. /**
  9007. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9008. * @phba: HBA structure that indicates port to create a queue on.
  9009. * @mq: The queue structure to use to create the mailbox queue.
  9010. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9011. * @cq: The completion queue to associate with this cq.
  9012. *
  9013. * This function provides failback (fb) functionality when the
  9014. * mq_create_ext fails on older FW generations. It's purpose is identical
  9015. * to mq_create_ext otherwise.
  9016. *
  9017. * This routine cannot fail as all attributes were previously accessed and
  9018. * initialized in mq_create_ext.
  9019. **/
  9020. static void
  9021. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9022. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9023. {
  9024. struct lpfc_mbx_mq_create *mq_create;
  9025. struct lpfc_dmabuf *dmabuf;
  9026. int length;
  9027. length = (sizeof(struct lpfc_mbx_mq_create) -
  9028. sizeof(struct lpfc_sli4_cfg_mhdr));
  9029. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9030. LPFC_MBOX_OPCODE_MQ_CREATE,
  9031. length, LPFC_SLI4_MBX_EMBED);
  9032. mq_create = &mbox->u.mqe.un.mq_create;
  9033. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9034. mq->page_count);
  9035. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9036. cq->queue_id);
  9037. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9038. switch (mq->entry_count) {
  9039. case 16:
  9040. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9041. LPFC_MQ_CNT_16);
  9042. break;
  9043. case 32:
  9044. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9045. LPFC_MQ_CNT_32);
  9046. break;
  9047. case 64:
  9048. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9049. LPFC_MQ_CNT_64);
  9050. break;
  9051. case 128:
  9052. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9053. LPFC_MQ_CNT_128);
  9054. break;
  9055. }
  9056. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9057. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9058. putPaddrLow(dmabuf->phys);
  9059. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9060. putPaddrHigh(dmabuf->phys);
  9061. }
  9062. }
  9063. /**
  9064. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9065. * @phba: HBA structure that indicates port to create a queue on.
  9066. * @mq: The queue structure to use to create the mailbox queue.
  9067. * @cq: The completion queue to associate with this cq.
  9068. * @subtype: The queue's subtype.
  9069. *
  9070. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9071. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9072. *
  9073. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9074. * is used to get the entry count and entry size that are necessary to
  9075. * determine the number of pages to allocate and use for this queue. This
  9076. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9077. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9078. * command to finish before continuing.
  9079. *
  9080. * On success this function will return a zero. If unable to allocate enough
  9081. * memory this function will return ENOMEM. If the queue create mailbox command
  9082. * fails this function will return ENXIO.
  9083. **/
  9084. int32_t
  9085. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9086. struct lpfc_queue *cq, uint32_t subtype)
  9087. {
  9088. struct lpfc_mbx_mq_create *mq_create;
  9089. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9090. struct lpfc_dmabuf *dmabuf;
  9091. LPFC_MBOXQ_t *mbox;
  9092. int rc, length, status = 0;
  9093. uint32_t shdr_status, shdr_add_status;
  9094. union lpfc_sli4_cfg_shdr *shdr;
  9095. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9096. if (!phba->sli4_hba.pc_sli4_params.supported)
  9097. hw_page_size = SLI4_PAGE_SIZE;
  9098. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9099. if (!mbox)
  9100. return -ENOMEM;
  9101. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9102. sizeof(struct lpfc_sli4_cfg_mhdr));
  9103. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9104. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9105. length, LPFC_SLI4_MBX_EMBED);
  9106. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9107. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9108. mq->page_count);
  9109. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9110. 1);
  9111. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9112. &mq_create_ext->u.request, 1);
  9113. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9114. &mq_create_ext->u.request, 1);
  9115. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9116. cq->queue_id);
  9117. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9118. switch (mq->entry_count) {
  9119. default:
  9120. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9121. "0362 Unsupported MQ count. (%d)\n",
  9122. mq->entry_count);
  9123. if (mq->entry_count < 16)
  9124. return -EINVAL;
  9125. /* otherwise default to smallest count (drop through) */
  9126. case 16:
  9127. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9128. LPFC_MQ_CNT_16);
  9129. break;
  9130. case 32:
  9131. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9132. LPFC_MQ_CNT_32);
  9133. break;
  9134. case 64:
  9135. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9136. LPFC_MQ_CNT_64);
  9137. break;
  9138. case 128:
  9139. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9140. LPFC_MQ_CNT_128);
  9141. break;
  9142. }
  9143. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9144. memset(dmabuf->virt, 0, hw_page_size);
  9145. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9146. putPaddrLow(dmabuf->phys);
  9147. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9148. putPaddrHigh(dmabuf->phys);
  9149. }
  9150. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9151. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9152. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9153. &mq_create_ext->u.response);
  9154. if (rc != MBX_SUCCESS) {
  9155. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9156. "2795 MQ_CREATE_EXT failed with "
  9157. "status x%x. Failback to MQ_CREATE.\n",
  9158. rc);
  9159. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9160. mq_create = &mbox->u.mqe.un.mq_create;
  9161. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9162. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9163. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9164. &mq_create->u.response);
  9165. }
  9166. /* The IOCTL status is embedded in the mailbox subheader. */
  9167. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9168. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9169. if (shdr_status || shdr_add_status || rc) {
  9170. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9171. "2502 MQ_CREATE mailbox failed with "
  9172. "status x%x add_status x%x, mbx status x%x\n",
  9173. shdr_status, shdr_add_status, rc);
  9174. status = -ENXIO;
  9175. goto out;
  9176. }
  9177. if (mq->queue_id == 0xFFFF) {
  9178. status = -ENXIO;
  9179. goto out;
  9180. }
  9181. mq->type = LPFC_MQ;
  9182. mq->subtype = subtype;
  9183. mq->host_index = 0;
  9184. mq->hba_index = 0;
  9185. /* link the mq onto the parent cq child list */
  9186. list_add_tail(&mq->list, &cq->child_list);
  9187. out:
  9188. mempool_free(mbox, phba->mbox_mem_pool);
  9189. return status;
  9190. }
  9191. /**
  9192. * lpfc_wq_create - Create a Work Queue on the HBA
  9193. * @phba: HBA structure that indicates port to create a queue on.
  9194. * @wq: The queue structure to use to create the work queue.
  9195. * @cq: The completion queue to bind this work queue to.
  9196. * @subtype: The subtype of the work queue indicating its functionality.
  9197. *
  9198. * This function creates a work queue, as detailed in @wq, on a port, described
  9199. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9200. *
  9201. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9202. * is used to get the entry count and entry size that are necessary to
  9203. * determine the number of pages to allocate and use for this queue. The @cq
  9204. * is used to indicate which completion queue to bind this work queue to. This
  9205. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9206. * work queue. This function is asynchronous and will wait for the mailbox
  9207. * command to finish before continuing.
  9208. *
  9209. * On success this function will return a zero. If unable to allocate enough
  9210. * memory this function will return ENOMEM. If the queue create mailbox command
  9211. * fails this function will return ENXIO.
  9212. **/
  9213. uint32_t
  9214. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9215. struct lpfc_queue *cq, uint32_t subtype)
  9216. {
  9217. struct lpfc_mbx_wq_create *wq_create;
  9218. struct lpfc_dmabuf *dmabuf;
  9219. LPFC_MBOXQ_t *mbox;
  9220. int rc, length, status = 0;
  9221. uint32_t shdr_status, shdr_add_status;
  9222. union lpfc_sli4_cfg_shdr *shdr;
  9223. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9224. if (!phba->sli4_hba.pc_sli4_params.supported)
  9225. hw_page_size = SLI4_PAGE_SIZE;
  9226. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9227. if (!mbox)
  9228. return -ENOMEM;
  9229. length = (sizeof(struct lpfc_mbx_wq_create) -
  9230. sizeof(struct lpfc_sli4_cfg_mhdr));
  9231. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9232. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9233. length, LPFC_SLI4_MBX_EMBED);
  9234. wq_create = &mbox->u.mqe.un.wq_create;
  9235. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9236. wq->page_count);
  9237. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9238. cq->queue_id);
  9239. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9240. memset(dmabuf->virt, 0, hw_page_size);
  9241. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9242. putPaddrLow(dmabuf->phys);
  9243. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9244. putPaddrHigh(dmabuf->phys);
  9245. }
  9246. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9247. /* The IOCTL status is embedded in the mailbox subheader. */
  9248. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9249. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9250. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9251. if (shdr_status || shdr_add_status || rc) {
  9252. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9253. "2503 WQ_CREATE mailbox failed with "
  9254. "status x%x add_status x%x, mbx status x%x\n",
  9255. shdr_status, shdr_add_status, rc);
  9256. status = -ENXIO;
  9257. goto out;
  9258. }
  9259. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9260. if (wq->queue_id == 0xFFFF) {
  9261. status = -ENXIO;
  9262. goto out;
  9263. }
  9264. wq->type = LPFC_WQ;
  9265. wq->subtype = subtype;
  9266. wq->host_index = 0;
  9267. wq->hba_index = 0;
  9268. /* link the wq onto the parent cq child list */
  9269. list_add_tail(&wq->list, &cq->child_list);
  9270. out:
  9271. mempool_free(mbox, phba->mbox_mem_pool);
  9272. return status;
  9273. }
  9274. /**
  9275. * lpfc_rq_create - Create a Receive Queue on the HBA
  9276. * @phba: HBA structure that indicates port to create a queue on.
  9277. * @hrq: The queue structure to use to create the header receive queue.
  9278. * @drq: The queue structure to use to create the data receive queue.
  9279. * @cq: The completion queue to bind this work queue to.
  9280. *
  9281. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9282. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9283. * to the HBA.
  9284. *
  9285. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9286. * struct is used to get the entry count that is necessary to determine the
  9287. * number of pages to use for this queue. The @cq is used to indicate which
  9288. * completion queue to bind received buffers that are posted to these queues to.
  9289. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9290. * receive queue pair. This function is asynchronous and will wait for the
  9291. * mailbox command to finish before continuing.
  9292. *
  9293. * On success this function will return a zero. If unable to allocate enough
  9294. * memory this function will return ENOMEM. If the queue create mailbox command
  9295. * fails this function will return ENXIO.
  9296. **/
  9297. uint32_t
  9298. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9299. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9300. {
  9301. struct lpfc_mbx_rq_create *rq_create;
  9302. struct lpfc_dmabuf *dmabuf;
  9303. LPFC_MBOXQ_t *mbox;
  9304. int rc, length, status = 0;
  9305. uint32_t shdr_status, shdr_add_status;
  9306. union lpfc_sli4_cfg_shdr *shdr;
  9307. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9308. if (!phba->sli4_hba.pc_sli4_params.supported)
  9309. hw_page_size = SLI4_PAGE_SIZE;
  9310. if (hrq->entry_count != drq->entry_count)
  9311. return -EINVAL;
  9312. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9313. if (!mbox)
  9314. return -ENOMEM;
  9315. length = (sizeof(struct lpfc_mbx_rq_create) -
  9316. sizeof(struct lpfc_sli4_cfg_mhdr));
  9317. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9318. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9319. length, LPFC_SLI4_MBX_EMBED);
  9320. rq_create = &mbox->u.mqe.un.rq_create;
  9321. switch (hrq->entry_count) {
  9322. default:
  9323. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9324. "2535 Unsupported RQ count. (%d)\n",
  9325. hrq->entry_count);
  9326. if (hrq->entry_count < 512)
  9327. return -EINVAL;
  9328. /* otherwise default to smallest count (drop through) */
  9329. case 512:
  9330. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9331. LPFC_RQ_RING_SIZE_512);
  9332. break;
  9333. case 1024:
  9334. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9335. LPFC_RQ_RING_SIZE_1024);
  9336. break;
  9337. case 2048:
  9338. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9339. LPFC_RQ_RING_SIZE_2048);
  9340. break;
  9341. case 4096:
  9342. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9343. LPFC_RQ_RING_SIZE_4096);
  9344. break;
  9345. }
  9346. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9347. cq->queue_id);
  9348. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9349. hrq->page_count);
  9350. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9351. LPFC_HDR_BUF_SIZE);
  9352. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9353. memset(dmabuf->virt, 0, hw_page_size);
  9354. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9355. putPaddrLow(dmabuf->phys);
  9356. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9357. putPaddrHigh(dmabuf->phys);
  9358. }
  9359. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9360. /* The IOCTL status is embedded in the mailbox subheader. */
  9361. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9362. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9363. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9364. if (shdr_status || shdr_add_status || rc) {
  9365. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9366. "2504 RQ_CREATE mailbox failed with "
  9367. "status x%x add_status x%x, mbx status x%x\n",
  9368. shdr_status, shdr_add_status, rc);
  9369. status = -ENXIO;
  9370. goto out;
  9371. }
  9372. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9373. if (hrq->queue_id == 0xFFFF) {
  9374. status = -ENXIO;
  9375. goto out;
  9376. }
  9377. hrq->type = LPFC_HRQ;
  9378. hrq->subtype = subtype;
  9379. hrq->host_index = 0;
  9380. hrq->hba_index = 0;
  9381. /* now create the data queue */
  9382. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9383. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9384. length, LPFC_SLI4_MBX_EMBED);
  9385. switch (drq->entry_count) {
  9386. default:
  9387. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9388. "2536 Unsupported RQ count. (%d)\n",
  9389. drq->entry_count);
  9390. if (drq->entry_count < 512)
  9391. return -EINVAL;
  9392. /* otherwise default to smallest count (drop through) */
  9393. case 512:
  9394. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9395. LPFC_RQ_RING_SIZE_512);
  9396. break;
  9397. case 1024:
  9398. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9399. LPFC_RQ_RING_SIZE_1024);
  9400. break;
  9401. case 2048:
  9402. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9403. LPFC_RQ_RING_SIZE_2048);
  9404. break;
  9405. case 4096:
  9406. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9407. LPFC_RQ_RING_SIZE_4096);
  9408. break;
  9409. }
  9410. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9411. cq->queue_id);
  9412. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9413. drq->page_count);
  9414. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9415. LPFC_DATA_BUF_SIZE);
  9416. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9417. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9418. putPaddrLow(dmabuf->phys);
  9419. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9420. putPaddrHigh(dmabuf->phys);
  9421. }
  9422. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9423. /* The IOCTL status is embedded in the mailbox subheader. */
  9424. shdr = (union lpfc_sli4_cfg_shdr *) &rq_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. status = -ENXIO;
  9429. goto out;
  9430. }
  9431. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9432. if (drq->queue_id == 0xFFFF) {
  9433. status = -ENXIO;
  9434. goto out;
  9435. }
  9436. drq->type = LPFC_DRQ;
  9437. drq->subtype = subtype;
  9438. drq->host_index = 0;
  9439. drq->hba_index = 0;
  9440. /* link the header and data RQs onto the parent cq child list */
  9441. list_add_tail(&hrq->list, &cq->child_list);
  9442. list_add_tail(&drq->list, &cq->child_list);
  9443. out:
  9444. mempool_free(mbox, phba->mbox_mem_pool);
  9445. return status;
  9446. }
  9447. /**
  9448. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9449. * @eq: The queue structure associated with the queue to destroy.
  9450. *
  9451. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9452. * command, specific to the type of queue, to the HBA.
  9453. *
  9454. * The @eq struct is used to get the queue ID of the queue to destroy.
  9455. *
  9456. * On success this function will return a zero. If the queue destroy mailbox
  9457. * command fails this function will return ENXIO.
  9458. **/
  9459. uint32_t
  9460. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9461. {
  9462. LPFC_MBOXQ_t *mbox;
  9463. int rc, length, status = 0;
  9464. uint32_t shdr_status, shdr_add_status;
  9465. union lpfc_sli4_cfg_shdr *shdr;
  9466. if (!eq)
  9467. return -ENODEV;
  9468. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9469. if (!mbox)
  9470. return -ENOMEM;
  9471. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9472. sizeof(struct lpfc_sli4_cfg_mhdr));
  9473. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9474. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9475. length, LPFC_SLI4_MBX_EMBED);
  9476. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9477. eq->queue_id);
  9478. mbox->vport = eq->phba->pport;
  9479. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9480. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9481. /* The IOCTL status is embedded in the mailbox subheader. */
  9482. shdr = (union lpfc_sli4_cfg_shdr *)
  9483. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9484. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9485. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9486. if (shdr_status || shdr_add_status || rc) {
  9487. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9488. "2505 EQ_DESTROY mailbox failed with "
  9489. "status x%x add_status x%x, mbx status x%x\n",
  9490. shdr_status, shdr_add_status, rc);
  9491. status = -ENXIO;
  9492. }
  9493. /* Remove eq from any list */
  9494. list_del_init(&eq->list);
  9495. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9496. return status;
  9497. }
  9498. /**
  9499. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9500. * @cq: The queue structure associated with the queue to destroy.
  9501. *
  9502. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9503. * command, specific to the type of queue, to the HBA.
  9504. *
  9505. * The @cq struct is used to get the queue ID of the queue to destroy.
  9506. *
  9507. * On success this function will return a zero. If the queue destroy mailbox
  9508. * command fails this function will return ENXIO.
  9509. **/
  9510. uint32_t
  9511. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9512. {
  9513. LPFC_MBOXQ_t *mbox;
  9514. int rc, length, status = 0;
  9515. uint32_t shdr_status, shdr_add_status;
  9516. union lpfc_sli4_cfg_shdr *shdr;
  9517. if (!cq)
  9518. return -ENODEV;
  9519. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9520. if (!mbox)
  9521. return -ENOMEM;
  9522. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9523. sizeof(struct lpfc_sli4_cfg_mhdr));
  9524. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9525. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9526. length, LPFC_SLI4_MBX_EMBED);
  9527. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9528. cq->queue_id);
  9529. mbox->vport = cq->phba->pport;
  9530. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9531. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9532. /* The IOCTL status is embedded in the mailbox subheader. */
  9533. shdr = (union lpfc_sli4_cfg_shdr *)
  9534. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9535. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9536. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9537. if (shdr_status || shdr_add_status || rc) {
  9538. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9539. "2506 CQ_DESTROY mailbox failed with "
  9540. "status x%x add_status x%x, mbx status x%x\n",
  9541. shdr_status, shdr_add_status, rc);
  9542. status = -ENXIO;
  9543. }
  9544. /* Remove cq from any list */
  9545. list_del_init(&cq->list);
  9546. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9547. return status;
  9548. }
  9549. /**
  9550. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9551. * @qm: The queue structure associated with the queue to destroy.
  9552. *
  9553. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9554. * command, specific to the type of queue, to the HBA.
  9555. *
  9556. * The @mq struct is used to get the queue ID of the queue to destroy.
  9557. *
  9558. * On success this function will return a zero. If the queue destroy mailbox
  9559. * command fails this function will return ENXIO.
  9560. **/
  9561. uint32_t
  9562. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9563. {
  9564. LPFC_MBOXQ_t *mbox;
  9565. int rc, length, status = 0;
  9566. uint32_t shdr_status, shdr_add_status;
  9567. union lpfc_sli4_cfg_shdr *shdr;
  9568. if (!mq)
  9569. return -ENODEV;
  9570. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9571. if (!mbox)
  9572. return -ENOMEM;
  9573. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9574. sizeof(struct lpfc_sli4_cfg_mhdr));
  9575. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9576. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9577. length, LPFC_SLI4_MBX_EMBED);
  9578. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9579. mq->queue_id);
  9580. mbox->vport = mq->phba->pport;
  9581. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9582. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9583. /* The IOCTL status is embedded in the mailbox subheader. */
  9584. shdr = (union lpfc_sli4_cfg_shdr *)
  9585. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9586. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9587. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9588. if (shdr_status || shdr_add_status || rc) {
  9589. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9590. "2507 MQ_DESTROY mailbox failed with "
  9591. "status x%x add_status x%x, mbx status x%x\n",
  9592. shdr_status, shdr_add_status, rc);
  9593. status = -ENXIO;
  9594. }
  9595. /* Remove mq from any list */
  9596. list_del_init(&mq->list);
  9597. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9598. return status;
  9599. }
  9600. /**
  9601. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9602. * @wq: The queue structure associated with the queue to destroy.
  9603. *
  9604. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9605. * command, specific to the type of queue, to the HBA.
  9606. *
  9607. * The @wq struct is used to get the queue ID of the queue to destroy.
  9608. *
  9609. * On success this function will return a zero. If the queue destroy mailbox
  9610. * command fails this function will return ENXIO.
  9611. **/
  9612. uint32_t
  9613. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9614. {
  9615. LPFC_MBOXQ_t *mbox;
  9616. int rc, length, status = 0;
  9617. uint32_t shdr_status, shdr_add_status;
  9618. union lpfc_sli4_cfg_shdr *shdr;
  9619. if (!wq)
  9620. return -ENODEV;
  9621. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9622. if (!mbox)
  9623. return -ENOMEM;
  9624. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9625. sizeof(struct lpfc_sli4_cfg_mhdr));
  9626. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9627. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9628. length, LPFC_SLI4_MBX_EMBED);
  9629. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9630. wq->queue_id);
  9631. mbox->vport = wq->phba->pport;
  9632. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9633. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9634. shdr = (union lpfc_sli4_cfg_shdr *)
  9635. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9636. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9637. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9638. if (shdr_status || shdr_add_status || rc) {
  9639. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9640. "2508 WQ_DESTROY mailbox failed with "
  9641. "status x%x add_status x%x, mbx status x%x\n",
  9642. shdr_status, shdr_add_status, rc);
  9643. status = -ENXIO;
  9644. }
  9645. /* Remove wq from any list */
  9646. list_del_init(&wq->list);
  9647. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9648. return status;
  9649. }
  9650. /**
  9651. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9652. * @rq: The queue structure associated with the queue to destroy.
  9653. *
  9654. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9655. * command, specific to the type of queue, to the HBA.
  9656. *
  9657. * The @rq struct is used to get the queue ID of the queue to destroy.
  9658. *
  9659. * On success this function will return a zero. If the queue destroy mailbox
  9660. * command fails this function will return ENXIO.
  9661. **/
  9662. uint32_t
  9663. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9664. struct lpfc_queue *drq)
  9665. {
  9666. LPFC_MBOXQ_t *mbox;
  9667. int rc, length, status = 0;
  9668. uint32_t shdr_status, shdr_add_status;
  9669. union lpfc_sli4_cfg_shdr *shdr;
  9670. if (!hrq || !drq)
  9671. return -ENODEV;
  9672. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9673. if (!mbox)
  9674. return -ENOMEM;
  9675. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9676. sizeof(struct mbox_header));
  9677. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9678. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9679. length, LPFC_SLI4_MBX_EMBED);
  9680. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9681. hrq->queue_id);
  9682. mbox->vport = hrq->phba->pport;
  9683. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9684. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9685. /* The IOCTL status is embedded in the mailbox subheader. */
  9686. shdr = (union lpfc_sli4_cfg_shdr *)
  9687. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9688. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9689. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9690. if (shdr_status || shdr_add_status || rc) {
  9691. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9692. "2509 RQ_DESTROY mailbox failed with "
  9693. "status x%x add_status x%x, mbx status x%x\n",
  9694. shdr_status, shdr_add_status, rc);
  9695. if (rc != MBX_TIMEOUT)
  9696. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9697. return -ENXIO;
  9698. }
  9699. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9700. drq->queue_id);
  9701. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9702. shdr = (union lpfc_sli4_cfg_shdr *)
  9703. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9704. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9705. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9706. if (shdr_status || shdr_add_status || rc) {
  9707. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9708. "2510 RQ_DESTROY mailbox failed with "
  9709. "status x%x add_status x%x, mbx status x%x\n",
  9710. shdr_status, shdr_add_status, rc);
  9711. status = -ENXIO;
  9712. }
  9713. list_del_init(&hrq->list);
  9714. list_del_init(&drq->list);
  9715. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9716. return status;
  9717. }
  9718. /**
  9719. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9720. * @phba: The virtual port for which this call being executed.
  9721. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9722. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9723. * @xritag: the xritag that ties this io to the SGL pages.
  9724. *
  9725. * This routine will post the sgl pages for the IO that has the xritag
  9726. * that is in the iocbq structure. The xritag is assigned during iocbq
  9727. * creation and persists for as long as the driver is loaded.
  9728. * if the caller has fewer than 256 scatter gather segments to map then
  9729. * pdma_phys_addr1 should be 0.
  9730. * If the caller needs to map more than 256 scatter gather segment then
  9731. * pdma_phys_addr1 should be a valid physical address.
  9732. * physical address for SGLs must be 64 byte aligned.
  9733. * If you are going to map 2 SGL's then the first one must have 256 entries
  9734. * the second sgl can have between 1 and 256 entries.
  9735. *
  9736. * Return codes:
  9737. * 0 - Success
  9738. * -ENXIO, -ENOMEM - Failure
  9739. **/
  9740. int
  9741. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9742. dma_addr_t pdma_phys_addr0,
  9743. dma_addr_t pdma_phys_addr1,
  9744. uint16_t xritag)
  9745. {
  9746. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9747. LPFC_MBOXQ_t *mbox;
  9748. int rc;
  9749. uint32_t shdr_status, shdr_add_status;
  9750. union lpfc_sli4_cfg_shdr *shdr;
  9751. if (xritag == NO_XRI) {
  9752. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9753. "0364 Invalid param:\n");
  9754. return -EINVAL;
  9755. }
  9756. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9757. if (!mbox)
  9758. return -ENOMEM;
  9759. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9760. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9761. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9762. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9763. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9764. &mbox->u.mqe.un.post_sgl_pages;
  9765. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9766. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9767. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9768. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9769. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9770. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9771. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9772. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9773. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9774. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9775. if (!phba->sli4_hba.intr_enable)
  9776. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9777. else
  9778. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9779. /* The IOCTL status is embedded in the mailbox subheader. */
  9780. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9781. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9782. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9783. if (rc != MBX_TIMEOUT)
  9784. mempool_free(mbox, phba->mbox_mem_pool);
  9785. if (shdr_status || shdr_add_status || rc) {
  9786. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9787. "2511 POST_SGL mailbox failed with "
  9788. "status x%x add_status x%x, mbx status x%x\n",
  9789. shdr_status, shdr_add_status, rc);
  9790. rc = -ENXIO;
  9791. }
  9792. return 0;
  9793. }
  9794. /**
  9795. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9796. * @phba: The virtual port for which this call being executed.
  9797. *
  9798. * This routine will remove all of the sgl pages registered with the hba.
  9799. *
  9800. * Return codes:
  9801. * 0 - Success
  9802. * -ENXIO, -ENOMEM - Failure
  9803. **/
  9804. int
  9805. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9806. {
  9807. LPFC_MBOXQ_t *mbox;
  9808. int rc;
  9809. uint32_t shdr_status, shdr_add_status;
  9810. union lpfc_sli4_cfg_shdr *shdr;
  9811. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9812. if (!mbox)
  9813. return -ENOMEM;
  9814. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9815. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9816. LPFC_SLI4_MBX_EMBED);
  9817. if (!phba->sli4_hba.intr_enable)
  9818. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9819. else
  9820. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9821. /* The IOCTL status is embedded in the mailbox subheader. */
  9822. shdr = (union lpfc_sli4_cfg_shdr *)
  9823. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9824. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9825. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9826. if (rc != MBX_TIMEOUT)
  9827. mempool_free(mbox, phba->mbox_mem_pool);
  9828. if (shdr_status || shdr_add_status || rc) {
  9829. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9830. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9831. "status x%x add_status x%x, mbx status x%x\n",
  9832. shdr_status, shdr_add_status, rc);
  9833. rc = -ENXIO;
  9834. }
  9835. return rc;
  9836. }
  9837. /**
  9838. * lpfc_sli4_next_xritag - Get an xritag for the io
  9839. * @phba: Pointer to HBA context object.
  9840. *
  9841. * This function gets an xritag for the iocb. If there is no unused xritag
  9842. * it will return 0xffff.
  9843. * The function returns the allocated xritag if successful, else returns zero.
  9844. * Zero is not a valid xritag.
  9845. * The caller is not required to hold any lock.
  9846. **/
  9847. uint16_t
  9848. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9849. {
  9850. uint16_t xritag;
  9851. spin_lock_irq(&phba->hbalock);
  9852. xritag = phba->sli4_hba.next_xri;
  9853. if ((xritag != (uint16_t) -1) && xritag <
  9854. (phba->sli4_hba.max_cfg_param.max_xri
  9855. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9856. phba->sli4_hba.next_xri++;
  9857. phba->sli4_hba.max_cfg_param.xri_used++;
  9858. spin_unlock_irq(&phba->hbalock);
  9859. return xritag;
  9860. }
  9861. spin_unlock_irq(&phba->hbalock);
  9862. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9863. "2004 Failed to allocate XRI.last XRITAG is %d"
  9864. " Max XRI is %d, Used XRI is %d\n",
  9865. phba->sli4_hba.next_xri,
  9866. phba->sli4_hba.max_cfg_param.max_xri,
  9867. phba->sli4_hba.max_cfg_param.xri_used);
  9868. return -1;
  9869. }
  9870. /**
  9871. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9872. * @phba: pointer to lpfc hba data structure.
  9873. *
  9874. * This routine is invoked to post a block of driver's sgl pages to the
  9875. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9876. * is only called when the driver is loading and after all IO has been
  9877. * stopped.
  9878. **/
  9879. int
  9880. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9881. {
  9882. struct lpfc_sglq *sglq_entry;
  9883. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9884. struct sgl_page_pairs *sgl_pg_pairs;
  9885. void *viraddr;
  9886. LPFC_MBOXQ_t *mbox;
  9887. uint32_t reqlen, alloclen, pg_pairs;
  9888. uint32_t mbox_tmo;
  9889. uint16_t xritag_start = 0;
  9890. int els_xri_cnt, rc = 0;
  9891. uint32_t shdr_status, shdr_add_status;
  9892. union lpfc_sli4_cfg_shdr *shdr;
  9893. /* The number of sgls to be posted */
  9894. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9895. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9896. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9897. if (reqlen > SLI4_PAGE_SIZE) {
  9898. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9899. "2559 Block sgl registration required DMA "
  9900. "size (%d) great than a page\n", reqlen);
  9901. return -ENOMEM;
  9902. }
  9903. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9904. if (!mbox) {
  9905. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9906. "2560 Failed to allocate mbox cmd memory\n");
  9907. return -ENOMEM;
  9908. }
  9909. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9910. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9911. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9912. LPFC_SLI4_MBX_NEMBED);
  9913. if (alloclen < reqlen) {
  9914. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9915. "0285 Allocated DMA memory size (%d) is "
  9916. "less than the requested DMA memory "
  9917. "size (%d)\n", alloclen, reqlen);
  9918. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9919. return -ENOMEM;
  9920. }
  9921. /* Get the first SGE entry from the non-embedded DMA memory */
  9922. viraddr = mbox->sge_array->addr[0];
  9923. /* Set up the SGL pages in the non-embedded DMA pages */
  9924. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9925. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9926. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9927. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9928. /* Set up the sge entry */
  9929. sgl_pg_pairs->sgl_pg0_addr_lo =
  9930. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9931. sgl_pg_pairs->sgl_pg0_addr_hi =
  9932. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9933. sgl_pg_pairs->sgl_pg1_addr_lo =
  9934. cpu_to_le32(putPaddrLow(0));
  9935. sgl_pg_pairs->sgl_pg1_addr_hi =
  9936. cpu_to_le32(putPaddrHigh(0));
  9937. /* Keep the first xritag on the list */
  9938. if (pg_pairs == 0)
  9939. xritag_start = sglq_entry->sli4_xritag;
  9940. sgl_pg_pairs++;
  9941. }
  9942. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9943. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9944. /* Perform endian conversion if necessary */
  9945. sgl->word0 = cpu_to_le32(sgl->word0);
  9946. if (!phba->sli4_hba.intr_enable)
  9947. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9948. else {
  9949. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9950. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9951. }
  9952. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9953. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9954. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9955. if (rc != MBX_TIMEOUT)
  9956. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9957. if (shdr_status || shdr_add_status || rc) {
  9958. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9959. "2513 POST_SGL_BLOCK mailbox command failed "
  9960. "status x%x add_status x%x mbx status x%x\n",
  9961. shdr_status, shdr_add_status, rc);
  9962. rc = -ENXIO;
  9963. }
  9964. return rc;
  9965. }
  9966. /**
  9967. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9968. * @phba: pointer to lpfc hba data structure.
  9969. * @sblist: pointer to scsi buffer list.
  9970. * @count: number of scsi buffers on the list.
  9971. *
  9972. * This routine is invoked to post a block of @count scsi sgl pages from a
  9973. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9974. * No Lock is held.
  9975. *
  9976. **/
  9977. int
  9978. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9979. int cnt)
  9980. {
  9981. struct lpfc_scsi_buf *psb;
  9982. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9983. struct sgl_page_pairs *sgl_pg_pairs;
  9984. void *viraddr;
  9985. LPFC_MBOXQ_t *mbox;
  9986. uint32_t reqlen, alloclen, pg_pairs;
  9987. uint32_t mbox_tmo;
  9988. uint16_t xritag_start = 0;
  9989. int rc = 0;
  9990. uint32_t shdr_status, shdr_add_status;
  9991. dma_addr_t pdma_phys_bpl1;
  9992. union lpfc_sli4_cfg_shdr *shdr;
  9993. /* Calculate the requested length of the dma memory */
  9994. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9995. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9996. if (reqlen > SLI4_PAGE_SIZE) {
  9997. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9998. "0217 Block sgl registration required DMA "
  9999. "size (%d) great than a page\n", reqlen);
  10000. return -ENOMEM;
  10001. }
  10002. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10003. if (!mbox) {
  10004. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10005. "0283 Failed to allocate mbox cmd memory\n");
  10006. return -ENOMEM;
  10007. }
  10008. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10009. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10010. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10011. LPFC_SLI4_MBX_NEMBED);
  10012. if (alloclen < reqlen) {
  10013. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10014. "2561 Allocated DMA memory size (%d) is "
  10015. "less than the requested DMA memory "
  10016. "size (%d)\n", alloclen, reqlen);
  10017. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10018. return -ENOMEM;
  10019. }
  10020. /* Get the first SGE entry from the non-embedded DMA memory */
  10021. viraddr = mbox->sge_array->addr[0];
  10022. /* Set up the SGL pages in the non-embedded DMA pages */
  10023. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10024. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10025. pg_pairs = 0;
  10026. list_for_each_entry(psb, sblist, list) {
  10027. /* Set up the sge entry */
  10028. sgl_pg_pairs->sgl_pg0_addr_lo =
  10029. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10030. sgl_pg_pairs->sgl_pg0_addr_hi =
  10031. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10032. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10033. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10034. else
  10035. pdma_phys_bpl1 = 0;
  10036. sgl_pg_pairs->sgl_pg1_addr_lo =
  10037. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10038. sgl_pg_pairs->sgl_pg1_addr_hi =
  10039. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10040. /* Keep the first xritag on the list */
  10041. if (pg_pairs == 0)
  10042. xritag_start = psb->cur_iocbq.sli4_xritag;
  10043. sgl_pg_pairs++;
  10044. pg_pairs++;
  10045. }
  10046. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10047. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10048. /* Perform endian conversion if necessary */
  10049. sgl->word0 = cpu_to_le32(sgl->word0);
  10050. if (!phba->sli4_hba.intr_enable)
  10051. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10052. else {
  10053. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10054. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10055. }
  10056. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10057. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10058. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10059. if (rc != MBX_TIMEOUT)
  10060. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10061. if (shdr_status || shdr_add_status || rc) {
  10062. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10063. "2564 POST_SGL_BLOCK mailbox command failed "
  10064. "status x%x add_status x%x mbx status x%x\n",
  10065. shdr_status, shdr_add_status, rc);
  10066. rc = -ENXIO;
  10067. }
  10068. return rc;
  10069. }
  10070. /**
  10071. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10072. * @phba: pointer to lpfc_hba struct that the frame was received on
  10073. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10074. *
  10075. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10076. * valid type of frame that the LPFC driver will handle. This function will
  10077. * return a zero if the frame is a valid frame or a non zero value when the
  10078. * frame does not pass the check.
  10079. **/
  10080. static int
  10081. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10082. {
  10083. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10084. char *type_names[] = FC_TYPE_NAMES_INIT;
  10085. struct fc_vft_header *fc_vft_hdr;
  10086. switch (fc_hdr->fh_r_ctl) {
  10087. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10088. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10089. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10090. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10091. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10092. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10093. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10094. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10095. case FC_RCTL_ELS_REQ: /* extended link services request */
  10096. case FC_RCTL_ELS_REP: /* extended link services reply */
  10097. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10098. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10099. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10100. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10101. case FC_RCTL_BA_RMC: /* remove connection */
  10102. case FC_RCTL_BA_ACC: /* basic accept */
  10103. case FC_RCTL_BA_RJT: /* basic reject */
  10104. case FC_RCTL_BA_PRMT:
  10105. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10106. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10107. case FC_RCTL_P_RJT: /* port reject */
  10108. case FC_RCTL_F_RJT: /* fabric reject */
  10109. case FC_RCTL_P_BSY: /* port busy */
  10110. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10111. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10112. case FC_RCTL_LCR: /* link credit reset */
  10113. case FC_RCTL_END: /* end */
  10114. break;
  10115. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10116. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10117. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10118. return lpfc_fc_frame_check(phba, fc_hdr);
  10119. default:
  10120. goto drop;
  10121. }
  10122. switch (fc_hdr->fh_type) {
  10123. case FC_TYPE_BLS:
  10124. case FC_TYPE_ELS:
  10125. case FC_TYPE_FCP:
  10126. case FC_TYPE_CT:
  10127. break;
  10128. case FC_TYPE_IP:
  10129. case FC_TYPE_ILS:
  10130. default:
  10131. goto drop;
  10132. }
  10133. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10134. "2538 Received frame rctl:%s type:%s\n",
  10135. rctl_names[fc_hdr->fh_r_ctl],
  10136. type_names[fc_hdr->fh_type]);
  10137. return 0;
  10138. drop:
  10139. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10140. "2539 Dropped frame rctl:%s type:%s\n",
  10141. rctl_names[fc_hdr->fh_r_ctl],
  10142. type_names[fc_hdr->fh_type]);
  10143. return 1;
  10144. }
  10145. /**
  10146. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10147. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10148. *
  10149. * This function processes the FC header to retrieve the VFI from the VF
  10150. * header, if one exists. This function will return the VFI if one exists
  10151. * or 0 if no VSAN Header exists.
  10152. **/
  10153. static uint32_t
  10154. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10155. {
  10156. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10157. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10158. return 0;
  10159. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10160. }
  10161. /**
  10162. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10163. * @phba: Pointer to the HBA structure to search for the vport on
  10164. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10165. * @fcfi: The FC Fabric ID that the frame came from
  10166. *
  10167. * This function searches the @phba for a vport that matches the content of the
  10168. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10169. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10170. * returns the matching vport pointer or NULL if unable to match frame to a
  10171. * vport.
  10172. **/
  10173. static struct lpfc_vport *
  10174. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10175. uint16_t fcfi)
  10176. {
  10177. struct lpfc_vport **vports;
  10178. struct lpfc_vport *vport = NULL;
  10179. int i;
  10180. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10181. fc_hdr->fh_d_id[1] << 8 |
  10182. fc_hdr->fh_d_id[2]);
  10183. vports = lpfc_create_vport_work_array(phba);
  10184. if (vports != NULL)
  10185. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10186. if (phba->fcf.fcfi == fcfi &&
  10187. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10188. vports[i]->fc_myDID == did) {
  10189. vport = vports[i];
  10190. break;
  10191. }
  10192. }
  10193. lpfc_destroy_vport_work_array(phba, vports);
  10194. return vport;
  10195. }
  10196. /**
  10197. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10198. * @vport: The vport to work on.
  10199. *
  10200. * This function updates the receive sequence time stamp for this vport. The
  10201. * receive sequence time stamp indicates the time that the last frame of the
  10202. * the sequence that has been idle for the longest amount of time was received.
  10203. * the driver uses this time stamp to indicate if any received sequences have
  10204. * timed out.
  10205. **/
  10206. void
  10207. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10208. {
  10209. struct lpfc_dmabuf *h_buf;
  10210. struct hbq_dmabuf *dmabuf = NULL;
  10211. /* get the oldest sequence on the rcv list */
  10212. h_buf = list_get_first(&vport->rcv_buffer_list,
  10213. struct lpfc_dmabuf, list);
  10214. if (!h_buf)
  10215. return;
  10216. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10217. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10218. }
  10219. /**
  10220. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10221. * @vport: The vport that the received sequences were sent to.
  10222. *
  10223. * This function cleans up all outstanding received sequences. This is called
  10224. * by the driver when a link event or user action invalidates all the received
  10225. * sequences.
  10226. **/
  10227. void
  10228. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10229. {
  10230. struct lpfc_dmabuf *h_buf, *hnext;
  10231. struct lpfc_dmabuf *d_buf, *dnext;
  10232. struct hbq_dmabuf *dmabuf = NULL;
  10233. /* start with the oldest sequence on the rcv list */
  10234. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10235. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10236. list_del_init(&dmabuf->hbuf.list);
  10237. list_for_each_entry_safe(d_buf, dnext,
  10238. &dmabuf->dbuf.list, list) {
  10239. list_del_init(&d_buf->list);
  10240. lpfc_in_buf_free(vport->phba, d_buf);
  10241. }
  10242. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10243. }
  10244. }
  10245. /**
  10246. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10247. * @vport: The vport that the received sequences were sent to.
  10248. *
  10249. * This function determines whether any received sequences have timed out by
  10250. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10251. * indicates that there is at least one timed out sequence this routine will
  10252. * go through the received sequences one at a time from most inactive to most
  10253. * active to determine which ones need to be cleaned up. Once it has determined
  10254. * that a sequence needs to be cleaned up it will simply free up the resources
  10255. * without sending an abort.
  10256. **/
  10257. void
  10258. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10259. {
  10260. struct lpfc_dmabuf *h_buf, *hnext;
  10261. struct lpfc_dmabuf *d_buf, *dnext;
  10262. struct hbq_dmabuf *dmabuf = NULL;
  10263. unsigned long timeout;
  10264. int abort_count = 0;
  10265. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10266. vport->rcv_buffer_time_stamp);
  10267. if (list_empty(&vport->rcv_buffer_list) ||
  10268. time_before(jiffies, timeout))
  10269. return;
  10270. /* start with the oldest sequence on the rcv list */
  10271. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10272. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10273. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10274. dmabuf->time_stamp);
  10275. if (time_before(jiffies, timeout))
  10276. break;
  10277. abort_count++;
  10278. list_del_init(&dmabuf->hbuf.list);
  10279. list_for_each_entry_safe(d_buf, dnext,
  10280. &dmabuf->dbuf.list, list) {
  10281. list_del_init(&d_buf->list);
  10282. lpfc_in_buf_free(vport->phba, d_buf);
  10283. }
  10284. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10285. }
  10286. if (abort_count)
  10287. lpfc_update_rcv_time_stamp(vport);
  10288. }
  10289. /**
  10290. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10291. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10292. *
  10293. * This function searches through the existing incomplete sequences that have
  10294. * been sent to this @vport. If the frame matches one of the incomplete
  10295. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10296. * make up that sequence. If no sequence is found that matches this frame then
  10297. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10298. * This function returns a pointer to the first dmabuf in the sequence list that
  10299. * the frame was linked to.
  10300. **/
  10301. static struct hbq_dmabuf *
  10302. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10303. {
  10304. struct fc_frame_header *new_hdr;
  10305. struct fc_frame_header *temp_hdr;
  10306. struct lpfc_dmabuf *d_buf;
  10307. struct lpfc_dmabuf *h_buf;
  10308. struct hbq_dmabuf *seq_dmabuf = NULL;
  10309. struct hbq_dmabuf *temp_dmabuf = NULL;
  10310. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10311. dmabuf->time_stamp = jiffies;
  10312. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10313. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10314. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10315. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10316. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10317. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10318. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10319. continue;
  10320. /* found a pending sequence that matches this frame */
  10321. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10322. break;
  10323. }
  10324. if (!seq_dmabuf) {
  10325. /*
  10326. * This indicates first frame received for this sequence.
  10327. * Queue the buffer on the vport's rcv_buffer_list.
  10328. */
  10329. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10330. lpfc_update_rcv_time_stamp(vport);
  10331. return dmabuf;
  10332. }
  10333. temp_hdr = seq_dmabuf->hbuf.virt;
  10334. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10335. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10336. list_del_init(&seq_dmabuf->hbuf.list);
  10337. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10338. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10339. lpfc_update_rcv_time_stamp(vport);
  10340. return dmabuf;
  10341. }
  10342. /* move this sequence to the tail to indicate a young sequence */
  10343. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10344. seq_dmabuf->time_stamp = jiffies;
  10345. lpfc_update_rcv_time_stamp(vport);
  10346. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10347. temp_hdr = dmabuf->hbuf.virt;
  10348. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10349. return seq_dmabuf;
  10350. }
  10351. /* find the correct place in the sequence to insert this frame */
  10352. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10353. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10354. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10355. /*
  10356. * If the frame's sequence count is greater than the frame on
  10357. * the list then insert the frame right after this frame
  10358. */
  10359. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10360. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10361. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10362. return seq_dmabuf;
  10363. }
  10364. }
  10365. return NULL;
  10366. }
  10367. /**
  10368. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10369. * @vport: pointer to a vitural port
  10370. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10371. *
  10372. * This function tries to abort from the partially assembed sequence, described
  10373. * by the information from basic abbort @dmabuf. It checks to see whether such
  10374. * partially assembled sequence held by the driver. If so, it shall free up all
  10375. * the frames from the partially assembled sequence.
  10376. *
  10377. * Return
  10378. * true -- if there is matching partially assembled sequence present and all
  10379. * the frames freed with the sequence;
  10380. * false -- if there is no matching partially assembled sequence present so
  10381. * nothing got aborted in the lower layer driver
  10382. **/
  10383. static bool
  10384. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10385. struct hbq_dmabuf *dmabuf)
  10386. {
  10387. struct fc_frame_header *new_hdr;
  10388. struct fc_frame_header *temp_hdr;
  10389. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10390. struct hbq_dmabuf *seq_dmabuf = NULL;
  10391. /* Use the hdr_buf to find the sequence that matches this frame */
  10392. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10393. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10394. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10395. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10396. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10397. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10398. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10399. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10400. continue;
  10401. /* found a pending sequence that matches this frame */
  10402. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10403. break;
  10404. }
  10405. /* Free up all the frames from the partially assembled sequence */
  10406. if (seq_dmabuf) {
  10407. list_for_each_entry_safe(d_buf, n_buf,
  10408. &seq_dmabuf->dbuf.list, list) {
  10409. list_del_init(&d_buf->list);
  10410. lpfc_in_buf_free(vport->phba, d_buf);
  10411. }
  10412. return true;
  10413. }
  10414. return false;
  10415. }
  10416. /**
  10417. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10418. * @phba: Pointer to HBA context object.
  10419. * @cmd_iocbq: pointer to the command iocbq structure.
  10420. * @rsp_iocbq: pointer to the response iocbq structure.
  10421. *
  10422. * This function handles the sequence abort accept iocb command complete
  10423. * event. It properly releases the memory allocated to the sequence abort
  10424. * accept iocb.
  10425. **/
  10426. static void
  10427. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10428. struct lpfc_iocbq *cmd_iocbq,
  10429. struct lpfc_iocbq *rsp_iocbq)
  10430. {
  10431. if (cmd_iocbq)
  10432. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10433. }
  10434. /**
  10435. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10436. * @phba: Pointer to HBA context object.
  10437. * @fc_hdr: pointer to a FC frame header.
  10438. *
  10439. * This function sends a basic accept to a previous unsol sequence abort
  10440. * event after aborting the sequence handling.
  10441. **/
  10442. static void
  10443. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10444. struct fc_frame_header *fc_hdr)
  10445. {
  10446. struct lpfc_iocbq *ctiocb = NULL;
  10447. struct lpfc_nodelist *ndlp;
  10448. uint16_t oxid, rxid;
  10449. uint32_t sid, fctl;
  10450. IOCB_t *icmd;
  10451. if (!lpfc_is_link_up(phba))
  10452. return;
  10453. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10454. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10455. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10456. ndlp = lpfc_findnode_did(phba->pport, sid);
  10457. if (!ndlp) {
  10458. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10459. "1268 Find ndlp returned NULL for oxid:x%x "
  10460. "SID:x%x\n", oxid, sid);
  10461. return;
  10462. }
  10463. /* Allocate buffer for acc iocb */
  10464. ctiocb = lpfc_sli_get_iocbq(phba);
  10465. if (!ctiocb)
  10466. return;
  10467. /* Extract the F_CTL field from FC_HDR */
  10468. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10469. icmd = &ctiocb->iocb;
  10470. icmd->un.xseq64.bdl.bdeSize = 0;
  10471. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10472. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10473. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10474. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10475. /* Fill in the rest of iocb fields */
  10476. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10477. icmd->ulpBdeCount = 0;
  10478. icmd->ulpLe = 1;
  10479. icmd->ulpClass = CLASS3;
  10480. icmd->ulpContext = ndlp->nlp_rpi;
  10481. ctiocb->iocb_cmpl = NULL;
  10482. ctiocb->vport = phba->pport;
  10483. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10484. if (fctl & FC_FC_EX_CTX) {
  10485. /* ABTS sent by responder to CT exchange, construction
  10486. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10487. * field and RX_ID from ABTS for RX_ID field.
  10488. */
  10489. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10490. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10491. ctiocb->sli4_xritag = oxid;
  10492. } else {
  10493. /* ABTS sent by initiator to CT exchange, construction
  10494. * of BA_ACC will need to allocate a new XRI as for the
  10495. * XRI_TAG and RX_ID fields.
  10496. */
  10497. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10498. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10499. ctiocb->sli4_xritag = NO_XRI;
  10500. }
  10501. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10502. /* Xmit CT abts accept on exchange <xid> */
  10503. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10504. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10505. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10506. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10507. }
  10508. /**
  10509. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10510. * @vport: Pointer to the vport on which this sequence was received
  10511. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10512. *
  10513. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10514. * receive sequence is only partially assembed by the driver, it shall abort
  10515. * the partially assembled frames for the sequence. Otherwise, if the
  10516. * unsolicited receive sequence has been completely assembled and passed to
  10517. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10518. * unsolicited sequence has been aborted. After that, it will issue a basic
  10519. * accept to accept the abort.
  10520. **/
  10521. void
  10522. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10523. struct hbq_dmabuf *dmabuf)
  10524. {
  10525. struct lpfc_hba *phba = vport->phba;
  10526. struct fc_frame_header fc_hdr;
  10527. uint32_t fctl;
  10528. bool abts_par;
  10529. /* Make a copy of fc_hdr before the dmabuf being released */
  10530. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10531. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10532. if (fctl & FC_FC_EX_CTX) {
  10533. /*
  10534. * ABTS sent by responder to exchange, just free the buffer
  10535. */
  10536. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10537. } else {
  10538. /*
  10539. * ABTS sent by initiator to exchange, need to do cleanup
  10540. */
  10541. /* Try to abort partially assembled seq */
  10542. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10543. /* Send abort to ULP if partially seq abort failed */
  10544. if (abts_par == false)
  10545. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10546. else
  10547. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10548. }
  10549. /* Send basic accept (BA_ACC) to the abort requester */
  10550. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10551. }
  10552. /**
  10553. * lpfc_seq_complete - Indicates if a sequence is complete
  10554. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10555. *
  10556. * This function checks the sequence, starting with the frame described by
  10557. * @dmabuf, to see if all the frames associated with this sequence are present.
  10558. * the frames associated with this sequence are linked to the @dmabuf using the
  10559. * dbuf list. This function looks for two major things. 1) That the first frame
  10560. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10561. * set. 3) That there are no holes in the sequence count. The function will
  10562. * return 1 when the sequence is complete, otherwise it will return 0.
  10563. **/
  10564. static int
  10565. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10566. {
  10567. struct fc_frame_header *hdr;
  10568. struct lpfc_dmabuf *d_buf;
  10569. struct hbq_dmabuf *seq_dmabuf;
  10570. uint32_t fctl;
  10571. int seq_count = 0;
  10572. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10573. /* make sure first fame of sequence has a sequence count of zero */
  10574. if (hdr->fh_seq_cnt != seq_count)
  10575. return 0;
  10576. fctl = (hdr->fh_f_ctl[0] << 16 |
  10577. hdr->fh_f_ctl[1] << 8 |
  10578. hdr->fh_f_ctl[2]);
  10579. /* If last frame of sequence we can return success. */
  10580. if (fctl & FC_FC_END_SEQ)
  10581. return 1;
  10582. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10583. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10584. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10585. /* If there is a hole in the sequence count then fail. */
  10586. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10587. return 0;
  10588. fctl = (hdr->fh_f_ctl[0] << 16 |
  10589. hdr->fh_f_ctl[1] << 8 |
  10590. hdr->fh_f_ctl[2]);
  10591. /* If last frame of sequence we can return success. */
  10592. if (fctl & FC_FC_END_SEQ)
  10593. return 1;
  10594. }
  10595. return 0;
  10596. }
  10597. /**
  10598. * lpfc_prep_seq - Prep sequence for ULP processing
  10599. * @vport: Pointer to the vport on which this sequence was received
  10600. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10601. *
  10602. * This function takes a sequence, described by a list of frames, and creates
  10603. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10604. * used to issue to the generic unsolicited sequence handler. This routine
  10605. * returns a pointer to the first iocbq in the list. If the function is unable
  10606. * to allocate an iocbq then it throw out the received frames that were not
  10607. * able to be described and return a pointer to the first iocbq. If unable to
  10608. * allocate any iocbqs (including the first) this function will return NULL.
  10609. **/
  10610. static struct lpfc_iocbq *
  10611. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10612. {
  10613. struct lpfc_dmabuf *d_buf, *n_buf;
  10614. struct lpfc_iocbq *first_iocbq, *iocbq;
  10615. struct fc_frame_header *fc_hdr;
  10616. uint32_t sid;
  10617. struct ulp_bde64 *pbde;
  10618. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10619. /* remove from receive buffer list */
  10620. list_del_init(&seq_dmabuf->hbuf.list);
  10621. lpfc_update_rcv_time_stamp(vport);
  10622. /* get the Remote Port's SID */
  10623. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10624. /* Get an iocbq struct to fill in. */
  10625. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10626. if (first_iocbq) {
  10627. /* Initialize the first IOCB. */
  10628. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10629. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10630. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10631. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10632. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10633. vport->vpi + vport->phba->vpi_base;
  10634. /* put the first buffer into the first IOCBq */
  10635. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10636. first_iocbq->context3 = NULL;
  10637. first_iocbq->iocb.ulpBdeCount = 1;
  10638. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10639. LPFC_DATA_BUF_SIZE;
  10640. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10641. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10642. bf_get(lpfc_rcqe_length,
  10643. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10644. }
  10645. iocbq = first_iocbq;
  10646. /*
  10647. * Each IOCBq can have two Buffers assigned, so go through the list
  10648. * of buffers for this sequence and save two buffers in each IOCBq
  10649. */
  10650. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10651. if (!iocbq) {
  10652. lpfc_in_buf_free(vport->phba, d_buf);
  10653. continue;
  10654. }
  10655. if (!iocbq->context3) {
  10656. iocbq->context3 = d_buf;
  10657. iocbq->iocb.ulpBdeCount++;
  10658. pbde = (struct ulp_bde64 *)
  10659. &iocbq->iocb.unsli3.sli3Words[4];
  10660. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10661. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10662. bf_get(lpfc_rcqe_length,
  10663. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10664. } else {
  10665. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10666. if (!iocbq) {
  10667. if (first_iocbq) {
  10668. first_iocbq->iocb.ulpStatus =
  10669. IOSTAT_FCP_RSP_ERROR;
  10670. first_iocbq->iocb.un.ulpWord[4] =
  10671. IOERR_NO_RESOURCES;
  10672. }
  10673. lpfc_in_buf_free(vport->phba, d_buf);
  10674. continue;
  10675. }
  10676. iocbq->context2 = d_buf;
  10677. iocbq->context3 = NULL;
  10678. iocbq->iocb.ulpBdeCount = 1;
  10679. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10680. LPFC_DATA_BUF_SIZE;
  10681. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10682. bf_get(lpfc_rcqe_length,
  10683. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10684. iocbq->iocb.un.rcvels.remoteID = sid;
  10685. list_add_tail(&iocbq->list, &first_iocbq->list);
  10686. }
  10687. }
  10688. return first_iocbq;
  10689. }
  10690. static void
  10691. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10692. struct hbq_dmabuf *seq_dmabuf)
  10693. {
  10694. struct fc_frame_header *fc_hdr;
  10695. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10696. struct lpfc_hba *phba = vport->phba;
  10697. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10698. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10699. if (!iocbq) {
  10700. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10701. "2707 Ring %d handler: Failed to allocate "
  10702. "iocb Rctl x%x Type x%x received\n",
  10703. LPFC_ELS_RING,
  10704. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10705. return;
  10706. }
  10707. if (!lpfc_complete_unsol_iocb(phba,
  10708. &phba->sli.ring[LPFC_ELS_RING],
  10709. iocbq, fc_hdr->fh_r_ctl,
  10710. fc_hdr->fh_type))
  10711. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10712. "2540 Ring %d handler: unexpected Rctl "
  10713. "x%x Type x%x received\n",
  10714. LPFC_ELS_RING,
  10715. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10716. /* Free iocb created in lpfc_prep_seq */
  10717. list_for_each_entry_safe(curr_iocb, next_iocb,
  10718. &iocbq->list, list) {
  10719. list_del_init(&curr_iocb->list);
  10720. lpfc_sli_release_iocbq(phba, curr_iocb);
  10721. }
  10722. lpfc_sli_release_iocbq(phba, iocbq);
  10723. }
  10724. /**
  10725. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10726. * @phba: Pointer to HBA context object.
  10727. *
  10728. * This function is called with no lock held. This function processes all
  10729. * the received buffers and gives it to upper layers when a received buffer
  10730. * indicates that it is the final frame in the sequence. The interrupt
  10731. * service routine processes received buffers at interrupt contexts and adds
  10732. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10733. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10734. * appropriate receive function when the final frame in a sequence is received.
  10735. **/
  10736. void
  10737. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10738. struct hbq_dmabuf *dmabuf)
  10739. {
  10740. struct hbq_dmabuf *seq_dmabuf;
  10741. struct fc_frame_header *fc_hdr;
  10742. struct lpfc_vport *vport;
  10743. uint32_t fcfi;
  10744. /* Process each received buffer */
  10745. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10746. /* check to see if this a valid type of frame */
  10747. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10748. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10749. return;
  10750. }
  10751. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10752. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10753. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10754. /* throw out the frame */
  10755. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10756. return;
  10757. }
  10758. /* Handle the basic abort sequence (BA_ABTS) event */
  10759. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10760. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10761. return;
  10762. }
  10763. /* Link this frame */
  10764. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10765. if (!seq_dmabuf) {
  10766. /* unable to add frame to vport - throw it out */
  10767. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10768. return;
  10769. }
  10770. /* If not last frame in sequence continue processing frames. */
  10771. if (!lpfc_seq_complete(seq_dmabuf))
  10772. return;
  10773. /* Send the complete sequence to the upper layer protocol */
  10774. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10775. }
  10776. /**
  10777. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10778. * @phba: pointer to lpfc hba data structure.
  10779. *
  10780. * This routine is invoked to post rpi header templates to the
  10781. * HBA consistent with the SLI-4 interface spec. This routine
  10782. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10783. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10784. *
  10785. * This routine does not require any locks. It's usage is expected
  10786. * to be driver load or reset recovery when the driver is
  10787. * sequential.
  10788. *
  10789. * Return codes
  10790. * 0 - successful
  10791. * EIO - The mailbox failed to complete successfully.
  10792. * When this error occurs, the driver is not guaranteed
  10793. * to have any rpi regions posted to the device and
  10794. * must either attempt to repost the regions or take a
  10795. * fatal error.
  10796. **/
  10797. int
  10798. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10799. {
  10800. struct lpfc_rpi_hdr *rpi_page;
  10801. uint32_t rc = 0;
  10802. /* Post all rpi memory regions to the port. */
  10803. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10804. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10805. if (rc != MBX_SUCCESS) {
  10806. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10807. "2008 Error %d posting all rpi "
  10808. "headers\n", rc);
  10809. rc = -EIO;
  10810. break;
  10811. }
  10812. }
  10813. return rc;
  10814. }
  10815. /**
  10816. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10817. * @phba: pointer to lpfc hba data structure.
  10818. * @rpi_page: pointer to the rpi memory region.
  10819. *
  10820. * This routine is invoked to post a single rpi header to the
  10821. * HBA consistent with the SLI-4 interface spec. This memory region
  10822. * maps up to 64 rpi context regions.
  10823. *
  10824. * Return codes
  10825. * 0 - successful
  10826. * ENOMEM - No available memory
  10827. * EIO - The mailbox failed to complete successfully.
  10828. **/
  10829. int
  10830. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10831. {
  10832. LPFC_MBOXQ_t *mboxq;
  10833. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10834. uint32_t rc = 0;
  10835. uint32_t mbox_tmo;
  10836. uint32_t shdr_status, shdr_add_status;
  10837. union lpfc_sli4_cfg_shdr *shdr;
  10838. /* The port is notified of the header region via a mailbox command. */
  10839. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10840. if (!mboxq) {
  10841. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10842. "2001 Unable to allocate memory for issuing "
  10843. "SLI_CONFIG_SPECIAL mailbox command\n");
  10844. return -ENOMEM;
  10845. }
  10846. /* Post all rpi memory regions to the port. */
  10847. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10848. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10849. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10850. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10851. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10852. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10853. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10854. hdr_tmpl, rpi_page->page_count);
  10855. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10856. rpi_page->start_rpi);
  10857. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10858. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10859. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10860. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10861. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10862. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10863. if (rc != MBX_TIMEOUT)
  10864. mempool_free(mboxq, phba->mbox_mem_pool);
  10865. if (shdr_status || shdr_add_status || rc) {
  10866. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10867. "2514 POST_RPI_HDR mailbox failed with "
  10868. "status x%x add_status x%x, mbx status x%x\n",
  10869. shdr_status, shdr_add_status, rc);
  10870. rc = -ENXIO;
  10871. }
  10872. return rc;
  10873. }
  10874. /**
  10875. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10876. * @phba: pointer to lpfc hba data structure.
  10877. *
  10878. * This routine is invoked to post rpi header templates to the
  10879. * HBA consistent with the SLI-4 interface spec. This routine
  10880. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10881. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10882. *
  10883. * Returns
  10884. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10885. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10886. **/
  10887. int
  10888. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10889. {
  10890. int rpi;
  10891. uint16_t max_rpi, rpi_base, rpi_limit;
  10892. uint16_t rpi_remaining;
  10893. struct lpfc_rpi_hdr *rpi_hdr;
  10894. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10895. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10896. rpi_limit = phba->sli4_hba.next_rpi;
  10897. /*
  10898. * The valid rpi range is not guaranteed to be zero-based. Start
  10899. * the search at the rpi_base as reported by the port.
  10900. */
  10901. spin_lock_irq(&phba->hbalock);
  10902. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10903. if (rpi >= rpi_limit || rpi < rpi_base)
  10904. rpi = LPFC_RPI_ALLOC_ERROR;
  10905. else {
  10906. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10907. phba->sli4_hba.max_cfg_param.rpi_used++;
  10908. phba->sli4_hba.rpi_count++;
  10909. }
  10910. /*
  10911. * Don't try to allocate more rpi header regions if the device limit
  10912. * on available rpis max has been exhausted.
  10913. */
  10914. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10915. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10916. spin_unlock_irq(&phba->hbalock);
  10917. return rpi;
  10918. }
  10919. /*
  10920. * If the driver is running low on rpi resources, allocate another
  10921. * page now. Note that the next_rpi value is used because
  10922. * it represents how many are actually in use whereas max_rpi notes
  10923. * how many are supported max by the device.
  10924. */
  10925. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10926. phba->sli4_hba.rpi_count;
  10927. spin_unlock_irq(&phba->hbalock);
  10928. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10929. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10930. if (!rpi_hdr) {
  10931. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10932. "2002 Error Could not grow rpi "
  10933. "count\n");
  10934. } else {
  10935. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10936. }
  10937. }
  10938. return rpi;
  10939. }
  10940. /**
  10941. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10942. * @phba: pointer to lpfc hba data structure.
  10943. *
  10944. * This routine is invoked to release an rpi to the pool of
  10945. * available rpis maintained by the driver.
  10946. **/
  10947. void
  10948. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10949. {
  10950. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  10951. phba->sli4_hba.rpi_count--;
  10952. phba->sli4_hba.max_cfg_param.rpi_used--;
  10953. }
  10954. }
  10955. /**
  10956. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10957. * @phba: pointer to lpfc hba data structure.
  10958. *
  10959. * This routine is invoked to release an rpi to the pool of
  10960. * available rpis maintained by the driver.
  10961. **/
  10962. void
  10963. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10964. {
  10965. spin_lock_irq(&phba->hbalock);
  10966. __lpfc_sli4_free_rpi(phba, rpi);
  10967. spin_unlock_irq(&phba->hbalock);
  10968. }
  10969. /**
  10970. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10971. * @phba: pointer to lpfc hba data structure.
  10972. *
  10973. * This routine is invoked to remove the memory region that
  10974. * provided rpi via a bitmask.
  10975. **/
  10976. void
  10977. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10978. {
  10979. kfree(phba->sli4_hba.rpi_bmask);
  10980. }
  10981. /**
  10982. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10983. * @phba: pointer to lpfc hba data structure.
  10984. *
  10985. * This routine is invoked to remove the memory region that
  10986. * provided rpi via a bitmask.
  10987. **/
  10988. int
  10989. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10990. {
  10991. LPFC_MBOXQ_t *mboxq;
  10992. struct lpfc_hba *phba = ndlp->phba;
  10993. int rc;
  10994. /* The port is notified of the header region via a mailbox command. */
  10995. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10996. if (!mboxq)
  10997. return -ENOMEM;
  10998. /* Post all rpi memory regions to the port. */
  10999. lpfc_resume_rpi(mboxq, ndlp);
  11000. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11001. if (rc == MBX_NOT_FINISHED) {
  11002. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11003. "2010 Resume RPI Mailbox failed "
  11004. "status %d, mbxStatus x%x\n", rc,
  11005. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11006. mempool_free(mboxq, phba->mbox_mem_pool);
  11007. return -EIO;
  11008. }
  11009. return 0;
  11010. }
  11011. /**
  11012. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11013. * @phba: pointer to lpfc hba data structure.
  11014. * @vpi: vpi value to activate with the port.
  11015. *
  11016. * This routine is invoked to activate a vpi with the
  11017. * port when the host intends to use vports with a
  11018. * nonzero vpi.
  11019. *
  11020. * Returns:
  11021. * 0 success
  11022. * -Evalue otherwise
  11023. **/
  11024. int
  11025. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  11026. {
  11027. LPFC_MBOXQ_t *mboxq;
  11028. int rc = 0;
  11029. int retval = MBX_SUCCESS;
  11030. uint32_t mbox_tmo;
  11031. if (vpi == 0)
  11032. return -EINVAL;
  11033. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11034. if (!mboxq)
  11035. return -ENOMEM;
  11036. lpfc_init_vpi(phba, mboxq, vpi);
  11037. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11038. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11039. if (rc != MBX_SUCCESS) {
  11040. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11041. "2022 INIT VPI Mailbox failed "
  11042. "status %d, mbxStatus x%x\n", rc,
  11043. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11044. retval = -EIO;
  11045. }
  11046. if (rc != MBX_TIMEOUT)
  11047. mempool_free(mboxq, phba->mbox_mem_pool);
  11048. return retval;
  11049. }
  11050. /**
  11051. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11052. * @phba: pointer to lpfc hba data structure.
  11053. * @mboxq: Pointer to mailbox object.
  11054. *
  11055. * This routine is invoked to manually add a single FCF record. The caller
  11056. * must pass a completely initialized FCF_Record. This routine takes
  11057. * care of the nonembedded mailbox operations.
  11058. **/
  11059. static void
  11060. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11061. {
  11062. void *virt_addr;
  11063. union lpfc_sli4_cfg_shdr *shdr;
  11064. uint32_t shdr_status, shdr_add_status;
  11065. virt_addr = mboxq->sge_array->addr[0];
  11066. /* The IOCTL status is embedded in the mailbox subheader. */
  11067. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11068. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11069. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11070. if ((shdr_status || shdr_add_status) &&
  11071. (shdr_status != STATUS_FCF_IN_USE))
  11072. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11073. "2558 ADD_FCF_RECORD mailbox failed with "
  11074. "status x%x add_status x%x\n",
  11075. shdr_status, shdr_add_status);
  11076. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11077. }
  11078. /**
  11079. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11080. * @phba: pointer to lpfc hba data structure.
  11081. * @fcf_record: pointer to the initialized fcf record to add.
  11082. *
  11083. * This routine is invoked to manually add a single FCF record. The caller
  11084. * must pass a completely initialized FCF_Record. This routine takes
  11085. * care of the nonembedded mailbox operations.
  11086. **/
  11087. int
  11088. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11089. {
  11090. int rc = 0;
  11091. LPFC_MBOXQ_t *mboxq;
  11092. uint8_t *bytep;
  11093. void *virt_addr;
  11094. dma_addr_t phys_addr;
  11095. struct lpfc_mbx_sge sge;
  11096. uint32_t alloc_len, req_len;
  11097. uint32_t fcfindex;
  11098. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11099. if (!mboxq) {
  11100. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11101. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11102. return -ENOMEM;
  11103. }
  11104. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11105. sizeof(uint32_t);
  11106. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11107. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11108. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11109. req_len, LPFC_SLI4_MBX_NEMBED);
  11110. if (alloc_len < req_len) {
  11111. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11112. "2523 Allocated DMA memory size (x%x) is "
  11113. "less than the requested DMA memory "
  11114. "size (x%x)\n", alloc_len, req_len);
  11115. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11116. return -ENOMEM;
  11117. }
  11118. /*
  11119. * Get the first SGE entry from the non-embedded DMA memory. This
  11120. * routine only uses a single SGE.
  11121. */
  11122. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11123. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11124. virt_addr = mboxq->sge_array->addr[0];
  11125. /*
  11126. * Configure the FCF record for FCFI 0. This is the driver's
  11127. * hardcoded default and gets used in nonFIP mode.
  11128. */
  11129. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11130. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11131. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11132. /*
  11133. * Copy the fcf_index and the FCF Record Data. The data starts after
  11134. * the FCoE header plus word10. The data copy needs to be endian
  11135. * correct.
  11136. */
  11137. bytep += sizeof(uint32_t);
  11138. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11139. mboxq->vport = phba->pport;
  11140. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11141. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11142. if (rc == MBX_NOT_FINISHED) {
  11143. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11144. "2515 ADD_FCF_RECORD mailbox failed with "
  11145. "status 0x%x\n", rc);
  11146. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11147. rc = -EIO;
  11148. } else
  11149. rc = 0;
  11150. return rc;
  11151. }
  11152. /**
  11153. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11154. * @phba: pointer to lpfc hba data structure.
  11155. * @fcf_record: pointer to the fcf record to write the default data.
  11156. * @fcf_index: FCF table entry index.
  11157. *
  11158. * This routine is invoked to build the driver's default FCF record. The
  11159. * values used are hardcoded. This routine handles memory initialization.
  11160. *
  11161. **/
  11162. void
  11163. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11164. struct fcf_record *fcf_record,
  11165. uint16_t fcf_index)
  11166. {
  11167. memset(fcf_record, 0, sizeof(struct fcf_record));
  11168. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11169. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11170. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11171. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11172. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11173. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11174. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11175. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11176. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11177. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11178. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11179. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11180. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11181. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11182. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11183. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11184. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11185. /* Set the VLAN bit map */
  11186. if (phba->valid_vlan) {
  11187. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11188. = 1 << (phba->vlan_id % 8);
  11189. }
  11190. }
  11191. /**
  11192. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11193. * @phba: pointer to lpfc hba data structure.
  11194. * @fcf_index: FCF table entry offset.
  11195. *
  11196. * This routine is invoked to scan the entire FCF table by reading FCF
  11197. * record and processing it one at a time starting from the @fcf_index
  11198. * for initial FCF discovery or fast FCF failover rediscovery.
  11199. *
  11200. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11201. * otherwise.
  11202. **/
  11203. int
  11204. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11205. {
  11206. int rc = 0, error;
  11207. LPFC_MBOXQ_t *mboxq;
  11208. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11209. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11210. if (!mboxq) {
  11211. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11212. "2000 Failed to allocate mbox for "
  11213. "READ_FCF cmd\n");
  11214. error = -ENOMEM;
  11215. goto fail_fcf_scan;
  11216. }
  11217. /* Construct the read FCF record mailbox command */
  11218. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11219. if (rc) {
  11220. error = -EINVAL;
  11221. goto fail_fcf_scan;
  11222. }
  11223. /* Issue the mailbox command asynchronously */
  11224. mboxq->vport = phba->pport;
  11225. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11226. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11227. if (rc == MBX_NOT_FINISHED)
  11228. error = -EIO;
  11229. else {
  11230. spin_lock_irq(&phba->hbalock);
  11231. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11232. spin_unlock_irq(&phba->hbalock);
  11233. /* Reset FCF round robin index bmask for new scan */
  11234. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) {
  11235. memset(phba->fcf.fcf_rr_bmask, 0,
  11236. sizeof(*phba->fcf.fcf_rr_bmask));
  11237. phba->fcf.eligible_fcf_cnt = 0;
  11238. }
  11239. error = 0;
  11240. }
  11241. fail_fcf_scan:
  11242. if (error) {
  11243. if (mboxq)
  11244. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11245. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11246. spin_lock_irq(&phba->hbalock);
  11247. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11248. spin_unlock_irq(&phba->hbalock);
  11249. }
  11250. return error;
  11251. }
  11252. /**
  11253. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11254. * @phba: pointer to lpfc hba data structure.
  11255. * @fcf_index: FCF table entry offset.
  11256. *
  11257. * This routine is invoked to read an FCF record indicated by @fcf_index
  11258. * and to use it for FLOGI round robin FCF failover.
  11259. *
  11260. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11261. * otherwise.
  11262. **/
  11263. int
  11264. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11265. {
  11266. int rc = 0, error;
  11267. LPFC_MBOXQ_t *mboxq;
  11268. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11269. if (!mboxq) {
  11270. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11271. "2763 Failed to allocate mbox for "
  11272. "READ_FCF cmd\n");
  11273. error = -ENOMEM;
  11274. goto fail_fcf_read;
  11275. }
  11276. /* Construct the read FCF record mailbox command */
  11277. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11278. if (rc) {
  11279. error = -EINVAL;
  11280. goto fail_fcf_read;
  11281. }
  11282. /* Issue the mailbox command asynchronously */
  11283. mboxq->vport = phba->pport;
  11284. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11285. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11286. if (rc == MBX_NOT_FINISHED)
  11287. error = -EIO;
  11288. else
  11289. error = 0;
  11290. fail_fcf_read:
  11291. if (error && mboxq)
  11292. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11293. return error;
  11294. }
  11295. /**
  11296. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11297. * @phba: pointer to lpfc hba data structure.
  11298. * @fcf_index: FCF table entry offset.
  11299. *
  11300. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11301. * determine whether it's eligible for FLOGI round robin failover list.
  11302. *
  11303. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11304. * otherwise.
  11305. **/
  11306. int
  11307. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11308. {
  11309. int rc = 0, error;
  11310. LPFC_MBOXQ_t *mboxq;
  11311. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11312. if (!mboxq) {
  11313. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11314. "2758 Failed to allocate mbox for "
  11315. "READ_FCF cmd\n");
  11316. error = -ENOMEM;
  11317. goto fail_fcf_read;
  11318. }
  11319. /* Construct the read FCF record mailbox command */
  11320. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11321. if (rc) {
  11322. error = -EINVAL;
  11323. goto fail_fcf_read;
  11324. }
  11325. /* Issue the mailbox command asynchronously */
  11326. mboxq->vport = phba->pport;
  11327. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11328. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11329. if (rc == MBX_NOT_FINISHED)
  11330. error = -EIO;
  11331. else
  11332. error = 0;
  11333. fail_fcf_read:
  11334. if (error && mboxq)
  11335. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11336. return error;
  11337. }
  11338. /**
  11339. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11340. * @phba: pointer to lpfc hba data structure.
  11341. *
  11342. * This routine is to get the next eligible FCF record index in a round
  11343. * robin fashion. If the next eligible FCF record index equals to the
  11344. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11345. * shall be returned, otherwise, the next eligible FCF record's index
  11346. * shall be returned.
  11347. **/
  11348. uint16_t
  11349. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11350. {
  11351. uint16_t next_fcf_index;
  11352. /* Search start from next bit of currently registered FCF index */
  11353. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11354. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11355. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11356. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11357. next_fcf_index);
  11358. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11359. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11360. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11361. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11362. /* Check roundrobin failover list empty condition */
  11363. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11364. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11365. "2844 No roundrobin failover FCF available\n");
  11366. return LPFC_FCOE_FCF_NEXT_NONE;
  11367. }
  11368. /* Check roundrobin failover index bmask stop condition */
  11369. if (next_fcf_index == phba->fcf.fcf_rr_init_indx) {
  11370. if (!(phba->fcf.fcf_flag & FCF_REDISC_RRU)) {
  11371. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11372. "2847 Round robin failover FCF index "
  11373. "search hit stop condition:x%x\n",
  11374. next_fcf_index);
  11375. return LPFC_FCOE_FCF_NEXT_NONE;
  11376. }
  11377. /* The roundrobin failover index bmask updated, start over */
  11378. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11379. "2848 Round robin failover FCF index bmask "
  11380. "updated, start over\n");
  11381. spin_lock_irq(&phba->hbalock);
  11382. phba->fcf.fcf_flag &= ~FCF_REDISC_RRU;
  11383. spin_unlock_irq(&phba->hbalock);
  11384. return phba->fcf.fcf_rr_init_indx;
  11385. }
  11386. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11387. "2845 Get next round robin failover "
  11388. "FCF index x%x\n", next_fcf_index);
  11389. return next_fcf_index;
  11390. }
  11391. /**
  11392. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11393. * @phba: pointer to lpfc hba data structure.
  11394. *
  11395. * This routine sets the FCF record index in to the eligible bmask for
  11396. * round robin failover search. It checks to make sure that the index
  11397. * does not go beyond the range of the driver allocated bmask dimension
  11398. * before setting the bit.
  11399. *
  11400. * Returns 0 if the index bit successfully set, otherwise, it returns
  11401. * -EINVAL.
  11402. **/
  11403. int
  11404. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11405. {
  11406. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11407. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11408. "2610 HBA FCF index reached driver's "
  11409. "book keeping dimension: fcf_index:%d, "
  11410. "driver_bmask_max:%d\n",
  11411. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11412. return -EINVAL;
  11413. }
  11414. /* Set the eligible FCF record index bmask */
  11415. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11416. /* Set the roundrobin index bmask updated */
  11417. spin_lock_irq(&phba->hbalock);
  11418. phba->fcf.fcf_flag |= FCF_REDISC_RRU;
  11419. spin_unlock_irq(&phba->hbalock);
  11420. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11421. "2790 Set FCF index x%x to round robin failover "
  11422. "bmask\n", fcf_index);
  11423. return 0;
  11424. }
  11425. /**
  11426. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11427. * @phba: pointer to lpfc hba data structure.
  11428. *
  11429. * This routine clears the FCF record index from the eligible bmask for
  11430. * round robin failover search. It checks to make sure that the index
  11431. * does not go beyond the range of the driver allocated bmask dimension
  11432. * before clearing the bit.
  11433. **/
  11434. void
  11435. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11436. {
  11437. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11438. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11439. "2762 HBA FCF index goes beyond driver's "
  11440. "book keeping dimension: fcf_index:%d, "
  11441. "driver_bmask_max:%d\n",
  11442. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11443. return;
  11444. }
  11445. /* Clear the eligible FCF record index bmask */
  11446. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11447. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11448. "2791 Clear FCF index x%x from round robin failover "
  11449. "bmask\n", fcf_index);
  11450. }
  11451. /**
  11452. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11453. * @phba: pointer to lpfc hba data structure.
  11454. *
  11455. * This routine is the completion routine for the rediscover FCF table mailbox
  11456. * command. If the mailbox command returned failure, it will try to stop the
  11457. * FCF rediscover wait timer.
  11458. **/
  11459. void
  11460. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11461. {
  11462. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11463. uint32_t shdr_status, shdr_add_status;
  11464. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11465. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11466. &redisc_fcf->header.cfg_shdr.response);
  11467. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11468. &redisc_fcf->header.cfg_shdr.response);
  11469. if (shdr_status || shdr_add_status) {
  11470. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11471. "2746 Requesting for FCF rediscovery failed "
  11472. "status x%x add_status x%x\n",
  11473. shdr_status, shdr_add_status);
  11474. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11475. spin_lock_irq(&phba->hbalock);
  11476. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11477. spin_unlock_irq(&phba->hbalock);
  11478. /*
  11479. * CVL event triggered FCF rediscover request failed,
  11480. * last resort to re-try current registered FCF entry.
  11481. */
  11482. lpfc_retry_pport_discovery(phba);
  11483. } else {
  11484. spin_lock_irq(&phba->hbalock);
  11485. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11486. spin_unlock_irq(&phba->hbalock);
  11487. /*
  11488. * DEAD FCF event triggered FCF rediscover request
  11489. * failed, last resort to fail over as a link down
  11490. * to FCF registration.
  11491. */
  11492. lpfc_sli4_fcf_dead_failthrough(phba);
  11493. }
  11494. } else {
  11495. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11496. "2775 Start FCF rediscovery quiescent period "
  11497. "wait timer before scaning FCF table\n");
  11498. /*
  11499. * Start FCF rediscovery wait timer for pending FCF
  11500. * before rescan FCF record table.
  11501. */
  11502. lpfc_fcf_redisc_wait_start_timer(phba);
  11503. }
  11504. mempool_free(mbox, phba->mbox_mem_pool);
  11505. }
  11506. /**
  11507. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11508. * @phba: pointer to lpfc hba data structure.
  11509. *
  11510. * This routine is invoked to request for rediscovery of the entire FCF table
  11511. * by the port.
  11512. **/
  11513. int
  11514. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11515. {
  11516. LPFC_MBOXQ_t *mbox;
  11517. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11518. int rc, length;
  11519. /* Cancel retry delay timers to all vports before FCF rediscover */
  11520. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11521. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11522. if (!mbox) {
  11523. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11524. "2745 Failed to allocate mbox for "
  11525. "requesting FCF rediscover.\n");
  11526. return -ENOMEM;
  11527. }
  11528. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11529. sizeof(struct lpfc_sli4_cfg_mhdr));
  11530. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11531. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11532. length, LPFC_SLI4_MBX_EMBED);
  11533. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11534. /* Set count to 0 for invalidating the entire FCF database */
  11535. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11536. /* Issue the mailbox command asynchronously */
  11537. mbox->vport = phba->pport;
  11538. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11539. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11540. if (rc == MBX_NOT_FINISHED) {
  11541. mempool_free(mbox, phba->mbox_mem_pool);
  11542. return -EIO;
  11543. }
  11544. return 0;
  11545. }
  11546. /**
  11547. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11548. * @phba: pointer to lpfc hba data structure.
  11549. *
  11550. * This function is the failover routine as a last resort to the FCF DEAD
  11551. * event when driver failed to perform fast FCF failover.
  11552. **/
  11553. void
  11554. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11555. {
  11556. uint32_t link_state;
  11557. /*
  11558. * Last resort as FCF DEAD event failover will treat this as
  11559. * a link down, but save the link state because we don't want
  11560. * it to be changed to Link Down unless it is already down.
  11561. */
  11562. link_state = phba->link_state;
  11563. lpfc_linkdown(phba);
  11564. phba->link_state = link_state;
  11565. /* Unregister FCF if no devices connected to it */
  11566. lpfc_unregister_unused_fcf(phba);
  11567. }
  11568. /**
  11569. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11570. * @phba: pointer to lpfc hba data structure.
  11571. *
  11572. * This function read region 23 and parse TLV for port status to
  11573. * decide if the user disaled the port. If the TLV indicates the
  11574. * port is disabled, the hba_flag is set accordingly.
  11575. **/
  11576. void
  11577. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11578. {
  11579. LPFC_MBOXQ_t *pmb = NULL;
  11580. MAILBOX_t *mb;
  11581. uint8_t *rgn23_data = NULL;
  11582. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11583. int rc;
  11584. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11585. if (!pmb) {
  11586. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11587. "2600 lpfc_sli_read_serdes_param failed to"
  11588. " allocate mailbox memory\n");
  11589. goto out;
  11590. }
  11591. mb = &pmb->u.mb;
  11592. /* Get adapter Region 23 data */
  11593. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11594. if (!rgn23_data)
  11595. goto out;
  11596. do {
  11597. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11598. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11599. if (rc != MBX_SUCCESS) {
  11600. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11601. "2601 lpfc_sli_read_link_ste failed to"
  11602. " read config region 23 rc 0x%x Status 0x%x\n",
  11603. rc, mb->mbxStatus);
  11604. mb->un.varDmp.word_cnt = 0;
  11605. }
  11606. /*
  11607. * dump mem may return a zero when finished or we got a
  11608. * mailbox error, either way we are done.
  11609. */
  11610. if (mb->un.varDmp.word_cnt == 0)
  11611. break;
  11612. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11613. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11614. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11615. rgn23_data + offset,
  11616. mb->un.varDmp.word_cnt);
  11617. offset += mb->un.varDmp.word_cnt;
  11618. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11619. data_size = offset;
  11620. offset = 0;
  11621. if (!data_size)
  11622. goto out;
  11623. /* Check the region signature first */
  11624. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11625. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11626. "2619 Config region 23 has bad signature\n");
  11627. goto out;
  11628. }
  11629. offset += 4;
  11630. /* Check the data structure version */
  11631. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11632. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11633. "2620 Config region 23 has bad version\n");
  11634. goto out;
  11635. }
  11636. offset += 4;
  11637. /* Parse TLV entries in the region */
  11638. while (offset < data_size) {
  11639. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11640. break;
  11641. /*
  11642. * If the TLV is not driver specific TLV or driver id is
  11643. * not linux driver id, skip the record.
  11644. */
  11645. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11646. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11647. (rgn23_data[offset + 3] != 0)) {
  11648. offset += rgn23_data[offset + 1] * 4 + 4;
  11649. continue;
  11650. }
  11651. /* Driver found a driver specific TLV in the config region */
  11652. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11653. offset += 4;
  11654. tlv_offset = 0;
  11655. /*
  11656. * Search for configured port state sub-TLV.
  11657. */
  11658. while ((offset < data_size) &&
  11659. (tlv_offset < sub_tlv_len)) {
  11660. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11661. offset += 4;
  11662. tlv_offset += 4;
  11663. break;
  11664. }
  11665. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11666. offset += rgn23_data[offset + 1] * 4 + 4;
  11667. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11668. continue;
  11669. }
  11670. /* This HBA contains PORT_STE configured */
  11671. if (!rgn23_data[offset + 2])
  11672. phba->hba_flag |= LINK_DISABLED;
  11673. goto out;
  11674. }
  11675. }
  11676. out:
  11677. if (pmb)
  11678. mempool_free(pmb, phba->mbox_mem_pool);
  11679. kfree(rgn23_data);
  11680. return;
  11681. }
  11682. /**
  11683. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11684. * @vport: pointer to vport data structure.
  11685. *
  11686. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11687. * and REG_VPI mailbox commands associated with the vport. This function
  11688. * is called when driver want to restart discovery of the vport due to
  11689. * a Clear Virtual Link event.
  11690. **/
  11691. void
  11692. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11693. {
  11694. struct lpfc_hba *phba = vport->phba;
  11695. LPFC_MBOXQ_t *mb, *nextmb;
  11696. struct lpfc_dmabuf *mp;
  11697. struct lpfc_nodelist *ndlp;
  11698. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  11699. spin_lock_irq(&phba->hbalock);
  11700. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11701. if (mb->vport != vport)
  11702. continue;
  11703. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11704. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11705. continue;
  11706. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11707. if (phba->sli_rev == LPFC_SLI_REV4)
  11708. __lpfc_sli4_free_rpi(phba,
  11709. mb->u.mb.un.varRegLogin.rpi);
  11710. mp = (struct lpfc_dmabuf *) (mb->context1);
  11711. if (mp) {
  11712. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11713. kfree(mp);
  11714. }
  11715. ndlp = (struct lpfc_nodelist *) mb->context2;
  11716. if (ndlp) {
  11717. spin_lock_irq(shost->host_lock);
  11718. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11719. spin_unlock_irq(shost->host_lock);
  11720. lpfc_nlp_put(ndlp);
  11721. mb->context2 = NULL;
  11722. }
  11723. }
  11724. list_del(&mb->list);
  11725. mempool_free(mb, phba->mbox_mem_pool);
  11726. }
  11727. mb = phba->sli.mbox_active;
  11728. if (mb && (mb->vport == vport)) {
  11729. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11730. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11731. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11732. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11733. ndlp = (struct lpfc_nodelist *) mb->context2;
  11734. if (ndlp) {
  11735. spin_lock_irq(shost->host_lock);
  11736. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11737. spin_unlock_irq(shost->host_lock);
  11738. lpfc_nlp_put(ndlp);
  11739. mb->context2 = NULL;
  11740. }
  11741. /* Unregister the RPI when mailbox complete */
  11742. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11743. }
  11744. }
  11745. spin_unlock_irq(&phba->hbalock);
  11746. }
  11747. /**
  11748. * lpfc_drain_txq - Drain the txq
  11749. * @phba: Pointer to HBA context object.
  11750. *
  11751. * This function attempt to submit IOCBs on the txq
  11752. * to the adapter. For SLI4 adapters, the txq contains
  11753. * ELS IOCBs that have been deferred because the there
  11754. * are no SGLs. This congestion can occur with large
  11755. * vport counts during node discovery.
  11756. **/
  11757. uint32_t
  11758. lpfc_drain_txq(struct lpfc_hba *phba)
  11759. {
  11760. LIST_HEAD(completions);
  11761. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  11762. struct lpfc_iocbq *piocbq = 0;
  11763. unsigned long iflags = 0;
  11764. char *fail_msg = NULL;
  11765. struct lpfc_sglq *sglq;
  11766. union lpfc_wqe wqe;
  11767. spin_lock_irqsave(&phba->hbalock, iflags);
  11768. if (pring->txq_cnt > pring->txq_max)
  11769. pring->txq_max = pring->txq_cnt;
  11770. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11771. while (pring->txq_cnt) {
  11772. spin_lock_irqsave(&phba->hbalock, iflags);
  11773. sglq = __lpfc_sli_get_sglq(phba);
  11774. if (!sglq) {
  11775. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11776. break;
  11777. } else {
  11778. piocbq = lpfc_sli_ringtx_get(phba, pring);
  11779. if (!piocbq) {
  11780. /* The txq_cnt out of sync. This should
  11781. * never happen
  11782. */
  11783. sglq = __lpfc_clear_active_sglq(phba,
  11784. sglq->sli4_xritag);
  11785. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11787. "2823 txq empty and txq_cnt is %d\n ",
  11788. pring->txq_cnt);
  11789. break;
  11790. }
  11791. }
  11792. /* The xri and iocb resources secured,
  11793. * attempt to issue request
  11794. */
  11795. piocbq->sli4_xritag = sglq->sli4_xritag;
  11796. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  11797. fail_msg = "to convert bpl to sgl";
  11798. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  11799. fail_msg = "to convert iocb to wqe";
  11800. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  11801. fail_msg = " - Wq is full";
  11802. else
  11803. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  11804. if (fail_msg) {
  11805. /* Failed means we can't issue and need to cancel */
  11806. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11807. "2822 IOCB failed %s iotag 0x%x "
  11808. "xri 0x%x\n",
  11809. fail_msg,
  11810. piocbq->iotag, piocbq->sli4_xritag);
  11811. list_add_tail(&piocbq->list, &completions);
  11812. }
  11813. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11814. }
  11815. /* Cancel all the IOCBs that cannot be issued */
  11816. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  11817. IOERR_SLI_ABORTED);
  11818. return pring->txq_cnt;
  11819. }