lpfc_sli.c 426 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
  63. struct lpfc_cqe *);
  64. static IOCB_t *
  65. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  66. {
  67. return &iocbq->iocb;
  68. }
  69. /**
  70. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  71. * @q: The Work Queue to operate on.
  72. * @wqe: The work Queue Entry to put on the Work queue.
  73. *
  74. * This routine will copy the contents of @wqe to the next available entry on
  75. * the @q. This function will then ring the Work Queue Doorbell to signal the
  76. * HBA to start processing the Work Queue Entry. This function returns 0 if
  77. * successful. If no entries are available on @q then this function will return
  78. * -ENOMEM.
  79. * The caller is expected to hold the hbalock when calling this routine.
  80. **/
  81. static uint32_t
  82. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  83. {
  84. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  85. struct lpfc_register doorbell;
  86. uint32_t host_index;
  87. /* If the host has not yet processed the next entry then we are done */
  88. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  89. return -ENOMEM;
  90. /* set consumption flag every once in a while */
  91. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  92. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  93. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  94. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  95. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  96. /* Update the host index before invoking device */
  97. host_index = q->host_index;
  98. q->host_index = ((q->host_index + 1) % q->entry_count);
  99. /* Ring Doorbell */
  100. doorbell.word0 = 0;
  101. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  102. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  103. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  104. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  105. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  106. return 0;
  107. }
  108. /**
  109. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  110. * @q: The Work Queue to operate on.
  111. * @index: The index to advance the hba index to.
  112. *
  113. * This routine will update the HBA index of a queue to reflect consumption of
  114. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  115. * an entry the host calls this function to update the queue's internal
  116. * pointers. This routine returns the number of entries that were consumed by
  117. * the HBA.
  118. **/
  119. static uint32_t
  120. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  121. {
  122. uint32_t released = 0;
  123. if (q->hba_index == index)
  124. return 0;
  125. do {
  126. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  127. released++;
  128. } while (q->hba_index != index);
  129. return released;
  130. }
  131. /**
  132. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  133. * @q: The Mailbox Queue to operate on.
  134. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  135. *
  136. * This routine will copy the contents of @mqe to the next available entry on
  137. * the @q. This function will then ring the Work Queue Doorbell to signal the
  138. * HBA to start processing the Work Queue Entry. This function returns 0 if
  139. * successful. If no entries are available on @q then this function will return
  140. * -ENOMEM.
  141. * The caller is expected to hold the hbalock when calling this routine.
  142. **/
  143. static uint32_t
  144. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  145. {
  146. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  147. struct lpfc_register doorbell;
  148. uint32_t host_index;
  149. /* If the host has not yet processed the next entry then we are done */
  150. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  151. return -ENOMEM;
  152. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  153. /* Save off the mailbox pointer for completion */
  154. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  155. /* Update the host index before invoking device */
  156. host_index = q->host_index;
  157. q->host_index = ((q->host_index + 1) % q->entry_count);
  158. /* Ring Doorbell */
  159. doorbell.word0 = 0;
  160. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  161. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  162. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  163. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  164. return 0;
  165. }
  166. /**
  167. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  168. * @q: The Mailbox Queue to operate on.
  169. *
  170. * This routine will update the HBA index of a queue to reflect consumption of
  171. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  172. * an entry the host calls this function to update the queue's internal
  173. * pointers. This routine returns the number of entries that were consumed by
  174. * the HBA.
  175. **/
  176. static uint32_t
  177. lpfc_sli4_mq_release(struct lpfc_queue *q)
  178. {
  179. /* Clear the mailbox pointer for completion */
  180. q->phba->mbox = NULL;
  181. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  182. return 1;
  183. }
  184. /**
  185. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  186. * @q: The Event Queue to get the first valid EQE from
  187. *
  188. * This routine will get the first valid Event Queue Entry from @q, update
  189. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  190. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  191. * processed, but not popped back to the HBA then this routine will return NULL.
  192. **/
  193. static struct lpfc_eqe *
  194. lpfc_sli4_eq_get(struct lpfc_queue *q)
  195. {
  196. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  197. /* If the next EQE is not valid then we are done */
  198. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  199. return NULL;
  200. /* If the host has not yet processed the next entry then we are done */
  201. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  202. return NULL;
  203. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  204. return eqe;
  205. }
  206. /**
  207. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  208. * @q: The Event Queue that the host has completed processing for.
  209. * @arm: Indicates whether the host wants to arms this CQ.
  210. *
  211. * This routine will mark all Event Queue Entries on @q, from the last
  212. * known completed entry to the last entry that was processed, as completed
  213. * by clearing the valid bit for each completion queue entry. Then it will
  214. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  215. * The internal host index in the @q will be updated by this routine to indicate
  216. * that the host has finished processing the entries. The @arm parameter
  217. * indicates that the queue should be rearmed when ringing the doorbell.
  218. *
  219. * This function will return the number of EQEs that were popped.
  220. **/
  221. uint32_t
  222. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  223. {
  224. uint32_t released = 0;
  225. struct lpfc_eqe *temp_eqe;
  226. struct lpfc_register doorbell;
  227. /* while there are valid entries */
  228. while (q->hba_index != q->host_index) {
  229. temp_eqe = q->qe[q->host_index].eqe;
  230. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  231. released++;
  232. q->host_index = ((q->host_index + 1) % q->entry_count);
  233. }
  234. if (unlikely(released == 0 && !arm))
  235. return 0;
  236. /* ring doorbell for number popped */
  237. doorbell.word0 = 0;
  238. if (arm) {
  239. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  240. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  241. }
  242. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  243. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  244. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  245. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  246. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  247. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  248. readl(q->phba->sli4_hba.EQCQDBregaddr);
  249. return released;
  250. }
  251. /**
  252. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  253. * @q: The Completion Queue to get the first valid CQE from
  254. *
  255. * This routine will get the first valid Completion Queue Entry from @q, update
  256. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  257. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  258. * processed, but not popped back to the HBA then this routine will return NULL.
  259. **/
  260. static struct lpfc_cqe *
  261. lpfc_sli4_cq_get(struct lpfc_queue *q)
  262. {
  263. struct lpfc_cqe *cqe;
  264. /* If the next CQE is not valid then we are done */
  265. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  266. return NULL;
  267. /* If the host has not yet processed the next entry then we are done */
  268. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  269. return NULL;
  270. cqe = q->qe[q->hba_index].cqe;
  271. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  272. return cqe;
  273. }
  274. /**
  275. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  276. * @q: The Completion Queue that the host has completed processing for.
  277. * @arm: Indicates whether the host wants to arms this CQ.
  278. *
  279. * This routine will mark all Completion queue entries on @q, from the last
  280. * known completed entry to the last entry that was processed, as completed
  281. * by clearing the valid bit for each completion queue entry. Then it will
  282. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  283. * The internal host index in the @q will be updated by this routine to indicate
  284. * that the host has finished processing the entries. The @arm parameter
  285. * indicates that the queue should be rearmed when ringing the doorbell.
  286. *
  287. * This function will return the number of CQEs that were released.
  288. **/
  289. uint32_t
  290. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  291. {
  292. uint32_t released = 0;
  293. struct lpfc_cqe *temp_qe;
  294. struct lpfc_register doorbell;
  295. /* while there are valid entries */
  296. while (q->hba_index != q->host_index) {
  297. temp_qe = q->qe[q->host_index].cqe;
  298. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  299. released++;
  300. q->host_index = ((q->host_index + 1) % q->entry_count);
  301. }
  302. if (unlikely(released == 0 && !arm))
  303. return 0;
  304. /* ring doorbell for number popped */
  305. doorbell.word0 = 0;
  306. if (arm)
  307. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  308. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  309. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  310. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  311. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  312. return released;
  313. }
  314. /**
  315. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  316. * @q: The Header Receive Queue to operate on.
  317. * @wqe: The Receive Queue Entry to put on the Receive queue.
  318. *
  319. * This routine will copy the contents of @wqe to the next available entry on
  320. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  321. * HBA to start processing the Receive Queue Entry. This function returns the
  322. * index that the rqe was copied to if successful. If no entries are available
  323. * on @q then this function will return -ENOMEM.
  324. * The caller is expected to hold the hbalock when calling this routine.
  325. **/
  326. static int
  327. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  328. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  329. {
  330. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  331. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  332. struct lpfc_register doorbell;
  333. int put_index = hq->host_index;
  334. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  335. return -EINVAL;
  336. if (hq->host_index != dq->host_index)
  337. return -EINVAL;
  338. /* If the host has not yet processed the next entry then we are done */
  339. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  340. return -EBUSY;
  341. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  342. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  343. /* Update the host index to point to the next slot */
  344. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  345. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  346. /* Ring The Header Receive Queue Doorbell */
  347. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  348. doorbell.word0 = 0;
  349. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  350. LPFC_RQ_POST_BATCH);
  351. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  352. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  353. }
  354. return put_index;
  355. }
  356. /**
  357. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  358. * @q: The Header Receive Queue to operate on.
  359. *
  360. * This routine will update the HBA index of a queue to reflect consumption of
  361. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  362. * consumed an entry the host calls this function to update the queue's
  363. * internal pointers. This routine returns the number of entries that were
  364. * consumed by the HBA.
  365. **/
  366. static uint32_t
  367. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  368. {
  369. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  370. return 0;
  371. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  372. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  373. return 1;
  374. }
  375. /**
  376. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  377. * @phba: Pointer to HBA context object.
  378. * @pring: Pointer to driver SLI ring object.
  379. *
  380. * This function returns pointer to next command iocb entry
  381. * in the command ring. The caller must hold hbalock to prevent
  382. * other threads consume the next command iocb.
  383. * SLI-2/SLI-3 provide different sized iocbs.
  384. **/
  385. static inline IOCB_t *
  386. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  387. {
  388. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  389. pring->cmdidx * phba->iocb_cmd_size);
  390. }
  391. /**
  392. * lpfc_resp_iocb - Get next response iocb entry in the ring
  393. * @phba: Pointer to HBA context object.
  394. * @pring: Pointer to driver SLI ring object.
  395. *
  396. * This function returns pointer to next response iocb entry
  397. * in the response ring. The caller must hold hbalock to make sure
  398. * that no other thread consume the next response iocb.
  399. * SLI-2/SLI-3 provide different sized iocbs.
  400. **/
  401. static inline IOCB_t *
  402. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  403. {
  404. return (IOCB_t *) (((char *) pring->rspringaddr) +
  405. pring->rspidx * phba->iocb_rsp_size);
  406. }
  407. /**
  408. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  409. * @phba: Pointer to HBA context object.
  410. *
  411. * This function is called with hbalock held. This function
  412. * allocates a new driver iocb object from the iocb pool. If the
  413. * allocation is successful, it returns pointer to the newly
  414. * allocated iocb object else it returns NULL.
  415. **/
  416. static struct lpfc_iocbq *
  417. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  418. {
  419. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  420. struct lpfc_iocbq * iocbq = NULL;
  421. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  422. if (iocbq)
  423. phba->iocb_cnt++;
  424. if (phba->iocb_cnt > phba->iocb_max)
  425. phba->iocb_max = phba->iocb_cnt;
  426. return iocbq;
  427. }
  428. /**
  429. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  430. * @phba: Pointer to HBA context object.
  431. * @xritag: XRI value.
  432. *
  433. * This function clears the sglq pointer from the array of acive
  434. * sglq's. The xritag that is passed in is used to index into the
  435. * array. Before the xritag can be used it needs to be adjusted
  436. * by subtracting the xribase.
  437. *
  438. * Returns sglq ponter = success, NULL = Failure.
  439. **/
  440. static struct lpfc_sglq *
  441. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  442. {
  443. uint16_t adj_xri;
  444. struct lpfc_sglq *sglq;
  445. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  446. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  447. return NULL;
  448. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  449. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  450. return sglq;
  451. }
  452. /**
  453. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  454. * @phba: Pointer to HBA context object.
  455. * @xritag: XRI value.
  456. *
  457. * This function returns the sglq pointer from the array of acive
  458. * sglq's. The xritag that is passed in is used to index into the
  459. * array. Before the xritag can be used it needs to be adjusted
  460. * by subtracting the xribase.
  461. *
  462. * Returns sglq ponter = success, NULL = Failure.
  463. **/
  464. struct lpfc_sglq *
  465. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  466. {
  467. uint16_t adj_xri;
  468. struct lpfc_sglq *sglq;
  469. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  470. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  471. return NULL;
  472. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  473. return sglq;
  474. }
  475. /**
  476. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  477. * @phba: Pointer to HBA context object.
  478. * @ndlp: nodelist pointer for this target.
  479. * @xritag: xri used in this exchange.
  480. * @rxid: Remote Exchange ID.
  481. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  482. *
  483. * This function is called with hbalock held.
  484. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  485. * rrq struct and adds it to the active_rrq_list.
  486. *
  487. * returns 0 for rrq slot for this xri
  488. * < 0 Were not able to get rrq mem or invalid parameter.
  489. **/
  490. static int
  491. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  492. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  493. {
  494. uint16_t adj_xri;
  495. struct lpfc_node_rrq *rrq;
  496. int empty;
  497. uint32_t did = 0;
  498. if (!ndlp)
  499. return -EINVAL;
  500. if (!phba->cfg_enable_rrq)
  501. return -EINVAL;
  502. if (phba->pport->load_flag & FC_UNLOADING) {
  503. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  504. goto out;
  505. }
  506. did = ndlp->nlp_DID;
  507. /*
  508. * set the active bit even if there is no mem available.
  509. */
  510. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  511. if (NLP_CHK_FREE_REQ(ndlp))
  512. goto out;
  513. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  514. goto out;
  515. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  516. goto out;
  517. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  518. if (rrq) {
  519. rrq->send_rrq = send_rrq;
  520. rrq->xritag = xritag;
  521. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  522. rrq->ndlp = ndlp;
  523. rrq->nlp_DID = ndlp->nlp_DID;
  524. rrq->vport = ndlp->vport;
  525. rrq->rxid = rxid;
  526. empty = list_empty(&phba->active_rrq_list);
  527. rrq->send_rrq = send_rrq;
  528. list_add_tail(&rrq->list, &phba->active_rrq_list);
  529. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  530. phba->hba_flag |= HBA_RRQ_ACTIVE;
  531. if (empty)
  532. lpfc_worker_wake_up(phba);
  533. }
  534. return 0;
  535. }
  536. out:
  537. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  538. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  539. " DID:0x%x Send:%d\n",
  540. xritag, rxid, did, send_rrq);
  541. return -EINVAL;
  542. }
  543. /**
  544. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  545. * @phba: Pointer to HBA context object.
  546. * @xritag: xri used in this exchange.
  547. * @rrq: The RRQ to be cleared.
  548. *
  549. **/
  550. void
  551. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  552. uint16_t xritag,
  553. struct lpfc_node_rrq *rrq)
  554. {
  555. uint16_t adj_xri;
  556. struct lpfc_nodelist *ndlp = NULL;
  557. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  558. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  559. /* The target DID could have been swapped (cable swap)
  560. * we should use the ndlp from the findnode if it is
  561. * available.
  562. */
  563. if ((!ndlp) && rrq->ndlp)
  564. ndlp = rrq->ndlp;
  565. if (!ndlp)
  566. goto out;
  567. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  568. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  569. rrq->send_rrq = 0;
  570. rrq->xritag = 0;
  571. rrq->rrq_stop_time = 0;
  572. }
  573. out:
  574. mempool_free(rrq, phba->rrq_pool);
  575. }
  576. /**
  577. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  578. * @phba: Pointer to HBA context object.
  579. *
  580. * This function is called with hbalock held. This function
  581. * Checks if stop_time (ratov from setting rrq active) has
  582. * been reached, if it has and the send_rrq flag is set then
  583. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  584. * then it will just call the routine to clear the rrq and
  585. * free the rrq resource.
  586. * The timer is set to the next rrq that is going to expire before
  587. * leaving the routine.
  588. *
  589. **/
  590. void
  591. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  592. {
  593. struct lpfc_node_rrq *rrq;
  594. struct lpfc_node_rrq *nextrrq;
  595. unsigned long next_time;
  596. unsigned long iflags;
  597. LIST_HEAD(send_rrq);
  598. spin_lock_irqsave(&phba->hbalock, iflags);
  599. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  600. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  601. list_for_each_entry_safe(rrq, nextrrq,
  602. &phba->active_rrq_list, list) {
  603. if (time_after(jiffies, rrq->rrq_stop_time))
  604. list_move(&rrq->list, &send_rrq);
  605. else if (time_before(rrq->rrq_stop_time, next_time))
  606. next_time = rrq->rrq_stop_time;
  607. }
  608. spin_unlock_irqrestore(&phba->hbalock, iflags);
  609. if (!list_empty(&phba->active_rrq_list))
  610. mod_timer(&phba->rrq_tmr, next_time);
  611. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  612. list_del(&rrq->list);
  613. if (!rrq->send_rrq)
  614. /* this call will free the rrq */
  615. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  616. else if (lpfc_send_rrq(phba, rrq)) {
  617. /* if we send the rrq then the completion handler
  618. * will clear the bit in the xribitmap.
  619. */
  620. lpfc_clr_rrq_active(phba, rrq->xritag,
  621. rrq);
  622. }
  623. }
  624. }
  625. /**
  626. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  627. * @vport: Pointer to vport context object.
  628. * @xri: The xri used in the exchange.
  629. * @did: The targets DID for this exchange.
  630. *
  631. * returns NULL = rrq not found in the phba->active_rrq_list.
  632. * rrq = rrq for this xri and target.
  633. **/
  634. struct lpfc_node_rrq *
  635. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  636. {
  637. struct lpfc_hba *phba = vport->phba;
  638. struct lpfc_node_rrq *rrq;
  639. struct lpfc_node_rrq *nextrrq;
  640. unsigned long iflags;
  641. if (phba->sli_rev != LPFC_SLI_REV4)
  642. return NULL;
  643. spin_lock_irqsave(&phba->hbalock, iflags);
  644. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  645. if (rrq->vport == vport && rrq->xritag == xri &&
  646. rrq->nlp_DID == did){
  647. list_del(&rrq->list);
  648. spin_unlock_irqrestore(&phba->hbalock, iflags);
  649. return rrq;
  650. }
  651. }
  652. spin_unlock_irqrestore(&phba->hbalock, iflags);
  653. return NULL;
  654. }
  655. /**
  656. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  657. * @vport: Pointer to vport context object.
  658. * @ndlp: Pointer to the lpfc_node_list structure.
  659. * If ndlp is NULL Remove all active RRQs for this vport from the
  660. * phba->active_rrq_list and clear the rrq.
  661. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  662. **/
  663. void
  664. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  665. {
  666. struct lpfc_hba *phba = vport->phba;
  667. struct lpfc_node_rrq *rrq;
  668. struct lpfc_node_rrq *nextrrq;
  669. unsigned long iflags;
  670. LIST_HEAD(rrq_list);
  671. if (phba->sli_rev != LPFC_SLI_REV4)
  672. return;
  673. if (!ndlp) {
  674. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  675. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  676. }
  677. spin_lock_irqsave(&phba->hbalock, iflags);
  678. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  679. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  680. list_move(&rrq->list, &rrq_list);
  681. spin_unlock_irqrestore(&phba->hbalock, iflags);
  682. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  683. list_del(&rrq->list);
  684. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  685. }
  686. }
  687. /**
  688. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  689. * @phba: Pointer to HBA context object.
  690. *
  691. * Remove all rrqs from the phba->active_rrq_list and free them by
  692. * calling __lpfc_clr_active_rrq
  693. *
  694. **/
  695. void
  696. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  697. {
  698. struct lpfc_node_rrq *rrq;
  699. struct lpfc_node_rrq *nextrrq;
  700. unsigned long next_time;
  701. unsigned long iflags;
  702. LIST_HEAD(rrq_list);
  703. if (phba->sli_rev != LPFC_SLI_REV4)
  704. return;
  705. spin_lock_irqsave(&phba->hbalock, iflags);
  706. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  707. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  708. list_splice_init(&phba->active_rrq_list, &rrq_list);
  709. spin_unlock_irqrestore(&phba->hbalock, iflags);
  710. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  711. list_del(&rrq->list);
  712. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  713. }
  714. if (!list_empty(&phba->active_rrq_list))
  715. mod_timer(&phba->rrq_tmr, next_time);
  716. }
  717. /**
  718. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  719. * @phba: Pointer to HBA context object.
  720. * @ndlp: Targets nodelist pointer for this exchange.
  721. * @xritag the xri in the bitmap to test.
  722. *
  723. * This function is called with hbalock held. This function
  724. * returns 0 = rrq not active for this xri
  725. * 1 = rrq is valid for this xri.
  726. **/
  727. int
  728. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  729. uint16_t xritag)
  730. {
  731. uint16_t adj_xri;
  732. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  733. if (!ndlp)
  734. return 0;
  735. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  736. return 1;
  737. else
  738. return 0;
  739. }
  740. /**
  741. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  742. * @phba: Pointer to HBA context object.
  743. * @ndlp: nodelist pointer for this target.
  744. * @xritag: xri used in this exchange.
  745. * @rxid: Remote Exchange ID.
  746. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  747. *
  748. * This function takes the hbalock.
  749. * The active bit is always set in the active rrq xri_bitmap even
  750. * if there is no slot avaiable for the other rrq information.
  751. *
  752. * returns 0 rrq actived for this xri
  753. * < 0 No memory or invalid ndlp.
  754. **/
  755. int
  756. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  757. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  758. {
  759. int ret;
  760. unsigned long iflags;
  761. spin_lock_irqsave(&phba->hbalock, iflags);
  762. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  763. spin_unlock_irqrestore(&phba->hbalock, iflags);
  764. return ret;
  765. }
  766. /**
  767. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  768. * @phba: Pointer to HBA context object.
  769. * @piocb: Pointer to the iocbq.
  770. *
  771. * This function is called with hbalock held. This function
  772. * Gets a new driver sglq object from the sglq list. If the
  773. * list is not empty then it is successful, it returns pointer to the newly
  774. * allocated sglq object else it returns NULL.
  775. **/
  776. static struct lpfc_sglq *
  777. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  778. {
  779. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  780. struct lpfc_sglq *sglq = NULL;
  781. struct lpfc_sglq *start_sglq = NULL;
  782. uint16_t adj_xri;
  783. struct lpfc_scsi_buf *lpfc_cmd;
  784. struct lpfc_nodelist *ndlp;
  785. int found = 0;
  786. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  787. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  788. ndlp = lpfc_cmd->rdata->pnode;
  789. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  790. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  791. ndlp = piocbq->context_un.ndlp;
  792. else
  793. ndlp = piocbq->context1;
  794. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  795. start_sglq = sglq;
  796. while (!found) {
  797. if (!sglq)
  798. return NULL;
  799. adj_xri = sglq->sli4_xritag -
  800. phba->sli4_hba.max_cfg_param.xri_base;
  801. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  802. /* This xri has an rrq outstanding for this DID.
  803. * put it back in the list and get another xri.
  804. */
  805. list_add_tail(&sglq->list, lpfc_sgl_list);
  806. sglq = NULL;
  807. list_remove_head(lpfc_sgl_list, sglq,
  808. struct lpfc_sglq, list);
  809. if (sglq == start_sglq) {
  810. sglq = NULL;
  811. break;
  812. } else
  813. continue;
  814. }
  815. sglq->ndlp = ndlp;
  816. found = 1;
  817. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  818. sglq->state = SGL_ALLOCATED;
  819. }
  820. return sglq;
  821. }
  822. /**
  823. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  824. * @phba: Pointer to HBA context object.
  825. *
  826. * This function is called with no lock held. This function
  827. * allocates a new driver iocb object from the iocb pool. If the
  828. * allocation is successful, it returns pointer to the newly
  829. * allocated iocb object else it returns NULL.
  830. **/
  831. struct lpfc_iocbq *
  832. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  833. {
  834. struct lpfc_iocbq * iocbq = NULL;
  835. unsigned long iflags;
  836. spin_lock_irqsave(&phba->hbalock, iflags);
  837. iocbq = __lpfc_sli_get_iocbq(phba);
  838. spin_unlock_irqrestore(&phba->hbalock, iflags);
  839. return iocbq;
  840. }
  841. /**
  842. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  843. * @phba: Pointer to HBA context object.
  844. * @iocbq: Pointer to driver iocb object.
  845. *
  846. * This function is called with hbalock held to release driver
  847. * iocb object to the iocb pool. The iotag in the iocb object
  848. * does not change for each use of the iocb object. This function
  849. * clears all other fields of the iocb object when it is freed.
  850. * The sqlq structure that holds the xritag and phys and virtual
  851. * mappings for the scatter gather list is retrieved from the
  852. * active array of sglq. The get of the sglq pointer also clears
  853. * the entry in the array. If the status of the IO indiactes that
  854. * this IO was aborted then the sglq entry it put on the
  855. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  856. * IO has good status or fails for any other reason then the sglq
  857. * entry is added to the free list (lpfc_sgl_list).
  858. **/
  859. static void
  860. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  861. {
  862. struct lpfc_sglq *sglq;
  863. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  864. unsigned long iflag = 0;
  865. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  866. if (iocbq->sli4_xritag == NO_XRI)
  867. sglq = NULL;
  868. else
  869. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  870. if (sglq) {
  871. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  872. (sglq->state != SGL_XRI_ABORTED)) {
  873. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  874. iflag);
  875. list_add(&sglq->list,
  876. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  877. spin_unlock_irqrestore(
  878. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  879. } else {
  880. sglq->state = SGL_FREED;
  881. sglq->ndlp = NULL;
  882. list_add_tail(&sglq->list,
  883. &phba->sli4_hba.lpfc_sgl_list);
  884. /* Check if TXQ queue needs to be serviced */
  885. if (pring->txq_cnt)
  886. lpfc_worker_wake_up(phba);
  887. }
  888. }
  889. /*
  890. * Clean all volatile data fields, preserve iotag and node struct.
  891. */
  892. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  893. iocbq->sli4_xritag = NO_XRI;
  894. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  895. }
  896. /**
  897. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  898. * @phba: Pointer to HBA context object.
  899. * @iocbq: Pointer to driver iocb object.
  900. *
  901. * This function is called with hbalock held to release driver
  902. * iocb object to the iocb pool. The iotag in the iocb object
  903. * does not change for each use of the iocb object. This function
  904. * clears all other fields of the iocb object when it is freed.
  905. **/
  906. static void
  907. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  908. {
  909. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  910. /*
  911. * Clean all volatile data fields, preserve iotag and node struct.
  912. */
  913. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  914. iocbq->sli4_xritag = NO_XRI;
  915. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  916. }
  917. /**
  918. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  919. * @phba: Pointer to HBA context object.
  920. * @iocbq: Pointer to driver iocb object.
  921. *
  922. * This function is called with hbalock held to release driver
  923. * iocb object to the iocb pool. The iotag in the iocb object
  924. * does not change for each use of the iocb object. This function
  925. * clears all other fields of the iocb object when it is freed.
  926. **/
  927. static void
  928. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  929. {
  930. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  931. phba->iocb_cnt--;
  932. }
  933. /**
  934. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  935. * @phba: Pointer to HBA context object.
  936. * @iocbq: Pointer to driver iocb object.
  937. *
  938. * This function is called with no lock held to release the iocb to
  939. * iocb pool.
  940. **/
  941. void
  942. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  943. {
  944. unsigned long iflags;
  945. /*
  946. * Clean all volatile data fields, preserve iotag and node struct.
  947. */
  948. spin_lock_irqsave(&phba->hbalock, iflags);
  949. __lpfc_sli_release_iocbq(phba, iocbq);
  950. spin_unlock_irqrestore(&phba->hbalock, iflags);
  951. }
  952. /**
  953. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  954. * @phba: Pointer to HBA context object.
  955. * @iocblist: List of IOCBs.
  956. * @ulpstatus: ULP status in IOCB command field.
  957. * @ulpWord4: ULP word-4 in IOCB command field.
  958. *
  959. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  960. * on the list by invoking the complete callback function associated with the
  961. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  962. * fields.
  963. **/
  964. void
  965. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  966. uint32_t ulpstatus, uint32_t ulpWord4)
  967. {
  968. struct lpfc_iocbq *piocb;
  969. while (!list_empty(iocblist)) {
  970. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  971. if (!piocb->iocb_cmpl)
  972. lpfc_sli_release_iocbq(phba, piocb);
  973. else {
  974. piocb->iocb.ulpStatus = ulpstatus;
  975. piocb->iocb.un.ulpWord[4] = ulpWord4;
  976. (piocb->iocb_cmpl) (phba, piocb, piocb);
  977. }
  978. }
  979. return;
  980. }
  981. /**
  982. * lpfc_sli_iocb_cmd_type - Get the iocb type
  983. * @iocb_cmnd: iocb command code.
  984. *
  985. * This function is called by ring event handler function to get the iocb type.
  986. * This function translates the iocb command to an iocb command type used to
  987. * decide the final disposition of each completed IOCB.
  988. * The function returns
  989. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  990. * LPFC_SOL_IOCB if it is a solicited iocb completion
  991. * LPFC_ABORT_IOCB if it is an abort iocb
  992. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  993. *
  994. * The caller is not required to hold any lock.
  995. **/
  996. static lpfc_iocb_type
  997. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  998. {
  999. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1000. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1001. return 0;
  1002. switch (iocb_cmnd) {
  1003. case CMD_XMIT_SEQUENCE_CR:
  1004. case CMD_XMIT_SEQUENCE_CX:
  1005. case CMD_XMIT_BCAST_CN:
  1006. case CMD_XMIT_BCAST_CX:
  1007. case CMD_ELS_REQUEST_CR:
  1008. case CMD_ELS_REQUEST_CX:
  1009. case CMD_CREATE_XRI_CR:
  1010. case CMD_CREATE_XRI_CX:
  1011. case CMD_GET_RPI_CN:
  1012. case CMD_XMIT_ELS_RSP_CX:
  1013. case CMD_GET_RPI_CR:
  1014. case CMD_FCP_IWRITE_CR:
  1015. case CMD_FCP_IWRITE_CX:
  1016. case CMD_FCP_IREAD_CR:
  1017. case CMD_FCP_IREAD_CX:
  1018. case CMD_FCP_ICMND_CR:
  1019. case CMD_FCP_ICMND_CX:
  1020. case CMD_FCP_TSEND_CX:
  1021. case CMD_FCP_TRSP_CX:
  1022. case CMD_FCP_TRECEIVE_CX:
  1023. case CMD_FCP_AUTO_TRSP_CX:
  1024. case CMD_ADAPTER_MSG:
  1025. case CMD_ADAPTER_DUMP:
  1026. case CMD_XMIT_SEQUENCE64_CR:
  1027. case CMD_XMIT_SEQUENCE64_CX:
  1028. case CMD_XMIT_BCAST64_CN:
  1029. case CMD_XMIT_BCAST64_CX:
  1030. case CMD_ELS_REQUEST64_CR:
  1031. case CMD_ELS_REQUEST64_CX:
  1032. case CMD_FCP_IWRITE64_CR:
  1033. case CMD_FCP_IWRITE64_CX:
  1034. case CMD_FCP_IREAD64_CR:
  1035. case CMD_FCP_IREAD64_CX:
  1036. case CMD_FCP_ICMND64_CR:
  1037. case CMD_FCP_ICMND64_CX:
  1038. case CMD_FCP_TSEND64_CX:
  1039. case CMD_FCP_TRSP64_CX:
  1040. case CMD_FCP_TRECEIVE64_CX:
  1041. case CMD_GEN_REQUEST64_CR:
  1042. case CMD_GEN_REQUEST64_CX:
  1043. case CMD_XMIT_ELS_RSP64_CX:
  1044. case DSSCMD_IWRITE64_CR:
  1045. case DSSCMD_IWRITE64_CX:
  1046. case DSSCMD_IREAD64_CR:
  1047. case DSSCMD_IREAD64_CX:
  1048. type = LPFC_SOL_IOCB;
  1049. break;
  1050. case CMD_ABORT_XRI_CN:
  1051. case CMD_ABORT_XRI_CX:
  1052. case CMD_CLOSE_XRI_CN:
  1053. case CMD_CLOSE_XRI_CX:
  1054. case CMD_XRI_ABORTED_CX:
  1055. case CMD_ABORT_MXRI64_CN:
  1056. case CMD_XMIT_BLS_RSP64_CX:
  1057. type = LPFC_ABORT_IOCB;
  1058. break;
  1059. case CMD_RCV_SEQUENCE_CX:
  1060. case CMD_RCV_ELS_REQ_CX:
  1061. case CMD_RCV_SEQUENCE64_CX:
  1062. case CMD_RCV_ELS_REQ64_CX:
  1063. case CMD_ASYNC_STATUS:
  1064. case CMD_IOCB_RCV_SEQ64_CX:
  1065. case CMD_IOCB_RCV_ELS64_CX:
  1066. case CMD_IOCB_RCV_CONT64_CX:
  1067. case CMD_IOCB_RET_XRI64_CX:
  1068. type = LPFC_UNSOL_IOCB;
  1069. break;
  1070. case CMD_IOCB_XMIT_MSEQ64_CR:
  1071. case CMD_IOCB_XMIT_MSEQ64_CX:
  1072. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1073. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1074. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1075. case CMD_IOCB_ABORT_EXTENDED_CN:
  1076. case CMD_IOCB_RET_HBQE64_CN:
  1077. case CMD_IOCB_FCP_IBIDIR64_CR:
  1078. case CMD_IOCB_FCP_IBIDIR64_CX:
  1079. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1080. case CMD_IOCB_LOGENTRY_CN:
  1081. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1082. printk("%s - Unhandled SLI-3 Command x%x\n",
  1083. __func__, iocb_cmnd);
  1084. type = LPFC_UNKNOWN_IOCB;
  1085. break;
  1086. default:
  1087. type = LPFC_UNKNOWN_IOCB;
  1088. break;
  1089. }
  1090. return type;
  1091. }
  1092. /**
  1093. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1094. * @phba: Pointer to HBA context object.
  1095. *
  1096. * This function is called from SLI initialization code
  1097. * to configure every ring of the HBA's SLI interface. The
  1098. * caller is not required to hold any lock. This function issues
  1099. * a config_ring mailbox command for each ring.
  1100. * This function returns zero if successful else returns a negative
  1101. * error code.
  1102. **/
  1103. static int
  1104. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1105. {
  1106. struct lpfc_sli *psli = &phba->sli;
  1107. LPFC_MBOXQ_t *pmb;
  1108. MAILBOX_t *pmbox;
  1109. int i, rc, ret = 0;
  1110. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1111. if (!pmb)
  1112. return -ENOMEM;
  1113. pmbox = &pmb->u.mb;
  1114. phba->link_state = LPFC_INIT_MBX_CMDS;
  1115. for (i = 0; i < psli->num_rings; i++) {
  1116. lpfc_config_ring(phba, i, pmb);
  1117. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1118. if (rc != MBX_SUCCESS) {
  1119. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1120. "0446 Adapter failed to init (%d), "
  1121. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1122. "ring %d\n",
  1123. rc, pmbox->mbxCommand,
  1124. pmbox->mbxStatus, i);
  1125. phba->link_state = LPFC_HBA_ERROR;
  1126. ret = -ENXIO;
  1127. break;
  1128. }
  1129. }
  1130. mempool_free(pmb, phba->mbox_mem_pool);
  1131. return ret;
  1132. }
  1133. /**
  1134. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1135. * @phba: Pointer to HBA context object.
  1136. * @pring: Pointer to driver SLI ring object.
  1137. * @piocb: Pointer to the driver iocb object.
  1138. *
  1139. * This function is called with hbalock held. The function adds the
  1140. * new iocb to txcmplq of the given ring. This function always returns
  1141. * 0. If this function is called for ELS ring, this function checks if
  1142. * there is a vport associated with the ELS command. This function also
  1143. * starts els_tmofunc timer if this is an ELS command.
  1144. **/
  1145. static int
  1146. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1147. struct lpfc_iocbq *piocb)
  1148. {
  1149. list_add_tail(&piocb->list, &pring->txcmplq);
  1150. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1151. pring->txcmplq_cnt++;
  1152. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1153. pring->txcmplq_max = pring->txcmplq_cnt;
  1154. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1155. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1156. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1157. if (!piocb->vport)
  1158. BUG();
  1159. else
  1160. mod_timer(&piocb->vport->els_tmofunc,
  1161. jiffies + HZ * (phba->fc_ratov << 1));
  1162. }
  1163. return 0;
  1164. }
  1165. /**
  1166. * lpfc_sli_ringtx_get - Get first element of the txq
  1167. * @phba: Pointer to HBA context object.
  1168. * @pring: Pointer to driver SLI ring object.
  1169. *
  1170. * This function is called with hbalock held to get next
  1171. * iocb in txq of the given ring. If there is any iocb in
  1172. * the txq, the function returns first iocb in the list after
  1173. * removing the iocb from the list, else it returns NULL.
  1174. **/
  1175. struct lpfc_iocbq *
  1176. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1177. {
  1178. struct lpfc_iocbq *cmd_iocb;
  1179. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1180. if (cmd_iocb != NULL)
  1181. pring->txq_cnt--;
  1182. return cmd_iocb;
  1183. }
  1184. /**
  1185. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1186. * @phba: Pointer to HBA context object.
  1187. * @pring: Pointer to driver SLI ring object.
  1188. *
  1189. * This function is called with hbalock held and the caller must post the
  1190. * iocb without releasing the lock. If the caller releases the lock,
  1191. * iocb slot returned by the function is not guaranteed to be available.
  1192. * The function returns pointer to the next available iocb slot if there
  1193. * is available slot in the ring, else it returns NULL.
  1194. * If the get index of the ring is ahead of the put index, the function
  1195. * will post an error attention event to the worker thread to take the
  1196. * HBA to offline state.
  1197. **/
  1198. static IOCB_t *
  1199. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1200. {
  1201. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1202. uint32_t max_cmd_idx = pring->numCiocb;
  1203. if ((pring->next_cmdidx == pring->cmdidx) &&
  1204. (++pring->next_cmdidx >= max_cmd_idx))
  1205. pring->next_cmdidx = 0;
  1206. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1207. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1208. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1209. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1210. "0315 Ring %d issue: portCmdGet %d "
  1211. "is bigger than cmd ring %d\n",
  1212. pring->ringno,
  1213. pring->local_getidx, max_cmd_idx);
  1214. phba->link_state = LPFC_HBA_ERROR;
  1215. /*
  1216. * All error attention handlers are posted to
  1217. * worker thread
  1218. */
  1219. phba->work_ha |= HA_ERATT;
  1220. phba->work_hs = HS_FFER3;
  1221. lpfc_worker_wake_up(phba);
  1222. return NULL;
  1223. }
  1224. if (pring->local_getidx == pring->next_cmdidx)
  1225. return NULL;
  1226. }
  1227. return lpfc_cmd_iocb(phba, pring);
  1228. }
  1229. /**
  1230. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1231. * @phba: Pointer to HBA context object.
  1232. * @iocbq: Pointer to driver iocb object.
  1233. *
  1234. * This function gets an iotag for the iocb. If there is no unused iotag and
  1235. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1236. * array and assigns a new iotag.
  1237. * The function returns the allocated iotag if successful, else returns zero.
  1238. * Zero is not a valid iotag.
  1239. * The caller is not required to hold any lock.
  1240. **/
  1241. uint16_t
  1242. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1243. {
  1244. struct lpfc_iocbq **new_arr;
  1245. struct lpfc_iocbq **old_arr;
  1246. size_t new_len;
  1247. struct lpfc_sli *psli = &phba->sli;
  1248. uint16_t iotag;
  1249. spin_lock_irq(&phba->hbalock);
  1250. iotag = psli->last_iotag;
  1251. if(++iotag < psli->iocbq_lookup_len) {
  1252. psli->last_iotag = iotag;
  1253. psli->iocbq_lookup[iotag] = iocbq;
  1254. spin_unlock_irq(&phba->hbalock);
  1255. iocbq->iotag = iotag;
  1256. return iotag;
  1257. } else if (psli->iocbq_lookup_len < (0xffff
  1258. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1259. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1260. spin_unlock_irq(&phba->hbalock);
  1261. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1262. GFP_KERNEL);
  1263. if (new_arr) {
  1264. spin_lock_irq(&phba->hbalock);
  1265. old_arr = psli->iocbq_lookup;
  1266. if (new_len <= psli->iocbq_lookup_len) {
  1267. /* highly unprobable case */
  1268. kfree(new_arr);
  1269. iotag = psli->last_iotag;
  1270. if(++iotag < psli->iocbq_lookup_len) {
  1271. psli->last_iotag = iotag;
  1272. psli->iocbq_lookup[iotag] = iocbq;
  1273. spin_unlock_irq(&phba->hbalock);
  1274. iocbq->iotag = iotag;
  1275. return iotag;
  1276. }
  1277. spin_unlock_irq(&phba->hbalock);
  1278. return 0;
  1279. }
  1280. if (psli->iocbq_lookup)
  1281. memcpy(new_arr, old_arr,
  1282. ((psli->last_iotag + 1) *
  1283. sizeof (struct lpfc_iocbq *)));
  1284. psli->iocbq_lookup = new_arr;
  1285. psli->iocbq_lookup_len = new_len;
  1286. psli->last_iotag = iotag;
  1287. psli->iocbq_lookup[iotag] = iocbq;
  1288. spin_unlock_irq(&phba->hbalock);
  1289. iocbq->iotag = iotag;
  1290. kfree(old_arr);
  1291. return iotag;
  1292. }
  1293. } else
  1294. spin_unlock_irq(&phba->hbalock);
  1295. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1296. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1297. psli->last_iotag);
  1298. return 0;
  1299. }
  1300. /**
  1301. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1302. * @phba: Pointer to HBA context object.
  1303. * @pring: Pointer to driver SLI ring object.
  1304. * @iocb: Pointer to iocb slot in the ring.
  1305. * @nextiocb: Pointer to driver iocb object which need to be
  1306. * posted to firmware.
  1307. *
  1308. * This function is called with hbalock held to post a new iocb to
  1309. * the firmware. This function copies the new iocb to ring iocb slot and
  1310. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1311. * a completion call back for this iocb else the function will free the
  1312. * iocb object.
  1313. **/
  1314. static void
  1315. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1316. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1317. {
  1318. /*
  1319. * Set up an iotag
  1320. */
  1321. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1322. if (pring->ringno == LPFC_ELS_RING) {
  1323. lpfc_debugfs_slow_ring_trc(phba,
  1324. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1325. *(((uint32_t *) &nextiocb->iocb) + 4),
  1326. *(((uint32_t *) &nextiocb->iocb) + 6),
  1327. *(((uint32_t *) &nextiocb->iocb) + 7));
  1328. }
  1329. /*
  1330. * Issue iocb command to adapter
  1331. */
  1332. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1333. wmb();
  1334. pring->stats.iocb_cmd++;
  1335. /*
  1336. * If there is no completion routine to call, we can release the
  1337. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1338. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1339. */
  1340. if (nextiocb->iocb_cmpl)
  1341. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1342. else
  1343. __lpfc_sli_release_iocbq(phba, nextiocb);
  1344. /*
  1345. * Let the HBA know what IOCB slot will be the next one the
  1346. * driver will put a command into.
  1347. */
  1348. pring->cmdidx = pring->next_cmdidx;
  1349. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1350. }
  1351. /**
  1352. * lpfc_sli_update_full_ring - Update the chip attention register
  1353. * @phba: Pointer to HBA context object.
  1354. * @pring: Pointer to driver SLI ring object.
  1355. *
  1356. * The caller is not required to hold any lock for calling this function.
  1357. * This function updates the chip attention bits for the ring to inform firmware
  1358. * that there are pending work to be done for this ring and requests an
  1359. * interrupt when there is space available in the ring. This function is
  1360. * called when the driver is unable to post more iocbs to the ring due
  1361. * to unavailability of space in the ring.
  1362. **/
  1363. static void
  1364. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1365. {
  1366. int ringno = pring->ringno;
  1367. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1368. wmb();
  1369. /*
  1370. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1371. * The HBA will tell us when an IOCB entry is available.
  1372. */
  1373. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1374. readl(phba->CAregaddr); /* flush */
  1375. pring->stats.iocb_cmd_full++;
  1376. }
  1377. /**
  1378. * lpfc_sli_update_ring - Update chip attention register
  1379. * @phba: Pointer to HBA context object.
  1380. * @pring: Pointer to driver SLI ring object.
  1381. *
  1382. * This function updates the chip attention register bit for the
  1383. * given ring to inform HBA that there is more work to be done
  1384. * in this ring. The caller is not required to hold any lock.
  1385. **/
  1386. static void
  1387. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1388. {
  1389. int ringno = pring->ringno;
  1390. /*
  1391. * Tell the HBA that there is work to do in this ring.
  1392. */
  1393. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1394. wmb();
  1395. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1396. readl(phba->CAregaddr); /* flush */
  1397. }
  1398. }
  1399. /**
  1400. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1401. * @phba: Pointer to HBA context object.
  1402. * @pring: Pointer to driver SLI ring object.
  1403. *
  1404. * This function is called with hbalock held to post pending iocbs
  1405. * in the txq to the firmware. This function is called when driver
  1406. * detects space available in the ring.
  1407. **/
  1408. static void
  1409. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1410. {
  1411. IOCB_t *iocb;
  1412. struct lpfc_iocbq *nextiocb;
  1413. /*
  1414. * Check to see if:
  1415. * (a) there is anything on the txq to send
  1416. * (b) link is up
  1417. * (c) link attention events can be processed (fcp ring only)
  1418. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1419. */
  1420. if (pring->txq_cnt &&
  1421. lpfc_is_link_up(phba) &&
  1422. (pring->ringno != phba->sli.fcp_ring ||
  1423. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1424. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1425. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1426. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1427. if (iocb)
  1428. lpfc_sli_update_ring(phba, pring);
  1429. else
  1430. lpfc_sli_update_full_ring(phba, pring);
  1431. }
  1432. return;
  1433. }
  1434. /**
  1435. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1436. * @phba: Pointer to HBA context object.
  1437. * @hbqno: HBQ number.
  1438. *
  1439. * This function is called with hbalock held to get the next
  1440. * available slot for the given HBQ. If there is free slot
  1441. * available for the HBQ it will return pointer to the next available
  1442. * HBQ entry else it will return NULL.
  1443. **/
  1444. static struct lpfc_hbq_entry *
  1445. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1446. {
  1447. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1448. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1449. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1450. hbqp->next_hbqPutIdx = 0;
  1451. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1452. uint32_t raw_index = phba->hbq_get[hbqno];
  1453. uint32_t getidx = le32_to_cpu(raw_index);
  1454. hbqp->local_hbqGetIdx = getidx;
  1455. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1456. lpfc_printf_log(phba, KERN_ERR,
  1457. LOG_SLI | LOG_VPORT,
  1458. "1802 HBQ %d: local_hbqGetIdx "
  1459. "%u is > than hbqp->entry_count %u\n",
  1460. hbqno, hbqp->local_hbqGetIdx,
  1461. hbqp->entry_count);
  1462. phba->link_state = LPFC_HBA_ERROR;
  1463. return NULL;
  1464. }
  1465. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1466. return NULL;
  1467. }
  1468. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1469. hbqp->hbqPutIdx;
  1470. }
  1471. /**
  1472. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1473. * @phba: Pointer to HBA context object.
  1474. *
  1475. * This function is called with no lock held to free all the
  1476. * hbq buffers while uninitializing the SLI interface. It also
  1477. * frees the HBQ buffers returned by the firmware but not yet
  1478. * processed by the upper layers.
  1479. **/
  1480. void
  1481. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1482. {
  1483. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1484. struct hbq_dmabuf *hbq_buf;
  1485. unsigned long flags;
  1486. int i, hbq_count;
  1487. uint32_t hbqno;
  1488. hbq_count = lpfc_sli_hbq_count();
  1489. /* Return all memory used by all HBQs */
  1490. spin_lock_irqsave(&phba->hbalock, flags);
  1491. for (i = 0; i < hbq_count; ++i) {
  1492. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1493. &phba->hbqs[i].hbq_buffer_list, list) {
  1494. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1495. list_del(&hbq_buf->dbuf.list);
  1496. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1497. }
  1498. phba->hbqs[i].buffer_count = 0;
  1499. }
  1500. /* Return all HBQ buffer that are in-fly */
  1501. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1502. list) {
  1503. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1504. list_del(&hbq_buf->dbuf.list);
  1505. if (hbq_buf->tag == -1) {
  1506. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1507. (phba, hbq_buf);
  1508. } else {
  1509. hbqno = hbq_buf->tag >> 16;
  1510. if (hbqno >= LPFC_MAX_HBQS)
  1511. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1512. (phba, hbq_buf);
  1513. else
  1514. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1515. hbq_buf);
  1516. }
  1517. }
  1518. /* Mark the HBQs not in use */
  1519. phba->hbq_in_use = 0;
  1520. spin_unlock_irqrestore(&phba->hbalock, flags);
  1521. }
  1522. /**
  1523. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1524. * @phba: Pointer to HBA context object.
  1525. * @hbqno: HBQ number.
  1526. * @hbq_buf: Pointer to HBQ buffer.
  1527. *
  1528. * This function is called with the hbalock held to post a
  1529. * hbq buffer to the firmware. If the function finds an empty
  1530. * slot in the HBQ, it will post the buffer. The function will return
  1531. * pointer to the hbq entry if it successfully post the buffer
  1532. * else it will return NULL.
  1533. **/
  1534. static int
  1535. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1536. struct hbq_dmabuf *hbq_buf)
  1537. {
  1538. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1539. }
  1540. /**
  1541. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1542. * @phba: Pointer to HBA context object.
  1543. * @hbqno: HBQ number.
  1544. * @hbq_buf: Pointer to HBQ buffer.
  1545. *
  1546. * This function is called with the hbalock held to post a hbq buffer to the
  1547. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1548. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1549. * it successfully post the buffer else it will return an error.
  1550. **/
  1551. static int
  1552. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1553. struct hbq_dmabuf *hbq_buf)
  1554. {
  1555. struct lpfc_hbq_entry *hbqe;
  1556. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1557. /* Get next HBQ entry slot to use */
  1558. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1559. if (hbqe) {
  1560. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1561. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1562. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1563. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1564. hbqe->bde.tus.f.bdeFlags = 0;
  1565. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1566. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1567. /* Sync SLIM */
  1568. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1569. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1570. /* flush */
  1571. readl(phba->hbq_put + hbqno);
  1572. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1573. return 0;
  1574. } else
  1575. return -ENOMEM;
  1576. }
  1577. /**
  1578. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1579. * @phba: Pointer to HBA context object.
  1580. * @hbqno: HBQ number.
  1581. * @hbq_buf: Pointer to HBQ buffer.
  1582. *
  1583. * This function is called with the hbalock held to post an RQE to the SLI4
  1584. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1585. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1586. **/
  1587. static int
  1588. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1589. struct hbq_dmabuf *hbq_buf)
  1590. {
  1591. int rc;
  1592. struct lpfc_rqe hrqe;
  1593. struct lpfc_rqe drqe;
  1594. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1595. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1596. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1597. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1598. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1599. &hrqe, &drqe);
  1600. if (rc < 0)
  1601. return rc;
  1602. hbq_buf->tag = rc;
  1603. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1604. return 0;
  1605. }
  1606. /* HBQ for ELS and CT traffic. */
  1607. static struct lpfc_hbq_init lpfc_els_hbq = {
  1608. .rn = 1,
  1609. .entry_count = 256,
  1610. .mask_count = 0,
  1611. .profile = 0,
  1612. .ring_mask = (1 << LPFC_ELS_RING),
  1613. .buffer_count = 0,
  1614. .init_count = 40,
  1615. .add_count = 40,
  1616. };
  1617. /* HBQ for the extra ring if needed */
  1618. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1619. .rn = 1,
  1620. .entry_count = 200,
  1621. .mask_count = 0,
  1622. .profile = 0,
  1623. .ring_mask = (1 << LPFC_EXTRA_RING),
  1624. .buffer_count = 0,
  1625. .init_count = 0,
  1626. .add_count = 5,
  1627. };
  1628. /* Array of HBQs */
  1629. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1630. &lpfc_els_hbq,
  1631. &lpfc_extra_hbq,
  1632. };
  1633. /**
  1634. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1635. * @phba: Pointer to HBA context object.
  1636. * @hbqno: HBQ number.
  1637. * @count: Number of HBQ buffers to be posted.
  1638. *
  1639. * This function is called with no lock held to post more hbq buffers to the
  1640. * given HBQ. The function returns the number of HBQ buffers successfully
  1641. * posted.
  1642. **/
  1643. static int
  1644. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1645. {
  1646. uint32_t i, posted = 0;
  1647. unsigned long flags;
  1648. struct hbq_dmabuf *hbq_buffer;
  1649. LIST_HEAD(hbq_buf_list);
  1650. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1651. return 0;
  1652. if ((phba->hbqs[hbqno].buffer_count + count) >
  1653. lpfc_hbq_defs[hbqno]->entry_count)
  1654. count = lpfc_hbq_defs[hbqno]->entry_count -
  1655. phba->hbqs[hbqno].buffer_count;
  1656. if (!count)
  1657. return 0;
  1658. /* Allocate HBQ entries */
  1659. for (i = 0; i < count; i++) {
  1660. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1661. if (!hbq_buffer)
  1662. break;
  1663. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1664. }
  1665. /* Check whether HBQ is still in use */
  1666. spin_lock_irqsave(&phba->hbalock, flags);
  1667. if (!phba->hbq_in_use)
  1668. goto err;
  1669. while (!list_empty(&hbq_buf_list)) {
  1670. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1671. dbuf.list);
  1672. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1673. (hbqno << 16));
  1674. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1675. phba->hbqs[hbqno].buffer_count++;
  1676. posted++;
  1677. } else
  1678. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1679. }
  1680. spin_unlock_irqrestore(&phba->hbalock, flags);
  1681. return posted;
  1682. err:
  1683. spin_unlock_irqrestore(&phba->hbalock, flags);
  1684. while (!list_empty(&hbq_buf_list)) {
  1685. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1686. dbuf.list);
  1687. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1688. }
  1689. return 0;
  1690. }
  1691. /**
  1692. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1693. * @phba: Pointer to HBA context object.
  1694. * @qno: HBQ number.
  1695. *
  1696. * This function posts more buffers to the HBQ. This function
  1697. * is called with no lock held. The function returns the number of HBQ entries
  1698. * successfully allocated.
  1699. **/
  1700. int
  1701. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1702. {
  1703. if (phba->sli_rev == LPFC_SLI_REV4)
  1704. return 0;
  1705. else
  1706. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1707. lpfc_hbq_defs[qno]->add_count);
  1708. }
  1709. /**
  1710. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1711. * @phba: Pointer to HBA context object.
  1712. * @qno: HBQ queue number.
  1713. *
  1714. * This function is called from SLI initialization code path with
  1715. * no lock held to post initial HBQ buffers to firmware. The
  1716. * function returns the number of HBQ entries successfully allocated.
  1717. **/
  1718. static int
  1719. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1720. {
  1721. if (phba->sli_rev == LPFC_SLI_REV4)
  1722. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1723. lpfc_hbq_defs[qno]->entry_count);
  1724. else
  1725. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1726. lpfc_hbq_defs[qno]->init_count);
  1727. }
  1728. /**
  1729. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1730. * @phba: Pointer to HBA context object.
  1731. * @hbqno: HBQ number.
  1732. *
  1733. * This function removes the first hbq buffer on an hbq list and returns a
  1734. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1735. **/
  1736. static struct hbq_dmabuf *
  1737. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1738. {
  1739. struct lpfc_dmabuf *d_buf;
  1740. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1741. if (!d_buf)
  1742. return NULL;
  1743. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1744. }
  1745. /**
  1746. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1747. * @phba: Pointer to HBA context object.
  1748. * @tag: Tag of the hbq buffer.
  1749. *
  1750. * This function is called with hbalock held. This function searches
  1751. * for the hbq buffer associated with the given tag in the hbq buffer
  1752. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1753. * it returns NULL.
  1754. **/
  1755. static struct hbq_dmabuf *
  1756. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1757. {
  1758. struct lpfc_dmabuf *d_buf;
  1759. struct hbq_dmabuf *hbq_buf;
  1760. uint32_t hbqno;
  1761. hbqno = tag >> 16;
  1762. if (hbqno >= LPFC_MAX_HBQS)
  1763. return NULL;
  1764. spin_lock_irq(&phba->hbalock);
  1765. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1766. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1767. if (hbq_buf->tag == tag) {
  1768. spin_unlock_irq(&phba->hbalock);
  1769. return hbq_buf;
  1770. }
  1771. }
  1772. spin_unlock_irq(&phba->hbalock);
  1773. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1774. "1803 Bad hbq tag. Data: x%x x%x\n",
  1775. tag, phba->hbqs[tag >> 16].buffer_count);
  1776. return NULL;
  1777. }
  1778. /**
  1779. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1780. * @phba: Pointer to HBA context object.
  1781. * @hbq_buffer: Pointer to HBQ buffer.
  1782. *
  1783. * This function is called with hbalock. This function gives back
  1784. * the hbq buffer to firmware. If the HBQ does not have space to
  1785. * post the buffer, it will free the buffer.
  1786. **/
  1787. void
  1788. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1789. {
  1790. uint32_t hbqno;
  1791. if (hbq_buffer) {
  1792. hbqno = hbq_buffer->tag >> 16;
  1793. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1794. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1795. }
  1796. }
  1797. /**
  1798. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1799. * @mbxCommand: mailbox command code.
  1800. *
  1801. * This function is called by the mailbox event handler function to verify
  1802. * that the completed mailbox command is a legitimate mailbox command. If the
  1803. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1804. * and the mailbox event handler will take the HBA offline.
  1805. **/
  1806. static int
  1807. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1808. {
  1809. uint8_t ret;
  1810. switch (mbxCommand) {
  1811. case MBX_LOAD_SM:
  1812. case MBX_READ_NV:
  1813. case MBX_WRITE_NV:
  1814. case MBX_WRITE_VPARMS:
  1815. case MBX_RUN_BIU_DIAG:
  1816. case MBX_INIT_LINK:
  1817. case MBX_DOWN_LINK:
  1818. case MBX_CONFIG_LINK:
  1819. case MBX_CONFIG_RING:
  1820. case MBX_RESET_RING:
  1821. case MBX_READ_CONFIG:
  1822. case MBX_READ_RCONFIG:
  1823. case MBX_READ_SPARM:
  1824. case MBX_READ_STATUS:
  1825. case MBX_READ_RPI:
  1826. case MBX_READ_XRI:
  1827. case MBX_READ_REV:
  1828. case MBX_READ_LNK_STAT:
  1829. case MBX_REG_LOGIN:
  1830. case MBX_UNREG_LOGIN:
  1831. case MBX_CLEAR_LA:
  1832. case MBX_DUMP_MEMORY:
  1833. case MBX_DUMP_CONTEXT:
  1834. case MBX_RUN_DIAGS:
  1835. case MBX_RESTART:
  1836. case MBX_UPDATE_CFG:
  1837. case MBX_DOWN_LOAD:
  1838. case MBX_DEL_LD_ENTRY:
  1839. case MBX_RUN_PROGRAM:
  1840. case MBX_SET_MASK:
  1841. case MBX_SET_VARIABLE:
  1842. case MBX_UNREG_D_ID:
  1843. case MBX_KILL_BOARD:
  1844. case MBX_CONFIG_FARP:
  1845. case MBX_BEACON:
  1846. case MBX_LOAD_AREA:
  1847. case MBX_RUN_BIU_DIAG64:
  1848. case MBX_CONFIG_PORT:
  1849. case MBX_READ_SPARM64:
  1850. case MBX_READ_RPI64:
  1851. case MBX_REG_LOGIN64:
  1852. case MBX_READ_TOPOLOGY:
  1853. case MBX_WRITE_WWN:
  1854. case MBX_SET_DEBUG:
  1855. case MBX_LOAD_EXP_ROM:
  1856. case MBX_ASYNCEVT_ENABLE:
  1857. case MBX_REG_VPI:
  1858. case MBX_UNREG_VPI:
  1859. case MBX_HEARTBEAT:
  1860. case MBX_PORT_CAPABILITIES:
  1861. case MBX_PORT_IOV_CONTROL:
  1862. case MBX_SLI4_CONFIG:
  1863. case MBX_SLI4_REQ_FTRS:
  1864. case MBX_REG_FCFI:
  1865. case MBX_UNREG_FCFI:
  1866. case MBX_REG_VFI:
  1867. case MBX_UNREG_VFI:
  1868. case MBX_INIT_VPI:
  1869. case MBX_INIT_VFI:
  1870. case MBX_RESUME_RPI:
  1871. case MBX_READ_EVENT_LOG_STATUS:
  1872. case MBX_READ_EVENT_LOG:
  1873. case MBX_SECURITY_MGMT:
  1874. case MBX_AUTH_PORT:
  1875. ret = mbxCommand;
  1876. break;
  1877. default:
  1878. ret = MBX_SHUTDOWN;
  1879. break;
  1880. }
  1881. return ret;
  1882. }
  1883. /**
  1884. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1885. * @phba: Pointer to HBA context object.
  1886. * @pmboxq: Pointer to mailbox command.
  1887. *
  1888. * This is completion handler function for mailbox commands issued from
  1889. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1890. * mailbox event handler function with no lock held. This function
  1891. * will wake up thread waiting on the wait queue pointed by context1
  1892. * of the mailbox.
  1893. **/
  1894. void
  1895. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1896. {
  1897. wait_queue_head_t *pdone_q;
  1898. unsigned long drvr_flag;
  1899. /*
  1900. * If pdone_q is empty, the driver thread gave up waiting and
  1901. * continued running.
  1902. */
  1903. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1904. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1905. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1906. if (pdone_q)
  1907. wake_up_interruptible(pdone_q);
  1908. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1909. return;
  1910. }
  1911. /**
  1912. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1913. * @phba: Pointer to HBA context object.
  1914. * @pmb: Pointer to mailbox object.
  1915. *
  1916. * This function is the default mailbox completion handler. It
  1917. * frees the memory resources associated with the completed mailbox
  1918. * command. If the completed command is a REG_LOGIN mailbox command,
  1919. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1920. **/
  1921. void
  1922. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1923. {
  1924. struct lpfc_vport *vport = pmb->vport;
  1925. struct lpfc_dmabuf *mp;
  1926. struct lpfc_nodelist *ndlp;
  1927. struct Scsi_Host *shost;
  1928. uint16_t rpi, vpi;
  1929. int rc;
  1930. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1931. if (mp) {
  1932. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1933. kfree(mp);
  1934. }
  1935. /*
  1936. * If a REG_LOGIN succeeded after node is destroyed or node
  1937. * is in re-discovery driver need to cleanup the RPI.
  1938. */
  1939. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1940. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1941. !pmb->u.mb.mbxStatus) {
  1942. rpi = pmb->u.mb.un.varWords[0];
  1943. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1944. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1945. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1946. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1947. if (rc != MBX_NOT_FINISHED)
  1948. return;
  1949. }
  1950. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1951. !(phba->pport->load_flag & FC_UNLOADING) &&
  1952. !pmb->u.mb.mbxStatus) {
  1953. shost = lpfc_shost_from_vport(vport);
  1954. spin_lock_irq(shost->host_lock);
  1955. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1956. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1957. spin_unlock_irq(shost->host_lock);
  1958. }
  1959. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1960. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1961. lpfc_nlp_put(ndlp);
  1962. pmb->context2 = NULL;
  1963. }
  1964. /* Check security permission status on INIT_LINK mailbox command */
  1965. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1966. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1967. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1968. "2860 SLI authentication is required "
  1969. "for INIT_LINK but has not done yet\n");
  1970. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1971. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1972. else
  1973. mempool_free(pmb, phba->mbox_mem_pool);
  1974. }
  1975. /**
  1976. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1977. * @phba: Pointer to HBA context object.
  1978. *
  1979. * This function is called with no lock held. This function processes all
  1980. * the completed mailbox commands and gives it to upper layers. The interrupt
  1981. * service routine processes mailbox completion interrupt and adds completed
  1982. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1983. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1984. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1985. * function returns the mailbox commands to the upper layer by calling the
  1986. * completion handler function of each mailbox.
  1987. **/
  1988. int
  1989. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1990. {
  1991. MAILBOX_t *pmbox;
  1992. LPFC_MBOXQ_t *pmb;
  1993. int rc;
  1994. LIST_HEAD(cmplq);
  1995. phba->sli.slistat.mbox_event++;
  1996. /* Get all completed mailboxe buffers into the cmplq */
  1997. spin_lock_irq(&phba->hbalock);
  1998. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1999. spin_unlock_irq(&phba->hbalock);
  2000. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2001. do {
  2002. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2003. if (pmb == NULL)
  2004. break;
  2005. pmbox = &pmb->u.mb;
  2006. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2007. if (pmb->vport) {
  2008. lpfc_debugfs_disc_trc(pmb->vport,
  2009. LPFC_DISC_TRC_MBOX_VPORT,
  2010. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2011. (uint32_t)pmbox->mbxCommand,
  2012. pmbox->un.varWords[0],
  2013. pmbox->un.varWords[1]);
  2014. }
  2015. else {
  2016. lpfc_debugfs_disc_trc(phba->pport,
  2017. LPFC_DISC_TRC_MBOX,
  2018. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2019. (uint32_t)pmbox->mbxCommand,
  2020. pmbox->un.varWords[0],
  2021. pmbox->un.varWords[1]);
  2022. }
  2023. }
  2024. /*
  2025. * It is a fatal error if unknown mbox command completion.
  2026. */
  2027. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2028. MBX_SHUTDOWN) {
  2029. /* Unknown mailbox command compl */
  2030. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2031. "(%d):0323 Unknown Mailbox command "
  2032. "x%x (x%x) Cmpl\n",
  2033. pmb->vport ? pmb->vport->vpi : 0,
  2034. pmbox->mbxCommand,
  2035. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2036. phba->link_state = LPFC_HBA_ERROR;
  2037. phba->work_hs = HS_FFER3;
  2038. lpfc_handle_eratt(phba);
  2039. continue;
  2040. }
  2041. if (pmbox->mbxStatus) {
  2042. phba->sli.slistat.mbox_stat_err++;
  2043. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2044. /* Mbox cmd cmpl error - RETRYing */
  2045. lpfc_printf_log(phba, KERN_INFO,
  2046. LOG_MBOX | LOG_SLI,
  2047. "(%d):0305 Mbox cmd cmpl "
  2048. "error - RETRYing Data: x%x "
  2049. "(x%x) x%x x%x x%x\n",
  2050. pmb->vport ? pmb->vport->vpi :0,
  2051. pmbox->mbxCommand,
  2052. lpfc_sli4_mbox_opcode_get(phba,
  2053. pmb),
  2054. pmbox->mbxStatus,
  2055. pmbox->un.varWords[0],
  2056. pmb->vport->port_state);
  2057. pmbox->mbxStatus = 0;
  2058. pmbox->mbxOwner = OWN_HOST;
  2059. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2060. if (rc != MBX_NOT_FINISHED)
  2061. continue;
  2062. }
  2063. }
  2064. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2065. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2066. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2067. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2068. pmb->vport ? pmb->vport->vpi : 0,
  2069. pmbox->mbxCommand,
  2070. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2071. pmb->mbox_cmpl,
  2072. *((uint32_t *) pmbox),
  2073. pmbox->un.varWords[0],
  2074. pmbox->un.varWords[1],
  2075. pmbox->un.varWords[2],
  2076. pmbox->un.varWords[3],
  2077. pmbox->un.varWords[4],
  2078. pmbox->un.varWords[5],
  2079. pmbox->un.varWords[6],
  2080. pmbox->un.varWords[7]);
  2081. if (pmb->mbox_cmpl)
  2082. pmb->mbox_cmpl(phba,pmb);
  2083. } while (1);
  2084. return 0;
  2085. }
  2086. /**
  2087. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2088. * @phba: Pointer to HBA context object.
  2089. * @pring: Pointer to driver SLI ring object.
  2090. * @tag: buffer tag.
  2091. *
  2092. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2093. * is set in the tag the buffer is posted for a particular exchange,
  2094. * the function will return the buffer without replacing the buffer.
  2095. * If the buffer is for unsolicited ELS or CT traffic, this function
  2096. * returns the buffer and also posts another buffer to the firmware.
  2097. **/
  2098. static struct lpfc_dmabuf *
  2099. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2100. struct lpfc_sli_ring *pring,
  2101. uint32_t tag)
  2102. {
  2103. struct hbq_dmabuf *hbq_entry;
  2104. if (tag & QUE_BUFTAG_BIT)
  2105. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2106. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2107. if (!hbq_entry)
  2108. return NULL;
  2109. return &hbq_entry->dbuf;
  2110. }
  2111. /**
  2112. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2113. * @phba: Pointer to HBA context object.
  2114. * @pring: Pointer to driver SLI ring object.
  2115. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2116. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2117. * @fch_type: the type for the first frame of the sequence.
  2118. *
  2119. * This function is called with no lock held. This function uses the r_ctl and
  2120. * type of the received sequence to find the correct callback function to call
  2121. * to process the sequence.
  2122. **/
  2123. static int
  2124. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2125. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2126. uint32_t fch_type)
  2127. {
  2128. int i;
  2129. /* unSolicited Responses */
  2130. if (pring->prt[0].profile) {
  2131. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2132. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2133. saveq);
  2134. return 1;
  2135. }
  2136. /* We must search, based on rctl / type
  2137. for the right routine */
  2138. for (i = 0; i < pring->num_mask; i++) {
  2139. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2140. (pring->prt[i].type == fch_type)) {
  2141. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2142. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2143. (phba, pring, saveq);
  2144. return 1;
  2145. }
  2146. }
  2147. return 0;
  2148. }
  2149. /**
  2150. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2151. * @phba: Pointer to HBA context object.
  2152. * @pring: Pointer to driver SLI ring object.
  2153. * @saveq: Pointer to the unsolicited iocb.
  2154. *
  2155. * This function is called with no lock held by the ring event handler
  2156. * when there is an unsolicited iocb posted to the response ring by the
  2157. * firmware. This function gets the buffer associated with the iocbs
  2158. * and calls the event handler for the ring. This function handles both
  2159. * qring buffers and hbq buffers.
  2160. * When the function returns 1 the caller can free the iocb object otherwise
  2161. * upper layer functions will free the iocb objects.
  2162. **/
  2163. static int
  2164. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2165. struct lpfc_iocbq *saveq)
  2166. {
  2167. IOCB_t * irsp;
  2168. WORD5 * w5p;
  2169. uint32_t Rctl, Type;
  2170. uint32_t match;
  2171. struct lpfc_iocbq *iocbq;
  2172. struct lpfc_dmabuf *dmzbuf;
  2173. match = 0;
  2174. irsp = &(saveq->iocb);
  2175. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2176. if (pring->lpfc_sli_rcv_async_status)
  2177. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2178. else
  2179. lpfc_printf_log(phba,
  2180. KERN_WARNING,
  2181. LOG_SLI,
  2182. "0316 Ring %d handler: unexpected "
  2183. "ASYNC_STATUS iocb received evt_code "
  2184. "0x%x\n",
  2185. pring->ringno,
  2186. irsp->un.asyncstat.evt_code);
  2187. return 1;
  2188. }
  2189. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2190. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2191. if (irsp->ulpBdeCount > 0) {
  2192. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2193. irsp->un.ulpWord[3]);
  2194. lpfc_in_buf_free(phba, dmzbuf);
  2195. }
  2196. if (irsp->ulpBdeCount > 1) {
  2197. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2198. irsp->unsli3.sli3Words[3]);
  2199. lpfc_in_buf_free(phba, dmzbuf);
  2200. }
  2201. if (irsp->ulpBdeCount > 2) {
  2202. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2203. irsp->unsli3.sli3Words[7]);
  2204. lpfc_in_buf_free(phba, dmzbuf);
  2205. }
  2206. return 1;
  2207. }
  2208. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2209. if (irsp->ulpBdeCount != 0) {
  2210. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2211. irsp->un.ulpWord[3]);
  2212. if (!saveq->context2)
  2213. lpfc_printf_log(phba,
  2214. KERN_ERR,
  2215. LOG_SLI,
  2216. "0341 Ring %d Cannot find buffer for "
  2217. "an unsolicited iocb. tag 0x%x\n",
  2218. pring->ringno,
  2219. irsp->un.ulpWord[3]);
  2220. }
  2221. if (irsp->ulpBdeCount == 2) {
  2222. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2223. irsp->unsli3.sli3Words[7]);
  2224. if (!saveq->context3)
  2225. lpfc_printf_log(phba,
  2226. KERN_ERR,
  2227. LOG_SLI,
  2228. "0342 Ring %d Cannot find buffer for an"
  2229. " unsolicited iocb. tag 0x%x\n",
  2230. pring->ringno,
  2231. irsp->unsli3.sli3Words[7]);
  2232. }
  2233. list_for_each_entry(iocbq, &saveq->list, list) {
  2234. irsp = &(iocbq->iocb);
  2235. if (irsp->ulpBdeCount != 0) {
  2236. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2237. irsp->un.ulpWord[3]);
  2238. if (!iocbq->context2)
  2239. lpfc_printf_log(phba,
  2240. KERN_ERR,
  2241. LOG_SLI,
  2242. "0343 Ring %d Cannot find "
  2243. "buffer for an unsolicited iocb"
  2244. ". tag 0x%x\n", pring->ringno,
  2245. irsp->un.ulpWord[3]);
  2246. }
  2247. if (irsp->ulpBdeCount == 2) {
  2248. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2249. irsp->unsli3.sli3Words[7]);
  2250. if (!iocbq->context3)
  2251. lpfc_printf_log(phba,
  2252. KERN_ERR,
  2253. LOG_SLI,
  2254. "0344 Ring %d Cannot find "
  2255. "buffer for an unsolicited "
  2256. "iocb. tag 0x%x\n",
  2257. pring->ringno,
  2258. irsp->unsli3.sli3Words[7]);
  2259. }
  2260. }
  2261. }
  2262. if (irsp->ulpBdeCount != 0 &&
  2263. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2264. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2265. int found = 0;
  2266. /* search continue save q for same XRI */
  2267. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2268. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2269. list_add_tail(&saveq->list, &iocbq->list);
  2270. found = 1;
  2271. break;
  2272. }
  2273. }
  2274. if (!found)
  2275. list_add_tail(&saveq->clist,
  2276. &pring->iocb_continue_saveq);
  2277. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2278. list_del_init(&iocbq->clist);
  2279. saveq = iocbq;
  2280. irsp = &(saveq->iocb);
  2281. } else
  2282. return 0;
  2283. }
  2284. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2285. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2286. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2287. Rctl = FC_RCTL_ELS_REQ;
  2288. Type = FC_TYPE_ELS;
  2289. } else {
  2290. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2291. Rctl = w5p->hcsw.Rctl;
  2292. Type = w5p->hcsw.Type;
  2293. /* Firmware Workaround */
  2294. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2295. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2296. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2297. Rctl = FC_RCTL_ELS_REQ;
  2298. Type = FC_TYPE_ELS;
  2299. w5p->hcsw.Rctl = Rctl;
  2300. w5p->hcsw.Type = Type;
  2301. }
  2302. }
  2303. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2304. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2305. "0313 Ring %d handler: unexpected Rctl x%x "
  2306. "Type x%x received\n",
  2307. pring->ringno, Rctl, Type);
  2308. return 1;
  2309. }
  2310. /**
  2311. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2312. * @phba: Pointer to HBA context object.
  2313. * @pring: Pointer to driver SLI ring object.
  2314. * @prspiocb: Pointer to response iocb object.
  2315. *
  2316. * This function looks up the iocb_lookup table to get the command iocb
  2317. * corresponding to the given response iocb using the iotag of the
  2318. * response iocb. This function is called with the hbalock held.
  2319. * This function returns the command iocb object if it finds the command
  2320. * iocb else returns NULL.
  2321. **/
  2322. static struct lpfc_iocbq *
  2323. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2324. struct lpfc_sli_ring *pring,
  2325. struct lpfc_iocbq *prspiocb)
  2326. {
  2327. struct lpfc_iocbq *cmd_iocb = NULL;
  2328. uint16_t iotag;
  2329. iotag = prspiocb->iocb.ulpIoTag;
  2330. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2331. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2332. list_del_init(&cmd_iocb->list);
  2333. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2334. pring->txcmplq_cnt--;
  2335. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2336. }
  2337. return cmd_iocb;
  2338. }
  2339. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2340. "0317 iotag x%x is out off "
  2341. "range: max iotag x%x wd0 x%x\n",
  2342. iotag, phba->sli.last_iotag,
  2343. *(((uint32_t *) &prspiocb->iocb) + 7));
  2344. return NULL;
  2345. }
  2346. /**
  2347. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2348. * @phba: Pointer to HBA context object.
  2349. * @pring: Pointer to driver SLI ring object.
  2350. * @iotag: IOCB tag.
  2351. *
  2352. * This function looks up the iocb_lookup table to get the command iocb
  2353. * corresponding to the given iotag. This function is called with the
  2354. * hbalock held.
  2355. * This function returns the command iocb object if it finds the command
  2356. * iocb else returns NULL.
  2357. **/
  2358. static struct lpfc_iocbq *
  2359. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2360. struct lpfc_sli_ring *pring, uint16_t iotag)
  2361. {
  2362. struct lpfc_iocbq *cmd_iocb;
  2363. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2364. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2365. list_del_init(&cmd_iocb->list);
  2366. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2367. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2368. pring->txcmplq_cnt--;
  2369. }
  2370. return cmd_iocb;
  2371. }
  2372. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2373. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2374. iotag, phba->sli.last_iotag);
  2375. return NULL;
  2376. }
  2377. /**
  2378. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2379. * @phba: Pointer to HBA context object.
  2380. * @pring: Pointer to driver SLI ring object.
  2381. * @saveq: Pointer to the response iocb to be processed.
  2382. *
  2383. * This function is called by the ring event handler for non-fcp
  2384. * rings when there is a new response iocb in the response ring.
  2385. * The caller is not required to hold any locks. This function
  2386. * gets the command iocb associated with the response iocb and
  2387. * calls the completion handler for the command iocb. If there
  2388. * is no completion handler, the function will free the resources
  2389. * associated with command iocb. If the response iocb is for
  2390. * an already aborted command iocb, the status of the completion
  2391. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2392. * This function always returns 1.
  2393. **/
  2394. static int
  2395. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2396. struct lpfc_iocbq *saveq)
  2397. {
  2398. struct lpfc_iocbq *cmdiocbp;
  2399. int rc = 1;
  2400. unsigned long iflag;
  2401. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2402. spin_lock_irqsave(&phba->hbalock, iflag);
  2403. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2404. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2405. if (cmdiocbp) {
  2406. if (cmdiocbp->iocb_cmpl) {
  2407. /*
  2408. * If an ELS command failed send an event to mgmt
  2409. * application.
  2410. */
  2411. if (saveq->iocb.ulpStatus &&
  2412. (pring->ringno == LPFC_ELS_RING) &&
  2413. (cmdiocbp->iocb.ulpCommand ==
  2414. CMD_ELS_REQUEST64_CR))
  2415. lpfc_send_els_failure_event(phba,
  2416. cmdiocbp, saveq);
  2417. /*
  2418. * Post all ELS completions to the worker thread.
  2419. * All other are passed to the completion callback.
  2420. */
  2421. if (pring->ringno == LPFC_ELS_RING) {
  2422. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2423. (cmdiocbp->iocb_flag &
  2424. LPFC_DRIVER_ABORTED)) {
  2425. spin_lock_irqsave(&phba->hbalock,
  2426. iflag);
  2427. cmdiocbp->iocb_flag &=
  2428. ~LPFC_DRIVER_ABORTED;
  2429. spin_unlock_irqrestore(&phba->hbalock,
  2430. iflag);
  2431. saveq->iocb.ulpStatus =
  2432. IOSTAT_LOCAL_REJECT;
  2433. saveq->iocb.un.ulpWord[4] =
  2434. IOERR_SLI_ABORTED;
  2435. /* Firmware could still be in progress
  2436. * of DMAing payload, so don't free data
  2437. * buffer till after a hbeat.
  2438. */
  2439. spin_lock_irqsave(&phba->hbalock,
  2440. iflag);
  2441. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2442. spin_unlock_irqrestore(&phba->hbalock,
  2443. iflag);
  2444. }
  2445. if (phba->sli_rev == LPFC_SLI_REV4) {
  2446. if (saveq->iocb_flag &
  2447. LPFC_EXCHANGE_BUSY) {
  2448. /* Set cmdiocb flag for the
  2449. * exchange busy so sgl (xri)
  2450. * will not be released until
  2451. * the abort xri is received
  2452. * from hba.
  2453. */
  2454. spin_lock_irqsave(
  2455. &phba->hbalock, iflag);
  2456. cmdiocbp->iocb_flag |=
  2457. LPFC_EXCHANGE_BUSY;
  2458. spin_unlock_irqrestore(
  2459. &phba->hbalock, iflag);
  2460. }
  2461. if (cmdiocbp->iocb_flag &
  2462. LPFC_DRIVER_ABORTED) {
  2463. /*
  2464. * Clear LPFC_DRIVER_ABORTED
  2465. * bit in case it was driver
  2466. * initiated abort.
  2467. */
  2468. spin_lock_irqsave(
  2469. &phba->hbalock, iflag);
  2470. cmdiocbp->iocb_flag &=
  2471. ~LPFC_DRIVER_ABORTED;
  2472. spin_unlock_irqrestore(
  2473. &phba->hbalock, iflag);
  2474. cmdiocbp->iocb.ulpStatus =
  2475. IOSTAT_LOCAL_REJECT;
  2476. cmdiocbp->iocb.un.ulpWord[4] =
  2477. IOERR_ABORT_REQUESTED;
  2478. /*
  2479. * For SLI4, irsiocb contains
  2480. * NO_XRI in sli_xritag, it
  2481. * shall not affect releasing
  2482. * sgl (xri) process.
  2483. */
  2484. saveq->iocb.ulpStatus =
  2485. IOSTAT_LOCAL_REJECT;
  2486. saveq->iocb.un.ulpWord[4] =
  2487. IOERR_SLI_ABORTED;
  2488. spin_lock_irqsave(
  2489. &phba->hbalock, iflag);
  2490. saveq->iocb_flag |=
  2491. LPFC_DELAY_MEM_FREE;
  2492. spin_unlock_irqrestore(
  2493. &phba->hbalock, iflag);
  2494. }
  2495. }
  2496. }
  2497. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2498. } else
  2499. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2500. } else {
  2501. /*
  2502. * Unknown initiating command based on the response iotag.
  2503. * This could be the case on the ELS ring because of
  2504. * lpfc_els_abort().
  2505. */
  2506. if (pring->ringno != LPFC_ELS_RING) {
  2507. /*
  2508. * Ring <ringno> handler: unexpected completion IoTag
  2509. * <IoTag>
  2510. */
  2511. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2512. "0322 Ring %d handler: "
  2513. "unexpected completion IoTag x%x "
  2514. "Data: x%x x%x x%x x%x\n",
  2515. pring->ringno,
  2516. saveq->iocb.ulpIoTag,
  2517. saveq->iocb.ulpStatus,
  2518. saveq->iocb.un.ulpWord[4],
  2519. saveq->iocb.ulpCommand,
  2520. saveq->iocb.ulpContext);
  2521. }
  2522. }
  2523. return rc;
  2524. }
  2525. /**
  2526. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2527. * @phba: Pointer to HBA context object.
  2528. * @pring: Pointer to driver SLI ring object.
  2529. *
  2530. * This function is called from the iocb ring event handlers when
  2531. * put pointer is ahead of the get pointer for a ring. This function signal
  2532. * an error attention condition to the worker thread and the worker
  2533. * thread will transition the HBA to offline state.
  2534. **/
  2535. static void
  2536. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2537. {
  2538. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2539. /*
  2540. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2541. * rsp ring <portRspMax>
  2542. */
  2543. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2544. "0312 Ring %d handler: portRspPut %d "
  2545. "is bigger than rsp ring %d\n",
  2546. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2547. pring->numRiocb);
  2548. phba->link_state = LPFC_HBA_ERROR;
  2549. /*
  2550. * All error attention handlers are posted to
  2551. * worker thread
  2552. */
  2553. phba->work_ha |= HA_ERATT;
  2554. phba->work_hs = HS_FFER3;
  2555. lpfc_worker_wake_up(phba);
  2556. return;
  2557. }
  2558. /**
  2559. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2560. * @ptr: Pointer to address of HBA context object.
  2561. *
  2562. * This function is invoked by the Error Attention polling timer when the
  2563. * timer times out. It will check the SLI Error Attention register for
  2564. * possible attention events. If so, it will post an Error Attention event
  2565. * and wake up worker thread to process it. Otherwise, it will set up the
  2566. * Error Attention polling timer for the next poll.
  2567. **/
  2568. void lpfc_poll_eratt(unsigned long ptr)
  2569. {
  2570. struct lpfc_hba *phba;
  2571. uint32_t eratt = 0;
  2572. phba = (struct lpfc_hba *)ptr;
  2573. /* Check chip HA register for error event */
  2574. eratt = lpfc_sli_check_eratt(phba);
  2575. if (eratt)
  2576. /* Tell the worker thread there is work to do */
  2577. lpfc_worker_wake_up(phba);
  2578. else
  2579. /* Restart the timer for next eratt poll */
  2580. mod_timer(&phba->eratt_poll, jiffies +
  2581. HZ * LPFC_ERATT_POLL_INTERVAL);
  2582. return;
  2583. }
  2584. /**
  2585. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2586. * @phba: Pointer to HBA context object.
  2587. * @pring: Pointer to driver SLI ring object.
  2588. * @mask: Host attention register mask for this ring.
  2589. *
  2590. * This function is called from the interrupt context when there is a ring
  2591. * event for the fcp ring. The caller does not hold any lock.
  2592. * The function processes each response iocb in the response ring until it
  2593. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2594. * LE bit set. The function will call the completion handler of the command iocb
  2595. * if the response iocb indicates a completion for a command iocb or it is
  2596. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2597. * function if this is an unsolicited iocb.
  2598. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2599. * to check it explicitly.
  2600. */
  2601. int
  2602. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2603. struct lpfc_sli_ring *pring, uint32_t mask)
  2604. {
  2605. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2606. IOCB_t *irsp = NULL;
  2607. IOCB_t *entry = NULL;
  2608. struct lpfc_iocbq *cmdiocbq = NULL;
  2609. struct lpfc_iocbq rspiocbq;
  2610. uint32_t status;
  2611. uint32_t portRspPut, portRspMax;
  2612. int rc = 1;
  2613. lpfc_iocb_type type;
  2614. unsigned long iflag;
  2615. uint32_t rsp_cmpl = 0;
  2616. spin_lock_irqsave(&phba->hbalock, iflag);
  2617. pring->stats.iocb_event++;
  2618. /*
  2619. * The next available response entry should never exceed the maximum
  2620. * entries. If it does, treat it as an adapter hardware error.
  2621. */
  2622. portRspMax = pring->numRiocb;
  2623. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2624. if (unlikely(portRspPut >= portRspMax)) {
  2625. lpfc_sli_rsp_pointers_error(phba, pring);
  2626. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2627. return 1;
  2628. }
  2629. if (phba->fcp_ring_in_use) {
  2630. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2631. return 1;
  2632. } else
  2633. phba->fcp_ring_in_use = 1;
  2634. rmb();
  2635. while (pring->rspidx != portRspPut) {
  2636. /*
  2637. * Fetch an entry off the ring and copy it into a local data
  2638. * structure. The copy involves a byte-swap since the
  2639. * network byte order and pci byte orders are different.
  2640. */
  2641. entry = lpfc_resp_iocb(phba, pring);
  2642. phba->last_completion_time = jiffies;
  2643. if (++pring->rspidx >= portRspMax)
  2644. pring->rspidx = 0;
  2645. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2646. (uint32_t *) &rspiocbq.iocb,
  2647. phba->iocb_rsp_size);
  2648. INIT_LIST_HEAD(&(rspiocbq.list));
  2649. irsp = &rspiocbq.iocb;
  2650. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2651. pring->stats.iocb_rsp++;
  2652. rsp_cmpl++;
  2653. if (unlikely(irsp->ulpStatus)) {
  2654. /*
  2655. * If resource errors reported from HBA, reduce
  2656. * queuedepths of the SCSI device.
  2657. */
  2658. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2659. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2660. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2661. phba->lpfc_rampdown_queue_depth(phba);
  2662. spin_lock_irqsave(&phba->hbalock, iflag);
  2663. }
  2664. /* Rsp ring <ringno> error: IOCB */
  2665. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2666. "0336 Rsp Ring %d error: IOCB Data: "
  2667. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2668. pring->ringno,
  2669. irsp->un.ulpWord[0],
  2670. irsp->un.ulpWord[1],
  2671. irsp->un.ulpWord[2],
  2672. irsp->un.ulpWord[3],
  2673. irsp->un.ulpWord[4],
  2674. irsp->un.ulpWord[5],
  2675. *(uint32_t *)&irsp->un1,
  2676. *((uint32_t *)&irsp->un1 + 1));
  2677. }
  2678. switch (type) {
  2679. case LPFC_ABORT_IOCB:
  2680. case LPFC_SOL_IOCB:
  2681. /*
  2682. * Idle exchange closed via ABTS from port. No iocb
  2683. * resources need to be recovered.
  2684. */
  2685. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2686. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2687. "0333 IOCB cmd 0x%x"
  2688. " processed. Skipping"
  2689. " completion\n",
  2690. irsp->ulpCommand);
  2691. break;
  2692. }
  2693. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2694. &rspiocbq);
  2695. if (unlikely(!cmdiocbq))
  2696. break;
  2697. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2698. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2699. if (cmdiocbq->iocb_cmpl) {
  2700. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2701. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2702. &rspiocbq);
  2703. spin_lock_irqsave(&phba->hbalock, iflag);
  2704. }
  2705. break;
  2706. case LPFC_UNSOL_IOCB:
  2707. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2708. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2709. spin_lock_irqsave(&phba->hbalock, iflag);
  2710. break;
  2711. default:
  2712. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2713. char adaptermsg[LPFC_MAX_ADPTMSG];
  2714. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2715. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2716. MAX_MSG_DATA);
  2717. dev_warn(&((phba->pcidev)->dev),
  2718. "lpfc%d: %s\n",
  2719. phba->brd_no, adaptermsg);
  2720. } else {
  2721. /* Unknown IOCB command */
  2722. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2723. "0334 Unknown IOCB command "
  2724. "Data: x%x, x%x x%x x%x x%x\n",
  2725. type, irsp->ulpCommand,
  2726. irsp->ulpStatus,
  2727. irsp->ulpIoTag,
  2728. irsp->ulpContext);
  2729. }
  2730. break;
  2731. }
  2732. /*
  2733. * The response IOCB has been processed. Update the ring
  2734. * pointer in SLIM. If the port response put pointer has not
  2735. * been updated, sync the pgp->rspPutInx and fetch the new port
  2736. * response put pointer.
  2737. */
  2738. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2739. if (pring->rspidx == portRspPut)
  2740. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2741. }
  2742. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2743. pring->stats.iocb_rsp_full++;
  2744. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2745. writel(status, phba->CAregaddr);
  2746. readl(phba->CAregaddr);
  2747. }
  2748. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2749. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2750. pring->stats.iocb_cmd_empty++;
  2751. /* Force update of the local copy of cmdGetInx */
  2752. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2753. lpfc_sli_resume_iocb(phba, pring);
  2754. if ((pring->lpfc_sli_cmd_available))
  2755. (pring->lpfc_sli_cmd_available) (phba, pring);
  2756. }
  2757. phba->fcp_ring_in_use = 0;
  2758. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2759. return rc;
  2760. }
  2761. /**
  2762. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2763. * @phba: Pointer to HBA context object.
  2764. * @pring: Pointer to driver SLI ring object.
  2765. * @rspiocbp: Pointer to driver response IOCB object.
  2766. *
  2767. * This function is called from the worker thread when there is a slow-path
  2768. * response IOCB to process. This function chains all the response iocbs until
  2769. * seeing the iocb with the LE bit set. The function will call
  2770. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2771. * completion of a command iocb. The function will call the
  2772. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2773. * The function frees the resources or calls the completion handler if this
  2774. * iocb is an abort completion. The function returns NULL when the response
  2775. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2776. * this function shall chain the iocb on to the iocb_continueq and return the
  2777. * response iocb passed in.
  2778. **/
  2779. static struct lpfc_iocbq *
  2780. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2781. struct lpfc_iocbq *rspiocbp)
  2782. {
  2783. struct lpfc_iocbq *saveq;
  2784. struct lpfc_iocbq *cmdiocbp;
  2785. struct lpfc_iocbq *next_iocb;
  2786. IOCB_t *irsp = NULL;
  2787. uint32_t free_saveq;
  2788. uint8_t iocb_cmd_type;
  2789. lpfc_iocb_type type;
  2790. unsigned long iflag;
  2791. int rc;
  2792. spin_lock_irqsave(&phba->hbalock, iflag);
  2793. /* First add the response iocb to the countinueq list */
  2794. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2795. pring->iocb_continueq_cnt++;
  2796. /* Now, determine whether the list is completed for processing */
  2797. irsp = &rspiocbp->iocb;
  2798. if (irsp->ulpLe) {
  2799. /*
  2800. * By default, the driver expects to free all resources
  2801. * associated with this iocb completion.
  2802. */
  2803. free_saveq = 1;
  2804. saveq = list_get_first(&pring->iocb_continueq,
  2805. struct lpfc_iocbq, list);
  2806. irsp = &(saveq->iocb);
  2807. list_del_init(&pring->iocb_continueq);
  2808. pring->iocb_continueq_cnt = 0;
  2809. pring->stats.iocb_rsp++;
  2810. /*
  2811. * If resource errors reported from HBA, reduce
  2812. * queuedepths of the SCSI device.
  2813. */
  2814. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2815. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2816. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2817. phba->lpfc_rampdown_queue_depth(phba);
  2818. spin_lock_irqsave(&phba->hbalock, iflag);
  2819. }
  2820. if (irsp->ulpStatus) {
  2821. /* Rsp ring <ringno> error: IOCB */
  2822. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2823. "0328 Rsp Ring %d error: "
  2824. "IOCB Data: "
  2825. "x%x x%x x%x x%x "
  2826. "x%x x%x x%x x%x "
  2827. "x%x x%x x%x x%x "
  2828. "x%x x%x x%x x%x\n",
  2829. pring->ringno,
  2830. irsp->un.ulpWord[0],
  2831. irsp->un.ulpWord[1],
  2832. irsp->un.ulpWord[2],
  2833. irsp->un.ulpWord[3],
  2834. irsp->un.ulpWord[4],
  2835. irsp->un.ulpWord[5],
  2836. *(((uint32_t *) irsp) + 6),
  2837. *(((uint32_t *) irsp) + 7),
  2838. *(((uint32_t *) irsp) + 8),
  2839. *(((uint32_t *) irsp) + 9),
  2840. *(((uint32_t *) irsp) + 10),
  2841. *(((uint32_t *) irsp) + 11),
  2842. *(((uint32_t *) irsp) + 12),
  2843. *(((uint32_t *) irsp) + 13),
  2844. *(((uint32_t *) irsp) + 14),
  2845. *(((uint32_t *) irsp) + 15));
  2846. }
  2847. /*
  2848. * Fetch the IOCB command type and call the correct completion
  2849. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2850. * get freed back to the lpfc_iocb_list by the discovery
  2851. * kernel thread.
  2852. */
  2853. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2854. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2855. switch (type) {
  2856. case LPFC_SOL_IOCB:
  2857. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2858. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2859. spin_lock_irqsave(&phba->hbalock, iflag);
  2860. break;
  2861. case LPFC_UNSOL_IOCB:
  2862. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2863. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2864. spin_lock_irqsave(&phba->hbalock, iflag);
  2865. if (!rc)
  2866. free_saveq = 0;
  2867. break;
  2868. case LPFC_ABORT_IOCB:
  2869. cmdiocbp = NULL;
  2870. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2871. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2872. saveq);
  2873. if (cmdiocbp) {
  2874. /* Call the specified completion routine */
  2875. if (cmdiocbp->iocb_cmpl) {
  2876. spin_unlock_irqrestore(&phba->hbalock,
  2877. iflag);
  2878. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2879. saveq);
  2880. spin_lock_irqsave(&phba->hbalock,
  2881. iflag);
  2882. } else
  2883. __lpfc_sli_release_iocbq(phba,
  2884. cmdiocbp);
  2885. }
  2886. break;
  2887. case LPFC_UNKNOWN_IOCB:
  2888. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2889. char adaptermsg[LPFC_MAX_ADPTMSG];
  2890. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2891. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2892. MAX_MSG_DATA);
  2893. dev_warn(&((phba->pcidev)->dev),
  2894. "lpfc%d: %s\n",
  2895. phba->brd_no, adaptermsg);
  2896. } else {
  2897. /* Unknown IOCB command */
  2898. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2899. "0335 Unknown IOCB "
  2900. "command Data: x%x "
  2901. "x%x x%x x%x\n",
  2902. irsp->ulpCommand,
  2903. irsp->ulpStatus,
  2904. irsp->ulpIoTag,
  2905. irsp->ulpContext);
  2906. }
  2907. break;
  2908. }
  2909. if (free_saveq) {
  2910. list_for_each_entry_safe(rspiocbp, next_iocb,
  2911. &saveq->list, list) {
  2912. list_del(&rspiocbp->list);
  2913. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2914. }
  2915. __lpfc_sli_release_iocbq(phba, saveq);
  2916. }
  2917. rspiocbp = NULL;
  2918. }
  2919. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2920. return rspiocbp;
  2921. }
  2922. /**
  2923. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2924. * @phba: Pointer to HBA context object.
  2925. * @pring: Pointer to driver SLI ring object.
  2926. * @mask: Host attention register mask for this ring.
  2927. *
  2928. * This routine wraps the actual slow_ring event process routine from the
  2929. * API jump table function pointer from the lpfc_hba struct.
  2930. **/
  2931. void
  2932. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2933. struct lpfc_sli_ring *pring, uint32_t mask)
  2934. {
  2935. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2936. }
  2937. /**
  2938. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2939. * @phba: Pointer to HBA context object.
  2940. * @pring: Pointer to driver SLI ring object.
  2941. * @mask: Host attention register mask for this ring.
  2942. *
  2943. * This function is called from the worker thread when there is a ring event
  2944. * for non-fcp rings. The caller does not hold any lock. The function will
  2945. * remove each response iocb in the response ring and calls the handle
  2946. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2947. **/
  2948. static void
  2949. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2950. struct lpfc_sli_ring *pring, uint32_t mask)
  2951. {
  2952. struct lpfc_pgp *pgp;
  2953. IOCB_t *entry;
  2954. IOCB_t *irsp = NULL;
  2955. struct lpfc_iocbq *rspiocbp = NULL;
  2956. uint32_t portRspPut, portRspMax;
  2957. unsigned long iflag;
  2958. uint32_t status;
  2959. pgp = &phba->port_gp[pring->ringno];
  2960. spin_lock_irqsave(&phba->hbalock, iflag);
  2961. pring->stats.iocb_event++;
  2962. /*
  2963. * The next available response entry should never exceed the maximum
  2964. * entries. If it does, treat it as an adapter hardware error.
  2965. */
  2966. portRspMax = pring->numRiocb;
  2967. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2968. if (portRspPut >= portRspMax) {
  2969. /*
  2970. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2971. * rsp ring <portRspMax>
  2972. */
  2973. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2974. "0303 Ring %d handler: portRspPut %d "
  2975. "is bigger than rsp ring %d\n",
  2976. pring->ringno, portRspPut, portRspMax);
  2977. phba->link_state = LPFC_HBA_ERROR;
  2978. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2979. phba->work_hs = HS_FFER3;
  2980. lpfc_handle_eratt(phba);
  2981. return;
  2982. }
  2983. rmb();
  2984. while (pring->rspidx != portRspPut) {
  2985. /*
  2986. * Build a completion list and call the appropriate handler.
  2987. * The process is to get the next available response iocb, get
  2988. * a free iocb from the list, copy the response data into the
  2989. * free iocb, insert to the continuation list, and update the
  2990. * next response index to slim. This process makes response
  2991. * iocb's in the ring available to DMA as fast as possible but
  2992. * pays a penalty for a copy operation. Since the iocb is
  2993. * only 32 bytes, this penalty is considered small relative to
  2994. * the PCI reads for register values and a slim write. When
  2995. * the ulpLe field is set, the entire Command has been
  2996. * received.
  2997. */
  2998. entry = lpfc_resp_iocb(phba, pring);
  2999. phba->last_completion_time = jiffies;
  3000. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3001. if (rspiocbp == NULL) {
  3002. printk(KERN_ERR "%s: out of buffers! Failing "
  3003. "completion.\n", __func__);
  3004. break;
  3005. }
  3006. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3007. phba->iocb_rsp_size);
  3008. irsp = &rspiocbp->iocb;
  3009. if (++pring->rspidx >= portRspMax)
  3010. pring->rspidx = 0;
  3011. if (pring->ringno == LPFC_ELS_RING) {
  3012. lpfc_debugfs_slow_ring_trc(phba,
  3013. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3014. *(((uint32_t *) irsp) + 4),
  3015. *(((uint32_t *) irsp) + 6),
  3016. *(((uint32_t *) irsp) + 7));
  3017. }
  3018. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3019. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3020. /* Handle the response IOCB */
  3021. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3022. spin_lock_irqsave(&phba->hbalock, iflag);
  3023. /*
  3024. * If the port response put pointer has not been updated, sync
  3025. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3026. * response put pointer.
  3027. */
  3028. if (pring->rspidx == portRspPut) {
  3029. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3030. }
  3031. } /* while (pring->rspidx != portRspPut) */
  3032. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3033. /* At least one response entry has been freed */
  3034. pring->stats.iocb_rsp_full++;
  3035. /* SET RxRE_RSP in Chip Att register */
  3036. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3037. writel(status, phba->CAregaddr);
  3038. readl(phba->CAregaddr); /* flush */
  3039. }
  3040. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3041. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3042. pring->stats.iocb_cmd_empty++;
  3043. /* Force update of the local copy of cmdGetInx */
  3044. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3045. lpfc_sli_resume_iocb(phba, pring);
  3046. if ((pring->lpfc_sli_cmd_available))
  3047. (pring->lpfc_sli_cmd_available) (phba, pring);
  3048. }
  3049. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3050. return;
  3051. }
  3052. /**
  3053. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3054. * @phba: Pointer to HBA context object.
  3055. * @pring: Pointer to driver SLI ring object.
  3056. * @mask: Host attention register mask for this ring.
  3057. *
  3058. * This function is called from the worker thread when there is a pending
  3059. * ELS response iocb on the driver internal slow-path response iocb worker
  3060. * queue. The caller does not hold any lock. The function will remove each
  3061. * response iocb from the response worker queue and calls the handle
  3062. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3063. **/
  3064. static void
  3065. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3066. struct lpfc_sli_ring *pring, uint32_t mask)
  3067. {
  3068. struct lpfc_iocbq *irspiocbq;
  3069. struct hbq_dmabuf *dmabuf;
  3070. struct lpfc_cq_event *cq_event;
  3071. unsigned long iflag;
  3072. spin_lock_irqsave(&phba->hbalock, iflag);
  3073. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3074. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3075. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3076. /* Get the response iocb from the head of work queue */
  3077. spin_lock_irqsave(&phba->hbalock, iflag);
  3078. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3079. cq_event, struct lpfc_cq_event, list);
  3080. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3081. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3082. case CQE_CODE_COMPL_WQE:
  3083. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3084. cq_event);
  3085. /* Translate ELS WCQE to response IOCBQ */
  3086. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3087. irspiocbq);
  3088. if (irspiocbq)
  3089. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3090. irspiocbq);
  3091. break;
  3092. case CQE_CODE_RECEIVE:
  3093. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3094. cq_event);
  3095. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3096. break;
  3097. default:
  3098. break;
  3099. }
  3100. }
  3101. }
  3102. /**
  3103. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3104. * @phba: Pointer to HBA context object.
  3105. * @pring: Pointer to driver SLI ring object.
  3106. *
  3107. * This function aborts all iocbs in the given ring and frees all the iocb
  3108. * objects in txq. This function issues an abort iocb for all the iocb commands
  3109. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3110. * the return of this function. The caller is not required to hold any locks.
  3111. **/
  3112. void
  3113. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3114. {
  3115. LIST_HEAD(completions);
  3116. struct lpfc_iocbq *iocb, *next_iocb;
  3117. if (pring->ringno == LPFC_ELS_RING) {
  3118. lpfc_fabric_abort_hba(phba);
  3119. }
  3120. /* Error everything on txq and txcmplq
  3121. * First do the txq.
  3122. */
  3123. spin_lock_irq(&phba->hbalock);
  3124. list_splice_init(&pring->txq, &completions);
  3125. pring->txq_cnt = 0;
  3126. /* Next issue ABTS for everything on the txcmplq */
  3127. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3128. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3129. spin_unlock_irq(&phba->hbalock);
  3130. /* Cancel all the IOCBs from the completions list */
  3131. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3132. IOERR_SLI_ABORTED);
  3133. }
  3134. /**
  3135. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3136. * @phba: Pointer to HBA context object.
  3137. *
  3138. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3139. * objects in txq and txcmplq. This function will not issue abort iocbs
  3140. * for all the iocb commands in txcmplq, they will just be returned with
  3141. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3142. * slot has been permanently disabled.
  3143. **/
  3144. void
  3145. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3146. {
  3147. LIST_HEAD(txq);
  3148. LIST_HEAD(txcmplq);
  3149. struct lpfc_sli *psli = &phba->sli;
  3150. struct lpfc_sli_ring *pring;
  3151. /* Currently, only one fcp ring */
  3152. pring = &psli->ring[psli->fcp_ring];
  3153. spin_lock_irq(&phba->hbalock);
  3154. /* Retrieve everything on txq */
  3155. list_splice_init(&pring->txq, &txq);
  3156. pring->txq_cnt = 0;
  3157. /* Retrieve everything on the txcmplq */
  3158. list_splice_init(&pring->txcmplq, &txcmplq);
  3159. pring->txcmplq_cnt = 0;
  3160. spin_unlock_irq(&phba->hbalock);
  3161. /* Flush the txq */
  3162. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3163. IOERR_SLI_DOWN);
  3164. /* Flush the txcmpq */
  3165. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3166. IOERR_SLI_DOWN);
  3167. }
  3168. /**
  3169. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3170. * @phba: Pointer to HBA context object.
  3171. * @mask: Bit mask to be checked.
  3172. *
  3173. * This function reads the host status register and compares
  3174. * with the provided bit mask to check if HBA completed
  3175. * the restart. This function will wait in a loop for the
  3176. * HBA to complete restart. If the HBA does not restart within
  3177. * 15 iterations, the function will reset the HBA again. The
  3178. * function returns 1 when HBA fail to restart otherwise returns
  3179. * zero.
  3180. **/
  3181. static int
  3182. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3183. {
  3184. uint32_t status;
  3185. int i = 0;
  3186. int retval = 0;
  3187. /* Read the HBA Host Status Register */
  3188. if (lpfc_readl(phba->HSregaddr, &status))
  3189. return 1;
  3190. /*
  3191. * Check status register every 100ms for 5 retries, then every
  3192. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3193. * every 2.5 sec for 4.
  3194. * Break our of the loop if errors occurred during init.
  3195. */
  3196. while (((status & mask) != mask) &&
  3197. !(status & HS_FFERM) &&
  3198. i++ < 20) {
  3199. if (i <= 5)
  3200. msleep(10);
  3201. else if (i <= 10)
  3202. msleep(500);
  3203. else
  3204. msleep(2500);
  3205. if (i == 15) {
  3206. /* Do post */
  3207. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3208. lpfc_sli_brdrestart(phba);
  3209. }
  3210. /* Read the HBA Host Status Register */
  3211. if (lpfc_readl(phba->HSregaddr, &status)) {
  3212. retval = 1;
  3213. break;
  3214. }
  3215. }
  3216. /* Check to see if any errors occurred during init */
  3217. if ((status & HS_FFERM) || (i >= 20)) {
  3218. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3219. "2751 Adapter failed to restart, "
  3220. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3221. status,
  3222. readl(phba->MBslimaddr + 0xa8),
  3223. readl(phba->MBslimaddr + 0xac));
  3224. phba->link_state = LPFC_HBA_ERROR;
  3225. retval = 1;
  3226. }
  3227. return retval;
  3228. }
  3229. /**
  3230. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3231. * @phba: Pointer to HBA context object.
  3232. * @mask: Bit mask to be checked.
  3233. *
  3234. * This function checks the host status register to check if HBA is
  3235. * ready. This function will wait in a loop for the HBA to be ready
  3236. * If the HBA is not ready , the function will will reset the HBA PCI
  3237. * function again. The function returns 1 when HBA fail to be ready
  3238. * otherwise returns zero.
  3239. **/
  3240. static int
  3241. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3242. {
  3243. uint32_t status;
  3244. int retval = 0;
  3245. /* Read the HBA Host Status Register */
  3246. status = lpfc_sli4_post_status_check(phba);
  3247. if (status) {
  3248. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3249. lpfc_sli_brdrestart(phba);
  3250. status = lpfc_sli4_post_status_check(phba);
  3251. }
  3252. /* Check to see if any errors occurred during init */
  3253. if (status) {
  3254. phba->link_state = LPFC_HBA_ERROR;
  3255. retval = 1;
  3256. } else
  3257. phba->sli4_hba.intr_enable = 0;
  3258. return retval;
  3259. }
  3260. /**
  3261. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3262. * @phba: Pointer to HBA context object.
  3263. * @mask: Bit mask to be checked.
  3264. *
  3265. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3266. * from the API jump table function pointer from the lpfc_hba struct.
  3267. **/
  3268. int
  3269. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3270. {
  3271. return phba->lpfc_sli_brdready(phba, mask);
  3272. }
  3273. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3274. /**
  3275. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3276. * @phba: Pointer to HBA context object.
  3277. *
  3278. * This function is called before resetting an HBA. This
  3279. * function requests HBA to quiesce DMAs before a reset.
  3280. **/
  3281. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3282. {
  3283. uint32_t __iomem *resp_buf;
  3284. uint32_t __iomem *mbox_buf;
  3285. volatile uint32_t mbox;
  3286. uint32_t hc_copy, ha_copy, resp_data;
  3287. int i;
  3288. uint8_t hdrtype;
  3289. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3290. if (hdrtype != 0x80 ||
  3291. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3292. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3293. return;
  3294. /*
  3295. * Tell the other part of the chip to suspend temporarily all
  3296. * its DMA activity.
  3297. */
  3298. resp_buf = phba->MBslimaddr;
  3299. /* Disable the error attention */
  3300. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3301. return;
  3302. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3303. readl(phba->HCregaddr); /* flush */
  3304. phba->link_flag |= LS_IGNORE_ERATT;
  3305. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3306. return;
  3307. if (ha_copy & HA_ERATT) {
  3308. /* Clear Chip error bit */
  3309. writel(HA_ERATT, phba->HAregaddr);
  3310. phba->pport->stopped = 1;
  3311. }
  3312. mbox = 0;
  3313. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3314. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3315. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3316. mbox_buf = phba->MBslimaddr;
  3317. writel(mbox, mbox_buf);
  3318. for (i = 0; i < 50; i++) {
  3319. if (lpfc_readl((resp_buf + 1), &resp_data))
  3320. return;
  3321. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3322. mdelay(1);
  3323. else
  3324. break;
  3325. }
  3326. resp_data = 0;
  3327. if (lpfc_readl((resp_buf + 1), &resp_data))
  3328. return;
  3329. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3330. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3331. phba->pport->stopped)
  3332. goto restore_hc;
  3333. else
  3334. goto clear_errat;
  3335. }
  3336. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3337. resp_data = 0;
  3338. for (i = 0; i < 500; i++) {
  3339. if (lpfc_readl(resp_buf, &resp_data))
  3340. return;
  3341. if (resp_data != mbox)
  3342. mdelay(1);
  3343. else
  3344. break;
  3345. }
  3346. clear_errat:
  3347. while (++i < 500) {
  3348. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3349. return;
  3350. if (!(ha_copy & HA_ERATT))
  3351. mdelay(1);
  3352. else
  3353. break;
  3354. }
  3355. if (readl(phba->HAregaddr) & HA_ERATT) {
  3356. writel(HA_ERATT, phba->HAregaddr);
  3357. phba->pport->stopped = 1;
  3358. }
  3359. restore_hc:
  3360. phba->link_flag &= ~LS_IGNORE_ERATT;
  3361. writel(hc_copy, phba->HCregaddr);
  3362. readl(phba->HCregaddr); /* flush */
  3363. }
  3364. /**
  3365. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3366. * @phba: Pointer to HBA context object.
  3367. *
  3368. * This function issues a kill_board mailbox command and waits for
  3369. * the error attention interrupt. This function is called for stopping
  3370. * the firmware processing. The caller is not required to hold any
  3371. * locks. This function calls lpfc_hba_down_post function to free
  3372. * any pending commands after the kill. The function will return 1 when it
  3373. * fails to kill the board else will return 0.
  3374. **/
  3375. int
  3376. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3377. {
  3378. struct lpfc_sli *psli;
  3379. LPFC_MBOXQ_t *pmb;
  3380. uint32_t status;
  3381. uint32_t ha_copy;
  3382. int retval;
  3383. int i = 0;
  3384. psli = &phba->sli;
  3385. /* Kill HBA */
  3386. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3387. "0329 Kill HBA Data: x%x x%x\n",
  3388. phba->pport->port_state, psli->sli_flag);
  3389. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3390. if (!pmb)
  3391. return 1;
  3392. /* Disable the error attention */
  3393. spin_lock_irq(&phba->hbalock);
  3394. if (lpfc_readl(phba->HCregaddr, &status)) {
  3395. spin_unlock_irq(&phba->hbalock);
  3396. mempool_free(pmb, phba->mbox_mem_pool);
  3397. return 1;
  3398. }
  3399. status &= ~HC_ERINT_ENA;
  3400. writel(status, phba->HCregaddr);
  3401. readl(phba->HCregaddr); /* flush */
  3402. phba->link_flag |= LS_IGNORE_ERATT;
  3403. spin_unlock_irq(&phba->hbalock);
  3404. lpfc_kill_board(phba, pmb);
  3405. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3406. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3407. if (retval != MBX_SUCCESS) {
  3408. if (retval != MBX_BUSY)
  3409. mempool_free(pmb, phba->mbox_mem_pool);
  3410. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3411. "2752 KILL_BOARD command failed retval %d\n",
  3412. retval);
  3413. spin_lock_irq(&phba->hbalock);
  3414. phba->link_flag &= ~LS_IGNORE_ERATT;
  3415. spin_unlock_irq(&phba->hbalock);
  3416. return 1;
  3417. }
  3418. spin_lock_irq(&phba->hbalock);
  3419. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3420. spin_unlock_irq(&phba->hbalock);
  3421. mempool_free(pmb, phba->mbox_mem_pool);
  3422. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3423. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3424. * 3 seconds we still set HBA_ERROR state because the status of the
  3425. * board is now undefined.
  3426. */
  3427. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3428. return 1;
  3429. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3430. mdelay(100);
  3431. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3432. return 1;
  3433. }
  3434. del_timer_sync(&psli->mbox_tmo);
  3435. if (ha_copy & HA_ERATT) {
  3436. writel(HA_ERATT, phba->HAregaddr);
  3437. phba->pport->stopped = 1;
  3438. }
  3439. spin_lock_irq(&phba->hbalock);
  3440. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3441. psli->mbox_active = NULL;
  3442. phba->link_flag &= ~LS_IGNORE_ERATT;
  3443. spin_unlock_irq(&phba->hbalock);
  3444. lpfc_hba_down_post(phba);
  3445. phba->link_state = LPFC_HBA_ERROR;
  3446. return ha_copy & HA_ERATT ? 0 : 1;
  3447. }
  3448. /**
  3449. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3450. * @phba: Pointer to HBA context object.
  3451. *
  3452. * This function resets the HBA by writing HC_INITFF to the control
  3453. * register. After the HBA resets, this function resets all the iocb ring
  3454. * indices. This function disables PCI layer parity checking during
  3455. * the reset.
  3456. * This function returns 0 always.
  3457. * The caller is not required to hold any locks.
  3458. **/
  3459. int
  3460. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3461. {
  3462. struct lpfc_sli *psli;
  3463. struct lpfc_sli_ring *pring;
  3464. uint16_t cfg_value;
  3465. int i;
  3466. psli = &phba->sli;
  3467. /* Reset HBA */
  3468. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3469. "0325 Reset HBA Data: x%x x%x\n",
  3470. phba->pport->port_state, psli->sli_flag);
  3471. /* perform board reset */
  3472. phba->fc_eventTag = 0;
  3473. phba->link_events = 0;
  3474. phba->pport->fc_myDID = 0;
  3475. phba->pport->fc_prevDID = 0;
  3476. /* Turn off parity checking and serr during the physical reset */
  3477. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3478. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3479. (cfg_value &
  3480. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3481. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3482. /* Now toggle INITFF bit in the Host Control Register */
  3483. writel(HC_INITFF, phba->HCregaddr);
  3484. mdelay(1);
  3485. readl(phba->HCregaddr); /* flush */
  3486. writel(0, phba->HCregaddr);
  3487. readl(phba->HCregaddr); /* flush */
  3488. /* Restore PCI cmd register */
  3489. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3490. /* Initialize relevant SLI info */
  3491. for (i = 0; i < psli->num_rings; i++) {
  3492. pring = &psli->ring[i];
  3493. pring->flag = 0;
  3494. pring->rspidx = 0;
  3495. pring->next_cmdidx = 0;
  3496. pring->local_getidx = 0;
  3497. pring->cmdidx = 0;
  3498. pring->missbufcnt = 0;
  3499. }
  3500. phba->link_state = LPFC_WARM_START;
  3501. return 0;
  3502. }
  3503. /**
  3504. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3505. * @phba: Pointer to HBA context object.
  3506. *
  3507. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3508. * checking during resets the device. The caller is not required to hold
  3509. * any locks.
  3510. *
  3511. * This function returns 0 always.
  3512. **/
  3513. int
  3514. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3515. {
  3516. struct lpfc_sli *psli = &phba->sli;
  3517. uint16_t cfg_value;
  3518. uint8_t qindx;
  3519. /* Reset HBA */
  3520. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3521. "0295 Reset HBA Data: x%x x%x\n",
  3522. phba->pport->port_state, psli->sli_flag);
  3523. /* perform board reset */
  3524. phba->fc_eventTag = 0;
  3525. phba->link_events = 0;
  3526. phba->pport->fc_myDID = 0;
  3527. phba->pport->fc_prevDID = 0;
  3528. spin_lock_irq(&phba->hbalock);
  3529. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3530. phba->fcf.fcf_flag = 0;
  3531. /* Clean up the child queue list for the CQs */
  3532. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3533. list_del_init(&phba->sli4_hba.els_wq->list);
  3534. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3535. list_del_init(&phba->sli4_hba.dat_rq->list);
  3536. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3537. list_del_init(&phba->sli4_hba.els_cq->list);
  3538. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3539. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3540. qindx = 0;
  3541. do
  3542. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3543. while (++qindx < phba->cfg_fcp_eq_count);
  3544. spin_unlock_irq(&phba->hbalock);
  3545. /* Now physically reset the device */
  3546. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3547. "0389 Performing PCI function reset!\n");
  3548. /* Turn off parity checking and serr during the physical reset */
  3549. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3550. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3551. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3552. /* Perform FCoE PCI function reset */
  3553. lpfc_pci_function_reset(phba);
  3554. /* Restore PCI cmd register */
  3555. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3556. return 0;
  3557. }
  3558. /**
  3559. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3560. * @phba: Pointer to HBA context object.
  3561. *
  3562. * This function is called in the SLI initialization code path to
  3563. * restart the HBA. The caller is not required to hold any lock.
  3564. * This function writes MBX_RESTART mailbox command to the SLIM and
  3565. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3566. * function to free any pending commands. The function enables
  3567. * POST only during the first initialization. The function returns zero.
  3568. * The function does not guarantee completion of MBX_RESTART mailbox
  3569. * command before the return of this function.
  3570. **/
  3571. static int
  3572. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3573. {
  3574. MAILBOX_t *mb;
  3575. struct lpfc_sli *psli;
  3576. volatile uint32_t word0;
  3577. void __iomem *to_slim;
  3578. uint32_t hba_aer_enabled;
  3579. spin_lock_irq(&phba->hbalock);
  3580. /* Take PCIe device Advanced Error Reporting (AER) state */
  3581. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3582. psli = &phba->sli;
  3583. /* Restart HBA */
  3584. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3585. "0337 Restart HBA Data: x%x x%x\n",
  3586. phba->pport->port_state, psli->sli_flag);
  3587. word0 = 0;
  3588. mb = (MAILBOX_t *) &word0;
  3589. mb->mbxCommand = MBX_RESTART;
  3590. mb->mbxHc = 1;
  3591. lpfc_reset_barrier(phba);
  3592. to_slim = phba->MBslimaddr;
  3593. writel(*(uint32_t *) mb, to_slim);
  3594. readl(to_slim); /* flush */
  3595. /* Only skip post after fc_ffinit is completed */
  3596. if (phba->pport->port_state)
  3597. word0 = 1; /* This is really setting up word1 */
  3598. else
  3599. word0 = 0; /* This is really setting up word1 */
  3600. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3601. writel(*(uint32_t *) mb, to_slim);
  3602. readl(to_slim); /* flush */
  3603. lpfc_sli_brdreset(phba);
  3604. phba->pport->stopped = 0;
  3605. phba->link_state = LPFC_INIT_START;
  3606. phba->hba_flag = 0;
  3607. spin_unlock_irq(&phba->hbalock);
  3608. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3609. psli->stats_start = get_seconds();
  3610. /* Give the INITFF and Post time to settle. */
  3611. mdelay(100);
  3612. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3613. if (hba_aer_enabled)
  3614. pci_disable_pcie_error_reporting(phba->pcidev);
  3615. lpfc_hba_down_post(phba);
  3616. return 0;
  3617. }
  3618. /**
  3619. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3620. * @phba: Pointer to HBA context object.
  3621. *
  3622. * This function is called in the SLI initialization code path to restart
  3623. * a SLI4 HBA. The caller is not required to hold any lock.
  3624. * At the end of the function, it calls lpfc_hba_down_post function to
  3625. * free any pending commands.
  3626. **/
  3627. static int
  3628. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3629. {
  3630. struct lpfc_sli *psli = &phba->sli;
  3631. uint32_t hba_aer_enabled;
  3632. /* Restart HBA */
  3633. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3634. "0296 Restart HBA Data: x%x x%x\n",
  3635. phba->pport->port_state, psli->sli_flag);
  3636. /* Take PCIe device Advanced Error Reporting (AER) state */
  3637. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3638. lpfc_sli4_brdreset(phba);
  3639. spin_lock_irq(&phba->hbalock);
  3640. phba->pport->stopped = 0;
  3641. phba->link_state = LPFC_INIT_START;
  3642. phba->hba_flag = 0;
  3643. spin_unlock_irq(&phba->hbalock);
  3644. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3645. psli->stats_start = get_seconds();
  3646. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3647. if (hba_aer_enabled)
  3648. pci_disable_pcie_error_reporting(phba->pcidev);
  3649. lpfc_hba_down_post(phba);
  3650. return 0;
  3651. }
  3652. /**
  3653. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3654. * @phba: Pointer to HBA context object.
  3655. *
  3656. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3657. * API jump table function pointer from the lpfc_hba struct.
  3658. **/
  3659. int
  3660. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3661. {
  3662. return phba->lpfc_sli_brdrestart(phba);
  3663. }
  3664. /**
  3665. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3666. * @phba: Pointer to HBA context object.
  3667. *
  3668. * This function is called after a HBA restart to wait for successful
  3669. * restart of the HBA. Successful restart of the HBA is indicated by
  3670. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3671. * iteration, the function will restart the HBA again. The function returns
  3672. * zero if HBA successfully restarted else returns negative error code.
  3673. **/
  3674. static int
  3675. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3676. {
  3677. uint32_t status, i = 0;
  3678. /* Read the HBA Host Status Register */
  3679. if (lpfc_readl(phba->HSregaddr, &status))
  3680. return -EIO;
  3681. /* Check status register to see what current state is */
  3682. i = 0;
  3683. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3684. /* Check every 10ms for 10 retries, then every 100ms for 90
  3685. * retries, then every 1 sec for 50 retires for a total of
  3686. * ~60 seconds before reset the board again and check every
  3687. * 1 sec for 50 retries. The up to 60 seconds before the
  3688. * board ready is required by the Falcon FIPS zeroization
  3689. * complete, and any reset the board in between shall cause
  3690. * restart of zeroization, further delay the board ready.
  3691. */
  3692. if (i++ >= 200) {
  3693. /* Adapter failed to init, timeout, status reg
  3694. <status> */
  3695. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3696. "0436 Adapter failed to init, "
  3697. "timeout, status reg x%x, "
  3698. "FW Data: A8 x%x AC x%x\n", status,
  3699. readl(phba->MBslimaddr + 0xa8),
  3700. readl(phba->MBslimaddr + 0xac));
  3701. phba->link_state = LPFC_HBA_ERROR;
  3702. return -ETIMEDOUT;
  3703. }
  3704. /* Check to see if any errors occurred during init */
  3705. if (status & HS_FFERM) {
  3706. /* ERROR: During chipset initialization */
  3707. /* Adapter failed to init, chipset, status reg
  3708. <status> */
  3709. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3710. "0437 Adapter failed to init, "
  3711. "chipset, status reg x%x, "
  3712. "FW Data: A8 x%x AC x%x\n", status,
  3713. readl(phba->MBslimaddr + 0xa8),
  3714. readl(phba->MBslimaddr + 0xac));
  3715. phba->link_state = LPFC_HBA_ERROR;
  3716. return -EIO;
  3717. }
  3718. if (i <= 10)
  3719. msleep(10);
  3720. else if (i <= 100)
  3721. msleep(100);
  3722. else
  3723. msleep(1000);
  3724. if (i == 150) {
  3725. /* Do post */
  3726. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3727. lpfc_sli_brdrestart(phba);
  3728. }
  3729. /* Read the HBA Host Status Register */
  3730. if (lpfc_readl(phba->HSregaddr, &status))
  3731. return -EIO;
  3732. }
  3733. /* Check to see if any errors occurred during init */
  3734. if (status & HS_FFERM) {
  3735. /* ERROR: During chipset initialization */
  3736. /* Adapter failed to init, chipset, status reg <status> */
  3737. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3738. "0438 Adapter failed to init, chipset, "
  3739. "status reg x%x, "
  3740. "FW Data: A8 x%x AC x%x\n", status,
  3741. readl(phba->MBslimaddr + 0xa8),
  3742. readl(phba->MBslimaddr + 0xac));
  3743. phba->link_state = LPFC_HBA_ERROR;
  3744. return -EIO;
  3745. }
  3746. /* Clear all interrupt enable conditions */
  3747. writel(0, phba->HCregaddr);
  3748. readl(phba->HCregaddr); /* flush */
  3749. /* setup host attn register */
  3750. writel(0xffffffff, phba->HAregaddr);
  3751. readl(phba->HAregaddr); /* flush */
  3752. return 0;
  3753. }
  3754. /**
  3755. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3756. *
  3757. * This function calculates and returns the number of HBQs required to be
  3758. * configured.
  3759. **/
  3760. int
  3761. lpfc_sli_hbq_count(void)
  3762. {
  3763. return ARRAY_SIZE(lpfc_hbq_defs);
  3764. }
  3765. /**
  3766. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3767. *
  3768. * This function adds the number of hbq entries in every HBQ to get
  3769. * the total number of hbq entries required for the HBA and returns
  3770. * the total count.
  3771. **/
  3772. static int
  3773. lpfc_sli_hbq_entry_count(void)
  3774. {
  3775. int hbq_count = lpfc_sli_hbq_count();
  3776. int count = 0;
  3777. int i;
  3778. for (i = 0; i < hbq_count; ++i)
  3779. count += lpfc_hbq_defs[i]->entry_count;
  3780. return count;
  3781. }
  3782. /**
  3783. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3784. *
  3785. * This function calculates amount of memory required for all hbq entries
  3786. * to be configured and returns the total memory required.
  3787. **/
  3788. int
  3789. lpfc_sli_hbq_size(void)
  3790. {
  3791. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3792. }
  3793. /**
  3794. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3795. * @phba: Pointer to HBA context object.
  3796. *
  3797. * This function is called during the SLI initialization to configure
  3798. * all the HBQs and post buffers to the HBQ. The caller is not
  3799. * required to hold any locks. This function will return zero if successful
  3800. * else it will return negative error code.
  3801. **/
  3802. static int
  3803. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3804. {
  3805. int hbq_count = lpfc_sli_hbq_count();
  3806. LPFC_MBOXQ_t *pmb;
  3807. MAILBOX_t *pmbox;
  3808. uint32_t hbqno;
  3809. uint32_t hbq_entry_index;
  3810. /* Get a Mailbox buffer to setup mailbox
  3811. * commands for HBA initialization
  3812. */
  3813. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3814. if (!pmb)
  3815. return -ENOMEM;
  3816. pmbox = &pmb->u.mb;
  3817. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3818. phba->link_state = LPFC_INIT_MBX_CMDS;
  3819. phba->hbq_in_use = 1;
  3820. hbq_entry_index = 0;
  3821. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3822. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3823. phba->hbqs[hbqno].hbqPutIdx = 0;
  3824. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3825. phba->hbqs[hbqno].entry_count =
  3826. lpfc_hbq_defs[hbqno]->entry_count;
  3827. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3828. hbq_entry_index, pmb);
  3829. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3830. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3831. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3832. mbxStatus <status>, ring <num> */
  3833. lpfc_printf_log(phba, KERN_ERR,
  3834. LOG_SLI | LOG_VPORT,
  3835. "1805 Adapter failed to init. "
  3836. "Data: x%x x%x x%x\n",
  3837. pmbox->mbxCommand,
  3838. pmbox->mbxStatus, hbqno);
  3839. phba->link_state = LPFC_HBA_ERROR;
  3840. mempool_free(pmb, phba->mbox_mem_pool);
  3841. return -ENXIO;
  3842. }
  3843. }
  3844. phba->hbq_count = hbq_count;
  3845. mempool_free(pmb, phba->mbox_mem_pool);
  3846. /* Initially populate or replenish the HBQs */
  3847. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3848. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3849. return 0;
  3850. }
  3851. /**
  3852. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3853. * @phba: Pointer to HBA context object.
  3854. *
  3855. * This function is called during the SLI initialization to configure
  3856. * all the HBQs and post buffers to the HBQ. The caller is not
  3857. * required to hold any locks. This function will return zero if successful
  3858. * else it will return negative error code.
  3859. **/
  3860. static int
  3861. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3862. {
  3863. phba->hbq_in_use = 1;
  3864. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3865. phba->hbq_count = 1;
  3866. /* Initially populate or replenish the HBQs */
  3867. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3868. return 0;
  3869. }
  3870. /**
  3871. * lpfc_sli_config_port - Issue config port mailbox command
  3872. * @phba: Pointer to HBA context object.
  3873. * @sli_mode: sli mode - 2/3
  3874. *
  3875. * This function is called by the sli intialization code path
  3876. * to issue config_port mailbox command. This function restarts the
  3877. * HBA firmware and issues a config_port mailbox command to configure
  3878. * the SLI interface in the sli mode specified by sli_mode
  3879. * variable. The caller is not required to hold any locks.
  3880. * The function returns 0 if successful, else returns negative error
  3881. * code.
  3882. **/
  3883. int
  3884. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3885. {
  3886. LPFC_MBOXQ_t *pmb;
  3887. uint32_t resetcount = 0, rc = 0, done = 0;
  3888. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3889. if (!pmb) {
  3890. phba->link_state = LPFC_HBA_ERROR;
  3891. return -ENOMEM;
  3892. }
  3893. phba->sli_rev = sli_mode;
  3894. while (resetcount < 2 && !done) {
  3895. spin_lock_irq(&phba->hbalock);
  3896. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3897. spin_unlock_irq(&phba->hbalock);
  3898. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3899. lpfc_sli_brdrestart(phba);
  3900. rc = lpfc_sli_chipset_init(phba);
  3901. if (rc)
  3902. break;
  3903. spin_lock_irq(&phba->hbalock);
  3904. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3905. spin_unlock_irq(&phba->hbalock);
  3906. resetcount++;
  3907. /* Call pre CONFIG_PORT mailbox command initialization. A
  3908. * value of 0 means the call was successful. Any other
  3909. * nonzero value is a failure, but if ERESTART is returned,
  3910. * the driver may reset the HBA and try again.
  3911. */
  3912. rc = lpfc_config_port_prep(phba);
  3913. if (rc == -ERESTART) {
  3914. phba->link_state = LPFC_LINK_UNKNOWN;
  3915. continue;
  3916. } else if (rc)
  3917. break;
  3918. phba->link_state = LPFC_INIT_MBX_CMDS;
  3919. lpfc_config_port(phba, pmb);
  3920. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3921. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3922. LPFC_SLI3_HBQ_ENABLED |
  3923. LPFC_SLI3_CRP_ENABLED |
  3924. LPFC_SLI3_BG_ENABLED |
  3925. LPFC_SLI3_DSS_ENABLED);
  3926. if (rc != MBX_SUCCESS) {
  3927. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3928. "0442 Adapter failed to init, mbxCmd x%x "
  3929. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3930. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3931. spin_lock_irq(&phba->hbalock);
  3932. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3933. spin_unlock_irq(&phba->hbalock);
  3934. rc = -ENXIO;
  3935. } else {
  3936. /* Allow asynchronous mailbox command to go through */
  3937. spin_lock_irq(&phba->hbalock);
  3938. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3939. spin_unlock_irq(&phba->hbalock);
  3940. done = 1;
  3941. }
  3942. }
  3943. if (!done) {
  3944. rc = -EINVAL;
  3945. goto do_prep_failed;
  3946. }
  3947. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3948. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3949. rc = -ENXIO;
  3950. goto do_prep_failed;
  3951. }
  3952. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3953. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3954. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3955. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3956. phba->max_vpi : phba->max_vports;
  3957. } else
  3958. phba->max_vpi = 0;
  3959. phba->fips_level = 0;
  3960. phba->fips_spec_rev = 0;
  3961. if (pmb->u.mb.un.varCfgPort.gdss) {
  3962. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3963. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3964. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3965. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3966. "2850 Security Crypto Active. FIPS x%d "
  3967. "(Spec Rev: x%d)",
  3968. phba->fips_level, phba->fips_spec_rev);
  3969. }
  3970. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3971. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3972. "2856 Config Port Security Crypto "
  3973. "Error: x%x ",
  3974. pmb->u.mb.un.varCfgPort.sec_err);
  3975. }
  3976. if (pmb->u.mb.un.varCfgPort.gerbm)
  3977. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3978. if (pmb->u.mb.un.varCfgPort.gcrp)
  3979. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3980. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3981. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3982. if (phba->cfg_enable_bg) {
  3983. if (pmb->u.mb.un.varCfgPort.gbg)
  3984. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3985. else
  3986. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3987. "0443 Adapter did not grant "
  3988. "BlockGuard\n");
  3989. }
  3990. } else {
  3991. phba->hbq_get = NULL;
  3992. phba->port_gp = phba->mbox->us.s2.port;
  3993. phba->max_vpi = 0;
  3994. }
  3995. do_prep_failed:
  3996. mempool_free(pmb, phba->mbox_mem_pool);
  3997. return rc;
  3998. }
  3999. /**
  4000. * lpfc_sli_hba_setup - SLI intialization function
  4001. * @phba: Pointer to HBA context object.
  4002. *
  4003. * This function is the main SLI intialization function. This function
  4004. * is called by the HBA intialization code, HBA reset code and HBA
  4005. * error attention handler code. Caller is not required to hold any
  4006. * locks. This function issues config_port mailbox command to configure
  4007. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4008. * calls the config_port_post function to issue init_link mailbox
  4009. * command and to start the discovery. The function will return zero
  4010. * if successful, else it will return negative error code.
  4011. **/
  4012. int
  4013. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4014. {
  4015. uint32_t rc;
  4016. int mode = 3;
  4017. switch (lpfc_sli_mode) {
  4018. case 2:
  4019. if (phba->cfg_enable_npiv) {
  4020. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4021. "1824 NPIV enabled: Override lpfc_sli_mode "
  4022. "parameter (%d) to auto (0).\n",
  4023. lpfc_sli_mode);
  4024. break;
  4025. }
  4026. mode = 2;
  4027. break;
  4028. case 0:
  4029. case 3:
  4030. break;
  4031. default:
  4032. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4033. "1819 Unrecognized lpfc_sli_mode "
  4034. "parameter: %d.\n", lpfc_sli_mode);
  4035. break;
  4036. }
  4037. rc = lpfc_sli_config_port(phba, mode);
  4038. if (rc && lpfc_sli_mode == 3)
  4039. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4040. "1820 Unable to select SLI-3. "
  4041. "Not supported by adapter.\n");
  4042. if (rc && mode != 2)
  4043. rc = lpfc_sli_config_port(phba, 2);
  4044. if (rc)
  4045. goto lpfc_sli_hba_setup_error;
  4046. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4047. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4048. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4049. if (!rc) {
  4050. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4051. "2709 This device supports "
  4052. "Advanced Error Reporting (AER)\n");
  4053. spin_lock_irq(&phba->hbalock);
  4054. phba->hba_flag |= HBA_AER_ENABLED;
  4055. spin_unlock_irq(&phba->hbalock);
  4056. } else {
  4057. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4058. "2708 This device does not support "
  4059. "Advanced Error Reporting (AER)\n");
  4060. phba->cfg_aer_support = 0;
  4061. }
  4062. }
  4063. if (phba->sli_rev == 3) {
  4064. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4065. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4066. } else {
  4067. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4068. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4069. phba->sli3_options = 0;
  4070. }
  4071. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4072. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4073. phba->sli_rev, phba->max_vpi);
  4074. rc = lpfc_sli_ring_map(phba);
  4075. if (rc)
  4076. goto lpfc_sli_hba_setup_error;
  4077. /* Init HBQs */
  4078. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4079. rc = lpfc_sli_hbq_setup(phba);
  4080. if (rc)
  4081. goto lpfc_sli_hba_setup_error;
  4082. }
  4083. spin_lock_irq(&phba->hbalock);
  4084. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4085. spin_unlock_irq(&phba->hbalock);
  4086. rc = lpfc_config_port_post(phba);
  4087. if (rc)
  4088. goto lpfc_sli_hba_setup_error;
  4089. return rc;
  4090. lpfc_sli_hba_setup_error:
  4091. phba->link_state = LPFC_HBA_ERROR;
  4092. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4093. "0445 Firmware initialization failed\n");
  4094. return rc;
  4095. }
  4096. /**
  4097. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4098. * @phba: Pointer to HBA context object.
  4099. * @mboxq: mailbox pointer.
  4100. * This function issue a dump mailbox command to read config region
  4101. * 23 and parse the records in the region and populate driver
  4102. * data structure.
  4103. **/
  4104. static int
  4105. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4106. LPFC_MBOXQ_t *mboxq)
  4107. {
  4108. struct lpfc_dmabuf *mp;
  4109. struct lpfc_mqe *mqe;
  4110. uint32_t data_length;
  4111. int rc;
  4112. /* Program the default value of vlan_id and fc_map */
  4113. phba->valid_vlan = 0;
  4114. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4115. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4116. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4117. mqe = &mboxq->u.mqe;
  4118. if (lpfc_dump_fcoe_param(phba, mboxq))
  4119. return -ENOMEM;
  4120. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4121. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4122. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4123. "(%d):2571 Mailbox cmd x%x Status x%x "
  4124. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4125. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4126. "CQ: x%x x%x x%x x%x\n",
  4127. mboxq->vport ? mboxq->vport->vpi : 0,
  4128. bf_get(lpfc_mqe_command, mqe),
  4129. bf_get(lpfc_mqe_status, mqe),
  4130. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4131. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4132. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4133. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4134. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4135. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4136. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4137. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4138. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4139. mboxq->mcqe.word0,
  4140. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4141. mboxq->mcqe.trailer);
  4142. if (rc) {
  4143. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4144. kfree(mp);
  4145. return -EIO;
  4146. }
  4147. data_length = mqe->un.mb_words[5];
  4148. if (data_length > DMP_RGN23_SIZE) {
  4149. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4150. kfree(mp);
  4151. return -EIO;
  4152. }
  4153. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4154. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4155. kfree(mp);
  4156. return 0;
  4157. }
  4158. /**
  4159. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4160. * @phba: pointer to lpfc hba data structure.
  4161. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4162. * @vpd: pointer to the memory to hold resulting port vpd data.
  4163. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4164. * On output, the number of data bytes in @vpd.
  4165. *
  4166. * This routine executes a READ_REV SLI4 mailbox command. In
  4167. * addition, this routine gets the port vpd data.
  4168. *
  4169. * Return codes
  4170. * 0 - successful
  4171. * -ENOMEM - could not allocated memory.
  4172. **/
  4173. static int
  4174. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4175. uint8_t *vpd, uint32_t *vpd_size)
  4176. {
  4177. int rc = 0;
  4178. uint32_t dma_size;
  4179. struct lpfc_dmabuf *dmabuf;
  4180. struct lpfc_mqe *mqe;
  4181. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4182. if (!dmabuf)
  4183. return -ENOMEM;
  4184. /*
  4185. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4186. * mailbox command.
  4187. */
  4188. dma_size = *vpd_size;
  4189. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4190. dma_size,
  4191. &dmabuf->phys,
  4192. GFP_KERNEL);
  4193. if (!dmabuf->virt) {
  4194. kfree(dmabuf);
  4195. return -ENOMEM;
  4196. }
  4197. memset(dmabuf->virt, 0, dma_size);
  4198. /*
  4199. * The SLI4 implementation of READ_REV conflicts at word1,
  4200. * bits 31:16 and SLI4 adds vpd functionality not present
  4201. * in SLI3. This code corrects the conflicts.
  4202. */
  4203. lpfc_read_rev(phba, mboxq);
  4204. mqe = &mboxq->u.mqe;
  4205. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4206. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4207. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4208. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4209. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4210. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4211. if (rc) {
  4212. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4213. dmabuf->virt, dmabuf->phys);
  4214. kfree(dmabuf);
  4215. return -EIO;
  4216. }
  4217. /*
  4218. * The available vpd length cannot be bigger than the
  4219. * DMA buffer passed to the port. Catch the less than
  4220. * case and update the caller's size.
  4221. */
  4222. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4223. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4224. memcpy(vpd, dmabuf->virt, *vpd_size);
  4225. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4226. dmabuf->virt, dmabuf->phys);
  4227. kfree(dmabuf);
  4228. return 0;
  4229. }
  4230. /**
  4231. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4232. * @phba: pointer to lpfc hba data structure.
  4233. *
  4234. * This routine is called to explicitly arm the SLI4 device's completion and
  4235. * event queues
  4236. **/
  4237. static void
  4238. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4239. {
  4240. uint8_t fcp_eqidx;
  4241. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4242. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4243. fcp_eqidx = 0;
  4244. do
  4245. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4246. LPFC_QUEUE_REARM);
  4247. while (++fcp_eqidx < phba->cfg_fcp_eq_count);
  4248. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4249. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4250. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4251. LPFC_QUEUE_REARM);
  4252. }
  4253. /**
  4254. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4255. * @phba: Pointer to HBA context object.
  4256. *
  4257. * This function is the main SLI4 device intialization PCI function. This
  4258. * function is called by the HBA intialization code, HBA reset code and
  4259. * HBA error attention handler code. Caller is not required to hold any
  4260. * locks.
  4261. **/
  4262. int
  4263. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4264. {
  4265. int rc;
  4266. LPFC_MBOXQ_t *mboxq;
  4267. struct lpfc_mqe *mqe;
  4268. uint8_t *vpd;
  4269. uint32_t vpd_size;
  4270. uint32_t ftr_rsp = 0;
  4271. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4272. struct lpfc_vport *vport = phba->pport;
  4273. struct lpfc_dmabuf *mp;
  4274. /*
  4275. * TODO: Why does this routine execute these task in a different
  4276. * order from probe?
  4277. */
  4278. /* Perform a PCI function reset to start from clean */
  4279. rc = lpfc_pci_function_reset(phba);
  4280. if (unlikely(rc))
  4281. return -ENODEV;
  4282. /* Check the HBA Host Status Register for readyness */
  4283. rc = lpfc_sli4_post_status_check(phba);
  4284. if (unlikely(rc))
  4285. return -ENODEV;
  4286. else {
  4287. spin_lock_irq(&phba->hbalock);
  4288. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4289. spin_unlock_irq(&phba->hbalock);
  4290. }
  4291. /*
  4292. * Allocate a single mailbox container for initializing the
  4293. * port.
  4294. */
  4295. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4296. if (!mboxq)
  4297. return -ENOMEM;
  4298. /*
  4299. * Continue initialization with default values even if driver failed
  4300. * to read FCoE param config regions
  4301. */
  4302. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4303. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  4304. "2570 Failed to read FCoE parameters\n");
  4305. /* Issue READ_REV to collect vpd and FW information. */
  4306. vpd_size = SLI4_PAGE_SIZE;
  4307. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4308. if (!vpd) {
  4309. rc = -ENOMEM;
  4310. goto out_free_mbox;
  4311. }
  4312. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4313. if (unlikely(rc)) {
  4314. kfree(vpd);
  4315. goto out_free_mbox;
  4316. }
  4317. mqe = &mboxq->u.mqe;
  4318. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4319. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4320. phba->hba_flag |= HBA_FCOE_MODE;
  4321. else
  4322. phba->hba_flag &= ~HBA_FCOE_MODE;
  4323. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4324. LPFC_DCBX_CEE_MODE)
  4325. phba->hba_flag |= HBA_FIP_SUPPORT;
  4326. else
  4327. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4328. if (phba->sli_rev != LPFC_SLI_REV4) {
  4329. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4330. "0376 READ_REV Error. SLI Level %d "
  4331. "FCoE enabled %d\n",
  4332. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4333. rc = -EIO;
  4334. kfree(vpd);
  4335. goto out_free_mbox;
  4336. }
  4337. /*
  4338. * Evaluate the read rev and vpd data. Populate the driver
  4339. * state with the results. If this routine fails, the failure
  4340. * is not fatal as the driver will use generic values.
  4341. */
  4342. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4343. if (unlikely(!rc)) {
  4344. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4345. "0377 Error %d parsing vpd. "
  4346. "Using defaults.\n", rc);
  4347. rc = 0;
  4348. }
  4349. kfree(vpd);
  4350. /* Save information as VPD data */
  4351. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4352. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4353. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4354. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4355. &mqe->un.read_rev);
  4356. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4357. &mqe->un.read_rev);
  4358. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4359. &mqe->un.read_rev);
  4360. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4361. &mqe->un.read_rev);
  4362. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4363. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4364. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4365. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4366. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4367. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4368. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4369. "(%d):0380 READ_REV Status x%x "
  4370. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4371. mboxq->vport ? mboxq->vport->vpi : 0,
  4372. bf_get(lpfc_mqe_status, mqe),
  4373. phba->vpd.rev.opFwName,
  4374. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4375. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4376. /*
  4377. * Discover the port's supported feature set and match it against the
  4378. * hosts requests.
  4379. */
  4380. lpfc_request_features(phba, mboxq);
  4381. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4382. if (unlikely(rc)) {
  4383. rc = -EIO;
  4384. goto out_free_mbox;
  4385. }
  4386. /*
  4387. * The port must support FCP initiator mode as this is the
  4388. * only mode running in the host.
  4389. */
  4390. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4391. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4392. "0378 No support for fcpi mode.\n");
  4393. ftr_rsp++;
  4394. }
  4395. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  4396. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  4397. else
  4398. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  4399. /*
  4400. * If the port cannot support the host's requested features
  4401. * then turn off the global config parameters to disable the
  4402. * feature in the driver. This is not a fatal error.
  4403. */
  4404. if ((phba->cfg_enable_bg) &&
  4405. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4406. ftr_rsp++;
  4407. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4408. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4409. ftr_rsp++;
  4410. if (ftr_rsp) {
  4411. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4412. "0379 Feature Mismatch Data: x%08x %08x "
  4413. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4414. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4415. phba->cfg_enable_npiv, phba->max_vpi);
  4416. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4417. phba->cfg_enable_bg = 0;
  4418. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4419. phba->cfg_enable_npiv = 0;
  4420. }
  4421. /* These SLI3 features are assumed in SLI4 */
  4422. spin_lock_irq(&phba->hbalock);
  4423. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4424. spin_unlock_irq(&phba->hbalock);
  4425. /* Read the port's service parameters. */
  4426. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4427. if (rc) {
  4428. phba->link_state = LPFC_HBA_ERROR;
  4429. rc = -ENOMEM;
  4430. goto out_free_mbox;
  4431. }
  4432. mboxq->vport = vport;
  4433. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4434. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4435. if (rc == MBX_SUCCESS) {
  4436. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4437. rc = 0;
  4438. }
  4439. /*
  4440. * This memory was allocated by the lpfc_read_sparam routine. Release
  4441. * it to the mbuf pool.
  4442. */
  4443. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4444. kfree(mp);
  4445. mboxq->context1 = NULL;
  4446. if (unlikely(rc)) {
  4447. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4448. "0382 READ_SPARAM command failed "
  4449. "status %d, mbxStatus x%x\n",
  4450. rc, bf_get(lpfc_mqe_status, mqe));
  4451. phba->link_state = LPFC_HBA_ERROR;
  4452. rc = -EIO;
  4453. goto out_free_mbox;
  4454. }
  4455. lpfc_update_vport_wwn(vport);
  4456. /* Update the fc_host data structures with new wwn. */
  4457. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4458. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4459. /* Register SGL pool to the device using non-embedded mailbox command */
  4460. rc = lpfc_sli4_post_sgl_list(phba);
  4461. if (unlikely(rc)) {
  4462. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4463. "0582 Error %d during sgl post operation\n",
  4464. rc);
  4465. rc = -ENODEV;
  4466. goto out_free_mbox;
  4467. }
  4468. /* Register SCSI SGL pool to the device */
  4469. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4470. if (unlikely(rc)) {
  4471. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4472. "0383 Error %d during scsi sgl post "
  4473. "operation\n", rc);
  4474. /* Some Scsi buffers were moved to the abort scsi list */
  4475. /* A pci function reset will repost them */
  4476. rc = -ENODEV;
  4477. goto out_free_mbox;
  4478. }
  4479. /* Post the rpi header region to the device. */
  4480. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4481. if (unlikely(rc)) {
  4482. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4483. "0393 Error %d during rpi post operation\n",
  4484. rc);
  4485. rc = -ENODEV;
  4486. goto out_free_mbox;
  4487. }
  4488. /* Set up all the queues to the device */
  4489. rc = lpfc_sli4_queue_setup(phba);
  4490. if (unlikely(rc)) {
  4491. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4492. "0381 Error %d during queue setup.\n ", rc);
  4493. goto out_stop_timers;
  4494. }
  4495. /* Arm the CQs and then EQs on device */
  4496. lpfc_sli4_arm_cqeq_intr(phba);
  4497. /* Indicate device interrupt mode */
  4498. phba->sli4_hba.intr_enable = 1;
  4499. /* Allow asynchronous mailbox command to go through */
  4500. spin_lock_irq(&phba->hbalock);
  4501. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4502. spin_unlock_irq(&phba->hbalock);
  4503. /* Post receive buffers to the device */
  4504. lpfc_sli4_rb_setup(phba);
  4505. /* Reset HBA FCF states after HBA reset */
  4506. phba->fcf.fcf_flag = 0;
  4507. phba->fcf.current_rec.flag = 0;
  4508. /* Start the ELS watchdog timer */
  4509. mod_timer(&vport->els_tmofunc,
  4510. jiffies + HZ * (phba->fc_ratov * 2));
  4511. /* Start heart beat timer */
  4512. mod_timer(&phba->hb_tmofunc,
  4513. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4514. phba->hb_outstanding = 0;
  4515. phba->last_completion_time = jiffies;
  4516. /* Start error attention (ERATT) polling timer */
  4517. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4518. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4519. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4520. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4521. if (!rc) {
  4522. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4523. "2829 This device supports "
  4524. "Advanced Error Reporting (AER)\n");
  4525. spin_lock_irq(&phba->hbalock);
  4526. phba->hba_flag |= HBA_AER_ENABLED;
  4527. spin_unlock_irq(&phba->hbalock);
  4528. } else {
  4529. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4530. "2830 This device does not support "
  4531. "Advanced Error Reporting (AER)\n");
  4532. phba->cfg_aer_support = 0;
  4533. }
  4534. }
  4535. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4536. /*
  4537. * The FC Port needs to register FCFI (index 0)
  4538. */
  4539. lpfc_reg_fcfi(phba, mboxq);
  4540. mboxq->vport = phba->pport;
  4541. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4542. if (rc != MBX_SUCCESS)
  4543. goto out_unset_queue;
  4544. rc = 0;
  4545. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  4546. &mboxq->u.mqe.un.reg_fcfi);
  4547. }
  4548. /*
  4549. * The port is ready, set the host's link state to LINK_DOWN
  4550. * in preparation for link interrupts.
  4551. */
  4552. spin_lock_irq(&phba->hbalock);
  4553. phba->link_state = LPFC_LINK_DOWN;
  4554. spin_unlock_irq(&phba->hbalock);
  4555. if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
  4556. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4557. out_unset_queue:
  4558. /* Unset all the queues set up in this routine when error out */
  4559. if (rc)
  4560. lpfc_sli4_queue_unset(phba);
  4561. out_stop_timers:
  4562. if (rc)
  4563. lpfc_stop_hba_timers(phba);
  4564. out_free_mbox:
  4565. mempool_free(mboxq, phba->mbox_mem_pool);
  4566. return rc;
  4567. }
  4568. /**
  4569. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4570. * @ptr: context object - pointer to hba structure.
  4571. *
  4572. * This is the callback function for mailbox timer. The mailbox
  4573. * timer is armed when a new mailbox command is issued and the timer
  4574. * is deleted when the mailbox complete. The function is called by
  4575. * the kernel timer code when a mailbox does not complete within
  4576. * expected time. This function wakes up the worker thread to
  4577. * process the mailbox timeout and returns. All the processing is
  4578. * done by the worker thread function lpfc_mbox_timeout_handler.
  4579. **/
  4580. void
  4581. lpfc_mbox_timeout(unsigned long ptr)
  4582. {
  4583. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4584. unsigned long iflag;
  4585. uint32_t tmo_posted;
  4586. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4587. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4588. if (!tmo_posted)
  4589. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4590. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4591. if (!tmo_posted)
  4592. lpfc_worker_wake_up(phba);
  4593. return;
  4594. }
  4595. /**
  4596. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4597. * @phba: Pointer to HBA context object.
  4598. *
  4599. * This function is called from worker thread when a mailbox command times out.
  4600. * The caller is not required to hold any locks. This function will reset the
  4601. * HBA and recover all the pending commands.
  4602. **/
  4603. void
  4604. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4605. {
  4606. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4607. MAILBOX_t *mb = &pmbox->u.mb;
  4608. struct lpfc_sli *psli = &phba->sli;
  4609. struct lpfc_sli_ring *pring;
  4610. /* Check the pmbox pointer first. There is a race condition
  4611. * between the mbox timeout handler getting executed in the
  4612. * worklist and the mailbox actually completing. When this
  4613. * race condition occurs, the mbox_active will be NULL.
  4614. */
  4615. spin_lock_irq(&phba->hbalock);
  4616. if (pmbox == NULL) {
  4617. lpfc_printf_log(phba, KERN_WARNING,
  4618. LOG_MBOX | LOG_SLI,
  4619. "0353 Active Mailbox cleared - mailbox timeout "
  4620. "exiting\n");
  4621. spin_unlock_irq(&phba->hbalock);
  4622. return;
  4623. }
  4624. /* Mbox cmd <mbxCommand> timeout */
  4625. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4626. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4627. mb->mbxCommand,
  4628. phba->pport->port_state,
  4629. phba->sli.sli_flag,
  4630. phba->sli.mbox_active);
  4631. spin_unlock_irq(&phba->hbalock);
  4632. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4633. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4634. * it to fail all outstanding SCSI IO.
  4635. */
  4636. spin_lock_irq(&phba->pport->work_port_lock);
  4637. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4638. spin_unlock_irq(&phba->pport->work_port_lock);
  4639. spin_lock_irq(&phba->hbalock);
  4640. phba->link_state = LPFC_LINK_UNKNOWN;
  4641. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4642. spin_unlock_irq(&phba->hbalock);
  4643. pring = &psli->ring[psli->fcp_ring];
  4644. lpfc_sli_abort_iocb_ring(phba, pring);
  4645. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4646. "0345 Resetting board due to mailbox timeout\n");
  4647. /* Reset the HBA device */
  4648. lpfc_reset_hba(phba);
  4649. }
  4650. /**
  4651. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4652. * @phba: Pointer to HBA context object.
  4653. * @pmbox: Pointer to mailbox object.
  4654. * @flag: Flag indicating how the mailbox need to be processed.
  4655. *
  4656. * This function is called by discovery code and HBA management code
  4657. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4658. * function gets the hbalock to protect the data structures.
  4659. * The mailbox command can be submitted in polling mode, in which case
  4660. * this function will wait in a polling loop for the completion of the
  4661. * mailbox.
  4662. * If the mailbox is submitted in no_wait mode (not polling) the
  4663. * function will submit the command and returns immediately without waiting
  4664. * for the mailbox completion. The no_wait is supported only when HBA
  4665. * is in SLI2/SLI3 mode - interrupts are enabled.
  4666. * The SLI interface allows only one mailbox pending at a time. If the
  4667. * mailbox is issued in polling mode and there is already a mailbox
  4668. * pending, then the function will return an error. If the mailbox is issued
  4669. * in NO_WAIT mode and there is a mailbox pending already, the function
  4670. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4671. * The sli layer owns the mailbox object until the completion of mailbox
  4672. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4673. * return codes the caller owns the mailbox command after the return of
  4674. * the function.
  4675. **/
  4676. static int
  4677. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4678. uint32_t flag)
  4679. {
  4680. MAILBOX_t *mb;
  4681. struct lpfc_sli *psli = &phba->sli;
  4682. uint32_t status, evtctr;
  4683. uint32_t ha_copy, hc_copy;
  4684. int i;
  4685. unsigned long timeout;
  4686. unsigned long drvr_flag = 0;
  4687. uint32_t word0, ldata;
  4688. void __iomem *to_slim;
  4689. int processing_queue = 0;
  4690. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4691. if (!pmbox) {
  4692. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4693. /* processing mbox queue from intr_handler */
  4694. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4695. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4696. return MBX_SUCCESS;
  4697. }
  4698. processing_queue = 1;
  4699. pmbox = lpfc_mbox_get(phba);
  4700. if (!pmbox) {
  4701. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4702. return MBX_SUCCESS;
  4703. }
  4704. }
  4705. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4706. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4707. if(!pmbox->vport) {
  4708. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4709. lpfc_printf_log(phba, KERN_ERR,
  4710. LOG_MBOX | LOG_VPORT,
  4711. "1806 Mbox x%x failed. No vport\n",
  4712. pmbox->u.mb.mbxCommand);
  4713. dump_stack();
  4714. goto out_not_finished;
  4715. }
  4716. }
  4717. /* If the PCI channel is in offline state, do not post mbox. */
  4718. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4719. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4720. goto out_not_finished;
  4721. }
  4722. /* If HBA has a deferred error attention, fail the iocb. */
  4723. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4724. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4725. goto out_not_finished;
  4726. }
  4727. psli = &phba->sli;
  4728. mb = &pmbox->u.mb;
  4729. status = MBX_SUCCESS;
  4730. if (phba->link_state == LPFC_HBA_ERROR) {
  4731. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4732. /* Mbox command <mbxCommand> cannot issue */
  4733. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4734. "(%d):0311 Mailbox command x%x cannot "
  4735. "issue Data: x%x x%x\n",
  4736. pmbox->vport ? pmbox->vport->vpi : 0,
  4737. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4738. goto out_not_finished;
  4739. }
  4740. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  4741. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  4742. !(hc_copy & HC_MBINT_ENA)) {
  4743. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4744. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4745. "(%d):2528 Mailbox command x%x cannot "
  4746. "issue Data: x%x x%x\n",
  4747. pmbox->vport ? pmbox->vport->vpi : 0,
  4748. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4749. goto out_not_finished;
  4750. }
  4751. }
  4752. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4753. /* Polling for a mbox command when another one is already active
  4754. * is not allowed in SLI. Also, the driver must have established
  4755. * SLI2 mode to queue and process multiple mbox commands.
  4756. */
  4757. if (flag & MBX_POLL) {
  4758. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4759. /* Mbox command <mbxCommand> cannot issue */
  4760. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4761. "(%d):2529 Mailbox command x%x "
  4762. "cannot issue Data: x%x x%x\n",
  4763. pmbox->vport ? pmbox->vport->vpi : 0,
  4764. pmbox->u.mb.mbxCommand,
  4765. psli->sli_flag, flag);
  4766. goto out_not_finished;
  4767. }
  4768. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4769. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4770. /* Mbox command <mbxCommand> cannot issue */
  4771. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4772. "(%d):2530 Mailbox command x%x "
  4773. "cannot issue Data: x%x x%x\n",
  4774. pmbox->vport ? pmbox->vport->vpi : 0,
  4775. pmbox->u.mb.mbxCommand,
  4776. psli->sli_flag, flag);
  4777. goto out_not_finished;
  4778. }
  4779. /* Another mailbox command is still being processed, queue this
  4780. * command to be processed later.
  4781. */
  4782. lpfc_mbox_put(phba, pmbox);
  4783. /* Mbox cmd issue - BUSY */
  4784. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4785. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4786. "x%x x%x x%x x%x\n",
  4787. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4788. mb->mbxCommand, phba->pport->port_state,
  4789. psli->sli_flag, flag);
  4790. psli->slistat.mbox_busy++;
  4791. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4792. if (pmbox->vport) {
  4793. lpfc_debugfs_disc_trc(pmbox->vport,
  4794. LPFC_DISC_TRC_MBOX_VPORT,
  4795. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4796. (uint32_t)mb->mbxCommand,
  4797. mb->un.varWords[0], mb->un.varWords[1]);
  4798. }
  4799. else {
  4800. lpfc_debugfs_disc_trc(phba->pport,
  4801. LPFC_DISC_TRC_MBOX,
  4802. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4803. (uint32_t)mb->mbxCommand,
  4804. mb->un.varWords[0], mb->un.varWords[1]);
  4805. }
  4806. return MBX_BUSY;
  4807. }
  4808. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4809. /* If we are not polling, we MUST be in SLI2 mode */
  4810. if (flag != MBX_POLL) {
  4811. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4812. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4813. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4814. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4815. /* Mbox command <mbxCommand> cannot issue */
  4816. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4817. "(%d):2531 Mailbox command x%x "
  4818. "cannot issue Data: x%x x%x\n",
  4819. pmbox->vport ? pmbox->vport->vpi : 0,
  4820. pmbox->u.mb.mbxCommand,
  4821. psli->sli_flag, flag);
  4822. goto out_not_finished;
  4823. }
  4824. /* timeout active mbox command */
  4825. mod_timer(&psli->mbox_tmo, (jiffies +
  4826. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4827. }
  4828. /* Mailbox cmd <cmd> issue */
  4829. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4830. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4831. "x%x\n",
  4832. pmbox->vport ? pmbox->vport->vpi : 0,
  4833. mb->mbxCommand, phba->pport->port_state,
  4834. psli->sli_flag, flag);
  4835. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4836. if (pmbox->vport) {
  4837. lpfc_debugfs_disc_trc(pmbox->vport,
  4838. LPFC_DISC_TRC_MBOX_VPORT,
  4839. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4840. (uint32_t)mb->mbxCommand,
  4841. mb->un.varWords[0], mb->un.varWords[1]);
  4842. }
  4843. else {
  4844. lpfc_debugfs_disc_trc(phba->pport,
  4845. LPFC_DISC_TRC_MBOX,
  4846. "MBOX Send: cmd:x%x mb:x%x x%x",
  4847. (uint32_t)mb->mbxCommand,
  4848. mb->un.varWords[0], mb->un.varWords[1]);
  4849. }
  4850. }
  4851. psli->slistat.mbox_cmd++;
  4852. evtctr = psli->slistat.mbox_event;
  4853. /* next set own bit for the adapter and copy over command word */
  4854. mb->mbxOwner = OWN_CHIP;
  4855. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4856. /* Populate mbox extension offset word. */
  4857. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4858. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4859. = (uint8_t *)phba->mbox_ext
  4860. - (uint8_t *)phba->mbox;
  4861. }
  4862. /* Copy the mailbox extension data */
  4863. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4864. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4865. (uint8_t *)phba->mbox_ext,
  4866. pmbox->in_ext_byte_len);
  4867. }
  4868. /* Copy command data to host SLIM area */
  4869. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4870. } else {
  4871. /* Populate mbox extension offset word. */
  4872. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4873. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4874. = MAILBOX_HBA_EXT_OFFSET;
  4875. /* Copy the mailbox extension data */
  4876. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4877. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4878. MAILBOX_HBA_EXT_OFFSET,
  4879. pmbox->context2, pmbox->in_ext_byte_len);
  4880. }
  4881. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4882. /* copy command data into host mbox for cmpl */
  4883. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4884. }
  4885. /* First copy mbox command data to HBA SLIM, skip past first
  4886. word */
  4887. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4888. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4889. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4890. /* Next copy over first word, with mbxOwner set */
  4891. ldata = *((uint32_t *)mb);
  4892. to_slim = phba->MBslimaddr;
  4893. writel(ldata, to_slim);
  4894. readl(to_slim); /* flush */
  4895. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4896. /* switch over to host mailbox */
  4897. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4898. }
  4899. }
  4900. wmb();
  4901. switch (flag) {
  4902. case MBX_NOWAIT:
  4903. /* Set up reference to mailbox command */
  4904. psli->mbox_active = pmbox;
  4905. /* Interrupt board to do it */
  4906. writel(CA_MBATT, phba->CAregaddr);
  4907. readl(phba->CAregaddr); /* flush */
  4908. /* Don't wait for it to finish, just return */
  4909. break;
  4910. case MBX_POLL:
  4911. /* Set up null reference to mailbox command */
  4912. psli->mbox_active = NULL;
  4913. /* Interrupt board to do it */
  4914. writel(CA_MBATT, phba->CAregaddr);
  4915. readl(phba->CAregaddr); /* flush */
  4916. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4917. /* First read mbox status word */
  4918. word0 = *((uint32_t *)phba->mbox);
  4919. word0 = le32_to_cpu(word0);
  4920. } else {
  4921. /* First read mbox status word */
  4922. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  4923. spin_unlock_irqrestore(&phba->hbalock,
  4924. drvr_flag);
  4925. goto out_not_finished;
  4926. }
  4927. }
  4928. /* Read the HBA Host Attention Register */
  4929. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  4930. spin_unlock_irqrestore(&phba->hbalock,
  4931. drvr_flag);
  4932. goto out_not_finished;
  4933. }
  4934. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4935. mb->mbxCommand) *
  4936. 1000) + jiffies;
  4937. i = 0;
  4938. /* Wait for command to complete */
  4939. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4940. (!(ha_copy & HA_MBATT) &&
  4941. (phba->link_state > LPFC_WARM_START))) {
  4942. if (time_after(jiffies, timeout)) {
  4943. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4944. spin_unlock_irqrestore(&phba->hbalock,
  4945. drvr_flag);
  4946. goto out_not_finished;
  4947. }
  4948. /* Check if we took a mbox interrupt while we were
  4949. polling */
  4950. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4951. && (evtctr != psli->slistat.mbox_event))
  4952. break;
  4953. if (i++ > 10) {
  4954. spin_unlock_irqrestore(&phba->hbalock,
  4955. drvr_flag);
  4956. msleep(1);
  4957. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4958. }
  4959. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4960. /* First copy command data */
  4961. word0 = *((uint32_t *)phba->mbox);
  4962. word0 = le32_to_cpu(word0);
  4963. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4964. MAILBOX_t *slimmb;
  4965. uint32_t slimword0;
  4966. /* Check real SLIM for any errors */
  4967. slimword0 = readl(phba->MBslimaddr);
  4968. slimmb = (MAILBOX_t *) & slimword0;
  4969. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4970. && slimmb->mbxStatus) {
  4971. psli->sli_flag &=
  4972. ~LPFC_SLI_ACTIVE;
  4973. word0 = slimword0;
  4974. }
  4975. }
  4976. } else {
  4977. /* First copy command data */
  4978. word0 = readl(phba->MBslimaddr);
  4979. }
  4980. /* Read the HBA Host Attention Register */
  4981. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  4982. spin_unlock_irqrestore(&phba->hbalock,
  4983. drvr_flag);
  4984. goto out_not_finished;
  4985. }
  4986. }
  4987. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4988. /* copy results back to user */
  4989. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4990. /* Copy the mailbox extension data */
  4991. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4992. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4993. pmbox->context2,
  4994. pmbox->out_ext_byte_len);
  4995. }
  4996. } else {
  4997. /* First copy command data */
  4998. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4999. MAILBOX_CMD_SIZE);
  5000. /* Copy the mailbox extension data */
  5001. if (pmbox->out_ext_byte_len && pmbox->context2) {
  5002. lpfc_memcpy_from_slim(pmbox->context2,
  5003. phba->MBslimaddr +
  5004. MAILBOX_HBA_EXT_OFFSET,
  5005. pmbox->out_ext_byte_len);
  5006. }
  5007. }
  5008. writel(HA_MBATT, phba->HAregaddr);
  5009. readl(phba->HAregaddr); /* flush */
  5010. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5011. status = mb->mbxStatus;
  5012. }
  5013. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5014. return status;
  5015. out_not_finished:
  5016. if (processing_queue) {
  5017. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5018. lpfc_mbox_cmpl_put(phba, pmbox);
  5019. }
  5020. return MBX_NOT_FINISHED;
  5021. }
  5022. /**
  5023. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  5024. * @phba: Pointer to HBA context object.
  5025. *
  5026. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  5027. * the driver internal pending mailbox queue. It will then try to wait out the
  5028. * possible outstanding mailbox command before return.
  5029. *
  5030. * Returns:
  5031. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  5032. * the outstanding mailbox command timed out.
  5033. **/
  5034. static int
  5035. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  5036. {
  5037. struct lpfc_sli *psli = &phba->sli;
  5038. uint8_t actcmd = MBX_HEARTBEAT;
  5039. int rc = 0;
  5040. unsigned long timeout;
  5041. /* Mark the asynchronous mailbox command posting as blocked */
  5042. spin_lock_irq(&phba->hbalock);
  5043. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  5044. if (phba->sli.mbox_active)
  5045. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  5046. spin_unlock_irq(&phba->hbalock);
  5047. /* Determine how long we might wait for the active mailbox
  5048. * command to be gracefully completed by firmware.
  5049. */
  5050. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5051. jiffies;
  5052. /* Wait for the outstnading mailbox command to complete */
  5053. while (phba->sli.mbox_active) {
  5054. /* Check active mailbox complete status every 2ms */
  5055. msleep(2);
  5056. if (time_after(jiffies, timeout)) {
  5057. /* Timeout, marked the outstanding cmd not complete */
  5058. rc = 1;
  5059. break;
  5060. }
  5061. }
  5062. /* Can not cleanly block async mailbox command, fails it */
  5063. if (rc) {
  5064. spin_lock_irq(&phba->hbalock);
  5065. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5066. spin_unlock_irq(&phba->hbalock);
  5067. }
  5068. return rc;
  5069. }
  5070. /**
  5071. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5072. * @phba: Pointer to HBA context object.
  5073. *
  5074. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5075. * commands from the driver internal pending mailbox queue. It makes sure
  5076. * that there is no outstanding mailbox command before resuming posting
  5077. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5078. * mailbox command, it will try to wait it out before resuming asynchronous
  5079. * mailbox command posting.
  5080. **/
  5081. static void
  5082. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5083. {
  5084. struct lpfc_sli *psli = &phba->sli;
  5085. spin_lock_irq(&phba->hbalock);
  5086. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5087. /* Asynchronous mailbox posting is not blocked, do nothing */
  5088. spin_unlock_irq(&phba->hbalock);
  5089. return;
  5090. }
  5091. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5092. * successful or timeout, after timing-out the outstanding mailbox
  5093. * command shall always be removed, so just unblock posting async
  5094. * mailbox command and resume
  5095. */
  5096. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5097. spin_unlock_irq(&phba->hbalock);
  5098. /* wake up worker thread to post asynchronlous mailbox command */
  5099. lpfc_worker_wake_up(phba);
  5100. }
  5101. /**
  5102. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5103. * @phba: Pointer to HBA context object.
  5104. * @mboxq: Pointer to mailbox object.
  5105. *
  5106. * The function posts a mailbox to the port. The mailbox is expected
  5107. * to be comletely filled in and ready for the port to operate on it.
  5108. * This routine executes a synchronous completion operation on the
  5109. * mailbox by polling for its completion.
  5110. *
  5111. * The caller must not be holding any locks when calling this routine.
  5112. *
  5113. * Returns:
  5114. * MBX_SUCCESS - mailbox posted successfully
  5115. * Any of the MBX error values.
  5116. **/
  5117. static int
  5118. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5119. {
  5120. int rc = MBX_SUCCESS;
  5121. unsigned long iflag;
  5122. uint32_t db_ready;
  5123. uint32_t mcqe_status;
  5124. uint32_t mbx_cmnd;
  5125. unsigned long timeout;
  5126. struct lpfc_sli *psli = &phba->sli;
  5127. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5128. struct lpfc_bmbx_create *mbox_rgn;
  5129. struct dma_address *dma_address;
  5130. struct lpfc_register bmbx_reg;
  5131. /*
  5132. * Only one mailbox can be active to the bootstrap mailbox region
  5133. * at a time and there is no queueing provided.
  5134. */
  5135. spin_lock_irqsave(&phba->hbalock, iflag);
  5136. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5137. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5138. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5139. "(%d):2532 Mailbox command x%x (x%x) "
  5140. "cannot issue Data: x%x x%x\n",
  5141. mboxq->vport ? mboxq->vport->vpi : 0,
  5142. mboxq->u.mb.mbxCommand,
  5143. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5144. psli->sli_flag, MBX_POLL);
  5145. return MBXERR_ERROR;
  5146. }
  5147. /* The server grabs the token and owns it until release */
  5148. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5149. phba->sli.mbox_active = mboxq;
  5150. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5151. /*
  5152. * Initialize the bootstrap memory region to avoid stale data areas
  5153. * in the mailbox post. Then copy the caller's mailbox contents to
  5154. * the bmbx mailbox region.
  5155. */
  5156. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5157. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5158. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5159. sizeof(struct lpfc_mqe));
  5160. /* Post the high mailbox dma address to the port and wait for ready. */
  5161. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5162. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5163. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5164. * 1000) + jiffies;
  5165. do {
  5166. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5167. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5168. if (!db_ready)
  5169. msleep(2);
  5170. if (time_after(jiffies, timeout)) {
  5171. rc = MBXERR_ERROR;
  5172. goto exit;
  5173. }
  5174. } while (!db_ready);
  5175. /* Post the low mailbox dma address to the port. */
  5176. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5177. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5178. * 1000) + jiffies;
  5179. do {
  5180. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5181. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5182. if (!db_ready)
  5183. msleep(2);
  5184. if (time_after(jiffies, timeout)) {
  5185. rc = MBXERR_ERROR;
  5186. goto exit;
  5187. }
  5188. } while (!db_ready);
  5189. /*
  5190. * Read the CQ to ensure the mailbox has completed.
  5191. * If so, update the mailbox status so that the upper layers
  5192. * can complete the request normally.
  5193. */
  5194. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5195. sizeof(struct lpfc_mqe));
  5196. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5197. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5198. sizeof(struct lpfc_mcqe));
  5199. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5200. /*
  5201. * When the CQE status indicates a failure and the mailbox status
  5202. * indicates success then copy the CQE status into the mailbox status
  5203. * (and prefix it with x4000).
  5204. */
  5205. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5206. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  5207. bf_set(lpfc_mqe_status, mb,
  5208. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  5209. rc = MBXERR_ERROR;
  5210. } else
  5211. lpfc_sli4_swap_str(phba, mboxq);
  5212. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5213. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5214. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5215. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5216. mboxq->vport ? mboxq->vport->vpi : 0,
  5217. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5218. bf_get(lpfc_mqe_status, mb),
  5219. mb->un.mb_words[0], mb->un.mb_words[1],
  5220. mb->un.mb_words[2], mb->un.mb_words[3],
  5221. mb->un.mb_words[4], mb->un.mb_words[5],
  5222. mb->un.mb_words[6], mb->un.mb_words[7],
  5223. mb->un.mb_words[8], mb->un.mb_words[9],
  5224. mb->un.mb_words[10], mb->un.mb_words[11],
  5225. mb->un.mb_words[12], mboxq->mcqe.word0,
  5226. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5227. mboxq->mcqe.trailer);
  5228. exit:
  5229. /* We are holding the token, no needed for lock when release */
  5230. spin_lock_irqsave(&phba->hbalock, iflag);
  5231. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5232. phba->sli.mbox_active = NULL;
  5233. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5234. return rc;
  5235. }
  5236. /**
  5237. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5238. * @phba: Pointer to HBA context object.
  5239. * @pmbox: Pointer to mailbox object.
  5240. * @flag: Flag indicating how the mailbox need to be processed.
  5241. *
  5242. * This function is called by discovery code and HBA management code to submit
  5243. * a mailbox command to firmware with SLI-4 interface spec.
  5244. *
  5245. * Return codes the caller owns the mailbox command after the return of the
  5246. * function.
  5247. **/
  5248. static int
  5249. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5250. uint32_t flag)
  5251. {
  5252. struct lpfc_sli *psli = &phba->sli;
  5253. unsigned long iflags;
  5254. int rc;
  5255. rc = lpfc_mbox_dev_check(phba);
  5256. if (unlikely(rc)) {
  5257. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5258. "(%d):2544 Mailbox command x%x (x%x) "
  5259. "cannot issue Data: x%x x%x\n",
  5260. mboxq->vport ? mboxq->vport->vpi : 0,
  5261. mboxq->u.mb.mbxCommand,
  5262. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5263. psli->sli_flag, flag);
  5264. goto out_not_finished;
  5265. }
  5266. /* Detect polling mode and jump to a handler */
  5267. if (!phba->sli4_hba.intr_enable) {
  5268. if (flag == MBX_POLL)
  5269. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5270. else
  5271. rc = -EIO;
  5272. if (rc != MBX_SUCCESS)
  5273. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5274. "(%d):2541 Mailbox command x%x "
  5275. "(x%x) cannot issue Data: x%x x%x\n",
  5276. mboxq->vport ? mboxq->vport->vpi : 0,
  5277. mboxq->u.mb.mbxCommand,
  5278. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5279. psli->sli_flag, flag);
  5280. return rc;
  5281. } else if (flag == MBX_POLL) {
  5282. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5283. "(%d):2542 Try to issue mailbox command "
  5284. "x%x (x%x) synchronously ahead of async"
  5285. "mailbox command queue: x%x x%x\n",
  5286. mboxq->vport ? mboxq->vport->vpi : 0,
  5287. mboxq->u.mb.mbxCommand,
  5288. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5289. psli->sli_flag, flag);
  5290. /* Try to block the asynchronous mailbox posting */
  5291. rc = lpfc_sli4_async_mbox_block(phba);
  5292. if (!rc) {
  5293. /* Successfully blocked, now issue sync mbox cmd */
  5294. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5295. if (rc != MBX_SUCCESS)
  5296. lpfc_printf_log(phba, KERN_ERR,
  5297. LOG_MBOX | LOG_SLI,
  5298. "(%d):2597 Mailbox command "
  5299. "x%x (x%x) cannot issue "
  5300. "Data: x%x x%x\n",
  5301. mboxq->vport ?
  5302. mboxq->vport->vpi : 0,
  5303. mboxq->u.mb.mbxCommand,
  5304. lpfc_sli4_mbox_opcode_get(phba,
  5305. mboxq),
  5306. psli->sli_flag, flag);
  5307. /* Unblock the async mailbox posting afterward */
  5308. lpfc_sli4_async_mbox_unblock(phba);
  5309. }
  5310. return rc;
  5311. }
  5312. /* Now, interrupt mode asynchrous mailbox command */
  5313. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5314. if (rc) {
  5315. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5316. "(%d):2543 Mailbox command x%x (x%x) "
  5317. "cannot issue Data: x%x x%x\n",
  5318. mboxq->vport ? mboxq->vport->vpi : 0,
  5319. mboxq->u.mb.mbxCommand,
  5320. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5321. psli->sli_flag, flag);
  5322. goto out_not_finished;
  5323. }
  5324. /* Put the mailbox command to the driver internal FIFO */
  5325. psli->slistat.mbox_busy++;
  5326. spin_lock_irqsave(&phba->hbalock, iflags);
  5327. lpfc_mbox_put(phba, mboxq);
  5328. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5329. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5330. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5331. "x%x (x%x) x%x x%x x%x\n",
  5332. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5333. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5334. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5335. phba->pport->port_state,
  5336. psli->sli_flag, MBX_NOWAIT);
  5337. /* Wake up worker thread to transport mailbox command from head */
  5338. lpfc_worker_wake_up(phba);
  5339. return MBX_BUSY;
  5340. out_not_finished:
  5341. return MBX_NOT_FINISHED;
  5342. }
  5343. /**
  5344. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5345. * @phba: Pointer to HBA context object.
  5346. *
  5347. * This function is called by worker thread to send a mailbox command to
  5348. * SLI4 HBA firmware.
  5349. *
  5350. **/
  5351. int
  5352. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5353. {
  5354. struct lpfc_sli *psli = &phba->sli;
  5355. LPFC_MBOXQ_t *mboxq;
  5356. int rc = MBX_SUCCESS;
  5357. unsigned long iflags;
  5358. struct lpfc_mqe *mqe;
  5359. uint32_t mbx_cmnd;
  5360. /* Check interrupt mode before post async mailbox command */
  5361. if (unlikely(!phba->sli4_hba.intr_enable))
  5362. return MBX_NOT_FINISHED;
  5363. /* Check for mailbox command service token */
  5364. spin_lock_irqsave(&phba->hbalock, iflags);
  5365. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5366. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5367. return MBX_NOT_FINISHED;
  5368. }
  5369. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5370. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5371. return MBX_NOT_FINISHED;
  5372. }
  5373. if (unlikely(phba->sli.mbox_active)) {
  5374. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5375. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5376. "0384 There is pending active mailbox cmd\n");
  5377. return MBX_NOT_FINISHED;
  5378. }
  5379. /* Take the mailbox command service token */
  5380. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5381. /* Get the next mailbox command from head of queue */
  5382. mboxq = lpfc_mbox_get(phba);
  5383. /* If no more mailbox command waiting for post, we're done */
  5384. if (!mboxq) {
  5385. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5386. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5387. return MBX_SUCCESS;
  5388. }
  5389. phba->sli.mbox_active = mboxq;
  5390. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5391. /* Check device readiness for posting mailbox command */
  5392. rc = lpfc_mbox_dev_check(phba);
  5393. if (unlikely(rc))
  5394. /* Driver clean routine will clean up pending mailbox */
  5395. goto out_not_finished;
  5396. /* Prepare the mbox command to be posted */
  5397. mqe = &mboxq->u.mqe;
  5398. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5399. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5400. mod_timer(&psli->mbox_tmo, (jiffies +
  5401. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5402. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5403. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5404. "x%x x%x\n",
  5405. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5406. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5407. phba->pport->port_state, psli->sli_flag);
  5408. if (mbx_cmnd != MBX_HEARTBEAT) {
  5409. if (mboxq->vport) {
  5410. lpfc_debugfs_disc_trc(mboxq->vport,
  5411. LPFC_DISC_TRC_MBOX_VPORT,
  5412. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5413. mbx_cmnd, mqe->un.mb_words[0],
  5414. mqe->un.mb_words[1]);
  5415. } else {
  5416. lpfc_debugfs_disc_trc(phba->pport,
  5417. LPFC_DISC_TRC_MBOX,
  5418. "MBOX Send: cmd:x%x mb:x%x x%x",
  5419. mbx_cmnd, mqe->un.mb_words[0],
  5420. mqe->un.mb_words[1]);
  5421. }
  5422. }
  5423. psli->slistat.mbox_cmd++;
  5424. /* Post the mailbox command to the port */
  5425. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5426. if (rc != MBX_SUCCESS) {
  5427. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5428. "(%d):2533 Mailbox command x%x (x%x) "
  5429. "cannot issue Data: x%x x%x\n",
  5430. mboxq->vport ? mboxq->vport->vpi : 0,
  5431. mboxq->u.mb.mbxCommand,
  5432. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5433. psli->sli_flag, MBX_NOWAIT);
  5434. goto out_not_finished;
  5435. }
  5436. return rc;
  5437. out_not_finished:
  5438. spin_lock_irqsave(&phba->hbalock, iflags);
  5439. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5440. __lpfc_mbox_cmpl_put(phba, mboxq);
  5441. /* Release the token */
  5442. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5443. phba->sli.mbox_active = NULL;
  5444. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5445. return MBX_NOT_FINISHED;
  5446. }
  5447. /**
  5448. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5449. * @phba: Pointer to HBA context object.
  5450. * @pmbox: Pointer to mailbox object.
  5451. * @flag: Flag indicating how the mailbox need to be processed.
  5452. *
  5453. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5454. * the API jump table function pointer from the lpfc_hba struct.
  5455. *
  5456. * Return codes the caller owns the mailbox command after the return of the
  5457. * function.
  5458. **/
  5459. int
  5460. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5461. {
  5462. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5463. }
  5464. /**
  5465. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  5466. * @phba: The hba struct for which this call is being executed.
  5467. * @dev_grp: The HBA PCI-Device group number.
  5468. *
  5469. * This routine sets up the mbox interface API function jump table in @phba
  5470. * struct.
  5471. * Returns: 0 - success, -ENODEV - failure.
  5472. **/
  5473. int
  5474. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5475. {
  5476. switch (dev_grp) {
  5477. case LPFC_PCI_DEV_LP:
  5478. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5479. phba->lpfc_sli_handle_slow_ring_event =
  5480. lpfc_sli_handle_slow_ring_event_s3;
  5481. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5482. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5483. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5484. break;
  5485. case LPFC_PCI_DEV_OC:
  5486. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5487. phba->lpfc_sli_handle_slow_ring_event =
  5488. lpfc_sli_handle_slow_ring_event_s4;
  5489. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5490. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5491. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5492. break;
  5493. default:
  5494. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5495. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5496. dev_grp);
  5497. return -ENODEV;
  5498. break;
  5499. }
  5500. return 0;
  5501. }
  5502. /**
  5503. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5504. * @phba: Pointer to HBA context object.
  5505. * @pring: Pointer to driver SLI ring object.
  5506. * @piocb: Pointer to address of newly added command iocb.
  5507. *
  5508. * This function is called with hbalock held to add a command
  5509. * iocb to the txq when SLI layer cannot submit the command iocb
  5510. * to the ring.
  5511. **/
  5512. void
  5513. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5514. struct lpfc_iocbq *piocb)
  5515. {
  5516. /* Insert the caller's iocb in the txq tail for later processing. */
  5517. list_add_tail(&piocb->list, &pring->txq);
  5518. pring->txq_cnt++;
  5519. }
  5520. /**
  5521. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5522. * @phba: Pointer to HBA context object.
  5523. * @pring: Pointer to driver SLI ring object.
  5524. * @piocb: Pointer to address of newly added command iocb.
  5525. *
  5526. * This function is called with hbalock held before a new
  5527. * iocb is submitted to the firmware. This function checks
  5528. * txq to flush the iocbs in txq to Firmware before
  5529. * submitting new iocbs to the Firmware.
  5530. * If there are iocbs in the txq which need to be submitted
  5531. * to firmware, lpfc_sli_next_iocb returns the first element
  5532. * of the txq after dequeuing it from txq.
  5533. * If there is no iocb in the txq then the function will return
  5534. * *piocb and *piocb is set to NULL. Caller needs to check
  5535. * *piocb to find if there are more commands in the txq.
  5536. **/
  5537. static struct lpfc_iocbq *
  5538. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5539. struct lpfc_iocbq **piocb)
  5540. {
  5541. struct lpfc_iocbq * nextiocb;
  5542. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5543. if (!nextiocb) {
  5544. nextiocb = *piocb;
  5545. *piocb = NULL;
  5546. }
  5547. return nextiocb;
  5548. }
  5549. /**
  5550. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5551. * @phba: Pointer to HBA context object.
  5552. * @ring_number: SLI ring number to issue iocb on.
  5553. * @piocb: Pointer to command iocb.
  5554. * @flag: Flag indicating if this command can be put into txq.
  5555. *
  5556. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5557. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5558. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5559. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5560. * this function allows only iocbs for posting buffers. This function finds
  5561. * next available slot in the command ring and posts the command to the
  5562. * available slot and writes the port attention register to request HBA start
  5563. * processing new iocb. If there is no slot available in the ring and
  5564. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5565. * the function returns IOCB_BUSY.
  5566. *
  5567. * This function is called with hbalock held. The function will return success
  5568. * after it successfully submit the iocb to firmware or after adding to the
  5569. * txq.
  5570. **/
  5571. static int
  5572. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5573. struct lpfc_iocbq *piocb, uint32_t flag)
  5574. {
  5575. struct lpfc_iocbq *nextiocb;
  5576. IOCB_t *iocb;
  5577. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5578. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5579. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5580. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5581. lpfc_printf_log(phba, KERN_ERR,
  5582. LOG_SLI | LOG_VPORT,
  5583. "1807 IOCB x%x failed. No vport\n",
  5584. piocb->iocb.ulpCommand);
  5585. dump_stack();
  5586. return IOCB_ERROR;
  5587. }
  5588. /* If the PCI channel is in offline state, do not post iocbs. */
  5589. if (unlikely(pci_channel_offline(phba->pcidev)))
  5590. return IOCB_ERROR;
  5591. /* If HBA has a deferred error attention, fail the iocb. */
  5592. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5593. return IOCB_ERROR;
  5594. /*
  5595. * We should never get an IOCB if we are in a < LINK_DOWN state
  5596. */
  5597. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5598. return IOCB_ERROR;
  5599. /*
  5600. * Check to see if we are blocking IOCB processing because of a
  5601. * outstanding event.
  5602. */
  5603. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5604. goto iocb_busy;
  5605. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5606. /*
  5607. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5608. * can be issued if the link is not up.
  5609. */
  5610. switch (piocb->iocb.ulpCommand) {
  5611. case CMD_GEN_REQUEST64_CR:
  5612. case CMD_GEN_REQUEST64_CX:
  5613. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5614. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5615. FC_RCTL_DD_UNSOL_CMD) ||
  5616. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5617. MENLO_TRANSPORT_TYPE))
  5618. goto iocb_busy;
  5619. break;
  5620. case CMD_QUE_RING_BUF_CN:
  5621. case CMD_QUE_RING_BUF64_CN:
  5622. /*
  5623. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5624. * completion, iocb_cmpl MUST be 0.
  5625. */
  5626. if (piocb->iocb_cmpl)
  5627. piocb->iocb_cmpl = NULL;
  5628. /*FALLTHROUGH*/
  5629. case CMD_CREATE_XRI_CR:
  5630. case CMD_CLOSE_XRI_CN:
  5631. case CMD_CLOSE_XRI_CX:
  5632. break;
  5633. default:
  5634. goto iocb_busy;
  5635. }
  5636. /*
  5637. * For FCP commands, we must be in a state where we can process link
  5638. * attention events.
  5639. */
  5640. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5641. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5642. goto iocb_busy;
  5643. }
  5644. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5645. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5646. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5647. if (iocb)
  5648. lpfc_sli_update_ring(phba, pring);
  5649. else
  5650. lpfc_sli_update_full_ring(phba, pring);
  5651. if (!piocb)
  5652. return IOCB_SUCCESS;
  5653. goto out_busy;
  5654. iocb_busy:
  5655. pring->stats.iocb_cmd_delay++;
  5656. out_busy:
  5657. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5658. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5659. return IOCB_SUCCESS;
  5660. }
  5661. return IOCB_BUSY;
  5662. }
  5663. /**
  5664. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5665. * @phba: Pointer to HBA context object.
  5666. * @piocb: Pointer to command iocb.
  5667. * @sglq: Pointer to the scatter gather queue object.
  5668. *
  5669. * This routine converts the bpl or bde that is in the IOCB
  5670. * to a sgl list for the sli4 hardware. The physical address
  5671. * of the bpl/bde is converted back to a virtual address.
  5672. * If the IOCB contains a BPL then the list of BDE's is
  5673. * converted to sli4_sge's. If the IOCB contains a single
  5674. * BDE then it is converted to a single sli_sge.
  5675. * The IOCB is still in cpu endianess so the contents of
  5676. * the bpl can be used without byte swapping.
  5677. *
  5678. * Returns valid XRI = Success, NO_XRI = Failure.
  5679. **/
  5680. static uint16_t
  5681. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5682. struct lpfc_sglq *sglq)
  5683. {
  5684. uint16_t xritag = NO_XRI;
  5685. struct ulp_bde64 *bpl = NULL;
  5686. struct ulp_bde64 bde;
  5687. struct sli4_sge *sgl = NULL;
  5688. IOCB_t *icmd;
  5689. int numBdes = 0;
  5690. int i = 0;
  5691. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5692. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5693. if (!piocbq || !sglq)
  5694. return xritag;
  5695. sgl = (struct sli4_sge *)sglq->sgl;
  5696. icmd = &piocbq->iocb;
  5697. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5698. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5699. sizeof(struct ulp_bde64);
  5700. /* The addrHigh and addrLow fields within the IOCB
  5701. * have not been byteswapped yet so there is no
  5702. * need to swap them back.
  5703. */
  5704. bpl = (struct ulp_bde64 *)
  5705. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5706. if (!bpl)
  5707. return xritag;
  5708. for (i = 0; i < numBdes; i++) {
  5709. /* Should already be byte swapped. */
  5710. sgl->addr_hi = bpl->addrHigh;
  5711. sgl->addr_lo = bpl->addrLow;
  5712. sgl->word2 = le32_to_cpu(sgl->word2);
  5713. if ((i+1) == numBdes)
  5714. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5715. else
  5716. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5717. /* swap the size field back to the cpu so we
  5718. * can assign it to the sgl.
  5719. */
  5720. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5721. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5722. /* The offsets in the sgl need to be accumulated
  5723. * separately for the request and reply lists.
  5724. * The request is always first, the reply follows.
  5725. */
  5726. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5727. /* add up the reply sg entries */
  5728. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5729. inbound++;
  5730. /* first inbound? reset the offset */
  5731. if (inbound == 1)
  5732. offset = 0;
  5733. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5734. offset += bde.tus.f.bdeSize;
  5735. }
  5736. sgl->word2 = cpu_to_le32(sgl->word2);
  5737. bpl++;
  5738. sgl++;
  5739. }
  5740. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5741. /* The addrHigh and addrLow fields of the BDE have not
  5742. * been byteswapped yet so they need to be swapped
  5743. * before putting them in the sgl.
  5744. */
  5745. sgl->addr_hi =
  5746. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5747. sgl->addr_lo =
  5748. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5749. sgl->word2 = le32_to_cpu(sgl->word2);
  5750. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5751. sgl->word2 = cpu_to_le32(sgl->word2);
  5752. sgl->sge_len =
  5753. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5754. }
  5755. return sglq->sli4_xritag;
  5756. }
  5757. /**
  5758. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5759. * @phba: Pointer to HBA context object.
  5760. *
  5761. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5762. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5763. * held.
  5764. *
  5765. * Return: index into SLI4 fast-path FCP queue index.
  5766. **/
  5767. static uint32_t
  5768. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5769. {
  5770. ++phba->fcp_qidx;
  5771. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5772. phba->fcp_qidx = 0;
  5773. return phba->fcp_qidx;
  5774. }
  5775. /**
  5776. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5777. * @phba: Pointer to HBA context object.
  5778. * @piocb: Pointer to command iocb.
  5779. * @wqe: Pointer to the work queue entry.
  5780. *
  5781. * This routine converts the iocb command to its Work Queue Entry
  5782. * equivalent. The wqe pointer should not have any fields set when
  5783. * this routine is called because it will memcpy over them.
  5784. * This routine does not set the CQ_ID or the WQEC bits in the
  5785. * wqe.
  5786. *
  5787. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5788. **/
  5789. static int
  5790. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5791. union lpfc_wqe *wqe)
  5792. {
  5793. uint32_t xmit_len = 0, total_len = 0;
  5794. uint8_t ct = 0;
  5795. uint32_t fip;
  5796. uint32_t abort_tag;
  5797. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5798. uint8_t cmnd;
  5799. uint16_t xritag;
  5800. uint16_t abrt_iotag;
  5801. struct lpfc_iocbq *abrtiocbq;
  5802. struct ulp_bde64 *bpl = NULL;
  5803. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5804. int numBdes, i;
  5805. struct ulp_bde64 bde;
  5806. struct lpfc_nodelist *ndlp;
  5807. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5808. /* The fcp commands will set command type */
  5809. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5810. command_type = FCP_COMMAND;
  5811. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5812. command_type = ELS_COMMAND_FIP;
  5813. else
  5814. command_type = ELS_COMMAND_NON_FIP;
  5815. /* Some of the fields are in the right position already */
  5816. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5817. abort_tag = (uint32_t) iocbq->iotag;
  5818. xritag = iocbq->sli4_xritag;
  5819. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5820. /* words0-2 bpl convert bde */
  5821. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5822. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5823. sizeof(struct ulp_bde64);
  5824. bpl = (struct ulp_bde64 *)
  5825. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5826. if (!bpl)
  5827. return IOCB_ERROR;
  5828. /* Should already be byte swapped. */
  5829. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5830. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5831. /* swap the size field back to the cpu so we
  5832. * can assign it to the sgl.
  5833. */
  5834. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5835. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5836. total_len = 0;
  5837. for (i = 0; i < numBdes; i++) {
  5838. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5839. total_len += bde.tus.f.bdeSize;
  5840. }
  5841. } else
  5842. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5843. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5844. cmnd = iocbq->iocb.ulpCommand;
  5845. switch (iocbq->iocb.ulpCommand) {
  5846. case CMD_ELS_REQUEST64_CR:
  5847. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  5848. if (!iocbq->iocb.ulpLe) {
  5849. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5850. "2007 Only Limited Edition cmd Format"
  5851. " supported 0x%x\n",
  5852. iocbq->iocb.ulpCommand);
  5853. return IOCB_ERROR;
  5854. }
  5855. wqe->els_req.payload_len = xmit_len;
  5856. /* Els_reguest64 has a TMO */
  5857. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5858. iocbq->iocb.ulpTimeout);
  5859. /* Need a VF for word 4 set the vf bit*/
  5860. bf_set(els_req64_vf, &wqe->els_req, 0);
  5861. /* And a VFID for word 12 */
  5862. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5863. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5864. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5865. iocbq->iocb.ulpContext);
  5866. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5867. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5868. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5869. if (command_type == ELS_COMMAND_FIP) {
  5870. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5871. >> LPFC_FIP_ELS_ID_SHIFT);
  5872. }
  5873. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, ndlp->nlp_rpi);
  5874. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5875. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5876. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5877. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5878. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5879. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5880. break;
  5881. case CMD_XMIT_SEQUENCE64_CX:
  5882. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5883. iocbq->iocb.un.ulpWord[3]);
  5884. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5885. iocbq->iocb.ulpContext);
  5886. /* The entire sequence is transmitted for this IOCB */
  5887. xmit_len = total_len;
  5888. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5889. case CMD_XMIT_SEQUENCE64_CR:
  5890. /* word3 iocb=io_tag32 wqe=reserved */
  5891. wqe->xmit_sequence.rsvd3 = 0;
  5892. /* word4 relative_offset memcpy */
  5893. /* word5 r_ctl/df_ctl memcpy */
  5894. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5895. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5896. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5897. LPFC_WQE_IOD_WRITE);
  5898. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5899. LPFC_WQE_LENLOC_WORD12);
  5900. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5901. wqe->xmit_sequence.xmit_len = xmit_len;
  5902. command_type = OTHER_COMMAND;
  5903. break;
  5904. case CMD_XMIT_BCAST64_CN:
  5905. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5906. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5907. /* word4 iocb=rsvd wqe=rsvd */
  5908. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5909. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5910. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5911. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5912. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5913. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5914. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5915. LPFC_WQE_LENLOC_WORD3);
  5916. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5917. break;
  5918. case CMD_FCP_IWRITE64_CR:
  5919. command_type = FCP_COMMAND_DATA_OUT;
  5920. /* word3 iocb=iotag wqe=payload_offset_len */
  5921. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5922. wqe->fcp_iwrite.payload_offset_len =
  5923. xmit_len + sizeof(struct fcp_rsp);
  5924. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5925. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5926. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5927. iocbq->iocb.ulpFCP2Rcvy);
  5928. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5929. /* Always open the exchange */
  5930. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5931. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5932. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5933. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5934. LPFC_WQE_LENLOC_WORD4);
  5935. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5936. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5937. break;
  5938. case CMD_FCP_IREAD64_CR:
  5939. /* word3 iocb=iotag wqe=payload_offset_len */
  5940. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5941. wqe->fcp_iread.payload_offset_len =
  5942. xmit_len + sizeof(struct fcp_rsp);
  5943. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5944. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5945. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5946. iocbq->iocb.ulpFCP2Rcvy);
  5947. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5948. /* Always open the exchange */
  5949. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5950. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5951. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5952. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5953. LPFC_WQE_LENLOC_WORD4);
  5954. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5955. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5956. break;
  5957. case CMD_FCP_ICMND64_CR:
  5958. /* word3 iocb=IO_TAG wqe=reserved */
  5959. wqe->fcp_icmd.rsrvd3 = 0;
  5960. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5961. /* Always open the exchange */
  5962. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5963. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5964. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5965. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5966. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5967. LPFC_WQE_LENLOC_NONE);
  5968. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5969. break;
  5970. case CMD_GEN_REQUEST64_CR:
  5971. /* For this command calculate the xmit length of the
  5972. * request bde.
  5973. */
  5974. xmit_len = 0;
  5975. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5976. sizeof(struct ulp_bde64);
  5977. for (i = 0; i < numBdes; i++) {
  5978. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5979. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5980. break;
  5981. xmit_len += bde.tus.f.bdeSize;
  5982. }
  5983. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5984. wqe->gen_req.request_payload_len = xmit_len;
  5985. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5986. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5987. /* word6 context tag copied in memcpy */
  5988. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5989. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5990. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5991. "2015 Invalid CT %x command 0x%x\n",
  5992. ct, iocbq->iocb.ulpCommand);
  5993. return IOCB_ERROR;
  5994. }
  5995. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5996. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5997. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5998. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5999. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  6000. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  6001. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  6002. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  6003. command_type = OTHER_COMMAND;
  6004. break;
  6005. case CMD_XMIT_ELS_RSP64_CX:
  6006. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  6007. /* words0-2 BDE memcpy */
  6008. /* word3 iocb=iotag32 wqe=response_payload_len */
  6009. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  6010. /* word4 iocb=did wge=rsvd. */
  6011. wqe->xmit_els_rsp.rsvd4 = 0;
  6012. /* word5 iocb=rsvd wge=did */
  6013. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  6014. iocbq->iocb.un.elsreq64.remoteID);
  6015. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  6016. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6017. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  6018. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  6019. iocbq->iocb.ulpContext);
  6020. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  6021. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  6022. iocbq->vport->vpi + phba->vpi_base);
  6023. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  6024. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  6025. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  6026. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  6027. LPFC_WQE_LENLOC_WORD3);
  6028. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  6029. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, ndlp->nlp_rpi);
  6030. command_type = OTHER_COMMAND;
  6031. break;
  6032. case CMD_CLOSE_XRI_CN:
  6033. case CMD_ABORT_XRI_CN:
  6034. case CMD_ABORT_XRI_CX:
  6035. /* words 0-2 memcpy should be 0 rserved */
  6036. /* port will send abts */
  6037. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  6038. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  6039. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  6040. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  6041. } else
  6042. fip = 0;
  6043. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  6044. /*
  6045. * The link is down, or the command was ELS_FIP
  6046. * so the fw does not need to send abts
  6047. * on the wire.
  6048. */
  6049. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  6050. else
  6051. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  6052. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  6053. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  6054. wqe->abort_cmd.rsrvd5 = 0;
  6055. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  6056. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6057. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  6058. /*
  6059. * The abort handler will send us CMD_ABORT_XRI_CN or
  6060. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6061. */
  6062. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6063. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6064. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6065. LPFC_WQE_LENLOC_NONE);
  6066. cmnd = CMD_ABORT_XRI_CX;
  6067. command_type = OTHER_COMMAND;
  6068. xritag = 0;
  6069. break;
  6070. case CMD_XMIT_BLS_RSP64_CX:
  6071. /* As BLS ABTS RSP WQE is very different from other WQEs,
  6072. * we re-construct this WQE here based on information in
  6073. * iocbq from scratch.
  6074. */
  6075. memset(wqe, 0, sizeof(union lpfc_wqe));
  6076. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6077. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6078. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  6079. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  6080. LPFC_ABTS_UNSOL_INT) {
  6081. /* ABTS sent by initiator to CT exchange, the
  6082. * RX_ID field will be filled with the newly
  6083. * allocated responder XRI.
  6084. */
  6085. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6086. iocbq->sli4_xritag);
  6087. } else {
  6088. /* ABTS sent by responder to CT exchange, the
  6089. * RX_ID field will be filled with the responder
  6090. * RX_ID from ABTS.
  6091. */
  6092. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6093. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  6094. }
  6095. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6096. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6097. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6098. iocbq->iocb.ulpContext);
  6099. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6100. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6101. LPFC_WQE_LENLOC_NONE);
  6102. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6103. command_type = OTHER_COMMAND;
  6104. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  6105. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  6106. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  6107. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  6108. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  6109. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  6110. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  6111. }
  6112. break;
  6113. case CMD_XRI_ABORTED_CX:
  6114. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6115. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6116. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6117. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6118. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6119. default:
  6120. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6121. "2014 Invalid command 0x%x\n",
  6122. iocbq->iocb.ulpCommand);
  6123. return IOCB_ERROR;
  6124. break;
  6125. }
  6126. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6127. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6128. wqe->generic.wqe_com.abort_tag = abort_tag;
  6129. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6130. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6131. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6132. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6133. return 0;
  6134. }
  6135. /**
  6136. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6137. * @phba: Pointer to HBA context object.
  6138. * @ring_number: SLI ring number to issue iocb on.
  6139. * @piocb: Pointer to command iocb.
  6140. * @flag: Flag indicating if this command can be put into txq.
  6141. *
  6142. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6143. * an iocb command to an HBA with SLI-4 interface spec.
  6144. *
  6145. * This function is called with hbalock held. The function will return success
  6146. * after it successfully submit the iocb to firmware or after adding to the
  6147. * txq.
  6148. **/
  6149. static int
  6150. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6151. struct lpfc_iocbq *piocb, uint32_t flag)
  6152. {
  6153. struct lpfc_sglq *sglq;
  6154. union lpfc_wqe wqe;
  6155. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6156. if (piocb->sli4_xritag == NO_XRI) {
  6157. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6158. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN ||
  6159. piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  6160. sglq = NULL;
  6161. else {
  6162. if (pring->txq_cnt) {
  6163. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6164. __lpfc_sli_ringtx_put(phba,
  6165. pring, piocb);
  6166. return IOCB_SUCCESS;
  6167. } else {
  6168. return IOCB_BUSY;
  6169. }
  6170. } else {
  6171. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6172. if (!sglq) {
  6173. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6174. __lpfc_sli_ringtx_put(phba,
  6175. pring,
  6176. piocb);
  6177. return IOCB_SUCCESS;
  6178. } else
  6179. return IOCB_BUSY;
  6180. }
  6181. }
  6182. }
  6183. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6184. sglq = NULL; /* These IO's already have an XRI and
  6185. * a mapped sgl.
  6186. */
  6187. } else {
  6188. /* This is a continuation of a commandi,(CX) so this
  6189. * sglq is on the active list
  6190. */
  6191. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6192. if (!sglq)
  6193. return IOCB_ERROR;
  6194. }
  6195. if (sglq) {
  6196. piocb->sli4_xritag = sglq->sli4_xritag;
  6197. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6198. return IOCB_ERROR;
  6199. }
  6200. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6201. return IOCB_ERROR;
  6202. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6203. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6204. /*
  6205. * For FCP command IOCB, get a new WQ index to distribute
  6206. * WQE across the WQsr. On the other hand, for abort IOCB,
  6207. * it carries the same WQ index to the original command
  6208. * IOCB.
  6209. */
  6210. if (piocb->iocb_flag & LPFC_IO_FCP)
  6211. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6212. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6213. &wqe))
  6214. return IOCB_ERROR;
  6215. } else {
  6216. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6217. return IOCB_ERROR;
  6218. }
  6219. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6220. return 0;
  6221. }
  6222. /**
  6223. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6224. *
  6225. * This routine wraps the actual lockless version for issusing IOCB function
  6226. * pointer from the lpfc_hba struct.
  6227. *
  6228. * Return codes:
  6229. * IOCB_ERROR - Error
  6230. * IOCB_SUCCESS - Success
  6231. * IOCB_BUSY - Busy
  6232. **/
  6233. int
  6234. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6235. struct lpfc_iocbq *piocb, uint32_t flag)
  6236. {
  6237. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6238. }
  6239. /**
  6240. * lpfc_sli_api_table_setup - Set up sli api function jump table
  6241. * @phba: The hba struct for which this call is being executed.
  6242. * @dev_grp: The HBA PCI-Device group number.
  6243. *
  6244. * This routine sets up the SLI interface API function jump table in @phba
  6245. * struct.
  6246. * Returns: 0 - success, -ENODEV - failure.
  6247. **/
  6248. int
  6249. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6250. {
  6251. switch (dev_grp) {
  6252. case LPFC_PCI_DEV_LP:
  6253. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6254. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6255. break;
  6256. case LPFC_PCI_DEV_OC:
  6257. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6258. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6259. break;
  6260. default:
  6261. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6262. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6263. dev_grp);
  6264. return -ENODEV;
  6265. break;
  6266. }
  6267. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6268. return 0;
  6269. }
  6270. /**
  6271. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6272. * @phba: Pointer to HBA context object.
  6273. * @pring: Pointer to driver SLI ring object.
  6274. * @piocb: Pointer to command iocb.
  6275. * @flag: Flag indicating if this command can be put into txq.
  6276. *
  6277. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6278. * function. This function gets the hbalock and calls
  6279. * __lpfc_sli_issue_iocb function and will return the error returned
  6280. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6281. * functions which do not hold hbalock.
  6282. **/
  6283. int
  6284. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6285. struct lpfc_iocbq *piocb, uint32_t flag)
  6286. {
  6287. unsigned long iflags;
  6288. int rc;
  6289. spin_lock_irqsave(&phba->hbalock, iflags);
  6290. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6291. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6292. return rc;
  6293. }
  6294. /**
  6295. * lpfc_extra_ring_setup - Extra ring setup function
  6296. * @phba: Pointer to HBA context object.
  6297. *
  6298. * This function is called while driver attaches with the
  6299. * HBA to setup the extra ring. The extra ring is used
  6300. * only when driver needs to support target mode functionality
  6301. * or IP over FC functionalities.
  6302. *
  6303. * This function is called with no lock held.
  6304. **/
  6305. static int
  6306. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6307. {
  6308. struct lpfc_sli *psli;
  6309. struct lpfc_sli_ring *pring;
  6310. psli = &phba->sli;
  6311. /* Adjust cmd/rsp ring iocb entries more evenly */
  6312. /* Take some away from the FCP ring */
  6313. pring = &psli->ring[psli->fcp_ring];
  6314. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6315. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6316. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6317. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6318. /* and give them to the extra ring */
  6319. pring = &psli->ring[psli->extra_ring];
  6320. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6321. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6322. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6323. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6324. /* Setup default profile for this ring */
  6325. pring->iotag_max = 4096;
  6326. pring->num_mask = 1;
  6327. pring->prt[0].profile = 0; /* Mask 0 */
  6328. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6329. pring->prt[0].type = phba->cfg_multi_ring_type;
  6330. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6331. return 0;
  6332. }
  6333. /**
  6334. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6335. * @phba: Pointer to HBA context object.
  6336. * @pring: Pointer to driver SLI ring object.
  6337. * @iocbq: Pointer to iocb object.
  6338. *
  6339. * This function is called by the slow ring event handler
  6340. * function when there is an ASYNC event iocb in the ring.
  6341. * This function is called with no lock held.
  6342. * Currently this function handles only temperature related
  6343. * ASYNC events. The function decodes the temperature sensor
  6344. * event message and posts events for the management applications.
  6345. **/
  6346. static void
  6347. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6348. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6349. {
  6350. IOCB_t *icmd;
  6351. uint16_t evt_code;
  6352. uint16_t temp;
  6353. struct temp_event temp_event_data;
  6354. struct Scsi_Host *shost;
  6355. uint32_t *iocb_w;
  6356. icmd = &iocbq->iocb;
  6357. evt_code = icmd->un.asyncstat.evt_code;
  6358. temp = icmd->ulpContext;
  6359. if ((evt_code != ASYNC_TEMP_WARN) &&
  6360. (evt_code != ASYNC_TEMP_SAFE)) {
  6361. iocb_w = (uint32_t *) icmd;
  6362. lpfc_printf_log(phba,
  6363. KERN_ERR,
  6364. LOG_SLI,
  6365. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6366. " evt_code 0x%x\n"
  6367. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6368. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6369. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6370. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6371. pring->ringno,
  6372. icmd->un.asyncstat.evt_code,
  6373. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6374. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6375. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6376. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6377. return;
  6378. }
  6379. temp_event_data.data = (uint32_t)temp;
  6380. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6381. if (evt_code == ASYNC_TEMP_WARN) {
  6382. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6383. lpfc_printf_log(phba,
  6384. KERN_ERR,
  6385. LOG_TEMP,
  6386. "0347 Adapter is very hot, please take "
  6387. "corrective action. temperature : %d Celsius\n",
  6388. temp);
  6389. }
  6390. if (evt_code == ASYNC_TEMP_SAFE) {
  6391. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6392. lpfc_printf_log(phba,
  6393. KERN_ERR,
  6394. LOG_TEMP,
  6395. "0340 Adapter temperature is OK now. "
  6396. "temperature : %d Celsius\n",
  6397. temp);
  6398. }
  6399. /* Send temperature change event to applications */
  6400. shost = lpfc_shost_from_vport(phba->pport);
  6401. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6402. sizeof(temp_event_data), (char *) &temp_event_data,
  6403. LPFC_NL_VENDOR_ID);
  6404. }
  6405. /**
  6406. * lpfc_sli_setup - SLI ring setup function
  6407. * @phba: Pointer to HBA context object.
  6408. *
  6409. * lpfc_sli_setup sets up rings of the SLI interface with
  6410. * number of iocbs per ring and iotags. This function is
  6411. * called while driver attach to the HBA and before the
  6412. * interrupts are enabled. So there is no need for locking.
  6413. *
  6414. * This function always returns 0.
  6415. **/
  6416. int
  6417. lpfc_sli_setup(struct lpfc_hba *phba)
  6418. {
  6419. int i, totiocbsize = 0;
  6420. struct lpfc_sli *psli = &phba->sli;
  6421. struct lpfc_sli_ring *pring;
  6422. psli->num_rings = MAX_CONFIGURED_RINGS;
  6423. psli->sli_flag = 0;
  6424. psli->fcp_ring = LPFC_FCP_RING;
  6425. psli->next_ring = LPFC_FCP_NEXT_RING;
  6426. psli->extra_ring = LPFC_EXTRA_RING;
  6427. psli->iocbq_lookup = NULL;
  6428. psli->iocbq_lookup_len = 0;
  6429. psli->last_iotag = 0;
  6430. for (i = 0; i < psli->num_rings; i++) {
  6431. pring = &psli->ring[i];
  6432. switch (i) {
  6433. case LPFC_FCP_RING: /* ring 0 - FCP */
  6434. /* numCiocb and numRiocb are used in config_port */
  6435. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6436. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6437. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6438. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6439. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6440. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6441. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6442. SLI3_IOCB_CMD_SIZE :
  6443. SLI2_IOCB_CMD_SIZE;
  6444. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6445. SLI3_IOCB_RSP_SIZE :
  6446. SLI2_IOCB_RSP_SIZE;
  6447. pring->iotag_ctr = 0;
  6448. pring->iotag_max =
  6449. (phba->cfg_hba_queue_depth * 2);
  6450. pring->fast_iotag = pring->iotag_max;
  6451. pring->num_mask = 0;
  6452. break;
  6453. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6454. /* numCiocb and numRiocb are used in config_port */
  6455. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6456. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6457. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6458. SLI3_IOCB_CMD_SIZE :
  6459. SLI2_IOCB_CMD_SIZE;
  6460. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6461. SLI3_IOCB_RSP_SIZE :
  6462. SLI2_IOCB_RSP_SIZE;
  6463. pring->iotag_max = phba->cfg_hba_queue_depth;
  6464. pring->num_mask = 0;
  6465. break;
  6466. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6467. /* numCiocb and numRiocb are used in config_port */
  6468. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6469. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6470. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6471. SLI3_IOCB_CMD_SIZE :
  6472. SLI2_IOCB_CMD_SIZE;
  6473. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6474. SLI3_IOCB_RSP_SIZE :
  6475. SLI2_IOCB_RSP_SIZE;
  6476. pring->fast_iotag = 0;
  6477. pring->iotag_ctr = 0;
  6478. pring->iotag_max = 4096;
  6479. pring->lpfc_sli_rcv_async_status =
  6480. lpfc_sli_async_event_handler;
  6481. pring->num_mask = LPFC_MAX_RING_MASK;
  6482. pring->prt[0].profile = 0; /* Mask 0 */
  6483. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6484. pring->prt[0].type = FC_TYPE_ELS;
  6485. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6486. lpfc_els_unsol_event;
  6487. pring->prt[1].profile = 0; /* Mask 1 */
  6488. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6489. pring->prt[1].type = FC_TYPE_ELS;
  6490. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6491. lpfc_els_unsol_event;
  6492. pring->prt[2].profile = 0; /* Mask 2 */
  6493. /* NameServer Inquiry */
  6494. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6495. /* NameServer */
  6496. pring->prt[2].type = FC_TYPE_CT;
  6497. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6498. lpfc_ct_unsol_event;
  6499. pring->prt[3].profile = 0; /* Mask 3 */
  6500. /* NameServer response */
  6501. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6502. /* NameServer */
  6503. pring->prt[3].type = FC_TYPE_CT;
  6504. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6505. lpfc_ct_unsol_event;
  6506. /* abort unsolicited sequence */
  6507. pring->prt[4].profile = 0; /* Mask 4 */
  6508. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6509. pring->prt[4].type = FC_TYPE_BLS;
  6510. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6511. lpfc_sli4_ct_abort_unsol_event;
  6512. break;
  6513. }
  6514. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6515. (pring->numRiocb * pring->sizeRiocb);
  6516. }
  6517. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6518. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6519. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6520. "SLI2 SLIM Data: x%x x%lx\n",
  6521. phba->brd_no, totiocbsize,
  6522. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6523. }
  6524. if (phba->cfg_multi_ring_support == 2)
  6525. lpfc_extra_ring_setup(phba);
  6526. return 0;
  6527. }
  6528. /**
  6529. * lpfc_sli_queue_setup - Queue initialization function
  6530. * @phba: Pointer to HBA context object.
  6531. *
  6532. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6533. * ring. This function also initializes ring indices of each ring.
  6534. * This function is called during the initialization of the SLI
  6535. * interface of an HBA.
  6536. * This function is called with no lock held and always returns
  6537. * 1.
  6538. **/
  6539. int
  6540. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6541. {
  6542. struct lpfc_sli *psli;
  6543. struct lpfc_sli_ring *pring;
  6544. int i;
  6545. psli = &phba->sli;
  6546. spin_lock_irq(&phba->hbalock);
  6547. INIT_LIST_HEAD(&psli->mboxq);
  6548. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6549. /* Initialize list headers for txq and txcmplq as double linked lists */
  6550. for (i = 0; i < psli->num_rings; i++) {
  6551. pring = &psli->ring[i];
  6552. pring->ringno = i;
  6553. pring->next_cmdidx = 0;
  6554. pring->local_getidx = 0;
  6555. pring->cmdidx = 0;
  6556. INIT_LIST_HEAD(&pring->txq);
  6557. INIT_LIST_HEAD(&pring->txcmplq);
  6558. INIT_LIST_HEAD(&pring->iocb_continueq);
  6559. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6560. INIT_LIST_HEAD(&pring->postbufq);
  6561. }
  6562. spin_unlock_irq(&phba->hbalock);
  6563. return 1;
  6564. }
  6565. /**
  6566. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6567. * @phba: Pointer to HBA context object.
  6568. *
  6569. * This routine flushes the mailbox command subsystem. It will unconditionally
  6570. * flush all the mailbox commands in the three possible stages in the mailbox
  6571. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6572. * command; and completed mailbox command queue. It is caller's responsibility
  6573. * to make sure that the driver is in the proper state to flush the mailbox
  6574. * command sub-system. Namely, the posting of mailbox commands into the
  6575. * pending mailbox command queue from the various clients must be stopped;
  6576. * either the HBA is in a state that it will never works on the outstanding
  6577. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6578. * mailbox command has been completed.
  6579. **/
  6580. static void
  6581. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6582. {
  6583. LIST_HEAD(completions);
  6584. struct lpfc_sli *psli = &phba->sli;
  6585. LPFC_MBOXQ_t *pmb;
  6586. unsigned long iflag;
  6587. /* Flush all the mailbox commands in the mbox system */
  6588. spin_lock_irqsave(&phba->hbalock, iflag);
  6589. /* The pending mailbox command queue */
  6590. list_splice_init(&phba->sli.mboxq, &completions);
  6591. /* The outstanding active mailbox command */
  6592. if (psli->mbox_active) {
  6593. list_add_tail(&psli->mbox_active->list, &completions);
  6594. psli->mbox_active = NULL;
  6595. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6596. }
  6597. /* The completed mailbox command queue */
  6598. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6599. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6600. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6601. while (!list_empty(&completions)) {
  6602. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6603. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6604. if (pmb->mbox_cmpl)
  6605. pmb->mbox_cmpl(phba, pmb);
  6606. }
  6607. }
  6608. /**
  6609. * lpfc_sli_host_down - Vport cleanup function
  6610. * @vport: Pointer to virtual port object.
  6611. *
  6612. * lpfc_sli_host_down is called to clean up the resources
  6613. * associated with a vport before destroying virtual
  6614. * port data structures.
  6615. * This function does following operations:
  6616. * - Free discovery resources associated with this virtual
  6617. * port.
  6618. * - Free iocbs associated with this virtual port in
  6619. * the txq.
  6620. * - Send abort for all iocb commands associated with this
  6621. * vport in txcmplq.
  6622. *
  6623. * This function is called with no lock held and always returns 1.
  6624. **/
  6625. int
  6626. lpfc_sli_host_down(struct lpfc_vport *vport)
  6627. {
  6628. LIST_HEAD(completions);
  6629. struct lpfc_hba *phba = vport->phba;
  6630. struct lpfc_sli *psli = &phba->sli;
  6631. struct lpfc_sli_ring *pring;
  6632. struct lpfc_iocbq *iocb, *next_iocb;
  6633. int i;
  6634. unsigned long flags = 0;
  6635. uint16_t prev_pring_flag;
  6636. lpfc_cleanup_discovery_resources(vport);
  6637. spin_lock_irqsave(&phba->hbalock, flags);
  6638. for (i = 0; i < psli->num_rings; i++) {
  6639. pring = &psli->ring[i];
  6640. prev_pring_flag = pring->flag;
  6641. /* Only slow rings */
  6642. if (pring->ringno == LPFC_ELS_RING) {
  6643. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6644. /* Set the lpfc data pending flag */
  6645. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6646. }
  6647. /*
  6648. * Error everything on the txq since these iocbs have not been
  6649. * given to the FW yet.
  6650. */
  6651. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6652. if (iocb->vport != vport)
  6653. continue;
  6654. list_move_tail(&iocb->list, &completions);
  6655. pring->txq_cnt--;
  6656. }
  6657. /* Next issue ABTS for everything on the txcmplq */
  6658. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6659. list) {
  6660. if (iocb->vport != vport)
  6661. continue;
  6662. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6663. }
  6664. pring->flag = prev_pring_flag;
  6665. }
  6666. spin_unlock_irqrestore(&phba->hbalock, flags);
  6667. /* Cancel all the IOCBs from the completions list */
  6668. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6669. IOERR_SLI_DOWN);
  6670. return 1;
  6671. }
  6672. /**
  6673. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6674. * @phba: Pointer to HBA context object.
  6675. *
  6676. * This function cleans up all iocb, buffers, mailbox commands
  6677. * while shutting down the HBA. This function is called with no
  6678. * lock held and always returns 1.
  6679. * This function does the following to cleanup driver resources:
  6680. * - Free discovery resources for each virtual port
  6681. * - Cleanup any pending fabric iocbs
  6682. * - Iterate through the iocb txq and free each entry
  6683. * in the list.
  6684. * - Free up any buffer posted to the HBA
  6685. * - Free mailbox commands in the mailbox queue.
  6686. **/
  6687. int
  6688. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6689. {
  6690. LIST_HEAD(completions);
  6691. struct lpfc_sli *psli = &phba->sli;
  6692. struct lpfc_sli_ring *pring;
  6693. struct lpfc_dmabuf *buf_ptr;
  6694. unsigned long flags = 0;
  6695. int i;
  6696. /* Shutdown the mailbox command sub-system */
  6697. lpfc_sli_mbox_sys_shutdown(phba);
  6698. lpfc_hba_down_prep(phba);
  6699. lpfc_fabric_abort_hba(phba);
  6700. spin_lock_irqsave(&phba->hbalock, flags);
  6701. for (i = 0; i < psli->num_rings; i++) {
  6702. pring = &psli->ring[i];
  6703. /* Only slow rings */
  6704. if (pring->ringno == LPFC_ELS_RING) {
  6705. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6706. /* Set the lpfc data pending flag */
  6707. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6708. }
  6709. /*
  6710. * Error everything on the txq since these iocbs have not been
  6711. * given to the FW yet.
  6712. */
  6713. list_splice_init(&pring->txq, &completions);
  6714. pring->txq_cnt = 0;
  6715. }
  6716. spin_unlock_irqrestore(&phba->hbalock, flags);
  6717. /* Cancel all the IOCBs from the completions list */
  6718. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6719. IOERR_SLI_DOWN);
  6720. spin_lock_irqsave(&phba->hbalock, flags);
  6721. list_splice_init(&phba->elsbuf, &completions);
  6722. phba->elsbuf_cnt = 0;
  6723. phba->elsbuf_prev_cnt = 0;
  6724. spin_unlock_irqrestore(&phba->hbalock, flags);
  6725. while (!list_empty(&completions)) {
  6726. list_remove_head(&completions, buf_ptr,
  6727. struct lpfc_dmabuf, list);
  6728. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6729. kfree(buf_ptr);
  6730. }
  6731. /* Return any active mbox cmds */
  6732. del_timer_sync(&psli->mbox_tmo);
  6733. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6734. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6735. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6736. return 1;
  6737. }
  6738. /**
  6739. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6740. * @srcp: Source memory pointer.
  6741. * @destp: Destination memory pointer.
  6742. * @cnt: Number of words required to be copied.
  6743. *
  6744. * This function is used for copying data between driver memory
  6745. * and the SLI memory. This function also changes the endianness
  6746. * of each word if native endianness is different from SLI
  6747. * endianness. This function can be called with or without
  6748. * lock.
  6749. **/
  6750. void
  6751. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6752. {
  6753. uint32_t *src = srcp;
  6754. uint32_t *dest = destp;
  6755. uint32_t ldata;
  6756. int i;
  6757. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6758. ldata = *src;
  6759. ldata = le32_to_cpu(ldata);
  6760. *dest = ldata;
  6761. src++;
  6762. dest++;
  6763. }
  6764. }
  6765. /**
  6766. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6767. * @srcp: Source memory pointer.
  6768. * @destp: Destination memory pointer.
  6769. * @cnt: Number of words required to be copied.
  6770. *
  6771. * This function is used for copying data between a data structure
  6772. * with big endian representation to local endianness.
  6773. * This function can be called with or without lock.
  6774. **/
  6775. void
  6776. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6777. {
  6778. uint32_t *src = srcp;
  6779. uint32_t *dest = destp;
  6780. uint32_t ldata;
  6781. int i;
  6782. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6783. ldata = *src;
  6784. ldata = be32_to_cpu(ldata);
  6785. *dest = ldata;
  6786. src++;
  6787. dest++;
  6788. }
  6789. }
  6790. /**
  6791. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6792. * @phba: Pointer to HBA context object.
  6793. * @pring: Pointer to driver SLI ring object.
  6794. * @mp: Pointer to driver buffer object.
  6795. *
  6796. * This function is called with no lock held.
  6797. * It always return zero after adding the buffer to the postbufq
  6798. * buffer list.
  6799. **/
  6800. int
  6801. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6802. struct lpfc_dmabuf *mp)
  6803. {
  6804. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6805. later */
  6806. spin_lock_irq(&phba->hbalock);
  6807. list_add_tail(&mp->list, &pring->postbufq);
  6808. pring->postbufq_cnt++;
  6809. spin_unlock_irq(&phba->hbalock);
  6810. return 0;
  6811. }
  6812. /**
  6813. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6814. * @phba: Pointer to HBA context object.
  6815. *
  6816. * When HBQ is enabled, buffers are searched based on tags. This function
  6817. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6818. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6819. * does not conflict with tags of buffer posted for unsolicited events.
  6820. * The function returns the allocated tag. The function is called with
  6821. * no locks held.
  6822. **/
  6823. uint32_t
  6824. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6825. {
  6826. spin_lock_irq(&phba->hbalock);
  6827. phba->buffer_tag_count++;
  6828. /*
  6829. * Always set the QUE_BUFTAG_BIT to distiguish between
  6830. * a tag assigned by HBQ.
  6831. */
  6832. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6833. spin_unlock_irq(&phba->hbalock);
  6834. return phba->buffer_tag_count;
  6835. }
  6836. /**
  6837. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6838. * @phba: Pointer to HBA context object.
  6839. * @pring: Pointer to driver SLI ring object.
  6840. * @tag: Buffer tag.
  6841. *
  6842. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6843. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6844. * iocb is posted to the response ring with the tag of the buffer.
  6845. * This function searches the pring->postbufq list using the tag
  6846. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6847. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6848. * buffer is returned to the caller else NULL is returned.
  6849. * This function is called with no lock held.
  6850. **/
  6851. struct lpfc_dmabuf *
  6852. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6853. uint32_t tag)
  6854. {
  6855. struct lpfc_dmabuf *mp, *next_mp;
  6856. struct list_head *slp = &pring->postbufq;
  6857. /* Search postbufq, from the beginning, looking for a match on tag */
  6858. spin_lock_irq(&phba->hbalock);
  6859. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6860. if (mp->buffer_tag == tag) {
  6861. list_del_init(&mp->list);
  6862. pring->postbufq_cnt--;
  6863. spin_unlock_irq(&phba->hbalock);
  6864. return mp;
  6865. }
  6866. }
  6867. spin_unlock_irq(&phba->hbalock);
  6868. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6869. "0402 Cannot find virtual addr for buffer tag on "
  6870. "ring %d Data x%lx x%p x%p x%x\n",
  6871. pring->ringno, (unsigned long) tag,
  6872. slp->next, slp->prev, pring->postbufq_cnt);
  6873. return NULL;
  6874. }
  6875. /**
  6876. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6877. * @phba: Pointer to HBA context object.
  6878. * @pring: Pointer to driver SLI ring object.
  6879. * @phys: DMA address of the buffer.
  6880. *
  6881. * This function searches the buffer list using the dma_address
  6882. * of unsolicited event to find the driver's lpfc_dmabuf object
  6883. * corresponding to the dma_address. The function returns the
  6884. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6885. * This function is called by the ct and els unsolicited event
  6886. * handlers to get the buffer associated with the unsolicited
  6887. * event.
  6888. *
  6889. * This function is called with no lock held.
  6890. **/
  6891. struct lpfc_dmabuf *
  6892. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6893. dma_addr_t phys)
  6894. {
  6895. struct lpfc_dmabuf *mp, *next_mp;
  6896. struct list_head *slp = &pring->postbufq;
  6897. /* Search postbufq, from the beginning, looking for a match on phys */
  6898. spin_lock_irq(&phba->hbalock);
  6899. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6900. if (mp->phys == phys) {
  6901. list_del_init(&mp->list);
  6902. pring->postbufq_cnt--;
  6903. spin_unlock_irq(&phba->hbalock);
  6904. return mp;
  6905. }
  6906. }
  6907. spin_unlock_irq(&phba->hbalock);
  6908. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6909. "0410 Cannot find virtual addr for mapped buf on "
  6910. "ring %d Data x%llx x%p x%p x%x\n",
  6911. pring->ringno, (unsigned long long)phys,
  6912. slp->next, slp->prev, pring->postbufq_cnt);
  6913. return NULL;
  6914. }
  6915. /**
  6916. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6917. * @phba: Pointer to HBA context object.
  6918. * @cmdiocb: Pointer to driver command iocb object.
  6919. * @rspiocb: Pointer to driver response iocb object.
  6920. *
  6921. * This function is the completion handler for the abort iocbs for
  6922. * ELS commands. This function is called from the ELS ring event
  6923. * handler with no lock held. This function frees memory resources
  6924. * associated with the abort iocb.
  6925. **/
  6926. static void
  6927. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6928. struct lpfc_iocbq *rspiocb)
  6929. {
  6930. IOCB_t *irsp = &rspiocb->iocb;
  6931. uint16_t abort_iotag, abort_context;
  6932. struct lpfc_iocbq *abort_iocb;
  6933. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6934. abort_iocb = NULL;
  6935. if (irsp->ulpStatus) {
  6936. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6937. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6938. spin_lock_irq(&phba->hbalock);
  6939. if (phba->sli_rev < LPFC_SLI_REV4) {
  6940. if (abort_iotag != 0 &&
  6941. abort_iotag <= phba->sli.last_iotag)
  6942. abort_iocb =
  6943. phba->sli.iocbq_lookup[abort_iotag];
  6944. } else
  6945. /* For sli4 the abort_tag is the XRI,
  6946. * so the abort routine puts the iotag of the iocb
  6947. * being aborted in the context field of the abort
  6948. * IOCB.
  6949. */
  6950. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6951. /*
  6952. * If the iocb is not found in Firmware queue the iocb
  6953. * might have completed already. Do not free it again.
  6954. */
  6955. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6956. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6957. spin_unlock_irq(&phba->hbalock);
  6958. lpfc_sli_release_iocbq(phba, cmdiocb);
  6959. return;
  6960. }
  6961. /* For SLI4 the ulpContext field for abort IOCB
  6962. * holds the iotag of the IOCB being aborted so
  6963. * the local abort_context needs to be reset to
  6964. * match the aborted IOCBs ulpContext.
  6965. */
  6966. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6967. abort_context = abort_iocb->iocb.ulpContext;
  6968. }
  6969. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6970. "0327 Cannot abort els iocb %p "
  6971. "with tag %x context %x, abort status %x, "
  6972. "abort code %x\n",
  6973. abort_iocb, abort_iotag, abort_context,
  6974. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6975. /*
  6976. * make sure we have the right iocbq before taking it
  6977. * off the txcmplq and try to call completion routine.
  6978. */
  6979. if (!abort_iocb ||
  6980. abort_iocb->iocb.ulpContext != abort_context ||
  6981. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6982. spin_unlock_irq(&phba->hbalock);
  6983. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6984. /*
  6985. * leave the SLI4 aborted command on the txcmplq
  6986. * list and the command complete WCQE's XB bit
  6987. * will tell whether the SGL (XRI) can be released
  6988. * immediately or to the aborted SGL list for the
  6989. * following abort XRI from the HBA.
  6990. */
  6991. list_del_init(&abort_iocb->list);
  6992. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6993. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6994. pring->txcmplq_cnt--;
  6995. }
  6996. /* Firmware could still be in progress of DMAing
  6997. * payload, so don't free data buffer till after
  6998. * a hbeat.
  6999. */
  7000. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  7001. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  7002. spin_unlock_irq(&phba->hbalock);
  7003. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  7004. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  7005. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  7006. } else
  7007. spin_unlock_irq(&phba->hbalock);
  7008. }
  7009. lpfc_sli_release_iocbq(phba, cmdiocb);
  7010. return;
  7011. }
  7012. /**
  7013. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  7014. * @phba: Pointer to HBA context object.
  7015. * @cmdiocb: Pointer to driver command iocb object.
  7016. * @rspiocb: Pointer to driver response iocb object.
  7017. *
  7018. * The function is called from SLI ring event handler with no
  7019. * lock held. This function is the completion handler for ELS commands
  7020. * which are aborted. The function frees memory resources used for
  7021. * the aborted ELS commands.
  7022. **/
  7023. static void
  7024. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7025. struct lpfc_iocbq *rspiocb)
  7026. {
  7027. IOCB_t *irsp = &rspiocb->iocb;
  7028. /* ELS cmd tag <ulpIoTag> completes */
  7029. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  7030. "0139 Ignoring ELS cmd tag x%x completion Data: "
  7031. "x%x x%x x%x\n",
  7032. irsp->ulpIoTag, irsp->ulpStatus,
  7033. irsp->un.ulpWord[4], irsp->ulpTimeout);
  7034. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  7035. lpfc_ct_free_iocb(phba, cmdiocb);
  7036. else
  7037. lpfc_els_free_iocb(phba, cmdiocb);
  7038. return;
  7039. }
  7040. /**
  7041. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  7042. * @phba: Pointer to HBA context object.
  7043. * @pring: Pointer to driver SLI ring object.
  7044. * @cmdiocb: Pointer to driver command iocb object.
  7045. *
  7046. * This function issues an abort iocb for the provided command iocb down to
  7047. * the port. Other than the case the outstanding command iocb is an abort
  7048. * request, this function issues abort out unconditionally. This function is
  7049. * called with hbalock held. The function returns 0 when it fails due to
  7050. * memory allocation failure or when the command iocb is an abort request.
  7051. **/
  7052. static int
  7053. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7054. struct lpfc_iocbq *cmdiocb)
  7055. {
  7056. struct lpfc_vport *vport = cmdiocb->vport;
  7057. struct lpfc_iocbq *abtsiocbp;
  7058. IOCB_t *icmd = NULL;
  7059. IOCB_t *iabt = NULL;
  7060. int retval;
  7061. /*
  7062. * There are certain command types we don't want to abort. And we
  7063. * don't want to abort commands that are already in the process of
  7064. * being aborted.
  7065. */
  7066. icmd = &cmdiocb->iocb;
  7067. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7068. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7069. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7070. return 0;
  7071. /* issue ABTS for this IOCB based on iotag */
  7072. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7073. if (abtsiocbp == NULL)
  7074. return 0;
  7075. /* This signals the response to set the correct status
  7076. * before calling the completion handler
  7077. */
  7078. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7079. iabt = &abtsiocbp->iocb;
  7080. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7081. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7082. if (phba->sli_rev == LPFC_SLI_REV4) {
  7083. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7084. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7085. }
  7086. else
  7087. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7088. iabt->ulpLe = 1;
  7089. iabt->ulpClass = icmd->ulpClass;
  7090. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7091. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7092. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7093. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7094. if (phba->link_state >= LPFC_LINK_UP)
  7095. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7096. else
  7097. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7098. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7099. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7100. "0339 Abort xri x%x, original iotag x%x, "
  7101. "abort cmd iotag x%x\n",
  7102. iabt->un.acxri.abortIoTag,
  7103. iabt->un.acxri.abortContextTag,
  7104. abtsiocbp->iotag);
  7105. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7106. if (retval)
  7107. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7108. /*
  7109. * Caller to this routine should check for IOCB_ERROR
  7110. * and handle it properly. This routine no longer removes
  7111. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7112. */
  7113. return retval;
  7114. }
  7115. /**
  7116. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7117. * @phba: Pointer to HBA context object.
  7118. * @pring: Pointer to driver SLI ring object.
  7119. * @cmdiocb: Pointer to driver command iocb object.
  7120. *
  7121. * This function issues an abort iocb for the provided command iocb. In case
  7122. * of unloading, the abort iocb will not be issued to commands on the ELS
  7123. * ring. Instead, the callback function shall be changed to those commands
  7124. * so that nothing happens when them finishes. This function is called with
  7125. * hbalock held. The function returns 0 when the command iocb is an abort
  7126. * request.
  7127. **/
  7128. int
  7129. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7130. struct lpfc_iocbq *cmdiocb)
  7131. {
  7132. struct lpfc_vport *vport = cmdiocb->vport;
  7133. int retval = IOCB_ERROR;
  7134. IOCB_t *icmd = NULL;
  7135. /*
  7136. * There are certain command types we don't want to abort. And we
  7137. * don't want to abort commands that are already in the process of
  7138. * being aborted.
  7139. */
  7140. icmd = &cmdiocb->iocb;
  7141. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7142. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7143. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7144. return 0;
  7145. /*
  7146. * If we're unloading, don't abort iocb on the ELS ring, but change
  7147. * the callback so that nothing happens when it finishes.
  7148. */
  7149. if ((vport->load_flag & FC_UNLOADING) &&
  7150. (pring->ringno == LPFC_ELS_RING)) {
  7151. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7152. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7153. else
  7154. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7155. goto abort_iotag_exit;
  7156. }
  7157. /* Now, we try to issue the abort to the cmdiocb out */
  7158. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7159. abort_iotag_exit:
  7160. /*
  7161. * Caller to this routine should check for IOCB_ERROR
  7162. * and handle it properly. This routine no longer removes
  7163. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7164. */
  7165. return retval;
  7166. }
  7167. /**
  7168. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7169. * @phba: Pointer to HBA context object.
  7170. * @pring: Pointer to driver SLI ring object.
  7171. *
  7172. * This function aborts all iocbs in the given ring and frees all the iocb
  7173. * objects in txq. This function issues abort iocbs unconditionally for all
  7174. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7175. * to complete before the return of this function. The caller is not required
  7176. * to hold any locks.
  7177. **/
  7178. static void
  7179. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7180. {
  7181. LIST_HEAD(completions);
  7182. struct lpfc_iocbq *iocb, *next_iocb;
  7183. if (pring->ringno == LPFC_ELS_RING)
  7184. lpfc_fabric_abort_hba(phba);
  7185. spin_lock_irq(&phba->hbalock);
  7186. /* Take off all the iocbs on txq for cancelling */
  7187. list_splice_init(&pring->txq, &completions);
  7188. pring->txq_cnt = 0;
  7189. /* Next issue ABTS for everything on the txcmplq */
  7190. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7191. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7192. spin_unlock_irq(&phba->hbalock);
  7193. /* Cancel all the IOCBs from the completions list */
  7194. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7195. IOERR_SLI_ABORTED);
  7196. }
  7197. /**
  7198. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7199. * @phba: pointer to lpfc HBA data structure.
  7200. *
  7201. * This routine will abort all pending and outstanding iocbs to an HBA.
  7202. **/
  7203. void
  7204. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7205. {
  7206. struct lpfc_sli *psli = &phba->sli;
  7207. struct lpfc_sli_ring *pring;
  7208. int i;
  7209. for (i = 0; i < psli->num_rings; i++) {
  7210. pring = &psli->ring[i];
  7211. lpfc_sli_iocb_ring_abort(phba, pring);
  7212. }
  7213. }
  7214. /**
  7215. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7216. * @iocbq: Pointer to driver iocb object.
  7217. * @vport: Pointer to driver virtual port object.
  7218. * @tgt_id: SCSI ID of the target.
  7219. * @lun_id: LUN ID of the scsi device.
  7220. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7221. *
  7222. * This function acts as an iocb filter for functions which abort or count
  7223. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7224. * 0 if the filtering criteria is met for the given iocb and will return
  7225. * 1 if the filtering criteria is not met.
  7226. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7227. * given iocb is for the SCSI device specified by vport, tgt_id and
  7228. * lun_id parameter.
  7229. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7230. * given iocb is for the SCSI target specified by vport and tgt_id
  7231. * parameters.
  7232. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7233. * given iocb is for the SCSI host associated with the given vport.
  7234. * This function is called with no locks held.
  7235. **/
  7236. static int
  7237. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7238. uint16_t tgt_id, uint64_t lun_id,
  7239. lpfc_ctx_cmd ctx_cmd)
  7240. {
  7241. struct lpfc_scsi_buf *lpfc_cmd;
  7242. int rc = 1;
  7243. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7244. return rc;
  7245. if (iocbq->vport != vport)
  7246. return rc;
  7247. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7248. if (lpfc_cmd->pCmd == NULL)
  7249. return rc;
  7250. switch (ctx_cmd) {
  7251. case LPFC_CTX_LUN:
  7252. if ((lpfc_cmd->rdata->pnode) &&
  7253. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7254. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7255. rc = 0;
  7256. break;
  7257. case LPFC_CTX_TGT:
  7258. if ((lpfc_cmd->rdata->pnode) &&
  7259. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7260. rc = 0;
  7261. break;
  7262. case LPFC_CTX_HOST:
  7263. rc = 0;
  7264. break;
  7265. default:
  7266. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7267. __func__, ctx_cmd);
  7268. break;
  7269. }
  7270. return rc;
  7271. }
  7272. /**
  7273. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7274. * @vport: Pointer to virtual port.
  7275. * @tgt_id: SCSI ID of the target.
  7276. * @lun_id: LUN ID of the scsi device.
  7277. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7278. *
  7279. * This function returns number of FCP commands pending for the vport.
  7280. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7281. * commands pending on the vport associated with SCSI device specified
  7282. * by tgt_id and lun_id parameters.
  7283. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7284. * commands pending on the vport associated with SCSI target specified
  7285. * by tgt_id parameter.
  7286. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7287. * commands pending on the vport.
  7288. * This function returns the number of iocbs which satisfy the filter.
  7289. * This function is called without any lock held.
  7290. **/
  7291. int
  7292. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7293. lpfc_ctx_cmd ctx_cmd)
  7294. {
  7295. struct lpfc_hba *phba = vport->phba;
  7296. struct lpfc_iocbq *iocbq;
  7297. int sum, i;
  7298. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7299. iocbq = phba->sli.iocbq_lookup[i];
  7300. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7301. ctx_cmd) == 0)
  7302. sum++;
  7303. }
  7304. return sum;
  7305. }
  7306. /**
  7307. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7308. * @phba: Pointer to HBA context object
  7309. * @cmdiocb: Pointer to command iocb object.
  7310. * @rspiocb: Pointer to response iocb object.
  7311. *
  7312. * This function is called when an aborted FCP iocb completes. This
  7313. * function is called by the ring event handler with no lock held.
  7314. * This function frees the iocb.
  7315. **/
  7316. void
  7317. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7318. struct lpfc_iocbq *rspiocb)
  7319. {
  7320. lpfc_sli_release_iocbq(phba, cmdiocb);
  7321. return;
  7322. }
  7323. /**
  7324. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7325. * @vport: Pointer to virtual port.
  7326. * @pring: Pointer to driver SLI ring object.
  7327. * @tgt_id: SCSI ID of the target.
  7328. * @lun_id: LUN ID of the scsi device.
  7329. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7330. *
  7331. * This function sends an abort command for every SCSI command
  7332. * associated with the given virtual port pending on the ring
  7333. * filtered by lpfc_sli_validate_fcp_iocb function.
  7334. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7335. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7336. * parameters
  7337. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7338. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7339. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7340. * FCP iocbs associated with virtual port.
  7341. * This function returns number of iocbs it failed to abort.
  7342. * This function is called with no locks held.
  7343. **/
  7344. int
  7345. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7346. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7347. {
  7348. struct lpfc_hba *phba = vport->phba;
  7349. struct lpfc_iocbq *iocbq;
  7350. struct lpfc_iocbq *abtsiocb;
  7351. IOCB_t *cmd = NULL;
  7352. int errcnt = 0, ret_val = 0;
  7353. int i;
  7354. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7355. iocbq = phba->sli.iocbq_lookup[i];
  7356. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7357. abort_cmd) != 0)
  7358. continue;
  7359. /* issue ABTS for this IOCB based on iotag */
  7360. abtsiocb = lpfc_sli_get_iocbq(phba);
  7361. if (abtsiocb == NULL) {
  7362. errcnt++;
  7363. continue;
  7364. }
  7365. cmd = &iocbq->iocb;
  7366. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7367. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7368. if (phba->sli_rev == LPFC_SLI_REV4)
  7369. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7370. else
  7371. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7372. abtsiocb->iocb.ulpLe = 1;
  7373. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7374. abtsiocb->vport = phba->pport;
  7375. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7376. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7377. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7378. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7379. if (lpfc_is_link_up(phba))
  7380. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7381. else
  7382. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7383. /* Setup callback routine and issue the command. */
  7384. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7385. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7386. abtsiocb, 0);
  7387. if (ret_val == IOCB_ERROR) {
  7388. lpfc_sli_release_iocbq(phba, abtsiocb);
  7389. errcnt++;
  7390. continue;
  7391. }
  7392. }
  7393. return errcnt;
  7394. }
  7395. /**
  7396. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7397. * @phba: Pointer to HBA context object.
  7398. * @cmdiocbq: Pointer to command iocb.
  7399. * @rspiocbq: Pointer to response iocb.
  7400. *
  7401. * This function is the completion handler for iocbs issued using
  7402. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7403. * ring event handler function without any lock held. This function
  7404. * can be called from both worker thread context and interrupt
  7405. * context. This function also can be called from other thread which
  7406. * cleans up the SLI layer objects.
  7407. * This function copy the contents of the response iocb to the
  7408. * response iocb memory object provided by the caller of
  7409. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7410. * sleeps for the iocb completion.
  7411. **/
  7412. static void
  7413. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7414. struct lpfc_iocbq *cmdiocbq,
  7415. struct lpfc_iocbq *rspiocbq)
  7416. {
  7417. wait_queue_head_t *pdone_q;
  7418. unsigned long iflags;
  7419. struct lpfc_scsi_buf *lpfc_cmd;
  7420. spin_lock_irqsave(&phba->hbalock, iflags);
  7421. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7422. if (cmdiocbq->context2 && rspiocbq)
  7423. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7424. &rspiocbq->iocb, sizeof(IOCB_t));
  7425. /* Set the exchange busy flag for task management commands */
  7426. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7427. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7428. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7429. cur_iocbq);
  7430. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7431. }
  7432. pdone_q = cmdiocbq->context_un.wait_queue;
  7433. if (pdone_q)
  7434. wake_up(pdone_q);
  7435. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7436. return;
  7437. }
  7438. /**
  7439. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7440. * @phba: Pointer to HBA context object..
  7441. * @piocbq: Pointer to command iocb.
  7442. * @flag: Flag to test.
  7443. *
  7444. * This routine grabs the hbalock and then test the iocb_flag to
  7445. * see if the passed in flag is set.
  7446. * Returns:
  7447. * 1 if flag is set.
  7448. * 0 if flag is not set.
  7449. **/
  7450. static int
  7451. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7452. struct lpfc_iocbq *piocbq, uint32_t flag)
  7453. {
  7454. unsigned long iflags;
  7455. int ret;
  7456. spin_lock_irqsave(&phba->hbalock, iflags);
  7457. ret = piocbq->iocb_flag & flag;
  7458. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7459. return ret;
  7460. }
  7461. /**
  7462. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7463. * @phba: Pointer to HBA context object..
  7464. * @pring: Pointer to sli ring.
  7465. * @piocb: Pointer to command iocb.
  7466. * @prspiocbq: Pointer to response iocb.
  7467. * @timeout: Timeout in number of seconds.
  7468. *
  7469. * This function issues the iocb to firmware and waits for the
  7470. * iocb to complete. If the iocb command is not
  7471. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7472. * Caller should not free the iocb resources if this function
  7473. * returns IOCB_TIMEDOUT.
  7474. * The function waits for the iocb completion using an
  7475. * non-interruptible wait.
  7476. * This function will sleep while waiting for iocb completion.
  7477. * So, this function should not be called from any context which
  7478. * does not allow sleeping. Due to the same reason, this function
  7479. * cannot be called with interrupt disabled.
  7480. * This function assumes that the iocb completions occur while
  7481. * this function sleep. So, this function cannot be called from
  7482. * the thread which process iocb completion for this ring.
  7483. * This function clears the iocb_flag of the iocb object before
  7484. * issuing the iocb and the iocb completion handler sets this
  7485. * flag and wakes this thread when the iocb completes.
  7486. * The contents of the response iocb will be copied to prspiocbq
  7487. * by the completion handler when the command completes.
  7488. * This function returns IOCB_SUCCESS when success.
  7489. * This function is called with no lock held.
  7490. **/
  7491. int
  7492. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7493. uint32_t ring_number,
  7494. struct lpfc_iocbq *piocb,
  7495. struct lpfc_iocbq *prspiocbq,
  7496. uint32_t timeout)
  7497. {
  7498. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7499. long timeleft, timeout_req = 0;
  7500. int retval = IOCB_SUCCESS;
  7501. uint32_t creg_val;
  7502. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7503. /*
  7504. * If the caller has provided a response iocbq buffer, then context2
  7505. * is NULL or its an error.
  7506. */
  7507. if (prspiocbq) {
  7508. if (piocb->context2)
  7509. return IOCB_ERROR;
  7510. piocb->context2 = prspiocbq;
  7511. }
  7512. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7513. piocb->context_un.wait_queue = &done_q;
  7514. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7515. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7516. if (lpfc_readl(phba->HCregaddr, &creg_val))
  7517. return IOCB_ERROR;
  7518. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7519. writel(creg_val, phba->HCregaddr);
  7520. readl(phba->HCregaddr); /* flush */
  7521. }
  7522. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7523. SLI_IOCB_RET_IOCB);
  7524. if (retval == IOCB_SUCCESS) {
  7525. timeout_req = timeout * HZ;
  7526. timeleft = wait_event_timeout(done_q,
  7527. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7528. timeout_req);
  7529. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7530. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7531. "0331 IOCB wake signaled\n");
  7532. } else if (timeleft == 0) {
  7533. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7534. "0338 IOCB wait timeout error - no "
  7535. "wake response Data x%x\n", timeout);
  7536. retval = IOCB_TIMEDOUT;
  7537. } else {
  7538. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7539. "0330 IOCB wake NOT set, "
  7540. "Data x%x x%lx\n",
  7541. timeout, (timeleft / jiffies));
  7542. retval = IOCB_TIMEDOUT;
  7543. }
  7544. } else if (retval == IOCB_BUSY) {
  7545. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7546. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7547. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7548. return retval;
  7549. } else {
  7550. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7551. "0332 IOCB wait issue failed, Data x%x\n",
  7552. retval);
  7553. retval = IOCB_ERROR;
  7554. }
  7555. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7556. if (lpfc_readl(phba->HCregaddr, &creg_val))
  7557. return IOCB_ERROR;
  7558. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7559. writel(creg_val, phba->HCregaddr);
  7560. readl(phba->HCregaddr); /* flush */
  7561. }
  7562. if (prspiocbq)
  7563. piocb->context2 = NULL;
  7564. piocb->context_un.wait_queue = NULL;
  7565. piocb->iocb_cmpl = NULL;
  7566. return retval;
  7567. }
  7568. /**
  7569. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7570. * @phba: Pointer to HBA context object.
  7571. * @pmboxq: Pointer to driver mailbox object.
  7572. * @timeout: Timeout in number of seconds.
  7573. *
  7574. * This function issues the mailbox to firmware and waits for the
  7575. * mailbox command to complete. If the mailbox command is not
  7576. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7577. * The function waits for the mailbox completion using an
  7578. * interruptible wait. If the thread is woken up due to a
  7579. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7580. * should not free the mailbox resources, if this function returns
  7581. * MBX_TIMEOUT.
  7582. * This function will sleep while waiting for mailbox completion.
  7583. * So, this function should not be called from any context which
  7584. * does not allow sleeping. Due to the same reason, this function
  7585. * cannot be called with interrupt disabled.
  7586. * This function assumes that the mailbox completion occurs while
  7587. * this function sleep. So, this function cannot be called from
  7588. * the worker thread which processes mailbox completion.
  7589. * This function is called in the context of HBA management
  7590. * applications.
  7591. * This function returns MBX_SUCCESS when successful.
  7592. * This function is called with no lock held.
  7593. **/
  7594. int
  7595. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7596. uint32_t timeout)
  7597. {
  7598. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7599. int retval;
  7600. unsigned long flag;
  7601. /* The caller must leave context1 empty. */
  7602. if (pmboxq->context1)
  7603. return MBX_NOT_FINISHED;
  7604. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7605. /* setup wake call as IOCB callback */
  7606. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7607. /* setup context field to pass wait_queue pointer to wake function */
  7608. pmboxq->context1 = &done_q;
  7609. /* now issue the command */
  7610. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7611. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7612. wait_event_interruptible_timeout(done_q,
  7613. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7614. timeout * HZ);
  7615. spin_lock_irqsave(&phba->hbalock, flag);
  7616. pmboxq->context1 = NULL;
  7617. /*
  7618. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7619. * else do not free the resources.
  7620. */
  7621. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7622. retval = MBX_SUCCESS;
  7623. lpfc_sli4_swap_str(phba, pmboxq);
  7624. } else {
  7625. retval = MBX_TIMEOUT;
  7626. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7627. }
  7628. spin_unlock_irqrestore(&phba->hbalock, flag);
  7629. }
  7630. return retval;
  7631. }
  7632. /**
  7633. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7634. * @phba: Pointer to HBA context.
  7635. *
  7636. * This function is called to shutdown the driver's mailbox sub-system.
  7637. * It first marks the mailbox sub-system is in a block state to prevent
  7638. * the asynchronous mailbox command from issued off the pending mailbox
  7639. * command queue. If the mailbox command sub-system shutdown is due to
  7640. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7641. * the mailbox sub-system flush routine to forcefully bring down the
  7642. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7643. * as with offline or HBA function reset), this routine will wait for the
  7644. * outstanding mailbox command to complete before invoking the mailbox
  7645. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7646. **/
  7647. void
  7648. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7649. {
  7650. struct lpfc_sli *psli = &phba->sli;
  7651. uint8_t actcmd = MBX_HEARTBEAT;
  7652. unsigned long timeout;
  7653. spin_lock_irq(&phba->hbalock);
  7654. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7655. spin_unlock_irq(&phba->hbalock);
  7656. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7657. spin_lock_irq(&phba->hbalock);
  7658. if (phba->sli.mbox_active)
  7659. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7660. spin_unlock_irq(&phba->hbalock);
  7661. /* Determine how long we might wait for the active mailbox
  7662. * command to be gracefully completed by firmware.
  7663. */
  7664. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7665. 1000) + jiffies;
  7666. while (phba->sli.mbox_active) {
  7667. /* Check active mailbox complete status every 2ms */
  7668. msleep(2);
  7669. if (time_after(jiffies, timeout))
  7670. /* Timeout, let the mailbox flush routine to
  7671. * forcefully release active mailbox command
  7672. */
  7673. break;
  7674. }
  7675. }
  7676. lpfc_sli_mbox_sys_flush(phba);
  7677. }
  7678. /**
  7679. * lpfc_sli_eratt_read - read sli-3 error attention events
  7680. * @phba: Pointer to HBA context.
  7681. *
  7682. * This function is called to read the SLI3 device error attention registers
  7683. * for possible error attention events. The caller must hold the hostlock
  7684. * with spin_lock_irq().
  7685. *
  7686. * This function returns 1 when there is Error Attention in the Host Attention
  7687. * Register and returns 0 otherwise.
  7688. **/
  7689. static int
  7690. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7691. {
  7692. uint32_t ha_copy;
  7693. /* Read chip Host Attention (HA) register */
  7694. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  7695. goto unplug_err;
  7696. if (ha_copy & HA_ERATT) {
  7697. /* Read host status register to retrieve error event */
  7698. if (lpfc_sli_read_hs(phba))
  7699. goto unplug_err;
  7700. /* Check if there is a deferred error condition is active */
  7701. if ((HS_FFER1 & phba->work_hs) &&
  7702. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7703. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7704. phba->hba_flag |= DEFER_ERATT;
  7705. /* Clear all interrupt enable conditions */
  7706. writel(0, phba->HCregaddr);
  7707. readl(phba->HCregaddr);
  7708. }
  7709. /* Set the driver HA work bitmap */
  7710. phba->work_ha |= HA_ERATT;
  7711. /* Indicate polling handles this ERATT */
  7712. phba->hba_flag |= HBA_ERATT_HANDLED;
  7713. return 1;
  7714. }
  7715. return 0;
  7716. unplug_err:
  7717. /* Set the driver HS work bitmap */
  7718. phba->work_hs |= UNPLUG_ERR;
  7719. /* Set the driver HA work bitmap */
  7720. phba->work_ha |= HA_ERATT;
  7721. /* Indicate polling handles this ERATT */
  7722. phba->hba_flag |= HBA_ERATT_HANDLED;
  7723. return 1;
  7724. }
  7725. /**
  7726. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7727. * @phba: Pointer to HBA context.
  7728. *
  7729. * This function is called to read the SLI4 device error attention registers
  7730. * for possible error attention events. The caller must hold the hostlock
  7731. * with spin_lock_irq().
  7732. *
  7733. * This function returns 1 when there is Error Attention in the Host Attention
  7734. * Register and returns 0 otherwise.
  7735. **/
  7736. static int
  7737. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7738. {
  7739. uint32_t uerr_sta_hi, uerr_sta_lo;
  7740. uint32_t if_type, portsmphr;
  7741. struct lpfc_register portstat_reg;
  7742. /*
  7743. * For now, use the SLI4 device internal unrecoverable error
  7744. * registers for error attention. This can be changed later.
  7745. */
  7746. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7747. switch (if_type) {
  7748. case LPFC_SLI_INTF_IF_TYPE_0:
  7749. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  7750. &uerr_sta_lo) ||
  7751. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  7752. &uerr_sta_hi)) {
  7753. phba->work_hs |= UNPLUG_ERR;
  7754. phba->work_ha |= HA_ERATT;
  7755. phba->hba_flag |= HBA_ERATT_HANDLED;
  7756. return 1;
  7757. }
  7758. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7759. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7760. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7761. "1423 HBA Unrecoverable error: "
  7762. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7763. "ue_mask_lo_reg=0x%x, "
  7764. "ue_mask_hi_reg=0x%x\n",
  7765. uerr_sta_lo, uerr_sta_hi,
  7766. phba->sli4_hba.ue_mask_lo,
  7767. phba->sli4_hba.ue_mask_hi);
  7768. phba->work_status[0] = uerr_sta_lo;
  7769. phba->work_status[1] = uerr_sta_hi;
  7770. phba->work_ha |= HA_ERATT;
  7771. phba->hba_flag |= HBA_ERATT_HANDLED;
  7772. return 1;
  7773. }
  7774. break;
  7775. case LPFC_SLI_INTF_IF_TYPE_2:
  7776. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  7777. &portstat_reg.word0) ||
  7778. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  7779. &portsmphr)){
  7780. phba->work_hs |= UNPLUG_ERR;
  7781. phba->work_ha |= HA_ERATT;
  7782. phba->hba_flag |= HBA_ERATT_HANDLED;
  7783. return 1;
  7784. }
  7785. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  7786. phba->work_status[0] =
  7787. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  7788. phba->work_status[1] =
  7789. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  7790. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7791. "2885 Port Error Detected: "
  7792. "port status reg 0x%x, "
  7793. "port smphr reg 0x%x, "
  7794. "error 1=0x%x, error 2=0x%x\n",
  7795. portstat_reg.word0,
  7796. portsmphr,
  7797. phba->work_status[0],
  7798. phba->work_status[1]);
  7799. phba->work_ha |= HA_ERATT;
  7800. phba->hba_flag |= HBA_ERATT_HANDLED;
  7801. return 1;
  7802. }
  7803. break;
  7804. case LPFC_SLI_INTF_IF_TYPE_1:
  7805. default:
  7806. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7807. "2886 HBA Error Attention on unsupported "
  7808. "if type %d.", if_type);
  7809. return 1;
  7810. }
  7811. return 0;
  7812. }
  7813. /**
  7814. * lpfc_sli_check_eratt - check error attention events
  7815. * @phba: Pointer to HBA context.
  7816. *
  7817. * This function is called from timer soft interrupt context to check HBA's
  7818. * error attention register bit for error attention events.
  7819. *
  7820. * This function returns 1 when there is Error Attention in the Host Attention
  7821. * Register and returns 0 otherwise.
  7822. **/
  7823. int
  7824. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7825. {
  7826. uint32_t ha_copy;
  7827. /* If somebody is waiting to handle an eratt, don't process it
  7828. * here. The brdkill function will do this.
  7829. */
  7830. if (phba->link_flag & LS_IGNORE_ERATT)
  7831. return 0;
  7832. /* Check if interrupt handler handles this ERATT */
  7833. spin_lock_irq(&phba->hbalock);
  7834. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7835. /* Interrupt handler has handled ERATT */
  7836. spin_unlock_irq(&phba->hbalock);
  7837. return 0;
  7838. }
  7839. /*
  7840. * If there is deferred error attention, do not check for error
  7841. * attention
  7842. */
  7843. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7844. spin_unlock_irq(&phba->hbalock);
  7845. return 0;
  7846. }
  7847. /* If PCI channel is offline, don't process it */
  7848. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7849. spin_unlock_irq(&phba->hbalock);
  7850. return 0;
  7851. }
  7852. switch (phba->sli_rev) {
  7853. case LPFC_SLI_REV2:
  7854. case LPFC_SLI_REV3:
  7855. /* Read chip Host Attention (HA) register */
  7856. ha_copy = lpfc_sli_eratt_read(phba);
  7857. break;
  7858. case LPFC_SLI_REV4:
  7859. /* Read device Uncoverable Error (UERR) registers */
  7860. ha_copy = lpfc_sli4_eratt_read(phba);
  7861. break;
  7862. default:
  7863. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7864. "0299 Invalid SLI revision (%d)\n",
  7865. phba->sli_rev);
  7866. ha_copy = 0;
  7867. break;
  7868. }
  7869. spin_unlock_irq(&phba->hbalock);
  7870. return ha_copy;
  7871. }
  7872. /**
  7873. * lpfc_intr_state_check - Check device state for interrupt handling
  7874. * @phba: Pointer to HBA context.
  7875. *
  7876. * This inline routine checks whether a device or its PCI slot is in a state
  7877. * that the interrupt should be handled.
  7878. *
  7879. * This function returns 0 if the device or the PCI slot is in a state that
  7880. * interrupt should be handled, otherwise -EIO.
  7881. */
  7882. static inline int
  7883. lpfc_intr_state_check(struct lpfc_hba *phba)
  7884. {
  7885. /* If the pci channel is offline, ignore all the interrupts */
  7886. if (unlikely(pci_channel_offline(phba->pcidev)))
  7887. return -EIO;
  7888. /* Update device level interrupt statistics */
  7889. phba->sli.slistat.sli_intr++;
  7890. /* Ignore all interrupts during initialization. */
  7891. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7892. return -EIO;
  7893. return 0;
  7894. }
  7895. /**
  7896. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7897. * @irq: Interrupt number.
  7898. * @dev_id: The device context pointer.
  7899. *
  7900. * This function is directly called from the PCI layer as an interrupt
  7901. * service routine when device with SLI-3 interface spec is enabled with
  7902. * MSI-X multi-message interrupt mode and there are slow-path events in
  7903. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7904. * interrupt mode, this function is called as part of the device-level
  7905. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7906. * is undergoing initialization, the interrupt handler will not process
  7907. * the interrupt. The link attention and ELS ring attention events are
  7908. * handled by the worker thread. The interrupt handler signals the worker
  7909. * thread and returns for these events. This function is called without
  7910. * any lock held. It gets the hbalock to access and update SLI data
  7911. * structures.
  7912. *
  7913. * This function returns IRQ_HANDLED when interrupt is handled else it
  7914. * returns IRQ_NONE.
  7915. **/
  7916. irqreturn_t
  7917. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7918. {
  7919. struct lpfc_hba *phba;
  7920. uint32_t ha_copy, hc_copy;
  7921. uint32_t work_ha_copy;
  7922. unsigned long status;
  7923. unsigned long iflag;
  7924. uint32_t control;
  7925. MAILBOX_t *mbox, *pmbox;
  7926. struct lpfc_vport *vport;
  7927. struct lpfc_nodelist *ndlp;
  7928. struct lpfc_dmabuf *mp;
  7929. LPFC_MBOXQ_t *pmb;
  7930. int rc;
  7931. /*
  7932. * Get the driver's phba structure from the dev_id and
  7933. * assume the HBA is not interrupting.
  7934. */
  7935. phba = (struct lpfc_hba *)dev_id;
  7936. if (unlikely(!phba))
  7937. return IRQ_NONE;
  7938. /*
  7939. * Stuff needs to be attented to when this function is invoked as an
  7940. * individual interrupt handler in MSI-X multi-message interrupt mode
  7941. */
  7942. if (phba->intr_type == MSIX) {
  7943. /* Check device state for handling interrupt */
  7944. if (lpfc_intr_state_check(phba))
  7945. return IRQ_NONE;
  7946. /* Need to read HA REG for slow-path events */
  7947. spin_lock_irqsave(&phba->hbalock, iflag);
  7948. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  7949. goto unplug_error;
  7950. /* If somebody is waiting to handle an eratt don't process it
  7951. * here. The brdkill function will do this.
  7952. */
  7953. if (phba->link_flag & LS_IGNORE_ERATT)
  7954. ha_copy &= ~HA_ERATT;
  7955. /* Check the need for handling ERATT in interrupt handler */
  7956. if (ha_copy & HA_ERATT) {
  7957. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7958. /* ERATT polling has handled ERATT */
  7959. ha_copy &= ~HA_ERATT;
  7960. else
  7961. /* Indicate interrupt handler handles ERATT */
  7962. phba->hba_flag |= HBA_ERATT_HANDLED;
  7963. }
  7964. /*
  7965. * If there is deferred error attention, do not check for any
  7966. * interrupt.
  7967. */
  7968. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7969. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7970. return IRQ_NONE;
  7971. }
  7972. /* Clear up only attention source related to slow-path */
  7973. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  7974. goto unplug_error;
  7975. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7976. HC_LAINT_ENA | HC_ERINT_ENA),
  7977. phba->HCregaddr);
  7978. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7979. phba->HAregaddr);
  7980. writel(hc_copy, phba->HCregaddr);
  7981. readl(phba->HAregaddr); /* flush */
  7982. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7983. } else
  7984. ha_copy = phba->ha_copy;
  7985. work_ha_copy = ha_copy & phba->work_ha_mask;
  7986. if (work_ha_copy) {
  7987. if (work_ha_copy & HA_LATT) {
  7988. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7989. /*
  7990. * Turn off Link Attention interrupts
  7991. * until CLEAR_LA done
  7992. */
  7993. spin_lock_irqsave(&phba->hbalock, iflag);
  7994. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7995. if (lpfc_readl(phba->HCregaddr, &control))
  7996. goto unplug_error;
  7997. control &= ~HC_LAINT_ENA;
  7998. writel(control, phba->HCregaddr);
  7999. readl(phba->HCregaddr); /* flush */
  8000. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8001. }
  8002. else
  8003. work_ha_copy &= ~HA_LATT;
  8004. }
  8005. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  8006. /*
  8007. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  8008. * the only slow ring.
  8009. */
  8010. status = (work_ha_copy &
  8011. (HA_RXMASK << (4*LPFC_ELS_RING)));
  8012. status >>= (4*LPFC_ELS_RING);
  8013. if (status & HA_RXMASK) {
  8014. spin_lock_irqsave(&phba->hbalock, iflag);
  8015. if (lpfc_readl(phba->HCregaddr, &control))
  8016. goto unplug_error;
  8017. lpfc_debugfs_slow_ring_trc(phba,
  8018. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  8019. control, status,
  8020. (uint32_t)phba->sli.slistat.sli_intr);
  8021. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  8022. lpfc_debugfs_slow_ring_trc(phba,
  8023. "ISR Disable ring:"
  8024. "pwork:x%x hawork:x%x wait:x%x",
  8025. phba->work_ha, work_ha_copy,
  8026. (uint32_t)((unsigned long)
  8027. &phba->work_waitq));
  8028. control &=
  8029. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  8030. writel(control, phba->HCregaddr);
  8031. readl(phba->HCregaddr); /* flush */
  8032. }
  8033. else {
  8034. lpfc_debugfs_slow_ring_trc(phba,
  8035. "ISR slow ring: pwork:"
  8036. "x%x hawork:x%x wait:x%x",
  8037. phba->work_ha, work_ha_copy,
  8038. (uint32_t)((unsigned long)
  8039. &phba->work_waitq));
  8040. }
  8041. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8042. }
  8043. }
  8044. spin_lock_irqsave(&phba->hbalock, iflag);
  8045. if (work_ha_copy & HA_ERATT) {
  8046. if (lpfc_sli_read_hs(phba))
  8047. goto unplug_error;
  8048. /*
  8049. * Check if there is a deferred error condition
  8050. * is active
  8051. */
  8052. if ((HS_FFER1 & phba->work_hs) &&
  8053. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  8054. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  8055. phba->work_hs)) {
  8056. phba->hba_flag |= DEFER_ERATT;
  8057. /* Clear all interrupt enable conditions */
  8058. writel(0, phba->HCregaddr);
  8059. readl(phba->HCregaddr);
  8060. }
  8061. }
  8062. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  8063. pmb = phba->sli.mbox_active;
  8064. pmbox = &pmb->u.mb;
  8065. mbox = phba->mbox;
  8066. vport = pmb->vport;
  8067. /* First check out the status word */
  8068. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  8069. if (pmbox->mbxOwner != OWN_HOST) {
  8070. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8071. /*
  8072. * Stray Mailbox Interrupt, mbxCommand <cmd>
  8073. * mbxStatus <status>
  8074. */
  8075. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8076. LOG_SLI,
  8077. "(%d):0304 Stray Mailbox "
  8078. "Interrupt mbxCommand x%x "
  8079. "mbxStatus x%x\n",
  8080. (vport ? vport->vpi : 0),
  8081. pmbox->mbxCommand,
  8082. pmbox->mbxStatus);
  8083. /* clear mailbox attention bit */
  8084. work_ha_copy &= ~HA_MBATT;
  8085. } else {
  8086. phba->sli.mbox_active = NULL;
  8087. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8088. phba->last_completion_time = jiffies;
  8089. del_timer(&phba->sli.mbox_tmo);
  8090. if (pmb->mbox_cmpl) {
  8091. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  8092. MAILBOX_CMD_SIZE);
  8093. if (pmb->out_ext_byte_len &&
  8094. pmb->context2)
  8095. lpfc_sli_pcimem_bcopy(
  8096. phba->mbox_ext,
  8097. pmb->context2,
  8098. pmb->out_ext_byte_len);
  8099. }
  8100. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8101. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8102. lpfc_debugfs_disc_trc(vport,
  8103. LPFC_DISC_TRC_MBOX_VPORT,
  8104. "MBOX dflt rpi: : "
  8105. "status:x%x rpi:x%x",
  8106. (uint32_t)pmbox->mbxStatus,
  8107. pmbox->un.varWords[0], 0);
  8108. if (!pmbox->mbxStatus) {
  8109. mp = (struct lpfc_dmabuf *)
  8110. (pmb->context1);
  8111. ndlp = (struct lpfc_nodelist *)
  8112. pmb->context2;
  8113. /* Reg_LOGIN of dflt RPI was
  8114. * successful. new lets get
  8115. * rid of the RPI using the
  8116. * same mbox buffer.
  8117. */
  8118. lpfc_unreg_login(phba,
  8119. vport->vpi,
  8120. pmbox->un.varWords[0],
  8121. pmb);
  8122. pmb->mbox_cmpl =
  8123. lpfc_mbx_cmpl_dflt_rpi;
  8124. pmb->context1 = mp;
  8125. pmb->context2 = ndlp;
  8126. pmb->vport = vport;
  8127. rc = lpfc_sli_issue_mbox(phba,
  8128. pmb,
  8129. MBX_NOWAIT);
  8130. if (rc != MBX_BUSY)
  8131. lpfc_printf_log(phba,
  8132. KERN_ERR,
  8133. LOG_MBOX | LOG_SLI,
  8134. "0350 rc should have"
  8135. "been MBX_BUSY\n");
  8136. if (rc != MBX_NOT_FINISHED)
  8137. goto send_current_mbox;
  8138. }
  8139. }
  8140. spin_lock_irqsave(
  8141. &phba->pport->work_port_lock,
  8142. iflag);
  8143. phba->pport->work_port_events &=
  8144. ~WORKER_MBOX_TMO;
  8145. spin_unlock_irqrestore(
  8146. &phba->pport->work_port_lock,
  8147. iflag);
  8148. lpfc_mbox_cmpl_put(phba, pmb);
  8149. }
  8150. } else
  8151. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8152. if ((work_ha_copy & HA_MBATT) &&
  8153. (phba->sli.mbox_active == NULL)) {
  8154. send_current_mbox:
  8155. /* Process next mailbox command if there is one */
  8156. do {
  8157. rc = lpfc_sli_issue_mbox(phba, NULL,
  8158. MBX_NOWAIT);
  8159. } while (rc == MBX_NOT_FINISHED);
  8160. if (rc != MBX_SUCCESS)
  8161. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8162. LOG_SLI, "0349 rc should be "
  8163. "MBX_SUCCESS\n");
  8164. }
  8165. spin_lock_irqsave(&phba->hbalock, iflag);
  8166. phba->work_ha |= work_ha_copy;
  8167. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8168. lpfc_worker_wake_up(phba);
  8169. }
  8170. return IRQ_HANDLED;
  8171. unplug_error:
  8172. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8173. return IRQ_HANDLED;
  8174. } /* lpfc_sli_sp_intr_handler */
  8175. /**
  8176. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8177. * @irq: Interrupt number.
  8178. * @dev_id: The device context pointer.
  8179. *
  8180. * This function is directly called from the PCI layer as an interrupt
  8181. * service routine when device with SLI-3 interface spec is enabled with
  8182. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8183. * ring event in the HBA. However, when the device is enabled with either
  8184. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8185. * device-level interrupt handler. When the PCI slot is in error recovery
  8186. * or the HBA is undergoing initialization, the interrupt handler will not
  8187. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8188. * the intrrupt context. This function is called without any lock held.
  8189. * It gets the hbalock to access and update SLI data structures.
  8190. *
  8191. * This function returns IRQ_HANDLED when interrupt is handled else it
  8192. * returns IRQ_NONE.
  8193. **/
  8194. irqreturn_t
  8195. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8196. {
  8197. struct lpfc_hba *phba;
  8198. uint32_t ha_copy;
  8199. unsigned long status;
  8200. unsigned long iflag;
  8201. /* Get the driver's phba structure from the dev_id and
  8202. * assume the HBA is not interrupting.
  8203. */
  8204. phba = (struct lpfc_hba *) dev_id;
  8205. if (unlikely(!phba))
  8206. return IRQ_NONE;
  8207. /*
  8208. * Stuff needs to be attented to when this function is invoked as an
  8209. * individual interrupt handler in MSI-X multi-message interrupt mode
  8210. */
  8211. if (phba->intr_type == MSIX) {
  8212. /* Check device state for handling interrupt */
  8213. if (lpfc_intr_state_check(phba))
  8214. return IRQ_NONE;
  8215. /* Need to read HA REG for FCP ring and other ring events */
  8216. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  8217. return IRQ_HANDLED;
  8218. /* Clear up only attention source related to fast-path */
  8219. spin_lock_irqsave(&phba->hbalock, iflag);
  8220. /*
  8221. * If there is deferred error attention, do not check for
  8222. * any interrupt.
  8223. */
  8224. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8225. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8226. return IRQ_NONE;
  8227. }
  8228. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8229. phba->HAregaddr);
  8230. readl(phba->HAregaddr); /* flush */
  8231. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8232. } else
  8233. ha_copy = phba->ha_copy;
  8234. /*
  8235. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8236. */
  8237. ha_copy &= ~(phba->work_ha_mask);
  8238. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8239. status >>= (4*LPFC_FCP_RING);
  8240. if (status & HA_RXMASK)
  8241. lpfc_sli_handle_fast_ring_event(phba,
  8242. &phba->sli.ring[LPFC_FCP_RING],
  8243. status);
  8244. if (phba->cfg_multi_ring_support == 2) {
  8245. /*
  8246. * Process all events on extra ring. Take the optimized path
  8247. * for extra ring IO.
  8248. */
  8249. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8250. status >>= (4*LPFC_EXTRA_RING);
  8251. if (status & HA_RXMASK) {
  8252. lpfc_sli_handle_fast_ring_event(phba,
  8253. &phba->sli.ring[LPFC_EXTRA_RING],
  8254. status);
  8255. }
  8256. }
  8257. return IRQ_HANDLED;
  8258. } /* lpfc_sli_fp_intr_handler */
  8259. /**
  8260. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8261. * @irq: Interrupt number.
  8262. * @dev_id: The device context pointer.
  8263. *
  8264. * This function is the HBA device-level interrupt handler to device with
  8265. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8266. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8267. * requires driver attention. This function invokes the slow-path interrupt
  8268. * attention handling function and fast-path interrupt attention handling
  8269. * function in turn to process the relevant HBA attention events. This
  8270. * function is called without any lock held. It gets the hbalock to access
  8271. * and update SLI data structures.
  8272. *
  8273. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8274. * returns IRQ_NONE.
  8275. **/
  8276. irqreturn_t
  8277. lpfc_sli_intr_handler(int irq, void *dev_id)
  8278. {
  8279. struct lpfc_hba *phba;
  8280. irqreturn_t sp_irq_rc, fp_irq_rc;
  8281. unsigned long status1, status2;
  8282. uint32_t hc_copy;
  8283. /*
  8284. * Get the driver's phba structure from the dev_id and
  8285. * assume the HBA is not interrupting.
  8286. */
  8287. phba = (struct lpfc_hba *) dev_id;
  8288. if (unlikely(!phba))
  8289. return IRQ_NONE;
  8290. /* Check device state for handling interrupt */
  8291. if (lpfc_intr_state_check(phba))
  8292. return IRQ_NONE;
  8293. spin_lock(&phba->hbalock);
  8294. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  8295. spin_unlock(&phba->hbalock);
  8296. return IRQ_HANDLED;
  8297. }
  8298. if (unlikely(!phba->ha_copy)) {
  8299. spin_unlock(&phba->hbalock);
  8300. return IRQ_NONE;
  8301. } else if (phba->ha_copy & HA_ERATT) {
  8302. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8303. /* ERATT polling has handled ERATT */
  8304. phba->ha_copy &= ~HA_ERATT;
  8305. else
  8306. /* Indicate interrupt handler handles ERATT */
  8307. phba->hba_flag |= HBA_ERATT_HANDLED;
  8308. }
  8309. /*
  8310. * If there is deferred error attention, do not check for any interrupt.
  8311. */
  8312. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8313. spin_unlock(&phba->hbalock);
  8314. return IRQ_NONE;
  8315. }
  8316. /* Clear attention sources except link and error attentions */
  8317. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  8318. spin_unlock(&phba->hbalock);
  8319. return IRQ_HANDLED;
  8320. }
  8321. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8322. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8323. phba->HCregaddr);
  8324. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8325. writel(hc_copy, phba->HCregaddr);
  8326. readl(phba->HAregaddr); /* flush */
  8327. spin_unlock(&phba->hbalock);
  8328. /*
  8329. * Invokes slow-path host attention interrupt handling as appropriate.
  8330. */
  8331. /* status of events with mailbox and link attention */
  8332. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8333. /* status of events with ELS ring */
  8334. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8335. status2 >>= (4*LPFC_ELS_RING);
  8336. if (status1 || (status2 & HA_RXMASK))
  8337. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8338. else
  8339. sp_irq_rc = IRQ_NONE;
  8340. /*
  8341. * Invoke fast-path host attention interrupt handling as appropriate.
  8342. */
  8343. /* status of events with FCP ring */
  8344. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8345. status1 >>= (4*LPFC_FCP_RING);
  8346. /* status of events with extra ring */
  8347. if (phba->cfg_multi_ring_support == 2) {
  8348. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8349. status2 >>= (4*LPFC_EXTRA_RING);
  8350. } else
  8351. status2 = 0;
  8352. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8353. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8354. else
  8355. fp_irq_rc = IRQ_NONE;
  8356. /* Return device-level interrupt handling status */
  8357. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8358. } /* lpfc_sli_intr_handler */
  8359. /**
  8360. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8361. * @phba: pointer to lpfc hba data structure.
  8362. *
  8363. * This routine is invoked by the worker thread to process all the pending
  8364. * SLI4 FCP abort XRI events.
  8365. **/
  8366. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8367. {
  8368. struct lpfc_cq_event *cq_event;
  8369. /* First, declare the fcp xri abort event has been handled */
  8370. spin_lock_irq(&phba->hbalock);
  8371. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8372. spin_unlock_irq(&phba->hbalock);
  8373. /* Now, handle all the fcp xri abort events */
  8374. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8375. /* Get the first event from the head of the event queue */
  8376. spin_lock_irq(&phba->hbalock);
  8377. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8378. cq_event, struct lpfc_cq_event, list);
  8379. spin_unlock_irq(&phba->hbalock);
  8380. /* Notify aborted XRI for FCP work queue */
  8381. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8382. /* Free the event processed back to the free pool */
  8383. lpfc_sli4_cq_event_release(phba, cq_event);
  8384. }
  8385. }
  8386. /**
  8387. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8388. * @phba: pointer to lpfc hba data structure.
  8389. *
  8390. * This routine is invoked by the worker thread to process all the pending
  8391. * SLI4 els abort xri events.
  8392. **/
  8393. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8394. {
  8395. struct lpfc_cq_event *cq_event;
  8396. /* First, declare the els xri abort event has been handled */
  8397. spin_lock_irq(&phba->hbalock);
  8398. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8399. spin_unlock_irq(&phba->hbalock);
  8400. /* Now, handle all the els xri abort events */
  8401. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8402. /* Get the first event from the head of the event queue */
  8403. spin_lock_irq(&phba->hbalock);
  8404. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8405. cq_event, struct lpfc_cq_event, list);
  8406. spin_unlock_irq(&phba->hbalock);
  8407. /* Notify aborted XRI for ELS work queue */
  8408. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8409. /* Free the event processed back to the free pool */
  8410. lpfc_sli4_cq_event_release(phba, cq_event);
  8411. }
  8412. }
  8413. /**
  8414. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8415. * @phba: pointer to lpfc hba data structure
  8416. * @pIocbIn: pointer to the rspiocbq
  8417. * @pIocbOut: pointer to the cmdiocbq
  8418. * @wcqe: pointer to the complete wcqe
  8419. *
  8420. * This routine transfers the fields of a command iocbq to a response iocbq
  8421. * by copying all the IOCB fields from command iocbq and transferring the
  8422. * completion status information from the complete wcqe.
  8423. **/
  8424. static void
  8425. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8426. struct lpfc_iocbq *pIocbIn,
  8427. struct lpfc_iocbq *pIocbOut,
  8428. struct lpfc_wcqe_complete *wcqe)
  8429. {
  8430. unsigned long iflags;
  8431. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8432. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8433. sizeof(struct lpfc_iocbq) - offset);
  8434. /* Map WCQE parameters into irspiocb parameters */
  8435. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8436. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8437. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8438. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8439. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8440. wcqe->total_data_placed;
  8441. else
  8442. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8443. else {
  8444. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8445. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8446. }
  8447. /* Pick up HBA exchange busy condition */
  8448. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8449. spin_lock_irqsave(&phba->hbalock, iflags);
  8450. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8451. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8452. }
  8453. }
  8454. /**
  8455. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8456. * @phba: Pointer to HBA context object.
  8457. * @wcqe: Pointer to work-queue completion queue entry.
  8458. *
  8459. * This routine handles an ELS work-queue completion event and construct
  8460. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8461. * discovery engine to handle.
  8462. *
  8463. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8464. **/
  8465. static struct lpfc_iocbq *
  8466. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8467. struct lpfc_iocbq *irspiocbq)
  8468. {
  8469. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8470. struct lpfc_iocbq *cmdiocbq;
  8471. struct lpfc_wcqe_complete *wcqe;
  8472. unsigned long iflags;
  8473. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8474. spin_lock_irqsave(&phba->hbalock, iflags);
  8475. pring->stats.iocb_event++;
  8476. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8477. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8478. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8479. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8480. if (unlikely(!cmdiocbq)) {
  8481. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8482. "0386 ELS complete with no corresponding "
  8483. "cmdiocb: iotag (%d)\n",
  8484. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8485. lpfc_sli_release_iocbq(phba, irspiocbq);
  8486. return NULL;
  8487. }
  8488. /* Fake the irspiocbq and copy necessary response information */
  8489. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8490. return irspiocbq;
  8491. }
  8492. /**
  8493. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8494. * @phba: Pointer to HBA context object.
  8495. * @cqe: Pointer to mailbox completion queue entry.
  8496. *
  8497. * This routine process a mailbox completion queue entry with asynchrous
  8498. * event.
  8499. *
  8500. * Return: true if work posted to worker thread, otherwise false.
  8501. **/
  8502. static bool
  8503. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8504. {
  8505. struct lpfc_cq_event *cq_event;
  8506. unsigned long iflags;
  8507. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8508. "0392 Async Event: word0:x%x, word1:x%x, "
  8509. "word2:x%x, word3:x%x\n", mcqe->word0,
  8510. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8511. /* Allocate a new internal CQ_EVENT entry */
  8512. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8513. if (!cq_event) {
  8514. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8515. "0394 Failed to allocate CQ_EVENT entry\n");
  8516. return false;
  8517. }
  8518. /* Move the CQE into an asynchronous event entry */
  8519. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8520. spin_lock_irqsave(&phba->hbalock, iflags);
  8521. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8522. /* Set the async event flag */
  8523. phba->hba_flag |= ASYNC_EVENT;
  8524. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8525. return true;
  8526. }
  8527. /**
  8528. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8529. * @phba: Pointer to HBA context object.
  8530. * @cqe: Pointer to mailbox completion queue entry.
  8531. *
  8532. * This routine process a mailbox completion queue entry with mailbox
  8533. * completion event.
  8534. *
  8535. * Return: true if work posted to worker thread, otherwise false.
  8536. **/
  8537. static bool
  8538. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8539. {
  8540. uint32_t mcqe_status;
  8541. MAILBOX_t *mbox, *pmbox;
  8542. struct lpfc_mqe *mqe;
  8543. struct lpfc_vport *vport;
  8544. struct lpfc_nodelist *ndlp;
  8545. struct lpfc_dmabuf *mp;
  8546. unsigned long iflags;
  8547. LPFC_MBOXQ_t *pmb;
  8548. bool workposted = false;
  8549. int rc;
  8550. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8551. if (!bf_get(lpfc_trailer_completed, mcqe))
  8552. goto out_no_mqe_complete;
  8553. /* Get the reference to the active mbox command */
  8554. spin_lock_irqsave(&phba->hbalock, iflags);
  8555. pmb = phba->sli.mbox_active;
  8556. if (unlikely(!pmb)) {
  8557. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8558. "1832 No pending MBOX command to handle\n");
  8559. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8560. goto out_no_mqe_complete;
  8561. }
  8562. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8563. mqe = &pmb->u.mqe;
  8564. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8565. mbox = phba->mbox;
  8566. vport = pmb->vport;
  8567. /* Reset heartbeat timer */
  8568. phba->last_completion_time = jiffies;
  8569. del_timer(&phba->sli.mbox_tmo);
  8570. /* Move mbox data to caller's mailbox region, do endian swapping */
  8571. if (pmb->mbox_cmpl && mbox)
  8572. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8573. /* Set the mailbox status with SLI4 range 0x4000 */
  8574. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8575. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8576. bf_set(lpfc_mqe_status, mqe,
  8577. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8578. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8579. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8580. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8581. "MBOX dflt rpi: status:x%x rpi:x%x",
  8582. mcqe_status,
  8583. pmbox->un.varWords[0], 0);
  8584. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8585. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8586. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8587. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8588. * RID of the PPI using the same mbox buffer.
  8589. */
  8590. lpfc_unreg_login(phba, vport->vpi,
  8591. pmbox->un.varWords[0], pmb);
  8592. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8593. pmb->context1 = mp;
  8594. pmb->context2 = ndlp;
  8595. pmb->vport = vport;
  8596. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8597. if (rc != MBX_BUSY)
  8598. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8599. LOG_SLI, "0385 rc should "
  8600. "have been MBX_BUSY\n");
  8601. if (rc != MBX_NOT_FINISHED)
  8602. goto send_current_mbox;
  8603. }
  8604. }
  8605. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8606. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8607. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8608. /* There is mailbox completion work to do */
  8609. spin_lock_irqsave(&phba->hbalock, iflags);
  8610. __lpfc_mbox_cmpl_put(phba, pmb);
  8611. phba->work_ha |= HA_MBATT;
  8612. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8613. workposted = true;
  8614. send_current_mbox:
  8615. spin_lock_irqsave(&phba->hbalock, iflags);
  8616. /* Release the mailbox command posting token */
  8617. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8618. /* Setting active mailbox pointer need to be in sync to flag clear */
  8619. phba->sli.mbox_active = NULL;
  8620. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8621. /* Wake up worker thread to post the next pending mailbox command */
  8622. lpfc_worker_wake_up(phba);
  8623. out_no_mqe_complete:
  8624. if (bf_get(lpfc_trailer_consumed, mcqe))
  8625. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8626. return workposted;
  8627. }
  8628. /**
  8629. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8630. * @phba: Pointer to HBA context object.
  8631. * @cqe: Pointer to mailbox completion queue entry.
  8632. *
  8633. * This routine process a mailbox completion queue entry, it invokes the
  8634. * proper mailbox complete handling or asynchrous event handling routine
  8635. * according to the MCQE's async bit.
  8636. *
  8637. * Return: true if work posted to worker thread, otherwise false.
  8638. **/
  8639. static bool
  8640. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8641. {
  8642. struct lpfc_mcqe mcqe;
  8643. bool workposted;
  8644. /* Copy the mailbox MCQE and convert endian order as needed */
  8645. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8646. /* Invoke the proper event handling routine */
  8647. if (!bf_get(lpfc_trailer_async, &mcqe))
  8648. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8649. else
  8650. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8651. return workposted;
  8652. }
  8653. /**
  8654. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8655. * @phba: Pointer to HBA context object.
  8656. * @wcqe: Pointer to work-queue completion queue entry.
  8657. *
  8658. * This routine handles an ELS work-queue completion event.
  8659. *
  8660. * Return: true if work posted to worker thread, otherwise false.
  8661. **/
  8662. static bool
  8663. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8664. struct lpfc_wcqe_complete *wcqe)
  8665. {
  8666. struct lpfc_iocbq *irspiocbq;
  8667. unsigned long iflags;
  8668. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8669. /* Get an irspiocbq for later ELS response processing use */
  8670. irspiocbq = lpfc_sli_get_iocbq(phba);
  8671. if (!irspiocbq) {
  8672. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8673. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8674. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8675. pring->txq_cnt, phba->iocb_cnt,
  8676. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8677. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8678. return false;
  8679. }
  8680. /* Save off the slow-path queue event for work thread to process */
  8681. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8682. spin_lock_irqsave(&phba->hbalock, iflags);
  8683. list_add_tail(&irspiocbq->cq_event.list,
  8684. &phba->sli4_hba.sp_queue_event);
  8685. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8686. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8687. return true;
  8688. }
  8689. /**
  8690. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8691. * @phba: Pointer to HBA context object.
  8692. * @wcqe: Pointer to work-queue completion queue entry.
  8693. *
  8694. * This routine handles slow-path WQ entry comsumed event by invoking the
  8695. * proper WQ release routine to the slow-path WQ.
  8696. **/
  8697. static void
  8698. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8699. struct lpfc_wcqe_release *wcqe)
  8700. {
  8701. /* Check for the slow-path ELS work queue */
  8702. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8703. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8704. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8705. else
  8706. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8707. "2579 Slow-path wqe consume event carries "
  8708. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8709. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8710. phba->sli4_hba.els_wq->queue_id);
  8711. }
  8712. /**
  8713. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8714. * @phba: Pointer to HBA context object.
  8715. * @cq: Pointer to a WQ completion queue.
  8716. * @wcqe: Pointer to work-queue completion queue entry.
  8717. *
  8718. * This routine handles an XRI abort event.
  8719. *
  8720. * Return: true if work posted to worker thread, otherwise false.
  8721. **/
  8722. static bool
  8723. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8724. struct lpfc_queue *cq,
  8725. struct sli4_wcqe_xri_aborted *wcqe)
  8726. {
  8727. bool workposted = false;
  8728. struct lpfc_cq_event *cq_event;
  8729. unsigned long iflags;
  8730. /* Allocate a new internal CQ_EVENT entry */
  8731. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8732. if (!cq_event) {
  8733. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8734. "0602 Failed to allocate CQ_EVENT entry\n");
  8735. return false;
  8736. }
  8737. /* Move the CQE into the proper xri abort event list */
  8738. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8739. switch (cq->subtype) {
  8740. case LPFC_FCP:
  8741. spin_lock_irqsave(&phba->hbalock, iflags);
  8742. list_add_tail(&cq_event->list,
  8743. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8744. /* Set the fcp xri abort event flag */
  8745. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8746. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8747. workposted = true;
  8748. break;
  8749. case LPFC_ELS:
  8750. spin_lock_irqsave(&phba->hbalock, iflags);
  8751. list_add_tail(&cq_event->list,
  8752. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8753. /* Set the els xri abort event flag */
  8754. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8755. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8756. workposted = true;
  8757. break;
  8758. default:
  8759. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8760. "0603 Invalid work queue CQE subtype (x%x)\n",
  8761. cq->subtype);
  8762. workposted = false;
  8763. break;
  8764. }
  8765. return workposted;
  8766. }
  8767. /**
  8768. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8769. * @phba: Pointer to HBA context object.
  8770. * @rcqe: Pointer to receive-queue completion queue entry.
  8771. *
  8772. * This routine process a receive-queue completion queue entry.
  8773. *
  8774. * Return: true if work posted to worker thread, otherwise false.
  8775. **/
  8776. static bool
  8777. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8778. {
  8779. bool workposted = false;
  8780. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8781. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8782. struct hbq_dmabuf *dma_buf;
  8783. uint32_t status;
  8784. unsigned long iflags;
  8785. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8786. goto out;
  8787. status = bf_get(lpfc_rcqe_status, rcqe);
  8788. switch (status) {
  8789. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8790. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8791. "2537 Receive Frame Truncated!!\n");
  8792. case FC_STATUS_RQ_SUCCESS:
  8793. lpfc_sli4_rq_release(hrq, drq);
  8794. spin_lock_irqsave(&phba->hbalock, iflags);
  8795. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8796. if (!dma_buf) {
  8797. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8798. goto out;
  8799. }
  8800. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8801. /* save off the frame for the word thread to process */
  8802. list_add_tail(&dma_buf->cq_event.list,
  8803. &phba->sli4_hba.sp_queue_event);
  8804. /* Frame received */
  8805. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8806. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8807. workposted = true;
  8808. break;
  8809. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8810. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8811. /* Post more buffers if possible */
  8812. spin_lock_irqsave(&phba->hbalock, iflags);
  8813. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8814. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8815. workposted = true;
  8816. break;
  8817. }
  8818. out:
  8819. return workposted;
  8820. }
  8821. /**
  8822. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8823. * @phba: Pointer to HBA context object.
  8824. * @cq: Pointer to the completion queue.
  8825. * @wcqe: Pointer to a completion queue entry.
  8826. *
  8827. * This routine process a slow-path work-queue or receive queue completion queue
  8828. * entry.
  8829. *
  8830. * Return: true if work posted to worker thread, otherwise false.
  8831. **/
  8832. static bool
  8833. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8834. struct lpfc_cqe *cqe)
  8835. {
  8836. struct lpfc_cqe cqevt;
  8837. bool workposted = false;
  8838. /* Copy the work queue CQE and convert endian order if needed */
  8839. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8840. /* Check and process for different type of WCQE and dispatch */
  8841. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8842. case CQE_CODE_COMPL_WQE:
  8843. /* Process the WQ/RQ complete event */
  8844. phba->last_completion_time = jiffies;
  8845. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8846. (struct lpfc_wcqe_complete *)&cqevt);
  8847. break;
  8848. case CQE_CODE_RELEASE_WQE:
  8849. /* Process the WQ release event */
  8850. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8851. (struct lpfc_wcqe_release *)&cqevt);
  8852. break;
  8853. case CQE_CODE_XRI_ABORTED:
  8854. /* Process the WQ XRI abort event */
  8855. phba->last_completion_time = jiffies;
  8856. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8857. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8858. break;
  8859. case CQE_CODE_RECEIVE:
  8860. /* Process the RQ event */
  8861. phba->last_completion_time = jiffies;
  8862. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8863. (struct lpfc_rcqe *)&cqevt);
  8864. break;
  8865. default:
  8866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8867. "0388 Not a valid WCQE code: x%x\n",
  8868. bf_get(lpfc_cqe_code, &cqevt));
  8869. break;
  8870. }
  8871. return workposted;
  8872. }
  8873. /**
  8874. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8875. * @phba: Pointer to HBA context object.
  8876. * @eqe: Pointer to fast-path event queue entry.
  8877. *
  8878. * This routine process a event queue entry from the slow-path event queue.
  8879. * It will check the MajorCode and MinorCode to determine this is for a
  8880. * completion event on a completion queue, if not, an error shall be logged
  8881. * and just return. Otherwise, it will get to the corresponding completion
  8882. * queue and process all the entries on that completion queue, rearm the
  8883. * completion queue, and then return.
  8884. *
  8885. **/
  8886. static void
  8887. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8888. {
  8889. struct lpfc_queue *cq = NULL, *childq, *speq;
  8890. struct lpfc_cqe *cqe;
  8891. bool workposted = false;
  8892. int ecount = 0;
  8893. uint16_t cqid;
  8894. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8895. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8896. "0359 Not a valid slow-path completion "
  8897. "event: majorcode=x%x, minorcode=x%x\n",
  8898. bf_get_le32(lpfc_eqe_major_code, eqe),
  8899. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8900. return;
  8901. }
  8902. /* Get the reference to the corresponding CQ */
  8903. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8904. /* Search for completion queue pointer matching this cqid */
  8905. speq = phba->sli4_hba.sp_eq;
  8906. list_for_each_entry(childq, &speq->child_list, list) {
  8907. if (childq->queue_id == cqid) {
  8908. cq = childq;
  8909. break;
  8910. }
  8911. }
  8912. if (unlikely(!cq)) {
  8913. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8914. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8915. "0365 Slow-path CQ identifier "
  8916. "(%d) does not exist\n", cqid);
  8917. return;
  8918. }
  8919. /* Process all the entries to the CQ */
  8920. switch (cq->type) {
  8921. case LPFC_MCQ:
  8922. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8923. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8924. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8925. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8926. }
  8927. break;
  8928. case LPFC_WCQ:
  8929. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8930. if (cq->subtype == LPFC_FCP)
  8931. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  8932. cqe);
  8933. else
  8934. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  8935. cqe);
  8936. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8937. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8938. }
  8939. break;
  8940. default:
  8941. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8942. "0370 Invalid completion queue type (%d)\n",
  8943. cq->type);
  8944. return;
  8945. }
  8946. /* Catch the no cq entry condition, log an error */
  8947. if (unlikely(ecount == 0))
  8948. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8949. "0371 No entry from the CQ: identifier "
  8950. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8951. /* In any case, flash and re-arm the RCQ */
  8952. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8953. /* wake up worker thread if there are works to be done */
  8954. if (workposted)
  8955. lpfc_worker_wake_up(phba);
  8956. }
  8957. /**
  8958. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8959. * @eqe: Pointer to fast-path completion queue entry.
  8960. *
  8961. * This routine process a fast-path work queue completion entry from fast-path
  8962. * event queue for FCP command response completion.
  8963. **/
  8964. static void
  8965. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8966. struct lpfc_wcqe_complete *wcqe)
  8967. {
  8968. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8969. struct lpfc_iocbq *cmdiocbq;
  8970. struct lpfc_iocbq irspiocbq;
  8971. unsigned long iflags;
  8972. spin_lock_irqsave(&phba->hbalock, iflags);
  8973. pring->stats.iocb_event++;
  8974. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8975. /* Check for response status */
  8976. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8977. /* If resource errors reported from HBA, reduce queue
  8978. * depth of the SCSI device.
  8979. */
  8980. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8981. IOSTAT_LOCAL_REJECT) &&
  8982. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8983. phba->lpfc_rampdown_queue_depth(phba);
  8984. }
  8985. /* Log the error status */
  8986. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8987. "0373 FCP complete error: status=x%x, "
  8988. "hw_status=x%x, total_data_specified=%d, "
  8989. "parameter=x%x, word3=x%x\n",
  8990. bf_get(lpfc_wcqe_c_status, wcqe),
  8991. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8992. wcqe->total_data_placed, wcqe->parameter,
  8993. wcqe->word3);
  8994. }
  8995. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8996. spin_lock_irqsave(&phba->hbalock, iflags);
  8997. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8998. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8999. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9000. if (unlikely(!cmdiocbq)) {
  9001. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9002. "0374 FCP complete with no corresponding "
  9003. "cmdiocb: iotag (%d)\n",
  9004. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9005. return;
  9006. }
  9007. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  9008. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9009. "0375 FCP cmdiocb not callback function "
  9010. "iotag: (%d)\n",
  9011. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9012. return;
  9013. }
  9014. /* Fake the irspiocb and copy necessary response information */
  9015. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  9016. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  9017. spin_lock_irqsave(&phba->hbalock, iflags);
  9018. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  9019. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9020. }
  9021. /* Pass the cmd_iocb and the rsp state to the upper layer */
  9022. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  9023. }
  9024. /**
  9025. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  9026. * @phba: Pointer to HBA context object.
  9027. * @cq: Pointer to completion queue.
  9028. * @wcqe: Pointer to work-queue completion queue entry.
  9029. *
  9030. * This routine handles an fast-path WQ entry comsumed event by invoking the
  9031. * proper WQ release routine to the slow-path WQ.
  9032. **/
  9033. static void
  9034. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9035. struct lpfc_wcqe_release *wcqe)
  9036. {
  9037. struct lpfc_queue *childwq;
  9038. bool wqid_matched = false;
  9039. uint16_t fcp_wqid;
  9040. /* Check for fast-path FCP work queue release */
  9041. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  9042. list_for_each_entry(childwq, &cq->child_list, list) {
  9043. if (childwq->queue_id == fcp_wqid) {
  9044. lpfc_sli4_wq_release(childwq,
  9045. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  9046. wqid_matched = true;
  9047. break;
  9048. }
  9049. }
  9050. /* Report warning log message if no match found */
  9051. if (wqid_matched != true)
  9052. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9053. "2580 Fast-path wqe consume event carries "
  9054. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  9055. }
  9056. /**
  9057. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  9058. * @cq: Pointer to the completion queue.
  9059. * @eqe: Pointer to fast-path completion queue entry.
  9060. *
  9061. * This routine process a fast-path work queue completion entry from fast-path
  9062. * event queue for FCP command response completion.
  9063. **/
  9064. static int
  9065. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9066. struct lpfc_cqe *cqe)
  9067. {
  9068. struct lpfc_wcqe_release wcqe;
  9069. bool workposted = false;
  9070. /* Copy the work queue CQE and convert endian order if needed */
  9071. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  9072. /* Check and process for different type of WCQE and dispatch */
  9073. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  9074. case CQE_CODE_COMPL_WQE:
  9075. /* Process the WQ complete event */
  9076. phba->last_completion_time = jiffies;
  9077. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  9078. (struct lpfc_wcqe_complete *)&wcqe);
  9079. break;
  9080. case CQE_CODE_RELEASE_WQE:
  9081. /* Process the WQ release event */
  9082. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  9083. (struct lpfc_wcqe_release *)&wcqe);
  9084. break;
  9085. case CQE_CODE_XRI_ABORTED:
  9086. /* Process the WQ XRI abort event */
  9087. phba->last_completion_time = jiffies;
  9088. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  9089. (struct sli4_wcqe_xri_aborted *)&wcqe);
  9090. break;
  9091. default:
  9092. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9093. "0144 Not a valid WCQE code: x%x\n",
  9094. bf_get(lpfc_wcqe_c_code, &wcqe));
  9095. break;
  9096. }
  9097. return workposted;
  9098. }
  9099. /**
  9100. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  9101. * @phba: Pointer to HBA context object.
  9102. * @eqe: Pointer to fast-path event queue entry.
  9103. *
  9104. * This routine process a event queue entry from the fast-path event queue.
  9105. * It will check the MajorCode and MinorCode to determine this is for a
  9106. * completion event on a completion queue, if not, an error shall be logged
  9107. * and just return. Otherwise, it will get to the corresponding completion
  9108. * queue and process all the entries on the completion queue, rearm the
  9109. * completion queue, and then return.
  9110. **/
  9111. static void
  9112. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  9113. uint32_t fcp_cqidx)
  9114. {
  9115. struct lpfc_queue *cq;
  9116. struct lpfc_cqe *cqe;
  9117. bool workposted = false;
  9118. uint16_t cqid;
  9119. int ecount = 0;
  9120. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  9121. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9122. "0366 Not a valid fast-path completion "
  9123. "event: majorcode=x%x, minorcode=x%x\n",
  9124. bf_get_le32(lpfc_eqe_major_code, eqe),
  9125. bf_get_le32(lpfc_eqe_minor_code, eqe));
  9126. return;
  9127. }
  9128. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  9129. if (unlikely(!cq)) {
  9130. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  9131. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9132. "0367 Fast-path completion queue "
  9133. "does not exist\n");
  9134. return;
  9135. }
  9136. /* Get the reference to the corresponding CQ */
  9137. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9138. if (unlikely(cqid != cq->queue_id)) {
  9139. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9140. "0368 Miss-matched fast-path completion "
  9141. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9142. cqid, cq->queue_id);
  9143. return;
  9144. }
  9145. /* Process all the entries to the CQ */
  9146. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9147. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9148. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9149. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9150. }
  9151. /* Catch the no cq entry condition */
  9152. if (unlikely(ecount == 0))
  9153. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9154. "0369 No entry from fast-path completion "
  9155. "queue fcpcqid=%d\n", cq->queue_id);
  9156. /* In any case, flash and re-arm the CQ */
  9157. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9158. /* wake up worker thread if there are works to be done */
  9159. if (workposted)
  9160. lpfc_worker_wake_up(phba);
  9161. }
  9162. static void
  9163. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9164. {
  9165. struct lpfc_eqe *eqe;
  9166. /* walk all the EQ entries and drop on the floor */
  9167. while ((eqe = lpfc_sli4_eq_get(eq)))
  9168. ;
  9169. /* Clear and re-arm the EQ */
  9170. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9171. }
  9172. /**
  9173. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9174. * @irq: Interrupt number.
  9175. * @dev_id: The device context pointer.
  9176. *
  9177. * This function is directly called from the PCI layer as an interrupt
  9178. * service routine when device with SLI-4 interface spec is enabled with
  9179. * MSI-X multi-message interrupt mode and there are slow-path events in
  9180. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9181. * interrupt mode, this function is called as part of the device-level
  9182. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9183. * undergoing initialization, the interrupt handler will not process the
  9184. * interrupt. The link attention and ELS ring attention events are handled
  9185. * by the worker thread. The interrupt handler signals the worker thread
  9186. * and returns for these events. This function is called without any lock
  9187. * held. It gets the hbalock to access and update SLI data 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_sp_intr_handler(int irq, void *dev_id)
  9194. {
  9195. struct lpfc_hba *phba;
  9196. struct lpfc_queue *speq;
  9197. struct lpfc_eqe *eqe;
  9198. unsigned long iflag;
  9199. int ecount = 0;
  9200. /*
  9201. * Get the driver's phba structure from the dev_id
  9202. */
  9203. phba = (struct lpfc_hba *)dev_id;
  9204. if (unlikely(!phba))
  9205. return IRQ_NONE;
  9206. /* Get to the EQ struct associated with this vector */
  9207. speq = phba->sli4_hba.sp_eq;
  9208. /* Check device state for handling interrupt */
  9209. if (unlikely(lpfc_intr_state_check(phba))) {
  9210. /* Check again for link_state with lock held */
  9211. spin_lock_irqsave(&phba->hbalock, iflag);
  9212. if (phba->link_state < LPFC_LINK_DOWN)
  9213. /* Flush, clear interrupt, and rearm the EQ */
  9214. lpfc_sli4_eq_flush(phba, speq);
  9215. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9216. return IRQ_NONE;
  9217. }
  9218. /*
  9219. * Process all the event on FCP slow-path EQ
  9220. */
  9221. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9222. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9223. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9224. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9225. }
  9226. /* Always clear and re-arm the slow-path EQ */
  9227. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9228. /* Catch the no cq entry condition */
  9229. if (unlikely(ecount == 0)) {
  9230. if (phba->intr_type == MSIX)
  9231. /* MSI-X treated interrupt served as no EQ share INT */
  9232. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9233. "0357 MSI-X interrupt with no EQE\n");
  9234. else
  9235. /* Non MSI-X treated on interrupt as EQ share INT */
  9236. return IRQ_NONE;
  9237. }
  9238. return IRQ_HANDLED;
  9239. } /* lpfc_sli4_sp_intr_handler */
  9240. /**
  9241. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9242. * @irq: Interrupt number.
  9243. * @dev_id: The device context pointer.
  9244. *
  9245. * This function is directly called from the PCI layer as an interrupt
  9246. * service routine when device with SLI-4 interface spec is enabled with
  9247. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9248. * ring event in the HBA. However, when the device is enabled with either
  9249. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9250. * device-level interrupt handler. When the PCI slot is in error recovery
  9251. * or the HBA is undergoing initialization, the interrupt handler will not
  9252. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9253. * the intrrupt context. This function is called without any lock held.
  9254. * It gets the hbalock to access and update SLI data structures. Note that,
  9255. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9256. * equal to that of FCP CQ index.
  9257. *
  9258. * This function returns IRQ_HANDLED when interrupt is handled else it
  9259. * returns IRQ_NONE.
  9260. **/
  9261. irqreturn_t
  9262. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9263. {
  9264. struct lpfc_hba *phba;
  9265. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9266. struct lpfc_queue *fpeq;
  9267. struct lpfc_eqe *eqe;
  9268. unsigned long iflag;
  9269. int ecount = 0;
  9270. uint32_t fcp_eqidx;
  9271. /* Get the driver's phba structure from the dev_id */
  9272. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9273. phba = fcp_eq_hdl->phba;
  9274. fcp_eqidx = fcp_eq_hdl->idx;
  9275. if (unlikely(!phba))
  9276. return IRQ_NONE;
  9277. /* Get to the EQ struct associated with this vector */
  9278. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9279. /* Check device state for handling interrupt */
  9280. if (unlikely(lpfc_intr_state_check(phba))) {
  9281. /* Check again for link_state with lock held */
  9282. spin_lock_irqsave(&phba->hbalock, iflag);
  9283. if (phba->link_state < LPFC_LINK_DOWN)
  9284. /* Flush, clear interrupt, and rearm the EQ */
  9285. lpfc_sli4_eq_flush(phba, fpeq);
  9286. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9287. return IRQ_NONE;
  9288. }
  9289. /*
  9290. * Process all the event on FCP fast-path EQ
  9291. */
  9292. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9293. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9294. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9295. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9296. }
  9297. /* Always clear and re-arm the fast-path EQ */
  9298. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9299. if (unlikely(ecount == 0)) {
  9300. if (phba->intr_type == MSIX)
  9301. /* MSI-X treated interrupt served as no EQ share INT */
  9302. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9303. "0358 MSI-X interrupt with no EQE\n");
  9304. else
  9305. /* Non MSI-X treated on interrupt as EQ share INT */
  9306. return IRQ_NONE;
  9307. }
  9308. return IRQ_HANDLED;
  9309. } /* lpfc_sli4_fp_intr_handler */
  9310. /**
  9311. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9312. * @irq: Interrupt number.
  9313. * @dev_id: The device context pointer.
  9314. *
  9315. * This function is the device-level interrupt handler to device with SLI-4
  9316. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9317. * interrupt mode is enabled and there is an event in the HBA which requires
  9318. * driver attention. This function invokes the slow-path interrupt attention
  9319. * handling function and fast-path interrupt attention handling function in
  9320. * turn to process the relevant HBA attention events. This function is called
  9321. * without any lock held. It gets the hbalock to access and update SLI data
  9322. * structures.
  9323. *
  9324. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9325. * returns IRQ_NONE.
  9326. **/
  9327. irqreturn_t
  9328. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9329. {
  9330. struct lpfc_hba *phba;
  9331. irqreturn_t sp_irq_rc, fp_irq_rc;
  9332. bool fp_handled = false;
  9333. uint32_t fcp_eqidx;
  9334. /* Get the driver's phba structure from the dev_id */
  9335. phba = (struct lpfc_hba *)dev_id;
  9336. if (unlikely(!phba))
  9337. return IRQ_NONE;
  9338. /*
  9339. * Invokes slow-path host attention interrupt handling as appropriate.
  9340. */
  9341. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9342. /*
  9343. * Invoke fast-path host attention interrupt handling as appropriate.
  9344. */
  9345. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9346. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9347. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9348. if (fp_irq_rc == IRQ_HANDLED)
  9349. fp_handled |= true;
  9350. }
  9351. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9352. } /* lpfc_sli4_intr_handler */
  9353. /**
  9354. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9355. * @queue: The queue structure to free.
  9356. *
  9357. * This function frees a queue structure and the DMAable memory used for
  9358. * the host resident queue. This function must be called after destroying the
  9359. * queue on the HBA.
  9360. **/
  9361. void
  9362. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9363. {
  9364. struct lpfc_dmabuf *dmabuf;
  9365. if (!queue)
  9366. return;
  9367. while (!list_empty(&queue->page_list)) {
  9368. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9369. list);
  9370. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9371. dmabuf->virt, dmabuf->phys);
  9372. kfree(dmabuf);
  9373. }
  9374. kfree(queue);
  9375. return;
  9376. }
  9377. /**
  9378. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9379. * @phba: The HBA that this queue is being created on.
  9380. * @entry_size: The size of each queue entry for this queue.
  9381. * @entry count: The number of entries that this queue will handle.
  9382. *
  9383. * This function allocates a queue structure and the DMAable memory used for
  9384. * the host resident queue. This function must be called before creating the
  9385. * queue on the HBA.
  9386. **/
  9387. struct lpfc_queue *
  9388. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9389. uint32_t entry_count)
  9390. {
  9391. struct lpfc_queue *queue;
  9392. struct lpfc_dmabuf *dmabuf;
  9393. int x, total_qe_count;
  9394. void *dma_pointer;
  9395. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9396. if (!phba->sli4_hba.pc_sli4_params.supported)
  9397. hw_page_size = SLI4_PAGE_SIZE;
  9398. queue = kzalloc(sizeof(struct lpfc_queue) +
  9399. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9400. if (!queue)
  9401. return NULL;
  9402. queue->page_count = (ALIGN(entry_size * entry_count,
  9403. hw_page_size))/hw_page_size;
  9404. INIT_LIST_HEAD(&queue->list);
  9405. INIT_LIST_HEAD(&queue->page_list);
  9406. INIT_LIST_HEAD(&queue->child_list);
  9407. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9408. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9409. if (!dmabuf)
  9410. goto out_fail;
  9411. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9412. hw_page_size, &dmabuf->phys,
  9413. GFP_KERNEL);
  9414. if (!dmabuf->virt) {
  9415. kfree(dmabuf);
  9416. goto out_fail;
  9417. }
  9418. memset(dmabuf->virt, 0, hw_page_size);
  9419. dmabuf->buffer_tag = x;
  9420. list_add_tail(&dmabuf->list, &queue->page_list);
  9421. /* initialize queue's entry array */
  9422. dma_pointer = dmabuf->virt;
  9423. for (; total_qe_count < entry_count &&
  9424. dma_pointer < (hw_page_size + dmabuf->virt);
  9425. total_qe_count++, dma_pointer += entry_size) {
  9426. queue->qe[total_qe_count].address = dma_pointer;
  9427. }
  9428. }
  9429. queue->entry_size = entry_size;
  9430. queue->entry_count = entry_count;
  9431. queue->phba = phba;
  9432. return queue;
  9433. out_fail:
  9434. lpfc_sli4_queue_free(queue);
  9435. return NULL;
  9436. }
  9437. /**
  9438. * lpfc_eq_create - Create an Event Queue on the HBA
  9439. * @phba: HBA structure that indicates port to create a queue on.
  9440. * @eq: The queue structure to use to create the event queue.
  9441. * @imax: The maximum interrupt per second limit.
  9442. *
  9443. * This function creates an event queue, as detailed in @eq, on a port,
  9444. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9445. *
  9446. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9447. * is used to get the entry count and entry size that are necessary to
  9448. * determine the number of pages to allocate and use for this queue. This
  9449. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9450. * event queue. This function is asynchronous and will wait for the mailbox
  9451. * command to finish before continuing.
  9452. *
  9453. * On success this function will return a zero. If unable to allocate enough
  9454. * memory this function will return -ENOMEM. If the queue create mailbox command
  9455. * fails this function will return -ENXIO.
  9456. **/
  9457. uint32_t
  9458. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9459. {
  9460. struct lpfc_mbx_eq_create *eq_create;
  9461. LPFC_MBOXQ_t *mbox;
  9462. int rc, length, status = 0;
  9463. struct lpfc_dmabuf *dmabuf;
  9464. uint32_t shdr_status, shdr_add_status;
  9465. union lpfc_sli4_cfg_shdr *shdr;
  9466. uint16_t dmult;
  9467. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9468. if (!phba->sli4_hba.pc_sli4_params.supported)
  9469. hw_page_size = SLI4_PAGE_SIZE;
  9470. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9471. if (!mbox)
  9472. return -ENOMEM;
  9473. length = (sizeof(struct lpfc_mbx_eq_create) -
  9474. sizeof(struct lpfc_sli4_cfg_mhdr));
  9475. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9476. LPFC_MBOX_OPCODE_EQ_CREATE,
  9477. length, LPFC_SLI4_MBX_EMBED);
  9478. eq_create = &mbox->u.mqe.un.eq_create;
  9479. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9480. eq->page_count);
  9481. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9482. LPFC_EQE_SIZE);
  9483. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9484. /* Calculate delay multiper from maximum interrupt per second */
  9485. dmult = LPFC_DMULT_CONST/imax - 1;
  9486. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9487. dmult);
  9488. switch (eq->entry_count) {
  9489. default:
  9490. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9491. "0360 Unsupported EQ count. (%d)\n",
  9492. eq->entry_count);
  9493. if (eq->entry_count < 256)
  9494. return -EINVAL;
  9495. /* otherwise default to smallest count (drop through) */
  9496. case 256:
  9497. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9498. LPFC_EQ_CNT_256);
  9499. break;
  9500. case 512:
  9501. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9502. LPFC_EQ_CNT_512);
  9503. break;
  9504. case 1024:
  9505. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9506. LPFC_EQ_CNT_1024);
  9507. break;
  9508. case 2048:
  9509. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9510. LPFC_EQ_CNT_2048);
  9511. break;
  9512. case 4096:
  9513. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9514. LPFC_EQ_CNT_4096);
  9515. break;
  9516. }
  9517. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9518. memset(dmabuf->virt, 0, hw_page_size);
  9519. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9520. putPaddrLow(dmabuf->phys);
  9521. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9522. putPaddrHigh(dmabuf->phys);
  9523. }
  9524. mbox->vport = phba->pport;
  9525. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9526. mbox->context1 = NULL;
  9527. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9528. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9529. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9530. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9531. if (shdr_status || shdr_add_status || rc) {
  9532. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9533. "2500 EQ_CREATE mailbox failed with "
  9534. "status x%x add_status x%x, mbx status x%x\n",
  9535. shdr_status, shdr_add_status, rc);
  9536. status = -ENXIO;
  9537. }
  9538. eq->type = LPFC_EQ;
  9539. eq->subtype = LPFC_NONE;
  9540. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9541. if (eq->queue_id == 0xFFFF)
  9542. status = -ENXIO;
  9543. eq->host_index = 0;
  9544. eq->hba_index = 0;
  9545. mempool_free(mbox, phba->mbox_mem_pool);
  9546. return status;
  9547. }
  9548. /**
  9549. * lpfc_cq_create - Create a Completion Queue on the HBA
  9550. * @phba: HBA structure that indicates port to create a queue on.
  9551. * @cq: The queue structure to use to create the completion queue.
  9552. * @eq: The event queue to bind this completion queue to.
  9553. *
  9554. * This function creates a completion queue, as detailed in @wq, on a port,
  9555. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9556. *
  9557. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9558. * is used to get the entry count and entry size that are necessary to
  9559. * determine the number of pages to allocate and use for this queue. The @eq
  9560. * is used to indicate which event queue to bind this completion queue to. This
  9561. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9562. * completion queue. This function is asynchronous and will wait for the mailbox
  9563. * command to finish before continuing.
  9564. *
  9565. * On success this function will return a zero. If unable to allocate enough
  9566. * memory this function will return -ENOMEM. If the queue create mailbox command
  9567. * fails this function will return -ENXIO.
  9568. **/
  9569. uint32_t
  9570. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9571. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9572. {
  9573. struct lpfc_mbx_cq_create *cq_create;
  9574. struct lpfc_dmabuf *dmabuf;
  9575. LPFC_MBOXQ_t *mbox;
  9576. int rc, length, status = 0;
  9577. uint32_t shdr_status, shdr_add_status;
  9578. union lpfc_sli4_cfg_shdr *shdr;
  9579. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9580. if (!phba->sli4_hba.pc_sli4_params.supported)
  9581. hw_page_size = SLI4_PAGE_SIZE;
  9582. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9583. if (!mbox)
  9584. return -ENOMEM;
  9585. length = (sizeof(struct lpfc_mbx_cq_create) -
  9586. sizeof(struct lpfc_sli4_cfg_mhdr));
  9587. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9588. LPFC_MBOX_OPCODE_CQ_CREATE,
  9589. length, LPFC_SLI4_MBX_EMBED);
  9590. cq_create = &mbox->u.mqe.un.cq_create;
  9591. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9592. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9593. cq->page_count);
  9594. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9595. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9596. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9597. phba->sli4_hba.pc_sli4_params.cqv);
  9598. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  9599. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  9600. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  9601. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  9602. eq->queue_id);
  9603. } else {
  9604. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  9605. eq->queue_id);
  9606. }
  9607. switch (cq->entry_count) {
  9608. default:
  9609. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9610. "0361 Unsupported CQ count. (%d)\n",
  9611. cq->entry_count);
  9612. if (cq->entry_count < 256)
  9613. return -EINVAL;
  9614. /* otherwise default to smallest count (drop through) */
  9615. case 256:
  9616. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9617. LPFC_CQ_CNT_256);
  9618. break;
  9619. case 512:
  9620. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9621. LPFC_CQ_CNT_512);
  9622. break;
  9623. case 1024:
  9624. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9625. LPFC_CQ_CNT_1024);
  9626. break;
  9627. }
  9628. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9629. memset(dmabuf->virt, 0, hw_page_size);
  9630. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9631. putPaddrLow(dmabuf->phys);
  9632. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9633. putPaddrHigh(dmabuf->phys);
  9634. }
  9635. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9636. /* The IOCTL status is embedded in the mailbox subheader. */
  9637. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9638. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9639. if (shdr_status || shdr_add_status || rc) {
  9640. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9641. "2501 CQ_CREATE mailbox failed with "
  9642. "status x%x add_status x%x, mbx status x%x\n",
  9643. shdr_status, shdr_add_status, rc);
  9644. status = -ENXIO;
  9645. goto out;
  9646. }
  9647. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9648. if (cq->queue_id == 0xFFFF) {
  9649. status = -ENXIO;
  9650. goto out;
  9651. }
  9652. /* link the cq onto the parent eq child list */
  9653. list_add_tail(&cq->list, &eq->child_list);
  9654. /* Set up completion queue's type and subtype */
  9655. cq->type = type;
  9656. cq->subtype = subtype;
  9657. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9658. cq->assoc_qid = eq->queue_id;
  9659. cq->host_index = 0;
  9660. cq->hba_index = 0;
  9661. out:
  9662. mempool_free(mbox, phba->mbox_mem_pool);
  9663. return status;
  9664. }
  9665. /**
  9666. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9667. * @phba: HBA structure that indicates port to create a queue on.
  9668. * @mq: The queue structure to use to create the mailbox queue.
  9669. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9670. * @cq: The completion queue to associate with this cq.
  9671. *
  9672. * This function provides failback (fb) functionality when the
  9673. * mq_create_ext fails on older FW generations. It's purpose is identical
  9674. * to mq_create_ext otherwise.
  9675. *
  9676. * This routine cannot fail as all attributes were previously accessed and
  9677. * initialized in mq_create_ext.
  9678. **/
  9679. static void
  9680. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9681. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9682. {
  9683. struct lpfc_mbx_mq_create *mq_create;
  9684. struct lpfc_dmabuf *dmabuf;
  9685. int length;
  9686. length = (sizeof(struct lpfc_mbx_mq_create) -
  9687. sizeof(struct lpfc_sli4_cfg_mhdr));
  9688. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9689. LPFC_MBOX_OPCODE_MQ_CREATE,
  9690. length, LPFC_SLI4_MBX_EMBED);
  9691. mq_create = &mbox->u.mqe.un.mq_create;
  9692. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9693. mq->page_count);
  9694. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9695. cq->queue_id);
  9696. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9697. switch (mq->entry_count) {
  9698. case 16:
  9699. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9700. LPFC_MQ_RING_SIZE_16);
  9701. break;
  9702. case 32:
  9703. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9704. LPFC_MQ_RING_SIZE_32);
  9705. break;
  9706. case 64:
  9707. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9708. LPFC_MQ_RING_SIZE_64);
  9709. break;
  9710. case 128:
  9711. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9712. LPFC_MQ_RING_SIZE_128);
  9713. break;
  9714. }
  9715. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9716. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9717. putPaddrLow(dmabuf->phys);
  9718. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9719. putPaddrHigh(dmabuf->phys);
  9720. }
  9721. }
  9722. /**
  9723. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9724. * @phba: HBA structure that indicates port to create a queue on.
  9725. * @mq: The queue structure to use to create the mailbox queue.
  9726. * @cq: The completion queue to associate with this cq.
  9727. * @subtype: The queue's subtype.
  9728. *
  9729. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9730. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9731. *
  9732. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9733. * is used to get the entry count and entry size that are necessary to
  9734. * determine the number of pages to allocate and use for this queue. This
  9735. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9736. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9737. * command to finish before continuing.
  9738. *
  9739. * On success this function will return a zero. If unable to allocate enough
  9740. * memory this function will return -ENOMEM. If the queue create mailbox command
  9741. * fails this function will return -ENXIO.
  9742. **/
  9743. int32_t
  9744. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9745. struct lpfc_queue *cq, uint32_t subtype)
  9746. {
  9747. struct lpfc_mbx_mq_create *mq_create;
  9748. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9749. struct lpfc_dmabuf *dmabuf;
  9750. LPFC_MBOXQ_t *mbox;
  9751. int rc, length, status = 0;
  9752. uint32_t shdr_status, shdr_add_status;
  9753. union lpfc_sli4_cfg_shdr *shdr;
  9754. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9755. if (!phba->sli4_hba.pc_sli4_params.supported)
  9756. hw_page_size = SLI4_PAGE_SIZE;
  9757. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9758. if (!mbox)
  9759. return -ENOMEM;
  9760. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9761. sizeof(struct lpfc_sli4_cfg_mhdr));
  9762. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9763. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9764. length, LPFC_SLI4_MBX_EMBED);
  9765. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9766. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9767. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  9768. &mq_create_ext->u.request, mq->page_count);
  9769. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  9770. &mq_create_ext->u.request, 1);
  9771. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  9772. &mq_create_ext->u.request, 1);
  9773. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9774. &mq_create_ext->u.request, 1);
  9775. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  9776. &mq_create_ext->u.request, 1);
  9777. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  9778. &mq_create_ext->u.request, 1);
  9779. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9780. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9781. phba->sli4_hba.pc_sli4_params.mqv);
  9782. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  9783. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  9784. cq->queue_id);
  9785. else
  9786. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9787. cq->queue_id);
  9788. switch (mq->entry_count) {
  9789. default:
  9790. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9791. "0362 Unsupported MQ count. (%d)\n",
  9792. mq->entry_count);
  9793. if (mq->entry_count < 16)
  9794. return -EINVAL;
  9795. /* otherwise default to smallest count (drop through) */
  9796. case 16:
  9797. bf_set(lpfc_mq_context_ring_size,
  9798. &mq_create_ext->u.request.context,
  9799. LPFC_MQ_RING_SIZE_16);
  9800. break;
  9801. case 32:
  9802. bf_set(lpfc_mq_context_ring_size,
  9803. &mq_create_ext->u.request.context,
  9804. LPFC_MQ_RING_SIZE_32);
  9805. break;
  9806. case 64:
  9807. bf_set(lpfc_mq_context_ring_size,
  9808. &mq_create_ext->u.request.context,
  9809. LPFC_MQ_RING_SIZE_64);
  9810. break;
  9811. case 128:
  9812. bf_set(lpfc_mq_context_ring_size,
  9813. &mq_create_ext->u.request.context,
  9814. LPFC_MQ_RING_SIZE_128);
  9815. break;
  9816. }
  9817. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9818. memset(dmabuf->virt, 0, hw_page_size);
  9819. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9820. putPaddrLow(dmabuf->phys);
  9821. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9822. putPaddrHigh(dmabuf->phys);
  9823. }
  9824. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9825. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9826. &mq_create_ext->u.response);
  9827. if (rc != MBX_SUCCESS) {
  9828. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9829. "2795 MQ_CREATE_EXT failed with "
  9830. "status x%x. Failback to MQ_CREATE.\n",
  9831. rc);
  9832. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9833. mq_create = &mbox->u.mqe.un.mq_create;
  9834. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9835. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9836. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9837. &mq_create->u.response);
  9838. }
  9839. /* The IOCTL status is embedded in the mailbox subheader. */
  9840. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9841. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9842. if (shdr_status || shdr_add_status || rc) {
  9843. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9844. "2502 MQ_CREATE mailbox failed with "
  9845. "status x%x add_status x%x, mbx status x%x\n",
  9846. shdr_status, shdr_add_status, rc);
  9847. status = -ENXIO;
  9848. goto out;
  9849. }
  9850. if (mq->queue_id == 0xFFFF) {
  9851. status = -ENXIO;
  9852. goto out;
  9853. }
  9854. mq->type = LPFC_MQ;
  9855. mq->assoc_qid = cq->queue_id;
  9856. mq->subtype = subtype;
  9857. mq->host_index = 0;
  9858. mq->hba_index = 0;
  9859. /* link the mq onto the parent cq child list */
  9860. list_add_tail(&mq->list, &cq->child_list);
  9861. out:
  9862. mempool_free(mbox, phba->mbox_mem_pool);
  9863. return status;
  9864. }
  9865. /**
  9866. * lpfc_wq_create - Create a Work Queue on the HBA
  9867. * @phba: HBA structure that indicates port to create a queue on.
  9868. * @wq: The queue structure to use to create the work queue.
  9869. * @cq: The completion queue to bind this work queue to.
  9870. * @subtype: The subtype of the work queue indicating its functionality.
  9871. *
  9872. * This function creates a work queue, as detailed in @wq, on a port, described
  9873. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9874. *
  9875. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9876. * is used to get the entry count and entry size that are necessary to
  9877. * determine the number of pages to allocate and use for this queue. The @cq
  9878. * is used to indicate which completion queue to bind this work queue to. This
  9879. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9880. * work queue. This function is asynchronous and will wait for the mailbox
  9881. * command to finish before continuing.
  9882. *
  9883. * On success this function will return a zero. If unable to allocate enough
  9884. * memory this function will return -ENOMEM. If the queue create mailbox command
  9885. * fails this function will return -ENXIO.
  9886. **/
  9887. uint32_t
  9888. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9889. struct lpfc_queue *cq, uint32_t subtype)
  9890. {
  9891. struct lpfc_mbx_wq_create *wq_create;
  9892. struct lpfc_dmabuf *dmabuf;
  9893. LPFC_MBOXQ_t *mbox;
  9894. int rc, length, status = 0;
  9895. uint32_t shdr_status, shdr_add_status;
  9896. union lpfc_sli4_cfg_shdr *shdr;
  9897. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9898. struct dma_address *page;
  9899. if (!phba->sli4_hba.pc_sli4_params.supported)
  9900. hw_page_size = SLI4_PAGE_SIZE;
  9901. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9902. if (!mbox)
  9903. return -ENOMEM;
  9904. length = (sizeof(struct lpfc_mbx_wq_create) -
  9905. sizeof(struct lpfc_sli4_cfg_mhdr));
  9906. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9907. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9908. length, LPFC_SLI4_MBX_EMBED);
  9909. wq_create = &mbox->u.mqe.un.wq_create;
  9910. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9911. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9912. wq->page_count);
  9913. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9914. cq->queue_id);
  9915. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9916. phba->sli4_hba.pc_sli4_params.wqv);
  9917. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  9918. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  9919. wq->entry_count);
  9920. switch (wq->entry_size) {
  9921. default:
  9922. case 64:
  9923. bf_set(lpfc_mbx_wq_create_wqe_size,
  9924. &wq_create->u.request_1,
  9925. LPFC_WQ_WQE_SIZE_64);
  9926. break;
  9927. case 128:
  9928. bf_set(lpfc_mbx_wq_create_wqe_size,
  9929. &wq_create->u.request_1,
  9930. LPFC_WQ_WQE_SIZE_128);
  9931. break;
  9932. }
  9933. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  9934. (PAGE_SIZE/SLI4_PAGE_SIZE));
  9935. page = wq_create->u.request_1.page;
  9936. } else {
  9937. page = wq_create->u.request.page;
  9938. }
  9939. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9940. memset(dmabuf->virt, 0, hw_page_size);
  9941. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  9942. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  9943. }
  9944. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9945. /* The IOCTL status is embedded in the mailbox subheader. */
  9946. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9947. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9948. if (shdr_status || shdr_add_status || rc) {
  9949. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9950. "2503 WQ_CREATE mailbox failed with "
  9951. "status x%x add_status x%x, mbx status x%x\n",
  9952. shdr_status, shdr_add_status, rc);
  9953. status = -ENXIO;
  9954. goto out;
  9955. }
  9956. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9957. if (wq->queue_id == 0xFFFF) {
  9958. status = -ENXIO;
  9959. goto out;
  9960. }
  9961. wq->type = LPFC_WQ;
  9962. wq->assoc_qid = cq->queue_id;
  9963. wq->subtype = subtype;
  9964. wq->host_index = 0;
  9965. wq->hba_index = 0;
  9966. /* link the wq onto the parent cq child list */
  9967. list_add_tail(&wq->list, &cq->child_list);
  9968. out:
  9969. mempool_free(mbox, phba->mbox_mem_pool);
  9970. return status;
  9971. }
  9972. /**
  9973. * lpfc_rq_create - Create a Receive Queue on the HBA
  9974. * @phba: HBA structure that indicates port to create a queue on.
  9975. * @hrq: The queue structure to use to create the header receive queue.
  9976. * @drq: The queue structure to use to create the data receive queue.
  9977. * @cq: The completion queue to bind this work queue to.
  9978. *
  9979. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9980. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9981. * to the HBA.
  9982. *
  9983. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9984. * struct is used to get the entry count that is necessary to determine the
  9985. * number of pages to use for this queue. The @cq is used to indicate which
  9986. * completion queue to bind received buffers that are posted to these queues to.
  9987. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9988. * receive queue pair. This function is asynchronous and will wait for the
  9989. * mailbox command to finish before continuing.
  9990. *
  9991. * On success this function will return a zero. If unable to allocate enough
  9992. * memory this function will return -ENOMEM. If the queue create mailbox command
  9993. * fails this function will return -ENXIO.
  9994. **/
  9995. uint32_t
  9996. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9997. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9998. {
  9999. struct lpfc_mbx_rq_create *rq_create;
  10000. struct lpfc_dmabuf *dmabuf;
  10001. LPFC_MBOXQ_t *mbox;
  10002. int rc, length, status = 0;
  10003. uint32_t shdr_status, shdr_add_status;
  10004. union lpfc_sli4_cfg_shdr *shdr;
  10005. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10006. if (!phba->sli4_hba.pc_sli4_params.supported)
  10007. hw_page_size = SLI4_PAGE_SIZE;
  10008. if (hrq->entry_count != drq->entry_count)
  10009. return -EINVAL;
  10010. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10011. if (!mbox)
  10012. return -ENOMEM;
  10013. length = (sizeof(struct lpfc_mbx_rq_create) -
  10014. sizeof(struct lpfc_sli4_cfg_mhdr));
  10015. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10016. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  10017. length, LPFC_SLI4_MBX_EMBED);
  10018. rq_create = &mbox->u.mqe.un.rq_create;
  10019. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  10020. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10021. phba->sli4_hba.pc_sli4_params.rqv);
  10022. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  10023. bf_set(lpfc_rq_context_rqe_count_1,
  10024. &rq_create->u.request.context,
  10025. hrq->entry_count);
  10026. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  10027. bf_set(lpfc_rq_context_rqe_size,
  10028. &rq_create->u.request.context,
  10029. LPFC_RQE_SIZE_8);
  10030. bf_set(lpfc_rq_context_page_size,
  10031. &rq_create->u.request.context,
  10032. (PAGE_SIZE/SLI4_PAGE_SIZE));
  10033. } else {
  10034. switch (hrq->entry_count) {
  10035. default:
  10036. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10037. "2535 Unsupported RQ count. (%d)\n",
  10038. hrq->entry_count);
  10039. if (hrq->entry_count < 512)
  10040. return -EINVAL;
  10041. /* otherwise default to smallest count (drop through) */
  10042. case 512:
  10043. bf_set(lpfc_rq_context_rqe_count,
  10044. &rq_create->u.request.context,
  10045. LPFC_RQ_RING_SIZE_512);
  10046. break;
  10047. case 1024:
  10048. bf_set(lpfc_rq_context_rqe_count,
  10049. &rq_create->u.request.context,
  10050. LPFC_RQ_RING_SIZE_1024);
  10051. break;
  10052. case 2048:
  10053. bf_set(lpfc_rq_context_rqe_count,
  10054. &rq_create->u.request.context,
  10055. LPFC_RQ_RING_SIZE_2048);
  10056. break;
  10057. case 4096:
  10058. bf_set(lpfc_rq_context_rqe_count,
  10059. &rq_create->u.request.context,
  10060. LPFC_RQ_RING_SIZE_4096);
  10061. break;
  10062. }
  10063. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  10064. LPFC_HDR_BUF_SIZE);
  10065. }
  10066. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  10067. cq->queue_id);
  10068. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  10069. hrq->page_count);
  10070. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  10071. memset(dmabuf->virt, 0, hw_page_size);
  10072. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10073. putPaddrLow(dmabuf->phys);
  10074. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10075. putPaddrHigh(dmabuf->phys);
  10076. }
  10077. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10078. /* The IOCTL status is embedded in the mailbox subheader. */
  10079. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10080. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10081. if (shdr_status || shdr_add_status || rc) {
  10082. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10083. "2504 RQ_CREATE mailbox failed with "
  10084. "status x%x add_status x%x, mbx status x%x\n",
  10085. shdr_status, shdr_add_status, rc);
  10086. status = -ENXIO;
  10087. goto out;
  10088. }
  10089. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  10090. if (hrq->queue_id == 0xFFFF) {
  10091. status = -ENXIO;
  10092. goto out;
  10093. }
  10094. hrq->type = LPFC_HRQ;
  10095. hrq->assoc_qid = cq->queue_id;
  10096. hrq->subtype = subtype;
  10097. hrq->host_index = 0;
  10098. hrq->hba_index = 0;
  10099. /* now create the data queue */
  10100. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10101. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  10102. length, LPFC_SLI4_MBX_EMBED);
  10103. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10104. phba->sli4_hba.pc_sli4_params.rqv);
  10105. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  10106. bf_set(lpfc_rq_context_rqe_count_1,
  10107. &rq_create->u.request.context, hrq->entry_count);
  10108. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  10109. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  10110. LPFC_RQE_SIZE_8);
  10111. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  10112. (PAGE_SIZE/SLI4_PAGE_SIZE));
  10113. } else {
  10114. switch (drq->entry_count) {
  10115. default:
  10116. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10117. "2536 Unsupported RQ count. (%d)\n",
  10118. drq->entry_count);
  10119. if (drq->entry_count < 512)
  10120. return -EINVAL;
  10121. /* otherwise default to smallest count (drop through) */
  10122. case 512:
  10123. bf_set(lpfc_rq_context_rqe_count,
  10124. &rq_create->u.request.context,
  10125. LPFC_RQ_RING_SIZE_512);
  10126. break;
  10127. case 1024:
  10128. bf_set(lpfc_rq_context_rqe_count,
  10129. &rq_create->u.request.context,
  10130. LPFC_RQ_RING_SIZE_1024);
  10131. break;
  10132. case 2048:
  10133. bf_set(lpfc_rq_context_rqe_count,
  10134. &rq_create->u.request.context,
  10135. LPFC_RQ_RING_SIZE_2048);
  10136. break;
  10137. case 4096:
  10138. bf_set(lpfc_rq_context_rqe_count,
  10139. &rq_create->u.request.context,
  10140. LPFC_RQ_RING_SIZE_4096);
  10141. break;
  10142. }
  10143. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  10144. LPFC_DATA_BUF_SIZE);
  10145. }
  10146. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  10147. cq->queue_id);
  10148. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  10149. drq->page_count);
  10150. list_for_each_entry(dmabuf, &drq->page_list, list) {
  10151. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10152. putPaddrLow(dmabuf->phys);
  10153. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10154. putPaddrHigh(dmabuf->phys);
  10155. }
  10156. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10157. /* The IOCTL status is embedded in the mailbox subheader. */
  10158. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  10159. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10160. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10161. if (shdr_status || shdr_add_status || rc) {
  10162. status = -ENXIO;
  10163. goto out;
  10164. }
  10165. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  10166. if (drq->queue_id == 0xFFFF) {
  10167. status = -ENXIO;
  10168. goto out;
  10169. }
  10170. drq->type = LPFC_DRQ;
  10171. drq->assoc_qid = cq->queue_id;
  10172. drq->subtype = subtype;
  10173. drq->host_index = 0;
  10174. drq->hba_index = 0;
  10175. /* link the header and data RQs onto the parent cq child list */
  10176. list_add_tail(&hrq->list, &cq->child_list);
  10177. list_add_tail(&drq->list, &cq->child_list);
  10178. out:
  10179. mempool_free(mbox, phba->mbox_mem_pool);
  10180. return status;
  10181. }
  10182. /**
  10183. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  10184. * @eq: The queue structure associated with the queue to destroy.
  10185. *
  10186. * This function destroys a queue, as detailed in @eq by sending an mailbox
  10187. * command, specific to the type of queue, to the HBA.
  10188. *
  10189. * The @eq struct is used to get the queue ID of the queue to destroy.
  10190. *
  10191. * On success this function will return a zero. If the queue destroy mailbox
  10192. * command fails this function will return -ENXIO.
  10193. **/
  10194. uint32_t
  10195. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10196. {
  10197. LPFC_MBOXQ_t *mbox;
  10198. int rc, length, status = 0;
  10199. uint32_t shdr_status, shdr_add_status;
  10200. union lpfc_sli4_cfg_shdr *shdr;
  10201. if (!eq)
  10202. return -ENODEV;
  10203. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  10204. if (!mbox)
  10205. return -ENOMEM;
  10206. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  10207. sizeof(struct lpfc_sli4_cfg_mhdr));
  10208. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10209. LPFC_MBOX_OPCODE_EQ_DESTROY,
  10210. length, LPFC_SLI4_MBX_EMBED);
  10211. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  10212. eq->queue_id);
  10213. mbox->vport = eq->phba->pport;
  10214. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10215. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  10216. /* The IOCTL status is embedded in the mailbox subheader. */
  10217. shdr = (union lpfc_sli4_cfg_shdr *)
  10218. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  10219. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10220. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10221. if (shdr_status || shdr_add_status || rc) {
  10222. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10223. "2505 EQ_DESTROY mailbox failed with "
  10224. "status x%x add_status x%x, mbx status x%x\n",
  10225. shdr_status, shdr_add_status, rc);
  10226. status = -ENXIO;
  10227. }
  10228. /* Remove eq from any list */
  10229. list_del_init(&eq->list);
  10230. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10231. return status;
  10232. }
  10233. /**
  10234. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10235. * @cq: The queue structure associated with the queue to destroy.
  10236. *
  10237. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10238. * command, specific to the type of queue, to the HBA.
  10239. *
  10240. * The @cq struct is used to get the queue ID of the queue to destroy.
  10241. *
  10242. * On success this function will return a zero. If the queue destroy mailbox
  10243. * command fails this function will return -ENXIO.
  10244. **/
  10245. uint32_t
  10246. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10247. {
  10248. LPFC_MBOXQ_t *mbox;
  10249. int rc, length, status = 0;
  10250. uint32_t shdr_status, shdr_add_status;
  10251. union lpfc_sli4_cfg_shdr *shdr;
  10252. if (!cq)
  10253. return -ENODEV;
  10254. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10255. if (!mbox)
  10256. return -ENOMEM;
  10257. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10258. sizeof(struct lpfc_sli4_cfg_mhdr));
  10259. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10260. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10261. length, LPFC_SLI4_MBX_EMBED);
  10262. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10263. cq->queue_id);
  10264. mbox->vport = cq->phba->pport;
  10265. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10266. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10267. /* The IOCTL status is embedded in the mailbox subheader. */
  10268. shdr = (union lpfc_sli4_cfg_shdr *)
  10269. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10270. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10271. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10272. if (shdr_status || shdr_add_status || rc) {
  10273. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10274. "2506 CQ_DESTROY mailbox failed with "
  10275. "status x%x add_status x%x, mbx status x%x\n",
  10276. shdr_status, shdr_add_status, rc);
  10277. status = -ENXIO;
  10278. }
  10279. /* Remove cq from any list */
  10280. list_del_init(&cq->list);
  10281. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10282. return status;
  10283. }
  10284. /**
  10285. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10286. * @qm: The queue structure associated with the queue to destroy.
  10287. *
  10288. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10289. * command, specific to the type of queue, to the HBA.
  10290. *
  10291. * The @mq struct is used to get the queue ID of the queue to destroy.
  10292. *
  10293. * On success this function will return a zero. If the queue destroy mailbox
  10294. * command fails this function will return -ENXIO.
  10295. **/
  10296. uint32_t
  10297. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10298. {
  10299. LPFC_MBOXQ_t *mbox;
  10300. int rc, length, status = 0;
  10301. uint32_t shdr_status, shdr_add_status;
  10302. union lpfc_sli4_cfg_shdr *shdr;
  10303. if (!mq)
  10304. return -ENODEV;
  10305. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10306. if (!mbox)
  10307. return -ENOMEM;
  10308. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10309. sizeof(struct lpfc_sli4_cfg_mhdr));
  10310. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10311. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10312. length, LPFC_SLI4_MBX_EMBED);
  10313. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10314. mq->queue_id);
  10315. mbox->vport = mq->phba->pport;
  10316. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10317. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10318. /* The IOCTL status is embedded in the mailbox subheader. */
  10319. shdr = (union lpfc_sli4_cfg_shdr *)
  10320. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10321. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10322. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10323. if (shdr_status || shdr_add_status || rc) {
  10324. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10325. "2507 MQ_DESTROY mailbox failed with "
  10326. "status x%x add_status x%x, mbx status x%x\n",
  10327. shdr_status, shdr_add_status, rc);
  10328. status = -ENXIO;
  10329. }
  10330. /* Remove mq from any list */
  10331. list_del_init(&mq->list);
  10332. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10333. return status;
  10334. }
  10335. /**
  10336. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10337. * @wq: The queue structure associated with the queue to destroy.
  10338. *
  10339. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10340. * command, specific to the type of queue, to the HBA.
  10341. *
  10342. * The @wq struct is used to get the queue ID of the queue to destroy.
  10343. *
  10344. * On success this function will return a zero. If the queue destroy mailbox
  10345. * command fails this function will return -ENXIO.
  10346. **/
  10347. uint32_t
  10348. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10349. {
  10350. LPFC_MBOXQ_t *mbox;
  10351. int rc, length, status = 0;
  10352. uint32_t shdr_status, shdr_add_status;
  10353. union lpfc_sli4_cfg_shdr *shdr;
  10354. if (!wq)
  10355. return -ENODEV;
  10356. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10357. if (!mbox)
  10358. return -ENOMEM;
  10359. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10360. sizeof(struct lpfc_sli4_cfg_mhdr));
  10361. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10362. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10363. length, LPFC_SLI4_MBX_EMBED);
  10364. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10365. wq->queue_id);
  10366. mbox->vport = wq->phba->pport;
  10367. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10368. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10369. shdr = (union lpfc_sli4_cfg_shdr *)
  10370. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10371. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10372. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10373. if (shdr_status || shdr_add_status || rc) {
  10374. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10375. "2508 WQ_DESTROY mailbox failed with "
  10376. "status x%x add_status x%x, mbx status x%x\n",
  10377. shdr_status, shdr_add_status, rc);
  10378. status = -ENXIO;
  10379. }
  10380. /* Remove wq from any list */
  10381. list_del_init(&wq->list);
  10382. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10383. return status;
  10384. }
  10385. /**
  10386. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10387. * @rq: The queue structure associated with the queue to destroy.
  10388. *
  10389. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10390. * command, specific to the type of queue, to the HBA.
  10391. *
  10392. * The @rq struct is used to get the queue ID of the queue to destroy.
  10393. *
  10394. * On success this function will return a zero. If the queue destroy mailbox
  10395. * command fails this function will return -ENXIO.
  10396. **/
  10397. uint32_t
  10398. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10399. struct lpfc_queue *drq)
  10400. {
  10401. LPFC_MBOXQ_t *mbox;
  10402. int rc, length, status = 0;
  10403. uint32_t shdr_status, shdr_add_status;
  10404. union lpfc_sli4_cfg_shdr *shdr;
  10405. if (!hrq || !drq)
  10406. return -ENODEV;
  10407. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10408. if (!mbox)
  10409. return -ENOMEM;
  10410. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10411. sizeof(struct lpfc_sli4_cfg_mhdr));
  10412. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10413. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10414. length, LPFC_SLI4_MBX_EMBED);
  10415. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10416. hrq->queue_id);
  10417. mbox->vport = hrq->phba->pport;
  10418. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10419. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10420. /* The IOCTL status is embedded in the mailbox subheader. */
  10421. shdr = (union lpfc_sli4_cfg_shdr *)
  10422. &mbox->u.mqe.un.rq_destroy.header.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 (shdr_status || shdr_add_status || rc) {
  10426. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10427. "2509 RQ_DESTROY mailbox failed with "
  10428. "status x%x add_status x%x, mbx status x%x\n",
  10429. shdr_status, shdr_add_status, rc);
  10430. if (rc != MBX_TIMEOUT)
  10431. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10432. return -ENXIO;
  10433. }
  10434. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10435. drq->queue_id);
  10436. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10437. shdr = (union lpfc_sli4_cfg_shdr *)
  10438. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10439. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10440. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10441. if (shdr_status || shdr_add_status || rc) {
  10442. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10443. "2510 RQ_DESTROY mailbox failed with "
  10444. "status x%x add_status x%x, mbx status x%x\n",
  10445. shdr_status, shdr_add_status, rc);
  10446. status = -ENXIO;
  10447. }
  10448. list_del_init(&hrq->list);
  10449. list_del_init(&drq->list);
  10450. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10451. return status;
  10452. }
  10453. /**
  10454. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10455. * @phba: The virtual port for which this call being executed.
  10456. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10457. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10458. * @xritag: the xritag that ties this io to the SGL pages.
  10459. *
  10460. * This routine will post the sgl pages for the IO that has the xritag
  10461. * that is in the iocbq structure. The xritag is assigned during iocbq
  10462. * creation and persists for as long as the driver is loaded.
  10463. * if the caller has fewer than 256 scatter gather segments to map then
  10464. * pdma_phys_addr1 should be 0.
  10465. * If the caller needs to map more than 256 scatter gather segment then
  10466. * pdma_phys_addr1 should be a valid physical address.
  10467. * physical address for SGLs must be 64 byte aligned.
  10468. * If you are going to map 2 SGL's then the first one must have 256 entries
  10469. * the second sgl can have between 1 and 256 entries.
  10470. *
  10471. * Return codes:
  10472. * 0 - Success
  10473. * -ENXIO, -ENOMEM - Failure
  10474. **/
  10475. int
  10476. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10477. dma_addr_t pdma_phys_addr0,
  10478. dma_addr_t pdma_phys_addr1,
  10479. uint16_t xritag)
  10480. {
  10481. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10482. LPFC_MBOXQ_t *mbox;
  10483. int rc;
  10484. uint32_t shdr_status, shdr_add_status;
  10485. union lpfc_sli4_cfg_shdr *shdr;
  10486. if (xritag == NO_XRI) {
  10487. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10488. "0364 Invalid param:\n");
  10489. return -EINVAL;
  10490. }
  10491. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10492. if (!mbox)
  10493. return -ENOMEM;
  10494. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10495. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10496. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10497. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  10498. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10499. &mbox->u.mqe.un.post_sgl_pages;
  10500. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10501. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10502. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10503. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10504. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10505. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10506. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10507. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10508. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10509. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10510. if (!phba->sli4_hba.intr_enable)
  10511. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10512. else
  10513. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10514. /* The IOCTL status is embedded in the mailbox subheader. */
  10515. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10516. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10517. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10518. if (rc != MBX_TIMEOUT)
  10519. mempool_free(mbox, phba->mbox_mem_pool);
  10520. if (shdr_status || shdr_add_status || rc) {
  10521. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10522. "2511 POST_SGL mailbox failed with "
  10523. "status x%x add_status x%x, mbx status x%x\n",
  10524. shdr_status, shdr_add_status, rc);
  10525. rc = -ENXIO;
  10526. }
  10527. return 0;
  10528. }
  10529. /**
  10530. * lpfc_sli4_next_xritag - Get an xritag for the io
  10531. * @phba: Pointer to HBA context object.
  10532. *
  10533. * This function gets an xritag for the iocb. If there is no unused xritag
  10534. * it will return 0xffff.
  10535. * The function returns the allocated xritag if successful, else returns zero.
  10536. * Zero is not a valid xritag.
  10537. * The caller is not required to hold any lock.
  10538. **/
  10539. uint16_t
  10540. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10541. {
  10542. uint16_t xritag;
  10543. spin_lock_irq(&phba->hbalock);
  10544. xritag = phba->sli4_hba.next_xri;
  10545. if ((xritag != (uint16_t) -1) && xritag <
  10546. (phba->sli4_hba.max_cfg_param.max_xri
  10547. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10548. phba->sli4_hba.next_xri++;
  10549. phba->sli4_hba.max_cfg_param.xri_used++;
  10550. spin_unlock_irq(&phba->hbalock);
  10551. return xritag;
  10552. }
  10553. spin_unlock_irq(&phba->hbalock);
  10554. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10555. "2004 Failed to allocate XRI.last XRITAG is %d"
  10556. " Max XRI is %d, Used XRI is %d\n",
  10557. phba->sli4_hba.next_xri,
  10558. phba->sli4_hba.max_cfg_param.max_xri,
  10559. phba->sli4_hba.max_cfg_param.xri_used);
  10560. return -1;
  10561. }
  10562. /**
  10563. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10564. * @phba: pointer to lpfc hba data structure.
  10565. *
  10566. * This routine is invoked to post a block of driver's sgl pages to the
  10567. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10568. * is only called when the driver is loading and after all IO has been
  10569. * stopped.
  10570. **/
  10571. int
  10572. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10573. {
  10574. struct lpfc_sglq *sglq_entry;
  10575. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10576. struct sgl_page_pairs *sgl_pg_pairs;
  10577. void *viraddr;
  10578. LPFC_MBOXQ_t *mbox;
  10579. uint32_t reqlen, alloclen, pg_pairs;
  10580. uint32_t mbox_tmo;
  10581. uint16_t xritag_start = 0;
  10582. int els_xri_cnt, rc = 0;
  10583. uint32_t shdr_status, shdr_add_status;
  10584. union lpfc_sli4_cfg_shdr *shdr;
  10585. /* The number of sgls to be posted */
  10586. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10587. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10588. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10589. if (reqlen > SLI4_PAGE_SIZE) {
  10590. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10591. "2559 Block sgl registration required DMA "
  10592. "size (%d) great than a page\n", reqlen);
  10593. return -ENOMEM;
  10594. }
  10595. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10596. if (!mbox) {
  10597. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10598. "2560 Failed to allocate mbox cmd memory\n");
  10599. return -ENOMEM;
  10600. }
  10601. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10602. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10603. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10604. LPFC_SLI4_MBX_NEMBED);
  10605. if (alloclen < reqlen) {
  10606. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10607. "0285 Allocated DMA memory size (%d) is "
  10608. "less than the requested DMA memory "
  10609. "size (%d)\n", alloclen, reqlen);
  10610. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10611. return -ENOMEM;
  10612. }
  10613. /* Get the first SGE entry from the non-embedded DMA memory */
  10614. viraddr = mbox->sge_array->addr[0];
  10615. /* Set up the SGL pages in the non-embedded DMA pages */
  10616. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10617. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10618. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10619. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10620. /* Set up the sge entry */
  10621. sgl_pg_pairs->sgl_pg0_addr_lo =
  10622. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10623. sgl_pg_pairs->sgl_pg0_addr_hi =
  10624. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10625. sgl_pg_pairs->sgl_pg1_addr_lo =
  10626. cpu_to_le32(putPaddrLow(0));
  10627. sgl_pg_pairs->sgl_pg1_addr_hi =
  10628. cpu_to_le32(putPaddrHigh(0));
  10629. /* Keep the first xritag on the list */
  10630. if (pg_pairs == 0)
  10631. xritag_start = sglq_entry->sli4_xritag;
  10632. sgl_pg_pairs++;
  10633. }
  10634. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10635. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10636. /* Perform endian conversion if necessary */
  10637. sgl->word0 = cpu_to_le32(sgl->word0);
  10638. if (!phba->sli4_hba.intr_enable)
  10639. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10640. else {
  10641. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10642. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10643. }
  10644. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10645. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10646. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10647. if (rc != MBX_TIMEOUT)
  10648. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10649. if (shdr_status || shdr_add_status || rc) {
  10650. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10651. "2513 POST_SGL_BLOCK mailbox command failed "
  10652. "status x%x add_status x%x mbx status x%x\n",
  10653. shdr_status, shdr_add_status, rc);
  10654. rc = -ENXIO;
  10655. }
  10656. return rc;
  10657. }
  10658. /**
  10659. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10660. * @phba: pointer to lpfc hba data structure.
  10661. * @sblist: pointer to scsi buffer list.
  10662. * @count: number of scsi buffers on the list.
  10663. *
  10664. * This routine is invoked to post a block of @count scsi sgl pages from a
  10665. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10666. * No Lock is held.
  10667. *
  10668. **/
  10669. int
  10670. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10671. int cnt)
  10672. {
  10673. struct lpfc_scsi_buf *psb;
  10674. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10675. struct sgl_page_pairs *sgl_pg_pairs;
  10676. void *viraddr;
  10677. LPFC_MBOXQ_t *mbox;
  10678. uint32_t reqlen, alloclen, pg_pairs;
  10679. uint32_t mbox_tmo;
  10680. uint16_t xritag_start = 0;
  10681. int rc = 0;
  10682. uint32_t shdr_status, shdr_add_status;
  10683. dma_addr_t pdma_phys_bpl1;
  10684. union lpfc_sli4_cfg_shdr *shdr;
  10685. /* Calculate the requested length of the dma memory */
  10686. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10687. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10688. if (reqlen > SLI4_PAGE_SIZE) {
  10689. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10690. "0217 Block sgl registration required DMA "
  10691. "size (%d) great than a page\n", reqlen);
  10692. return -ENOMEM;
  10693. }
  10694. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10695. if (!mbox) {
  10696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10697. "0283 Failed to allocate mbox cmd memory\n");
  10698. return -ENOMEM;
  10699. }
  10700. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10701. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10702. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10703. LPFC_SLI4_MBX_NEMBED);
  10704. if (alloclen < reqlen) {
  10705. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10706. "2561 Allocated DMA memory size (%d) is "
  10707. "less than the requested DMA memory "
  10708. "size (%d)\n", alloclen, reqlen);
  10709. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10710. return -ENOMEM;
  10711. }
  10712. /* Get the first SGE entry from the non-embedded DMA memory */
  10713. viraddr = mbox->sge_array->addr[0];
  10714. /* Set up the SGL pages in the non-embedded DMA pages */
  10715. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10716. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10717. pg_pairs = 0;
  10718. list_for_each_entry(psb, sblist, list) {
  10719. /* Set up the sge entry */
  10720. sgl_pg_pairs->sgl_pg0_addr_lo =
  10721. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10722. sgl_pg_pairs->sgl_pg0_addr_hi =
  10723. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10724. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10725. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10726. else
  10727. pdma_phys_bpl1 = 0;
  10728. sgl_pg_pairs->sgl_pg1_addr_lo =
  10729. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10730. sgl_pg_pairs->sgl_pg1_addr_hi =
  10731. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10732. /* Keep the first xritag on the list */
  10733. if (pg_pairs == 0)
  10734. xritag_start = psb->cur_iocbq.sli4_xritag;
  10735. sgl_pg_pairs++;
  10736. pg_pairs++;
  10737. }
  10738. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10739. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10740. /* Perform endian conversion if necessary */
  10741. sgl->word0 = cpu_to_le32(sgl->word0);
  10742. if (!phba->sli4_hba.intr_enable)
  10743. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10744. else {
  10745. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10746. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10747. }
  10748. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10749. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10750. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10751. if (rc != MBX_TIMEOUT)
  10752. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10753. if (shdr_status || shdr_add_status || rc) {
  10754. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10755. "2564 POST_SGL_BLOCK mailbox command failed "
  10756. "status x%x add_status x%x mbx status x%x\n",
  10757. shdr_status, shdr_add_status, rc);
  10758. rc = -ENXIO;
  10759. }
  10760. return rc;
  10761. }
  10762. /**
  10763. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10764. * @phba: pointer to lpfc_hba struct that the frame was received on
  10765. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10766. *
  10767. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10768. * valid type of frame that the LPFC driver will handle. This function will
  10769. * return a zero if the frame is a valid frame or a non zero value when the
  10770. * frame does not pass the check.
  10771. **/
  10772. static int
  10773. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10774. {
  10775. /* make rctl_names static to save stack space */
  10776. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10777. char *type_names[] = FC_TYPE_NAMES_INIT;
  10778. struct fc_vft_header *fc_vft_hdr;
  10779. uint32_t *header = (uint32_t *) fc_hdr;
  10780. switch (fc_hdr->fh_r_ctl) {
  10781. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10782. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10783. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10784. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10785. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10786. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10787. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10788. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10789. case FC_RCTL_ELS_REQ: /* extended link services request */
  10790. case FC_RCTL_ELS_REP: /* extended link services reply */
  10791. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10792. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10793. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10794. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10795. case FC_RCTL_BA_RMC: /* remove connection */
  10796. case FC_RCTL_BA_ACC: /* basic accept */
  10797. case FC_RCTL_BA_RJT: /* basic reject */
  10798. case FC_RCTL_BA_PRMT:
  10799. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10800. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10801. case FC_RCTL_P_RJT: /* port reject */
  10802. case FC_RCTL_F_RJT: /* fabric reject */
  10803. case FC_RCTL_P_BSY: /* port busy */
  10804. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10805. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10806. case FC_RCTL_LCR: /* link credit reset */
  10807. case FC_RCTL_END: /* end */
  10808. break;
  10809. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10810. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10811. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10812. return lpfc_fc_frame_check(phba, fc_hdr);
  10813. default:
  10814. goto drop;
  10815. }
  10816. switch (fc_hdr->fh_type) {
  10817. case FC_TYPE_BLS:
  10818. case FC_TYPE_ELS:
  10819. case FC_TYPE_FCP:
  10820. case FC_TYPE_CT:
  10821. break;
  10822. case FC_TYPE_IP:
  10823. case FC_TYPE_ILS:
  10824. default:
  10825. goto drop;
  10826. }
  10827. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10828. "2538 Received frame rctl:%s type:%s "
  10829. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  10830. rctl_names[fc_hdr->fh_r_ctl],
  10831. type_names[fc_hdr->fh_type],
  10832. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  10833. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  10834. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  10835. return 0;
  10836. drop:
  10837. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10838. "2539 Dropped frame rctl:%s type:%s\n",
  10839. rctl_names[fc_hdr->fh_r_ctl],
  10840. type_names[fc_hdr->fh_type]);
  10841. return 1;
  10842. }
  10843. /**
  10844. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10845. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10846. *
  10847. * This function processes the FC header to retrieve the VFI from the VF
  10848. * header, if one exists. This function will return the VFI if one exists
  10849. * or 0 if no VSAN Header exists.
  10850. **/
  10851. static uint32_t
  10852. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10853. {
  10854. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10855. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10856. return 0;
  10857. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10858. }
  10859. /**
  10860. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10861. * @phba: Pointer to the HBA structure to search for the vport on
  10862. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10863. * @fcfi: The FC Fabric ID that the frame came from
  10864. *
  10865. * This function searches the @phba for a vport that matches the content of the
  10866. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10867. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10868. * returns the matching vport pointer or NULL if unable to match frame to a
  10869. * vport.
  10870. **/
  10871. static struct lpfc_vport *
  10872. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10873. uint16_t fcfi)
  10874. {
  10875. struct lpfc_vport **vports;
  10876. struct lpfc_vport *vport = NULL;
  10877. int i;
  10878. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10879. fc_hdr->fh_d_id[1] << 8 |
  10880. fc_hdr->fh_d_id[2]);
  10881. vports = lpfc_create_vport_work_array(phba);
  10882. if (vports != NULL)
  10883. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10884. if (phba->fcf.fcfi == fcfi &&
  10885. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10886. vports[i]->fc_myDID == did) {
  10887. vport = vports[i];
  10888. break;
  10889. }
  10890. }
  10891. lpfc_destroy_vport_work_array(phba, vports);
  10892. return vport;
  10893. }
  10894. /**
  10895. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10896. * @vport: The vport to work on.
  10897. *
  10898. * This function updates the receive sequence time stamp for this vport. The
  10899. * receive sequence time stamp indicates the time that the last frame of the
  10900. * the sequence that has been idle for the longest amount of time was received.
  10901. * the driver uses this time stamp to indicate if any received sequences have
  10902. * timed out.
  10903. **/
  10904. void
  10905. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10906. {
  10907. struct lpfc_dmabuf *h_buf;
  10908. struct hbq_dmabuf *dmabuf = NULL;
  10909. /* get the oldest sequence on the rcv list */
  10910. h_buf = list_get_first(&vport->rcv_buffer_list,
  10911. struct lpfc_dmabuf, list);
  10912. if (!h_buf)
  10913. return;
  10914. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10915. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10916. }
  10917. /**
  10918. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10919. * @vport: The vport that the received sequences were sent to.
  10920. *
  10921. * This function cleans up all outstanding received sequences. This is called
  10922. * by the driver when a link event or user action invalidates all the received
  10923. * sequences.
  10924. **/
  10925. void
  10926. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10927. {
  10928. struct lpfc_dmabuf *h_buf, *hnext;
  10929. struct lpfc_dmabuf *d_buf, *dnext;
  10930. struct hbq_dmabuf *dmabuf = NULL;
  10931. /* start with the oldest sequence on the rcv list */
  10932. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10933. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10934. list_del_init(&dmabuf->hbuf.list);
  10935. list_for_each_entry_safe(d_buf, dnext,
  10936. &dmabuf->dbuf.list, list) {
  10937. list_del_init(&d_buf->list);
  10938. lpfc_in_buf_free(vport->phba, d_buf);
  10939. }
  10940. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10941. }
  10942. }
  10943. /**
  10944. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10945. * @vport: The vport that the received sequences were sent to.
  10946. *
  10947. * This function determines whether any received sequences have timed out by
  10948. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10949. * indicates that there is at least one timed out sequence this routine will
  10950. * go through the received sequences one at a time from most inactive to most
  10951. * active to determine which ones need to be cleaned up. Once it has determined
  10952. * that a sequence needs to be cleaned up it will simply free up the resources
  10953. * without sending an abort.
  10954. **/
  10955. void
  10956. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10957. {
  10958. struct lpfc_dmabuf *h_buf, *hnext;
  10959. struct lpfc_dmabuf *d_buf, *dnext;
  10960. struct hbq_dmabuf *dmabuf = NULL;
  10961. unsigned long timeout;
  10962. int abort_count = 0;
  10963. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10964. vport->rcv_buffer_time_stamp);
  10965. if (list_empty(&vport->rcv_buffer_list) ||
  10966. time_before(jiffies, timeout))
  10967. return;
  10968. /* start with the oldest sequence on the rcv list */
  10969. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10970. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10971. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10972. dmabuf->time_stamp);
  10973. if (time_before(jiffies, timeout))
  10974. break;
  10975. abort_count++;
  10976. list_del_init(&dmabuf->hbuf.list);
  10977. list_for_each_entry_safe(d_buf, dnext,
  10978. &dmabuf->dbuf.list, list) {
  10979. list_del_init(&d_buf->list);
  10980. lpfc_in_buf_free(vport->phba, d_buf);
  10981. }
  10982. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10983. }
  10984. if (abort_count)
  10985. lpfc_update_rcv_time_stamp(vport);
  10986. }
  10987. /**
  10988. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10989. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10990. *
  10991. * This function searches through the existing incomplete sequences that have
  10992. * been sent to this @vport. If the frame matches one of the incomplete
  10993. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10994. * make up that sequence. If no sequence is found that matches this frame then
  10995. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10996. * This function returns a pointer to the first dmabuf in the sequence list that
  10997. * the frame was linked to.
  10998. **/
  10999. static struct hbq_dmabuf *
  11000. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  11001. {
  11002. struct fc_frame_header *new_hdr;
  11003. struct fc_frame_header *temp_hdr;
  11004. struct lpfc_dmabuf *d_buf;
  11005. struct lpfc_dmabuf *h_buf;
  11006. struct hbq_dmabuf *seq_dmabuf = NULL;
  11007. struct hbq_dmabuf *temp_dmabuf = NULL;
  11008. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  11009. dmabuf->time_stamp = jiffies;
  11010. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11011. /* Use the hdr_buf to find the sequence that this frame belongs to */
  11012. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  11013. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  11014. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  11015. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  11016. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  11017. continue;
  11018. /* found a pending sequence that matches this frame */
  11019. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  11020. break;
  11021. }
  11022. if (!seq_dmabuf) {
  11023. /*
  11024. * This indicates first frame received for this sequence.
  11025. * Queue the buffer on the vport's rcv_buffer_list.
  11026. */
  11027. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11028. lpfc_update_rcv_time_stamp(vport);
  11029. return dmabuf;
  11030. }
  11031. temp_hdr = seq_dmabuf->hbuf.virt;
  11032. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  11033. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  11034. list_del_init(&seq_dmabuf->hbuf.list);
  11035. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11036. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  11037. lpfc_update_rcv_time_stamp(vport);
  11038. return dmabuf;
  11039. }
  11040. /* move this sequence to the tail to indicate a young sequence */
  11041. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11042. seq_dmabuf->time_stamp = jiffies;
  11043. lpfc_update_rcv_time_stamp(vport);
  11044. if (list_empty(&seq_dmabuf->dbuf.list)) {
  11045. temp_hdr = dmabuf->hbuf.virt;
  11046. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  11047. return seq_dmabuf;
  11048. }
  11049. /* find the correct place in the sequence to insert this frame */
  11050. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  11051. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11052. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  11053. /*
  11054. * If the frame's sequence count is greater than the frame on
  11055. * the list then insert the frame right after this frame
  11056. */
  11057. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  11058. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  11059. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  11060. return seq_dmabuf;
  11061. }
  11062. }
  11063. return NULL;
  11064. }
  11065. /**
  11066. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  11067. * @vport: pointer to a vitural port
  11068. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11069. *
  11070. * This function tries to abort from the partially assembed sequence, described
  11071. * by the information from basic abbort @dmabuf. It checks to see whether such
  11072. * partially assembled sequence held by the driver. If so, it shall free up all
  11073. * the frames from the partially assembled sequence.
  11074. *
  11075. * Return
  11076. * true -- if there is matching partially assembled sequence present and all
  11077. * the frames freed with the sequence;
  11078. * false -- if there is no matching partially assembled sequence present so
  11079. * nothing got aborted in the lower layer driver
  11080. **/
  11081. static bool
  11082. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  11083. struct hbq_dmabuf *dmabuf)
  11084. {
  11085. struct fc_frame_header *new_hdr;
  11086. struct fc_frame_header *temp_hdr;
  11087. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  11088. struct hbq_dmabuf *seq_dmabuf = NULL;
  11089. /* Use the hdr_buf to find the sequence that matches this frame */
  11090. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  11091. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  11092. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11093. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  11094. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  11095. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  11096. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  11097. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  11098. continue;
  11099. /* found a pending sequence that matches this frame */
  11100. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  11101. break;
  11102. }
  11103. /* Free up all the frames from the partially assembled sequence */
  11104. if (seq_dmabuf) {
  11105. list_for_each_entry_safe(d_buf, n_buf,
  11106. &seq_dmabuf->dbuf.list, list) {
  11107. list_del_init(&d_buf->list);
  11108. lpfc_in_buf_free(vport->phba, d_buf);
  11109. }
  11110. return true;
  11111. }
  11112. return false;
  11113. }
  11114. /**
  11115. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  11116. * @phba: Pointer to HBA context object.
  11117. * @cmd_iocbq: pointer to the command iocbq structure.
  11118. * @rsp_iocbq: pointer to the response iocbq structure.
  11119. *
  11120. * This function handles the sequence abort response iocb command complete
  11121. * event. It properly releases the memory allocated to the sequence abort
  11122. * accept iocb.
  11123. **/
  11124. static void
  11125. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  11126. struct lpfc_iocbq *cmd_iocbq,
  11127. struct lpfc_iocbq *rsp_iocbq)
  11128. {
  11129. if (cmd_iocbq)
  11130. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  11131. }
  11132. /**
  11133. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  11134. * @phba: Pointer to HBA context object.
  11135. * @fc_hdr: pointer to a FC frame header.
  11136. *
  11137. * This function sends a basic response to a previous unsol sequence abort
  11138. * event after aborting the sequence handling.
  11139. **/
  11140. static void
  11141. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  11142. struct fc_frame_header *fc_hdr)
  11143. {
  11144. struct lpfc_iocbq *ctiocb = NULL;
  11145. struct lpfc_nodelist *ndlp;
  11146. uint16_t oxid, rxid;
  11147. uint32_t sid, fctl;
  11148. IOCB_t *icmd;
  11149. int rc;
  11150. if (!lpfc_is_link_up(phba))
  11151. return;
  11152. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11153. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  11154. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  11155. ndlp = lpfc_findnode_did(phba->pport, sid);
  11156. if (!ndlp) {
  11157. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  11158. "1268 Find ndlp returned NULL for oxid:x%x "
  11159. "SID:x%x\n", oxid, sid);
  11160. return;
  11161. }
  11162. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  11163. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  11164. + phba->sli4_hba.max_cfg_param.xri_base))
  11165. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  11166. /* Allocate buffer for rsp iocb */
  11167. ctiocb = lpfc_sli_get_iocbq(phba);
  11168. if (!ctiocb)
  11169. return;
  11170. /* Extract the F_CTL field from FC_HDR */
  11171. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  11172. icmd = &ctiocb->iocb;
  11173. icmd->un.xseq64.bdl.bdeSize = 0;
  11174. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  11175. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  11176. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  11177. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  11178. /* Fill in the rest of iocb fields */
  11179. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  11180. icmd->ulpBdeCount = 0;
  11181. icmd->ulpLe = 1;
  11182. icmd->ulpClass = CLASS3;
  11183. icmd->ulpContext = ndlp->nlp_rpi;
  11184. ctiocb->context1 = ndlp;
  11185. ctiocb->iocb_cmpl = NULL;
  11186. ctiocb->vport = phba->pport;
  11187. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  11188. ctiocb->sli4_xritag = NO_XRI;
  11189. /* If the oxid maps to the FCP XRI range or if it is out of range,
  11190. * send a BLS_RJT. The driver no longer has that exchange.
  11191. * Override the IOCB for a BA_RJT.
  11192. */
  11193. if (oxid > (phba->sli4_hba.max_cfg_param.max_xri +
  11194. phba->sli4_hba.max_cfg_param.xri_base) ||
  11195. oxid > (lpfc_sli4_get_els_iocb_cnt(phba) +
  11196. phba->sli4_hba.max_cfg_param.xri_base)) {
  11197. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  11198. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  11199. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  11200. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  11201. }
  11202. if (fctl & FC_FC_EX_CTX) {
  11203. /* ABTS sent by responder to CT exchange, construction
  11204. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  11205. * field and RX_ID from ABTS for RX_ID field.
  11206. */
  11207. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  11208. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  11209. } else {
  11210. /* ABTS sent by initiator to CT exchange, construction
  11211. * of BA_ACC will need to allocate a new XRI as for the
  11212. * XRI_TAG and RX_ID fields.
  11213. */
  11214. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  11215. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI);
  11216. }
  11217. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  11218. /* Xmit CT abts response on exchange <xid> */
  11219. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11220. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  11221. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  11222. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  11223. if (rc == IOCB_ERROR) {
  11224. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  11225. "2925 Failed to issue CT ABTS RSP x%x on "
  11226. "xri x%x, Data x%x\n",
  11227. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  11228. phba->link_state);
  11229. lpfc_sli_release_iocbq(phba, ctiocb);
  11230. }
  11231. }
  11232. /**
  11233. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  11234. * @vport: Pointer to the vport on which this sequence was received
  11235. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11236. *
  11237. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  11238. * receive sequence is only partially assembed by the driver, it shall abort
  11239. * the partially assembled frames for the sequence. Otherwise, if the
  11240. * unsolicited receive sequence has been completely assembled and passed to
  11241. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  11242. * unsolicited sequence has been aborted. After that, it will issue a basic
  11243. * accept to accept the abort.
  11244. **/
  11245. void
  11246. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  11247. struct hbq_dmabuf *dmabuf)
  11248. {
  11249. struct lpfc_hba *phba = vport->phba;
  11250. struct fc_frame_header fc_hdr;
  11251. uint32_t fctl;
  11252. bool abts_par;
  11253. /* Make a copy of fc_hdr before the dmabuf being released */
  11254. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11255. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11256. if (fctl & FC_FC_EX_CTX) {
  11257. /*
  11258. * ABTS sent by responder to exchange, just free the buffer
  11259. */
  11260. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11261. } else {
  11262. /*
  11263. * ABTS sent by initiator to exchange, need to do cleanup
  11264. */
  11265. /* Try to abort partially assembled seq */
  11266. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11267. /* Send abort to ULP if partially seq abort failed */
  11268. if (abts_par == false)
  11269. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11270. else
  11271. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11272. }
  11273. /* Send basic accept (BA_ACC) to the abort requester */
  11274. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  11275. }
  11276. /**
  11277. * lpfc_seq_complete - Indicates if a sequence is complete
  11278. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11279. *
  11280. * This function checks the sequence, starting with the frame described by
  11281. * @dmabuf, to see if all the frames associated with this sequence are present.
  11282. * the frames associated with this sequence are linked to the @dmabuf using the
  11283. * dbuf list. This function looks for two major things. 1) That the first frame
  11284. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11285. * set. 3) That there are no holes in the sequence count. The function will
  11286. * return 1 when the sequence is complete, otherwise it will return 0.
  11287. **/
  11288. static int
  11289. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11290. {
  11291. struct fc_frame_header *hdr;
  11292. struct lpfc_dmabuf *d_buf;
  11293. struct hbq_dmabuf *seq_dmabuf;
  11294. uint32_t fctl;
  11295. int seq_count = 0;
  11296. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11297. /* make sure first fame of sequence has a sequence count of zero */
  11298. if (hdr->fh_seq_cnt != seq_count)
  11299. return 0;
  11300. fctl = (hdr->fh_f_ctl[0] << 16 |
  11301. hdr->fh_f_ctl[1] << 8 |
  11302. hdr->fh_f_ctl[2]);
  11303. /* If last frame of sequence we can return success. */
  11304. if (fctl & FC_FC_END_SEQ)
  11305. return 1;
  11306. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11307. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11308. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11309. /* If there is a hole in the sequence count then fail. */
  11310. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11311. return 0;
  11312. fctl = (hdr->fh_f_ctl[0] << 16 |
  11313. hdr->fh_f_ctl[1] << 8 |
  11314. hdr->fh_f_ctl[2]);
  11315. /* If last frame of sequence we can return success. */
  11316. if (fctl & FC_FC_END_SEQ)
  11317. return 1;
  11318. }
  11319. return 0;
  11320. }
  11321. /**
  11322. * lpfc_prep_seq - Prep sequence for ULP processing
  11323. * @vport: Pointer to the vport on which this sequence was received
  11324. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11325. *
  11326. * This function takes a sequence, described by a list of frames, and creates
  11327. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11328. * used to issue to the generic unsolicited sequence handler. This routine
  11329. * returns a pointer to the first iocbq in the list. If the function is unable
  11330. * to allocate an iocbq then it throw out the received frames that were not
  11331. * able to be described and return a pointer to the first iocbq. If unable to
  11332. * allocate any iocbqs (including the first) this function will return NULL.
  11333. **/
  11334. static struct lpfc_iocbq *
  11335. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11336. {
  11337. struct lpfc_dmabuf *d_buf, *n_buf;
  11338. struct lpfc_iocbq *first_iocbq, *iocbq;
  11339. struct fc_frame_header *fc_hdr;
  11340. uint32_t sid;
  11341. struct ulp_bde64 *pbde;
  11342. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11343. /* remove from receive buffer list */
  11344. list_del_init(&seq_dmabuf->hbuf.list);
  11345. lpfc_update_rcv_time_stamp(vport);
  11346. /* get the Remote Port's SID */
  11347. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11348. /* Get an iocbq struct to fill in. */
  11349. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11350. if (first_iocbq) {
  11351. /* Initialize the first IOCB. */
  11352. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11353. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11354. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11355. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11356. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11357. vport->vpi + vport->phba->vpi_base;
  11358. /* put the first buffer into the first IOCBq */
  11359. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11360. first_iocbq->context3 = NULL;
  11361. first_iocbq->iocb.ulpBdeCount = 1;
  11362. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11363. LPFC_DATA_BUF_SIZE;
  11364. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11365. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11366. bf_get(lpfc_rcqe_length,
  11367. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11368. }
  11369. iocbq = first_iocbq;
  11370. /*
  11371. * Each IOCBq can have two Buffers assigned, so go through the list
  11372. * of buffers for this sequence and save two buffers in each IOCBq
  11373. */
  11374. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11375. if (!iocbq) {
  11376. lpfc_in_buf_free(vport->phba, d_buf);
  11377. continue;
  11378. }
  11379. if (!iocbq->context3) {
  11380. iocbq->context3 = d_buf;
  11381. iocbq->iocb.ulpBdeCount++;
  11382. pbde = (struct ulp_bde64 *)
  11383. &iocbq->iocb.unsli3.sli3Words[4];
  11384. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11385. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11386. bf_get(lpfc_rcqe_length,
  11387. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11388. } else {
  11389. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11390. if (!iocbq) {
  11391. if (first_iocbq) {
  11392. first_iocbq->iocb.ulpStatus =
  11393. IOSTAT_FCP_RSP_ERROR;
  11394. first_iocbq->iocb.un.ulpWord[4] =
  11395. IOERR_NO_RESOURCES;
  11396. }
  11397. lpfc_in_buf_free(vport->phba, d_buf);
  11398. continue;
  11399. }
  11400. iocbq->context2 = d_buf;
  11401. iocbq->context3 = NULL;
  11402. iocbq->iocb.ulpBdeCount = 1;
  11403. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11404. LPFC_DATA_BUF_SIZE;
  11405. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11406. bf_get(lpfc_rcqe_length,
  11407. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11408. iocbq->iocb.un.rcvels.remoteID = sid;
  11409. list_add_tail(&iocbq->list, &first_iocbq->list);
  11410. }
  11411. }
  11412. return first_iocbq;
  11413. }
  11414. static void
  11415. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11416. struct hbq_dmabuf *seq_dmabuf)
  11417. {
  11418. struct fc_frame_header *fc_hdr;
  11419. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11420. struct lpfc_hba *phba = vport->phba;
  11421. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11422. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11423. if (!iocbq) {
  11424. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11425. "2707 Ring %d handler: Failed to allocate "
  11426. "iocb Rctl x%x Type x%x received\n",
  11427. LPFC_ELS_RING,
  11428. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11429. return;
  11430. }
  11431. if (!lpfc_complete_unsol_iocb(phba,
  11432. &phba->sli.ring[LPFC_ELS_RING],
  11433. iocbq, fc_hdr->fh_r_ctl,
  11434. fc_hdr->fh_type))
  11435. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11436. "2540 Ring %d handler: unexpected Rctl "
  11437. "x%x Type x%x received\n",
  11438. LPFC_ELS_RING,
  11439. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11440. /* Free iocb created in lpfc_prep_seq */
  11441. list_for_each_entry_safe(curr_iocb, next_iocb,
  11442. &iocbq->list, list) {
  11443. list_del_init(&curr_iocb->list);
  11444. lpfc_sli_release_iocbq(phba, curr_iocb);
  11445. }
  11446. lpfc_sli_release_iocbq(phba, iocbq);
  11447. }
  11448. /**
  11449. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11450. * @phba: Pointer to HBA context object.
  11451. *
  11452. * This function is called with no lock held. This function processes all
  11453. * the received buffers and gives it to upper layers when a received buffer
  11454. * indicates that it is the final frame in the sequence. The interrupt
  11455. * service routine processes received buffers at interrupt contexts and adds
  11456. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11457. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11458. * appropriate receive function when the final frame in a sequence is received.
  11459. **/
  11460. void
  11461. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11462. struct hbq_dmabuf *dmabuf)
  11463. {
  11464. struct hbq_dmabuf *seq_dmabuf;
  11465. struct fc_frame_header *fc_hdr;
  11466. struct lpfc_vport *vport;
  11467. uint32_t fcfi;
  11468. /* Process each received buffer */
  11469. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11470. /* check to see if this a valid type of frame */
  11471. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11472. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11473. return;
  11474. }
  11475. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11476. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11477. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11478. /* throw out the frame */
  11479. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11480. return;
  11481. }
  11482. /* Handle the basic abort sequence (BA_ABTS) event */
  11483. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11484. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11485. return;
  11486. }
  11487. /* Link this frame */
  11488. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11489. if (!seq_dmabuf) {
  11490. /* unable to add frame to vport - throw it out */
  11491. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11492. return;
  11493. }
  11494. /* If not last frame in sequence continue processing frames. */
  11495. if (!lpfc_seq_complete(seq_dmabuf))
  11496. return;
  11497. /* Send the complete sequence to the upper layer protocol */
  11498. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11499. }
  11500. /**
  11501. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11502. * @phba: pointer to lpfc hba data structure.
  11503. *
  11504. * This routine is invoked to post rpi header templates to the
  11505. * HBA consistent with the SLI-4 interface spec. This routine
  11506. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11507. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11508. *
  11509. * This routine does not require any locks. It's usage is expected
  11510. * to be driver load or reset recovery when the driver is
  11511. * sequential.
  11512. *
  11513. * Return codes
  11514. * 0 - successful
  11515. * -EIO - The mailbox failed to complete successfully.
  11516. * When this error occurs, the driver is not guaranteed
  11517. * to have any rpi regions posted to the device and
  11518. * must either attempt to repost the regions or take a
  11519. * fatal error.
  11520. **/
  11521. int
  11522. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11523. {
  11524. struct lpfc_rpi_hdr *rpi_page;
  11525. uint32_t rc = 0;
  11526. /* Post all rpi memory regions to the port. */
  11527. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11528. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11529. if (rc != MBX_SUCCESS) {
  11530. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11531. "2008 Error %d posting all rpi "
  11532. "headers\n", rc);
  11533. rc = -EIO;
  11534. break;
  11535. }
  11536. }
  11537. return rc;
  11538. }
  11539. /**
  11540. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11541. * @phba: pointer to lpfc hba data structure.
  11542. * @rpi_page: pointer to the rpi memory region.
  11543. *
  11544. * This routine is invoked to post a single rpi header to the
  11545. * HBA consistent with the SLI-4 interface spec. This memory region
  11546. * maps up to 64 rpi context regions.
  11547. *
  11548. * Return codes
  11549. * 0 - successful
  11550. * -ENOMEM - No available memory
  11551. * -EIO - The mailbox failed to complete successfully.
  11552. **/
  11553. int
  11554. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11555. {
  11556. LPFC_MBOXQ_t *mboxq;
  11557. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11558. uint32_t rc = 0;
  11559. uint32_t mbox_tmo;
  11560. uint32_t shdr_status, shdr_add_status;
  11561. union lpfc_sli4_cfg_shdr *shdr;
  11562. /* The port is notified of the header region via a mailbox command. */
  11563. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11564. if (!mboxq) {
  11565. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11566. "2001 Unable to allocate memory for issuing "
  11567. "SLI_CONFIG_SPECIAL mailbox command\n");
  11568. return -ENOMEM;
  11569. }
  11570. /* Post all rpi memory regions to the port. */
  11571. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11572. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11573. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11574. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11575. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11576. sizeof(struct lpfc_sli4_cfg_mhdr),
  11577. LPFC_SLI4_MBX_EMBED);
  11578. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11579. hdr_tmpl, rpi_page->page_count);
  11580. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11581. rpi_page->start_rpi);
  11582. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11583. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11584. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11585. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11586. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11587. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11588. if (rc != MBX_TIMEOUT)
  11589. mempool_free(mboxq, phba->mbox_mem_pool);
  11590. if (shdr_status || shdr_add_status || rc) {
  11591. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11592. "2514 POST_RPI_HDR mailbox failed with "
  11593. "status x%x add_status x%x, mbx status x%x\n",
  11594. shdr_status, shdr_add_status, rc);
  11595. rc = -ENXIO;
  11596. }
  11597. return rc;
  11598. }
  11599. /**
  11600. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11601. * @phba: pointer to lpfc hba data structure.
  11602. *
  11603. * This routine is invoked to post rpi header templates to the
  11604. * HBA consistent with the SLI-4 interface spec. This routine
  11605. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11606. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11607. *
  11608. * Returns
  11609. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11610. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11611. **/
  11612. int
  11613. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11614. {
  11615. int rpi;
  11616. uint16_t max_rpi, rpi_base, rpi_limit;
  11617. uint16_t rpi_remaining;
  11618. struct lpfc_rpi_hdr *rpi_hdr;
  11619. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11620. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11621. rpi_limit = phba->sli4_hba.next_rpi;
  11622. /*
  11623. * The valid rpi range is not guaranteed to be zero-based. Start
  11624. * the search at the rpi_base as reported by the port.
  11625. */
  11626. spin_lock_irq(&phba->hbalock);
  11627. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11628. if (rpi >= rpi_limit || rpi < rpi_base)
  11629. rpi = LPFC_RPI_ALLOC_ERROR;
  11630. else {
  11631. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11632. phba->sli4_hba.max_cfg_param.rpi_used++;
  11633. phba->sli4_hba.rpi_count++;
  11634. }
  11635. /*
  11636. * Don't try to allocate more rpi header regions if the device limit
  11637. * on available rpis max has been exhausted.
  11638. */
  11639. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11640. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11641. spin_unlock_irq(&phba->hbalock);
  11642. return rpi;
  11643. }
  11644. /*
  11645. * If the driver is running low on rpi resources, allocate another
  11646. * page now. Note that the next_rpi value is used because
  11647. * it represents how many are actually in use whereas max_rpi notes
  11648. * how many are supported max by the device.
  11649. */
  11650. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11651. phba->sli4_hba.rpi_count;
  11652. spin_unlock_irq(&phba->hbalock);
  11653. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11654. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11655. if (!rpi_hdr) {
  11656. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11657. "2002 Error Could not grow rpi "
  11658. "count\n");
  11659. } else {
  11660. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11661. }
  11662. }
  11663. return rpi;
  11664. }
  11665. /**
  11666. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11667. * @phba: pointer to lpfc hba data structure.
  11668. *
  11669. * This routine is invoked to release an rpi to the pool of
  11670. * available rpis maintained by the driver.
  11671. **/
  11672. void
  11673. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11674. {
  11675. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11676. phba->sli4_hba.rpi_count--;
  11677. phba->sli4_hba.max_cfg_param.rpi_used--;
  11678. }
  11679. }
  11680. /**
  11681. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11682. * @phba: pointer to lpfc hba data structure.
  11683. *
  11684. * This routine is invoked to release an rpi to the pool of
  11685. * available rpis maintained by the driver.
  11686. **/
  11687. void
  11688. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11689. {
  11690. spin_lock_irq(&phba->hbalock);
  11691. __lpfc_sli4_free_rpi(phba, rpi);
  11692. spin_unlock_irq(&phba->hbalock);
  11693. }
  11694. /**
  11695. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11696. * @phba: pointer to lpfc hba data structure.
  11697. *
  11698. * This routine is invoked to remove the memory region that
  11699. * provided rpi via a bitmask.
  11700. **/
  11701. void
  11702. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11703. {
  11704. kfree(phba->sli4_hba.rpi_bmask);
  11705. }
  11706. /**
  11707. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11708. * @phba: pointer to lpfc hba data structure.
  11709. *
  11710. * This routine is invoked to remove the memory region that
  11711. * provided rpi via a bitmask.
  11712. **/
  11713. int
  11714. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11715. {
  11716. LPFC_MBOXQ_t *mboxq;
  11717. struct lpfc_hba *phba = ndlp->phba;
  11718. int rc;
  11719. /* The port is notified of the header region via a mailbox command. */
  11720. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11721. if (!mboxq)
  11722. return -ENOMEM;
  11723. /* Post all rpi memory regions to the port. */
  11724. lpfc_resume_rpi(mboxq, ndlp);
  11725. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11726. if (rc == MBX_NOT_FINISHED) {
  11727. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11728. "2010 Resume RPI Mailbox failed "
  11729. "status %d, mbxStatus x%x\n", rc,
  11730. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11731. mempool_free(mboxq, phba->mbox_mem_pool);
  11732. return -EIO;
  11733. }
  11734. return 0;
  11735. }
  11736. /**
  11737. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11738. * @vport: Pointer to the vport for which the vpi is being initialized
  11739. *
  11740. * This routine is invoked to activate a vpi with the port.
  11741. *
  11742. * Returns:
  11743. * 0 success
  11744. * -Evalue otherwise
  11745. **/
  11746. int
  11747. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11748. {
  11749. LPFC_MBOXQ_t *mboxq;
  11750. int rc = 0;
  11751. int retval = MBX_SUCCESS;
  11752. uint32_t mbox_tmo;
  11753. struct lpfc_hba *phba = vport->phba;
  11754. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11755. if (!mboxq)
  11756. return -ENOMEM;
  11757. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11758. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11759. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11760. if (rc != MBX_SUCCESS) {
  11761. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11762. "2022 INIT VPI Mailbox failed "
  11763. "status %d, mbxStatus x%x\n", rc,
  11764. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11765. retval = -EIO;
  11766. }
  11767. if (rc != MBX_TIMEOUT)
  11768. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11769. return retval;
  11770. }
  11771. /**
  11772. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11773. * @phba: pointer to lpfc hba data structure.
  11774. * @mboxq: Pointer to mailbox object.
  11775. *
  11776. * This routine is invoked to manually add a single FCF record. The caller
  11777. * must pass a completely initialized FCF_Record. This routine takes
  11778. * care of the nonembedded mailbox operations.
  11779. **/
  11780. static void
  11781. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11782. {
  11783. void *virt_addr;
  11784. union lpfc_sli4_cfg_shdr *shdr;
  11785. uint32_t shdr_status, shdr_add_status;
  11786. virt_addr = mboxq->sge_array->addr[0];
  11787. /* The IOCTL status is embedded in the mailbox subheader. */
  11788. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11789. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11790. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11791. if ((shdr_status || shdr_add_status) &&
  11792. (shdr_status != STATUS_FCF_IN_USE))
  11793. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11794. "2558 ADD_FCF_RECORD mailbox failed with "
  11795. "status x%x add_status x%x\n",
  11796. shdr_status, shdr_add_status);
  11797. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11798. }
  11799. /**
  11800. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11801. * @phba: pointer to lpfc hba data structure.
  11802. * @fcf_record: pointer to the initialized fcf record to add.
  11803. *
  11804. * This routine is invoked to manually add a single FCF record. The caller
  11805. * must pass a completely initialized FCF_Record. This routine takes
  11806. * care of the nonembedded mailbox operations.
  11807. **/
  11808. int
  11809. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11810. {
  11811. int rc = 0;
  11812. LPFC_MBOXQ_t *mboxq;
  11813. uint8_t *bytep;
  11814. void *virt_addr;
  11815. dma_addr_t phys_addr;
  11816. struct lpfc_mbx_sge sge;
  11817. uint32_t alloc_len, req_len;
  11818. uint32_t fcfindex;
  11819. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11820. if (!mboxq) {
  11821. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11822. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11823. return -ENOMEM;
  11824. }
  11825. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11826. sizeof(uint32_t);
  11827. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11828. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11829. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11830. req_len, LPFC_SLI4_MBX_NEMBED);
  11831. if (alloc_len < req_len) {
  11832. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11833. "2523 Allocated DMA memory size (x%x) is "
  11834. "less than the requested DMA memory "
  11835. "size (x%x)\n", alloc_len, req_len);
  11836. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11837. return -ENOMEM;
  11838. }
  11839. /*
  11840. * Get the first SGE entry from the non-embedded DMA memory. This
  11841. * routine only uses a single SGE.
  11842. */
  11843. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11844. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11845. virt_addr = mboxq->sge_array->addr[0];
  11846. /*
  11847. * Configure the FCF record for FCFI 0. This is the driver's
  11848. * hardcoded default and gets used in nonFIP mode.
  11849. */
  11850. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11851. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11852. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11853. /*
  11854. * Copy the fcf_index and the FCF Record Data. The data starts after
  11855. * the FCoE header plus word10. The data copy needs to be endian
  11856. * correct.
  11857. */
  11858. bytep += sizeof(uint32_t);
  11859. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11860. mboxq->vport = phba->pport;
  11861. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11862. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11863. if (rc == MBX_NOT_FINISHED) {
  11864. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11865. "2515 ADD_FCF_RECORD mailbox failed with "
  11866. "status 0x%x\n", rc);
  11867. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11868. rc = -EIO;
  11869. } else
  11870. rc = 0;
  11871. return rc;
  11872. }
  11873. /**
  11874. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11875. * @phba: pointer to lpfc hba data structure.
  11876. * @fcf_record: pointer to the fcf record to write the default data.
  11877. * @fcf_index: FCF table entry index.
  11878. *
  11879. * This routine is invoked to build the driver's default FCF record. The
  11880. * values used are hardcoded. This routine handles memory initialization.
  11881. *
  11882. **/
  11883. void
  11884. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11885. struct fcf_record *fcf_record,
  11886. uint16_t fcf_index)
  11887. {
  11888. memset(fcf_record, 0, sizeof(struct fcf_record));
  11889. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11890. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11891. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11892. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11893. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11894. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11895. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11896. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11897. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11898. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11899. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11900. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11901. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11902. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11903. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11904. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11905. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11906. /* Set the VLAN bit map */
  11907. if (phba->valid_vlan) {
  11908. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11909. = 1 << (phba->vlan_id % 8);
  11910. }
  11911. }
  11912. /**
  11913. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11914. * @phba: pointer to lpfc hba data structure.
  11915. * @fcf_index: FCF table entry offset.
  11916. *
  11917. * This routine is invoked to scan the entire FCF table by reading FCF
  11918. * record and processing it one at a time starting from the @fcf_index
  11919. * for initial FCF discovery or fast FCF failover rediscovery.
  11920. *
  11921. * Return 0 if the mailbox command is submitted successfully, none 0
  11922. * otherwise.
  11923. **/
  11924. int
  11925. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11926. {
  11927. int rc = 0, error;
  11928. LPFC_MBOXQ_t *mboxq;
  11929. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11930. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11931. if (!mboxq) {
  11932. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11933. "2000 Failed to allocate mbox for "
  11934. "READ_FCF cmd\n");
  11935. error = -ENOMEM;
  11936. goto fail_fcf_scan;
  11937. }
  11938. /* Construct the read FCF record mailbox command */
  11939. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11940. if (rc) {
  11941. error = -EINVAL;
  11942. goto fail_fcf_scan;
  11943. }
  11944. /* Issue the mailbox command asynchronously */
  11945. mboxq->vport = phba->pport;
  11946. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11947. spin_lock_irq(&phba->hbalock);
  11948. phba->hba_flag |= FCF_TS_INPROG;
  11949. spin_unlock_irq(&phba->hbalock);
  11950. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11951. if (rc == MBX_NOT_FINISHED)
  11952. error = -EIO;
  11953. else {
  11954. /* Reset eligible FCF count for new scan */
  11955. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11956. phba->fcf.eligible_fcf_cnt = 0;
  11957. error = 0;
  11958. }
  11959. fail_fcf_scan:
  11960. if (error) {
  11961. if (mboxq)
  11962. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11963. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11964. spin_lock_irq(&phba->hbalock);
  11965. phba->hba_flag &= ~FCF_TS_INPROG;
  11966. spin_unlock_irq(&phba->hbalock);
  11967. }
  11968. return error;
  11969. }
  11970. /**
  11971. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11972. * @phba: pointer to lpfc hba data structure.
  11973. * @fcf_index: FCF table entry offset.
  11974. *
  11975. * This routine is invoked to read an FCF record indicated by @fcf_index
  11976. * and to use it for FLOGI roundrobin FCF failover.
  11977. *
  11978. * Return 0 if the mailbox command is submitted successfully, none 0
  11979. * otherwise.
  11980. **/
  11981. int
  11982. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11983. {
  11984. int rc = 0, error;
  11985. LPFC_MBOXQ_t *mboxq;
  11986. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11987. if (!mboxq) {
  11988. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11989. "2763 Failed to allocate mbox for "
  11990. "READ_FCF cmd\n");
  11991. error = -ENOMEM;
  11992. goto fail_fcf_read;
  11993. }
  11994. /* Construct the read FCF record mailbox command */
  11995. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11996. if (rc) {
  11997. error = -EINVAL;
  11998. goto fail_fcf_read;
  11999. }
  12000. /* Issue the mailbox command asynchronously */
  12001. mboxq->vport = phba->pport;
  12002. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  12003. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  12004. if (rc == MBX_NOT_FINISHED)
  12005. error = -EIO;
  12006. else
  12007. error = 0;
  12008. fail_fcf_read:
  12009. if (error && mboxq)
  12010. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  12011. return error;
  12012. }
  12013. /**
  12014. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  12015. * @phba: pointer to lpfc hba data structure.
  12016. * @fcf_index: FCF table entry offset.
  12017. *
  12018. * This routine is invoked to read an FCF record indicated by @fcf_index to
  12019. * determine whether it's eligible for FLOGI roundrobin failover list.
  12020. *
  12021. * Return 0 if the mailbox command is submitted successfully, none 0
  12022. * otherwise.
  12023. **/
  12024. int
  12025. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  12026. {
  12027. int rc = 0, error;
  12028. LPFC_MBOXQ_t *mboxq;
  12029. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12030. if (!mboxq) {
  12031. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  12032. "2758 Failed to allocate mbox for "
  12033. "READ_FCF cmd\n");
  12034. error = -ENOMEM;
  12035. goto fail_fcf_read;
  12036. }
  12037. /* Construct the read FCF record mailbox command */
  12038. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  12039. if (rc) {
  12040. error = -EINVAL;
  12041. goto fail_fcf_read;
  12042. }
  12043. /* Issue the mailbox command asynchronously */
  12044. mboxq->vport = phba->pport;
  12045. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  12046. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  12047. if (rc == MBX_NOT_FINISHED)
  12048. error = -EIO;
  12049. else
  12050. error = 0;
  12051. fail_fcf_read:
  12052. if (error && mboxq)
  12053. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  12054. return error;
  12055. }
  12056. /**
  12057. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  12058. * @phba: pointer to lpfc hba data structure.
  12059. *
  12060. * This routine is to get the next eligible FCF record index in a round
  12061. * robin fashion. If the next eligible FCF record index equals to the
  12062. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  12063. * shall be returned, otherwise, the next eligible FCF record's index
  12064. * shall be returned.
  12065. **/
  12066. uint16_t
  12067. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  12068. {
  12069. uint16_t next_fcf_index;
  12070. /* Search start from next bit of currently registered FCF index */
  12071. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  12072. LPFC_SLI4_FCF_TBL_INDX_MAX;
  12073. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  12074. LPFC_SLI4_FCF_TBL_INDX_MAX,
  12075. next_fcf_index);
  12076. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  12077. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  12078. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  12079. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  12080. /* Check roundrobin failover list empty condition */
  12081. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12082. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  12083. "2844 No roundrobin failover FCF available\n");
  12084. return LPFC_FCOE_FCF_NEXT_NONE;
  12085. }
  12086. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12087. "2845 Get next roundrobin failover FCF (x%x)\n",
  12088. next_fcf_index);
  12089. return next_fcf_index;
  12090. }
  12091. /**
  12092. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  12093. * @phba: pointer to lpfc hba data structure.
  12094. *
  12095. * This routine sets the FCF record index in to the eligible bmask for
  12096. * roundrobin failover search. It checks to make sure that the index
  12097. * does not go beyond the range of the driver allocated bmask dimension
  12098. * before setting the bit.
  12099. *
  12100. * Returns 0 if the index bit successfully set, otherwise, it returns
  12101. * -EINVAL.
  12102. **/
  12103. int
  12104. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  12105. {
  12106. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12107. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12108. "2610 FCF (x%x) reached driver's book "
  12109. "keeping dimension:x%x\n",
  12110. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  12111. return -EINVAL;
  12112. }
  12113. /* Set the eligible FCF record index bmask */
  12114. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  12115. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12116. "2790 Set FCF (x%x) to roundrobin FCF failover "
  12117. "bmask\n", fcf_index);
  12118. return 0;
  12119. }
  12120. /**
  12121. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  12122. * @phba: pointer to lpfc hba data structure.
  12123. *
  12124. * This routine clears the FCF record index from the eligible bmask for
  12125. * roundrobin failover search. It checks to make sure that the index
  12126. * does not go beyond the range of the driver allocated bmask dimension
  12127. * before clearing the bit.
  12128. **/
  12129. void
  12130. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  12131. {
  12132. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12133. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12134. "2762 FCF (x%x) reached driver's book "
  12135. "keeping dimension:x%x\n",
  12136. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  12137. return;
  12138. }
  12139. /* Clear the eligible FCF record index bmask */
  12140. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  12141. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12142. "2791 Clear FCF (x%x) from roundrobin failover "
  12143. "bmask\n", fcf_index);
  12144. }
  12145. /**
  12146. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  12147. * @phba: pointer to lpfc hba data structure.
  12148. *
  12149. * This routine is the completion routine for the rediscover FCF table mailbox
  12150. * command. If the mailbox command returned failure, it will try to stop the
  12151. * FCF rediscover wait timer.
  12152. **/
  12153. void
  12154. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  12155. {
  12156. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  12157. uint32_t shdr_status, shdr_add_status;
  12158. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12159. shdr_status = bf_get(lpfc_mbox_hdr_status,
  12160. &redisc_fcf->header.cfg_shdr.response);
  12161. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12162. &redisc_fcf->header.cfg_shdr.response);
  12163. if (shdr_status || shdr_add_status) {
  12164. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12165. "2746 Requesting for FCF rediscovery failed "
  12166. "status x%x add_status x%x\n",
  12167. shdr_status, shdr_add_status);
  12168. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  12169. spin_lock_irq(&phba->hbalock);
  12170. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  12171. spin_unlock_irq(&phba->hbalock);
  12172. /*
  12173. * CVL event triggered FCF rediscover request failed,
  12174. * last resort to re-try current registered FCF entry.
  12175. */
  12176. lpfc_retry_pport_discovery(phba);
  12177. } else {
  12178. spin_lock_irq(&phba->hbalock);
  12179. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  12180. spin_unlock_irq(&phba->hbalock);
  12181. /*
  12182. * DEAD FCF event triggered FCF rediscover request
  12183. * failed, last resort to fail over as a link down
  12184. * to FCF registration.
  12185. */
  12186. lpfc_sli4_fcf_dead_failthrough(phba);
  12187. }
  12188. } else {
  12189. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12190. "2775 Start FCF rediscover quiescent timer\n");
  12191. /*
  12192. * Start FCF rediscovery wait timer for pending FCF
  12193. * before rescan FCF record table.
  12194. */
  12195. lpfc_fcf_redisc_wait_start_timer(phba);
  12196. }
  12197. mempool_free(mbox, phba->mbox_mem_pool);
  12198. }
  12199. /**
  12200. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  12201. * @phba: pointer to lpfc hba data structure.
  12202. *
  12203. * This routine is invoked to request for rediscovery of the entire FCF table
  12204. * by the port.
  12205. **/
  12206. int
  12207. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  12208. {
  12209. LPFC_MBOXQ_t *mbox;
  12210. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  12211. int rc, length;
  12212. /* Cancel retry delay timers to all vports before FCF rediscover */
  12213. lpfc_cancel_all_vport_retry_delay_timer(phba);
  12214. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12215. if (!mbox) {
  12216. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12217. "2745 Failed to allocate mbox for "
  12218. "requesting FCF rediscover.\n");
  12219. return -ENOMEM;
  12220. }
  12221. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  12222. sizeof(struct lpfc_sli4_cfg_mhdr));
  12223. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12224. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  12225. length, LPFC_SLI4_MBX_EMBED);
  12226. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12227. /* Set count to 0 for invalidating the entire FCF database */
  12228. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  12229. /* Issue the mailbox command asynchronously */
  12230. mbox->vport = phba->pport;
  12231. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  12232. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  12233. if (rc == MBX_NOT_FINISHED) {
  12234. mempool_free(mbox, phba->mbox_mem_pool);
  12235. return -EIO;
  12236. }
  12237. return 0;
  12238. }
  12239. /**
  12240. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  12241. * @phba: pointer to lpfc hba data structure.
  12242. *
  12243. * This function is the failover routine as a last resort to the FCF DEAD
  12244. * event when driver failed to perform fast FCF failover.
  12245. **/
  12246. void
  12247. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  12248. {
  12249. uint32_t link_state;
  12250. /*
  12251. * Last resort as FCF DEAD event failover will treat this as
  12252. * a link down, but save the link state because we don't want
  12253. * it to be changed to Link Down unless it is already down.
  12254. */
  12255. link_state = phba->link_state;
  12256. lpfc_linkdown(phba);
  12257. phba->link_state = link_state;
  12258. /* Unregister FCF if no devices connected to it */
  12259. lpfc_unregister_unused_fcf(phba);
  12260. }
  12261. /**
  12262. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12263. * @phba: pointer to lpfc hba data structure.
  12264. *
  12265. * This function read region 23 and parse TLV for port status to
  12266. * decide if the user disaled the port. If the TLV indicates the
  12267. * port is disabled, the hba_flag is set accordingly.
  12268. **/
  12269. void
  12270. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12271. {
  12272. LPFC_MBOXQ_t *pmb = NULL;
  12273. MAILBOX_t *mb;
  12274. uint8_t *rgn23_data = NULL;
  12275. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12276. int rc;
  12277. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12278. if (!pmb) {
  12279. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12280. "2600 lpfc_sli_read_serdes_param failed to"
  12281. " allocate mailbox memory\n");
  12282. goto out;
  12283. }
  12284. mb = &pmb->u.mb;
  12285. /* Get adapter Region 23 data */
  12286. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12287. if (!rgn23_data)
  12288. goto out;
  12289. do {
  12290. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12291. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12292. if (rc != MBX_SUCCESS) {
  12293. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12294. "2601 lpfc_sli_read_link_ste failed to"
  12295. " read config region 23 rc 0x%x Status 0x%x\n",
  12296. rc, mb->mbxStatus);
  12297. mb->un.varDmp.word_cnt = 0;
  12298. }
  12299. /*
  12300. * dump mem may return a zero when finished or we got a
  12301. * mailbox error, either way we are done.
  12302. */
  12303. if (mb->un.varDmp.word_cnt == 0)
  12304. break;
  12305. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12306. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12307. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12308. rgn23_data + offset,
  12309. mb->un.varDmp.word_cnt);
  12310. offset += mb->un.varDmp.word_cnt;
  12311. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12312. data_size = offset;
  12313. offset = 0;
  12314. if (!data_size)
  12315. goto out;
  12316. /* Check the region signature first */
  12317. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12318. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12319. "2619 Config region 23 has bad signature\n");
  12320. goto out;
  12321. }
  12322. offset += 4;
  12323. /* Check the data structure version */
  12324. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12325. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12326. "2620 Config region 23 has bad version\n");
  12327. goto out;
  12328. }
  12329. offset += 4;
  12330. /* Parse TLV entries in the region */
  12331. while (offset < data_size) {
  12332. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12333. break;
  12334. /*
  12335. * If the TLV is not driver specific TLV or driver id is
  12336. * not linux driver id, skip the record.
  12337. */
  12338. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12339. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12340. (rgn23_data[offset + 3] != 0)) {
  12341. offset += rgn23_data[offset + 1] * 4 + 4;
  12342. continue;
  12343. }
  12344. /* Driver found a driver specific TLV in the config region */
  12345. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12346. offset += 4;
  12347. tlv_offset = 0;
  12348. /*
  12349. * Search for configured port state sub-TLV.
  12350. */
  12351. while ((offset < data_size) &&
  12352. (tlv_offset < sub_tlv_len)) {
  12353. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12354. offset += 4;
  12355. tlv_offset += 4;
  12356. break;
  12357. }
  12358. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12359. offset += rgn23_data[offset + 1] * 4 + 4;
  12360. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12361. continue;
  12362. }
  12363. /* This HBA contains PORT_STE configured */
  12364. if (!rgn23_data[offset + 2])
  12365. phba->hba_flag |= LINK_DISABLED;
  12366. goto out;
  12367. }
  12368. }
  12369. out:
  12370. if (pmb)
  12371. mempool_free(pmb, phba->mbox_mem_pool);
  12372. kfree(rgn23_data);
  12373. return;
  12374. }
  12375. /**
  12376. * lpfc_wr_object - write an object to the firmware
  12377. * @phba: HBA structure that indicates port to create a queue on.
  12378. * @dmabuf_list: list of dmabufs to write to the port.
  12379. * @size: the total byte value of the objects to write to the port.
  12380. * @offset: the current offset to be used to start the transfer.
  12381. *
  12382. * This routine will create a wr_object mailbox command to send to the port.
  12383. * the mailbox command will be constructed using the dma buffers described in
  12384. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  12385. * BDEs that the imbedded mailbox can support. The @offset variable will be
  12386. * used to indicate the starting offset of the transfer and will also return
  12387. * the offset after the write object mailbox has completed. @size is used to
  12388. * determine the end of the object and whether the eof bit should be set.
  12389. *
  12390. * Return 0 is successful and offset will contain the the new offset to use
  12391. * for the next write.
  12392. * Return negative value for error cases.
  12393. **/
  12394. int
  12395. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  12396. uint32_t size, uint32_t *offset)
  12397. {
  12398. struct lpfc_mbx_wr_object *wr_object;
  12399. LPFC_MBOXQ_t *mbox;
  12400. int rc = 0, i = 0;
  12401. uint32_t shdr_status, shdr_add_status;
  12402. uint32_t mbox_tmo;
  12403. union lpfc_sli4_cfg_shdr *shdr;
  12404. struct lpfc_dmabuf *dmabuf;
  12405. uint32_t written = 0;
  12406. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12407. if (!mbox)
  12408. return -ENOMEM;
  12409. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12410. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  12411. sizeof(struct lpfc_mbx_wr_object) -
  12412. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12413. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  12414. wr_object->u.request.write_offset = *offset;
  12415. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  12416. wr_object->u.request.object_name[0] =
  12417. cpu_to_le32(wr_object->u.request.object_name[0]);
  12418. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  12419. list_for_each_entry(dmabuf, dmabuf_list, list) {
  12420. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  12421. break;
  12422. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  12423. wr_object->u.request.bde[i].addrHigh =
  12424. putPaddrHigh(dmabuf->phys);
  12425. if (written + SLI4_PAGE_SIZE >= size) {
  12426. wr_object->u.request.bde[i].tus.f.bdeSize =
  12427. (size - written);
  12428. written += (size - written);
  12429. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  12430. } else {
  12431. wr_object->u.request.bde[i].tus.f.bdeSize =
  12432. SLI4_PAGE_SIZE;
  12433. written += SLI4_PAGE_SIZE;
  12434. }
  12435. i++;
  12436. }
  12437. wr_object->u.request.bde_count = i;
  12438. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  12439. if (!phba->sli4_hba.intr_enable)
  12440. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12441. else {
  12442. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  12443. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12444. }
  12445. /* The IOCTL status is embedded in the mailbox subheader. */
  12446. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  12447. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12448. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12449. if (rc != MBX_TIMEOUT)
  12450. mempool_free(mbox, phba->mbox_mem_pool);
  12451. if (shdr_status || shdr_add_status || rc) {
  12452. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12453. "3025 Write Object mailbox failed with "
  12454. "status x%x add_status x%x, mbx status x%x\n",
  12455. shdr_status, shdr_add_status, rc);
  12456. rc = -ENXIO;
  12457. } else
  12458. *offset += wr_object->u.response.actual_write_length;
  12459. return rc;
  12460. }
  12461. /**
  12462. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12463. * @vport: pointer to vport data structure.
  12464. *
  12465. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12466. * and REG_VPI mailbox commands associated with the vport. This function
  12467. * is called when driver want to restart discovery of the vport due to
  12468. * a Clear Virtual Link event.
  12469. **/
  12470. void
  12471. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12472. {
  12473. struct lpfc_hba *phba = vport->phba;
  12474. LPFC_MBOXQ_t *mb, *nextmb;
  12475. struct lpfc_dmabuf *mp;
  12476. struct lpfc_nodelist *ndlp;
  12477. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12478. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12479. LIST_HEAD(mbox_cmd_list);
  12480. uint8_t restart_loop;
  12481. /* Clean up internally queued mailbox commands with the vport */
  12482. spin_lock_irq(&phba->hbalock);
  12483. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12484. if (mb->vport != vport)
  12485. continue;
  12486. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12487. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12488. continue;
  12489. list_del(&mb->list);
  12490. list_add_tail(&mb->list, &mbox_cmd_list);
  12491. }
  12492. /* Clean up active mailbox command with the vport */
  12493. mb = phba->sli.mbox_active;
  12494. if (mb && (mb->vport == vport)) {
  12495. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12496. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12497. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12498. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12499. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12500. /* Put reference count for delayed processing */
  12501. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12502. /* Unregister the RPI when mailbox complete */
  12503. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12504. }
  12505. }
  12506. /* Cleanup any mailbox completions which are not yet processed */
  12507. do {
  12508. restart_loop = 0;
  12509. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12510. /*
  12511. * If this mailox is already processed or it is
  12512. * for another vport ignore it.
  12513. */
  12514. if ((mb->vport != vport) ||
  12515. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12516. continue;
  12517. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12518. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12519. continue;
  12520. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12521. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12522. ndlp = (struct lpfc_nodelist *)mb->context2;
  12523. /* Unregister the RPI when mailbox complete */
  12524. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12525. restart_loop = 1;
  12526. spin_unlock_irq(&phba->hbalock);
  12527. spin_lock(shost->host_lock);
  12528. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12529. spin_unlock(shost->host_lock);
  12530. spin_lock_irq(&phba->hbalock);
  12531. break;
  12532. }
  12533. }
  12534. } while (restart_loop);
  12535. spin_unlock_irq(&phba->hbalock);
  12536. /* Release the cleaned-up mailbox commands */
  12537. while (!list_empty(&mbox_cmd_list)) {
  12538. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12539. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12540. mp = (struct lpfc_dmabuf *) (mb->context1);
  12541. if (mp) {
  12542. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12543. kfree(mp);
  12544. }
  12545. ndlp = (struct lpfc_nodelist *) mb->context2;
  12546. mb->context2 = NULL;
  12547. if (ndlp) {
  12548. spin_lock(shost->host_lock);
  12549. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12550. spin_unlock(shost->host_lock);
  12551. lpfc_nlp_put(ndlp);
  12552. }
  12553. }
  12554. mempool_free(mb, phba->mbox_mem_pool);
  12555. }
  12556. /* Release the ndlp with the cleaned-up active mailbox command */
  12557. if (act_mbx_ndlp) {
  12558. spin_lock(shost->host_lock);
  12559. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12560. spin_unlock(shost->host_lock);
  12561. lpfc_nlp_put(act_mbx_ndlp);
  12562. }
  12563. }
  12564. /**
  12565. * lpfc_drain_txq - Drain the txq
  12566. * @phba: Pointer to HBA context object.
  12567. *
  12568. * This function attempt to submit IOCBs on the txq
  12569. * to the adapter. For SLI4 adapters, the txq contains
  12570. * ELS IOCBs that have been deferred because the there
  12571. * are no SGLs. This congestion can occur with large
  12572. * vport counts during node discovery.
  12573. **/
  12574. uint32_t
  12575. lpfc_drain_txq(struct lpfc_hba *phba)
  12576. {
  12577. LIST_HEAD(completions);
  12578. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12579. struct lpfc_iocbq *piocbq = 0;
  12580. unsigned long iflags = 0;
  12581. char *fail_msg = NULL;
  12582. struct lpfc_sglq *sglq;
  12583. union lpfc_wqe wqe;
  12584. spin_lock_irqsave(&phba->hbalock, iflags);
  12585. if (pring->txq_cnt > pring->txq_max)
  12586. pring->txq_max = pring->txq_cnt;
  12587. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12588. while (pring->txq_cnt) {
  12589. spin_lock_irqsave(&phba->hbalock, iflags);
  12590. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12591. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12592. if (!sglq) {
  12593. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12594. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12595. break;
  12596. } else {
  12597. if (!piocbq) {
  12598. /* The txq_cnt out of sync. This should
  12599. * never happen
  12600. */
  12601. sglq = __lpfc_clear_active_sglq(phba,
  12602. sglq->sli4_xritag);
  12603. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12604. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12605. "2823 txq empty and txq_cnt is %d\n ",
  12606. pring->txq_cnt);
  12607. break;
  12608. }
  12609. }
  12610. /* The xri and iocb resources secured,
  12611. * attempt to issue request
  12612. */
  12613. piocbq->sli4_xritag = sglq->sli4_xritag;
  12614. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12615. fail_msg = "to convert bpl to sgl";
  12616. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12617. fail_msg = "to convert iocb to wqe";
  12618. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12619. fail_msg = " - Wq is full";
  12620. else
  12621. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12622. if (fail_msg) {
  12623. /* Failed means we can't issue and need to cancel */
  12624. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12625. "2822 IOCB failed %s iotag 0x%x "
  12626. "xri 0x%x\n",
  12627. fail_msg,
  12628. piocbq->iotag, piocbq->sli4_xritag);
  12629. list_add_tail(&piocbq->list, &completions);
  12630. }
  12631. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12632. }
  12633. /* Cancel all the IOCBs that cannot be issued */
  12634. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12635. IOERR_SLI_ABORTED);
  12636. return pring->txq_cnt;
  12637. }