lpfc_sli.c 415 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  473. * @phba: Pointer to HBA context object.
  474. * @ndlp: nodelist pointer for this target.
  475. * @xritag: xri used in this exchange.
  476. * @rxid: Remote Exchange ID.
  477. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  478. *
  479. * This function is called with hbalock held.
  480. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  481. * rrq struct and adds it to the active_rrq_list.
  482. *
  483. * returns 0 for rrq slot for this xri
  484. * < 0 Were not able to get rrq mem or invalid parameter.
  485. **/
  486. static int
  487. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  488. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  489. {
  490. uint16_t adj_xri;
  491. struct lpfc_node_rrq *rrq;
  492. int empty;
  493. /*
  494. * set the active bit even if there is no mem available.
  495. */
  496. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  497. if (!ndlp)
  498. return -EINVAL;
  499. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  500. return -EINVAL;
  501. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  502. if (rrq) {
  503. rrq->send_rrq = send_rrq;
  504. rrq->xritag = xritag;
  505. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  506. rrq->ndlp = ndlp;
  507. rrq->nlp_DID = ndlp->nlp_DID;
  508. rrq->vport = ndlp->vport;
  509. rrq->rxid = rxid;
  510. empty = list_empty(&phba->active_rrq_list);
  511. if (phba->cfg_enable_rrq && send_rrq)
  512. /*
  513. * We need the xri before we can add this to the
  514. * phba active rrq list.
  515. */
  516. rrq->send_rrq = send_rrq;
  517. else
  518. rrq->send_rrq = 0;
  519. list_add_tail(&rrq->list, &phba->active_rrq_list);
  520. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  521. phba->hba_flag |= HBA_RRQ_ACTIVE;
  522. if (empty)
  523. lpfc_worker_wake_up(phba);
  524. }
  525. return 0;
  526. }
  527. return -ENOMEM;
  528. }
  529. /**
  530. * __lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  531. * @phba: Pointer to HBA context object.
  532. * @xritag: xri used in this exchange.
  533. * @rrq: The RRQ to be cleared.
  534. *
  535. * This function is called with hbalock held. This function
  536. **/
  537. static void
  538. __lpfc_clr_rrq_active(struct lpfc_hba *phba,
  539. uint16_t xritag,
  540. struct lpfc_node_rrq *rrq)
  541. {
  542. uint16_t adj_xri;
  543. struct lpfc_nodelist *ndlp;
  544. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  545. /* The target DID could have been swapped (cable swap)
  546. * we should use the ndlp from the findnode if it is
  547. * available.
  548. */
  549. if (!ndlp)
  550. ndlp = rrq->ndlp;
  551. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  552. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  553. rrq->send_rrq = 0;
  554. rrq->xritag = 0;
  555. rrq->rrq_stop_time = 0;
  556. }
  557. mempool_free(rrq, phba->rrq_pool);
  558. }
  559. /**
  560. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  561. * @phba: Pointer to HBA context object.
  562. *
  563. * This function is called with hbalock held. This function
  564. * Checks if stop_time (ratov from setting rrq active) has
  565. * been reached, if it has and the send_rrq flag is set then
  566. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  567. * then it will just call the routine to clear the rrq and
  568. * free the rrq resource.
  569. * The timer is set to the next rrq that is going to expire before
  570. * leaving the routine.
  571. *
  572. **/
  573. void
  574. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  575. {
  576. struct lpfc_node_rrq *rrq;
  577. struct lpfc_node_rrq *nextrrq;
  578. unsigned long next_time;
  579. unsigned long iflags;
  580. spin_lock_irqsave(&phba->hbalock, iflags);
  581. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  582. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  583. list_for_each_entry_safe(rrq, nextrrq,
  584. &phba->active_rrq_list, list) {
  585. if (time_after(jiffies, rrq->rrq_stop_time)) {
  586. list_del(&rrq->list);
  587. if (!rrq->send_rrq)
  588. /* this call will free the rrq */
  589. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  590. else {
  591. /* if we send the rrq then the completion handler
  592. * will clear the bit in the xribitmap.
  593. */
  594. spin_unlock_irqrestore(&phba->hbalock, iflags);
  595. if (lpfc_send_rrq(phba, rrq)) {
  596. lpfc_clr_rrq_active(phba, rrq->xritag,
  597. rrq);
  598. }
  599. spin_lock_irqsave(&phba->hbalock, iflags);
  600. }
  601. } else if (time_before(rrq->rrq_stop_time, next_time))
  602. next_time = rrq->rrq_stop_time;
  603. }
  604. spin_unlock_irqrestore(&phba->hbalock, iflags);
  605. if (!list_empty(&phba->active_rrq_list))
  606. mod_timer(&phba->rrq_tmr, next_time);
  607. }
  608. /**
  609. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  610. * @vport: Pointer to vport context object.
  611. * @xri: The xri used in the exchange.
  612. * @did: The targets DID for this exchange.
  613. *
  614. * returns NULL = rrq not found in the phba->active_rrq_list.
  615. * rrq = rrq for this xri and target.
  616. **/
  617. struct lpfc_node_rrq *
  618. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  619. {
  620. struct lpfc_hba *phba = vport->phba;
  621. struct lpfc_node_rrq *rrq;
  622. struct lpfc_node_rrq *nextrrq;
  623. unsigned long iflags;
  624. if (phba->sli_rev != LPFC_SLI_REV4)
  625. return NULL;
  626. spin_lock_irqsave(&phba->hbalock, iflags);
  627. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  628. if (rrq->vport == vport && rrq->xritag == xri &&
  629. rrq->nlp_DID == did){
  630. list_del(&rrq->list);
  631. spin_unlock_irqrestore(&phba->hbalock, iflags);
  632. return rrq;
  633. }
  634. }
  635. spin_unlock_irqrestore(&phba->hbalock, iflags);
  636. return NULL;
  637. }
  638. /**
  639. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  640. * @vport: Pointer to vport context object.
  641. *
  642. * Remove all active RRQs for this vport from the phba->active_rrq_list and
  643. * clear the rrq.
  644. **/
  645. void
  646. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport)
  647. {
  648. struct lpfc_hba *phba = vport->phba;
  649. struct lpfc_node_rrq *rrq;
  650. struct lpfc_node_rrq *nextrrq;
  651. unsigned long iflags;
  652. if (phba->sli_rev != LPFC_SLI_REV4)
  653. return;
  654. spin_lock_irqsave(&phba->hbalock, iflags);
  655. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  656. if (rrq->vport == vport) {
  657. list_del(&rrq->list);
  658. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  659. }
  660. }
  661. spin_unlock_irqrestore(&phba->hbalock, iflags);
  662. }
  663. /**
  664. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  665. * @phba: Pointer to HBA context object.
  666. *
  667. * Remove all rrqs from the phba->active_rrq_list and free them by
  668. * calling __lpfc_clr_active_rrq
  669. *
  670. **/
  671. void
  672. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  673. {
  674. struct lpfc_node_rrq *rrq;
  675. struct lpfc_node_rrq *nextrrq;
  676. unsigned long next_time;
  677. unsigned long iflags;
  678. if (phba->sli_rev != LPFC_SLI_REV4)
  679. return;
  680. spin_lock_irqsave(&phba->hbalock, iflags);
  681. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  682. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  683. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  684. list_del(&rrq->list);
  685. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  686. }
  687. spin_unlock_irqrestore(&phba->hbalock, iflags);
  688. if (!list_empty(&phba->active_rrq_list))
  689. mod_timer(&phba->rrq_tmr, next_time);
  690. }
  691. /**
  692. * __lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  693. * @phba: Pointer to HBA context object.
  694. * @ndlp: Targets nodelist pointer for this exchange.
  695. * @xritag the xri in the bitmap to test.
  696. *
  697. * This function is called with hbalock held. This function
  698. * returns 0 = rrq not active for this xri
  699. * 1 = rrq is valid for this xri.
  700. **/
  701. static int
  702. __lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  703. uint16_t xritag)
  704. {
  705. uint16_t adj_xri;
  706. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  707. if (!ndlp)
  708. return 0;
  709. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  710. return 1;
  711. else
  712. return 0;
  713. }
  714. /**
  715. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  716. * @phba: Pointer to HBA context object.
  717. * @ndlp: nodelist pointer for this target.
  718. * @xritag: xri used in this exchange.
  719. * @rxid: Remote Exchange ID.
  720. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  721. *
  722. * This function takes the hbalock.
  723. * The active bit is always set in the active rrq xri_bitmap even
  724. * if there is no slot avaiable for the other rrq information.
  725. *
  726. * returns 0 rrq actived for this xri
  727. * < 0 No memory or invalid ndlp.
  728. **/
  729. int
  730. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  731. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  732. {
  733. int ret;
  734. unsigned long iflags;
  735. spin_lock_irqsave(&phba->hbalock, iflags);
  736. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  737. spin_unlock_irqrestore(&phba->hbalock, iflags);
  738. return ret;
  739. }
  740. /**
  741. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  742. * @phba: Pointer to HBA context object.
  743. * @xritag: xri used in this exchange.
  744. * @rrq: The RRQ to be cleared.
  745. *
  746. * This function is takes the hbalock.
  747. **/
  748. void
  749. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  750. uint16_t xritag,
  751. struct lpfc_node_rrq *rrq)
  752. {
  753. unsigned long iflags;
  754. spin_lock_irqsave(&phba->hbalock, iflags);
  755. __lpfc_clr_rrq_active(phba, xritag, rrq);
  756. spin_unlock_irqrestore(&phba->hbalock, iflags);
  757. return;
  758. }
  759. /**
  760. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  761. * @phba: Pointer to HBA context object.
  762. * @ndlp: Targets nodelist pointer for this exchange.
  763. * @xritag the xri in the bitmap to test.
  764. *
  765. * This function takes the hbalock.
  766. * returns 0 = rrq not active for this xri
  767. * 1 = rrq is valid for this xri.
  768. **/
  769. int
  770. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  771. uint16_t xritag)
  772. {
  773. int ret;
  774. unsigned long iflags;
  775. spin_lock_irqsave(&phba->hbalock, iflags);
  776. ret = __lpfc_test_rrq_active(phba, ndlp, xritag);
  777. spin_unlock_irqrestore(&phba->hbalock, iflags);
  778. return ret;
  779. }
  780. /**
  781. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  782. * @phba: Pointer to HBA context object.
  783. * @piocb: Pointer to the iocbq.
  784. *
  785. * This function is called with hbalock held. This function
  786. * Gets a new driver sglq object from the sglq list. If the
  787. * list is not empty then it is successful, it returns pointer to the newly
  788. * allocated sglq object else it returns NULL.
  789. **/
  790. static struct lpfc_sglq *
  791. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  792. {
  793. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  794. struct lpfc_sglq *sglq = NULL;
  795. struct lpfc_sglq *start_sglq = NULL;
  796. uint16_t adj_xri;
  797. struct lpfc_scsi_buf *lpfc_cmd;
  798. struct lpfc_nodelist *ndlp;
  799. int found = 0;
  800. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  801. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  802. ndlp = lpfc_cmd->rdata->pnode;
  803. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  804. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  805. ndlp = piocbq->context_un.ndlp;
  806. else
  807. ndlp = piocbq->context1;
  808. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  809. start_sglq = sglq;
  810. while (!found) {
  811. if (!sglq)
  812. return NULL;
  813. adj_xri = sglq->sli4_xritag -
  814. phba->sli4_hba.max_cfg_param.xri_base;
  815. if (__lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  816. /* This xri has an rrq outstanding for this DID.
  817. * put it back in the list and get another xri.
  818. */
  819. list_add_tail(&sglq->list, lpfc_sgl_list);
  820. sglq = NULL;
  821. list_remove_head(lpfc_sgl_list, sglq,
  822. struct lpfc_sglq, list);
  823. if (sglq == start_sglq) {
  824. sglq = NULL;
  825. break;
  826. } else
  827. continue;
  828. }
  829. sglq->ndlp = ndlp;
  830. found = 1;
  831. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  832. sglq->state = SGL_ALLOCATED;
  833. }
  834. return sglq;
  835. }
  836. /**
  837. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  838. * @phba: Pointer to HBA context object.
  839. *
  840. * This function is called with no lock held. This function
  841. * allocates a new driver iocb object from the iocb pool. If the
  842. * allocation is successful, it returns pointer to the newly
  843. * allocated iocb object else it returns NULL.
  844. **/
  845. struct lpfc_iocbq *
  846. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  847. {
  848. struct lpfc_iocbq * iocbq = NULL;
  849. unsigned long iflags;
  850. spin_lock_irqsave(&phba->hbalock, iflags);
  851. iocbq = __lpfc_sli_get_iocbq(phba);
  852. spin_unlock_irqrestore(&phba->hbalock, iflags);
  853. return iocbq;
  854. }
  855. /**
  856. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  857. * @phba: Pointer to HBA context object.
  858. * @iocbq: Pointer to driver iocb object.
  859. *
  860. * This function is called with hbalock held to release driver
  861. * iocb object to the iocb pool. The iotag in the iocb object
  862. * does not change for each use of the iocb object. This function
  863. * clears all other fields of the iocb object when it is freed.
  864. * The sqlq structure that holds the xritag and phys and virtual
  865. * mappings for the scatter gather list is retrieved from the
  866. * active array of sglq. The get of the sglq pointer also clears
  867. * the entry in the array. If the status of the IO indiactes that
  868. * this IO was aborted then the sglq entry it put on the
  869. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  870. * IO has good status or fails for any other reason then the sglq
  871. * entry is added to the free list (lpfc_sgl_list).
  872. **/
  873. static void
  874. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  875. {
  876. struct lpfc_sglq *sglq;
  877. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  878. unsigned long iflag = 0;
  879. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  880. if (iocbq->sli4_xritag == NO_XRI)
  881. sglq = NULL;
  882. else
  883. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  884. if (sglq) {
  885. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  886. (sglq->state != SGL_XRI_ABORTED)) {
  887. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  888. iflag);
  889. list_add(&sglq->list,
  890. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  891. spin_unlock_irqrestore(
  892. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  893. } else {
  894. sglq->state = SGL_FREED;
  895. sglq->ndlp = NULL;
  896. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  897. /* Check if TXQ queue needs to be serviced */
  898. if (pring->txq_cnt)
  899. lpfc_worker_wake_up(phba);
  900. }
  901. }
  902. /*
  903. * Clean all volatile data fields, preserve iotag and node struct.
  904. */
  905. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  906. iocbq->sli4_xritag = NO_XRI;
  907. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  908. }
  909. /**
  910. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  911. * @phba: Pointer to HBA context object.
  912. * @iocbq: Pointer to driver iocb object.
  913. *
  914. * This function is called with hbalock held to release driver
  915. * iocb object to the iocb pool. The iotag in the iocb object
  916. * does not change for each use of the iocb object. This function
  917. * clears all other fields of the iocb object when it is freed.
  918. **/
  919. static void
  920. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  921. {
  922. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  923. /*
  924. * Clean all volatile data fields, preserve iotag and node struct.
  925. */
  926. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  927. iocbq->sli4_xritag = NO_XRI;
  928. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  929. }
  930. /**
  931. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  932. * @phba: Pointer to HBA context object.
  933. * @iocbq: Pointer to driver iocb object.
  934. *
  935. * This function is called with hbalock held to release driver
  936. * iocb object to the iocb pool. The iotag in the iocb object
  937. * does not change for each use of the iocb object. This function
  938. * clears all other fields of the iocb object when it is freed.
  939. **/
  940. static void
  941. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  942. {
  943. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  944. phba->iocb_cnt--;
  945. }
  946. /**
  947. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  948. * @phba: Pointer to HBA context object.
  949. * @iocbq: Pointer to driver iocb object.
  950. *
  951. * This function is called with no lock held to release the iocb to
  952. * iocb pool.
  953. **/
  954. void
  955. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  956. {
  957. unsigned long iflags;
  958. /*
  959. * Clean all volatile data fields, preserve iotag and node struct.
  960. */
  961. spin_lock_irqsave(&phba->hbalock, iflags);
  962. __lpfc_sli_release_iocbq(phba, iocbq);
  963. spin_unlock_irqrestore(&phba->hbalock, iflags);
  964. }
  965. /**
  966. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  967. * @phba: Pointer to HBA context object.
  968. * @iocblist: List of IOCBs.
  969. * @ulpstatus: ULP status in IOCB command field.
  970. * @ulpWord4: ULP word-4 in IOCB command field.
  971. *
  972. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  973. * on the list by invoking the complete callback function associated with the
  974. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  975. * fields.
  976. **/
  977. void
  978. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  979. uint32_t ulpstatus, uint32_t ulpWord4)
  980. {
  981. struct lpfc_iocbq *piocb;
  982. while (!list_empty(iocblist)) {
  983. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  984. if (!piocb->iocb_cmpl)
  985. lpfc_sli_release_iocbq(phba, piocb);
  986. else {
  987. piocb->iocb.ulpStatus = ulpstatus;
  988. piocb->iocb.un.ulpWord[4] = ulpWord4;
  989. (piocb->iocb_cmpl) (phba, piocb, piocb);
  990. }
  991. }
  992. return;
  993. }
  994. /**
  995. * lpfc_sli_iocb_cmd_type - Get the iocb type
  996. * @iocb_cmnd: iocb command code.
  997. *
  998. * This function is called by ring event handler function to get the iocb type.
  999. * This function translates the iocb command to an iocb command type used to
  1000. * decide the final disposition of each completed IOCB.
  1001. * The function returns
  1002. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1003. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1004. * LPFC_ABORT_IOCB if it is an abort iocb
  1005. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1006. *
  1007. * The caller is not required to hold any lock.
  1008. **/
  1009. static lpfc_iocb_type
  1010. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1011. {
  1012. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1013. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1014. return 0;
  1015. switch (iocb_cmnd) {
  1016. case CMD_XMIT_SEQUENCE_CR:
  1017. case CMD_XMIT_SEQUENCE_CX:
  1018. case CMD_XMIT_BCAST_CN:
  1019. case CMD_XMIT_BCAST_CX:
  1020. case CMD_ELS_REQUEST_CR:
  1021. case CMD_ELS_REQUEST_CX:
  1022. case CMD_CREATE_XRI_CR:
  1023. case CMD_CREATE_XRI_CX:
  1024. case CMD_GET_RPI_CN:
  1025. case CMD_XMIT_ELS_RSP_CX:
  1026. case CMD_GET_RPI_CR:
  1027. case CMD_FCP_IWRITE_CR:
  1028. case CMD_FCP_IWRITE_CX:
  1029. case CMD_FCP_IREAD_CR:
  1030. case CMD_FCP_IREAD_CX:
  1031. case CMD_FCP_ICMND_CR:
  1032. case CMD_FCP_ICMND_CX:
  1033. case CMD_FCP_TSEND_CX:
  1034. case CMD_FCP_TRSP_CX:
  1035. case CMD_FCP_TRECEIVE_CX:
  1036. case CMD_FCP_AUTO_TRSP_CX:
  1037. case CMD_ADAPTER_MSG:
  1038. case CMD_ADAPTER_DUMP:
  1039. case CMD_XMIT_SEQUENCE64_CR:
  1040. case CMD_XMIT_SEQUENCE64_CX:
  1041. case CMD_XMIT_BCAST64_CN:
  1042. case CMD_XMIT_BCAST64_CX:
  1043. case CMD_ELS_REQUEST64_CR:
  1044. case CMD_ELS_REQUEST64_CX:
  1045. case CMD_FCP_IWRITE64_CR:
  1046. case CMD_FCP_IWRITE64_CX:
  1047. case CMD_FCP_IREAD64_CR:
  1048. case CMD_FCP_IREAD64_CX:
  1049. case CMD_FCP_ICMND64_CR:
  1050. case CMD_FCP_ICMND64_CX:
  1051. case CMD_FCP_TSEND64_CX:
  1052. case CMD_FCP_TRSP64_CX:
  1053. case CMD_FCP_TRECEIVE64_CX:
  1054. case CMD_GEN_REQUEST64_CR:
  1055. case CMD_GEN_REQUEST64_CX:
  1056. case CMD_XMIT_ELS_RSP64_CX:
  1057. case DSSCMD_IWRITE64_CR:
  1058. case DSSCMD_IWRITE64_CX:
  1059. case DSSCMD_IREAD64_CR:
  1060. case DSSCMD_IREAD64_CX:
  1061. type = LPFC_SOL_IOCB;
  1062. break;
  1063. case CMD_ABORT_XRI_CN:
  1064. case CMD_ABORT_XRI_CX:
  1065. case CMD_CLOSE_XRI_CN:
  1066. case CMD_CLOSE_XRI_CX:
  1067. case CMD_XRI_ABORTED_CX:
  1068. case CMD_ABORT_MXRI64_CN:
  1069. case CMD_XMIT_BLS_RSP64_CX:
  1070. type = LPFC_ABORT_IOCB;
  1071. break;
  1072. case CMD_RCV_SEQUENCE_CX:
  1073. case CMD_RCV_ELS_REQ_CX:
  1074. case CMD_RCV_SEQUENCE64_CX:
  1075. case CMD_RCV_ELS_REQ64_CX:
  1076. case CMD_ASYNC_STATUS:
  1077. case CMD_IOCB_RCV_SEQ64_CX:
  1078. case CMD_IOCB_RCV_ELS64_CX:
  1079. case CMD_IOCB_RCV_CONT64_CX:
  1080. case CMD_IOCB_RET_XRI64_CX:
  1081. type = LPFC_UNSOL_IOCB;
  1082. break;
  1083. case CMD_IOCB_XMIT_MSEQ64_CR:
  1084. case CMD_IOCB_XMIT_MSEQ64_CX:
  1085. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1086. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1087. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1088. case CMD_IOCB_ABORT_EXTENDED_CN:
  1089. case CMD_IOCB_RET_HBQE64_CN:
  1090. case CMD_IOCB_FCP_IBIDIR64_CR:
  1091. case CMD_IOCB_FCP_IBIDIR64_CX:
  1092. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1093. case CMD_IOCB_LOGENTRY_CN:
  1094. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1095. printk("%s - Unhandled SLI-3 Command x%x\n",
  1096. __func__, iocb_cmnd);
  1097. type = LPFC_UNKNOWN_IOCB;
  1098. break;
  1099. default:
  1100. type = LPFC_UNKNOWN_IOCB;
  1101. break;
  1102. }
  1103. return type;
  1104. }
  1105. /**
  1106. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1107. * @phba: Pointer to HBA context object.
  1108. *
  1109. * This function is called from SLI initialization code
  1110. * to configure every ring of the HBA's SLI interface. The
  1111. * caller is not required to hold any lock. This function issues
  1112. * a config_ring mailbox command for each ring.
  1113. * This function returns zero if successful else returns a negative
  1114. * error code.
  1115. **/
  1116. static int
  1117. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1118. {
  1119. struct lpfc_sli *psli = &phba->sli;
  1120. LPFC_MBOXQ_t *pmb;
  1121. MAILBOX_t *pmbox;
  1122. int i, rc, ret = 0;
  1123. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1124. if (!pmb)
  1125. return -ENOMEM;
  1126. pmbox = &pmb->u.mb;
  1127. phba->link_state = LPFC_INIT_MBX_CMDS;
  1128. for (i = 0; i < psli->num_rings; i++) {
  1129. lpfc_config_ring(phba, i, pmb);
  1130. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1131. if (rc != MBX_SUCCESS) {
  1132. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1133. "0446 Adapter failed to init (%d), "
  1134. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1135. "ring %d\n",
  1136. rc, pmbox->mbxCommand,
  1137. pmbox->mbxStatus, i);
  1138. phba->link_state = LPFC_HBA_ERROR;
  1139. ret = -ENXIO;
  1140. break;
  1141. }
  1142. }
  1143. mempool_free(pmb, phba->mbox_mem_pool);
  1144. return ret;
  1145. }
  1146. /**
  1147. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1148. * @phba: Pointer to HBA context object.
  1149. * @pring: Pointer to driver SLI ring object.
  1150. * @piocb: Pointer to the driver iocb object.
  1151. *
  1152. * This function is called with hbalock held. The function adds the
  1153. * new iocb to txcmplq of the given ring. This function always returns
  1154. * 0. If this function is called for ELS ring, this function checks if
  1155. * there is a vport associated with the ELS command. This function also
  1156. * starts els_tmofunc timer if this is an ELS command.
  1157. **/
  1158. static int
  1159. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1160. struct lpfc_iocbq *piocb)
  1161. {
  1162. list_add_tail(&piocb->list, &pring->txcmplq);
  1163. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1164. pring->txcmplq_cnt++;
  1165. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1166. pring->txcmplq_max = pring->txcmplq_cnt;
  1167. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1168. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1169. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1170. if (!piocb->vport)
  1171. BUG();
  1172. else
  1173. mod_timer(&piocb->vport->els_tmofunc,
  1174. jiffies + HZ * (phba->fc_ratov << 1));
  1175. }
  1176. return 0;
  1177. }
  1178. /**
  1179. * lpfc_sli_ringtx_get - Get first element of the txq
  1180. * @phba: Pointer to HBA context object.
  1181. * @pring: Pointer to driver SLI ring object.
  1182. *
  1183. * This function is called with hbalock held to get next
  1184. * iocb in txq of the given ring. If there is any iocb in
  1185. * the txq, the function returns first iocb in the list after
  1186. * removing the iocb from the list, else it returns NULL.
  1187. **/
  1188. struct lpfc_iocbq *
  1189. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1190. {
  1191. struct lpfc_iocbq *cmd_iocb;
  1192. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1193. if (cmd_iocb != NULL)
  1194. pring->txq_cnt--;
  1195. return cmd_iocb;
  1196. }
  1197. /**
  1198. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1199. * @phba: Pointer to HBA context object.
  1200. * @pring: Pointer to driver SLI ring object.
  1201. *
  1202. * This function is called with hbalock held and the caller must post the
  1203. * iocb without releasing the lock. If the caller releases the lock,
  1204. * iocb slot returned by the function is not guaranteed to be available.
  1205. * The function returns pointer to the next available iocb slot if there
  1206. * is available slot in the ring, else it returns NULL.
  1207. * If the get index of the ring is ahead of the put index, the function
  1208. * will post an error attention event to the worker thread to take the
  1209. * HBA to offline state.
  1210. **/
  1211. static IOCB_t *
  1212. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1213. {
  1214. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1215. uint32_t max_cmd_idx = pring->numCiocb;
  1216. if ((pring->next_cmdidx == pring->cmdidx) &&
  1217. (++pring->next_cmdidx >= max_cmd_idx))
  1218. pring->next_cmdidx = 0;
  1219. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1220. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1221. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1222. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1223. "0315 Ring %d issue: portCmdGet %d "
  1224. "is bigger than cmd ring %d\n",
  1225. pring->ringno,
  1226. pring->local_getidx, max_cmd_idx);
  1227. phba->link_state = LPFC_HBA_ERROR;
  1228. /*
  1229. * All error attention handlers are posted to
  1230. * worker thread
  1231. */
  1232. phba->work_ha |= HA_ERATT;
  1233. phba->work_hs = HS_FFER3;
  1234. lpfc_worker_wake_up(phba);
  1235. return NULL;
  1236. }
  1237. if (pring->local_getidx == pring->next_cmdidx)
  1238. return NULL;
  1239. }
  1240. return lpfc_cmd_iocb(phba, pring);
  1241. }
  1242. /**
  1243. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1244. * @phba: Pointer to HBA context object.
  1245. * @iocbq: Pointer to driver iocb object.
  1246. *
  1247. * This function gets an iotag for the iocb. If there is no unused iotag and
  1248. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1249. * array and assigns a new iotag.
  1250. * The function returns the allocated iotag if successful, else returns zero.
  1251. * Zero is not a valid iotag.
  1252. * The caller is not required to hold any lock.
  1253. **/
  1254. uint16_t
  1255. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1256. {
  1257. struct lpfc_iocbq **new_arr;
  1258. struct lpfc_iocbq **old_arr;
  1259. size_t new_len;
  1260. struct lpfc_sli *psli = &phba->sli;
  1261. uint16_t iotag;
  1262. spin_lock_irq(&phba->hbalock);
  1263. iotag = psli->last_iotag;
  1264. if(++iotag < psli->iocbq_lookup_len) {
  1265. psli->last_iotag = iotag;
  1266. psli->iocbq_lookup[iotag] = iocbq;
  1267. spin_unlock_irq(&phba->hbalock);
  1268. iocbq->iotag = iotag;
  1269. return iotag;
  1270. } else if (psli->iocbq_lookup_len < (0xffff
  1271. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1272. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1273. spin_unlock_irq(&phba->hbalock);
  1274. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1275. GFP_KERNEL);
  1276. if (new_arr) {
  1277. spin_lock_irq(&phba->hbalock);
  1278. old_arr = psli->iocbq_lookup;
  1279. if (new_len <= psli->iocbq_lookup_len) {
  1280. /* highly unprobable case */
  1281. kfree(new_arr);
  1282. iotag = psli->last_iotag;
  1283. if(++iotag < psli->iocbq_lookup_len) {
  1284. psli->last_iotag = iotag;
  1285. psli->iocbq_lookup[iotag] = iocbq;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. iocbq->iotag = iotag;
  1288. return iotag;
  1289. }
  1290. spin_unlock_irq(&phba->hbalock);
  1291. return 0;
  1292. }
  1293. if (psli->iocbq_lookup)
  1294. memcpy(new_arr, old_arr,
  1295. ((psli->last_iotag + 1) *
  1296. sizeof (struct lpfc_iocbq *)));
  1297. psli->iocbq_lookup = new_arr;
  1298. psli->iocbq_lookup_len = new_len;
  1299. psli->last_iotag = iotag;
  1300. psli->iocbq_lookup[iotag] = iocbq;
  1301. spin_unlock_irq(&phba->hbalock);
  1302. iocbq->iotag = iotag;
  1303. kfree(old_arr);
  1304. return iotag;
  1305. }
  1306. } else
  1307. spin_unlock_irq(&phba->hbalock);
  1308. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1309. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1310. psli->last_iotag);
  1311. return 0;
  1312. }
  1313. /**
  1314. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1315. * @phba: Pointer to HBA context object.
  1316. * @pring: Pointer to driver SLI ring object.
  1317. * @iocb: Pointer to iocb slot in the ring.
  1318. * @nextiocb: Pointer to driver iocb object which need to be
  1319. * posted to firmware.
  1320. *
  1321. * This function is called with hbalock held to post a new iocb to
  1322. * the firmware. This function copies the new iocb to ring iocb slot and
  1323. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1324. * a completion call back for this iocb else the function will free the
  1325. * iocb object.
  1326. **/
  1327. static void
  1328. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1329. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1330. {
  1331. /*
  1332. * Set up an iotag
  1333. */
  1334. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1335. if (pring->ringno == LPFC_ELS_RING) {
  1336. lpfc_debugfs_slow_ring_trc(phba,
  1337. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1338. *(((uint32_t *) &nextiocb->iocb) + 4),
  1339. *(((uint32_t *) &nextiocb->iocb) + 6),
  1340. *(((uint32_t *) &nextiocb->iocb) + 7));
  1341. }
  1342. /*
  1343. * Issue iocb command to adapter
  1344. */
  1345. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1346. wmb();
  1347. pring->stats.iocb_cmd++;
  1348. /*
  1349. * If there is no completion routine to call, we can release the
  1350. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1351. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1352. */
  1353. if (nextiocb->iocb_cmpl)
  1354. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1355. else
  1356. __lpfc_sli_release_iocbq(phba, nextiocb);
  1357. /*
  1358. * Let the HBA know what IOCB slot will be the next one the
  1359. * driver will put a command into.
  1360. */
  1361. pring->cmdidx = pring->next_cmdidx;
  1362. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1363. }
  1364. /**
  1365. * lpfc_sli_update_full_ring - Update the chip attention register
  1366. * @phba: Pointer to HBA context object.
  1367. * @pring: Pointer to driver SLI ring object.
  1368. *
  1369. * The caller is not required to hold any lock for calling this function.
  1370. * This function updates the chip attention bits for the ring to inform firmware
  1371. * that there are pending work to be done for this ring and requests an
  1372. * interrupt when there is space available in the ring. This function is
  1373. * called when the driver is unable to post more iocbs to the ring due
  1374. * to unavailability of space in the ring.
  1375. **/
  1376. static void
  1377. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1378. {
  1379. int ringno = pring->ringno;
  1380. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1381. wmb();
  1382. /*
  1383. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1384. * The HBA will tell us when an IOCB entry is available.
  1385. */
  1386. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1387. readl(phba->CAregaddr); /* flush */
  1388. pring->stats.iocb_cmd_full++;
  1389. }
  1390. /**
  1391. * lpfc_sli_update_ring - Update chip attention register
  1392. * @phba: Pointer to HBA context object.
  1393. * @pring: Pointer to driver SLI ring object.
  1394. *
  1395. * This function updates the chip attention register bit for the
  1396. * given ring to inform HBA that there is more work to be done
  1397. * in this ring. The caller is not required to hold any lock.
  1398. **/
  1399. static void
  1400. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1401. {
  1402. int ringno = pring->ringno;
  1403. /*
  1404. * Tell the HBA that there is work to do in this ring.
  1405. */
  1406. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1407. wmb();
  1408. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1409. readl(phba->CAregaddr); /* flush */
  1410. }
  1411. }
  1412. /**
  1413. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1414. * @phba: Pointer to HBA context object.
  1415. * @pring: Pointer to driver SLI ring object.
  1416. *
  1417. * This function is called with hbalock held to post pending iocbs
  1418. * in the txq to the firmware. This function is called when driver
  1419. * detects space available in the ring.
  1420. **/
  1421. static void
  1422. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1423. {
  1424. IOCB_t *iocb;
  1425. struct lpfc_iocbq *nextiocb;
  1426. /*
  1427. * Check to see if:
  1428. * (a) there is anything on the txq to send
  1429. * (b) link is up
  1430. * (c) link attention events can be processed (fcp ring only)
  1431. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1432. */
  1433. if (pring->txq_cnt &&
  1434. lpfc_is_link_up(phba) &&
  1435. (pring->ringno != phba->sli.fcp_ring ||
  1436. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1437. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1438. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1439. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1440. if (iocb)
  1441. lpfc_sli_update_ring(phba, pring);
  1442. else
  1443. lpfc_sli_update_full_ring(phba, pring);
  1444. }
  1445. return;
  1446. }
  1447. /**
  1448. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1449. * @phba: Pointer to HBA context object.
  1450. * @hbqno: HBQ number.
  1451. *
  1452. * This function is called with hbalock held to get the next
  1453. * available slot for the given HBQ. If there is free slot
  1454. * available for the HBQ it will return pointer to the next available
  1455. * HBQ entry else it will return NULL.
  1456. **/
  1457. static struct lpfc_hbq_entry *
  1458. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1459. {
  1460. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1461. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1462. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1463. hbqp->next_hbqPutIdx = 0;
  1464. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1465. uint32_t raw_index = phba->hbq_get[hbqno];
  1466. uint32_t getidx = le32_to_cpu(raw_index);
  1467. hbqp->local_hbqGetIdx = getidx;
  1468. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1469. lpfc_printf_log(phba, KERN_ERR,
  1470. LOG_SLI | LOG_VPORT,
  1471. "1802 HBQ %d: local_hbqGetIdx "
  1472. "%u is > than hbqp->entry_count %u\n",
  1473. hbqno, hbqp->local_hbqGetIdx,
  1474. hbqp->entry_count);
  1475. phba->link_state = LPFC_HBA_ERROR;
  1476. return NULL;
  1477. }
  1478. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1479. return NULL;
  1480. }
  1481. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1482. hbqp->hbqPutIdx;
  1483. }
  1484. /**
  1485. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1486. * @phba: Pointer to HBA context object.
  1487. *
  1488. * This function is called with no lock held to free all the
  1489. * hbq buffers while uninitializing the SLI interface. It also
  1490. * frees the HBQ buffers returned by the firmware but not yet
  1491. * processed by the upper layers.
  1492. **/
  1493. void
  1494. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1495. {
  1496. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1497. struct hbq_dmabuf *hbq_buf;
  1498. unsigned long flags;
  1499. int i, hbq_count;
  1500. uint32_t hbqno;
  1501. hbq_count = lpfc_sli_hbq_count();
  1502. /* Return all memory used by all HBQs */
  1503. spin_lock_irqsave(&phba->hbalock, flags);
  1504. for (i = 0; i < hbq_count; ++i) {
  1505. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1506. &phba->hbqs[i].hbq_buffer_list, list) {
  1507. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1508. list_del(&hbq_buf->dbuf.list);
  1509. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1510. }
  1511. phba->hbqs[i].buffer_count = 0;
  1512. }
  1513. /* Return all HBQ buffer that are in-fly */
  1514. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1515. list) {
  1516. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1517. list_del(&hbq_buf->dbuf.list);
  1518. if (hbq_buf->tag == -1) {
  1519. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1520. (phba, hbq_buf);
  1521. } else {
  1522. hbqno = hbq_buf->tag >> 16;
  1523. if (hbqno >= LPFC_MAX_HBQS)
  1524. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1525. (phba, hbq_buf);
  1526. else
  1527. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1528. hbq_buf);
  1529. }
  1530. }
  1531. /* Mark the HBQs not in use */
  1532. phba->hbq_in_use = 0;
  1533. spin_unlock_irqrestore(&phba->hbalock, flags);
  1534. }
  1535. /**
  1536. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1537. * @phba: Pointer to HBA context object.
  1538. * @hbqno: HBQ number.
  1539. * @hbq_buf: Pointer to HBQ buffer.
  1540. *
  1541. * This function is called with the hbalock held to post a
  1542. * hbq buffer to the firmware. If the function finds an empty
  1543. * slot in the HBQ, it will post the buffer. The function will return
  1544. * pointer to the hbq entry if it successfully post the buffer
  1545. * else it will return NULL.
  1546. **/
  1547. static int
  1548. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1549. struct hbq_dmabuf *hbq_buf)
  1550. {
  1551. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1552. }
  1553. /**
  1554. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1555. * @phba: Pointer to HBA context object.
  1556. * @hbqno: HBQ number.
  1557. * @hbq_buf: Pointer to HBQ buffer.
  1558. *
  1559. * This function is called with the hbalock held to post a hbq buffer to the
  1560. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1561. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1562. * it successfully post the buffer else it will return an error.
  1563. **/
  1564. static int
  1565. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1566. struct hbq_dmabuf *hbq_buf)
  1567. {
  1568. struct lpfc_hbq_entry *hbqe;
  1569. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1570. /* Get next HBQ entry slot to use */
  1571. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1572. if (hbqe) {
  1573. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1574. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1575. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1576. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1577. hbqe->bde.tus.f.bdeFlags = 0;
  1578. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1579. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1580. /* Sync SLIM */
  1581. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1582. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1583. /* flush */
  1584. readl(phba->hbq_put + hbqno);
  1585. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1586. return 0;
  1587. } else
  1588. return -ENOMEM;
  1589. }
  1590. /**
  1591. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1592. * @phba: Pointer to HBA context object.
  1593. * @hbqno: HBQ number.
  1594. * @hbq_buf: Pointer to HBQ buffer.
  1595. *
  1596. * This function is called with the hbalock held to post an RQE to the SLI4
  1597. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1598. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1599. **/
  1600. static int
  1601. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1602. struct hbq_dmabuf *hbq_buf)
  1603. {
  1604. int rc;
  1605. struct lpfc_rqe hrqe;
  1606. struct lpfc_rqe drqe;
  1607. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1608. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1609. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1610. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1611. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1612. &hrqe, &drqe);
  1613. if (rc < 0)
  1614. return rc;
  1615. hbq_buf->tag = rc;
  1616. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1617. return 0;
  1618. }
  1619. /* HBQ for ELS and CT traffic. */
  1620. static struct lpfc_hbq_init lpfc_els_hbq = {
  1621. .rn = 1,
  1622. .entry_count = 256,
  1623. .mask_count = 0,
  1624. .profile = 0,
  1625. .ring_mask = (1 << LPFC_ELS_RING),
  1626. .buffer_count = 0,
  1627. .init_count = 40,
  1628. .add_count = 40,
  1629. };
  1630. /* HBQ for the extra ring if needed */
  1631. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1632. .rn = 1,
  1633. .entry_count = 200,
  1634. .mask_count = 0,
  1635. .profile = 0,
  1636. .ring_mask = (1 << LPFC_EXTRA_RING),
  1637. .buffer_count = 0,
  1638. .init_count = 0,
  1639. .add_count = 5,
  1640. };
  1641. /* Array of HBQs */
  1642. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1643. &lpfc_els_hbq,
  1644. &lpfc_extra_hbq,
  1645. };
  1646. /**
  1647. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1648. * @phba: Pointer to HBA context object.
  1649. * @hbqno: HBQ number.
  1650. * @count: Number of HBQ buffers to be posted.
  1651. *
  1652. * This function is called with no lock held to post more hbq buffers to the
  1653. * given HBQ. The function returns the number of HBQ buffers successfully
  1654. * posted.
  1655. **/
  1656. static int
  1657. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1658. {
  1659. uint32_t i, posted = 0;
  1660. unsigned long flags;
  1661. struct hbq_dmabuf *hbq_buffer;
  1662. LIST_HEAD(hbq_buf_list);
  1663. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1664. return 0;
  1665. if ((phba->hbqs[hbqno].buffer_count + count) >
  1666. lpfc_hbq_defs[hbqno]->entry_count)
  1667. count = lpfc_hbq_defs[hbqno]->entry_count -
  1668. phba->hbqs[hbqno].buffer_count;
  1669. if (!count)
  1670. return 0;
  1671. /* Allocate HBQ entries */
  1672. for (i = 0; i < count; i++) {
  1673. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1674. if (!hbq_buffer)
  1675. break;
  1676. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1677. }
  1678. /* Check whether HBQ is still in use */
  1679. spin_lock_irqsave(&phba->hbalock, flags);
  1680. if (!phba->hbq_in_use)
  1681. goto err;
  1682. while (!list_empty(&hbq_buf_list)) {
  1683. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1684. dbuf.list);
  1685. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1686. (hbqno << 16));
  1687. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1688. phba->hbqs[hbqno].buffer_count++;
  1689. posted++;
  1690. } else
  1691. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1692. }
  1693. spin_unlock_irqrestore(&phba->hbalock, flags);
  1694. return posted;
  1695. err:
  1696. spin_unlock_irqrestore(&phba->hbalock, flags);
  1697. while (!list_empty(&hbq_buf_list)) {
  1698. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1699. dbuf.list);
  1700. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1701. }
  1702. return 0;
  1703. }
  1704. /**
  1705. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1706. * @phba: Pointer to HBA context object.
  1707. * @qno: HBQ number.
  1708. *
  1709. * This function posts more buffers to the HBQ. This function
  1710. * is called with no lock held. The function returns the number of HBQ entries
  1711. * successfully allocated.
  1712. **/
  1713. int
  1714. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1715. {
  1716. if (phba->sli_rev == LPFC_SLI_REV4)
  1717. return 0;
  1718. else
  1719. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1720. lpfc_hbq_defs[qno]->add_count);
  1721. }
  1722. /**
  1723. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1724. * @phba: Pointer to HBA context object.
  1725. * @qno: HBQ queue number.
  1726. *
  1727. * This function is called from SLI initialization code path with
  1728. * no lock held to post initial HBQ buffers to firmware. The
  1729. * function returns the number of HBQ entries successfully allocated.
  1730. **/
  1731. static int
  1732. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1733. {
  1734. if (phba->sli_rev == LPFC_SLI_REV4)
  1735. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1736. lpfc_hbq_defs[qno]->entry_count);
  1737. else
  1738. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1739. lpfc_hbq_defs[qno]->init_count);
  1740. }
  1741. /**
  1742. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1743. * @phba: Pointer to HBA context object.
  1744. * @hbqno: HBQ number.
  1745. *
  1746. * This function removes the first hbq buffer on an hbq list and returns a
  1747. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1748. **/
  1749. static struct hbq_dmabuf *
  1750. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1751. {
  1752. struct lpfc_dmabuf *d_buf;
  1753. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1754. if (!d_buf)
  1755. return NULL;
  1756. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1757. }
  1758. /**
  1759. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1760. * @phba: Pointer to HBA context object.
  1761. * @tag: Tag of the hbq buffer.
  1762. *
  1763. * This function is called with hbalock held. This function searches
  1764. * for the hbq buffer associated with the given tag in the hbq buffer
  1765. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1766. * it returns NULL.
  1767. **/
  1768. static struct hbq_dmabuf *
  1769. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1770. {
  1771. struct lpfc_dmabuf *d_buf;
  1772. struct hbq_dmabuf *hbq_buf;
  1773. uint32_t hbqno;
  1774. hbqno = tag >> 16;
  1775. if (hbqno >= LPFC_MAX_HBQS)
  1776. return NULL;
  1777. spin_lock_irq(&phba->hbalock);
  1778. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1779. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1780. if (hbq_buf->tag == tag) {
  1781. spin_unlock_irq(&phba->hbalock);
  1782. return hbq_buf;
  1783. }
  1784. }
  1785. spin_unlock_irq(&phba->hbalock);
  1786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1787. "1803 Bad hbq tag. Data: x%x x%x\n",
  1788. tag, phba->hbqs[tag >> 16].buffer_count);
  1789. return NULL;
  1790. }
  1791. /**
  1792. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1793. * @phba: Pointer to HBA context object.
  1794. * @hbq_buffer: Pointer to HBQ buffer.
  1795. *
  1796. * This function is called with hbalock. This function gives back
  1797. * the hbq buffer to firmware. If the HBQ does not have space to
  1798. * post the buffer, it will free the buffer.
  1799. **/
  1800. void
  1801. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1802. {
  1803. uint32_t hbqno;
  1804. if (hbq_buffer) {
  1805. hbqno = hbq_buffer->tag >> 16;
  1806. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1807. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1808. }
  1809. }
  1810. /**
  1811. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1812. * @mbxCommand: mailbox command code.
  1813. *
  1814. * This function is called by the mailbox event handler function to verify
  1815. * that the completed mailbox command is a legitimate mailbox command. If the
  1816. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1817. * and the mailbox event handler will take the HBA offline.
  1818. **/
  1819. static int
  1820. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1821. {
  1822. uint8_t ret;
  1823. switch (mbxCommand) {
  1824. case MBX_LOAD_SM:
  1825. case MBX_READ_NV:
  1826. case MBX_WRITE_NV:
  1827. case MBX_WRITE_VPARMS:
  1828. case MBX_RUN_BIU_DIAG:
  1829. case MBX_INIT_LINK:
  1830. case MBX_DOWN_LINK:
  1831. case MBX_CONFIG_LINK:
  1832. case MBX_CONFIG_RING:
  1833. case MBX_RESET_RING:
  1834. case MBX_READ_CONFIG:
  1835. case MBX_READ_RCONFIG:
  1836. case MBX_READ_SPARM:
  1837. case MBX_READ_STATUS:
  1838. case MBX_READ_RPI:
  1839. case MBX_READ_XRI:
  1840. case MBX_READ_REV:
  1841. case MBX_READ_LNK_STAT:
  1842. case MBX_REG_LOGIN:
  1843. case MBX_UNREG_LOGIN:
  1844. case MBX_CLEAR_LA:
  1845. case MBX_DUMP_MEMORY:
  1846. case MBX_DUMP_CONTEXT:
  1847. case MBX_RUN_DIAGS:
  1848. case MBX_RESTART:
  1849. case MBX_UPDATE_CFG:
  1850. case MBX_DOWN_LOAD:
  1851. case MBX_DEL_LD_ENTRY:
  1852. case MBX_RUN_PROGRAM:
  1853. case MBX_SET_MASK:
  1854. case MBX_SET_VARIABLE:
  1855. case MBX_UNREG_D_ID:
  1856. case MBX_KILL_BOARD:
  1857. case MBX_CONFIG_FARP:
  1858. case MBX_BEACON:
  1859. case MBX_LOAD_AREA:
  1860. case MBX_RUN_BIU_DIAG64:
  1861. case MBX_CONFIG_PORT:
  1862. case MBX_READ_SPARM64:
  1863. case MBX_READ_RPI64:
  1864. case MBX_REG_LOGIN64:
  1865. case MBX_READ_TOPOLOGY:
  1866. case MBX_WRITE_WWN:
  1867. case MBX_SET_DEBUG:
  1868. case MBX_LOAD_EXP_ROM:
  1869. case MBX_ASYNCEVT_ENABLE:
  1870. case MBX_REG_VPI:
  1871. case MBX_UNREG_VPI:
  1872. case MBX_HEARTBEAT:
  1873. case MBX_PORT_CAPABILITIES:
  1874. case MBX_PORT_IOV_CONTROL:
  1875. case MBX_SLI4_CONFIG:
  1876. case MBX_SLI4_REQ_FTRS:
  1877. case MBX_REG_FCFI:
  1878. case MBX_UNREG_FCFI:
  1879. case MBX_REG_VFI:
  1880. case MBX_UNREG_VFI:
  1881. case MBX_INIT_VPI:
  1882. case MBX_INIT_VFI:
  1883. case MBX_RESUME_RPI:
  1884. case MBX_READ_EVENT_LOG_STATUS:
  1885. case MBX_READ_EVENT_LOG:
  1886. case MBX_SECURITY_MGMT:
  1887. case MBX_AUTH_PORT:
  1888. ret = mbxCommand;
  1889. break;
  1890. default:
  1891. ret = MBX_SHUTDOWN;
  1892. break;
  1893. }
  1894. return ret;
  1895. }
  1896. /**
  1897. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1898. * @phba: Pointer to HBA context object.
  1899. * @pmboxq: Pointer to mailbox command.
  1900. *
  1901. * This is completion handler function for mailbox commands issued from
  1902. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1903. * mailbox event handler function with no lock held. This function
  1904. * will wake up thread waiting on the wait queue pointed by context1
  1905. * of the mailbox.
  1906. **/
  1907. void
  1908. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1909. {
  1910. wait_queue_head_t *pdone_q;
  1911. unsigned long drvr_flag;
  1912. /*
  1913. * If pdone_q is empty, the driver thread gave up waiting and
  1914. * continued running.
  1915. */
  1916. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1917. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1918. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1919. if (pdone_q)
  1920. wake_up_interruptible(pdone_q);
  1921. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1922. return;
  1923. }
  1924. /**
  1925. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1926. * @phba: Pointer to HBA context object.
  1927. * @pmb: Pointer to mailbox object.
  1928. *
  1929. * This function is the default mailbox completion handler. It
  1930. * frees the memory resources associated with the completed mailbox
  1931. * command. If the completed command is a REG_LOGIN mailbox command,
  1932. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1933. **/
  1934. void
  1935. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1936. {
  1937. struct lpfc_vport *vport = pmb->vport;
  1938. struct lpfc_dmabuf *mp;
  1939. struct lpfc_nodelist *ndlp;
  1940. struct Scsi_Host *shost;
  1941. uint16_t rpi, vpi;
  1942. int rc;
  1943. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1944. if (mp) {
  1945. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1946. kfree(mp);
  1947. }
  1948. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1949. (phba->sli_rev == LPFC_SLI_REV4) &&
  1950. (pmb->u.mb.un.varUnregLogin.rsvd1 == 0x0))
  1951. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1952. /*
  1953. * If a REG_LOGIN succeeded after node is destroyed or node
  1954. * is in re-discovery driver need to cleanup the RPI.
  1955. */
  1956. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1957. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1958. !pmb->u.mb.mbxStatus) {
  1959. rpi = pmb->u.mb.un.varWords[0];
  1960. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1961. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1962. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1963. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1964. if (rc != MBX_NOT_FINISHED)
  1965. return;
  1966. }
  1967. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1968. !(phba->pport->load_flag & FC_UNLOADING) &&
  1969. !pmb->u.mb.mbxStatus) {
  1970. shost = lpfc_shost_from_vport(vport);
  1971. spin_lock_irq(shost->host_lock);
  1972. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1973. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1974. spin_unlock_irq(shost->host_lock);
  1975. }
  1976. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1977. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1978. lpfc_nlp_put(ndlp);
  1979. pmb->context2 = NULL;
  1980. }
  1981. /* Check security permission status on INIT_LINK mailbox command */
  1982. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1983. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1984. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1985. "2860 SLI authentication is required "
  1986. "for INIT_LINK but has not done yet\n");
  1987. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1988. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1989. else
  1990. mempool_free(pmb, phba->mbox_mem_pool);
  1991. }
  1992. /**
  1993. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1994. * @phba: Pointer to HBA context object.
  1995. *
  1996. * This function is called with no lock held. This function processes all
  1997. * the completed mailbox commands and gives it to upper layers. The interrupt
  1998. * service routine processes mailbox completion interrupt and adds completed
  1999. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2000. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2001. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2002. * function returns the mailbox commands to the upper layer by calling the
  2003. * completion handler function of each mailbox.
  2004. **/
  2005. int
  2006. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2007. {
  2008. MAILBOX_t *pmbox;
  2009. LPFC_MBOXQ_t *pmb;
  2010. int rc;
  2011. LIST_HEAD(cmplq);
  2012. phba->sli.slistat.mbox_event++;
  2013. /* Get all completed mailboxe buffers into the cmplq */
  2014. spin_lock_irq(&phba->hbalock);
  2015. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2016. spin_unlock_irq(&phba->hbalock);
  2017. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2018. do {
  2019. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2020. if (pmb == NULL)
  2021. break;
  2022. pmbox = &pmb->u.mb;
  2023. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2024. if (pmb->vport) {
  2025. lpfc_debugfs_disc_trc(pmb->vport,
  2026. LPFC_DISC_TRC_MBOX_VPORT,
  2027. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2028. (uint32_t)pmbox->mbxCommand,
  2029. pmbox->un.varWords[0],
  2030. pmbox->un.varWords[1]);
  2031. }
  2032. else {
  2033. lpfc_debugfs_disc_trc(phba->pport,
  2034. LPFC_DISC_TRC_MBOX,
  2035. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2036. (uint32_t)pmbox->mbxCommand,
  2037. pmbox->un.varWords[0],
  2038. pmbox->un.varWords[1]);
  2039. }
  2040. }
  2041. /*
  2042. * It is a fatal error if unknown mbox command completion.
  2043. */
  2044. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2045. MBX_SHUTDOWN) {
  2046. /* Unknown mailbox command compl */
  2047. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2048. "(%d):0323 Unknown Mailbox command "
  2049. "x%x (x%x) Cmpl\n",
  2050. pmb->vport ? pmb->vport->vpi : 0,
  2051. pmbox->mbxCommand,
  2052. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2053. phba->link_state = LPFC_HBA_ERROR;
  2054. phba->work_hs = HS_FFER3;
  2055. lpfc_handle_eratt(phba);
  2056. continue;
  2057. }
  2058. if (pmbox->mbxStatus) {
  2059. phba->sli.slistat.mbox_stat_err++;
  2060. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2061. /* Mbox cmd cmpl error - RETRYing */
  2062. lpfc_printf_log(phba, KERN_INFO,
  2063. LOG_MBOX | LOG_SLI,
  2064. "(%d):0305 Mbox cmd cmpl "
  2065. "error - RETRYing Data: x%x "
  2066. "(x%x) x%x x%x x%x\n",
  2067. pmb->vport ? pmb->vport->vpi :0,
  2068. pmbox->mbxCommand,
  2069. lpfc_sli4_mbox_opcode_get(phba,
  2070. pmb),
  2071. pmbox->mbxStatus,
  2072. pmbox->un.varWords[0],
  2073. pmb->vport->port_state);
  2074. pmbox->mbxStatus = 0;
  2075. pmbox->mbxOwner = OWN_HOST;
  2076. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2077. if (rc != MBX_NOT_FINISHED)
  2078. continue;
  2079. }
  2080. }
  2081. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2082. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2083. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2084. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2085. pmb->vport ? pmb->vport->vpi : 0,
  2086. pmbox->mbxCommand,
  2087. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2088. pmb->mbox_cmpl,
  2089. *((uint32_t *) pmbox),
  2090. pmbox->un.varWords[0],
  2091. pmbox->un.varWords[1],
  2092. pmbox->un.varWords[2],
  2093. pmbox->un.varWords[3],
  2094. pmbox->un.varWords[4],
  2095. pmbox->un.varWords[5],
  2096. pmbox->un.varWords[6],
  2097. pmbox->un.varWords[7]);
  2098. if (pmb->mbox_cmpl)
  2099. pmb->mbox_cmpl(phba,pmb);
  2100. } while (1);
  2101. return 0;
  2102. }
  2103. /**
  2104. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2105. * @phba: Pointer to HBA context object.
  2106. * @pring: Pointer to driver SLI ring object.
  2107. * @tag: buffer tag.
  2108. *
  2109. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2110. * is set in the tag the buffer is posted for a particular exchange,
  2111. * the function will return the buffer without replacing the buffer.
  2112. * If the buffer is for unsolicited ELS or CT traffic, this function
  2113. * returns the buffer and also posts another buffer to the firmware.
  2114. **/
  2115. static struct lpfc_dmabuf *
  2116. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2117. struct lpfc_sli_ring *pring,
  2118. uint32_t tag)
  2119. {
  2120. struct hbq_dmabuf *hbq_entry;
  2121. if (tag & QUE_BUFTAG_BIT)
  2122. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2123. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2124. if (!hbq_entry)
  2125. return NULL;
  2126. return &hbq_entry->dbuf;
  2127. }
  2128. /**
  2129. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2130. * @phba: Pointer to HBA context object.
  2131. * @pring: Pointer to driver SLI ring object.
  2132. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2133. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2134. * @fch_type: the type for the first frame of the sequence.
  2135. *
  2136. * This function is called with no lock held. This function uses the r_ctl and
  2137. * type of the received sequence to find the correct callback function to call
  2138. * to process the sequence.
  2139. **/
  2140. static int
  2141. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2142. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2143. uint32_t fch_type)
  2144. {
  2145. int i;
  2146. /* unSolicited Responses */
  2147. if (pring->prt[0].profile) {
  2148. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2149. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2150. saveq);
  2151. return 1;
  2152. }
  2153. /* We must search, based on rctl / type
  2154. for the right routine */
  2155. for (i = 0; i < pring->num_mask; i++) {
  2156. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2157. (pring->prt[i].type == fch_type)) {
  2158. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2159. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2160. (phba, pring, saveq);
  2161. return 1;
  2162. }
  2163. }
  2164. return 0;
  2165. }
  2166. /**
  2167. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2168. * @phba: Pointer to HBA context object.
  2169. * @pring: Pointer to driver SLI ring object.
  2170. * @saveq: Pointer to the unsolicited iocb.
  2171. *
  2172. * This function is called with no lock held by the ring event handler
  2173. * when there is an unsolicited iocb posted to the response ring by the
  2174. * firmware. This function gets the buffer associated with the iocbs
  2175. * and calls the event handler for the ring. This function handles both
  2176. * qring buffers and hbq buffers.
  2177. * When the function returns 1 the caller can free the iocb object otherwise
  2178. * upper layer functions will free the iocb objects.
  2179. **/
  2180. static int
  2181. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2182. struct lpfc_iocbq *saveq)
  2183. {
  2184. IOCB_t * irsp;
  2185. WORD5 * w5p;
  2186. uint32_t Rctl, Type;
  2187. uint32_t match;
  2188. struct lpfc_iocbq *iocbq;
  2189. struct lpfc_dmabuf *dmzbuf;
  2190. match = 0;
  2191. irsp = &(saveq->iocb);
  2192. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2193. if (pring->lpfc_sli_rcv_async_status)
  2194. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2195. else
  2196. lpfc_printf_log(phba,
  2197. KERN_WARNING,
  2198. LOG_SLI,
  2199. "0316 Ring %d handler: unexpected "
  2200. "ASYNC_STATUS iocb received evt_code "
  2201. "0x%x\n",
  2202. pring->ringno,
  2203. irsp->un.asyncstat.evt_code);
  2204. return 1;
  2205. }
  2206. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2207. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2208. if (irsp->ulpBdeCount > 0) {
  2209. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2210. irsp->un.ulpWord[3]);
  2211. lpfc_in_buf_free(phba, dmzbuf);
  2212. }
  2213. if (irsp->ulpBdeCount > 1) {
  2214. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2215. irsp->unsli3.sli3Words[3]);
  2216. lpfc_in_buf_free(phba, dmzbuf);
  2217. }
  2218. if (irsp->ulpBdeCount > 2) {
  2219. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2220. irsp->unsli3.sli3Words[7]);
  2221. lpfc_in_buf_free(phba, dmzbuf);
  2222. }
  2223. return 1;
  2224. }
  2225. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2226. if (irsp->ulpBdeCount != 0) {
  2227. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2228. irsp->un.ulpWord[3]);
  2229. if (!saveq->context2)
  2230. lpfc_printf_log(phba,
  2231. KERN_ERR,
  2232. LOG_SLI,
  2233. "0341 Ring %d Cannot find buffer for "
  2234. "an unsolicited iocb. tag 0x%x\n",
  2235. pring->ringno,
  2236. irsp->un.ulpWord[3]);
  2237. }
  2238. if (irsp->ulpBdeCount == 2) {
  2239. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2240. irsp->unsli3.sli3Words[7]);
  2241. if (!saveq->context3)
  2242. lpfc_printf_log(phba,
  2243. KERN_ERR,
  2244. LOG_SLI,
  2245. "0342 Ring %d Cannot find buffer for an"
  2246. " unsolicited iocb. tag 0x%x\n",
  2247. pring->ringno,
  2248. irsp->unsli3.sli3Words[7]);
  2249. }
  2250. list_for_each_entry(iocbq, &saveq->list, list) {
  2251. irsp = &(iocbq->iocb);
  2252. if (irsp->ulpBdeCount != 0) {
  2253. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2254. irsp->un.ulpWord[3]);
  2255. if (!iocbq->context2)
  2256. lpfc_printf_log(phba,
  2257. KERN_ERR,
  2258. LOG_SLI,
  2259. "0343 Ring %d Cannot find "
  2260. "buffer for an unsolicited iocb"
  2261. ". tag 0x%x\n", pring->ringno,
  2262. irsp->un.ulpWord[3]);
  2263. }
  2264. if (irsp->ulpBdeCount == 2) {
  2265. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2266. irsp->unsli3.sli3Words[7]);
  2267. if (!iocbq->context3)
  2268. lpfc_printf_log(phba,
  2269. KERN_ERR,
  2270. LOG_SLI,
  2271. "0344 Ring %d Cannot find "
  2272. "buffer for an unsolicited "
  2273. "iocb. tag 0x%x\n",
  2274. pring->ringno,
  2275. irsp->unsli3.sli3Words[7]);
  2276. }
  2277. }
  2278. }
  2279. if (irsp->ulpBdeCount != 0 &&
  2280. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2281. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2282. int found = 0;
  2283. /* search continue save q for same XRI */
  2284. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2285. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2286. list_add_tail(&saveq->list, &iocbq->list);
  2287. found = 1;
  2288. break;
  2289. }
  2290. }
  2291. if (!found)
  2292. list_add_tail(&saveq->clist,
  2293. &pring->iocb_continue_saveq);
  2294. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2295. list_del_init(&iocbq->clist);
  2296. saveq = iocbq;
  2297. irsp = &(saveq->iocb);
  2298. } else
  2299. return 0;
  2300. }
  2301. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2302. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2303. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2304. Rctl = FC_RCTL_ELS_REQ;
  2305. Type = FC_TYPE_ELS;
  2306. } else {
  2307. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2308. Rctl = w5p->hcsw.Rctl;
  2309. Type = w5p->hcsw.Type;
  2310. /* Firmware Workaround */
  2311. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2312. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2313. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2314. Rctl = FC_RCTL_ELS_REQ;
  2315. Type = FC_TYPE_ELS;
  2316. w5p->hcsw.Rctl = Rctl;
  2317. w5p->hcsw.Type = Type;
  2318. }
  2319. }
  2320. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2321. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2322. "0313 Ring %d handler: unexpected Rctl x%x "
  2323. "Type x%x received\n",
  2324. pring->ringno, Rctl, Type);
  2325. return 1;
  2326. }
  2327. /**
  2328. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2329. * @phba: Pointer to HBA context object.
  2330. * @pring: Pointer to driver SLI ring object.
  2331. * @prspiocb: Pointer to response iocb object.
  2332. *
  2333. * This function looks up the iocb_lookup table to get the command iocb
  2334. * corresponding to the given response iocb using the iotag of the
  2335. * response iocb. This function is called with the hbalock held.
  2336. * This function returns the command iocb object if it finds the command
  2337. * iocb else returns NULL.
  2338. **/
  2339. static struct lpfc_iocbq *
  2340. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2341. struct lpfc_sli_ring *pring,
  2342. struct lpfc_iocbq *prspiocb)
  2343. {
  2344. struct lpfc_iocbq *cmd_iocb = NULL;
  2345. uint16_t iotag;
  2346. iotag = prspiocb->iocb.ulpIoTag;
  2347. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2348. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2349. list_del_init(&cmd_iocb->list);
  2350. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2351. pring->txcmplq_cnt--;
  2352. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2353. }
  2354. return cmd_iocb;
  2355. }
  2356. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2357. "0317 iotag x%x is out off "
  2358. "range: max iotag x%x wd0 x%x\n",
  2359. iotag, phba->sli.last_iotag,
  2360. *(((uint32_t *) &prspiocb->iocb) + 7));
  2361. return NULL;
  2362. }
  2363. /**
  2364. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2365. * @phba: Pointer to HBA context object.
  2366. * @pring: Pointer to driver SLI ring object.
  2367. * @iotag: IOCB tag.
  2368. *
  2369. * This function looks up the iocb_lookup table to get the command iocb
  2370. * corresponding to the given iotag. This function is called with the
  2371. * hbalock held.
  2372. * This function returns the command iocb object if it finds the command
  2373. * iocb else returns NULL.
  2374. **/
  2375. static struct lpfc_iocbq *
  2376. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2377. struct lpfc_sli_ring *pring, uint16_t iotag)
  2378. {
  2379. struct lpfc_iocbq *cmd_iocb;
  2380. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2381. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2382. list_del_init(&cmd_iocb->list);
  2383. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2384. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2385. pring->txcmplq_cnt--;
  2386. }
  2387. return cmd_iocb;
  2388. }
  2389. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2390. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2391. iotag, phba->sli.last_iotag);
  2392. return NULL;
  2393. }
  2394. /**
  2395. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2396. * @phba: Pointer to HBA context object.
  2397. * @pring: Pointer to driver SLI ring object.
  2398. * @saveq: Pointer to the response iocb to be processed.
  2399. *
  2400. * This function is called by the ring event handler for non-fcp
  2401. * rings when there is a new response iocb in the response ring.
  2402. * The caller is not required to hold any locks. This function
  2403. * gets the command iocb associated with the response iocb and
  2404. * calls the completion handler for the command iocb. If there
  2405. * is no completion handler, the function will free the resources
  2406. * associated with command iocb. If the response iocb is for
  2407. * an already aborted command iocb, the status of the completion
  2408. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2409. * This function always returns 1.
  2410. **/
  2411. static int
  2412. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2413. struct lpfc_iocbq *saveq)
  2414. {
  2415. struct lpfc_iocbq *cmdiocbp;
  2416. int rc = 1;
  2417. unsigned long iflag;
  2418. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2419. spin_lock_irqsave(&phba->hbalock, iflag);
  2420. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2421. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2422. if (cmdiocbp) {
  2423. if (cmdiocbp->iocb_cmpl) {
  2424. /*
  2425. * If an ELS command failed send an event to mgmt
  2426. * application.
  2427. */
  2428. if (saveq->iocb.ulpStatus &&
  2429. (pring->ringno == LPFC_ELS_RING) &&
  2430. (cmdiocbp->iocb.ulpCommand ==
  2431. CMD_ELS_REQUEST64_CR))
  2432. lpfc_send_els_failure_event(phba,
  2433. cmdiocbp, saveq);
  2434. /*
  2435. * Post all ELS completions to the worker thread.
  2436. * All other are passed to the completion callback.
  2437. */
  2438. if (pring->ringno == LPFC_ELS_RING) {
  2439. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2440. (cmdiocbp->iocb_flag &
  2441. LPFC_DRIVER_ABORTED)) {
  2442. spin_lock_irqsave(&phba->hbalock,
  2443. iflag);
  2444. cmdiocbp->iocb_flag &=
  2445. ~LPFC_DRIVER_ABORTED;
  2446. spin_unlock_irqrestore(&phba->hbalock,
  2447. iflag);
  2448. saveq->iocb.ulpStatus =
  2449. IOSTAT_LOCAL_REJECT;
  2450. saveq->iocb.un.ulpWord[4] =
  2451. IOERR_SLI_ABORTED;
  2452. /* Firmware could still be in progress
  2453. * of DMAing payload, so don't free data
  2454. * buffer till after a hbeat.
  2455. */
  2456. spin_lock_irqsave(&phba->hbalock,
  2457. iflag);
  2458. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2459. spin_unlock_irqrestore(&phba->hbalock,
  2460. iflag);
  2461. }
  2462. if (phba->sli_rev == LPFC_SLI_REV4) {
  2463. if (saveq->iocb_flag &
  2464. LPFC_EXCHANGE_BUSY) {
  2465. /* Set cmdiocb flag for the
  2466. * exchange busy so sgl (xri)
  2467. * will not be released until
  2468. * the abort xri is received
  2469. * from hba.
  2470. */
  2471. spin_lock_irqsave(
  2472. &phba->hbalock, iflag);
  2473. cmdiocbp->iocb_flag |=
  2474. LPFC_EXCHANGE_BUSY;
  2475. spin_unlock_irqrestore(
  2476. &phba->hbalock, iflag);
  2477. }
  2478. if (cmdiocbp->iocb_flag &
  2479. LPFC_DRIVER_ABORTED) {
  2480. /*
  2481. * Clear LPFC_DRIVER_ABORTED
  2482. * bit in case it was driver
  2483. * initiated abort.
  2484. */
  2485. spin_lock_irqsave(
  2486. &phba->hbalock, iflag);
  2487. cmdiocbp->iocb_flag &=
  2488. ~LPFC_DRIVER_ABORTED;
  2489. spin_unlock_irqrestore(
  2490. &phba->hbalock, iflag);
  2491. cmdiocbp->iocb.ulpStatus =
  2492. IOSTAT_LOCAL_REJECT;
  2493. cmdiocbp->iocb.un.ulpWord[4] =
  2494. IOERR_ABORT_REQUESTED;
  2495. /*
  2496. * For SLI4, irsiocb contains
  2497. * NO_XRI in sli_xritag, it
  2498. * shall not affect releasing
  2499. * sgl (xri) process.
  2500. */
  2501. saveq->iocb.ulpStatus =
  2502. IOSTAT_LOCAL_REJECT;
  2503. saveq->iocb.un.ulpWord[4] =
  2504. IOERR_SLI_ABORTED;
  2505. spin_lock_irqsave(
  2506. &phba->hbalock, iflag);
  2507. saveq->iocb_flag |=
  2508. LPFC_DELAY_MEM_FREE;
  2509. spin_unlock_irqrestore(
  2510. &phba->hbalock, iflag);
  2511. }
  2512. }
  2513. }
  2514. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2515. } else
  2516. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2517. } else {
  2518. /*
  2519. * Unknown initiating command based on the response iotag.
  2520. * This could be the case on the ELS ring because of
  2521. * lpfc_els_abort().
  2522. */
  2523. if (pring->ringno != LPFC_ELS_RING) {
  2524. /*
  2525. * Ring <ringno> handler: unexpected completion IoTag
  2526. * <IoTag>
  2527. */
  2528. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2529. "0322 Ring %d handler: "
  2530. "unexpected completion IoTag x%x "
  2531. "Data: x%x x%x x%x x%x\n",
  2532. pring->ringno,
  2533. saveq->iocb.ulpIoTag,
  2534. saveq->iocb.ulpStatus,
  2535. saveq->iocb.un.ulpWord[4],
  2536. saveq->iocb.ulpCommand,
  2537. saveq->iocb.ulpContext);
  2538. }
  2539. }
  2540. return rc;
  2541. }
  2542. /**
  2543. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2544. * @phba: Pointer to HBA context object.
  2545. * @pring: Pointer to driver SLI ring object.
  2546. *
  2547. * This function is called from the iocb ring event handlers when
  2548. * put pointer is ahead of the get pointer for a ring. This function signal
  2549. * an error attention condition to the worker thread and the worker
  2550. * thread will transition the HBA to offline state.
  2551. **/
  2552. static void
  2553. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2554. {
  2555. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2556. /*
  2557. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2558. * rsp ring <portRspMax>
  2559. */
  2560. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2561. "0312 Ring %d handler: portRspPut %d "
  2562. "is bigger than rsp ring %d\n",
  2563. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2564. pring->numRiocb);
  2565. phba->link_state = LPFC_HBA_ERROR;
  2566. /*
  2567. * All error attention handlers are posted to
  2568. * worker thread
  2569. */
  2570. phba->work_ha |= HA_ERATT;
  2571. phba->work_hs = HS_FFER3;
  2572. lpfc_worker_wake_up(phba);
  2573. return;
  2574. }
  2575. /**
  2576. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2577. * @ptr: Pointer to address of HBA context object.
  2578. *
  2579. * This function is invoked by the Error Attention polling timer when the
  2580. * timer times out. It will check the SLI Error Attention register for
  2581. * possible attention events. If so, it will post an Error Attention event
  2582. * and wake up worker thread to process it. Otherwise, it will set up the
  2583. * Error Attention polling timer for the next poll.
  2584. **/
  2585. void lpfc_poll_eratt(unsigned long ptr)
  2586. {
  2587. struct lpfc_hba *phba;
  2588. uint32_t eratt = 0;
  2589. phba = (struct lpfc_hba *)ptr;
  2590. /* Check chip HA register for error event */
  2591. eratt = lpfc_sli_check_eratt(phba);
  2592. if (eratt)
  2593. /* Tell the worker thread there is work to do */
  2594. lpfc_worker_wake_up(phba);
  2595. else
  2596. /* Restart the timer for next eratt poll */
  2597. mod_timer(&phba->eratt_poll, jiffies +
  2598. HZ * LPFC_ERATT_POLL_INTERVAL);
  2599. return;
  2600. }
  2601. /**
  2602. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2603. * @phba: Pointer to HBA context object.
  2604. * @pring: Pointer to driver SLI ring object.
  2605. * @mask: Host attention register mask for this ring.
  2606. *
  2607. * This function is called from the interrupt context when there is a ring
  2608. * event for the fcp ring. The caller does not hold any lock.
  2609. * The function processes each response iocb in the response ring until it
  2610. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2611. * LE bit set. The function will call the completion handler of the command iocb
  2612. * if the response iocb indicates a completion for a command iocb or it is
  2613. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2614. * function if this is an unsolicited iocb.
  2615. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2616. * to check it explicitly.
  2617. */
  2618. int
  2619. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2620. struct lpfc_sli_ring *pring, uint32_t mask)
  2621. {
  2622. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2623. IOCB_t *irsp = NULL;
  2624. IOCB_t *entry = NULL;
  2625. struct lpfc_iocbq *cmdiocbq = NULL;
  2626. struct lpfc_iocbq rspiocbq;
  2627. uint32_t status;
  2628. uint32_t portRspPut, portRspMax;
  2629. int rc = 1;
  2630. lpfc_iocb_type type;
  2631. unsigned long iflag;
  2632. uint32_t rsp_cmpl = 0;
  2633. spin_lock_irqsave(&phba->hbalock, iflag);
  2634. pring->stats.iocb_event++;
  2635. /*
  2636. * The next available response entry should never exceed the maximum
  2637. * entries. If it does, treat it as an adapter hardware error.
  2638. */
  2639. portRspMax = pring->numRiocb;
  2640. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2641. if (unlikely(portRspPut >= portRspMax)) {
  2642. lpfc_sli_rsp_pointers_error(phba, pring);
  2643. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2644. return 1;
  2645. }
  2646. if (phba->fcp_ring_in_use) {
  2647. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2648. return 1;
  2649. } else
  2650. phba->fcp_ring_in_use = 1;
  2651. rmb();
  2652. while (pring->rspidx != portRspPut) {
  2653. /*
  2654. * Fetch an entry off the ring and copy it into a local data
  2655. * structure. The copy involves a byte-swap since the
  2656. * network byte order and pci byte orders are different.
  2657. */
  2658. entry = lpfc_resp_iocb(phba, pring);
  2659. phba->last_completion_time = jiffies;
  2660. if (++pring->rspidx >= portRspMax)
  2661. pring->rspidx = 0;
  2662. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2663. (uint32_t *) &rspiocbq.iocb,
  2664. phba->iocb_rsp_size);
  2665. INIT_LIST_HEAD(&(rspiocbq.list));
  2666. irsp = &rspiocbq.iocb;
  2667. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2668. pring->stats.iocb_rsp++;
  2669. rsp_cmpl++;
  2670. if (unlikely(irsp->ulpStatus)) {
  2671. /*
  2672. * If resource errors reported from HBA, reduce
  2673. * queuedepths of the SCSI device.
  2674. */
  2675. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2676. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2677. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2678. phba->lpfc_rampdown_queue_depth(phba);
  2679. spin_lock_irqsave(&phba->hbalock, iflag);
  2680. }
  2681. /* Rsp ring <ringno> error: IOCB */
  2682. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2683. "0336 Rsp Ring %d error: IOCB Data: "
  2684. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2685. pring->ringno,
  2686. irsp->un.ulpWord[0],
  2687. irsp->un.ulpWord[1],
  2688. irsp->un.ulpWord[2],
  2689. irsp->un.ulpWord[3],
  2690. irsp->un.ulpWord[4],
  2691. irsp->un.ulpWord[5],
  2692. *(uint32_t *)&irsp->un1,
  2693. *((uint32_t *)&irsp->un1 + 1));
  2694. }
  2695. switch (type) {
  2696. case LPFC_ABORT_IOCB:
  2697. case LPFC_SOL_IOCB:
  2698. /*
  2699. * Idle exchange closed via ABTS from port. No iocb
  2700. * resources need to be recovered.
  2701. */
  2702. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2703. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2704. "0333 IOCB cmd 0x%x"
  2705. " processed. Skipping"
  2706. " completion\n",
  2707. irsp->ulpCommand);
  2708. break;
  2709. }
  2710. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2711. &rspiocbq);
  2712. if (unlikely(!cmdiocbq))
  2713. break;
  2714. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2715. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2716. if (cmdiocbq->iocb_cmpl) {
  2717. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2718. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2719. &rspiocbq);
  2720. spin_lock_irqsave(&phba->hbalock, iflag);
  2721. }
  2722. break;
  2723. case LPFC_UNSOL_IOCB:
  2724. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2725. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2726. spin_lock_irqsave(&phba->hbalock, iflag);
  2727. break;
  2728. default:
  2729. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2730. char adaptermsg[LPFC_MAX_ADPTMSG];
  2731. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2732. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2733. MAX_MSG_DATA);
  2734. dev_warn(&((phba->pcidev)->dev),
  2735. "lpfc%d: %s\n",
  2736. phba->brd_no, adaptermsg);
  2737. } else {
  2738. /* Unknown IOCB command */
  2739. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2740. "0334 Unknown IOCB command "
  2741. "Data: x%x, x%x x%x x%x x%x\n",
  2742. type, irsp->ulpCommand,
  2743. irsp->ulpStatus,
  2744. irsp->ulpIoTag,
  2745. irsp->ulpContext);
  2746. }
  2747. break;
  2748. }
  2749. /*
  2750. * The response IOCB has been processed. Update the ring
  2751. * pointer in SLIM. If the port response put pointer has not
  2752. * been updated, sync the pgp->rspPutInx and fetch the new port
  2753. * response put pointer.
  2754. */
  2755. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2756. if (pring->rspidx == portRspPut)
  2757. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2758. }
  2759. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2760. pring->stats.iocb_rsp_full++;
  2761. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2762. writel(status, phba->CAregaddr);
  2763. readl(phba->CAregaddr);
  2764. }
  2765. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2766. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2767. pring->stats.iocb_cmd_empty++;
  2768. /* Force update of the local copy of cmdGetInx */
  2769. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2770. lpfc_sli_resume_iocb(phba, pring);
  2771. if ((pring->lpfc_sli_cmd_available))
  2772. (pring->lpfc_sli_cmd_available) (phba, pring);
  2773. }
  2774. phba->fcp_ring_in_use = 0;
  2775. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2776. return rc;
  2777. }
  2778. /**
  2779. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2780. * @phba: Pointer to HBA context object.
  2781. * @pring: Pointer to driver SLI ring object.
  2782. * @rspiocbp: Pointer to driver response IOCB object.
  2783. *
  2784. * This function is called from the worker thread when there is a slow-path
  2785. * response IOCB to process. This function chains all the response iocbs until
  2786. * seeing the iocb with the LE bit set. The function will call
  2787. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2788. * completion of a command iocb. The function will call the
  2789. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2790. * The function frees the resources or calls the completion handler if this
  2791. * iocb is an abort completion. The function returns NULL when the response
  2792. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2793. * this function shall chain the iocb on to the iocb_continueq and return the
  2794. * response iocb passed in.
  2795. **/
  2796. static struct lpfc_iocbq *
  2797. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2798. struct lpfc_iocbq *rspiocbp)
  2799. {
  2800. struct lpfc_iocbq *saveq;
  2801. struct lpfc_iocbq *cmdiocbp;
  2802. struct lpfc_iocbq *next_iocb;
  2803. IOCB_t *irsp = NULL;
  2804. uint32_t free_saveq;
  2805. uint8_t iocb_cmd_type;
  2806. lpfc_iocb_type type;
  2807. unsigned long iflag;
  2808. int rc;
  2809. spin_lock_irqsave(&phba->hbalock, iflag);
  2810. /* First add the response iocb to the countinueq list */
  2811. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2812. pring->iocb_continueq_cnt++;
  2813. /* Now, determine whetehr the list is completed for processing */
  2814. irsp = &rspiocbp->iocb;
  2815. if (irsp->ulpLe) {
  2816. /*
  2817. * By default, the driver expects to free all resources
  2818. * associated with this iocb completion.
  2819. */
  2820. free_saveq = 1;
  2821. saveq = list_get_first(&pring->iocb_continueq,
  2822. struct lpfc_iocbq, list);
  2823. irsp = &(saveq->iocb);
  2824. list_del_init(&pring->iocb_continueq);
  2825. pring->iocb_continueq_cnt = 0;
  2826. pring->stats.iocb_rsp++;
  2827. /*
  2828. * If resource errors reported from HBA, reduce
  2829. * queuedepths of the SCSI device.
  2830. */
  2831. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2832. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2833. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2834. phba->lpfc_rampdown_queue_depth(phba);
  2835. spin_lock_irqsave(&phba->hbalock, iflag);
  2836. }
  2837. if (irsp->ulpStatus) {
  2838. /* Rsp ring <ringno> error: IOCB */
  2839. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2840. "0328 Rsp Ring %d error: "
  2841. "IOCB Data: "
  2842. "x%x x%x x%x x%x "
  2843. "x%x x%x x%x x%x "
  2844. "x%x x%x x%x x%x "
  2845. "x%x x%x x%x x%x\n",
  2846. pring->ringno,
  2847. irsp->un.ulpWord[0],
  2848. irsp->un.ulpWord[1],
  2849. irsp->un.ulpWord[2],
  2850. irsp->un.ulpWord[3],
  2851. irsp->un.ulpWord[4],
  2852. irsp->un.ulpWord[5],
  2853. *(((uint32_t *) irsp) + 6),
  2854. *(((uint32_t *) irsp) + 7),
  2855. *(((uint32_t *) irsp) + 8),
  2856. *(((uint32_t *) irsp) + 9),
  2857. *(((uint32_t *) irsp) + 10),
  2858. *(((uint32_t *) irsp) + 11),
  2859. *(((uint32_t *) irsp) + 12),
  2860. *(((uint32_t *) irsp) + 13),
  2861. *(((uint32_t *) irsp) + 14),
  2862. *(((uint32_t *) irsp) + 15));
  2863. }
  2864. /*
  2865. * Fetch the IOCB command type and call the correct completion
  2866. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2867. * get freed back to the lpfc_iocb_list by the discovery
  2868. * kernel thread.
  2869. */
  2870. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2871. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2872. switch (type) {
  2873. case LPFC_SOL_IOCB:
  2874. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2875. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2876. spin_lock_irqsave(&phba->hbalock, iflag);
  2877. break;
  2878. case LPFC_UNSOL_IOCB:
  2879. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2880. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2881. spin_lock_irqsave(&phba->hbalock, iflag);
  2882. if (!rc)
  2883. free_saveq = 0;
  2884. break;
  2885. case LPFC_ABORT_IOCB:
  2886. cmdiocbp = NULL;
  2887. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2888. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2889. saveq);
  2890. if (cmdiocbp) {
  2891. /* Call the specified completion routine */
  2892. if (cmdiocbp->iocb_cmpl) {
  2893. spin_unlock_irqrestore(&phba->hbalock,
  2894. iflag);
  2895. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2896. saveq);
  2897. spin_lock_irqsave(&phba->hbalock,
  2898. iflag);
  2899. } else
  2900. __lpfc_sli_release_iocbq(phba,
  2901. cmdiocbp);
  2902. }
  2903. break;
  2904. case LPFC_UNKNOWN_IOCB:
  2905. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2906. char adaptermsg[LPFC_MAX_ADPTMSG];
  2907. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2908. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2909. MAX_MSG_DATA);
  2910. dev_warn(&((phba->pcidev)->dev),
  2911. "lpfc%d: %s\n",
  2912. phba->brd_no, adaptermsg);
  2913. } else {
  2914. /* Unknown IOCB command */
  2915. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2916. "0335 Unknown IOCB "
  2917. "command Data: x%x "
  2918. "x%x x%x x%x\n",
  2919. irsp->ulpCommand,
  2920. irsp->ulpStatus,
  2921. irsp->ulpIoTag,
  2922. irsp->ulpContext);
  2923. }
  2924. break;
  2925. }
  2926. if (free_saveq) {
  2927. list_for_each_entry_safe(rspiocbp, next_iocb,
  2928. &saveq->list, list) {
  2929. list_del(&rspiocbp->list);
  2930. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2931. }
  2932. __lpfc_sli_release_iocbq(phba, saveq);
  2933. }
  2934. rspiocbp = NULL;
  2935. }
  2936. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2937. return rspiocbp;
  2938. }
  2939. /**
  2940. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2941. * @phba: Pointer to HBA context object.
  2942. * @pring: Pointer to driver SLI ring object.
  2943. * @mask: Host attention register mask for this ring.
  2944. *
  2945. * This routine wraps the actual slow_ring event process routine from the
  2946. * API jump table function pointer from the lpfc_hba struct.
  2947. **/
  2948. void
  2949. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2950. struct lpfc_sli_ring *pring, uint32_t mask)
  2951. {
  2952. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2953. }
  2954. /**
  2955. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2956. * @phba: Pointer to HBA context object.
  2957. * @pring: Pointer to driver SLI ring object.
  2958. * @mask: Host attention register mask for this ring.
  2959. *
  2960. * This function is called from the worker thread when there is a ring event
  2961. * for non-fcp rings. The caller does not hold any lock. The function will
  2962. * remove each response iocb in the response ring and calls the handle
  2963. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2964. **/
  2965. static void
  2966. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2967. struct lpfc_sli_ring *pring, uint32_t mask)
  2968. {
  2969. struct lpfc_pgp *pgp;
  2970. IOCB_t *entry;
  2971. IOCB_t *irsp = NULL;
  2972. struct lpfc_iocbq *rspiocbp = NULL;
  2973. uint32_t portRspPut, portRspMax;
  2974. unsigned long iflag;
  2975. uint32_t status;
  2976. pgp = &phba->port_gp[pring->ringno];
  2977. spin_lock_irqsave(&phba->hbalock, iflag);
  2978. pring->stats.iocb_event++;
  2979. /*
  2980. * The next available response entry should never exceed the maximum
  2981. * entries. If it does, treat it as an adapter hardware error.
  2982. */
  2983. portRspMax = pring->numRiocb;
  2984. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2985. if (portRspPut >= portRspMax) {
  2986. /*
  2987. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2988. * rsp ring <portRspMax>
  2989. */
  2990. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2991. "0303 Ring %d handler: portRspPut %d "
  2992. "is bigger than rsp ring %d\n",
  2993. pring->ringno, portRspPut, portRspMax);
  2994. phba->link_state = LPFC_HBA_ERROR;
  2995. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2996. phba->work_hs = HS_FFER3;
  2997. lpfc_handle_eratt(phba);
  2998. return;
  2999. }
  3000. rmb();
  3001. while (pring->rspidx != portRspPut) {
  3002. /*
  3003. * Build a completion list and call the appropriate handler.
  3004. * The process is to get the next available response iocb, get
  3005. * a free iocb from the list, copy the response data into the
  3006. * free iocb, insert to the continuation list, and update the
  3007. * next response index to slim. This process makes response
  3008. * iocb's in the ring available to DMA as fast as possible but
  3009. * pays a penalty for a copy operation. Since the iocb is
  3010. * only 32 bytes, this penalty is considered small relative to
  3011. * the PCI reads for register values and a slim write. When
  3012. * the ulpLe field is set, the entire Command has been
  3013. * received.
  3014. */
  3015. entry = lpfc_resp_iocb(phba, pring);
  3016. phba->last_completion_time = jiffies;
  3017. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3018. if (rspiocbp == NULL) {
  3019. printk(KERN_ERR "%s: out of buffers! Failing "
  3020. "completion.\n", __func__);
  3021. break;
  3022. }
  3023. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3024. phba->iocb_rsp_size);
  3025. irsp = &rspiocbp->iocb;
  3026. if (++pring->rspidx >= portRspMax)
  3027. pring->rspidx = 0;
  3028. if (pring->ringno == LPFC_ELS_RING) {
  3029. lpfc_debugfs_slow_ring_trc(phba,
  3030. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3031. *(((uint32_t *) irsp) + 4),
  3032. *(((uint32_t *) irsp) + 6),
  3033. *(((uint32_t *) irsp) + 7));
  3034. }
  3035. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3036. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3037. /* Handle the response IOCB */
  3038. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3039. spin_lock_irqsave(&phba->hbalock, iflag);
  3040. /*
  3041. * If the port response put pointer has not been updated, sync
  3042. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3043. * response put pointer.
  3044. */
  3045. if (pring->rspidx == portRspPut) {
  3046. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3047. }
  3048. } /* while (pring->rspidx != portRspPut) */
  3049. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3050. /* At least one response entry has been freed */
  3051. pring->stats.iocb_rsp_full++;
  3052. /* SET RxRE_RSP in Chip Att register */
  3053. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3054. writel(status, phba->CAregaddr);
  3055. readl(phba->CAregaddr); /* flush */
  3056. }
  3057. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3058. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3059. pring->stats.iocb_cmd_empty++;
  3060. /* Force update of the local copy of cmdGetInx */
  3061. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3062. lpfc_sli_resume_iocb(phba, pring);
  3063. if ((pring->lpfc_sli_cmd_available))
  3064. (pring->lpfc_sli_cmd_available) (phba, pring);
  3065. }
  3066. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3067. return;
  3068. }
  3069. /**
  3070. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3071. * @phba: Pointer to HBA context object.
  3072. * @pring: Pointer to driver SLI ring object.
  3073. * @mask: Host attention register mask for this ring.
  3074. *
  3075. * This function is called from the worker thread when there is a pending
  3076. * ELS response iocb on the driver internal slow-path response iocb worker
  3077. * queue. The caller does not hold any lock. The function will remove each
  3078. * response iocb from the response worker queue and calls the handle
  3079. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3080. **/
  3081. static void
  3082. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3083. struct lpfc_sli_ring *pring, uint32_t mask)
  3084. {
  3085. struct lpfc_iocbq *irspiocbq;
  3086. struct hbq_dmabuf *dmabuf;
  3087. struct lpfc_cq_event *cq_event;
  3088. unsigned long iflag;
  3089. spin_lock_irqsave(&phba->hbalock, iflag);
  3090. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3091. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3092. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3093. /* Get the response iocb from the head of work queue */
  3094. spin_lock_irqsave(&phba->hbalock, iflag);
  3095. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3096. cq_event, struct lpfc_cq_event, list);
  3097. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3098. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3099. case CQE_CODE_COMPL_WQE:
  3100. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3101. cq_event);
  3102. /* Translate ELS WCQE to response IOCBQ */
  3103. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3104. irspiocbq);
  3105. if (irspiocbq)
  3106. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3107. irspiocbq);
  3108. break;
  3109. case CQE_CODE_RECEIVE:
  3110. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3111. cq_event);
  3112. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3113. break;
  3114. default:
  3115. break;
  3116. }
  3117. }
  3118. }
  3119. /**
  3120. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3121. * @phba: Pointer to HBA context object.
  3122. * @pring: Pointer to driver SLI ring object.
  3123. *
  3124. * This function aborts all iocbs in the given ring and frees all the iocb
  3125. * objects in txq. This function issues an abort iocb for all the iocb commands
  3126. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3127. * the return of this function. The caller is not required to hold any locks.
  3128. **/
  3129. void
  3130. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3131. {
  3132. LIST_HEAD(completions);
  3133. struct lpfc_iocbq *iocb, *next_iocb;
  3134. if (pring->ringno == LPFC_ELS_RING) {
  3135. lpfc_fabric_abort_hba(phba);
  3136. }
  3137. /* Error everything on txq and txcmplq
  3138. * First do the txq.
  3139. */
  3140. spin_lock_irq(&phba->hbalock);
  3141. list_splice_init(&pring->txq, &completions);
  3142. pring->txq_cnt = 0;
  3143. /* Next issue ABTS for everything on the txcmplq */
  3144. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3145. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3146. spin_unlock_irq(&phba->hbalock);
  3147. /* Cancel all the IOCBs from the completions list */
  3148. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3149. IOERR_SLI_ABORTED);
  3150. }
  3151. /**
  3152. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3153. * @phba: Pointer to HBA context object.
  3154. *
  3155. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3156. * objects in txq and txcmplq. This function will not issue abort iocbs
  3157. * for all the iocb commands in txcmplq, they will just be returned with
  3158. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3159. * slot has been permanently disabled.
  3160. **/
  3161. void
  3162. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3163. {
  3164. LIST_HEAD(txq);
  3165. LIST_HEAD(txcmplq);
  3166. struct lpfc_sli *psli = &phba->sli;
  3167. struct lpfc_sli_ring *pring;
  3168. /* Currently, only one fcp ring */
  3169. pring = &psli->ring[psli->fcp_ring];
  3170. spin_lock_irq(&phba->hbalock);
  3171. /* Retrieve everything on txq */
  3172. list_splice_init(&pring->txq, &txq);
  3173. pring->txq_cnt = 0;
  3174. /* Retrieve everything on the txcmplq */
  3175. list_splice_init(&pring->txcmplq, &txcmplq);
  3176. pring->txcmplq_cnt = 0;
  3177. spin_unlock_irq(&phba->hbalock);
  3178. /* Flush the txq */
  3179. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3180. IOERR_SLI_DOWN);
  3181. /* Flush the txcmpq */
  3182. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3183. IOERR_SLI_DOWN);
  3184. }
  3185. /**
  3186. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3187. * @phba: Pointer to HBA context object.
  3188. * @mask: Bit mask to be checked.
  3189. *
  3190. * This function reads the host status register and compares
  3191. * with the provided bit mask to check if HBA completed
  3192. * the restart. This function will wait in a loop for the
  3193. * HBA to complete restart. If the HBA does not restart within
  3194. * 15 iterations, the function will reset the HBA again. The
  3195. * function returns 1 when HBA fail to restart otherwise returns
  3196. * zero.
  3197. **/
  3198. static int
  3199. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3200. {
  3201. uint32_t status;
  3202. int i = 0;
  3203. int retval = 0;
  3204. /* Read the HBA Host Status Register */
  3205. status = readl(phba->HSregaddr);
  3206. /*
  3207. * Check status register every 100ms for 5 retries, then every
  3208. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3209. * every 2.5 sec for 4.
  3210. * Break our of the loop if errors occurred during init.
  3211. */
  3212. while (((status & mask) != mask) &&
  3213. !(status & HS_FFERM) &&
  3214. i++ < 20) {
  3215. if (i <= 5)
  3216. msleep(10);
  3217. else if (i <= 10)
  3218. msleep(500);
  3219. else
  3220. msleep(2500);
  3221. if (i == 15) {
  3222. /* Do post */
  3223. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3224. lpfc_sli_brdrestart(phba);
  3225. }
  3226. /* Read the HBA Host Status Register */
  3227. status = readl(phba->HSregaddr);
  3228. }
  3229. /* Check to see if any errors occurred during init */
  3230. if ((status & HS_FFERM) || (i >= 20)) {
  3231. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3232. "2751 Adapter failed to restart, "
  3233. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3234. status,
  3235. readl(phba->MBslimaddr + 0xa8),
  3236. readl(phba->MBslimaddr + 0xac));
  3237. phba->link_state = LPFC_HBA_ERROR;
  3238. retval = 1;
  3239. }
  3240. return retval;
  3241. }
  3242. /**
  3243. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3244. * @phba: Pointer to HBA context object.
  3245. * @mask: Bit mask to be checked.
  3246. *
  3247. * This function checks the host status register to check if HBA is
  3248. * ready. This function will wait in a loop for the HBA to be ready
  3249. * If the HBA is not ready , the function will will reset the HBA PCI
  3250. * function again. The function returns 1 when HBA fail to be ready
  3251. * otherwise returns zero.
  3252. **/
  3253. static int
  3254. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3255. {
  3256. uint32_t status;
  3257. int retval = 0;
  3258. /* Read the HBA Host Status Register */
  3259. status = lpfc_sli4_post_status_check(phba);
  3260. if (status) {
  3261. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3262. lpfc_sli_brdrestart(phba);
  3263. status = lpfc_sli4_post_status_check(phba);
  3264. }
  3265. /* Check to see if any errors occurred during init */
  3266. if (status) {
  3267. phba->link_state = LPFC_HBA_ERROR;
  3268. retval = 1;
  3269. } else
  3270. phba->sli4_hba.intr_enable = 0;
  3271. return retval;
  3272. }
  3273. /**
  3274. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3275. * @phba: Pointer to HBA context object.
  3276. * @mask: Bit mask to be checked.
  3277. *
  3278. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3279. * from the API jump table function pointer from the lpfc_hba struct.
  3280. **/
  3281. int
  3282. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3283. {
  3284. return phba->lpfc_sli_brdready(phba, mask);
  3285. }
  3286. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3287. /**
  3288. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3289. * @phba: Pointer to HBA context object.
  3290. *
  3291. * This function is called before resetting an HBA. This
  3292. * function requests HBA to quiesce DMAs before a reset.
  3293. **/
  3294. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3295. {
  3296. uint32_t __iomem *resp_buf;
  3297. uint32_t __iomem *mbox_buf;
  3298. volatile uint32_t mbox;
  3299. uint32_t hc_copy;
  3300. int i;
  3301. uint8_t hdrtype;
  3302. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3303. if (hdrtype != 0x80 ||
  3304. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3305. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3306. return;
  3307. /*
  3308. * Tell the other part of the chip to suspend temporarily all
  3309. * its DMA activity.
  3310. */
  3311. resp_buf = phba->MBslimaddr;
  3312. /* Disable the error attention */
  3313. hc_copy = readl(phba->HCregaddr);
  3314. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3315. readl(phba->HCregaddr); /* flush */
  3316. phba->link_flag |= LS_IGNORE_ERATT;
  3317. if (readl(phba->HAregaddr) & HA_ERATT) {
  3318. /* Clear Chip error bit */
  3319. writel(HA_ERATT, phba->HAregaddr);
  3320. phba->pport->stopped = 1;
  3321. }
  3322. mbox = 0;
  3323. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3324. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3325. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3326. mbox_buf = phba->MBslimaddr;
  3327. writel(mbox, mbox_buf);
  3328. for (i = 0;
  3329. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  3330. mdelay(1);
  3331. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  3332. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3333. phba->pport->stopped)
  3334. goto restore_hc;
  3335. else
  3336. goto clear_errat;
  3337. }
  3338. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3339. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  3340. mdelay(1);
  3341. clear_errat:
  3342. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3343. mdelay(1);
  3344. if (readl(phba->HAregaddr) & HA_ERATT) {
  3345. writel(HA_ERATT, phba->HAregaddr);
  3346. phba->pport->stopped = 1;
  3347. }
  3348. restore_hc:
  3349. phba->link_flag &= ~LS_IGNORE_ERATT;
  3350. writel(hc_copy, phba->HCregaddr);
  3351. readl(phba->HCregaddr); /* flush */
  3352. }
  3353. /**
  3354. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3355. * @phba: Pointer to HBA context object.
  3356. *
  3357. * This function issues a kill_board mailbox command and waits for
  3358. * the error attention interrupt. This function is called for stopping
  3359. * the firmware processing. The caller is not required to hold any
  3360. * locks. This function calls lpfc_hba_down_post function to free
  3361. * any pending commands after the kill. The function will return 1 when it
  3362. * fails to kill the board else will return 0.
  3363. **/
  3364. int
  3365. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3366. {
  3367. struct lpfc_sli *psli;
  3368. LPFC_MBOXQ_t *pmb;
  3369. uint32_t status;
  3370. uint32_t ha_copy;
  3371. int retval;
  3372. int i = 0;
  3373. psli = &phba->sli;
  3374. /* Kill HBA */
  3375. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3376. "0329 Kill HBA Data: x%x x%x\n",
  3377. phba->pport->port_state, psli->sli_flag);
  3378. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3379. if (!pmb)
  3380. return 1;
  3381. /* Disable the error attention */
  3382. spin_lock_irq(&phba->hbalock);
  3383. status = readl(phba->HCregaddr);
  3384. status &= ~HC_ERINT_ENA;
  3385. writel(status, phba->HCregaddr);
  3386. readl(phba->HCregaddr); /* flush */
  3387. phba->link_flag |= LS_IGNORE_ERATT;
  3388. spin_unlock_irq(&phba->hbalock);
  3389. lpfc_kill_board(phba, pmb);
  3390. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3391. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3392. if (retval != MBX_SUCCESS) {
  3393. if (retval != MBX_BUSY)
  3394. mempool_free(pmb, phba->mbox_mem_pool);
  3395. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3396. "2752 KILL_BOARD command failed retval %d\n",
  3397. retval);
  3398. spin_lock_irq(&phba->hbalock);
  3399. phba->link_flag &= ~LS_IGNORE_ERATT;
  3400. spin_unlock_irq(&phba->hbalock);
  3401. return 1;
  3402. }
  3403. spin_lock_irq(&phba->hbalock);
  3404. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3405. spin_unlock_irq(&phba->hbalock);
  3406. mempool_free(pmb, phba->mbox_mem_pool);
  3407. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3408. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3409. * 3 seconds we still set HBA_ERROR state because the status of the
  3410. * board is now undefined.
  3411. */
  3412. ha_copy = readl(phba->HAregaddr);
  3413. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3414. mdelay(100);
  3415. ha_copy = readl(phba->HAregaddr);
  3416. }
  3417. del_timer_sync(&psli->mbox_tmo);
  3418. if (ha_copy & HA_ERATT) {
  3419. writel(HA_ERATT, phba->HAregaddr);
  3420. phba->pport->stopped = 1;
  3421. }
  3422. spin_lock_irq(&phba->hbalock);
  3423. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3424. psli->mbox_active = NULL;
  3425. phba->link_flag &= ~LS_IGNORE_ERATT;
  3426. spin_unlock_irq(&phba->hbalock);
  3427. lpfc_hba_down_post(phba);
  3428. phba->link_state = LPFC_HBA_ERROR;
  3429. return ha_copy & HA_ERATT ? 0 : 1;
  3430. }
  3431. /**
  3432. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3433. * @phba: Pointer to HBA context object.
  3434. *
  3435. * This function resets the HBA by writing HC_INITFF to the control
  3436. * register. After the HBA resets, this function resets all the iocb ring
  3437. * indices. This function disables PCI layer parity checking during
  3438. * the reset.
  3439. * This function returns 0 always.
  3440. * The caller is not required to hold any locks.
  3441. **/
  3442. int
  3443. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3444. {
  3445. struct lpfc_sli *psli;
  3446. struct lpfc_sli_ring *pring;
  3447. uint16_t cfg_value;
  3448. int i;
  3449. psli = &phba->sli;
  3450. /* Reset HBA */
  3451. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3452. "0325 Reset HBA Data: x%x x%x\n",
  3453. phba->pport->port_state, psli->sli_flag);
  3454. /* perform board reset */
  3455. phba->fc_eventTag = 0;
  3456. phba->link_events = 0;
  3457. phba->pport->fc_myDID = 0;
  3458. phba->pport->fc_prevDID = 0;
  3459. /* Turn off parity checking and serr during the physical reset */
  3460. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3461. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3462. (cfg_value &
  3463. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3464. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3465. /* Now toggle INITFF bit in the Host Control Register */
  3466. writel(HC_INITFF, phba->HCregaddr);
  3467. mdelay(1);
  3468. readl(phba->HCregaddr); /* flush */
  3469. writel(0, phba->HCregaddr);
  3470. readl(phba->HCregaddr); /* flush */
  3471. /* Restore PCI cmd register */
  3472. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3473. /* Initialize relevant SLI info */
  3474. for (i = 0; i < psli->num_rings; i++) {
  3475. pring = &psli->ring[i];
  3476. pring->flag = 0;
  3477. pring->rspidx = 0;
  3478. pring->next_cmdidx = 0;
  3479. pring->local_getidx = 0;
  3480. pring->cmdidx = 0;
  3481. pring->missbufcnt = 0;
  3482. }
  3483. phba->link_state = LPFC_WARM_START;
  3484. return 0;
  3485. }
  3486. /**
  3487. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3488. * @phba: Pointer to HBA context object.
  3489. *
  3490. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3491. * checking during resets the device. The caller is not required to hold
  3492. * any locks.
  3493. *
  3494. * This function returns 0 always.
  3495. **/
  3496. int
  3497. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3498. {
  3499. struct lpfc_sli *psli = &phba->sli;
  3500. uint16_t cfg_value;
  3501. uint8_t qindx;
  3502. /* Reset HBA */
  3503. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3504. "0295 Reset HBA Data: x%x x%x\n",
  3505. phba->pport->port_state, psli->sli_flag);
  3506. /* perform board reset */
  3507. phba->fc_eventTag = 0;
  3508. phba->link_events = 0;
  3509. phba->pport->fc_myDID = 0;
  3510. phba->pport->fc_prevDID = 0;
  3511. spin_lock_irq(&phba->hbalock);
  3512. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3513. phba->fcf.fcf_flag = 0;
  3514. /* Clean up the child queue list for the CQs */
  3515. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3516. list_del_init(&phba->sli4_hba.els_wq->list);
  3517. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3518. list_del_init(&phba->sli4_hba.dat_rq->list);
  3519. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3520. list_del_init(&phba->sli4_hba.els_cq->list);
  3521. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3522. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3523. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3524. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3525. spin_unlock_irq(&phba->hbalock);
  3526. /* Now physically reset the device */
  3527. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3528. "0389 Performing PCI function reset!\n");
  3529. /* Turn off parity checking and serr during the physical reset */
  3530. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3531. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3532. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3533. /* Perform FCoE PCI function reset */
  3534. lpfc_pci_function_reset(phba);
  3535. /* Restore PCI cmd register */
  3536. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3537. return 0;
  3538. }
  3539. /**
  3540. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3541. * @phba: Pointer to HBA context object.
  3542. *
  3543. * This function is called in the SLI initialization code path to
  3544. * restart the HBA. The caller is not required to hold any lock.
  3545. * This function writes MBX_RESTART mailbox command to the SLIM and
  3546. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3547. * function to free any pending commands. The function enables
  3548. * POST only during the first initialization. The function returns zero.
  3549. * The function does not guarantee completion of MBX_RESTART mailbox
  3550. * command before the return of this function.
  3551. **/
  3552. static int
  3553. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3554. {
  3555. MAILBOX_t *mb;
  3556. struct lpfc_sli *psli;
  3557. volatile uint32_t word0;
  3558. void __iomem *to_slim;
  3559. uint32_t hba_aer_enabled;
  3560. spin_lock_irq(&phba->hbalock);
  3561. /* Take PCIe device Advanced Error Reporting (AER) state */
  3562. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3563. psli = &phba->sli;
  3564. /* Restart HBA */
  3565. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3566. "0337 Restart HBA Data: x%x x%x\n",
  3567. phba->pport->port_state, psli->sli_flag);
  3568. word0 = 0;
  3569. mb = (MAILBOX_t *) &word0;
  3570. mb->mbxCommand = MBX_RESTART;
  3571. mb->mbxHc = 1;
  3572. lpfc_reset_barrier(phba);
  3573. to_slim = phba->MBslimaddr;
  3574. writel(*(uint32_t *) mb, to_slim);
  3575. readl(to_slim); /* flush */
  3576. /* Only skip post after fc_ffinit is completed */
  3577. if (phba->pport->port_state)
  3578. word0 = 1; /* This is really setting up word1 */
  3579. else
  3580. word0 = 0; /* This is really setting up word1 */
  3581. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3582. writel(*(uint32_t *) mb, to_slim);
  3583. readl(to_slim); /* flush */
  3584. lpfc_sli_brdreset(phba);
  3585. phba->pport->stopped = 0;
  3586. phba->link_state = LPFC_INIT_START;
  3587. phba->hba_flag = 0;
  3588. spin_unlock_irq(&phba->hbalock);
  3589. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3590. psli->stats_start = get_seconds();
  3591. /* Give the INITFF and Post time to settle. */
  3592. mdelay(100);
  3593. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3594. if (hba_aer_enabled)
  3595. pci_disable_pcie_error_reporting(phba->pcidev);
  3596. lpfc_hba_down_post(phba);
  3597. return 0;
  3598. }
  3599. /**
  3600. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3601. * @phba: Pointer to HBA context object.
  3602. *
  3603. * This function is called in the SLI initialization code path to restart
  3604. * a SLI4 HBA. The caller is not required to hold any lock.
  3605. * At the end of the function, it calls lpfc_hba_down_post function to
  3606. * free any pending commands.
  3607. **/
  3608. static int
  3609. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3610. {
  3611. struct lpfc_sli *psli = &phba->sli;
  3612. uint32_t hba_aer_enabled;
  3613. /* Restart HBA */
  3614. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3615. "0296 Restart HBA Data: x%x x%x\n",
  3616. phba->pport->port_state, psli->sli_flag);
  3617. /* Take PCIe device Advanced Error Reporting (AER) state */
  3618. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3619. lpfc_sli4_brdreset(phba);
  3620. spin_lock_irq(&phba->hbalock);
  3621. phba->pport->stopped = 0;
  3622. phba->link_state = LPFC_INIT_START;
  3623. phba->hba_flag = 0;
  3624. spin_unlock_irq(&phba->hbalock);
  3625. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3626. psli->stats_start = get_seconds();
  3627. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3628. if (hba_aer_enabled)
  3629. pci_disable_pcie_error_reporting(phba->pcidev);
  3630. lpfc_hba_down_post(phba);
  3631. return 0;
  3632. }
  3633. /**
  3634. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3635. * @phba: Pointer to HBA context object.
  3636. *
  3637. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3638. * API jump table function pointer from the lpfc_hba struct.
  3639. **/
  3640. int
  3641. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3642. {
  3643. return phba->lpfc_sli_brdrestart(phba);
  3644. }
  3645. /**
  3646. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3647. * @phba: Pointer to HBA context object.
  3648. *
  3649. * This function is called after a HBA restart to wait for successful
  3650. * restart of the HBA. Successful restart of the HBA is indicated by
  3651. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3652. * iteration, the function will restart the HBA again. The function returns
  3653. * zero if HBA successfully restarted else returns negative error code.
  3654. **/
  3655. static int
  3656. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3657. {
  3658. uint32_t status, i = 0;
  3659. /* Read the HBA Host Status Register */
  3660. status = readl(phba->HSregaddr);
  3661. /* Check status register to see what current state is */
  3662. i = 0;
  3663. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3664. /* Check every 10ms for 10 retries, then every 100ms for 90
  3665. * retries, then every 1 sec for 50 retires for a total of
  3666. * ~60 seconds before reset the board again and check every
  3667. * 1 sec for 50 retries. The up to 60 seconds before the
  3668. * board ready is required by the Falcon FIPS zeroization
  3669. * complete, and any reset the board in between shall cause
  3670. * restart of zeroization, further delay the board ready.
  3671. */
  3672. if (i++ >= 200) {
  3673. /* Adapter failed to init, timeout, status reg
  3674. <status> */
  3675. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3676. "0436 Adapter failed to init, "
  3677. "timeout, status reg x%x, "
  3678. "FW Data: A8 x%x AC x%x\n", status,
  3679. readl(phba->MBslimaddr + 0xa8),
  3680. readl(phba->MBslimaddr + 0xac));
  3681. phba->link_state = LPFC_HBA_ERROR;
  3682. return -ETIMEDOUT;
  3683. }
  3684. /* Check to see if any errors occurred during init */
  3685. if (status & HS_FFERM) {
  3686. /* ERROR: During chipset initialization */
  3687. /* Adapter failed to init, chipset, status reg
  3688. <status> */
  3689. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3690. "0437 Adapter failed to init, "
  3691. "chipset, status reg x%x, "
  3692. "FW Data: A8 x%x AC x%x\n", status,
  3693. readl(phba->MBslimaddr + 0xa8),
  3694. readl(phba->MBslimaddr + 0xac));
  3695. phba->link_state = LPFC_HBA_ERROR;
  3696. return -EIO;
  3697. }
  3698. if (i <= 10)
  3699. msleep(10);
  3700. else if (i <= 100)
  3701. msleep(100);
  3702. else
  3703. msleep(1000);
  3704. if (i == 150) {
  3705. /* Do post */
  3706. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3707. lpfc_sli_brdrestart(phba);
  3708. }
  3709. /* Read the HBA Host Status Register */
  3710. status = readl(phba->HSregaddr);
  3711. }
  3712. /* Check to see if any errors occurred during init */
  3713. if (status & HS_FFERM) {
  3714. /* ERROR: During chipset initialization */
  3715. /* Adapter failed to init, chipset, status reg <status> */
  3716. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3717. "0438 Adapter failed to init, chipset, "
  3718. "status reg x%x, "
  3719. "FW Data: A8 x%x AC x%x\n", status,
  3720. readl(phba->MBslimaddr + 0xa8),
  3721. readl(phba->MBslimaddr + 0xac));
  3722. phba->link_state = LPFC_HBA_ERROR;
  3723. return -EIO;
  3724. }
  3725. /* Clear all interrupt enable conditions */
  3726. writel(0, phba->HCregaddr);
  3727. readl(phba->HCregaddr); /* flush */
  3728. /* setup host attn register */
  3729. writel(0xffffffff, phba->HAregaddr);
  3730. readl(phba->HAregaddr); /* flush */
  3731. return 0;
  3732. }
  3733. /**
  3734. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3735. *
  3736. * This function calculates and returns the number of HBQs required to be
  3737. * configured.
  3738. **/
  3739. int
  3740. lpfc_sli_hbq_count(void)
  3741. {
  3742. return ARRAY_SIZE(lpfc_hbq_defs);
  3743. }
  3744. /**
  3745. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3746. *
  3747. * This function adds the number of hbq entries in every HBQ to get
  3748. * the total number of hbq entries required for the HBA and returns
  3749. * the total count.
  3750. **/
  3751. static int
  3752. lpfc_sli_hbq_entry_count(void)
  3753. {
  3754. int hbq_count = lpfc_sli_hbq_count();
  3755. int count = 0;
  3756. int i;
  3757. for (i = 0; i < hbq_count; ++i)
  3758. count += lpfc_hbq_defs[i]->entry_count;
  3759. return count;
  3760. }
  3761. /**
  3762. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3763. *
  3764. * This function calculates amount of memory required for all hbq entries
  3765. * to be configured and returns the total memory required.
  3766. **/
  3767. int
  3768. lpfc_sli_hbq_size(void)
  3769. {
  3770. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3771. }
  3772. /**
  3773. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3774. * @phba: Pointer to HBA context object.
  3775. *
  3776. * This function is called during the SLI initialization to configure
  3777. * all the HBQs and post buffers to the HBQ. The caller is not
  3778. * required to hold any locks. This function will return zero if successful
  3779. * else it will return negative error code.
  3780. **/
  3781. static int
  3782. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3783. {
  3784. int hbq_count = lpfc_sli_hbq_count();
  3785. LPFC_MBOXQ_t *pmb;
  3786. MAILBOX_t *pmbox;
  3787. uint32_t hbqno;
  3788. uint32_t hbq_entry_index;
  3789. /* Get a Mailbox buffer to setup mailbox
  3790. * commands for HBA initialization
  3791. */
  3792. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3793. if (!pmb)
  3794. return -ENOMEM;
  3795. pmbox = &pmb->u.mb;
  3796. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3797. phba->link_state = LPFC_INIT_MBX_CMDS;
  3798. phba->hbq_in_use = 1;
  3799. hbq_entry_index = 0;
  3800. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3801. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3802. phba->hbqs[hbqno].hbqPutIdx = 0;
  3803. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3804. phba->hbqs[hbqno].entry_count =
  3805. lpfc_hbq_defs[hbqno]->entry_count;
  3806. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3807. hbq_entry_index, pmb);
  3808. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3809. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3810. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3811. mbxStatus <status>, ring <num> */
  3812. lpfc_printf_log(phba, KERN_ERR,
  3813. LOG_SLI | LOG_VPORT,
  3814. "1805 Adapter failed to init. "
  3815. "Data: x%x x%x x%x\n",
  3816. pmbox->mbxCommand,
  3817. pmbox->mbxStatus, hbqno);
  3818. phba->link_state = LPFC_HBA_ERROR;
  3819. mempool_free(pmb, phba->mbox_mem_pool);
  3820. return -ENXIO;
  3821. }
  3822. }
  3823. phba->hbq_count = hbq_count;
  3824. mempool_free(pmb, phba->mbox_mem_pool);
  3825. /* Initially populate or replenish the HBQs */
  3826. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3827. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3828. return 0;
  3829. }
  3830. /**
  3831. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3832. * @phba: Pointer to HBA context object.
  3833. *
  3834. * This function is called during the SLI initialization to configure
  3835. * all the HBQs and post buffers to the HBQ. The caller is not
  3836. * required to hold any locks. This function will return zero if successful
  3837. * else it will return negative error code.
  3838. **/
  3839. static int
  3840. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3841. {
  3842. phba->hbq_in_use = 1;
  3843. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3844. phba->hbq_count = 1;
  3845. /* Initially populate or replenish the HBQs */
  3846. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3847. return 0;
  3848. }
  3849. /**
  3850. * lpfc_sli_config_port - Issue config port mailbox command
  3851. * @phba: Pointer to HBA context object.
  3852. * @sli_mode: sli mode - 2/3
  3853. *
  3854. * This function is called by the sli intialization code path
  3855. * to issue config_port mailbox command. This function restarts the
  3856. * HBA firmware and issues a config_port mailbox command to configure
  3857. * the SLI interface in the sli mode specified by sli_mode
  3858. * variable. The caller is not required to hold any locks.
  3859. * The function returns 0 if successful, else returns negative error
  3860. * code.
  3861. **/
  3862. int
  3863. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3864. {
  3865. LPFC_MBOXQ_t *pmb;
  3866. uint32_t resetcount = 0, rc = 0, done = 0;
  3867. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3868. if (!pmb) {
  3869. phba->link_state = LPFC_HBA_ERROR;
  3870. return -ENOMEM;
  3871. }
  3872. phba->sli_rev = sli_mode;
  3873. while (resetcount < 2 && !done) {
  3874. spin_lock_irq(&phba->hbalock);
  3875. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3876. spin_unlock_irq(&phba->hbalock);
  3877. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3878. lpfc_sli_brdrestart(phba);
  3879. rc = lpfc_sli_chipset_init(phba);
  3880. if (rc)
  3881. break;
  3882. spin_lock_irq(&phba->hbalock);
  3883. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3884. spin_unlock_irq(&phba->hbalock);
  3885. resetcount++;
  3886. /* Call pre CONFIG_PORT mailbox command initialization. A
  3887. * value of 0 means the call was successful. Any other
  3888. * nonzero value is a failure, but if ERESTART is returned,
  3889. * the driver may reset the HBA and try again.
  3890. */
  3891. rc = lpfc_config_port_prep(phba);
  3892. if (rc == -ERESTART) {
  3893. phba->link_state = LPFC_LINK_UNKNOWN;
  3894. continue;
  3895. } else if (rc)
  3896. break;
  3897. phba->link_state = LPFC_INIT_MBX_CMDS;
  3898. lpfc_config_port(phba, pmb);
  3899. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3900. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3901. LPFC_SLI3_HBQ_ENABLED |
  3902. LPFC_SLI3_CRP_ENABLED |
  3903. LPFC_SLI3_BG_ENABLED |
  3904. LPFC_SLI3_DSS_ENABLED);
  3905. if (rc != MBX_SUCCESS) {
  3906. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3907. "0442 Adapter failed to init, mbxCmd x%x "
  3908. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3909. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3910. spin_lock_irq(&phba->hbalock);
  3911. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3912. spin_unlock_irq(&phba->hbalock);
  3913. rc = -ENXIO;
  3914. } else {
  3915. /* Allow asynchronous mailbox command to go through */
  3916. spin_lock_irq(&phba->hbalock);
  3917. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3918. spin_unlock_irq(&phba->hbalock);
  3919. done = 1;
  3920. }
  3921. }
  3922. if (!done) {
  3923. rc = -EINVAL;
  3924. goto do_prep_failed;
  3925. }
  3926. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3927. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3928. rc = -ENXIO;
  3929. goto do_prep_failed;
  3930. }
  3931. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3932. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3933. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3934. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3935. phba->max_vpi : phba->max_vports;
  3936. } else
  3937. phba->max_vpi = 0;
  3938. phba->fips_level = 0;
  3939. phba->fips_spec_rev = 0;
  3940. if (pmb->u.mb.un.varCfgPort.gdss) {
  3941. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3942. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3943. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3944. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3945. "2850 Security Crypto Active. FIPS x%d "
  3946. "(Spec Rev: x%d)",
  3947. phba->fips_level, phba->fips_spec_rev);
  3948. }
  3949. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3950. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3951. "2856 Config Port Security Crypto "
  3952. "Error: x%x ",
  3953. pmb->u.mb.un.varCfgPort.sec_err);
  3954. }
  3955. if (pmb->u.mb.un.varCfgPort.gerbm)
  3956. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3957. if (pmb->u.mb.un.varCfgPort.gcrp)
  3958. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3959. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3960. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3961. if (phba->cfg_enable_bg) {
  3962. if (pmb->u.mb.un.varCfgPort.gbg)
  3963. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3964. else
  3965. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3966. "0443 Adapter did not grant "
  3967. "BlockGuard\n");
  3968. }
  3969. } else {
  3970. phba->hbq_get = NULL;
  3971. phba->port_gp = phba->mbox->us.s2.port;
  3972. phba->max_vpi = 0;
  3973. }
  3974. do_prep_failed:
  3975. mempool_free(pmb, phba->mbox_mem_pool);
  3976. return rc;
  3977. }
  3978. /**
  3979. * lpfc_sli_hba_setup - SLI intialization function
  3980. * @phba: Pointer to HBA context object.
  3981. *
  3982. * This function is the main SLI intialization function. This function
  3983. * is called by the HBA intialization code, HBA reset code and HBA
  3984. * error attention handler code. Caller is not required to hold any
  3985. * locks. This function issues config_port mailbox command to configure
  3986. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3987. * calls the config_port_post function to issue init_link mailbox
  3988. * command and to start the discovery. The function will return zero
  3989. * if successful, else it will return negative error code.
  3990. **/
  3991. int
  3992. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3993. {
  3994. uint32_t rc;
  3995. int mode = 3;
  3996. switch (lpfc_sli_mode) {
  3997. case 2:
  3998. if (phba->cfg_enable_npiv) {
  3999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4000. "1824 NPIV enabled: Override lpfc_sli_mode "
  4001. "parameter (%d) to auto (0).\n",
  4002. lpfc_sli_mode);
  4003. break;
  4004. }
  4005. mode = 2;
  4006. break;
  4007. case 0:
  4008. case 3:
  4009. break;
  4010. default:
  4011. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4012. "1819 Unrecognized lpfc_sli_mode "
  4013. "parameter: %d.\n", lpfc_sli_mode);
  4014. break;
  4015. }
  4016. rc = lpfc_sli_config_port(phba, mode);
  4017. if (rc && lpfc_sli_mode == 3)
  4018. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4019. "1820 Unable to select SLI-3. "
  4020. "Not supported by adapter.\n");
  4021. if (rc && mode != 2)
  4022. rc = lpfc_sli_config_port(phba, 2);
  4023. if (rc)
  4024. goto lpfc_sli_hba_setup_error;
  4025. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4026. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4027. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4028. if (!rc) {
  4029. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4030. "2709 This device supports "
  4031. "Advanced Error Reporting (AER)\n");
  4032. spin_lock_irq(&phba->hbalock);
  4033. phba->hba_flag |= HBA_AER_ENABLED;
  4034. spin_unlock_irq(&phba->hbalock);
  4035. } else {
  4036. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4037. "2708 This device does not support "
  4038. "Advanced Error Reporting (AER)\n");
  4039. phba->cfg_aer_support = 0;
  4040. }
  4041. }
  4042. if (phba->sli_rev == 3) {
  4043. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4044. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4045. } else {
  4046. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4047. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4048. phba->sli3_options = 0;
  4049. }
  4050. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4051. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4052. phba->sli_rev, phba->max_vpi);
  4053. rc = lpfc_sli_ring_map(phba);
  4054. if (rc)
  4055. goto lpfc_sli_hba_setup_error;
  4056. /* Init HBQs */
  4057. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4058. rc = lpfc_sli_hbq_setup(phba);
  4059. if (rc)
  4060. goto lpfc_sli_hba_setup_error;
  4061. }
  4062. spin_lock_irq(&phba->hbalock);
  4063. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4064. spin_unlock_irq(&phba->hbalock);
  4065. rc = lpfc_config_port_post(phba);
  4066. if (rc)
  4067. goto lpfc_sli_hba_setup_error;
  4068. return rc;
  4069. lpfc_sli_hba_setup_error:
  4070. phba->link_state = LPFC_HBA_ERROR;
  4071. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4072. "0445 Firmware initialization failed\n");
  4073. return rc;
  4074. }
  4075. /**
  4076. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4077. * @phba: Pointer to HBA context object.
  4078. * @mboxq: mailbox pointer.
  4079. * This function issue a dump mailbox command to read config region
  4080. * 23 and parse the records in the region and populate driver
  4081. * data structure.
  4082. **/
  4083. static int
  4084. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4085. LPFC_MBOXQ_t *mboxq)
  4086. {
  4087. struct lpfc_dmabuf *mp;
  4088. struct lpfc_mqe *mqe;
  4089. uint32_t data_length;
  4090. int rc;
  4091. /* Program the default value of vlan_id and fc_map */
  4092. phba->valid_vlan = 0;
  4093. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4094. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4095. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4096. mqe = &mboxq->u.mqe;
  4097. if (lpfc_dump_fcoe_param(phba, mboxq))
  4098. return -ENOMEM;
  4099. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4100. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4101. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4102. "(%d):2571 Mailbox cmd x%x Status x%x "
  4103. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4104. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4105. "CQ: x%x x%x x%x x%x\n",
  4106. mboxq->vport ? mboxq->vport->vpi : 0,
  4107. bf_get(lpfc_mqe_command, mqe),
  4108. bf_get(lpfc_mqe_status, mqe),
  4109. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4110. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4111. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4112. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4113. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4114. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4115. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4116. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4117. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4118. mboxq->mcqe.word0,
  4119. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4120. mboxq->mcqe.trailer);
  4121. if (rc) {
  4122. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4123. kfree(mp);
  4124. return -EIO;
  4125. }
  4126. data_length = mqe->un.mb_words[5];
  4127. if (data_length > DMP_RGN23_SIZE) {
  4128. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4129. kfree(mp);
  4130. return -EIO;
  4131. }
  4132. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4133. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4134. kfree(mp);
  4135. return 0;
  4136. }
  4137. /**
  4138. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4139. * @phba: pointer to lpfc hba data structure.
  4140. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4141. * @vpd: pointer to the memory to hold resulting port vpd data.
  4142. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4143. * On output, the number of data bytes in @vpd.
  4144. *
  4145. * This routine executes a READ_REV SLI4 mailbox command. In
  4146. * addition, this routine gets the port vpd data.
  4147. *
  4148. * Return codes
  4149. * 0 - successful
  4150. * -ENOMEM - could not allocated memory.
  4151. **/
  4152. static int
  4153. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4154. uint8_t *vpd, uint32_t *vpd_size)
  4155. {
  4156. int rc = 0;
  4157. uint32_t dma_size;
  4158. struct lpfc_dmabuf *dmabuf;
  4159. struct lpfc_mqe *mqe;
  4160. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4161. if (!dmabuf)
  4162. return -ENOMEM;
  4163. /*
  4164. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4165. * mailbox command.
  4166. */
  4167. dma_size = *vpd_size;
  4168. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4169. dma_size,
  4170. &dmabuf->phys,
  4171. GFP_KERNEL);
  4172. if (!dmabuf->virt) {
  4173. kfree(dmabuf);
  4174. return -ENOMEM;
  4175. }
  4176. memset(dmabuf->virt, 0, dma_size);
  4177. /*
  4178. * The SLI4 implementation of READ_REV conflicts at word1,
  4179. * bits 31:16 and SLI4 adds vpd functionality not present
  4180. * in SLI3. This code corrects the conflicts.
  4181. */
  4182. lpfc_read_rev(phba, mboxq);
  4183. mqe = &mboxq->u.mqe;
  4184. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4185. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4186. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4187. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4188. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4189. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4190. if (rc) {
  4191. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4192. dmabuf->virt, dmabuf->phys);
  4193. kfree(dmabuf);
  4194. return -EIO;
  4195. }
  4196. /*
  4197. * The available vpd length cannot be bigger than the
  4198. * DMA buffer passed to the port. Catch the less than
  4199. * case and update the caller's size.
  4200. */
  4201. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4202. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4203. memcpy(vpd, dmabuf->virt, *vpd_size);
  4204. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4205. dmabuf->virt, dmabuf->phys);
  4206. kfree(dmabuf);
  4207. return 0;
  4208. }
  4209. /**
  4210. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4211. * @phba: pointer to lpfc hba data structure.
  4212. *
  4213. * This routine is called to explicitly arm the SLI4 device's completion and
  4214. * event queues
  4215. **/
  4216. static void
  4217. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4218. {
  4219. uint8_t fcp_eqidx;
  4220. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4221. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4222. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4223. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4224. LPFC_QUEUE_REARM);
  4225. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4226. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4227. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4228. LPFC_QUEUE_REARM);
  4229. }
  4230. /**
  4231. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4232. * @phba: Pointer to HBA context object.
  4233. *
  4234. * This function is the main SLI4 device intialization PCI function. This
  4235. * function is called by the HBA intialization code, HBA reset code and
  4236. * HBA error attention handler code. Caller is not required to hold any
  4237. * locks.
  4238. **/
  4239. int
  4240. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4241. {
  4242. int rc;
  4243. LPFC_MBOXQ_t *mboxq;
  4244. struct lpfc_mqe *mqe;
  4245. uint8_t *vpd;
  4246. uint32_t vpd_size;
  4247. uint32_t ftr_rsp = 0;
  4248. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4249. struct lpfc_vport *vport = phba->pport;
  4250. struct lpfc_dmabuf *mp;
  4251. /* Perform a PCI function reset to start from clean */
  4252. rc = lpfc_pci_function_reset(phba);
  4253. if (unlikely(rc))
  4254. return -ENODEV;
  4255. /* Check the HBA Host Status Register for readyness */
  4256. rc = lpfc_sli4_post_status_check(phba);
  4257. if (unlikely(rc))
  4258. return -ENODEV;
  4259. else {
  4260. spin_lock_irq(&phba->hbalock);
  4261. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4262. spin_unlock_irq(&phba->hbalock);
  4263. }
  4264. /*
  4265. * Allocate a single mailbox container for initializing the
  4266. * port.
  4267. */
  4268. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4269. if (!mboxq)
  4270. return -ENOMEM;
  4271. /*
  4272. * Continue initialization with default values even if driver failed
  4273. * to read FCoE param config regions
  4274. */
  4275. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4276. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4277. "2570 Failed to read FCoE parameters\n");
  4278. /* Issue READ_REV to collect vpd and FW information. */
  4279. vpd_size = SLI4_PAGE_SIZE;
  4280. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4281. if (!vpd) {
  4282. rc = -ENOMEM;
  4283. goto out_free_mbox;
  4284. }
  4285. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4286. if (unlikely(rc)) {
  4287. kfree(vpd);
  4288. goto out_free_mbox;
  4289. }
  4290. mqe = &mboxq->u.mqe;
  4291. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4292. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4293. phba->hba_flag |= HBA_FCOE_MODE;
  4294. else
  4295. phba->hba_flag &= ~HBA_FCOE_MODE;
  4296. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4297. LPFC_DCBX_CEE_MODE)
  4298. phba->hba_flag |= HBA_FIP_SUPPORT;
  4299. else
  4300. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4301. if (phba->sli_rev != LPFC_SLI_REV4 ||
  4302. !(phba->hba_flag & HBA_FCOE_MODE)) {
  4303. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4304. "0376 READ_REV Error. SLI Level %d "
  4305. "FCoE enabled %d\n",
  4306. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4307. rc = -EIO;
  4308. kfree(vpd);
  4309. goto out_free_mbox;
  4310. }
  4311. /*
  4312. * Evaluate the read rev and vpd data. Populate the driver
  4313. * state with the results. If this routine fails, the failure
  4314. * is not fatal as the driver will use generic values.
  4315. */
  4316. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4317. if (unlikely(!rc)) {
  4318. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4319. "0377 Error %d parsing vpd. "
  4320. "Using defaults.\n", rc);
  4321. rc = 0;
  4322. }
  4323. kfree(vpd);
  4324. /* Save information as VPD data */
  4325. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4326. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4327. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4328. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4329. &mqe->un.read_rev);
  4330. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4331. &mqe->un.read_rev);
  4332. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4333. &mqe->un.read_rev);
  4334. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4335. &mqe->un.read_rev);
  4336. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4337. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4338. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4339. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4340. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4341. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4342. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4343. "(%d):0380 READ_REV Status x%x "
  4344. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4345. mboxq->vport ? mboxq->vport->vpi : 0,
  4346. bf_get(lpfc_mqe_status, mqe),
  4347. phba->vpd.rev.opFwName,
  4348. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4349. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4350. /*
  4351. * Discover the port's supported feature set and match it against the
  4352. * hosts requests.
  4353. */
  4354. lpfc_request_features(phba, mboxq);
  4355. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4356. if (unlikely(rc)) {
  4357. rc = -EIO;
  4358. goto out_free_mbox;
  4359. }
  4360. /*
  4361. * The port must support FCP initiator mode as this is the
  4362. * only mode running in the host.
  4363. */
  4364. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4365. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4366. "0378 No support for fcpi mode.\n");
  4367. ftr_rsp++;
  4368. }
  4369. /*
  4370. * If the port cannot support the host's requested features
  4371. * then turn off the global config parameters to disable the
  4372. * feature in the driver. This is not a fatal error.
  4373. */
  4374. if ((phba->cfg_enable_bg) &&
  4375. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4376. ftr_rsp++;
  4377. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4378. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4379. ftr_rsp++;
  4380. if (ftr_rsp) {
  4381. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4382. "0379 Feature Mismatch Data: x%08x %08x "
  4383. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4384. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4385. phba->cfg_enable_npiv, phba->max_vpi);
  4386. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4387. phba->cfg_enable_bg = 0;
  4388. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4389. phba->cfg_enable_npiv = 0;
  4390. }
  4391. /* These SLI3 features are assumed in SLI4 */
  4392. spin_lock_irq(&phba->hbalock);
  4393. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4394. spin_unlock_irq(&phba->hbalock);
  4395. /* Read the port's service parameters. */
  4396. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4397. if (rc) {
  4398. phba->link_state = LPFC_HBA_ERROR;
  4399. rc = -ENOMEM;
  4400. goto out_free_mbox;
  4401. }
  4402. mboxq->vport = vport;
  4403. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4404. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4405. if (rc == MBX_SUCCESS) {
  4406. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4407. rc = 0;
  4408. }
  4409. /*
  4410. * This memory was allocated by the lpfc_read_sparam routine. Release
  4411. * it to the mbuf pool.
  4412. */
  4413. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4414. kfree(mp);
  4415. mboxq->context1 = NULL;
  4416. if (unlikely(rc)) {
  4417. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4418. "0382 READ_SPARAM command failed "
  4419. "status %d, mbxStatus x%x\n",
  4420. rc, bf_get(lpfc_mqe_status, mqe));
  4421. phba->link_state = LPFC_HBA_ERROR;
  4422. rc = -EIO;
  4423. goto out_free_mbox;
  4424. }
  4425. if (phba->cfg_soft_wwnn)
  4426. u64_to_wwn(phba->cfg_soft_wwnn,
  4427. vport->fc_sparam.nodeName.u.wwn);
  4428. if (phba->cfg_soft_wwpn)
  4429. u64_to_wwn(phba->cfg_soft_wwpn,
  4430. vport->fc_sparam.portName.u.wwn);
  4431. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4432. sizeof(struct lpfc_name));
  4433. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4434. sizeof(struct lpfc_name));
  4435. /* Update the fc_host data structures with new wwn. */
  4436. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4437. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4438. /* Register SGL pool to the device using non-embedded mailbox command */
  4439. rc = lpfc_sli4_post_sgl_list(phba);
  4440. if (unlikely(rc)) {
  4441. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4442. "0582 Error %d during sgl post operation\n",
  4443. rc);
  4444. rc = -ENODEV;
  4445. goto out_free_mbox;
  4446. }
  4447. /* Register SCSI SGL pool to the device */
  4448. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4449. if (unlikely(rc)) {
  4450. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4451. "0383 Error %d during scsi sgl post "
  4452. "operation\n", rc);
  4453. /* Some Scsi buffers were moved to the abort scsi list */
  4454. /* A pci function reset will repost them */
  4455. rc = -ENODEV;
  4456. goto out_free_mbox;
  4457. }
  4458. /* Post the rpi header region to the device. */
  4459. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4460. if (unlikely(rc)) {
  4461. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4462. "0393 Error %d during rpi post operation\n",
  4463. rc);
  4464. rc = -ENODEV;
  4465. goto out_free_mbox;
  4466. }
  4467. /* Set up all the queues to the device */
  4468. rc = lpfc_sli4_queue_setup(phba);
  4469. if (unlikely(rc)) {
  4470. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4471. "0381 Error %d during queue setup.\n ", rc);
  4472. goto out_stop_timers;
  4473. }
  4474. /* Arm the CQs and then EQs on device */
  4475. lpfc_sli4_arm_cqeq_intr(phba);
  4476. /* Indicate device interrupt mode */
  4477. phba->sli4_hba.intr_enable = 1;
  4478. /* Allow asynchronous mailbox command to go through */
  4479. spin_lock_irq(&phba->hbalock);
  4480. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4481. spin_unlock_irq(&phba->hbalock);
  4482. /* Post receive buffers to the device */
  4483. lpfc_sli4_rb_setup(phba);
  4484. /* Reset HBA FCF states after HBA reset */
  4485. phba->fcf.fcf_flag = 0;
  4486. phba->fcf.current_rec.flag = 0;
  4487. /* Start the ELS watchdog timer */
  4488. mod_timer(&vport->els_tmofunc,
  4489. jiffies + HZ * (phba->fc_ratov * 2));
  4490. /* Start heart beat timer */
  4491. mod_timer(&phba->hb_tmofunc,
  4492. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4493. phba->hb_outstanding = 0;
  4494. phba->last_completion_time = jiffies;
  4495. /* Start error attention (ERATT) polling timer */
  4496. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4497. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4498. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4499. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4500. if (!rc) {
  4501. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4502. "2829 This device supports "
  4503. "Advanced Error Reporting (AER)\n");
  4504. spin_lock_irq(&phba->hbalock);
  4505. phba->hba_flag |= HBA_AER_ENABLED;
  4506. spin_unlock_irq(&phba->hbalock);
  4507. } else {
  4508. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4509. "2830 This device does not support "
  4510. "Advanced Error Reporting (AER)\n");
  4511. phba->cfg_aer_support = 0;
  4512. }
  4513. }
  4514. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4515. /*
  4516. * The FC Port needs to register FCFI (index 0)
  4517. */
  4518. lpfc_reg_fcfi(phba, mboxq);
  4519. mboxq->vport = phba->pport;
  4520. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4521. if (rc == MBX_SUCCESS)
  4522. rc = 0;
  4523. else
  4524. goto out_unset_queue;
  4525. }
  4526. /*
  4527. * The port is ready, set the host's link state to LINK_DOWN
  4528. * in preparation for link interrupts.
  4529. */
  4530. spin_lock_irq(&phba->hbalock);
  4531. phba->link_state = LPFC_LINK_DOWN;
  4532. spin_unlock_irq(&phba->hbalock);
  4533. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4534. out_unset_queue:
  4535. /* Unset all the queues set up in this routine when error out */
  4536. if (rc)
  4537. lpfc_sli4_queue_unset(phba);
  4538. out_stop_timers:
  4539. if (rc)
  4540. lpfc_stop_hba_timers(phba);
  4541. out_free_mbox:
  4542. mempool_free(mboxq, phba->mbox_mem_pool);
  4543. return rc;
  4544. }
  4545. /**
  4546. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4547. * @ptr: context object - pointer to hba structure.
  4548. *
  4549. * This is the callback function for mailbox timer. The mailbox
  4550. * timer is armed when a new mailbox command is issued and the timer
  4551. * is deleted when the mailbox complete. The function is called by
  4552. * the kernel timer code when a mailbox does not complete within
  4553. * expected time. This function wakes up the worker thread to
  4554. * process the mailbox timeout and returns. All the processing is
  4555. * done by the worker thread function lpfc_mbox_timeout_handler.
  4556. **/
  4557. void
  4558. lpfc_mbox_timeout(unsigned long ptr)
  4559. {
  4560. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4561. unsigned long iflag;
  4562. uint32_t tmo_posted;
  4563. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4564. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4565. if (!tmo_posted)
  4566. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4567. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4568. if (!tmo_posted)
  4569. lpfc_worker_wake_up(phba);
  4570. return;
  4571. }
  4572. /**
  4573. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4574. * @phba: Pointer to HBA context object.
  4575. *
  4576. * This function is called from worker thread when a mailbox command times out.
  4577. * The caller is not required to hold any locks. This function will reset the
  4578. * HBA and recover all the pending commands.
  4579. **/
  4580. void
  4581. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4582. {
  4583. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4584. MAILBOX_t *mb = &pmbox->u.mb;
  4585. struct lpfc_sli *psli = &phba->sli;
  4586. struct lpfc_sli_ring *pring;
  4587. /* Check the pmbox pointer first. There is a race condition
  4588. * between the mbox timeout handler getting executed in the
  4589. * worklist and the mailbox actually completing. When this
  4590. * race condition occurs, the mbox_active will be NULL.
  4591. */
  4592. spin_lock_irq(&phba->hbalock);
  4593. if (pmbox == NULL) {
  4594. lpfc_printf_log(phba, KERN_WARNING,
  4595. LOG_MBOX | LOG_SLI,
  4596. "0353 Active Mailbox cleared - mailbox timeout "
  4597. "exiting\n");
  4598. spin_unlock_irq(&phba->hbalock);
  4599. return;
  4600. }
  4601. /* Mbox cmd <mbxCommand> timeout */
  4602. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4603. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4604. mb->mbxCommand,
  4605. phba->pport->port_state,
  4606. phba->sli.sli_flag,
  4607. phba->sli.mbox_active);
  4608. spin_unlock_irq(&phba->hbalock);
  4609. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4610. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4611. * it to fail all oustanding SCSI IO.
  4612. */
  4613. spin_lock_irq(&phba->pport->work_port_lock);
  4614. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4615. spin_unlock_irq(&phba->pport->work_port_lock);
  4616. spin_lock_irq(&phba->hbalock);
  4617. phba->link_state = LPFC_LINK_UNKNOWN;
  4618. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4619. spin_unlock_irq(&phba->hbalock);
  4620. pring = &psli->ring[psli->fcp_ring];
  4621. lpfc_sli_abort_iocb_ring(phba, pring);
  4622. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4623. "0345 Resetting board due to mailbox timeout\n");
  4624. /* Reset the HBA device */
  4625. lpfc_reset_hba(phba);
  4626. }
  4627. /**
  4628. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4629. * @phba: Pointer to HBA context object.
  4630. * @pmbox: Pointer to mailbox object.
  4631. * @flag: Flag indicating how the mailbox need to be processed.
  4632. *
  4633. * This function is called by discovery code and HBA management code
  4634. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4635. * function gets the hbalock to protect the data structures.
  4636. * The mailbox command can be submitted in polling mode, in which case
  4637. * this function will wait in a polling loop for the completion of the
  4638. * mailbox.
  4639. * If the mailbox is submitted in no_wait mode (not polling) the
  4640. * function will submit the command and returns immediately without waiting
  4641. * for the mailbox completion. The no_wait is supported only when HBA
  4642. * is in SLI2/SLI3 mode - interrupts are enabled.
  4643. * The SLI interface allows only one mailbox pending at a time. If the
  4644. * mailbox is issued in polling mode and there is already a mailbox
  4645. * pending, then the function will return an error. If the mailbox is issued
  4646. * in NO_WAIT mode and there is a mailbox pending already, the function
  4647. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4648. * The sli layer owns the mailbox object until the completion of mailbox
  4649. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4650. * return codes the caller owns the mailbox command after the return of
  4651. * the function.
  4652. **/
  4653. static int
  4654. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4655. uint32_t flag)
  4656. {
  4657. MAILBOX_t *mb;
  4658. struct lpfc_sli *psli = &phba->sli;
  4659. uint32_t status, evtctr;
  4660. uint32_t ha_copy;
  4661. int i;
  4662. unsigned long timeout;
  4663. unsigned long drvr_flag = 0;
  4664. uint32_t word0, ldata;
  4665. void __iomem *to_slim;
  4666. int processing_queue = 0;
  4667. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4668. if (!pmbox) {
  4669. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4670. /* processing mbox queue from intr_handler */
  4671. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4672. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4673. return MBX_SUCCESS;
  4674. }
  4675. processing_queue = 1;
  4676. pmbox = lpfc_mbox_get(phba);
  4677. if (!pmbox) {
  4678. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4679. return MBX_SUCCESS;
  4680. }
  4681. }
  4682. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4683. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4684. if(!pmbox->vport) {
  4685. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4686. lpfc_printf_log(phba, KERN_ERR,
  4687. LOG_MBOX | LOG_VPORT,
  4688. "1806 Mbox x%x failed. No vport\n",
  4689. pmbox->u.mb.mbxCommand);
  4690. dump_stack();
  4691. goto out_not_finished;
  4692. }
  4693. }
  4694. /* If the PCI channel is in offline state, do not post mbox. */
  4695. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4696. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4697. goto out_not_finished;
  4698. }
  4699. /* If HBA has a deferred error attention, fail the iocb. */
  4700. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4701. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4702. goto out_not_finished;
  4703. }
  4704. psli = &phba->sli;
  4705. mb = &pmbox->u.mb;
  4706. status = MBX_SUCCESS;
  4707. if (phba->link_state == LPFC_HBA_ERROR) {
  4708. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4709. /* Mbox command <mbxCommand> cannot issue */
  4710. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4711. "(%d):0311 Mailbox command x%x cannot "
  4712. "issue Data: x%x x%x\n",
  4713. pmbox->vport ? pmbox->vport->vpi : 0,
  4714. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4715. goto out_not_finished;
  4716. }
  4717. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4718. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4719. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4720. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4721. "(%d):2528 Mailbox command x%x cannot "
  4722. "issue Data: x%x x%x\n",
  4723. pmbox->vport ? pmbox->vport->vpi : 0,
  4724. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4725. goto out_not_finished;
  4726. }
  4727. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4728. /* Polling for a mbox command when another one is already active
  4729. * is not allowed in SLI. Also, the driver must have established
  4730. * SLI2 mode to queue and process multiple mbox commands.
  4731. */
  4732. if (flag & MBX_POLL) {
  4733. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4734. /* Mbox command <mbxCommand> cannot issue */
  4735. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4736. "(%d):2529 Mailbox command x%x "
  4737. "cannot issue Data: x%x x%x\n",
  4738. pmbox->vport ? pmbox->vport->vpi : 0,
  4739. pmbox->u.mb.mbxCommand,
  4740. psli->sli_flag, flag);
  4741. goto out_not_finished;
  4742. }
  4743. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4744. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4745. /* Mbox command <mbxCommand> cannot issue */
  4746. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4747. "(%d):2530 Mailbox command x%x "
  4748. "cannot issue Data: x%x x%x\n",
  4749. pmbox->vport ? pmbox->vport->vpi : 0,
  4750. pmbox->u.mb.mbxCommand,
  4751. psli->sli_flag, flag);
  4752. goto out_not_finished;
  4753. }
  4754. /* Another mailbox command is still being processed, queue this
  4755. * command to be processed later.
  4756. */
  4757. lpfc_mbox_put(phba, pmbox);
  4758. /* Mbox cmd issue - BUSY */
  4759. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4760. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4761. "x%x x%x x%x x%x\n",
  4762. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4763. mb->mbxCommand, phba->pport->port_state,
  4764. psli->sli_flag, flag);
  4765. psli->slistat.mbox_busy++;
  4766. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4767. if (pmbox->vport) {
  4768. lpfc_debugfs_disc_trc(pmbox->vport,
  4769. LPFC_DISC_TRC_MBOX_VPORT,
  4770. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4771. (uint32_t)mb->mbxCommand,
  4772. mb->un.varWords[0], mb->un.varWords[1]);
  4773. }
  4774. else {
  4775. lpfc_debugfs_disc_trc(phba->pport,
  4776. LPFC_DISC_TRC_MBOX,
  4777. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4778. (uint32_t)mb->mbxCommand,
  4779. mb->un.varWords[0], mb->un.varWords[1]);
  4780. }
  4781. return MBX_BUSY;
  4782. }
  4783. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4784. /* If we are not polling, we MUST be in SLI2 mode */
  4785. if (flag != MBX_POLL) {
  4786. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4787. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4788. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4789. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4790. /* Mbox command <mbxCommand> cannot issue */
  4791. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4792. "(%d):2531 Mailbox command x%x "
  4793. "cannot issue Data: x%x x%x\n",
  4794. pmbox->vport ? pmbox->vport->vpi : 0,
  4795. pmbox->u.mb.mbxCommand,
  4796. psli->sli_flag, flag);
  4797. goto out_not_finished;
  4798. }
  4799. /* timeout active mbox command */
  4800. mod_timer(&psli->mbox_tmo, (jiffies +
  4801. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4802. }
  4803. /* Mailbox cmd <cmd> issue */
  4804. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4805. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4806. "x%x\n",
  4807. pmbox->vport ? pmbox->vport->vpi : 0,
  4808. mb->mbxCommand, phba->pport->port_state,
  4809. psli->sli_flag, flag);
  4810. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4811. if (pmbox->vport) {
  4812. lpfc_debugfs_disc_trc(pmbox->vport,
  4813. LPFC_DISC_TRC_MBOX_VPORT,
  4814. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4815. (uint32_t)mb->mbxCommand,
  4816. mb->un.varWords[0], mb->un.varWords[1]);
  4817. }
  4818. else {
  4819. lpfc_debugfs_disc_trc(phba->pport,
  4820. LPFC_DISC_TRC_MBOX,
  4821. "MBOX Send: cmd:x%x mb:x%x x%x",
  4822. (uint32_t)mb->mbxCommand,
  4823. mb->un.varWords[0], mb->un.varWords[1]);
  4824. }
  4825. }
  4826. psli->slistat.mbox_cmd++;
  4827. evtctr = psli->slistat.mbox_event;
  4828. /* next set own bit for the adapter and copy over command word */
  4829. mb->mbxOwner = OWN_CHIP;
  4830. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4831. /* Populate mbox extension offset word. */
  4832. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4833. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4834. = (uint8_t *)phba->mbox_ext
  4835. - (uint8_t *)phba->mbox;
  4836. }
  4837. /* Copy the mailbox extension data */
  4838. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4839. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4840. (uint8_t *)phba->mbox_ext,
  4841. pmbox->in_ext_byte_len);
  4842. }
  4843. /* Copy command data to host SLIM area */
  4844. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4845. } else {
  4846. /* Populate mbox extension offset word. */
  4847. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4848. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4849. = MAILBOX_HBA_EXT_OFFSET;
  4850. /* Copy the mailbox extension data */
  4851. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4852. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4853. MAILBOX_HBA_EXT_OFFSET,
  4854. pmbox->context2, pmbox->in_ext_byte_len);
  4855. }
  4856. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4857. /* copy command data into host mbox for cmpl */
  4858. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4859. }
  4860. /* First copy mbox command data to HBA SLIM, skip past first
  4861. word */
  4862. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4863. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4864. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4865. /* Next copy over first word, with mbxOwner set */
  4866. ldata = *((uint32_t *)mb);
  4867. to_slim = phba->MBslimaddr;
  4868. writel(ldata, to_slim);
  4869. readl(to_slim); /* flush */
  4870. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4871. /* switch over to host mailbox */
  4872. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4873. }
  4874. }
  4875. wmb();
  4876. switch (flag) {
  4877. case MBX_NOWAIT:
  4878. /* Set up reference to mailbox command */
  4879. psli->mbox_active = pmbox;
  4880. /* Interrupt board to do it */
  4881. writel(CA_MBATT, phba->CAregaddr);
  4882. readl(phba->CAregaddr); /* flush */
  4883. /* Don't wait for it to finish, just return */
  4884. break;
  4885. case MBX_POLL:
  4886. /* Set up null reference to mailbox command */
  4887. psli->mbox_active = NULL;
  4888. /* Interrupt board to do it */
  4889. writel(CA_MBATT, phba->CAregaddr);
  4890. readl(phba->CAregaddr); /* flush */
  4891. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4892. /* First read mbox status word */
  4893. word0 = *((uint32_t *)phba->mbox);
  4894. word0 = le32_to_cpu(word0);
  4895. } else {
  4896. /* First read mbox status word */
  4897. word0 = readl(phba->MBslimaddr);
  4898. }
  4899. /* Read the HBA Host Attention Register */
  4900. ha_copy = readl(phba->HAregaddr);
  4901. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4902. mb->mbxCommand) *
  4903. 1000) + jiffies;
  4904. i = 0;
  4905. /* Wait for command to complete */
  4906. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4907. (!(ha_copy & HA_MBATT) &&
  4908. (phba->link_state > LPFC_WARM_START))) {
  4909. if (time_after(jiffies, timeout)) {
  4910. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4911. spin_unlock_irqrestore(&phba->hbalock,
  4912. drvr_flag);
  4913. goto out_not_finished;
  4914. }
  4915. /* Check if we took a mbox interrupt while we were
  4916. polling */
  4917. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4918. && (evtctr != psli->slistat.mbox_event))
  4919. break;
  4920. if (i++ > 10) {
  4921. spin_unlock_irqrestore(&phba->hbalock,
  4922. drvr_flag);
  4923. msleep(1);
  4924. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4925. }
  4926. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4927. /* First copy command data */
  4928. word0 = *((uint32_t *)phba->mbox);
  4929. word0 = le32_to_cpu(word0);
  4930. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4931. MAILBOX_t *slimmb;
  4932. uint32_t slimword0;
  4933. /* Check real SLIM for any errors */
  4934. slimword0 = readl(phba->MBslimaddr);
  4935. slimmb = (MAILBOX_t *) & slimword0;
  4936. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4937. && slimmb->mbxStatus) {
  4938. psli->sli_flag &=
  4939. ~LPFC_SLI_ACTIVE;
  4940. word0 = slimword0;
  4941. }
  4942. }
  4943. } else {
  4944. /* First copy command data */
  4945. word0 = readl(phba->MBslimaddr);
  4946. }
  4947. /* Read the HBA Host Attention Register */
  4948. ha_copy = readl(phba->HAregaddr);
  4949. }
  4950. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4951. /* copy results back to user */
  4952. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4953. /* Copy the mailbox extension data */
  4954. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4955. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4956. pmbox->context2,
  4957. pmbox->out_ext_byte_len);
  4958. }
  4959. } else {
  4960. /* First copy command data */
  4961. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4962. MAILBOX_CMD_SIZE);
  4963. /* Copy the mailbox extension data */
  4964. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4965. lpfc_memcpy_from_slim(pmbox->context2,
  4966. phba->MBslimaddr +
  4967. MAILBOX_HBA_EXT_OFFSET,
  4968. pmbox->out_ext_byte_len);
  4969. }
  4970. }
  4971. writel(HA_MBATT, phba->HAregaddr);
  4972. readl(phba->HAregaddr); /* flush */
  4973. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4974. status = mb->mbxStatus;
  4975. }
  4976. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4977. return status;
  4978. out_not_finished:
  4979. if (processing_queue) {
  4980. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4981. lpfc_mbox_cmpl_put(phba, pmbox);
  4982. }
  4983. return MBX_NOT_FINISHED;
  4984. }
  4985. /**
  4986. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4987. * @phba: Pointer to HBA context object.
  4988. *
  4989. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4990. * the driver internal pending mailbox queue. It will then try to wait out the
  4991. * possible outstanding mailbox command before return.
  4992. *
  4993. * Returns:
  4994. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4995. * the outstanding mailbox command timed out.
  4996. **/
  4997. static int
  4998. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4999. {
  5000. struct lpfc_sli *psli = &phba->sli;
  5001. uint8_t actcmd = MBX_HEARTBEAT;
  5002. int rc = 0;
  5003. unsigned long timeout;
  5004. /* Mark the asynchronous mailbox command posting as blocked */
  5005. spin_lock_irq(&phba->hbalock);
  5006. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  5007. if (phba->sli.mbox_active)
  5008. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  5009. spin_unlock_irq(&phba->hbalock);
  5010. /* Determine how long we might wait for the active mailbox
  5011. * command to be gracefully completed by firmware.
  5012. */
  5013. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5014. jiffies;
  5015. /* Wait for the outstnading mailbox command to complete */
  5016. while (phba->sli.mbox_active) {
  5017. /* Check active mailbox complete status every 2ms */
  5018. msleep(2);
  5019. if (time_after(jiffies, timeout)) {
  5020. /* Timeout, marked the outstanding cmd not complete */
  5021. rc = 1;
  5022. break;
  5023. }
  5024. }
  5025. /* Can not cleanly block async mailbox command, fails it */
  5026. if (rc) {
  5027. spin_lock_irq(&phba->hbalock);
  5028. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5029. spin_unlock_irq(&phba->hbalock);
  5030. }
  5031. return rc;
  5032. }
  5033. /**
  5034. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5035. * @phba: Pointer to HBA context object.
  5036. *
  5037. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5038. * commands from the driver internal pending mailbox queue. It makes sure
  5039. * that there is no outstanding mailbox command before resuming posting
  5040. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5041. * mailbox command, it will try to wait it out before resuming asynchronous
  5042. * mailbox command posting.
  5043. **/
  5044. static void
  5045. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5046. {
  5047. struct lpfc_sli *psli = &phba->sli;
  5048. spin_lock_irq(&phba->hbalock);
  5049. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5050. /* Asynchronous mailbox posting is not blocked, do nothing */
  5051. spin_unlock_irq(&phba->hbalock);
  5052. return;
  5053. }
  5054. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5055. * successful or timeout, after timing-out the outstanding mailbox
  5056. * command shall always be removed, so just unblock posting async
  5057. * mailbox command and resume
  5058. */
  5059. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5060. spin_unlock_irq(&phba->hbalock);
  5061. /* wake up worker thread to post asynchronlous mailbox command */
  5062. lpfc_worker_wake_up(phba);
  5063. }
  5064. /**
  5065. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5066. * @phba: Pointer to HBA context object.
  5067. * @mboxq: Pointer to mailbox object.
  5068. *
  5069. * The function posts a mailbox to the port. The mailbox is expected
  5070. * to be comletely filled in and ready for the port to operate on it.
  5071. * This routine executes a synchronous completion operation on the
  5072. * mailbox by polling for its completion.
  5073. *
  5074. * The caller must not be holding any locks when calling this routine.
  5075. *
  5076. * Returns:
  5077. * MBX_SUCCESS - mailbox posted successfully
  5078. * Any of the MBX error values.
  5079. **/
  5080. static int
  5081. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5082. {
  5083. int rc = MBX_SUCCESS;
  5084. unsigned long iflag;
  5085. uint32_t db_ready;
  5086. uint32_t mcqe_status;
  5087. uint32_t mbx_cmnd;
  5088. unsigned long timeout;
  5089. struct lpfc_sli *psli = &phba->sli;
  5090. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5091. struct lpfc_bmbx_create *mbox_rgn;
  5092. struct dma_address *dma_address;
  5093. struct lpfc_register bmbx_reg;
  5094. /*
  5095. * Only one mailbox can be active to the bootstrap mailbox region
  5096. * at a time and there is no queueing provided.
  5097. */
  5098. spin_lock_irqsave(&phba->hbalock, iflag);
  5099. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5100. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5101. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5102. "(%d):2532 Mailbox command x%x (x%x) "
  5103. "cannot issue Data: x%x x%x\n",
  5104. mboxq->vport ? mboxq->vport->vpi : 0,
  5105. mboxq->u.mb.mbxCommand,
  5106. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5107. psli->sli_flag, MBX_POLL);
  5108. return MBXERR_ERROR;
  5109. }
  5110. /* The server grabs the token and owns it until release */
  5111. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5112. phba->sli.mbox_active = mboxq;
  5113. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5114. /*
  5115. * Initialize the bootstrap memory region to avoid stale data areas
  5116. * in the mailbox post. Then copy the caller's mailbox contents to
  5117. * the bmbx mailbox region.
  5118. */
  5119. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5120. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5121. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5122. sizeof(struct lpfc_mqe));
  5123. /* Post the high mailbox dma address to the port and wait for ready. */
  5124. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5125. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5126. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5127. * 1000) + jiffies;
  5128. do {
  5129. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5130. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5131. if (!db_ready)
  5132. msleep(2);
  5133. if (time_after(jiffies, timeout)) {
  5134. rc = MBXERR_ERROR;
  5135. goto exit;
  5136. }
  5137. } while (!db_ready);
  5138. /* Post the low mailbox dma address to the port. */
  5139. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5140. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5141. * 1000) + jiffies;
  5142. do {
  5143. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5144. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5145. if (!db_ready)
  5146. msleep(2);
  5147. if (time_after(jiffies, timeout)) {
  5148. rc = MBXERR_ERROR;
  5149. goto exit;
  5150. }
  5151. } while (!db_ready);
  5152. /*
  5153. * Read the CQ to ensure the mailbox has completed.
  5154. * If so, update the mailbox status so that the upper layers
  5155. * can complete the request normally.
  5156. */
  5157. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5158. sizeof(struct lpfc_mqe));
  5159. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5160. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5161. sizeof(struct lpfc_mcqe));
  5162. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5163. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  5164. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5165. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  5166. rc = MBXERR_ERROR;
  5167. } else
  5168. lpfc_sli4_swap_str(phba, mboxq);
  5169. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5170. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5171. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5172. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5173. mboxq->vport ? mboxq->vport->vpi : 0,
  5174. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5175. bf_get(lpfc_mqe_status, mb),
  5176. mb->un.mb_words[0], mb->un.mb_words[1],
  5177. mb->un.mb_words[2], mb->un.mb_words[3],
  5178. mb->un.mb_words[4], mb->un.mb_words[5],
  5179. mb->un.mb_words[6], mb->un.mb_words[7],
  5180. mb->un.mb_words[8], mb->un.mb_words[9],
  5181. mb->un.mb_words[10], mb->un.mb_words[11],
  5182. mb->un.mb_words[12], mboxq->mcqe.word0,
  5183. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5184. mboxq->mcqe.trailer);
  5185. exit:
  5186. /* We are holding the token, no needed for lock when release */
  5187. spin_lock_irqsave(&phba->hbalock, iflag);
  5188. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5189. phba->sli.mbox_active = NULL;
  5190. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5191. return rc;
  5192. }
  5193. /**
  5194. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5195. * @phba: Pointer to HBA context object.
  5196. * @pmbox: Pointer to mailbox object.
  5197. * @flag: Flag indicating how the mailbox need to be processed.
  5198. *
  5199. * This function is called by discovery code and HBA management code to submit
  5200. * a mailbox command to firmware with SLI-4 interface spec.
  5201. *
  5202. * Return codes the caller owns the mailbox command after the return of the
  5203. * function.
  5204. **/
  5205. static int
  5206. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5207. uint32_t flag)
  5208. {
  5209. struct lpfc_sli *psli = &phba->sli;
  5210. unsigned long iflags;
  5211. int rc;
  5212. rc = lpfc_mbox_dev_check(phba);
  5213. if (unlikely(rc)) {
  5214. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5215. "(%d):2544 Mailbox command x%x (x%x) "
  5216. "cannot issue Data: x%x x%x\n",
  5217. mboxq->vport ? mboxq->vport->vpi : 0,
  5218. mboxq->u.mb.mbxCommand,
  5219. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5220. psli->sli_flag, flag);
  5221. goto out_not_finished;
  5222. }
  5223. /* Detect polling mode and jump to a handler */
  5224. if (!phba->sli4_hba.intr_enable) {
  5225. if (flag == MBX_POLL)
  5226. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5227. else
  5228. rc = -EIO;
  5229. if (rc != MBX_SUCCESS)
  5230. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5231. "(%d):2541 Mailbox command x%x "
  5232. "(x%x) cannot issue Data: x%x x%x\n",
  5233. mboxq->vport ? mboxq->vport->vpi : 0,
  5234. mboxq->u.mb.mbxCommand,
  5235. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5236. psli->sli_flag, flag);
  5237. return rc;
  5238. } else if (flag == MBX_POLL) {
  5239. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5240. "(%d):2542 Try to issue mailbox command "
  5241. "x%x (x%x) synchronously ahead of async"
  5242. "mailbox command queue: x%x x%x\n",
  5243. mboxq->vport ? mboxq->vport->vpi : 0,
  5244. mboxq->u.mb.mbxCommand,
  5245. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5246. psli->sli_flag, flag);
  5247. /* Try to block the asynchronous mailbox posting */
  5248. rc = lpfc_sli4_async_mbox_block(phba);
  5249. if (!rc) {
  5250. /* Successfully blocked, now issue sync mbox cmd */
  5251. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5252. if (rc != MBX_SUCCESS)
  5253. lpfc_printf_log(phba, KERN_ERR,
  5254. LOG_MBOX | LOG_SLI,
  5255. "(%d):2597 Mailbox command "
  5256. "x%x (x%x) cannot issue "
  5257. "Data: x%x x%x\n",
  5258. mboxq->vport ?
  5259. mboxq->vport->vpi : 0,
  5260. mboxq->u.mb.mbxCommand,
  5261. lpfc_sli4_mbox_opcode_get(phba,
  5262. mboxq),
  5263. psli->sli_flag, flag);
  5264. /* Unblock the async mailbox posting afterward */
  5265. lpfc_sli4_async_mbox_unblock(phba);
  5266. }
  5267. return rc;
  5268. }
  5269. /* Now, interrupt mode asynchrous mailbox command */
  5270. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5271. if (rc) {
  5272. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5273. "(%d):2543 Mailbox command x%x (x%x) "
  5274. "cannot issue Data: x%x x%x\n",
  5275. mboxq->vport ? mboxq->vport->vpi : 0,
  5276. mboxq->u.mb.mbxCommand,
  5277. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5278. psli->sli_flag, flag);
  5279. goto out_not_finished;
  5280. }
  5281. /* Put the mailbox command to the driver internal FIFO */
  5282. psli->slistat.mbox_busy++;
  5283. spin_lock_irqsave(&phba->hbalock, iflags);
  5284. lpfc_mbox_put(phba, mboxq);
  5285. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5286. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5287. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5288. "x%x (x%x) x%x x%x x%x\n",
  5289. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5290. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5291. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5292. phba->pport->port_state,
  5293. psli->sli_flag, MBX_NOWAIT);
  5294. /* Wake up worker thread to transport mailbox command from head */
  5295. lpfc_worker_wake_up(phba);
  5296. return MBX_BUSY;
  5297. out_not_finished:
  5298. return MBX_NOT_FINISHED;
  5299. }
  5300. /**
  5301. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5302. * @phba: Pointer to HBA context object.
  5303. *
  5304. * This function is called by worker thread to send a mailbox command to
  5305. * SLI4 HBA firmware.
  5306. *
  5307. **/
  5308. int
  5309. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5310. {
  5311. struct lpfc_sli *psli = &phba->sli;
  5312. LPFC_MBOXQ_t *mboxq;
  5313. int rc = MBX_SUCCESS;
  5314. unsigned long iflags;
  5315. struct lpfc_mqe *mqe;
  5316. uint32_t mbx_cmnd;
  5317. /* Check interrupt mode before post async mailbox command */
  5318. if (unlikely(!phba->sli4_hba.intr_enable))
  5319. return MBX_NOT_FINISHED;
  5320. /* Check for mailbox command service token */
  5321. spin_lock_irqsave(&phba->hbalock, iflags);
  5322. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5323. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5324. return MBX_NOT_FINISHED;
  5325. }
  5326. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5327. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5328. return MBX_NOT_FINISHED;
  5329. }
  5330. if (unlikely(phba->sli.mbox_active)) {
  5331. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5332. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5333. "0384 There is pending active mailbox cmd\n");
  5334. return MBX_NOT_FINISHED;
  5335. }
  5336. /* Take the mailbox command service token */
  5337. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5338. /* Get the next mailbox command from head of queue */
  5339. mboxq = lpfc_mbox_get(phba);
  5340. /* If no more mailbox command waiting for post, we're done */
  5341. if (!mboxq) {
  5342. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5343. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5344. return MBX_SUCCESS;
  5345. }
  5346. phba->sli.mbox_active = mboxq;
  5347. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5348. /* Check device readiness for posting mailbox command */
  5349. rc = lpfc_mbox_dev_check(phba);
  5350. if (unlikely(rc))
  5351. /* Driver clean routine will clean up pending mailbox */
  5352. goto out_not_finished;
  5353. /* Prepare the mbox command to be posted */
  5354. mqe = &mboxq->u.mqe;
  5355. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5356. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5357. mod_timer(&psli->mbox_tmo, (jiffies +
  5358. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5359. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5360. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5361. "x%x x%x\n",
  5362. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5363. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5364. phba->pport->port_state, psli->sli_flag);
  5365. if (mbx_cmnd != MBX_HEARTBEAT) {
  5366. if (mboxq->vport) {
  5367. lpfc_debugfs_disc_trc(mboxq->vport,
  5368. LPFC_DISC_TRC_MBOX_VPORT,
  5369. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5370. mbx_cmnd, mqe->un.mb_words[0],
  5371. mqe->un.mb_words[1]);
  5372. } else {
  5373. lpfc_debugfs_disc_trc(phba->pport,
  5374. LPFC_DISC_TRC_MBOX,
  5375. "MBOX Send: cmd:x%x mb:x%x x%x",
  5376. mbx_cmnd, mqe->un.mb_words[0],
  5377. mqe->un.mb_words[1]);
  5378. }
  5379. }
  5380. psli->slistat.mbox_cmd++;
  5381. /* Post the mailbox command to the port */
  5382. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5383. if (rc != MBX_SUCCESS) {
  5384. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5385. "(%d):2533 Mailbox command x%x (x%x) "
  5386. "cannot issue Data: x%x x%x\n",
  5387. mboxq->vport ? mboxq->vport->vpi : 0,
  5388. mboxq->u.mb.mbxCommand,
  5389. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5390. psli->sli_flag, MBX_NOWAIT);
  5391. goto out_not_finished;
  5392. }
  5393. return rc;
  5394. out_not_finished:
  5395. spin_lock_irqsave(&phba->hbalock, iflags);
  5396. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5397. __lpfc_mbox_cmpl_put(phba, mboxq);
  5398. /* Release the token */
  5399. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5400. phba->sli.mbox_active = NULL;
  5401. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5402. return MBX_NOT_FINISHED;
  5403. }
  5404. /**
  5405. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5406. * @phba: Pointer to HBA context object.
  5407. * @pmbox: Pointer to mailbox object.
  5408. * @flag: Flag indicating how the mailbox need to be processed.
  5409. *
  5410. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5411. * the API jump table function pointer from the lpfc_hba struct.
  5412. *
  5413. * Return codes the caller owns the mailbox command after the return of the
  5414. * function.
  5415. **/
  5416. int
  5417. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5418. {
  5419. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5420. }
  5421. /**
  5422. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5423. * @phba: The hba struct for which this call is being executed.
  5424. * @dev_grp: The HBA PCI-Device group number.
  5425. *
  5426. * This routine sets up the mbox interface API function jump table in @phba
  5427. * struct.
  5428. * Returns: 0 - success, -ENODEV - failure.
  5429. **/
  5430. int
  5431. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5432. {
  5433. switch (dev_grp) {
  5434. case LPFC_PCI_DEV_LP:
  5435. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5436. phba->lpfc_sli_handle_slow_ring_event =
  5437. lpfc_sli_handle_slow_ring_event_s3;
  5438. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5439. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5440. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5441. break;
  5442. case LPFC_PCI_DEV_OC:
  5443. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5444. phba->lpfc_sli_handle_slow_ring_event =
  5445. lpfc_sli_handle_slow_ring_event_s4;
  5446. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5447. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5448. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5449. break;
  5450. default:
  5451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5452. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5453. dev_grp);
  5454. return -ENODEV;
  5455. break;
  5456. }
  5457. return 0;
  5458. }
  5459. /**
  5460. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5461. * @phba: Pointer to HBA context object.
  5462. * @pring: Pointer to driver SLI ring object.
  5463. * @piocb: Pointer to address of newly added command iocb.
  5464. *
  5465. * This function is called with hbalock held to add a command
  5466. * iocb to the txq when SLI layer cannot submit the command iocb
  5467. * to the ring.
  5468. **/
  5469. void
  5470. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5471. struct lpfc_iocbq *piocb)
  5472. {
  5473. /* Insert the caller's iocb in the txq tail for later processing. */
  5474. list_add_tail(&piocb->list, &pring->txq);
  5475. pring->txq_cnt++;
  5476. }
  5477. /**
  5478. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5479. * @phba: Pointer to HBA context object.
  5480. * @pring: Pointer to driver SLI ring object.
  5481. * @piocb: Pointer to address of newly added command iocb.
  5482. *
  5483. * This function is called with hbalock held before a new
  5484. * iocb is submitted to the firmware. This function checks
  5485. * txq to flush the iocbs in txq to Firmware before
  5486. * submitting new iocbs to the Firmware.
  5487. * If there are iocbs in the txq which need to be submitted
  5488. * to firmware, lpfc_sli_next_iocb returns the first element
  5489. * of the txq after dequeuing it from txq.
  5490. * If there is no iocb in the txq then the function will return
  5491. * *piocb and *piocb is set to NULL. Caller needs to check
  5492. * *piocb to find if there are more commands in the txq.
  5493. **/
  5494. static struct lpfc_iocbq *
  5495. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5496. struct lpfc_iocbq **piocb)
  5497. {
  5498. struct lpfc_iocbq * nextiocb;
  5499. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5500. if (!nextiocb) {
  5501. nextiocb = *piocb;
  5502. *piocb = NULL;
  5503. }
  5504. return nextiocb;
  5505. }
  5506. /**
  5507. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5508. * @phba: Pointer to HBA context object.
  5509. * @ring_number: SLI ring number to issue iocb on.
  5510. * @piocb: Pointer to command iocb.
  5511. * @flag: Flag indicating if this command can be put into txq.
  5512. *
  5513. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5514. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5515. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5516. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5517. * this function allows only iocbs for posting buffers. This function finds
  5518. * next available slot in the command ring and posts the command to the
  5519. * available slot and writes the port attention register to request HBA start
  5520. * processing new iocb. If there is no slot available in the ring and
  5521. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5522. * the function returns IOCB_BUSY.
  5523. *
  5524. * This function is called with hbalock held. The function will return success
  5525. * after it successfully submit the iocb to firmware or after adding to the
  5526. * txq.
  5527. **/
  5528. static int
  5529. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5530. struct lpfc_iocbq *piocb, uint32_t flag)
  5531. {
  5532. struct lpfc_iocbq *nextiocb;
  5533. IOCB_t *iocb;
  5534. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5535. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5536. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5537. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5538. lpfc_printf_log(phba, KERN_ERR,
  5539. LOG_SLI | LOG_VPORT,
  5540. "1807 IOCB x%x failed. No vport\n",
  5541. piocb->iocb.ulpCommand);
  5542. dump_stack();
  5543. return IOCB_ERROR;
  5544. }
  5545. /* If the PCI channel is in offline state, do not post iocbs. */
  5546. if (unlikely(pci_channel_offline(phba->pcidev)))
  5547. return IOCB_ERROR;
  5548. /* If HBA has a deferred error attention, fail the iocb. */
  5549. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5550. return IOCB_ERROR;
  5551. /*
  5552. * We should never get an IOCB if we are in a < LINK_DOWN state
  5553. */
  5554. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5555. return IOCB_ERROR;
  5556. /*
  5557. * Check to see if we are blocking IOCB processing because of a
  5558. * outstanding event.
  5559. */
  5560. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5561. goto iocb_busy;
  5562. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5563. /*
  5564. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5565. * can be issued if the link is not up.
  5566. */
  5567. switch (piocb->iocb.ulpCommand) {
  5568. case CMD_GEN_REQUEST64_CR:
  5569. case CMD_GEN_REQUEST64_CX:
  5570. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5571. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5572. FC_RCTL_DD_UNSOL_CMD) ||
  5573. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5574. MENLO_TRANSPORT_TYPE))
  5575. goto iocb_busy;
  5576. break;
  5577. case CMD_QUE_RING_BUF_CN:
  5578. case CMD_QUE_RING_BUF64_CN:
  5579. /*
  5580. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5581. * completion, iocb_cmpl MUST be 0.
  5582. */
  5583. if (piocb->iocb_cmpl)
  5584. piocb->iocb_cmpl = NULL;
  5585. /*FALLTHROUGH*/
  5586. case CMD_CREATE_XRI_CR:
  5587. case CMD_CLOSE_XRI_CN:
  5588. case CMD_CLOSE_XRI_CX:
  5589. break;
  5590. default:
  5591. goto iocb_busy;
  5592. }
  5593. /*
  5594. * For FCP commands, we must be in a state where we can process link
  5595. * attention events.
  5596. */
  5597. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5598. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5599. goto iocb_busy;
  5600. }
  5601. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5602. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5603. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5604. if (iocb)
  5605. lpfc_sli_update_ring(phba, pring);
  5606. else
  5607. lpfc_sli_update_full_ring(phba, pring);
  5608. if (!piocb)
  5609. return IOCB_SUCCESS;
  5610. goto out_busy;
  5611. iocb_busy:
  5612. pring->stats.iocb_cmd_delay++;
  5613. out_busy:
  5614. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5615. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5616. return IOCB_SUCCESS;
  5617. }
  5618. return IOCB_BUSY;
  5619. }
  5620. /**
  5621. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5622. * @phba: Pointer to HBA context object.
  5623. * @piocb: Pointer to command iocb.
  5624. * @sglq: Pointer to the scatter gather queue object.
  5625. *
  5626. * This routine converts the bpl or bde that is in the IOCB
  5627. * to a sgl list for the sli4 hardware. The physical address
  5628. * of the bpl/bde is converted back to a virtual address.
  5629. * If the IOCB contains a BPL then the list of BDE's is
  5630. * converted to sli4_sge's. If the IOCB contains a single
  5631. * BDE then it is converted to a single sli_sge.
  5632. * The IOCB is still in cpu endianess so the contents of
  5633. * the bpl can be used without byte swapping.
  5634. *
  5635. * Returns valid XRI = Success, NO_XRI = Failure.
  5636. **/
  5637. static uint16_t
  5638. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5639. struct lpfc_sglq *sglq)
  5640. {
  5641. uint16_t xritag = NO_XRI;
  5642. struct ulp_bde64 *bpl = NULL;
  5643. struct ulp_bde64 bde;
  5644. struct sli4_sge *sgl = NULL;
  5645. IOCB_t *icmd;
  5646. int numBdes = 0;
  5647. int i = 0;
  5648. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5649. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5650. if (!piocbq || !sglq)
  5651. return xritag;
  5652. sgl = (struct sli4_sge *)sglq->sgl;
  5653. icmd = &piocbq->iocb;
  5654. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5655. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5656. sizeof(struct ulp_bde64);
  5657. /* The addrHigh and addrLow fields within the IOCB
  5658. * have not been byteswapped yet so there is no
  5659. * need to swap them back.
  5660. */
  5661. bpl = (struct ulp_bde64 *)
  5662. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5663. if (!bpl)
  5664. return xritag;
  5665. for (i = 0; i < numBdes; i++) {
  5666. /* Should already be byte swapped. */
  5667. sgl->addr_hi = bpl->addrHigh;
  5668. sgl->addr_lo = bpl->addrLow;
  5669. if ((i+1) == numBdes)
  5670. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5671. else
  5672. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5673. sgl->word2 = cpu_to_le32(sgl->word2);
  5674. /* swap the size field back to the cpu so we
  5675. * can assign it to the sgl.
  5676. */
  5677. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5678. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5679. /* The offsets in the sgl need to be accumulated
  5680. * separately for the request and reply lists.
  5681. * The request is always first, the reply follows.
  5682. */
  5683. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5684. /* add up the reply sg entries */
  5685. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5686. inbound++;
  5687. /* first inbound? reset the offset */
  5688. if (inbound == 1)
  5689. offset = 0;
  5690. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5691. offset += bde.tus.f.bdeSize;
  5692. }
  5693. bpl++;
  5694. sgl++;
  5695. }
  5696. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5697. /* The addrHigh and addrLow fields of the BDE have not
  5698. * been byteswapped yet so they need to be swapped
  5699. * before putting them in the sgl.
  5700. */
  5701. sgl->addr_hi =
  5702. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5703. sgl->addr_lo =
  5704. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5705. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5706. sgl->word2 = cpu_to_le32(sgl->word2);
  5707. sgl->sge_len =
  5708. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5709. }
  5710. return sglq->sli4_xritag;
  5711. }
  5712. /**
  5713. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5714. * @phba: Pointer to HBA context object.
  5715. *
  5716. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5717. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5718. * held.
  5719. *
  5720. * Return: index into SLI4 fast-path FCP queue index.
  5721. **/
  5722. static uint32_t
  5723. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5724. {
  5725. ++phba->fcp_qidx;
  5726. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5727. phba->fcp_qidx = 0;
  5728. return phba->fcp_qidx;
  5729. }
  5730. /**
  5731. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5732. * @phba: Pointer to HBA context object.
  5733. * @piocb: Pointer to command iocb.
  5734. * @wqe: Pointer to the work queue entry.
  5735. *
  5736. * This routine converts the iocb command to its Work Queue Entry
  5737. * equivalent. The wqe pointer should not have any fields set when
  5738. * this routine is called because it will memcpy over them.
  5739. * This routine does not set the CQ_ID or the WQEC bits in the
  5740. * wqe.
  5741. *
  5742. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5743. **/
  5744. static int
  5745. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5746. union lpfc_wqe *wqe)
  5747. {
  5748. uint32_t xmit_len = 0, total_len = 0;
  5749. uint8_t ct = 0;
  5750. uint32_t fip;
  5751. uint32_t abort_tag;
  5752. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5753. uint8_t cmnd;
  5754. uint16_t xritag;
  5755. uint16_t abrt_iotag;
  5756. struct lpfc_iocbq *abrtiocbq;
  5757. struct ulp_bde64 *bpl = NULL;
  5758. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5759. int numBdes, i;
  5760. struct ulp_bde64 bde;
  5761. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5762. /* The fcp commands will set command type */
  5763. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5764. command_type = FCP_COMMAND;
  5765. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5766. command_type = ELS_COMMAND_FIP;
  5767. else
  5768. command_type = ELS_COMMAND_NON_FIP;
  5769. /* Some of the fields are in the right position already */
  5770. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5771. abort_tag = (uint32_t) iocbq->iotag;
  5772. xritag = iocbq->sli4_xritag;
  5773. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5774. /* words0-2 bpl convert bde */
  5775. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5776. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5777. sizeof(struct ulp_bde64);
  5778. bpl = (struct ulp_bde64 *)
  5779. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5780. if (!bpl)
  5781. return IOCB_ERROR;
  5782. /* Should already be byte swapped. */
  5783. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5784. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5785. /* swap the size field back to the cpu so we
  5786. * can assign it to the sgl.
  5787. */
  5788. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5789. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5790. total_len = 0;
  5791. for (i = 0; i < numBdes; i++) {
  5792. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5793. total_len += bde.tus.f.bdeSize;
  5794. }
  5795. } else
  5796. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5797. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5798. cmnd = iocbq->iocb.ulpCommand;
  5799. switch (iocbq->iocb.ulpCommand) {
  5800. case CMD_ELS_REQUEST64_CR:
  5801. if (!iocbq->iocb.ulpLe) {
  5802. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5803. "2007 Only Limited Edition cmd Format"
  5804. " supported 0x%x\n",
  5805. iocbq->iocb.ulpCommand);
  5806. return IOCB_ERROR;
  5807. }
  5808. wqe->els_req.payload_len = xmit_len;
  5809. /* Els_reguest64 has a TMO */
  5810. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5811. iocbq->iocb.ulpTimeout);
  5812. /* Need a VF for word 4 set the vf bit*/
  5813. bf_set(els_req64_vf, &wqe->els_req, 0);
  5814. /* And a VFID for word 12 */
  5815. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5816. /*
  5817. * Set ct field to 3, indicates that the context_tag field
  5818. * contains the FCFI and remote N_Port_ID is
  5819. * in word 5.
  5820. */
  5821. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5822. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5823. iocbq->iocb.ulpContext);
  5824. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5825. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5826. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5827. if (command_type == ELS_COMMAND_FIP) {
  5828. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5829. >> LPFC_FIP_ELS_ID_SHIFT);
  5830. }
  5831. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5832. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5833. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5834. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5835. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5836. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5837. break;
  5838. case CMD_XMIT_SEQUENCE64_CX:
  5839. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5840. iocbq->iocb.un.ulpWord[3]);
  5841. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5842. iocbq->iocb.ulpContext);
  5843. /* The entire sequence is transmitted for this IOCB */
  5844. xmit_len = total_len;
  5845. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5846. case CMD_XMIT_SEQUENCE64_CR:
  5847. /* word3 iocb=io_tag32 wqe=reserved */
  5848. wqe->xmit_sequence.rsvd3 = 0;
  5849. /* word4 relative_offset memcpy */
  5850. /* word5 r_ctl/df_ctl memcpy */
  5851. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5852. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5853. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5854. LPFC_WQE_IOD_WRITE);
  5855. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5856. LPFC_WQE_LENLOC_WORD12);
  5857. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5858. wqe->xmit_sequence.xmit_len = xmit_len;
  5859. command_type = OTHER_COMMAND;
  5860. break;
  5861. case CMD_XMIT_BCAST64_CN:
  5862. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5863. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5864. /* word4 iocb=rsvd wqe=rsvd */
  5865. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5866. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5867. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5868. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5869. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5870. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5871. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5872. LPFC_WQE_LENLOC_WORD3);
  5873. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5874. break;
  5875. case CMD_FCP_IWRITE64_CR:
  5876. command_type = FCP_COMMAND_DATA_OUT;
  5877. /* word3 iocb=iotag wqe=payload_offset_len */
  5878. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5879. wqe->fcp_iwrite.payload_offset_len =
  5880. xmit_len + sizeof(struct fcp_rsp);
  5881. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5882. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5883. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5884. iocbq->iocb.ulpFCP2Rcvy);
  5885. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5886. /* Always open the exchange */
  5887. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5888. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5889. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5890. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5891. LPFC_WQE_LENLOC_WORD4);
  5892. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5893. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5894. break;
  5895. case CMD_FCP_IREAD64_CR:
  5896. /* word3 iocb=iotag wqe=payload_offset_len */
  5897. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5898. wqe->fcp_iread.payload_offset_len =
  5899. xmit_len + sizeof(struct fcp_rsp);
  5900. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5901. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5902. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5903. iocbq->iocb.ulpFCP2Rcvy);
  5904. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5905. /* Always open the exchange */
  5906. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5907. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5908. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5909. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5910. LPFC_WQE_LENLOC_WORD4);
  5911. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5912. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5913. break;
  5914. case CMD_FCP_ICMND64_CR:
  5915. /* word3 iocb=IO_TAG wqe=reserved */
  5916. wqe->fcp_icmd.rsrvd3 = 0;
  5917. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5918. /* Always open the exchange */
  5919. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5920. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5921. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5922. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5923. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5924. LPFC_WQE_LENLOC_NONE);
  5925. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5926. break;
  5927. case CMD_GEN_REQUEST64_CR:
  5928. /* For this command calculate the xmit length of the
  5929. * request bde.
  5930. */
  5931. xmit_len = 0;
  5932. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5933. sizeof(struct ulp_bde64);
  5934. for (i = 0; i < numBdes; i++) {
  5935. if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5936. break;
  5937. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5938. xmit_len += bde.tus.f.bdeSize;
  5939. }
  5940. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5941. wqe->gen_req.request_payload_len = xmit_len;
  5942. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5943. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5944. /* word6 context tag copied in memcpy */
  5945. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5946. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5947. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5948. "2015 Invalid CT %x command 0x%x\n",
  5949. ct, iocbq->iocb.ulpCommand);
  5950. return IOCB_ERROR;
  5951. }
  5952. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5953. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5954. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5955. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5956. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5957. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5958. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5959. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5960. command_type = OTHER_COMMAND;
  5961. break;
  5962. case CMD_XMIT_ELS_RSP64_CX:
  5963. /* words0-2 BDE memcpy */
  5964. /* word3 iocb=iotag32 wqe=response_payload_len */
  5965. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  5966. /* word4 iocb=did wge=rsvd. */
  5967. wqe->xmit_els_rsp.rsvd4 = 0;
  5968. /* word5 iocb=rsvd wge=did */
  5969. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5970. iocbq->iocb.un.elsreq64.remoteID);
  5971. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  5972. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5973. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  5974. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5975. iocbq->iocb.ulpContext);
  5976. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5977. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5978. iocbq->vport->vpi + phba->vpi_base);
  5979. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  5980. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  5981. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  5982. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  5983. LPFC_WQE_LENLOC_WORD3);
  5984. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  5985. command_type = OTHER_COMMAND;
  5986. break;
  5987. case CMD_CLOSE_XRI_CN:
  5988. case CMD_ABORT_XRI_CN:
  5989. case CMD_ABORT_XRI_CX:
  5990. /* words 0-2 memcpy should be 0 rserved */
  5991. /* port will send abts */
  5992. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  5993. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  5994. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  5995. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  5996. } else
  5997. fip = 0;
  5998. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  5999. /*
  6000. * The link is down, or the command was ELS_FIP
  6001. * so the fw does not need to send abts
  6002. * on the wire.
  6003. */
  6004. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  6005. else
  6006. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  6007. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  6008. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  6009. wqe->abort_cmd.rsrvd5 = 0;
  6010. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  6011. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6012. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  6013. /*
  6014. * The abort handler will send us CMD_ABORT_XRI_CN or
  6015. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6016. */
  6017. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6018. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6019. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6020. LPFC_WQE_LENLOC_NONE);
  6021. cmnd = CMD_ABORT_XRI_CX;
  6022. command_type = OTHER_COMMAND;
  6023. xritag = 0;
  6024. break;
  6025. case CMD_XMIT_BLS_RSP64_CX:
  6026. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  6027. * we re-construct this WQE here based on information in
  6028. * iocbq from scratch.
  6029. */
  6030. memset(wqe, 0, sizeof(union lpfc_wqe));
  6031. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6032. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6033. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  6034. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  6035. LPFC_ABTS_UNSOL_INT) {
  6036. /* ABTS sent by initiator to CT exchange, the
  6037. * RX_ID field will be filled with the newly
  6038. * allocated responder XRI.
  6039. */
  6040. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6041. iocbq->sli4_xritag);
  6042. } else {
  6043. /* ABTS sent by responder to CT exchange, the
  6044. * RX_ID field will be filled with the responder
  6045. * RX_ID from ABTS.
  6046. */
  6047. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6048. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  6049. }
  6050. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6051. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6052. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6053. iocbq->iocb.ulpContext);
  6054. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6055. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6056. LPFC_WQE_LENLOC_NONE);
  6057. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6058. command_type = OTHER_COMMAND;
  6059. break;
  6060. case CMD_XRI_ABORTED_CX:
  6061. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6062. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6063. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6064. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6065. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6066. default:
  6067. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6068. "2014 Invalid command 0x%x\n",
  6069. iocbq->iocb.ulpCommand);
  6070. return IOCB_ERROR;
  6071. break;
  6072. }
  6073. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6074. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6075. wqe->generic.wqe_com.abort_tag = abort_tag;
  6076. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6077. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6078. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6079. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6080. return 0;
  6081. }
  6082. /**
  6083. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6084. * @phba: Pointer to HBA context object.
  6085. * @ring_number: SLI ring number to issue iocb on.
  6086. * @piocb: Pointer to command iocb.
  6087. * @flag: Flag indicating if this command can be put into txq.
  6088. *
  6089. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6090. * an iocb command to an HBA with SLI-4 interface spec.
  6091. *
  6092. * This function is called with hbalock held. The function will return success
  6093. * after it successfully submit the iocb to firmware or after adding to the
  6094. * txq.
  6095. **/
  6096. static int
  6097. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6098. struct lpfc_iocbq *piocb, uint32_t flag)
  6099. {
  6100. struct lpfc_sglq *sglq;
  6101. union lpfc_wqe wqe;
  6102. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6103. if (piocb->sli4_xritag == NO_XRI) {
  6104. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6105. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  6106. sglq = NULL;
  6107. else {
  6108. if (pring->txq_cnt) {
  6109. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6110. __lpfc_sli_ringtx_put(phba,
  6111. pring, piocb);
  6112. return IOCB_SUCCESS;
  6113. } else {
  6114. return IOCB_BUSY;
  6115. }
  6116. } else {
  6117. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6118. if (!sglq) {
  6119. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6120. __lpfc_sli_ringtx_put(phba,
  6121. pring,
  6122. piocb);
  6123. return IOCB_SUCCESS;
  6124. } else
  6125. return IOCB_BUSY;
  6126. }
  6127. }
  6128. }
  6129. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6130. sglq = NULL; /* These IO's already have an XRI and
  6131. * a mapped sgl.
  6132. */
  6133. } else {
  6134. /* This is a continuation of a commandi,(CX) so this
  6135. * sglq is on the active list
  6136. */
  6137. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6138. if (!sglq)
  6139. return IOCB_ERROR;
  6140. }
  6141. if (sglq) {
  6142. piocb->sli4_xritag = sglq->sli4_xritag;
  6143. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6144. return IOCB_ERROR;
  6145. }
  6146. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6147. return IOCB_ERROR;
  6148. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6149. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6150. /*
  6151. * For FCP command IOCB, get a new WQ index to distribute
  6152. * WQE across the WQsr. On the other hand, for abort IOCB,
  6153. * it carries the same WQ index to the original command
  6154. * IOCB.
  6155. */
  6156. if (piocb->iocb_flag & LPFC_IO_FCP)
  6157. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6158. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6159. &wqe))
  6160. return IOCB_ERROR;
  6161. } else {
  6162. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6163. return IOCB_ERROR;
  6164. }
  6165. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6166. return 0;
  6167. }
  6168. /**
  6169. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6170. *
  6171. * This routine wraps the actual lockless version for issusing IOCB function
  6172. * pointer from the lpfc_hba struct.
  6173. *
  6174. * Return codes:
  6175. * IOCB_ERROR - Error
  6176. * IOCB_SUCCESS - Success
  6177. * IOCB_BUSY - Busy
  6178. **/
  6179. int
  6180. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6181. struct lpfc_iocbq *piocb, uint32_t flag)
  6182. {
  6183. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6184. }
  6185. /**
  6186. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  6187. * @phba: The hba struct for which this call is being executed.
  6188. * @dev_grp: The HBA PCI-Device group number.
  6189. *
  6190. * This routine sets up the SLI interface API function jump table in @phba
  6191. * struct.
  6192. * Returns: 0 - success, -ENODEV - failure.
  6193. **/
  6194. int
  6195. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6196. {
  6197. switch (dev_grp) {
  6198. case LPFC_PCI_DEV_LP:
  6199. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6200. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6201. break;
  6202. case LPFC_PCI_DEV_OC:
  6203. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6204. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6205. break;
  6206. default:
  6207. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6208. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6209. dev_grp);
  6210. return -ENODEV;
  6211. break;
  6212. }
  6213. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6214. return 0;
  6215. }
  6216. /**
  6217. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6218. * @phba: Pointer to HBA context object.
  6219. * @pring: Pointer to driver SLI ring object.
  6220. * @piocb: Pointer to command iocb.
  6221. * @flag: Flag indicating if this command can be put into txq.
  6222. *
  6223. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6224. * function. This function gets the hbalock and calls
  6225. * __lpfc_sli_issue_iocb function and will return the error returned
  6226. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6227. * functions which do not hold hbalock.
  6228. **/
  6229. int
  6230. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6231. struct lpfc_iocbq *piocb, uint32_t flag)
  6232. {
  6233. unsigned long iflags;
  6234. int rc;
  6235. spin_lock_irqsave(&phba->hbalock, iflags);
  6236. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6237. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6238. return rc;
  6239. }
  6240. /**
  6241. * lpfc_extra_ring_setup - Extra ring setup function
  6242. * @phba: Pointer to HBA context object.
  6243. *
  6244. * This function is called while driver attaches with the
  6245. * HBA to setup the extra ring. The extra ring is used
  6246. * only when driver needs to support target mode functionality
  6247. * or IP over FC functionalities.
  6248. *
  6249. * This function is called with no lock held.
  6250. **/
  6251. static int
  6252. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6253. {
  6254. struct lpfc_sli *psli;
  6255. struct lpfc_sli_ring *pring;
  6256. psli = &phba->sli;
  6257. /* Adjust cmd/rsp ring iocb entries more evenly */
  6258. /* Take some away from the FCP ring */
  6259. pring = &psli->ring[psli->fcp_ring];
  6260. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6261. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6262. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6263. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6264. /* and give them to the extra ring */
  6265. pring = &psli->ring[psli->extra_ring];
  6266. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6267. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6268. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6269. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6270. /* Setup default profile for this ring */
  6271. pring->iotag_max = 4096;
  6272. pring->num_mask = 1;
  6273. pring->prt[0].profile = 0; /* Mask 0 */
  6274. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6275. pring->prt[0].type = phba->cfg_multi_ring_type;
  6276. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6277. return 0;
  6278. }
  6279. /**
  6280. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6281. * @phba: Pointer to HBA context object.
  6282. * @pring: Pointer to driver SLI ring object.
  6283. * @iocbq: Pointer to iocb object.
  6284. *
  6285. * This function is called by the slow ring event handler
  6286. * function when there is an ASYNC event iocb in the ring.
  6287. * This function is called with no lock held.
  6288. * Currently this function handles only temperature related
  6289. * ASYNC events. The function decodes the temperature sensor
  6290. * event message and posts events for the management applications.
  6291. **/
  6292. static void
  6293. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6294. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6295. {
  6296. IOCB_t *icmd;
  6297. uint16_t evt_code;
  6298. uint16_t temp;
  6299. struct temp_event temp_event_data;
  6300. struct Scsi_Host *shost;
  6301. uint32_t *iocb_w;
  6302. icmd = &iocbq->iocb;
  6303. evt_code = icmd->un.asyncstat.evt_code;
  6304. temp = icmd->ulpContext;
  6305. if ((evt_code != ASYNC_TEMP_WARN) &&
  6306. (evt_code != ASYNC_TEMP_SAFE)) {
  6307. iocb_w = (uint32_t *) icmd;
  6308. lpfc_printf_log(phba,
  6309. KERN_ERR,
  6310. LOG_SLI,
  6311. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6312. " evt_code 0x%x\n"
  6313. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6314. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6315. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6316. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6317. pring->ringno,
  6318. icmd->un.asyncstat.evt_code,
  6319. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6320. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6321. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6322. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6323. return;
  6324. }
  6325. temp_event_data.data = (uint32_t)temp;
  6326. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6327. if (evt_code == ASYNC_TEMP_WARN) {
  6328. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6329. lpfc_printf_log(phba,
  6330. KERN_ERR,
  6331. LOG_TEMP,
  6332. "0347 Adapter is very hot, please take "
  6333. "corrective action. temperature : %d Celsius\n",
  6334. temp);
  6335. }
  6336. if (evt_code == ASYNC_TEMP_SAFE) {
  6337. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6338. lpfc_printf_log(phba,
  6339. KERN_ERR,
  6340. LOG_TEMP,
  6341. "0340 Adapter temperature is OK now. "
  6342. "temperature : %d Celsius\n",
  6343. temp);
  6344. }
  6345. /* Send temperature change event to applications */
  6346. shost = lpfc_shost_from_vport(phba->pport);
  6347. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6348. sizeof(temp_event_data), (char *) &temp_event_data,
  6349. LPFC_NL_VENDOR_ID);
  6350. }
  6351. /**
  6352. * lpfc_sli_setup - SLI ring setup function
  6353. * @phba: Pointer to HBA context object.
  6354. *
  6355. * lpfc_sli_setup sets up rings of the SLI interface with
  6356. * number of iocbs per ring and iotags. This function is
  6357. * called while driver attach to the HBA and before the
  6358. * interrupts are enabled. So there is no need for locking.
  6359. *
  6360. * This function always returns 0.
  6361. **/
  6362. int
  6363. lpfc_sli_setup(struct lpfc_hba *phba)
  6364. {
  6365. int i, totiocbsize = 0;
  6366. struct lpfc_sli *psli = &phba->sli;
  6367. struct lpfc_sli_ring *pring;
  6368. psli->num_rings = MAX_CONFIGURED_RINGS;
  6369. psli->sli_flag = 0;
  6370. psli->fcp_ring = LPFC_FCP_RING;
  6371. psli->next_ring = LPFC_FCP_NEXT_RING;
  6372. psli->extra_ring = LPFC_EXTRA_RING;
  6373. psli->iocbq_lookup = NULL;
  6374. psli->iocbq_lookup_len = 0;
  6375. psli->last_iotag = 0;
  6376. for (i = 0; i < psli->num_rings; i++) {
  6377. pring = &psli->ring[i];
  6378. switch (i) {
  6379. case LPFC_FCP_RING: /* ring 0 - FCP */
  6380. /* numCiocb and numRiocb are used in config_port */
  6381. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6382. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6383. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6384. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6385. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6386. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6387. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6388. SLI3_IOCB_CMD_SIZE :
  6389. SLI2_IOCB_CMD_SIZE;
  6390. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6391. SLI3_IOCB_RSP_SIZE :
  6392. SLI2_IOCB_RSP_SIZE;
  6393. pring->iotag_ctr = 0;
  6394. pring->iotag_max =
  6395. (phba->cfg_hba_queue_depth * 2);
  6396. pring->fast_iotag = pring->iotag_max;
  6397. pring->num_mask = 0;
  6398. break;
  6399. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6400. /* numCiocb and numRiocb are used in config_port */
  6401. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6402. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6403. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6404. SLI3_IOCB_CMD_SIZE :
  6405. SLI2_IOCB_CMD_SIZE;
  6406. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6407. SLI3_IOCB_RSP_SIZE :
  6408. SLI2_IOCB_RSP_SIZE;
  6409. pring->iotag_max = phba->cfg_hba_queue_depth;
  6410. pring->num_mask = 0;
  6411. break;
  6412. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6413. /* numCiocb and numRiocb are used in config_port */
  6414. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6415. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6416. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6417. SLI3_IOCB_CMD_SIZE :
  6418. SLI2_IOCB_CMD_SIZE;
  6419. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6420. SLI3_IOCB_RSP_SIZE :
  6421. SLI2_IOCB_RSP_SIZE;
  6422. pring->fast_iotag = 0;
  6423. pring->iotag_ctr = 0;
  6424. pring->iotag_max = 4096;
  6425. pring->lpfc_sli_rcv_async_status =
  6426. lpfc_sli_async_event_handler;
  6427. pring->num_mask = LPFC_MAX_RING_MASK;
  6428. pring->prt[0].profile = 0; /* Mask 0 */
  6429. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6430. pring->prt[0].type = FC_TYPE_ELS;
  6431. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6432. lpfc_els_unsol_event;
  6433. pring->prt[1].profile = 0; /* Mask 1 */
  6434. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6435. pring->prt[1].type = FC_TYPE_ELS;
  6436. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6437. lpfc_els_unsol_event;
  6438. pring->prt[2].profile = 0; /* Mask 2 */
  6439. /* NameServer Inquiry */
  6440. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6441. /* NameServer */
  6442. pring->prt[2].type = FC_TYPE_CT;
  6443. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6444. lpfc_ct_unsol_event;
  6445. pring->prt[3].profile = 0; /* Mask 3 */
  6446. /* NameServer response */
  6447. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6448. /* NameServer */
  6449. pring->prt[3].type = FC_TYPE_CT;
  6450. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6451. lpfc_ct_unsol_event;
  6452. /* abort unsolicited sequence */
  6453. pring->prt[4].profile = 0; /* Mask 4 */
  6454. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6455. pring->prt[4].type = FC_TYPE_BLS;
  6456. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6457. lpfc_sli4_ct_abort_unsol_event;
  6458. break;
  6459. }
  6460. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6461. (pring->numRiocb * pring->sizeRiocb);
  6462. }
  6463. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6464. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6465. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6466. "SLI2 SLIM Data: x%x x%lx\n",
  6467. phba->brd_no, totiocbsize,
  6468. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6469. }
  6470. if (phba->cfg_multi_ring_support == 2)
  6471. lpfc_extra_ring_setup(phba);
  6472. return 0;
  6473. }
  6474. /**
  6475. * lpfc_sli_queue_setup - Queue initialization function
  6476. * @phba: Pointer to HBA context object.
  6477. *
  6478. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6479. * ring. This function also initializes ring indices of each ring.
  6480. * This function is called during the initialization of the SLI
  6481. * interface of an HBA.
  6482. * This function is called with no lock held and always returns
  6483. * 1.
  6484. **/
  6485. int
  6486. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6487. {
  6488. struct lpfc_sli *psli;
  6489. struct lpfc_sli_ring *pring;
  6490. int i;
  6491. psli = &phba->sli;
  6492. spin_lock_irq(&phba->hbalock);
  6493. INIT_LIST_HEAD(&psli->mboxq);
  6494. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6495. /* Initialize list headers for txq and txcmplq as double linked lists */
  6496. for (i = 0; i < psli->num_rings; i++) {
  6497. pring = &psli->ring[i];
  6498. pring->ringno = i;
  6499. pring->next_cmdidx = 0;
  6500. pring->local_getidx = 0;
  6501. pring->cmdidx = 0;
  6502. INIT_LIST_HEAD(&pring->txq);
  6503. INIT_LIST_HEAD(&pring->txcmplq);
  6504. INIT_LIST_HEAD(&pring->iocb_continueq);
  6505. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6506. INIT_LIST_HEAD(&pring->postbufq);
  6507. }
  6508. spin_unlock_irq(&phba->hbalock);
  6509. return 1;
  6510. }
  6511. /**
  6512. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6513. * @phba: Pointer to HBA context object.
  6514. *
  6515. * This routine flushes the mailbox command subsystem. It will unconditionally
  6516. * flush all the mailbox commands in the three possible stages in the mailbox
  6517. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6518. * command; and completed mailbox command queue. It is caller's responsibility
  6519. * to make sure that the driver is in the proper state to flush the mailbox
  6520. * command sub-system. Namely, the posting of mailbox commands into the
  6521. * pending mailbox command queue from the various clients must be stopped;
  6522. * either the HBA is in a state that it will never works on the outstanding
  6523. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6524. * mailbox command has been completed.
  6525. **/
  6526. static void
  6527. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6528. {
  6529. LIST_HEAD(completions);
  6530. struct lpfc_sli *psli = &phba->sli;
  6531. LPFC_MBOXQ_t *pmb;
  6532. unsigned long iflag;
  6533. /* Flush all the mailbox commands in the mbox system */
  6534. spin_lock_irqsave(&phba->hbalock, iflag);
  6535. /* The pending mailbox command queue */
  6536. list_splice_init(&phba->sli.mboxq, &completions);
  6537. /* The outstanding active mailbox command */
  6538. if (psli->mbox_active) {
  6539. list_add_tail(&psli->mbox_active->list, &completions);
  6540. psli->mbox_active = NULL;
  6541. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6542. }
  6543. /* The completed mailbox command queue */
  6544. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6545. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6546. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6547. while (!list_empty(&completions)) {
  6548. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6549. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6550. if (pmb->mbox_cmpl)
  6551. pmb->mbox_cmpl(phba, pmb);
  6552. }
  6553. }
  6554. /**
  6555. * lpfc_sli_host_down - Vport cleanup function
  6556. * @vport: Pointer to virtual port object.
  6557. *
  6558. * lpfc_sli_host_down is called to clean up the resources
  6559. * associated with a vport before destroying virtual
  6560. * port data structures.
  6561. * This function does following operations:
  6562. * - Free discovery resources associated with this virtual
  6563. * port.
  6564. * - Free iocbs associated with this virtual port in
  6565. * the txq.
  6566. * - Send abort for all iocb commands associated with this
  6567. * vport in txcmplq.
  6568. *
  6569. * This function is called with no lock held and always returns 1.
  6570. **/
  6571. int
  6572. lpfc_sli_host_down(struct lpfc_vport *vport)
  6573. {
  6574. LIST_HEAD(completions);
  6575. struct lpfc_hba *phba = vport->phba;
  6576. struct lpfc_sli *psli = &phba->sli;
  6577. struct lpfc_sli_ring *pring;
  6578. struct lpfc_iocbq *iocb, *next_iocb;
  6579. int i;
  6580. unsigned long flags = 0;
  6581. uint16_t prev_pring_flag;
  6582. lpfc_cleanup_discovery_resources(vport);
  6583. spin_lock_irqsave(&phba->hbalock, flags);
  6584. for (i = 0; i < psli->num_rings; i++) {
  6585. pring = &psli->ring[i];
  6586. prev_pring_flag = pring->flag;
  6587. /* Only slow rings */
  6588. if (pring->ringno == LPFC_ELS_RING) {
  6589. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6590. /* Set the lpfc data pending flag */
  6591. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6592. }
  6593. /*
  6594. * Error everything on the txq since these iocbs have not been
  6595. * given to the FW yet.
  6596. */
  6597. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6598. if (iocb->vport != vport)
  6599. continue;
  6600. list_move_tail(&iocb->list, &completions);
  6601. pring->txq_cnt--;
  6602. }
  6603. /* Next issue ABTS for everything on the txcmplq */
  6604. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6605. list) {
  6606. if (iocb->vport != vport)
  6607. continue;
  6608. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6609. }
  6610. pring->flag = prev_pring_flag;
  6611. }
  6612. spin_unlock_irqrestore(&phba->hbalock, flags);
  6613. /* Cancel all the IOCBs from the completions list */
  6614. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6615. IOERR_SLI_DOWN);
  6616. return 1;
  6617. }
  6618. /**
  6619. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6620. * @phba: Pointer to HBA context object.
  6621. *
  6622. * This function cleans up all iocb, buffers, mailbox commands
  6623. * while shutting down the HBA. This function is called with no
  6624. * lock held and always returns 1.
  6625. * This function does the following to cleanup driver resources:
  6626. * - Free discovery resources for each virtual port
  6627. * - Cleanup any pending fabric iocbs
  6628. * - Iterate through the iocb txq and free each entry
  6629. * in the list.
  6630. * - Free up any buffer posted to the HBA
  6631. * - Free mailbox commands in the mailbox queue.
  6632. **/
  6633. int
  6634. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6635. {
  6636. LIST_HEAD(completions);
  6637. struct lpfc_sli *psli = &phba->sli;
  6638. struct lpfc_sli_ring *pring;
  6639. struct lpfc_dmabuf *buf_ptr;
  6640. unsigned long flags = 0;
  6641. int i;
  6642. /* Shutdown the mailbox command sub-system */
  6643. lpfc_sli_mbox_sys_shutdown(phba);
  6644. lpfc_hba_down_prep(phba);
  6645. lpfc_fabric_abort_hba(phba);
  6646. spin_lock_irqsave(&phba->hbalock, flags);
  6647. for (i = 0; i < psli->num_rings; i++) {
  6648. pring = &psli->ring[i];
  6649. /* Only slow rings */
  6650. if (pring->ringno == LPFC_ELS_RING) {
  6651. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6652. /* Set the lpfc data pending flag */
  6653. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6654. }
  6655. /*
  6656. * Error everything on the txq since these iocbs have not been
  6657. * given to the FW yet.
  6658. */
  6659. list_splice_init(&pring->txq, &completions);
  6660. pring->txq_cnt = 0;
  6661. }
  6662. spin_unlock_irqrestore(&phba->hbalock, flags);
  6663. /* Cancel all the IOCBs from the completions list */
  6664. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6665. IOERR_SLI_DOWN);
  6666. spin_lock_irqsave(&phba->hbalock, flags);
  6667. list_splice_init(&phba->elsbuf, &completions);
  6668. phba->elsbuf_cnt = 0;
  6669. phba->elsbuf_prev_cnt = 0;
  6670. spin_unlock_irqrestore(&phba->hbalock, flags);
  6671. while (!list_empty(&completions)) {
  6672. list_remove_head(&completions, buf_ptr,
  6673. struct lpfc_dmabuf, list);
  6674. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6675. kfree(buf_ptr);
  6676. }
  6677. /* Return any active mbox cmds */
  6678. del_timer_sync(&psli->mbox_tmo);
  6679. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6680. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6681. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6682. return 1;
  6683. }
  6684. /**
  6685. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6686. * @srcp: Source memory pointer.
  6687. * @destp: Destination memory pointer.
  6688. * @cnt: Number of words required to be copied.
  6689. *
  6690. * This function is used for copying data between driver memory
  6691. * and the SLI memory. This function also changes the endianness
  6692. * of each word if native endianness is different from SLI
  6693. * endianness. This function can be called with or without
  6694. * lock.
  6695. **/
  6696. void
  6697. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6698. {
  6699. uint32_t *src = srcp;
  6700. uint32_t *dest = destp;
  6701. uint32_t ldata;
  6702. int i;
  6703. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6704. ldata = *src;
  6705. ldata = le32_to_cpu(ldata);
  6706. *dest = ldata;
  6707. src++;
  6708. dest++;
  6709. }
  6710. }
  6711. /**
  6712. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6713. * @srcp: Source memory pointer.
  6714. * @destp: Destination memory pointer.
  6715. * @cnt: Number of words required to be copied.
  6716. *
  6717. * This function is used for copying data between a data structure
  6718. * with big endian representation to local endianness.
  6719. * This function can be called with or without lock.
  6720. **/
  6721. void
  6722. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6723. {
  6724. uint32_t *src = srcp;
  6725. uint32_t *dest = destp;
  6726. uint32_t ldata;
  6727. int i;
  6728. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6729. ldata = *src;
  6730. ldata = be32_to_cpu(ldata);
  6731. *dest = ldata;
  6732. src++;
  6733. dest++;
  6734. }
  6735. }
  6736. /**
  6737. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6738. * @phba: Pointer to HBA context object.
  6739. * @pring: Pointer to driver SLI ring object.
  6740. * @mp: Pointer to driver buffer object.
  6741. *
  6742. * This function is called with no lock held.
  6743. * It always return zero after adding the buffer to the postbufq
  6744. * buffer list.
  6745. **/
  6746. int
  6747. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6748. struct lpfc_dmabuf *mp)
  6749. {
  6750. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6751. later */
  6752. spin_lock_irq(&phba->hbalock);
  6753. list_add_tail(&mp->list, &pring->postbufq);
  6754. pring->postbufq_cnt++;
  6755. spin_unlock_irq(&phba->hbalock);
  6756. return 0;
  6757. }
  6758. /**
  6759. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6760. * @phba: Pointer to HBA context object.
  6761. *
  6762. * When HBQ is enabled, buffers are searched based on tags. This function
  6763. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6764. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6765. * does not conflict with tags of buffer posted for unsolicited events.
  6766. * The function returns the allocated tag. The function is called with
  6767. * no locks held.
  6768. **/
  6769. uint32_t
  6770. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6771. {
  6772. spin_lock_irq(&phba->hbalock);
  6773. phba->buffer_tag_count++;
  6774. /*
  6775. * Always set the QUE_BUFTAG_BIT to distiguish between
  6776. * a tag assigned by HBQ.
  6777. */
  6778. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6779. spin_unlock_irq(&phba->hbalock);
  6780. return phba->buffer_tag_count;
  6781. }
  6782. /**
  6783. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6784. * @phba: Pointer to HBA context object.
  6785. * @pring: Pointer to driver SLI ring object.
  6786. * @tag: Buffer tag.
  6787. *
  6788. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6789. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6790. * iocb is posted to the response ring with the tag of the buffer.
  6791. * This function searches the pring->postbufq list using the tag
  6792. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6793. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6794. * buffer is returned to the caller else NULL is returned.
  6795. * This function is called with no lock held.
  6796. **/
  6797. struct lpfc_dmabuf *
  6798. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6799. uint32_t tag)
  6800. {
  6801. struct lpfc_dmabuf *mp, *next_mp;
  6802. struct list_head *slp = &pring->postbufq;
  6803. /* Search postbufq, from the begining, looking for a match on tag */
  6804. spin_lock_irq(&phba->hbalock);
  6805. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6806. if (mp->buffer_tag == tag) {
  6807. list_del_init(&mp->list);
  6808. pring->postbufq_cnt--;
  6809. spin_unlock_irq(&phba->hbalock);
  6810. return mp;
  6811. }
  6812. }
  6813. spin_unlock_irq(&phba->hbalock);
  6814. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6815. "0402 Cannot find virtual addr for buffer tag on "
  6816. "ring %d Data x%lx x%p x%p x%x\n",
  6817. pring->ringno, (unsigned long) tag,
  6818. slp->next, slp->prev, pring->postbufq_cnt);
  6819. return NULL;
  6820. }
  6821. /**
  6822. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6823. * @phba: Pointer to HBA context object.
  6824. * @pring: Pointer to driver SLI ring object.
  6825. * @phys: DMA address of the buffer.
  6826. *
  6827. * This function searches the buffer list using the dma_address
  6828. * of unsolicited event to find the driver's lpfc_dmabuf object
  6829. * corresponding to the dma_address. The function returns the
  6830. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6831. * This function is called by the ct and els unsolicited event
  6832. * handlers to get the buffer associated with the unsolicited
  6833. * event.
  6834. *
  6835. * This function is called with no lock held.
  6836. **/
  6837. struct lpfc_dmabuf *
  6838. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6839. dma_addr_t phys)
  6840. {
  6841. struct lpfc_dmabuf *mp, *next_mp;
  6842. struct list_head *slp = &pring->postbufq;
  6843. /* Search postbufq, from the begining, looking for a match on phys */
  6844. spin_lock_irq(&phba->hbalock);
  6845. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6846. if (mp->phys == phys) {
  6847. list_del_init(&mp->list);
  6848. pring->postbufq_cnt--;
  6849. spin_unlock_irq(&phba->hbalock);
  6850. return mp;
  6851. }
  6852. }
  6853. spin_unlock_irq(&phba->hbalock);
  6854. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6855. "0410 Cannot find virtual addr for mapped buf on "
  6856. "ring %d Data x%llx x%p x%p x%x\n",
  6857. pring->ringno, (unsigned long long)phys,
  6858. slp->next, slp->prev, pring->postbufq_cnt);
  6859. return NULL;
  6860. }
  6861. /**
  6862. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6863. * @phba: Pointer to HBA context object.
  6864. * @cmdiocb: Pointer to driver command iocb object.
  6865. * @rspiocb: Pointer to driver response iocb object.
  6866. *
  6867. * This function is the completion handler for the abort iocbs for
  6868. * ELS commands. This function is called from the ELS ring event
  6869. * handler with no lock held. This function frees memory resources
  6870. * associated with the abort iocb.
  6871. **/
  6872. static void
  6873. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6874. struct lpfc_iocbq *rspiocb)
  6875. {
  6876. IOCB_t *irsp = &rspiocb->iocb;
  6877. uint16_t abort_iotag, abort_context;
  6878. struct lpfc_iocbq *abort_iocb;
  6879. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6880. abort_iocb = NULL;
  6881. if (irsp->ulpStatus) {
  6882. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6883. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6884. spin_lock_irq(&phba->hbalock);
  6885. if (phba->sli_rev < LPFC_SLI_REV4) {
  6886. if (abort_iotag != 0 &&
  6887. abort_iotag <= phba->sli.last_iotag)
  6888. abort_iocb =
  6889. phba->sli.iocbq_lookup[abort_iotag];
  6890. } else
  6891. /* For sli4 the abort_tag is the XRI,
  6892. * so the abort routine puts the iotag of the iocb
  6893. * being aborted in the context field of the abort
  6894. * IOCB.
  6895. */
  6896. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6897. /*
  6898. * If the iocb is not found in Firmware queue the iocb
  6899. * might have completed already. Do not free it again.
  6900. */
  6901. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6902. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6903. spin_unlock_irq(&phba->hbalock);
  6904. lpfc_sli_release_iocbq(phba, cmdiocb);
  6905. return;
  6906. }
  6907. /* For SLI4 the ulpContext field for abort IOCB
  6908. * holds the iotag of the IOCB being aborted so
  6909. * the local abort_context needs to be reset to
  6910. * match the aborted IOCBs ulpContext.
  6911. */
  6912. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6913. abort_context = abort_iocb->iocb.ulpContext;
  6914. }
  6915. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6916. "0327 Cannot abort els iocb %p "
  6917. "with tag %x context %x, abort status %x, "
  6918. "abort code %x\n",
  6919. abort_iocb, abort_iotag, abort_context,
  6920. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6921. /*
  6922. * make sure we have the right iocbq before taking it
  6923. * off the txcmplq and try to call completion routine.
  6924. */
  6925. if (!abort_iocb ||
  6926. abort_iocb->iocb.ulpContext != abort_context ||
  6927. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6928. spin_unlock_irq(&phba->hbalock);
  6929. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6930. /*
  6931. * leave the SLI4 aborted command on the txcmplq
  6932. * list and the command complete WCQE's XB bit
  6933. * will tell whether the SGL (XRI) can be released
  6934. * immediately or to the aborted SGL list for the
  6935. * following abort XRI from the HBA.
  6936. */
  6937. list_del_init(&abort_iocb->list);
  6938. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6939. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6940. pring->txcmplq_cnt--;
  6941. }
  6942. /* Firmware could still be in progress of DMAing
  6943. * payload, so don't free data buffer till after
  6944. * a hbeat.
  6945. */
  6946. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6947. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6948. spin_unlock_irq(&phba->hbalock);
  6949. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6950. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6951. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6952. } else
  6953. spin_unlock_irq(&phba->hbalock);
  6954. }
  6955. lpfc_sli_release_iocbq(phba, cmdiocb);
  6956. return;
  6957. }
  6958. /**
  6959. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6960. * @phba: Pointer to HBA context object.
  6961. * @cmdiocb: Pointer to driver command iocb object.
  6962. * @rspiocb: Pointer to driver response iocb object.
  6963. *
  6964. * The function is called from SLI ring event handler with no
  6965. * lock held. This function is the completion handler for ELS commands
  6966. * which are aborted. The function frees memory resources used for
  6967. * the aborted ELS commands.
  6968. **/
  6969. static void
  6970. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6971. struct lpfc_iocbq *rspiocb)
  6972. {
  6973. IOCB_t *irsp = &rspiocb->iocb;
  6974. /* ELS cmd tag <ulpIoTag> completes */
  6975. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6976. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6977. "x%x x%x x%x\n",
  6978. irsp->ulpIoTag, irsp->ulpStatus,
  6979. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6980. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6981. lpfc_ct_free_iocb(phba, cmdiocb);
  6982. else
  6983. lpfc_els_free_iocb(phba, cmdiocb);
  6984. return;
  6985. }
  6986. /**
  6987. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  6988. * @phba: Pointer to HBA context object.
  6989. * @pring: Pointer to driver SLI ring object.
  6990. * @cmdiocb: Pointer to driver command iocb object.
  6991. *
  6992. * This function issues an abort iocb for the provided command iocb down to
  6993. * the port. Other than the case the outstanding command iocb is an abort
  6994. * request, this function issues abort out unconditionally. This function is
  6995. * called with hbalock held. The function returns 0 when it fails due to
  6996. * memory allocation failure or when the command iocb is an abort request.
  6997. **/
  6998. static int
  6999. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7000. struct lpfc_iocbq *cmdiocb)
  7001. {
  7002. struct lpfc_vport *vport = cmdiocb->vport;
  7003. struct lpfc_iocbq *abtsiocbp;
  7004. IOCB_t *icmd = NULL;
  7005. IOCB_t *iabt = NULL;
  7006. int retval;
  7007. /*
  7008. * There are certain command types we don't want to abort. And we
  7009. * don't want to abort commands that are already in the process of
  7010. * being aborted.
  7011. */
  7012. icmd = &cmdiocb->iocb;
  7013. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7014. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7015. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7016. return 0;
  7017. /* issue ABTS for this IOCB based on iotag */
  7018. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7019. if (abtsiocbp == NULL)
  7020. return 0;
  7021. /* This signals the response to set the correct status
  7022. * before calling the completion handler
  7023. */
  7024. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7025. iabt = &abtsiocbp->iocb;
  7026. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7027. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7028. if (phba->sli_rev == LPFC_SLI_REV4) {
  7029. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7030. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7031. }
  7032. else
  7033. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7034. iabt->ulpLe = 1;
  7035. iabt->ulpClass = icmd->ulpClass;
  7036. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7037. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7038. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7039. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7040. if (phba->link_state >= LPFC_LINK_UP)
  7041. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7042. else
  7043. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7044. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7045. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7046. "0339 Abort xri x%x, original iotag x%x, "
  7047. "abort cmd iotag x%x\n",
  7048. iabt->un.acxri.abortIoTag,
  7049. iabt->un.acxri.abortContextTag,
  7050. abtsiocbp->iotag);
  7051. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7052. if (retval)
  7053. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7054. /*
  7055. * Caller to this routine should check for IOCB_ERROR
  7056. * and handle it properly. This routine no longer removes
  7057. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7058. */
  7059. return retval;
  7060. }
  7061. /**
  7062. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7063. * @phba: Pointer to HBA context object.
  7064. * @pring: Pointer to driver SLI ring object.
  7065. * @cmdiocb: Pointer to driver command iocb object.
  7066. *
  7067. * This function issues an abort iocb for the provided command iocb. In case
  7068. * of unloading, the abort iocb will not be issued to commands on the ELS
  7069. * ring. Instead, the callback function shall be changed to those commands
  7070. * so that nothing happens when them finishes. This function is called with
  7071. * hbalock held. The function returns 0 when the command iocb is an abort
  7072. * request.
  7073. **/
  7074. int
  7075. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7076. struct lpfc_iocbq *cmdiocb)
  7077. {
  7078. struct lpfc_vport *vport = cmdiocb->vport;
  7079. int retval = IOCB_ERROR;
  7080. IOCB_t *icmd = NULL;
  7081. /*
  7082. * There are certain command types we don't want to abort. And we
  7083. * don't want to abort commands that are already in the process of
  7084. * being aborted.
  7085. */
  7086. icmd = &cmdiocb->iocb;
  7087. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7088. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7089. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7090. return 0;
  7091. /*
  7092. * If we're unloading, don't abort iocb on the ELS ring, but change
  7093. * the callback so that nothing happens when it finishes.
  7094. */
  7095. if ((vport->load_flag & FC_UNLOADING) &&
  7096. (pring->ringno == LPFC_ELS_RING)) {
  7097. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7098. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7099. else
  7100. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7101. goto abort_iotag_exit;
  7102. }
  7103. /* Now, we try to issue the abort to the cmdiocb out */
  7104. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7105. abort_iotag_exit:
  7106. /*
  7107. * Caller to this routine should check for IOCB_ERROR
  7108. * and handle it properly. This routine no longer removes
  7109. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7110. */
  7111. return retval;
  7112. }
  7113. /**
  7114. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7115. * @phba: Pointer to HBA context object.
  7116. * @pring: Pointer to driver SLI ring object.
  7117. *
  7118. * This function aborts all iocbs in the given ring and frees all the iocb
  7119. * objects in txq. This function issues abort iocbs unconditionally for all
  7120. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7121. * to complete before the return of this function. The caller is not required
  7122. * to hold any locks.
  7123. **/
  7124. static void
  7125. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7126. {
  7127. LIST_HEAD(completions);
  7128. struct lpfc_iocbq *iocb, *next_iocb;
  7129. if (pring->ringno == LPFC_ELS_RING)
  7130. lpfc_fabric_abort_hba(phba);
  7131. spin_lock_irq(&phba->hbalock);
  7132. /* Take off all the iocbs on txq for cancelling */
  7133. list_splice_init(&pring->txq, &completions);
  7134. pring->txq_cnt = 0;
  7135. /* Next issue ABTS for everything on the txcmplq */
  7136. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7137. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7138. spin_unlock_irq(&phba->hbalock);
  7139. /* Cancel all the IOCBs from the completions list */
  7140. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7141. IOERR_SLI_ABORTED);
  7142. }
  7143. /**
  7144. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7145. * @phba: pointer to lpfc HBA data structure.
  7146. *
  7147. * This routine will abort all pending and outstanding iocbs to an HBA.
  7148. **/
  7149. void
  7150. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7151. {
  7152. struct lpfc_sli *psli = &phba->sli;
  7153. struct lpfc_sli_ring *pring;
  7154. int i;
  7155. for (i = 0; i < psli->num_rings; i++) {
  7156. pring = &psli->ring[i];
  7157. lpfc_sli_iocb_ring_abort(phba, pring);
  7158. }
  7159. }
  7160. /**
  7161. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7162. * @iocbq: Pointer to driver iocb object.
  7163. * @vport: Pointer to driver virtual port object.
  7164. * @tgt_id: SCSI ID of the target.
  7165. * @lun_id: LUN ID of the scsi device.
  7166. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7167. *
  7168. * This function acts as an iocb filter for functions which abort or count
  7169. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7170. * 0 if the filtering criteria is met for the given iocb and will return
  7171. * 1 if the filtering criteria is not met.
  7172. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7173. * given iocb is for the SCSI device specified by vport, tgt_id and
  7174. * lun_id parameter.
  7175. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7176. * given iocb is for the SCSI target specified by vport and tgt_id
  7177. * parameters.
  7178. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7179. * given iocb is for the SCSI host associated with the given vport.
  7180. * This function is called with no locks held.
  7181. **/
  7182. static int
  7183. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7184. uint16_t tgt_id, uint64_t lun_id,
  7185. lpfc_ctx_cmd ctx_cmd)
  7186. {
  7187. struct lpfc_scsi_buf *lpfc_cmd;
  7188. int rc = 1;
  7189. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7190. return rc;
  7191. if (iocbq->vport != vport)
  7192. return rc;
  7193. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7194. if (lpfc_cmd->pCmd == NULL)
  7195. return rc;
  7196. switch (ctx_cmd) {
  7197. case LPFC_CTX_LUN:
  7198. if ((lpfc_cmd->rdata->pnode) &&
  7199. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7200. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7201. rc = 0;
  7202. break;
  7203. case LPFC_CTX_TGT:
  7204. if ((lpfc_cmd->rdata->pnode) &&
  7205. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7206. rc = 0;
  7207. break;
  7208. case LPFC_CTX_HOST:
  7209. rc = 0;
  7210. break;
  7211. default:
  7212. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7213. __func__, ctx_cmd);
  7214. break;
  7215. }
  7216. return rc;
  7217. }
  7218. /**
  7219. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7220. * @vport: Pointer to virtual port.
  7221. * @tgt_id: SCSI ID of the target.
  7222. * @lun_id: LUN ID of the scsi device.
  7223. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7224. *
  7225. * This function returns number of FCP commands pending for the vport.
  7226. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7227. * commands pending on the vport associated with SCSI device specified
  7228. * by tgt_id and lun_id parameters.
  7229. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7230. * commands pending on the vport associated with SCSI target specified
  7231. * by tgt_id parameter.
  7232. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7233. * commands pending on the vport.
  7234. * This function returns the number of iocbs which satisfy the filter.
  7235. * This function is called without any lock held.
  7236. **/
  7237. int
  7238. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7239. lpfc_ctx_cmd ctx_cmd)
  7240. {
  7241. struct lpfc_hba *phba = vport->phba;
  7242. struct lpfc_iocbq *iocbq;
  7243. int sum, i;
  7244. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7245. iocbq = phba->sli.iocbq_lookup[i];
  7246. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7247. ctx_cmd) == 0)
  7248. sum++;
  7249. }
  7250. return sum;
  7251. }
  7252. /**
  7253. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7254. * @phba: Pointer to HBA context object
  7255. * @cmdiocb: Pointer to command iocb object.
  7256. * @rspiocb: Pointer to response iocb object.
  7257. *
  7258. * This function is called when an aborted FCP iocb completes. This
  7259. * function is called by the ring event handler with no lock held.
  7260. * This function frees the iocb.
  7261. **/
  7262. void
  7263. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7264. struct lpfc_iocbq *rspiocb)
  7265. {
  7266. lpfc_sli_release_iocbq(phba, cmdiocb);
  7267. return;
  7268. }
  7269. /**
  7270. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7271. * @vport: Pointer to virtual port.
  7272. * @pring: Pointer to driver SLI ring object.
  7273. * @tgt_id: SCSI ID of the target.
  7274. * @lun_id: LUN ID of the scsi device.
  7275. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7276. *
  7277. * This function sends an abort command for every SCSI command
  7278. * associated with the given virtual port pending on the ring
  7279. * filtered by lpfc_sli_validate_fcp_iocb function.
  7280. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7281. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7282. * parameters
  7283. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7284. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7285. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7286. * FCP iocbs associated with virtual port.
  7287. * This function returns number of iocbs it failed to abort.
  7288. * This function is called with no locks held.
  7289. **/
  7290. int
  7291. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7292. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7293. {
  7294. struct lpfc_hba *phba = vport->phba;
  7295. struct lpfc_iocbq *iocbq;
  7296. struct lpfc_iocbq *abtsiocb;
  7297. IOCB_t *cmd = NULL;
  7298. int errcnt = 0, ret_val = 0;
  7299. int i;
  7300. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7301. iocbq = phba->sli.iocbq_lookup[i];
  7302. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7303. abort_cmd) != 0)
  7304. continue;
  7305. /* issue ABTS for this IOCB based on iotag */
  7306. abtsiocb = lpfc_sli_get_iocbq(phba);
  7307. if (abtsiocb == NULL) {
  7308. errcnt++;
  7309. continue;
  7310. }
  7311. cmd = &iocbq->iocb;
  7312. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7313. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7314. if (phba->sli_rev == LPFC_SLI_REV4)
  7315. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7316. else
  7317. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7318. abtsiocb->iocb.ulpLe = 1;
  7319. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7320. abtsiocb->vport = phba->pport;
  7321. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7322. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7323. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7324. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7325. if (lpfc_is_link_up(phba))
  7326. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7327. else
  7328. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7329. /* Setup callback routine and issue the command. */
  7330. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7331. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7332. abtsiocb, 0);
  7333. if (ret_val == IOCB_ERROR) {
  7334. lpfc_sli_release_iocbq(phba, abtsiocb);
  7335. errcnt++;
  7336. continue;
  7337. }
  7338. }
  7339. return errcnt;
  7340. }
  7341. /**
  7342. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7343. * @phba: Pointer to HBA context object.
  7344. * @cmdiocbq: Pointer to command iocb.
  7345. * @rspiocbq: Pointer to response iocb.
  7346. *
  7347. * This function is the completion handler for iocbs issued using
  7348. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7349. * ring event handler function without any lock held. This function
  7350. * can be called from both worker thread context and interrupt
  7351. * context. This function also can be called from other thread which
  7352. * cleans up the SLI layer objects.
  7353. * This function copy the contents of the response iocb to the
  7354. * response iocb memory object provided by the caller of
  7355. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7356. * sleeps for the iocb completion.
  7357. **/
  7358. static void
  7359. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7360. struct lpfc_iocbq *cmdiocbq,
  7361. struct lpfc_iocbq *rspiocbq)
  7362. {
  7363. wait_queue_head_t *pdone_q;
  7364. unsigned long iflags;
  7365. struct lpfc_scsi_buf *lpfc_cmd;
  7366. spin_lock_irqsave(&phba->hbalock, iflags);
  7367. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7368. if (cmdiocbq->context2 && rspiocbq)
  7369. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7370. &rspiocbq->iocb, sizeof(IOCB_t));
  7371. /* Set the exchange busy flag for task management commands */
  7372. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7373. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7374. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7375. cur_iocbq);
  7376. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7377. }
  7378. pdone_q = cmdiocbq->context_un.wait_queue;
  7379. if (pdone_q)
  7380. wake_up(pdone_q);
  7381. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7382. return;
  7383. }
  7384. /**
  7385. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7386. * @phba: Pointer to HBA context object..
  7387. * @piocbq: Pointer to command iocb.
  7388. * @flag: Flag to test.
  7389. *
  7390. * This routine grabs the hbalock and then test the iocb_flag to
  7391. * see if the passed in flag is set.
  7392. * Returns:
  7393. * 1 if flag is set.
  7394. * 0 if flag is not set.
  7395. **/
  7396. static int
  7397. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7398. struct lpfc_iocbq *piocbq, uint32_t flag)
  7399. {
  7400. unsigned long iflags;
  7401. int ret;
  7402. spin_lock_irqsave(&phba->hbalock, iflags);
  7403. ret = piocbq->iocb_flag & flag;
  7404. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7405. return ret;
  7406. }
  7407. /**
  7408. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7409. * @phba: Pointer to HBA context object..
  7410. * @pring: Pointer to sli ring.
  7411. * @piocb: Pointer to command iocb.
  7412. * @prspiocbq: Pointer to response iocb.
  7413. * @timeout: Timeout in number of seconds.
  7414. *
  7415. * This function issues the iocb to firmware and waits for the
  7416. * iocb to complete. If the iocb command is not
  7417. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7418. * Caller should not free the iocb resources if this function
  7419. * returns IOCB_TIMEDOUT.
  7420. * The function waits for the iocb completion using an
  7421. * non-interruptible wait.
  7422. * This function will sleep while waiting for iocb completion.
  7423. * So, this function should not be called from any context which
  7424. * does not allow sleeping. Due to the same reason, this function
  7425. * cannot be called with interrupt disabled.
  7426. * This function assumes that the iocb completions occur while
  7427. * this function sleep. So, this function cannot be called from
  7428. * the thread which process iocb completion for this ring.
  7429. * This function clears the iocb_flag of the iocb object before
  7430. * issuing the iocb and the iocb completion handler sets this
  7431. * flag and wakes this thread when the iocb completes.
  7432. * The contents of the response iocb will be copied to prspiocbq
  7433. * by the completion handler when the command completes.
  7434. * This function returns IOCB_SUCCESS when success.
  7435. * This function is called with no lock held.
  7436. **/
  7437. int
  7438. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7439. uint32_t ring_number,
  7440. struct lpfc_iocbq *piocb,
  7441. struct lpfc_iocbq *prspiocbq,
  7442. uint32_t timeout)
  7443. {
  7444. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7445. long timeleft, timeout_req = 0;
  7446. int retval = IOCB_SUCCESS;
  7447. uint32_t creg_val;
  7448. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7449. /*
  7450. * If the caller has provided a response iocbq buffer, then context2
  7451. * is NULL or its an error.
  7452. */
  7453. if (prspiocbq) {
  7454. if (piocb->context2)
  7455. return IOCB_ERROR;
  7456. piocb->context2 = prspiocbq;
  7457. }
  7458. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7459. piocb->context_un.wait_queue = &done_q;
  7460. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7461. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7462. creg_val = readl(phba->HCregaddr);
  7463. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7464. writel(creg_val, phba->HCregaddr);
  7465. readl(phba->HCregaddr); /* flush */
  7466. }
  7467. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7468. SLI_IOCB_RET_IOCB);
  7469. if (retval == IOCB_SUCCESS) {
  7470. timeout_req = timeout * HZ;
  7471. timeleft = wait_event_timeout(done_q,
  7472. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7473. timeout_req);
  7474. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7475. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7476. "0331 IOCB wake signaled\n");
  7477. } else if (timeleft == 0) {
  7478. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7479. "0338 IOCB wait timeout error - no "
  7480. "wake response Data x%x\n", timeout);
  7481. retval = IOCB_TIMEDOUT;
  7482. } else {
  7483. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7484. "0330 IOCB wake NOT set, "
  7485. "Data x%x x%lx\n",
  7486. timeout, (timeleft / jiffies));
  7487. retval = IOCB_TIMEDOUT;
  7488. }
  7489. } else if (retval == IOCB_BUSY) {
  7490. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7491. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7492. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7493. return retval;
  7494. } else {
  7495. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7496. "0332 IOCB wait issue failed, Data x%x\n",
  7497. retval);
  7498. retval = IOCB_ERROR;
  7499. }
  7500. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7501. creg_val = readl(phba->HCregaddr);
  7502. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7503. writel(creg_val, phba->HCregaddr);
  7504. readl(phba->HCregaddr); /* flush */
  7505. }
  7506. if (prspiocbq)
  7507. piocb->context2 = NULL;
  7508. piocb->context_un.wait_queue = NULL;
  7509. piocb->iocb_cmpl = NULL;
  7510. return retval;
  7511. }
  7512. /**
  7513. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7514. * @phba: Pointer to HBA context object.
  7515. * @pmboxq: Pointer to driver mailbox object.
  7516. * @timeout: Timeout in number of seconds.
  7517. *
  7518. * This function issues the mailbox to firmware and waits for the
  7519. * mailbox command to complete. If the mailbox command is not
  7520. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7521. * The function waits for the mailbox completion using an
  7522. * interruptible wait. If the thread is woken up due to a
  7523. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7524. * should not free the mailbox resources, if this function returns
  7525. * MBX_TIMEOUT.
  7526. * This function will sleep while waiting for mailbox completion.
  7527. * So, this function should not be called from any context which
  7528. * does not allow sleeping. Due to the same reason, this function
  7529. * cannot be called with interrupt disabled.
  7530. * This function assumes that the mailbox completion occurs while
  7531. * this function sleep. So, this function cannot be called from
  7532. * the worker thread which processes mailbox completion.
  7533. * This function is called in the context of HBA management
  7534. * applications.
  7535. * This function returns MBX_SUCCESS when successful.
  7536. * This function is called with no lock held.
  7537. **/
  7538. int
  7539. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7540. uint32_t timeout)
  7541. {
  7542. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7543. int retval;
  7544. unsigned long flag;
  7545. /* The caller must leave context1 empty. */
  7546. if (pmboxq->context1)
  7547. return MBX_NOT_FINISHED;
  7548. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7549. /* setup wake call as IOCB callback */
  7550. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7551. /* setup context field to pass wait_queue pointer to wake function */
  7552. pmboxq->context1 = &done_q;
  7553. /* now issue the command */
  7554. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7555. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7556. wait_event_interruptible_timeout(done_q,
  7557. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7558. timeout * HZ);
  7559. spin_lock_irqsave(&phba->hbalock, flag);
  7560. pmboxq->context1 = NULL;
  7561. /*
  7562. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7563. * else do not free the resources.
  7564. */
  7565. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7566. retval = MBX_SUCCESS;
  7567. lpfc_sli4_swap_str(phba, pmboxq);
  7568. } else {
  7569. retval = MBX_TIMEOUT;
  7570. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7571. }
  7572. spin_unlock_irqrestore(&phba->hbalock, flag);
  7573. }
  7574. return retval;
  7575. }
  7576. /**
  7577. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7578. * @phba: Pointer to HBA context.
  7579. *
  7580. * This function is called to shutdown the driver's mailbox sub-system.
  7581. * It first marks the mailbox sub-system is in a block state to prevent
  7582. * the asynchronous mailbox command from issued off the pending mailbox
  7583. * command queue. If the mailbox command sub-system shutdown is due to
  7584. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7585. * the mailbox sub-system flush routine to forcefully bring down the
  7586. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7587. * as with offline or HBA function reset), this routine will wait for the
  7588. * outstanding mailbox command to complete before invoking the mailbox
  7589. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7590. **/
  7591. void
  7592. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7593. {
  7594. struct lpfc_sli *psli = &phba->sli;
  7595. uint8_t actcmd = MBX_HEARTBEAT;
  7596. unsigned long timeout;
  7597. spin_lock_irq(&phba->hbalock);
  7598. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7599. spin_unlock_irq(&phba->hbalock);
  7600. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7601. spin_lock_irq(&phba->hbalock);
  7602. if (phba->sli.mbox_active)
  7603. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7604. spin_unlock_irq(&phba->hbalock);
  7605. /* Determine how long we might wait for the active mailbox
  7606. * command to be gracefully completed by firmware.
  7607. */
  7608. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7609. 1000) + jiffies;
  7610. while (phba->sli.mbox_active) {
  7611. /* Check active mailbox complete status every 2ms */
  7612. msleep(2);
  7613. if (time_after(jiffies, timeout))
  7614. /* Timeout, let the mailbox flush routine to
  7615. * forcefully release active mailbox command
  7616. */
  7617. break;
  7618. }
  7619. }
  7620. lpfc_sli_mbox_sys_flush(phba);
  7621. }
  7622. /**
  7623. * lpfc_sli_eratt_read - read sli-3 error attention events
  7624. * @phba: Pointer to HBA context.
  7625. *
  7626. * This function is called to read the SLI3 device error attention registers
  7627. * for possible error attention events. The caller must hold the hostlock
  7628. * with spin_lock_irq().
  7629. *
  7630. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7631. * Register and returns 0 otherwise.
  7632. **/
  7633. static int
  7634. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7635. {
  7636. uint32_t ha_copy;
  7637. /* Read chip Host Attention (HA) register */
  7638. ha_copy = readl(phba->HAregaddr);
  7639. if (ha_copy & HA_ERATT) {
  7640. /* Read host status register to retrieve error event */
  7641. lpfc_sli_read_hs(phba);
  7642. /* Check if there is a deferred error condition is active */
  7643. if ((HS_FFER1 & phba->work_hs) &&
  7644. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7645. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7646. phba->hba_flag |= DEFER_ERATT;
  7647. /* Clear all interrupt enable conditions */
  7648. writel(0, phba->HCregaddr);
  7649. readl(phba->HCregaddr);
  7650. }
  7651. /* Set the driver HA work bitmap */
  7652. phba->work_ha |= HA_ERATT;
  7653. /* Indicate polling handles this ERATT */
  7654. phba->hba_flag |= HBA_ERATT_HANDLED;
  7655. return 1;
  7656. }
  7657. return 0;
  7658. }
  7659. /**
  7660. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7661. * @phba: Pointer to HBA context.
  7662. *
  7663. * This function is called to read the SLI4 device error attention registers
  7664. * for possible error attention events. The caller must hold the hostlock
  7665. * with spin_lock_irq().
  7666. *
  7667. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7668. * Register and returns 0 otherwise.
  7669. **/
  7670. static int
  7671. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7672. {
  7673. uint32_t uerr_sta_hi, uerr_sta_lo;
  7674. /* For now, use the SLI4 device internal unrecoverable error
  7675. * registers for error attention. This can be changed later.
  7676. */
  7677. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7678. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7679. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7680. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7681. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7682. "1423 HBA Unrecoverable error: "
  7683. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7684. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7685. uerr_sta_lo, uerr_sta_hi,
  7686. phba->sli4_hba.ue_mask_lo,
  7687. phba->sli4_hba.ue_mask_hi);
  7688. phba->work_status[0] = uerr_sta_lo;
  7689. phba->work_status[1] = uerr_sta_hi;
  7690. /* Set the driver HA work bitmap */
  7691. phba->work_ha |= HA_ERATT;
  7692. /* Indicate polling handles this ERATT */
  7693. phba->hba_flag |= HBA_ERATT_HANDLED;
  7694. return 1;
  7695. }
  7696. return 0;
  7697. }
  7698. /**
  7699. * lpfc_sli_check_eratt - check error attention events
  7700. * @phba: Pointer to HBA context.
  7701. *
  7702. * This function is called from timer soft interrupt context to check HBA's
  7703. * error attention register bit for error attention events.
  7704. *
  7705. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7706. * Register and returns 0 otherwise.
  7707. **/
  7708. int
  7709. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7710. {
  7711. uint32_t ha_copy;
  7712. /* If somebody is waiting to handle an eratt, don't process it
  7713. * here. The brdkill function will do this.
  7714. */
  7715. if (phba->link_flag & LS_IGNORE_ERATT)
  7716. return 0;
  7717. /* Check if interrupt handler handles this ERATT */
  7718. spin_lock_irq(&phba->hbalock);
  7719. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7720. /* Interrupt handler has handled ERATT */
  7721. spin_unlock_irq(&phba->hbalock);
  7722. return 0;
  7723. }
  7724. /*
  7725. * If there is deferred error attention, do not check for error
  7726. * attention
  7727. */
  7728. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7729. spin_unlock_irq(&phba->hbalock);
  7730. return 0;
  7731. }
  7732. /* If PCI channel is offline, don't process it */
  7733. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7734. spin_unlock_irq(&phba->hbalock);
  7735. return 0;
  7736. }
  7737. switch (phba->sli_rev) {
  7738. case LPFC_SLI_REV2:
  7739. case LPFC_SLI_REV3:
  7740. /* Read chip Host Attention (HA) register */
  7741. ha_copy = lpfc_sli_eratt_read(phba);
  7742. break;
  7743. case LPFC_SLI_REV4:
  7744. /* Read devcie Uncoverable Error (UERR) registers */
  7745. ha_copy = lpfc_sli4_eratt_read(phba);
  7746. break;
  7747. default:
  7748. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7749. "0299 Invalid SLI revision (%d)\n",
  7750. phba->sli_rev);
  7751. ha_copy = 0;
  7752. break;
  7753. }
  7754. spin_unlock_irq(&phba->hbalock);
  7755. return ha_copy;
  7756. }
  7757. /**
  7758. * lpfc_intr_state_check - Check device state for interrupt handling
  7759. * @phba: Pointer to HBA context.
  7760. *
  7761. * This inline routine checks whether a device or its PCI slot is in a state
  7762. * that the interrupt should be handled.
  7763. *
  7764. * This function returns 0 if the device or the PCI slot is in a state that
  7765. * interrupt should be handled, otherwise -EIO.
  7766. */
  7767. static inline int
  7768. lpfc_intr_state_check(struct lpfc_hba *phba)
  7769. {
  7770. /* If the pci channel is offline, ignore all the interrupts */
  7771. if (unlikely(pci_channel_offline(phba->pcidev)))
  7772. return -EIO;
  7773. /* Update device level interrupt statistics */
  7774. phba->sli.slistat.sli_intr++;
  7775. /* Ignore all interrupts during initialization. */
  7776. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7777. return -EIO;
  7778. return 0;
  7779. }
  7780. /**
  7781. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7782. * @irq: Interrupt number.
  7783. * @dev_id: The device context pointer.
  7784. *
  7785. * This function is directly called from the PCI layer as an interrupt
  7786. * service routine when device with SLI-3 interface spec is enabled with
  7787. * MSI-X multi-message interrupt mode and there are slow-path events in
  7788. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7789. * interrupt mode, this function is called as part of the device-level
  7790. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7791. * is undergoing initialization, the interrupt handler will not process
  7792. * the interrupt. The link attention and ELS ring attention events are
  7793. * handled by the worker thread. The interrupt handler signals the worker
  7794. * thread and returns for these events. This function is called without
  7795. * any lock held. It gets the hbalock to access and update SLI data
  7796. * structures.
  7797. *
  7798. * This function returns IRQ_HANDLED when interrupt is handled else it
  7799. * returns IRQ_NONE.
  7800. **/
  7801. irqreturn_t
  7802. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7803. {
  7804. struct lpfc_hba *phba;
  7805. uint32_t ha_copy, hc_copy;
  7806. uint32_t work_ha_copy;
  7807. unsigned long status;
  7808. unsigned long iflag;
  7809. uint32_t control;
  7810. MAILBOX_t *mbox, *pmbox;
  7811. struct lpfc_vport *vport;
  7812. struct lpfc_nodelist *ndlp;
  7813. struct lpfc_dmabuf *mp;
  7814. LPFC_MBOXQ_t *pmb;
  7815. int rc;
  7816. /*
  7817. * Get the driver's phba structure from the dev_id and
  7818. * assume the HBA is not interrupting.
  7819. */
  7820. phba = (struct lpfc_hba *)dev_id;
  7821. if (unlikely(!phba))
  7822. return IRQ_NONE;
  7823. /*
  7824. * Stuff needs to be attented to when this function is invoked as an
  7825. * individual interrupt handler in MSI-X multi-message interrupt mode
  7826. */
  7827. if (phba->intr_type == MSIX) {
  7828. /* Check device state for handling interrupt */
  7829. if (lpfc_intr_state_check(phba))
  7830. return IRQ_NONE;
  7831. /* Need to read HA REG for slow-path events */
  7832. spin_lock_irqsave(&phba->hbalock, iflag);
  7833. ha_copy = readl(phba->HAregaddr);
  7834. /* If somebody is waiting to handle an eratt don't process it
  7835. * here. The brdkill function will do this.
  7836. */
  7837. if (phba->link_flag & LS_IGNORE_ERATT)
  7838. ha_copy &= ~HA_ERATT;
  7839. /* Check the need for handling ERATT in interrupt handler */
  7840. if (ha_copy & HA_ERATT) {
  7841. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7842. /* ERATT polling has handled ERATT */
  7843. ha_copy &= ~HA_ERATT;
  7844. else
  7845. /* Indicate interrupt handler handles ERATT */
  7846. phba->hba_flag |= HBA_ERATT_HANDLED;
  7847. }
  7848. /*
  7849. * If there is deferred error attention, do not check for any
  7850. * interrupt.
  7851. */
  7852. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7853. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7854. return IRQ_NONE;
  7855. }
  7856. /* Clear up only attention source related to slow-path */
  7857. hc_copy = readl(phba->HCregaddr);
  7858. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7859. HC_LAINT_ENA | HC_ERINT_ENA),
  7860. phba->HCregaddr);
  7861. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7862. phba->HAregaddr);
  7863. writel(hc_copy, phba->HCregaddr);
  7864. readl(phba->HAregaddr); /* flush */
  7865. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7866. } else
  7867. ha_copy = phba->ha_copy;
  7868. work_ha_copy = ha_copy & phba->work_ha_mask;
  7869. if (work_ha_copy) {
  7870. if (work_ha_copy & HA_LATT) {
  7871. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7872. /*
  7873. * Turn off Link Attention interrupts
  7874. * until CLEAR_LA done
  7875. */
  7876. spin_lock_irqsave(&phba->hbalock, iflag);
  7877. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7878. control = readl(phba->HCregaddr);
  7879. control &= ~HC_LAINT_ENA;
  7880. writel(control, phba->HCregaddr);
  7881. readl(phba->HCregaddr); /* flush */
  7882. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7883. }
  7884. else
  7885. work_ha_copy &= ~HA_LATT;
  7886. }
  7887. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7888. /*
  7889. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7890. * the only slow ring.
  7891. */
  7892. status = (work_ha_copy &
  7893. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7894. status >>= (4*LPFC_ELS_RING);
  7895. if (status & HA_RXMASK) {
  7896. spin_lock_irqsave(&phba->hbalock, iflag);
  7897. control = readl(phba->HCregaddr);
  7898. lpfc_debugfs_slow_ring_trc(phba,
  7899. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7900. control, status,
  7901. (uint32_t)phba->sli.slistat.sli_intr);
  7902. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7903. lpfc_debugfs_slow_ring_trc(phba,
  7904. "ISR Disable ring:"
  7905. "pwork:x%x hawork:x%x wait:x%x",
  7906. phba->work_ha, work_ha_copy,
  7907. (uint32_t)((unsigned long)
  7908. &phba->work_waitq));
  7909. control &=
  7910. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7911. writel(control, phba->HCregaddr);
  7912. readl(phba->HCregaddr); /* flush */
  7913. }
  7914. else {
  7915. lpfc_debugfs_slow_ring_trc(phba,
  7916. "ISR slow ring: pwork:"
  7917. "x%x hawork:x%x wait:x%x",
  7918. phba->work_ha, work_ha_copy,
  7919. (uint32_t)((unsigned long)
  7920. &phba->work_waitq));
  7921. }
  7922. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7923. }
  7924. }
  7925. spin_lock_irqsave(&phba->hbalock, iflag);
  7926. if (work_ha_copy & HA_ERATT) {
  7927. lpfc_sli_read_hs(phba);
  7928. /*
  7929. * Check if there is a deferred error condition
  7930. * is active
  7931. */
  7932. if ((HS_FFER1 & phba->work_hs) &&
  7933. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7934. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  7935. phba->work_hs)) {
  7936. phba->hba_flag |= DEFER_ERATT;
  7937. /* Clear all interrupt enable conditions */
  7938. writel(0, phba->HCregaddr);
  7939. readl(phba->HCregaddr);
  7940. }
  7941. }
  7942. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7943. pmb = phba->sli.mbox_active;
  7944. pmbox = &pmb->u.mb;
  7945. mbox = phba->mbox;
  7946. vport = pmb->vport;
  7947. /* First check out the status word */
  7948. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7949. if (pmbox->mbxOwner != OWN_HOST) {
  7950. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7951. /*
  7952. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7953. * mbxStatus <status>
  7954. */
  7955. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7956. LOG_SLI,
  7957. "(%d):0304 Stray Mailbox "
  7958. "Interrupt mbxCommand x%x "
  7959. "mbxStatus x%x\n",
  7960. (vport ? vport->vpi : 0),
  7961. pmbox->mbxCommand,
  7962. pmbox->mbxStatus);
  7963. /* clear mailbox attention bit */
  7964. work_ha_copy &= ~HA_MBATT;
  7965. } else {
  7966. phba->sli.mbox_active = NULL;
  7967. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7968. phba->last_completion_time = jiffies;
  7969. del_timer(&phba->sli.mbox_tmo);
  7970. if (pmb->mbox_cmpl) {
  7971. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7972. MAILBOX_CMD_SIZE);
  7973. if (pmb->out_ext_byte_len &&
  7974. pmb->context2)
  7975. lpfc_sli_pcimem_bcopy(
  7976. phba->mbox_ext,
  7977. pmb->context2,
  7978. pmb->out_ext_byte_len);
  7979. }
  7980. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7981. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7982. lpfc_debugfs_disc_trc(vport,
  7983. LPFC_DISC_TRC_MBOX_VPORT,
  7984. "MBOX dflt rpi: : "
  7985. "status:x%x rpi:x%x",
  7986. (uint32_t)pmbox->mbxStatus,
  7987. pmbox->un.varWords[0], 0);
  7988. if (!pmbox->mbxStatus) {
  7989. mp = (struct lpfc_dmabuf *)
  7990. (pmb->context1);
  7991. ndlp = (struct lpfc_nodelist *)
  7992. pmb->context2;
  7993. /* Reg_LOGIN of dflt RPI was
  7994. * successful. new lets get
  7995. * rid of the RPI using the
  7996. * same mbox buffer.
  7997. */
  7998. lpfc_unreg_login(phba,
  7999. vport->vpi,
  8000. pmbox->un.varWords[0],
  8001. pmb);
  8002. pmb->mbox_cmpl =
  8003. lpfc_mbx_cmpl_dflt_rpi;
  8004. pmb->context1 = mp;
  8005. pmb->context2 = ndlp;
  8006. pmb->vport = vport;
  8007. rc = lpfc_sli_issue_mbox(phba,
  8008. pmb,
  8009. MBX_NOWAIT);
  8010. if (rc != MBX_BUSY)
  8011. lpfc_printf_log(phba,
  8012. KERN_ERR,
  8013. LOG_MBOX | LOG_SLI,
  8014. "0350 rc should have"
  8015. "been MBX_BUSY\n");
  8016. if (rc != MBX_NOT_FINISHED)
  8017. goto send_current_mbox;
  8018. }
  8019. }
  8020. spin_lock_irqsave(
  8021. &phba->pport->work_port_lock,
  8022. iflag);
  8023. phba->pport->work_port_events &=
  8024. ~WORKER_MBOX_TMO;
  8025. spin_unlock_irqrestore(
  8026. &phba->pport->work_port_lock,
  8027. iflag);
  8028. lpfc_mbox_cmpl_put(phba, pmb);
  8029. }
  8030. } else
  8031. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8032. if ((work_ha_copy & HA_MBATT) &&
  8033. (phba->sli.mbox_active == NULL)) {
  8034. send_current_mbox:
  8035. /* Process next mailbox command if there is one */
  8036. do {
  8037. rc = lpfc_sli_issue_mbox(phba, NULL,
  8038. MBX_NOWAIT);
  8039. } while (rc == MBX_NOT_FINISHED);
  8040. if (rc != MBX_SUCCESS)
  8041. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8042. LOG_SLI, "0349 rc should be "
  8043. "MBX_SUCCESS\n");
  8044. }
  8045. spin_lock_irqsave(&phba->hbalock, iflag);
  8046. phba->work_ha |= work_ha_copy;
  8047. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8048. lpfc_worker_wake_up(phba);
  8049. }
  8050. return IRQ_HANDLED;
  8051. } /* lpfc_sli_sp_intr_handler */
  8052. /**
  8053. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8054. * @irq: Interrupt number.
  8055. * @dev_id: The device context pointer.
  8056. *
  8057. * This function is directly called from the PCI layer as an interrupt
  8058. * service routine when device with SLI-3 interface spec is enabled with
  8059. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8060. * ring event in the HBA. However, when the device is enabled with either
  8061. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8062. * device-level interrupt handler. When the PCI slot is in error recovery
  8063. * or the HBA is undergoing initialization, the interrupt handler will not
  8064. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8065. * the intrrupt context. This function is called without any lock held.
  8066. * It gets the hbalock to access and update SLI data structures.
  8067. *
  8068. * This function returns IRQ_HANDLED when interrupt is handled else it
  8069. * returns IRQ_NONE.
  8070. **/
  8071. irqreturn_t
  8072. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8073. {
  8074. struct lpfc_hba *phba;
  8075. uint32_t ha_copy;
  8076. unsigned long status;
  8077. unsigned long iflag;
  8078. /* Get the driver's phba structure from the dev_id and
  8079. * assume the HBA is not interrupting.
  8080. */
  8081. phba = (struct lpfc_hba *) dev_id;
  8082. if (unlikely(!phba))
  8083. return IRQ_NONE;
  8084. /*
  8085. * Stuff needs to be attented to when this function is invoked as an
  8086. * individual interrupt handler in MSI-X multi-message interrupt mode
  8087. */
  8088. if (phba->intr_type == MSIX) {
  8089. /* Check device state for handling interrupt */
  8090. if (lpfc_intr_state_check(phba))
  8091. return IRQ_NONE;
  8092. /* Need to read HA REG for FCP ring and other ring events */
  8093. ha_copy = readl(phba->HAregaddr);
  8094. /* Clear up only attention source related to fast-path */
  8095. spin_lock_irqsave(&phba->hbalock, iflag);
  8096. /*
  8097. * If there is deferred error attention, do not check for
  8098. * any interrupt.
  8099. */
  8100. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8101. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8102. return IRQ_NONE;
  8103. }
  8104. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8105. phba->HAregaddr);
  8106. readl(phba->HAregaddr); /* flush */
  8107. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8108. } else
  8109. ha_copy = phba->ha_copy;
  8110. /*
  8111. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8112. */
  8113. ha_copy &= ~(phba->work_ha_mask);
  8114. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8115. status >>= (4*LPFC_FCP_RING);
  8116. if (status & HA_RXMASK)
  8117. lpfc_sli_handle_fast_ring_event(phba,
  8118. &phba->sli.ring[LPFC_FCP_RING],
  8119. status);
  8120. if (phba->cfg_multi_ring_support == 2) {
  8121. /*
  8122. * Process all events on extra ring. Take the optimized path
  8123. * for extra ring IO.
  8124. */
  8125. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8126. status >>= (4*LPFC_EXTRA_RING);
  8127. if (status & HA_RXMASK) {
  8128. lpfc_sli_handle_fast_ring_event(phba,
  8129. &phba->sli.ring[LPFC_EXTRA_RING],
  8130. status);
  8131. }
  8132. }
  8133. return IRQ_HANDLED;
  8134. } /* lpfc_sli_fp_intr_handler */
  8135. /**
  8136. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8137. * @irq: Interrupt number.
  8138. * @dev_id: The device context pointer.
  8139. *
  8140. * This function is the HBA device-level interrupt handler to device with
  8141. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8142. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8143. * requires driver attention. This function invokes the slow-path interrupt
  8144. * attention handling function and fast-path interrupt attention handling
  8145. * function in turn to process the relevant HBA attention events. This
  8146. * function is called without any lock held. It gets the hbalock to access
  8147. * and update SLI data structures.
  8148. *
  8149. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8150. * returns IRQ_NONE.
  8151. **/
  8152. irqreturn_t
  8153. lpfc_sli_intr_handler(int irq, void *dev_id)
  8154. {
  8155. struct lpfc_hba *phba;
  8156. irqreturn_t sp_irq_rc, fp_irq_rc;
  8157. unsigned long status1, status2;
  8158. uint32_t hc_copy;
  8159. /*
  8160. * Get the driver's phba structure from the dev_id and
  8161. * assume the HBA is not interrupting.
  8162. */
  8163. phba = (struct lpfc_hba *) dev_id;
  8164. if (unlikely(!phba))
  8165. return IRQ_NONE;
  8166. /* Check device state for handling interrupt */
  8167. if (lpfc_intr_state_check(phba))
  8168. return IRQ_NONE;
  8169. spin_lock(&phba->hbalock);
  8170. phba->ha_copy = readl(phba->HAregaddr);
  8171. if (unlikely(!phba->ha_copy)) {
  8172. spin_unlock(&phba->hbalock);
  8173. return IRQ_NONE;
  8174. } else if (phba->ha_copy & HA_ERATT) {
  8175. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8176. /* ERATT polling has handled ERATT */
  8177. phba->ha_copy &= ~HA_ERATT;
  8178. else
  8179. /* Indicate interrupt handler handles ERATT */
  8180. phba->hba_flag |= HBA_ERATT_HANDLED;
  8181. }
  8182. /*
  8183. * If there is deferred error attention, do not check for any interrupt.
  8184. */
  8185. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8186. spin_unlock(&phba->hbalock);
  8187. return IRQ_NONE;
  8188. }
  8189. /* Clear attention sources except link and error attentions */
  8190. hc_copy = readl(phba->HCregaddr);
  8191. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8192. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8193. phba->HCregaddr);
  8194. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8195. writel(hc_copy, phba->HCregaddr);
  8196. readl(phba->HAregaddr); /* flush */
  8197. spin_unlock(&phba->hbalock);
  8198. /*
  8199. * Invokes slow-path host attention interrupt handling as appropriate.
  8200. */
  8201. /* status of events with mailbox and link attention */
  8202. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8203. /* status of events with ELS ring */
  8204. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8205. status2 >>= (4*LPFC_ELS_RING);
  8206. if (status1 || (status2 & HA_RXMASK))
  8207. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8208. else
  8209. sp_irq_rc = IRQ_NONE;
  8210. /*
  8211. * Invoke fast-path host attention interrupt handling as appropriate.
  8212. */
  8213. /* status of events with FCP ring */
  8214. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8215. status1 >>= (4*LPFC_FCP_RING);
  8216. /* status of events with extra ring */
  8217. if (phba->cfg_multi_ring_support == 2) {
  8218. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8219. status2 >>= (4*LPFC_EXTRA_RING);
  8220. } else
  8221. status2 = 0;
  8222. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8223. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8224. else
  8225. fp_irq_rc = IRQ_NONE;
  8226. /* Return device-level interrupt handling status */
  8227. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8228. } /* lpfc_sli_intr_handler */
  8229. /**
  8230. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8231. * @phba: pointer to lpfc hba data structure.
  8232. *
  8233. * This routine is invoked by the worker thread to process all the pending
  8234. * SLI4 FCP abort XRI events.
  8235. **/
  8236. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8237. {
  8238. struct lpfc_cq_event *cq_event;
  8239. /* First, declare the fcp xri abort event has been handled */
  8240. spin_lock_irq(&phba->hbalock);
  8241. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8242. spin_unlock_irq(&phba->hbalock);
  8243. /* Now, handle all the fcp xri abort events */
  8244. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8245. /* Get the first event from the head of the event queue */
  8246. spin_lock_irq(&phba->hbalock);
  8247. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8248. cq_event, struct lpfc_cq_event, list);
  8249. spin_unlock_irq(&phba->hbalock);
  8250. /* Notify aborted XRI for FCP work queue */
  8251. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8252. /* Free the event processed back to the free pool */
  8253. lpfc_sli4_cq_event_release(phba, cq_event);
  8254. }
  8255. }
  8256. /**
  8257. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8258. * @phba: pointer to lpfc hba data structure.
  8259. *
  8260. * This routine is invoked by the worker thread to process all the pending
  8261. * SLI4 els abort xri events.
  8262. **/
  8263. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8264. {
  8265. struct lpfc_cq_event *cq_event;
  8266. /* First, declare the els xri abort event has been handled */
  8267. spin_lock_irq(&phba->hbalock);
  8268. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8269. spin_unlock_irq(&phba->hbalock);
  8270. /* Now, handle all the els xri abort events */
  8271. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8272. /* Get the first event from the head of the event queue */
  8273. spin_lock_irq(&phba->hbalock);
  8274. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8275. cq_event, struct lpfc_cq_event, list);
  8276. spin_unlock_irq(&phba->hbalock);
  8277. /* Notify aborted XRI for ELS work queue */
  8278. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8279. /* Free the event processed back to the free pool */
  8280. lpfc_sli4_cq_event_release(phba, cq_event);
  8281. }
  8282. }
  8283. /**
  8284. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8285. * @phba: pointer to lpfc hba data structure
  8286. * @pIocbIn: pointer to the rspiocbq
  8287. * @pIocbOut: pointer to the cmdiocbq
  8288. * @wcqe: pointer to the complete wcqe
  8289. *
  8290. * This routine transfers the fields of a command iocbq to a response iocbq
  8291. * by copying all the IOCB fields from command iocbq and transferring the
  8292. * completion status information from the complete wcqe.
  8293. **/
  8294. static void
  8295. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8296. struct lpfc_iocbq *pIocbIn,
  8297. struct lpfc_iocbq *pIocbOut,
  8298. struct lpfc_wcqe_complete *wcqe)
  8299. {
  8300. unsigned long iflags;
  8301. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8302. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8303. sizeof(struct lpfc_iocbq) - offset);
  8304. /* Map WCQE parameters into irspiocb parameters */
  8305. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8306. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8307. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8308. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8309. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8310. wcqe->total_data_placed;
  8311. else
  8312. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8313. else {
  8314. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8315. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8316. }
  8317. /* Pick up HBA exchange busy condition */
  8318. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8319. spin_lock_irqsave(&phba->hbalock, iflags);
  8320. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8321. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8322. }
  8323. }
  8324. /**
  8325. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8326. * @phba: Pointer to HBA context object.
  8327. * @wcqe: Pointer to work-queue completion queue entry.
  8328. *
  8329. * This routine handles an ELS work-queue completion event and construct
  8330. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8331. * discovery engine to handle.
  8332. *
  8333. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8334. **/
  8335. static struct lpfc_iocbq *
  8336. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8337. struct lpfc_iocbq *irspiocbq)
  8338. {
  8339. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8340. struct lpfc_iocbq *cmdiocbq;
  8341. struct lpfc_wcqe_complete *wcqe;
  8342. unsigned long iflags;
  8343. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8344. spin_lock_irqsave(&phba->hbalock, iflags);
  8345. pring->stats.iocb_event++;
  8346. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8347. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8348. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8349. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8350. if (unlikely(!cmdiocbq)) {
  8351. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8352. "0386 ELS complete with no corresponding "
  8353. "cmdiocb: iotag (%d)\n",
  8354. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8355. lpfc_sli_release_iocbq(phba, irspiocbq);
  8356. return NULL;
  8357. }
  8358. /* Fake the irspiocbq and copy necessary response information */
  8359. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8360. return irspiocbq;
  8361. }
  8362. /**
  8363. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8364. * @phba: Pointer to HBA context object.
  8365. * @cqe: Pointer to mailbox completion queue entry.
  8366. *
  8367. * This routine process a mailbox completion queue entry with asynchrous
  8368. * event.
  8369. *
  8370. * Return: true if work posted to worker thread, otherwise false.
  8371. **/
  8372. static bool
  8373. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8374. {
  8375. struct lpfc_cq_event *cq_event;
  8376. unsigned long iflags;
  8377. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8378. "0392 Async Event: word0:x%x, word1:x%x, "
  8379. "word2:x%x, word3:x%x\n", mcqe->word0,
  8380. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8381. /* Allocate a new internal CQ_EVENT entry */
  8382. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8383. if (!cq_event) {
  8384. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8385. "0394 Failed to allocate CQ_EVENT entry\n");
  8386. return false;
  8387. }
  8388. /* Move the CQE into an asynchronous event entry */
  8389. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8390. spin_lock_irqsave(&phba->hbalock, iflags);
  8391. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8392. /* Set the async event flag */
  8393. phba->hba_flag |= ASYNC_EVENT;
  8394. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8395. return true;
  8396. }
  8397. /**
  8398. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8399. * @phba: Pointer to HBA context object.
  8400. * @cqe: Pointer to mailbox completion queue entry.
  8401. *
  8402. * This routine process a mailbox completion queue entry with mailbox
  8403. * completion event.
  8404. *
  8405. * Return: true if work posted to worker thread, otherwise false.
  8406. **/
  8407. static bool
  8408. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8409. {
  8410. uint32_t mcqe_status;
  8411. MAILBOX_t *mbox, *pmbox;
  8412. struct lpfc_mqe *mqe;
  8413. struct lpfc_vport *vport;
  8414. struct lpfc_nodelist *ndlp;
  8415. struct lpfc_dmabuf *mp;
  8416. unsigned long iflags;
  8417. LPFC_MBOXQ_t *pmb;
  8418. bool workposted = false;
  8419. int rc;
  8420. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8421. if (!bf_get(lpfc_trailer_completed, mcqe))
  8422. goto out_no_mqe_complete;
  8423. /* Get the reference to the active mbox command */
  8424. spin_lock_irqsave(&phba->hbalock, iflags);
  8425. pmb = phba->sli.mbox_active;
  8426. if (unlikely(!pmb)) {
  8427. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8428. "1832 No pending MBOX command to handle\n");
  8429. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8430. goto out_no_mqe_complete;
  8431. }
  8432. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8433. mqe = &pmb->u.mqe;
  8434. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8435. mbox = phba->mbox;
  8436. vport = pmb->vport;
  8437. /* Reset heartbeat timer */
  8438. phba->last_completion_time = jiffies;
  8439. del_timer(&phba->sli.mbox_tmo);
  8440. /* Move mbox data to caller's mailbox region, do endian swapping */
  8441. if (pmb->mbox_cmpl && mbox)
  8442. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8443. /* Set the mailbox status with SLI4 range 0x4000 */
  8444. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8445. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8446. bf_set(lpfc_mqe_status, mqe,
  8447. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8448. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8449. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8450. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8451. "MBOX dflt rpi: status:x%x rpi:x%x",
  8452. mcqe_status,
  8453. pmbox->un.varWords[0], 0);
  8454. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8455. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8456. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8457. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8458. * RID of the PPI using the same mbox buffer.
  8459. */
  8460. lpfc_unreg_login(phba, vport->vpi,
  8461. pmbox->un.varWords[0], pmb);
  8462. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8463. pmb->context1 = mp;
  8464. pmb->context2 = ndlp;
  8465. pmb->vport = vport;
  8466. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8467. if (rc != MBX_BUSY)
  8468. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8469. LOG_SLI, "0385 rc should "
  8470. "have been MBX_BUSY\n");
  8471. if (rc != MBX_NOT_FINISHED)
  8472. goto send_current_mbox;
  8473. }
  8474. }
  8475. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8476. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8477. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8478. /* There is mailbox completion work to do */
  8479. spin_lock_irqsave(&phba->hbalock, iflags);
  8480. __lpfc_mbox_cmpl_put(phba, pmb);
  8481. phba->work_ha |= HA_MBATT;
  8482. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8483. workposted = true;
  8484. send_current_mbox:
  8485. spin_lock_irqsave(&phba->hbalock, iflags);
  8486. /* Release the mailbox command posting token */
  8487. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8488. /* Setting active mailbox pointer need to be in sync to flag clear */
  8489. phba->sli.mbox_active = NULL;
  8490. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8491. /* Wake up worker thread to post the next pending mailbox command */
  8492. lpfc_worker_wake_up(phba);
  8493. out_no_mqe_complete:
  8494. if (bf_get(lpfc_trailer_consumed, mcqe))
  8495. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8496. return workposted;
  8497. }
  8498. /**
  8499. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8500. * @phba: Pointer to HBA context object.
  8501. * @cqe: Pointer to mailbox completion queue entry.
  8502. *
  8503. * This routine process a mailbox completion queue entry, it invokes the
  8504. * proper mailbox complete handling or asynchrous event handling routine
  8505. * according to the MCQE's async bit.
  8506. *
  8507. * Return: true if work posted to worker thread, otherwise false.
  8508. **/
  8509. static bool
  8510. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8511. {
  8512. struct lpfc_mcqe mcqe;
  8513. bool workposted;
  8514. /* Copy the mailbox MCQE and convert endian order as needed */
  8515. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8516. /* Invoke the proper event handling routine */
  8517. if (!bf_get(lpfc_trailer_async, &mcqe))
  8518. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8519. else
  8520. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8521. return workposted;
  8522. }
  8523. /**
  8524. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8525. * @phba: Pointer to HBA context object.
  8526. * @wcqe: Pointer to work-queue completion queue entry.
  8527. *
  8528. * This routine handles an ELS work-queue completion event.
  8529. *
  8530. * Return: true if work posted to worker thread, otherwise false.
  8531. **/
  8532. static bool
  8533. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8534. struct lpfc_wcqe_complete *wcqe)
  8535. {
  8536. struct lpfc_iocbq *irspiocbq;
  8537. unsigned long iflags;
  8538. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8539. /* Get an irspiocbq for later ELS response processing use */
  8540. irspiocbq = lpfc_sli_get_iocbq(phba);
  8541. if (!irspiocbq) {
  8542. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8543. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8544. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8545. pring->txq_cnt, phba->iocb_cnt,
  8546. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8547. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8548. return false;
  8549. }
  8550. /* Save off the slow-path queue event for work thread to process */
  8551. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8552. spin_lock_irqsave(&phba->hbalock, iflags);
  8553. list_add_tail(&irspiocbq->cq_event.list,
  8554. &phba->sli4_hba.sp_queue_event);
  8555. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8556. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8557. return true;
  8558. }
  8559. /**
  8560. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8561. * @phba: Pointer to HBA context object.
  8562. * @wcqe: Pointer to work-queue completion queue entry.
  8563. *
  8564. * This routine handles slow-path WQ entry comsumed event by invoking the
  8565. * proper WQ release routine to the slow-path WQ.
  8566. **/
  8567. static void
  8568. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8569. struct lpfc_wcqe_release *wcqe)
  8570. {
  8571. /* Check for the slow-path ELS work queue */
  8572. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8573. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8574. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8575. else
  8576. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8577. "2579 Slow-path wqe consume event carries "
  8578. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8579. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8580. phba->sli4_hba.els_wq->queue_id);
  8581. }
  8582. /**
  8583. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8584. * @phba: Pointer to HBA context object.
  8585. * @cq: Pointer to a WQ completion queue.
  8586. * @wcqe: Pointer to work-queue completion queue entry.
  8587. *
  8588. * This routine handles an XRI abort event.
  8589. *
  8590. * Return: true if work posted to worker thread, otherwise false.
  8591. **/
  8592. static bool
  8593. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8594. struct lpfc_queue *cq,
  8595. struct sli4_wcqe_xri_aborted *wcqe)
  8596. {
  8597. bool workposted = false;
  8598. struct lpfc_cq_event *cq_event;
  8599. unsigned long iflags;
  8600. /* Allocate a new internal CQ_EVENT entry */
  8601. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8602. if (!cq_event) {
  8603. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8604. "0602 Failed to allocate CQ_EVENT entry\n");
  8605. return false;
  8606. }
  8607. /* Move the CQE into the proper xri abort event list */
  8608. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8609. switch (cq->subtype) {
  8610. case LPFC_FCP:
  8611. spin_lock_irqsave(&phba->hbalock, iflags);
  8612. list_add_tail(&cq_event->list,
  8613. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8614. /* Set the fcp xri abort event flag */
  8615. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8616. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8617. workposted = true;
  8618. break;
  8619. case LPFC_ELS:
  8620. spin_lock_irqsave(&phba->hbalock, iflags);
  8621. list_add_tail(&cq_event->list,
  8622. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8623. /* Set the els xri abort event flag */
  8624. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8625. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8626. workposted = true;
  8627. break;
  8628. default:
  8629. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8630. "0603 Invalid work queue CQE subtype (x%x)\n",
  8631. cq->subtype);
  8632. workposted = false;
  8633. break;
  8634. }
  8635. return workposted;
  8636. }
  8637. /**
  8638. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8639. * @phba: Pointer to HBA context object.
  8640. * @rcqe: Pointer to receive-queue completion queue entry.
  8641. *
  8642. * This routine process a receive-queue completion queue entry.
  8643. *
  8644. * Return: true if work posted to worker thread, otherwise false.
  8645. **/
  8646. static bool
  8647. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8648. {
  8649. bool workposted = false;
  8650. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8651. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8652. struct hbq_dmabuf *dma_buf;
  8653. uint32_t status;
  8654. unsigned long iflags;
  8655. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8656. goto out;
  8657. status = bf_get(lpfc_rcqe_status, rcqe);
  8658. switch (status) {
  8659. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8660. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8661. "2537 Receive Frame Truncated!!\n");
  8662. case FC_STATUS_RQ_SUCCESS:
  8663. lpfc_sli4_rq_release(hrq, drq);
  8664. spin_lock_irqsave(&phba->hbalock, iflags);
  8665. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8666. if (!dma_buf) {
  8667. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8668. goto out;
  8669. }
  8670. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8671. /* save off the frame for the word thread to process */
  8672. list_add_tail(&dma_buf->cq_event.list,
  8673. &phba->sli4_hba.sp_queue_event);
  8674. /* Frame received */
  8675. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8676. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8677. workposted = true;
  8678. break;
  8679. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8680. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8681. /* Post more buffers if possible */
  8682. spin_lock_irqsave(&phba->hbalock, iflags);
  8683. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8684. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8685. workposted = true;
  8686. break;
  8687. }
  8688. out:
  8689. return workposted;
  8690. }
  8691. /**
  8692. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8693. * @phba: Pointer to HBA context object.
  8694. * @cq: Pointer to the completion queue.
  8695. * @wcqe: Pointer to a completion queue entry.
  8696. *
  8697. * This routine process a slow-path work-queue or recieve queue completion queue
  8698. * entry.
  8699. *
  8700. * Return: true if work posted to worker thread, otherwise false.
  8701. **/
  8702. static bool
  8703. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8704. struct lpfc_cqe *cqe)
  8705. {
  8706. struct lpfc_cqe cqevt;
  8707. bool workposted = false;
  8708. /* Copy the work queue CQE and convert endian order if needed */
  8709. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8710. /* Check and process for different type of WCQE and dispatch */
  8711. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8712. case CQE_CODE_COMPL_WQE:
  8713. /* Process the WQ/RQ complete event */
  8714. phba->last_completion_time = jiffies;
  8715. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8716. (struct lpfc_wcqe_complete *)&cqevt);
  8717. break;
  8718. case CQE_CODE_RELEASE_WQE:
  8719. /* Process the WQ release event */
  8720. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8721. (struct lpfc_wcqe_release *)&cqevt);
  8722. break;
  8723. case CQE_CODE_XRI_ABORTED:
  8724. /* Process the WQ XRI abort event */
  8725. phba->last_completion_time = jiffies;
  8726. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8727. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8728. break;
  8729. case CQE_CODE_RECEIVE:
  8730. /* Process the RQ event */
  8731. phba->last_completion_time = jiffies;
  8732. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8733. (struct lpfc_rcqe *)&cqevt);
  8734. break;
  8735. default:
  8736. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8737. "0388 Not a valid WCQE code: x%x\n",
  8738. bf_get(lpfc_cqe_code, &cqevt));
  8739. break;
  8740. }
  8741. return workposted;
  8742. }
  8743. /**
  8744. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8745. * @phba: Pointer to HBA context object.
  8746. * @eqe: Pointer to fast-path event queue entry.
  8747. *
  8748. * This routine process a event queue entry from the slow-path event queue.
  8749. * It will check the MajorCode and MinorCode to determine this is for a
  8750. * completion event on a completion queue, if not, an error shall be logged
  8751. * and just return. Otherwise, it will get to the corresponding completion
  8752. * queue and process all the entries on that completion queue, rearm the
  8753. * completion queue, and then return.
  8754. *
  8755. **/
  8756. static void
  8757. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8758. {
  8759. struct lpfc_queue *cq = NULL, *childq, *speq;
  8760. struct lpfc_cqe *cqe;
  8761. bool workposted = false;
  8762. int ecount = 0;
  8763. uint16_t cqid;
  8764. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8765. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8766. "0359 Not a valid slow-path completion "
  8767. "event: majorcode=x%x, minorcode=x%x\n",
  8768. bf_get_le32(lpfc_eqe_major_code, eqe),
  8769. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8770. return;
  8771. }
  8772. /* Get the reference to the corresponding CQ */
  8773. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8774. /* Search for completion queue pointer matching this cqid */
  8775. speq = phba->sli4_hba.sp_eq;
  8776. list_for_each_entry(childq, &speq->child_list, list) {
  8777. if (childq->queue_id == cqid) {
  8778. cq = childq;
  8779. break;
  8780. }
  8781. }
  8782. if (unlikely(!cq)) {
  8783. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8784. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8785. "0365 Slow-path CQ identifier "
  8786. "(%d) does not exist\n", cqid);
  8787. return;
  8788. }
  8789. /* Process all the entries to the CQ */
  8790. switch (cq->type) {
  8791. case LPFC_MCQ:
  8792. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8793. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8794. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8795. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8796. }
  8797. break;
  8798. case LPFC_WCQ:
  8799. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8800. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8801. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8802. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8803. }
  8804. break;
  8805. default:
  8806. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8807. "0370 Invalid completion queue type (%d)\n",
  8808. cq->type);
  8809. return;
  8810. }
  8811. /* Catch the no cq entry condition, log an error */
  8812. if (unlikely(ecount == 0))
  8813. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8814. "0371 No entry from the CQ: identifier "
  8815. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8816. /* In any case, flash and re-arm the RCQ */
  8817. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8818. /* wake up worker thread if there are works to be done */
  8819. if (workposted)
  8820. lpfc_worker_wake_up(phba);
  8821. }
  8822. /**
  8823. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8824. * @eqe: Pointer to fast-path completion queue entry.
  8825. *
  8826. * This routine process a fast-path work queue completion entry from fast-path
  8827. * event queue for FCP command response completion.
  8828. **/
  8829. static void
  8830. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8831. struct lpfc_wcqe_complete *wcqe)
  8832. {
  8833. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8834. struct lpfc_iocbq *cmdiocbq;
  8835. struct lpfc_iocbq irspiocbq;
  8836. unsigned long iflags;
  8837. spin_lock_irqsave(&phba->hbalock, iflags);
  8838. pring->stats.iocb_event++;
  8839. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8840. /* Check for response status */
  8841. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8842. /* If resource errors reported from HBA, reduce queue
  8843. * depth of the SCSI device.
  8844. */
  8845. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8846. IOSTAT_LOCAL_REJECT) &&
  8847. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8848. phba->lpfc_rampdown_queue_depth(phba);
  8849. }
  8850. /* Log the error status */
  8851. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8852. "0373 FCP complete error: status=x%x, "
  8853. "hw_status=x%x, total_data_specified=%d, "
  8854. "parameter=x%x, word3=x%x\n",
  8855. bf_get(lpfc_wcqe_c_status, wcqe),
  8856. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8857. wcqe->total_data_placed, wcqe->parameter,
  8858. wcqe->word3);
  8859. }
  8860. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8861. spin_lock_irqsave(&phba->hbalock, iflags);
  8862. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8863. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8864. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8865. if (unlikely(!cmdiocbq)) {
  8866. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8867. "0374 FCP complete with no corresponding "
  8868. "cmdiocb: iotag (%d)\n",
  8869. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8870. return;
  8871. }
  8872. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8873. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8874. "0375 FCP cmdiocb not callback function "
  8875. "iotag: (%d)\n",
  8876. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8877. return;
  8878. }
  8879. /* Fake the irspiocb and copy necessary response information */
  8880. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8881. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8882. spin_lock_irqsave(&phba->hbalock, iflags);
  8883. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8884. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8885. }
  8886. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8887. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8888. }
  8889. /**
  8890. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8891. * @phba: Pointer to HBA context object.
  8892. * @cq: Pointer to completion queue.
  8893. * @wcqe: Pointer to work-queue completion queue entry.
  8894. *
  8895. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8896. * proper WQ release routine to the slow-path WQ.
  8897. **/
  8898. static void
  8899. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8900. struct lpfc_wcqe_release *wcqe)
  8901. {
  8902. struct lpfc_queue *childwq;
  8903. bool wqid_matched = false;
  8904. uint16_t fcp_wqid;
  8905. /* Check for fast-path FCP work queue release */
  8906. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8907. list_for_each_entry(childwq, &cq->child_list, list) {
  8908. if (childwq->queue_id == fcp_wqid) {
  8909. lpfc_sli4_wq_release(childwq,
  8910. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8911. wqid_matched = true;
  8912. break;
  8913. }
  8914. }
  8915. /* Report warning log message if no match found */
  8916. if (wqid_matched != true)
  8917. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8918. "2580 Fast-path wqe consume event carries "
  8919. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8920. }
  8921. /**
  8922. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8923. * @cq: Pointer to the completion queue.
  8924. * @eqe: Pointer to fast-path completion queue entry.
  8925. *
  8926. * This routine process a fast-path work queue completion entry from fast-path
  8927. * event queue for FCP command response completion.
  8928. **/
  8929. static int
  8930. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8931. struct lpfc_cqe *cqe)
  8932. {
  8933. struct lpfc_wcqe_release wcqe;
  8934. bool workposted = false;
  8935. /* Copy the work queue CQE and convert endian order if needed */
  8936. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8937. /* Check and process for different type of WCQE and dispatch */
  8938. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8939. case CQE_CODE_COMPL_WQE:
  8940. /* Process the WQ complete event */
  8941. phba->last_completion_time = jiffies;
  8942. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8943. (struct lpfc_wcqe_complete *)&wcqe);
  8944. break;
  8945. case CQE_CODE_RELEASE_WQE:
  8946. /* Process the WQ release event */
  8947. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8948. (struct lpfc_wcqe_release *)&wcqe);
  8949. break;
  8950. case CQE_CODE_XRI_ABORTED:
  8951. /* Process the WQ XRI abort event */
  8952. phba->last_completion_time = jiffies;
  8953. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8954. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8955. break;
  8956. default:
  8957. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8958. "0144 Not a valid WCQE code: x%x\n",
  8959. bf_get(lpfc_wcqe_c_code, &wcqe));
  8960. break;
  8961. }
  8962. return workposted;
  8963. }
  8964. /**
  8965. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8966. * @phba: Pointer to HBA context object.
  8967. * @eqe: Pointer to fast-path event queue entry.
  8968. *
  8969. * This routine process a event queue entry from the fast-path event queue.
  8970. * It will check the MajorCode and MinorCode to determine this is for a
  8971. * completion event on a completion queue, if not, an error shall be logged
  8972. * and just return. Otherwise, it will get to the corresponding completion
  8973. * queue and process all the entries on the completion queue, rearm the
  8974. * completion queue, and then return.
  8975. **/
  8976. static void
  8977. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8978. uint32_t fcp_cqidx)
  8979. {
  8980. struct lpfc_queue *cq;
  8981. struct lpfc_cqe *cqe;
  8982. bool workposted = false;
  8983. uint16_t cqid;
  8984. int ecount = 0;
  8985. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8986. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8987. "0366 Not a valid fast-path completion "
  8988. "event: majorcode=x%x, minorcode=x%x\n",
  8989. bf_get_le32(lpfc_eqe_major_code, eqe),
  8990. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8991. return;
  8992. }
  8993. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8994. if (unlikely(!cq)) {
  8995. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8996. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8997. "0367 Fast-path completion queue "
  8998. "does not exist\n");
  8999. return;
  9000. }
  9001. /* Get the reference to the corresponding CQ */
  9002. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9003. if (unlikely(cqid != cq->queue_id)) {
  9004. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9005. "0368 Miss-matched fast-path completion "
  9006. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9007. cqid, cq->queue_id);
  9008. return;
  9009. }
  9010. /* Process all the entries to the CQ */
  9011. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9012. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9013. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9014. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9015. }
  9016. /* Catch the no cq entry condition */
  9017. if (unlikely(ecount == 0))
  9018. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9019. "0369 No entry from fast-path completion "
  9020. "queue fcpcqid=%d\n", cq->queue_id);
  9021. /* In any case, flash and re-arm the CQ */
  9022. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9023. /* wake up worker thread if there are works to be done */
  9024. if (workposted)
  9025. lpfc_worker_wake_up(phba);
  9026. }
  9027. static void
  9028. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9029. {
  9030. struct lpfc_eqe *eqe;
  9031. /* walk all the EQ entries and drop on the floor */
  9032. while ((eqe = lpfc_sli4_eq_get(eq)))
  9033. ;
  9034. /* Clear and re-arm the EQ */
  9035. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9036. }
  9037. /**
  9038. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9039. * @irq: Interrupt number.
  9040. * @dev_id: The device context pointer.
  9041. *
  9042. * This function is directly called from the PCI layer as an interrupt
  9043. * service routine when device with SLI-4 interface spec is enabled with
  9044. * MSI-X multi-message interrupt mode and there are slow-path events in
  9045. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9046. * interrupt mode, this function is called as part of the device-level
  9047. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9048. * undergoing initialization, the interrupt handler will not process the
  9049. * interrupt. The link attention and ELS ring attention events are handled
  9050. * by the worker thread. The interrupt handler signals the worker thread
  9051. * and returns for these events. This function is called without any lock
  9052. * held. It gets the hbalock to access and update SLI data structures.
  9053. *
  9054. * This function returns IRQ_HANDLED when interrupt is handled else it
  9055. * returns IRQ_NONE.
  9056. **/
  9057. irqreturn_t
  9058. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  9059. {
  9060. struct lpfc_hba *phba;
  9061. struct lpfc_queue *speq;
  9062. struct lpfc_eqe *eqe;
  9063. unsigned long iflag;
  9064. int ecount = 0;
  9065. /*
  9066. * Get the driver's phba structure from the dev_id
  9067. */
  9068. phba = (struct lpfc_hba *)dev_id;
  9069. if (unlikely(!phba))
  9070. return IRQ_NONE;
  9071. /* Get to the EQ struct associated with this vector */
  9072. speq = phba->sli4_hba.sp_eq;
  9073. /* Check device state for handling interrupt */
  9074. if (unlikely(lpfc_intr_state_check(phba))) {
  9075. /* Check again for link_state with lock held */
  9076. spin_lock_irqsave(&phba->hbalock, iflag);
  9077. if (phba->link_state < LPFC_LINK_DOWN)
  9078. /* Flush, clear interrupt, and rearm the EQ */
  9079. lpfc_sli4_eq_flush(phba, speq);
  9080. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9081. return IRQ_NONE;
  9082. }
  9083. /*
  9084. * Process all the event on FCP slow-path EQ
  9085. */
  9086. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9087. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9088. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9089. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9090. }
  9091. /* Always clear and re-arm the slow-path EQ */
  9092. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9093. /* Catch the no cq entry condition */
  9094. if (unlikely(ecount == 0)) {
  9095. if (phba->intr_type == MSIX)
  9096. /* MSI-X treated interrupt served as no EQ share INT */
  9097. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9098. "0357 MSI-X interrupt with no EQE\n");
  9099. else
  9100. /* Non MSI-X treated on interrupt as EQ share INT */
  9101. return IRQ_NONE;
  9102. }
  9103. return IRQ_HANDLED;
  9104. } /* lpfc_sli4_sp_intr_handler */
  9105. /**
  9106. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9107. * @irq: Interrupt number.
  9108. * @dev_id: The device context pointer.
  9109. *
  9110. * This function is directly called from the PCI layer as an interrupt
  9111. * service routine when device with SLI-4 interface spec is enabled with
  9112. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9113. * ring event in the HBA. However, when the device is enabled with either
  9114. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9115. * device-level interrupt handler. When the PCI slot is in error recovery
  9116. * or the HBA is undergoing initialization, the interrupt handler will not
  9117. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9118. * the intrrupt context. This function is called without any lock held.
  9119. * It gets the hbalock to access and update SLI data structures. Note that,
  9120. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9121. * equal to that of FCP CQ index.
  9122. *
  9123. * This function returns IRQ_HANDLED when interrupt is handled else it
  9124. * returns IRQ_NONE.
  9125. **/
  9126. irqreturn_t
  9127. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9128. {
  9129. struct lpfc_hba *phba;
  9130. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9131. struct lpfc_queue *fpeq;
  9132. struct lpfc_eqe *eqe;
  9133. unsigned long iflag;
  9134. int ecount = 0;
  9135. uint32_t fcp_eqidx;
  9136. /* Get the driver's phba structure from the dev_id */
  9137. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9138. phba = fcp_eq_hdl->phba;
  9139. fcp_eqidx = fcp_eq_hdl->idx;
  9140. if (unlikely(!phba))
  9141. return IRQ_NONE;
  9142. /* Get to the EQ struct associated with this vector */
  9143. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9144. /* Check device state for handling interrupt */
  9145. if (unlikely(lpfc_intr_state_check(phba))) {
  9146. /* Check again for link_state with lock held */
  9147. spin_lock_irqsave(&phba->hbalock, iflag);
  9148. if (phba->link_state < LPFC_LINK_DOWN)
  9149. /* Flush, clear interrupt, and rearm the EQ */
  9150. lpfc_sli4_eq_flush(phba, fpeq);
  9151. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9152. return IRQ_NONE;
  9153. }
  9154. /*
  9155. * Process all the event on FCP fast-path EQ
  9156. */
  9157. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9158. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9159. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9160. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9161. }
  9162. /* Always clear and re-arm the fast-path EQ */
  9163. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9164. if (unlikely(ecount == 0)) {
  9165. if (phba->intr_type == MSIX)
  9166. /* MSI-X treated interrupt served as no EQ share INT */
  9167. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9168. "0358 MSI-X interrupt with no EQE\n");
  9169. else
  9170. /* Non MSI-X treated on interrupt as EQ share INT */
  9171. return IRQ_NONE;
  9172. }
  9173. return IRQ_HANDLED;
  9174. } /* lpfc_sli4_fp_intr_handler */
  9175. /**
  9176. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9177. * @irq: Interrupt number.
  9178. * @dev_id: The device context pointer.
  9179. *
  9180. * This function is the device-level interrupt handler to device with SLI-4
  9181. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9182. * interrupt mode is enabled and there is an event in the HBA which requires
  9183. * driver attention. This function invokes the slow-path interrupt attention
  9184. * handling function and fast-path interrupt attention handling function in
  9185. * turn to process the relevant HBA attention events. This function is called
  9186. * without any lock held. It gets the hbalock to access and update SLI data
  9187. * structures.
  9188. *
  9189. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9190. * returns IRQ_NONE.
  9191. **/
  9192. irqreturn_t
  9193. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9194. {
  9195. struct lpfc_hba *phba;
  9196. irqreturn_t sp_irq_rc, fp_irq_rc;
  9197. bool fp_handled = false;
  9198. uint32_t fcp_eqidx;
  9199. /* Get the driver's phba structure from the dev_id */
  9200. phba = (struct lpfc_hba *)dev_id;
  9201. if (unlikely(!phba))
  9202. return IRQ_NONE;
  9203. /*
  9204. * Invokes slow-path host attention interrupt handling as appropriate.
  9205. */
  9206. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9207. /*
  9208. * Invoke fast-path host attention interrupt handling as appropriate.
  9209. */
  9210. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9211. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9212. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9213. if (fp_irq_rc == IRQ_HANDLED)
  9214. fp_handled |= true;
  9215. }
  9216. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9217. } /* lpfc_sli4_intr_handler */
  9218. /**
  9219. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9220. * @queue: The queue structure to free.
  9221. *
  9222. * This function frees a queue structure and the DMAable memeory used for
  9223. * the host resident queue. This function must be called after destroying the
  9224. * queue on the HBA.
  9225. **/
  9226. void
  9227. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9228. {
  9229. struct lpfc_dmabuf *dmabuf;
  9230. if (!queue)
  9231. return;
  9232. while (!list_empty(&queue->page_list)) {
  9233. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9234. list);
  9235. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9236. dmabuf->virt, dmabuf->phys);
  9237. kfree(dmabuf);
  9238. }
  9239. kfree(queue);
  9240. return;
  9241. }
  9242. /**
  9243. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9244. * @phba: The HBA that this queue is being created on.
  9245. * @entry_size: The size of each queue entry for this queue.
  9246. * @entry count: The number of entries that this queue will handle.
  9247. *
  9248. * This function allocates a queue structure and the DMAable memory used for
  9249. * the host resident queue. This function must be called before creating the
  9250. * queue on the HBA.
  9251. **/
  9252. struct lpfc_queue *
  9253. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9254. uint32_t entry_count)
  9255. {
  9256. struct lpfc_queue *queue;
  9257. struct lpfc_dmabuf *dmabuf;
  9258. int x, total_qe_count;
  9259. void *dma_pointer;
  9260. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9261. if (!phba->sli4_hba.pc_sli4_params.supported)
  9262. hw_page_size = SLI4_PAGE_SIZE;
  9263. queue = kzalloc(sizeof(struct lpfc_queue) +
  9264. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9265. if (!queue)
  9266. return NULL;
  9267. queue->page_count = (ALIGN(entry_size * entry_count,
  9268. hw_page_size))/hw_page_size;
  9269. INIT_LIST_HEAD(&queue->list);
  9270. INIT_LIST_HEAD(&queue->page_list);
  9271. INIT_LIST_HEAD(&queue->child_list);
  9272. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9273. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9274. if (!dmabuf)
  9275. goto out_fail;
  9276. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9277. hw_page_size, &dmabuf->phys,
  9278. GFP_KERNEL);
  9279. if (!dmabuf->virt) {
  9280. kfree(dmabuf);
  9281. goto out_fail;
  9282. }
  9283. memset(dmabuf->virt, 0, hw_page_size);
  9284. dmabuf->buffer_tag = x;
  9285. list_add_tail(&dmabuf->list, &queue->page_list);
  9286. /* initialize queue's entry array */
  9287. dma_pointer = dmabuf->virt;
  9288. for (; total_qe_count < entry_count &&
  9289. dma_pointer < (hw_page_size + dmabuf->virt);
  9290. total_qe_count++, dma_pointer += entry_size) {
  9291. queue->qe[total_qe_count].address = dma_pointer;
  9292. }
  9293. }
  9294. queue->entry_size = entry_size;
  9295. queue->entry_count = entry_count;
  9296. queue->phba = phba;
  9297. return queue;
  9298. out_fail:
  9299. lpfc_sli4_queue_free(queue);
  9300. return NULL;
  9301. }
  9302. /**
  9303. * lpfc_eq_create - Create an Event Queue on the HBA
  9304. * @phba: HBA structure that indicates port to create a queue on.
  9305. * @eq: The queue structure to use to create the event queue.
  9306. * @imax: The maximum interrupt per second limit.
  9307. *
  9308. * This function creates an event queue, as detailed in @eq, on a port,
  9309. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9310. *
  9311. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9312. * is used to get the entry count and entry size that are necessary to
  9313. * determine the number of pages to allocate and use for this queue. This
  9314. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9315. * event queue. This function is asynchronous and will wait for the mailbox
  9316. * command to finish before continuing.
  9317. *
  9318. * On success this function will return a zero. If unable to allocate enough
  9319. * memory this function will return -ENOMEM. If the queue create mailbox command
  9320. * fails this function will return -ENXIO.
  9321. **/
  9322. uint32_t
  9323. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9324. {
  9325. struct lpfc_mbx_eq_create *eq_create;
  9326. LPFC_MBOXQ_t *mbox;
  9327. int rc, length, status = 0;
  9328. struct lpfc_dmabuf *dmabuf;
  9329. uint32_t shdr_status, shdr_add_status;
  9330. union lpfc_sli4_cfg_shdr *shdr;
  9331. uint16_t dmult;
  9332. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9333. if (!phba->sli4_hba.pc_sli4_params.supported)
  9334. hw_page_size = SLI4_PAGE_SIZE;
  9335. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9336. if (!mbox)
  9337. return -ENOMEM;
  9338. length = (sizeof(struct lpfc_mbx_eq_create) -
  9339. sizeof(struct lpfc_sli4_cfg_mhdr));
  9340. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9341. LPFC_MBOX_OPCODE_EQ_CREATE,
  9342. length, LPFC_SLI4_MBX_EMBED);
  9343. eq_create = &mbox->u.mqe.un.eq_create;
  9344. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9345. eq->page_count);
  9346. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9347. LPFC_EQE_SIZE);
  9348. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9349. /* Calculate delay multiper from maximum interrupt per second */
  9350. dmult = LPFC_DMULT_CONST/imax - 1;
  9351. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9352. dmult);
  9353. switch (eq->entry_count) {
  9354. default:
  9355. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9356. "0360 Unsupported EQ count. (%d)\n",
  9357. eq->entry_count);
  9358. if (eq->entry_count < 256)
  9359. return -EINVAL;
  9360. /* otherwise default to smallest count (drop through) */
  9361. case 256:
  9362. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9363. LPFC_EQ_CNT_256);
  9364. break;
  9365. case 512:
  9366. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9367. LPFC_EQ_CNT_512);
  9368. break;
  9369. case 1024:
  9370. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9371. LPFC_EQ_CNT_1024);
  9372. break;
  9373. case 2048:
  9374. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9375. LPFC_EQ_CNT_2048);
  9376. break;
  9377. case 4096:
  9378. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9379. LPFC_EQ_CNT_4096);
  9380. break;
  9381. }
  9382. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9383. memset(dmabuf->virt, 0, hw_page_size);
  9384. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9385. putPaddrLow(dmabuf->phys);
  9386. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9387. putPaddrHigh(dmabuf->phys);
  9388. }
  9389. mbox->vport = phba->pport;
  9390. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9391. mbox->context1 = NULL;
  9392. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9393. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9394. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9395. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9396. if (shdr_status || shdr_add_status || rc) {
  9397. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9398. "2500 EQ_CREATE mailbox failed with "
  9399. "status x%x add_status x%x, mbx status x%x\n",
  9400. shdr_status, shdr_add_status, rc);
  9401. status = -ENXIO;
  9402. }
  9403. eq->type = LPFC_EQ;
  9404. eq->subtype = LPFC_NONE;
  9405. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9406. if (eq->queue_id == 0xFFFF)
  9407. status = -ENXIO;
  9408. eq->host_index = 0;
  9409. eq->hba_index = 0;
  9410. mempool_free(mbox, phba->mbox_mem_pool);
  9411. return status;
  9412. }
  9413. /**
  9414. * lpfc_cq_create - Create a Completion Queue on the HBA
  9415. * @phba: HBA structure that indicates port to create a queue on.
  9416. * @cq: The queue structure to use to create the completion queue.
  9417. * @eq: The event queue to bind this completion queue to.
  9418. *
  9419. * This function creates a completion queue, as detailed in @wq, on a port,
  9420. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9421. *
  9422. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9423. * is used to get the entry count and entry size that are necessary to
  9424. * determine the number of pages to allocate and use for this queue. The @eq
  9425. * is used to indicate which event queue to bind this completion queue to. This
  9426. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9427. * completion queue. This function is asynchronous and will wait for the mailbox
  9428. * command to finish before continuing.
  9429. *
  9430. * On success this function will return a zero. If unable to allocate enough
  9431. * memory this function will return -ENOMEM. If the queue create mailbox command
  9432. * fails this function will return -ENXIO.
  9433. **/
  9434. uint32_t
  9435. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9436. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9437. {
  9438. struct lpfc_mbx_cq_create *cq_create;
  9439. struct lpfc_dmabuf *dmabuf;
  9440. LPFC_MBOXQ_t *mbox;
  9441. int rc, length, status = 0;
  9442. uint32_t shdr_status, shdr_add_status;
  9443. union lpfc_sli4_cfg_shdr *shdr;
  9444. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9445. if (!phba->sli4_hba.pc_sli4_params.supported)
  9446. hw_page_size = SLI4_PAGE_SIZE;
  9447. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9448. if (!mbox)
  9449. return -ENOMEM;
  9450. length = (sizeof(struct lpfc_mbx_cq_create) -
  9451. sizeof(struct lpfc_sli4_cfg_mhdr));
  9452. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9453. LPFC_MBOX_OPCODE_CQ_CREATE,
  9454. length, LPFC_SLI4_MBX_EMBED);
  9455. cq_create = &mbox->u.mqe.un.cq_create;
  9456. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9457. cq->page_count);
  9458. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9459. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9460. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  9461. switch (cq->entry_count) {
  9462. default:
  9463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9464. "0361 Unsupported CQ count. (%d)\n",
  9465. cq->entry_count);
  9466. if (cq->entry_count < 256)
  9467. return -EINVAL;
  9468. /* otherwise default to smallest count (drop through) */
  9469. case 256:
  9470. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9471. LPFC_CQ_CNT_256);
  9472. break;
  9473. case 512:
  9474. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9475. LPFC_CQ_CNT_512);
  9476. break;
  9477. case 1024:
  9478. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9479. LPFC_CQ_CNT_1024);
  9480. break;
  9481. }
  9482. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9483. memset(dmabuf->virt, 0, hw_page_size);
  9484. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9485. putPaddrLow(dmabuf->phys);
  9486. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9487. putPaddrHigh(dmabuf->phys);
  9488. }
  9489. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9490. /* The IOCTL status is embedded in the mailbox subheader. */
  9491. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9492. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9493. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9494. if (shdr_status || shdr_add_status || rc) {
  9495. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9496. "2501 CQ_CREATE mailbox failed with "
  9497. "status x%x add_status x%x, mbx status x%x\n",
  9498. shdr_status, shdr_add_status, rc);
  9499. status = -ENXIO;
  9500. goto out;
  9501. }
  9502. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9503. if (cq->queue_id == 0xFFFF) {
  9504. status = -ENXIO;
  9505. goto out;
  9506. }
  9507. /* link the cq onto the parent eq child list */
  9508. list_add_tail(&cq->list, &eq->child_list);
  9509. /* Set up completion queue's type and subtype */
  9510. cq->type = type;
  9511. cq->subtype = subtype;
  9512. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9513. cq->host_index = 0;
  9514. cq->hba_index = 0;
  9515. out:
  9516. mempool_free(mbox, phba->mbox_mem_pool);
  9517. return status;
  9518. }
  9519. /**
  9520. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9521. * @phba: HBA structure that indicates port to create a queue on.
  9522. * @mq: The queue structure to use to create the mailbox queue.
  9523. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9524. * @cq: The completion queue to associate with this cq.
  9525. *
  9526. * This function provides failback (fb) functionality when the
  9527. * mq_create_ext fails on older FW generations. It's purpose is identical
  9528. * to mq_create_ext otherwise.
  9529. *
  9530. * This routine cannot fail as all attributes were previously accessed and
  9531. * initialized in mq_create_ext.
  9532. **/
  9533. static void
  9534. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9535. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9536. {
  9537. struct lpfc_mbx_mq_create *mq_create;
  9538. struct lpfc_dmabuf *dmabuf;
  9539. int length;
  9540. length = (sizeof(struct lpfc_mbx_mq_create) -
  9541. sizeof(struct lpfc_sli4_cfg_mhdr));
  9542. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9543. LPFC_MBOX_OPCODE_MQ_CREATE,
  9544. length, LPFC_SLI4_MBX_EMBED);
  9545. mq_create = &mbox->u.mqe.un.mq_create;
  9546. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9547. mq->page_count);
  9548. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9549. cq->queue_id);
  9550. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9551. switch (mq->entry_count) {
  9552. case 16:
  9553. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9554. LPFC_MQ_CNT_16);
  9555. break;
  9556. case 32:
  9557. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9558. LPFC_MQ_CNT_32);
  9559. break;
  9560. case 64:
  9561. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9562. LPFC_MQ_CNT_64);
  9563. break;
  9564. case 128:
  9565. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9566. LPFC_MQ_CNT_128);
  9567. break;
  9568. }
  9569. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9570. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9571. putPaddrLow(dmabuf->phys);
  9572. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9573. putPaddrHigh(dmabuf->phys);
  9574. }
  9575. }
  9576. /**
  9577. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9578. * @phba: HBA structure that indicates port to create a queue on.
  9579. * @mq: The queue structure to use to create the mailbox queue.
  9580. * @cq: The completion queue to associate with this cq.
  9581. * @subtype: The queue's subtype.
  9582. *
  9583. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9584. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9585. *
  9586. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9587. * is used to get the entry count and entry size that are necessary to
  9588. * determine the number of pages to allocate and use for this queue. This
  9589. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9590. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9591. * command to finish before continuing.
  9592. *
  9593. * On success this function will return a zero. If unable to allocate enough
  9594. * memory this function will return -ENOMEM. If the queue create mailbox command
  9595. * fails this function will return -ENXIO.
  9596. **/
  9597. int32_t
  9598. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9599. struct lpfc_queue *cq, uint32_t subtype)
  9600. {
  9601. struct lpfc_mbx_mq_create *mq_create;
  9602. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9603. struct lpfc_dmabuf *dmabuf;
  9604. LPFC_MBOXQ_t *mbox;
  9605. int rc, length, status = 0;
  9606. uint32_t shdr_status, shdr_add_status;
  9607. union lpfc_sli4_cfg_shdr *shdr;
  9608. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9609. if (!phba->sli4_hba.pc_sli4_params.supported)
  9610. hw_page_size = SLI4_PAGE_SIZE;
  9611. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9612. if (!mbox)
  9613. return -ENOMEM;
  9614. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9615. sizeof(struct lpfc_sli4_cfg_mhdr));
  9616. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9617. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9618. length, LPFC_SLI4_MBX_EMBED);
  9619. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9620. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9621. mq->page_count);
  9622. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9623. 1);
  9624. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9625. &mq_create_ext->u.request, 1);
  9626. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9627. &mq_create_ext->u.request, 1);
  9628. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9629. cq->queue_id);
  9630. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9631. switch (mq->entry_count) {
  9632. default:
  9633. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9634. "0362 Unsupported MQ count. (%d)\n",
  9635. mq->entry_count);
  9636. if (mq->entry_count < 16)
  9637. return -EINVAL;
  9638. /* otherwise default to smallest count (drop through) */
  9639. case 16:
  9640. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9641. LPFC_MQ_CNT_16);
  9642. break;
  9643. case 32:
  9644. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9645. LPFC_MQ_CNT_32);
  9646. break;
  9647. case 64:
  9648. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9649. LPFC_MQ_CNT_64);
  9650. break;
  9651. case 128:
  9652. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9653. LPFC_MQ_CNT_128);
  9654. break;
  9655. }
  9656. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9657. memset(dmabuf->virt, 0, hw_page_size);
  9658. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9659. putPaddrLow(dmabuf->phys);
  9660. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9661. putPaddrHigh(dmabuf->phys);
  9662. }
  9663. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9664. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9665. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9666. &mq_create_ext->u.response);
  9667. if (rc != MBX_SUCCESS) {
  9668. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9669. "2795 MQ_CREATE_EXT failed with "
  9670. "status x%x. Failback to MQ_CREATE.\n",
  9671. rc);
  9672. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9673. mq_create = &mbox->u.mqe.un.mq_create;
  9674. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9675. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9676. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9677. &mq_create->u.response);
  9678. }
  9679. /* The IOCTL status is embedded in the mailbox subheader. */
  9680. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9681. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9682. if (shdr_status || shdr_add_status || rc) {
  9683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9684. "2502 MQ_CREATE mailbox failed with "
  9685. "status x%x add_status x%x, mbx status x%x\n",
  9686. shdr_status, shdr_add_status, rc);
  9687. status = -ENXIO;
  9688. goto out;
  9689. }
  9690. if (mq->queue_id == 0xFFFF) {
  9691. status = -ENXIO;
  9692. goto out;
  9693. }
  9694. mq->type = LPFC_MQ;
  9695. mq->subtype = subtype;
  9696. mq->host_index = 0;
  9697. mq->hba_index = 0;
  9698. /* link the mq onto the parent cq child list */
  9699. list_add_tail(&mq->list, &cq->child_list);
  9700. out:
  9701. mempool_free(mbox, phba->mbox_mem_pool);
  9702. return status;
  9703. }
  9704. /**
  9705. * lpfc_wq_create - Create a Work Queue on the HBA
  9706. * @phba: HBA structure that indicates port to create a queue on.
  9707. * @wq: The queue structure to use to create the work queue.
  9708. * @cq: The completion queue to bind this work queue to.
  9709. * @subtype: The subtype of the work queue indicating its functionality.
  9710. *
  9711. * This function creates a work queue, as detailed in @wq, on a port, described
  9712. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9713. *
  9714. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9715. * is used to get the entry count and entry size that are necessary to
  9716. * determine the number of pages to allocate and use for this queue. The @cq
  9717. * is used to indicate which completion queue to bind this work queue to. This
  9718. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9719. * work queue. This function is asynchronous and will wait for the mailbox
  9720. * command to finish before continuing.
  9721. *
  9722. * On success this function will return a zero. If unable to allocate enough
  9723. * memory this function will return -ENOMEM. If the queue create mailbox command
  9724. * fails this function will return -ENXIO.
  9725. **/
  9726. uint32_t
  9727. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9728. struct lpfc_queue *cq, uint32_t subtype)
  9729. {
  9730. struct lpfc_mbx_wq_create *wq_create;
  9731. struct lpfc_dmabuf *dmabuf;
  9732. LPFC_MBOXQ_t *mbox;
  9733. int rc, length, status = 0;
  9734. uint32_t shdr_status, shdr_add_status;
  9735. union lpfc_sli4_cfg_shdr *shdr;
  9736. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9737. if (!phba->sli4_hba.pc_sli4_params.supported)
  9738. hw_page_size = SLI4_PAGE_SIZE;
  9739. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9740. if (!mbox)
  9741. return -ENOMEM;
  9742. length = (sizeof(struct lpfc_mbx_wq_create) -
  9743. sizeof(struct lpfc_sli4_cfg_mhdr));
  9744. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9745. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9746. length, LPFC_SLI4_MBX_EMBED);
  9747. wq_create = &mbox->u.mqe.un.wq_create;
  9748. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9749. wq->page_count);
  9750. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9751. cq->queue_id);
  9752. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9753. memset(dmabuf->virt, 0, hw_page_size);
  9754. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9755. putPaddrLow(dmabuf->phys);
  9756. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9757. putPaddrHigh(dmabuf->phys);
  9758. }
  9759. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9760. /* The IOCTL status is embedded in the mailbox subheader. */
  9761. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9762. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9763. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9764. if (shdr_status || shdr_add_status || rc) {
  9765. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9766. "2503 WQ_CREATE mailbox failed with "
  9767. "status x%x add_status x%x, mbx status x%x\n",
  9768. shdr_status, shdr_add_status, rc);
  9769. status = -ENXIO;
  9770. goto out;
  9771. }
  9772. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9773. if (wq->queue_id == 0xFFFF) {
  9774. status = -ENXIO;
  9775. goto out;
  9776. }
  9777. wq->type = LPFC_WQ;
  9778. wq->subtype = subtype;
  9779. wq->host_index = 0;
  9780. wq->hba_index = 0;
  9781. /* link the wq onto the parent cq child list */
  9782. list_add_tail(&wq->list, &cq->child_list);
  9783. out:
  9784. mempool_free(mbox, phba->mbox_mem_pool);
  9785. return status;
  9786. }
  9787. /**
  9788. * lpfc_rq_create - Create a Receive Queue on the HBA
  9789. * @phba: HBA structure that indicates port to create a queue on.
  9790. * @hrq: The queue structure to use to create the header receive queue.
  9791. * @drq: The queue structure to use to create the data receive queue.
  9792. * @cq: The completion queue to bind this work queue to.
  9793. *
  9794. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9795. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9796. * to the HBA.
  9797. *
  9798. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9799. * struct is used to get the entry count that is necessary to determine the
  9800. * number of pages to use for this queue. The @cq is used to indicate which
  9801. * completion queue to bind received buffers that are posted to these queues to.
  9802. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9803. * receive queue pair. This function is asynchronous and will wait for the
  9804. * mailbox command to finish before continuing.
  9805. *
  9806. * On success this function will return a zero. If unable to allocate enough
  9807. * memory this function will return -ENOMEM. If the queue create mailbox command
  9808. * fails this function will return -ENXIO.
  9809. **/
  9810. uint32_t
  9811. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9812. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9813. {
  9814. struct lpfc_mbx_rq_create *rq_create;
  9815. struct lpfc_dmabuf *dmabuf;
  9816. LPFC_MBOXQ_t *mbox;
  9817. int rc, length, status = 0;
  9818. uint32_t shdr_status, shdr_add_status;
  9819. union lpfc_sli4_cfg_shdr *shdr;
  9820. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9821. if (!phba->sli4_hba.pc_sli4_params.supported)
  9822. hw_page_size = SLI4_PAGE_SIZE;
  9823. if (hrq->entry_count != drq->entry_count)
  9824. return -EINVAL;
  9825. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9826. if (!mbox)
  9827. return -ENOMEM;
  9828. length = (sizeof(struct lpfc_mbx_rq_create) -
  9829. sizeof(struct lpfc_sli4_cfg_mhdr));
  9830. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9831. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9832. length, LPFC_SLI4_MBX_EMBED);
  9833. rq_create = &mbox->u.mqe.un.rq_create;
  9834. switch (hrq->entry_count) {
  9835. default:
  9836. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9837. "2535 Unsupported RQ count. (%d)\n",
  9838. hrq->entry_count);
  9839. if (hrq->entry_count < 512)
  9840. return -EINVAL;
  9841. /* otherwise default to smallest count (drop through) */
  9842. case 512:
  9843. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9844. LPFC_RQ_RING_SIZE_512);
  9845. break;
  9846. case 1024:
  9847. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9848. LPFC_RQ_RING_SIZE_1024);
  9849. break;
  9850. case 2048:
  9851. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9852. LPFC_RQ_RING_SIZE_2048);
  9853. break;
  9854. case 4096:
  9855. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9856. LPFC_RQ_RING_SIZE_4096);
  9857. break;
  9858. }
  9859. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9860. cq->queue_id);
  9861. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9862. hrq->page_count);
  9863. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9864. LPFC_HDR_BUF_SIZE);
  9865. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9866. memset(dmabuf->virt, 0, hw_page_size);
  9867. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9868. putPaddrLow(dmabuf->phys);
  9869. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9870. putPaddrHigh(dmabuf->phys);
  9871. }
  9872. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9873. /* The IOCTL status is embedded in the mailbox subheader. */
  9874. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9875. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9876. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9877. if (shdr_status || shdr_add_status || rc) {
  9878. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9879. "2504 RQ_CREATE mailbox failed with "
  9880. "status x%x add_status x%x, mbx status x%x\n",
  9881. shdr_status, shdr_add_status, rc);
  9882. status = -ENXIO;
  9883. goto out;
  9884. }
  9885. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9886. if (hrq->queue_id == 0xFFFF) {
  9887. status = -ENXIO;
  9888. goto out;
  9889. }
  9890. hrq->type = LPFC_HRQ;
  9891. hrq->subtype = subtype;
  9892. hrq->host_index = 0;
  9893. hrq->hba_index = 0;
  9894. /* now create the data queue */
  9895. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9896. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9897. length, LPFC_SLI4_MBX_EMBED);
  9898. switch (drq->entry_count) {
  9899. default:
  9900. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9901. "2536 Unsupported RQ count. (%d)\n",
  9902. drq->entry_count);
  9903. if (drq->entry_count < 512)
  9904. return -EINVAL;
  9905. /* otherwise default to smallest count (drop through) */
  9906. case 512:
  9907. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9908. LPFC_RQ_RING_SIZE_512);
  9909. break;
  9910. case 1024:
  9911. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9912. LPFC_RQ_RING_SIZE_1024);
  9913. break;
  9914. case 2048:
  9915. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9916. LPFC_RQ_RING_SIZE_2048);
  9917. break;
  9918. case 4096:
  9919. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9920. LPFC_RQ_RING_SIZE_4096);
  9921. break;
  9922. }
  9923. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9924. cq->queue_id);
  9925. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9926. drq->page_count);
  9927. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9928. LPFC_DATA_BUF_SIZE);
  9929. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9930. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9931. putPaddrLow(dmabuf->phys);
  9932. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9933. putPaddrHigh(dmabuf->phys);
  9934. }
  9935. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9936. /* The IOCTL status is embedded in the mailbox subheader. */
  9937. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9938. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9939. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9940. if (shdr_status || shdr_add_status || rc) {
  9941. status = -ENXIO;
  9942. goto out;
  9943. }
  9944. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9945. if (drq->queue_id == 0xFFFF) {
  9946. status = -ENXIO;
  9947. goto out;
  9948. }
  9949. drq->type = LPFC_DRQ;
  9950. drq->subtype = subtype;
  9951. drq->host_index = 0;
  9952. drq->hba_index = 0;
  9953. /* link the header and data RQs onto the parent cq child list */
  9954. list_add_tail(&hrq->list, &cq->child_list);
  9955. list_add_tail(&drq->list, &cq->child_list);
  9956. out:
  9957. mempool_free(mbox, phba->mbox_mem_pool);
  9958. return status;
  9959. }
  9960. /**
  9961. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9962. * @eq: The queue structure associated with the queue to destroy.
  9963. *
  9964. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9965. * command, specific to the type of queue, to the HBA.
  9966. *
  9967. * The @eq struct is used to get the queue ID of the queue to destroy.
  9968. *
  9969. * On success this function will return a zero. If the queue destroy mailbox
  9970. * command fails this function will return -ENXIO.
  9971. **/
  9972. uint32_t
  9973. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9974. {
  9975. LPFC_MBOXQ_t *mbox;
  9976. int rc, length, status = 0;
  9977. uint32_t shdr_status, shdr_add_status;
  9978. union lpfc_sli4_cfg_shdr *shdr;
  9979. if (!eq)
  9980. return -ENODEV;
  9981. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9982. if (!mbox)
  9983. return -ENOMEM;
  9984. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9985. sizeof(struct lpfc_sli4_cfg_mhdr));
  9986. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9987. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9988. length, LPFC_SLI4_MBX_EMBED);
  9989. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9990. eq->queue_id);
  9991. mbox->vport = eq->phba->pport;
  9992. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9993. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9994. /* The IOCTL status is embedded in the mailbox subheader. */
  9995. shdr = (union lpfc_sli4_cfg_shdr *)
  9996. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9997. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9998. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9999. if (shdr_status || shdr_add_status || rc) {
  10000. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10001. "2505 EQ_DESTROY mailbox failed with "
  10002. "status x%x add_status x%x, mbx status x%x\n",
  10003. shdr_status, shdr_add_status, rc);
  10004. status = -ENXIO;
  10005. }
  10006. /* Remove eq from any list */
  10007. list_del_init(&eq->list);
  10008. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10009. return status;
  10010. }
  10011. /**
  10012. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10013. * @cq: The queue structure associated with the queue to destroy.
  10014. *
  10015. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10016. * command, specific to the type of queue, to the HBA.
  10017. *
  10018. * The @cq struct is used to get the queue ID of the queue to destroy.
  10019. *
  10020. * On success this function will return a zero. If the queue destroy mailbox
  10021. * command fails this function will return -ENXIO.
  10022. **/
  10023. uint32_t
  10024. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10025. {
  10026. LPFC_MBOXQ_t *mbox;
  10027. int rc, length, status = 0;
  10028. uint32_t shdr_status, shdr_add_status;
  10029. union lpfc_sli4_cfg_shdr *shdr;
  10030. if (!cq)
  10031. return -ENODEV;
  10032. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10033. if (!mbox)
  10034. return -ENOMEM;
  10035. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10036. sizeof(struct lpfc_sli4_cfg_mhdr));
  10037. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10038. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10039. length, LPFC_SLI4_MBX_EMBED);
  10040. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10041. cq->queue_id);
  10042. mbox->vport = cq->phba->pport;
  10043. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10044. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10045. /* The IOCTL status is embedded in the mailbox subheader. */
  10046. shdr = (union lpfc_sli4_cfg_shdr *)
  10047. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10048. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10049. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10050. if (shdr_status || shdr_add_status || rc) {
  10051. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10052. "2506 CQ_DESTROY mailbox failed with "
  10053. "status x%x add_status x%x, mbx status x%x\n",
  10054. shdr_status, shdr_add_status, rc);
  10055. status = -ENXIO;
  10056. }
  10057. /* Remove cq from any list */
  10058. list_del_init(&cq->list);
  10059. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10060. return status;
  10061. }
  10062. /**
  10063. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10064. * @qm: The queue structure associated with the queue to destroy.
  10065. *
  10066. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10067. * command, specific to the type of queue, to the HBA.
  10068. *
  10069. * The @mq struct is used to get the queue ID of the queue to destroy.
  10070. *
  10071. * On success this function will return a zero. If the queue destroy mailbox
  10072. * command fails this function will return -ENXIO.
  10073. **/
  10074. uint32_t
  10075. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10076. {
  10077. LPFC_MBOXQ_t *mbox;
  10078. int rc, length, status = 0;
  10079. uint32_t shdr_status, shdr_add_status;
  10080. union lpfc_sli4_cfg_shdr *shdr;
  10081. if (!mq)
  10082. return -ENODEV;
  10083. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10084. if (!mbox)
  10085. return -ENOMEM;
  10086. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10087. sizeof(struct lpfc_sli4_cfg_mhdr));
  10088. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10089. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10090. length, LPFC_SLI4_MBX_EMBED);
  10091. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10092. mq->queue_id);
  10093. mbox->vport = mq->phba->pport;
  10094. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10095. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10096. /* The IOCTL status is embedded in the mailbox subheader. */
  10097. shdr = (union lpfc_sli4_cfg_shdr *)
  10098. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10099. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10100. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10101. if (shdr_status || shdr_add_status || rc) {
  10102. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10103. "2507 MQ_DESTROY mailbox failed with "
  10104. "status x%x add_status x%x, mbx status x%x\n",
  10105. shdr_status, shdr_add_status, rc);
  10106. status = -ENXIO;
  10107. }
  10108. /* Remove mq from any list */
  10109. list_del_init(&mq->list);
  10110. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10111. return status;
  10112. }
  10113. /**
  10114. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10115. * @wq: The queue structure associated with the queue to destroy.
  10116. *
  10117. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10118. * command, specific to the type of queue, to the HBA.
  10119. *
  10120. * The @wq struct is used to get the queue ID of the queue to destroy.
  10121. *
  10122. * On success this function will return a zero. If the queue destroy mailbox
  10123. * command fails this function will return -ENXIO.
  10124. **/
  10125. uint32_t
  10126. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10127. {
  10128. LPFC_MBOXQ_t *mbox;
  10129. int rc, length, status = 0;
  10130. uint32_t shdr_status, shdr_add_status;
  10131. union lpfc_sli4_cfg_shdr *shdr;
  10132. if (!wq)
  10133. return -ENODEV;
  10134. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10135. if (!mbox)
  10136. return -ENOMEM;
  10137. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10138. sizeof(struct lpfc_sli4_cfg_mhdr));
  10139. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10140. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10141. length, LPFC_SLI4_MBX_EMBED);
  10142. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10143. wq->queue_id);
  10144. mbox->vport = wq->phba->pport;
  10145. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10146. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10147. shdr = (union lpfc_sli4_cfg_shdr *)
  10148. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10149. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10150. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10151. if (shdr_status || shdr_add_status || rc) {
  10152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10153. "2508 WQ_DESTROY mailbox failed with "
  10154. "status x%x add_status x%x, mbx status x%x\n",
  10155. shdr_status, shdr_add_status, rc);
  10156. status = -ENXIO;
  10157. }
  10158. /* Remove wq from any list */
  10159. list_del_init(&wq->list);
  10160. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10161. return status;
  10162. }
  10163. /**
  10164. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10165. * @rq: The queue structure associated with the queue to destroy.
  10166. *
  10167. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10168. * command, specific to the type of queue, to the HBA.
  10169. *
  10170. * The @rq struct is used to get the queue ID of the queue to destroy.
  10171. *
  10172. * On success this function will return a zero. If the queue destroy mailbox
  10173. * command fails this function will return -ENXIO.
  10174. **/
  10175. uint32_t
  10176. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10177. struct lpfc_queue *drq)
  10178. {
  10179. LPFC_MBOXQ_t *mbox;
  10180. int rc, length, status = 0;
  10181. uint32_t shdr_status, shdr_add_status;
  10182. union lpfc_sli4_cfg_shdr *shdr;
  10183. if (!hrq || !drq)
  10184. return -ENODEV;
  10185. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10186. if (!mbox)
  10187. return -ENOMEM;
  10188. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10189. sizeof(struct mbox_header));
  10190. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10191. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10192. length, LPFC_SLI4_MBX_EMBED);
  10193. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10194. hrq->queue_id);
  10195. mbox->vport = hrq->phba->pport;
  10196. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10197. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10198. /* The IOCTL status is embedded in the mailbox subheader. */
  10199. shdr = (union lpfc_sli4_cfg_shdr *)
  10200. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10201. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10202. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10203. if (shdr_status || shdr_add_status || rc) {
  10204. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10205. "2509 RQ_DESTROY mailbox failed with "
  10206. "status x%x add_status x%x, mbx status x%x\n",
  10207. shdr_status, shdr_add_status, rc);
  10208. if (rc != MBX_TIMEOUT)
  10209. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10210. return -ENXIO;
  10211. }
  10212. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10213. drq->queue_id);
  10214. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10215. shdr = (union lpfc_sli4_cfg_shdr *)
  10216. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10217. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10218. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10219. if (shdr_status || shdr_add_status || rc) {
  10220. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10221. "2510 RQ_DESTROY mailbox failed with "
  10222. "status x%x add_status x%x, mbx status x%x\n",
  10223. shdr_status, shdr_add_status, rc);
  10224. status = -ENXIO;
  10225. }
  10226. list_del_init(&hrq->list);
  10227. list_del_init(&drq->list);
  10228. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10229. return status;
  10230. }
  10231. /**
  10232. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10233. * @phba: The virtual port for which this call being executed.
  10234. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10235. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10236. * @xritag: the xritag that ties this io to the SGL pages.
  10237. *
  10238. * This routine will post the sgl pages for the IO that has the xritag
  10239. * that is in the iocbq structure. The xritag is assigned during iocbq
  10240. * creation and persists for as long as the driver is loaded.
  10241. * if the caller has fewer than 256 scatter gather segments to map then
  10242. * pdma_phys_addr1 should be 0.
  10243. * If the caller needs to map more than 256 scatter gather segment then
  10244. * pdma_phys_addr1 should be a valid physical address.
  10245. * physical address for SGLs must be 64 byte aligned.
  10246. * If you are going to map 2 SGL's then the first one must have 256 entries
  10247. * the second sgl can have between 1 and 256 entries.
  10248. *
  10249. * Return codes:
  10250. * 0 - Success
  10251. * -ENXIO, -ENOMEM - Failure
  10252. **/
  10253. int
  10254. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10255. dma_addr_t pdma_phys_addr0,
  10256. dma_addr_t pdma_phys_addr1,
  10257. uint16_t xritag)
  10258. {
  10259. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10260. LPFC_MBOXQ_t *mbox;
  10261. int rc;
  10262. uint32_t shdr_status, shdr_add_status;
  10263. union lpfc_sli4_cfg_shdr *shdr;
  10264. if (xritag == NO_XRI) {
  10265. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10266. "0364 Invalid param:\n");
  10267. return -EINVAL;
  10268. }
  10269. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10270. if (!mbox)
  10271. return -ENOMEM;
  10272. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10273. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10274. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10275. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10276. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10277. &mbox->u.mqe.un.post_sgl_pages;
  10278. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10279. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10280. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10281. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10282. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10283. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10284. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10285. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10286. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10287. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10288. if (!phba->sli4_hba.intr_enable)
  10289. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10290. else
  10291. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10292. /* The IOCTL status is embedded in the mailbox subheader. */
  10293. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10294. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10295. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10296. if (rc != MBX_TIMEOUT)
  10297. mempool_free(mbox, phba->mbox_mem_pool);
  10298. if (shdr_status || shdr_add_status || rc) {
  10299. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10300. "2511 POST_SGL mailbox failed with "
  10301. "status x%x add_status x%x, mbx status x%x\n",
  10302. shdr_status, shdr_add_status, rc);
  10303. rc = -ENXIO;
  10304. }
  10305. return 0;
  10306. }
  10307. /**
  10308. * lpfc_sli4_next_xritag - Get an xritag for the io
  10309. * @phba: Pointer to HBA context object.
  10310. *
  10311. * This function gets an xritag for the iocb. If there is no unused xritag
  10312. * it will return 0xffff.
  10313. * The function returns the allocated xritag if successful, else returns zero.
  10314. * Zero is not a valid xritag.
  10315. * The caller is not required to hold any lock.
  10316. **/
  10317. uint16_t
  10318. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10319. {
  10320. uint16_t xritag;
  10321. spin_lock_irq(&phba->hbalock);
  10322. xritag = phba->sli4_hba.next_xri;
  10323. if ((xritag != (uint16_t) -1) && xritag <
  10324. (phba->sli4_hba.max_cfg_param.max_xri
  10325. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10326. phba->sli4_hba.next_xri++;
  10327. phba->sli4_hba.max_cfg_param.xri_used++;
  10328. spin_unlock_irq(&phba->hbalock);
  10329. return xritag;
  10330. }
  10331. spin_unlock_irq(&phba->hbalock);
  10332. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10333. "2004 Failed to allocate XRI.last XRITAG is %d"
  10334. " Max XRI is %d, Used XRI is %d\n",
  10335. phba->sli4_hba.next_xri,
  10336. phba->sli4_hba.max_cfg_param.max_xri,
  10337. phba->sli4_hba.max_cfg_param.xri_used);
  10338. return -1;
  10339. }
  10340. /**
  10341. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10342. * @phba: pointer to lpfc hba data structure.
  10343. *
  10344. * This routine is invoked to post a block of driver's sgl pages to the
  10345. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10346. * is only called when the driver is loading and after all IO has been
  10347. * stopped.
  10348. **/
  10349. int
  10350. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10351. {
  10352. struct lpfc_sglq *sglq_entry;
  10353. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10354. struct sgl_page_pairs *sgl_pg_pairs;
  10355. void *viraddr;
  10356. LPFC_MBOXQ_t *mbox;
  10357. uint32_t reqlen, alloclen, pg_pairs;
  10358. uint32_t mbox_tmo;
  10359. uint16_t xritag_start = 0;
  10360. int els_xri_cnt, rc = 0;
  10361. uint32_t shdr_status, shdr_add_status;
  10362. union lpfc_sli4_cfg_shdr *shdr;
  10363. /* The number of sgls to be posted */
  10364. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10365. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10366. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10367. if (reqlen > SLI4_PAGE_SIZE) {
  10368. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10369. "2559 Block sgl registration required DMA "
  10370. "size (%d) great than a page\n", reqlen);
  10371. return -ENOMEM;
  10372. }
  10373. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10374. if (!mbox) {
  10375. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10376. "2560 Failed to allocate mbox cmd memory\n");
  10377. return -ENOMEM;
  10378. }
  10379. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10380. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10381. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10382. LPFC_SLI4_MBX_NEMBED);
  10383. if (alloclen < reqlen) {
  10384. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10385. "0285 Allocated DMA memory size (%d) is "
  10386. "less than the requested DMA memory "
  10387. "size (%d)\n", alloclen, reqlen);
  10388. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10389. return -ENOMEM;
  10390. }
  10391. /* Get the first SGE entry from the non-embedded DMA memory */
  10392. viraddr = mbox->sge_array->addr[0];
  10393. /* Set up the SGL pages in the non-embedded DMA pages */
  10394. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10395. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10396. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10397. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10398. /* Set up the sge entry */
  10399. sgl_pg_pairs->sgl_pg0_addr_lo =
  10400. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10401. sgl_pg_pairs->sgl_pg0_addr_hi =
  10402. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10403. sgl_pg_pairs->sgl_pg1_addr_lo =
  10404. cpu_to_le32(putPaddrLow(0));
  10405. sgl_pg_pairs->sgl_pg1_addr_hi =
  10406. cpu_to_le32(putPaddrHigh(0));
  10407. /* Keep the first xritag on the list */
  10408. if (pg_pairs == 0)
  10409. xritag_start = sglq_entry->sli4_xritag;
  10410. sgl_pg_pairs++;
  10411. }
  10412. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10413. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10414. /* Perform endian conversion if necessary */
  10415. sgl->word0 = cpu_to_le32(sgl->word0);
  10416. if (!phba->sli4_hba.intr_enable)
  10417. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10418. else {
  10419. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10420. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10421. }
  10422. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10423. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10424. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10425. if (rc != MBX_TIMEOUT)
  10426. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10427. if (shdr_status || shdr_add_status || rc) {
  10428. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10429. "2513 POST_SGL_BLOCK mailbox command failed "
  10430. "status x%x add_status x%x mbx status x%x\n",
  10431. shdr_status, shdr_add_status, rc);
  10432. rc = -ENXIO;
  10433. }
  10434. return rc;
  10435. }
  10436. /**
  10437. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10438. * @phba: pointer to lpfc hba data structure.
  10439. * @sblist: pointer to scsi buffer list.
  10440. * @count: number of scsi buffers on the list.
  10441. *
  10442. * This routine is invoked to post a block of @count scsi sgl pages from a
  10443. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10444. * No Lock is held.
  10445. *
  10446. **/
  10447. int
  10448. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10449. int cnt)
  10450. {
  10451. struct lpfc_scsi_buf *psb;
  10452. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10453. struct sgl_page_pairs *sgl_pg_pairs;
  10454. void *viraddr;
  10455. LPFC_MBOXQ_t *mbox;
  10456. uint32_t reqlen, alloclen, pg_pairs;
  10457. uint32_t mbox_tmo;
  10458. uint16_t xritag_start = 0;
  10459. int rc = 0;
  10460. uint32_t shdr_status, shdr_add_status;
  10461. dma_addr_t pdma_phys_bpl1;
  10462. union lpfc_sli4_cfg_shdr *shdr;
  10463. /* Calculate the requested length of the dma memory */
  10464. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10465. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10466. if (reqlen > SLI4_PAGE_SIZE) {
  10467. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10468. "0217 Block sgl registration required DMA "
  10469. "size (%d) great than a page\n", reqlen);
  10470. return -ENOMEM;
  10471. }
  10472. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10473. if (!mbox) {
  10474. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10475. "0283 Failed to allocate mbox cmd memory\n");
  10476. return -ENOMEM;
  10477. }
  10478. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10479. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10480. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10481. LPFC_SLI4_MBX_NEMBED);
  10482. if (alloclen < reqlen) {
  10483. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10484. "2561 Allocated DMA memory size (%d) is "
  10485. "less than the requested DMA memory "
  10486. "size (%d)\n", alloclen, reqlen);
  10487. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10488. return -ENOMEM;
  10489. }
  10490. /* Get the first SGE entry from the non-embedded DMA memory */
  10491. viraddr = mbox->sge_array->addr[0];
  10492. /* Set up the SGL pages in the non-embedded DMA pages */
  10493. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10494. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10495. pg_pairs = 0;
  10496. list_for_each_entry(psb, sblist, list) {
  10497. /* Set up the sge entry */
  10498. sgl_pg_pairs->sgl_pg0_addr_lo =
  10499. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10500. sgl_pg_pairs->sgl_pg0_addr_hi =
  10501. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10502. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10503. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10504. else
  10505. pdma_phys_bpl1 = 0;
  10506. sgl_pg_pairs->sgl_pg1_addr_lo =
  10507. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10508. sgl_pg_pairs->sgl_pg1_addr_hi =
  10509. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10510. /* Keep the first xritag on the list */
  10511. if (pg_pairs == 0)
  10512. xritag_start = psb->cur_iocbq.sli4_xritag;
  10513. sgl_pg_pairs++;
  10514. pg_pairs++;
  10515. }
  10516. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10517. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10518. /* Perform endian conversion if necessary */
  10519. sgl->word0 = cpu_to_le32(sgl->word0);
  10520. if (!phba->sli4_hba.intr_enable)
  10521. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10522. else {
  10523. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10524. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10525. }
  10526. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10527. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10528. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10529. if (rc != MBX_TIMEOUT)
  10530. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10531. if (shdr_status || shdr_add_status || rc) {
  10532. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10533. "2564 POST_SGL_BLOCK mailbox command failed "
  10534. "status x%x add_status x%x mbx status x%x\n",
  10535. shdr_status, shdr_add_status, rc);
  10536. rc = -ENXIO;
  10537. }
  10538. return rc;
  10539. }
  10540. /**
  10541. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10542. * @phba: pointer to lpfc_hba struct that the frame was received on
  10543. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10544. *
  10545. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10546. * valid type of frame that the LPFC driver will handle. This function will
  10547. * return a zero if the frame is a valid frame or a non zero value when the
  10548. * frame does not pass the check.
  10549. **/
  10550. static int
  10551. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10552. {
  10553. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10554. char *type_names[] = FC_TYPE_NAMES_INIT;
  10555. struct fc_vft_header *fc_vft_hdr;
  10556. switch (fc_hdr->fh_r_ctl) {
  10557. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10558. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10559. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10560. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10561. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10562. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10563. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10564. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10565. case FC_RCTL_ELS_REQ: /* extended link services request */
  10566. case FC_RCTL_ELS_REP: /* extended link services reply */
  10567. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10568. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10569. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10570. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10571. case FC_RCTL_BA_RMC: /* remove connection */
  10572. case FC_RCTL_BA_ACC: /* basic accept */
  10573. case FC_RCTL_BA_RJT: /* basic reject */
  10574. case FC_RCTL_BA_PRMT:
  10575. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10576. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10577. case FC_RCTL_P_RJT: /* port reject */
  10578. case FC_RCTL_F_RJT: /* fabric reject */
  10579. case FC_RCTL_P_BSY: /* port busy */
  10580. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10581. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10582. case FC_RCTL_LCR: /* link credit reset */
  10583. case FC_RCTL_END: /* end */
  10584. break;
  10585. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10586. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10587. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10588. return lpfc_fc_frame_check(phba, fc_hdr);
  10589. default:
  10590. goto drop;
  10591. }
  10592. switch (fc_hdr->fh_type) {
  10593. case FC_TYPE_BLS:
  10594. case FC_TYPE_ELS:
  10595. case FC_TYPE_FCP:
  10596. case FC_TYPE_CT:
  10597. break;
  10598. case FC_TYPE_IP:
  10599. case FC_TYPE_ILS:
  10600. default:
  10601. goto drop;
  10602. }
  10603. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10604. "2538 Received frame rctl:%s type:%s\n",
  10605. rctl_names[fc_hdr->fh_r_ctl],
  10606. type_names[fc_hdr->fh_type]);
  10607. return 0;
  10608. drop:
  10609. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10610. "2539 Dropped frame rctl:%s type:%s\n",
  10611. rctl_names[fc_hdr->fh_r_ctl],
  10612. type_names[fc_hdr->fh_type]);
  10613. return 1;
  10614. }
  10615. /**
  10616. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10617. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10618. *
  10619. * This function processes the FC header to retrieve the VFI from the VF
  10620. * header, if one exists. This function will return the VFI if one exists
  10621. * or 0 if no VSAN Header exists.
  10622. **/
  10623. static uint32_t
  10624. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10625. {
  10626. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10627. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10628. return 0;
  10629. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10630. }
  10631. /**
  10632. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10633. * @phba: Pointer to the HBA structure to search for the vport on
  10634. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10635. * @fcfi: The FC Fabric ID that the frame came from
  10636. *
  10637. * This function searches the @phba for a vport that matches the content of the
  10638. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10639. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10640. * returns the matching vport pointer or NULL if unable to match frame to a
  10641. * vport.
  10642. **/
  10643. static struct lpfc_vport *
  10644. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10645. uint16_t fcfi)
  10646. {
  10647. struct lpfc_vport **vports;
  10648. struct lpfc_vport *vport = NULL;
  10649. int i;
  10650. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10651. fc_hdr->fh_d_id[1] << 8 |
  10652. fc_hdr->fh_d_id[2]);
  10653. vports = lpfc_create_vport_work_array(phba);
  10654. if (vports != NULL)
  10655. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10656. if (phba->fcf.fcfi == fcfi &&
  10657. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10658. vports[i]->fc_myDID == did) {
  10659. vport = vports[i];
  10660. break;
  10661. }
  10662. }
  10663. lpfc_destroy_vport_work_array(phba, vports);
  10664. return vport;
  10665. }
  10666. /**
  10667. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10668. * @vport: The vport to work on.
  10669. *
  10670. * This function updates the receive sequence time stamp for this vport. The
  10671. * receive sequence time stamp indicates the time that the last frame of the
  10672. * the sequence that has been idle for the longest amount of time was received.
  10673. * the driver uses this time stamp to indicate if any received sequences have
  10674. * timed out.
  10675. **/
  10676. void
  10677. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10678. {
  10679. struct lpfc_dmabuf *h_buf;
  10680. struct hbq_dmabuf *dmabuf = NULL;
  10681. /* get the oldest sequence on the rcv list */
  10682. h_buf = list_get_first(&vport->rcv_buffer_list,
  10683. struct lpfc_dmabuf, list);
  10684. if (!h_buf)
  10685. return;
  10686. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10687. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10688. }
  10689. /**
  10690. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10691. * @vport: The vport that the received sequences were sent to.
  10692. *
  10693. * This function cleans up all outstanding received sequences. This is called
  10694. * by the driver when a link event or user action invalidates all the received
  10695. * sequences.
  10696. **/
  10697. void
  10698. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10699. {
  10700. struct lpfc_dmabuf *h_buf, *hnext;
  10701. struct lpfc_dmabuf *d_buf, *dnext;
  10702. struct hbq_dmabuf *dmabuf = NULL;
  10703. /* start with the oldest sequence on the rcv list */
  10704. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10705. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10706. list_del_init(&dmabuf->hbuf.list);
  10707. list_for_each_entry_safe(d_buf, dnext,
  10708. &dmabuf->dbuf.list, list) {
  10709. list_del_init(&d_buf->list);
  10710. lpfc_in_buf_free(vport->phba, d_buf);
  10711. }
  10712. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10713. }
  10714. }
  10715. /**
  10716. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10717. * @vport: The vport that the received sequences were sent to.
  10718. *
  10719. * This function determines whether any received sequences have timed out by
  10720. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10721. * indicates that there is at least one timed out sequence this routine will
  10722. * go through the received sequences one at a time from most inactive to most
  10723. * active to determine which ones need to be cleaned up. Once it has determined
  10724. * that a sequence needs to be cleaned up it will simply free up the resources
  10725. * without sending an abort.
  10726. **/
  10727. void
  10728. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10729. {
  10730. struct lpfc_dmabuf *h_buf, *hnext;
  10731. struct lpfc_dmabuf *d_buf, *dnext;
  10732. struct hbq_dmabuf *dmabuf = NULL;
  10733. unsigned long timeout;
  10734. int abort_count = 0;
  10735. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10736. vport->rcv_buffer_time_stamp);
  10737. if (list_empty(&vport->rcv_buffer_list) ||
  10738. time_before(jiffies, timeout))
  10739. return;
  10740. /* start with the oldest sequence on the rcv list */
  10741. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10742. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10743. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10744. dmabuf->time_stamp);
  10745. if (time_before(jiffies, timeout))
  10746. break;
  10747. abort_count++;
  10748. list_del_init(&dmabuf->hbuf.list);
  10749. list_for_each_entry_safe(d_buf, dnext,
  10750. &dmabuf->dbuf.list, list) {
  10751. list_del_init(&d_buf->list);
  10752. lpfc_in_buf_free(vport->phba, d_buf);
  10753. }
  10754. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10755. }
  10756. if (abort_count)
  10757. lpfc_update_rcv_time_stamp(vport);
  10758. }
  10759. /**
  10760. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10761. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10762. *
  10763. * This function searches through the existing incomplete sequences that have
  10764. * been sent to this @vport. If the frame matches one of the incomplete
  10765. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10766. * make up that sequence. If no sequence is found that matches this frame then
  10767. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10768. * This function returns a pointer to the first dmabuf in the sequence list that
  10769. * the frame was linked to.
  10770. **/
  10771. static struct hbq_dmabuf *
  10772. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10773. {
  10774. struct fc_frame_header *new_hdr;
  10775. struct fc_frame_header *temp_hdr;
  10776. struct lpfc_dmabuf *d_buf;
  10777. struct lpfc_dmabuf *h_buf;
  10778. struct hbq_dmabuf *seq_dmabuf = NULL;
  10779. struct hbq_dmabuf *temp_dmabuf = NULL;
  10780. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10781. dmabuf->time_stamp = jiffies;
  10782. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10783. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10784. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10785. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10786. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10787. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10788. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10789. continue;
  10790. /* found a pending sequence that matches this frame */
  10791. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10792. break;
  10793. }
  10794. if (!seq_dmabuf) {
  10795. /*
  10796. * This indicates first frame received for this sequence.
  10797. * Queue the buffer on the vport's rcv_buffer_list.
  10798. */
  10799. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10800. lpfc_update_rcv_time_stamp(vport);
  10801. return dmabuf;
  10802. }
  10803. temp_hdr = seq_dmabuf->hbuf.virt;
  10804. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10805. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10806. list_del_init(&seq_dmabuf->hbuf.list);
  10807. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10808. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10809. lpfc_update_rcv_time_stamp(vport);
  10810. return dmabuf;
  10811. }
  10812. /* move this sequence to the tail to indicate a young sequence */
  10813. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10814. seq_dmabuf->time_stamp = jiffies;
  10815. lpfc_update_rcv_time_stamp(vport);
  10816. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10817. temp_hdr = dmabuf->hbuf.virt;
  10818. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10819. return seq_dmabuf;
  10820. }
  10821. /* find the correct place in the sequence to insert this frame */
  10822. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10823. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10824. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10825. /*
  10826. * If the frame's sequence count is greater than the frame on
  10827. * the list then insert the frame right after this frame
  10828. */
  10829. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10830. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10831. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10832. return seq_dmabuf;
  10833. }
  10834. }
  10835. return NULL;
  10836. }
  10837. /**
  10838. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10839. * @vport: pointer to a vitural port
  10840. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10841. *
  10842. * This function tries to abort from the partially assembed sequence, described
  10843. * by the information from basic abbort @dmabuf. It checks to see whether such
  10844. * partially assembled sequence held by the driver. If so, it shall free up all
  10845. * the frames from the partially assembled sequence.
  10846. *
  10847. * Return
  10848. * true -- if there is matching partially assembled sequence present and all
  10849. * the frames freed with the sequence;
  10850. * false -- if there is no matching partially assembled sequence present so
  10851. * nothing got aborted in the lower layer driver
  10852. **/
  10853. static bool
  10854. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10855. struct hbq_dmabuf *dmabuf)
  10856. {
  10857. struct fc_frame_header *new_hdr;
  10858. struct fc_frame_header *temp_hdr;
  10859. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10860. struct hbq_dmabuf *seq_dmabuf = NULL;
  10861. /* Use the hdr_buf to find the sequence that matches this frame */
  10862. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10863. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10864. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10865. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10866. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10867. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10868. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10869. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10870. continue;
  10871. /* found a pending sequence that matches this frame */
  10872. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10873. break;
  10874. }
  10875. /* Free up all the frames from the partially assembled sequence */
  10876. if (seq_dmabuf) {
  10877. list_for_each_entry_safe(d_buf, n_buf,
  10878. &seq_dmabuf->dbuf.list, list) {
  10879. list_del_init(&d_buf->list);
  10880. lpfc_in_buf_free(vport->phba, d_buf);
  10881. }
  10882. return true;
  10883. }
  10884. return false;
  10885. }
  10886. /**
  10887. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10888. * @phba: Pointer to HBA context object.
  10889. * @cmd_iocbq: pointer to the command iocbq structure.
  10890. * @rsp_iocbq: pointer to the response iocbq structure.
  10891. *
  10892. * This function handles the sequence abort accept iocb command complete
  10893. * event. It properly releases the memory allocated to the sequence abort
  10894. * accept iocb.
  10895. **/
  10896. static void
  10897. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10898. struct lpfc_iocbq *cmd_iocbq,
  10899. struct lpfc_iocbq *rsp_iocbq)
  10900. {
  10901. if (cmd_iocbq)
  10902. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10903. }
  10904. /**
  10905. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10906. * @phba: Pointer to HBA context object.
  10907. * @fc_hdr: pointer to a FC frame header.
  10908. *
  10909. * This function sends a basic accept to a previous unsol sequence abort
  10910. * event after aborting the sequence handling.
  10911. **/
  10912. static void
  10913. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10914. struct fc_frame_header *fc_hdr)
  10915. {
  10916. struct lpfc_iocbq *ctiocb = NULL;
  10917. struct lpfc_nodelist *ndlp;
  10918. uint16_t oxid, rxid;
  10919. uint32_t sid, fctl;
  10920. IOCB_t *icmd;
  10921. if (!lpfc_is_link_up(phba))
  10922. return;
  10923. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10924. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10925. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10926. ndlp = lpfc_findnode_did(phba->pport, sid);
  10927. if (!ndlp) {
  10928. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10929. "1268 Find ndlp returned NULL for oxid:x%x "
  10930. "SID:x%x\n", oxid, sid);
  10931. return;
  10932. }
  10933. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  10934. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  10935. + phba->sli4_hba.max_cfg_param.xri_base))
  10936. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  10937. /* Allocate buffer for acc iocb */
  10938. ctiocb = lpfc_sli_get_iocbq(phba);
  10939. if (!ctiocb)
  10940. return;
  10941. /* Extract the F_CTL field from FC_HDR */
  10942. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10943. icmd = &ctiocb->iocb;
  10944. icmd->un.xseq64.bdl.bdeSize = 0;
  10945. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10946. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10947. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10948. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10949. /* Fill in the rest of iocb fields */
  10950. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10951. icmd->ulpBdeCount = 0;
  10952. icmd->ulpLe = 1;
  10953. icmd->ulpClass = CLASS3;
  10954. icmd->ulpContext = ndlp->nlp_rpi;
  10955. ctiocb->context1 = ndlp;
  10956. ctiocb->iocb_cmpl = NULL;
  10957. ctiocb->vport = phba->pport;
  10958. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10959. if (fctl & FC_FC_EX_CTX) {
  10960. /* ABTS sent by responder to CT exchange, construction
  10961. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10962. * field and RX_ID from ABTS for RX_ID field.
  10963. */
  10964. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10965. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10966. ctiocb->sli4_xritag = oxid;
  10967. } else {
  10968. /* ABTS sent by initiator to CT exchange, construction
  10969. * of BA_ACC will need to allocate a new XRI as for the
  10970. * XRI_TAG and RX_ID fields.
  10971. */
  10972. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10973. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10974. ctiocb->sli4_xritag = NO_XRI;
  10975. }
  10976. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10977. /* Xmit CT abts accept on exchange <xid> */
  10978. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10979. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10980. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10981. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10982. }
  10983. /**
  10984. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10985. * @vport: Pointer to the vport on which this sequence was received
  10986. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10987. *
  10988. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10989. * receive sequence is only partially assembed by the driver, it shall abort
  10990. * the partially assembled frames for the sequence. Otherwise, if the
  10991. * unsolicited receive sequence has been completely assembled and passed to
  10992. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10993. * unsolicited sequence has been aborted. After that, it will issue a basic
  10994. * accept to accept the abort.
  10995. **/
  10996. void
  10997. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10998. struct hbq_dmabuf *dmabuf)
  10999. {
  11000. struct lpfc_hba *phba = vport->phba;
  11001. struct fc_frame_header fc_hdr;
  11002. uint32_t fctl;
  11003. bool abts_par;
  11004. /* Make a copy of fc_hdr before the dmabuf being released */
  11005. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11006. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11007. if (fctl & FC_FC_EX_CTX) {
  11008. /*
  11009. * ABTS sent by responder to exchange, just free the buffer
  11010. */
  11011. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11012. } else {
  11013. /*
  11014. * ABTS sent by initiator to exchange, need to do cleanup
  11015. */
  11016. /* Try to abort partially assembled seq */
  11017. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11018. /* Send abort to ULP if partially seq abort failed */
  11019. if (abts_par == false)
  11020. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11021. else
  11022. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11023. }
  11024. /* Send basic accept (BA_ACC) to the abort requester */
  11025. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  11026. }
  11027. /**
  11028. * lpfc_seq_complete - Indicates if a sequence is complete
  11029. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11030. *
  11031. * This function checks the sequence, starting with the frame described by
  11032. * @dmabuf, to see if all the frames associated with this sequence are present.
  11033. * the frames associated with this sequence are linked to the @dmabuf using the
  11034. * dbuf list. This function looks for two major things. 1) That the first frame
  11035. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11036. * set. 3) That there are no holes in the sequence count. The function will
  11037. * return 1 when the sequence is complete, otherwise it will return 0.
  11038. **/
  11039. static int
  11040. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11041. {
  11042. struct fc_frame_header *hdr;
  11043. struct lpfc_dmabuf *d_buf;
  11044. struct hbq_dmabuf *seq_dmabuf;
  11045. uint32_t fctl;
  11046. int seq_count = 0;
  11047. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11048. /* make sure first fame of sequence has a sequence count of zero */
  11049. if (hdr->fh_seq_cnt != seq_count)
  11050. return 0;
  11051. fctl = (hdr->fh_f_ctl[0] << 16 |
  11052. hdr->fh_f_ctl[1] << 8 |
  11053. hdr->fh_f_ctl[2]);
  11054. /* If last frame of sequence we can return success. */
  11055. if (fctl & FC_FC_END_SEQ)
  11056. return 1;
  11057. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11058. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11059. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11060. /* If there is a hole in the sequence count then fail. */
  11061. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11062. return 0;
  11063. fctl = (hdr->fh_f_ctl[0] << 16 |
  11064. hdr->fh_f_ctl[1] << 8 |
  11065. hdr->fh_f_ctl[2]);
  11066. /* If last frame of sequence we can return success. */
  11067. if (fctl & FC_FC_END_SEQ)
  11068. return 1;
  11069. }
  11070. return 0;
  11071. }
  11072. /**
  11073. * lpfc_prep_seq - Prep sequence for ULP processing
  11074. * @vport: Pointer to the vport on which this sequence was received
  11075. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11076. *
  11077. * This function takes a sequence, described by a list of frames, and creates
  11078. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11079. * used to issue to the generic unsolicited sequence handler. This routine
  11080. * returns a pointer to the first iocbq in the list. If the function is unable
  11081. * to allocate an iocbq then it throw out the received frames that were not
  11082. * able to be described and return a pointer to the first iocbq. If unable to
  11083. * allocate any iocbqs (including the first) this function will return NULL.
  11084. **/
  11085. static struct lpfc_iocbq *
  11086. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11087. {
  11088. struct lpfc_dmabuf *d_buf, *n_buf;
  11089. struct lpfc_iocbq *first_iocbq, *iocbq;
  11090. struct fc_frame_header *fc_hdr;
  11091. uint32_t sid;
  11092. struct ulp_bde64 *pbde;
  11093. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11094. /* remove from receive buffer list */
  11095. list_del_init(&seq_dmabuf->hbuf.list);
  11096. lpfc_update_rcv_time_stamp(vport);
  11097. /* get the Remote Port's SID */
  11098. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11099. /* Get an iocbq struct to fill in. */
  11100. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11101. if (first_iocbq) {
  11102. /* Initialize the first IOCB. */
  11103. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11104. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11105. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11106. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11107. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11108. vport->vpi + vport->phba->vpi_base;
  11109. /* put the first buffer into the first IOCBq */
  11110. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11111. first_iocbq->context3 = NULL;
  11112. first_iocbq->iocb.ulpBdeCount = 1;
  11113. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11114. LPFC_DATA_BUF_SIZE;
  11115. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11116. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11117. bf_get(lpfc_rcqe_length,
  11118. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11119. }
  11120. iocbq = first_iocbq;
  11121. /*
  11122. * Each IOCBq can have two Buffers assigned, so go through the list
  11123. * of buffers for this sequence and save two buffers in each IOCBq
  11124. */
  11125. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11126. if (!iocbq) {
  11127. lpfc_in_buf_free(vport->phba, d_buf);
  11128. continue;
  11129. }
  11130. if (!iocbq->context3) {
  11131. iocbq->context3 = d_buf;
  11132. iocbq->iocb.ulpBdeCount++;
  11133. pbde = (struct ulp_bde64 *)
  11134. &iocbq->iocb.unsli3.sli3Words[4];
  11135. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11136. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11137. bf_get(lpfc_rcqe_length,
  11138. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11139. } else {
  11140. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11141. if (!iocbq) {
  11142. if (first_iocbq) {
  11143. first_iocbq->iocb.ulpStatus =
  11144. IOSTAT_FCP_RSP_ERROR;
  11145. first_iocbq->iocb.un.ulpWord[4] =
  11146. IOERR_NO_RESOURCES;
  11147. }
  11148. lpfc_in_buf_free(vport->phba, d_buf);
  11149. continue;
  11150. }
  11151. iocbq->context2 = d_buf;
  11152. iocbq->context3 = NULL;
  11153. iocbq->iocb.ulpBdeCount = 1;
  11154. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11155. LPFC_DATA_BUF_SIZE;
  11156. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11157. bf_get(lpfc_rcqe_length,
  11158. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11159. iocbq->iocb.un.rcvels.remoteID = sid;
  11160. list_add_tail(&iocbq->list, &first_iocbq->list);
  11161. }
  11162. }
  11163. return first_iocbq;
  11164. }
  11165. static void
  11166. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11167. struct hbq_dmabuf *seq_dmabuf)
  11168. {
  11169. struct fc_frame_header *fc_hdr;
  11170. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11171. struct lpfc_hba *phba = vport->phba;
  11172. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11173. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11174. if (!iocbq) {
  11175. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11176. "2707 Ring %d handler: Failed to allocate "
  11177. "iocb Rctl x%x Type x%x received\n",
  11178. LPFC_ELS_RING,
  11179. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11180. return;
  11181. }
  11182. if (!lpfc_complete_unsol_iocb(phba,
  11183. &phba->sli.ring[LPFC_ELS_RING],
  11184. iocbq, fc_hdr->fh_r_ctl,
  11185. fc_hdr->fh_type))
  11186. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11187. "2540 Ring %d handler: unexpected Rctl "
  11188. "x%x Type x%x received\n",
  11189. LPFC_ELS_RING,
  11190. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11191. /* Free iocb created in lpfc_prep_seq */
  11192. list_for_each_entry_safe(curr_iocb, next_iocb,
  11193. &iocbq->list, list) {
  11194. list_del_init(&curr_iocb->list);
  11195. lpfc_sli_release_iocbq(phba, curr_iocb);
  11196. }
  11197. lpfc_sli_release_iocbq(phba, iocbq);
  11198. }
  11199. /**
  11200. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11201. * @phba: Pointer to HBA context object.
  11202. *
  11203. * This function is called with no lock held. This function processes all
  11204. * the received buffers and gives it to upper layers when a received buffer
  11205. * indicates that it is the final frame in the sequence. The interrupt
  11206. * service routine processes received buffers at interrupt contexts and adds
  11207. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11208. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11209. * appropriate receive function when the final frame in a sequence is received.
  11210. **/
  11211. void
  11212. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11213. struct hbq_dmabuf *dmabuf)
  11214. {
  11215. struct hbq_dmabuf *seq_dmabuf;
  11216. struct fc_frame_header *fc_hdr;
  11217. struct lpfc_vport *vport;
  11218. uint32_t fcfi;
  11219. /* Process each received buffer */
  11220. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11221. /* check to see if this a valid type of frame */
  11222. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11223. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11224. return;
  11225. }
  11226. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11227. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11228. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11229. /* throw out the frame */
  11230. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11231. return;
  11232. }
  11233. /* Handle the basic abort sequence (BA_ABTS) event */
  11234. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11235. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11236. return;
  11237. }
  11238. /* Link this frame */
  11239. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11240. if (!seq_dmabuf) {
  11241. /* unable to add frame to vport - throw it out */
  11242. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11243. return;
  11244. }
  11245. /* If not last frame in sequence continue processing frames. */
  11246. if (!lpfc_seq_complete(seq_dmabuf))
  11247. return;
  11248. /* Send the complete sequence to the upper layer protocol */
  11249. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11250. }
  11251. /**
  11252. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11253. * @phba: pointer to lpfc hba data structure.
  11254. *
  11255. * This routine is invoked to post rpi header templates to the
  11256. * HBA consistent with the SLI-4 interface spec. This routine
  11257. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11258. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11259. *
  11260. * This routine does not require any locks. It's usage is expected
  11261. * to be driver load or reset recovery when the driver is
  11262. * sequential.
  11263. *
  11264. * Return codes
  11265. * 0 - successful
  11266. * -EIO - The mailbox failed to complete successfully.
  11267. * When this error occurs, the driver is not guaranteed
  11268. * to have any rpi regions posted to the device and
  11269. * must either attempt to repost the regions or take a
  11270. * fatal error.
  11271. **/
  11272. int
  11273. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11274. {
  11275. struct lpfc_rpi_hdr *rpi_page;
  11276. uint32_t rc = 0;
  11277. /* Post all rpi memory regions to the port. */
  11278. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11279. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11280. if (rc != MBX_SUCCESS) {
  11281. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11282. "2008 Error %d posting all rpi "
  11283. "headers\n", rc);
  11284. rc = -EIO;
  11285. break;
  11286. }
  11287. }
  11288. return rc;
  11289. }
  11290. /**
  11291. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11292. * @phba: pointer to lpfc hba data structure.
  11293. * @rpi_page: pointer to the rpi memory region.
  11294. *
  11295. * This routine is invoked to post a single rpi header to the
  11296. * HBA consistent with the SLI-4 interface spec. This memory region
  11297. * maps up to 64 rpi context regions.
  11298. *
  11299. * Return codes
  11300. * 0 - successful
  11301. * -ENOMEM - No available memory
  11302. * -EIO - The mailbox failed to complete successfully.
  11303. **/
  11304. int
  11305. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11306. {
  11307. LPFC_MBOXQ_t *mboxq;
  11308. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11309. uint32_t rc = 0;
  11310. uint32_t mbox_tmo;
  11311. uint32_t shdr_status, shdr_add_status;
  11312. union lpfc_sli4_cfg_shdr *shdr;
  11313. /* The port is notified of the header region via a mailbox command. */
  11314. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11315. if (!mboxq) {
  11316. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11317. "2001 Unable to allocate memory for issuing "
  11318. "SLI_CONFIG_SPECIAL mailbox command\n");
  11319. return -ENOMEM;
  11320. }
  11321. /* Post all rpi memory regions to the port. */
  11322. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11323. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11324. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11325. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11326. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11327. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  11328. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11329. hdr_tmpl, rpi_page->page_count);
  11330. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11331. rpi_page->start_rpi);
  11332. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11333. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11334. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11335. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11336. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11337. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11338. if (rc != MBX_TIMEOUT)
  11339. mempool_free(mboxq, phba->mbox_mem_pool);
  11340. if (shdr_status || shdr_add_status || rc) {
  11341. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11342. "2514 POST_RPI_HDR mailbox failed with "
  11343. "status x%x add_status x%x, mbx status x%x\n",
  11344. shdr_status, shdr_add_status, rc);
  11345. rc = -ENXIO;
  11346. }
  11347. return rc;
  11348. }
  11349. /**
  11350. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11351. * @phba: pointer to lpfc hba data structure.
  11352. *
  11353. * This routine is invoked to post rpi header templates to the
  11354. * HBA consistent with the SLI-4 interface spec. This routine
  11355. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11356. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11357. *
  11358. * Returns
  11359. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11360. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11361. **/
  11362. int
  11363. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11364. {
  11365. int rpi;
  11366. uint16_t max_rpi, rpi_base, rpi_limit;
  11367. uint16_t rpi_remaining;
  11368. struct lpfc_rpi_hdr *rpi_hdr;
  11369. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11370. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11371. rpi_limit = phba->sli4_hba.next_rpi;
  11372. /*
  11373. * The valid rpi range is not guaranteed to be zero-based. Start
  11374. * the search at the rpi_base as reported by the port.
  11375. */
  11376. spin_lock_irq(&phba->hbalock);
  11377. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11378. if (rpi >= rpi_limit || rpi < rpi_base)
  11379. rpi = LPFC_RPI_ALLOC_ERROR;
  11380. else {
  11381. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11382. phba->sli4_hba.max_cfg_param.rpi_used++;
  11383. phba->sli4_hba.rpi_count++;
  11384. }
  11385. /*
  11386. * Don't try to allocate more rpi header regions if the device limit
  11387. * on available rpis max has been exhausted.
  11388. */
  11389. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11390. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11391. spin_unlock_irq(&phba->hbalock);
  11392. return rpi;
  11393. }
  11394. /*
  11395. * If the driver is running low on rpi resources, allocate another
  11396. * page now. Note that the next_rpi value is used because
  11397. * it represents how many are actually in use whereas max_rpi notes
  11398. * how many are supported max by the device.
  11399. */
  11400. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11401. phba->sli4_hba.rpi_count;
  11402. spin_unlock_irq(&phba->hbalock);
  11403. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11404. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11405. if (!rpi_hdr) {
  11406. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11407. "2002 Error Could not grow rpi "
  11408. "count\n");
  11409. } else {
  11410. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11411. }
  11412. }
  11413. return rpi;
  11414. }
  11415. /**
  11416. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11417. * @phba: pointer to lpfc hba data structure.
  11418. *
  11419. * This routine is invoked to release an rpi to the pool of
  11420. * available rpis maintained by the driver.
  11421. **/
  11422. void
  11423. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11424. {
  11425. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11426. phba->sli4_hba.rpi_count--;
  11427. phba->sli4_hba.max_cfg_param.rpi_used--;
  11428. }
  11429. }
  11430. /**
  11431. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11432. * @phba: pointer to lpfc hba data structure.
  11433. *
  11434. * This routine is invoked to release an rpi to the pool of
  11435. * available rpis maintained by the driver.
  11436. **/
  11437. void
  11438. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11439. {
  11440. spin_lock_irq(&phba->hbalock);
  11441. __lpfc_sli4_free_rpi(phba, rpi);
  11442. spin_unlock_irq(&phba->hbalock);
  11443. }
  11444. /**
  11445. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11446. * @phba: pointer to lpfc hba data structure.
  11447. *
  11448. * This routine is invoked to remove the memory region that
  11449. * provided rpi via a bitmask.
  11450. **/
  11451. void
  11452. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11453. {
  11454. kfree(phba->sli4_hba.rpi_bmask);
  11455. }
  11456. /**
  11457. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11458. * @phba: pointer to lpfc hba data structure.
  11459. *
  11460. * This routine is invoked to remove the memory region that
  11461. * provided rpi via a bitmask.
  11462. **/
  11463. int
  11464. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11465. {
  11466. LPFC_MBOXQ_t *mboxq;
  11467. struct lpfc_hba *phba = ndlp->phba;
  11468. int rc;
  11469. /* The port is notified of the header region via a mailbox command. */
  11470. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11471. if (!mboxq)
  11472. return -ENOMEM;
  11473. /* Post all rpi memory regions to the port. */
  11474. lpfc_resume_rpi(mboxq, ndlp);
  11475. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11476. if (rc == MBX_NOT_FINISHED) {
  11477. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11478. "2010 Resume RPI Mailbox failed "
  11479. "status %d, mbxStatus x%x\n", rc,
  11480. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11481. mempool_free(mboxq, phba->mbox_mem_pool);
  11482. return -EIO;
  11483. }
  11484. return 0;
  11485. }
  11486. /**
  11487. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11488. * @vport: Pointer to the vport for which the vpi is being initialized
  11489. *
  11490. * This routine is invoked to activate a vpi with the port.
  11491. *
  11492. * Returns:
  11493. * 0 success
  11494. * -Evalue otherwise
  11495. **/
  11496. int
  11497. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11498. {
  11499. LPFC_MBOXQ_t *mboxq;
  11500. int rc = 0;
  11501. int retval = MBX_SUCCESS;
  11502. uint32_t mbox_tmo;
  11503. struct lpfc_hba *phba = vport->phba;
  11504. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11505. if (!mboxq)
  11506. return -ENOMEM;
  11507. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11508. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11509. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11510. if (rc != MBX_SUCCESS) {
  11511. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11512. "2022 INIT VPI Mailbox failed "
  11513. "status %d, mbxStatus x%x\n", rc,
  11514. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11515. retval = -EIO;
  11516. }
  11517. if (rc != MBX_TIMEOUT)
  11518. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11519. return retval;
  11520. }
  11521. /**
  11522. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11523. * @phba: pointer to lpfc hba data structure.
  11524. * @mboxq: Pointer to mailbox object.
  11525. *
  11526. * This routine is invoked to manually add a single FCF record. The caller
  11527. * must pass a completely initialized FCF_Record. This routine takes
  11528. * care of the nonembedded mailbox operations.
  11529. **/
  11530. static void
  11531. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11532. {
  11533. void *virt_addr;
  11534. union lpfc_sli4_cfg_shdr *shdr;
  11535. uint32_t shdr_status, shdr_add_status;
  11536. virt_addr = mboxq->sge_array->addr[0];
  11537. /* The IOCTL status is embedded in the mailbox subheader. */
  11538. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11539. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11540. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11541. if ((shdr_status || shdr_add_status) &&
  11542. (shdr_status != STATUS_FCF_IN_USE))
  11543. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11544. "2558 ADD_FCF_RECORD mailbox failed with "
  11545. "status x%x add_status x%x\n",
  11546. shdr_status, shdr_add_status);
  11547. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11548. }
  11549. /**
  11550. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11551. * @phba: pointer to lpfc hba data structure.
  11552. * @fcf_record: pointer to the initialized fcf record to add.
  11553. *
  11554. * This routine is invoked to manually add a single FCF record. The caller
  11555. * must pass a completely initialized FCF_Record. This routine takes
  11556. * care of the nonembedded mailbox operations.
  11557. **/
  11558. int
  11559. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11560. {
  11561. int rc = 0;
  11562. LPFC_MBOXQ_t *mboxq;
  11563. uint8_t *bytep;
  11564. void *virt_addr;
  11565. dma_addr_t phys_addr;
  11566. struct lpfc_mbx_sge sge;
  11567. uint32_t alloc_len, req_len;
  11568. uint32_t fcfindex;
  11569. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11570. if (!mboxq) {
  11571. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11572. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11573. return -ENOMEM;
  11574. }
  11575. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11576. sizeof(uint32_t);
  11577. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11578. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11579. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11580. req_len, LPFC_SLI4_MBX_NEMBED);
  11581. if (alloc_len < req_len) {
  11582. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11583. "2523 Allocated DMA memory size (x%x) is "
  11584. "less than the requested DMA memory "
  11585. "size (x%x)\n", alloc_len, req_len);
  11586. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11587. return -ENOMEM;
  11588. }
  11589. /*
  11590. * Get the first SGE entry from the non-embedded DMA memory. This
  11591. * routine only uses a single SGE.
  11592. */
  11593. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11594. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11595. virt_addr = mboxq->sge_array->addr[0];
  11596. /*
  11597. * Configure the FCF record for FCFI 0. This is the driver's
  11598. * hardcoded default and gets used in nonFIP mode.
  11599. */
  11600. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11601. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11602. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11603. /*
  11604. * Copy the fcf_index and the FCF Record Data. The data starts after
  11605. * the FCoE header plus word10. The data copy needs to be endian
  11606. * correct.
  11607. */
  11608. bytep += sizeof(uint32_t);
  11609. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11610. mboxq->vport = phba->pport;
  11611. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11612. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11613. if (rc == MBX_NOT_FINISHED) {
  11614. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11615. "2515 ADD_FCF_RECORD mailbox failed with "
  11616. "status 0x%x\n", rc);
  11617. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11618. rc = -EIO;
  11619. } else
  11620. rc = 0;
  11621. return rc;
  11622. }
  11623. /**
  11624. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11625. * @phba: pointer to lpfc hba data structure.
  11626. * @fcf_record: pointer to the fcf record to write the default data.
  11627. * @fcf_index: FCF table entry index.
  11628. *
  11629. * This routine is invoked to build the driver's default FCF record. The
  11630. * values used are hardcoded. This routine handles memory initialization.
  11631. *
  11632. **/
  11633. void
  11634. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11635. struct fcf_record *fcf_record,
  11636. uint16_t fcf_index)
  11637. {
  11638. memset(fcf_record, 0, sizeof(struct fcf_record));
  11639. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11640. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11641. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11642. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11643. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11644. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11645. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11646. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11647. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11648. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11649. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11650. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11651. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11652. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11653. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11654. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11655. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11656. /* Set the VLAN bit map */
  11657. if (phba->valid_vlan) {
  11658. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11659. = 1 << (phba->vlan_id % 8);
  11660. }
  11661. }
  11662. /**
  11663. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11664. * @phba: pointer to lpfc hba data structure.
  11665. * @fcf_index: FCF table entry offset.
  11666. *
  11667. * This routine is invoked to scan the entire FCF table by reading FCF
  11668. * record and processing it one at a time starting from the @fcf_index
  11669. * for initial FCF discovery or fast FCF failover rediscovery.
  11670. *
  11671. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11672. * otherwise.
  11673. **/
  11674. int
  11675. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11676. {
  11677. int rc = 0, error;
  11678. LPFC_MBOXQ_t *mboxq;
  11679. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11680. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11681. if (!mboxq) {
  11682. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11683. "2000 Failed to allocate mbox for "
  11684. "READ_FCF cmd\n");
  11685. error = -ENOMEM;
  11686. goto fail_fcf_scan;
  11687. }
  11688. /* Construct the read FCF record mailbox command */
  11689. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11690. if (rc) {
  11691. error = -EINVAL;
  11692. goto fail_fcf_scan;
  11693. }
  11694. /* Issue the mailbox command asynchronously */
  11695. mboxq->vport = phba->pport;
  11696. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11697. spin_lock_irq(&phba->hbalock);
  11698. phba->hba_flag |= FCF_TS_INPROG;
  11699. spin_unlock_irq(&phba->hbalock);
  11700. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11701. if (rc == MBX_NOT_FINISHED)
  11702. error = -EIO;
  11703. else {
  11704. /* Reset eligible FCF count for new scan */
  11705. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11706. phba->fcf.eligible_fcf_cnt = 0;
  11707. error = 0;
  11708. }
  11709. fail_fcf_scan:
  11710. if (error) {
  11711. if (mboxq)
  11712. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11713. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11714. spin_lock_irq(&phba->hbalock);
  11715. phba->hba_flag &= ~FCF_TS_INPROG;
  11716. spin_unlock_irq(&phba->hbalock);
  11717. }
  11718. return error;
  11719. }
  11720. /**
  11721. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11722. * @phba: pointer to lpfc hba data structure.
  11723. * @fcf_index: FCF table entry offset.
  11724. *
  11725. * This routine is invoked to read an FCF record indicated by @fcf_index
  11726. * and to use it for FLOGI roundrobin FCF failover.
  11727. *
  11728. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11729. * otherwise.
  11730. **/
  11731. int
  11732. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11733. {
  11734. int rc = 0, error;
  11735. LPFC_MBOXQ_t *mboxq;
  11736. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11737. if (!mboxq) {
  11738. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11739. "2763 Failed to allocate mbox for "
  11740. "READ_FCF cmd\n");
  11741. error = -ENOMEM;
  11742. goto fail_fcf_read;
  11743. }
  11744. /* Construct the read FCF record mailbox command */
  11745. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11746. if (rc) {
  11747. error = -EINVAL;
  11748. goto fail_fcf_read;
  11749. }
  11750. /* Issue the mailbox command asynchronously */
  11751. mboxq->vport = phba->pport;
  11752. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11753. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11754. if (rc == MBX_NOT_FINISHED)
  11755. error = -EIO;
  11756. else
  11757. error = 0;
  11758. fail_fcf_read:
  11759. if (error && mboxq)
  11760. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11761. return error;
  11762. }
  11763. /**
  11764. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11765. * @phba: pointer to lpfc hba data structure.
  11766. * @fcf_index: FCF table entry offset.
  11767. *
  11768. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11769. * determine whether it's eligible for FLOGI roundrobin failover list.
  11770. *
  11771. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11772. * otherwise.
  11773. **/
  11774. int
  11775. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11776. {
  11777. int rc = 0, error;
  11778. LPFC_MBOXQ_t *mboxq;
  11779. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11780. if (!mboxq) {
  11781. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11782. "2758 Failed to allocate mbox for "
  11783. "READ_FCF cmd\n");
  11784. error = -ENOMEM;
  11785. goto fail_fcf_read;
  11786. }
  11787. /* Construct the read FCF record mailbox command */
  11788. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11789. if (rc) {
  11790. error = -EINVAL;
  11791. goto fail_fcf_read;
  11792. }
  11793. /* Issue the mailbox command asynchronously */
  11794. mboxq->vport = phba->pport;
  11795. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11796. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11797. if (rc == MBX_NOT_FINISHED)
  11798. error = -EIO;
  11799. else
  11800. error = 0;
  11801. fail_fcf_read:
  11802. if (error && mboxq)
  11803. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11804. return error;
  11805. }
  11806. /**
  11807. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11808. * @phba: pointer to lpfc hba data structure.
  11809. *
  11810. * This routine is to get the next eligible FCF record index in a round
  11811. * robin fashion. If the next eligible FCF record index equals to the
  11812. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11813. * shall be returned, otherwise, the next eligible FCF record's index
  11814. * shall be returned.
  11815. **/
  11816. uint16_t
  11817. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11818. {
  11819. uint16_t next_fcf_index;
  11820. /* Search start from next bit of currently registered FCF index */
  11821. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11822. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11823. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11824. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11825. next_fcf_index);
  11826. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11827. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11828. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11829. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11830. /* Check roundrobin failover list empty condition */
  11831. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11832. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11833. "2844 No roundrobin failover FCF available\n");
  11834. return LPFC_FCOE_FCF_NEXT_NONE;
  11835. }
  11836. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11837. "2845 Get next roundrobin failover FCF (x%x)\n",
  11838. next_fcf_index);
  11839. return next_fcf_index;
  11840. }
  11841. /**
  11842. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11843. * @phba: pointer to lpfc hba data structure.
  11844. *
  11845. * This routine sets the FCF record index in to the eligible bmask for
  11846. * roundrobin failover search. It checks to make sure that the index
  11847. * does not go beyond the range of the driver allocated bmask dimension
  11848. * before setting the bit.
  11849. *
  11850. * Returns 0 if the index bit successfully set, otherwise, it returns
  11851. * -EINVAL.
  11852. **/
  11853. int
  11854. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11855. {
  11856. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11857. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11858. "2610 FCF (x%x) reached driver's book "
  11859. "keeping dimension:x%x\n",
  11860. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11861. return -EINVAL;
  11862. }
  11863. /* Set the eligible FCF record index bmask */
  11864. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11865. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11866. "2790 Set FCF (x%x) to roundrobin FCF failover "
  11867. "bmask\n", fcf_index);
  11868. return 0;
  11869. }
  11870. /**
  11871. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11872. * @phba: pointer to lpfc hba data structure.
  11873. *
  11874. * This routine clears the FCF record index from the eligible bmask for
  11875. * roundrobin failover search. It checks to make sure that the index
  11876. * does not go beyond the range of the driver allocated bmask dimension
  11877. * before clearing the bit.
  11878. **/
  11879. void
  11880. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11881. {
  11882. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11883. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11884. "2762 FCF (x%x) reached driver's book "
  11885. "keeping dimension:x%x\n",
  11886. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11887. return;
  11888. }
  11889. /* Clear the eligible FCF record index bmask */
  11890. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11891. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11892. "2791 Clear FCF (x%x) from roundrobin failover "
  11893. "bmask\n", fcf_index);
  11894. }
  11895. /**
  11896. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11897. * @phba: pointer to lpfc hba data structure.
  11898. *
  11899. * This routine is the completion routine for the rediscover FCF table mailbox
  11900. * command. If the mailbox command returned failure, it will try to stop the
  11901. * FCF rediscover wait timer.
  11902. **/
  11903. void
  11904. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11905. {
  11906. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11907. uint32_t shdr_status, shdr_add_status;
  11908. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11909. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11910. &redisc_fcf->header.cfg_shdr.response);
  11911. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11912. &redisc_fcf->header.cfg_shdr.response);
  11913. if (shdr_status || shdr_add_status) {
  11914. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11915. "2746 Requesting for FCF rediscovery failed "
  11916. "status x%x add_status x%x\n",
  11917. shdr_status, shdr_add_status);
  11918. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11919. spin_lock_irq(&phba->hbalock);
  11920. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11921. spin_unlock_irq(&phba->hbalock);
  11922. /*
  11923. * CVL event triggered FCF rediscover request failed,
  11924. * last resort to re-try current registered FCF entry.
  11925. */
  11926. lpfc_retry_pport_discovery(phba);
  11927. } else {
  11928. spin_lock_irq(&phba->hbalock);
  11929. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11930. spin_unlock_irq(&phba->hbalock);
  11931. /*
  11932. * DEAD FCF event triggered FCF rediscover request
  11933. * failed, last resort to fail over as a link down
  11934. * to FCF registration.
  11935. */
  11936. lpfc_sli4_fcf_dead_failthrough(phba);
  11937. }
  11938. } else {
  11939. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11940. "2775 Start FCF rediscover quiescent timer\n");
  11941. /*
  11942. * Start FCF rediscovery wait timer for pending FCF
  11943. * before rescan FCF record table.
  11944. */
  11945. lpfc_fcf_redisc_wait_start_timer(phba);
  11946. }
  11947. mempool_free(mbox, phba->mbox_mem_pool);
  11948. }
  11949. /**
  11950. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11951. * @phba: pointer to lpfc hba data structure.
  11952. *
  11953. * This routine is invoked to request for rediscovery of the entire FCF table
  11954. * by the port.
  11955. **/
  11956. int
  11957. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11958. {
  11959. LPFC_MBOXQ_t *mbox;
  11960. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11961. int rc, length;
  11962. /* Cancel retry delay timers to all vports before FCF rediscover */
  11963. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11964. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11965. if (!mbox) {
  11966. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11967. "2745 Failed to allocate mbox for "
  11968. "requesting FCF rediscover.\n");
  11969. return -ENOMEM;
  11970. }
  11971. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11972. sizeof(struct lpfc_sli4_cfg_mhdr));
  11973. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11974. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11975. length, LPFC_SLI4_MBX_EMBED);
  11976. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11977. /* Set count to 0 for invalidating the entire FCF database */
  11978. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11979. /* Issue the mailbox command asynchronously */
  11980. mbox->vport = phba->pport;
  11981. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11982. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11983. if (rc == MBX_NOT_FINISHED) {
  11984. mempool_free(mbox, phba->mbox_mem_pool);
  11985. return -EIO;
  11986. }
  11987. return 0;
  11988. }
  11989. /**
  11990. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11991. * @phba: pointer to lpfc hba data structure.
  11992. *
  11993. * This function is the failover routine as a last resort to the FCF DEAD
  11994. * event when driver failed to perform fast FCF failover.
  11995. **/
  11996. void
  11997. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11998. {
  11999. uint32_t link_state;
  12000. /*
  12001. * Last resort as FCF DEAD event failover will treat this as
  12002. * a link down, but save the link state because we don't want
  12003. * it to be changed to Link Down unless it is already down.
  12004. */
  12005. link_state = phba->link_state;
  12006. lpfc_linkdown(phba);
  12007. phba->link_state = link_state;
  12008. /* Unregister FCF if no devices connected to it */
  12009. lpfc_unregister_unused_fcf(phba);
  12010. }
  12011. /**
  12012. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12013. * @phba: pointer to lpfc hba data structure.
  12014. *
  12015. * This function read region 23 and parse TLV for port status to
  12016. * decide if the user disaled the port. If the TLV indicates the
  12017. * port is disabled, the hba_flag is set accordingly.
  12018. **/
  12019. void
  12020. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12021. {
  12022. LPFC_MBOXQ_t *pmb = NULL;
  12023. MAILBOX_t *mb;
  12024. uint8_t *rgn23_data = NULL;
  12025. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12026. int rc;
  12027. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12028. if (!pmb) {
  12029. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12030. "2600 lpfc_sli_read_serdes_param failed to"
  12031. " allocate mailbox memory\n");
  12032. goto out;
  12033. }
  12034. mb = &pmb->u.mb;
  12035. /* Get adapter Region 23 data */
  12036. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12037. if (!rgn23_data)
  12038. goto out;
  12039. do {
  12040. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12041. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12042. if (rc != MBX_SUCCESS) {
  12043. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12044. "2601 lpfc_sli_read_link_ste failed to"
  12045. " read config region 23 rc 0x%x Status 0x%x\n",
  12046. rc, mb->mbxStatus);
  12047. mb->un.varDmp.word_cnt = 0;
  12048. }
  12049. /*
  12050. * dump mem may return a zero when finished or we got a
  12051. * mailbox error, either way we are done.
  12052. */
  12053. if (mb->un.varDmp.word_cnt == 0)
  12054. break;
  12055. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12056. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12057. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12058. rgn23_data + offset,
  12059. mb->un.varDmp.word_cnt);
  12060. offset += mb->un.varDmp.word_cnt;
  12061. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12062. data_size = offset;
  12063. offset = 0;
  12064. if (!data_size)
  12065. goto out;
  12066. /* Check the region signature first */
  12067. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12068. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12069. "2619 Config region 23 has bad signature\n");
  12070. goto out;
  12071. }
  12072. offset += 4;
  12073. /* Check the data structure version */
  12074. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12075. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12076. "2620 Config region 23 has bad version\n");
  12077. goto out;
  12078. }
  12079. offset += 4;
  12080. /* Parse TLV entries in the region */
  12081. while (offset < data_size) {
  12082. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12083. break;
  12084. /*
  12085. * If the TLV is not driver specific TLV or driver id is
  12086. * not linux driver id, skip the record.
  12087. */
  12088. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12089. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12090. (rgn23_data[offset + 3] != 0)) {
  12091. offset += rgn23_data[offset + 1] * 4 + 4;
  12092. continue;
  12093. }
  12094. /* Driver found a driver specific TLV in the config region */
  12095. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12096. offset += 4;
  12097. tlv_offset = 0;
  12098. /*
  12099. * Search for configured port state sub-TLV.
  12100. */
  12101. while ((offset < data_size) &&
  12102. (tlv_offset < sub_tlv_len)) {
  12103. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12104. offset += 4;
  12105. tlv_offset += 4;
  12106. break;
  12107. }
  12108. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12109. offset += rgn23_data[offset + 1] * 4 + 4;
  12110. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12111. continue;
  12112. }
  12113. /* This HBA contains PORT_STE configured */
  12114. if (!rgn23_data[offset + 2])
  12115. phba->hba_flag |= LINK_DISABLED;
  12116. goto out;
  12117. }
  12118. }
  12119. out:
  12120. if (pmb)
  12121. mempool_free(pmb, phba->mbox_mem_pool);
  12122. kfree(rgn23_data);
  12123. return;
  12124. }
  12125. /**
  12126. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12127. * @vport: pointer to vport data structure.
  12128. *
  12129. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12130. * and REG_VPI mailbox commands associated with the vport. This function
  12131. * is called when driver want to restart discovery of the vport due to
  12132. * a Clear Virtual Link event.
  12133. **/
  12134. void
  12135. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12136. {
  12137. struct lpfc_hba *phba = vport->phba;
  12138. LPFC_MBOXQ_t *mb, *nextmb;
  12139. struct lpfc_dmabuf *mp;
  12140. struct lpfc_nodelist *ndlp;
  12141. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12142. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12143. LIST_HEAD(mbox_cmd_list);
  12144. uint8_t restart_loop;
  12145. /* Clean up internally queued mailbox commands with the vport */
  12146. spin_lock_irq(&phba->hbalock);
  12147. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12148. if (mb->vport != vport)
  12149. continue;
  12150. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12151. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12152. continue;
  12153. list_del(&mb->list);
  12154. list_add_tail(&mb->list, &mbox_cmd_list);
  12155. }
  12156. /* Clean up active mailbox command with the vport */
  12157. mb = phba->sli.mbox_active;
  12158. if (mb && (mb->vport == vport)) {
  12159. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12160. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12161. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12162. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12163. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12164. /* Put reference count for delayed processing */
  12165. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12166. /* Unregister the RPI when mailbox complete */
  12167. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12168. }
  12169. }
  12170. /* Cleanup any mailbox completions which are not yet processed */
  12171. do {
  12172. restart_loop = 0;
  12173. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12174. /*
  12175. * If this mailox is already processed or it is
  12176. * for another vport ignore it.
  12177. */
  12178. if ((mb->vport != vport) ||
  12179. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12180. continue;
  12181. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12182. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12183. continue;
  12184. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12185. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12186. ndlp = (struct lpfc_nodelist *)mb->context2;
  12187. /* Unregister the RPI when mailbox complete */
  12188. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12189. restart_loop = 1;
  12190. spin_unlock_irq(&phba->hbalock);
  12191. spin_lock(shost->host_lock);
  12192. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12193. spin_unlock(shost->host_lock);
  12194. spin_lock_irq(&phba->hbalock);
  12195. break;
  12196. }
  12197. }
  12198. } while (restart_loop);
  12199. spin_unlock_irq(&phba->hbalock);
  12200. /* Release the cleaned-up mailbox commands */
  12201. while (!list_empty(&mbox_cmd_list)) {
  12202. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12203. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12204. if (phba->sli_rev == LPFC_SLI_REV4)
  12205. __lpfc_sli4_free_rpi(phba,
  12206. mb->u.mb.un.varRegLogin.rpi);
  12207. mp = (struct lpfc_dmabuf *) (mb->context1);
  12208. if (mp) {
  12209. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12210. kfree(mp);
  12211. }
  12212. ndlp = (struct lpfc_nodelist *) mb->context2;
  12213. mb->context2 = NULL;
  12214. if (ndlp) {
  12215. spin_lock(shost->host_lock);
  12216. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12217. spin_unlock(shost->host_lock);
  12218. lpfc_nlp_put(ndlp);
  12219. }
  12220. }
  12221. mempool_free(mb, phba->mbox_mem_pool);
  12222. }
  12223. /* Release the ndlp with the cleaned-up active mailbox command */
  12224. if (act_mbx_ndlp) {
  12225. spin_lock(shost->host_lock);
  12226. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12227. spin_unlock(shost->host_lock);
  12228. lpfc_nlp_put(act_mbx_ndlp);
  12229. }
  12230. }
  12231. /**
  12232. * lpfc_drain_txq - Drain the txq
  12233. * @phba: Pointer to HBA context object.
  12234. *
  12235. * This function attempt to submit IOCBs on the txq
  12236. * to the adapter. For SLI4 adapters, the txq contains
  12237. * ELS IOCBs that have been deferred because the there
  12238. * are no SGLs. This congestion can occur with large
  12239. * vport counts during node discovery.
  12240. **/
  12241. uint32_t
  12242. lpfc_drain_txq(struct lpfc_hba *phba)
  12243. {
  12244. LIST_HEAD(completions);
  12245. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12246. struct lpfc_iocbq *piocbq = 0;
  12247. unsigned long iflags = 0;
  12248. char *fail_msg = NULL;
  12249. struct lpfc_sglq *sglq;
  12250. union lpfc_wqe wqe;
  12251. spin_lock_irqsave(&phba->hbalock, iflags);
  12252. if (pring->txq_cnt > pring->txq_max)
  12253. pring->txq_max = pring->txq_cnt;
  12254. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12255. while (pring->txq_cnt) {
  12256. spin_lock_irqsave(&phba->hbalock, iflags);
  12257. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12258. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12259. if (!sglq) {
  12260. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12261. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12262. break;
  12263. } else {
  12264. if (!piocbq) {
  12265. /* The txq_cnt out of sync. This should
  12266. * never happen
  12267. */
  12268. sglq = __lpfc_clear_active_sglq(phba,
  12269. sglq->sli4_xritag);
  12270. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12271. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12272. "2823 txq empty and txq_cnt is %d\n ",
  12273. pring->txq_cnt);
  12274. break;
  12275. }
  12276. }
  12277. /* The xri and iocb resources secured,
  12278. * attempt to issue request
  12279. */
  12280. piocbq->sli4_xritag = sglq->sli4_xritag;
  12281. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12282. fail_msg = "to convert bpl to sgl";
  12283. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12284. fail_msg = "to convert iocb to wqe";
  12285. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12286. fail_msg = " - Wq is full";
  12287. else
  12288. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12289. if (fail_msg) {
  12290. /* Failed means we can't issue and need to cancel */
  12291. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12292. "2822 IOCB failed %s iotag 0x%x "
  12293. "xri 0x%x\n",
  12294. fail_msg,
  12295. piocbq->iotag, piocbq->sli4_xritag);
  12296. list_add_tail(&piocbq->list, &completions);
  12297. }
  12298. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12299. }
  12300. /* Cancel all the IOCBs that cannot be issued */
  12301. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12302. IOERR_SLI_ABORTED);
  12303. return pring->txq_cnt;
  12304. }