lpfc_sli.c 422 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  92. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  93. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  94. /* Update the host index before invoking device */
  95. host_index = q->host_index;
  96. q->host_index = ((q->host_index + 1) % q->entry_count);
  97. /* Ring Doorbell */
  98. doorbell.word0 = 0;
  99. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  100. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  101. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  102. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  103. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  104. return 0;
  105. }
  106. /**
  107. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  108. * @q: The Work Queue to operate on.
  109. * @index: The index to advance the hba index to.
  110. *
  111. * This routine will update the HBA index of a queue to reflect consumption of
  112. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  113. * an entry the host calls this function to update the queue's internal
  114. * pointers. This routine returns the number of entries that were consumed by
  115. * the HBA.
  116. **/
  117. static uint32_t
  118. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  119. {
  120. uint32_t released = 0;
  121. if (q->hba_index == index)
  122. return 0;
  123. do {
  124. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  125. released++;
  126. } while (q->hba_index != index);
  127. return released;
  128. }
  129. /**
  130. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  131. * @q: The Mailbox Queue to operate on.
  132. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  133. *
  134. * This routine will copy the contents of @mqe to the next available entry on
  135. * the @q. This function will then ring the Work Queue Doorbell to signal the
  136. * HBA to start processing the Work Queue Entry. This function returns 0 if
  137. * successful. If no entries are available on @q then this function will return
  138. * -ENOMEM.
  139. * The caller is expected to hold the hbalock when calling this routine.
  140. **/
  141. static uint32_t
  142. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  143. {
  144. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  145. struct lpfc_register doorbell;
  146. uint32_t host_index;
  147. /* If the host has not yet processed the next entry then we are done */
  148. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  149. return -ENOMEM;
  150. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  151. /* Save off the mailbox pointer for completion */
  152. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  153. /* Update the host index before invoking device */
  154. host_index = q->host_index;
  155. q->host_index = ((q->host_index + 1) % q->entry_count);
  156. /* Ring Doorbell */
  157. doorbell.word0 = 0;
  158. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  159. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  160. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  161. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  162. return 0;
  163. }
  164. /**
  165. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  166. * @q: The Mailbox Queue to operate on.
  167. *
  168. * This routine will update the HBA index of a queue to reflect consumption of
  169. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  170. * an entry the host calls this function to update the queue's internal
  171. * pointers. This routine returns the number of entries that were consumed by
  172. * the HBA.
  173. **/
  174. static uint32_t
  175. lpfc_sli4_mq_release(struct lpfc_queue *q)
  176. {
  177. /* Clear the mailbox pointer for completion */
  178. q->phba->mbox = NULL;
  179. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  180. return 1;
  181. }
  182. /**
  183. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  184. * @q: The Event Queue to get the first valid EQE from
  185. *
  186. * This routine will get the first valid Event Queue Entry from @q, update
  187. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  188. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  189. * processed, but not popped back to the HBA then this routine will return NULL.
  190. **/
  191. static struct lpfc_eqe *
  192. lpfc_sli4_eq_get(struct lpfc_queue *q)
  193. {
  194. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  195. /* If the next EQE is not valid then we are done */
  196. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  197. return NULL;
  198. /* If the host has not yet processed the next entry then we are done */
  199. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  200. return NULL;
  201. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  202. return eqe;
  203. }
  204. /**
  205. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  206. * @q: The Event Queue that the host has completed processing for.
  207. * @arm: Indicates whether the host wants to arms this CQ.
  208. *
  209. * This routine will mark all Event Queue Entries on @q, from the last
  210. * known completed entry to the last entry that was processed, as completed
  211. * by clearing the valid bit for each completion queue entry. Then it will
  212. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  213. * The internal host index in the @q will be updated by this routine to indicate
  214. * that the host has finished processing the entries. The @arm parameter
  215. * indicates that the queue should be rearmed when ringing the doorbell.
  216. *
  217. * This function will return the number of EQEs that were popped.
  218. **/
  219. uint32_t
  220. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  221. {
  222. uint32_t released = 0;
  223. struct lpfc_eqe *temp_eqe;
  224. struct lpfc_register doorbell;
  225. /* while there are valid entries */
  226. while (q->hba_index != q->host_index) {
  227. temp_eqe = q->qe[q->host_index].eqe;
  228. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  229. released++;
  230. q->host_index = ((q->host_index + 1) % q->entry_count);
  231. }
  232. if (unlikely(released == 0 && !arm))
  233. return 0;
  234. /* ring doorbell for number popped */
  235. doorbell.word0 = 0;
  236. if (arm) {
  237. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  238. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  239. }
  240. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  241. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  242. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  243. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  244. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  245. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  246. readl(q->phba->sli4_hba.EQCQDBregaddr);
  247. return released;
  248. }
  249. /**
  250. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  251. * @q: The Completion Queue to get the first valid CQE from
  252. *
  253. * This routine will get the first valid Completion Queue Entry from @q, update
  254. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  255. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  256. * processed, but not popped back to the HBA then this routine will return NULL.
  257. **/
  258. static struct lpfc_cqe *
  259. lpfc_sli4_cq_get(struct lpfc_queue *q)
  260. {
  261. struct lpfc_cqe *cqe;
  262. /* If the next CQE is not valid then we are done */
  263. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  264. return NULL;
  265. /* If the host has not yet processed the next entry then we are done */
  266. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  267. return NULL;
  268. cqe = q->qe[q->hba_index].cqe;
  269. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  270. return cqe;
  271. }
  272. /**
  273. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  274. * @q: The Completion Queue that the host has completed processing for.
  275. * @arm: Indicates whether the host wants to arms this CQ.
  276. *
  277. * This routine will mark all Completion queue entries on @q, from the last
  278. * known completed entry to the last entry that was processed, as completed
  279. * by clearing the valid bit for each completion queue entry. Then it will
  280. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  281. * The internal host index in the @q will be updated by this routine to indicate
  282. * that the host has finished processing the entries. The @arm parameter
  283. * indicates that the queue should be rearmed when ringing the doorbell.
  284. *
  285. * This function will return the number of CQEs that were released.
  286. **/
  287. uint32_t
  288. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  289. {
  290. uint32_t released = 0;
  291. struct lpfc_cqe *temp_qe;
  292. struct lpfc_register doorbell;
  293. /* while there are valid entries */
  294. while (q->hba_index != q->host_index) {
  295. temp_qe = q->qe[q->host_index].cqe;
  296. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  297. released++;
  298. q->host_index = ((q->host_index + 1) % q->entry_count);
  299. }
  300. if (unlikely(released == 0 && !arm))
  301. return 0;
  302. /* ring doorbell for number popped */
  303. doorbell.word0 = 0;
  304. if (arm)
  305. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  306. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  307. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  308. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  309. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  310. return released;
  311. }
  312. /**
  313. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  314. * @q: The Header Receive Queue to operate on.
  315. * @wqe: The Receive Queue Entry to put on the Receive queue.
  316. *
  317. * This routine will copy the contents of @wqe to the next available entry on
  318. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  319. * HBA to start processing the Receive Queue Entry. This function returns the
  320. * index that the rqe was copied to if successful. If no entries are available
  321. * on @q then this function will return -ENOMEM.
  322. * The caller is expected to hold the hbalock when calling this routine.
  323. **/
  324. static int
  325. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  326. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  327. {
  328. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  329. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  330. struct lpfc_register doorbell;
  331. int put_index = hq->host_index;
  332. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  333. return -EINVAL;
  334. if (hq->host_index != dq->host_index)
  335. return -EINVAL;
  336. /* If the host has not yet processed the next entry then we are done */
  337. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  338. return -EBUSY;
  339. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  340. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  341. /* Update the host index to point to the next slot */
  342. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  343. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  344. /* Ring The Header Receive Queue Doorbell */
  345. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  346. doorbell.word0 = 0;
  347. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  348. LPFC_RQ_POST_BATCH);
  349. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  350. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  351. }
  352. return put_index;
  353. }
  354. /**
  355. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  356. * @q: The Header Receive Queue to operate on.
  357. *
  358. * This routine will update the HBA index of a queue to reflect consumption of
  359. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  360. * consumed an entry the host calls this function to update the queue's
  361. * internal pointers. This routine returns the number of entries that were
  362. * consumed by the HBA.
  363. **/
  364. static uint32_t
  365. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  366. {
  367. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  368. return 0;
  369. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  370. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  371. return 1;
  372. }
  373. /**
  374. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  375. * @phba: Pointer to HBA context object.
  376. * @pring: Pointer to driver SLI ring object.
  377. *
  378. * This function returns pointer to next command iocb entry
  379. * in the command ring. The caller must hold hbalock to prevent
  380. * other threads consume the next command iocb.
  381. * SLI-2/SLI-3 provide different sized iocbs.
  382. **/
  383. static inline IOCB_t *
  384. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  385. {
  386. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  387. pring->cmdidx * phba->iocb_cmd_size);
  388. }
  389. /**
  390. * lpfc_resp_iocb - Get next response iocb entry in the ring
  391. * @phba: Pointer to HBA context object.
  392. * @pring: Pointer to driver SLI ring object.
  393. *
  394. * This function returns pointer to next response iocb entry
  395. * in the response ring. The caller must hold hbalock to make sure
  396. * that no other thread consume the next response iocb.
  397. * SLI-2/SLI-3 provide different sized iocbs.
  398. **/
  399. static inline IOCB_t *
  400. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  401. {
  402. return (IOCB_t *) (((char *) pring->rspringaddr) +
  403. pring->rspidx * phba->iocb_rsp_size);
  404. }
  405. /**
  406. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  407. * @phba: Pointer to HBA context object.
  408. *
  409. * This function is called with hbalock held. This function
  410. * allocates a new driver iocb object from the iocb pool. If the
  411. * allocation is successful, it returns pointer to the newly
  412. * allocated iocb object else it returns NULL.
  413. **/
  414. static struct lpfc_iocbq *
  415. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  416. {
  417. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  418. struct lpfc_iocbq * iocbq = NULL;
  419. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  420. if (iocbq)
  421. phba->iocb_cnt++;
  422. if (phba->iocb_cnt > phba->iocb_max)
  423. phba->iocb_max = phba->iocb_cnt;
  424. return iocbq;
  425. }
  426. /**
  427. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  428. * @phba: Pointer to HBA context object.
  429. * @xritag: XRI value.
  430. *
  431. * This function clears the sglq pointer from the array of acive
  432. * sglq's. The xritag that is passed in is used to index into the
  433. * array. Before the xritag can be used it needs to be adjusted
  434. * by subtracting the xribase.
  435. *
  436. * Returns sglq ponter = success, NULL = Failure.
  437. **/
  438. static struct lpfc_sglq *
  439. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  440. {
  441. uint16_t adj_xri;
  442. struct lpfc_sglq *sglq;
  443. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  444. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  445. return NULL;
  446. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  447. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  448. return sglq;
  449. }
  450. /**
  451. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  452. * @phba: Pointer to HBA context object.
  453. * @xritag: XRI value.
  454. *
  455. * This function returns the sglq pointer from the array of acive
  456. * sglq's. The xritag that is passed in is used to index into the
  457. * array. Before the xritag can be used it needs to be adjusted
  458. * by subtracting the xribase.
  459. *
  460. * Returns sglq ponter = success, NULL = Failure.
  461. **/
  462. struct lpfc_sglq *
  463. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  464. {
  465. uint16_t adj_xri;
  466. struct lpfc_sglq *sglq;
  467. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  468. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  469. return NULL;
  470. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  471. return sglq;
  472. }
  473. /**
  474. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  475. * @phba: Pointer to HBA context object.
  476. * @ndlp: nodelist pointer for this target.
  477. * @xritag: xri used in this exchange.
  478. * @rxid: Remote Exchange ID.
  479. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  480. *
  481. * This function is called with hbalock held.
  482. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  483. * rrq struct and adds it to the active_rrq_list.
  484. *
  485. * returns 0 for rrq slot for this xri
  486. * < 0 Were not able to get rrq mem or invalid parameter.
  487. **/
  488. static int
  489. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  490. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  491. {
  492. uint16_t adj_xri;
  493. struct lpfc_node_rrq *rrq;
  494. int empty;
  495. uint32_t did = 0;
  496. if (!ndlp)
  497. return -EINVAL;
  498. if (!phba->cfg_enable_rrq)
  499. return -EINVAL;
  500. if (phba->pport->load_flag & FC_UNLOADING) {
  501. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  502. goto out;
  503. }
  504. did = ndlp->nlp_DID;
  505. /*
  506. * set the active bit even if there is no mem available.
  507. */
  508. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  509. if (NLP_CHK_FREE_REQ(ndlp))
  510. goto out;
  511. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  512. goto out;
  513. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  514. goto out;
  515. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  516. if (rrq) {
  517. rrq->send_rrq = send_rrq;
  518. rrq->xritag = xritag;
  519. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  520. rrq->ndlp = ndlp;
  521. rrq->nlp_DID = ndlp->nlp_DID;
  522. rrq->vport = ndlp->vport;
  523. rrq->rxid = rxid;
  524. empty = list_empty(&phba->active_rrq_list);
  525. rrq->send_rrq = send_rrq;
  526. list_add_tail(&rrq->list, &phba->active_rrq_list);
  527. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  528. phba->hba_flag |= HBA_RRQ_ACTIVE;
  529. if (empty)
  530. lpfc_worker_wake_up(phba);
  531. }
  532. return 0;
  533. }
  534. out:
  535. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  536. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  537. " DID:0x%x Send:%d\n",
  538. xritag, rxid, did, send_rrq);
  539. return -EINVAL;
  540. }
  541. /**
  542. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  543. * @phba: Pointer to HBA context object.
  544. * @xritag: xri used in this exchange.
  545. * @rrq: The RRQ to be cleared.
  546. *
  547. **/
  548. void
  549. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  550. uint16_t xritag,
  551. struct lpfc_node_rrq *rrq)
  552. {
  553. uint16_t adj_xri;
  554. struct lpfc_nodelist *ndlp = NULL;
  555. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  556. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  557. /* The target DID could have been swapped (cable swap)
  558. * we should use the ndlp from the findnode if it is
  559. * available.
  560. */
  561. if ((!ndlp) && rrq->ndlp)
  562. ndlp = rrq->ndlp;
  563. if (!ndlp)
  564. goto out;
  565. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  566. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  567. rrq->send_rrq = 0;
  568. rrq->xritag = 0;
  569. rrq->rrq_stop_time = 0;
  570. }
  571. out:
  572. mempool_free(rrq, phba->rrq_pool);
  573. }
  574. /**
  575. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  576. * @phba: Pointer to HBA context object.
  577. *
  578. * This function is called with hbalock held. This function
  579. * Checks if stop_time (ratov from setting rrq active) has
  580. * been reached, if it has and the send_rrq flag is set then
  581. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  582. * then it will just call the routine to clear the rrq and
  583. * free the rrq resource.
  584. * The timer is set to the next rrq that is going to expire before
  585. * leaving the routine.
  586. *
  587. **/
  588. void
  589. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  590. {
  591. struct lpfc_node_rrq *rrq;
  592. struct lpfc_node_rrq *nextrrq;
  593. unsigned long next_time;
  594. unsigned long iflags;
  595. LIST_HEAD(send_rrq);
  596. spin_lock_irqsave(&phba->hbalock, iflags);
  597. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  598. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  599. list_for_each_entry_safe(rrq, nextrrq,
  600. &phba->active_rrq_list, list) {
  601. if (time_after(jiffies, rrq->rrq_stop_time))
  602. list_move(&rrq->list, &send_rrq);
  603. else if (time_before(rrq->rrq_stop_time, next_time))
  604. next_time = rrq->rrq_stop_time;
  605. }
  606. spin_unlock_irqrestore(&phba->hbalock, iflags);
  607. if (!list_empty(&phba->active_rrq_list))
  608. mod_timer(&phba->rrq_tmr, next_time);
  609. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  610. list_del(&rrq->list);
  611. if (!rrq->send_rrq)
  612. /* this call will free the rrq */
  613. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  614. else if (lpfc_send_rrq(phba, rrq)) {
  615. /* if we send the rrq then the completion handler
  616. * will clear the bit in the xribitmap.
  617. */
  618. lpfc_clr_rrq_active(phba, rrq->xritag,
  619. rrq);
  620. }
  621. }
  622. }
  623. /**
  624. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  625. * @vport: Pointer to vport context object.
  626. * @xri: The xri used in the exchange.
  627. * @did: The targets DID for this exchange.
  628. *
  629. * returns NULL = rrq not found in the phba->active_rrq_list.
  630. * rrq = rrq for this xri and target.
  631. **/
  632. struct lpfc_node_rrq *
  633. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  634. {
  635. struct lpfc_hba *phba = vport->phba;
  636. struct lpfc_node_rrq *rrq;
  637. struct lpfc_node_rrq *nextrrq;
  638. unsigned long iflags;
  639. if (phba->sli_rev != LPFC_SLI_REV4)
  640. return NULL;
  641. spin_lock_irqsave(&phba->hbalock, iflags);
  642. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  643. if (rrq->vport == vport && rrq->xritag == xri &&
  644. rrq->nlp_DID == did){
  645. list_del(&rrq->list);
  646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  647. return rrq;
  648. }
  649. }
  650. spin_unlock_irqrestore(&phba->hbalock, iflags);
  651. return NULL;
  652. }
  653. /**
  654. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  655. * @vport: Pointer to vport context object.
  656. * @ndlp: Pointer to the lpfc_node_list structure.
  657. * If ndlp is NULL Remove all active RRQs for this vport from the
  658. * phba->active_rrq_list and clear the rrq.
  659. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  660. **/
  661. void
  662. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  663. {
  664. struct lpfc_hba *phba = vport->phba;
  665. struct lpfc_node_rrq *rrq;
  666. struct lpfc_node_rrq *nextrrq;
  667. unsigned long iflags;
  668. LIST_HEAD(rrq_list);
  669. if (phba->sli_rev != LPFC_SLI_REV4)
  670. return;
  671. if (!ndlp) {
  672. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  673. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  674. }
  675. spin_lock_irqsave(&phba->hbalock, iflags);
  676. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  677. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  678. list_move(&rrq->list, &rrq_list);
  679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  680. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  681. list_del(&rrq->list);
  682. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  683. }
  684. }
  685. /**
  686. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  687. * @phba: Pointer to HBA context object.
  688. *
  689. * Remove all rrqs from the phba->active_rrq_list and free them by
  690. * calling __lpfc_clr_active_rrq
  691. *
  692. **/
  693. void
  694. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  695. {
  696. struct lpfc_node_rrq *rrq;
  697. struct lpfc_node_rrq *nextrrq;
  698. unsigned long next_time;
  699. unsigned long iflags;
  700. LIST_HEAD(rrq_list);
  701. if (phba->sli_rev != LPFC_SLI_REV4)
  702. return;
  703. spin_lock_irqsave(&phba->hbalock, iflags);
  704. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  705. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  706. list_splice_init(&phba->active_rrq_list, &rrq_list);
  707. spin_unlock_irqrestore(&phba->hbalock, iflags);
  708. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  709. list_del(&rrq->list);
  710. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  711. }
  712. if (!list_empty(&phba->active_rrq_list))
  713. mod_timer(&phba->rrq_tmr, next_time);
  714. }
  715. /**
  716. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  717. * @phba: Pointer to HBA context object.
  718. * @ndlp: Targets nodelist pointer for this exchange.
  719. * @xritag the xri in the bitmap to test.
  720. *
  721. * This function is called with hbalock held. This function
  722. * returns 0 = rrq not active for this xri
  723. * 1 = rrq is valid for this xri.
  724. **/
  725. int
  726. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  727. uint16_t xritag)
  728. {
  729. uint16_t adj_xri;
  730. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  731. if (!ndlp)
  732. return 0;
  733. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  734. return 1;
  735. else
  736. return 0;
  737. }
  738. /**
  739. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  740. * @phba: Pointer to HBA context object.
  741. * @ndlp: nodelist pointer for this target.
  742. * @xritag: xri used in this exchange.
  743. * @rxid: Remote Exchange ID.
  744. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  745. *
  746. * This function takes the hbalock.
  747. * The active bit is always set in the active rrq xri_bitmap even
  748. * if there is no slot avaiable for the other rrq information.
  749. *
  750. * returns 0 rrq actived for this xri
  751. * < 0 No memory or invalid ndlp.
  752. **/
  753. int
  754. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  755. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  756. {
  757. int ret;
  758. unsigned long iflags;
  759. spin_lock_irqsave(&phba->hbalock, iflags);
  760. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  761. spin_unlock_irqrestore(&phba->hbalock, iflags);
  762. return ret;
  763. }
  764. /**
  765. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  766. * @phba: Pointer to HBA context object.
  767. * @piocb: Pointer to the iocbq.
  768. *
  769. * This function is called with hbalock held. This function
  770. * Gets a new driver sglq object from the sglq list. If the
  771. * list is not empty then it is successful, it returns pointer to the newly
  772. * allocated sglq object else it returns NULL.
  773. **/
  774. static struct lpfc_sglq *
  775. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  776. {
  777. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  778. struct lpfc_sglq *sglq = NULL;
  779. struct lpfc_sglq *start_sglq = NULL;
  780. uint16_t adj_xri;
  781. struct lpfc_scsi_buf *lpfc_cmd;
  782. struct lpfc_nodelist *ndlp;
  783. int found = 0;
  784. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  785. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  786. ndlp = lpfc_cmd->rdata->pnode;
  787. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  788. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  789. ndlp = piocbq->context_un.ndlp;
  790. else
  791. ndlp = piocbq->context1;
  792. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  793. start_sglq = sglq;
  794. while (!found) {
  795. if (!sglq)
  796. return NULL;
  797. adj_xri = sglq->sli4_xritag -
  798. phba->sli4_hba.max_cfg_param.xri_base;
  799. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  800. /* This xri has an rrq outstanding for this DID.
  801. * put it back in the list and get another xri.
  802. */
  803. list_add_tail(&sglq->list, lpfc_sgl_list);
  804. sglq = NULL;
  805. list_remove_head(lpfc_sgl_list, sglq,
  806. struct lpfc_sglq, list);
  807. if (sglq == start_sglq) {
  808. sglq = NULL;
  809. break;
  810. } else
  811. continue;
  812. }
  813. sglq->ndlp = ndlp;
  814. found = 1;
  815. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  816. sglq->state = SGL_ALLOCATED;
  817. }
  818. return sglq;
  819. }
  820. /**
  821. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  822. * @phba: Pointer to HBA context object.
  823. *
  824. * This function is called with no lock held. This function
  825. * allocates a new driver iocb object from the iocb pool. If the
  826. * allocation is successful, it returns pointer to the newly
  827. * allocated iocb object else it returns NULL.
  828. **/
  829. struct lpfc_iocbq *
  830. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  831. {
  832. struct lpfc_iocbq * iocbq = NULL;
  833. unsigned long iflags;
  834. spin_lock_irqsave(&phba->hbalock, iflags);
  835. iocbq = __lpfc_sli_get_iocbq(phba);
  836. spin_unlock_irqrestore(&phba->hbalock, iflags);
  837. return iocbq;
  838. }
  839. /**
  840. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  841. * @phba: Pointer to HBA context object.
  842. * @iocbq: Pointer to driver iocb object.
  843. *
  844. * This function is called with hbalock held to release driver
  845. * iocb object to the iocb pool. The iotag in the iocb object
  846. * does not change for each use of the iocb object. This function
  847. * clears all other fields of the iocb object when it is freed.
  848. * The sqlq structure that holds the xritag and phys and virtual
  849. * mappings for the scatter gather list is retrieved from the
  850. * active array of sglq. The get of the sglq pointer also clears
  851. * the entry in the array. If the status of the IO indiactes that
  852. * this IO was aborted then the sglq entry it put on the
  853. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  854. * IO has good status or fails for any other reason then the sglq
  855. * entry is added to the free list (lpfc_sgl_list).
  856. **/
  857. static void
  858. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  859. {
  860. struct lpfc_sglq *sglq;
  861. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  862. unsigned long iflag = 0;
  863. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  864. if (iocbq->sli4_xritag == NO_XRI)
  865. sglq = NULL;
  866. else
  867. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  868. if (sglq) {
  869. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  870. (sglq->state != SGL_XRI_ABORTED)) {
  871. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  872. iflag);
  873. list_add(&sglq->list,
  874. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  875. spin_unlock_irqrestore(
  876. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  877. } else {
  878. sglq->state = SGL_FREED;
  879. sglq->ndlp = NULL;
  880. list_add_tail(&sglq->list,
  881. &phba->sli4_hba.lpfc_sgl_list);
  882. /* Check if TXQ queue needs to be serviced */
  883. if (pring->txq_cnt)
  884. lpfc_worker_wake_up(phba);
  885. }
  886. }
  887. /*
  888. * Clean all volatile data fields, preserve iotag and node struct.
  889. */
  890. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  891. iocbq->sli4_xritag = NO_XRI;
  892. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  893. }
  894. /**
  895. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  896. * @phba: Pointer to HBA context object.
  897. * @iocbq: Pointer to driver iocb object.
  898. *
  899. * This function is called with hbalock held to release driver
  900. * iocb object to the iocb pool. The iotag in the iocb object
  901. * does not change for each use of the iocb object. This function
  902. * clears all other fields of the iocb object when it is freed.
  903. **/
  904. static void
  905. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  906. {
  907. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  908. /*
  909. * Clean all volatile data fields, preserve iotag and node struct.
  910. */
  911. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  912. iocbq->sli4_xritag = NO_XRI;
  913. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  914. }
  915. /**
  916. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  917. * @phba: Pointer to HBA context object.
  918. * @iocbq: Pointer to driver iocb object.
  919. *
  920. * This function is called with hbalock held to release driver
  921. * iocb object to the iocb pool. The iotag in the iocb object
  922. * does not change for each use of the iocb object. This function
  923. * clears all other fields of the iocb object when it is freed.
  924. **/
  925. static void
  926. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  927. {
  928. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  929. phba->iocb_cnt--;
  930. }
  931. /**
  932. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  933. * @phba: Pointer to HBA context object.
  934. * @iocbq: Pointer to driver iocb object.
  935. *
  936. * This function is called with no lock held to release the iocb to
  937. * iocb pool.
  938. **/
  939. void
  940. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  941. {
  942. unsigned long iflags;
  943. /*
  944. * Clean all volatile data fields, preserve iotag and node struct.
  945. */
  946. spin_lock_irqsave(&phba->hbalock, iflags);
  947. __lpfc_sli_release_iocbq(phba, iocbq);
  948. spin_unlock_irqrestore(&phba->hbalock, iflags);
  949. }
  950. /**
  951. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  952. * @phba: Pointer to HBA context object.
  953. * @iocblist: List of IOCBs.
  954. * @ulpstatus: ULP status in IOCB command field.
  955. * @ulpWord4: ULP word-4 in IOCB command field.
  956. *
  957. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  958. * on the list by invoking the complete callback function associated with the
  959. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  960. * fields.
  961. **/
  962. void
  963. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  964. uint32_t ulpstatus, uint32_t ulpWord4)
  965. {
  966. struct lpfc_iocbq *piocb;
  967. while (!list_empty(iocblist)) {
  968. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  969. if (!piocb->iocb_cmpl)
  970. lpfc_sli_release_iocbq(phba, piocb);
  971. else {
  972. piocb->iocb.ulpStatus = ulpstatus;
  973. piocb->iocb.un.ulpWord[4] = ulpWord4;
  974. (piocb->iocb_cmpl) (phba, piocb, piocb);
  975. }
  976. }
  977. return;
  978. }
  979. /**
  980. * lpfc_sli_iocb_cmd_type - Get the iocb type
  981. * @iocb_cmnd: iocb command code.
  982. *
  983. * This function is called by ring event handler function to get the iocb type.
  984. * This function translates the iocb command to an iocb command type used to
  985. * decide the final disposition of each completed IOCB.
  986. * The function returns
  987. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  988. * LPFC_SOL_IOCB if it is a solicited iocb completion
  989. * LPFC_ABORT_IOCB if it is an abort iocb
  990. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  991. *
  992. * The caller is not required to hold any lock.
  993. **/
  994. static lpfc_iocb_type
  995. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  996. {
  997. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  998. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  999. return 0;
  1000. switch (iocb_cmnd) {
  1001. case CMD_XMIT_SEQUENCE_CR:
  1002. case CMD_XMIT_SEQUENCE_CX:
  1003. case CMD_XMIT_BCAST_CN:
  1004. case CMD_XMIT_BCAST_CX:
  1005. case CMD_ELS_REQUEST_CR:
  1006. case CMD_ELS_REQUEST_CX:
  1007. case CMD_CREATE_XRI_CR:
  1008. case CMD_CREATE_XRI_CX:
  1009. case CMD_GET_RPI_CN:
  1010. case CMD_XMIT_ELS_RSP_CX:
  1011. case CMD_GET_RPI_CR:
  1012. case CMD_FCP_IWRITE_CR:
  1013. case CMD_FCP_IWRITE_CX:
  1014. case CMD_FCP_IREAD_CR:
  1015. case CMD_FCP_IREAD_CX:
  1016. case CMD_FCP_ICMND_CR:
  1017. case CMD_FCP_ICMND_CX:
  1018. case CMD_FCP_TSEND_CX:
  1019. case CMD_FCP_TRSP_CX:
  1020. case CMD_FCP_TRECEIVE_CX:
  1021. case CMD_FCP_AUTO_TRSP_CX:
  1022. case CMD_ADAPTER_MSG:
  1023. case CMD_ADAPTER_DUMP:
  1024. case CMD_XMIT_SEQUENCE64_CR:
  1025. case CMD_XMIT_SEQUENCE64_CX:
  1026. case CMD_XMIT_BCAST64_CN:
  1027. case CMD_XMIT_BCAST64_CX:
  1028. case CMD_ELS_REQUEST64_CR:
  1029. case CMD_ELS_REQUEST64_CX:
  1030. case CMD_FCP_IWRITE64_CR:
  1031. case CMD_FCP_IWRITE64_CX:
  1032. case CMD_FCP_IREAD64_CR:
  1033. case CMD_FCP_IREAD64_CX:
  1034. case CMD_FCP_ICMND64_CR:
  1035. case CMD_FCP_ICMND64_CX:
  1036. case CMD_FCP_TSEND64_CX:
  1037. case CMD_FCP_TRSP64_CX:
  1038. case CMD_FCP_TRECEIVE64_CX:
  1039. case CMD_GEN_REQUEST64_CR:
  1040. case CMD_GEN_REQUEST64_CX:
  1041. case CMD_XMIT_ELS_RSP64_CX:
  1042. case DSSCMD_IWRITE64_CR:
  1043. case DSSCMD_IWRITE64_CX:
  1044. case DSSCMD_IREAD64_CR:
  1045. case DSSCMD_IREAD64_CX:
  1046. type = LPFC_SOL_IOCB;
  1047. break;
  1048. case CMD_ABORT_XRI_CN:
  1049. case CMD_ABORT_XRI_CX:
  1050. case CMD_CLOSE_XRI_CN:
  1051. case CMD_CLOSE_XRI_CX:
  1052. case CMD_XRI_ABORTED_CX:
  1053. case CMD_ABORT_MXRI64_CN:
  1054. case CMD_XMIT_BLS_RSP64_CX:
  1055. type = LPFC_ABORT_IOCB;
  1056. break;
  1057. case CMD_RCV_SEQUENCE_CX:
  1058. case CMD_RCV_ELS_REQ_CX:
  1059. case CMD_RCV_SEQUENCE64_CX:
  1060. case CMD_RCV_ELS_REQ64_CX:
  1061. case CMD_ASYNC_STATUS:
  1062. case CMD_IOCB_RCV_SEQ64_CX:
  1063. case CMD_IOCB_RCV_ELS64_CX:
  1064. case CMD_IOCB_RCV_CONT64_CX:
  1065. case CMD_IOCB_RET_XRI64_CX:
  1066. type = LPFC_UNSOL_IOCB;
  1067. break;
  1068. case CMD_IOCB_XMIT_MSEQ64_CR:
  1069. case CMD_IOCB_XMIT_MSEQ64_CX:
  1070. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1071. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1072. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1073. case CMD_IOCB_ABORT_EXTENDED_CN:
  1074. case CMD_IOCB_RET_HBQE64_CN:
  1075. case CMD_IOCB_FCP_IBIDIR64_CR:
  1076. case CMD_IOCB_FCP_IBIDIR64_CX:
  1077. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1078. case CMD_IOCB_LOGENTRY_CN:
  1079. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1080. printk("%s - Unhandled SLI-3 Command x%x\n",
  1081. __func__, iocb_cmnd);
  1082. type = LPFC_UNKNOWN_IOCB;
  1083. break;
  1084. default:
  1085. type = LPFC_UNKNOWN_IOCB;
  1086. break;
  1087. }
  1088. return type;
  1089. }
  1090. /**
  1091. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1092. * @phba: Pointer to HBA context object.
  1093. *
  1094. * This function is called from SLI initialization code
  1095. * to configure every ring of the HBA's SLI interface. The
  1096. * caller is not required to hold any lock. This function issues
  1097. * a config_ring mailbox command for each ring.
  1098. * This function returns zero if successful else returns a negative
  1099. * error code.
  1100. **/
  1101. static int
  1102. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1103. {
  1104. struct lpfc_sli *psli = &phba->sli;
  1105. LPFC_MBOXQ_t *pmb;
  1106. MAILBOX_t *pmbox;
  1107. int i, rc, ret = 0;
  1108. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1109. if (!pmb)
  1110. return -ENOMEM;
  1111. pmbox = &pmb->u.mb;
  1112. phba->link_state = LPFC_INIT_MBX_CMDS;
  1113. for (i = 0; i < psli->num_rings; i++) {
  1114. lpfc_config_ring(phba, i, pmb);
  1115. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1116. if (rc != MBX_SUCCESS) {
  1117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1118. "0446 Adapter failed to init (%d), "
  1119. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1120. "ring %d\n",
  1121. rc, pmbox->mbxCommand,
  1122. pmbox->mbxStatus, i);
  1123. phba->link_state = LPFC_HBA_ERROR;
  1124. ret = -ENXIO;
  1125. break;
  1126. }
  1127. }
  1128. mempool_free(pmb, phba->mbox_mem_pool);
  1129. return ret;
  1130. }
  1131. /**
  1132. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1133. * @phba: Pointer to HBA context object.
  1134. * @pring: Pointer to driver SLI ring object.
  1135. * @piocb: Pointer to the driver iocb object.
  1136. *
  1137. * This function is called with hbalock held. The function adds the
  1138. * new iocb to txcmplq of the given ring. This function always returns
  1139. * 0. If this function is called for ELS ring, this function checks if
  1140. * there is a vport associated with the ELS command. This function also
  1141. * starts els_tmofunc timer if this is an ELS command.
  1142. **/
  1143. static int
  1144. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1145. struct lpfc_iocbq *piocb)
  1146. {
  1147. list_add_tail(&piocb->list, &pring->txcmplq);
  1148. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1149. pring->txcmplq_cnt++;
  1150. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1151. pring->txcmplq_max = pring->txcmplq_cnt;
  1152. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1153. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1154. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1155. if (!piocb->vport)
  1156. BUG();
  1157. else
  1158. mod_timer(&piocb->vport->els_tmofunc,
  1159. jiffies + HZ * (phba->fc_ratov << 1));
  1160. }
  1161. return 0;
  1162. }
  1163. /**
  1164. * lpfc_sli_ringtx_get - Get first element of the txq
  1165. * @phba: Pointer to HBA context object.
  1166. * @pring: Pointer to driver SLI ring object.
  1167. *
  1168. * This function is called with hbalock held to get next
  1169. * iocb in txq of the given ring. If there is any iocb in
  1170. * the txq, the function returns first iocb in the list after
  1171. * removing the iocb from the list, else it returns NULL.
  1172. **/
  1173. struct lpfc_iocbq *
  1174. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1175. {
  1176. struct lpfc_iocbq *cmd_iocb;
  1177. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1178. if (cmd_iocb != NULL)
  1179. pring->txq_cnt--;
  1180. return cmd_iocb;
  1181. }
  1182. /**
  1183. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1184. * @phba: Pointer to HBA context object.
  1185. * @pring: Pointer to driver SLI ring object.
  1186. *
  1187. * This function is called with hbalock held and the caller must post the
  1188. * iocb without releasing the lock. If the caller releases the lock,
  1189. * iocb slot returned by the function is not guaranteed to be available.
  1190. * The function returns pointer to the next available iocb slot if there
  1191. * is available slot in the ring, else it returns NULL.
  1192. * If the get index of the ring is ahead of the put index, the function
  1193. * will post an error attention event to the worker thread to take the
  1194. * HBA to offline state.
  1195. **/
  1196. static IOCB_t *
  1197. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1198. {
  1199. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1200. uint32_t max_cmd_idx = pring->numCiocb;
  1201. if ((pring->next_cmdidx == pring->cmdidx) &&
  1202. (++pring->next_cmdidx >= max_cmd_idx))
  1203. pring->next_cmdidx = 0;
  1204. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1205. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1206. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1207. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1208. "0315 Ring %d issue: portCmdGet %d "
  1209. "is bigger than cmd ring %d\n",
  1210. pring->ringno,
  1211. pring->local_getidx, max_cmd_idx);
  1212. phba->link_state = LPFC_HBA_ERROR;
  1213. /*
  1214. * All error attention handlers are posted to
  1215. * worker thread
  1216. */
  1217. phba->work_ha |= HA_ERATT;
  1218. phba->work_hs = HS_FFER3;
  1219. lpfc_worker_wake_up(phba);
  1220. return NULL;
  1221. }
  1222. if (pring->local_getidx == pring->next_cmdidx)
  1223. return NULL;
  1224. }
  1225. return lpfc_cmd_iocb(phba, pring);
  1226. }
  1227. /**
  1228. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1229. * @phba: Pointer to HBA context object.
  1230. * @iocbq: Pointer to driver iocb object.
  1231. *
  1232. * This function gets an iotag for the iocb. If there is no unused iotag and
  1233. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1234. * array and assigns a new iotag.
  1235. * The function returns the allocated iotag if successful, else returns zero.
  1236. * Zero is not a valid iotag.
  1237. * The caller is not required to hold any lock.
  1238. **/
  1239. uint16_t
  1240. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1241. {
  1242. struct lpfc_iocbq **new_arr;
  1243. struct lpfc_iocbq **old_arr;
  1244. size_t new_len;
  1245. struct lpfc_sli *psli = &phba->sli;
  1246. uint16_t iotag;
  1247. spin_lock_irq(&phba->hbalock);
  1248. iotag = psli->last_iotag;
  1249. if(++iotag < psli->iocbq_lookup_len) {
  1250. psli->last_iotag = iotag;
  1251. psli->iocbq_lookup[iotag] = iocbq;
  1252. spin_unlock_irq(&phba->hbalock);
  1253. iocbq->iotag = iotag;
  1254. return iotag;
  1255. } else if (psli->iocbq_lookup_len < (0xffff
  1256. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1257. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1258. spin_unlock_irq(&phba->hbalock);
  1259. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1260. GFP_KERNEL);
  1261. if (new_arr) {
  1262. spin_lock_irq(&phba->hbalock);
  1263. old_arr = psli->iocbq_lookup;
  1264. if (new_len <= psli->iocbq_lookup_len) {
  1265. /* highly unprobable case */
  1266. kfree(new_arr);
  1267. iotag = psli->last_iotag;
  1268. if(++iotag < psli->iocbq_lookup_len) {
  1269. psli->last_iotag = iotag;
  1270. psli->iocbq_lookup[iotag] = iocbq;
  1271. spin_unlock_irq(&phba->hbalock);
  1272. iocbq->iotag = iotag;
  1273. return iotag;
  1274. }
  1275. spin_unlock_irq(&phba->hbalock);
  1276. return 0;
  1277. }
  1278. if (psli->iocbq_lookup)
  1279. memcpy(new_arr, old_arr,
  1280. ((psli->last_iotag + 1) *
  1281. sizeof (struct lpfc_iocbq *)));
  1282. psli->iocbq_lookup = new_arr;
  1283. psli->iocbq_lookup_len = new_len;
  1284. psli->last_iotag = iotag;
  1285. psli->iocbq_lookup[iotag] = iocbq;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. iocbq->iotag = iotag;
  1288. kfree(old_arr);
  1289. return iotag;
  1290. }
  1291. } else
  1292. spin_unlock_irq(&phba->hbalock);
  1293. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1294. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1295. psli->last_iotag);
  1296. return 0;
  1297. }
  1298. /**
  1299. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1300. * @phba: Pointer to HBA context object.
  1301. * @pring: Pointer to driver SLI ring object.
  1302. * @iocb: Pointer to iocb slot in the ring.
  1303. * @nextiocb: Pointer to driver iocb object which need to be
  1304. * posted to firmware.
  1305. *
  1306. * This function is called with hbalock held to post a new iocb to
  1307. * the firmware. This function copies the new iocb to ring iocb slot and
  1308. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1309. * a completion call back for this iocb else the function will free the
  1310. * iocb object.
  1311. **/
  1312. static void
  1313. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1314. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1315. {
  1316. /*
  1317. * Set up an iotag
  1318. */
  1319. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1320. if (pring->ringno == LPFC_ELS_RING) {
  1321. lpfc_debugfs_slow_ring_trc(phba,
  1322. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1323. *(((uint32_t *) &nextiocb->iocb) + 4),
  1324. *(((uint32_t *) &nextiocb->iocb) + 6),
  1325. *(((uint32_t *) &nextiocb->iocb) + 7));
  1326. }
  1327. /*
  1328. * Issue iocb command to adapter
  1329. */
  1330. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1331. wmb();
  1332. pring->stats.iocb_cmd++;
  1333. /*
  1334. * If there is no completion routine to call, we can release the
  1335. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1336. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1337. */
  1338. if (nextiocb->iocb_cmpl)
  1339. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1340. else
  1341. __lpfc_sli_release_iocbq(phba, nextiocb);
  1342. /*
  1343. * Let the HBA know what IOCB slot will be the next one the
  1344. * driver will put a command into.
  1345. */
  1346. pring->cmdidx = pring->next_cmdidx;
  1347. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1348. }
  1349. /**
  1350. * lpfc_sli_update_full_ring - Update the chip attention register
  1351. * @phba: Pointer to HBA context object.
  1352. * @pring: Pointer to driver SLI ring object.
  1353. *
  1354. * The caller is not required to hold any lock for calling this function.
  1355. * This function updates the chip attention bits for the ring to inform firmware
  1356. * that there are pending work to be done for this ring and requests an
  1357. * interrupt when there is space available in the ring. This function is
  1358. * called when the driver is unable to post more iocbs to the ring due
  1359. * to unavailability of space in the ring.
  1360. **/
  1361. static void
  1362. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1363. {
  1364. int ringno = pring->ringno;
  1365. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1366. wmb();
  1367. /*
  1368. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1369. * The HBA will tell us when an IOCB entry is available.
  1370. */
  1371. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1372. readl(phba->CAregaddr); /* flush */
  1373. pring->stats.iocb_cmd_full++;
  1374. }
  1375. /**
  1376. * lpfc_sli_update_ring - Update chip attention register
  1377. * @phba: Pointer to HBA context object.
  1378. * @pring: Pointer to driver SLI ring object.
  1379. *
  1380. * This function updates the chip attention register bit for the
  1381. * given ring to inform HBA that there is more work to be done
  1382. * in this ring. The caller is not required to hold any lock.
  1383. **/
  1384. static void
  1385. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1386. {
  1387. int ringno = pring->ringno;
  1388. /*
  1389. * Tell the HBA that there is work to do in this ring.
  1390. */
  1391. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1392. wmb();
  1393. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1394. readl(phba->CAregaddr); /* flush */
  1395. }
  1396. }
  1397. /**
  1398. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1399. * @phba: Pointer to HBA context object.
  1400. * @pring: Pointer to driver SLI ring object.
  1401. *
  1402. * This function is called with hbalock held to post pending iocbs
  1403. * in the txq to the firmware. This function is called when driver
  1404. * detects space available in the ring.
  1405. **/
  1406. static void
  1407. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1408. {
  1409. IOCB_t *iocb;
  1410. struct lpfc_iocbq *nextiocb;
  1411. /*
  1412. * Check to see if:
  1413. * (a) there is anything on the txq to send
  1414. * (b) link is up
  1415. * (c) link attention events can be processed (fcp ring only)
  1416. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1417. */
  1418. if (pring->txq_cnt &&
  1419. lpfc_is_link_up(phba) &&
  1420. (pring->ringno != phba->sli.fcp_ring ||
  1421. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1422. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1423. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1424. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1425. if (iocb)
  1426. lpfc_sli_update_ring(phba, pring);
  1427. else
  1428. lpfc_sli_update_full_ring(phba, pring);
  1429. }
  1430. return;
  1431. }
  1432. /**
  1433. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1434. * @phba: Pointer to HBA context object.
  1435. * @hbqno: HBQ number.
  1436. *
  1437. * This function is called with hbalock held to get the next
  1438. * available slot for the given HBQ. If there is free slot
  1439. * available for the HBQ it will return pointer to the next available
  1440. * HBQ entry else it will return NULL.
  1441. **/
  1442. static struct lpfc_hbq_entry *
  1443. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1444. {
  1445. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1446. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1447. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1448. hbqp->next_hbqPutIdx = 0;
  1449. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1450. uint32_t raw_index = phba->hbq_get[hbqno];
  1451. uint32_t getidx = le32_to_cpu(raw_index);
  1452. hbqp->local_hbqGetIdx = getidx;
  1453. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1454. lpfc_printf_log(phba, KERN_ERR,
  1455. LOG_SLI | LOG_VPORT,
  1456. "1802 HBQ %d: local_hbqGetIdx "
  1457. "%u is > than hbqp->entry_count %u\n",
  1458. hbqno, hbqp->local_hbqGetIdx,
  1459. hbqp->entry_count);
  1460. phba->link_state = LPFC_HBA_ERROR;
  1461. return NULL;
  1462. }
  1463. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1464. return NULL;
  1465. }
  1466. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1467. hbqp->hbqPutIdx;
  1468. }
  1469. /**
  1470. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1471. * @phba: Pointer to HBA context object.
  1472. *
  1473. * This function is called with no lock held to free all the
  1474. * hbq buffers while uninitializing the SLI interface. It also
  1475. * frees the HBQ buffers returned by the firmware but not yet
  1476. * processed by the upper layers.
  1477. **/
  1478. void
  1479. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1480. {
  1481. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1482. struct hbq_dmabuf *hbq_buf;
  1483. unsigned long flags;
  1484. int i, hbq_count;
  1485. uint32_t hbqno;
  1486. hbq_count = lpfc_sli_hbq_count();
  1487. /* Return all memory used by all HBQs */
  1488. spin_lock_irqsave(&phba->hbalock, flags);
  1489. for (i = 0; i < hbq_count; ++i) {
  1490. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1491. &phba->hbqs[i].hbq_buffer_list, list) {
  1492. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1493. list_del(&hbq_buf->dbuf.list);
  1494. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1495. }
  1496. phba->hbqs[i].buffer_count = 0;
  1497. }
  1498. /* Return all HBQ buffer that are in-fly */
  1499. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1500. list) {
  1501. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1502. list_del(&hbq_buf->dbuf.list);
  1503. if (hbq_buf->tag == -1) {
  1504. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1505. (phba, hbq_buf);
  1506. } else {
  1507. hbqno = hbq_buf->tag >> 16;
  1508. if (hbqno >= LPFC_MAX_HBQS)
  1509. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1510. (phba, hbq_buf);
  1511. else
  1512. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1513. hbq_buf);
  1514. }
  1515. }
  1516. /* Mark the HBQs not in use */
  1517. phba->hbq_in_use = 0;
  1518. spin_unlock_irqrestore(&phba->hbalock, flags);
  1519. }
  1520. /**
  1521. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1522. * @phba: Pointer to HBA context object.
  1523. * @hbqno: HBQ number.
  1524. * @hbq_buf: Pointer to HBQ buffer.
  1525. *
  1526. * This function is called with the hbalock held to post a
  1527. * hbq buffer to the firmware. If the function finds an empty
  1528. * slot in the HBQ, it will post the buffer. The function will return
  1529. * pointer to the hbq entry if it successfully post the buffer
  1530. * else it will return NULL.
  1531. **/
  1532. static int
  1533. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1534. struct hbq_dmabuf *hbq_buf)
  1535. {
  1536. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1537. }
  1538. /**
  1539. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1540. * @phba: Pointer to HBA context object.
  1541. * @hbqno: HBQ number.
  1542. * @hbq_buf: Pointer to HBQ buffer.
  1543. *
  1544. * This function is called with the hbalock held to post a hbq buffer to the
  1545. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1546. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1547. * it successfully post the buffer else it will return an error.
  1548. **/
  1549. static int
  1550. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1551. struct hbq_dmabuf *hbq_buf)
  1552. {
  1553. struct lpfc_hbq_entry *hbqe;
  1554. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1555. /* Get next HBQ entry slot to use */
  1556. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1557. if (hbqe) {
  1558. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1559. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1560. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1561. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1562. hbqe->bde.tus.f.bdeFlags = 0;
  1563. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1564. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1565. /* Sync SLIM */
  1566. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1567. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1568. /* flush */
  1569. readl(phba->hbq_put + hbqno);
  1570. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1571. return 0;
  1572. } else
  1573. return -ENOMEM;
  1574. }
  1575. /**
  1576. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1577. * @phba: Pointer to HBA context object.
  1578. * @hbqno: HBQ number.
  1579. * @hbq_buf: Pointer to HBQ buffer.
  1580. *
  1581. * This function is called with the hbalock held to post an RQE to the SLI4
  1582. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1583. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1584. **/
  1585. static int
  1586. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1587. struct hbq_dmabuf *hbq_buf)
  1588. {
  1589. int rc;
  1590. struct lpfc_rqe hrqe;
  1591. struct lpfc_rqe drqe;
  1592. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1593. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1594. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1595. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1596. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1597. &hrqe, &drqe);
  1598. if (rc < 0)
  1599. return rc;
  1600. hbq_buf->tag = rc;
  1601. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1602. return 0;
  1603. }
  1604. /* HBQ for ELS and CT traffic. */
  1605. static struct lpfc_hbq_init lpfc_els_hbq = {
  1606. .rn = 1,
  1607. .entry_count = 256,
  1608. .mask_count = 0,
  1609. .profile = 0,
  1610. .ring_mask = (1 << LPFC_ELS_RING),
  1611. .buffer_count = 0,
  1612. .init_count = 40,
  1613. .add_count = 40,
  1614. };
  1615. /* HBQ for the extra ring if needed */
  1616. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1617. .rn = 1,
  1618. .entry_count = 200,
  1619. .mask_count = 0,
  1620. .profile = 0,
  1621. .ring_mask = (1 << LPFC_EXTRA_RING),
  1622. .buffer_count = 0,
  1623. .init_count = 0,
  1624. .add_count = 5,
  1625. };
  1626. /* Array of HBQs */
  1627. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1628. &lpfc_els_hbq,
  1629. &lpfc_extra_hbq,
  1630. };
  1631. /**
  1632. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1633. * @phba: Pointer to HBA context object.
  1634. * @hbqno: HBQ number.
  1635. * @count: Number of HBQ buffers to be posted.
  1636. *
  1637. * This function is called with no lock held to post more hbq buffers to the
  1638. * given HBQ. The function returns the number of HBQ buffers successfully
  1639. * posted.
  1640. **/
  1641. static int
  1642. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1643. {
  1644. uint32_t i, posted = 0;
  1645. unsigned long flags;
  1646. struct hbq_dmabuf *hbq_buffer;
  1647. LIST_HEAD(hbq_buf_list);
  1648. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1649. return 0;
  1650. if ((phba->hbqs[hbqno].buffer_count + count) >
  1651. lpfc_hbq_defs[hbqno]->entry_count)
  1652. count = lpfc_hbq_defs[hbqno]->entry_count -
  1653. phba->hbqs[hbqno].buffer_count;
  1654. if (!count)
  1655. return 0;
  1656. /* Allocate HBQ entries */
  1657. for (i = 0; i < count; i++) {
  1658. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1659. if (!hbq_buffer)
  1660. break;
  1661. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1662. }
  1663. /* Check whether HBQ is still in use */
  1664. spin_lock_irqsave(&phba->hbalock, flags);
  1665. if (!phba->hbq_in_use)
  1666. goto err;
  1667. while (!list_empty(&hbq_buf_list)) {
  1668. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1669. dbuf.list);
  1670. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1671. (hbqno << 16));
  1672. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1673. phba->hbqs[hbqno].buffer_count++;
  1674. posted++;
  1675. } else
  1676. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1677. }
  1678. spin_unlock_irqrestore(&phba->hbalock, flags);
  1679. return posted;
  1680. err:
  1681. spin_unlock_irqrestore(&phba->hbalock, flags);
  1682. while (!list_empty(&hbq_buf_list)) {
  1683. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1684. dbuf.list);
  1685. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1686. }
  1687. return 0;
  1688. }
  1689. /**
  1690. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1691. * @phba: Pointer to HBA context object.
  1692. * @qno: HBQ number.
  1693. *
  1694. * This function posts more buffers to the HBQ. This function
  1695. * is called with no lock held. The function returns the number of HBQ entries
  1696. * successfully allocated.
  1697. **/
  1698. int
  1699. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1700. {
  1701. if (phba->sli_rev == LPFC_SLI_REV4)
  1702. return 0;
  1703. else
  1704. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1705. lpfc_hbq_defs[qno]->add_count);
  1706. }
  1707. /**
  1708. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1709. * @phba: Pointer to HBA context object.
  1710. * @qno: HBQ queue number.
  1711. *
  1712. * This function is called from SLI initialization code path with
  1713. * no lock held to post initial HBQ buffers to firmware. The
  1714. * function returns the number of HBQ entries successfully allocated.
  1715. **/
  1716. static int
  1717. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1718. {
  1719. if (phba->sli_rev == LPFC_SLI_REV4)
  1720. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1721. lpfc_hbq_defs[qno]->entry_count);
  1722. else
  1723. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1724. lpfc_hbq_defs[qno]->init_count);
  1725. }
  1726. /**
  1727. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1728. * @phba: Pointer to HBA context object.
  1729. * @hbqno: HBQ number.
  1730. *
  1731. * This function removes the first hbq buffer on an hbq list and returns a
  1732. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1733. **/
  1734. static struct hbq_dmabuf *
  1735. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1736. {
  1737. struct lpfc_dmabuf *d_buf;
  1738. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1739. if (!d_buf)
  1740. return NULL;
  1741. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1742. }
  1743. /**
  1744. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1745. * @phba: Pointer to HBA context object.
  1746. * @tag: Tag of the hbq buffer.
  1747. *
  1748. * This function is called with hbalock held. This function searches
  1749. * for the hbq buffer associated with the given tag in the hbq buffer
  1750. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1751. * it returns NULL.
  1752. **/
  1753. static struct hbq_dmabuf *
  1754. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1755. {
  1756. struct lpfc_dmabuf *d_buf;
  1757. struct hbq_dmabuf *hbq_buf;
  1758. uint32_t hbqno;
  1759. hbqno = tag >> 16;
  1760. if (hbqno >= LPFC_MAX_HBQS)
  1761. return NULL;
  1762. spin_lock_irq(&phba->hbalock);
  1763. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1764. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1765. if (hbq_buf->tag == tag) {
  1766. spin_unlock_irq(&phba->hbalock);
  1767. return hbq_buf;
  1768. }
  1769. }
  1770. spin_unlock_irq(&phba->hbalock);
  1771. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1772. "1803 Bad hbq tag. Data: x%x x%x\n",
  1773. tag, phba->hbqs[tag >> 16].buffer_count);
  1774. return NULL;
  1775. }
  1776. /**
  1777. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1778. * @phba: Pointer to HBA context object.
  1779. * @hbq_buffer: Pointer to HBQ buffer.
  1780. *
  1781. * This function is called with hbalock. This function gives back
  1782. * the hbq buffer to firmware. If the HBQ does not have space to
  1783. * post the buffer, it will free the buffer.
  1784. **/
  1785. void
  1786. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1787. {
  1788. uint32_t hbqno;
  1789. if (hbq_buffer) {
  1790. hbqno = hbq_buffer->tag >> 16;
  1791. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1792. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1793. }
  1794. }
  1795. /**
  1796. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1797. * @mbxCommand: mailbox command code.
  1798. *
  1799. * This function is called by the mailbox event handler function to verify
  1800. * that the completed mailbox command is a legitimate mailbox command. If the
  1801. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1802. * and the mailbox event handler will take the HBA offline.
  1803. **/
  1804. static int
  1805. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1806. {
  1807. uint8_t ret;
  1808. switch (mbxCommand) {
  1809. case MBX_LOAD_SM:
  1810. case MBX_READ_NV:
  1811. case MBX_WRITE_NV:
  1812. case MBX_WRITE_VPARMS:
  1813. case MBX_RUN_BIU_DIAG:
  1814. case MBX_INIT_LINK:
  1815. case MBX_DOWN_LINK:
  1816. case MBX_CONFIG_LINK:
  1817. case MBX_CONFIG_RING:
  1818. case MBX_RESET_RING:
  1819. case MBX_READ_CONFIG:
  1820. case MBX_READ_RCONFIG:
  1821. case MBX_READ_SPARM:
  1822. case MBX_READ_STATUS:
  1823. case MBX_READ_RPI:
  1824. case MBX_READ_XRI:
  1825. case MBX_READ_REV:
  1826. case MBX_READ_LNK_STAT:
  1827. case MBX_REG_LOGIN:
  1828. case MBX_UNREG_LOGIN:
  1829. case MBX_CLEAR_LA:
  1830. case MBX_DUMP_MEMORY:
  1831. case MBX_DUMP_CONTEXT:
  1832. case MBX_RUN_DIAGS:
  1833. case MBX_RESTART:
  1834. case MBX_UPDATE_CFG:
  1835. case MBX_DOWN_LOAD:
  1836. case MBX_DEL_LD_ENTRY:
  1837. case MBX_RUN_PROGRAM:
  1838. case MBX_SET_MASK:
  1839. case MBX_SET_VARIABLE:
  1840. case MBX_UNREG_D_ID:
  1841. case MBX_KILL_BOARD:
  1842. case MBX_CONFIG_FARP:
  1843. case MBX_BEACON:
  1844. case MBX_LOAD_AREA:
  1845. case MBX_RUN_BIU_DIAG64:
  1846. case MBX_CONFIG_PORT:
  1847. case MBX_READ_SPARM64:
  1848. case MBX_READ_RPI64:
  1849. case MBX_REG_LOGIN64:
  1850. case MBX_READ_TOPOLOGY:
  1851. case MBX_WRITE_WWN:
  1852. case MBX_SET_DEBUG:
  1853. case MBX_LOAD_EXP_ROM:
  1854. case MBX_ASYNCEVT_ENABLE:
  1855. case MBX_REG_VPI:
  1856. case MBX_UNREG_VPI:
  1857. case MBX_HEARTBEAT:
  1858. case MBX_PORT_CAPABILITIES:
  1859. case MBX_PORT_IOV_CONTROL:
  1860. case MBX_SLI4_CONFIG:
  1861. case MBX_SLI4_REQ_FTRS:
  1862. case MBX_REG_FCFI:
  1863. case MBX_UNREG_FCFI:
  1864. case MBX_REG_VFI:
  1865. case MBX_UNREG_VFI:
  1866. case MBX_INIT_VPI:
  1867. case MBX_INIT_VFI:
  1868. case MBX_RESUME_RPI:
  1869. case MBX_READ_EVENT_LOG_STATUS:
  1870. case MBX_READ_EVENT_LOG:
  1871. case MBX_SECURITY_MGMT:
  1872. case MBX_AUTH_PORT:
  1873. ret = mbxCommand;
  1874. break;
  1875. default:
  1876. ret = MBX_SHUTDOWN;
  1877. break;
  1878. }
  1879. return ret;
  1880. }
  1881. /**
  1882. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1883. * @phba: Pointer to HBA context object.
  1884. * @pmboxq: Pointer to mailbox command.
  1885. *
  1886. * This is completion handler function for mailbox commands issued from
  1887. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1888. * mailbox event handler function with no lock held. This function
  1889. * will wake up thread waiting on the wait queue pointed by context1
  1890. * of the mailbox.
  1891. **/
  1892. void
  1893. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1894. {
  1895. wait_queue_head_t *pdone_q;
  1896. unsigned long drvr_flag;
  1897. /*
  1898. * If pdone_q is empty, the driver thread gave up waiting and
  1899. * continued running.
  1900. */
  1901. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1902. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1903. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1904. if (pdone_q)
  1905. wake_up_interruptible(pdone_q);
  1906. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1907. return;
  1908. }
  1909. /**
  1910. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1911. * @phba: Pointer to HBA context object.
  1912. * @pmb: Pointer to mailbox object.
  1913. *
  1914. * This function is the default mailbox completion handler. It
  1915. * frees the memory resources associated with the completed mailbox
  1916. * command. If the completed command is a REG_LOGIN mailbox command,
  1917. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1918. **/
  1919. void
  1920. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1921. {
  1922. struct lpfc_vport *vport = pmb->vport;
  1923. struct lpfc_dmabuf *mp;
  1924. struct lpfc_nodelist *ndlp;
  1925. struct Scsi_Host *shost;
  1926. uint16_t rpi, vpi;
  1927. int rc;
  1928. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1929. if (mp) {
  1930. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1931. kfree(mp);
  1932. }
  1933. /*
  1934. * If a REG_LOGIN succeeded after node is destroyed or node
  1935. * is in re-discovery driver need to cleanup the RPI.
  1936. */
  1937. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1938. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1939. !pmb->u.mb.mbxStatus) {
  1940. rpi = pmb->u.mb.un.varWords[0];
  1941. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1942. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1943. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1944. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1945. if (rc != MBX_NOT_FINISHED)
  1946. return;
  1947. }
  1948. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1949. !(phba->pport->load_flag & FC_UNLOADING) &&
  1950. !pmb->u.mb.mbxStatus) {
  1951. shost = lpfc_shost_from_vport(vport);
  1952. spin_lock_irq(shost->host_lock);
  1953. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1954. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1955. spin_unlock_irq(shost->host_lock);
  1956. }
  1957. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1958. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1959. lpfc_nlp_put(ndlp);
  1960. pmb->context2 = NULL;
  1961. }
  1962. /* Check security permission status on INIT_LINK mailbox command */
  1963. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1964. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1965. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1966. "2860 SLI authentication is required "
  1967. "for INIT_LINK but has not done yet\n");
  1968. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1969. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1970. else
  1971. mempool_free(pmb, phba->mbox_mem_pool);
  1972. }
  1973. /**
  1974. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1975. * @phba: Pointer to HBA context object.
  1976. *
  1977. * This function is called with no lock held. This function processes all
  1978. * the completed mailbox commands and gives it to upper layers. The interrupt
  1979. * service routine processes mailbox completion interrupt and adds completed
  1980. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1981. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1982. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1983. * function returns the mailbox commands to the upper layer by calling the
  1984. * completion handler function of each mailbox.
  1985. **/
  1986. int
  1987. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1988. {
  1989. MAILBOX_t *pmbox;
  1990. LPFC_MBOXQ_t *pmb;
  1991. int rc;
  1992. LIST_HEAD(cmplq);
  1993. phba->sli.slistat.mbox_event++;
  1994. /* Get all completed mailboxe buffers into the cmplq */
  1995. spin_lock_irq(&phba->hbalock);
  1996. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1997. spin_unlock_irq(&phba->hbalock);
  1998. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1999. do {
  2000. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2001. if (pmb == NULL)
  2002. break;
  2003. pmbox = &pmb->u.mb;
  2004. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2005. if (pmb->vport) {
  2006. lpfc_debugfs_disc_trc(pmb->vport,
  2007. LPFC_DISC_TRC_MBOX_VPORT,
  2008. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2009. (uint32_t)pmbox->mbxCommand,
  2010. pmbox->un.varWords[0],
  2011. pmbox->un.varWords[1]);
  2012. }
  2013. else {
  2014. lpfc_debugfs_disc_trc(phba->pport,
  2015. LPFC_DISC_TRC_MBOX,
  2016. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2017. (uint32_t)pmbox->mbxCommand,
  2018. pmbox->un.varWords[0],
  2019. pmbox->un.varWords[1]);
  2020. }
  2021. }
  2022. /*
  2023. * It is a fatal error if unknown mbox command completion.
  2024. */
  2025. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2026. MBX_SHUTDOWN) {
  2027. /* Unknown mailbox command compl */
  2028. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2029. "(%d):0323 Unknown Mailbox command "
  2030. "x%x (x%x) Cmpl\n",
  2031. pmb->vport ? pmb->vport->vpi : 0,
  2032. pmbox->mbxCommand,
  2033. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2034. phba->link_state = LPFC_HBA_ERROR;
  2035. phba->work_hs = HS_FFER3;
  2036. lpfc_handle_eratt(phba);
  2037. continue;
  2038. }
  2039. if (pmbox->mbxStatus) {
  2040. phba->sli.slistat.mbox_stat_err++;
  2041. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2042. /* Mbox cmd cmpl error - RETRYing */
  2043. lpfc_printf_log(phba, KERN_INFO,
  2044. LOG_MBOX | LOG_SLI,
  2045. "(%d):0305 Mbox cmd cmpl "
  2046. "error - RETRYing Data: x%x "
  2047. "(x%x) x%x x%x x%x\n",
  2048. pmb->vport ? pmb->vport->vpi :0,
  2049. pmbox->mbxCommand,
  2050. lpfc_sli4_mbox_opcode_get(phba,
  2051. pmb),
  2052. pmbox->mbxStatus,
  2053. pmbox->un.varWords[0],
  2054. pmb->vport->port_state);
  2055. pmbox->mbxStatus = 0;
  2056. pmbox->mbxOwner = OWN_HOST;
  2057. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2058. if (rc != MBX_NOT_FINISHED)
  2059. continue;
  2060. }
  2061. }
  2062. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2063. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2064. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2065. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2066. pmb->vport ? pmb->vport->vpi : 0,
  2067. pmbox->mbxCommand,
  2068. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2069. pmb->mbox_cmpl,
  2070. *((uint32_t *) pmbox),
  2071. pmbox->un.varWords[0],
  2072. pmbox->un.varWords[1],
  2073. pmbox->un.varWords[2],
  2074. pmbox->un.varWords[3],
  2075. pmbox->un.varWords[4],
  2076. pmbox->un.varWords[5],
  2077. pmbox->un.varWords[6],
  2078. pmbox->un.varWords[7]);
  2079. if (pmb->mbox_cmpl)
  2080. pmb->mbox_cmpl(phba,pmb);
  2081. } while (1);
  2082. return 0;
  2083. }
  2084. /**
  2085. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2086. * @phba: Pointer to HBA context object.
  2087. * @pring: Pointer to driver SLI ring object.
  2088. * @tag: buffer tag.
  2089. *
  2090. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2091. * is set in the tag the buffer is posted for a particular exchange,
  2092. * the function will return the buffer without replacing the buffer.
  2093. * If the buffer is for unsolicited ELS or CT traffic, this function
  2094. * returns the buffer and also posts another buffer to the firmware.
  2095. **/
  2096. static struct lpfc_dmabuf *
  2097. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2098. struct lpfc_sli_ring *pring,
  2099. uint32_t tag)
  2100. {
  2101. struct hbq_dmabuf *hbq_entry;
  2102. if (tag & QUE_BUFTAG_BIT)
  2103. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2104. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2105. if (!hbq_entry)
  2106. return NULL;
  2107. return &hbq_entry->dbuf;
  2108. }
  2109. /**
  2110. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2111. * @phba: Pointer to HBA context object.
  2112. * @pring: Pointer to driver SLI ring object.
  2113. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2114. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2115. * @fch_type: the type for the first frame of the sequence.
  2116. *
  2117. * This function is called with no lock held. This function uses the r_ctl and
  2118. * type of the received sequence to find the correct callback function to call
  2119. * to process the sequence.
  2120. **/
  2121. static int
  2122. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2123. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2124. uint32_t fch_type)
  2125. {
  2126. int i;
  2127. /* unSolicited Responses */
  2128. if (pring->prt[0].profile) {
  2129. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2130. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2131. saveq);
  2132. return 1;
  2133. }
  2134. /* We must search, based on rctl / type
  2135. for the right routine */
  2136. for (i = 0; i < pring->num_mask; i++) {
  2137. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2138. (pring->prt[i].type == fch_type)) {
  2139. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2140. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2141. (phba, pring, saveq);
  2142. return 1;
  2143. }
  2144. }
  2145. return 0;
  2146. }
  2147. /**
  2148. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2149. * @phba: Pointer to HBA context object.
  2150. * @pring: Pointer to driver SLI ring object.
  2151. * @saveq: Pointer to the unsolicited iocb.
  2152. *
  2153. * This function is called with no lock held by the ring event handler
  2154. * when there is an unsolicited iocb posted to the response ring by the
  2155. * firmware. This function gets the buffer associated with the iocbs
  2156. * and calls the event handler for the ring. This function handles both
  2157. * qring buffers and hbq buffers.
  2158. * When the function returns 1 the caller can free the iocb object otherwise
  2159. * upper layer functions will free the iocb objects.
  2160. **/
  2161. static int
  2162. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2163. struct lpfc_iocbq *saveq)
  2164. {
  2165. IOCB_t * irsp;
  2166. WORD5 * w5p;
  2167. uint32_t Rctl, Type;
  2168. uint32_t match;
  2169. struct lpfc_iocbq *iocbq;
  2170. struct lpfc_dmabuf *dmzbuf;
  2171. match = 0;
  2172. irsp = &(saveq->iocb);
  2173. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2174. if (pring->lpfc_sli_rcv_async_status)
  2175. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2176. else
  2177. lpfc_printf_log(phba,
  2178. KERN_WARNING,
  2179. LOG_SLI,
  2180. "0316 Ring %d handler: unexpected "
  2181. "ASYNC_STATUS iocb received evt_code "
  2182. "0x%x\n",
  2183. pring->ringno,
  2184. irsp->un.asyncstat.evt_code);
  2185. return 1;
  2186. }
  2187. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2188. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2189. if (irsp->ulpBdeCount > 0) {
  2190. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2191. irsp->un.ulpWord[3]);
  2192. lpfc_in_buf_free(phba, dmzbuf);
  2193. }
  2194. if (irsp->ulpBdeCount > 1) {
  2195. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2196. irsp->unsli3.sli3Words[3]);
  2197. lpfc_in_buf_free(phba, dmzbuf);
  2198. }
  2199. if (irsp->ulpBdeCount > 2) {
  2200. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2201. irsp->unsli3.sli3Words[7]);
  2202. lpfc_in_buf_free(phba, dmzbuf);
  2203. }
  2204. return 1;
  2205. }
  2206. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2207. if (irsp->ulpBdeCount != 0) {
  2208. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2209. irsp->un.ulpWord[3]);
  2210. if (!saveq->context2)
  2211. lpfc_printf_log(phba,
  2212. KERN_ERR,
  2213. LOG_SLI,
  2214. "0341 Ring %d Cannot find buffer for "
  2215. "an unsolicited iocb. tag 0x%x\n",
  2216. pring->ringno,
  2217. irsp->un.ulpWord[3]);
  2218. }
  2219. if (irsp->ulpBdeCount == 2) {
  2220. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2221. irsp->unsli3.sli3Words[7]);
  2222. if (!saveq->context3)
  2223. lpfc_printf_log(phba,
  2224. KERN_ERR,
  2225. LOG_SLI,
  2226. "0342 Ring %d Cannot find buffer for an"
  2227. " unsolicited iocb. tag 0x%x\n",
  2228. pring->ringno,
  2229. irsp->unsli3.sli3Words[7]);
  2230. }
  2231. list_for_each_entry(iocbq, &saveq->list, list) {
  2232. irsp = &(iocbq->iocb);
  2233. if (irsp->ulpBdeCount != 0) {
  2234. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2235. irsp->un.ulpWord[3]);
  2236. if (!iocbq->context2)
  2237. lpfc_printf_log(phba,
  2238. KERN_ERR,
  2239. LOG_SLI,
  2240. "0343 Ring %d Cannot find "
  2241. "buffer for an unsolicited iocb"
  2242. ". tag 0x%x\n", pring->ringno,
  2243. irsp->un.ulpWord[3]);
  2244. }
  2245. if (irsp->ulpBdeCount == 2) {
  2246. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2247. irsp->unsli3.sli3Words[7]);
  2248. if (!iocbq->context3)
  2249. lpfc_printf_log(phba,
  2250. KERN_ERR,
  2251. LOG_SLI,
  2252. "0344 Ring %d Cannot find "
  2253. "buffer for an unsolicited "
  2254. "iocb. tag 0x%x\n",
  2255. pring->ringno,
  2256. irsp->unsli3.sli3Words[7]);
  2257. }
  2258. }
  2259. }
  2260. if (irsp->ulpBdeCount != 0 &&
  2261. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2262. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2263. int found = 0;
  2264. /* search continue save q for same XRI */
  2265. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2266. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2267. list_add_tail(&saveq->list, &iocbq->list);
  2268. found = 1;
  2269. break;
  2270. }
  2271. }
  2272. if (!found)
  2273. list_add_tail(&saveq->clist,
  2274. &pring->iocb_continue_saveq);
  2275. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2276. list_del_init(&iocbq->clist);
  2277. saveq = iocbq;
  2278. irsp = &(saveq->iocb);
  2279. } else
  2280. return 0;
  2281. }
  2282. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2283. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2284. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2285. Rctl = FC_RCTL_ELS_REQ;
  2286. Type = FC_TYPE_ELS;
  2287. } else {
  2288. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2289. Rctl = w5p->hcsw.Rctl;
  2290. Type = w5p->hcsw.Type;
  2291. /* Firmware Workaround */
  2292. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2293. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2294. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2295. Rctl = FC_RCTL_ELS_REQ;
  2296. Type = FC_TYPE_ELS;
  2297. w5p->hcsw.Rctl = Rctl;
  2298. w5p->hcsw.Type = Type;
  2299. }
  2300. }
  2301. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2302. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2303. "0313 Ring %d handler: unexpected Rctl x%x "
  2304. "Type x%x received\n",
  2305. pring->ringno, Rctl, Type);
  2306. return 1;
  2307. }
  2308. /**
  2309. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2310. * @phba: Pointer to HBA context object.
  2311. * @pring: Pointer to driver SLI ring object.
  2312. * @prspiocb: Pointer to response iocb object.
  2313. *
  2314. * This function looks up the iocb_lookup table to get the command iocb
  2315. * corresponding to the given response iocb using the iotag of the
  2316. * response iocb. This function is called with the hbalock held.
  2317. * This function returns the command iocb object if it finds the command
  2318. * iocb else returns NULL.
  2319. **/
  2320. static struct lpfc_iocbq *
  2321. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2322. struct lpfc_sli_ring *pring,
  2323. struct lpfc_iocbq *prspiocb)
  2324. {
  2325. struct lpfc_iocbq *cmd_iocb = NULL;
  2326. uint16_t iotag;
  2327. iotag = prspiocb->iocb.ulpIoTag;
  2328. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2329. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2330. list_del_init(&cmd_iocb->list);
  2331. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2332. pring->txcmplq_cnt--;
  2333. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2334. }
  2335. return cmd_iocb;
  2336. }
  2337. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2338. "0317 iotag x%x is out off "
  2339. "range: max iotag x%x wd0 x%x\n",
  2340. iotag, phba->sli.last_iotag,
  2341. *(((uint32_t *) &prspiocb->iocb) + 7));
  2342. return NULL;
  2343. }
  2344. /**
  2345. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2346. * @phba: Pointer to HBA context object.
  2347. * @pring: Pointer to driver SLI ring object.
  2348. * @iotag: IOCB tag.
  2349. *
  2350. * This function looks up the iocb_lookup table to get the command iocb
  2351. * corresponding to the given iotag. This function is called with the
  2352. * hbalock held.
  2353. * This function returns the command iocb object if it finds the command
  2354. * iocb else returns NULL.
  2355. **/
  2356. static struct lpfc_iocbq *
  2357. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2358. struct lpfc_sli_ring *pring, uint16_t iotag)
  2359. {
  2360. struct lpfc_iocbq *cmd_iocb;
  2361. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2362. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2363. list_del_init(&cmd_iocb->list);
  2364. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2365. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2366. pring->txcmplq_cnt--;
  2367. }
  2368. return cmd_iocb;
  2369. }
  2370. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2371. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2372. iotag, phba->sli.last_iotag);
  2373. return NULL;
  2374. }
  2375. /**
  2376. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2377. * @phba: Pointer to HBA context object.
  2378. * @pring: Pointer to driver SLI ring object.
  2379. * @saveq: Pointer to the response iocb to be processed.
  2380. *
  2381. * This function is called by the ring event handler for non-fcp
  2382. * rings when there is a new response iocb in the response ring.
  2383. * The caller is not required to hold any locks. This function
  2384. * gets the command iocb associated with the response iocb and
  2385. * calls the completion handler for the command iocb. If there
  2386. * is no completion handler, the function will free the resources
  2387. * associated with command iocb. If the response iocb is for
  2388. * an already aborted command iocb, the status of the completion
  2389. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2390. * This function always returns 1.
  2391. **/
  2392. static int
  2393. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2394. struct lpfc_iocbq *saveq)
  2395. {
  2396. struct lpfc_iocbq *cmdiocbp;
  2397. int rc = 1;
  2398. unsigned long iflag;
  2399. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2400. spin_lock_irqsave(&phba->hbalock, iflag);
  2401. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2402. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2403. if (cmdiocbp) {
  2404. if (cmdiocbp->iocb_cmpl) {
  2405. /*
  2406. * If an ELS command failed send an event to mgmt
  2407. * application.
  2408. */
  2409. if (saveq->iocb.ulpStatus &&
  2410. (pring->ringno == LPFC_ELS_RING) &&
  2411. (cmdiocbp->iocb.ulpCommand ==
  2412. CMD_ELS_REQUEST64_CR))
  2413. lpfc_send_els_failure_event(phba,
  2414. cmdiocbp, saveq);
  2415. /*
  2416. * Post all ELS completions to the worker thread.
  2417. * All other are passed to the completion callback.
  2418. */
  2419. if (pring->ringno == LPFC_ELS_RING) {
  2420. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2421. (cmdiocbp->iocb_flag &
  2422. LPFC_DRIVER_ABORTED)) {
  2423. spin_lock_irqsave(&phba->hbalock,
  2424. iflag);
  2425. cmdiocbp->iocb_flag &=
  2426. ~LPFC_DRIVER_ABORTED;
  2427. spin_unlock_irqrestore(&phba->hbalock,
  2428. iflag);
  2429. saveq->iocb.ulpStatus =
  2430. IOSTAT_LOCAL_REJECT;
  2431. saveq->iocb.un.ulpWord[4] =
  2432. IOERR_SLI_ABORTED;
  2433. /* Firmware could still be in progress
  2434. * of DMAing payload, so don't free data
  2435. * buffer till after a hbeat.
  2436. */
  2437. spin_lock_irqsave(&phba->hbalock,
  2438. iflag);
  2439. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2440. spin_unlock_irqrestore(&phba->hbalock,
  2441. iflag);
  2442. }
  2443. if (phba->sli_rev == LPFC_SLI_REV4) {
  2444. if (saveq->iocb_flag &
  2445. LPFC_EXCHANGE_BUSY) {
  2446. /* Set cmdiocb flag for the
  2447. * exchange busy so sgl (xri)
  2448. * will not be released until
  2449. * the abort xri is received
  2450. * from hba.
  2451. */
  2452. spin_lock_irqsave(
  2453. &phba->hbalock, iflag);
  2454. cmdiocbp->iocb_flag |=
  2455. LPFC_EXCHANGE_BUSY;
  2456. spin_unlock_irqrestore(
  2457. &phba->hbalock, iflag);
  2458. }
  2459. if (cmdiocbp->iocb_flag &
  2460. LPFC_DRIVER_ABORTED) {
  2461. /*
  2462. * Clear LPFC_DRIVER_ABORTED
  2463. * bit in case it was driver
  2464. * initiated abort.
  2465. */
  2466. spin_lock_irqsave(
  2467. &phba->hbalock, iflag);
  2468. cmdiocbp->iocb_flag &=
  2469. ~LPFC_DRIVER_ABORTED;
  2470. spin_unlock_irqrestore(
  2471. &phba->hbalock, iflag);
  2472. cmdiocbp->iocb.ulpStatus =
  2473. IOSTAT_LOCAL_REJECT;
  2474. cmdiocbp->iocb.un.ulpWord[4] =
  2475. IOERR_ABORT_REQUESTED;
  2476. /*
  2477. * For SLI4, irsiocb contains
  2478. * NO_XRI in sli_xritag, it
  2479. * shall not affect releasing
  2480. * sgl (xri) process.
  2481. */
  2482. saveq->iocb.ulpStatus =
  2483. IOSTAT_LOCAL_REJECT;
  2484. saveq->iocb.un.ulpWord[4] =
  2485. IOERR_SLI_ABORTED;
  2486. spin_lock_irqsave(
  2487. &phba->hbalock, iflag);
  2488. saveq->iocb_flag |=
  2489. LPFC_DELAY_MEM_FREE;
  2490. spin_unlock_irqrestore(
  2491. &phba->hbalock, iflag);
  2492. }
  2493. }
  2494. }
  2495. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2496. } else
  2497. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2498. } else {
  2499. /*
  2500. * Unknown initiating command based on the response iotag.
  2501. * This could be the case on the ELS ring because of
  2502. * lpfc_els_abort().
  2503. */
  2504. if (pring->ringno != LPFC_ELS_RING) {
  2505. /*
  2506. * Ring <ringno> handler: unexpected completion IoTag
  2507. * <IoTag>
  2508. */
  2509. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2510. "0322 Ring %d handler: "
  2511. "unexpected completion IoTag x%x "
  2512. "Data: x%x x%x x%x x%x\n",
  2513. pring->ringno,
  2514. saveq->iocb.ulpIoTag,
  2515. saveq->iocb.ulpStatus,
  2516. saveq->iocb.un.ulpWord[4],
  2517. saveq->iocb.ulpCommand,
  2518. saveq->iocb.ulpContext);
  2519. }
  2520. }
  2521. return rc;
  2522. }
  2523. /**
  2524. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2525. * @phba: Pointer to HBA context object.
  2526. * @pring: Pointer to driver SLI ring object.
  2527. *
  2528. * This function is called from the iocb ring event handlers when
  2529. * put pointer is ahead of the get pointer for a ring. This function signal
  2530. * an error attention condition to the worker thread and the worker
  2531. * thread will transition the HBA to offline state.
  2532. **/
  2533. static void
  2534. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2535. {
  2536. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2537. /*
  2538. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2539. * rsp ring <portRspMax>
  2540. */
  2541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2542. "0312 Ring %d handler: portRspPut %d "
  2543. "is bigger than rsp ring %d\n",
  2544. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2545. pring->numRiocb);
  2546. phba->link_state = LPFC_HBA_ERROR;
  2547. /*
  2548. * All error attention handlers are posted to
  2549. * worker thread
  2550. */
  2551. phba->work_ha |= HA_ERATT;
  2552. phba->work_hs = HS_FFER3;
  2553. lpfc_worker_wake_up(phba);
  2554. return;
  2555. }
  2556. /**
  2557. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2558. * @ptr: Pointer to address of HBA context object.
  2559. *
  2560. * This function is invoked by the Error Attention polling timer when the
  2561. * timer times out. It will check the SLI Error Attention register for
  2562. * possible attention events. If so, it will post an Error Attention event
  2563. * and wake up worker thread to process it. Otherwise, it will set up the
  2564. * Error Attention polling timer for the next poll.
  2565. **/
  2566. void lpfc_poll_eratt(unsigned long ptr)
  2567. {
  2568. struct lpfc_hba *phba;
  2569. uint32_t eratt = 0;
  2570. phba = (struct lpfc_hba *)ptr;
  2571. /* Check chip HA register for error event */
  2572. eratt = lpfc_sli_check_eratt(phba);
  2573. if (eratt)
  2574. /* Tell the worker thread there is work to do */
  2575. lpfc_worker_wake_up(phba);
  2576. else
  2577. /* Restart the timer for next eratt poll */
  2578. mod_timer(&phba->eratt_poll, jiffies +
  2579. HZ * LPFC_ERATT_POLL_INTERVAL);
  2580. return;
  2581. }
  2582. /**
  2583. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2584. * @phba: Pointer to HBA context object.
  2585. * @pring: Pointer to driver SLI ring object.
  2586. * @mask: Host attention register mask for this ring.
  2587. *
  2588. * This function is called from the interrupt context when there is a ring
  2589. * event for the fcp ring. The caller does not hold any lock.
  2590. * The function processes each response iocb in the response ring until it
  2591. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2592. * LE bit set. The function will call the completion handler of the command iocb
  2593. * if the response iocb indicates a completion for a command iocb or it is
  2594. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2595. * function if this is an unsolicited iocb.
  2596. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2597. * to check it explicitly.
  2598. */
  2599. int
  2600. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2601. struct lpfc_sli_ring *pring, uint32_t mask)
  2602. {
  2603. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2604. IOCB_t *irsp = NULL;
  2605. IOCB_t *entry = NULL;
  2606. struct lpfc_iocbq *cmdiocbq = NULL;
  2607. struct lpfc_iocbq rspiocbq;
  2608. uint32_t status;
  2609. uint32_t portRspPut, portRspMax;
  2610. int rc = 1;
  2611. lpfc_iocb_type type;
  2612. unsigned long iflag;
  2613. uint32_t rsp_cmpl = 0;
  2614. spin_lock_irqsave(&phba->hbalock, iflag);
  2615. pring->stats.iocb_event++;
  2616. /*
  2617. * The next available response entry should never exceed the maximum
  2618. * entries. If it does, treat it as an adapter hardware error.
  2619. */
  2620. portRspMax = pring->numRiocb;
  2621. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2622. if (unlikely(portRspPut >= portRspMax)) {
  2623. lpfc_sli_rsp_pointers_error(phba, pring);
  2624. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2625. return 1;
  2626. }
  2627. if (phba->fcp_ring_in_use) {
  2628. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2629. return 1;
  2630. } else
  2631. phba->fcp_ring_in_use = 1;
  2632. rmb();
  2633. while (pring->rspidx != portRspPut) {
  2634. /*
  2635. * Fetch an entry off the ring and copy it into a local data
  2636. * structure. The copy involves a byte-swap since the
  2637. * network byte order and pci byte orders are different.
  2638. */
  2639. entry = lpfc_resp_iocb(phba, pring);
  2640. phba->last_completion_time = jiffies;
  2641. if (++pring->rspidx >= portRspMax)
  2642. pring->rspidx = 0;
  2643. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2644. (uint32_t *) &rspiocbq.iocb,
  2645. phba->iocb_rsp_size);
  2646. INIT_LIST_HEAD(&(rspiocbq.list));
  2647. irsp = &rspiocbq.iocb;
  2648. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2649. pring->stats.iocb_rsp++;
  2650. rsp_cmpl++;
  2651. if (unlikely(irsp->ulpStatus)) {
  2652. /*
  2653. * If resource errors reported from HBA, reduce
  2654. * queuedepths of the SCSI device.
  2655. */
  2656. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2657. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2658. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2659. phba->lpfc_rampdown_queue_depth(phba);
  2660. spin_lock_irqsave(&phba->hbalock, iflag);
  2661. }
  2662. /* Rsp ring <ringno> error: IOCB */
  2663. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2664. "0336 Rsp Ring %d error: IOCB Data: "
  2665. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2666. pring->ringno,
  2667. irsp->un.ulpWord[0],
  2668. irsp->un.ulpWord[1],
  2669. irsp->un.ulpWord[2],
  2670. irsp->un.ulpWord[3],
  2671. irsp->un.ulpWord[4],
  2672. irsp->un.ulpWord[5],
  2673. *(uint32_t *)&irsp->un1,
  2674. *((uint32_t *)&irsp->un1 + 1));
  2675. }
  2676. switch (type) {
  2677. case LPFC_ABORT_IOCB:
  2678. case LPFC_SOL_IOCB:
  2679. /*
  2680. * Idle exchange closed via ABTS from port. No iocb
  2681. * resources need to be recovered.
  2682. */
  2683. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2684. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2685. "0333 IOCB cmd 0x%x"
  2686. " processed. Skipping"
  2687. " completion\n",
  2688. irsp->ulpCommand);
  2689. break;
  2690. }
  2691. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2692. &rspiocbq);
  2693. if (unlikely(!cmdiocbq))
  2694. break;
  2695. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2696. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2697. if (cmdiocbq->iocb_cmpl) {
  2698. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2699. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2700. &rspiocbq);
  2701. spin_lock_irqsave(&phba->hbalock, iflag);
  2702. }
  2703. break;
  2704. case LPFC_UNSOL_IOCB:
  2705. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2706. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2707. spin_lock_irqsave(&phba->hbalock, iflag);
  2708. break;
  2709. default:
  2710. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2711. char adaptermsg[LPFC_MAX_ADPTMSG];
  2712. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2713. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2714. MAX_MSG_DATA);
  2715. dev_warn(&((phba->pcidev)->dev),
  2716. "lpfc%d: %s\n",
  2717. phba->brd_no, adaptermsg);
  2718. } else {
  2719. /* Unknown IOCB command */
  2720. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2721. "0334 Unknown IOCB command "
  2722. "Data: x%x, x%x x%x x%x x%x\n",
  2723. type, irsp->ulpCommand,
  2724. irsp->ulpStatus,
  2725. irsp->ulpIoTag,
  2726. irsp->ulpContext);
  2727. }
  2728. break;
  2729. }
  2730. /*
  2731. * The response IOCB has been processed. Update the ring
  2732. * pointer in SLIM. If the port response put pointer has not
  2733. * been updated, sync the pgp->rspPutInx and fetch the new port
  2734. * response put pointer.
  2735. */
  2736. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2737. if (pring->rspidx == portRspPut)
  2738. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2739. }
  2740. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2741. pring->stats.iocb_rsp_full++;
  2742. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2743. writel(status, phba->CAregaddr);
  2744. readl(phba->CAregaddr);
  2745. }
  2746. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2747. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2748. pring->stats.iocb_cmd_empty++;
  2749. /* Force update of the local copy of cmdGetInx */
  2750. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2751. lpfc_sli_resume_iocb(phba, pring);
  2752. if ((pring->lpfc_sli_cmd_available))
  2753. (pring->lpfc_sli_cmd_available) (phba, pring);
  2754. }
  2755. phba->fcp_ring_in_use = 0;
  2756. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2757. return rc;
  2758. }
  2759. /**
  2760. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2761. * @phba: Pointer to HBA context object.
  2762. * @pring: Pointer to driver SLI ring object.
  2763. * @rspiocbp: Pointer to driver response IOCB object.
  2764. *
  2765. * This function is called from the worker thread when there is a slow-path
  2766. * response IOCB to process. This function chains all the response iocbs until
  2767. * seeing the iocb with the LE bit set. The function will call
  2768. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2769. * completion of a command iocb. The function will call the
  2770. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2771. * The function frees the resources or calls the completion handler if this
  2772. * iocb is an abort completion. The function returns NULL when the response
  2773. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2774. * this function shall chain the iocb on to the iocb_continueq and return the
  2775. * response iocb passed in.
  2776. **/
  2777. static struct lpfc_iocbq *
  2778. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2779. struct lpfc_iocbq *rspiocbp)
  2780. {
  2781. struct lpfc_iocbq *saveq;
  2782. struct lpfc_iocbq *cmdiocbp;
  2783. struct lpfc_iocbq *next_iocb;
  2784. IOCB_t *irsp = NULL;
  2785. uint32_t free_saveq;
  2786. uint8_t iocb_cmd_type;
  2787. lpfc_iocb_type type;
  2788. unsigned long iflag;
  2789. int rc;
  2790. spin_lock_irqsave(&phba->hbalock, iflag);
  2791. /* First add the response iocb to the countinueq list */
  2792. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2793. pring->iocb_continueq_cnt++;
  2794. /* Now, determine whetehr the list is completed for processing */
  2795. irsp = &rspiocbp->iocb;
  2796. if (irsp->ulpLe) {
  2797. /*
  2798. * By default, the driver expects to free all resources
  2799. * associated with this iocb completion.
  2800. */
  2801. free_saveq = 1;
  2802. saveq = list_get_first(&pring->iocb_continueq,
  2803. struct lpfc_iocbq, list);
  2804. irsp = &(saveq->iocb);
  2805. list_del_init(&pring->iocb_continueq);
  2806. pring->iocb_continueq_cnt = 0;
  2807. pring->stats.iocb_rsp++;
  2808. /*
  2809. * If resource errors reported from HBA, reduce
  2810. * queuedepths of the SCSI device.
  2811. */
  2812. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2813. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2814. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2815. phba->lpfc_rampdown_queue_depth(phba);
  2816. spin_lock_irqsave(&phba->hbalock, iflag);
  2817. }
  2818. if (irsp->ulpStatus) {
  2819. /* Rsp ring <ringno> error: IOCB */
  2820. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2821. "0328 Rsp Ring %d error: "
  2822. "IOCB Data: "
  2823. "x%x x%x x%x x%x "
  2824. "x%x x%x x%x x%x "
  2825. "x%x x%x x%x x%x "
  2826. "x%x x%x x%x x%x\n",
  2827. pring->ringno,
  2828. irsp->un.ulpWord[0],
  2829. irsp->un.ulpWord[1],
  2830. irsp->un.ulpWord[2],
  2831. irsp->un.ulpWord[3],
  2832. irsp->un.ulpWord[4],
  2833. irsp->un.ulpWord[5],
  2834. *(((uint32_t *) irsp) + 6),
  2835. *(((uint32_t *) irsp) + 7),
  2836. *(((uint32_t *) irsp) + 8),
  2837. *(((uint32_t *) irsp) + 9),
  2838. *(((uint32_t *) irsp) + 10),
  2839. *(((uint32_t *) irsp) + 11),
  2840. *(((uint32_t *) irsp) + 12),
  2841. *(((uint32_t *) irsp) + 13),
  2842. *(((uint32_t *) irsp) + 14),
  2843. *(((uint32_t *) irsp) + 15));
  2844. }
  2845. /*
  2846. * Fetch the IOCB command type and call the correct completion
  2847. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2848. * get freed back to the lpfc_iocb_list by the discovery
  2849. * kernel thread.
  2850. */
  2851. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2852. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2853. switch (type) {
  2854. case LPFC_SOL_IOCB:
  2855. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2856. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2857. spin_lock_irqsave(&phba->hbalock, iflag);
  2858. break;
  2859. case LPFC_UNSOL_IOCB:
  2860. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2861. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2862. spin_lock_irqsave(&phba->hbalock, iflag);
  2863. if (!rc)
  2864. free_saveq = 0;
  2865. break;
  2866. case LPFC_ABORT_IOCB:
  2867. cmdiocbp = NULL;
  2868. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2869. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2870. saveq);
  2871. if (cmdiocbp) {
  2872. /* Call the specified completion routine */
  2873. if (cmdiocbp->iocb_cmpl) {
  2874. spin_unlock_irqrestore(&phba->hbalock,
  2875. iflag);
  2876. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2877. saveq);
  2878. spin_lock_irqsave(&phba->hbalock,
  2879. iflag);
  2880. } else
  2881. __lpfc_sli_release_iocbq(phba,
  2882. cmdiocbp);
  2883. }
  2884. break;
  2885. case LPFC_UNKNOWN_IOCB:
  2886. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2887. char adaptermsg[LPFC_MAX_ADPTMSG];
  2888. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2889. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2890. MAX_MSG_DATA);
  2891. dev_warn(&((phba->pcidev)->dev),
  2892. "lpfc%d: %s\n",
  2893. phba->brd_no, adaptermsg);
  2894. } else {
  2895. /* Unknown IOCB command */
  2896. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2897. "0335 Unknown IOCB "
  2898. "command Data: x%x "
  2899. "x%x x%x x%x\n",
  2900. irsp->ulpCommand,
  2901. irsp->ulpStatus,
  2902. irsp->ulpIoTag,
  2903. irsp->ulpContext);
  2904. }
  2905. break;
  2906. }
  2907. if (free_saveq) {
  2908. list_for_each_entry_safe(rspiocbp, next_iocb,
  2909. &saveq->list, list) {
  2910. list_del(&rspiocbp->list);
  2911. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2912. }
  2913. __lpfc_sli_release_iocbq(phba, saveq);
  2914. }
  2915. rspiocbp = NULL;
  2916. }
  2917. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2918. return rspiocbp;
  2919. }
  2920. /**
  2921. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2922. * @phba: Pointer to HBA context object.
  2923. * @pring: Pointer to driver SLI ring object.
  2924. * @mask: Host attention register mask for this ring.
  2925. *
  2926. * This routine wraps the actual slow_ring event process routine from the
  2927. * API jump table function pointer from the lpfc_hba struct.
  2928. **/
  2929. void
  2930. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2931. struct lpfc_sli_ring *pring, uint32_t mask)
  2932. {
  2933. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2934. }
  2935. /**
  2936. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2937. * @phba: Pointer to HBA context object.
  2938. * @pring: Pointer to driver SLI ring object.
  2939. * @mask: Host attention register mask for this ring.
  2940. *
  2941. * This function is called from the worker thread when there is a ring event
  2942. * for non-fcp rings. The caller does not hold any lock. The function will
  2943. * remove each response iocb in the response ring and calls the handle
  2944. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2945. **/
  2946. static void
  2947. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2948. struct lpfc_sli_ring *pring, uint32_t mask)
  2949. {
  2950. struct lpfc_pgp *pgp;
  2951. IOCB_t *entry;
  2952. IOCB_t *irsp = NULL;
  2953. struct lpfc_iocbq *rspiocbp = NULL;
  2954. uint32_t portRspPut, portRspMax;
  2955. unsigned long iflag;
  2956. uint32_t status;
  2957. pgp = &phba->port_gp[pring->ringno];
  2958. spin_lock_irqsave(&phba->hbalock, iflag);
  2959. pring->stats.iocb_event++;
  2960. /*
  2961. * The next available response entry should never exceed the maximum
  2962. * entries. If it does, treat it as an adapter hardware error.
  2963. */
  2964. portRspMax = pring->numRiocb;
  2965. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2966. if (portRspPut >= portRspMax) {
  2967. /*
  2968. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2969. * rsp ring <portRspMax>
  2970. */
  2971. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2972. "0303 Ring %d handler: portRspPut %d "
  2973. "is bigger than rsp ring %d\n",
  2974. pring->ringno, portRspPut, portRspMax);
  2975. phba->link_state = LPFC_HBA_ERROR;
  2976. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2977. phba->work_hs = HS_FFER3;
  2978. lpfc_handle_eratt(phba);
  2979. return;
  2980. }
  2981. rmb();
  2982. while (pring->rspidx != portRspPut) {
  2983. /*
  2984. * Build a completion list and call the appropriate handler.
  2985. * The process is to get the next available response iocb, get
  2986. * a free iocb from the list, copy the response data into the
  2987. * free iocb, insert to the continuation list, and update the
  2988. * next response index to slim. This process makes response
  2989. * iocb's in the ring available to DMA as fast as possible but
  2990. * pays a penalty for a copy operation. Since the iocb is
  2991. * only 32 bytes, this penalty is considered small relative to
  2992. * the PCI reads for register values and a slim write. When
  2993. * the ulpLe field is set, the entire Command has been
  2994. * received.
  2995. */
  2996. entry = lpfc_resp_iocb(phba, pring);
  2997. phba->last_completion_time = jiffies;
  2998. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2999. if (rspiocbp == NULL) {
  3000. printk(KERN_ERR "%s: out of buffers! Failing "
  3001. "completion.\n", __func__);
  3002. break;
  3003. }
  3004. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3005. phba->iocb_rsp_size);
  3006. irsp = &rspiocbp->iocb;
  3007. if (++pring->rspidx >= portRspMax)
  3008. pring->rspidx = 0;
  3009. if (pring->ringno == LPFC_ELS_RING) {
  3010. lpfc_debugfs_slow_ring_trc(phba,
  3011. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3012. *(((uint32_t *) irsp) + 4),
  3013. *(((uint32_t *) irsp) + 6),
  3014. *(((uint32_t *) irsp) + 7));
  3015. }
  3016. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3018. /* Handle the response IOCB */
  3019. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3020. spin_lock_irqsave(&phba->hbalock, iflag);
  3021. /*
  3022. * If the port response put pointer has not been updated, sync
  3023. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3024. * response put pointer.
  3025. */
  3026. if (pring->rspidx == portRspPut) {
  3027. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3028. }
  3029. } /* while (pring->rspidx != portRspPut) */
  3030. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3031. /* At least one response entry has been freed */
  3032. pring->stats.iocb_rsp_full++;
  3033. /* SET RxRE_RSP in Chip Att register */
  3034. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3035. writel(status, phba->CAregaddr);
  3036. readl(phba->CAregaddr); /* flush */
  3037. }
  3038. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3039. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3040. pring->stats.iocb_cmd_empty++;
  3041. /* Force update of the local copy of cmdGetInx */
  3042. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3043. lpfc_sli_resume_iocb(phba, pring);
  3044. if ((pring->lpfc_sli_cmd_available))
  3045. (pring->lpfc_sli_cmd_available) (phba, pring);
  3046. }
  3047. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3048. return;
  3049. }
  3050. /**
  3051. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3052. * @phba: Pointer to HBA context object.
  3053. * @pring: Pointer to driver SLI ring object.
  3054. * @mask: Host attention register mask for this ring.
  3055. *
  3056. * This function is called from the worker thread when there is a pending
  3057. * ELS response iocb on the driver internal slow-path response iocb worker
  3058. * queue. The caller does not hold any lock. The function will remove each
  3059. * response iocb from the response worker queue and calls the handle
  3060. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3061. **/
  3062. static void
  3063. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3064. struct lpfc_sli_ring *pring, uint32_t mask)
  3065. {
  3066. struct lpfc_iocbq *irspiocbq;
  3067. struct hbq_dmabuf *dmabuf;
  3068. struct lpfc_cq_event *cq_event;
  3069. unsigned long iflag;
  3070. spin_lock_irqsave(&phba->hbalock, iflag);
  3071. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3072. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3073. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3074. /* Get the response iocb from the head of work queue */
  3075. spin_lock_irqsave(&phba->hbalock, iflag);
  3076. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3077. cq_event, struct lpfc_cq_event, list);
  3078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3079. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3080. case CQE_CODE_COMPL_WQE:
  3081. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3082. cq_event);
  3083. /* Translate ELS WCQE to response IOCBQ */
  3084. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3085. irspiocbq);
  3086. if (irspiocbq)
  3087. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3088. irspiocbq);
  3089. break;
  3090. case CQE_CODE_RECEIVE:
  3091. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3092. cq_event);
  3093. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3094. break;
  3095. default:
  3096. break;
  3097. }
  3098. }
  3099. }
  3100. /**
  3101. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3102. * @phba: Pointer to HBA context object.
  3103. * @pring: Pointer to driver SLI ring object.
  3104. *
  3105. * This function aborts all iocbs in the given ring and frees all the iocb
  3106. * objects in txq. This function issues an abort iocb for all the iocb commands
  3107. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3108. * the return of this function. The caller is not required to hold any locks.
  3109. **/
  3110. void
  3111. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3112. {
  3113. LIST_HEAD(completions);
  3114. struct lpfc_iocbq *iocb, *next_iocb;
  3115. if (pring->ringno == LPFC_ELS_RING) {
  3116. lpfc_fabric_abort_hba(phba);
  3117. }
  3118. /* Error everything on txq and txcmplq
  3119. * First do the txq.
  3120. */
  3121. spin_lock_irq(&phba->hbalock);
  3122. list_splice_init(&pring->txq, &completions);
  3123. pring->txq_cnt = 0;
  3124. /* Next issue ABTS for everything on the txcmplq */
  3125. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3126. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3127. spin_unlock_irq(&phba->hbalock);
  3128. /* Cancel all the IOCBs from the completions list */
  3129. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3130. IOERR_SLI_ABORTED);
  3131. }
  3132. /**
  3133. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3134. * @phba: Pointer to HBA context object.
  3135. *
  3136. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3137. * objects in txq and txcmplq. This function will not issue abort iocbs
  3138. * for all the iocb commands in txcmplq, they will just be returned with
  3139. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3140. * slot has been permanently disabled.
  3141. **/
  3142. void
  3143. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3144. {
  3145. LIST_HEAD(txq);
  3146. LIST_HEAD(txcmplq);
  3147. struct lpfc_sli *psli = &phba->sli;
  3148. struct lpfc_sli_ring *pring;
  3149. /* Currently, only one fcp ring */
  3150. pring = &psli->ring[psli->fcp_ring];
  3151. spin_lock_irq(&phba->hbalock);
  3152. /* Retrieve everything on txq */
  3153. list_splice_init(&pring->txq, &txq);
  3154. pring->txq_cnt = 0;
  3155. /* Retrieve everything on the txcmplq */
  3156. list_splice_init(&pring->txcmplq, &txcmplq);
  3157. pring->txcmplq_cnt = 0;
  3158. spin_unlock_irq(&phba->hbalock);
  3159. /* Flush the txq */
  3160. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3161. IOERR_SLI_DOWN);
  3162. /* Flush the txcmpq */
  3163. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3164. IOERR_SLI_DOWN);
  3165. }
  3166. /**
  3167. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3168. * @phba: Pointer to HBA context object.
  3169. * @mask: Bit mask to be checked.
  3170. *
  3171. * This function reads the host status register and compares
  3172. * with the provided bit mask to check if HBA completed
  3173. * the restart. This function will wait in a loop for the
  3174. * HBA to complete restart. If the HBA does not restart within
  3175. * 15 iterations, the function will reset the HBA again. The
  3176. * function returns 1 when HBA fail to restart otherwise returns
  3177. * zero.
  3178. **/
  3179. static int
  3180. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3181. {
  3182. uint32_t status;
  3183. int i = 0;
  3184. int retval = 0;
  3185. /* Read the HBA Host Status Register */
  3186. if (lpfc_readl(phba->HSregaddr, &status))
  3187. return 1;
  3188. /*
  3189. * Check status register every 100ms for 5 retries, then every
  3190. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3191. * every 2.5 sec for 4.
  3192. * Break our of the loop if errors occurred during init.
  3193. */
  3194. while (((status & mask) != mask) &&
  3195. !(status & HS_FFERM) &&
  3196. i++ < 20) {
  3197. if (i <= 5)
  3198. msleep(10);
  3199. else if (i <= 10)
  3200. msleep(500);
  3201. else
  3202. msleep(2500);
  3203. if (i == 15) {
  3204. /* Do post */
  3205. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3206. lpfc_sli_brdrestart(phba);
  3207. }
  3208. /* Read the HBA Host Status Register */
  3209. if (lpfc_readl(phba->HSregaddr, &status)) {
  3210. retval = 1;
  3211. break;
  3212. }
  3213. }
  3214. /* Check to see if any errors occurred during init */
  3215. if ((status & HS_FFERM) || (i >= 20)) {
  3216. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3217. "2751 Adapter failed to restart, "
  3218. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3219. status,
  3220. readl(phba->MBslimaddr + 0xa8),
  3221. readl(phba->MBslimaddr + 0xac));
  3222. phba->link_state = LPFC_HBA_ERROR;
  3223. retval = 1;
  3224. }
  3225. return retval;
  3226. }
  3227. /**
  3228. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3229. * @phba: Pointer to HBA context object.
  3230. * @mask: Bit mask to be checked.
  3231. *
  3232. * This function checks the host status register to check if HBA is
  3233. * ready. This function will wait in a loop for the HBA to be ready
  3234. * If the HBA is not ready , the function will will reset the HBA PCI
  3235. * function again. The function returns 1 when HBA fail to be ready
  3236. * otherwise returns zero.
  3237. **/
  3238. static int
  3239. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3240. {
  3241. uint32_t status;
  3242. int retval = 0;
  3243. /* Read the HBA Host Status Register */
  3244. status = lpfc_sli4_post_status_check(phba);
  3245. if (status) {
  3246. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3247. lpfc_sli_brdrestart(phba);
  3248. status = lpfc_sli4_post_status_check(phba);
  3249. }
  3250. /* Check to see if any errors occurred during init */
  3251. if (status) {
  3252. phba->link_state = LPFC_HBA_ERROR;
  3253. retval = 1;
  3254. } else
  3255. phba->sli4_hba.intr_enable = 0;
  3256. return retval;
  3257. }
  3258. /**
  3259. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3260. * @phba: Pointer to HBA context object.
  3261. * @mask: Bit mask to be checked.
  3262. *
  3263. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3264. * from the API jump table function pointer from the lpfc_hba struct.
  3265. **/
  3266. int
  3267. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3268. {
  3269. return phba->lpfc_sli_brdready(phba, mask);
  3270. }
  3271. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3272. /**
  3273. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3274. * @phba: Pointer to HBA context object.
  3275. *
  3276. * This function is called before resetting an HBA. This
  3277. * function requests HBA to quiesce DMAs before a reset.
  3278. **/
  3279. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3280. {
  3281. uint32_t __iomem *resp_buf;
  3282. uint32_t __iomem *mbox_buf;
  3283. volatile uint32_t mbox;
  3284. uint32_t hc_copy, ha_copy, resp_data;
  3285. int i;
  3286. uint8_t hdrtype;
  3287. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3288. if (hdrtype != 0x80 ||
  3289. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3290. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3291. return;
  3292. /*
  3293. * Tell the other part of the chip to suspend temporarily all
  3294. * its DMA activity.
  3295. */
  3296. resp_buf = phba->MBslimaddr;
  3297. /* Disable the error attention */
  3298. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3299. return;
  3300. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3301. readl(phba->HCregaddr); /* flush */
  3302. phba->link_flag |= LS_IGNORE_ERATT;
  3303. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3304. return;
  3305. if (ha_copy & HA_ERATT) {
  3306. /* Clear Chip error bit */
  3307. writel(HA_ERATT, phba->HAregaddr);
  3308. phba->pport->stopped = 1;
  3309. }
  3310. mbox = 0;
  3311. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3312. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3313. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3314. mbox_buf = phba->MBslimaddr;
  3315. writel(mbox, mbox_buf);
  3316. for (i = 0; i < 50; i++) {
  3317. if (lpfc_readl((resp_buf + 1), &resp_data))
  3318. return;
  3319. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3320. mdelay(1);
  3321. else
  3322. break;
  3323. }
  3324. resp_data = 0;
  3325. if (lpfc_readl((resp_buf + 1), &resp_data))
  3326. return;
  3327. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3328. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3329. phba->pport->stopped)
  3330. goto restore_hc;
  3331. else
  3332. goto clear_errat;
  3333. }
  3334. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3335. resp_data = 0;
  3336. for (i = 0; i < 500; i++) {
  3337. if (lpfc_readl(resp_buf, &resp_data))
  3338. return;
  3339. if (resp_data != mbox)
  3340. mdelay(1);
  3341. else
  3342. break;
  3343. }
  3344. clear_errat:
  3345. while (++i < 500) {
  3346. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3347. return;
  3348. if (!(ha_copy & HA_ERATT))
  3349. mdelay(1);
  3350. else
  3351. break;
  3352. }
  3353. if (readl(phba->HAregaddr) & HA_ERATT) {
  3354. writel(HA_ERATT, phba->HAregaddr);
  3355. phba->pport->stopped = 1;
  3356. }
  3357. restore_hc:
  3358. phba->link_flag &= ~LS_IGNORE_ERATT;
  3359. writel(hc_copy, phba->HCregaddr);
  3360. readl(phba->HCregaddr); /* flush */
  3361. }
  3362. /**
  3363. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3364. * @phba: Pointer to HBA context object.
  3365. *
  3366. * This function issues a kill_board mailbox command and waits for
  3367. * the error attention interrupt. This function is called for stopping
  3368. * the firmware processing. The caller is not required to hold any
  3369. * locks. This function calls lpfc_hba_down_post function to free
  3370. * any pending commands after the kill. The function will return 1 when it
  3371. * fails to kill the board else will return 0.
  3372. **/
  3373. int
  3374. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3375. {
  3376. struct lpfc_sli *psli;
  3377. LPFC_MBOXQ_t *pmb;
  3378. uint32_t status;
  3379. uint32_t ha_copy;
  3380. int retval;
  3381. int i = 0;
  3382. psli = &phba->sli;
  3383. /* Kill HBA */
  3384. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3385. "0329 Kill HBA Data: x%x x%x\n",
  3386. phba->pport->port_state, psli->sli_flag);
  3387. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3388. if (!pmb)
  3389. return 1;
  3390. /* Disable the error attention */
  3391. spin_lock_irq(&phba->hbalock);
  3392. if (lpfc_readl(phba->HCregaddr, &status)) {
  3393. spin_unlock_irq(&phba->hbalock);
  3394. mempool_free(pmb, phba->mbox_mem_pool);
  3395. return 1;
  3396. }
  3397. status &= ~HC_ERINT_ENA;
  3398. writel(status, phba->HCregaddr);
  3399. readl(phba->HCregaddr); /* flush */
  3400. phba->link_flag |= LS_IGNORE_ERATT;
  3401. spin_unlock_irq(&phba->hbalock);
  3402. lpfc_kill_board(phba, pmb);
  3403. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3404. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3405. if (retval != MBX_SUCCESS) {
  3406. if (retval != MBX_BUSY)
  3407. mempool_free(pmb, phba->mbox_mem_pool);
  3408. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3409. "2752 KILL_BOARD command failed retval %d\n",
  3410. retval);
  3411. spin_lock_irq(&phba->hbalock);
  3412. phba->link_flag &= ~LS_IGNORE_ERATT;
  3413. spin_unlock_irq(&phba->hbalock);
  3414. return 1;
  3415. }
  3416. spin_lock_irq(&phba->hbalock);
  3417. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3418. spin_unlock_irq(&phba->hbalock);
  3419. mempool_free(pmb, phba->mbox_mem_pool);
  3420. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3421. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3422. * 3 seconds we still set HBA_ERROR state because the status of the
  3423. * board is now undefined.
  3424. */
  3425. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3426. return 1;
  3427. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3428. mdelay(100);
  3429. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3430. return 1;
  3431. }
  3432. del_timer_sync(&psli->mbox_tmo);
  3433. if (ha_copy & HA_ERATT) {
  3434. writel(HA_ERATT, phba->HAregaddr);
  3435. phba->pport->stopped = 1;
  3436. }
  3437. spin_lock_irq(&phba->hbalock);
  3438. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3439. psli->mbox_active = NULL;
  3440. phba->link_flag &= ~LS_IGNORE_ERATT;
  3441. spin_unlock_irq(&phba->hbalock);
  3442. lpfc_hba_down_post(phba);
  3443. phba->link_state = LPFC_HBA_ERROR;
  3444. return ha_copy & HA_ERATT ? 0 : 1;
  3445. }
  3446. /**
  3447. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3448. * @phba: Pointer to HBA context object.
  3449. *
  3450. * This function resets the HBA by writing HC_INITFF to the control
  3451. * register. After the HBA resets, this function resets all the iocb ring
  3452. * indices. This function disables PCI layer parity checking during
  3453. * the reset.
  3454. * This function returns 0 always.
  3455. * The caller is not required to hold any locks.
  3456. **/
  3457. int
  3458. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3459. {
  3460. struct lpfc_sli *psli;
  3461. struct lpfc_sli_ring *pring;
  3462. uint16_t cfg_value;
  3463. int i;
  3464. psli = &phba->sli;
  3465. /* Reset HBA */
  3466. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3467. "0325 Reset HBA Data: x%x x%x\n",
  3468. phba->pport->port_state, psli->sli_flag);
  3469. /* perform board reset */
  3470. phba->fc_eventTag = 0;
  3471. phba->link_events = 0;
  3472. phba->pport->fc_myDID = 0;
  3473. phba->pport->fc_prevDID = 0;
  3474. /* Turn off parity checking and serr during the physical reset */
  3475. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3476. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3477. (cfg_value &
  3478. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3479. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3480. /* Now toggle INITFF bit in the Host Control Register */
  3481. writel(HC_INITFF, phba->HCregaddr);
  3482. mdelay(1);
  3483. readl(phba->HCregaddr); /* flush */
  3484. writel(0, phba->HCregaddr);
  3485. readl(phba->HCregaddr); /* flush */
  3486. /* Restore PCI cmd register */
  3487. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3488. /* Initialize relevant SLI info */
  3489. for (i = 0; i < psli->num_rings; i++) {
  3490. pring = &psli->ring[i];
  3491. pring->flag = 0;
  3492. pring->rspidx = 0;
  3493. pring->next_cmdidx = 0;
  3494. pring->local_getidx = 0;
  3495. pring->cmdidx = 0;
  3496. pring->missbufcnt = 0;
  3497. }
  3498. phba->link_state = LPFC_WARM_START;
  3499. return 0;
  3500. }
  3501. /**
  3502. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3503. * @phba: Pointer to HBA context object.
  3504. *
  3505. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3506. * checking during resets the device. The caller is not required to hold
  3507. * any locks.
  3508. *
  3509. * This function returns 0 always.
  3510. **/
  3511. int
  3512. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3513. {
  3514. struct lpfc_sli *psli = &phba->sli;
  3515. uint16_t cfg_value;
  3516. uint8_t qindx;
  3517. /* Reset HBA */
  3518. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3519. "0295 Reset HBA Data: x%x x%x\n",
  3520. phba->pport->port_state, psli->sli_flag);
  3521. /* perform board reset */
  3522. phba->fc_eventTag = 0;
  3523. phba->link_events = 0;
  3524. phba->pport->fc_myDID = 0;
  3525. phba->pport->fc_prevDID = 0;
  3526. spin_lock_irq(&phba->hbalock);
  3527. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3528. phba->fcf.fcf_flag = 0;
  3529. /* Clean up the child queue list for the CQs */
  3530. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3531. list_del_init(&phba->sli4_hba.els_wq->list);
  3532. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3533. list_del_init(&phba->sli4_hba.dat_rq->list);
  3534. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3535. list_del_init(&phba->sli4_hba.els_cq->list);
  3536. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3537. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3538. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3539. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3540. spin_unlock_irq(&phba->hbalock);
  3541. /* Now physically reset the device */
  3542. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3543. "0389 Performing PCI function reset!\n");
  3544. /* Turn off parity checking and serr during the physical reset */
  3545. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3546. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3547. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3548. /* Perform FCoE PCI function reset */
  3549. lpfc_pci_function_reset(phba);
  3550. /* Restore PCI cmd register */
  3551. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3552. return 0;
  3553. }
  3554. /**
  3555. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3556. * @phba: Pointer to HBA context object.
  3557. *
  3558. * This function is called in the SLI initialization code path to
  3559. * restart the HBA. The caller is not required to hold any lock.
  3560. * This function writes MBX_RESTART mailbox command to the SLIM and
  3561. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3562. * function to free any pending commands. The function enables
  3563. * POST only during the first initialization. The function returns zero.
  3564. * The function does not guarantee completion of MBX_RESTART mailbox
  3565. * command before the return of this function.
  3566. **/
  3567. static int
  3568. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3569. {
  3570. MAILBOX_t *mb;
  3571. struct lpfc_sli *psli;
  3572. volatile uint32_t word0;
  3573. void __iomem *to_slim;
  3574. uint32_t hba_aer_enabled;
  3575. spin_lock_irq(&phba->hbalock);
  3576. /* Take PCIe device Advanced Error Reporting (AER) state */
  3577. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3578. psli = &phba->sli;
  3579. /* Restart HBA */
  3580. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3581. "0337 Restart HBA Data: x%x x%x\n",
  3582. phba->pport->port_state, psli->sli_flag);
  3583. word0 = 0;
  3584. mb = (MAILBOX_t *) &word0;
  3585. mb->mbxCommand = MBX_RESTART;
  3586. mb->mbxHc = 1;
  3587. lpfc_reset_barrier(phba);
  3588. to_slim = phba->MBslimaddr;
  3589. writel(*(uint32_t *) mb, to_slim);
  3590. readl(to_slim); /* flush */
  3591. /* Only skip post after fc_ffinit is completed */
  3592. if (phba->pport->port_state)
  3593. word0 = 1; /* This is really setting up word1 */
  3594. else
  3595. word0 = 0; /* This is really setting up word1 */
  3596. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3597. writel(*(uint32_t *) mb, to_slim);
  3598. readl(to_slim); /* flush */
  3599. lpfc_sli_brdreset(phba);
  3600. phba->pport->stopped = 0;
  3601. phba->link_state = LPFC_INIT_START;
  3602. phba->hba_flag = 0;
  3603. spin_unlock_irq(&phba->hbalock);
  3604. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3605. psli->stats_start = get_seconds();
  3606. /* Give the INITFF and Post time to settle. */
  3607. mdelay(100);
  3608. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3609. if (hba_aer_enabled)
  3610. pci_disable_pcie_error_reporting(phba->pcidev);
  3611. lpfc_hba_down_post(phba);
  3612. return 0;
  3613. }
  3614. /**
  3615. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3616. * @phba: Pointer to HBA context object.
  3617. *
  3618. * This function is called in the SLI initialization code path to restart
  3619. * a SLI4 HBA. The caller is not required to hold any lock.
  3620. * At the end of the function, it calls lpfc_hba_down_post function to
  3621. * free any pending commands.
  3622. **/
  3623. static int
  3624. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3625. {
  3626. struct lpfc_sli *psli = &phba->sli;
  3627. uint32_t hba_aer_enabled;
  3628. /* Restart HBA */
  3629. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3630. "0296 Restart HBA Data: x%x x%x\n",
  3631. phba->pport->port_state, psli->sli_flag);
  3632. /* Take PCIe device Advanced Error Reporting (AER) state */
  3633. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3634. lpfc_sli4_brdreset(phba);
  3635. spin_lock_irq(&phba->hbalock);
  3636. phba->pport->stopped = 0;
  3637. phba->link_state = LPFC_INIT_START;
  3638. phba->hba_flag = 0;
  3639. spin_unlock_irq(&phba->hbalock);
  3640. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3641. psli->stats_start = get_seconds();
  3642. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3643. if (hba_aer_enabled)
  3644. pci_disable_pcie_error_reporting(phba->pcidev);
  3645. lpfc_hba_down_post(phba);
  3646. return 0;
  3647. }
  3648. /**
  3649. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3650. * @phba: Pointer to HBA context object.
  3651. *
  3652. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3653. * API jump table function pointer from the lpfc_hba struct.
  3654. **/
  3655. int
  3656. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3657. {
  3658. return phba->lpfc_sli_brdrestart(phba);
  3659. }
  3660. /**
  3661. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3662. * @phba: Pointer to HBA context object.
  3663. *
  3664. * This function is called after a HBA restart to wait for successful
  3665. * restart of the HBA. Successful restart of the HBA is indicated by
  3666. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3667. * iteration, the function will restart the HBA again. The function returns
  3668. * zero if HBA successfully restarted else returns negative error code.
  3669. **/
  3670. static int
  3671. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3672. {
  3673. uint32_t status, i = 0;
  3674. /* Read the HBA Host Status Register */
  3675. if (lpfc_readl(phba->HSregaddr, &status))
  3676. return -EIO;
  3677. /* Check status register to see what current state is */
  3678. i = 0;
  3679. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3680. /* Check every 10ms for 10 retries, then every 100ms for 90
  3681. * retries, then every 1 sec for 50 retires for a total of
  3682. * ~60 seconds before reset the board again and check every
  3683. * 1 sec for 50 retries. The up to 60 seconds before the
  3684. * board ready is required by the Falcon FIPS zeroization
  3685. * complete, and any reset the board in between shall cause
  3686. * restart of zeroization, further delay the board ready.
  3687. */
  3688. if (i++ >= 200) {
  3689. /* Adapter failed to init, timeout, status reg
  3690. <status> */
  3691. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3692. "0436 Adapter failed to init, "
  3693. "timeout, status reg x%x, "
  3694. "FW Data: A8 x%x AC x%x\n", status,
  3695. readl(phba->MBslimaddr + 0xa8),
  3696. readl(phba->MBslimaddr + 0xac));
  3697. phba->link_state = LPFC_HBA_ERROR;
  3698. return -ETIMEDOUT;
  3699. }
  3700. /* Check to see if any errors occurred during init */
  3701. if (status & HS_FFERM) {
  3702. /* ERROR: During chipset initialization */
  3703. /* Adapter failed to init, chipset, status reg
  3704. <status> */
  3705. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3706. "0437 Adapter failed to init, "
  3707. "chipset, status reg x%x, "
  3708. "FW Data: A8 x%x AC x%x\n", status,
  3709. readl(phba->MBslimaddr + 0xa8),
  3710. readl(phba->MBslimaddr + 0xac));
  3711. phba->link_state = LPFC_HBA_ERROR;
  3712. return -EIO;
  3713. }
  3714. if (i <= 10)
  3715. msleep(10);
  3716. else if (i <= 100)
  3717. msleep(100);
  3718. else
  3719. msleep(1000);
  3720. if (i == 150) {
  3721. /* Do post */
  3722. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3723. lpfc_sli_brdrestart(phba);
  3724. }
  3725. /* Read the HBA Host Status Register */
  3726. if (lpfc_readl(phba->HSregaddr, &status))
  3727. return -EIO;
  3728. }
  3729. /* Check to see if any errors occurred during init */
  3730. if (status & HS_FFERM) {
  3731. /* ERROR: During chipset initialization */
  3732. /* Adapter failed to init, chipset, status reg <status> */
  3733. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3734. "0438 Adapter failed to init, chipset, "
  3735. "status reg x%x, "
  3736. "FW Data: A8 x%x AC x%x\n", status,
  3737. readl(phba->MBslimaddr + 0xa8),
  3738. readl(phba->MBslimaddr + 0xac));
  3739. phba->link_state = LPFC_HBA_ERROR;
  3740. return -EIO;
  3741. }
  3742. /* Clear all interrupt enable conditions */
  3743. writel(0, phba->HCregaddr);
  3744. readl(phba->HCregaddr); /* flush */
  3745. /* setup host attn register */
  3746. writel(0xffffffff, phba->HAregaddr);
  3747. readl(phba->HAregaddr); /* flush */
  3748. return 0;
  3749. }
  3750. /**
  3751. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3752. *
  3753. * This function calculates and returns the number of HBQs required to be
  3754. * configured.
  3755. **/
  3756. int
  3757. lpfc_sli_hbq_count(void)
  3758. {
  3759. return ARRAY_SIZE(lpfc_hbq_defs);
  3760. }
  3761. /**
  3762. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3763. *
  3764. * This function adds the number of hbq entries in every HBQ to get
  3765. * the total number of hbq entries required for the HBA and returns
  3766. * the total count.
  3767. **/
  3768. static int
  3769. lpfc_sli_hbq_entry_count(void)
  3770. {
  3771. int hbq_count = lpfc_sli_hbq_count();
  3772. int count = 0;
  3773. int i;
  3774. for (i = 0; i < hbq_count; ++i)
  3775. count += lpfc_hbq_defs[i]->entry_count;
  3776. return count;
  3777. }
  3778. /**
  3779. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3780. *
  3781. * This function calculates amount of memory required for all hbq entries
  3782. * to be configured and returns the total memory required.
  3783. **/
  3784. int
  3785. lpfc_sli_hbq_size(void)
  3786. {
  3787. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3788. }
  3789. /**
  3790. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3791. * @phba: Pointer to HBA context object.
  3792. *
  3793. * This function is called during the SLI initialization to configure
  3794. * all the HBQs and post buffers to the HBQ. The caller is not
  3795. * required to hold any locks. This function will return zero if successful
  3796. * else it will return negative error code.
  3797. **/
  3798. static int
  3799. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3800. {
  3801. int hbq_count = lpfc_sli_hbq_count();
  3802. LPFC_MBOXQ_t *pmb;
  3803. MAILBOX_t *pmbox;
  3804. uint32_t hbqno;
  3805. uint32_t hbq_entry_index;
  3806. /* Get a Mailbox buffer to setup mailbox
  3807. * commands for HBA initialization
  3808. */
  3809. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3810. if (!pmb)
  3811. return -ENOMEM;
  3812. pmbox = &pmb->u.mb;
  3813. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3814. phba->link_state = LPFC_INIT_MBX_CMDS;
  3815. phba->hbq_in_use = 1;
  3816. hbq_entry_index = 0;
  3817. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3818. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3819. phba->hbqs[hbqno].hbqPutIdx = 0;
  3820. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3821. phba->hbqs[hbqno].entry_count =
  3822. lpfc_hbq_defs[hbqno]->entry_count;
  3823. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3824. hbq_entry_index, pmb);
  3825. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3826. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3827. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3828. mbxStatus <status>, ring <num> */
  3829. lpfc_printf_log(phba, KERN_ERR,
  3830. LOG_SLI | LOG_VPORT,
  3831. "1805 Adapter failed to init. "
  3832. "Data: x%x x%x x%x\n",
  3833. pmbox->mbxCommand,
  3834. pmbox->mbxStatus, hbqno);
  3835. phba->link_state = LPFC_HBA_ERROR;
  3836. mempool_free(pmb, phba->mbox_mem_pool);
  3837. return -ENXIO;
  3838. }
  3839. }
  3840. phba->hbq_count = hbq_count;
  3841. mempool_free(pmb, phba->mbox_mem_pool);
  3842. /* Initially populate or replenish the HBQs */
  3843. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3844. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3845. return 0;
  3846. }
  3847. /**
  3848. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3849. * @phba: Pointer to HBA context object.
  3850. *
  3851. * This function is called during the SLI initialization to configure
  3852. * all the HBQs and post buffers to the HBQ. The caller is not
  3853. * required to hold any locks. This function will return zero if successful
  3854. * else it will return negative error code.
  3855. **/
  3856. static int
  3857. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3858. {
  3859. phba->hbq_in_use = 1;
  3860. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3861. phba->hbq_count = 1;
  3862. /* Initially populate or replenish the HBQs */
  3863. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3864. return 0;
  3865. }
  3866. /**
  3867. * lpfc_sli_config_port - Issue config port mailbox command
  3868. * @phba: Pointer to HBA context object.
  3869. * @sli_mode: sli mode - 2/3
  3870. *
  3871. * This function is called by the sli intialization code path
  3872. * to issue config_port mailbox command. This function restarts the
  3873. * HBA firmware and issues a config_port mailbox command to configure
  3874. * the SLI interface in the sli mode specified by sli_mode
  3875. * variable. The caller is not required to hold any locks.
  3876. * The function returns 0 if successful, else returns negative error
  3877. * code.
  3878. **/
  3879. int
  3880. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3881. {
  3882. LPFC_MBOXQ_t *pmb;
  3883. uint32_t resetcount = 0, rc = 0, done = 0;
  3884. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3885. if (!pmb) {
  3886. phba->link_state = LPFC_HBA_ERROR;
  3887. return -ENOMEM;
  3888. }
  3889. phba->sli_rev = sli_mode;
  3890. while (resetcount < 2 && !done) {
  3891. spin_lock_irq(&phba->hbalock);
  3892. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3893. spin_unlock_irq(&phba->hbalock);
  3894. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3895. lpfc_sli_brdrestart(phba);
  3896. rc = lpfc_sli_chipset_init(phba);
  3897. if (rc)
  3898. break;
  3899. spin_lock_irq(&phba->hbalock);
  3900. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3901. spin_unlock_irq(&phba->hbalock);
  3902. resetcount++;
  3903. /* Call pre CONFIG_PORT mailbox command initialization. A
  3904. * value of 0 means the call was successful. Any other
  3905. * nonzero value is a failure, but if ERESTART is returned,
  3906. * the driver may reset the HBA and try again.
  3907. */
  3908. rc = lpfc_config_port_prep(phba);
  3909. if (rc == -ERESTART) {
  3910. phba->link_state = LPFC_LINK_UNKNOWN;
  3911. continue;
  3912. } else if (rc)
  3913. break;
  3914. phba->link_state = LPFC_INIT_MBX_CMDS;
  3915. lpfc_config_port(phba, pmb);
  3916. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3917. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3918. LPFC_SLI3_HBQ_ENABLED |
  3919. LPFC_SLI3_CRP_ENABLED |
  3920. LPFC_SLI3_BG_ENABLED |
  3921. LPFC_SLI3_DSS_ENABLED);
  3922. if (rc != MBX_SUCCESS) {
  3923. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3924. "0442 Adapter failed to init, mbxCmd x%x "
  3925. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3926. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3927. spin_lock_irq(&phba->hbalock);
  3928. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3929. spin_unlock_irq(&phba->hbalock);
  3930. rc = -ENXIO;
  3931. } else {
  3932. /* Allow asynchronous mailbox command to go through */
  3933. spin_lock_irq(&phba->hbalock);
  3934. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3935. spin_unlock_irq(&phba->hbalock);
  3936. done = 1;
  3937. }
  3938. }
  3939. if (!done) {
  3940. rc = -EINVAL;
  3941. goto do_prep_failed;
  3942. }
  3943. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3944. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3945. rc = -ENXIO;
  3946. goto do_prep_failed;
  3947. }
  3948. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3949. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3950. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3951. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3952. phba->max_vpi : phba->max_vports;
  3953. } else
  3954. phba->max_vpi = 0;
  3955. phba->fips_level = 0;
  3956. phba->fips_spec_rev = 0;
  3957. if (pmb->u.mb.un.varCfgPort.gdss) {
  3958. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3959. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3960. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3961. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3962. "2850 Security Crypto Active. FIPS x%d "
  3963. "(Spec Rev: x%d)",
  3964. phba->fips_level, phba->fips_spec_rev);
  3965. }
  3966. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3967. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3968. "2856 Config Port Security Crypto "
  3969. "Error: x%x ",
  3970. pmb->u.mb.un.varCfgPort.sec_err);
  3971. }
  3972. if (pmb->u.mb.un.varCfgPort.gerbm)
  3973. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3974. if (pmb->u.mb.un.varCfgPort.gcrp)
  3975. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3976. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3977. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3978. if (phba->cfg_enable_bg) {
  3979. if (pmb->u.mb.un.varCfgPort.gbg)
  3980. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3981. else
  3982. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3983. "0443 Adapter did not grant "
  3984. "BlockGuard\n");
  3985. }
  3986. } else {
  3987. phba->hbq_get = NULL;
  3988. phba->port_gp = phba->mbox->us.s2.port;
  3989. phba->max_vpi = 0;
  3990. }
  3991. do_prep_failed:
  3992. mempool_free(pmb, phba->mbox_mem_pool);
  3993. return rc;
  3994. }
  3995. /**
  3996. * lpfc_sli_hba_setup - SLI intialization function
  3997. * @phba: Pointer to HBA context object.
  3998. *
  3999. * This function is the main SLI intialization function. This function
  4000. * is called by the HBA intialization code, HBA reset code and HBA
  4001. * error attention handler code. Caller is not required to hold any
  4002. * locks. This function issues config_port mailbox command to configure
  4003. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4004. * calls the config_port_post function to issue init_link mailbox
  4005. * command and to start the discovery. The function will return zero
  4006. * if successful, else it will return negative error code.
  4007. **/
  4008. int
  4009. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4010. {
  4011. uint32_t rc;
  4012. int mode = 3;
  4013. switch (lpfc_sli_mode) {
  4014. case 2:
  4015. if (phba->cfg_enable_npiv) {
  4016. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4017. "1824 NPIV enabled: Override lpfc_sli_mode "
  4018. "parameter (%d) to auto (0).\n",
  4019. lpfc_sli_mode);
  4020. break;
  4021. }
  4022. mode = 2;
  4023. break;
  4024. case 0:
  4025. case 3:
  4026. break;
  4027. default:
  4028. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4029. "1819 Unrecognized lpfc_sli_mode "
  4030. "parameter: %d.\n", lpfc_sli_mode);
  4031. break;
  4032. }
  4033. rc = lpfc_sli_config_port(phba, mode);
  4034. if (rc && lpfc_sli_mode == 3)
  4035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4036. "1820 Unable to select SLI-3. "
  4037. "Not supported by adapter.\n");
  4038. if (rc && mode != 2)
  4039. rc = lpfc_sli_config_port(phba, 2);
  4040. if (rc)
  4041. goto lpfc_sli_hba_setup_error;
  4042. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4043. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4044. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4045. if (!rc) {
  4046. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4047. "2709 This device supports "
  4048. "Advanced Error Reporting (AER)\n");
  4049. spin_lock_irq(&phba->hbalock);
  4050. phba->hba_flag |= HBA_AER_ENABLED;
  4051. spin_unlock_irq(&phba->hbalock);
  4052. } else {
  4053. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4054. "2708 This device does not support "
  4055. "Advanced Error Reporting (AER)\n");
  4056. phba->cfg_aer_support = 0;
  4057. }
  4058. }
  4059. if (phba->sli_rev == 3) {
  4060. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4061. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4062. } else {
  4063. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4064. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4065. phba->sli3_options = 0;
  4066. }
  4067. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4068. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4069. phba->sli_rev, phba->max_vpi);
  4070. rc = lpfc_sli_ring_map(phba);
  4071. if (rc)
  4072. goto lpfc_sli_hba_setup_error;
  4073. /* Init HBQs */
  4074. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4075. rc = lpfc_sli_hbq_setup(phba);
  4076. if (rc)
  4077. goto lpfc_sli_hba_setup_error;
  4078. }
  4079. spin_lock_irq(&phba->hbalock);
  4080. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4081. spin_unlock_irq(&phba->hbalock);
  4082. rc = lpfc_config_port_post(phba);
  4083. if (rc)
  4084. goto lpfc_sli_hba_setup_error;
  4085. return rc;
  4086. lpfc_sli_hba_setup_error:
  4087. phba->link_state = LPFC_HBA_ERROR;
  4088. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4089. "0445 Firmware initialization failed\n");
  4090. return rc;
  4091. }
  4092. /**
  4093. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4094. * @phba: Pointer to HBA context object.
  4095. * @mboxq: mailbox pointer.
  4096. * This function issue a dump mailbox command to read config region
  4097. * 23 and parse the records in the region and populate driver
  4098. * data structure.
  4099. **/
  4100. static int
  4101. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4102. LPFC_MBOXQ_t *mboxq)
  4103. {
  4104. struct lpfc_dmabuf *mp;
  4105. struct lpfc_mqe *mqe;
  4106. uint32_t data_length;
  4107. int rc;
  4108. /* Program the default value of vlan_id and fc_map */
  4109. phba->valid_vlan = 0;
  4110. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4111. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4112. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4113. mqe = &mboxq->u.mqe;
  4114. if (lpfc_dump_fcoe_param(phba, mboxq))
  4115. return -ENOMEM;
  4116. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4117. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4118. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4119. "(%d):2571 Mailbox cmd x%x Status x%x "
  4120. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4121. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4122. "CQ: x%x x%x x%x x%x\n",
  4123. mboxq->vport ? mboxq->vport->vpi : 0,
  4124. bf_get(lpfc_mqe_command, mqe),
  4125. bf_get(lpfc_mqe_status, mqe),
  4126. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4127. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4128. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4129. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4130. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4131. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4132. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4133. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4134. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4135. mboxq->mcqe.word0,
  4136. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4137. mboxq->mcqe.trailer);
  4138. if (rc) {
  4139. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4140. kfree(mp);
  4141. return -EIO;
  4142. }
  4143. data_length = mqe->un.mb_words[5];
  4144. if (data_length > DMP_RGN23_SIZE) {
  4145. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4146. kfree(mp);
  4147. return -EIO;
  4148. }
  4149. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4150. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4151. kfree(mp);
  4152. return 0;
  4153. }
  4154. /**
  4155. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4156. * @phba: pointer to lpfc hba data structure.
  4157. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4158. * @vpd: pointer to the memory to hold resulting port vpd data.
  4159. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4160. * On output, the number of data bytes in @vpd.
  4161. *
  4162. * This routine executes a READ_REV SLI4 mailbox command. In
  4163. * addition, this routine gets the port vpd data.
  4164. *
  4165. * Return codes
  4166. * 0 - successful
  4167. * -ENOMEM - could not allocated memory.
  4168. **/
  4169. static int
  4170. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4171. uint8_t *vpd, uint32_t *vpd_size)
  4172. {
  4173. int rc = 0;
  4174. uint32_t dma_size;
  4175. struct lpfc_dmabuf *dmabuf;
  4176. struct lpfc_mqe *mqe;
  4177. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4178. if (!dmabuf)
  4179. return -ENOMEM;
  4180. /*
  4181. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4182. * mailbox command.
  4183. */
  4184. dma_size = *vpd_size;
  4185. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4186. dma_size,
  4187. &dmabuf->phys,
  4188. GFP_KERNEL);
  4189. if (!dmabuf->virt) {
  4190. kfree(dmabuf);
  4191. return -ENOMEM;
  4192. }
  4193. memset(dmabuf->virt, 0, dma_size);
  4194. /*
  4195. * The SLI4 implementation of READ_REV conflicts at word1,
  4196. * bits 31:16 and SLI4 adds vpd functionality not present
  4197. * in SLI3. This code corrects the conflicts.
  4198. */
  4199. lpfc_read_rev(phba, mboxq);
  4200. mqe = &mboxq->u.mqe;
  4201. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4202. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4203. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4204. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4205. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4206. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4207. if (rc) {
  4208. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4209. dmabuf->virt, dmabuf->phys);
  4210. kfree(dmabuf);
  4211. return -EIO;
  4212. }
  4213. /*
  4214. * The available vpd length cannot be bigger than the
  4215. * DMA buffer passed to the port. Catch the less than
  4216. * case and update the caller's size.
  4217. */
  4218. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4219. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4220. memcpy(vpd, dmabuf->virt, *vpd_size);
  4221. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4222. dmabuf->virt, dmabuf->phys);
  4223. kfree(dmabuf);
  4224. return 0;
  4225. }
  4226. /**
  4227. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4228. * @phba: pointer to lpfc hba data structure.
  4229. *
  4230. * This routine is called to explicitly arm the SLI4 device's completion and
  4231. * event queues
  4232. **/
  4233. static void
  4234. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4235. {
  4236. uint8_t fcp_eqidx;
  4237. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4238. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4239. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4240. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4241. LPFC_QUEUE_REARM);
  4242. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4243. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4244. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4245. LPFC_QUEUE_REARM);
  4246. }
  4247. /**
  4248. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4249. * @phba: Pointer to HBA context object.
  4250. *
  4251. * This function is the main SLI4 device intialization PCI function. This
  4252. * function is called by the HBA intialization code, HBA reset code and
  4253. * HBA error attention handler code. Caller is not required to hold any
  4254. * locks.
  4255. **/
  4256. int
  4257. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4258. {
  4259. int rc;
  4260. LPFC_MBOXQ_t *mboxq;
  4261. struct lpfc_mqe *mqe;
  4262. uint8_t *vpd;
  4263. uint32_t vpd_size;
  4264. uint32_t ftr_rsp = 0;
  4265. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4266. struct lpfc_vport *vport = phba->pport;
  4267. struct lpfc_dmabuf *mp;
  4268. /*
  4269. * TODO: Why does this routine execute these task in a different
  4270. * order from probe?
  4271. */
  4272. /* Perform a PCI function reset to start from clean */
  4273. rc = lpfc_pci_function_reset(phba);
  4274. if (unlikely(rc))
  4275. return -ENODEV;
  4276. /* Check the HBA Host Status Register for readyness */
  4277. rc = lpfc_sli4_post_status_check(phba);
  4278. if (unlikely(rc))
  4279. return -ENODEV;
  4280. else {
  4281. spin_lock_irq(&phba->hbalock);
  4282. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4283. spin_unlock_irq(&phba->hbalock);
  4284. }
  4285. /*
  4286. * Allocate a single mailbox container for initializing the
  4287. * port.
  4288. */
  4289. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4290. if (!mboxq)
  4291. return -ENOMEM;
  4292. /*
  4293. * Continue initialization with default values even if driver failed
  4294. * to read FCoE param config regions
  4295. */
  4296. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4297. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4298. "2570 Failed to read FCoE parameters\n");
  4299. /* Issue READ_REV to collect vpd and FW information. */
  4300. vpd_size = SLI4_PAGE_SIZE;
  4301. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4302. if (!vpd) {
  4303. rc = -ENOMEM;
  4304. goto out_free_mbox;
  4305. }
  4306. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4307. if (unlikely(rc)) {
  4308. kfree(vpd);
  4309. goto out_free_mbox;
  4310. }
  4311. mqe = &mboxq->u.mqe;
  4312. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4313. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4314. phba->hba_flag |= HBA_FCOE_MODE;
  4315. else
  4316. phba->hba_flag &= ~HBA_FCOE_MODE;
  4317. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4318. LPFC_DCBX_CEE_MODE)
  4319. phba->hba_flag |= HBA_FIP_SUPPORT;
  4320. else
  4321. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4322. if (phba->sli_rev != LPFC_SLI_REV4 ||
  4323. !(phba->hba_flag & HBA_FCOE_MODE)) {
  4324. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4325. "0376 READ_REV Error. SLI Level %d "
  4326. "FCoE enabled %d\n",
  4327. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4328. rc = -EIO;
  4329. kfree(vpd);
  4330. goto out_free_mbox;
  4331. }
  4332. /*
  4333. * Evaluate the read rev and vpd data. Populate the driver
  4334. * state with the results. If this routine fails, the failure
  4335. * is not fatal as the driver will use generic values.
  4336. */
  4337. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4338. if (unlikely(!rc)) {
  4339. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4340. "0377 Error %d parsing vpd. "
  4341. "Using defaults.\n", rc);
  4342. rc = 0;
  4343. }
  4344. kfree(vpd);
  4345. /* Save information as VPD data */
  4346. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4347. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4348. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4349. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4350. &mqe->un.read_rev);
  4351. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4352. &mqe->un.read_rev);
  4353. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4354. &mqe->un.read_rev);
  4355. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4356. &mqe->un.read_rev);
  4357. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4358. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4359. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4360. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4361. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4362. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4363. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4364. "(%d):0380 READ_REV Status x%x "
  4365. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4366. mboxq->vport ? mboxq->vport->vpi : 0,
  4367. bf_get(lpfc_mqe_status, mqe),
  4368. phba->vpd.rev.opFwName,
  4369. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4370. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4371. /*
  4372. * Discover the port's supported feature set and match it against the
  4373. * hosts requests.
  4374. */
  4375. lpfc_request_features(phba, mboxq);
  4376. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4377. if (unlikely(rc)) {
  4378. rc = -EIO;
  4379. goto out_free_mbox;
  4380. }
  4381. /*
  4382. * The port must support FCP initiator mode as this is the
  4383. * only mode running in the host.
  4384. */
  4385. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4386. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4387. "0378 No support for fcpi mode.\n");
  4388. ftr_rsp++;
  4389. }
  4390. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  4391. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  4392. else
  4393. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  4394. /*
  4395. * If the port cannot support the host's requested features
  4396. * then turn off the global config parameters to disable the
  4397. * feature in the driver. This is not a fatal error.
  4398. */
  4399. if ((phba->cfg_enable_bg) &&
  4400. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4401. ftr_rsp++;
  4402. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4403. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4404. ftr_rsp++;
  4405. if (ftr_rsp) {
  4406. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4407. "0379 Feature Mismatch Data: x%08x %08x "
  4408. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4409. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4410. phba->cfg_enable_npiv, phba->max_vpi);
  4411. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4412. phba->cfg_enable_bg = 0;
  4413. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4414. phba->cfg_enable_npiv = 0;
  4415. }
  4416. /* These SLI3 features are assumed in SLI4 */
  4417. spin_lock_irq(&phba->hbalock);
  4418. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4419. spin_unlock_irq(&phba->hbalock);
  4420. /* Read the port's service parameters. */
  4421. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4422. if (rc) {
  4423. phba->link_state = LPFC_HBA_ERROR;
  4424. rc = -ENOMEM;
  4425. goto out_free_mbox;
  4426. }
  4427. mboxq->vport = vport;
  4428. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4429. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4430. if (rc == MBX_SUCCESS) {
  4431. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4432. rc = 0;
  4433. }
  4434. /*
  4435. * This memory was allocated by the lpfc_read_sparam routine. Release
  4436. * it to the mbuf pool.
  4437. */
  4438. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4439. kfree(mp);
  4440. mboxq->context1 = NULL;
  4441. if (unlikely(rc)) {
  4442. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4443. "0382 READ_SPARAM command failed "
  4444. "status %d, mbxStatus x%x\n",
  4445. rc, bf_get(lpfc_mqe_status, mqe));
  4446. phba->link_state = LPFC_HBA_ERROR;
  4447. rc = -EIO;
  4448. goto out_free_mbox;
  4449. }
  4450. if (phba->cfg_soft_wwnn)
  4451. u64_to_wwn(phba->cfg_soft_wwnn,
  4452. vport->fc_sparam.nodeName.u.wwn);
  4453. if (phba->cfg_soft_wwpn)
  4454. u64_to_wwn(phba->cfg_soft_wwpn,
  4455. vport->fc_sparam.portName.u.wwn);
  4456. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4457. sizeof(struct lpfc_name));
  4458. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4459. sizeof(struct lpfc_name));
  4460. /* Update the fc_host data structures with new wwn. */
  4461. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4462. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4463. /* Register SGL pool to the device using non-embedded mailbox command */
  4464. rc = lpfc_sli4_post_sgl_list(phba);
  4465. if (unlikely(rc)) {
  4466. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4467. "0582 Error %d during sgl post operation\n",
  4468. rc);
  4469. rc = -ENODEV;
  4470. goto out_free_mbox;
  4471. }
  4472. /* Register SCSI SGL pool to the device */
  4473. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4474. if (unlikely(rc)) {
  4475. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4476. "0383 Error %d during scsi sgl post "
  4477. "operation\n", rc);
  4478. /* Some Scsi buffers were moved to the abort scsi list */
  4479. /* A pci function reset will repost them */
  4480. rc = -ENODEV;
  4481. goto out_free_mbox;
  4482. }
  4483. /* Post the rpi header region to the device. */
  4484. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4485. if (unlikely(rc)) {
  4486. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4487. "0393 Error %d during rpi post operation\n",
  4488. rc);
  4489. rc = -ENODEV;
  4490. goto out_free_mbox;
  4491. }
  4492. /* Set up all the queues to the device */
  4493. rc = lpfc_sli4_queue_setup(phba);
  4494. if (unlikely(rc)) {
  4495. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4496. "0381 Error %d during queue setup.\n ", rc);
  4497. goto out_stop_timers;
  4498. }
  4499. /* Arm the CQs and then EQs on device */
  4500. lpfc_sli4_arm_cqeq_intr(phba);
  4501. /* Indicate device interrupt mode */
  4502. phba->sli4_hba.intr_enable = 1;
  4503. /* Allow asynchronous mailbox command to go through */
  4504. spin_lock_irq(&phba->hbalock);
  4505. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4506. spin_unlock_irq(&phba->hbalock);
  4507. /* Post receive buffers to the device */
  4508. lpfc_sli4_rb_setup(phba);
  4509. /* Reset HBA FCF states after HBA reset */
  4510. phba->fcf.fcf_flag = 0;
  4511. phba->fcf.current_rec.flag = 0;
  4512. /* Start the ELS watchdog timer */
  4513. mod_timer(&vport->els_tmofunc,
  4514. jiffies + HZ * (phba->fc_ratov * 2));
  4515. /* Start heart beat timer */
  4516. mod_timer(&phba->hb_tmofunc,
  4517. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4518. phba->hb_outstanding = 0;
  4519. phba->last_completion_time = jiffies;
  4520. /* Start error attention (ERATT) polling timer */
  4521. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4522. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4523. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4524. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4525. if (!rc) {
  4526. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4527. "2829 This device supports "
  4528. "Advanced Error Reporting (AER)\n");
  4529. spin_lock_irq(&phba->hbalock);
  4530. phba->hba_flag |= HBA_AER_ENABLED;
  4531. spin_unlock_irq(&phba->hbalock);
  4532. } else {
  4533. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4534. "2830 This device does not support "
  4535. "Advanced Error Reporting (AER)\n");
  4536. phba->cfg_aer_support = 0;
  4537. }
  4538. }
  4539. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4540. /*
  4541. * The FC Port needs to register FCFI (index 0)
  4542. */
  4543. lpfc_reg_fcfi(phba, mboxq);
  4544. mboxq->vport = phba->pport;
  4545. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4546. if (rc == MBX_SUCCESS)
  4547. rc = 0;
  4548. else
  4549. goto out_unset_queue;
  4550. }
  4551. /*
  4552. * The port is ready, set the host's link state to LINK_DOWN
  4553. * in preparation for link interrupts.
  4554. */
  4555. spin_lock_irq(&phba->hbalock);
  4556. phba->link_state = LPFC_LINK_DOWN;
  4557. spin_unlock_irq(&phba->hbalock);
  4558. if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
  4559. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4560. out_unset_queue:
  4561. /* Unset all the queues set up in this routine when error out */
  4562. if (rc)
  4563. lpfc_sli4_queue_unset(phba);
  4564. out_stop_timers:
  4565. if (rc)
  4566. lpfc_stop_hba_timers(phba);
  4567. out_free_mbox:
  4568. mempool_free(mboxq, phba->mbox_mem_pool);
  4569. return rc;
  4570. }
  4571. /**
  4572. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4573. * @ptr: context object - pointer to hba structure.
  4574. *
  4575. * This is the callback function for mailbox timer. The mailbox
  4576. * timer is armed when a new mailbox command is issued and the timer
  4577. * is deleted when the mailbox complete. The function is called by
  4578. * the kernel timer code when a mailbox does not complete within
  4579. * expected time. This function wakes up the worker thread to
  4580. * process the mailbox timeout and returns. All the processing is
  4581. * done by the worker thread function lpfc_mbox_timeout_handler.
  4582. **/
  4583. void
  4584. lpfc_mbox_timeout(unsigned long ptr)
  4585. {
  4586. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4587. unsigned long iflag;
  4588. uint32_t tmo_posted;
  4589. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4590. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4591. if (!tmo_posted)
  4592. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4593. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4594. if (!tmo_posted)
  4595. lpfc_worker_wake_up(phba);
  4596. return;
  4597. }
  4598. /**
  4599. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4600. * @phba: Pointer to HBA context object.
  4601. *
  4602. * This function is called from worker thread when a mailbox command times out.
  4603. * The caller is not required to hold any locks. This function will reset the
  4604. * HBA and recover all the pending commands.
  4605. **/
  4606. void
  4607. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4608. {
  4609. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4610. MAILBOX_t *mb = &pmbox->u.mb;
  4611. struct lpfc_sli *psli = &phba->sli;
  4612. struct lpfc_sli_ring *pring;
  4613. /* Check the pmbox pointer first. There is a race condition
  4614. * between the mbox timeout handler getting executed in the
  4615. * worklist and the mailbox actually completing. When this
  4616. * race condition occurs, the mbox_active will be NULL.
  4617. */
  4618. spin_lock_irq(&phba->hbalock);
  4619. if (pmbox == NULL) {
  4620. lpfc_printf_log(phba, KERN_WARNING,
  4621. LOG_MBOX | LOG_SLI,
  4622. "0353 Active Mailbox cleared - mailbox timeout "
  4623. "exiting\n");
  4624. spin_unlock_irq(&phba->hbalock);
  4625. return;
  4626. }
  4627. /* Mbox cmd <mbxCommand> timeout */
  4628. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4629. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4630. mb->mbxCommand,
  4631. phba->pport->port_state,
  4632. phba->sli.sli_flag,
  4633. phba->sli.mbox_active);
  4634. spin_unlock_irq(&phba->hbalock);
  4635. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4636. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4637. * it to fail all oustanding SCSI IO.
  4638. */
  4639. spin_lock_irq(&phba->pport->work_port_lock);
  4640. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4641. spin_unlock_irq(&phba->pport->work_port_lock);
  4642. spin_lock_irq(&phba->hbalock);
  4643. phba->link_state = LPFC_LINK_UNKNOWN;
  4644. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4645. spin_unlock_irq(&phba->hbalock);
  4646. pring = &psli->ring[psli->fcp_ring];
  4647. lpfc_sli_abort_iocb_ring(phba, pring);
  4648. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4649. "0345 Resetting board due to mailbox timeout\n");
  4650. /* Reset the HBA device */
  4651. lpfc_reset_hba(phba);
  4652. }
  4653. /**
  4654. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4655. * @phba: Pointer to HBA context object.
  4656. * @pmbox: Pointer to mailbox object.
  4657. * @flag: Flag indicating how the mailbox need to be processed.
  4658. *
  4659. * This function is called by discovery code and HBA management code
  4660. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4661. * function gets the hbalock to protect the data structures.
  4662. * The mailbox command can be submitted in polling mode, in which case
  4663. * this function will wait in a polling loop for the completion of the
  4664. * mailbox.
  4665. * If the mailbox is submitted in no_wait mode (not polling) the
  4666. * function will submit the command and returns immediately without waiting
  4667. * for the mailbox completion. The no_wait is supported only when HBA
  4668. * is in SLI2/SLI3 mode - interrupts are enabled.
  4669. * The SLI interface allows only one mailbox pending at a time. If the
  4670. * mailbox is issued in polling mode and there is already a mailbox
  4671. * pending, then the function will return an error. If the mailbox is issued
  4672. * in NO_WAIT mode and there is a mailbox pending already, the function
  4673. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4674. * The sli layer owns the mailbox object until the completion of mailbox
  4675. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4676. * return codes the caller owns the mailbox command after the return of
  4677. * the function.
  4678. **/
  4679. static int
  4680. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4681. uint32_t flag)
  4682. {
  4683. MAILBOX_t *mb;
  4684. struct lpfc_sli *psli = &phba->sli;
  4685. uint32_t status, evtctr;
  4686. uint32_t ha_copy, hc_copy;
  4687. int i;
  4688. unsigned long timeout;
  4689. unsigned long drvr_flag = 0;
  4690. uint32_t word0, ldata;
  4691. void __iomem *to_slim;
  4692. int processing_queue = 0;
  4693. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4694. if (!pmbox) {
  4695. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4696. /* processing mbox queue from intr_handler */
  4697. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4698. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4699. return MBX_SUCCESS;
  4700. }
  4701. processing_queue = 1;
  4702. pmbox = lpfc_mbox_get(phba);
  4703. if (!pmbox) {
  4704. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4705. return MBX_SUCCESS;
  4706. }
  4707. }
  4708. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4709. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4710. if(!pmbox->vport) {
  4711. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4712. lpfc_printf_log(phba, KERN_ERR,
  4713. LOG_MBOX | LOG_VPORT,
  4714. "1806 Mbox x%x failed. No vport\n",
  4715. pmbox->u.mb.mbxCommand);
  4716. dump_stack();
  4717. goto out_not_finished;
  4718. }
  4719. }
  4720. /* If the PCI channel is in offline state, do not post mbox. */
  4721. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4722. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4723. goto out_not_finished;
  4724. }
  4725. /* If HBA has a deferred error attention, fail the iocb. */
  4726. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4727. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4728. goto out_not_finished;
  4729. }
  4730. psli = &phba->sli;
  4731. mb = &pmbox->u.mb;
  4732. status = MBX_SUCCESS;
  4733. if (phba->link_state == LPFC_HBA_ERROR) {
  4734. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4735. /* Mbox command <mbxCommand> cannot issue */
  4736. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4737. "(%d):0311 Mailbox command x%x cannot "
  4738. "issue Data: x%x x%x\n",
  4739. pmbox->vport ? pmbox->vport->vpi : 0,
  4740. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4741. goto out_not_finished;
  4742. }
  4743. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  4744. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  4745. !(hc_copy & HC_MBINT_ENA)) {
  4746. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4747. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4748. "(%d):2528 Mailbox command x%x cannot "
  4749. "issue Data: x%x x%x\n",
  4750. pmbox->vport ? pmbox->vport->vpi : 0,
  4751. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4752. goto out_not_finished;
  4753. }
  4754. }
  4755. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4756. /* Polling for a mbox command when another one is already active
  4757. * is not allowed in SLI. Also, the driver must have established
  4758. * SLI2 mode to queue and process multiple mbox commands.
  4759. */
  4760. if (flag & MBX_POLL) {
  4761. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4762. /* Mbox command <mbxCommand> cannot issue */
  4763. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4764. "(%d):2529 Mailbox command x%x "
  4765. "cannot issue Data: x%x x%x\n",
  4766. pmbox->vport ? pmbox->vport->vpi : 0,
  4767. pmbox->u.mb.mbxCommand,
  4768. psli->sli_flag, flag);
  4769. goto out_not_finished;
  4770. }
  4771. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4772. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4773. /* Mbox command <mbxCommand> cannot issue */
  4774. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4775. "(%d):2530 Mailbox command x%x "
  4776. "cannot issue Data: x%x x%x\n",
  4777. pmbox->vport ? pmbox->vport->vpi : 0,
  4778. pmbox->u.mb.mbxCommand,
  4779. psli->sli_flag, flag);
  4780. goto out_not_finished;
  4781. }
  4782. /* Another mailbox command is still being processed, queue this
  4783. * command to be processed later.
  4784. */
  4785. lpfc_mbox_put(phba, pmbox);
  4786. /* Mbox cmd issue - BUSY */
  4787. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4788. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4789. "x%x x%x x%x x%x\n",
  4790. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4791. mb->mbxCommand, phba->pport->port_state,
  4792. psli->sli_flag, flag);
  4793. psli->slistat.mbox_busy++;
  4794. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4795. if (pmbox->vport) {
  4796. lpfc_debugfs_disc_trc(pmbox->vport,
  4797. LPFC_DISC_TRC_MBOX_VPORT,
  4798. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4799. (uint32_t)mb->mbxCommand,
  4800. mb->un.varWords[0], mb->un.varWords[1]);
  4801. }
  4802. else {
  4803. lpfc_debugfs_disc_trc(phba->pport,
  4804. LPFC_DISC_TRC_MBOX,
  4805. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4806. (uint32_t)mb->mbxCommand,
  4807. mb->un.varWords[0], mb->un.varWords[1]);
  4808. }
  4809. return MBX_BUSY;
  4810. }
  4811. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4812. /* If we are not polling, we MUST be in SLI2 mode */
  4813. if (flag != MBX_POLL) {
  4814. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4815. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4816. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4817. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4818. /* Mbox command <mbxCommand> cannot issue */
  4819. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4820. "(%d):2531 Mailbox command x%x "
  4821. "cannot issue Data: x%x x%x\n",
  4822. pmbox->vport ? pmbox->vport->vpi : 0,
  4823. pmbox->u.mb.mbxCommand,
  4824. psli->sli_flag, flag);
  4825. goto out_not_finished;
  4826. }
  4827. /* timeout active mbox command */
  4828. mod_timer(&psli->mbox_tmo, (jiffies +
  4829. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4830. }
  4831. /* Mailbox cmd <cmd> issue */
  4832. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4833. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4834. "x%x\n",
  4835. pmbox->vport ? pmbox->vport->vpi : 0,
  4836. mb->mbxCommand, phba->pport->port_state,
  4837. psli->sli_flag, flag);
  4838. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4839. if (pmbox->vport) {
  4840. lpfc_debugfs_disc_trc(pmbox->vport,
  4841. LPFC_DISC_TRC_MBOX_VPORT,
  4842. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4843. (uint32_t)mb->mbxCommand,
  4844. mb->un.varWords[0], mb->un.varWords[1]);
  4845. }
  4846. else {
  4847. lpfc_debugfs_disc_trc(phba->pport,
  4848. LPFC_DISC_TRC_MBOX,
  4849. "MBOX Send: cmd:x%x mb:x%x x%x",
  4850. (uint32_t)mb->mbxCommand,
  4851. mb->un.varWords[0], mb->un.varWords[1]);
  4852. }
  4853. }
  4854. psli->slistat.mbox_cmd++;
  4855. evtctr = psli->slistat.mbox_event;
  4856. /* next set own bit for the adapter and copy over command word */
  4857. mb->mbxOwner = OWN_CHIP;
  4858. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4859. /* Populate mbox extension offset word. */
  4860. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4861. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4862. = (uint8_t *)phba->mbox_ext
  4863. - (uint8_t *)phba->mbox;
  4864. }
  4865. /* Copy the mailbox extension data */
  4866. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4867. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4868. (uint8_t *)phba->mbox_ext,
  4869. pmbox->in_ext_byte_len);
  4870. }
  4871. /* Copy command data to host SLIM area */
  4872. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4873. } else {
  4874. /* Populate mbox extension offset word. */
  4875. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4876. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4877. = MAILBOX_HBA_EXT_OFFSET;
  4878. /* Copy the mailbox extension data */
  4879. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4880. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4881. MAILBOX_HBA_EXT_OFFSET,
  4882. pmbox->context2, pmbox->in_ext_byte_len);
  4883. }
  4884. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4885. /* copy command data into host mbox for cmpl */
  4886. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4887. }
  4888. /* First copy mbox command data to HBA SLIM, skip past first
  4889. word */
  4890. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4891. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4892. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4893. /* Next copy over first word, with mbxOwner set */
  4894. ldata = *((uint32_t *)mb);
  4895. to_slim = phba->MBslimaddr;
  4896. writel(ldata, to_slim);
  4897. readl(to_slim); /* flush */
  4898. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4899. /* switch over to host mailbox */
  4900. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4901. }
  4902. }
  4903. wmb();
  4904. switch (flag) {
  4905. case MBX_NOWAIT:
  4906. /* Set up reference to mailbox command */
  4907. psli->mbox_active = pmbox;
  4908. /* Interrupt board to do it */
  4909. writel(CA_MBATT, phba->CAregaddr);
  4910. readl(phba->CAregaddr); /* flush */
  4911. /* Don't wait for it to finish, just return */
  4912. break;
  4913. case MBX_POLL:
  4914. /* Set up null reference to mailbox command */
  4915. psli->mbox_active = NULL;
  4916. /* Interrupt board to do it */
  4917. writel(CA_MBATT, phba->CAregaddr);
  4918. readl(phba->CAregaddr); /* flush */
  4919. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4920. /* First read mbox status word */
  4921. word0 = *((uint32_t *)phba->mbox);
  4922. word0 = le32_to_cpu(word0);
  4923. } else {
  4924. /* First read mbox status word */
  4925. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  4926. spin_unlock_irqrestore(&phba->hbalock,
  4927. drvr_flag);
  4928. goto out_not_finished;
  4929. }
  4930. }
  4931. /* Read the HBA Host Attention Register */
  4932. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  4933. spin_unlock_irqrestore(&phba->hbalock,
  4934. drvr_flag);
  4935. goto out_not_finished;
  4936. }
  4937. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4938. mb->mbxCommand) *
  4939. 1000) + jiffies;
  4940. i = 0;
  4941. /* Wait for command to complete */
  4942. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4943. (!(ha_copy & HA_MBATT) &&
  4944. (phba->link_state > LPFC_WARM_START))) {
  4945. if (time_after(jiffies, timeout)) {
  4946. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4947. spin_unlock_irqrestore(&phba->hbalock,
  4948. drvr_flag);
  4949. goto out_not_finished;
  4950. }
  4951. /* Check if we took a mbox interrupt while we were
  4952. polling */
  4953. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4954. && (evtctr != psli->slistat.mbox_event))
  4955. break;
  4956. if (i++ > 10) {
  4957. spin_unlock_irqrestore(&phba->hbalock,
  4958. drvr_flag);
  4959. msleep(1);
  4960. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4961. }
  4962. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4963. /* First copy command data */
  4964. word0 = *((uint32_t *)phba->mbox);
  4965. word0 = le32_to_cpu(word0);
  4966. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4967. MAILBOX_t *slimmb;
  4968. uint32_t slimword0;
  4969. /* Check real SLIM for any errors */
  4970. slimword0 = readl(phba->MBslimaddr);
  4971. slimmb = (MAILBOX_t *) & slimword0;
  4972. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4973. && slimmb->mbxStatus) {
  4974. psli->sli_flag &=
  4975. ~LPFC_SLI_ACTIVE;
  4976. word0 = slimword0;
  4977. }
  4978. }
  4979. } else {
  4980. /* First copy command data */
  4981. word0 = readl(phba->MBslimaddr);
  4982. }
  4983. /* Read the HBA Host Attention Register */
  4984. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  4985. spin_unlock_irqrestore(&phba->hbalock,
  4986. drvr_flag);
  4987. goto out_not_finished;
  4988. }
  4989. }
  4990. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4991. /* copy results back to user */
  4992. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4993. /* Copy the mailbox extension data */
  4994. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4995. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4996. pmbox->context2,
  4997. pmbox->out_ext_byte_len);
  4998. }
  4999. } else {
  5000. /* First copy command data */
  5001. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  5002. MAILBOX_CMD_SIZE);
  5003. /* Copy the mailbox extension data */
  5004. if (pmbox->out_ext_byte_len && pmbox->context2) {
  5005. lpfc_memcpy_from_slim(pmbox->context2,
  5006. phba->MBslimaddr +
  5007. MAILBOX_HBA_EXT_OFFSET,
  5008. pmbox->out_ext_byte_len);
  5009. }
  5010. }
  5011. writel(HA_MBATT, phba->HAregaddr);
  5012. readl(phba->HAregaddr); /* flush */
  5013. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5014. status = mb->mbxStatus;
  5015. }
  5016. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5017. return status;
  5018. out_not_finished:
  5019. if (processing_queue) {
  5020. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5021. lpfc_mbox_cmpl_put(phba, pmbox);
  5022. }
  5023. return MBX_NOT_FINISHED;
  5024. }
  5025. /**
  5026. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  5027. * @phba: Pointer to HBA context object.
  5028. *
  5029. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  5030. * the driver internal pending mailbox queue. It will then try to wait out the
  5031. * possible outstanding mailbox command before return.
  5032. *
  5033. * Returns:
  5034. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  5035. * the outstanding mailbox command timed out.
  5036. **/
  5037. static int
  5038. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  5039. {
  5040. struct lpfc_sli *psli = &phba->sli;
  5041. uint8_t actcmd = MBX_HEARTBEAT;
  5042. int rc = 0;
  5043. unsigned long timeout;
  5044. /* Mark the asynchronous mailbox command posting as blocked */
  5045. spin_lock_irq(&phba->hbalock);
  5046. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  5047. if (phba->sli.mbox_active)
  5048. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  5049. spin_unlock_irq(&phba->hbalock);
  5050. /* Determine how long we might wait for the active mailbox
  5051. * command to be gracefully completed by firmware.
  5052. */
  5053. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5054. jiffies;
  5055. /* Wait for the outstnading mailbox command to complete */
  5056. while (phba->sli.mbox_active) {
  5057. /* Check active mailbox complete status every 2ms */
  5058. msleep(2);
  5059. if (time_after(jiffies, timeout)) {
  5060. /* Timeout, marked the outstanding cmd not complete */
  5061. rc = 1;
  5062. break;
  5063. }
  5064. }
  5065. /* Can not cleanly block async mailbox command, fails it */
  5066. if (rc) {
  5067. spin_lock_irq(&phba->hbalock);
  5068. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5069. spin_unlock_irq(&phba->hbalock);
  5070. }
  5071. return rc;
  5072. }
  5073. /**
  5074. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5075. * @phba: Pointer to HBA context object.
  5076. *
  5077. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5078. * commands from the driver internal pending mailbox queue. It makes sure
  5079. * that there is no outstanding mailbox command before resuming posting
  5080. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5081. * mailbox command, it will try to wait it out before resuming asynchronous
  5082. * mailbox command posting.
  5083. **/
  5084. static void
  5085. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5086. {
  5087. struct lpfc_sli *psli = &phba->sli;
  5088. spin_lock_irq(&phba->hbalock);
  5089. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5090. /* Asynchronous mailbox posting is not blocked, do nothing */
  5091. spin_unlock_irq(&phba->hbalock);
  5092. return;
  5093. }
  5094. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5095. * successful or timeout, after timing-out the outstanding mailbox
  5096. * command shall always be removed, so just unblock posting async
  5097. * mailbox command and resume
  5098. */
  5099. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5100. spin_unlock_irq(&phba->hbalock);
  5101. /* wake up worker thread to post asynchronlous mailbox command */
  5102. lpfc_worker_wake_up(phba);
  5103. }
  5104. /**
  5105. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5106. * @phba: Pointer to HBA context object.
  5107. * @mboxq: Pointer to mailbox object.
  5108. *
  5109. * The function posts a mailbox to the port. The mailbox is expected
  5110. * to be comletely filled in and ready for the port to operate on it.
  5111. * This routine executes a synchronous completion operation on the
  5112. * mailbox by polling for its completion.
  5113. *
  5114. * The caller must not be holding any locks when calling this routine.
  5115. *
  5116. * Returns:
  5117. * MBX_SUCCESS - mailbox posted successfully
  5118. * Any of the MBX error values.
  5119. **/
  5120. static int
  5121. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5122. {
  5123. int rc = MBX_SUCCESS;
  5124. unsigned long iflag;
  5125. uint32_t db_ready;
  5126. uint32_t mcqe_status;
  5127. uint32_t mbx_cmnd;
  5128. unsigned long timeout;
  5129. struct lpfc_sli *psli = &phba->sli;
  5130. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5131. struct lpfc_bmbx_create *mbox_rgn;
  5132. struct dma_address *dma_address;
  5133. struct lpfc_register bmbx_reg;
  5134. /*
  5135. * Only one mailbox can be active to the bootstrap mailbox region
  5136. * at a time and there is no queueing provided.
  5137. */
  5138. spin_lock_irqsave(&phba->hbalock, iflag);
  5139. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5140. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5141. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5142. "(%d):2532 Mailbox command x%x (x%x) "
  5143. "cannot issue Data: x%x x%x\n",
  5144. mboxq->vport ? mboxq->vport->vpi : 0,
  5145. mboxq->u.mb.mbxCommand,
  5146. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5147. psli->sli_flag, MBX_POLL);
  5148. return MBXERR_ERROR;
  5149. }
  5150. /* The server grabs the token and owns it until release */
  5151. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5152. phba->sli.mbox_active = mboxq;
  5153. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5154. /*
  5155. * Initialize the bootstrap memory region to avoid stale data areas
  5156. * in the mailbox post. Then copy the caller's mailbox contents to
  5157. * the bmbx mailbox region.
  5158. */
  5159. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5160. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5161. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5162. sizeof(struct lpfc_mqe));
  5163. /* Post the high mailbox dma address to the port and wait for ready. */
  5164. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5165. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5166. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5167. * 1000) + jiffies;
  5168. do {
  5169. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5170. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5171. if (!db_ready)
  5172. msleep(2);
  5173. if (time_after(jiffies, timeout)) {
  5174. rc = MBXERR_ERROR;
  5175. goto exit;
  5176. }
  5177. } while (!db_ready);
  5178. /* Post the low mailbox dma address to the port. */
  5179. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5180. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5181. * 1000) + jiffies;
  5182. do {
  5183. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5184. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5185. if (!db_ready)
  5186. msleep(2);
  5187. if (time_after(jiffies, timeout)) {
  5188. rc = MBXERR_ERROR;
  5189. goto exit;
  5190. }
  5191. } while (!db_ready);
  5192. /*
  5193. * Read the CQ to ensure the mailbox has completed.
  5194. * If so, update the mailbox status so that the upper layers
  5195. * can complete the request normally.
  5196. */
  5197. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5198. sizeof(struct lpfc_mqe));
  5199. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5200. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5201. sizeof(struct lpfc_mcqe));
  5202. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5203. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  5204. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5205. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  5206. rc = MBXERR_ERROR;
  5207. } else
  5208. lpfc_sli4_swap_str(phba, mboxq);
  5209. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5210. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5211. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5212. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5213. mboxq->vport ? mboxq->vport->vpi : 0,
  5214. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5215. bf_get(lpfc_mqe_status, mb),
  5216. mb->un.mb_words[0], mb->un.mb_words[1],
  5217. mb->un.mb_words[2], mb->un.mb_words[3],
  5218. mb->un.mb_words[4], mb->un.mb_words[5],
  5219. mb->un.mb_words[6], mb->un.mb_words[7],
  5220. mb->un.mb_words[8], mb->un.mb_words[9],
  5221. mb->un.mb_words[10], mb->un.mb_words[11],
  5222. mb->un.mb_words[12], mboxq->mcqe.word0,
  5223. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5224. mboxq->mcqe.trailer);
  5225. exit:
  5226. /* We are holding the token, no needed for lock when release */
  5227. spin_lock_irqsave(&phba->hbalock, iflag);
  5228. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5229. phba->sli.mbox_active = NULL;
  5230. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5231. return rc;
  5232. }
  5233. /**
  5234. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5235. * @phba: Pointer to HBA context object.
  5236. * @pmbox: Pointer to mailbox object.
  5237. * @flag: Flag indicating how the mailbox need to be processed.
  5238. *
  5239. * This function is called by discovery code and HBA management code to submit
  5240. * a mailbox command to firmware with SLI-4 interface spec.
  5241. *
  5242. * Return codes the caller owns the mailbox command after the return of the
  5243. * function.
  5244. **/
  5245. static int
  5246. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5247. uint32_t flag)
  5248. {
  5249. struct lpfc_sli *psli = &phba->sli;
  5250. unsigned long iflags;
  5251. int rc;
  5252. rc = lpfc_mbox_dev_check(phba);
  5253. if (unlikely(rc)) {
  5254. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5255. "(%d):2544 Mailbox command x%x (x%x) "
  5256. "cannot issue Data: x%x x%x\n",
  5257. mboxq->vport ? mboxq->vport->vpi : 0,
  5258. mboxq->u.mb.mbxCommand,
  5259. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5260. psli->sli_flag, flag);
  5261. goto out_not_finished;
  5262. }
  5263. /* Detect polling mode and jump to a handler */
  5264. if (!phba->sli4_hba.intr_enable) {
  5265. if (flag == MBX_POLL)
  5266. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5267. else
  5268. rc = -EIO;
  5269. if (rc != MBX_SUCCESS)
  5270. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5271. "(%d):2541 Mailbox command x%x "
  5272. "(x%x) cannot issue Data: x%x x%x\n",
  5273. mboxq->vport ? mboxq->vport->vpi : 0,
  5274. mboxq->u.mb.mbxCommand,
  5275. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5276. psli->sli_flag, flag);
  5277. return rc;
  5278. } else if (flag == MBX_POLL) {
  5279. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5280. "(%d):2542 Try to issue mailbox command "
  5281. "x%x (x%x) synchronously ahead of async"
  5282. "mailbox command queue: x%x x%x\n",
  5283. mboxq->vport ? mboxq->vport->vpi : 0,
  5284. mboxq->u.mb.mbxCommand,
  5285. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5286. psli->sli_flag, flag);
  5287. /* Try to block the asynchronous mailbox posting */
  5288. rc = lpfc_sli4_async_mbox_block(phba);
  5289. if (!rc) {
  5290. /* Successfully blocked, now issue sync mbox cmd */
  5291. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5292. if (rc != MBX_SUCCESS)
  5293. lpfc_printf_log(phba, KERN_ERR,
  5294. LOG_MBOX | LOG_SLI,
  5295. "(%d):2597 Mailbox command "
  5296. "x%x (x%x) cannot issue "
  5297. "Data: x%x x%x\n",
  5298. mboxq->vport ?
  5299. mboxq->vport->vpi : 0,
  5300. mboxq->u.mb.mbxCommand,
  5301. lpfc_sli4_mbox_opcode_get(phba,
  5302. mboxq),
  5303. psli->sli_flag, flag);
  5304. /* Unblock the async mailbox posting afterward */
  5305. lpfc_sli4_async_mbox_unblock(phba);
  5306. }
  5307. return rc;
  5308. }
  5309. /* Now, interrupt mode asynchrous mailbox command */
  5310. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5311. if (rc) {
  5312. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5313. "(%d):2543 Mailbox command x%x (x%x) "
  5314. "cannot issue Data: x%x x%x\n",
  5315. mboxq->vport ? mboxq->vport->vpi : 0,
  5316. mboxq->u.mb.mbxCommand,
  5317. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5318. psli->sli_flag, flag);
  5319. goto out_not_finished;
  5320. }
  5321. /* Put the mailbox command to the driver internal FIFO */
  5322. psli->slistat.mbox_busy++;
  5323. spin_lock_irqsave(&phba->hbalock, iflags);
  5324. lpfc_mbox_put(phba, mboxq);
  5325. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5326. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5327. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5328. "x%x (x%x) x%x x%x x%x\n",
  5329. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5330. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5331. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5332. phba->pport->port_state,
  5333. psli->sli_flag, MBX_NOWAIT);
  5334. /* Wake up worker thread to transport mailbox command from head */
  5335. lpfc_worker_wake_up(phba);
  5336. return MBX_BUSY;
  5337. out_not_finished:
  5338. return MBX_NOT_FINISHED;
  5339. }
  5340. /**
  5341. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5342. * @phba: Pointer to HBA context object.
  5343. *
  5344. * This function is called by worker thread to send a mailbox command to
  5345. * SLI4 HBA firmware.
  5346. *
  5347. **/
  5348. int
  5349. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5350. {
  5351. struct lpfc_sli *psli = &phba->sli;
  5352. LPFC_MBOXQ_t *mboxq;
  5353. int rc = MBX_SUCCESS;
  5354. unsigned long iflags;
  5355. struct lpfc_mqe *mqe;
  5356. uint32_t mbx_cmnd;
  5357. /* Check interrupt mode before post async mailbox command */
  5358. if (unlikely(!phba->sli4_hba.intr_enable))
  5359. return MBX_NOT_FINISHED;
  5360. /* Check for mailbox command service token */
  5361. spin_lock_irqsave(&phba->hbalock, iflags);
  5362. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5363. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5364. return MBX_NOT_FINISHED;
  5365. }
  5366. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5367. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5368. return MBX_NOT_FINISHED;
  5369. }
  5370. if (unlikely(phba->sli.mbox_active)) {
  5371. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5372. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5373. "0384 There is pending active mailbox cmd\n");
  5374. return MBX_NOT_FINISHED;
  5375. }
  5376. /* Take the mailbox command service token */
  5377. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5378. /* Get the next mailbox command from head of queue */
  5379. mboxq = lpfc_mbox_get(phba);
  5380. /* If no more mailbox command waiting for post, we're done */
  5381. if (!mboxq) {
  5382. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5383. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5384. return MBX_SUCCESS;
  5385. }
  5386. phba->sli.mbox_active = mboxq;
  5387. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5388. /* Check device readiness for posting mailbox command */
  5389. rc = lpfc_mbox_dev_check(phba);
  5390. if (unlikely(rc))
  5391. /* Driver clean routine will clean up pending mailbox */
  5392. goto out_not_finished;
  5393. /* Prepare the mbox command to be posted */
  5394. mqe = &mboxq->u.mqe;
  5395. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5396. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5397. mod_timer(&psli->mbox_tmo, (jiffies +
  5398. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5399. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5400. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5401. "x%x x%x\n",
  5402. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5403. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5404. phba->pport->port_state, psli->sli_flag);
  5405. if (mbx_cmnd != MBX_HEARTBEAT) {
  5406. if (mboxq->vport) {
  5407. lpfc_debugfs_disc_trc(mboxq->vport,
  5408. LPFC_DISC_TRC_MBOX_VPORT,
  5409. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5410. mbx_cmnd, mqe->un.mb_words[0],
  5411. mqe->un.mb_words[1]);
  5412. } else {
  5413. lpfc_debugfs_disc_trc(phba->pport,
  5414. LPFC_DISC_TRC_MBOX,
  5415. "MBOX Send: cmd:x%x mb:x%x x%x",
  5416. mbx_cmnd, mqe->un.mb_words[0],
  5417. mqe->un.mb_words[1]);
  5418. }
  5419. }
  5420. psli->slistat.mbox_cmd++;
  5421. /* Post the mailbox command to the port */
  5422. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5423. if (rc != MBX_SUCCESS) {
  5424. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5425. "(%d):2533 Mailbox command x%x (x%x) "
  5426. "cannot issue Data: x%x x%x\n",
  5427. mboxq->vport ? mboxq->vport->vpi : 0,
  5428. mboxq->u.mb.mbxCommand,
  5429. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5430. psli->sli_flag, MBX_NOWAIT);
  5431. goto out_not_finished;
  5432. }
  5433. return rc;
  5434. out_not_finished:
  5435. spin_lock_irqsave(&phba->hbalock, iflags);
  5436. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5437. __lpfc_mbox_cmpl_put(phba, mboxq);
  5438. /* Release the token */
  5439. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5440. phba->sli.mbox_active = NULL;
  5441. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5442. return MBX_NOT_FINISHED;
  5443. }
  5444. /**
  5445. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5446. * @phba: Pointer to HBA context object.
  5447. * @pmbox: Pointer to mailbox object.
  5448. * @flag: Flag indicating how the mailbox need to be processed.
  5449. *
  5450. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5451. * the API jump table function pointer from the lpfc_hba struct.
  5452. *
  5453. * Return codes the caller owns the mailbox command after the return of the
  5454. * function.
  5455. **/
  5456. int
  5457. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5458. {
  5459. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5460. }
  5461. /**
  5462. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5463. * @phba: The hba struct for which this call is being executed.
  5464. * @dev_grp: The HBA PCI-Device group number.
  5465. *
  5466. * This routine sets up the mbox interface API function jump table in @phba
  5467. * struct.
  5468. * Returns: 0 - success, -ENODEV - failure.
  5469. **/
  5470. int
  5471. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5472. {
  5473. switch (dev_grp) {
  5474. case LPFC_PCI_DEV_LP:
  5475. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5476. phba->lpfc_sli_handle_slow_ring_event =
  5477. lpfc_sli_handle_slow_ring_event_s3;
  5478. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5479. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5480. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5481. break;
  5482. case LPFC_PCI_DEV_OC:
  5483. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5484. phba->lpfc_sli_handle_slow_ring_event =
  5485. lpfc_sli_handle_slow_ring_event_s4;
  5486. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5487. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5488. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5489. break;
  5490. default:
  5491. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5492. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5493. dev_grp);
  5494. return -ENODEV;
  5495. break;
  5496. }
  5497. return 0;
  5498. }
  5499. /**
  5500. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5501. * @phba: Pointer to HBA context object.
  5502. * @pring: Pointer to driver SLI ring object.
  5503. * @piocb: Pointer to address of newly added command iocb.
  5504. *
  5505. * This function is called with hbalock held to add a command
  5506. * iocb to the txq when SLI layer cannot submit the command iocb
  5507. * to the ring.
  5508. **/
  5509. void
  5510. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5511. struct lpfc_iocbq *piocb)
  5512. {
  5513. /* Insert the caller's iocb in the txq tail for later processing. */
  5514. list_add_tail(&piocb->list, &pring->txq);
  5515. pring->txq_cnt++;
  5516. }
  5517. /**
  5518. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5519. * @phba: Pointer to HBA context object.
  5520. * @pring: Pointer to driver SLI ring object.
  5521. * @piocb: Pointer to address of newly added command iocb.
  5522. *
  5523. * This function is called with hbalock held before a new
  5524. * iocb is submitted to the firmware. This function checks
  5525. * txq to flush the iocbs in txq to Firmware before
  5526. * submitting new iocbs to the Firmware.
  5527. * If there are iocbs in the txq which need to be submitted
  5528. * to firmware, lpfc_sli_next_iocb returns the first element
  5529. * of the txq after dequeuing it from txq.
  5530. * If there is no iocb in the txq then the function will return
  5531. * *piocb and *piocb is set to NULL. Caller needs to check
  5532. * *piocb to find if there are more commands in the txq.
  5533. **/
  5534. static struct lpfc_iocbq *
  5535. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5536. struct lpfc_iocbq **piocb)
  5537. {
  5538. struct lpfc_iocbq * nextiocb;
  5539. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5540. if (!nextiocb) {
  5541. nextiocb = *piocb;
  5542. *piocb = NULL;
  5543. }
  5544. return nextiocb;
  5545. }
  5546. /**
  5547. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5548. * @phba: Pointer to HBA context object.
  5549. * @ring_number: SLI ring number to issue iocb on.
  5550. * @piocb: Pointer to command iocb.
  5551. * @flag: Flag indicating if this command can be put into txq.
  5552. *
  5553. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5554. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5555. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5556. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5557. * this function allows only iocbs for posting buffers. This function finds
  5558. * next available slot in the command ring and posts the command to the
  5559. * available slot and writes the port attention register to request HBA start
  5560. * processing new iocb. If there is no slot available in the ring and
  5561. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5562. * the function returns IOCB_BUSY.
  5563. *
  5564. * This function is called with hbalock held. The function will return success
  5565. * after it successfully submit the iocb to firmware or after adding to the
  5566. * txq.
  5567. **/
  5568. static int
  5569. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5570. struct lpfc_iocbq *piocb, uint32_t flag)
  5571. {
  5572. struct lpfc_iocbq *nextiocb;
  5573. IOCB_t *iocb;
  5574. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5575. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5576. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5577. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5578. lpfc_printf_log(phba, KERN_ERR,
  5579. LOG_SLI | LOG_VPORT,
  5580. "1807 IOCB x%x failed. No vport\n",
  5581. piocb->iocb.ulpCommand);
  5582. dump_stack();
  5583. return IOCB_ERROR;
  5584. }
  5585. /* If the PCI channel is in offline state, do not post iocbs. */
  5586. if (unlikely(pci_channel_offline(phba->pcidev)))
  5587. return IOCB_ERROR;
  5588. /* If HBA has a deferred error attention, fail the iocb. */
  5589. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5590. return IOCB_ERROR;
  5591. /*
  5592. * We should never get an IOCB if we are in a < LINK_DOWN state
  5593. */
  5594. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5595. return IOCB_ERROR;
  5596. /*
  5597. * Check to see if we are blocking IOCB processing because of a
  5598. * outstanding event.
  5599. */
  5600. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5601. goto iocb_busy;
  5602. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5603. /*
  5604. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5605. * can be issued if the link is not up.
  5606. */
  5607. switch (piocb->iocb.ulpCommand) {
  5608. case CMD_GEN_REQUEST64_CR:
  5609. case CMD_GEN_REQUEST64_CX:
  5610. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5611. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5612. FC_RCTL_DD_UNSOL_CMD) ||
  5613. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5614. MENLO_TRANSPORT_TYPE))
  5615. goto iocb_busy;
  5616. break;
  5617. case CMD_QUE_RING_BUF_CN:
  5618. case CMD_QUE_RING_BUF64_CN:
  5619. /*
  5620. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5621. * completion, iocb_cmpl MUST be 0.
  5622. */
  5623. if (piocb->iocb_cmpl)
  5624. piocb->iocb_cmpl = NULL;
  5625. /*FALLTHROUGH*/
  5626. case CMD_CREATE_XRI_CR:
  5627. case CMD_CLOSE_XRI_CN:
  5628. case CMD_CLOSE_XRI_CX:
  5629. break;
  5630. default:
  5631. goto iocb_busy;
  5632. }
  5633. /*
  5634. * For FCP commands, we must be in a state where we can process link
  5635. * attention events.
  5636. */
  5637. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5638. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5639. goto iocb_busy;
  5640. }
  5641. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5642. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5643. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5644. if (iocb)
  5645. lpfc_sli_update_ring(phba, pring);
  5646. else
  5647. lpfc_sli_update_full_ring(phba, pring);
  5648. if (!piocb)
  5649. return IOCB_SUCCESS;
  5650. goto out_busy;
  5651. iocb_busy:
  5652. pring->stats.iocb_cmd_delay++;
  5653. out_busy:
  5654. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5655. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5656. return IOCB_SUCCESS;
  5657. }
  5658. return IOCB_BUSY;
  5659. }
  5660. /**
  5661. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5662. * @phba: Pointer to HBA context object.
  5663. * @piocb: Pointer to command iocb.
  5664. * @sglq: Pointer to the scatter gather queue object.
  5665. *
  5666. * This routine converts the bpl or bde that is in the IOCB
  5667. * to a sgl list for the sli4 hardware. The physical address
  5668. * of the bpl/bde is converted back to a virtual address.
  5669. * If the IOCB contains a BPL then the list of BDE's is
  5670. * converted to sli4_sge's. If the IOCB contains a single
  5671. * BDE then it is converted to a single sli_sge.
  5672. * The IOCB is still in cpu endianess so the contents of
  5673. * the bpl can be used without byte swapping.
  5674. *
  5675. * Returns valid XRI = Success, NO_XRI = Failure.
  5676. **/
  5677. static uint16_t
  5678. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5679. struct lpfc_sglq *sglq)
  5680. {
  5681. uint16_t xritag = NO_XRI;
  5682. struct ulp_bde64 *bpl = NULL;
  5683. struct ulp_bde64 bde;
  5684. struct sli4_sge *sgl = NULL;
  5685. IOCB_t *icmd;
  5686. int numBdes = 0;
  5687. int i = 0;
  5688. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5689. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5690. if (!piocbq || !sglq)
  5691. return xritag;
  5692. sgl = (struct sli4_sge *)sglq->sgl;
  5693. icmd = &piocbq->iocb;
  5694. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5695. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5696. sizeof(struct ulp_bde64);
  5697. /* The addrHigh and addrLow fields within the IOCB
  5698. * have not been byteswapped yet so there is no
  5699. * need to swap them back.
  5700. */
  5701. bpl = (struct ulp_bde64 *)
  5702. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5703. if (!bpl)
  5704. return xritag;
  5705. for (i = 0; i < numBdes; i++) {
  5706. /* Should already be byte swapped. */
  5707. sgl->addr_hi = bpl->addrHigh;
  5708. sgl->addr_lo = bpl->addrLow;
  5709. if ((i+1) == numBdes)
  5710. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5711. else
  5712. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5713. /* swap the size field back to the cpu so we
  5714. * can assign it to the sgl.
  5715. */
  5716. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5717. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5718. /* The offsets in the sgl need to be accumulated
  5719. * separately for the request and reply lists.
  5720. * The request is always first, the reply follows.
  5721. */
  5722. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5723. /* add up the reply sg entries */
  5724. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5725. inbound++;
  5726. /* first inbound? reset the offset */
  5727. if (inbound == 1)
  5728. offset = 0;
  5729. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5730. offset += bde.tus.f.bdeSize;
  5731. }
  5732. sgl->word2 = cpu_to_le32(sgl->word2);
  5733. bpl++;
  5734. sgl++;
  5735. }
  5736. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5737. /* The addrHigh and addrLow fields of the BDE have not
  5738. * been byteswapped yet so they need to be swapped
  5739. * before putting them in the sgl.
  5740. */
  5741. sgl->addr_hi =
  5742. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5743. sgl->addr_lo =
  5744. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5745. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5746. sgl->word2 = cpu_to_le32(sgl->word2);
  5747. sgl->sge_len =
  5748. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5749. }
  5750. return sglq->sli4_xritag;
  5751. }
  5752. /**
  5753. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5754. * @phba: Pointer to HBA context object.
  5755. *
  5756. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5757. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5758. * held.
  5759. *
  5760. * Return: index into SLI4 fast-path FCP queue index.
  5761. **/
  5762. static uint32_t
  5763. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5764. {
  5765. ++phba->fcp_qidx;
  5766. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5767. phba->fcp_qidx = 0;
  5768. return phba->fcp_qidx;
  5769. }
  5770. /**
  5771. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5772. * @phba: Pointer to HBA context object.
  5773. * @piocb: Pointer to command iocb.
  5774. * @wqe: Pointer to the work queue entry.
  5775. *
  5776. * This routine converts the iocb command to its Work Queue Entry
  5777. * equivalent. The wqe pointer should not have any fields set when
  5778. * this routine is called because it will memcpy over them.
  5779. * This routine does not set the CQ_ID or the WQEC bits in the
  5780. * wqe.
  5781. *
  5782. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5783. **/
  5784. static int
  5785. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5786. union lpfc_wqe *wqe)
  5787. {
  5788. uint32_t xmit_len = 0, total_len = 0;
  5789. uint8_t ct = 0;
  5790. uint32_t fip;
  5791. uint32_t abort_tag;
  5792. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5793. uint8_t cmnd;
  5794. uint16_t xritag;
  5795. uint16_t abrt_iotag;
  5796. struct lpfc_iocbq *abrtiocbq;
  5797. struct ulp_bde64 *bpl = NULL;
  5798. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5799. int numBdes, i;
  5800. struct ulp_bde64 bde;
  5801. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5802. /* The fcp commands will set command type */
  5803. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5804. command_type = FCP_COMMAND;
  5805. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5806. command_type = ELS_COMMAND_FIP;
  5807. else
  5808. command_type = ELS_COMMAND_NON_FIP;
  5809. /* Some of the fields are in the right position already */
  5810. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5811. abort_tag = (uint32_t) iocbq->iotag;
  5812. xritag = iocbq->sli4_xritag;
  5813. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5814. /* words0-2 bpl convert bde */
  5815. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5816. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5817. sizeof(struct ulp_bde64);
  5818. bpl = (struct ulp_bde64 *)
  5819. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5820. if (!bpl)
  5821. return IOCB_ERROR;
  5822. /* Should already be byte swapped. */
  5823. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5824. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5825. /* swap the size field back to the cpu so we
  5826. * can assign it to the sgl.
  5827. */
  5828. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5829. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5830. total_len = 0;
  5831. for (i = 0; i < numBdes; i++) {
  5832. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5833. total_len += bde.tus.f.bdeSize;
  5834. }
  5835. } else
  5836. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5837. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5838. cmnd = iocbq->iocb.ulpCommand;
  5839. switch (iocbq->iocb.ulpCommand) {
  5840. case CMD_ELS_REQUEST64_CR:
  5841. if (!iocbq->iocb.ulpLe) {
  5842. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5843. "2007 Only Limited Edition cmd Format"
  5844. " supported 0x%x\n",
  5845. iocbq->iocb.ulpCommand);
  5846. return IOCB_ERROR;
  5847. }
  5848. wqe->els_req.payload_len = xmit_len;
  5849. /* Els_reguest64 has a TMO */
  5850. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5851. iocbq->iocb.ulpTimeout);
  5852. /* Need a VF for word 4 set the vf bit*/
  5853. bf_set(els_req64_vf, &wqe->els_req, 0);
  5854. /* And a VFID for word 12 */
  5855. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5856. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5857. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5858. iocbq->iocb.ulpContext);
  5859. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5860. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5861. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5862. if (command_type == ELS_COMMAND_FIP) {
  5863. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5864. >> LPFC_FIP_ELS_ID_SHIFT);
  5865. }
  5866. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5867. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5868. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5869. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5870. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5871. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5872. break;
  5873. case CMD_XMIT_SEQUENCE64_CX:
  5874. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5875. iocbq->iocb.un.ulpWord[3]);
  5876. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5877. iocbq->iocb.ulpContext);
  5878. /* The entire sequence is transmitted for this IOCB */
  5879. xmit_len = total_len;
  5880. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5881. case CMD_XMIT_SEQUENCE64_CR:
  5882. /* word3 iocb=io_tag32 wqe=reserved */
  5883. wqe->xmit_sequence.rsvd3 = 0;
  5884. /* word4 relative_offset memcpy */
  5885. /* word5 r_ctl/df_ctl memcpy */
  5886. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5887. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5888. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5889. LPFC_WQE_IOD_WRITE);
  5890. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5891. LPFC_WQE_LENLOC_WORD12);
  5892. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5893. wqe->xmit_sequence.xmit_len = xmit_len;
  5894. command_type = OTHER_COMMAND;
  5895. break;
  5896. case CMD_XMIT_BCAST64_CN:
  5897. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5898. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5899. /* word4 iocb=rsvd wqe=rsvd */
  5900. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5901. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5902. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5903. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5904. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5905. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5906. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5907. LPFC_WQE_LENLOC_WORD3);
  5908. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5909. break;
  5910. case CMD_FCP_IWRITE64_CR:
  5911. command_type = FCP_COMMAND_DATA_OUT;
  5912. /* word3 iocb=iotag wqe=payload_offset_len */
  5913. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5914. wqe->fcp_iwrite.payload_offset_len =
  5915. xmit_len + sizeof(struct fcp_rsp);
  5916. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5917. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5918. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5919. iocbq->iocb.ulpFCP2Rcvy);
  5920. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5921. /* Always open the exchange */
  5922. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5923. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5924. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5925. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5926. LPFC_WQE_LENLOC_WORD4);
  5927. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5928. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5929. break;
  5930. case CMD_FCP_IREAD64_CR:
  5931. /* word3 iocb=iotag wqe=payload_offset_len */
  5932. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5933. wqe->fcp_iread.payload_offset_len =
  5934. xmit_len + sizeof(struct fcp_rsp);
  5935. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5936. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5937. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5938. iocbq->iocb.ulpFCP2Rcvy);
  5939. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5940. /* Always open the exchange */
  5941. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5942. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5943. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5944. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5945. LPFC_WQE_LENLOC_WORD4);
  5946. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5947. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5948. break;
  5949. case CMD_FCP_ICMND64_CR:
  5950. /* word3 iocb=IO_TAG wqe=reserved */
  5951. wqe->fcp_icmd.rsrvd3 = 0;
  5952. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5953. /* Always open the exchange */
  5954. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5955. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5956. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5957. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5958. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5959. LPFC_WQE_LENLOC_NONE);
  5960. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5961. break;
  5962. case CMD_GEN_REQUEST64_CR:
  5963. /* For this command calculate the xmit length of the
  5964. * request bde.
  5965. */
  5966. xmit_len = 0;
  5967. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5968. sizeof(struct ulp_bde64);
  5969. for (i = 0; i < numBdes; i++) {
  5970. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5971. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5972. break;
  5973. xmit_len += bde.tus.f.bdeSize;
  5974. }
  5975. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5976. wqe->gen_req.request_payload_len = xmit_len;
  5977. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5978. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5979. /* word6 context tag copied in memcpy */
  5980. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5981. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5982. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5983. "2015 Invalid CT %x command 0x%x\n",
  5984. ct, iocbq->iocb.ulpCommand);
  5985. return IOCB_ERROR;
  5986. }
  5987. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5988. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5989. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5990. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5991. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5992. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5993. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5994. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5995. command_type = OTHER_COMMAND;
  5996. break;
  5997. case CMD_XMIT_ELS_RSP64_CX:
  5998. /* words0-2 BDE memcpy */
  5999. /* word3 iocb=iotag32 wqe=response_payload_len */
  6000. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  6001. /* word4 iocb=did wge=rsvd. */
  6002. wqe->xmit_els_rsp.rsvd4 = 0;
  6003. /* word5 iocb=rsvd wge=did */
  6004. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  6005. iocbq->iocb.un.elsreq64.remoteID);
  6006. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  6007. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6008. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  6009. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  6010. iocbq->iocb.ulpContext);
  6011. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  6012. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  6013. iocbq->vport->vpi + phba->vpi_base);
  6014. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  6015. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  6016. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  6017. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  6018. LPFC_WQE_LENLOC_WORD3);
  6019. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  6020. command_type = OTHER_COMMAND;
  6021. break;
  6022. case CMD_CLOSE_XRI_CN:
  6023. case CMD_ABORT_XRI_CN:
  6024. case CMD_ABORT_XRI_CX:
  6025. /* words 0-2 memcpy should be 0 rserved */
  6026. /* port will send abts */
  6027. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  6028. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  6029. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  6030. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  6031. } else
  6032. fip = 0;
  6033. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  6034. /*
  6035. * The link is down, or the command was ELS_FIP
  6036. * so the fw does not need to send abts
  6037. * on the wire.
  6038. */
  6039. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  6040. else
  6041. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  6042. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  6043. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  6044. wqe->abort_cmd.rsrvd5 = 0;
  6045. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  6046. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6047. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  6048. /*
  6049. * The abort handler will send us CMD_ABORT_XRI_CN or
  6050. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6051. */
  6052. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6053. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6054. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6055. LPFC_WQE_LENLOC_NONE);
  6056. cmnd = CMD_ABORT_XRI_CX;
  6057. command_type = OTHER_COMMAND;
  6058. xritag = 0;
  6059. break;
  6060. case CMD_XMIT_BLS_RSP64_CX:
  6061. /* As BLS ABTS RSP WQE is very different from other WQEs,
  6062. * we re-construct this WQE here based on information in
  6063. * iocbq from scratch.
  6064. */
  6065. memset(wqe, 0, sizeof(union lpfc_wqe));
  6066. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6067. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6068. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  6069. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  6070. LPFC_ABTS_UNSOL_INT) {
  6071. /* ABTS sent by initiator to CT exchange, the
  6072. * RX_ID field will be filled with the newly
  6073. * allocated responder XRI.
  6074. */
  6075. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6076. iocbq->sli4_xritag);
  6077. } else {
  6078. /* ABTS sent by responder to CT exchange, the
  6079. * RX_ID field will be filled with the responder
  6080. * RX_ID from ABTS.
  6081. */
  6082. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6083. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  6084. }
  6085. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6086. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6087. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6088. iocbq->iocb.ulpContext);
  6089. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6090. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6091. LPFC_WQE_LENLOC_NONE);
  6092. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6093. command_type = OTHER_COMMAND;
  6094. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  6095. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  6096. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  6097. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  6098. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  6099. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  6100. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  6101. }
  6102. break;
  6103. case CMD_XRI_ABORTED_CX:
  6104. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6105. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6106. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6107. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6108. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6109. default:
  6110. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6111. "2014 Invalid command 0x%x\n",
  6112. iocbq->iocb.ulpCommand);
  6113. return IOCB_ERROR;
  6114. break;
  6115. }
  6116. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6117. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6118. wqe->generic.wqe_com.abort_tag = abort_tag;
  6119. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6120. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6121. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6122. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6123. return 0;
  6124. }
  6125. /**
  6126. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6127. * @phba: Pointer to HBA context object.
  6128. * @ring_number: SLI ring number to issue iocb on.
  6129. * @piocb: Pointer to command iocb.
  6130. * @flag: Flag indicating if this command can be put into txq.
  6131. *
  6132. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6133. * an iocb command to an HBA with SLI-4 interface spec.
  6134. *
  6135. * This function is called with hbalock held. The function will return success
  6136. * after it successfully submit the iocb to firmware or after adding to the
  6137. * txq.
  6138. **/
  6139. static int
  6140. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6141. struct lpfc_iocbq *piocb, uint32_t flag)
  6142. {
  6143. struct lpfc_sglq *sglq;
  6144. union lpfc_wqe wqe;
  6145. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6146. if (piocb->sli4_xritag == NO_XRI) {
  6147. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6148. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN ||
  6149. piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  6150. sglq = NULL;
  6151. else {
  6152. if (pring->txq_cnt) {
  6153. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6154. __lpfc_sli_ringtx_put(phba,
  6155. pring, piocb);
  6156. return IOCB_SUCCESS;
  6157. } else {
  6158. return IOCB_BUSY;
  6159. }
  6160. } else {
  6161. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6162. if (!sglq) {
  6163. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6164. __lpfc_sli_ringtx_put(phba,
  6165. pring,
  6166. piocb);
  6167. return IOCB_SUCCESS;
  6168. } else
  6169. return IOCB_BUSY;
  6170. }
  6171. }
  6172. }
  6173. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6174. sglq = NULL; /* These IO's already have an XRI and
  6175. * a mapped sgl.
  6176. */
  6177. } else {
  6178. /* This is a continuation of a commandi,(CX) so this
  6179. * sglq is on the active list
  6180. */
  6181. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6182. if (!sglq)
  6183. return IOCB_ERROR;
  6184. }
  6185. if (sglq) {
  6186. piocb->sli4_xritag = sglq->sli4_xritag;
  6187. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6188. return IOCB_ERROR;
  6189. }
  6190. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6191. return IOCB_ERROR;
  6192. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6193. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6194. /*
  6195. * For FCP command IOCB, get a new WQ index to distribute
  6196. * WQE across the WQsr. On the other hand, for abort IOCB,
  6197. * it carries the same WQ index to the original command
  6198. * IOCB.
  6199. */
  6200. if (piocb->iocb_flag & LPFC_IO_FCP)
  6201. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6202. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6203. &wqe))
  6204. return IOCB_ERROR;
  6205. } else {
  6206. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6207. return IOCB_ERROR;
  6208. }
  6209. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6210. return 0;
  6211. }
  6212. /**
  6213. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6214. *
  6215. * This routine wraps the actual lockless version for issusing IOCB function
  6216. * pointer from the lpfc_hba struct.
  6217. *
  6218. * Return codes:
  6219. * IOCB_ERROR - Error
  6220. * IOCB_SUCCESS - Success
  6221. * IOCB_BUSY - Busy
  6222. **/
  6223. int
  6224. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6225. struct lpfc_iocbq *piocb, uint32_t flag)
  6226. {
  6227. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6228. }
  6229. /**
  6230. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  6231. * @phba: The hba struct for which this call is being executed.
  6232. * @dev_grp: The HBA PCI-Device group number.
  6233. *
  6234. * This routine sets up the SLI interface API function jump table in @phba
  6235. * struct.
  6236. * Returns: 0 - success, -ENODEV - failure.
  6237. **/
  6238. int
  6239. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6240. {
  6241. switch (dev_grp) {
  6242. case LPFC_PCI_DEV_LP:
  6243. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6244. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6245. break;
  6246. case LPFC_PCI_DEV_OC:
  6247. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6248. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6249. break;
  6250. default:
  6251. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6252. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6253. dev_grp);
  6254. return -ENODEV;
  6255. break;
  6256. }
  6257. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6258. return 0;
  6259. }
  6260. /**
  6261. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6262. * @phba: Pointer to HBA context object.
  6263. * @pring: Pointer to driver SLI ring object.
  6264. * @piocb: Pointer to command iocb.
  6265. * @flag: Flag indicating if this command can be put into txq.
  6266. *
  6267. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6268. * function. This function gets the hbalock and calls
  6269. * __lpfc_sli_issue_iocb function and will return the error returned
  6270. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6271. * functions which do not hold hbalock.
  6272. **/
  6273. int
  6274. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6275. struct lpfc_iocbq *piocb, uint32_t flag)
  6276. {
  6277. unsigned long iflags;
  6278. int rc;
  6279. spin_lock_irqsave(&phba->hbalock, iflags);
  6280. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6281. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6282. return rc;
  6283. }
  6284. /**
  6285. * lpfc_extra_ring_setup - Extra ring setup function
  6286. * @phba: Pointer to HBA context object.
  6287. *
  6288. * This function is called while driver attaches with the
  6289. * HBA to setup the extra ring. The extra ring is used
  6290. * only when driver needs to support target mode functionality
  6291. * or IP over FC functionalities.
  6292. *
  6293. * This function is called with no lock held.
  6294. **/
  6295. static int
  6296. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6297. {
  6298. struct lpfc_sli *psli;
  6299. struct lpfc_sli_ring *pring;
  6300. psli = &phba->sli;
  6301. /* Adjust cmd/rsp ring iocb entries more evenly */
  6302. /* Take some away from the FCP ring */
  6303. pring = &psli->ring[psli->fcp_ring];
  6304. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6305. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6306. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6307. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6308. /* and give them to the extra ring */
  6309. pring = &psli->ring[psli->extra_ring];
  6310. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6311. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6312. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6313. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6314. /* Setup default profile for this ring */
  6315. pring->iotag_max = 4096;
  6316. pring->num_mask = 1;
  6317. pring->prt[0].profile = 0; /* Mask 0 */
  6318. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6319. pring->prt[0].type = phba->cfg_multi_ring_type;
  6320. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6321. return 0;
  6322. }
  6323. /**
  6324. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6325. * @phba: Pointer to HBA context object.
  6326. * @pring: Pointer to driver SLI ring object.
  6327. * @iocbq: Pointer to iocb object.
  6328. *
  6329. * This function is called by the slow ring event handler
  6330. * function when there is an ASYNC event iocb in the ring.
  6331. * This function is called with no lock held.
  6332. * Currently this function handles only temperature related
  6333. * ASYNC events. The function decodes the temperature sensor
  6334. * event message and posts events for the management applications.
  6335. **/
  6336. static void
  6337. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6338. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6339. {
  6340. IOCB_t *icmd;
  6341. uint16_t evt_code;
  6342. uint16_t temp;
  6343. struct temp_event temp_event_data;
  6344. struct Scsi_Host *shost;
  6345. uint32_t *iocb_w;
  6346. icmd = &iocbq->iocb;
  6347. evt_code = icmd->un.asyncstat.evt_code;
  6348. temp = icmd->ulpContext;
  6349. if ((evt_code != ASYNC_TEMP_WARN) &&
  6350. (evt_code != ASYNC_TEMP_SAFE)) {
  6351. iocb_w = (uint32_t *) icmd;
  6352. lpfc_printf_log(phba,
  6353. KERN_ERR,
  6354. LOG_SLI,
  6355. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6356. " evt_code 0x%x\n"
  6357. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6358. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6359. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6360. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6361. pring->ringno,
  6362. icmd->un.asyncstat.evt_code,
  6363. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6364. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6365. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6366. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6367. return;
  6368. }
  6369. temp_event_data.data = (uint32_t)temp;
  6370. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6371. if (evt_code == ASYNC_TEMP_WARN) {
  6372. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6373. lpfc_printf_log(phba,
  6374. KERN_ERR,
  6375. LOG_TEMP,
  6376. "0347 Adapter is very hot, please take "
  6377. "corrective action. temperature : %d Celsius\n",
  6378. temp);
  6379. }
  6380. if (evt_code == ASYNC_TEMP_SAFE) {
  6381. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6382. lpfc_printf_log(phba,
  6383. KERN_ERR,
  6384. LOG_TEMP,
  6385. "0340 Adapter temperature is OK now. "
  6386. "temperature : %d Celsius\n",
  6387. temp);
  6388. }
  6389. /* Send temperature change event to applications */
  6390. shost = lpfc_shost_from_vport(phba->pport);
  6391. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6392. sizeof(temp_event_data), (char *) &temp_event_data,
  6393. LPFC_NL_VENDOR_ID);
  6394. }
  6395. /**
  6396. * lpfc_sli_setup - SLI ring setup function
  6397. * @phba: Pointer to HBA context object.
  6398. *
  6399. * lpfc_sli_setup sets up rings of the SLI interface with
  6400. * number of iocbs per ring and iotags. This function is
  6401. * called while driver attach to the HBA and before the
  6402. * interrupts are enabled. So there is no need for locking.
  6403. *
  6404. * This function always returns 0.
  6405. **/
  6406. int
  6407. lpfc_sli_setup(struct lpfc_hba *phba)
  6408. {
  6409. int i, totiocbsize = 0;
  6410. struct lpfc_sli *psli = &phba->sli;
  6411. struct lpfc_sli_ring *pring;
  6412. psli->num_rings = MAX_CONFIGURED_RINGS;
  6413. psli->sli_flag = 0;
  6414. psli->fcp_ring = LPFC_FCP_RING;
  6415. psli->next_ring = LPFC_FCP_NEXT_RING;
  6416. psli->extra_ring = LPFC_EXTRA_RING;
  6417. psli->iocbq_lookup = NULL;
  6418. psli->iocbq_lookup_len = 0;
  6419. psli->last_iotag = 0;
  6420. for (i = 0; i < psli->num_rings; i++) {
  6421. pring = &psli->ring[i];
  6422. switch (i) {
  6423. case LPFC_FCP_RING: /* ring 0 - FCP */
  6424. /* numCiocb and numRiocb are used in config_port */
  6425. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6426. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6427. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6428. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6429. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6430. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6431. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6432. SLI3_IOCB_CMD_SIZE :
  6433. SLI2_IOCB_CMD_SIZE;
  6434. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6435. SLI3_IOCB_RSP_SIZE :
  6436. SLI2_IOCB_RSP_SIZE;
  6437. pring->iotag_ctr = 0;
  6438. pring->iotag_max =
  6439. (phba->cfg_hba_queue_depth * 2);
  6440. pring->fast_iotag = pring->iotag_max;
  6441. pring->num_mask = 0;
  6442. break;
  6443. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6444. /* numCiocb and numRiocb are used in config_port */
  6445. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6446. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6447. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6448. SLI3_IOCB_CMD_SIZE :
  6449. SLI2_IOCB_CMD_SIZE;
  6450. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6451. SLI3_IOCB_RSP_SIZE :
  6452. SLI2_IOCB_RSP_SIZE;
  6453. pring->iotag_max = phba->cfg_hba_queue_depth;
  6454. pring->num_mask = 0;
  6455. break;
  6456. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6457. /* numCiocb and numRiocb are used in config_port */
  6458. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6459. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6460. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6461. SLI3_IOCB_CMD_SIZE :
  6462. SLI2_IOCB_CMD_SIZE;
  6463. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6464. SLI3_IOCB_RSP_SIZE :
  6465. SLI2_IOCB_RSP_SIZE;
  6466. pring->fast_iotag = 0;
  6467. pring->iotag_ctr = 0;
  6468. pring->iotag_max = 4096;
  6469. pring->lpfc_sli_rcv_async_status =
  6470. lpfc_sli_async_event_handler;
  6471. pring->num_mask = LPFC_MAX_RING_MASK;
  6472. pring->prt[0].profile = 0; /* Mask 0 */
  6473. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6474. pring->prt[0].type = FC_TYPE_ELS;
  6475. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6476. lpfc_els_unsol_event;
  6477. pring->prt[1].profile = 0; /* Mask 1 */
  6478. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6479. pring->prt[1].type = FC_TYPE_ELS;
  6480. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6481. lpfc_els_unsol_event;
  6482. pring->prt[2].profile = 0; /* Mask 2 */
  6483. /* NameServer Inquiry */
  6484. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6485. /* NameServer */
  6486. pring->prt[2].type = FC_TYPE_CT;
  6487. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6488. lpfc_ct_unsol_event;
  6489. pring->prt[3].profile = 0; /* Mask 3 */
  6490. /* NameServer response */
  6491. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6492. /* NameServer */
  6493. pring->prt[3].type = FC_TYPE_CT;
  6494. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6495. lpfc_ct_unsol_event;
  6496. /* abort unsolicited sequence */
  6497. pring->prt[4].profile = 0; /* Mask 4 */
  6498. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6499. pring->prt[4].type = FC_TYPE_BLS;
  6500. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6501. lpfc_sli4_ct_abort_unsol_event;
  6502. break;
  6503. }
  6504. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6505. (pring->numRiocb * pring->sizeRiocb);
  6506. }
  6507. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6508. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6509. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6510. "SLI2 SLIM Data: x%x x%lx\n",
  6511. phba->brd_no, totiocbsize,
  6512. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6513. }
  6514. if (phba->cfg_multi_ring_support == 2)
  6515. lpfc_extra_ring_setup(phba);
  6516. return 0;
  6517. }
  6518. /**
  6519. * lpfc_sli_queue_setup - Queue initialization function
  6520. * @phba: Pointer to HBA context object.
  6521. *
  6522. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6523. * ring. This function also initializes ring indices of each ring.
  6524. * This function is called during the initialization of the SLI
  6525. * interface of an HBA.
  6526. * This function is called with no lock held and always returns
  6527. * 1.
  6528. **/
  6529. int
  6530. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6531. {
  6532. struct lpfc_sli *psli;
  6533. struct lpfc_sli_ring *pring;
  6534. int i;
  6535. psli = &phba->sli;
  6536. spin_lock_irq(&phba->hbalock);
  6537. INIT_LIST_HEAD(&psli->mboxq);
  6538. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6539. /* Initialize list headers for txq and txcmplq as double linked lists */
  6540. for (i = 0; i < psli->num_rings; i++) {
  6541. pring = &psli->ring[i];
  6542. pring->ringno = i;
  6543. pring->next_cmdidx = 0;
  6544. pring->local_getidx = 0;
  6545. pring->cmdidx = 0;
  6546. INIT_LIST_HEAD(&pring->txq);
  6547. INIT_LIST_HEAD(&pring->txcmplq);
  6548. INIT_LIST_HEAD(&pring->iocb_continueq);
  6549. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6550. INIT_LIST_HEAD(&pring->postbufq);
  6551. }
  6552. spin_unlock_irq(&phba->hbalock);
  6553. return 1;
  6554. }
  6555. /**
  6556. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6557. * @phba: Pointer to HBA context object.
  6558. *
  6559. * This routine flushes the mailbox command subsystem. It will unconditionally
  6560. * flush all the mailbox commands in the three possible stages in the mailbox
  6561. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6562. * command; and completed mailbox command queue. It is caller's responsibility
  6563. * to make sure that the driver is in the proper state to flush the mailbox
  6564. * command sub-system. Namely, the posting of mailbox commands into the
  6565. * pending mailbox command queue from the various clients must be stopped;
  6566. * either the HBA is in a state that it will never works on the outstanding
  6567. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6568. * mailbox command has been completed.
  6569. **/
  6570. static void
  6571. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6572. {
  6573. LIST_HEAD(completions);
  6574. struct lpfc_sli *psli = &phba->sli;
  6575. LPFC_MBOXQ_t *pmb;
  6576. unsigned long iflag;
  6577. /* Flush all the mailbox commands in the mbox system */
  6578. spin_lock_irqsave(&phba->hbalock, iflag);
  6579. /* The pending mailbox command queue */
  6580. list_splice_init(&phba->sli.mboxq, &completions);
  6581. /* The outstanding active mailbox command */
  6582. if (psli->mbox_active) {
  6583. list_add_tail(&psli->mbox_active->list, &completions);
  6584. psli->mbox_active = NULL;
  6585. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6586. }
  6587. /* The completed mailbox command queue */
  6588. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6589. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6590. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6591. while (!list_empty(&completions)) {
  6592. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6593. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6594. if (pmb->mbox_cmpl)
  6595. pmb->mbox_cmpl(phba, pmb);
  6596. }
  6597. }
  6598. /**
  6599. * lpfc_sli_host_down - Vport cleanup function
  6600. * @vport: Pointer to virtual port object.
  6601. *
  6602. * lpfc_sli_host_down is called to clean up the resources
  6603. * associated with a vport before destroying virtual
  6604. * port data structures.
  6605. * This function does following operations:
  6606. * - Free discovery resources associated with this virtual
  6607. * port.
  6608. * - Free iocbs associated with this virtual port in
  6609. * the txq.
  6610. * - Send abort for all iocb commands associated with this
  6611. * vport in txcmplq.
  6612. *
  6613. * This function is called with no lock held and always returns 1.
  6614. **/
  6615. int
  6616. lpfc_sli_host_down(struct lpfc_vport *vport)
  6617. {
  6618. LIST_HEAD(completions);
  6619. struct lpfc_hba *phba = vport->phba;
  6620. struct lpfc_sli *psli = &phba->sli;
  6621. struct lpfc_sli_ring *pring;
  6622. struct lpfc_iocbq *iocb, *next_iocb;
  6623. int i;
  6624. unsigned long flags = 0;
  6625. uint16_t prev_pring_flag;
  6626. lpfc_cleanup_discovery_resources(vport);
  6627. spin_lock_irqsave(&phba->hbalock, flags);
  6628. for (i = 0; i < psli->num_rings; i++) {
  6629. pring = &psli->ring[i];
  6630. prev_pring_flag = pring->flag;
  6631. /* Only slow rings */
  6632. if (pring->ringno == LPFC_ELS_RING) {
  6633. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6634. /* Set the lpfc data pending flag */
  6635. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6636. }
  6637. /*
  6638. * Error everything on the txq since these iocbs have not been
  6639. * given to the FW yet.
  6640. */
  6641. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6642. if (iocb->vport != vport)
  6643. continue;
  6644. list_move_tail(&iocb->list, &completions);
  6645. pring->txq_cnt--;
  6646. }
  6647. /* Next issue ABTS for everything on the txcmplq */
  6648. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6649. list) {
  6650. if (iocb->vport != vport)
  6651. continue;
  6652. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6653. }
  6654. pring->flag = prev_pring_flag;
  6655. }
  6656. spin_unlock_irqrestore(&phba->hbalock, flags);
  6657. /* Cancel all the IOCBs from the completions list */
  6658. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6659. IOERR_SLI_DOWN);
  6660. return 1;
  6661. }
  6662. /**
  6663. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6664. * @phba: Pointer to HBA context object.
  6665. *
  6666. * This function cleans up all iocb, buffers, mailbox commands
  6667. * while shutting down the HBA. This function is called with no
  6668. * lock held and always returns 1.
  6669. * This function does the following to cleanup driver resources:
  6670. * - Free discovery resources for each virtual port
  6671. * - Cleanup any pending fabric iocbs
  6672. * - Iterate through the iocb txq and free each entry
  6673. * in the list.
  6674. * - Free up any buffer posted to the HBA
  6675. * - Free mailbox commands in the mailbox queue.
  6676. **/
  6677. int
  6678. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6679. {
  6680. LIST_HEAD(completions);
  6681. struct lpfc_sli *psli = &phba->sli;
  6682. struct lpfc_sli_ring *pring;
  6683. struct lpfc_dmabuf *buf_ptr;
  6684. unsigned long flags = 0;
  6685. int i;
  6686. /* Shutdown the mailbox command sub-system */
  6687. lpfc_sli_mbox_sys_shutdown(phba);
  6688. lpfc_hba_down_prep(phba);
  6689. lpfc_fabric_abort_hba(phba);
  6690. spin_lock_irqsave(&phba->hbalock, flags);
  6691. for (i = 0; i < psli->num_rings; i++) {
  6692. pring = &psli->ring[i];
  6693. /* Only slow rings */
  6694. if (pring->ringno == LPFC_ELS_RING) {
  6695. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6696. /* Set the lpfc data pending flag */
  6697. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6698. }
  6699. /*
  6700. * Error everything on the txq since these iocbs have not been
  6701. * given to the FW yet.
  6702. */
  6703. list_splice_init(&pring->txq, &completions);
  6704. pring->txq_cnt = 0;
  6705. }
  6706. spin_unlock_irqrestore(&phba->hbalock, flags);
  6707. /* Cancel all the IOCBs from the completions list */
  6708. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6709. IOERR_SLI_DOWN);
  6710. spin_lock_irqsave(&phba->hbalock, flags);
  6711. list_splice_init(&phba->elsbuf, &completions);
  6712. phba->elsbuf_cnt = 0;
  6713. phba->elsbuf_prev_cnt = 0;
  6714. spin_unlock_irqrestore(&phba->hbalock, flags);
  6715. while (!list_empty(&completions)) {
  6716. list_remove_head(&completions, buf_ptr,
  6717. struct lpfc_dmabuf, list);
  6718. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6719. kfree(buf_ptr);
  6720. }
  6721. /* Return any active mbox cmds */
  6722. del_timer_sync(&psli->mbox_tmo);
  6723. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6724. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6725. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6726. return 1;
  6727. }
  6728. /**
  6729. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6730. * @srcp: Source memory pointer.
  6731. * @destp: Destination memory pointer.
  6732. * @cnt: Number of words required to be copied.
  6733. *
  6734. * This function is used for copying data between driver memory
  6735. * and the SLI memory. This function also changes the endianness
  6736. * of each word if native endianness is different from SLI
  6737. * endianness. This function can be called with or without
  6738. * lock.
  6739. **/
  6740. void
  6741. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6742. {
  6743. uint32_t *src = srcp;
  6744. uint32_t *dest = destp;
  6745. uint32_t ldata;
  6746. int i;
  6747. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6748. ldata = *src;
  6749. ldata = le32_to_cpu(ldata);
  6750. *dest = ldata;
  6751. src++;
  6752. dest++;
  6753. }
  6754. }
  6755. /**
  6756. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6757. * @srcp: Source memory pointer.
  6758. * @destp: Destination memory pointer.
  6759. * @cnt: Number of words required to be copied.
  6760. *
  6761. * This function is used for copying data between a data structure
  6762. * with big endian representation to local endianness.
  6763. * This function can be called with or without lock.
  6764. **/
  6765. void
  6766. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6767. {
  6768. uint32_t *src = srcp;
  6769. uint32_t *dest = destp;
  6770. uint32_t ldata;
  6771. int i;
  6772. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6773. ldata = *src;
  6774. ldata = be32_to_cpu(ldata);
  6775. *dest = ldata;
  6776. src++;
  6777. dest++;
  6778. }
  6779. }
  6780. /**
  6781. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6782. * @phba: Pointer to HBA context object.
  6783. * @pring: Pointer to driver SLI ring object.
  6784. * @mp: Pointer to driver buffer object.
  6785. *
  6786. * This function is called with no lock held.
  6787. * It always return zero after adding the buffer to the postbufq
  6788. * buffer list.
  6789. **/
  6790. int
  6791. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6792. struct lpfc_dmabuf *mp)
  6793. {
  6794. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6795. later */
  6796. spin_lock_irq(&phba->hbalock);
  6797. list_add_tail(&mp->list, &pring->postbufq);
  6798. pring->postbufq_cnt++;
  6799. spin_unlock_irq(&phba->hbalock);
  6800. return 0;
  6801. }
  6802. /**
  6803. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6804. * @phba: Pointer to HBA context object.
  6805. *
  6806. * When HBQ is enabled, buffers are searched based on tags. This function
  6807. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6808. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6809. * does not conflict with tags of buffer posted for unsolicited events.
  6810. * The function returns the allocated tag. The function is called with
  6811. * no locks held.
  6812. **/
  6813. uint32_t
  6814. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6815. {
  6816. spin_lock_irq(&phba->hbalock);
  6817. phba->buffer_tag_count++;
  6818. /*
  6819. * Always set the QUE_BUFTAG_BIT to distiguish between
  6820. * a tag assigned by HBQ.
  6821. */
  6822. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6823. spin_unlock_irq(&phba->hbalock);
  6824. return phba->buffer_tag_count;
  6825. }
  6826. /**
  6827. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6828. * @phba: Pointer to HBA context object.
  6829. * @pring: Pointer to driver SLI ring object.
  6830. * @tag: Buffer tag.
  6831. *
  6832. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6833. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6834. * iocb is posted to the response ring with the tag of the buffer.
  6835. * This function searches the pring->postbufq list using the tag
  6836. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6837. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6838. * buffer is returned to the caller else NULL is returned.
  6839. * This function is called with no lock held.
  6840. **/
  6841. struct lpfc_dmabuf *
  6842. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6843. uint32_t tag)
  6844. {
  6845. struct lpfc_dmabuf *mp, *next_mp;
  6846. struct list_head *slp = &pring->postbufq;
  6847. /* Search postbufq, from the begining, looking for a match on tag */
  6848. spin_lock_irq(&phba->hbalock);
  6849. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6850. if (mp->buffer_tag == tag) {
  6851. list_del_init(&mp->list);
  6852. pring->postbufq_cnt--;
  6853. spin_unlock_irq(&phba->hbalock);
  6854. return mp;
  6855. }
  6856. }
  6857. spin_unlock_irq(&phba->hbalock);
  6858. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6859. "0402 Cannot find virtual addr for buffer tag on "
  6860. "ring %d Data x%lx x%p x%p x%x\n",
  6861. pring->ringno, (unsigned long) tag,
  6862. slp->next, slp->prev, pring->postbufq_cnt);
  6863. return NULL;
  6864. }
  6865. /**
  6866. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6867. * @phba: Pointer to HBA context object.
  6868. * @pring: Pointer to driver SLI ring object.
  6869. * @phys: DMA address of the buffer.
  6870. *
  6871. * This function searches the buffer list using the dma_address
  6872. * of unsolicited event to find the driver's lpfc_dmabuf object
  6873. * corresponding to the dma_address. The function returns the
  6874. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6875. * This function is called by the ct and els unsolicited event
  6876. * handlers to get the buffer associated with the unsolicited
  6877. * event.
  6878. *
  6879. * This function is called with no lock held.
  6880. **/
  6881. struct lpfc_dmabuf *
  6882. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6883. dma_addr_t phys)
  6884. {
  6885. struct lpfc_dmabuf *mp, *next_mp;
  6886. struct list_head *slp = &pring->postbufq;
  6887. /* Search postbufq, from the begining, looking for a match on phys */
  6888. spin_lock_irq(&phba->hbalock);
  6889. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6890. if (mp->phys == phys) {
  6891. list_del_init(&mp->list);
  6892. pring->postbufq_cnt--;
  6893. spin_unlock_irq(&phba->hbalock);
  6894. return mp;
  6895. }
  6896. }
  6897. spin_unlock_irq(&phba->hbalock);
  6898. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6899. "0410 Cannot find virtual addr for mapped buf on "
  6900. "ring %d Data x%llx x%p x%p x%x\n",
  6901. pring->ringno, (unsigned long long)phys,
  6902. slp->next, slp->prev, pring->postbufq_cnt);
  6903. return NULL;
  6904. }
  6905. /**
  6906. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6907. * @phba: Pointer to HBA context object.
  6908. * @cmdiocb: Pointer to driver command iocb object.
  6909. * @rspiocb: Pointer to driver response iocb object.
  6910. *
  6911. * This function is the completion handler for the abort iocbs for
  6912. * ELS commands. This function is called from the ELS ring event
  6913. * handler with no lock held. This function frees memory resources
  6914. * associated with the abort iocb.
  6915. **/
  6916. static void
  6917. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6918. struct lpfc_iocbq *rspiocb)
  6919. {
  6920. IOCB_t *irsp = &rspiocb->iocb;
  6921. uint16_t abort_iotag, abort_context;
  6922. struct lpfc_iocbq *abort_iocb;
  6923. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6924. abort_iocb = NULL;
  6925. if (irsp->ulpStatus) {
  6926. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6927. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6928. spin_lock_irq(&phba->hbalock);
  6929. if (phba->sli_rev < LPFC_SLI_REV4) {
  6930. if (abort_iotag != 0 &&
  6931. abort_iotag <= phba->sli.last_iotag)
  6932. abort_iocb =
  6933. phba->sli.iocbq_lookup[abort_iotag];
  6934. } else
  6935. /* For sli4 the abort_tag is the XRI,
  6936. * so the abort routine puts the iotag of the iocb
  6937. * being aborted in the context field of the abort
  6938. * IOCB.
  6939. */
  6940. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6941. /*
  6942. * If the iocb is not found in Firmware queue the iocb
  6943. * might have completed already. Do not free it again.
  6944. */
  6945. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6946. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6947. spin_unlock_irq(&phba->hbalock);
  6948. lpfc_sli_release_iocbq(phba, cmdiocb);
  6949. return;
  6950. }
  6951. /* For SLI4 the ulpContext field for abort IOCB
  6952. * holds the iotag of the IOCB being aborted so
  6953. * the local abort_context needs to be reset to
  6954. * match the aborted IOCBs ulpContext.
  6955. */
  6956. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6957. abort_context = abort_iocb->iocb.ulpContext;
  6958. }
  6959. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6960. "0327 Cannot abort els iocb %p "
  6961. "with tag %x context %x, abort status %x, "
  6962. "abort code %x\n",
  6963. abort_iocb, abort_iotag, abort_context,
  6964. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6965. /*
  6966. * make sure we have the right iocbq before taking it
  6967. * off the txcmplq and try to call completion routine.
  6968. */
  6969. if (!abort_iocb ||
  6970. abort_iocb->iocb.ulpContext != abort_context ||
  6971. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6972. spin_unlock_irq(&phba->hbalock);
  6973. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6974. /*
  6975. * leave the SLI4 aborted command on the txcmplq
  6976. * list and the command complete WCQE's XB bit
  6977. * will tell whether the SGL (XRI) can be released
  6978. * immediately or to the aborted SGL list for the
  6979. * following abort XRI from the HBA.
  6980. */
  6981. list_del_init(&abort_iocb->list);
  6982. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6983. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6984. pring->txcmplq_cnt--;
  6985. }
  6986. /* Firmware could still be in progress of DMAing
  6987. * payload, so don't free data buffer till after
  6988. * a hbeat.
  6989. */
  6990. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6991. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6992. spin_unlock_irq(&phba->hbalock);
  6993. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6994. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6995. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6996. } else
  6997. spin_unlock_irq(&phba->hbalock);
  6998. }
  6999. lpfc_sli_release_iocbq(phba, cmdiocb);
  7000. return;
  7001. }
  7002. /**
  7003. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  7004. * @phba: Pointer to HBA context object.
  7005. * @cmdiocb: Pointer to driver command iocb object.
  7006. * @rspiocb: Pointer to driver response iocb object.
  7007. *
  7008. * The function is called from SLI ring event handler with no
  7009. * lock held. This function is the completion handler for ELS commands
  7010. * which are aborted. The function frees memory resources used for
  7011. * the aborted ELS commands.
  7012. **/
  7013. static void
  7014. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7015. struct lpfc_iocbq *rspiocb)
  7016. {
  7017. IOCB_t *irsp = &rspiocb->iocb;
  7018. /* ELS cmd tag <ulpIoTag> completes */
  7019. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  7020. "0139 Ignoring ELS cmd tag x%x completion Data: "
  7021. "x%x x%x x%x\n",
  7022. irsp->ulpIoTag, irsp->ulpStatus,
  7023. irsp->un.ulpWord[4], irsp->ulpTimeout);
  7024. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  7025. lpfc_ct_free_iocb(phba, cmdiocb);
  7026. else
  7027. lpfc_els_free_iocb(phba, cmdiocb);
  7028. return;
  7029. }
  7030. /**
  7031. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  7032. * @phba: Pointer to HBA context object.
  7033. * @pring: Pointer to driver SLI ring object.
  7034. * @cmdiocb: Pointer to driver command iocb object.
  7035. *
  7036. * This function issues an abort iocb for the provided command iocb down to
  7037. * the port. Other than the case the outstanding command iocb is an abort
  7038. * request, this function issues abort out unconditionally. This function is
  7039. * called with hbalock held. The function returns 0 when it fails due to
  7040. * memory allocation failure or when the command iocb is an abort request.
  7041. **/
  7042. static int
  7043. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7044. struct lpfc_iocbq *cmdiocb)
  7045. {
  7046. struct lpfc_vport *vport = cmdiocb->vport;
  7047. struct lpfc_iocbq *abtsiocbp;
  7048. IOCB_t *icmd = NULL;
  7049. IOCB_t *iabt = NULL;
  7050. int retval;
  7051. /*
  7052. * There are certain command types we don't want to abort. And we
  7053. * don't want to abort commands that are already in the process of
  7054. * being aborted.
  7055. */
  7056. icmd = &cmdiocb->iocb;
  7057. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7058. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7059. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7060. return 0;
  7061. /* issue ABTS for this IOCB based on iotag */
  7062. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7063. if (abtsiocbp == NULL)
  7064. return 0;
  7065. /* This signals the response to set the correct status
  7066. * before calling the completion handler
  7067. */
  7068. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7069. iabt = &abtsiocbp->iocb;
  7070. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7071. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7072. if (phba->sli_rev == LPFC_SLI_REV4) {
  7073. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7074. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7075. }
  7076. else
  7077. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7078. iabt->ulpLe = 1;
  7079. iabt->ulpClass = icmd->ulpClass;
  7080. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7081. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7082. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7083. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7084. if (phba->link_state >= LPFC_LINK_UP)
  7085. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7086. else
  7087. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7088. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7089. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7090. "0339 Abort xri x%x, original iotag x%x, "
  7091. "abort cmd iotag x%x\n",
  7092. iabt->un.acxri.abortIoTag,
  7093. iabt->un.acxri.abortContextTag,
  7094. abtsiocbp->iotag);
  7095. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7096. if (retval)
  7097. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7098. /*
  7099. * Caller to this routine should check for IOCB_ERROR
  7100. * and handle it properly. This routine no longer removes
  7101. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7102. */
  7103. return retval;
  7104. }
  7105. /**
  7106. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7107. * @phba: Pointer to HBA context object.
  7108. * @pring: Pointer to driver SLI ring object.
  7109. * @cmdiocb: Pointer to driver command iocb object.
  7110. *
  7111. * This function issues an abort iocb for the provided command iocb. In case
  7112. * of unloading, the abort iocb will not be issued to commands on the ELS
  7113. * ring. Instead, the callback function shall be changed to those commands
  7114. * so that nothing happens when them finishes. This function is called with
  7115. * hbalock held. The function returns 0 when the command iocb is an abort
  7116. * request.
  7117. **/
  7118. int
  7119. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7120. struct lpfc_iocbq *cmdiocb)
  7121. {
  7122. struct lpfc_vport *vport = cmdiocb->vport;
  7123. int retval = IOCB_ERROR;
  7124. IOCB_t *icmd = NULL;
  7125. /*
  7126. * There are certain command types we don't want to abort. And we
  7127. * don't want to abort commands that are already in the process of
  7128. * being aborted.
  7129. */
  7130. icmd = &cmdiocb->iocb;
  7131. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7132. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7133. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7134. return 0;
  7135. /*
  7136. * If we're unloading, don't abort iocb on the ELS ring, but change
  7137. * the callback so that nothing happens when it finishes.
  7138. */
  7139. if ((vport->load_flag & FC_UNLOADING) &&
  7140. (pring->ringno == LPFC_ELS_RING)) {
  7141. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7142. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7143. else
  7144. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7145. goto abort_iotag_exit;
  7146. }
  7147. /* Now, we try to issue the abort to the cmdiocb out */
  7148. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7149. abort_iotag_exit:
  7150. /*
  7151. * Caller to this routine should check for IOCB_ERROR
  7152. * and handle it properly. This routine no longer removes
  7153. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7154. */
  7155. return retval;
  7156. }
  7157. /**
  7158. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7159. * @phba: Pointer to HBA context object.
  7160. * @pring: Pointer to driver SLI ring object.
  7161. *
  7162. * This function aborts all iocbs in the given ring and frees all the iocb
  7163. * objects in txq. This function issues abort iocbs unconditionally for all
  7164. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7165. * to complete before the return of this function. The caller is not required
  7166. * to hold any locks.
  7167. **/
  7168. static void
  7169. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7170. {
  7171. LIST_HEAD(completions);
  7172. struct lpfc_iocbq *iocb, *next_iocb;
  7173. if (pring->ringno == LPFC_ELS_RING)
  7174. lpfc_fabric_abort_hba(phba);
  7175. spin_lock_irq(&phba->hbalock);
  7176. /* Take off all the iocbs on txq for cancelling */
  7177. list_splice_init(&pring->txq, &completions);
  7178. pring->txq_cnt = 0;
  7179. /* Next issue ABTS for everything on the txcmplq */
  7180. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7181. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7182. spin_unlock_irq(&phba->hbalock);
  7183. /* Cancel all the IOCBs from the completions list */
  7184. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7185. IOERR_SLI_ABORTED);
  7186. }
  7187. /**
  7188. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7189. * @phba: pointer to lpfc HBA data structure.
  7190. *
  7191. * This routine will abort all pending and outstanding iocbs to an HBA.
  7192. **/
  7193. void
  7194. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7195. {
  7196. struct lpfc_sli *psli = &phba->sli;
  7197. struct lpfc_sli_ring *pring;
  7198. int i;
  7199. for (i = 0; i < psli->num_rings; i++) {
  7200. pring = &psli->ring[i];
  7201. lpfc_sli_iocb_ring_abort(phba, pring);
  7202. }
  7203. }
  7204. /**
  7205. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7206. * @iocbq: Pointer to driver iocb object.
  7207. * @vport: Pointer to driver virtual port object.
  7208. * @tgt_id: SCSI ID of the target.
  7209. * @lun_id: LUN ID of the scsi device.
  7210. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7211. *
  7212. * This function acts as an iocb filter for functions which abort or count
  7213. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7214. * 0 if the filtering criteria is met for the given iocb and will return
  7215. * 1 if the filtering criteria is not met.
  7216. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7217. * given iocb is for the SCSI device specified by vport, tgt_id and
  7218. * lun_id parameter.
  7219. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7220. * given iocb is for the SCSI target specified by vport and tgt_id
  7221. * parameters.
  7222. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7223. * given iocb is for the SCSI host associated with the given vport.
  7224. * This function is called with no locks held.
  7225. **/
  7226. static int
  7227. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7228. uint16_t tgt_id, uint64_t lun_id,
  7229. lpfc_ctx_cmd ctx_cmd)
  7230. {
  7231. struct lpfc_scsi_buf *lpfc_cmd;
  7232. int rc = 1;
  7233. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7234. return rc;
  7235. if (iocbq->vport != vport)
  7236. return rc;
  7237. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7238. if (lpfc_cmd->pCmd == NULL)
  7239. return rc;
  7240. switch (ctx_cmd) {
  7241. case LPFC_CTX_LUN:
  7242. if ((lpfc_cmd->rdata->pnode) &&
  7243. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7244. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7245. rc = 0;
  7246. break;
  7247. case LPFC_CTX_TGT:
  7248. if ((lpfc_cmd->rdata->pnode) &&
  7249. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7250. rc = 0;
  7251. break;
  7252. case LPFC_CTX_HOST:
  7253. rc = 0;
  7254. break;
  7255. default:
  7256. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7257. __func__, ctx_cmd);
  7258. break;
  7259. }
  7260. return rc;
  7261. }
  7262. /**
  7263. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7264. * @vport: Pointer to virtual port.
  7265. * @tgt_id: SCSI ID of the target.
  7266. * @lun_id: LUN ID of the scsi device.
  7267. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7268. *
  7269. * This function returns number of FCP commands pending for the vport.
  7270. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7271. * commands pending on the vport associated with SCSI device specified
  7272. * by tgt_id and lun_id parameters.
  7273. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7274. * commands pending on the vport associated with SCSI target specified
  7275. * by tgt_id parameter.
  7276. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7277. * commands pending on the vport.
  7278. * This function returns the number of iocbs which satisfy the filter.
  7279. * This function is called without any lock held.
  7280. **/
  7281. int
  7282. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7283. lpfc_ctx_cmd ctx_cmd)
  7284. {
  7285. struct lpfc_hba *phba = vport->phba;
  7286. struct lpfc_iocbq *iocbq;
  7287. int sum, i;
  7288. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7289. iocbq = phba->sli.iocbq_lookup[i];
  7290. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7291. ctx_cmd) == 0)
  7292. sum++;
  7293. }
  7294. return sum;
  7295. }
  7296. /**
  7297. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7298. * @phba: Pointer to HBA context object
  7299. * @cmdiocb: Pointer to command iocb object.
  7300. * @rspiocb: Pointer to response iocb object.
  7301. *
  7302. * This function is called when an aborted FCP iocb completes. This
  7303. * function is called by the ring event handler with no lock held.
  7304. * This function frees the iocb.
  7305. **/
  7306. void
  7307. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7308. struct lpfc_iocbq *rspiocb)
  7309. {
  7310. lpfc_sli_release_iocbq(phba, cmdiocb);
  7311. return;
  7312. }
  7313. /**
  7314. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7315. * @vport: Pointer to virtual port.
  7316. * @pring: Pointer to driver SLI ring object.
  7317. * @tgt_id: SCSI ID of the target.
  7318. * @lun_id: LUN ID of the scsi device.
  7319. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7320. *
  7321. * This function sends an abort command for every SCSI command
  7322. * associated with the given virtual port pending on the ring
  7323. * filtered by lpfc_sli_validate_fcp_iocb function.
  7324. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7325. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7326. * parameters
  7327. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7328. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7329. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7330. * FCP iocbs associated with virtual port.
  7331. * This function returns number of iocbs it failed to abort.
  7332. * This function is called with no locks held.
  7333. **/
  7334. int
  7335. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7336. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7337. {
  7338. struct lpfc_hba *phba = vport->phba;
  7339. struct lpfc_iocbq *iocbq;
  7340. struct lpfc_iocbq *abtsiocb;
  7341. IOCB_t *cmd = NULL;
  7342. int errcnt = 0, ret_val = 0;
  7343. int i;
  7344. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7345. iocbq = phba->sli.iocbq_lookup[i];
  7346. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7347. abort_cmd) != 0)
  7348. continue;
  7349. /* issue ABTS for this IOCB based on iotag */
  7350. abtsiocb = lpfc_sli_get_iocbq(phba);
  7351. if (abtsiocb == NULL) {
  7352. errcnt++;
  7353. continue;
  7354. }
  7355. cmd = &iocbq->iocb;
  7356. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7357. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7358. if (phba->sli_rev == LPFC_SLI_REV4)
  7359. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7360. else
  7361. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7362. abtsiocb->iocb.ulpLe = 1;
  7363. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7364. abtsiocb->vport = phba->pport;
  7365. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7366. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7367. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7368. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7369. if (lpfc_is_link_up(phba))
  7370. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7371. else
  7372. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7373. /* Setup callback routine and issue the command. */
  7374. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7375. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7376. abtsiocb, 0);
  7377. if (ret_val == IOCB_ERROR) {
  7378. lpfc_sli_release_iocbq(phba, abtsiocb);
  7379. errcnt++;
  7380. continue;
  7381. }
  7382. }
  7383. return errcnt;
  7384. }
  7385. /**
  7386. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7387. * @phba: Pointer to HBA context object.
  7388. * @cmdiocbq: Pointer to command iocb.
  7389. * @rspiocbq: Pointer to response iocb.
  7390. *
  7391. * This function is the completion handler for iocbs issued using
  7392. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7393. * ring event handler function without any lock held. This function
  7394. * can be called from both worker thread context and interrupt
  7395. * context. This function also can be called from other thread which
  7396. * cleans up the SLI layer objects.
  7397. * This function copy the contents of the response iocb to the
  7398. * response iocb memory object provided by the caller of
  7399. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7400. * sleeps for the iocb completion.
  7401. **/
  7402. static void
  7403. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7404. struct lpfc_iocbq *cmdiocbq,
  7405. struct lpfc_iocbq *rspiocbq)
  7406. {
  7407. wait_queue_head_t *pdone_q;
  7408. unsigned long iflags;
  7409. struct lpfc_scsi_buf *lpfc_cmd;
  7410. spin_lock_irqsave(&phba->hbalock, iflags);
  7411. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7412. if (cmdiocbq->context2 && rspiocbq)
  7413. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7414. &rspiocbq->iocb, sizeof(IOCB_t));
  7415. /* Set the exchange busy flag for task management commands */
  7416. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7417. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7418. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7419. cur_iocbq);
  7420. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7421. }
  7422. pdone_q = cmdiocbq->context_un.wait_queue;
  7423. if (pdone_q)
  7424. wake_up(pdone_q);
  7425. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7426. return;
  7427. }
  7428. /**
  7429. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7430. * @phba: Pointer to HBA context object..
  7431. * @piocbq: Pointer to command iocb.
  7432. * @flag: Flag to test.
  7433. *
  7434. * This routine grabs the hbalock and then test the iocb_flag to
  7435. * see if the passed in flag is set.
  7436. * Returns:
  7437. * 1 if flag is set.
  7438. * 0 if flag is not set.
  7439. **/
  7440. static int
  7441. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7442. struct lpfc_iocbq *piocbq, uint32_t flag)
  7443. {
  7444. unsigned long iflags;
  7445. int ret;
  7446. spin_lock_irqsave(&phba->hbalock, iflags);
  7447. ret = piocbq->iocb_flag & flag;
  7448. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7449. return ret;
  7450. }
  7451. /**
  7452. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7453. * @phba: Pointer to HBA context object..
  7454. * @pring: Pointer to sli ring.
  7455. * @piocb: Pointer to command iocb.
  7456. * @prspiocbq: Pointer to response iocb.
  7457. * @timeout: Timeout in number of seconds.
  7458. *
  7459. * This function issues the iocb to firmware and waits for the
  7460. * iocb to complete. If the iocb command is not
  7461. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7462. * Caller should not free the iocb resources if this function
  7463. * returns IOCB_TIMEDOUT.
  7464. * The function waits for the iocb completion using an
  7465. * non-interruptible wait.
  7466. * This function will sleep while waiting for iocb completion.
  7467. * So, this function should not be called from any context which
  7468. * does not allow sleeping. Due to the same reason, this function
  7469. * cannot be called with interrupt disabled.
  7470. * This function assumes that the iocb completions occur while
  7471. * this function sleep. So, this function cannot be called from
  7472. * the thread which process iocb completion for this ring.
  7473. * This function clears the iocb_flag of the iocb object before
  7474. * issuing the iocb and the iocb completion handler sets this
  7475. * flag and wakes this thread when the iocb completes.
  7476. * The contents of the response iocb will be copied to prspiocbq
  7477. * by the completion handler when the command completes.
  7478. * This function returns IOCB_SUCCESS when success.
  7479. * This function is called with no lock held.
  7480. **/
  7481. int
  7482. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7483. uint32_t ring_number,
  7484. struct lpfc_iocbq *piocb,
  7485. struct lpfc_iocbq *prspiocbq,
  7486. uint32_t timeout)
  7487. {
  7488. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7489. long timeleft, timeout_req = 0;
  7490. int retval = IOCB_SUCCESS;
  7491. uint32_t creg_val;
  7492. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7493. /*
  7494. * If the caller has provided a response iocbq buffer, then context2
  7495. * is NULL or its an error.
  7496. */
  7497. if (prspiocbq) {
  7498. if (piocb->context2)
  7499. return IOCB_ERROR;
  7500. piocb->context2 = prspiocbq;
  7501. }
  7502. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7503. piocb->context_un.wait_queue = &done_q;
  7504. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7505. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7506. if (lpfc_readl(phba->HCregaddr, &creg_val))
  7507. return IOCB_ERROR;
  7508. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7509. writel(creg_val, phba->HCregaddr);
  7510. readl(phba->HCregaddr); /* flush */
  7511. }
  7512. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7513. SLI_IOCB_RET_IOCB);
  7514. if (retval == IOCB_SUCCESS) {
  7515. timeout_req = timeout * HZ;
  7516. timeleft = wait_event_timeout(done_q,
  7517. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7518. timeout_req);
  7519. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7520. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7521. "0331 IOCB wake signaled\n");
  7522. } else if (timeleft == 0) {
  7523. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7524. "0338 IOCB wait timeout error - no "
  7525. "wake response Data x%x\n", timeout);
  7526. retval = IOCB_TIMEDOUT;
  7527. } else {
  7528. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7529. "0330 IOCB wake NOT set, "
  7530. "Data x%x x%lx\n",
  7531. timeout, (timeleft / jiffies));
  7532. retval = IOCB_TIMEDOUT;
  7533. }
  7534. } else if (retval == IOCB_BUSY) {
  7535. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7536. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7537. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7538. return retval;
  7539. } else {
  7540. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7541. "0332 IOCB wait issue failed, Data x%x\n",
  7542. retval);
  7543. retval = IOCB_ERROR;
  7544. }
  7545. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7546. if (lpfc_readl(phba->HCregaddr, &creg_val))
  7547. return IOCB_ERROR;
  7548. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7549. writel(creg_val, phba->HCregaddr);
  7550. readl(phba->HCregaddr); /* flush */
  7551. }
  7552. if (prspiocbq)
  7553. piocb->context2 = NULL;
  7554. piocb->context_un.wait_queue = NULL;
  7555. piocb->iocb_cmpl = NULL;
  7556. return retval;
  7557. }
  7558. /**
  7559. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7560. * @phba: Pointer to HBA context object.
  7561. * @pmboxq: Pointer to driver mailbox object.
  7562. * @timeout: Timeout in number of seconds.
  7563. *
  7564. * This function issues the mailbox to firmware and waits for the
  7565. * mailbox command to complete. If the mailbox command is not
  7566. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7567. * The function waits for the mailbox completion using an
  7568. * interruptible wait. If the thread is woken up due to a
  7569. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7570. * should not free the mailbox resources, if this function returns
  7571. * MBX_TIMEOUT.
  7572. * This function will sleep while waiting for mailbox completion.
  7573. * So, this function should not be called from any context which
  7574. * does not allow sleeping. Due to the same reason, this function
  7575. * cannot be called with interrupt disabled.
  7576. * This function assumes that the mailbox completion occurs while
  7577. * this function sleep. So, this function cannot be called from
  7578. * the worker thread which processes mailbox completion.
  7579. * This function is called in the context of HBA management
  7580. * applications.
  7581. * This function returns MBX_SUCCESS when successful.
  7582. * This function is called with no lock held.
  7583. **/
  7584. int
  7585. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7586. uint32_t timeout)
  7587. {
  7588. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7589. int retval;
  7590. unsigned long flag;
  7591. /* The caller must leave context1 empty. */
  7592. if (pmboxq->context1)
  7593. return MBX_NOT_FINISHED;
  7594. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7595. /* setup wake call as IOCB callback */
  7596. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7597. /* setup context field to pass wait_queue pointer to wake function */
  7598. pmboxq->context1 = &done_q;
  7599. /* now issue the command */
  7600. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7601. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7602. wait_event_interruptible_timeout(done_q,
  7603. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7604. timeout * HZ);
  7605. spin_lock_irqsave(&phba->hbalock, flag);
  7606. pmboxq->context1 = NULL;
  7607. /*
  7608. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7609. * else do not free the resources.
  7610. */
  7611. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7612. retval = MBX_SUCCESS;
  7613. lpfc_sli4_swap_str(phba, pmboxq);
  7614. } else {
  7615. retval = MBX_TIMEOUT;
  7616. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7617. }
  7618. spin_unlock_irqrestore(&phba->hbalock, flag);
  7619. }
  7620. return retval;
  7621. }
  7622. /**
  7623. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7624. * @phba: Pointer to HBA context.
  7625. *
  7626. * This function is called to shutdown the driver's mailbox sub-system.
  7627. * It first marks the mailbox sub-system is in a block state to prevent
  7628. * the asynchronous mailbox command from issued off the pending mailbox
  7629. * command queue. If the mailbox command sub-system shutdown is due to
  7630. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7631. * the mailbox sub-system flush routine to forcefully bring down the
  7632. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7633. * as with offline or HBA function reset), this routine will wait for the
  7634. * outstanding mailbox command to complete before invoking the mailbox
  7635. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7636. **/
  7637. void
  7638. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7639. {
  7640. struct lpfc_sli *psli = &phba->sli;
  7641. uint8_t actcmd = MBX_HEARTBEAT;
  7642. unsigned long timeout;
  7643. spin_lock_irq(&phba->hbalock);
  7644. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7645. spin_unlock_irq(&phba->hbalock);
  7646. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7647. spin_lock_irq(&phba->hbalock);
  7648. if (phba->sli.mbox_active)
  7649. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7650. spin_unlock_irq(&phba->hbalock);
  7651. /* Determine how long we might wait for the active mailbox
  7652. * command to be gracefully completed by firmware.
  7653. */
  7654. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7655. 1000) + jiffies;
  7656. while (phba->sli.mbox_active) {
  7657. /* Check active mailbox complete status every 2ms */
  7658. msleep(2);
  7659. if (time_after(jiffies, timeout))
  7660. /* Timeout, let the mailbox flush routine to
  7661. * forcefully release active mailbox command
  7662. */
  7663. break;
  7664. }
  7665. }
  7666. lpfc_sli_mbox_sys_flush(phba);
  7667. }
  7668. /**
  7669. * lpfc_sli_eratt_read - read sli-3 error attention events
  7670. * @phba: Pointer to HBA context.
  7671. *
  7672. * This function is called to read the SLI3 device error attention registers
  7673. * for possible error attention events. The caller must hold the hostlock
  7674. * with spin_lock_irq().
  7675. *
  7676. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7677. * Register and returns 0 otherwise.
  7678. **/
  7679. static int
  7680. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7681. {
  7682. uint32_t ha_copy;
  7683. /* Read chip Host Attention (HA) register */
  7684. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  7685. goto unplug_err;
  7686. if (ha_copy & HA_ERATT) {
  7687. /* Read host status register to retrieve error event */
  7688. if (lpfc_sli_read_hs(phba))
  7689. goto unplug_err;
  7690. /* Check if there is a deferred error condition is active */
  7691. if ((HS_FFER1 & phba->work_hs) &&
  7692. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7693. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7694. phba->hba_flag |= DEFER_ERATT;
  7695. /* Clear all interrupt enable conditions */
  7696. writel(0, phba->HCregaddr);
  7697. readl(phba->HCregaddr);
  7698. }
  7699. /* Set the driver HA work bitmap */
  7700. phba->work_ha |= HA_ERATT;
  7701. /* Indicate polling handles this ERATT */
  7702. phba->hba_flag |= HBA_ERATT_HANDLED;
  7703. return 1;
  7704. }
  7705. return 0;
  7706. unplug_err:
  7707. /* Set the driver HS work bitmap */
  7708. phba->work_hs |= UNPLUG_ERR;
  7709. /* Set the driver HA work bitmap */
  7710. phba->work_ha |= HA_ERATT;
  7711. /* Indicate polling handles this ERATT */
  7712. phba->hba_flag |= HBA_ERATT_HANDLED;
  7713. return 1;
  7714. }
  7715. /**
  7716. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7717. * @phba: Pointer to HBA context.
  7718. *
  7719. * This function is called to read the SLI4 device error attention registers
  7720. * for possible error attention events. The caller must hold the hostlock
  7721. * with spin_lock_irq().
  7722. *
  7723. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7724. * Register and returns 0 otherwise.
  7725. **/
  7726. static int
  7727. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7728. {
  7729. uint32_t uerr_sta_hi, uerr_sta_lo;
  7730. uint32_t if_type, portsmphr;
  7731. struct lpfc_register portstat_reg;
  7732. /*
  7733. * For now, use the SLI4 device internal unrecoverable error
  7734. * registers for error attention. This can be changed later.
  7735. */
  7736. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7737. switch (if_type) {
  7738. case LPFC_SLI_INTF_IF_TYPE_0:
  7739. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  7740. &uerr_sta_lo) ||
  7741. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  7742. &uerr_sta_hi)) {
  7743. phba->work_hs |= UNPLUG_ERR;
  7744. phba->work_ha |= HA_ERATT;
  7745. phba->hba_flag |= HBA_ERATT_HANDLED;
  7746. return 1;
  7747. }
  7748. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7749. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7750. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7751. "1423 HBA Unrecoverable error: "
  7752. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7753. "ue_mask_lo_reg=0x%x, "
  7754. "ue_mask_hi_reg=0x%x\n",
  7755. uerr_sta_lo, uerr_sta_hi,
  7756. phba->sli4_hba.ue_mask_lo,
  7757. phba->sli4_hba.ue_mask_hi);
  7758. phba->work_status[0] = uerr_sta_lo;
  7759. phba->work_status[1] = uerr_sta_hi;
  7760. phba->work_ha |= HA_ERATT;
  7761. phba->hba_flag |= HBA_ERATT_HANDLED;
  7762. return 1;
  7763. }
  7764. break;
  7765. case LPFC_SLI_INTF_IF_TYPE_2:
  7766. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  7767. &portstat_reg.word0) ||
  7768. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  7769. &portsmphr)){
  7770. phba->work_hs |= UNPLUG_ERR;
  7771. phba->work_ha |= HA_ERATT;
  7772. phba->hba_flag |= HBA_ERATT_HANDLED;
  7773. return 1;
  7774. }
  7775. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  7776. phba->work_status[0] =
  7777. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  7778. phba->work_status[1] =
  7779. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  7780. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7781. "2885 Port Error Detected: "
  7782. "port status reg 0x%x, "
  7783. "port smphr reg 0x%x, "
  7784. "error 1=0x%x, error 2=0x%x\n",
  7785. portstat_reg.word0,
  7786. portsmphr,
  7787. phba->work_status[0],
  7788. phba->work_status[1]);
  7789. phba->work_ha |= HA_ERATT;
  7790. phba->hba_flag |= HBA_ERATT_HANDLED;
  7791. return 1;
  7792. }
  7793. break;
  7794. case LPFC_SLI_INTF_IF_TYPE_1:
  7795. default:
  7796. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7797. "2886 HBA Error Attention on unsupported "
  7798. "if type %d.", if_type);
  7799. return 1;
  7800. }
  7801. return 0;
  7802. }
  7803. /**
  7804. * lpfc_sli_check_eratt - check error attention events
  7805. * @phba: Pointer to HBA context.
  7806. *
  7807. * This function is called from timer soft interrupt context to check HBA's
  7808. * error attention register bit for error attention events.
  7809. *
  7810. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7811. * Register and returns 0 otherwise.
  7812. **/
  7813. int
  7814. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7815. {
  7816. uint32_t ha_copy;
  7817. /* If somebody is waiting to handle an eratt, don't process it
  7818. * here. The brdkill function will do this.
  7819. */
  7820. if (phba->link_flag & LS_IGNORE_ERATT)
  7821. return 0;
  7822. /* Check if interrupt handler handles this ERATT */
  7823. spin_lock_irq(&phba->hbalock);
  7824. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7825. /* Interrupt handler has handled ERATT */
  7826. spin_unlock_irq(&phba->hbalock);
  7827. return 0;
  7828. }
  7829. /*
  7830. * If there is deferred error attention, do not check for error
  7831. * attention
  7832. */
  7833. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7834. spin_unlock_irq(&phba->hbalock);
  7835. return 0;
  7836. }
  7837. /* If PCI channel is offline, don't process it */
  7838. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7839. spin_unlock_irq(&phba->hbalock);
  7840. return 0;
  7841. }
  7842. switch (phba->sli_rev) {
  7843. case LPFC_SLI_REV2:
  7844. case LPFC_SLI_REV3:
  7845. /* Read chip Host Attention (HA) register */
  7846. ha_copy = lpfc_sli_eratt_read(phba);
  7847. break;
  7848. case LPFC_SLI_REV4:
  7849. /* Read device Uncoverable Error (UERR) registers */
  7850. ha_copy = lpfc_sli4_eratt_read(phba);
  7851. break;
  7852. default:
  7853. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7854. "0299 Invalid SLI revision (%d)\n",
  7855. phba->sli_rev);
  7856. ha_copy = 0;
  7857. break;
  7858. }
  7859. spin_unlock_irq(&phba->hbalock);
  7860. return ha_copy;
  7861. }
  7862. /**
  7863. * lpfc_intr_state_check - Check device state for interrupt handling
  7864. * @phba: Pointer to HBA context.
  7865. *
  7866. * This inline routine checks whether a device or its PCI slot is in a state
  7867. * that the interrupt should be handled.
  7868. *
  7869. * This function returns 0 if the device or the PCI slot is in a state that
  7870. * interrupt should be handled, otherwise -EIO.
  7871. */
  7872. static inline int
  7873. lpfc_intr_state_check(struct lpfc_hba *phba)
  7874. {
  7875. /* If the pci channel is offline, ignore all the interrupts */
  7876. if (unlikely(pci_channel_offline(phba->pcidev)))
  7877. return -EIO;
  7878. /* Update device level interrupt statistics */
  7879. phba->sli.slistat.sli_intr++;
  7880. /* Ignore all interrupts during initialization. */
  7881. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7882. return -EIO;
  7883. return 0;
  7884. }
  7885. /**
  7886. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7887. * @irq: Interrupt number.
  7888. * @dev_id: The device context pointer.
  7889. *
  7890. * This function is directly called from the PCI layer as an interrupt
  7891. * service routine when device with SLI-3 interface spec is enabled with
  7892. * MSI-X multi-message interrupt mode and there are slow-path events in
  7893. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7894. * interrupt mode, this function is called as part of the device-level
  7895. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7896. * is undergoing initialization, the interrupt handler will not process
  7897. * the interrupt. The link attention and ELS ring attention events are
  7898. * handled by the worker thread. The interrupt handler signals the worker
  7899. * thread and returns for these events. This function is called without
  7900. * any lock held. It gets the hbalock to access and update SLI data
  7901. * structures.
  7902. *
  7903. * This function returns IRQ_HANDLED when interrupt is handled else it
  7904. * returns IRQ_NONE.
  7905. **/
  7906. irqreturn_t
  7907. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7908. {
  7909. struct lpfc_hba *phba;
  7910. uint32_t ha_copy, hc_copy;
  7911. uint32_t work_ha_copy;
  7912. unsigned long status;
  7913. unsigned long iflag;
  7914. uint32_t control;
  7915. MAILBOX_t *mbox, *pmbox;
  7916. struct lpfc_vport *vport;
  7917. struct lpfc_nodelist *ndlp;
  7918. struct lpfc_dmabuf *mp;
  7919. LPFC_MBOXQ_t *pmb;
  7920. int rc;
  7921. /*
  7922. * Get the driver's phba structure from the dev_id and
  7923. * assume the HBA is not interrupting.
  7924. */
  7925. phba = (struct lpfc_hba *)dev_id;
  7926. if (unlikely(!phba))
  7927. return IRQ_NONE;
  7928. /*
  7929. * Stuff needs to be attented to when this function is invoked as an
  7930. * individual interrupt handler in MSI-X multi-message interrupt mode
  7931. */
  7932. if (phba->intr_type == MSIX) {
  7933. /* Check device state for handling interrupt */
  7934. if (lpfc_intr_state_check(phba))
  7935. return IRQ_NONE;
  7936. /* Need to read HA REG for slow-path events */
  7937. spin_lock_irqsave(&phba->hbalock, iflag);
  7938. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  7939. goto unplug_error;
  7940. /* If somebody is waiting to handle an eratt don't process it
  7941. * here. The brdkill function will do this.
  7942. */
  7943. if (phba->link_flag & LS_IGNORE_ERATT)
  7944. ha_copy &= ~HA_ERATT;
  7945. /* Check the need for handling ERATT in interrupt handler */
  7946. if (ha_copy & HA_ERATT) {
  7947. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7948. /* ERATT polling has handled ERATT */
  7949. ha_copy &= ~HA_ERATT;
  7950. else
  7951. /* Indicate interrupt handler handles ERATT */
  7952. phba->hba_flag |= HBA_ERATT_HANDLED;
  7953. }
  7954. /*
  7955. * If there is deferred error attention, do not check for any
  7956. * interrupt.
  7957. */
  7958. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7959. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7960. return IRQ_NONE;
  7961. }
  7962. /* Clear up only attention source related to slow-path */
  7963. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  7964. goto unplug_error;
  7965. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7966. HC_LAINT_ENA | HC_ERINT_ENA),
  7967. phba->HCregaddr);
  7968. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7969. phba->HAregaddr);
  7970. writel(hc_copy, phba->HCregaddr);
  7971. readl(phba->HAregaddr); /* flush */
  7972. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7973. } else
  7974. ha_copy = phba->ha_copy;
  7975. work_ha_copy = ha_copy & phba->work_ha_mask;
  7976. if (work_ha_copy) {
  7977. if (work_ha_copy & HA_LATT) {
  7978. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7979. /*
  7980. * Turn off Link Attention interrupts
  7981. * until CLEAR_LA done
  7982. */
  7983. spin_lock_irqsave(&phba->hbalock, iflag);
  7984. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7985. if (lpfc_readl(phba->HCregaddr, &control))
  7986. goto unplug_error;
  7987. control &= ~HC_LAINT_ENA;
  7988. writel(control, phba->HCregaddr);
  7989. readl(phba->HCregaddr); /* flush */
  7990. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7991. }
  7992. else
  7993. work_ha_copy &= ~HA_LATT;
  7994. }
  7995. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7996. /*
  7997. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7998. * the only slow ring.
  7999. */
  8000. status = (work_ha_copy &
  8001. (HA_RXMASK << (4*LPFC_ELS_RING)));
  8002. status >>= (4*LPFC_ELS_RING);
  8003. if (status & HA_RXMASK) {
  8004. spin_lock_irqsave(&phba->hbalock, iflag);
  8005. if (lpfc_readl(phba->HCregaddr, &control))
  8006. goto unplug_error;
  8007. lpfc_debugfs_slow_ring_trc(phba,
  8008. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  8009. control, status,
  8010. (uint32_t)phba->sli.slistat.sli_intr);
  8011. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  8012. lpfc_debugfs_slow_ring_trc(phba,
  8013. "ISR Disable ring:"
  8014. "pwork:x%x hawork:x%x wait:x%x",
  8015. phba->work_ha, work_ha_copy,
  8016. (uint32_t)((unsigned long)
  8017. &phba->work_waitq));
  8018. control &=
  8019. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  8020. writel(control, phba->HCregaddr);
  8021. readl(phba->HCregaddr); /* flush */
  8022. }
  8023. else {
  8024. lpfc_debugfs_slow_ring_trc(phba,
  8025. "ISR slow ring: pwork:"
  8026. "x%x hawork:x%x wait:x%x",
  8027. phba->work_ha, work_ha_copy,
  8028. (uint32_t)((unsigned long)
  8029. &phba->work_waitq));
  8030. }
  8031. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8032. }
  8033. }
  8034. spin_lock_irqsave(&phba->hbalock, iflag);
  8035. if (work_ha_copy & HA_ERATT) {
  8036. if (lpfc_sli_read_hs(phba))
  8037. goto unplug_error;
  8038. /*
  8039. * Check if there is a deferred error condition
  8040. * is active
  8041. */
  8042. if ((HS_FFER1 & phba->work_hs) &&
  8043. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  8044. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  8045. phba->work_hs)) {
  8046. phba->hba_flag |= DEFER_ERATT;
  8047. /* Clear all interrupt enable conditions */
  8048. writel(0, phba->HCregaddr);
  8049. readl(phba->HCregaddr);
  8050. }
  8051. }
  8052. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  8053. pmb = phba->sli.mbox_active;
  8054. pmbox = &pmb->u.mb;
  8055. mbox = phba->mbox;
  8056. vport = pmb->vport;
  8057. /* First check out the status word */
  8058. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  8059. if (pmbox->mbxOwner != OWN_HOST) {
  8060. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8061. /*
  8062. * Stray Mailbox Interrupt, mbxCommand <cmd>
  8063. * mbxStatus <status>
  8064. */
  8065. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8066. LOG_SLI,
  8067. "(%d):0304 Stray Mailbox "
  8068. "Interrupt mbxCommand x%x "
  8069. "mbxStatus x%x\n",
  8070. (vport ? vport->vpi : 0),
  8071. pmbox->mbxCommand,
  8072. pmbox->mbxStatus);
  8073. /* clear mailbox attention bit */
  8074. work_ha_copy &= ~HA_MBATT;
  8075. } else {
  8076. phba->sli.mbox_active = NULL;
  8077. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8078. phba->last_completion_time = jiffies;
  8079. del_timer(&phba->sli.mbox_tmo);
  8080. if (pmb->mbox_cmpl) {
  8081. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  8082. MAILBOX_CMD_SIZE);
  8083. if (pmb->out_ext_byte_len &&
  8084. pmb->context2)
  8085. lpfc_sli_pcimem_bcopy(
  8086. phba->mbox_ext,
  8087. pmb->context2,
  8088. pmb->out_ext_byte_len);
  8089. }
  8090. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8091. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8092. lpfc_debugfs_disc_trc(vport,
  8093. LPFC_DISC_TRC_MBOX_VPORT,
  8094. "MBOX dflt rpi: : "
  8095. "status:x%x rpi:x%x",
  8096. (uint32_t)pmbox->mbxStatus,
  8097. pmbox->un.varWords[0], 0);
  8098. if (!pmbox->mbxStatus) {
  8099. mp = (struct lpfc_dmabuf *)
  8100. (pmb->context1);
  8101. ndlp = (struct lpfc_nodelist *)
  8102. pmb->context2;
  8103. /* Reg_LOGIN of dflt RPI was
  8104. * successful. new lets get
  8105. * rid of the RPI using the
  8106. * same mbox buffer.
  8107. */
  8108. lpfc_unreg_login(phba,
  8109. vport->vpi,
  8110. pmbox->un.varWords[0],
  8111. pmb);
  8112. pmb->mbox_cmpl =
  8113. lpfc_mbx_cmpl_dflt_rpi;
  8114. pmb->context1 = mp;
  8115. pmb->context2 = ndlp;
  8116. pmb->vport = vport;
  8117. rc = lpfc_sli_issue_mbox(phba,
  8118. pmb,
  8119. MBX_NOWAIT);
  8120. if (rc != MBX_BUSY)
  8121. lpfc_printf_log(phba,
  8122. KERN_ERR,
  8123. LOG_MBOX | LOG_SLI,
  8124. "0350 rc should have"
  8125. "been MBX_BUSY\n");
  8126. if (rc != MBX_NOT_FINISHED)
  8127. goto send_current_mbox;
  8128. }
  8129. }
  8130. spin_lock_irqsave(
  8131. &phba->pport->work_port_lock,
  8132. iflag);
  8133. phba->pport->work_port_events &=
  8134. ~WORKER_MBOX_TMO;
  8135. spin_unlock_irqrestore(
  8136. &phba->pport->work_port_lock,
  8137. iflag);
  8138. lpfc_mbox_cmpl_put(phba, pmb);
  8139. }
  8140. } else
  8141. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8142. if ((work_ha_copy & HA_MBATT) &&
  8143. (phba->sli.mbox_active == NULL)) {
  8144. send_current_mbox:
  8145. /* Process next mailbox command if there is one */
  8146. do {
  8147. rc = lpfc_sli_issue_mbox(phba, NULL,
  8148. MBX_NOWAIT);
  8149. } while (rc == MBX_NOT_FINISHED);
  8150. if (rc != MBX_SUCCESS)
  8151. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8152. LOG_SLI, "0349 rc should be "
  8153. "MBX_SUCCESS\n");
  8154. }
  8155. spin_lock_irqsave(&phba->hbalock, iflag);
  8156. phba->work_ha |= work_ha_copy;
  8157. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8158. lpfc_worker_wake_up(phba);
  8159. }
  8160. return IRQ_HANDLED;
  8161. unplug_error:
  8162. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8163. return IRQ_HANDLED;
  8164. } /* lpfc_sli_sp_intr_handler */
  8165. /**
  8166. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8167. * @irq: Interrupt number.
  8168. * @dev_id: The device context pointer.
  8169. *
  8170. * This function is directly called from the PCI layer as an interrupt
  8171. * service routine when device with SLI-3 interface spec is enabled with
  8172. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8173. * ring event in the HBA. However, when the device is enabled with either
  8174. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8175. * device-level interrupt handler. When the PCI slot is in error recovery
  8176. * or the HBA is undergoing initialization, the interrupt handler will not
  8177. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8178. * the intrrupt context. This function is called without any lock held.
  8179. * It gets the hbalock to access and update SLI data structures.
  8180. *
  8181. * This function returns IRQ_HANDLED when interrupt is handled else it
  8182. * returns IRQ_NONE.
  8183. **/
  8184. irqreturn_t
  8185. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8186. {
  8187. struct lpfc_hba *phba;
  8188. uint32_t ha_copy;
  8189. unsigned long status;
  8190. unsigned long iflag;
  8191. /* Get the driver's phba structure from the dev_id and
  8192. * assume the HBA is not interrupting.
  8193. */
  8194. phba = (struct lpfc_hba *) dev_id;
  8195. if (unlikely(!phba))
  8196. return IRQ_NONE;
  8197. /*
  8198. * Stuff needs to be attented to when this function is invoked as an
  8199. * individual interrupt handler in MSI-X multi-message interrupt mode
  8200. */
  8201. if (phba->intr_type == MSIX) {
  8202. /* Check device state for handling interrupt */
  8203. if (lpfc_intr_state_check(phba))
  8204. return IRQ_NONE;
  8205. /* Need to read HA REG for FCP ring and other ring events */
  8206. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  8207. return IRQ_HANDLED;
  8208. /* Clear up only attention source related to fast-path */
  8209. spin_lock_irqsave(&phba->hbalock, iflag);
  8210. /*
  8211. * If there is deferred error attention, do not check for
  8212. * any interrupt.
  8213. */
  8214. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8215. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8216. return IRQ_NONE;
  8217. }
  8218. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8219. phba->HAregaddr);
  8220. readl(phba->HAregaddr); /* flush */
  8221. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8222. } else
  8223. ha_copy = phba->ha_copy;
  8224. /*
  8225. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8226. */
  8227. ha_copy &= ~(phba->work_ha_mask);
  8228. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8229. status >>= (4*LPFC_FCP_RING);
  8230. if (status & HA_RXMASK)
  8231. lpfc_sli_handle_fast_ring_event(phba,
  8232. &phba->sli.ring[LPFC_FCP_RING],
  8233. status);
  8234. if (phba->cfg_multi_ring_support == 2) {
  8235. /*
  8236. * Process all events on extra ring. Take the optimized path
  8237. * for extra ring IO.
  8238. */
  8239. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8240. status >>= (4*LPFC_EXTRA_RING);
  8241. if (status & HA_RXMASK) {
  8242. lpfc_sli_handle_fast_ring_event(phba,
  8243. &phba->sli.ring[LPFC_EXTRA_RING],
  8244. status);
  8245. }
  8246. }
  8247. return IRQ_HANDLED;
  8248. } /* lpfc_sli_fp_intr_handler */
  8249. /**
  8250. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8251. * @irq: Interrupt number.
  8252. * @dev_id: The device context pointer.
  8253. *
  8254. * This function is the HBA device-level interrupt handler to device with
  8255. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8256. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8257. * requires driver attention. This function invokes the slow-path interrupt
  8258. * attention handling function and fast-path interrupt attention handling
  8259. * function in turn to process the relevant HBA attention events. This
  8260. * function is called without any lock held. It gets the hbalock to access
  8261. * and update SLI data structures.
  8262. *
  8263. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8264. * returns IRQ_NONE.
  8265. **/
  8266. irqreturn_t
  8267. lpfc_sli_intr_handler(int irq, void *dev_id)
  8268. {
  8269. struct lpfc_hba *phba;
  8270. irqreturn_t sp_irq_rc, fp_irq_rc;
  8271. unsigned long status1, status2;
  8272. uint32_t hc_copy;
  8273. /*
  8274. * Get the driver's phba structure from the dev_id and
  8275. * assume the HBA is not interrupting.
  8276. */
  8277. phba = (struct lpfc_hba *) dev_id;
  8278. if (unlikely(!phba))
  8279. return IRQ_NONE;
  8280. /* Check device state for handling interrupt */
  8281. if (lpfc_intr_state_check(phba))
  8282. return IRQ_NONE;
  8283. spin_lock(&phba->hbalock);
  8284. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  8285. spin_unlock(&phba->hbalock);
  8286. return IRQ_HANDLED;
  8287. }
  8288. if (unlikely(!phba->ha_copy)) {
  8289. spin_unlock(&phba->hbalock);
  8290. return IRQ_NONE;
  8291. } else if (phba->ha_copy & HA_ERATT) {
  8292. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8293. /* ERATT polling has handled ERATT */
  8294. phba->ha_copy &= ~HA_ERATT;
  8295. else
  8296. /* Indicate interrupt handler handles ERATT */
  8297. phba->hba_flag |= HBA_ERATT_HANDLED;
  8298. }
  8299. /*
  8300. * If there is deferred error attention, do not check for any interrupt.
  8301. */
  8302. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8303. spin_unlock(&phba->hbalock);
  8304. return IRQ_NONE;
  8305. }
  8306. /* Clear attention sources except link and error attentions */
  8307. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  8308. spin_unlock(&phba->hbalock);
  8309. return IRQ_HANDLED;
  8310. }
  8311. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8312. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8313. phba->HCregaddr);
  8314. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8315. writel(hc_copy, phba->HCregaddr);
  8316. readl(phba->HAregaddr); /* flush */
  8317. spin_unlock(&phba->hbalock);
  8318. /*
  8319. * Invokes slow-path host attention interrupt handling as appropriate.
  8320. */
  8321. /* status of events with mailbox and link attention */
  8322. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8323. /* status of events with ELS ring */
  8324. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8325. status2 >>= (4*LPFC_ELS_RING);
  8326. if (status1 || (status2 & HA_RXMASK))
  8327. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8328. else
  8329. sp_irq_rc = IRQ_NONE;
  8330. /*
  8331. * Invoke fast-path host attention interrupt handling as appropriate.
  8332. */
  8333. /* status of events with FCP ring */
  8334. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8335. status1 >>= (4*LPFC_FCP_RING);
  8336. /* status of events with extra ring */
  8337. if (phba->cfg_multi_ring_support == 2) {
  8338. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8339. status2 >>= (4*LPFC_EXTRA_RING);
  8340. } else
  8341. status2 = 0;
  8342. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8343. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8344. else
  8345. fp_irq_rc = IRQ_NONE;
  8346. /* Return device-level interrupt handling status */
  8347. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8348. } /* lpfc_sli_intr_handler */
  8349. /**
  8350. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8351. * @phba: pointer to lpfc hba data structure.
  8352. *
  8353. * This routine is invoked by the worker thread to process all the pending
  8354. * SLI4 FCP abort XRI events.
  8355. **/
  8356. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8357. {
  8358. struct lpfc_cq_event *cq_event;
  8359. /* First, declare the fcp xri abort event has been handled */
  8360. spin_lock_irq(&phba->hbalock);
  8361. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8362. spin_unlock_irq(&phba->hbalock);
  8363. /* Now, handle all the fcp xri abort events */
  8364. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8365. /* Get the first event from the head of the event queue */
  8366. spin_lock_irq(&phba->hbalock);
  8367. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8368. cq_event, struct lpfc_cq_event, list);
  8369. spin_unlock_irq(&phba->hbalock);
  8370. /* Notify aborted XRI for FCP work queue */
  8371. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8372. /* Free the event processed back to the free pool */
  8373. lpfc_sli4_cq_event_release(phba, cq_event);
  8374. }
  8375. }
  8376. /**
  8377. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8378. * @phba: pointer to lpfc hba data structure.
  8379. *
  8380. * This routine is invoked by the worker thread to process all the pending
  8381. * SLI4 els abort xri events.
  8382. **/
  8383. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8384. {
  8385. struct lpfc_cq_event *cq_event;
  8386. /* First, declare the els xri abort event has been handled */
  8387. spin_lock_irq(&phba->hbalock);
  8388. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8389. spin_unlock_irq(&phba->hbalock);
  8390. /* Now, handle all the els xri abort events */
  8391. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8392. /* Get the first event from the head of the event queue */
  8393. spin_lock_irq(&phba->hbalock);
  8394. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8395. cq_event, struct lpfc_cq_event, list);
  8396. spin_unlock_irq(&phba->hbalock);
  8397. /* Notify aborted XRI for ELS work queue */
  8398. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8399. /* Free the event processed back to the free pool */
  8400. lpfc_sli4_cq_event_release(phba, cq_event);
  8401. }
  8402. }
  8403. /**
  8404. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8405. * @phba: pointer to lpfc hba data structure
  8406. * @pIocbIn: pointer to the rspiocbq
  8407. * @pIocbOut: pointer to the cmdiocbq
  8408. * @wcqe: pointer to the complete wcqe
  8409. *
  8410. * This routine transfers the fields of a command iocbq to a response iocbq
  8411. * by copying all the IOCB fields from command iocbq and transferring the
  8412. * completion status information from the complete wcqe.
  8413. **/
  8414. static void
  8415. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8416. struct lpfc_iocbq *pIocbIn,
  8417. struct lpfc_iocbq *pIocbOut,
  8418. struct lpfc_wcqe_complete *wcqe)
  8419. {
  8420. unsigned long iflags;
  8421. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8422. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8423. sizeof(struct lpfc_iocbq) - offset);
  8424. /* Map WCQE parameters into irspiocb parameters */
  8425. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8426. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8427. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8428. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8429. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8430. wcqe->total_data_placed;
  8431. else
  8432. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8433. else {
  8434. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8435. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8436. }
  8437. /* Pick up HBA exchange busy condition */
  8438. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8439. spin_lock_irqsave(&phba->hbalock, iflags);
  8440. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8441. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8442. }
  8443. }
  8444. /**
  8445. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8446. * @phba: Pointer to HBA context object.
  8447. * @wcqe: Pointer to work-queue completion queue entry.
  8448. *
  8449. * This routine handles an ELS work-queue completion event and construct
  8450. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8451. * discovery engine to handle.
  8452. *
  8453. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8454. **/
  8455. static struct lpfc_iocbq *
  8456. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8457. struct lpfc_iocbq *irspiocbq)
  8458. {
  8459. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8460. struct lpfc_iocbq *cmdiocbq;
  8461. struct lpfc_wcqe_complete *wcqe;
  8462. unsigned long iflags;
  8463. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8464. spin_lock_irqsave(&phba->hbalock, iflags);
  8465. pring->stats.iocb_event++;
  8466. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8467. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8468. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8469. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8470. if (unlikely(!cmdiocbq)) {
  8471. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8472. "0386 ELS complete with no corresponding "
  8473. "cmdiocb: iotag (%d)\n",
  8474. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8475. lpfc_sli_release_iocbq(phba, irspiocbq);
  8476. return NULL;
  8477. }
  8478. /* Fake the irspiocbq and copy necessary response information */
  8479. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8480. return irspiocbq;
  8481. }
  8482. /**
  8483. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8484. * @phba: Pointer to HBA context object.
  8485. * @cqe: Pointer to mailbox completion queue entry.
  8486. *
  8487. * This routine process a mailbox completion queue entry with asynchrous
  8488. * event.
  8489. *
  8490. * Return: true if work posted to worker thread, otherwise false.
  8491. **/
  8492. static bool
  8493. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8494. {
  8495. struct lpfc_cq_event *cq_event;
  8496. unsigned long iflags;
  8497. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8498. "0392 Async Event: word0:x%x, word1:x%x, "
  8499. "word2:x%x, word3:x%x\n", mcqe->word0,
  8500. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8501. /* Allocate a new internal CQ_EVENT entry */
  8502. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8503. if (!cq_event) {
  8504. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8505. "0394 Failed to allocate CQ_EVENT entry\n");
  8506. return false;
  8507. }
  8508. /* Move the CQE into an asynchronous event entry */
  8509. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8510. spin_lock_irqsave(&phba->hbalock, iflags);
  8511. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8512. /* Set the async event flag */
  8513. phba->hba_flag |= ASYNC_EVENT;
  8514. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8515. return true;
  8516. }
  8517. /**
  8518. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8519. * @phba: Pointer to HBA context object.
  8520. * @cqe: Pointer to mailbox completion queue entry.
  8521. *
  8522. * This routine process a mailbox completion queue entry with mailbox
  8523. * completion event.
  8524. *
  8525. * Return: true if work posted to worker thread, otherwise false.
  8526. **/
  8527. static bool
  8528. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8529. {
  8530. uint32_t mcqe_status;
  8531. MAILBOX_t *mbox, *pmbox;
  8532. struct lpfc_mqe *mqe;
  8533. struct lpfc_vport *vport;
  8534. struct lpfc_nodelist *ndlp;
  8535. struct lpfc_dmabuf *mp;
  8536. unsigned long iflags;
  8537. LPFC_MBOXQ_t *pmb;
  8538. bool workposted = false;
  8539. int rc;
  8540. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8541. if (!bf_get(lpfc_trailer_completed, mcqe))
  8542. goto out_no_mqe_complete;
  8543. /* Get the reference to the active mbox command */
  8544. spin_lock_irqsave(&phba->hbalock, iflags);
  8545. pmb = phba->sli.mbox_active;
  8546. if (unlikely(!pmb)) {
  8547. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8548. "1832 No pending MBOX command to handle\n");
  8549. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8550. goto out_no_mqe_complete;
  8551. }
  8552. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8553. mqe = &pmb->u.mqe;
  8554. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8555. mbox = phba->mbox;
  8556. vport = pmb->vport;
  8557. /* Reset heartbeat timer */
  8558. phba->last_completion_time = jiffies;
  8559. del_timer(&phba->sli.mbox_tmo);
  8560. /* Move mbox data to caller's mailbox region, do endian swapping */
  8561. if (pmb->mbox_cmpl && mbox)
  8562. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8563. /* Set the mailbox status with SLI4 range 0x4000 */
  8564. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8565. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8566. bf_set(lpfc_mqe_status, mqe,
  8567. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8568. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8569. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8570. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8571. "MBOX dflt rpi: status:x%x rpi:x%x",
  8572. mcqe_status,
  8573. pmbox->un.varWords[0], 0);
  8574. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8575. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8576. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8577. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8578. * RID of the PPI using the same mbox buffer.
  8579. */
  8580. lpfc_unreg_login(phba, vport->vpi,
  8581. pmbox->un.varWords[0], pmb);
  8582. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8583. pmb->context1 = mp;
  8584. pmb->context2 = ndlp;
  8585. pmb->vport = vport;
  8586. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8587. if (rc != MBX_BUSY)
  8588. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8589. LOG_SLI, "0385 rc should "
  8590. "have been MBX_BUSY\n");
  8591. if (rc != MBX_NOT_FINISHED)
  8592. goto send_current_mbox;
  8593. }
  8594. }
  8595. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8596. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8597. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8598. /* There is mailbox completion work to do */
  8599. spin_lock_irqsave(&phba->hbalock, iflags);
  8600. __lpfc_mbox_cmpl_put(phba, pmb);
  8601. phba->work_ha |= HA_MBATT;
  8602. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8603. workposted = true;
  8604. send_current_mbox:
  8605. spin_lock_irqsave(&phba->hbalock, iflags);
  8606. /* Release the mailbox command posting token */
  8607. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8608. /* Setting active mailbox pointer need to be in sync to flag clear */
  8609. phba->sli.mbox_active = NULL;
  8610. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8611. /* Wake up worker thread to post the next pending mailbox command */
  8612. lpfc_worker_wake_up(phba);
  8613. out_no_mqe_complete:
  8614. if (bf_get(lpfc_trailer_consumed, mcqe))
  8615. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8616. return workposted;
  8617. }
  8618. /**
  8619. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8620. * @phba: Pointer to HBA context object.
  8621. * @cqe: Pointer to mailbox completion queue entry.
  8622. *
  8623. * This routine process a mailbox completion queue entry, it invokes the
  8624. * proper mailbox complete handling or asynchrous event handling routine
  8625. * according to the MCQE's async bit.
  8626. *
  8627. * Return: true if work posted to worker thread, otherwise false.
  8628. **/
  8629. static bool
  8630. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8631. {
  8632. struct lpfc_mcqe mcqe;
  8633. bool workposted;
  8634. /* Copy the mailbox MCQE and convert endian order as needed */
  8635. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8636. /* Invoke the proper event handling routine */
  8637. if (!bf_get(lpfc_trailer_async, &mcqe))
  8638. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8639. else
  8640. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8641. return workposted;
  8642. }
  8643. /**
  8644. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8645. * @phba: Pointer to HBA context object.
  8646. * @wcqe: Pointer to work-queue completion queue entry.
  8647. *
  8648. * This routine handles an ELS work-queue completion event.
  8649. *
  8650. * Return: true if work posted to worker thread, otherwise false.
  8651. **/
  8652. static bool
  8653. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8654. struct lpfc_wcqe_complete *wcqe)
  8655. {
  8656. struct lpfc_iocbq *irspiocbq;
  8657. unsigned long iflags;
  8658. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8659. /* Get an irspiocbq for later ELS response processing use */
  8660. irspiocbq = lpfc_sli_get_iocbq(phba);
  8661. if (!irspiocbq) {
  8662. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8663. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8664. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8665. pring->txq_cnt, phba->iocb_cnt,
  8666. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8667. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8668. return false;
  8669. }
  8670. /* Save off the slow-path queue event for work thread to process */
  8671. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8672. spin_lock_irqsave(&phba->hbalock, iflags);
  8673. list_add_tail(&irspiocbq->cq_event.list,
  8674. &phba->sli4_hba.sp_queue_event);
  8675. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8676. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8677. return true;
  8678. }
  8679. /**
  8680. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8681. * @phba: Pointer to HBA context object.
  8682. * @wcqe: Pointer to work-queue completion queue entry.
  8683. *
  8684. * This routine handles slow-path WQ entry comsumed event by invoking the
  8685. * proper WQ release routine to the slow-path WQ.
  8686. **/
  8687. static void
  8688. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8689. struct lpfc_wcqe_release *wcqe)
  8690. {
  8691. /* Check for the slow-path ELS work queue */
  8692. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8693. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8694. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8695. else
  8696. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8697. "2579 Slow-path wqe consume event carries "
  8698. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8699. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8700. phba->sli4_hba.els_wq->queue_id);
  8701. }
  8702. /**
  8703. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8704. * @phba: Pointer to HBA context object.
  8705. * @cq: Pointer to a WQ completion queue.
  8706. * @wcqe: Pointer to work-queue completion queue entry.
  8707. *
  8708. * This routine handles an XRI abort event.
  8709. *
  8710. * Return: true if work posted to worker thread, otherwise false.
  8711. **/
  8712. static bool
  8713. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8714. struct lpfc_queue *cq,
  8715. struct sli4_wcqe_xri_aborted *wcqe)
  8716. {
  8717. bool workposted = false;
  8718. struct lpfc_cq_event *cq_event;
  8719. unsigned long iflags;
  8720. /* Allocate a new internal CQ_EVENT entry */
  8721. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8722. if (!cq_event) {
  8723. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8724. "0602 Failed to allocate CQ_EVENT entry\n");
  8725. return false;
  8726. }
  8727. /* Move the CQE into the proper xri abort event list */
  8728. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8729. switch (cq->subtype) {
  8730. case LPFC_FCP:
  8731. spin_lock_irqsave(&phba->hbalock, iflags);
  8732. list_add_tail(&cq_event->list,
  8733. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8734. /* Set the fcp xri abort event flag */
  8735. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8736. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8737. workposted = true;
  8738. break;
  8739. case LPFC_ELS:
  8740. spin_lock_irqsave(&phba->hbalock, iflags);
  8741. list_add_tail(&cq_event->list,
  8742. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8743. /* Set the els xri abort event flag */
  8744. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8745. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8746. workposted = true;
  8747. break;
  8748. default:
  8749. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8750. "0603 Invalid work queue CQE subtype (x%x)\n",
  8751. cq->subtype);
  8752. workposted = false;
  8753. break;
  8754. }
  8755. return workposted;
  8756. }
  8757. /**
  8758. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8759. * @phba: Pointer to HBA context object.
  8760. * @rcqe: Pointer to receive-queue completion queue entry.
  8761. *
  8762. * This routine process a receive-queue completion queue entry.
  8763. *
  8764. * Return: true if work posted to worker thread, otherwise false.
  8765. **/
  8766. static bool
  8767. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8768. {
  8769. bool workposted = false;
  8770. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8771. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8772. struct hbq_dmabuf *dma_buf;
  8773. uint32_t status;
  8774. unsigned long iflags;
  8775. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8776. goto out;
  8777. status = bf_get(lpfc_rcqe_status, rcqe);
  8778. switch (status) {
  8779. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8780. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8781. "2537 Receive Frame Truncated!!\n");
  8782. case FC_STATUS_RQ_SUCCESS:
  8783. lpfc_sli4_rq_release(hrq, drq);
  8784. spin_lock_irqsave(&phba->hbalock, iflags);
  8785. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8786. if (!dma_buf) {
  8787. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8788. goto out;
  8789. }
  8790. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8791. /* save off the frame for the word thread to process */
  8792. list_add_tail(&dma_buf->cq_event.list,
  8793. &phba->sli4_hba.sp_queue_event);
  8794. /* Frame received */
  8795. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8796. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8797. workposted = true;
  8798. break;
  8799. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8800. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8801. /* Post more buffers if possible */
  8802. spin_lock_irqsave(&phba->hbalock, iflags);
  8803. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8804. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8805. workposted = true;
  8806. break;
  8807. }
  8808. out:
  8809. return workposted;
  8810. }
  8811. /**
  8812. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8813. * @phba: Pointer to HBA context object.
  8814. * @cq: Pointer to the completion queue.
  8815. * @wcqe: Pointer to a completion queue entry.
  8816. *
  8817. * This routine process a slow-path work-queue or recieve queue completion queue
  8818. * entry.
  8819. *
  8820. * Return: true if work posted to worker thread, otherwise false.
  8821. **/
  8822. static bool
  8823. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8824. struct lpfc_cqe *cqe)
  8825. {
  8826. struct lpfc_cqe cqevt;
  8827. bool workposted = false;
  8828. /* Copy the work queue CQE and convert endian order if needed */
  8829. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8830. /* Check and process for different type of WCQE and dispatch */
  8831. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8832. case CQE_CODE_COMPL_WQE:
  8833. /* Process the WQ/RQ complete event */
  8834. phba->last_completion_time = jiffies;
  8835. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8836. (struct lpfc_wcqe_complete *)&cqevt);
  8837. break;
  8838. case CQE_CODE_RELEASE_WQE:
  8839. /* Process the WQ release event */
  8840. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8841. (struct lpfc_wcqe_release *)&cqevt);
  8842. break;
  8843. case CQE_CODE_XRI_ABORTED:
  8844. /* Process the WQ XRI abort event */
  8845. phba->last_completion_time = jiffies;
  8846. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8847. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8848. break;
  8849. case CQE_CODE_RECEIVE:
  8850. /* Process the RQ event */
  8851. phba->last_completion_time = jiffies;
  8852. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8853. (struct lpfc_rcqe *)&cqevt);
  8854. break;
  8855. default:
  8856. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8857. "0388 Not a valid WCQE code: x%x\n",
  8858. bf_get(lpfc_cqe_code, &cqevt));
  8859. break;
  8860. }
  8861. return workposted;
  8862. }
  8863. /**
  8864. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8865. * @phba: Pointer to HBA context object.
  8866. * @eqe: Pointer to fast-path event queue entry.
  8867. *
  8868. * This routine process a event queue entry from the slow-path event queue.
  8869. * It will check the MajorCode and MinorCode to determine this is for a
  8870. * completion event on a completion queue, if not, an error shall be logged
  8871. * and just return. Otherwise, it will get to the corresponding completion
  8872. * queue and process all the entries on that completion queue, rearm the
  8873. * completion queue, and then return.
  8874. *
  8875. **/
  8876. static void
  8877. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8878. {
  8879. struct lpfc_queue *cq = NULL, *childq, *speq;
  8880. struct lpfc_cqe *cqe;
  8881. bool workposted = false;
  8882. int ecount = 0;
  8883. uint16_t cqid;
  8884. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8885. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8886. "0359 Not a valid slow-path completion "
  8887. "event: majorcode=x%x, minorcode=x%x\n",
  8888. bf_get_le32(lpfc_eqe_major_code, eqe),
  8889. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8890. return;
  8891. }
  8892. /* Get the reference to the corresponding CQ */
  8893. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8894. /* Search for completion queue pointer matching this cqid */
  8895. speq = phba->sli4_hba.sp_eq;
  8896. list_for_each_entry(childq, &speq->child_list, list) {
  8897. if (childq->queue_id == cqid) {
  8898. cq = childq;
  8899. break;
  8900. }
  8901. }
  8902. if (unlikely(!cq)) {
  8903. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8904. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8905. "0365 Slow-path CQ identifier "
  8906. "(%d) does not exist\n", cqid);
  8907. return;
  8908. }
  8909. /* Process all the entries to the CQ */
  8910. switch (cq->type) {
  8911. case LPFC_MCQ:
  8912. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8913. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8914. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8915. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8916. }
  8917. break;
  8918. case LPFC_WCQ:
  8919. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8920. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8921. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8922. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8923. }
  8924. break;
  8925. default:
  8926. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8927. "0370 Invalid completion queue type (%d)\n",
  8928. cq->type);
  8929. return;
  8930. }
  8931. /* Catch the no cq entry condition, log an error */
  8932. if (unlikely(ecount == 0))
  8933. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8934. "0371 No entry from the CQ: identifier "
  8935. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8936. /* In any case, flash and re-arm the RCQ */
  8937. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8938. /* wake up worker thread if there are works to be done */
  8939. if (workposted)
  8940. lpfc_worker_wake_up(phba);
  8941. }
  8942. /**
  8943. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8944. * @eqe: Pointer to fast-path completion queue entry.
  8945. *
  8946. * This routine process a fast-path work queue completion entry from fast-path
  8947. * event queue for FCP command response completion.
  8948. **/
  8949. static void
  8950. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8951. struct lpfc_wcqe_complete *wcqe)
  8952. {
  8953. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8954. struct lpfc_iocbq *cmdiocbq;
  8955. struct lpfc_iocbq irspiocbq;
  8956. unsigned long iflags;
  8957. spin_lock_irqsave(&phba->hbalock, iflags);
  8958. pring->stats.iocb_event++;
  8959. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8960. /* Check for response status */
  8961. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8962. /* If resource errors reported from HBA, reduce queue
  8963. * depth of the SCSI device.
  8964. */
  8965. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8966. IOSTAT_LOCAL_REJECT) &&
  8967. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8968. phba->lpfc_rampdown_queue_depth(phba);
  8969. }
  8970. /* Log the error status */
  8971. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8972. "0373 FCP complete error: status=x%x, "
  8973. "hw_status=x%x, total_data_specified=%d, "
  8974. "parameter=x%x, word3=x%x\n",
  8975. bf_get(lpfc_wcqe_c_status, wcqe),
  8976. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8977. wcqe->total_data_placed, wcqe->parameter,
  8978. wcqe->word3);
  8979. }
  8980. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8981. spin_lock_irqsave(&phba->hbalock, iflags);
  8982. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8983. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8984. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8985. if (unlikely(!cmdiocbq)) {
  8986. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8987. "0374 FCP complete with no corresponding "
  8988. "cmdiocb: iotag (%d)\n",
  8989. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8990. return;
  8991. }
  8992. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8993. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8994. "0375 FCP cmdiocb not callback function "
  8995. "iotag: (%d)\n",
  8996. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8997. return;
  8998. }
  8999. /* Fake the irspiocb and copy necessary response information */
  9000. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  9001. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  9002. spin_lock_irqsave(&phba->hbalock, iflags);
  9003. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  9004. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9005. }
  9006. /* Pass the cmd_iocb and the rsp state to the upper layer */
  9007. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  9008. }
  9009. /**
  9010. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  9011. * @phba: Pointer to HBA context object.
  9012. * @cq: Pointer to completion queue.
  9013. * @wcqe: Pointer to work-queue completion queue entry.
  9014. *
  9015. * This routine handles an fast-path WQ entry comsumed event by invoking the
  9016. * proper WQ release routine to the slow-path WQ.
  9017. **/
  9018. static void
  9019. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9020. struct lpfc_wcqe_release *wcqe)
  9021. {
  9022. struct lpfc_queue *childwq;
  9023. bool wqid_matched = false;
  9024. uint16_t fcp_wqid;
  9025. /* Check for fast-path FCP work queue release */
  9026. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  9027. list_for_each_entry(childwq, &cq->child_list, list) {
  9028. if (childwq->queue_id == fcp_wqid) {
  9029. lpfc_sli4_wq_release(childwq,
  9030. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  9031. wqid_matched = true;
  9032. break;
  9033. }
  9034. }
  9035. /* Report warning log message if no match found */
  9036. if (wqid_matched != true)
  9037. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9038. "2580 Fast-path wqe consume event carries "
  9039. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  9040. }
  9041. /**
  9042. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  9043. * @cq: Pointer to the completion queue.
  9044. * @eqe: Pointer to fast-path completion queue entry.
  9045. *
  9046. * This routine process a fast-path work queue completion entry from fast-path
  9047. * event queue for FCP command response completion.
  9048. **/
  9049. static int
  9050. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9051. struct lpfc_cqe *cqe)
  9052. {
  9053. struct lpfc_wcqe_release wcqe;
  9054. bool workposted = false;
  9055. /* Copy the work queue CQE and convert endian order if needed */
  9056. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  9057. /* Check and process for different type of WCQE and dispatch */
  9058. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  9059. case CQE_CODE_COMPL_WQE:
  9060. /* Process the WQ complete event */
  9061. phba->last_completion_time = jiffies;
  9062. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  9063. (struct lpfc_wcqe_complete *)&wcqe);
  9064. break;
  9065. case CQE_CODE_RELEASE_WQE:
  9066. /* Process the WQ release event */
  9067. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  9068. (struct lpfc_wcqe_release *)&wcqe);
  9069. break;
  9070. case CQE_CODE_XRI_ABORTED:
  9071. /* Process the WQ XRI abort event */
  9072. phba->last_completion_time = jiffies;
  9073. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  9074. (struct sli4_wcqe_xri_aborted *)&wcqe);
  9075. break;
  9076. default:
  9077. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9078. "0144 Not a valid WCQE code: x%x\n",
  9079. bf_get(lpfc_wcqe_c_code, &wcqe));
  9080. break;
  9081. }
  9082. return workposted;
  9083. }
  9084. /**
  9085. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  9086. * @phba: Pointer to HBA context object.
  9087. * @eqe: Pointer to fast-path event queue entry.
  9088. *
  9089. * This routine process a event queue entry from the fast-path event queue.
  9090. * It will check the MajorCode and MinorCode to determine this is for a
  9091. * completion event on a completion queue, if not, an error shall be logged
  9092. * and just return. Otherwise, it will get to the corresponding completion
  9093. * queue and process all the entries on the completion queue, rearm the
  9094. * completion queue, and then return.
  9095. **/
  9096. static void
  9097. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  9098. uint32_t fcp_cqidx)
  9099. {
  9100. struct lpfc_queue *cq;
  9101. struct lpfc_cqe *cqe;
  9102. bool workposted = false;
  9103. uint16_t cqid;
  9104. int ecount = 0;
  9105. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  9106. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9107. "0366 Not a valid fast-path completion "
  9108. "event: majorcode=x%x, minorcode=x%x\n",
  9109. bf_get_le32(lpfc_eqe_major_code, eqe),
  9110. bf_get_le32(lpfc_eqe_minor_code, eqe));
  9111. return;
  9112. }
  9113. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  9114. if (unlikely(!cq)) {
  9115. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  9116. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9117. "0367 Fast-path completion queue "
  9118. "does not exist\n");
  9119. return;
  9120. }
  9121. /* Get the reference to the corresponding CQ */
  9122. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9123. if (unlikely(cqid != cq->queue_id)) {
  9124. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9125. "0368 Miss-matched fast-path completion "
  9126. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9127. cqid, cq->queue_id);
  9128. return;
  9129. }
  9130. /* Process all the entries to the CQ */
  9131. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9132. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9133. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9134. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9135. }
  9136. /* Catch the no cq entry condition */
  9137. if (unlikely(ecount == 0))
  9138. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9139. "0369 No entry from fast-path completion "
  9140. "queue fcpcqid=%d\n", cq->queue_id);
  9141. /* In any case, flash and re-arm the CQ */
  9142. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9143. /* wake up worker thread if there are works to be done */
  9144. if (workposted)
  9145. lpfc_worker_wake_up(phba);
  9146. }
  9147. static void
  9148. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9149. {
  9150. struct lpfc_eqe *eqe;
  9151. /* walk all the EQ entries and drop on the floor */
  9152. while ((eqe = lpfc_sli4_eq_get(eq)))
  9153. ;
  9154. /* Clear and re-arm the EQ */
  9155. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9156. }
  9157. /**
  9158. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9159. * @irq: Interrupt number.
  9160. * @dev_id: The device context pointer.
  9161. *
  9162. * This function is directly called from the PCI layer as an interrupt
  9163. * service routine when device with SLI-4 interface spec is enabled with
  9164. * MSI-X multi-message interrupt mode and there are slow-path events in
  9165. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9166. * interrupt mode, this function is called as part of the device-level
  9167. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9168. * undergoing initialization, the interrupt handler will not process the
  9169. * interrupt. The link attention and ELS ring attention events are handled
  9170. * by the worker thread. The interrupt handler signals the worker thread
  9171. * and returns for these events. This function is called without any lock
  9172. * held. It gets the hbalock to access and update SLI data structures.
  9173. *
  9174. * This function returns IRQ_HANDLED when interrupt is handled else it
  9175. * returns IRQ_NONE.
  9176. **/
  9177. irqreturn_t
  9178. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  9179. {
  9180. struct lpfc_hba *phba;
  9181. struct lpfc_queue *speq;
  9182. struct lpfc_eqe *eqe;
  9183. unsigned long iflag;
  9184. int ecount = 0;
  9185. /*
  9186. * Get the driver's phba structure from the dev_id
  9187. */
  9188. phba = (struct lpfc_hba *)dev_id;
  9189. if (unlikely(!phba))
  9190. return IRQ_NONE;
  9191. /* Get to the EQ struct associated with this vector */
  9192. speq = phba->sli4_hba.sp_eq;
  9193. /* Check device state for handling interrupt */
  9194. if (unlikely(lpfc_intr_state_check(phba))) {
  9195. /* Check again for link_state with lock held */
  9196. spin_lock_irqsave(&phba->hbalock, iflag);
  9197. if (phba->link_state < LPFC_LINK_DOWN)
  9198. /* Flush, clear interrupt, and rearm the EQ */
  9199. lpfc_sli4_eq_flush(phba, speq);
  9200. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9201. return IRQ_NONE;
  9202. }
  9203. /*
  9204. * Process all the event on FCP slow-path EQ
  9205. */
  9206. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9207. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9208. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9209. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9210. }
  9211. /* Always clear and re-arm the slow-path EQ */
  9212. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9213. /* Catch the no cq entry condition */
  9214. if (unlikely(ecount == 0)) {
  9215. if (phba->intr_type == MSIX)
  9216. /* MSI-X treated interrupt served as no EQ share INT */
  9217. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9218. "0357 MSI-X interrupt with no EQE\n");
  9219. else
  9220. /* Non MSI-X treated on interrupt as EQ share INT */
  9221. return IRQ_NONE;
  9222. }
  9223. return IRQ_HANDLED;
  9224. } /* lpfc_sli4_sp_intr_handler */
  9225. /**
  9226. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9227. * @irq: Interrupt number.
  9228. * @dev_id: The device context pointer.
  9229. *
  9230. * This function is directly called from the PCI layer as an interrupt
  9231. * service routine when device with SLI-4 interface spec is enabled with
  9232. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9233. * ring event in the HBA. However, when the device is enabled with either
  9234. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9235. * device-level interrupt handler. When the PCI slot is in error recovery
  9236. * or the HBA is undergoing initialization, the interrupt handler will not
  9237. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9238. * the intrrupt context. This function is called without any lock held.
  9239. * It gets the hbalock to access and update SLI data structures. Note that,
  9240. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9241. * equal to that of FCP CQ index.
  9242. *
  9243. * This function returns IRQ_HANDLED when interrupt is handled else it
  9244. * returns IRQ_NONE.
  9245. **/
  9246. irqreturn_t
  9247. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9248. {
  9249. struct lpfc_hba *phba;
  9250. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9251. struct lpfc_queue *fpeq;
  9252. struct lpfc_eqe *eqe;
  9253. unsigned long iflag;
  9254. int ecount = 0;
  9255. uint32_t fcp_eqidx;
  9256. /* Get the driver's phba structure from the dev_id */
  9257. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9258. phba = fcp_eq_hdl->phba;
  9259. fcp_eqidx = fcp_eq_hdl->idx;
  9260. if (unlikely(!phba))
  9261. return IRQ_NONE;
  9262. /* Get to the EQ struct associated with this vector */
  9263. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9264. /* Check device state for handling interrupt */
  9265. if (unlikely(lpfc_intr_state_check(phba))) {
  9266. /* Check again for link_state with lock held */
  9267. spin_lock_irqsave(&phba->hbalock, iflag);
  9268. if (phba->link_state < LPFC_LINK_DOWN)
  9269. /* Flush, clear interrupt, and rearm the EQ */
  9270. lpfc_sli4_eq_flush(phba, fpeq);
  9271. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9272. return IRQ_NONE;
  9273. }
  9274. /*
  9275. * Process all the event on FCP fast-path EQ
  9276. */
  9277. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9278. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9279. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9280. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9281. }
  9282. /* Always clear and re-arm the fast-path EQ */
  9283. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9284. if (unlikely(ecount == 0)) {
  9285. if (phba->intr_type == MSIX)
  9286. /* MSI-X treated interrupt served as no EQ share INT */
  9287. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9288. "0358 MSI-X interrupt with no EQE\n");
  9289. else
  9290. /* Non MSI-X treated on interrupt as EQ share INT */
  9291. return IRQ_NONE;
  9292. }
  9293. return IRQ_HANDLED;
  9294. } /* lpfc_sli4_fp_intr_handler */
  9295. /**
  9296. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9297. * @irq: Interrupt number.
  9298. * @dev_id: The device context pointer.
  9299. *
  9300. * This function is the device-level interrupt handler to device with SLI-4
  9301. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9302. * interrupt mode is enabled and there is an event in the HBA which requires
  9303. * driver attention. This function invokes the slow-path interrupt attention
  9304. * handling function and fast-path interrupt attention handling function in
  9305. * turn to process the relevant HBA attention events. This function is called
  9306. * without any lock held. It gets the hbalock to access and update SLI data
  9307. * structures.
  9308. *
  9309. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9310. * returns IRQ_NONE.
  9311. **/
  9312. irqreturn_t
  9313. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9314. {
  9315. struct lpfc_hba *phba;
  9316. irqreturn_t sp_irq_rc, fp_irq_rc;
  9317. bool fp_handled = false;
  9318. uint32_t fcp_eqidx;
  9319. /* Get the driver's phba structure from the dev_id */
  9320. phba = (struct lpfc_hba *)dev_id;
  9321. if (unlikely(!phba))
  9322. return IRQ_NONE;
  9323. /*
  9324. * Invokes slow-path host attention interrupt handling as appropriate.
  9325. */
  9326. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9327. /*
  9328. * Invoke fast-path host attention interrupt handling as appropriate.
  9329. */
  9330. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9331. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9332. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9333. if (fp_irq_rc == IRQ_HANDLED)
  9334. fp_handled |= true;
  9335. }
  9336. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9337. } /* lpfc_sli4_intr_handler */
  9338. /**
  9339. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9340. * @queue: The queue structure to free.
  9341. *
  9342. * This function frees a queue structure and the DMAable memory used for
  9343. * the host resident queue. This function must be called after destroying the
  9344. * queue on the HBA.
  9345. **/
  9346. void
  9347. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9348. {
  9349. struct lpfc_dmabuf *dmabuf;
  9350. if (!queue)
  9351. return;
  9352. while (!list_empty(&queue->page_list)) {
  9353. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9354. list);
  9355. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9356. dmabuf->virt, dmabuf->phys);
  9357. kfree(dmabuf);
  9358. }
  9359. kfree(queue);
  9360. return;
  9361. }
  9362. /**
  9363. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9364. * @phba: The HBA that this queue is being created on.
  9365. * @entry_size: The size of each queue entry for this queue.
  9366. * @entry count: The number of entries that this queue will handle.
  9367. *
  9368. * This function allocates a queue structure and the DMAable memory used for
  9369. * the host resident queue. This function must be called before creating the
  9370. * queue on the HBA.
  9371. **/
  9372. struct lpfc_queue *
  9373. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9374. uint32_t entry_count)
  9375. {
  9376. struct lpfc_queue *queue;
  9377. struct lpfc_dmabuf *dmabuf;
  9378. int x, total_qe_count;
  9379. void *dma_pointer;
  9380. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9381. if (!phba->sli4_hba.pc_sli4_params.supported)
  9382. hw_page_size = SLI4_PAGE_SIZE;
  9383. queue = kzalloc(sizeof(struct lpfc_queue) +
  9384. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9385. if (!queue)
  9386. return NULL;
  9387. queue->page_count = (ALIGN(entry_size * entry_count,
  9388. hw_page_size))/hw_page_size;
  9389. INIT_LIST_HEAD(&queue->list);
  9390. INIT_LIST_HEAD(&queue->page_list);
  9391. INIT_LIST_HEAD(&queue->child_list);
  9392. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9393. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9394. if (!dmabuf)
  9395. goto out_fail;
  9396. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9397. hw_page_size, &dmabuf->phys,
  9398. GFP_KERNEL);
  9399. if (!dmabuf->virt) {
  9400. kfree(dmabuf);
  9401. goto out_fail;
  9402. }
  9403. memset(dmabuf->virt, 0, hw_page_size);
  9404. dmabuf->buffer_tag = x;
  9405. list_add_tail(&dmabuf->list, &queue->page_list);
  9406. /* initialize queue's entry array */
  9407. dma_pointer = dmabuf->virt;
  9408. for (; total_qe_count < entry_count &&
  9409. dma_pointer < (hw_page_size + dmabuf->virt);
  9410. total_qe_count++, dma_pointer += entry_size) {
  9411. queue->qe[total_qe_count].address = dma_pointer;
  9412. }
  9413. }
  9414. queue->entry_size = entry_size;
  9415. queue->entry_count = entry_count;
  9416. queue->phba = phba;
  9417. return queue;
  9418. out_fail:
  9419. lpfc_sli4_queue_free(queue);
  9420. return NULL;
  9421. }
  9422. /**
  9423. * lpfc_eq_create - Create an Event Queue on the HBA
  9424. * @phba: HBA structure that indicates port to create a queue on.
  9425. * @eq: The queue structure to use to create the event queue.
  9426. * @imax: The maximum interrupt per second limit.
  9427. *
  9428. * This function creates an event queue, as detailed in @eq, on a port,
  9429. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9430. *
  9431. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9432. * is used to get the entry count and entry size that are necessary to
  9433. * determine the number of pages to allocate and use for this queue. This
  9434. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9435. * event queue. This function is asynchronous and will wait for the mailbox
  9436. * command to finish before continuing.
  9437. *
  9438. * On success this function will return a zero. If unable to allocate enough
  9439. * memory this function will return -ENOMEM. If the queue create mailbox command
  9440. * fails this function will return -ENXIO.
  9441. **/
  9442. uint32_t
  9443. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9444. {
  9445. struct lpfc_mbx_eq_create *eq_create;
  9446. LPFC_MBOXQ_t *mbox;
  9447. int rc, length, status = 0;
  9448. struct lpfc_dmabuf *dmabuf;
  9449. uint32_t shdr_status, shdr_add_status;
  9450. union lpfc_sli4_cfg_shdr *shdr;
  9451. uint16_t dmult;
  9452. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9453. if (!phba->sli4_hba.pc_sli4_params.supported)
  9454. hw_page_size = SLI4_PAGE_SIZE;
  9455. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9456. if (!mbox)
  9457. return -ENOMEM;
  9458. length = (sizeof(struct lpfc_mbx_eq_create) -
  9459. sizeof(struct lpfc_sli4_cfg_mhdr));
  9460. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9461. LPFC_MBOX_OPCODE_EQ_CREATE,
  9462. length, LPFC_SLI4_MBX_EMBED);
  9463. eq_create = &mbox->u.mqe.un.eq_create;
  9464. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9465. eq->page_count);
  9466. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9467. LPFC_EQE_SIZE);
  9468. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9469. /* Calculate delay multiper from maximum interrupt per second */
  9470. dmult = LPFC_DMULT_CONST/imax - 1;
  9471. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9472. dmult);
  9473. switch (eq->entry_count) {
  9474. default:
  9475. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9476. "0360 Unsupported EQ count. (%d)\n",
  9477. eq->entry_count);
  9478. if (eq->entry_count < 256)
  9479. return -EINVAL;
  9480. /* otherwise default to smallest count (drop through) */
  9481. case 256:
  9482. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9483. LPFC_EQ_CNT_256);
  9484. break;
  9485. case 512:
  9486. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9487. LPFC_EQ_CNT_512);
  9488. break;
  9489. case 1024:
  9490. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9491. LPFC_EQ_CNT_1024);
  9492. break;
  9493. case 2048:
  9494. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9495. LPFC_EQ_CNT_2048);
  9496. break;
  9497. case 4096:
  9498. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9499. LPFC_EQ_CNT_4096);
  9500. break;
  9501. }
  9502. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9503. memset(dmabuf->virt, 0, hw_page_size);
  9504. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9505. putPaddrLow(dmabuf->phys);
  9506. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9507. putPaddrHigh(dmabuf->phys);
  9508. }
  9509. mbox->vport = phba->pport;
  9510. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9511. mbox->context1 = NULL;
  9512. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9513. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9514. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9515. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9516. if (shdr_status || shdr_add_status || rc) {
  9517. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9518. "2500 EQ_CREATE mailbox failed with "
  9519. "status x%x add_status x%x, mbx status x%x\n",
  9520. shdr_status, shdr_add_status, rc);
  9521. status = -ENXIO;
  9522. }
  9523. eq->type = LPFC_EQ;
  9524. eq->subtype = LPFC_NONE;
  9525. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9526. if (eq->queue_id == 0xFFFF)
  9527. status = -ENXIO;
  9528. eq->host_index = 0;
  9529. eq->hba_index = 0;
  9530. mempool_free(mbox, phba->mbox_mem_pool);
  9531. return status;
  9532. }
  9533. /**
  9534. * lpfc_cq_create - Create a Completion Queue on the HBA
  9535. * @phba: HBA structure that indicates port to create a queue on.
  9536. * @cq: The queue structure to use to create the completion queue.
  9537. * @eq: The event queue to bind this completion queue to.
  9538. *
  9539. * This function creates a completion queue, as detailed in @wq, on a port,
  9540. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9541. *
  9542. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9543. * is used to get the entry count and entry size that are necessary to
  9544. * determine the number of pages to allocate and use for this queue. The @eq
  9545. * is used to indicate which event queue to bind this completion queue to. This
  9546. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9547. * completion queue. This function is asynchronous and will wait for the mailbox
  9548. * command to finish before continuing.
  9549. *
  9550. * On success this function will return a zero. If unable to allocate enough
  9551. * memory this function will return -ENOMEM. If the queue create mailbox command
  9552. * fails this function will return -ENXIO.
  9553. **/
  9554. uint32_t
  9555. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9556. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9557. {
  9558. struct lpfc_mbx_cq_create *cq_create;
  9559. struct lpfc_dmabuf *dmabuf;
  9560. LPFC_MBOXQ_t *mbox;
  9561. int rc, length, status = 0;
  9562. uint32_t shdr_status, shdr_add_status;
  9563. union lpfc_sli4_cfg_shdr *shdr;
  9564. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9565. if (!phba->sli4_hba.pc_sli4_params.supported)
  9566. hw_page_size = SLI4_PAGE_SIZE;
  9567. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9568. if (!mbox)
  9569. return -ENOMEM;
  9570. length = (sizeof(struct lpfc_mbx_cq_create) -
  9571. sizeof(struct lpfc_sli4_cfg_mhdr));
  9572. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9573. LPFC_MBOX_OPCODE_CQ_CREATE,
  9574. length, LPFC_SLI4_MBX_EMBED);
  9575. cq_create = &mbox->u.mqe.un.cq_create;
  9576. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9577. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9578. cq->page_count);
  9579. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9580. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9581. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9582. phba->sli4_hba.pc_sli4_params.cqv);
  9583. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  9584. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
  9585. (PAGE_SIZE/SLI4_PAGE_SIZE));
  9586. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  9587. eq->queue_id);
  9588. } else {
  9589. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  9590. eq->queue_id);
  9591. }
  9592. switch (cq->entry_count) {
  9593. default:
  9594. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9595. "0361 Unsupported CQ count. (%d)\n",
  9596. cq->entry_count);
  9597. if (cq->entry_count < 256)
  9598. return -EINVAL;
  9599. /* otherwise default to smallest count (drop through) */
  9600. case 256:
  9601. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9602. LPFC_CQ_CNT_256);
  9603. break;
  9604. case 512:
  9605. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9606. LPFC_CQ_CNT_512);
  9607. break;
  9608. case 1024:
  9609. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9610. LPFC_CQ_CNT_1024);
  9611. break;
  9612. }
  9613. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9614. memset(dmabuf->virt, 0, hw_page_size);
  9615. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9616. putPaddrLow(dmabuf->phys);
  9617. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9618. putPaddrHigh(dmabuf->phys);
  9619. }
  9620. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9621. /* The IOCTL status is embedded in the mailbox subheader. */
  9622. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9623. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9624. if (shdr_status || shdr_add_status || rc) {
  9625. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9626. "2501 CQ_CREATE mailbox failed with "
  9627. "status x%x add_status x%x, mbx status x%x\n",
  9628. shdr_status, shdr_add_status, rc);
  9629. status = -ENXIO;
  9630. goto out;
  9631. }
  9632. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9633. if (cq->queue_id == 0xFFFF) {
  9634. status = -ENXIO;
  9635. goto out;
  9636. }
  9637. /* link the cq onto the parent eq child list */
  9638. list_add_tail(&cq->list, &eq->child_list);
  9639. /* Set up completion queue's type and subtype */
  9640. cq->type = type;
  9641. cq->subtype = subtype;
  9642. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9643. cq->assoc_qid = eq->queue_id;
  9644. cq->host_index = 0;
  9645. cq->hba_index = 0;
  9646. out:
  9647. mempool_free(mbox, phba->mbox_mem_pool);
  9648. return status;
  9649. }
  9650. /**
  9651. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9652. * @phba: HBA structure that indicates port to create a queue on.
  9653. * @mq: The queue structure to use to create the mailbox queue.
  9654. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9655. * @cq: The completion queue to associate with this cq.
  9656. *
  9657. * This function provides failback (fb) functionality when the
  9658. * mq_create_ext fails on older FW generations. It's purpose is identical
  9659. * to mq_create_ext otherwise.
  9660. *
  9661. * This routine cannot fail as all attributes were previously accessed and
  9662. * initialized in mq_create_ext.
  9663. **/
  9664. static void
  9665. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9666. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9667. {
  9668. struct lpfc_mbx_mq_create *mq_create;
  9669. struct lpfc_dmabuf *dmabuf;
  9670. int length;
  9671. length = (sizeof(struct lpfc_mbx_mq_create) -
  9672. sizeof(struct lpfc_sli4_cfg_mhdr));
  9673. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9674. LPFC_MBOX_OPCODE_MQ_CREATE,
  9675. length, LPFC_SLI4_MBX_EMBED);
  9676. mq_create = &mbox->u.mqe.un.mq_create;
  9677. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9678. mq->page_count);
  9679. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9680. cq->queue_id);
  9681. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9682. switch (mq->entry_count) {
  9683. case 16:
  9684. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9685. LPFC_MQ_RING_SIZE_16);
  9686. break;
  9687. case 32:
  9688. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9689. LPFC_MQ_RING_SIZE_32);
  9690. break;
  9691. case 64:
  9692. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9693. LPFC_MQ_RING_SIZE_64);
  9694. break;
  9695. case 128:
  9696. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9697. LPFC_MQ_RING_SIZE_128);
  9698. break;
  9699. }
  9700. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9701. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9702. putPaddrLow(dmabuf->phys);
  9703. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9704. putPaddrHigh(dmabuf->phys);
  9705. }
  9706. }
  9707. /**
  9708. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9709. * @phba: HBA structure that indicates port to create a queue on.
  9710. * @mq: The queue structure to use to create the mailbox queue.
  9711. * @cq: The completion queue to associate with this cq.
  9712. * @subtype: The queue's subtype.
  9713. *
  9714. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9715. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9716. *
  9717. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9718. * is used to get the entry count and entry size that are necessary to
  9719. * determine the number of pages to allocate and use for this queue. This
  9720. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9721. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9722. * command to finish before continuing.
  9723. *
  9724. * On success this function will return a zero. If unable to allocate enough
  9725. * memory this function will return -ENOMEM. If the queue create mailbox command
  9726. * fails this function will return -ENXIO.
  9727. **/
  9728. int32_t
  9729. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9730. struct lpfc_queue *cq, uint32_t subtype)
  9731. {
  9732. struct lpfc_mbx_mq_create *mq_create;
  9733. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9734. struct lpfc_dmabuf *dmabuf;
  9735. LPFC_MBOXQ_t *mbox;
  9736. int rc, length, status = 0;
  9737. uint32_t shdr_status, shdr_add_status;
  9738. union lpfc_sli4_cfg_shdr *shdr;
  9739. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9740. if (!phba->sli4_hba.pc_sli4_params.supported)
  9741. hw_page_size = SLI4_PAGE_SIZE;
  9742. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9743. if (!mbox)
  9744. return -ENOMEM;
  9745. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9746. sizeof(struct lpfc_sli4_cfg_mhdr));
  9747. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9748. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9749. length, LPFC_SLI4_MBX_EMBED);
  9750. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9751. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9752. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  9753. &mq_create_ext->u.request, mq->page_count);
  9754. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  9755. &mq_create_ext->u.request, 1);
  9756. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  9757. &mq_create_ext->u.request, 1);
  9758. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9759. &mq_create_ext->u.request, 1);
  9760. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  9761. &mq_create_ext->u.request, 1);
  9762. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  9763. &mq_create_ext->u.request, 1);
  9764. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9765. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9766. phba->sli4_hba.pc_sli4_params.mqv);
  9767. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  9768. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  9769. cq->queue_id);
  9770. else
  9771. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9772. cq->queue_id);
  9773. switch (mq->entry_count) {
  9774. default:
  9775. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9776. "0362 Unsupported MQ count. (%d)\n",
  9777. mq->entry_count);
  9778. if (mq->entry_count < 16)
  9779. return -EINVAL;
  9780. /* otherwise default to smallest count (drop through) */
  9781. case 16:
  9782. bf_set(lpfc_mq_context_ring_size,
  9783. &mq_create_ext->u.request.context,
  9784. LPFC_MQ_RING_SIZE_16);
  9785. break;
  9786. case 32:
  9787. bf_set(lpfc_mq_context_ring_size,
  9788. &mq_create_ext->u.request.context,
  9789. LPFC_MQ_RING_SIZE_32);
  9790. break;
  9791. case 64:
  9792. bf_set(lpfc_mq_context_ring_size,
  9793. &mq_create_ext->u.request.context,
  9794. LPFC_MQ_RING_SIZE_64);
  9795. break;
  9796. case 128:
  9797. bf_set(lpfc_mq_context_ring_size,
  9798. &mq_create_ext->u.request.context,
  9799. LPFC_MQ_RING_SIZE_128);
  9800. break;
  9801. }
  9802. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9803. memset(dmabuf->virt, 0, hw_page_size);
  9804. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9805. putPaddrLow(dmabuf->phys);
  9806. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9807. putPaddrHigh(dmabuf->phys);
  9808. }
  9809. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9810. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9811. &mq_create_ext->u.response);
  9812. if (rc != MBX_SUCCESS) {
  9813. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9814. "2795 MQ_CREATE_EXT failed with "
  9815. "status x%x. Failback to MQ_CREATE.\n",
  9816. rc);
  9817. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9818. mq_create = &mbox->u.mqe.un.mq_create;
  9819. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9820. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9821. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9822. &mq_create->u.response);
  9823. }
  9824. /* The IOCTL status is embedded in the mailbox subheader. */
  9825. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9826. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9827. if (shdr_status || shdr_add_status || rc) {
  9828. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9829. "2502 MQ_CREATE mailbox failed with "
  9830. "status x%x add_status x%x, mbx status x%x\n",
  9831. shdr_status, shdr_add_status, rc);
  9832. status = -ENXIO;
  9833. goto out;
  9834. }
  9835. if (mq->queue_id == 0xFFFF) {
  9836. status = -ENXIO;
  9837. goto out;
  9838. }
  9839. mq->type = LPFC_MQ;
  9840. mq->assoc_qid = cq->queue_id;
  9841. mq->subtype = subtype;
  9842. mq->host_index = 0;
  9843. mq->hba_index = 0;
  9844. /* link the mq onto the parent cq child list */
  9845. list_add_tail(&mq->list, &cq->child_list);
  9846. out:
  9847. mempool_free(mbox, phba->mbox_mem_pool);
  9848. return status;
  9849. }
  9850. /**
  9851. * lpfc_wq_create - Create a Work Queue on the HBA
  9852. * @phba: HBA structure that indicates port to create a queue on.
  9853. * @wq: The queue structure to use to create the work queue.
  9854. * @cq: The completion queue to bind this work queue to.
  9855. * @subtype: The subtype of the work queue indicating its functionality.
  9856. *
  9857. * This function creates a work queue, as detailed in @wq, on a port, described
  9858. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9859. *
  9860. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9861. * is used to get the entry count and entry size that are necessary to
  9862. * determine the number of pages to allocate and use for this queue. The @cq
  9863. * is used to indicate which completion queue to bind this work queue to. This
  9864. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9865. * work queue. This function is asynchronous and will wait for the mailbox
  9866. * command to finish before continuing.
  9867. *
  9868. * On success this function will return a zero. If unable to allocate enough
  9869. * memory this function will return -ENOMEM. If the queue create mailbox command
  9870. * fails this function will return -ENXIO.
  9871. **/
  9872. uint32_t
  9873. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9874. struct lpfc_queue *cq, uint32_t subtype)
  9875. {
  9876. struct lpfc_mbx_wq_create *wq_create;
  9877. struct lpfc_dmabuf *dmabuf;
  9878. LPFC_MBOXQ_t *mbox;
  9879. int rc, length, status = 0;
  9880. uint32_t shdr_status, shdr_add_status;
  9881. union lpfc_sli4_cfg_shdr *shdr;
  9882. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9883. struct dma_address *page;
  9884. if (!phba->sli4_hba.pc_sli4_params.supported)
  9885. hw_page_size = SLI4_PAGE_SIZE;
  9886. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9887. if (!mbox)
  9888. return -ENOMEM;
  9889. length = (sizeof(struct lpfc_mbx_wq_create) -
  9890. sizeof(struct lpfc_sli4_cfg_mhdr));
  9891. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9892. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9893. length, LPFC_SLI4_MBX_EMBED);
  9894. wq_create = &mbox->u.mqe.un.wq_create;
  9895. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9896. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9897. wq->page_count);
  9898. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9899. cq->queue_id);
  9900. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9901. phba->sli4_hba.pc_sli4_params.wqv);
  9902. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  9903. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  9904. wq->entry_count);
  9905. switch (wq->entry_size) {
  9906. default:
  9907. case 64:
  9908. bf_set(lpfc_mbx_wq_create_wqe_size,
  9909. &wq_create->u.request_1,
  9910. LPFC_WQ_WQE_SIZE_64);
  9911. break;
  9912. case 128:
  9913. bf_set(lpfc_mbx_wq_create_wqe_size,
  9914. &wq_create->u.request_1,
  9915. LPFC_WQ_WQE_SIZE_128);
  9916. break;
  9917. }
  9918. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  9919. (PAGE_SIZE/SLI4_PAGE_SIZE));
  9920. page = wq_create->u.request_1.page;
  9921. } else {
  9922. page = wq_create->u.request.page;
  9923. }
  9924. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9925. memset(dmabuf->virt, 0, hw_page_size);
  9926. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  9927. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  9928. }
  9929. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9930. /* The IOCTL status is embedded in the mailbox subheader. */
  9931. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9932. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9933. if (shdr_status || shdr_add_status || rc) {
  9934. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9935. "2503 WQ_CREATE mailbox failed with "
  9936. "status x%x add_status x%x, mbx status x%x\n",
  9937. shdr_status, shdr_add_status, rc);
  9938. status = -ENXIO;
  9939. goto out;
  9940. }
  9941. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9942. if (wq->queue_id == 0xFFFF) {
  9943. status = -ENXIO;
  9944. goto out;
  9945. }
  9946. wq->type = LPFC_WQ;
  9947. wq->assoc_qid = cq->queue_id;
  9948. wq->subtype = subtype;
  9949. wq->host_index = 0;
  9950. wq->hba_index = 0;
  9951. /* link the wq onto the parent cq child list */
  9952. list_add_tail(&wq->list, &cq->child_list);
  9953. out:
  9954. mempool_free(mbox, phba->mbox_mem_pool);
  9955. return status;
  9956. }
  9957. /**
  9958. * lpfc_rq_create - Create a Receive Queue on the HBA
  9959. * @phba: HBA structure that indicates port to create a queue on.
  9960. * @hrq: The queue structure to use to create the header receive queue.
  9961. * @drq: The queue structure to use to create the data receive queue.
  9962. * @cq: The completion queue to bind this work queue to.
  9963. *
  9964. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9965. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9966. * to the HBA.
  9967. *
  9968. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9969. * struct is used to get the entry count that is necessary to determine the
  9970. * number of pages to use for this queue. The @cq is used to indicate which
  9971. * completion queue to bind received buffers that are posted to these queues to.
  9972. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9973. * receive queue pair. This function is asynchronous and will wait for the
  9974. * mailbox command to finish before continuing.
  9975. *
  9976. * On success this function will return a zero. If unable to allocate enough
  9977. * memory this function will return -ENOMEM. If the queue create mailbox command
  9978. * fails this function will return -ENXIO.
  9979. **/
  9980. uint32_t
  9981. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9982. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9983. {
  9984. struct lpfc_mbx_rq_create *rq_create;
  9985. struct lpfc_dmabuf *dmabuf;
  9986. LPFC_MBOXQ_t *mbox;
  9987. int rc, length, status = 0;
  9988. uint32_t shdr_status, shdr_add_status;
  9989. union lpfc_sli4_cfg_shdr *shdr;
  9990. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9991. if (!phba->sli4_hba.pc_sli4_params.supported)
  9992. hw_page_size = SLI4_PAGE_SIZE;
  9993. if (hrq->entry_count != drq->entry_count)
  9994. return -EINVAL;
  9995. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9996. if (!mbox)
  9997. return -ENOMEM;
  9998. length = (sizeof(struct lpfc_mbx_rq_create) -
  9999. sizeof(struct lpfc_sli4_cfg_mhdr));
  10000. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10001. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  10002. length, LPFC_SLI4_MBX_EMBED);
  10003. rq_create = &mbox->u.mqe.un.rq_create;
  10004. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  10005. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10006. phba->sli4_hba.pc_sli4_params.rqv);
  10007. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  10008. bf_set(lpfc_rq_context_rqe_count_1,
  10009. &rq_create->u.request.context,
  10010. hrq->entry_count);
  10011. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  10012. } else {
  10013. switch (hrq->entry_count) {
  10014. default:
  10015. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10016. "2535 Unsupported RQ count. (%d)\n",
  10017. hrq->entry_count);
  10018. if (hrq->entry_count < 512)
  10019. return -EINVAL;
  10020. /* otherwise default to smallest count (drop through) */
  10021. case 512:
  10022. bf_set(lpfc_rq_context_rqe_count,
  10023. &rq_create->u.request.context,
  10024. LPFC_RQ_RING_SIZE_512);
  10025. break;
  10026. case 1024:
  10027. bf_set(lpfc_rq_context_rqe_count,
  10028. &rq_create->u.request.context,
  10029. LPFC_RQ_RING_SIZE_1024);
  10030. break;
  10031. case 2048:
  10032. bf_set(lpfc_rq_context_rqe_count,
  10033. &rq_create->u.request.context,
  10034. LPFC_RQ_RING_SIZE_2048);
  10035. break;
  10036. case 4096:
  10037. bf_set(lpfc_rq_context_rqe_count,
  10038. &rq_create->u.request.context,
  10039. LPFC_RQ_RING_SIZE_4096);
  10040. break;
  10041. }
  10042. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  10043. LPFC_HDR_BUF_SIZE);
  10044. }
  10045. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  10046. cq->queue_id);
  10047. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  10048. hrq->page_count);
  10049. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  10050. memset(dmabuf->virt, 0, hw_page_size);
  10051. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10052. putPaddrLow(dmabuf->phys);
  10053. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10054. putPaddrHigh(dmabuf->phys);
  10055. }
  10056. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10057. /* The IOCTL status is embedded in the mailbox subheader. */
  10058. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10059. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10060. if (shdr_status || shdr_add_status || rc) {
  10061. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10062. "2504 RQ_CREATE mailbox failed with "
  10063. "status x%x add_status x%x, mbx status x%x\n",
  10064. shdr_status, shdr_add_status, rc);
  10065. status = -ENXIO;
  10066. goto out;
  10067. }
  10068. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  10069. if (hrq->queue_id == 0xFFFF) {
  10070. status = -ENXIO;
  10071. goto out;
  10072. }
  10073. hrq->type = LPFC_HRQ;
  10074. hrq->assoc_qid = cq->queue_id;
  10075. hrq->subtype = subtype;
  10076. hrq->host_index = 0;
  10077. hrq->hba_index = 0;
  10078. /* now create the data queue */
  10079. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10080. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  10081. length, LPFC_SLI4_MBX_EMBED);
  10082. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10083. phba->sli4_hba.pc_sli4_params.rqv);
  10084. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  10085. bf_set(lpfc_rq_context_rqe_count_1,
  10086. &rq_create->u.request.context,
  10087. hrq->entry_count);
  10088. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  10089. } else {
  10090. switch (drq->entry_count) {
  10091. default:
  10092. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10093. "2536 Unsupported RQ count. (%d)\n",
  10094. drq->entry_count);
  10095. if (drq->entry_count < 512)
  10096. return -EINVAL;
  10097. /* otherwise default to smallest count (drop through) */
  10098. case 512:
  10099. bf_set(lpfc_rq_context_rqe_count,
  10100. &rq_create->u.request.context,
  10101. LPFC_RQ_RING_SIZE_512);
  10102. break;
  10103. case 1024:
  10104. bf_set(lpfc_rq_context_rqe_count,
  10105. &rq_create->u.request.context,
  10106. LPFC_RQ_RING_SIZE_1024);
  10107. break;
  10108. case 2048:
  10109. bf_set(lpfc_rq_context_rqe_count,
  10110. &rq_create->u.request.context,
  10111. LPFC_RQ_RING_SIZE_2048);
  10112. break;
  10113. case 4096:
  10114. bf_set(lpfc_rq_context_rqe_count,
  10115. &rq_create->u.request.context,
  10116. LPFC_RQ_RING_SIZE_4096);
  10117. break;
  10118. }
  10119. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  10120. LPFC_DATA_BUF_SIZE);
  10121. }
  10122. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  10123. cq->queue_id);
  10124. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  10125. drq->page_count);
  10126. list_for_each_entry(dmabuf, &drq->page_list, list) {
  10127. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10128. putPaddrLow(dmabuf->phys);
  10129. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10130. putPaddrHigh(dmabuf->phys);
  10131. }
  10132. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10133. /* The IOCTL status is embedded in the mailbox subheader. */
  10134. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  10135. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10136. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10137. if (shdr_status || shdr_add_status || rc) {
  10138. status = -ENXIO;
  10139. goto out;
  10140. }
  10141. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  10142. if (drq->queue_id == 0xFFFF) {
  10143. status = -ENXIO;
  10144. goto out;
  10145. }
  10146. drq->type = LPFC_DRQ;
  10147. drq->assoc_qid = cq->queue_id;
  10148. drq->subtype = subtype;
  10149. drq->host_index = 0;
  10150. drq->hba_index = 0;
  10151. /* link the header and data RQs onto the parent cq child list */
  10152. list_add_tail(&hrq->list, &cq->child_list);
  10153. list_add_tail(&drq->list, &cq->child_list);
  10154. out:
  10155. mempool_free(mbox, phba->mbox_mem_pool);
  10156. return status;
  10157. }
  10158. /**
  10159. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  10160. * @eq: The queue structure associated with the queue to destroy.
  10161. *
  10162. * This function destroys a queue, as detailed in @eq by sending an mailbox
  10163. * command, specific to the type of queue, to the HBA.
  10164. *
  10165. * The @eq struct is used to get the queue ID of the queue to destroy.
  10166. *
  10167. * On success this function will return a zero. If the queue destroy mailbox
  10168. * command fails this function will return -ENXIO.
  10169. **/
  10170. uint32_t
  10171. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10172. {
  10173. LPFC_MBOXQ_t *mbox;
  10174. int rc, length, status = 0;
  10175. uint32_t shdr_status, shdr_add_status;
  10176. union lpfc_sli4_cfg_shdr *shdr;
  10177. if (!eq)
  10178. return -ENODEV;
  10179. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  10180. if (!mbox)
  10181. return -ENOMEM;
  10182. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  10183. sizeof(struct lpfc_sli4_cfg_mhdr));
  10184. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10185. LPFC_MBOX_OPCODE_EQ_DESTROY,
  10186. length, LPFC_SLI4_MBX_EMBED);
  10187. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  10188. eq->queue_id);
  10189. mbox->vport = eq->phba->pport;
  10190. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10191. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  10192. /* The IOCTL status is embedded in the mailbox subheader. */
  10193. shdr = (union lpfc_sli4_cfg_shdr *)
  10194. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  10195. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10196. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10197. if (shdr_status || shdr_add_status || rc) {
  10198. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10199. "2505 EQ_DESTROY mailbox failed with "
  10200. "status x%x add_status x%x, mbx status x%x\n",
  10201. shdr_status, shdr_add_status, rc);
  10202. status = -ENXIO;
  10203. }
  10204. /* Remove eq from any list */
  10205. list_del_init(&eq->list);
  10206. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10207. return status;
  10208. }
  10209. /**
  10210. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10211. * @cq: The queue structure associated with the queue to destroy.
  10212. *
  10213. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10214. * command, specific to the type of queue, to the HBA.
  10215. *
  10216. * The @cq struct is used to get the queue ID of the queue to destroy.
  10217. *
  10218. * On success this function will return a zero. If the queue destroy mailbox
  10219. * command fails this function will return -ENXIO.
  10220. **/
  10221. uint32_t
  10222. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10223. {
  10224. LPFC_MBOXQ_t *mbox;
  10225. int rc, length, status = 0;
  10226. uint32_t shdr_status, shdr_add_status;
  10227. union lpfc_sli4_cfg_shdr *shdr;
  10228. if (!cq)
  10229. return -ENODEV;
  10230. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10231. if (!mbox)
  10232. return -ENOMEM;
  10233. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10234. sizeof(struct lpfc_sli4_cfg_mhdr));
  10235. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10236. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10237. length, LPFC_SLI4_MBX_EMBED);
  10238. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10239. cq->queue_id);
  10240. mbox->vport = cq->phba->pport;
  10241. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10242. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10243. /* The IOCTL status is embedded in the mailbox subheader. */
  10244. shdr = (union lpfc_sli4_cfg_shdr *)
  10245. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10246. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10247. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10248. if (shdr_status || shdr_add_status || rc) {
  10249. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10250. "2506 CQ_DESTROY mailbox failed with "
  10251. "status x%x add_status x%x, mbx status x%x\n",
  10252. shdr_status, shdr_add_status, rc);
  10253. status = -ENXIO;
  10254. }
  10255. /* Remove cq from any list */
  10256. list_del_init(&cq->list);
  10257. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10258. return status;
  10259. }
  10260. /**
  10261. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10262. * @qm: The queue structure associated with the queue to destroy.
  10263. *
  10264. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10265. * command, specific to the type of queue, to the HBA.
  10266. *
  10267. * The @mq struct is used to get the queue ID of the queue to destroy.
  10268. *
  10269. * On success this function will return a zero. If the queue destroy mailbox
  10270. * command fails this function will return -ENXIO.
  10271. **/
  10272. uint32_t
  10273. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10274. {
  10275. LPFC_MBOXQ_t *mbox;
  10276. int rc, length, status = 0;
  10277. uint32_t shdr_status, shdr_add_status;
  10278. union lpfc_sli4_cfg_shdr *shdr;
  10279. if (!mq)
  10280. return -ENODEV;
  10281. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10282. if (!mbox)
  10283. return -ENOMEM;
  10284. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10285. sizeof(struct lpfc_sli4_cfg_mhdr));
  10286. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10287. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10288. length, LPFC_SLI4_MBX_EMBED);
  10289. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10290. mq->queue_id);
  10291. mbox->vport = mq->phba->pport;
  10292. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10293. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10294. /* The IOCTL status is embedded in the mailbox subheader. */
  10295. shdr = (union lpfc_sli4_cfg_shdr *)
  10296. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10297. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10298. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10299. if (shdr_status || shdr_add_status || rc) {
  10300. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10301. "2507 MQ_DESTROY mailbox failed with "
  10302. "status x%x add_status x%x, mbx status x%x\n",
  10303. shdr_status, shdr_add_status, rc);
  10304. status = -ENXIO;
  10305. }
  10306. /* Remove mq from any list */
  10307. list_del_init(&mq->list);
  10308. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10309. return status;
  10310. }
  10311. /**
  10312. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10313. * @wq: The queue structure associated with the queue to destroy.
  10314. *
  10315. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10316. * command, specific to the type of queue, to the HBA.
  10317. *
  10318. * The @wq struct is used to get the queue ID of the queue to destroy.
  10319. *
  10320. * On success this function will return a zero. If the queue destroy mailbox
  10321. * command fails this function will return -ENXIO.
  10322. **/
  10323. uint32_t
  10324. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10325. {
  10326. LPFC_MBOXQ_t *mbox;
  10327. int rc, length, status = 0;
  10328. uint32_t shdr_status, shdr_add_status;
  10329. union lpfc_sli4_cfg_shdr *shdr;
  10330. if (!wq)
  10331. return -ENODEV;
  10332. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10333. if (!mbox)
  10334. return -ENOMEM;
  10335. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10336. sizeof(struct lpfc_sli4_cfg_mhdr));
  10337. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10338. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10339. length, LPFC_SLI4_MBX_EMBED);
  10340. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10341. wq->queue_id);
  10342. mbox->vport = wq->phba->pport;
  10343. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10344. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10345. shdr = (union lpfc_sli4_cfg_shdr *)
  10346. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10347. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10348. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10349. if (shdr_status || shdr_add_status || rc) {
  10350. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10351. "2508 WQ_DESTROY mailbox failed with "
  10352. "status x%x add_status x%x, mbx status x%x\n",
  10353. shdr_status, shdr_add_status, rc);
  10354. status = -ENXIO;
  10355. }
  10356. /* Remove wq from any list */
  10357. list_del_init(&wq->list);
  10358. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10359. return status;
  10360. }
  10361. /**
  10362. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10363. * @rq: The queue structure associated with the queue to destroy.
  10364. *
  10365. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10366. * command, specific to the type of queue, to the HBA.
  10367. *
  10368. * The @rq struct is used to get the queue ID of the queue to destroy.
  10369. *
  10370. * On success this function will return a zero. If the queue destroy mailbox
  10371. * command fails this function will return -ENXIO.
  10372. **/
  10373. uint32_t
  10374. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10375. struct lpfc_queue *drq)
  10376. {
  10377. LPFC_MBOXQ_t *mbox;
  10378. int rc, length, status = 0;
  10379. uint32_t shdr_status, shdr_add_status;
  10380. union lpfc_sli4_cfg_shdr *shdr;
  10381. if (!hrq || !drq)
  10382. return -ENODEV;
  10383. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10384. if (!mbox)
  10385. return -ENOMEM;
  10386. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10387. sizeof(struct lpfc_sli4_cfg_mhdr));
  10388. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10389. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10390. length, LPFC_SLI4_MBX_EMBED);
  10391. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10392. hrq->queue_id);
  10393. mbox->vport = hrq->phba->pport;
  10394. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10395. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10396. /* The IOCTL status is embedded in the mailbox subheader. */
  10397. shdr = (union lpfc_sli4_cfg_shdr *)
  10398. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10399. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10400. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10401. if (shdr_status || shdr_add_status || rc) {
  10402. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10403. "2509 RQ_DESTROY mailbox failed with "
  10404. "status x%x add_status x%x, mbx status x%x\n",
  10405. shdr_status, shdr_add_status, rc);
  10406. if (rc != MBX_TIMEOUT)
  10407. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10408. return -ENXIO;
  10409. }
  10410. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10411. drq->queue_id);
  10412. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10413. shdr = (union lpfc_sli4_cfg_shdr *)
  10414. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10415. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10416. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10417. if (shdr_status || shdr_add_status || rc) {
  10418. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10419. "2510 RQ_DESTROY mailbox failed with "
  10420. "status x%x add_status x%x, mbx status x%x\n",
  10421. shdr_status, shdr_add_status, rc);
  10422. status = -ENXIO;
  10423. }
  10424. list_del_init(&hrq->list);
  10425. list_del_init(&drq->list);
  10426. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10427. return status;
  10428. }
  10429. /**
  10430. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10431. * @phba: The virtual port for which this call being executed.
  10432. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10433. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10434. * @xritag: the xritag that ties this io to the SGL pages.
  10435. *
  10436. * This routine will post the sgl pages for the IO that has the xritag
  10437. * that is in the iocbq structure. The xritag is assigned during iocbq
  10438. * creation and persists for as long as the driver is loaded.
  10439. * if the caller has fewer than 256 scatter gather segments to map then
  10440. * pdma_phys_addr1 should be 0.
  10441. * If the caller needs to map more than 256 scatter gather segment then
  10442. * pdma_phys_addr1 should be a valid physical address.
  10443. * physical address for SGLs must be 64 byte aligned.
  10444. * If you are going to map 2 SGL's then the first one must have 256 entries
  10445. * the second sgl can have between 1 and 256 entries.
  10446. *
  10447. * Return codes:
  10448. * 0 - Success
  10449. * -ENXIO, -ENOMEM - Failure
  10450. **/
  10451. int
  10452. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10453. dma_addr_t pdma_phys_addr0,
  10454. dma_addr_t pdma_phys_addr1,
  10455. uint16_t xritag)
  10456. {
  10457. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10458. LPFC_MBOXQ_t *mbox;
  10459. int rc;
  10460. uint32_t shdr_status, shdr_add_status;
  10461. union lpfc_sli4_cfg_shdr *shdr;
  10462. if (xritag == NO_XRI) {
  10463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10464. "0364 Invalid param:\n");
  10465. return -EINVAL;
  10466. }
  10467. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10468. if (!mbox)
  10469. return -ENOMEM;
  10470. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10471. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10472. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10473. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  10474. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10475. &mbox->u.mqe.un.post_sgl_pages;
  10476. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10477. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10478. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10479. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10480. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10481. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10482. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10483. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10484. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10485. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10486. if (!phba->sli4_hba.intr_enable)
  10487. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10488. else
  10489. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10490. /* The IOCTL status is embedded in the mailbox subheader. */
  10491. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10492. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10493. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10494. if (rc != MBX_TIMEOUT)
  10495. mempool_free(mbox, phba->mbox_mem_pool);
  10496. if (shdr_status || shdr_add_status || rc) {
  10497. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10498. "2511 POST_SGL mailbox failed with "
  10499. "status x%x add_status x%x, mbx status x%x\n",
  10500. shdr_status, shdr_add_status, rc);
  10501. rc = -ENXIO;
  10502. }
  10503. return 0;
  10504. }
  10505. /**
  10506. * lpfc_sli4_next_xritag - Get an xritag for the io
  10507. * @phba: Pointer to HBA context object.
  10508. *
  10509. * This function gets an xritag for the iocb. If there is no unused xritag
  10510. * it will return 0xffff.
  10511. * The function returns the allocated xritag if successful, else returns zero.
  10512. * Zero is not a valid xritag.
  10513. * The caller is not required to hold any lock.
  10514. **/
  10515. uint16_t
  10516. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10517. {
  10518. uint16_t xritag;
  10519. spin_lock_irq(&phba->hbalock);
  10520. xritag = phba->sli4_hba.next_xri;
  10521. if ((xritag != (uint16_t) -1) && xritag <
  10522. (phba->sli4_hba.max_cfg_param.max_xri
  10523. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10524. phba->sli4_hba.next_xri++;
  10525. phba->sli4_hba.max_cfg_param.xri_used++;
  10526. spin_unlock_irq(&phba->hbalock);
  10527. return xritag;
  10528. }
  10529. spin_unlock_irq(&phba->hbalock);
  10530. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10531. "2004 Failed to allocate XRI.last XRITAG is %d"
  10532. " Max XRI is %d, Used XRI is %d\n",
  10533. phba->sli4_hba.next_xri,
  10534. phba->sli4_hba.max_cfg_param.max_xri,
  10535. phba->sli4_hba.max_cfg_param.xri_used);
  10536. return -1;
  10537. }
  10538. /**
  10539. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10540. * @phba: pointer to lpfc hba data structure.
  10541. *
  10542. * This routine is invoked to post a block of driver's sgl pages to the
  10543. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10544. * is only called when the driver is loading and after all IO has been
  10545. * stopped.
  10546. **/
  10547. int
  10548. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10549. {
  10550. struct lpfc_sglq *sglq_entry;
  10551. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10552. struct sgl_page_pairs *sgl_pg_pairs;
  10553. void *viraddr;
  10554. LPFC_MBOXQ_t *mbox;
  10555. uint32_t reqlen, alloclen, pg_pairs;
  10556. uint32_t mbox_tmo;
  10557. uint16_t xritag_start = 0;
  10558. int els_xri_cnt, rc = 0;
  10559. uint32_t shdr_status, shdr_add_status;
  10560. union lpfc_sli4_cfg_shdr *shdr;
  10561. /* The number of sgls to be posted */
  10562. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10563. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10564. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10565. if (reqlen > SLI4_PAGE_SIZE) {
  10566. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10567. "2559 Block sgl registration required DMA "
  10568. "size (%d) great than a page\n", reqlen);
  10569. return -ENOMEM;
  10570. }
  10571. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10572. if (!mbox) {
  10573. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10574. "2560 Failed to allocate mbox cmd memory\n");
  10575. return -ENOMEM;
  10576. }
  10577. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10578. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10579. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10580. LPFC_SLI4_MBX_NEMBED);
  10581. if (alloclen < reqlen) {
  10582. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10583. "0285 Allocated DMA memory size (%d) is "
  10584. "less than the requested DMA memory "
  10585. "size (%d)\n", alloclen, reqlen);
  10586. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10587. return -ENOMEM;
  10588. }
  10589. /* Get the first SGE entry from the non-embedded DMA memory */
  10590. viraddr = mbox->sge_array->addr[0];
  10591. /* Set up the SGL pages in the non-embedded DMA pages */
  10592. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10593. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10594. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10595. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10596. /* Set up the sge entry */
  10597. sgl_pg_pairs->sgl_pg0_addr_lo =
  10598. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10599. sgl_pg_pairs->sgl_pg0_addr_hi =
  10600. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10601. sgl_pg_pairs->sgl_pg1_addr_lo =
  10602. cpu_to_le32(putPaddrLow(0));
  10603. sgl_pg_pairs->sgl_pg1_addr_hi =
  10604. cpu_to_le32(putPaddrHigh(0));
  10605. /* Keep the first xritag on the list */
  10606. if (pg_pairs == 0)
  10607. xritag_start = sglq_entry->sli4_xritag;
  10608. sgl_pg_pairs++;
  10609. }
  10610. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10611. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10612. /* Perform endian conversion if necessary */
  10613. sgl->word0 = cpu_to_le32(sgl->word0);
  10614. if (!phba->sli4_hba.intr_enable)
  10615. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10616. else {
  10617. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10618. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10619. }
  10620. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10621. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10622. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10623. if (rc != MBX_TIMEOUT)
  10624. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10625. if (shdr_status || shdr_add_status || rc) {
  10626. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10627. "2513 POST_SGL_BLOCK mailbox command failed "
  10628. "status x%x add_status x%x mbx status x%x\n",
  10629. shdr_status, shdr_add_status, rc);
  10630. rc = -ENXIO;
  10631. }
  10632. return rc;
  10633. }
  10634. /**
  10635. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10636. * @phba: pointer to lpfc hba data structure.
  10637. * @sblist: pointer to scsi buffer list.
  10638. * @count: number of scsi buffers on the list.
  10639. *
  10640. * This routine is invoked to post a block of @count scsi sgl pages from a
  10641. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10642. * No Lock is held.
  10643. *
  10644. **/
  10645. int
  10646. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10647. int cnt)
  10648. {
  10649. struct lpfc_scsi_buf *psb;
  10650. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10651. struct sgl_page_pairs *sgl_pg_pairs;
  10652. void *viraddr;
  10653. LPFC_MBOXQ_t *mbox;
  10654. uint32_t reqlen, alloclen, pg_pairs;
  10655. uint32_t mbox_tmo;
  10656. uint16_t xritag_start = 0;
  10657. int rc = 0;
  10658. uint32_t shdr_status, shdr_add_status;
  10659. dma_addr_t pdma_phys_bpl1;
  10660. union lpfc_sli4_cfg_shdr *shdr;
  10661. /* Calculate the requested length of the dma memory */
  10662. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10663. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10664. if (reqlen > SLI4_PAGE_SIZE) {
  10665. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10666. "0217 Block sgl registration required DMA "
  10667. "size (%d) great than a page\n", reqlen);
  10668. return -ENOMEM;
  10669. }
  10670. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10671. if (!mbox) {
  10672. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10673. "0283 Failed to allocate mbox cmd memory\n");
  10674. return -ENOMEM;
  10675. }
  10676. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10677. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10678. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10679. LPFC_SLI4_MBX_NEMBED);
  10680. if (alloclen < reqlen) {
  10681. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10682. "2561 Allocated DMA memory size (%d) is "
  10683. "less than the requested DMA memory "
  10684. "size (%d)\n", alloclen, reqlen);
  10685. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10686. return -ENOMEM;
  10687. }
  10688. /* Get the first SGE entry from the non-embedded DMA memory */
  10689. viraddr = mbox->sge_array->addr[0];
  10690. /* Set up the SGL pages in the non-embedded DMA pages */
  10691. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10692. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10693. pg_pairs = 0;
  10694. list_for_each_entry(psb, sblist, list) {
  10695. /* Set up the sge entry */
  10696. sgl_pg_pairs->sgl_pg0_addr_lo =
  10697. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10698. sgl_pg_pairs->sgl_pg0_addr_hi =
  10699. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10700. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10701. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10702. else
  10703. pdma_phys_bpl1 = 0;
  10704. sgl_pg_pairs->sgl_pg1_addr_lo =
  10705. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10706. sgl_pg_pairs->sgl_pg1_addr_hi =
  10707. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10708. /* Keep the first xritag on the list */
  10709. if (pg_pairs == 0)
  10710. xritag_start = psb->cur_iocbq.sli4_xritag;
  10711. sgl_pg_pairs++;
  10712. pg_pairs++;
  10713. }
  10714. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10715. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10716. /* Perform endian conversion if necessary */
  10717. sgl->word0 = cpu_to_le32(sgl->word0);
  10718. if (!phba->sli4_hba.intr_enable)
  10719. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10720. else {
  10721. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10722. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10723. }
  10724. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10725. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10726. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10727. if (rc != MBX_TIMEOUT)
  10728. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10729. if (shdr_status || shdr_add_status || rc) {
  10730. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10731. "2564 POST_SGL_BLOCK mailbox command failed "
  10732. "status x%x add_status x%x mbx status x%x\n",
  10733. shdr_status, shdr_add_status, rc);
  10734. rc = -ENXIO;
  10735. }
  10736. return rc;
  10737. }
  10738. /**
  10739. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10740. * @phba: pointer to lpfc_hba struct that the frame was received on
  10741. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10742. *
  10743. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10744. * valid type of frame that the LPFC driver will handle. This function will
  10745. * return a zero if the frame is a valid frame or a non zero value when the
  10746. * frame does not pass the check.
  10747. **/
  10748. static int
  10749. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10750. {
  10751. /* make rctl_names static to save stack space */
  10752. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10753. char *type_names[] = FC_TYPE_NAMES_INIT;
  10754. struct fc_vft_header *fc_vft_hdr;
  10755. uint32_t *header = (uint32_t *) fc_hdr;
  10756. switch (fc_hdr->fh_r_ctl) {
  10757. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10758. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10759. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10760. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10761. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10762. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10763. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10764. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10765. case FC_RCTL_ELS_REQ: /* extended link services request */
  10766. case FC_RCTL_ELS_REP: /* extended link services reply */
  10767. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10768. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10769. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10770. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10771. case FC_RCTL_BA_RMC: /* remove connection */
  10772. case FC_RCTL_BA_ACC: /* basic accept */
  10773. case FC_RCTL_BA_RJT: /* basic reject */
  10774. case FC_RCTL_BA_PRMT:
  10775. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10776. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10777. case FC_RCTL_P_RJT: /* port reject */
  10778. case FC_RCTL_F_RJT: /* fabric reject */
  10779. case FC_RCTL_P_BSY: /* port busy */
  10780. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10781. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10782. case FC_RCTL_LCR: /* link credit reset */
  10783. case FC_RCTL_END: /* end */
  10784. break;
  10785. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10786. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10787. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10788. return lpfc_fc_frame_check(phba, fc_hdr);
  10789. default:
  10790. goto drop;
  10791. }
  10792. switch (fc_hdr->fh_type) {
  10793. case FC_TYPE_BLS:
  10794. case FC_TYPE_ELS:
  10795. case FC_TYPE_FCP:
  10796. case FC_TYPE_CT:
  10797. break;
  10798. case FC_TYPE_IP:
  10799. case FC_TYPE_ILS:
  10800. default:
  10801. goto drop;
  10802. }
  10803. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10804. "2538 Received frame rctl:%s type:%s "
  10805. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  10806. rctl_names[fc_hdr->fh_r_ctl],
  10807. type_names[fc_hdr->fh_type],
  10808. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  10809. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  10810. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  10811. return 0;
  10812. drop:
  10813. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10814. "2539 Dropped frame rctl:%s type:%s\n",
  10815. rctl_names[fc_hdr->fh_r_ctl],
  10816. type_names[fc_hdr->fh_type]);
  10817. return 1;
  10818. }
  10819. /**
  10820. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10821. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10822. *
  10823. * This function processes the FC header to retrieve the VFI from the VF
  10824. * header, if one exists. This function will return the VFI if one exists
  10825. * or 0 if no VSAN Header exists.
  10826. **/
  10827. static uint32_t
  10828. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10829. {
  10830. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10831. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10832. return 0;
  10833. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10834. }
  10835. /**
  10836. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10837. * @phba: Pointer to the HBA structure to search for the vport on
  10838. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10839. * @fcfi: The FC Fabric ID that the frame came from
  10840. *
  10841. * This function searches the @phba for a vport that matches the content of the
  10842. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10843. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10844. * returns the matching vport pointer or NULL if unable to match frame to a
  10845. * vport.
  10846. **/
  10847. static struct lpfc_vport *
  10848. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10849. uint16_t fcfi)
  10850. {
  10851. struct lpfc_vport **vports;
  10852. struct lpfc_vport *vport = NULL;
  10853. int i;
  10854. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10855. fc_hdr->fh_d_id[1] << 8 |
  10856. fc_hdr->fh_d_id[2]);
  10857. vports = lpfc_create_vport_work_array(phba);
  10858. if (vports != NULL)
  10859. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10860. if (phba->fcf.fcfi == fcfi &&
  10861. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10862. vports[i]->fc_myDID == did) {
  10863. vport = vports[i];
  10864. break;
  10865. }
  10866. }
  10867. lpfc_destroy_vport_work_array(phba, vports);
  10868. return vport;
  10869. }
  10870. /**
  10871. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10872. * @vport: The vport to work on.
  10873. *
  10874. * This function updates the receive sequence time stamp for this vport. The
  10875. * receive sequence time stamp indicates the time that the last frame of the
  10876. * the sequence that has been idle for the longest amount of time was received.
  10877. * the driver uses this time stamp to indicate if any received sequences have
  10878. * timed out.
  10879. **/
  10880. void
  10881. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10882. {
  10883. struct lpfc_dmabuf *h_buf;
  10884. struct hbq_dmabuf *dmabuf = NULL;
  10885. /* get the oldest sequence on the rcv list */
  10886. h_buf = list_get_first(&vport->rcv_buffer_list,
  10887. struct lpfc_dmabuf, list);
  10888. if (!h_buf)
  10889. return;
  10890. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10891. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10892. }
  10893. /**
  10894. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10895. * @vport: The vport that the received sequences were sent to.
  10896. *
  10897. * This function cleans up all outstanding received sequences. This is called
  10898. * by the driver when a link event or user action invalidates all the received
  10899. * sequences.
  10900. **/
  10901. void
  10902. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10903. {
  10904. struct lpfc_dmabuf *h_buf, *hnext;
  10905. struct lpfc_dmabuf *d_buf, *dnext;
  10906. struct hbq_dmabuf *dmabuf = NULL;
  10907. /* start with the oldest sequence on the rcv list */
  10908. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10909. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10910. list_del_init(&dmabuf->hbuf.list);
  10911. list_for_each_entry_safe(d_buf, dnext,
  10912. &dmabuf->dbuf.list, list) {
  10913. list_del_init(&d_buf->list);
  10914. lpfc_in_buf_free(vport->phba, d_buf);
  10915. }
  10916. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10917. }
  10918. }
  10919. /**
  10920. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10921. * @vport: The vport that the received sequences were sent to.
  10922. *
  10923. * This function determines whether any received sequences have timed out by
  10924. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10925. * indicates that there is at least one timed out sequence this routine will
  10926. * go through the received sequences one at a time from most inactive to most
  10927. * active to determine which ones need to be cleaned up. Once it has determined
  10928. * that a sequence needs to be cleaned up it will simply free up the resources
  10929. * without sending an abort.
  10930. **/
  10931. void
  10932. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10933. {
  10934. struct lpfc_dmabuf *h_buf, *hnext;
  10935. struct lpfc_dmabuf *d_buf, *dnext;
  10936. struct hbq_dmabuf *dmabuf = NULL;
  10937. unsigned long timeout;
  10938. int abort_count = 0;
  10939. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10940. vport->rcv_buffer_time_stamp);
  10941. if (list_empty(&vport->rcv_buffer_list) ||
  10942. time_before(jiffies, timeout))
  10943. return;
  10944. /* start with the oldest sequence on the rcv list */
  10945. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10946. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10947. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10948. dmabuf->time_stamp);
  10949. if (time_before(jiffies, timeout))
  10950. break;
  10951. abort_count++;
  10952. list_del_init(&dmabuf->hbuf.list);
  10953. list_for_each_entry_safe(d_buf, dnext,
  10954. &dmabuf->dbuf.list, list) {
  10955. list_del_init(&d_buf->list);
  10956. lpfc_in_buf_free(vport->phba, d_buf);
  10957. }
  10958. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10959. }
  10960. if (abort_count)
  10961. lpfc_update_rcv_time_stamp(vport);
  10962. }
  10963. /**
  10964. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10965. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10966. *
  10967. * This function searches through the existing incomplete sequences that have
  10968. * been sent to this @vport. If the frame matches one of the incomplete
  10969. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10970. * make up that sequence. If no sequence is found that matches this frame then
  10971. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10972. * This function returns a pointer to the first dmabuf in the sequence list that
  10973. * the frame was linked to.
  10974. **/
  10975. static struct hbq_dmabuf *
  10976. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10977. {
  10978. struct fc_frame_header *new_hdr;
  10979. struct fc_frame_header *temp_hdr;
  10980. struct lpfc_dmabuf *d_buf;
  10981. struct lpfc_dmabuf *h_buf;
  10982. struct hbq_dmabuf *seq_dmabuf = NULL;
  10983. struct hbq_dmabuf *temp_dmabuf = NULL;
  10984. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10985. dmabuf->time_stamp = jiffies;
  10986. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10987. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10988. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10989. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10990. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10991. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10992. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10993. continue;
  10994. /* found a pending sequence that matches this frame */
  10995. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10996. break;
  10997. }
  10998. if (!seq_dmabuf) {
  10999. /*
  11000. * This indicates first frame received for this sequence.
  11001. * Queue the buffer on the vport's rcv_buffer_list.
  11002. */
  11003. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11004. lpfc_update_rcv_time_stamp(vport);
  11005. return dmabuf;
  11006. }
  11007. temp_hdr = seq_dmabuf->hbuf.virt;
  11008. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  11009. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  11010. list_del_init(&seq_dmabuf->hbuf.list);
  11011. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11012. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  11013. lpfc_update_rcv_time_stamp(vport);
  11014. return dmabuf;
  11015. }
  11016. /* move this sequence to the tail to indicate a young sequence */
  11017. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11018. seq_dmabuf->time_stamp = jiffies;
  11019. lpfc_update_rcv_time_stamp(vport);
  11020. if (list_empty(&seq_dmabuf->dbuf.list)) {
  11021. temp_hdr = dmabuf->hbuf.virt;
  11022. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  11023. return seq_dmabuf;
  11024. }
  11025. /* find the correct place in the sequence to insert this frame */
  11026. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  11027. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11028. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  11029. /*
  11030. * If the frame's sequence count is greater than the frame on
  11031. * the list then insert the frame right after this frame
  11032. */
  11033. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  11034. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  11035. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  11036. return seq_dmabuf;
  11037. }
  11038. }
  11039. return NULL;
  11040. }
  11041. /**
  11042. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  11043. * @vport: pointer to a vitural port
  11044. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11045. *
  11046. * This function tries to abort from the partially assembed sequence, described
  11047. * by the information from basic abbort @dmabuf. It checks to see whether such
  11048. * partially assembled sequence held by the driver. If so, it shall free up all
  11049. * the frames from the partially assembled sequence.
  11050. *
  11051. * Return
  11052. * true -- if there is matching partially assembled sequence present and all
  11053. * the frames freed with the sequence;
  11054. * false -- if there is no matching partially assembled sequence present so
  11055. * nothing got aborted in the lower layer driver
  11056. **/
  11057. static bool
  11058. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  11059. struct hbq_dmabuf *dmabuf)
  11060. {
  11061. struct fc_frame_header *new_hdr;
  11062. struct fc_frame_header *temp_hdr;
  11063. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  11064. struct hbq_dmabuf *seq_dmabuf = NULL;
  11065. /* Use the hdr_buf to find the sequence that matches this frame */
  11066. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  11067. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  11068. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11069. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  11070. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  11071. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  11072. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  11073. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  11074. continue;
  11075. /* found a pending sequence that matches this frame */
  11076. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  11077. break;
  11078. }
  11079. /* Free up all the frames from the partially assembled sequence */
  11080. if (seq_dmabuf) {
  11081. list_for_each_entry_safe(d_buf, n_buf,
  11082. &seq_dmabuf->dbuf.list, list) {
  11083. list_del_init(&d_buf->list);
  11084. lpfc_in_buf_free(vport->phba, d_buf);
  11085. }
  11086. return true;
  11087. }
  11088. return false;
  11089. }
  11090. /**
  11091. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  11092. * @phba: Pointer to HBA context object.
  11093. * @cmd_iocbq: pointer to the command iocbq structure.
  11094. * @rsp_iocbq: pointer to the response iocbq structure.
  11095. *
  11096. * This function handles the sequence abort response iocb command complete
  11097. * event. It properly releases the memory allocated to the sequence abort
  11098. * accept iocb.
  11099. **/
  11100. static void
  11101. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  11102. struct lpfc_iocbq *cmd_iocbq,
  11103. struct lpfc_iocbq *rsp_iocbq)
  11104. {
  11105. if (cmd_iocbq)
  11106. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  11107. }
  11108. /**
  11109. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  11110. * @phba: Pointer to HBA context object.
  11111. * @fc_hdr: pointer to a FC frame header.
  11112. *
  11113. * This function sends a basic response to a previous unsol sequence abort
  11114. * event after aborting the sequence handling.
  11115. **/
  11116. static void
  11117. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  11118. struct fc_frame_header *fc_hdr)
  11119. {
  11120. struct lpfc_iocbq *ctiocb = NULL;
  11121. struct lpfc_nodelist *ndlp;
  11122. uint16_t oxid, rxid;
  11123. uint32_t sid, fctl;
  11124. IOCB_t *icmd;
  11125. int rc;
  11126. if (!lpfc_is_link_up(phba))
  11127. return;
  11128. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11129. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  11130. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  11131. ndlp = lpfc_findnode_did(phba->pport, sid);
  11132. if (!ndlp) {
  11133. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  11134. "1268 Find ndlp returned NULL for oxid:x%x "
  11135. "SID:x%x\n", oxid, sid);
  11136. return;
  11137. }
  11138. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  11139. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  11140. + phba->sli4_hba.max_cfg_param.xri_base))
  11141. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  11142. /* Allocate buffer for rsp iocb */
  11143. ctiocb = lpfc_sli_get_iocbq(phba);
  11144. if (!ctiocb)
  11145. return;
  11146. /* Extract the F_CTL field from FC_HDR */
  11147. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  11148. icmd = &ctiocb->iocb;
  11149. icmd->un.xseq64.bdl.bdeSize = 0;
  11150. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  11151. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  11152. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  11153. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  11154. /* Fill in the rest of iocb fields */
  11155. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  11156. icmd->ulpBdeCount = 0;
  11157. icmd->ulpLe = 1;
  11158. icmd->ulpClass = CLASS3;
  11159. icmd->ulpContext = ndlp->nlp_rpi;
  11160. ctiocb->context1 = ndlp;
  11161. ctiocb->iocb_cmpl = NULL;
  11162. ctiocb->vport = phba->pport;
  11163. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  11164. ctiocb->sli4_xritag = NO_XRI;
  11165. /* If the oxid maps to the FCP XRI range or if it is out of range,
  11166. * send a BLS_RJT. The driver no longer has that exchange.
  11167. * Override the IOCB for a BA_RJT.
  11168. */
  11169. if (oxid > (phba->sli4_hba.max_cfg_param.max_xri +
  11170. phba->sli4_hba.max_cfg_param.xri_base) ||
  11171. oxid > (lpfc_sli4_get_els_iocb_cnt(phba) +
  11172. phba->sli4_hba.max_cfg_param.xri_base)) {
  11173. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  11174. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  11175. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  11176. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  11177. }
  11178. if (fctl & FC_FC_EX_CTX) {
  11179. /* ABTS sent by responder to CT exchange, construction
  11180. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  11181. * field and RX_ID from ABTS for RX_ID field.
  11182. */
  11183. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  11184. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  11185. } else {
  11186. /* ABTS sent by initiator to CT exchange, construction
  11187. * of BA_ACC will need to allocate a new XRI as for the
  11188. * XRI_TAG and RX_ID fields.
  11189. */
  11190. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  11191. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI);
  11192. }
  11193. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  11194. /* Xmit CT abts response on exchange <xid> */
  11195. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11196. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  11197. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  11198. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  11199. if (rc == IOCB_ERROR) {
  11200. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  11201. "2925 Failed to issue CT ABTS RSP x%x on "
  11202. "xri x%x, Data x%x\n",
  11203. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  11204. phba->link_state);
  11205. lpfc_sli_release_iocbq(phba, ctiocb);
  11206. }
  11207. }
  11208. /**
  11209. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  11210. * @vport: Pointer to the vport on which this sequence was received
  11211. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11212. *
  11213. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  11214. * receive sequence is only partially assembed by the driver, it shall abort
  11215. * the partially assembled frames for the sequence. Otherwise, if the
  11216. * unsolicited receive sequence has been completely assembled and passed to
  11217. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  11218. * unsolicited sequence has been aborted. After that, it will issue a basic
  11219. * accept to accept the abort.
  11220. **/
  11221. void
  11222. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  11223. struct hbq_dmabuf *dmabuf)
  11224. {
  11225. struct lpfc_hba *phba = vport->phba;
  11226. struct fc_frame_header fc_hdr;
  11227. uint32_t fctl;
  11228. bool abts_par;
  11229. /* Make a copy of fc_hdr before the dmabuf being released */
  11230. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11231. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11232. if (fctl & FC_FC_EX_CTX) {
  11233. /*
  11234. * ABTS sent by responder to exchange, just free the buffer
  11235. */
  11236. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11237. } else {
  11238. /*
  11239. * ABTS sent by initiator to exchange, need to do cleanup
  11240. */
  11241. /* Try to abort partially assembled seq */
  11242. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11243. /* Send abort to ULP if partially seq abort failed */
  11244. if (abts_par == false)
  11245. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11246. else
  11247. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11248. }
  11249. /* Send basic accept (BA_ACC) to the abort requester */
  11250. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  11251. }
  11252. /**
  11253. * lpfc_seq_complete - Indicates if a sequence is complete
  11254. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11255. *
  11256. * This function checks the sequence, starting with the frame described by
  11257. * @dmabuf, to see if all the frames associated with this sequence are present.
  11258. * the frames associated with this sequence are linked to the @dmabuf using the
  11259. * dbuf list. This function looks for two major things. 1) That the first frame
  11260. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11261. * set. 3) That there are no holes in the sequence count. The function will
  11262. * return 1 when the sequence is complete, otherwise it will return 0.
  11263. **/
  11264. static int
  11265. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11266. {
  11267. struct fc_frame_header *hdr;
  11268. struct lpfc_dmabuf *d_buf;
  11269. struct hbq_dmabuf *seq_dmabuf;
  11270. uint32_t fctl;
  11271. int seq_count = 0;
  11272. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11273. /* make sure first fame of sequence has a sequence count of zero */
  11274. if (hdr->fh_seq_cnt != seq_count)
  11275. return 0;
  11276. fctl = (hdr->fh_f_ctl[0] << 16 |
  11277. hdr->fh_f_ctl[1] << 8 |
  11278. hdr->fh_f_ctl[2]);
  11279. /* If last frame of sequence we can return success. */
  11280. if (fctl & FC_FC_END_SEQ)
  11281. return 1;
  11282. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11283. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11284. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11285. /* If there is a hole in the sequence count then fail. */
  11286. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11287. return 0;
  11288. fctl = (hdr->fh_f_ctl[0] << 16 |
  11289. hdr->fh_f_ctl[1] << 8 |
  11290. hdr->fh_f_ctl[2]);
  11291. /* If last frame of sequence we can return success. */
  11292. if (fctl & FC_FC_END_SEQ)
  11293. return 1;
  11294. }
  11295. return 0;
  11296. }
  11297. /**
  11298. * lpfc_prep_seq - Prep sequence for ULP processing
  11299. * @vport: Pointer to the vport on which this sequence was received
  11300. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11301. *
  11302. * This function takes a sequence, described by a list of frames, and creates
  11303. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11304. * used to issue to the generic unsolicited sequence handler. This routine
  11305. * returns a pointer to the first iocbq in the list. If the function is unable
  11306. * to allocate an iocbq then it throw out the received frames that were not
  11307. * able to be described and return a pointer to the first iocbq. If unable to
  11308. * allocate any iocbqs (including the first) this function will return NULL.
  11309. **/
  11310. static struct lpfc_iocbq *
  11311. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11312. {
  11313. struct lpfc_dmabuf *d_buf, *n_buf;
  11314. struct lpfc_iocbq *first_iocbq, *iocbq;
  11315. struct fc_frame_header *fc_hdr;
  11316. uint32_t sid;
  11317. struct ulp_bde64 *pbde;
  11318. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11319. /* remove from receive buffer list */
  11320. list_del_init(&seq_dmabuf->hbuf.list);
  11321. lpfc_update_rcv_time_stamp(vport);
  11322. /* get the Remote Port's SID */
  11323. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11324. /* Get an iocbq struct to fill in. */
  11325. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11326. if (first_iocbq) {
  11327. /* Initialize the first IOCB. */
  11328. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11329. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11330. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11331. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11332. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11333. vport->vpi + vport->phba->vpi_base;
  11334. /* put the first buffer into the first IOCBq */
  11335. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11336. first_iocbq->context3 = NULL;
  11337. first_iocbq->iocb.ulpBdeCount = 1;
  11338. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11339. LPFC_DATA_BUF_SIZE;
  11340. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11341. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11342. bf_get(lpfc_rcqe_length,
  11343. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11344. }
  11345. iocbq = first_iocbq;
  11346. /*
  11347. * Each IOCBq can have two Buffers assigned, so go through the list
  11348. * of buffers for this sequence and save two buffers in each IOCBq
  11349. */
  11350. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11351. if (!iocbq) {
  11352. lpfc_in_buf_free(vport->phba, d_buf);
  11353. continue;
  11354. }
  11355. if (!iocbq->context3) {
  11356. iocbq->context3 = d_buf;
  11357. iocbq->iocb.ulpBdeCount++;
  11358. pbde = (struct ulp_bde64 *)
  11359. &iocbq->iocb.unsli3.sli3Words[4];
  11360. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11361. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11362. bf_get(lpfc_rcqe_length,
  11363. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11364. } else {
  11365. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11366. if (!iocbq) {
  11367. if (first_iocbq) {
  11368. first_iocbq->iocb.ulpStatus =
  11369. IOSTAT_FCP_RSP_ERROR;
  11370. first_iocbq->iocb.un.ulpWord[4] =
  11371. IOERR_NO_RESOURCES;
  11372. }
  11373. lpfc_in_buf_free(vport->phba, d_buf);
  11374. continue;
  11375. }
  11376. iocbq->context2 = d_buf;
  11377. iocbq->context3 = NULL;
  11378. iocbq->iocb.ulpBdeCount = 1;
  11379. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11380. LPFC_DATA_BUF_SIZE;
  11381. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11382. bf_get(lpfc_rcqe_length,
  11383. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11384. iocbq->iocb.un.rcvels.remoteID = sid;
  11385. list_add_tail(&iocbq->list, &first_iocbq->list);
  11386. }
  11387. }
  11388. return first_iocbq;
  11389. }
  11390. static void
  11391. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11392. struct hbq_dmabuf *seq_dmabuf)
  11393. {
  11394. struct fc_frame_header *fc_hdr;
  11395. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11396. struct lpfc_hba *phba = vport->phba;
  11397. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11398. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11399. if (!iocbq) {
  11400. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11401. "2707 Ring %d handler: Failed to allocate "
  11402. "iocb Rctl x%x Type x%x received\n",
  11403. LPFC_ELS_RING,
  11404. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11405. return;
  11406. }
  11407. if (!lpfc_complete_unsol_iocb(phba,
  11408. &phba->sli.ring[LPFC_ELS_RING],
  11409. iocbq, fc_hdr->fh_r_ctl,
  11410. fc_hdr->fh_type))
  11411. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11412. "2540 Ring %d handler: unexpected Rctl "
  11413. "x%x Type x%x received\n",
  11414. LPFC_ELS_RING,
  11415. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11416. /* Free iocb created in lpfc_prep_seq */
  11417. list_for_each_entry_safe(curr_iocb, next_iocb,
  11418. &iocbq->list, list) {
  11419. list_del_init(&curr_iocb->list);
  11420. lpfc_sli_release_iocbq(phba, curr_iocb);
  11421. }
  11422. lpfc_sli_release_iocbq(phba, iocbq);
  11423. }
  11424. /**
  11425. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11426. * @phba: Pointer to HBA context object.
  11427. *
  11428. * This function is called with no lock held. This function processes all
  11429. * the received buffers and gives it to upper layers when a received buffer
  11430. * indicates that it is the final frame in the sequence. The interrupt
  11431. * service routine processes received buffers at interrupt contexts and adds
  11432. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11433. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11434. * appropriate receive function when the final frame in a sequence is received.
  11435. **/
  11436. void
  11437. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11438. struct hbq_dmabuf *dmabuf)
  11439. {
  11440. struct hbq_dmabuf *seq_dmabuf;
  11441. struct fc_frame_header *fc_hdr;
  11442. struct lpfc_vport *vport;
  11443. uint32_t fcfi;
  11444. /* Process each received buffer */
  11445. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11446. /* check to see if this a valid type of frame */
  11447. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11448. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11449. return;
  11450. }
  11451. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11452. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11453. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11454. /* throw out the frame */
  11455. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11456. return;
  11457. }
  11458. /* Handle the basic abort sequence (BA_ABTS) event */
  11459. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11460. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11461. return;
  11462. }
  11463. /* Link this frame */
  11464. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11465. if (!seq_dmabuf) {
  11466. /* unable to add frame to vport - throw it out */
  11467. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11468. return;
  11469. }
  11470. /* If not last frame in sequence continue processing frames. */
  11471. if (!lpfc_seq_complete(seq_dmabuf))
  11472. return;
  11473. /* Send the complete sequence to the upper layer protocol */
  11474. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11475. }
  11476. /**
  11477. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11478. * @phba: pointer to lpfc hba data structure.
  11479. *
  11480. * This routine is invoked to post rpi header templates to the
  11481. * HBA consistent with the SLI-4 interface spec. This routine
  11482. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11483. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11484. *
  11485. * This routine does not require any locks. It's usage is expected
  11486. * to be driver load or reset recovery when the driver is
  11487. * sequential.
  11488. *
  11489. * Return codes
  11490. * 0 - successful
  11491. * -EIO - The mailbox failed to complete successfully.
  11492. * When this error occurs, the driver is not guaranteed
  11493. * to have any rpi regions posted to the device and
  11494. * must either attempt to repost the regions or take a
  11495. * fatal error.
  11496. **/
  11497. int
  11498. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11499. {
  11500. struct lpfc_rpi_hdr *rpi_page;
  11501. uint32_t rc = 0;
  11502. /* Post all rpi memory regions to the port. */
  11503. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11504. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11505. if (rc != MBX_SUCCESS) {
  11506. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11507. "2008 Error %d posting all rpi "
  11508. "headers\n", rc);
  11509. rc = -EIO;
  11510. break;
  11511. }
  11512. }
  11513. return rc;
  11514. }
  11515. /**
  11516. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11517. * @phba: pointer to lpfc hba data structure.
  11518. * @rpi_page: pointer to the rpi memory region.
  11519. *
  11520. * This routine is invoked to post a single rpi header to the
  11521. * HBA consistent with the SLI-4 interface spec. This memory region
  11522. * maps up to 64 rpi context regions.
  11523. *
  11524. * Return codes
  11525. * 0 - successful
  11526. * -ENOMEM - No available memory
  11527. * -EIO - The mailbox failed to complete successfully.
  11528. **/
  11529. int
  11530. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11531. {
  11532. LPFC_MBOXQ_t *mboxq;
  11533. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11534. uint32_t rc = 0;
  11535. uint32_t mbox_tmo;
  11536. uint32_t shdr_status, shdr_add_status;
  11537. union lpfc_sli4_cfg_shdr *shdr;
  11538. /* The port is notified of the header region via a mailbox command. */
  11539. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11540. if (!mboxq) {
  11541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11542. "2001 Unable to allocate memory for issuing "
  11543. "SLI_CONFIG_SPECIAL mailbox command\n");
  11544. return -ENOMEM;
  11545. }
  11546. /* Post all rpi memory regions to the port. */
  11547. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11548. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11549. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11550. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11551. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11552. sizeof(struct lpfc_sli4_cfg_mhdr),
  11553. LPFC_SLI4_MBX_EMBED);
  11554. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11555. hdr_tmpl, rpi_page->page_count);
  11556. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11557. rpi_page->start_rpi);
  11558. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11559. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11560. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11561. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11562. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11563. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11564. if (rc != MBX_TIMEOUT)
  11565. mempool_free(mboxq, phba->mbox_mem_pool);
  11566. if (shdr_status || shdr_add_status || rc) {
  11567. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11568. "2514 POST_RPI_HDR mailbox failed with "
  11569. "status x%x add_status x%x, mbx status x%x\n",
  11570. shdr_status, shdr_add_status, rc);
  11571. rc = -ENXIO;
  11572. }
  11573. return rc;
  11574. }
  11575. /**
  11576. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11577. * @phba: pointer to lpfc hba data structure.
  11578. *
  11579. * This routine is invoked to post rpi header templates to the
  11580. * HBA consistent with the SLI-4 interface spec. This routine
  11581. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11582. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11583. *
  11584. * Returns
  11585. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11586. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11587. **/
  11588. int
  11589. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11590. {
  11591. int rpi;
  11592. uint16_t max_rpi, rpi_base, rpi_limit;
  11593. uint16_t rpi_remaining;
  11594. struct lpfc_rpi_hdr *rpi_hdr;
  11595. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11596. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11597. rpi_limit = phba->sli4_hba.next_rpi;
  11598. /*
  11599. * The valid rpi range is not guaranteed to be zero-based. Start
  11600. * the search at the rpi_base as reported by the port.
  11601. */
  11602. spin_lock_irq(&phba->hbalock);
  11603. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11604. if (rpi >= rpi_limit || rpi < rpi_base)
  11605. rpi = LPFC_RPI_ALLOC_ERROR;
  11606. else {
  11607. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11608. phba->sli4_hba.max_cfg_param.rpi_used++;
  11609. phba->sli4_hba.rpi_count++;
  11610. }
  11611. /*
  11612. * Don't try to allocate more rpi header regions if the device limit
  11613. * on available rpis max has been exhausted.
  11614. */
  11615. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11616. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11617. spin_unlock_irq(&phba->hbalock);
  11618. return rpi;
  11619. }
  11620. /*
  11621. * If the driver is running low on rpi resources, allocate another
  11622. * page now. Note that the next_rpi value is used because
  11623. * it represents how many are actually in use whereas max_rpi notes
  11624. * how many are supported max by the device.
  11625. */
  11626. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11627. phba->sli4_hba.rpi_count;
  11628. spin_unlock_irq(&phba->hbalock);
  11629. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11630. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11631. if (!rpi_hdr) {
  11632. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11633. "2002 Error Could not grow rpi "
  11634. "count\n");
  11635. } else {
  11636. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11637. }
  11638. }
  11639. return rpi;
  11640. }
  11641. /**
  11642. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11643. * @phba: pointer to lpfc hba data structure.
  11644. *
  11645. * This routine is invoked to release an rpi to the pool of
  11646. * available rpis maintained by the driver.
  11647. **/
  11648. void
  11649. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11650. {
  11651. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11652. phba->sli4_hba.rpi_count--;
  11653. phba->sli4_hba.max_cfg_param.rpi_used--;
  11654. }
  11655. }
  11656. /**
  11657. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11658. * @phba: pointer to lpfc hba data structure.
  11659. *
  11660. * This routine is invoked to release an rpi to the pool of
  11661. * available rpis maintained by the driver.
  11662. **/
  11663. void
  11664. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11665. {
  11666. spin_lock_irq(&phba->hbalock);
  11667. __lpfc_sli4_free_rpi(phba, rpi);
  11668. spin_unlock_irq(&phba->hbalock);
  11669. }
  11670. /**
  11671. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11672. * @phba: pointer to lpfc hba data structure.
  11673. *
  11674. * This routine is invoked to remove the memory region that
  11675. * provided rpi via a bitmask.
  11676. **/
  11677. void
  11678. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11679. {
  11680. kfree(phba->sli4_hba.rpi_bmask);
  11681. }
  11682. /**
  11683. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11684. * @phba: pointer to lpfc hba data structure.
  11685. *
  11686. * This routine is invoked to remove the memory region that
  11687. * provided rpi via a bitmask.
  11688. **/
  11689. int
  11690. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11691. {
  11692. LPFC_MBOXQ_t *mboxq;
  11693. struct lpfc_hba *phba = ndlp->phba;
  11694. int rc;
  11695. /* The port is notified of the header region via a mailbox command. */
  11696. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11697. if (!mboxq)
  11698. return -ENOMEM;
  11699. /* Post all rpi memory regions to the port. */
  11700. lpfc_resume_rpi(mboxq, ndlp);
  11701. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11702. if (rc == MBX_NOT_FINISHED) {
  11703. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11704. "2010 Resume RPI Mailbox failed "
  11705. "status %d, mbxStatus x%x\n", rc,
  11706. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11707. mempool_free(mboxq, phba->mbox_mem_pool);
  11708. return -EIO;
  11709. }
  11710. return 0;
  11711. }
  11712. /**
  11713. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11714. * @vport: Pointer to the vport for which the vpi is being initialized
  11715. *
  11716. * This routine is invoked to activate a vpi with the port.
  11717. *
  11718. * Returns:
  11719. * 0 success
  11720. * -Evalue otherwise
  11721. **/
  11722. int
  11723. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11724. {
  11725. LPFC_MBOXQ_t *mboxq;
  11726. int rc = 0;
  11727. int retval = MBX_SUCCESS;
  11728. uint32_t mbox_tmo;
  11729. struct lpfc_hba *phba = vport->phba;
  11730. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11731. if (!mboxq)
  11732. return -ENOMEM;
  11733. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11734. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11735. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11736. if (rc != MBX_SUCCESS) {
  11737. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11738. "2022 INIT VPI Mailbox failed "
  11739. "status %d, mbxStatus x%x\n", rc,
  11740. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11741. retval = -EIO;
  11742. }
  11743. if (rc != MBX_TIMEOUT)
  11744. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11745. return retval;
  11746. }
  11747. /**
  11748. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11749. * @phba: pointer to lpfc hba data structure.
  11750. * @mboxq: Pointer to mailbox object.
  11751. *
  11752. * This routine is invoked to manually add a single FCF record. The caller
  11753. * must pass a completely initialized FCF_Record. This routine takes
  11754. * care of the nonembedded mailbox operations.
  11755. **/
  11756. static void
  11757. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11758. {
  11759. void *virt_addr;
  11760. union lpfc_sli4_cfg_shdr *shdr;
  11761. uint32_t shdr_status, shdr_add_status;
  11762. virt_addr = mboxq->sge_array->addr[0];
  11763. /* The IOCTL status is embedded in the mailbox subheader. */
  11764. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11765. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11766. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11767. if ((shdr_status || shdr_add_status) &&
  11768. (shdr_status != STATUS_FCF_IN_USE))
  11769. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11770. "2558 ADD_FCF_RECORD mailbox failed with "
  11771. "status x%x add_status x%x\n",
  11772. shdr_status, shdr_add_status);
  11773. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11774. }
  11775. /**
  11776. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11777. * @phba: pointer to lpfc hba data structure.
  11778. * @fcf_record: pointer to the initialized fcf record to add.
  11779. *
  11780. * This routine is invoked to manually add a single FCF record. The caller
  11781. * must pass a completely initialized FCF_Record. This routine takes
  11782. * care of the nonembedded mailbox operations.
  11783. **/
  11784. int
  11785. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11786. {
  11787. int rc = 0;
  11788. LPFC_MBOXQ_t *mboxq;
  11789. uint8_t *bytep;
  11790. void *virt_addr;
  11791. dma_addr_t phys_addr;
  11792. struct lpfc_mbx_sge sge;
  11793. uint32_t alloc_len, req_len;
  11794. uint32_t fcfindex;
  11795. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11796. if (!mboxq) {
  11797. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11798. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11799. return -ENOMEM;
  11800. }
  11801. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11802. sizeof(uint32_t);
  11803. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11804. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11805. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11806. req_len, LPFC_SLI4_MBX_NEMBED);
  11807. if (alloc_len < req_len) {
  11808. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11809. "2523 Allocated DMA memory size (x%x) is "
  11810. "less than the requested DMA memory "
  11811. "size (x%x)\n", alloc_len, req_len);
  11812. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11813. return -ENOMEM;
  11814. }
  11815. /*
  11816. * Get the first SGE entry from the non-embedded DMA memory. This
  11817. * routine only uses a single SGE.
  11818. */
  11819. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11820. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11821. virt_addr = mboxq->sge_array->addr[0];
  11822. /*
  11823. * Configure the FCF record for FCFI 0. This is the driver's
  11824. * hardcoded default and gets used in nonFIP mode.
  11825. */
  11826. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11827. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11828. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11829. /*
  11830. * Copy the fcf_index and the FCF Record Data. The data starts after
  11831. * the FCoE header plus word10. The data copy needs to be endian
  11832. * correct.
  11833. */
  11834. bytep += sizeof(uint32_t);
  11835. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11836. mboxq->vport = phba->pport;
  11837. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11838. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11839. if (rc == MBX_NOT_FINISHED) {
  11840. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11841. "2515 ADD_FCF_RECORD mailbox failed with "
  11842. "status 0x%x\n", rc);
  11843. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11844. rc = -EIO;
  11845. } else
  11846. rc = 0;
  11847. return rc;
  11848. }
  11849. /**
  11850. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11851. * @phba: pointer to lpfc hba data structure.
  11852. * @fcf_record: pointer to the fcf record to write the default data.
  11853. * @fcf_index: FCF table entry index.
  11854. *
  11855. * This routine is invoked to build the driver's default FCF record. The
  11856. * values used are hardcoded. This routine handles memory initialization.
  11857. *
  11858. **/
  11859. void
  11860. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11861. struct fcf_record *fcf_record,
  11862. uint16_t fcf_index)
  11863. {
  11864. memset(fcf_record, 0, sizeof(struct fcf_record));
  11865. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11866. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11867. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11868. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11869. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11870. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11871. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11872. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11873. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11874. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11875. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11876. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11877. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11878. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11879. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11880. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11881. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11882. /* Set the VLAN bit map */
  11883. if (phba->valid_vlan) {
  11884. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11885. = 1 << (phba->vlan_id % 8);
  11886. }
  11887. }
  11888. /**
  11889. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11890. * @phba: pointer to lpfc hba data structure.
  11891. * @fcf_index: FCF table entry offset.
  11892. *
  11893. * This routine is invoked to scan the entire FCF table by reading FCF
  11894. * record and processing it one at a time starting from the @fcf_index
  11895. * for initial FCF discovery or fast FCF failover rediscovery.
  11896. *
  11897. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11898. * otherwise.
  11899. **/
  11900. int
  11901. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11902. {
  11903. int rc = 0, error;
  11904. LPFC_MBOXQ_t *mboxq;
  11905. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11906. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11907. if (!mboxq) {
  11908. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11909. "2000 Failed to allocate mbox for "
  11910. "READ_FCF cmd\n");
  11911. error = -ENOMEM;
  11912. goto fail_fcf_scan;
  11913. }
  11914. /* Construct the read FCF record mailbox command */
  11915. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11916. if (rc) {
  11917. error = -EINVAL;
  11918. goto fail_fcf_scan;
  11919. }
  11920. /* Issue the mailbox command asynchronously */
  11921. mboxq->vport = phba->pport;
  11922. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11923. spin_lock_irq(&phba->hbalock);
  11924. phba->hba_flag |= FCF_TS_INPROG;
  11925. spin_unlock_irq(&phba->hbalock);
  11926. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11927. if (rc == MBX_NOT_FINISHED)
  11928. error = -EIO;
  11929. else {
  11930. /* Reset eligible FCF count for new scan */
  11931. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11932. phba->fcf.eligible_fcf_cnt = 0;
  11933. error = 0;
  11934. }
  11935. fail_fcf_scan:
  11936. if (error) {
  11937. if (mboxq)
  11938. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11939. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11940. spin_lock_irq(&phba->hbalock);
  11941. phba->hba_flag &= ~FCF_TS_INPROG;
  11942. spin_unlock_irq(&phba->hbalock);
  11943. }
  11944. return error;
  11945. }
  11946. /**
  11947. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11948. * @phba: pointer to lpfc hba data structure.
  11949. * @fcf_index: FCF table entry offset.
  11950. *
  11951. * This routine is invoked to read an FCF record indicated by @fcf_index
  11952. * and to use it for FLOGI roundrobin FCF failover.
  11953. *
  11954. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11955. * otherwise.
  11956. **/
  11957. int
  11958. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11959. {
  11960. int rc = 0, error;
  11961. LPFC_MBOXQ_t *mboxq;
  11962. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11963. if (!mboxq) {
  11964. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11965. "2763 Failed to allocate mbox for "
  11966. "READ_FCF cmd\n");
  11967. error = -ENOMEM;
  11968. goto fail_fcf_read;
  11969. }
  11970. /* Construct the read FCF record mailbox command */
  11971. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11972. if (rc) {
  11973. error = -EINVAL;
  11974. goto fail_fcf_read;
  11975. }
  11976. /* Issue the mailbox command asynchronously */
  11977. mboxq->vport = phba->pport;
  11978. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11979. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11980. if (rc == MBX_NOT_FINISHED)
  11981. error = -EIO;
  11982. else
  11983. error = 0;
  11984. fail_fcf_read:
  11985. if (error && mboxq)
  11986. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11987. return error;
  11988. }
  11989. /**
  11990. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11991. * @phba: pointer to lpfc hba data structure.
  11992. * @fcf_index: FCF table entry offset.
  11993. *
  11994. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11995. * determine whether it's eligible for FLOGI roundrobin failover list.
  11996. *
  11997. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11998. * otherwise.
  11999. **/
  12000. int
  12001. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  12002. {
  12003. int rc = 0, error;
  12004. LPFC_MBOXQ_t *mboxq;
  12005. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12006. if (!mboxq) {
  12007. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  12008. "2758 Failed to allocate mbox for "
  12009. "READ_FCF cmd\n");
  12010. error = -ENOMEM;
  12011. goto fail_fcf_read;
  12012. }
  12013. /* Construct the read FCF record mailbox command */
  12014. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  12015. if (rc) {
  12016. error = -EINVAL;
  12017. goto fail_fcf_read;
  12018. }
  12019. /* Issue the mailbox command asynchronously */
  12020. mboxq->vport = phba->pport;
  12021. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  12022. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  12023. if (rc == MBX_NOT_FINISHED)
  12024. error = -EIO;
  12025. else
  12026. error = 0;
  12027. fail_fcf_read:
  12028. if (error && mboxq)
  12029. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  12030. return error;
  12031. }
  12032. /**
  12033. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  12034. * @phba: pointer to lpfc hba data structure.
  12035. *
  12036. * This routine is to get the next eligible FCF record index in a round
  12037. * robin fashion. If the next eligible FCF record index equals to the
  12038. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  12039. * shall be returned, otherwise, the next eligible FCF record's index
  12040. * shall be returned.
  12041. **/
  12042. uint16_t
  12043. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  12044. {
  12045. uint16_t next_fcf_index;
  12046. /* Search start from next bit of currently registered FCF index */
  12047. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  12048. LPFC_SLI4_FCF_TBL_INDX_MAX;
  12049. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  12050. LPFC_SLI4_FCF_TBL_INDX_MAX,
  12051. next_fcf_index);
  12052. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  12053. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  12054. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  12055. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  12056. /* Check roundrobin failover list empty condition */
  12057. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12058. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  12059. "2844 No roundrobin failover FCF available\n");
  12060. return LPFC_FCOE_FCF_NEXT_NONE;
  12061. }
  12062. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12063. "2845 Get next roundrobin failover FCF (x%x)\n",
  12064. next_fcf_index);
  12065. return next_fcf_index;
  12066. }
  12067. /**
  12068. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  12069. * @phba: pointer to lpfc hba data structure.
  12070. *
  12071. * This routine sets the FCF record index in to the eligible bmask for
  12072. * roundrobin failover search. It checks to make sure that the index
  12073. * does not go beyond the range of the driver allocated bmask dimension
  12074. * before setting the bit.
  12075. *
  12076. * Returns 0 if the index bit successfully set, otherwise, it returns
  12077. * -EINVAL.
  12078. **/
  12079. int
  12080. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  12081. {
  12082. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12083. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12084. "2610 FCF (x%x) reached driver's book "
  12085. "keeping dimension:x%x\n",
  12086. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  12087. return -EINVAL;
  12088. }
  12089. /* Set the eligible FCF record index bmask */
  12090. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  12091. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12092. "2790 Set FCF (x%x) to roundrobin FCF failover "
  12093. "bmask\n", fcf_index);
  12094. return 0;
  12095. }
  12096. /**
  12097. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  12098. * @phba: pointer to lpfc hba data structure.
  12099. *
  12100. * This routine clears the FCF record index from the eligible bmask for
  12101. * roundrobin failover search. It checks to make sure that the index
  12102. * does not go beyond the range of the driver allocated bmask dimension
  12103. * before clearing the bit.
  12104. **/
  12105. void
  12106. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  12107. {
  12108. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12109. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12110. "2762 FCF (x%x) reached driver's book "
  12111. "keeping dimension:x%x\n",
  12112. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  12113. return;
  12114. }
  12115. /* Clear the eligible FCF record index bmask */
  12116. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  12117. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12118. "2791 Clear FCF (x%x) from roundrobin failover "
  12119. "bmask\n", fcf_index);
  12120. }
  12121. /**
  12122. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  12123. * @phba: pointer to lpfc hba data structure.
  12124. *
  12125. * This routine is the completion routine for the rediscover FCF table mailbox
  12126. * command. If the mailbox command returned failure, it will try to stop the
  12127. * FCF rediscover wait timer.
  12128. **/
  12129. void
  12130. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  12131. {
  12132. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  12133. uint32_t shdr_status, shdr_add_status;
  12134. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12135. shdr_status = bf_get(lpfc_mbox_hdr_status,
  12136. &redisc_fcf->header.cfg_shdr.response);
  12137. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12138. &redisc_fcf->header.cfg_shdr.response);
  12139. if (shdr_status || shdr_add_status) {
  12140. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12141. "2746 Requesting for FCF rediscovery failed "
  12142. "status x%x add_status x%x\n",
  12143. shdr_status, shdr_add_status);
  12144. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  12145. spin_lock_irq(&phba->hbalock);
  12146. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  12147. spin_unlock_irq(&phba->hbalock);
  12148. /*
  12149. * CVL event triggered FCF rediscover request failed,
  12150. * last resort to re-try current registered FCF entry.
  12151. */
  12152. lpfc_retry_pport_discovery(phba);
  12153. } else {
  12154. spin_lock_irq(&phba->hbalock);
  12155. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  12156. spin_unlock_irq(&phba->hbalock);
  12157. /*
  12158. * DEAD FCF event triggered FCF rediscover request
  12159. * failed, last resort to fail over as a link down
  12160. * to FCF registration.
  12161. */
  12162. lpfc_sli4_fcf_dead_failthrough(phba);
  12163. }
  12164. } else {
  12165. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12166. "2775 Start FCF rediscover quiescent timer\n");
  12167. /*
  12168. * Start FCF rediscovery wait timer for pending FCF
  12169. * before rescan FCF record table.
  12170. */
  12171. lpfc_fcf_redisc_wait_start_timer(phba);
  12172. }
  12173. mempool_free(mbox, phba->mbox_mem_pool);
  12174. }
  12175. /**
  12176. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  12177. * @phba: pointer to lpfc hba data structure.
  12178. *
  12179. * This routine is invoked to request for rediscovery of the entire FCF table
  12180. * by the port.
  12181. **/
  12182. int
  12183. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  12184. {
  12185. LPFC_MBOXQ_t *mbox;
  12186. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  12187. int rc, length;
  12188. /* Cancel retry delay timers to all vports before FCF rediscover */
  12189. lpfc_cancel_all_vport_retry_delay_timer(phba);
  12190. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12191. if (!mbox) {
  12192. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12193. "2745 Failed to allocate mbox for "
  12194. "requesting FCF rediscover.\n");
  12195. return -ENOMEM;
  12196. }
  12197. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  12198. sizeof(struct lpfc_sli4_cfg_mhdr));
  12199. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12200. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  12201. length, LPFC_SLI4_MBX_EMBED);
  12202. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12203. /* Set count to 0 for invalidating the entire FCF database */
  12204. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  12205. /* Issue the mailbox command asynchronously */
  12206. mbox->vport = phba->pport;
  12207. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  12208. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  12209. if (rc == MBX_NOT_FINISHED) {
  12210. mempool_free(mbox, phba->mbox_mem_pool);
  12211. return -EIO;
  12212. }
  12213. return 0;
  12214. }
  12215. /**
  12216. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  12217. * @phba: pointer to lpfc hba data structure.
  12218. *
  12219. * This function is the failover routine as a last resort to the FCF DEAD
  12220. * event when driver failed to perform fast FCF failover.
  12221. **/
  12222. void
  12223. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  12224. {
  12225. uint32_t link_state;
  12226. /*
  12227. * Last resort as FCF DEAD event failover will treat this as
  12228. * a link down, but save the link state because we don't want
  12229. * it to be changed to Link Down unless it is already down.
  12230. */
  12231. link_state = phba->link_state;
  12232. lpfc_linkdown(phba);
  12233. phba->link_state = link_state;
  12234. /* Unregister FCF if no devices connected to it */
  12235. lpfc_unregister_unused_fcf(phba);
  12236. }
  12237. /**
  12238. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12239. * @phba: pointer to lpfc hba data structure.
  12240. *
  12241. * This function read region 23 and parse TLV for port status to
  12242. * decide if the user disaled the port. If the TLV indicates the
  12243. * port is disabled, the hba_flag is set accordingly.
  12244. **/
  12245. void
  12246. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12247. {
  12248. LPFC_MBOXQ_t *pmb = NULL;
  12249. MAILBOX_t *mb;
  12250. uint8_t *rgn23_data = NULL;
  12251. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12252. int rc;
  12253. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12254. if (!pmb) {
  12255. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12256. "2600 lpfc_sli_read_serdes_param failed to"
  12257. " allocate mailbox memory\n");
  12258. goto out;
  12259. }
  12260. mb = &pmb->u.mb;
  12261. /* Get adapter Region 23 data */
  12262. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12263. if (!rgn23_data)
  12264. goto out;
  12265. do {
  12266. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12267. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12268. if (rc != MBX_SUCCESS) {
  12269. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12270. "2601 lpfc_sli_read_link_ste failed to"
  12271. " read config region 23 rc 0x%x Status 0x%x\n",
  12272. rc, mb->mbxStatus);
  12273. mb->un.varDmp.word_cnt = 0;
  12274. }
  12275. /*
  12276. * dump mem may return a zero when finished or we got a
  12277. * mailbox error, either way we are done.
  12278. */
  12279. if (mb->un.varDmp.word_cnt == 0)
  12280. break;
  12281. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12282. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12283. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12284. rgn23_data + offset,
  12285. mb->un.varDmp.word_cnt);
  12286. offset += mb->un.varDmp.word_cnt;
  12287. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12288. data_size = offset;
  12289. offset = 0;
  12290. if (!data_size)
  12291. goto out;
  12292. /* Check the region signature first */
  12293. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12294. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12295. "2619 Config region 23 has bad signature\n");
  12296. goto out;
  12297. }
  12298. offset += 4;
  12299. /* Check the data structure version */
  12300. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12301. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12302. "2620 Config region 23 has bad version\n");
  12303. goto out;
  12304. }
  12305. offset += 4;
  12306. /* Parse TLV entries in the region */
  12307. while (offset < data_size) {
  12308. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12309. break;
  12310. /*
  12311. * If the TLV is not driver specific TLV or driver id is
  12312. * not linux driver id, skip the record.
  12313. */
  12314. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12315. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12316. (rgn23_data[offset + 3] != 0)) {
  12317. offset += rgn23_data[offset + 1] * 4 + 4;
  12318. continue;
  12319. }
  12320. /* Driver found a driver specific TLV in the config region */
  12321. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12322. offset += 4;
  12323. tlv_offset = 0;
  12324. /*
  12325. * Search for configured port state sub-TLV.
  12326. */
  12327. while ((offset < data_size) &&
  12328. (tlv_offset < sub_tlv_len)) {
  12329. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12330. offset += 4;
  12331. tlv_offset += 4;
  12332. break;
  12333. }
  12334. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12335. offset += rgn23_data[offset + 1] * 4 + 4;
  12336. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12337. continue;
  12338. }
  12339. /* This HBA contains PORT_STE configured */
  12340. if (!rgn23_data[offset + 2])
  12341. phba->hba_flag |= LINK_DISABLED;
  12342. goto out;
  12343. }
  12344. }
  12345. out:
  12346. if (pmb)
  12347. mempool_free(pmb, phba->mbox_mem_pool);
  12348. kfree(rgn23_data);
  12349. return;
  12350. }
  12351. /**
  12352. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12353. * @vport: pointer to vport data structure.
  12354. *
  12355. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12356. * and REG_VPI mailbox commands associated with the vport. This function
  12357. * is called when driver want to restart discovery of the vport due to
  12358. * a Clear Virtual Link event.
  12359. **/
  12360. void
  12361. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12362. {
  12363. struct lpfc_hba *phba = vport->phba;
  12364. LPFC_MBOXQ_t *mb, *nextmb;
  12365. struct lpfc_dmabuf *mp;
  12366. struct lpfc_nodelist *ndlp;
  12367. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12368. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12369. LIST_HEAD(mbox_cmd_list);
  12370. uint8_t restart_loop;
  12371. /* Clean up internally queued mailbox commands with the vport */
  12372. spin_lock_irq(&phba->hbalock);
  12373. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12374. if (mb->vport != vport)
  12375. continue;
  12376. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12377. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12378. continue;
  12379. list_del(&mb->list);
  12380. list_add_tail(&mb->list, &mbox_cmd_list);
  12381. }
  12382. /* Clean up active mailbox command with the vport */
  12383. mb = phba->sli.mbox_active;
  12384. if (mb && (mb->vport == vport)) {
  12385. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12386. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12387. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12388. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12389. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12390. /* Put reference count for delayed processing */
  12391. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12392. /* Unregister the RPI when mailbox complete */
  12393. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12394. }
  12395. }
  12396. /* Cleanup any mailbox completions which are not yet processed */
  12397. do {
  12398. restart_loop = 0;
  12399. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12400. /*
  12401. * If this mailox is already processed or it is
  12402. * for another vport ignore it.
  12403. */
  12404. if ((mb->vport != vport) ||
  12405. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12406. continue;
  12407. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12408. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12409. continue;
  12410. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12411. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12412. ndlp = (struct lpfc_nodelist *)mb->context2;
  12413. /* Unregister the RPI when mailbox complete */
  12414. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12415. restart_loop = 1;
  12416. spin_unlock_irq(&phba->hbalock);
  12417. spin_lock(shost->host_lock);
  12418. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12419. spin_unlock(shost->host_lock);
  12420. spin_lock_irq(&phba->hbalock);
  12421. break;
  12422. }
  12423. }
  12424. } while (restart_loop);
  12425. spin_unlock_irq(&phba->hbalock);
  12426. /* Release the cleaned-up mailbox commands */
  12427. while (!list_empty(&mbox_cmd_list)) {
  12428. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12429. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12430. mp = (struct lpfc_dmabuf *) (mb->context1);
  12431. if (mp) {
  12432. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12433. kfree(mp);
  12434. }
  12435. ndlp = (struct lpfc_nodelist *) mb->context2;
  12436. mb->context2 = NULL;
  12437. if (ndlp) {
  12438. spin_lock(shost->host_lock);
  12439. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12440. spin_unlock(shost->host_lock);
  12441. lpfc_nlp_put(ndlp);
  12442. }
  12443. }
  12444. mempool_free(mb, phba->mbox_mem_pool);
  12445. }
  12446. /* Release the ndlp with the cleaned-up active mailbox command */
  12447. if (act_mbx_ndlp) {
  12448. spin_lock(shost->host_lock);
  12449. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12450. spin_unlock(shost->host_lock);
  12451. lpfc_nlp_put(act_mbx_ndlp);
  12452. }
  12453. }
  12454. /**
  12455. * lpfc_drain_txq - Drain the txq
  12456. * @phba: Pointer to HBA context object.
  12457. *
  12458. * This function attempt to submit IOCBs on the txq
  12459. * to the adapter. For SLI4 adapters, the txq contains
  12460. * ELS IOCBs that have been deferred because the there
  12461. * are no SGLs. This congestion can occur with large
  12462. * vport counts during node discovery.
  12463. **/
  12464. uint32_t
  12465. lpfc_drain_txq(struct lpfc_hba *phba)
  12466. {
  12467. LIST_HEAD(completions);
  12468. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12469. struct lpfc_iocbq *piocbq = 0;
  12470. unsigned long iflags = 0;
  12471. char *fail_msg = NULL;
  12472. struct lpfc_sglq *sglq;
  12473. union lpfc_wqe wqe;
  12474. spin_lock_irqsave(&phba->hbalock, iflags);
  12475. if (pring->txq_cnt > pring->txq_max)
  12476. pring->txq_max = pring->txq_cnt;
  12477. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12478. while (pring->txq_cnt) {
  12479. spin_lock_irqsave(&phba->hbalock, iflags);
  12480. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12481. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12482. if (!sglq) {
  12483. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12484. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12485. break;
  12486. } else {
  12487. if (!piocbq) {
  12488. /* The txq_cnt out of sync. This should
  12489. * never happen
  12490. */
  12491. sglq = __lpfc_clear_active_sglq(phba,
  12492. sglq->sli4_xritag);
  12493. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12494. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12495. "2823 txq empty and txq_cnt is %d\n ",
  12496. pring->txq_cnt);
  12497. break;
  12498. }
  12499. }
  12500. /* The xri and iocb resources secured,
  12501. * attempt to issue request
  12502. */
  12503. piocbq->sli4_xritag = sglq->sli4_xritag;
  12504. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12505. fail_msg = "to convert bpl to sgl";
  12506. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12507. fail_msg = "to convert iocb to wqe";
  12508. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12509. fail_msg = " - Wq is full";
  12510. else
  12511. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12512. if (fail_msg) {
  12513. /* Failed means we can't issue and need to cancel */
  12514. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12515. "2822 IOCB failed %s iotag 0x%x "
  12516. "xri 0x%x\n",
  12517. fail_msg,
  12518. piocbq->iotag, piocbq->sli4_xritag);
  12519. list_add_tail(&piocbq->list, &completions);
  12520. }
  12521. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12522. }
  12523. /* Cancel all the IOCBs that cannot be issued */
  12524. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12525. IOERR_SLI_ABORTED);
  12526. return pring->txq_cnt;
  12527. }