bfa_svc.c 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include "bfad_drv.h"
  18. #include "bfad_im.h"
  19. #include "bfa_plog.h"
  20. #include "bfa_cs.h"
  21. #include "bfa_modules.h"
  22. BFA_TRC_FILE(HAL, FCXP);
  23. BFA_MODULE(fcdiag);
  24. BFA_MODULE(fcxp);
  25. BFA_MODULE(sgpg);
  26. BFA_MODULE(lps);
  27. BFA_MODULE(fcport);
  28. BFA_MODULE(rport);
  29. BFA_MODULE(uf);
  30. /*
  31. * LPS related definitions
  32. */
  33. #define BFA_LPS_MIN_LPORTS (1)
  34. #define BFA_LPS_MAX_LPORTS (256)
  35. /*
  36. * Maximum Vports supported per physical port or vf.
  37. */
  38. #define BFA_LPS_MAX_VPORTS_SUPP_CB 255
  39. #define BFA_LPS_MAX_VPORTS_SUPP_CT 190
  40. /*
  41. * FC PORT related definitions
  42. */
  43. /*
  44. * The port is considered disabled if corresponding physical port or IOC are
  45. * disabled explicitly
  46. */
  47. #define BFA_PORT_IS_DISABLED(bfa) \
  48. ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
  49. (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
  50. /*
  51. * BFA port state machine events
  52. */
  53. enum bfa_fcport_sm_event {
  54. BFA_FCPORT_SM_START = 1, /* start port state machine */
  55. BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
  56. BFA_FCPORT_SM_ENABLE = 3, /* enable port */
  57. BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
  58. BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
  59. BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
  60. BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
  61. BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
  62. BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
  63. BFA_FCPORT_SM_DPORTENABLE = 10, /* enable dport */
  64. BFA_FCPORT_SM_DPORTDISABLE = 11,/* disable dport */
  65. };
  66. /*
  67. * BFA port link notification state machine events
  68. */
  69. enum bfa_fcport_ln_sm_event {
  70. BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
  71. BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
  72. BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
  73. };
  74. /*
  75. * RPORT related definitions
  76. */
  77. #define bfa_rport_offline_cb(__rp) do { \
  78. if ((__rp)->bfa->fcs) \
  79. bfa_cb_rport_offline((__rp)->rport_drv); \
  80. else { \
  81. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  82. __bfa_cb_rport_offline, (__rp)); \
  83. } \
  84. } while (0)
  85. #define bfa_rport_online_cb(__rp) do { \
  86. if ((__rp)->bfa->fcs) \
  87. bfa_cb_rport_online((__rp)->rport_drv); \
  88. else { \
  89. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  90. __bfa_cb_rport_online, (__rp)); \
  91. } \
  92. } while (0)
  93. /*
  94. * forward declarations FCXP related functions
  95. */
  96. static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
  97. static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  98. struct bfi_fcxp_send_rsp_s *fcxp_rsp);
  99. static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
  100. struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
  101. static void bfa_fcxp_qresume(void *cbarg);
  102. static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
  103. struct bfi_fcxp_send_req_s *send_req);
  104. /*
  105. * forward declarations for LPS functions
  106. */
  107. static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg,
  108. struct bfa_meminfo_s *minfo, struct bfa_s *bfa);
  109. static void bfa_lps_attach(struct bfa_s *bfa, void *bfad,
  110. struct bfa_iocfc_cfg_s *cfg,
  111. struct bfa_pcidev_s *pcidev);
  112. static void bfa_lps_detach(struct bfa_s *bfa);
  113. static void bfa_lps_start(struct bfa_s *bfa);
  114. static void bfa_lps_stop(struct bfa_s *bfa);
  115. static void bfa_lps_iocdisable(struct bfa_s *bfa);
  116. static void bfa_lps_login_rsp(struct bfa_s *bfa,
  117. struct bfi_lps_login_rsp_s *rsp);
  118. static void bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count);
  119. static void bfa_lps_logout_rsp(struct bfa_s *bfa,
  120. struct bfi_lps_logout_rsp_s *rsp);
  121. static void bfa_lps_reqq_resume(void *lps_arg);
  122. static void bfa_lps_free(struct bfa_lps_s *lps);
  123. static void bfa_lps_send_login(struct bfa_lps_s *lps);
  124. static void bfa_lps_send_logout(struct bfa_lps_s *lps);
  125. static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
  126. static void bfa_lps_login_comp(struct bfa_lps_s *lps);
  127. static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
  128. static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
  129. /*
  130. * forward declaration for LPS state machine
  131. */
  132. static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
  133. static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
  134. static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
  135. event);
  136. static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
  137. static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
  138. enum bfa_lps_event event);
  139. static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
  140. static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
  141. event);
  142. /*
  143. * forward declaration for FC Port functions
  144. */
  145. static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
  146. static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
  147. static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
  148. static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
  149. static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
  150. static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
  151. static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
  152. enum bfa_port_linkstate event, bfa_boolean_t trunk);
  153. static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
  154. enum bfa_port_linkstate event);
  155. static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
  156. static void bfa_fcport_stats_get_timeout(void *cbarg);
  157. static void bfa_fcport_stats_clr_timeout(void *cbarg);
  158. static void bfa_trunk_iocdisable(struct bfa_s *bfa);
  159. /*
  160. * forward declaration for FC PORT state machine
  161. */
  162. static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  163. enum bfa_fcport_sm_event event);
  164. static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  165. enum bfa_fcport_sm_event event);
  166. static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  167. enum bfa_fcport_sm_event event);
  168. static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  169. enum bfa_fcport_sm_event event);
  170. static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  171. enum bfa_fcport_sm_event event);
  172. static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  173. enum bfa_fcport_sm_event event);
  174. static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  175. enum bfa_fcport_sm_event event);
  176. static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  177. enum bfa_fcport_sm_event event);
  178. static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  179. enum bfa_fcport_sm_event event);
  180. static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  181. enum bfa_fcport_sm_event event);
  182. static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  183. enum bfa_fcport_sm_event event);
  184. static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  185. enum bfa_fcport_sm_event event);
  186. static void bfa_fcport_sm_dport(struct bfa_fcport_s *fcport,
  187. enum bfa_fcport_sm_event event);
  188. static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  189. enum bfa_fcport_ln_sm_event event);
  190. static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  191. enum bfa_fcport_ln_sm_event event);
  192. static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  193. enum bfa_fcport_ln_sm_event event);
  194. static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  195. enum bfa_fcport_ln_sm_event event);
  196. static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  197. enum bfa_fcport_ln_sm_event event);
  198. static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  199. enum bfa_fcport_ln_sm_event event);
  200. static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  201. enum bfa_fcport_ln_sm_event event);
  202. static struct bfa_sm_table_s hal_port_sm_table[] = {
  203. {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
  204. {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
  205. {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
  206. {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
  207. {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
  208. {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
  209. {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
  210. {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
  211. {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
  212. {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
  213. {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
  214. {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
  215. {BFA_SM(bfa_fcport_sm_dport), BFA_PORT_ST_DPORT},
  216. };
  217. /*
  218. * forward declaration for RPORT related functions
  219. */
  220. static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
  221. static void bfa_rport_free(struct bfa_rport_s *rport);
  222. static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
  223. static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
  224. static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
  225. static void __bfa_cb_rport_online(void *cbarg,
  226. bfa_boolean_t complete);
  227. static void __bfa_cb_rport_offline(void *cbarg,
  228. bfa_boolean_t complete);
  229. /*
  230. * forward declaration for RPORT state machine
  231. */
  232. static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
  233. enum bfa_rport_event event);
  234. static void bfa_rport_sm_created(struct bfa_rport_s *rp,
  235. enum bfa_rport_event event);
  236. static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
  237. enum bfa_rport_event event);
  238. static void bfa_rport_sm_online(struct bfa_rport_s *rp,
  239. enum bfa_rport_event event);
  240. static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
  241. enum bfa_rport_event event);
  242. static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
  243. enum bfa_rport_event event);
  244. static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
  245. enum bfa_rport_event event);
  246. static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  247. enum bfa_rport_event event);
  248. static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  249. enum bfa_rport_event event);
  250. static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
  251. enum bfa_rport_event event);
  252. static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
  253. enum bfa_rport_event event);
  254. static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
  255. enum bfa_rport_event event);
  256. static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
  257. enum bfa_rport_event event);
  258. /*
  259. * PLOG related definitions
  260. */
  261. static int
  262. plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
  263. {
  264. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  265. (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
  266. return 1;
  267. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  268. (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
  269. return 1;
  270. return 0;
  271. }
  272. static u64
  273. bfa_get_log_time(void)
  274. {
  275. u64 system_time = 0;
  276. struct timeval tv;
  277. do_gettimeofday(&tv);
  278. /* We are interested in seconds only. */
  279. system_time = tv.tv_sec;
  280. return system_time;
  281. }
  282. static void
  283. bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
  284. {
  285. u16 tail;
  286. struct bfa_plog_rec_s *pl_recp;
  287. if (plog->plog_enabled == 0)
  288. return;
  289. if (plkd_validate_logrec(pl_rec)) {
  290. WARN_ON(1);
  291. return;
  292. }
  293. tail = plog->tail;
  294. pl_recp = &(plog->plog_recs[tail]);
  295. memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
  296. pl_recp->tv = bfa_get_log_time();
  297. BFA_PL_LOG_REC_INCR(plog->tail);
  298. if (plog->head == plog->tail)
  299. BFA_PL_LOG_REC_INCR(plog->head);
  300. }
  301. void
  302. bfa_plog_init(struct bfa_plog_s *plog)
  303. {
  304. memset((char *)plog, 0, sizeof(struct bfa_plog_s));
  305. memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
  306. plog->head = plog->tail = 0;
  307. plog->plog_enabled = 1;
  308. }
  309. void
  310. bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  311. enum bfa_plog_eid event,
  312. u16 misc, char *log_str)
  313. {
  314. struct bfa_plog_rec_s lp;
  315. if (plog->plog_enabled) {
  316. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  317. lp.mid = mid;
  318. lp.eid = event;
  319. lp.log_type = BFA_PL_LOG_TYPE_STRING;
  320. lp.misc = misc;
  321. strncpy(lp.log_entry.string_log, log_str,
  322. BFA_PL_STRING_LOG_SZ - 1);
  323. lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
  324. bfa_plog_add(plog, &lp);
  325. }
  326. }
  327. void
  328. bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  329. enum bfa_plog_eid event,
  330. u16 misc, u32 *intarr, u32 num_ints)
  331. {
  332. struct bfa_plog_rec_s lp;
  333. u32 i;
  334. if (num_ints > BFA_PL_INT_LOG_SZ)
  335. num_ints = BFA_PL_INT_LOG_SZ;
  336. if (plog->plog_enabled) {
  337. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  338. lp.mid = mid;
  339. lp.eid = event;
  340. lp.log_type = BFA_PL_LOG_TYPE_INT;
  341. lp.misc = misc;
  342. for (i = 0; i < num_ints; i++)
  343. lp.log_entry.int_log[i] = intarr[i];
  344. lp.log_num_ints = (u8) num_ints;
  345. bfa_plog_add(plog, &lp);
  346. }
  347. }
  348. void
  349. bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  350. enum bfa_plog_eid event,
  351. u16 misc, struct fchs_s *fchdr)
  352. {
  353. struct bfa_plog_rec_s lp;
  354. u32 *tmp_int = (u32 *) fchdr;
  355. u32 ints[BFA_PL_INT_LOG_SZ];
  356. if (plog->plog_enabled) {
  357. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  358. ints[0] = tmp_int[0];
  359. ints[1] = tmp_int[1];
  360. ints[2] = tmp_int[4];
  361. bfa_plog_intarr(plog, mid, event, misc, ints, 3);
  362. }
  363. }
  364. void
  365. bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  366. enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
  367. u32 pld_w0)
  368. {
  369. struct bfa_plog_rec_s lp;
  370. u32 *tmp_int = (u32 *) fchdr;
  371. u32 ints[BFA_PL_INT_LOG_SZ];
  372. if (plog->plog_enabled) {
  373. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  374. ints[0] = tmp_int[0];
  375. ints[1] = tmp_int[1];
  376. ints[2] = tmp_int[4];
  377. ints[3] = pld_w0;
  378. bfa_plog_intarr(plog, mid, event, misc, ints, 4);
  379. }
  380. }
  381. /*
  382. * fcxp_pvt BFA FCXP private functions
  383. */
  384. static void
  385. claim_fcxps_mem(struct bfa_fcxp_mod_s *mod)
  386. {
  387. u16 i;
  388. struct bfa_fcxp_s *fcxp;
  389. fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod);
  390. memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
  391. INIT_LIST_HEAD(&mod->fcxp_req_free_q);
  392. INIT_LIST_HEAD(&mod->fcxp_rsp_free_q);
  393. INIT_LIST_HEAD(&mod->fcxp_active_q);
  394. INIT_LIST_HEAD(&mod->fcxp_req_unused_q);
  395. INIT_LIST_HEAD(&mod->fcxp_rsp_unused_q);
  396. mod->fcxp_list = fcxp;
  397. for (i = 0; i < mod->num_fcxps; i++) {
  398. fcxp->fcxp_mod = mod;
  399. fcxp->fcxp_tag = i;
  400. if (i < (mod->num_fcxps / 2)) {
  401. list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
  402. fcxp->req_rsp = BFA_TRUE;
  403. } else {
  404. list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
  405. fcxp->req_rsp = BFA_FALSE;
  406. }
  407. bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
  408. fcxp->reqq_waiting = BFA_FALSE;
  409. fcxp = fcxp + 1;
  410. }
  411. bfa_mem_kva_curp(mod) = (void *)fcxp;
  412. }
  413. static void
  414. bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  415. struct bfa_s *bfa)
  416. {
  417. struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa);
  418. struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa);
  419. struct bfa_mem_dma_s *seg_ptr;
  420. u16 nsegs, idx, per_seg_fcxp;
  421. u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs;
  422. u32 per_fcxp_sz;
  423. if (num_fcxps == 0)
  424. return;
  425. if (cfg->drvcfg.min_cfg)
  426. per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ;
  427. else
  428. per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ;
  429. /* dma memory */
  430. nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz);
  431. per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz);
  432. bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) {
  433. if (num_fcxps >= per_seg_fcxp) {
  434. num_fcxps -= per_seg_fcxp;
  435. bfa_mem_dma_setup(minfo, seg_ptr,
  436. per_seg_fcxp * per_fcxp_sz);
  437. } else
  438. bfa_mem_dma_setup(minfo, seg_ptr,
  439. num_fcxps * per_fcxp_sz);
  440. }
  441. /* kva memory */
  442. bfa_mem_kva_setup(minfo, fcxp_kva,
  443. cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s));
  444. }
  445. static void
  446. bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  447. struct bfa_pcidev_s *pcidev)
  448. {
  449. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  450. mod->bfa = bfa;
  451. mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
  452. /*
  453. * Initialize FCXP request and response payload sizes.
  454. */
  455. mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
  456. if (!cfg->drvcfg.min_cfg)
  457. mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
  458. INIT_LIST_HEAD(&mod->req_wait_q);
  459. INIT_LIST_HEAD(&mod->rsp_wait_q);
  460. claim_fcxps_mem(mod);
  461. }
  462. static void
  463. bfa_fcxp_detach(struct bfa_s *bfa)
  464. {
  465. }
  466. static void
  467. bfa_fcxp_start(struct bfa_s *bfa)
  468. {
  469. }
  470. static void
  471. bfa_fcxp_stop(struct bfa_s *bfa)
  472. {
  473. }
  474. static void
  475. bfa_fcxp_iocdisable(struct bfa_s *bfa)
  476. {
  477. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  478. struct bfa_fcxp_s *fcxp;
  479. struct list_head *qe, *qen;
  480. /* Enqueue unused fcxp resources to free_q */
  481. list_splice_tail_init(&mod->fcxp_req_unused_q, &mod->fcxp_req_free_q);
  482. list_splice_tail_init(&mod->fcxp_rsp_unused_q, &mod->fcxp_rsp_free_q);
  483. list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
  484. fcxp = (struct bfa_fcxp_s *) qe;
  485. if (fcxp->caller == NULL) {
  486. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  487. BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
  488. bfa_fcxp_free(fcxp);
  489. } else {
  490. fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
  491. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  492. __bfa_fcxp_send_cbfn, fcxp);
  493. }
  494. }
  495. }
  496. static struct bfa_fcxp_s *
  497. bfa_fcxp_get(struct bfa_fcxp_mod_s *fm, bfa_boolean_t req)
  498. {
  499. struct bfa_fcxp_s *fcxp;
  500. if (req)
  501. bfa_q_deq(&fm->fcxp_req_free_q, &fcxp);
  502. else
  503. bfa_q_deq(&fm->fcxp_rsp_free_q, &fcxp);
  504. if (fcxp)
  505. list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
  506. return fcxp;
  507. }
  508. static void
  509. bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
  510. struct bfa_s *bfa,
  511. u8 *use_ibuf,
  512. u32 *nr_sgles,
  513. bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
  514. bfa_fcxp_get_sglen_t *r_sglen_cbfn,
  515. struct list_head *r_sgpg_q,
  516. int n_sgles,
  517. bfa_fcxp_get_sgaddr_t sga_cbfn,
  518. bfa_fcxp_get_sglen_t sglen_cbfn)
  519. {
  520. WARN_ON(bfa == NULL);
  521. bfa_trc(bfa, fcxp->fcxp_tag);
  522. if (n_sgles == 0) {
  523. *use_ibuf = 1;
  524. } else {
  525. WARN_ON(*sga_cbfn == NULL);
  526. WARN_ON(*sglen_cbfn == NULL);
  527. *use_ibuf = 0;
  528. *r_sga_cbfn = sga_cbfn;
  529. *r_sglen_cbfn = sglen_cbfn;
  530. *nr_sgles = n_sgles;
  531. /*
  532. * alloc required sgpgs
  533. */
  534. if (n_sgles > BFI_SGE_INLINE)
  535. WARN_ON(1);
  536. }
  537. }
  538. static void
  539. bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
  540. void *caller, struct bfa_s *bfa, int nreq_sgles,
  541. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  542. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  543. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  544. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  545. {
  546. WARN_ON(bfa == NULL);
  547. bfa_trc(bfa, fcxp->fcxp_tag);
  548. fcxp->caller = caller;
  549. bfa_fcxp_init_reqrsp(fcxp, bfa,
  550. &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
  551. &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
  552. nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
  553. bfa_fcxp_init_reqrsp(fcxp, bfa,
  554. &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
  555. &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
  556. nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
  557. }
  558. static void
  559. bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
  560. {
  561. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  562. struct bfa_fcxp_wqe_s *wqe;
  563. if (fcxp->req_rsp)
  564. bfa_q_deq(&mod->req_wait_q, &wqe);
  565. else
  566. bfa_q_deq(&mod->rsp_wait_q, &wqe);
  567. if (wqe) {
  568. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  569. bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
  570. wqe->nrsp_sgles, wqe->req_sga_cbfn,
  571. wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
  572. wqe->rsp_sglen_cbfn);
  573. wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
  574. return;
  575. }
  576. WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
  577. list_del(&fcxp->qe);
  578. if (fcxp->req_rsp)
  579. list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
  580. else
  581. list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
  582. }
  583. static void
  584. bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
  585. bfa_status_t req_status, u32 rsp_len,
  586. u32 resid_len, struct fchs_s *rsp_fchs)
  587. {
  588. /* discarded fcxp completion */
  589. }
  590. static void
  591. __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
  592. {
  593. struct bfa_fcxp_s *fcxp = cbarg;
  594. if (complete) {
  595. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  596. fcxp->rsp_status, fcxp->rsp_len,
  597. fcxp->residue_len, &fcxp->rsp_fchs);
  598. } else {
  599. bfa_fcxp_free(fcxp);
  600. }
  601. }
  602. static void
  603. hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  604. {
  605. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  606. struct bfa_fcxp_s *fcxp;
  607. u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
  608. bfa_trc(bfa, fcxp_tag);
  609. fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
  610. /*
  611. * @todo f/w should not set residue to non-0 when everything
  612. * is received.
  613. */
  614. if (fcxp_rsp->req_status == BFA_STATUS_OK)
  615. fcxp_rsp->residue_len = 0;
  616. else
  617. fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
  618. fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
  619. WARN_ON(fcxp->send_cbfn == NULL);
  620. hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
  621. if (fcxp->send_cbfn != NULL) {
  622. bfa_trc(mod->bfa, (NULL == fcxp->caller));
  623. if (fcxp->caller == NULL) {
  624. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  625. fcxp_rsp->req_status, fcxp_rsp->rsp_len,
  626. fcxp_rsp->residue_len, &fcxp_rsp->fchs);
  627. /*
  628. * fcxp automatically freed on return from the callback
  629. */
  630. bfa_fcxp_free(fcxp);
  631. } else {
  632. fcxp->rsp_status = fcxp_rsp->req_status;
  633. fcxp->rsp_len = fcxp_rsp->rsp_len;
  634. fcxp->residue_len = fcxp_rsp->residue_len;
  635. fcxp->rsp_fchs = fcxp_rsp->fchs;
  636. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  637. __bfa_fcxp_send_cbfn, fcxp);
  638. }
  639. } else {
  640. bfa_trc(bfa, (NULL == fcxp->send_cbfn));
  641. }
  642. }
  643. static void
  644. hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
  645. struct fchs_s *fchs)
  646. {
  647. /*
  648. * TODO: TX ox_id
  649. */
  650. if (reqlen > 0) {
  651. if (fcxp->use_ireqbuf) {
  652. u32 pld_w0 =
  653. *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
  654. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  655. BFA_PL_EID_TX,
  656. reqlen + sizeof(struct fchs_s), fchs,
  657. pld_w0);
  658. } else {
  659. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  660. BFA_PL_EID_TX,
  661. reqlen + sizeof(struct fchs_s),
  662. fchs);
  663. }
  664. } else {
  665. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
  666. reqlen + sizeof(struct fchs_s), fchs);
  667. }
  668. }
  669. static void
  670. hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  671. struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  672. {
  673. if (fcxp_rsp->rsp_len > 0) {
  674. if (fcxp->use_irspbuf) {
  675. u32 pld_w0 =
  676. *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
  677. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  678. BFA_PL_EID_RX,
  679. (u16) fcxp_rsp->rsp_len,
  680. &fcxp_rsp->fchs, pld_w0);
  681. } else {
  682. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  683. BFA_PL_EID_RX,
  684. (u16) fcxp_rsp->rsp_len,
  685. &fcxp_rsp->fchs);
  686. }
  687. } else {
  688. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
  689. (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
  690. }
  691. }
  692. /*
  693. * Handler to resume sending fcxp when space in available in cpe queue.
  694. */
  695. static void
  696. bfa_fcxp_qresume(void *cbarg)
  697. {
  698. struct bfa_fcxp_s *fcxp = cbarg;
  699. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  700. struct bfi_fcxp_send_req_s *send_req;
  701. fcxp->reqq_waiting = BFA_FALSE;
  702. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  703. bfa_fcxp_queue(fcxp, send_req);
  704. }
  705. /*
  706. * Queue fcxp send request to foimrware.
  707. */
  708. static void
  709. bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
  710. {
  711. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  712. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  713. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  714. struct bfa_rport_s *rport = reqi->bfa_rport;
  715. bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
  716. bfa_fn_lpu(bfa));
  717. send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
  718. if (rport) {
  719. send_req->rport_fw_hndl = rport->fw_handle;
  720. send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
  721. if (send_req->max_frmsz == 0)
  722. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  723. } else {
  724. send_req->rport_fw_hndl = 0;
  725. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  726. }
  727. send_req->vf_id = cpu_to_be16(reqi->vf_id);
  728. send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag);
  729. send_req->class = reqi->class;
  730. send_req->rsp_timeout = rspi->rsp_timeout;
  731. send_req->cts = reqi->cts;
  732. send_req->fchs = reqi->fchs;
  733. send_req->req_len = cpu_to_be32(reqi->req_tot_len);
  734. send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
  735. /*
  736. * setup req sgles
  737. */
  738. if (fcxp->use_ireqbuf == 1) {
  739. bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
  740. BFA_FCXP_REQ_PLD_PA(fcxp));
  741. } else {
  742. if (fcxp->nreq_sgles > 0) {
  743. WARN_ON(fcxp->nreq_sgles != 1);
  744. bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
  745. fcxp->req_sga_cbfn(fcxp->caller, 0));
  746. } else {
  747. WARN_ON(reqi->req_tot_len != 0);
  748. bfa_alen_set(&send_req->rsp_alen, 0, 0);
  749. }
  750. }
  751. /*
  752. * setup rsp sgles
  753. */
  754. if (fcxp->use_irspbuf == 1) {
  755. WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
  756. bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
  757. BFA_FCXP_RSP_PLD_PA(fcxp));
  758. } else {
  759. if (fcxp->nrsp_sgles > 0) {
  760. WARN_ON(fcxp->nrsp_sgles != 1);
  761. bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
  762. fcxp->rsp_sga_cbfn(fcxp->caller, 0));
  763. } else {
  764. WARN_ON(rspi->rsp_maxlen != 0);
  765. bfa_alen_set(&send_req->rsp_alen, 0, 0);
  766. }
  767. }
  768. hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
  769. bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh);
  770. bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
  771. bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
  772. }
  773. /*
  774. * Allocate an FCXP instance to send a response or to send a request
  775. * that has a response. Request/response buffers are allocated by caller.
  776. *
  777. * @param[in] bfa BFA bfa instance
  778. * @param[in] nreq_sgles Number of SG elements required for request
  779. * buffer. 0, if fcxp internal buffers are used.
  780. * Use bfa_fcxp_get_reqbuf() to get the
  781. * internal req buffer.
  782. * @param[in] req_sgles SG elements describing request buffer. Will be
  783. * copied in by BFA and hence can be freed on
  784. * return from this function.
  785. * @param[in] get_req_sga function ptr to be called to get a request SG
  786. * Address (given the sge index).
  787. * @param[in] get_req_sglen function ptr to be called to get a request SG
  788. * len (given the sge index).
  789. * @param[in] get_rsp_sga function ptr to be called to get a response SG
  790. * Address (given the sge index).
  791. * @param[in] get_rsp_sglen function ptr to be called to get a response SG
  792. * len (given the sge index).
  793. * @param[in] req Allocated FCXP is used to send req or rsp?
  794. * request - BFA_TRUE, response - BFA_FALSE
  795. *
  796. * @return FCXP instance. NULL on failure.
  797. */
  798. struct bfa_fcxp_s *
  799. bfa_fcxp_req_rsp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
  800. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  801. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  802. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  803. bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
  804. {
  805. struct bfa_fcxp_s *fcxp = NULL;
  806. WARN_ON(bfa == NULL);
  807. fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa), req);
  808. if (fcxp == NULL)
  809. return NULL;
  810. bfa_trc(bfa, fcxp->fcxp_tag);
  811. bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
  812. req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
  813. return fcxp;
  814. }
  815. /*
  816. * Get the internal request buffer pointer
  817. *
  818. * @param[in] fcxp BFA fcxp pointer
  819. *
  820. * @return pointer to the internal request buffer
  821. */
  822. void *
  823. bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
  824. {
  825. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  826. void *reqbuf;
  827. WARN_ON(fcxp->use_ireqbuf != 1);
  828. reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
  829. mod->req_pld_sz + mod->rsp_pld_sz);
  830. return reqbuf;
  831. }
  832. u32
  833. bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
  834. {
  835. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  836. return mod->req_pld_sz;
  837. }
  838. /*
  839. * Get the internal response buffer pointer
  840. *
  841. * @param[in] fcxp BFA fcxp pointer
  842. *
  843. * @return pointer to the internal request buffer
  844. */
  845. void *
  846. bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
  847. {
  848. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  849. void *fcxp_buf;
  850. WARN_ON(fcxp->use_irspbuf != 1);
  851. fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
  852. mod->req_pld_sz + mod->rsp_pld_sz);
  853. /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
  854. return ((u8 *) fcxp_buf) + mod->req_pld_sz;
  855. }
  856. /*
  857. * Free the BFA FCXP
  858. *
  859. * @param[in] fcxp BFA fcxp pointer
  860. *
  861. * @return void
  862. */
  863. void
  864. bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
  865. {
  866. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  867. WARN_ON(fcxp == NULL);
  868. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  869. bfa_fcxp_put(fcxp);
  870. }
  871. /*
  872. * Send a FCXP request
  873. *
  874. * @param[in] fcxp BFA fcxp pointer
  875. * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
  876. * @param[in] vf_id virtual Fabric ID
  877. * @param[in] lp_tag lport tag
  878. * @param[in] cts use Continuous sequence
  879. * @param[in] cos fc Class of Service
  880. * @param[in] reqlen request length, does not include FCHS length
  881. * @param[in] fchs fc Header Pointer. The header content will be copied
  882. * in by BFA.
  883. *
  884. * @param[in] cbfn call back function to be called on receiving
  885. * the response
  886. * @param[in] cbarg arg for cbfn
  887. * @param[in] rsp_timeout
  888. * response timeout
  889. *
  890. * @return bfa_status_t
  891. */
  892. void
  893. bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
  894. u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
  895. u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
  896. void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
  897. {
  898. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  899. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  900. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  901. struct bfi_fcxp_send_req_s *send_req;
  902. bfa_trc(bfa, fcxp->fcxp_tag);
  903. /*
  904. * setup request/response info
  905. */
  906. reqi->bfa_rport = rport;
  907. reqi->vf_id = vf_id;
  908. reqi->lp_tag = lp_tag;
  909. reqi->class = cos;
  910. rspi->rsp_timeout = rsp_timeout;
  911. reqi->cts = cts;
  912. reqi->fchs = *fchs;
  913. reqi->req_tot_len = reqlen;
  914. rspi->rsp_maxlen = rsp_maxlen;
  915. fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
  916. fcxp->send_cbarg = cbarg;
  917. /*
  918. * If no room in CPE queue, wait for space in request queue
  919. */
  920. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  921. if (!send_req) {
  922. bfa_trc(bfa, fcxp->fcxp_tag);
  923. fcxp->reqq_waiting = BFA_TRUE;
  924. bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
  925. return;
  926. }
  927. bfa_fcxp_queue(fcxp, send_req);
  928. }
  929. /*
  930. * Abort a BFA FCXP
  931. *
  932. * @param[in] fcxp BFA fcxp pointer
  933. *
  934. * @return void
  935. */
  936. bfa_status_t
  937. bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
  938. {
  939. bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
  940. WARN_ON(1);
  941. return BFA_STATUS_OK;
  942. }
  943. void
  944. bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
  945. bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
  946. void *caller, int nreq_sgles,
  947. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  948. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  949. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  950. bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
  951. {
  952. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  953. if (req)
  954. WARN_ON(!list_empty(&mod->fcxp_req_free_q));
  955. else
  956. WARN_ON(!list_empty(&mod->fcxp_rsp_free_q));
  957. wqe->alloc_cbfn = alloc_cbfn;
  958. wqe->alloc_cbarg = alloc_cbarg;
  959. wqe->caller = caller;
  960. wqe->bfa = bfa;
  961. wqe->nreq_sgles = nreq_sgles;
  962. wqe->nrsp_sgles = nrsp_sgles;
  963. wqe->req_sga_cbfn = req_sga_cbfn;
  964. wqe->req_sglen_cbfn = req_sglen_cbfn;
  965. wqe->rsp_sga_cbfn = rsp_sga_cbfn;
  966. wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
  967. if (req)
  968. list_add_tail(&wqe->qe, &mod->req_wait_q);
  969. else
  970. list_add_tail(&wqe->qe, &mod->rsp_wait_q);
  971. }
  972. void
  973. bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
  974. {
  975. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  976. WARN_ON(!bfa_q_is_on_q(&mod->req_wait_q, wqe) ||
  977. !bfa_q_is_on_q(&mod->rsp_wait_q, wqe));
  978. list_del(&wqe->qe);
  979. }
  980. void
  981. bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
  982. {
  983. /*
  984. * If waiting for room in request queue, cancel reqq wait
  985. * and free fcxp.
  986. */
  987. if (fcxp->reqq_waiting) {
  988. fcxp->reqq_waiting = BFA_FALSE;
  989. bfa_reqq_wcancel(&fcxp->reqq_wqe);
  990. bfa_fcxp_free(fcxp);
  991. return;
  992. }
  993. fcxp->send_cbfn = bfa_fcxp_null_comp;
  994. }
  995. void
  996. bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  997. {
  998. switch (msg->mhdr.msg_id) {
  999. case BFI_FCXP_I2H_SEND_RSP:
  1000. hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
  1001. break;
  1002. default:
  1003. bfa_trc(bfa, msg->mhdr.msg_id);
  1004. WARN_ON(1);
  1005. }
  1006. }
  1007. u32
  1008. bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
  1009. {
  1010. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  1011. return mod->rsp_pld_sz;
  1012. }
  1013. void
  1014. bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw)
  1015. {
  1016. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  1017. struct list_head *qe;
  1018. int i;
  1019. for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) {
  1020. if (i < ((mod->num_fcxps - num_fcxp_fw) / 2)) {
  1021. bfa_q_deq_tail(&mod->fcxp_req_free_q, &qe);
  1022. list_add_tail(qe, &mod->fcxp_req_unused_q);
  1023. } else {
  1024. bfa_q_deq_tail(&mod->fcxp_rsp_free_q, &qe);
  1025. list_add_tail(qe, &mod->fcxp_rsp_unused_q);
  1026. }
  1027. }
  1028. }
  1029. /*
  1030. * BFA LPS state machine functions
  1031. */
  1032. /*
  1033. * Init state -- no login
  1034. */
  1035. static void
  1036. bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1037. {
  1038. bfa_trc(lps->bfa, lps->bfa_tag);
  1039. bfa_trc(lps->bfa, event);
  1040. switch (event) {
  1041. case BFA_LPS_SM_LOGIN:
  1042. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1043. bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
  1044. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1045. } else {
  1046. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1047. bfa_lps_send_login(lps);
  1048. }
  1049. if (lps->fdisc)
  1050. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1051. BFA_PL_EID_LOGIN, 0, "FDISC Request");
  1052. else
  1053. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1054. BFA_PL_EID_LOGIN, 0, "FLOGI Request");
  1055. break;
  1056. case BFA_LPS_SM_LOGOUT:
  1057. bfa_lps_logout_comp(lps);
  1058. break;
  1059. case BFA_LPS_SM_DELETE:
  1060. bfa_lps_free(lps);
  1061. break;
  1062. case BFA_LPS_SM_RX_CVL:
  1063. case BFA_LPS_SM_OFFLINE:
  1064. break;
  1065. case BFA_LPS_SM_FWRSP:
  1066. /*
  1067. * Could happen when fabric detects loopback and discards
  1068. * the lps request. Fw will eventually sent out the timeout
  1069. * Just ignore
  1070. */
  1071. break;
  1072. case BFA_LPS_SM_SET_N2N_PID:
  1073. /*
  1074. * When topology is set to loop, bfa_lps_set_n2n_pid() sends
  1075. * this event. Ignore this event.
  1076. */
  1077. break;
  1078. default:
  1079. bfa_sm_fault(lps->bfa, event);
  1080. }
  1081. }
  1082. /*
  1083. * login is in progress -- awaiting response from firmware
  1084. */
  1085. static void
  1086. bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1087. {
  1088. bfa_trc(lps->bfa, lps->bfa_tag);
  1089. bfa_trc(lps->bfa, event);
  1090. switch (event) {
  1091. case BFA_LPS_SM_FWRSP:
  1092. case BFA_LPS_SM_OFFLINE:
  1093. if (lps->status == BFA_STATUS_OK) {
  1094. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1095. if (lps->fdisc)
  1096. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1097. BFA_PL_EID_LOGIN, 0, "FDISC Accept");
  1098. else
  1099. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1100. BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
  1101. /* If N2N, send the assigned PID to FW */
  1102. bfa_trc(lps->bfa, lps->fport);
  1103. bfa_trc(lps->bfa, lps->lp_pid);
  1104. if (!lps->fport && lps->lp_pid)
  1105. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1106. } else {
  1107. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1108. if (lps->fdisc)
  1109. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1110. BFA_PL_EID_LOGIN, 0,
  1111. "FDISC Fail (RJT or timeout)");
  1112. else
  1113. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1114. BFA_PL_EID_LOGIN, 0,
  1115. "FLOGI Fail (RJT or timeout)");
  1116. }
  1117. bfa_lps_login_comp(lps);
  1118. break;
  1119. case BFA_LPS_SM_DELETE:
  1120. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1121. break;
  1122. case BFA_LPS_SM_SET_N2N_PID:
  1123. bfa_trc(lps->bfa, lps->fport);
  1124. bfa_trc(lps->bfa, lps->lp_pid);
  1125. break;
  1126. default:
  1127. bfa_sm_fault(lps->bfa, event);
  1128. }
  1129. }
  1130. /*
  1131. * login pending - awaiting space in request queue
  1132. */
  1133. static void
  1134. bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1135. {
  1136. bfa_trc(lps->bfa, lps->bfa_tag);
  1137. bfa_trc(lps->bfa, event);
  1138. switch (event) {
  1139. case BFA_LPS_SM_RESUME:
  1140. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1141. bfa_lps_send_login(lps);
  1142. break;
  1143. case BFA_LPS_SM_OFFLINE:
  1144. case BFA_LPS_SM_DELETE:
  1145. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1146. bfa_reqq_wcancel(&lps->wqe);
  1147. break;
  1148. case BFA_LPS_SM_RX_CVL:
  1149. /*
  1150. * Login was not even sent out; so when getting out
  1151. * of this state, it will appear like a login retry
  1152. * after Clear virtual link
  1153. */
  1154. break;
  1155. default:
  1156. bfa_sm_fault(lps->bfa, event);
  1157. }
  1158. }
  1159. /*
  1160. * login complete
  1161. */
  1162. static void
  1163. bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1164. {
  1165. bfa_trc(lps->bfa, lps->bfa_tag);
  1166. bfa_trc(lps->bfa, event);
  1167. switch (event) {
  1168. case BFA_LPS_SM_LOGOUT:
  1169. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1170. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1171. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1172. } else {
  1173. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1174. bfa_lps_send_logout(lps);
  1175. }
  1176. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1177. BFA_PL_EID_LOGO, 0, "Logout");
  1178. break;
  1179. case BFA_LPS_SM_RX_CVL:
  1180. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1181. /* Let the vport module know about this event */
  1182. bfa_lps_cvl_event(lps);
  1183. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1184. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1185. break;
  1186. case BFA_LPS_SM_SET_N2N_PID:
  1187. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1188. bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
  1189. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1190. } else
  1191. bfa_lps_send_set_n2n_pid(lps);
  1192. break;
  1193. case BFA_LPS_SM_OFFLINE:
  1194. case BFA_LPS_SM_DELETE:
  1195. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1196. break;
  1197. default:
  1198. bfa_sm_fault(lps->bfa, event);
  1199. }
  1200. }
  1201. /*
  1202. * login complete
  1203. */
  1204. static void
  1205. bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1206. {
  1207. bfa_trc(lps->bfa, lps->bfa_tag);
  1208. bfa_trc(lps->bfa, event);
  1209. switch (event) {
  1210. case BFA_LPS_SM_RESUME:
  1211. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1212. bfa_lps_send_set_n2n_pid(lps);
  1213. break;
  1214. case BFA_LPS_SM_LOGOUT:
  1215. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1216. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1217. BFA_PL_EID_LOGO, 0, "Logout");
  1218. break;
  1219. case BFA_LPS_SM_RX_CVL:
  1220. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1221. bfa_reqq_wcancel(&lps->wqe);
  1222. /* Let the vport module know about this event */
  1223. bfa_lps_cvl_event(lps);
  1224. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1225. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1226. break;
  1227. case BFA_LPS_SM_OFFLINE:
  1228. case BFA_LPS_SM_DELETE:
  1229. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1230. bfa_reqq_wcancel(&lps->wqe);
  1231. break;
  1232. default:
  1233. bfa_sm_fault(lps->bfa, event);
  1234. }
  1235. }
  1236. /*
  1237. * logout in progress - awaiting firmware response
  1238. */
  1239. static void
  1240. bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1241. {
  1242. bfa_trc(lps->bfa, lps->bfa_tag);
  1243. bfa_trc(lps->bfa, event);
  1244. switch (event) {
  1245. case BFA_LPS_SM_FWRSP:
  1246. case BFA_LPS_SM_OFFLINE:
  1247. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1248. bfa_lps_logout_comp(lps);
  1249. break;
  1250. case BFA_LPS_SM_DELETE:
  1251. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1252. break;
  1253. default:
  1254. bfa_sm_fault(lps->bfa, event);
  1255. }
  1256. }
  1257. /*
  1258. * logout pending -- awaiting space in request queue
  1259. */
  1260. static void
  1261. bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1262. {
  1263. bfa_trc(lps->bfa, lps->bfa_tag);
  1264. bfa_trc(lps->bfa, event);
  1265. switch (event) {
  1266. case BFA_LPS_SM_RESUME:
  1267. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1268. bfa_lps_send_logout(lps);
  1269. break;
  1270. case BFA_LPS_SM_OFFLINE:
  1271. case BFA_LPS_SM_DELETE:
  1272. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1273. bfa_reqq_wcancel(&lps->wqe);
  1274. break;
  1275. default:
  1276. bfa_sm_fault(lps->bfa, event);
  1277. }
  1278. }
  1279. /*
  1280. * lps_pvt BFA LPS private functions
  1281. */
  1282. /*
  1283. * return memory requirement
  1284. */
  1285. static void
  1286. bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  1287. struct bfa_s *bfa)
  1288. {
  1289. struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
  1290. if (cfg->drvcfg.min_cfg)
  1291. bfa_mem_kva_setup(minfo, lps_kva,
  1292. sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
  1293. else
  1294. bfa_mem_kva_setup(minfo, lps_kva,
  1295. sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
  1296. }
  1297. /*
  1298. * bfa module attach at initialization time
  1299. */
  1300. static void
  1301. bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1302. struct bfa_pcidev_s *pcidev)
  1303. {
  1304. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1305. struct bfa_lps_s *lps;
  1306. int i;
  1307. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1308. if (cfg->drvcfg.min_cfg)
  1309. mod->num_lps = BFA_LPS_MIN_LPORTS;
  1310. else
  1311. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1312. mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
  1313. bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
  1314. INIT_LIST_HEAD(&mod->lps_free_q);
  1315. INIT_LIST_HEAD(&mod->lps_active_q);
  1316. INIT_LIST_HEAD(&mod->lps_login_q);
  1317. for (i = 0; i < mod->num_lps; i++, lps++) {
  1318. lps->bfa = bfa;
  1319. lps->bfa_tag = (u8) i;
  1320. lps->reqq = BFA_REQQ_LPS;
  1321. bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
  1322. list_add_tail(&lps->qe, &mod->lps_free_q);
  1323. }
  1324. }
  1325. static void
  1326. bfa_lps_detach(struct bfa_s *bfa)
  1327. {
  1328. }
  1329. static void
  1330. bfa_lps_start(struct bfa_s *bfa)
  1331. {
  1332. }
  1333. static void
  1334. bfa_lps_stop(struct bfa_s *bfa)
  1335. {
  1336. }
  1337. /*
  1338. * IOC in disabled state -- consider all lps offline
  1339. */
  1340. static void
  1341. bfa_lps_iocdisable(struct bfa_s *bfa)
  1342. {
  1343. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1344. struct bfa_lps_s *lps;
  1345. struct list_head *qe, *qen;
  1346. list_for_each_safe(qe, qen, &mod->lps_active_q) {
  1347. lps = (struct bfa_lps_s *) qe;
  1348. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1349. }
  1350. list_for_each_safe(qe, qen, &mod->lps_login_q) {
  1351. lps = (struct bfa_lps_s *) qe;
  1352. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1353. }
  1354. list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
  1355. }
  1356. /*
  1357. * Firmware login response
  1358. */
  1359. static void
  1360. bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
  1361. {
  1362. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1363. struct bfa_lps_s *lps;
  1364. WARN_ON(rsp->bfa_tag >= mod->num_lps);
  1365. lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
  1366. lps->status = rsp->status;
  1367. switch (rsp->status) {
  1368. case BFA_STATUS_OK:
  1369. lps->fw_tag = rsp->fw_tag;
  1370. lps->fport = rsp->f_port;
  1371. if (lps->fport)
  1372. lps->lp_pid = rsp->lp_pid;
  1373. lps->npiv_en = rsp->npiv_en;
  1374. lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
  1375. lps->pr_pwwn = rsp->port_name;
  1376. lps->pr_nwwn = rsp->node_name;
  1377. lps->auth_req = rsp->auth_req;
  1378. lps->lp_mac = rsp->lp_mac;
  1379. lps->brcd_switch = rsp->brcd_switch;
  1380. lps->fcf_mac = rsp->fcf_mac;
  1381. lps->pr_bbscn = rsp->bb_scn;
  1382. break;
  1383. case BFA_STATUS_FABRIC_RJT:
  1384. lps->lsrjt_rsn = rsp->lsrjt_rsn;
  1385. lps->lsrjt_expl = rsp->lsrjt_expl;
  1386. break;
  1387. case BFA_STATUS_EPROTOCOL:
  1388. lps->ext_status = rsp->ext_status;
  1389. break;
  1390. case BFA_STATUS_VPORT_MAX:
  1391. if (rsp->ext_status)
  1392. bfa_lps_no_res(lps, rsp->ext_status);
  1393. break;
  1394. default:
  1395. /* Nothing to do with other status */
  1396. break;
  1397. }
  1398. list_del(&lps->qe);
  1399. list_add_tail(&lps->qe, &mod->lps_active_q);
  1400. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1401. }
  1402. static void
  1403. bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
  1404. {
  1405. struct bfa_s *bfa = first_lps->bfa;
  1406. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1407. struct list_head *qe, *qe_next;
  1408. struct bfa_lps_s *lps;
  1409. bfa_trc(bfa, count);
  1410. qe = bfa_q_next(first_lps);
  1411. while (count && qe) {
  1412. qe_next = bfa_q_next(qe);
  1413. lps = (struct bfa_lps_s *)qe;
  1414. bfa_trc(bfa, lps->bfa_tag);
  1415. lps->status = first_lps->status;
  1416. list_del(&lps->qe);
  1417. list_add_tail(&lps->qe, &mod->lps_active_q);
  1418. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1419. qe = qe_next;
  1420. count--;
  1421. }
  1422. }
  1423. /*
  1424. * Firmware logout response
  1425. */
  1426. static void
  1427. bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
  1428. {
  1429. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1430. struct bfa_lps_s *lps;
  1431. WARN_ON(rsp->bfa_tag >= mod->num_lps);
  1432. lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
  1433. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1434. }
  1435. /*
  1436. * Firmware received a Clear virtual link request (for FCoE)
  1437. */
  1438. static void
  1439. bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
  1440. {
  1441. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1442. struct bfa_lps_s *lps;
  1443. lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
  1444. bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
  1445. }
  1446. /*
  1447. * Space is available in request queue, resume queueing request to firmware.
  1448. */
  1449. static void
  1450. bfa_lps_reqq_resume(void *lps_arg)
  1451. {
  1452. struct bfa_lps_s *lps = lps_arg;
  1453. bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
  1454. }
  1455. /*
  1456. * lps is freed -- triggered by vport delete
  1457. */
  1458. static void
  1459. bfa_lps_free(struct bfa_lps_s *lps)
  1460. {
  1461. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1462. lps->lp_pid = 0;
  1463. list_del(&lps->qe);
  1464. list_add_tail(&lps->qe, &mod->lps_free_q);
  1465. }
  1466. /*
  1467. * send login request to firmware
  1468. */
  1469. static void
  1470. bfa_lps_send_login(struct bfa_lps_s *lps)
  1471. {
  1472. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1473. struct bfi_lps_login_req_s *m;
  1474. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1475. WARN_ON(!m);
  1476. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
  1477. bfa_fn_lpu(lps->bfa));
  1478. m->bfa_tag = lps->bfa_tag;
  1479. m->alpa = lps->alpa;
  1480. m->pdu_size = cpu_to_be16(lps->pdusz);
  1481. m->pwwn = lps->pwwn;
  1482. m->nwwn = lps->nwwn;
  1483. m->fdisc = lps->fdisc;
  1484. m->auth_en = lps->auth_en;
  1485. m->bb_scn = lps->bb_scn;
  1486. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1487. list_del(&lps->qe);
  1488. list_add_tail(&lps->qe, &mod->lps_login_q);
  1489. }
  1490. /*
  1491. * send logout request to firmware
  1492. */
  1493. static void
  1494. bfa_lps_send_logout(struct bfa_lps_s *lps)
  1495. {
  1496. struct bfi_lps_logout_req_s *m;
  1497. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1498. WARN_ON(!m);
  1499. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
  1500. bfa_fn_lpu(lps->bfa));
  1501. m->fw_tag = lps->fw_tag;
  1502. m->port_name = lps->pwwn;
  1503. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1504. }
  1505. /*
  1506. * send n2n pid set request to firmware
  1507. */
  1508. static void
  1509. bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
  1510. {
  1511. struct bfi_lps_n2n_pid_req_s *m;
  1512. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1513. WARN_ON(!m);
  1514. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
  1515. bfa_fn_lpu(lps->bfa));
  1516. m->fw_tag = lps->fw_tag;
  1517. m->lp_pid = lps->lp_pid;
  1518. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1519. }
  1520. /*
  1521. * Indirect login completion handler for non-fcs
  1522. */
  1523. static void
  1524. bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
  1525. {
  1526. struct bfa_lps_s *lps = arg;
  1527. if (!complete)
  1528. return;
  1529. if (lps->fdisc)
  1530. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1531. else
  1532. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1533. }
  1534. /*
  1535. * Login completion handler -- direct call for fcs, queue for others
  1536. */
  1537. static void
  1538. bfa_lps_login_comp(struct bfa_lps_s *lps)
  1539. {
  1540. if (!lps->bfa->fcs) {
  1541. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
  1542. lps);
  1543. return;
  1544. }
  1545. if (lps->fdisc)
  1546. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1547. else
  1548. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1549. }
  1550. /*
  1551. * Indirect logout completion handler for non-fcs
  1552. */
  1553. static void
  1554. bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
  1555. {
  1556. struct bfa_lps_s *lps = arg;
  1557. if (!complete)
  1558. return;
  1559. if (lps->fdisc)
  1560. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1561. else
  1562. bfa_cb_lps_flogo_comp(lps->bfa->bfad, lps->uarg);
  1563. }
  1564. /*
  1565. * Logout completion handler -- direct call for fcs, queue for others
  1566. */
  1567. static void
  1568. bfa_lps_logout_comp(struct bfa_lps_s *lps)
  1569. {
  1570. if (!lps->bfa->fcs) {
  1571. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
  1572. lps);
  1573. return;
  1574. }
  1575. if (lps->fdisc)
  1576. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1577. }
  1578. /*
  1579. * Clear virtual link completion handler for non-fcs
  1580. */
  1581. static void
  1582. bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
  1583. {
  1584. struct bfa_lps_s *lps = arg;
  1585. if (!complete)
  1586. return;
  1587. /* Clear virtual link to base port will result in link down */
  1588. if (lps->fdisc)
  1589. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1590. }
  1591. /*
  1592. * Received Clear virtual link event --direct call for fcs,
  1593. * queue for others
  1594. */
  1595. static void
  1596. bfa_lps_cvl_event(struct bfa_lps_s *lps)
  1597. {
  1598. if (!lps->bfa->fcs) {
  1599. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
  1600. lps);
  1601. return;
  1602. }
  1603. /* Clear virtual link to base port will result in link down */
  1604. if (lps->fdisc)
  1605. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1606. }
  1607. /*
  1608. * lps_public BFA LPS public functions
  1609. */
  1610. u32
  1611. bfa_lps_get_max_vport(struct bfa_s *bfa)
  1612. {
  1613. if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
  1614. return BFA_LPS_MAX_VPORTS_SUPP_CT;
  1615. else
  1616. return BFA_LPS_MAX_VPORTS_SUPP_CB;
  1617. }
  1618. /*
  1619. * Allocate a lport srvice tag.
  1620. */
  1621. struct bfa_lps_s *
  1622. bfa_lps_alloc(struct bfa_s *bfa)
  1623. {
  1624. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1625. struct bfa_lps_s *lps = NULL;
  1626. bfa_q_deq(&mod->lps_free_q, &lps);
  1627. if (lps == NULL)
  1628. return NULL;
  1629. list_add_tail(&lps->qe, &mod->lps_active_q);
  1630. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1631. return lps;
  1632. }
  1633. /*
  1634. * Free lport service tag. This can be called anytime after an alloc.
  1635. * No need to wait for any pending login/logout completions.
  1636. */
  1637. void
  1638. bfa_lps_delete(struct bfa_lps_s *lps)
  1639. {
  1640. bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
  1641. }
  1642. /*
  1643. * Initiate a lport login.
  1644. */
  1645. void
  1646. bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
  1647. wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
  1648. {
  1649. lps->uarg = uarg;
  1650. lps->alpa = alpa;
  1651. lps->pdusz = pdusz;
  1652. lps->pwwn = pwwn;
  1653. lps->nwwn = nwwn;
  1654. lps->fdisc = BFA_FALSE;
  1655. lps->auth_en = auth_en;
  1656. lps->bb_scn = bb_scn;
  1657. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1658. }
  1659. /*
  1660. * Initiate a lport fdisc login.
  1661. */
  1662. void
  1663. bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
  1664. wwn_t nwwn)
  1665. {
  1666. lps->uarg = uarg;
  1667. lps->alpa = 0;
  1668. lps->pdusz = pdusz;
  1669. lps->pwwn = pwwn;
  1670. lps->nwwn = nwwn;
  1671. lps->fdisc = BFA_TRUE;
  1672. lps->auth_en = BFA_FALSE;
  1673. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1674. }
  1675. /*
  1676. * Initiate a lport FDSIC logout.
  1677. */
  1678. void
  1679. bfa_lps_fdisclogo(struct bfa_lps_s *lps)
  1680. {
  1681. bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
  1682. }
  1683. u8
  1684. bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
  1685. {
  1686. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1687. return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
  1688. }
  1689. /*
  1690. * Return lport services tag given the pid
  1691. */
  1692. u8
  1693. bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
  1694. {
  1695. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1696. struct bfa_lps_s *lps;
  1697. int i;
  1698. for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
  1699. if (lps->lp_pid == pid)
  1700. return lps->bfa_tag;
  1701. }
  1702. /* Return base port tag anyway */
  1703. return 0;
  1704. }
  1705. /*
  1706. * return port id assigned to the base lport
  1707. */
  1708. u32
  1709. bfa_lps_get_base_pid(struct bfa_s *bfa)
  1710. {
  1711. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1712. return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
  1713. }
  1714. /*
  1715. * Set PID in case of n2n (which is assigned during PLOGI)
  1716. */
  1717. void
  1718. bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
  1719. {
  1720. bfa_trc(lps->bfa, lps->bfa_tag);
  1721. bfa_trc(lps->bfa, n2n_pid);
  1722. lps->lp_pid = n2n_pid;
  1723. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1724. }
  1725. /*
  1726. * LPS firmware message class handler.
  1727. */
  1728. void
  1729. bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  1730. {
  1731. union bfi_lps_i2h_msg_u msg;
  1732. bfa_trc(bfa, m->mhdr.msg_id);
  1733. msg.msg = m;
  1734. switch (m->mhdr.msg_id) {
  1735. case BFI_LPS_I2H_LOGIN_RSP:
  1736. bfa_lps_login_rsp(bfa, msg.login_rsp);
  1737. break;
  1738. case BFI_LPS_I2H_LOGOUT_RSP:
  1739. bfa_lps_logout_rsp(bfa, msg.logout_rsp);
  1740. break;
  1741. case BFI_LPS_I2H_CVL_EVENT:
  1742. bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
  1743. break;
  1744. default:
  1745. bfa_trc(bfa, m->mhdr.msg_id);
  1746. WARN_ON(1);
  1747. }
  1748. }
  1749. static void
  1750. bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
  1751. {
  1752. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1753. struct bfa_aen_entry_s *aen_entry;
  1754. bfad_get_aen_entry(bfad, aen_entry);
  1755. if (!aen_entry)
  1756. return;
  1757. aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
  1758. aen_entry->aen_data.port.pwwn = fcport->pwwn;
  1759. /* Send the AEN notification */
  1760. bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
  1761. BFA_AEN_CAT_PORT, event);
  1762. }
  1763. /*
  1764. * FC PORT state machine functions
  1765. */
  1766. static void
  1767. bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  1768. enum bfa_fcport_sm_event event)
  1769. {
  1770. bfa_trc(fcport->bfa, event);
  1771. switch (event) {
  1772. case BFA_FCPORT_SM_START:
  1773. /*
  1774. * Start event after IOC is configured and BFA is started.
  1775. */
  1776. fcport->use_flash_cfg = BFA_TRUE;
  1777. if (bfa_fcport_send_enable(fcport)) {
  1778. bfa_trc(fcport->bfa, BFA_TRUE);
  1779. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1780. } else {
  1781. bfa_trc(fcport->bfa, BFA_FALSE);
  1782. bfa_sm_set_state(fcport,
  1783. bfa_fcport_sm_enabling_qwait);
  1784. }
  1785. break;
  1786. case BFA_FCPORT_SM_ENABLE:
  1787. /*
  1788. * Port is persistently configured to be in enabled state. Do
  1789. * not change state. Port enabling is done when START event is
  1790. * received.
  1791. */
  1792. break;
  1793. case BFA_FCPORT_SM_DISABLE:
  1794. /*
  1795. * If a port is persistently configured to be disabled, the
  1796. * first event will a port disable request.
  1797. */
  1798. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1799. break;
  1800. case BFA_FCPORT_SM_HWFAIL:
  1801. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1802. break;
  1803. default:
  1804. bfa_sm_fault(fcport->bfa, event);
  1805. }
  1806. }
  1807. static void
  1808. bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  1809. enum bfa_fcport_sm_event event)
  1810. {
  1811. char pwwn_buf[BFA_STRING_32];
  1812. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1813. bfa_trc(fcport->bfa, event);
  1814. switch (event) {
  1815. case BFA_FCPORT_SM_QRESUME:
  1816. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1817. bfa_fcport_send_enable(fcport);
  1818. break;
  1819. case BFA_FCPORT_SM_STOP:
  1820. bfa_reqq_wcancel(&fcport->reqq_wait);
  1821. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1822. break;
  1823. case BFA_FCPORT_SM_ENABLE:
  1824. /*
  1825. * Already enable is in progress.
  1826. */
  1827. break;
  1828. case BFA_FCPORT_SM_DISABLE:
  1829. /*
  1830. * Just send disable request to firmware when room becomes
  1831. * available in request queue.
  1832. */
  1833. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1834. bfa_reqq_wcancel(&fcport->reqq_wait);
  1835. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1836. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1837. wwn2str(pwwn_buf, fcport->pwwn);
  1838. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1839. "Base port disabled: WWN = %s\n", pwwn_buf);
  1840. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1841. break;
  1842. case BFA_FCPORT_SM_LINKUP:
  1843. case BFA_FCPORT_SM_LINKDOWN:
  1844. /*
  1845. * Possible to get link events when doing back-to-back
  1846. * enable/disables.
  1847. */
  1848. break;
  1849. case BFA_FCPORT_SM_HWFAIL:
  1850. bfa_reqq_wcancel(&fcport->reqq_wait);
  1851. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1852. break;
  1853. default:
  1854. bfa_sm_fault(fcport->bfa, event);
  1855. }
  1856. }
  1857. static void
  1858. bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  1859. enum bfa_fcport_sm_event event)
  1860. {
  1861. char pwwn_buf[BFA_STRING_32];
  1862. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1863. bfa_trc(fcport->bfa, event);
  1864. switch (event) {
  1865. case BFA_FCPORT_SM_FWRSP:
  1866. case BFA_FCPORT_SM_LINKDOWN:
  1867. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1868. break;
  1869. case BFA_FCPORT_SM_LINKUP:
  1870. bfa_fcport_update_linkinfo(fcport);
  1871. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1872. WARN_ON(!fcport->event_cbfn);
  1873. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1874. break;
  1875. case BFA_FCPORT_SM_ENABLE:
  1876. /*
  1877. * Already being enabled.
  1878. */
  1879. break;
  1880. case BFA_FCPORT_SM_DISABLE:
  1881. if (bfa_fcport_send_disable(fcport))
  1882. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1883. else
  1884. bfa_sm_set_state(fcport,
  1885. bfa_fcport_sm_disabling_qwait);
  1886. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1887. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1888. wwn2str(pwwn_buf, fcport->pwwn);
  1889. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1890. "Base port disabled: WWN = %s\n", pwwn_buf);
  1891. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1892. break;
  1893. case BFA_FCPORT_SM_STOP:
  1894. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1895. break;
  1896. case BFA_FCPORT_SM_HWFAIL:
  1897. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1898. break;
  1899. default:
  1900. bfa_sm_fault(fcport->bfa, event);
  1901. }
  1902. }
  1903. static void
  1904. bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  1905. enum bfa_fcport_sm_event event)
  1906. {
  1907. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  1908. char pwwn_buf[BFA_STRING_32];
  1909. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1910. bfa_trc(fcport->bfa, event);
  1911. switch (event) {
  1912. case BFA_FCPORT_SM_LINKUP:
  1913. bfa_fcport_update_linkinfo(fcport);
  1914. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1915. WARN_ON(!fcport->event_cbfn);
  1916. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1917. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
  1918. if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  1919. bfa_trc(fcport->bfa,
  1920. pevent->link_state.attr.vc_fcf.fcf.fipenabled);
  1921. bfa_trc(fcport->bfa,
  1922. pevent->link_state.attr.vc_fcf.fcf.fipfailed);
  1923. if (pevent->link_state.attr.vc_fcf.fcf.fipfailed)
  1924. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1925. BFA_PL_EID_FIP_FCF_DISC, 0,
  1926. "FIP FCF Discovery Failed");
  1927. else
  1928. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1929. BFA_PL_EID_FIP_FCF_DISC, 0,
  1930. "FIP FCF Discovered");
  1931. }
  1932. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1933. wwn2str(pwwn_buf, fcport->pwwn);
  1934. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1935. "Base port online: WWN = %s\n", pwwn_buf);
  1936. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
  1937. /* If QoS is enabled and it is not online, send AEN */
  1938. if (fcport->cfg.qos_enabled &&
  1939. fcport->qos_attr.state != BFA_QOS_ONLINE)
  1940. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
  1941. break;
  1942. case BFA_FCPORT_SM_LINKDOWN:
  1943. /*
  1944. * Possible to get link down event.
  1945. */
  1946. break;
  1947. case BFA_FCPORT_SM_ENABLE:
  1948. /*
  1949. * Already enabled.
  1950. */
  1951. break;
  1952. case BFA_FCPORT_SM_DISABLE:
  1953. if (bfa_fcport_send_disable(fcport))
  1954. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1955. else
  1956. bfa_sm_set_state(fcport,
  1957. bfa_fcport_sm_disabling_qwait);
  1958. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1959. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1960. wwn2str(pwwn_buf, fcport->pwwn);
  1961. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1962. "Base port disabled: WWN = %s\n", pwwn_buf);
  1963. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1964. break;
  1965. case BFA_FCPORT_SM_STOP:
  1966. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1967. break;
  1968. case BFA_FCPORT_SM_HWFAIL:
  1969. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1970. break;
  1971. default:
  1972. bfa_sm_fault(fcport->bfa, event);
  1973. }
  1974. }
  1975. static void
  1976. bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  1977. enum bfa_fcport_sm_event event)
  1978. {
  1979. char pwwn_buf[BFA_STRING_32];
  1980. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1981. bfa_trc(fcport->bfa, event);
  1982. switch (event) {
  1983. case BFA_FCPORT_SM_ENABLE:
  1984. /*
  1985. * Already enabled.
  1986. */
  1987. break;
  1988. case BFA_FCPORT_SM_DISABLE:
  1989. if (bfa_fcport_send_disable(fcport))
  1990. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1991. else
  1992. bfa_sm_set_state(fcport,
  1993. bfa_fcport_sm_disabling_qwait);
  1994. bfa_fcport_reset_linkinfo(fcport);
  1995. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1996. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1997. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1998. wwn2str(pwwn_buf, fcport->pwwn);
  1999. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2000. "Base port offline: WWN = %s\n", pwwn_buf);
  2001. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  2002. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2003. "Base port disabled: WWN = %s\n", pwwn_buf);
  2004. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  2005. break;
  2006. case BFA_FCPORT_SM_LINKDOWN:
  2007. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  2008. bfa_fcport_reset_linkinfo(fcport);
  2009. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  2010. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2011. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
  2012. wwn2str(pwwn_buf, fcport->pwwn);
  2013. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  2014. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2015. "Base port offline: WWN = %s\n", pwwn_buf);
  2016. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  2017. } else {
  2018. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  2019. "Base port (WWN = %s) "
  2020. "lost fabric connectivity\n", pwwn_buf);
  2021. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  2022. }
  2023. break;
  2024. case BFA_FCPORT_SM_STOP:
  2025. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2026. bfa_fcport_reset_linkinfo(fcport);
  2027. wwn2str(pwwn_buf, fcport->pwwn);
  2028. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  2029. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2030. "Base port offline: WWN = %s\n", pwwn_buf);
  2031. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  2032. } else {
  2033. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  2034. "Base port (WWN = %s) "
  2035. "lost fabric connectivity\n", pwwn_buf);
  2036. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  2037. }
  2038. break;
  2039. case BFA_FCPORT_SM_HWFAIL:
  2040. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2041. bfa_fcport_reset_linkinfo(fcport);
  2042. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  2043. wwn2str(pwwn_buf, fcport->pwwn);
  2044. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  2045. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2046. "Base port offline: WWN = %s\n", pwwn_buf);
  2047. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  2048. } else {
  2049. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  2050. "Base port (WWN = %s) "
  2051. "lost fabric connectivity\n", pwwn_buf);
  2052. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  2053. }
  2054. break;
  2055. default:
  2056. bfa_sm_fault(fcport->bfa, event);
  2057. }
  2058. }
  2059. static void
  2060. bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  2061. enum bfa_fcport_sm_event event)
  2062. {
  2063. bfa_trc(fcport->bfa, event);
  2064. switch (event) {
  2065. case BFA_FCPORT_SM_QRESUME:
  2066. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  2067. bfa_fcport_send_disable(fcport);
  2068. break;
  2069. case BFA_FCPORT_SM_STOP:
  2070. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2071. bfa_reqq_wcancel(&fcport->reqq_wait);
  2072. break;
  2073. case BFA_FCPORT_SM_ENABLE:
  2074. bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
  2075. break;
  2076. case BFA_FCPORT_SM_DISABLE:
  2077. /*
  2078. * Already being disabled.
  2079. */
  2080. break;
  2081. case BFA_FCPORT_SM_LINKUP:
  2082. case BFA_FCPORT_SM_LINKDOWN:
  2083. /*
  2084. * Possible to get link events when doing back-to-back
  2085. * enable/disables.
  2086. */
  2087. break;
  2088. case BFA_FCPORT_SM_HWFAIL:
  2089. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2090. bfa_reqq_wcancel(&fcport->reqq_wait);
  2091. break;
  2092. default:
  2093. bfa_sm_fault(fcport->bfa, event);
  2094. }
  2095. }
  2096. static void
  2097. bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  2098. enum bfa_fcport_sm_event event)
  2099. {
  2100. bfa_trc(fcport->bfa, event);
  2101. switch (event) {
  2102. case BFA_FCPORT_SM_QRESUME:
  2103. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  2104. bfa_fcport_send_disable(fcport);
  2105. if (bfa_fcport_send_enable(fcport))
  2106. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2107. else
  2108. bfa_sm_set_state(fcport,
  2109. bfa_fcport_sm_enabling_qwait);
  2110. break;
  2111. case BFA_FCPORT_SM_STOP:
  2112. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2113. bfa_reqq_wcancel(&fcport->reqq_wait);
  2114. break;
  2115. case BFA_FCPORT_SM_ENABLE:
  2116. break;
  2117. case BFA_FCPORT_SM_DISABLE:
  2118. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  2119. break;
  2120. case BFA_FCPORT_SM_LINKUP:
  2121. case BFA_FCPORT_SM_LINKDOWN:
  2122. /*
  2123. * Possible to get link events when doing back-to-back
  2124. * enable/disables.
  2125. */
  2126. break;
  2127. case BFA_FCPORT_SM_HWFAIL:
  2128. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2129. bfa_reqq_wcancel(&fcport->reqq_wait);
  2130. break;
  2131. default:
  2132. bfa_sm_fault(fcport->bfa, event);
  2133. }
  2134. }
  2135. static void
  2136. bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  2137. enum bfa_fcport_sm_event event)
  2138. {
  2139. char pwwn_buf[BFA_STRING_32];
  2140. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2141. bfa_trc(fcport->bfa, event);
  2142. switch (event) {
  2143. case BFA_FCPORT_SM_FWRSP:
  2144. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2145. break;
  2146. case BFA_FCPORT_SM_DISABLE:
  2147. /*
  2148. * Already being disabled.
  2149. */
  2150. break;
  2151. case BFA_FCPORT_SM_ENABLE:
  2152. if (bfa_fcport_send_enable(fcport))
  2153. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2154. else
  2155. bfa_sm_set_state(fcport,
  2156. bfa_fcport_sm_enabling_qwait);
  2157. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2158. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2159. wwn2str(pwwn_buf, fcport->pwwn);
  2160. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2161. "Base port enabled: WWN = %s\n", pwwn_buf);
  2162. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  2163. break;
  2164. case BFA_FCPORT_SM_STOP:
  2165. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2166. break;
  2167. case BFA_FCPORT_SM_LINKUP:
  2168. case BFA_FCPORT_SM_LINKDOWN:
  2169. /*
  2170. * Possible to get link events when doing back-to-back
  2171. * enable/disables.
  2172. */
  2173. break;
  2174. case BFA_FCPORT_SM_HWFAIL:
  2175. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2176. break;
  2177. default:
  2178. bfa_sm_fault(fcport->bfa, event);
  2179. }
  2180. }
  2181. static void
  2182. bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  2183. enum bfa_fcport_sm_event event)
  2184. {
  2185. char pwwn_buf[BFA_STRING_32];
  2186. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2187. bfa_trc(fcport->bfa, event);
  2188. switch (event) {
  2189. case BFA_FCPORT_SM_START:
  2190. /*
  2191. * Ignore start event for a port that is disabled.
  2192. */
  2193. break;
  2194. case BFA_FCPORT_SM_STOP:
  2195. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2196. break;
  2197. case BFA_FCPORT_SM_ENABLE:
  2198. if (bfa_fcport_send_enable(fcport))
  2199. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2200. else
  2201. bfa_sm_set_state(fcport,
  2202. bfa_fcport_sm_enabling_qwait);
  2203. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2204. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2205. wwn2str(pwwn_buf, fcport->pwwn);
  2206. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2207. "Base port enabled: WWN = %s\n", pwwn_buf);
  2208. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  2209. break;
  2210. case BFA_FCPORT_SM_DISABLE:
  2211. /*
  2212. * Already disabled.
  2213. */
  2214. break;
  2215. case BFA_FCPORT_SM_HWFAIL:
  2216. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2217. break;
  2218. case BFA_FCPORT_SM_DPORTENABLE:
  2219. bfa_sm_set_state(fcport, bfa_fcport_sm_dport);
  2220. break;
  2221. default:
  2222. bfa_sm_fault(fcport->bfa, event);
  2223. }
  2224. }
  2225. static void
  2226. bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  2227. enum bfa_fcport_sm_event event)
  2228. {
  2229. bfa_trc(fcport->bfa, event);
  2230. switch (event) {
  2231. case BFA_FCPORT_SM_START:
  2232. if (bfa_fcport_send_enable(fcport))
  2233. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2234. else
  2235. bfa_sm_set_state(fcport,
  2236. bfa_fcport_sm_enabling_qwait);
  2237. break;
  2238. default:
  2239. /*
  2240. * Ignore all other events.
  2241. */
  2242. ;
  2243. }
  2244. }
  2245. /*
  2246. * Port is enabled. IOC is down/failed.
  2247. */
  2248. static void
  2249. bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  2250. enum bfa_fcport_sm_event event)
  2251. {
  2252. bfa_trc(fcport->bfa, event);
  2253. switch (event) {
  2254. case BFA_FCPORT_SM_START:
  2255. if (bfa_fcport_send_enable(fcport))
  2256. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2257. else
  2258. bfa_sm_set_state(fcport,
  2259. bfa_fcport_sm_enabling_qwait);
  2260. break;
  2261. default:
  2262. /*
  2263. * Ignore all events.
  2264. */
  2265. ;
  2266. }
  2267. }
  2268. /*
  2269. * Port is disabled. IOC is down/failed.
  2270. */
  2271. static void
  2272. bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  2273. enum bfa_fcport_sm_event event)
  2274. {
  2275. bfa_trc(fcport->bfa, event);
  2276. switch (event) {
  2277. case BFA_FCPORT_SM_START:
  2278. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2279. break;
  2280. case BFA_FCPORT_SM_ENABLE:
  2281. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2282. break;
  2283. default:
  2284. /*
  2285. * Ignore all events.
  2286. */
  2287. ;
  2288. }
  2289. }
  2290. static void
  2291. bfa_fcport_sm_dport(struct bfa_fcport_s *fcport, enum bfa_fcport_sm_event event)
  2292. {
  2293. bfa_trc(fcport->bfa, event);
  2294. switch (event) {
  2295. case BFA_FCPORT_SM_DPORTENABLE:
  2296. case BFA_FCPORT_SM_DISABLE:
  2297. case BFA_FCPORT_SM_ENABLE:
  2298. case BFA_FCPORT_SM_START:
  2299. /*
  2300. * Ignore event for a port that is dport
  2301. */
  2302. break;
  2303. case BFA_FCPORT_SM_STOP:
  2304. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2305. break;
  2306. case BFA_FCPORT_SM_HWFAIL:
  2307. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2308. break;
  2309. case BFA_FCPORT_SM_DPORTDISABLE:
  2310. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2311. break;
  2312. default:
  2313. bfa_sm_fault(fcport->bfa, event);
  2314. }
  2315. }
  2316. /*
  2317. * Link state is down
  2318. */
  2319. static void
  2320. bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  2321. enum bfa_fcport_ln_sm_event event)
  2322. {
  2323. bfa_trc(ln->fcport->bfa, event);
  2324. switch (event) {
  2325. case BFA_FCPORT_LN_SM_LINKUP:
  2326. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2327. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2328. break;
  2329. default:
  2330. bfa_sm_fault(ln->fcport->bfa, event);
  2331. }
  2332. }
  2333. /*
  2334. * Link state is waiting for down notification
  2335. */
  2336. static void
  2337. bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  2338. enum bfa_fcport_ln_sm_event event)
  2339. {
  2340. bfa_trc(ln->fcport->bfa, event);
  2341. switch (event) {
  2342. case BFA_FCPORT_LN_SM_LINKUP:
  2343. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2344. break;
  2345. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2346. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2347. break;
  2348. default:
  2349. bfa_sm_fault(ln->fcport->bfa, event);
  2350. }
  2351. }
  2352. /*
  2353. * Link state is waiting for down notification and there is a pending up
  2354. */
  2355. static void
  2356. bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2357. enum bfa_fcport_ln_sm_event event)
  2358. {
  2359. bfa_trc(ln->fcport->bfa, event);
  2360. switch (event) {
  2361. case BFA_FCPORT_LN_SM_LINKDOWN:
  2362. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2363. break;
  2364. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2365. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2366. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2367. break;
  2368. default:
  2369. bfa_sm_fault(ln->fcport->bfa, event);
  2370. }
  2371. }
  2372. /*
  2373. * Link state is up
  2374. */
  2375. static void
  2376. bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  2377. enum bfa_fcport_ln_sm_event event)
  2378. {
  2379. bfa_trc(ln->fcport->bfa, event);
  2380. switch (event) {
  2381. case BFA_FCPORT_LN_SM_LINKDOWN:
  2382. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2383. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2384. break;
  2385. default:
  2386. bfa_sm_fault(ln->fcport->bfa, event);
  2387. }
  2388. }
  2389. /*
  2390. * Link state is waiting for up notification
  2391. */
  2392. static void
  2393. bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  2394. enum bfa_fcport_ln_sm_event event)
  2395. {
  2396. bfa_trc(ln->fcport->bfa, event);
  2397. switch (event) {
  2398. case BFA_FCPORT_LN_SM_LINKDOWN:
  2399. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2400. break;
  2401. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2402. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
  2403. break;
  2404. default:
  2405. bfa_sm_fault(ln->fcport->bfa, event);
  2406. }
  2407. }
  2408. /*
  2409. * Link state is waiting for up notification and there is a pending down
  2410. */
  2411. static void
  2412. bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  2413. enum bfa_fcport_ln_sm_event event)
  2414. {
  2415. bfa_trc(ln->fcport->bfa, event);
  2416. switch (event) {
  2417. case BFA_FCPORT_LN_SM_LINKUP:
  2418. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
  2419. break;
  2420. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2421. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2422. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2423. break;
  2424. default:
  2425. bfa_sm_fault(ln->fcport->bfa, event);
  2426. }
  2427. }
  2428. /*
  2429. * Link state is waiting for up notification and there are pending down and up
  2430. */
  2431. static void
  2432. bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2433. enum bfa_fcport_ln_sm_event event)
  2434. {
  2435. bfa_trc(ln->fcport->bfa, event);
  2436. switch (event) {
  2437. case BFA_FCPORT_LN_SM_LINKDOWN:
  2438. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2439. break;
  2440. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2441. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2442. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2443. break;
  2444. default:
  2445. bfa_sm_fault(ln->fcport->bfa, event);
  2446. }
  2447. }
  2448. static void
  2449. __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
  2450. {
  2451. struct bfa_fcport_ln_s *ln = cbarg;
  2452. if (complete)
  2453. ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
  2454. else
  2455. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2456. }
  2457. /*
  2458. * Send SCN notification to upper layers.
  2459. * trunk - false if caller is fcport to ignore fcport event in trunked mode
  2460. */
  2461. static void
  2462. bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
  2463. bfa_boolean_t trunk)
  2464. {
  2465. if (fcport->cfg.trunked && !trunk)
  2466. return;
  2467. switch (event) {
  2468. case BFA_PORT_LINKUP:
  2469. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
  2470. break;
  2471. case BFA_PORT_LINKDOWN:
  2472. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
  2473. break;
  2474. default:
  2475. WARN_ON(1);
  2476. }
  2477. }
  2478. static void
  2479. bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
  2480. {
  2481. struct bfa_fcport_s *fcport = ln->fcport;
  2482. if (fcport->bfa->fcs) {
  2483. fcport->event_cbfn(fcport->event_cbarg, event);
  2484. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2485. } else {
  2486. ln->ln_event = event;
  2487. bfa_cb_queue(fcport->bfa, &ln->ln_qe,
  2488. __bfa_cb_fcport_event, ln);
  2489. }
  2490. }
  2491. #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
  2492. BFA_CACHELINE_SZ))
  2493. static void
  2494. bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  2495. struct bfa_s *bfa)
  2496. {
  2497. struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
  2498. bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
  2499. }
  2500. static void
  2501. bfa_fcport_qresume(void *cbarg)
  2502. {
  2503. struct bfa_fcport_s *fcport = cbarg;
  2504. bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
  2505. }
  2506. static void
  2507. bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
  2508. {
  2509. struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
  2510. fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
  2511. fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
  2512. fcport->stats = (union bfa_fcport_stats_u *)
  2513. bfa_mem_dma_virt(fcport_dma);
  2514. }
  2515. /*
  2516. * Memory initialization.
  2517. */
  2518. static void
  2519. bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  2520. struct bfa_pcidev_s *pcidev)
  2521. {
  2522. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2523. struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
  2524. struct bfa_fcport_ln_s *ln = &fcport->ln;
  2525. struct timeval tv;
  2526. fcport->bfa = bfa;
  2527. ln->fcport = fcport;
  2528. bfa_fcport_mem_claim(fcport);
  2529. bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
  2530. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2531. /*
  2532. * initialize time stamp for stats reset
  2533. */
  2534. do_gettimeofday(&tv);
  2535. fcport->stats_reset_time = tv.tv_sec;
  2536. /*
  2537. * initialize and set default configuration
  2538. */
  2539. port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
  2540. port_cfg->speed = BFA_PORT_SPEED_AUTO;
  2541. port_cfg->trunked = BFA_FALSE;
  2542. port_cfg->maxfrsize = 0;
  2543. port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
  2544. INIT_LIST_HEAD(&fcport->stats_pending_q);
  2545. INIT_LIST_HEAD(&fcport->statsclr_pending_q);
  2546. bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
  2547. }
  2548. static void
  2549. bfa_fcport_detach(struct bfa_s *bfa)
  2550. {
  2551. }
  2552. /*
  2553. * Called when IOC is ready.
  2554. */
  2555. static void
  2556. bfa_fcport_start(struct bfa_s *bfa)
  2557. {
  2558. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
  2559. }
  2560. /*
  2561. * Called before IOC is stopped.
  2562. */
  2563. static void
  2564. bfa_fcport_stop(struct bfa_s *bfa)
  2565. {
  2566. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
  2567. bfa_trunk_iocdisable(bfa);
  2568. }
  2569. /*
  2570. * Called when IOC failure is detected.
  2571. */
  2572. static void
  2573. bfa_fcport_iocdisable(struct bfa_s *bfa)
  2574. {
  2575. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2576. bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
  2577. bfa_trunk_iocdisable(bfa);
  2578. }
  2579. /*
  2580. * Update loop info in fcport for SCN online
  2581. */
  2582. static void
  2583. bfa_fcport_update_loop_info(struct bfa_fcport_s *fcport,
  2584. struct bfa_fcport_loop_info_s *loop_info)
  2585. {
  2586. fcport->myalpa = loop_info->myalpa;
  2587. fcport->alpabm_valid =
  2588. loop_info->alpabm_val;
  2589. memcpy(fcport->alpabm.alpa_bm,
  2590. loop_info->alpabm.alpa_bm,
  2591. sizeof(struct fc_alpabm_s));
  2592. }
  2593. static void
  2594. bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
  2595. {
  2596. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  2597. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2598. fcport->speed = pevent->link_state.speed;
  2599. fcport->topology = pevent->link_state.topology;
  2600. if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP) {
  2601. bfa_fcport_update_loop_info(fcport,
  2602. &pevent->link_state.attr.loop_info);
  2603. return;
  2604. }
  2605. /* QoS Details */
  2606. fcport->qos_attr = pevent->link_state.qos_attr;
  2607. fcport->qos_vc_attr = pevent->link_state.attr.vc_fcf.qos_vc_attr;
  2608. /*
  2609. * update trunk state if applicable
  2610. */
  2611. if (!fcport->cfg.trunked)
  2612. trunk->attr.state = BFA_TRUNK_DISABLED;
  2613. /* update FCoE specific */
  2614. fcport->fcoe_vlan =
  2615. be16_to_cpu(pevent->link_state.attr.vc_fcf.fcf.vlan);
  2616. bfa_trc(fcport->bfa, fcport->speed);
  2617. bfa_trc(fcport->bfa, fcport->topology);
  2618. }
  2619. static void
  2620. bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
  2621. {
  2622. fcport->speed = BFA_PORT_SPEED_UNKNOWN;
  2623. fcport->topology = BFA_PORT_TOPOLOGY_NONE;
  2624. fcport->bbsc_op_state = BFA_FALSE;
  2625. }
  2626. /*
  2627. * Send port enable message to firmware.
  2628. */
  2629. static bfa_boolean_t
  2630. bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
  2631. {
  2632. struct bfi_fcport_enable_req_s *m;
  2633. /*
  2634. * Increment message tag before queue check, so that responses to old
  2635. * requests are discarded.
  2636. */
  2637. fcport->msgtag++;
  2638. /*
  2639. * check for room in queue to send request now
  2640. */
  2641. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2642. if (!m) {
  2643. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2644. &fcport->reqq_wait);
  2645. return BFA_FALSE;
  2646. }
  2647. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
  2648. bfa_fn_lpu(fcport->bfa));
  2649. m->nwwn = fcport->nwwn;
  2650. m->pwwn = fcport->pwwn;
  2651. m->port_cfg = fcport->cfg;
  2652. m->msgtag = fcport->msgtag;
  2653. m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
  2654. m->use_flash_cfg = fcport->use_flash_cfg;
  2655. bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
  2656. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
  2657. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
  2658. /*
  2659. * queue I/O message to firmware
  2660. */
  2661. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
  2662. return BFA_TRUE;
  2663. }
  2664. /*
  2665. * Send port disable message to firmware.
  2666. */
  2667. static bfa_boolean_t
  2668. bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
  2669. {
  2670. struct bfi_fcport_req_s *m;
  2671. /*
  2672. * Increment message tag before queue check, so that responses to old
  2673. * requests are discarded.
  2674. */
  2675. fcport->msgtag++;
  2676. /*
  2677. * check for room in queue to send request now
  2678. */
  2679. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2680. if (!m) {
  2681. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2682. &fcport->reqq_wait);
  2683. return BFA_FALSE;
  2684. }
  2685. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
  2686. bfa_fn_lpu(fcport->bfa));
  2687. m->msgtag = fcport->msgtag;
  2688. /*
  2689. * queue I/O message to firmware
  2690. */
  2691. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
  2692. return BFA_TRUE;
  2693. }
  2694. static void
  2695. bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
  2696. {
  2697. fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
  2698. fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
  2699. bfa_trc(fcport->bfa, fcport->pwwn);
  2700. bfa_trc(fcport->bfa, fcport->nwwn);
  2701. }
  2702. static void
  2703. bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
  2704. struct bfa_qos_stats_s *s)
  2705. {
  2706. u32 *dip = (u32 *) d;
  2707. __be32 *sip = (__be32 *) s;
  2708. int i;
  2709. /* Now swap the 32 bit fields */
  2710. for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
  2711. dip[i] = be32_to_cpu(sip[i]);
  2712. }
  2713. static void
  2714. bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
  2715. struct bfa_fcoe_stats_s *s)
  2716. {
  2717. u32 *dip = (u32 *) d;
  2718. __be32 *sip = (__be32 *) s;
  2719. int i;
  2720. for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
  2721. i = i + 2) {
  2722. #ifdef __BIG_ENDIAN
  2723. dip[i] = be32_to_cpu(sip[i]);
  2724. dip[i + 1] = be32_to_cpu(sip[i + 1]);
  2725. #else
  2726. dip[i] = be32_to_cpu(sip[i + 1]);
  2727. dip[i + 1] = be32_to_cpu(sip[i]);
  2728. #endif
  2729. }
  2730. }
  2731. static void
  2732. __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
  2733. {
  2734. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
  2735. struct bfa_cb_pending_q_s *cb;
  2736. struct list_head *qe, *qen;
  2737. union bfa_fcport_stats_u *ret;
  2738. if (complete) {
  2739. struct timeval tv;
  2740. if (fcport->stats_status == BFA_STATUS_OK)
  2741. do_gettimeofday(&tv);
  2742. list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
  2743. bfa_q_deq(&fcport->stats_pending_q, &qe);
  2744. cb = (struct bfa_cb_pending_q_s *)qe;
  2745. if (fcport->stats_status == BFA_STATUS_OK) {
  2746. ret = (union bfa_fcport_stats_u *)cb->data;
  2747. /* Swap FC QoS or FCoE stats */
  2748. if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
  2749. bfa_fcport_qos_stats_swap(&ret->fcqos,
  2750. &fcport->stats->fcqos);
  2751. else {
  2752. bfa_fcport_fcoe_stats_swap(&ret->fcoe,
  2753. &fcport->stats->fcoe);
  2754. ret->fcoe.secs_reset =
  2755. tv.tv_sec - fcport->stats_reset_time;
  2756. }
  2757. }
  2758. bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
  2759. fcport->stats_status);
  2760. }
  2761. fcport->stats_status = BFA_STATUS_OK;
  2762. } else {
  2763. INIT_LIST_HEAD(&fcport->stats_pending_q);
  2764. fcport->stats_status = BFA_STATUS_OK;
  2765. }
  2766. }
  2767. static void
  2768. bfa_fcport_stats_get_timeout(void *cbarg)
  2769. {
  2770. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2771. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2772. if (fcport->stats_qfull) {
  2773. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2774. fcport->stats_qfull = BFA_FALSE;
  2775. }
  2776. fcport->stats_status = BFA_STATUS_ETIMER;
  2777. __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
  2778. }
  2779. static void
  2780. bfa_fcport_send_stats_get(void *cbarg)
  2781. {
  2782. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2783. struct bfi_fcport_req_s *msg;
  2784. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2785. if (!msg) {
  2786. fcport->stats_qfull = BFA_TRUE;
  2787. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2788. bfa_fcport_send_stats_get, fcport);
  2789. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2790. &fcport->stats_reqq_wait);
  2791. return;
  2792. }
  2793. fcport->stats_qfull = BFA_FALSE;
  2794. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2795. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
  2796. bfa_fn_lpu(fcport->bfa));
  2797. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
  2798. }
  2799. static void
  2800. __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
  2801. {
  2802. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2803. struct bfa_cb_pending_q_s *cb;
  2804. struct list_head *qe, *qen;
  2805. if (complete) {
  2806. struct timeval tv;
  2807. /*
  2808. * re-initialize time stamp for stats reset
  2809. */
  2810. do_gettimeofday(&tv);
  2811. fcport->stats_reset_time = tv.tv_sec;
  2812. list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
  2813. bfa_q_deq(&fcport->statsclr_pending_q, &qe);
  2814. cb = (struct bfa_cb_pending_q_s *)qe;
  2815. bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
  2816. fcport->stats_status);
  2817. }
  2818. fcport->stats_status = BFA_STATUS_OK;
  2819. } else {
  2820. INIT_LIST_HEAD(&fcport->statsclr_pending_q);
  2821. fcport->stats_status = BFA_STATUS_OK;
  2822. }
  2823. }
  2824. static void
  2825. bfa_fcport_stats_clr_timeout(void *cbarg)
  2826. {
  2827. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2828. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2829. if (fcport->stats_qfull) {
  2830. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2831. fcport->stats_qfull = BFA_FALSE;
  2832. }
  2833. fcport->stats_status = BFA_STATUS_ETIMER;
  2834. __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
  2835. }
  2836. static void
  2837. bfa_fcport_send_stats_clear(void *cbarg)
  2838. {
  2839. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2840. struct bfi_fcport_req_s *msg;
  2841. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2842. if (!msg) {
  2843. fcport->stats_qfull = BFA_TRUE;
  2844. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2845. bfa_fcport_send_stats_clear, fcport);
  2846. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2847. &fcport->stats_reqq_wait);
  2848. return;
  2849. }
  2850. fcport->stats_qfull = BFA_FALSE;
  2851. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2852. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
  2853. bfa_fn_lpu(fcport->bfa));
  2854. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
  2855. }
  2856. /*
  2857. * Handle trunk SCN event from firmware.
  2858. */
  2859. static void
  2860. bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
  2861. {
  2862. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2863. struct bfi_fcport_trunk_link_s *tlink;
  2864. struct bfa_trunk_link_attr_s *lattr;
  2865. enum bfa_trunk_state state_prev;
  2866. int i;
  2867. int link_bm = 0;
  2868. bfa_trc(fcport->bfa, fcport->cfg.trunked);
  2869. WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
  2870. scn->trunk_state != BFA_TRUNK_OFFLINE);
  2871. bfa_trc(fcport->bfa, trunk->attr.state);
  2872. bfa_trc(fcport->bfa, scn->trunk_state);
  2873. bfa_trc(fcport->bfa, scn->trunk_speed);
  2874. /*
  2875. * Save off new state for trunk attribute query
  2876. */
  2877. state_prev = trunk->attr.state;
  2878. if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
  2879. trunk->attr.state = scn->trunk_state;
  2880. trunk->attr.speed = scn->trunk_speed;
  2881. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2882. lattr = &trunk->attr.link_attr[i];
  2883. tlink = &scn->tlink[i];
  2884. lattr->link_state = tlink->state;
  2885. lattr->trunk_wwn = tlink->trunk_wwn;
  2886. lattr->fctl = tlink->fctl;
  2887. lattr->speed = tlink->speed;
  2888. lattr->deskew = be32_to_cpu(tlink->deskew);
  2889. if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
  2890. fcport->speed = tlink->speed;
  2891. fcport->topology = BFA_PORT_TOPOLOGY_P2P;
  2892. link_bm |= 1 << i;
  2893. }
  2894. bfa_trc(fcport->bfa, lattr->link_state);
  2895. bfa_trc(fcport->bfa, lattr->trunk_wwn);
  2896. bfa_trc(fcport->bfa, lattr->fctl);
  2897. bfa_trc(fcport->bfa, lattr->speed);
  2898. bfa_trc(fcport->bfa, lattr->deskew);
  2899. }
  2900. switch (link_bm) {
  2901. case 3:
  2902. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2903. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
  2904. break;
  2905. case 2:
  2906. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2907. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
  2908. break;
  2909. case 1:
  2910. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2911. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
  2912. break;
  2913. default:
  2914. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2915. BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
  2916. }
  2917. /*
  2918. * Notify upper layers if trunk state changed.
  2919. */
  2920. if ((state_prev != trunk->attr.state) ||
  2921. (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
  2922. bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
  2923. BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
  2924. }
  2925. }
  2926. static void
  2927. bfa_trunk_iocdisable(struct bfa_s *bfa)
  2928. {
  2929. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2930. int i = 0;
  2931. /*
  2932. * In trunked mode, notify upper layers that link is down
  2933. */
  2934. if (fcport->cfg.trunked) {
  2935. if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
  2936. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
  2937. fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
  2938. fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
  2939. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2940. fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
  2941. fcport->trunk.attr.link_attr[i].fctl =
  2942. BFA_TRUNK_LINK_FCTL_NORMAL;
  2943. fcport->trunk.attr.link_attr[i].link_state =
  2944. BFA_TRUNK_LINK_STATE_DN_LINKDN;
  2945. fcport->trunk.attr.link_attr[i].speed =
  2946. BFA_PORT_SPEED_UNKNOWN;
  2947. fcport->trunk.attr.link_attr[i].deskew = 0;
  2948. }
  2949. }
  2950. }
  2951. /*
  2952. * Called to initialize port attributes
  2953. */
  2954. void
  2955. bfa_fcport_init(struct bfa_s *bfa)
  2956. {
  2957. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2958. /*
  2959. * Initialize port attributes from IOC hardware data.
  2960. */
  2961. bfa_fcport_set_wwns(fcport);
  2962. if (fcport->cfg.maxfrsize == 0)
  2963. fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  2964. fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  2965. fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  2966. if (bfa_fcport_is_pbcdisabled(bfa))
  2967. bfa->modules.port.pbc_disabled = BFA_TRUE;
  2968. WARN_ON(!fcport->cfg.maxfrsize);
  2969. WARN_ON(!fcport->cfg.rx_bbcredit);
  2970. WARN_ON(!fcport->speed_sup);
  2971. }
  2972. /*
  2973. * Firmware message handler.
  2974. */
  2975. void
  2976. bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  2977. {
  2978. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2979. union bfi_fcport_i2h_msg_u i2hmsg;
  2980. i2hmsg.msg = msg;
  2981. fcport->event_arg.i2hmsg = i2hmsg;
  2982. bfa_trc(bfa, msg->mhdr.msg_id);
  2983. bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
  2984. switch (msg->mhdr.msg_id) {
  2985. case BFI_FCPORT_I2H_ENABLE_RSP:
  2986. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
  2987. if (fcport->use_flash_cfg) {
  2988. fcport->cfg = i2hmsg.penable_rsp->port_cfg;
  2989. fcport->cfg.maxfrsize =
  2990. cpu_to_be16(fcport->cfg.maxfrsize);
  2991. fcport->cfg.path_tov =
  2992. cpu_to_be16(fcport->cfg.path_tov);
  2993. fcport->cfg.q_depth =
  2994. cpu_to_be16(fcport->cfg.q_depth);
  2995. if (fcport->cfg.trunked)
  2996. fcport->trunk.attr.state =
  2997. BFA_TRUNK_OFFLINE;
  2998. else
  2999. fcport->trunk.attr.state =
  3000. BFA_TRUNK_DISABLED;
  3001. fcport->use_flash_cfg = BFA_FALSE;
  3002. }
  3003. if (fcport->cfg.qos_enabled)
  3004. fcport->qos_attr.state = BFA_QOS_OFFLINE;
  3005. else
  3006. fcport->qos_attr.state = BFA_QOS_DISABLED;
  3007. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  3008. }
  3009. break;
  3010. case BFI_FCPORT_I2H_DISABLE_RSP:
  3011. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  3012. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  3013. break;
  3014. case BFI_FCPORT_I2H_EVENT:
  3015. if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
  3016. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
  3017. else
  3018. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
  3019. break;
  3020. case BFI_FCPORT_I2H_TRUNK_SCN:
  3021. bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
  3022. break;
  3023. case BFI_FCPORT_I2H_STATS_GET_RSP:
  3024. /*
  3025. * check for timer pop before processing the rsp
  3026. */
  3027. if (list_empty(&fcport->stats_pending_q) ||
  3028. (fcport->stats_status == BFA_STATUS_ETIMER))
  3029. break;
  3030. bfa_timer_stop(&fcport->timer);
  3031. fcport->stats_status = i2hmsg.pstatsget_rsp->status;
  3032. __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
  3033. break;
  3034. case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
  3035. /*
  3036. * check for timer pop before processing the rsp
  3037. */
  3038. if (list_empty(&fcport->statsclr_pending_q) ||
  3039. (fcport->stats_status == BFA_STATUS_ETIMER))
  3040. break;
  3041. bfa_timer_stop(&fcport->timer);
  3042. fcport->stats_status = BFA_STATUS_OK;
  3043. __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
  3044. break;
  3045. case BFI_FCPORT_I2H_ENABLE_AEN:
  3046. bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
  3047. break;
  3048. case BFI_FCPORT_I2H_DISABLE_AEN:
  3049. bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
  3050. break;
  3051. default:
  3052. WARN_ON(1);
  3053. break;
  3054. }
  3055. }
  3056. /*
  3057. * Registered callback for port events.
  3058. */
  3059. void
  3060. bfa_fcport_event_register(struct bfa_s *bfa,
  3061. void (*cbfn) (void *cbarg,
  3062. enum bfa_port_linkstate event),
  3063. void *cbarg)
  3064. {
  3065. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3066. fcport->event_cbfn = cbfn;
  3067. fcport->event_cbarg = cbarg;
  3068. }
  3069. bfa_status_t
  3070. bfa_fcport_enable(struct bfa_s *bfa)
  3071. {
  3072. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3073. if (bfa_fcport_is_pbcdisabled(bfa))
  3074. return BFA_STATUS_PBC;
  3075. if (bfa_ioc_is_disabled(&bfa->ioc))
  3076. return BFA_STATUS_IOC_DISABLED;
  3077. if (fcport->diag_busy)
  3078. return BFA_STATUS_DIAG_BUSY;
  3079. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
  3080. return BFA_STATUS_OK;
  3081. }
  3082. bfa_status_t
  3083. bfa_fcport_disable(struct bfa_s *bfa)
  3084. {
  3085. if (bfa_fcport_is_pbcdisabled(bfa))
  3086. return BFA_STATUS_PBC;
  3087. if (bfa_ioc_is_disabled(&bfa->ioc))
  3088. return BFA_STATUS_IOC_DISABLED;
  3089. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
  3090. return BFA_STATUS_OK;
  3091. }
  3092. /* If PBC is disabled on port, return error */
  3093. bfa_status_t
  3094. bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
  3095. {
  3096. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3097. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  3098. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  3099. if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
  3100. bfa_trc(bfa, fcport->pwwn);
  3101. return BFA_STATUS_PBC;
  3102. }
  3103. return BFA_STATUS_OK;
  3104. }
  3105. /*
  3106. * Configure port speed.
  3107. */
  3108. bfa_status_t
  3109. bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
  3110. {
  3111. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3112. bfa_trc(bfa, speed);
  3113. if (fcport->cfg.trunked == BFA_TRUE)
  3114. return BFA_STATUS_TRUNK_ENABLED;
  3115. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  3116. (speed == BFA_PORT_SPEED_16GBPS))
  3117. return BFA_STATUS_UNSUPP_SPEED;
  3118. if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
  3119. bfa_trc(bfa, fcport->speed_sup);
  3120. return BFA_STATUS_UNSUPP_SPEED;
  3121. }
  3122. /* Port speed entered needs to be checked */
  3123. if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
  3124. /* For CT2, 1G is not supported */
  3125. if ((speed == BFA_PORT_SPEED_1GBPS) &&
  3126. (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
  3127. return BFA_STATUS_UNSUPP_SPEED;
  3128. /* Already checked for Auto Speed and Max Speed supp */
  3129. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  3130. speed == BFA_PORT_SPEED_2GBPS ||
  3131. speed == BFA_PORT_SPEED_4GBPS ||
  3132. speed == BFA_PORT_SPEED_8GBPS ||
  3133. speed == BFA_PORT_SPEED_16GBPS ||
  3134. speed == BFA_PORT_SPEED_AUTO))
  3135. return BFA_STATUS_UNSUPP_SPEED;
  3136. } else {
  3137. if (speed != BFA_PORT_SPEED_10GBPS)
  3138. return BFA_STATUS_UNSUPP_SPEED;
  3139. }
  3140. fcport->cfg.speed = speed;
  3141. return BFA_STATUS_OK;
  3142. }
  3143. /*
  3144. * Get current speed.
  3145. */
  3146. enum bfa_port_speed
  3147. bfa_fcport_get_speed(struct bfa_s *bfa)
  3148. {
  3149. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3150. return fcport->speed;
  3151. }
  3152. /*
  3153. * Configure port topology.
  3154. */
  3155. bfa_status_t
  3156. bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
  3157. {
  3158. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3159. bfa_trc(bfa, topology);
  3160. bfa_trc(bfa, fcport->cfg.topology);
  3161. switch (topology) {
  3162. case BFA_PORT_TOPOLOGY_P2P:
  3163. break;
  3164. case BFA_PORT_TOPOLOGY_LOOP:
  3165. if ((bfa_fcport_is_qos_enabled(bfa) != BFA_FALSE) ||
  3166. (fcport->qos_attr.state != BFA_QOS_DISABLED))
  3167. return BFA_STATUS_ERROR_QOS_ENABLED;
  3168. if (fcport->cfg.ratelimit != BFA_FALSE)
  3169. return BFA_STATUS_ERROR_TRL_ENABLED;
  3170. if ((bfa_fcport_is_trunk_enabled(bfa) != BFA_FALSE) ||
  3171. (fcport->trunk.attr.state != BFA_TRUNK_DISABLED))
  3172. return BFA_STATUS_ERROR_TRUNK_ENABLED;
  3173. if ((bfa_fcport_get_speed(bfa) == BFA_PORT_SPEED_16GBPS) ||
  3174. (fcport->cfg.speed == BFA_PORT_SPEED_16GBPS))
  3175. return BFA_STATUS_UNSUPP_SPEED;
  3176. if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type))
  3177. return BFA_STATUS_LOOP_UNSUPP_MEZZ;
  3178. if (bfa_fcport_is_dport(bfa) != BFA_FALSE)
  3179. return BFA_STATUS_DPORT_ERR;
  3180. break;
  3181. case BFA_PORT_TOPOLOGY_AUTO:
  3182. break;
  3183. default:
  3184. return BFA_STATUS_EINVAL;
  3185. }
  3186. fcport->cfg.topology = topology;
  3187. return BFA_STATUS_OK;
  3188. }
  3189. /*
  3190. * Get current topology.
  3191. */
  3192. enum bfa_port_topology
  3193. bfa_fcport_get_topology(struct bfa_s *bfa)
  3194. {
  3195. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3196. return fcport->topology;
  3197. }
  3198. /**
  3199. * Get config topology.
  3200. */
  3201. enum bfa_port_topology
  3202. bfa_fcport_get_cfg_topology(struct bfa_s *bfa)
  3203. {
  3204. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3205. return fcport->cfg.topology;
  3206. }
  3207. bfa_status_t
  3208. bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  3209. {
  3210. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3211. bfa_trc(bfa, alpa);
  3212. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3213. bfa_trc(bfa, fcport->cfg.hardalpa);
  3214. fcport->cfg.cfg_hardalpa = BFA_TRUE;
  3215. fcport->cfg.hardalpa = alpa;
  3216. return BFA_STATUS_OK;
  3217. }
  3218. bfa_status_t
  3219. bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
  3220. {
  3221. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3222. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3223. bfa_trc(bfa, fcport->cfg.hardalpa);
  3224. fcport->cfg.cfg_hardalpa = BFA_FALSE;
  3225. return BFA_STATUS_OK;
  3226. }
  3227. bfa_boolean_t
  3228. bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  3229. {
  3230. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3231. *alpa = fcport->cfg.hardalpa;
  3232. return fcport->cfg.cfg_hardalpa;
  3233. }
  3234. u8
  3235. bfa_fcport_get_myalpa(struct bfa_s *bfa)
  3236. {
  3237. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3238. return fcport->myalpa;
  3239. }
  3240. bfa_status_t
  3241. bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  3242. {
  3243. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3244. bfa_trc(bfa, maxfrsize);
  3245. bfa_trc(bfa, fcport->cfg.maxfrsize);
  3246. /* with in range */
  3247. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  3248. return BFA_STATUS_INVLD_DFSZ;
  3249. /* power of 2, if not the max frame size of 2112 */
  3250. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  3251. return BFA_STATUS_INVLD_DFSZ;
  3252. fcport->cfg.maxfrsize = maxfrsize;
  3253. return BFA_STATUS_OK;
  3254. }
  3255. u16
  3256. bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
  3257. {
  3258. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3259. return fcport->cfg.maxfrsize;
  3260. }
  3261. u8
  3262. bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
  3263. {
  3264. if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP)
  3265. return (BFA_FCPORT_MOD(bfa))->cfg.rx_bbcredit;
  3266. else
  3267. return 0;
  3268. }
  3269. void
  3270. bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
  3271. {
  3272. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3273. fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
  3274. fcport->cfg.bb_scn = bb_scn;
  3275. if (bb_scn)
  3276. fcport->bbsc_op_state = BFA_TRUE;
  3277. }
  3278. /*
  3279. * Get port attributes.
  3280. */
  3281. wwn_t
  3282. bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  3283. {
  3284. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3285. if (node)
  3286. return fcport->nwwn;
  3287. else
  3288. return fcport->pwwn;
  3289. }
  3290. void
  3291. bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
  3292. {
  3293. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3294. memset(attr, 0, sizeof(struct bfa_port_attr_s));
  3295. attr->nwwn = fcport->nwwn;
  3296. attr->pwwn = fcport->pwwn;
  3297. attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
  3298. attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
  3299. memcpy(&attr->pport_cfg, &fcport->cfg,
  3300. sizeof(struct bfa_port_cfg_s));
  3301. /* speed attributes */
  3302. attr->pport_cfg.speed = fcport->cfg.speed;
  3303. attr->speed_supported = fcport->speed_sup;
  3304. attr->speed = fcport->speed;
  3305. attr->cos_supported = FC_CLASS_3;
  3306. /* topology attributes */
  3307. attr->pport_cfg.topology = fcport->cfg.topology;
  3308. attr->topology = fcport->topology;
  3309. attr->pport_cfg.trunked = fcport->cfg.trunked;
  3310. /* beacon attributes */
  3311. attr->beacon = fcport->beacon;
  3312. attr->link_e2e_beacon = fcport->link_e2e_beacon;
  3313. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  3314. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  3315. attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
  3316. attr->bbsc_op_status = fcport->bbsc_op_state;
  3317. /* PBC Disabled State */
  3318. if (bfa_fcport_is_pbcdisabled(bfa))
  3319. attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
  3320. else {
  3321. if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
  3322. attr->port_state = BFA_PORT_ST_IOCDIS;
  3323. else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
  3324. attr->port_state = BFA_PORT_ST_FWMISMATCH;
  3325. }
  3326. /* FCoE vlan */
  3327. attr->fcoe_vlan = fcport->fcoe_vlan;
  3328. }
  3329. #define BFA_FCPORT_STATS_TOV 1000
  3330. /*
  3331. * Fetch port statistics (FCQoS or FCoE).
  3332. */
  3333. bfa_status_t
  3334. bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
  3335. {
  3336. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3337. if (bfa_ioc_is_disabled(&bfa->ioc))
  3338. return BFA_STATUS_IOC_DISABLED;
  3339. if (!list_empty(&fcport->statsclr_pending_q))
  3340. return BFA_STATUS_DEVBUSY;
  3341. if (list_empty(&fcport->stats_pending_q)) {
  3342. list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
  3343. bfa_fcport_send_stats_get(fcport);
  3344. bfa_timer_start(bfa, &fcport->timer,
  3345. bfa_fcport_stats_get_timeout,
  3346. fcport, BFA_FCPORT_STATS_TOV);
  3347. } else
  3348. list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
  3349. return BFA_STATUS_OK;
  3350. }
  3351. /*
  3352. * Reset port statistics (FCQoS or FCoE).
  3353. */
  3354. bfa_status_t
  3355. bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
  3356. {
  3357. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3358. if (!list_empty(&fcport->stats_pending_q))
  3359. return BFA_STATUS_DEVBUSY;
  3360. if (list_empty(&fcport->statsclr_pending_q)) {
  3361. list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
  3362. bfa_fcport_send_stats_clear(fcport);
  3363. bfa_timer_start(bfa, &fcport->timer,
  3364. bfa_fcport_stats_clr_timeout,
  3365. fcport, BFA_FCPORT_STATS_TOV);
  3366. } else
  3367. list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
  3368. return BFA_STATUS_OK;
  3369. }
  3370. /*
  3371. * Fetch port attributes.
  3372. */
  3373. bfa_boolean_t
  3374. bfa_fcport_is_disabled(struct bfa_s *bfa)
  3375. {
  3376. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3377. return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3378. BFA_PORT_ST_DISABLED;
  3379. }
  3380. bfa_boolean_t
  3381. bfa_fcport_is_dport(struct bfa_s *bfa)
  3382. {
  3383. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3384. return (bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3385. BFA_PORT_ST_DPORT);
  3386. }
  3387. bfa_boolean_t
  3388. bfa_fcport_is_ratelim(struct bfa_s *bfa)
  3389. {
  3390. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3391. return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
  3392. }
  3393. /*
  3394. * Enable/Disable FAA feature in port config
  3395. */
  3396. void
  3397. bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
  3398. {
  3399. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3400. bfa_trc(bfa, state);
  3401. fcport->cfg.faa_state = state;
  3402. }
  3403. /*
  3404. * Get default minimum ratelim speed
  3405. */
  3406. enum bfa_port_speed
  3407. bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
  3408. {
  3409. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3410. bfa_trc(bfa, fcport->cfg.trl_def_speed);
  3411. return fcport->cfg.trl_def_speed;
  3412. }
  3413. void
  3414. bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
  3415. bfa_boolean_t link_e2e_beacon)
  3416. {
  3417. struct bfa_s *bfa = dev;
  3418. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3419. bfa_trc(bfa, beacon);
  3420. bfa_trc(bfa, link_e2e_beacon);
  3421. bfa_trc(bfa, fcport->beacon);
  3422. bfa_trc(bfa, fcport->link_e2e_beacon);
  3423. fcport->beacon = beacon;
  3424. fcport->link_e2e_beacon = link_e2e_beacon;
  3425. }
  3426. bfa_boolean_t
  3427. bfa_fcport_is_linkup(struct bfa_s *bfa)
  3428. {
  3429. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3430. return (!fcport->cfg.trunked &&
  3431. bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
  3432. (fcport->cfg.trunked &&
  3433. fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
  3434. }
  3435. bfa_boolean_t
  3436. bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
  3437. {
  3438. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3439. return fcport->cfg.qos_enabled;
  3440. }
  3441. bfa_boolean_t
  3442. bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
  3443. {
  3444. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3445. return fcport->cfg.trunked;
  3446. }
  3447. void
  3448. bfa_fcport_dportenable(struct bfa_s *bfa)
  3449. {
  3450. /*
  3451. * Assume caller check for port is in disable state
  3452. */
  3453. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTENABLE);
  3454. bfa_port_set_dportenabled(&bfa->modules.port, BFA_TRUE);
  3455. }
  3456. void
  3457. bfa_fcport_dportdisable(struct bfa_s *bfa)
  3458. {
  3459. /*
  3460. * Assume caller check for port is in disable state
  3461. */
  3462. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTDISABLE);
  3463. bfa_port_set_dportenabled(&bfa->modules.port, BFA_FALSE);
  3464. }
  3465. /*
  3466. * Rport State machine functions
  3467. */
  3468. /*
  3469. * Beginning state, only online event expected.
  3470. */
  3471. static void
  3472. bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3473. {
  3474. bfa_trc(rp->bfa, rp->rport_tag);
  3475. bfa_trc(rp->bfa, event);
  3476. switch (event) {
  3477. case BFA_RPORT_SM_CREATE:
  3478. bfa_stats(rp, sm_un_cr);
  3479. bfa_sm_set_state(rp, bfa_rport_sm_created);
  3480. break;
  3481. default:
  3482. bfa_stats(rp, sm_un_unexp);
  3483. bfa_sm_fault(rp->bfa, event);
  3484. }
  3485. }
  3486. static void
  3487. bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3488. {
  3489. bfa_trc(rp->bfa, rp->rport_tag);
  3490. bfa_trc(rp->bfa, event);
  3491. switch (event) {
  3492. case BFA_RPORT_SM_ONLINE:
  3493. bfa_stats(rp, sm_cr_on);
  3494. if (bfa_rport_send_fwcreate(rp))
  3495. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3496. else
  3497. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3498. break;
  3499. case BFA_RPORT_SM_DELETE:
  3500. bfa_stats(rp, sm_cr_del);
  3501. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3502. bfa_rport_free(rp);
  3503. break;
  3504. case BFA_RPORT_SM_HWFAIL:
  3505. bfa_stats(rp, sm_cr_hwf);
  3506. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3507. break;
  3508. default:
  3509. bfa_stats(rp, sm_cr_unexp);
  3510. bfa_sm_fault(rp->bfa, event);
  3511. }
  3512. }
  3513. /*
  3514. * Waiting for rport create response from firmware.
  3515. */
  3516. static void
  3517. bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3518. {
  3519. bfa_trc(rp->bfa, rp->rport_tag);
  3520. bfa_trc(rp->bfa, event);
  3521. switch (event) {
  3522. case BFA_RPORT_SM_FWRSP:
  3523. bfa_stats(rp, sm_fwc_rsp);
  3524. bfa_sm_set_state(rp, bfa_rport_sm_online);
  3525. bfa_rport_online_cb(rp);
  3526. break;
  3527. case BFA_RPORT_SM_DELETE:
  3528. bfa_stats(rp, sm_fwc_del);
  3529. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3530. break;
  3531. case BFA_RPORT_SM_OFFLINE:
  3532. bfa_stats(rp, sm_fwc_off);
  3533. bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
  3534. break;
  3535. case BFA_RPORT_SM_HWFAIL:
  3536. bfa_stats(rp, sm_fwc_hwf);
  3537. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3538. break;
  3539. default:
  3540. bfa_stats(rp, sm_fwc_unexp);
  3541. bfa_sm_fault(rp->bfa, event);
  3542. }
  3543. }
  3544. /*
  3545. * Request queue is full, awaiting queue resume to send create request.
  3546. */
  3547. static void
  3548. bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3549. {
  3550. bfa_trc(rp->bfa, rp->rport_tag);
  3551. bfa_trc(rp->bfa, event);
  3552. switch (event) {
  3553. case BFA_RPORT_SM_QRESUME:
  3554. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3555. bfa_rport_send_fwcreate(rp);
  3556. break;
  3557. case BFA_RPORT_SM_DELETE:
  3558. bfa_stats(rp, sm_fwc_del);
  3559. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3560. bfa_reqq_wcancel(&rp->reqq_wait);
  3561. bfa_rport_free(rp);
  3562. break;
  3563. case BFA_RPORT_SM_OFFLINE:
  3564. bfa_stats(rp, sm_fwc_off);
  3565. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3566. bfa_reqq_wcancel(&rp->reqq_wait);
  3567. bfa_rport_offline_cb(rp);
  3568. break;
  3569. case BFA_RPORT_SM_HWFAIL:
  3570. bfa_stats(rp, sm_fwc_hwf);
  3571. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3572. bfa_reqq_wcancel(&rp->reqq_wait);
  3573. break;
  3574. default:
  3575. bfa_stats(rp, sm_fwc_unexp);
  3576. bfa_sm_fault(rp->bfa, event);
  3577. }
  3578. }
  3579. /*
  3580. * Online state - normal parking state.
  3581. */
  3582. static void
  3583. bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3584. {
  3585. struct bfi_rport_qos_scn_s *qos_scn;
  3586. bfa_trc(rp->bfa, rp->rport_tag);
  3587. bfa_trc(rp->bfa, event);
  3588. switch (event) {
  3589. case BFA_RPORT_SM_OFFLINE:
  3590. bfa_stats(rp, sm_on_off);
  3591. if (bfa_rport_send_fwdelete(rp))
  3592. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3593. else
  3594. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3595. break;
  3596. case BFA_RPORT_SM_DELETE:
  3597. bfa_stats(rp, sm_on_del);
  3598. if (bfa_rport_send_fwdelete(rp))
  3599. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3600. else
  3601. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3602. break;
  3603. case BFA_RPORT_SM_HWFAIL:
  3604. bfa_stats(rp, sm_on_hwf);
  3605. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3606. break;
  3607. case BFA_RPORT_SM_SET_SPEED:
  3608. bfa_rport_send_fwspeed(rp);
  3609. break;
  3610. case BFA_RPORT_SM_QOS_SCN:
  3611. qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
  3612. rp->qos_attr = qos_scn->new_qos_attr;
  3613. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
  3614. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
  3615. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
  3616. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
  3617. qos_scn->old_qos_attr.qos_flow_id =
  3618. be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
  3619. qos_scn->new_qos_attr.qos_flow_id =
  3620. be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
  3621. if (qos_scn->old_qos_attr.qos_flow_id !=
  3622. qos_scn->new_qos_attr.qos_flow_id)
  3623. bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
  3624. qos_scn->old_qos_attr,
  3625. qos_scn->new_qos_attr);
  3626. if (qos_scn->old_qos_attr.qos_priority !=
  3627. qos_scn->new_qos_attr.qos_priority)
  3628. bfa_cb_rport_qos_scn_prio(rp->rport_drv,
  3629. qos_scn->old_qos_attr,
  3630. qos_scn->new_qos_attr);
  3631. break;
  3632. default:
  3633. bfa_stats(rp, sm_on_unexp);
  3634. bfa_sm_fault(rp->bfa, event);
  3635. }
  3636. }
  3637. /*
  3638. * Firmware rport is being deleted - awaiting f/w response.
  3639. */
  3640. static void
  3641. bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3642. {
  3643. bfa_trc(rp->bfa, rp->rport_tag);
  3644. bfa_trc(rp->bfa, event);
  3645. switch (event) {
  3646. case BFA_RPORT_SM_FWRSP:
  3647. bfa_stats(rp, sm_fwd_rsp);
  3648. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3649. bfa_rport_offline_cb(rp);
  3650. break;
  3651. case BFA_RPORT_SM_DELETE:
  3652. bfa_stats(rp, sm_fwd_del);
  3653. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3654. break;
  3655. case BFA_RPORT_SM_HWFAIL:
  3656. bfa_stats(rp, sm_fwd_hwf);
  3657. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3658. bfa_rport_offline_cb(rp);
  3659. break;
  3660. default:
  3661. bfa_stats(rp, sm_fwd_unexp);
  3662. bfa_sm_fault(rp->bfa, event);
  3663. }
  3664. }
  3665. static void
  3666. bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3667. {
  3668. bfa_trc(rp->bfa, rp->rport_tag);
  3669. bfa_trc(rp->bfa, event);
  3670. switch (event) {
  3671. case BFA_RPORT_SM_QRESUME:
  3672. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3673. bfa_rport_send_fwdelete(rp);
  3674. break;
  3675. case BFA_RPORT_SM_DELETE:
  3676. bfa_stats(rp, sm_fwd_del);
  3677. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3678. break;
  3679. case BFA_RPORT_SM_HWFAIL:
  3680. bfa_stats(rp, sm_fwd_hwf);
  3681. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3682. bfa_reqq_wcancel(&rp->reqq_wait);
  3683. bfa_rport_offline_cb(rp);
  3684. break;
  3685. default:
  3686. bfa_stats(rp, sm_fwd_unexp);
  3687. bfa_sm_fault(rp->bfa, event);
  3688. }
  3689. }
  3690. /*
  3691. * Offline state.
  3692. */
  3693. static void
  3694. bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3695. {
  3696. bfa_trc(rp->bfa, rp->rport_tag);
  3697. bfa_trc(rp->bfa, event);
  3698. switch (event) {
  3699. case BFA_RPORT_SM_DELETE:
  3700. bfa_stats(rp, sm_off_del);
  3701. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3702. bfa_rport_free(rp);
  3703. break;
  3704. case BFA_RPORT_SM_ONLINE:
  3705. bfa_stats(rp, sm_off_on);
  3706. if (bfa_rport_send_fwcreate(rp))
  3707. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3708. else
  3709. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3710. break;
  3711. case BFA_RPORT_SM_HWFAIL:
  3712. bfa_stats(rp, sm_off_hwf);
  3713. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3714. break;
  3715. case BFA_RPORT_SM_OFFLINE:
  3716. bfa_rport_offline_cb(rp);
  3717. break;
  3718. default:
  3719. bfa_stats(rp, sm_off_unexp);
  3720. bfa_sm_fault(rp->bfa, event);
  3721. }
  3722. }
  3723. /*
  3724. * Rport is deleted, waiting for firmware response to delete.
  3725. */
  3726. static void
  3727. bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3728. {
  3729. bfa_trc(rp->bfa, rp->rport_tag);
  3730. bfa_trc(rp->bfa, event);
  3731. switch (event) {
  3732. case BFA_RPORT_SM_FWRSP:
  3733. bfa_stats(rp, sm_del_fwrsp);
  3734. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3735. bfa_rport_free(rp);
  3736. break;
  3737. case BFA_RPORT_SM_HWFAIL:
  3738. bfa_stats(rp, sm_del_hwf);
  3739. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3740. bfa_rport_free(rp);
  3741. break;
  3742. default:
  3743. bfa_sm_fault(rp->bfa, event);
  3744. }
  3745. }
  3746. static void
  3747. bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3748. {
  3749. bfa_trc(rp->bfa, rp->rport_tag);
  3750. bfa_trc(rp->bfa, event);
  3751. switch (event) {
  3752. case BFA_RPORT_SM_QRESUME:
  3753. bfa_stats(rp, sm_del_fwrsp);
  3754. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3755. bfa_rport_send_fwdelete(rp);
  3756. break;
  3757. case BFA_RPORT_SM_HWFAIL:
  3758. bfa_stats(rp, sm_del_hwf);
  3759. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3760. bfa_reqq_wcancel(&rp->reqq_wait);
  3761. bfa_rport_free(rp);
  3762. break;
  3763. default:
  3764. bfa_sm_fault(rp->bfa, event);
  3765. }
  3766. }
  3767. /*
  3768. * Waiting for rport create response from firmware. A delete is pending.
  3769. */
  3770. static void
  3771. bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  3772. enum bfa_rport_event event)
  3773. {
  3774. bfa_trc(rp->bfa, rp->rport_tag);
  3775. bfa_trc(rp->bfa, event);
  3776. switch (event) {
  3777. case BFA_RPORT_SM_FWRSP:
  3778. bfa_stats(rp, sm_delp_fwrsp);
  3779. if (bfa_rport_send_fwdelete(rp))
  3780. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3781. else
  3782. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3783. break;
  3784. case BFA_RPORT_SM_HWFAIL:
  3785. bfa_stats(rp, sm_delp_hwf);
  3786. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3787. bfa_rport_free(rp);
  3788. break;
  3789. default:
  3790. bfa_stats(rp, sm_delp_unexp);
  3791. bfa_sm_fault(rp->bfa, event);
  3792. }
  3793. }
  3794. /*
  3795. * Waiting for rport create response from firmware. Rport offline is pending.
  3796. */
  3797. static void
  3798. bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  3799. enum bfa_rport_event event)
  3800. {
  3801. bfa_trc(rp->bfa, rp->rport_tag);
  3802. bfa_trc(rp->bfa, event);
  3803. switch (event) {
  3804. case BFA_RPORT_SM_FWRSP:
  3805. bfa_stats(rp, sm_offp_fwrsp);
  3806. if (bfa_rport_send_fwdelete(rp))
  3807. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3808. else
  3809. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3810. break;
  3811. case BFA_RPORT_SM_DELETE:
  3812. bfa_stats(rp, sm_offp_del);
  3813. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3814. break;
  3815. case BFA_RPORT_SM_HWFAIL:
  3816. bfa_stats(rp, sm_offp_hwf);
  3817. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3818. bfa_rport_offline_cb(rp);
  3819. break;
  3820. default:
  3821. bfa_stats(rp, sm_offp_unexp);
  3822. bfa_sm_fault(rp->bfa, event);
  3823. }
  3824. }
  3825. /*
  3826. * IOC h/w failed.
  3827. */
  3828. static void
  3829. bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3830. {
  3831. bfa_trc(rp->bfa, rp->rport_tag);
  3832. bfa_trc(rp->bfa, event);
  3833. switch (event) {
  3834. case BFA_RPORT_SM_OFFLINE:
  3835. bfa_stats(rp, sm_iocd_off);
  3836. bfa_rport_offline_cb(rp);
  3837. break;
  3838. case BFA_RPORT_SM_DELETE:
  3839. bfa_stats(rp, sm_iocd_del);
  3840. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3841. bfa_rport_free(rp);
  3842. break;
  3843. case BFA_RPORT_SM_ONLINE:
  3844. bfa_stats(rp, sm_iocd_on);
  3845. if (bfa_rport_send_fwcreate(rp))
  3846. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3847. else
  3848. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3849. break;
  3850. case BFA_RPORT_SM_HWFAIL:
  3851. break;
  3852. default:
  3853. bfa_stats(rp, sm_iocd_unexp);
  3854. bfa_sm_fault(rp->bfa, event);
  3855. }
  3856. }
  3857. /*
  3858. * bfa_rport_private BFA rport private functions
  3859. */
  3860. static void
  3861. __bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
  3862. {
  3863. struct bfa_rport_s *rp = cbarg;
  3864. if (complete)
  3865. bfa_cb_rport_online(rp->rport_drv);
  3866. }
  3867. static void
  3868. __bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
  3869. {
  3870. struct bfa_rport_s *rp = cbarg;
  3871. if (complete)
  3872. bfa_cb_rport_offline(rp->rport_drv);
  3873. }
  3874. static void
  3875. bfa_rport_qresume(void *cbarg)
  3876. {
  3877. struct bfa_rport_s *rp = cbarg;
  3878. bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
  3879. }
  3880. static void
  3881. bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  3882. struct bfa_s *bfa)
  3883. {
  3884. struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
  3885. if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
  3886. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  3887. /* kva memory */
  3888. bfa_mem_kva_setup(minfo, rport_kva,
  3889. cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
  3890. }
  3891. static void
  3892. bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  3893. struct bfa_pcidev_s *pcidev)
  3894. {
  3895. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3896. struct bfa_rport_s *rp;
  3897. u16 i;
  3898. INIT_LIST_HEAD(&mod->rp_free_q);
  3899. INIT_LIST_HEAD(&mod->rp_active_q);
  3900. INIT_LIST_HEAD(&mod->rp_unused_q);
  3901. rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
  3902. mod->rps_list = rp;
  3903. mod->num_rports = cfg->fwcfg.num_rports;
  3904. WARN_ON(!mod->num_rports ||
  3905. (mod->num_rports & (mod->num_rports - 1)));
  3906. for (i = 0; i < mod->num_rports; i++, rp++) {
  3907. memset(rp, 0, sizeof(struct bfa_rport_s));
  3908. rp->bfa = bfa;
  3909. rp->rport_tag = i;
  3910. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3911. /*
  3912. * - is unused
  3913. */
  3914. if (i)
  3915. list_add_tail(&rp->qe, &mod->rp_free_q);
  3916. bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
  3917. }
  3918. /*
  3919. * consume memory
  3920. */
  3921. bfa_mem_kva_curp(mod) = (u8 *) rp;
  3922. }
  3923. static void
  3924. bfa_rport_detach(struct bfa_s *bfa)
  3925. {
  3926. }
  3927. static void
  3928. bfa_rport_start(struct bfa_s *bfa)
  3929. {
  3930. }
  3931. static void
  3932. bfa_rport_stop(struct bfa_s *bfa)
  3933. {
  3934. }
  3935. static void
  3936. bfa_rport_iocdisable(struct bfa_s *bfa)
  3937. {
  3938. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3939. struct bfa_rport_s *rport;
  3940. struct list_head *qe, *qen;
  3941. /* Enqueue unused rport resources to free_q */
  3942. list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
  3943. list_for_each_safe(qe, qen, &mod->rp_active_q) {
  3944. rport = (struct bfa_rport_s *) qe;
  3945. bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
  3946. }
  3947. }
  3948. static struct bfa_rport_s *
  3949. bfa_rport_alloc(struct bfa_rport_mod_s *mod)
  3950. {
  3951. struct bfa_rport_s *rport;
  3952. bfa_q_deq(&mod->rp_free_q, &rport);
  3953. if (rport)
  3954. list_add_tail(&rport->qe, &mod->rp_active_q);
  3955. return rport;
  3956. }
  3957. static void
  3958. bfa_rport_free(struct bfa_rport_s *rport)
  3959. {
  3960. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
  3961. WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
  3962. list_del(&rport->qe);
  3963. list_add_tail(&rport->qe, &mod->rp_free_q);
  3964. }
  3965. static bfa_boolean_t
  3966. bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
  3967. {
  3968. struct bfi_rport_create_req_s *m;
  3969. /*
  3970. * check for room in queue to send request now
  3971. */
  3972. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3973. if (!m) {
  3974. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  3975. return BFA_FALSE;
  3976. }
  3977. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
  3978. bfa_fn_lpu(rp->bfa));
  3979. m->bfa_handle = rp->rport_tag;
  3980. m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
  3981. m->pid = rp->rport_info.pid;
  3982. m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
  3983. m->local_pid = rp->rport_info.local_pid;
  3984. m->fc_class = rp->rport_info.fc_class;
  3985. m->vf_en = rp->rport_info.vf_en;
  3986. m->vf_id = rp->rport_info.vf_id;
  3987. m->cisc = rp->rport_info.cisc;
  3988. /*
  3989. * queue I/O message to firmware
  3990. */
  3991. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  3992. return BFA_TRUE;
  3993. }
  3994. static bfa_boolean_t
  3995. bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
  3996. {
  3997. struct bfi_rport_delete_req_s *m;
  3998. /*
  3999. * check for room in queue to send request now
  4000. */
  4001. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  4002. if (!m) {
  4003. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  4004. return BFA_FALSE;
  4005. }
  4006. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
  4007. bfa_fn_lpu(rp->bfa));
  4008. m->fw_handle = rp->fw_handle;
  4009. /*
  4010. * queue I/O message to firmware
  4011. */
  4012. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  4013. return BFA_TRUE;
  4014. }
  4015. static bfa_boolean_t
  4016. bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
  4017. {
  4018. struct bfa_rport_speed_req_s *m;
  4019. /*
  4020. * check for room in queue to send request now
  4021. */
  4022. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  4023. if (!m) {
  4024. bfa_trc(rp->bfa, rp->rport_info.speed);
  4025. return BFA_FALSE;
  4026. }
  4027. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
  4028. bfa_fn_lpu(rp->bfa));
  4029. m->fw_handle = rp->fw_handle;
  4030. m->speed = (u8)rp->rport_info.speed;
  4031. /*
  4032. * queue I/O message to firmware
  4033. */
  4034. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  4035. return BFA_TRUE;
  4036. }
  4037. /*
  4038. * bfa_rport_public
  4039. */
  4040. /*
  4041. * Rport interrupt processing.
  4042. */
  4043. void
  4044. bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  4045. {
  4046. union bfi_rport_i2h_msg_u msg;
  4047. struct bfa_rport_s *rp;
  4048. bfa_trc(bfa, m->mhdr.msg_id);
  4049. msg.msg = m;
  4050. switch (m->mhdr.msg_id) {
  4051. case BFI_RPORT_I2H_CREATE_RSP:
  4052. rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
  4053. rp->fw_handle = msg.create_rsp->fw_handle;
  4054. rp->qos_attr = msg.create_rsp->qos_attr;
  4055. bfa_rport_set_lunmask(bfa, rp);
  4056. WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
  4057. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  4058. break;
  4059. case BFI_RPORT_I2H_DELETE_RSP:
  4060. rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
  4061. WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
  4062. bfa_rport_unset_lunmask(bfa, rp);
  4063. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  4064. break;
  4065. case BFI_RPORT_I2H_QOS_SCN:
  4066. rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
  4067. rp->event_arg.fw_msg = msg.qos_scn_evt;
  4068. bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
  4069. break;
  4070. case BFI_RPORT_I2H_LIP_SCN_ONLINE:
  4071. bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa),
  4072. &msg.lip_scn->loop_info);
  4073. bfa_cb_rport_scn_online(bfa);
  4074. break;
  4075. case BFI_RPORT_I2H_LIP_SCN_OFFLINE:
  4076. bfa_cb_rport_scn_offline(bfa);
  4077. break;
  4078. case BFI_RPORT_I2H_NO_DEV:
  4079. rp = BFA_RPORT_FROM_TAG(bfa, msg.lip_scn->bfa_handle);
  4080. bfa_cb_rport_scn_no_dev(rp->rport_drv);
  4081. break;
  4082. default:
  4083. bfa_trc(bfa, m->mhdr.msg_id);
  4084. WARN_ON(1);
  4085. }
  4086. }
  4087. void
  4088. bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
  4089. {
  4090. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  4091. struct list_head *qe;
  4092. int i;
  4093. for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
  4094. bfa_q_deq_tail(&mod->rp_free_q, &qe);
  4095. list_add_tail(qe, &mod->rp_unused_q);
  4096. }
  4097. }
  4098. /*
  4099. * bfa_rport_api
  4100. */
  4101. struct bfa_rport_s *
  4102. bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
  4103. {
  4104. struct bfa_rport_s *rp;
  4105. rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
  4106. if (rp == NULL)
  4107. return NULL;
  4108. rp->bfa = bfa;
  4109. rp->rport_drv = rport_drv;
  4110. memset(&rp->stats, 0, sizeof(rp->stats));
  4111. WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
  4112. bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
  4113. return rp;
  4114. }
  4115. void
  4116. bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
  4117. {
  4118. WARN_ON(rport_info->max_frmsz == 0);
  4119. /*
  4120. * Some JBODs are seen to be not setting PDU size correctly in PLOGI
  4121. * responses. Default to minimum size.
  4122. */
  4123. if (rport_info->max_frmsz == 0) {
  4124. bfa_trc(rport->bfa, rport->rport_tag);
  4125. rport_info->max_frmsz = FC_MIN_PDUSZ;
  4126. }
  4127. rport->rport_info = *rport_info;
  4128. bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
  4129. }
  4130. void
  4131. bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
  4132. {
  4133. WARN_ON(speed == 0);
  4134. WARN_ON(speed == BFA_PORT_SPEED_AUTO);
  4135. if (rport) {
  4136. rport->rport_info.speed = speed;
  4137. bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
  4138. }
  4139. }
  4140. /* Set Rport LUN Mask */
  4141. void
  4142. bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
  4143. {
  4144. struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
  4145. wwn_t lp_wwn, rp_wwn;
  4146. u8 lp_tag = (u8)rp->rport_info.lp_tag;
  4147. rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
  4148. lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
  4149. BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
  4150. rp->lun_mask = BFA_TRUE;
  4151. bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
  4152. }
  4153. /* Unset Rport LUN mask */
  4154. void
  4155. bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
  4156. {
  4157. struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
  4158. wwn_t lp_wwn, rp_wwn;
  4159. rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
  4160. lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
  4161. BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
  4162. rp->lun_mask = BFA_FALSE;
  4163. bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
  4164. BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
  4165. }
  4166. /*
  4167. * SGPG related functions
  4168. */
  4169. /*
  4170. * Compute and return memory needed by FCP(im) module.
  4171. */
  4172. static void
  4173. bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  4174. struct bfa_s *bfa)
  4175. {
  4176. struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
  4177. struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
  4178. struct bfa_mem_dma_s *seg_ptr;
  4179. u16 nsegs, idx, per_seg_sgpg, num_sgpg;
  4180. u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
  4181. if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
  4182. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  4183. else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
  4184. cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
  4185. num_sgpg = cfg->drvcfg.num_sgpgs;
  4186. nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
  4187. per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
  4188. bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
  4189. if (num_sgpg >= per_seg_sgpg) {
  4190. num_sgpg -= per_seg_sgpg;
  4191. bfa_mem_dma_setup(minfo, seg_ptr,
  4192. per_seg_sgpg * sgpg_sz);
  4193. } else
  4194. bfa_mem_dma_setup(minfo, seg_ptr,
  4195. num_sgpg * sgpg_sz);
  4196. }
  4197. /* kva memory */
  4198. bfa_mem_kva_setup(minfo, sgpg_kva,
  4199. cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
  4200. }
  4201. static void
  4202. bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4203. struct bfa_pcidev_s *pcidev)
  4204. {
  4205. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4206. struct bfa_sgpg_s *hsgpg;
  4207. struct bfi_sgpg_s *sgpg;
  4208. u64 align_len;
  4209. struct bfa_mem_dma_s *seg_ptr;
  4210. u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
  4211. u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
  4212. union {
  4213. u64 pa;
  4214. union bfi_addr_u addr;
  4215. } sgpg_pa, sgpg_pa_tmp;
  4216. INIT_LIST_HEAD(&mod->sgpg_q);
  4217. INIT_LIST_HEAD(&mod->sgpg_wait_q);
  4218. bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
  4219. mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
  4220. num_sgpg = cfg->drvcfg.num_sgpgs;
  4221. nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
  4222. /* dma/kva mem claim */
  4223. hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
  4224. bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
  4225. if (!bfa_mem_dma_virt(seg_ptr))
  4226. break;
  4227. align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
  4228. bfa_mem_dma_phys(seg_ptr);
  4229. sgpg = (struct bfi_sgpg_s *)
  4230. (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
  4231. sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
  4232. WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
  4233. per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
  4234. for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
  4235. memset(hsgpg, 0, sizeof(*hsgpg));
  4236. memset(sgpg, 0, sizeof(*sgpg));
  4237. hsgpg->sgpg = sgpg;
  4238. sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
  4239. hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
  4240. list_add_tail(&hsgpg->qe, &mod->sgpg_q);
  4241. sgpg++;
  4242. hsgpg++;
  4243. sgpg_pa.pa += sgpg_sz;
  4244. }
  4245. }
  4246. bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
  4247. }
  4248. static void
  4249. bfa_sgpg_detach(struct bfa_s *bfa)
  4250. {
  4251. }
  4252. static void
  4253. bfa_sgpg_start(struct bfa_s *bfa)
  4254. {
  4255. }
  4256. static void
  4257. bfa_sgpg_stop(struct bfa_s *bfa)
  4258. {
  4259. }
  4260. static void
  4261. bfa_sgpg_iocdisable(struct bfa_s *bfa)
  4262. {
  4263. }
  4264. bfa_status_t
  4265. bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
  4266. {
  4267. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4268. struct bfa_sgpg_s *hsgpg;
  4269. int i;
  4270. if (mod->free_sgpgs < nsgpgs)
  4271. return BFA_STATUS_ENOMEM;
  4272. for (i = 0; i < nsgpgs; i++) {
  4273. bfa_q_deq(&mod->sgpg_q, &hsgpg);
  4274. WARN_ON(!hsgpg);
  4275. list_add_tail(&hsgpg->qe, sgpg_q);
  4276. }
  4277. mod->free_sgpgs -= nsgpgs;
  4278. return BFA_STATUS_OK;
  4279. }
  4280. void
  4281. bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
  4282. {
  4283. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4284. struct bfa_sgpg_wqe_s *wqe;
  4285. mod->free_sgpgs += nsgpg;
  4286. WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
  4287. list_splice_tail_init(sgpg_q, &mod->sgpg_q);
  4288. if (list_empty(&mod->sgpg_wait_q))
  4289. return;
  4290. /*
  4291. * satisfy as many waiting requests as possible
  4292. */
  4293. do {
  4294. wqe = bfa_q_first(&mod->sgpg_wait_q);
  4295. if (mod->free_sgpgs < wqe->nsgpg)
  4296. nsgpg = mod->free_sgpgs;
  4297. else
  4298. nsgpg = wqe->nsgpg;
  4299. bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
  4300. wqe->nsgpg -= nsgpg;
  4301. if (wqe->nsgpg == 0) {
  4302. list_del(&wqe->qe);
  4303. wqe->cbfn(wqe->cbarg);
  4304. }
  4305. } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
  4306. }
  4307. void
  4308. bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
  4309. {
  4310. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4311. WARN_ON(nsgpg <= 0);
  4312. WARN_ON(nsgpg <= mod->free_sgpgs);
  4313. wqe->nsgpg_total = wqe->nsgpg = nsgpg;
  4314. /*
  4315. * allocate any left to this one first
  4316. */
  4317. if (mod->free_sgpgs) {
  4318. /*
  4319. * no one else is waiting for SGPG
  4320. */
  4321. WARN_ON(!list_empty(&mod->sgpg_wait_q));
  4322. list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
  4323. wqe->nsgpg -= mod->free_sgpgs;
  4324. mod->free_sgpgs = 0;
  4325. }
  4326. list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
  4327. }
  4328. void
  4329. bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
  4330. {
  4331. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4332. WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
  4333. list_del(&wqe->qe);
  4334. if (wqe->nsgpg_total != wqe->nsgpg)
  4335. bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
  4336. wqe->nsgpg_total - wqe->nsgpg);
  4337. }
  4338. void
  4339. bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
  4340. void *cbarg)
  4341. {
  4342. INIT_LIST_HEAD(&wqe->sgpg_q);
  4343. wqe->cbfn = cbfn;
  4344. wqe->cbarg = cbarg;
  4345. }
  4346. /*
  4347. * UF related functions
  4348. */
  4349. /*
  4350. *****************************************************************************
  4351. * Internal functions
  4352. *****************************************************************************
  4353. */
  4354. static void
  4355. __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
  4356. {
  4357. struct bfa_uf_s *uf = cbarg;
  4358. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
  4359. if (complete)
  4360. ufm->ufrecv(ufm->cbarg, uf);
  4361. }
  4362. static void
  4363. claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
  4364. {
  4365. struct bfi_uf_buf_post_s *uf_bp_msg;
  4366. u16 i;
  4367. u16 buf_len;
  4368. ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
  4369. uf_bp_msg = ufm->uf_buf_posts;
  4370. for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
  4371. i++, uf_bp_msg++) {
  4372. memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
  4373. uf_bp_msg->buf_tag = i;
  4374. buf_len = sizeof(struct bfa_uf_buf_s);
  4375. uf_bp_msg->buf_len = cpu_to_be16(buf_len);
  4376. bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
  4377. bfa_fn_lpu(ufm->bfa));
  4378. bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
  4379. }
  4380. /*
  4381. * advance pointer beyond consumed memory
  4382. */
  4383. bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
  4384. }
  4385. static void
  4386. claim_ufs(struct bfa_uf_mod_s *ufm)
  4387. {
  4388. u16 i;
  4389. struct bfa_uf_s *uf;
  4390. /*
  4391. * Claim block of memory for UF list
  4392. */
  4393. ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
  4394. /*
  4395. * Initialize UFs and queue it in UF free queue
  4396. */
  4397. for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
  4398. memset(uf, 0, sizeof(struct bfa_uf_s));
  4399. uf->bfa = ufm->bfa;
  4400. uf->uf_tag = i;
  4401. uf->pb_len = BFA_PER_UF_DMA_SZ;
  4402. uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
  4403. uf->buf_pa = ufm_pbs_pa(ufm, i);
  4404. list_add_tail(&uf->qe, &ufm->uf_free_q);
  4405. }
  4406. /*
  4407. * advance memory pointer
  4408. */
  4409. bfa_mem_kva_curp(ufm) = (u8 *) uf;
  4410. }
  4411. static void
  4412. uf_mem_claim(struct bfa_uf_mod_s *ufm)
  4413. {
  4414. claim_ufs(ufm);
  4415. claim_uf_post_msgs(ufm);
  4416. }
  4417. static void
  4418. bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  4419. struct bfa_s *bfa)
  4420. {
  4421. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4422. struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
  4423. u32 num_ufs = cfg->fwcfg.num_uf_bufs;
  4424. struct bfa_mem_dma_s *seg_ptr;
  4425. u16 nsegs, idx, per_seg_uf = 0;
  4426. nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
  4427. per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
  4428. bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
  4429. if (num_ufs >= per_seg_uf) {
  4430. num_ufs -= per_seg_uf;
  4431. bfa_mem_dma_setup(minfo, seg_ptr,
  4432. per_seg_uf * BFA_PER_UF_DMA_SZ);
  4433. } else
  4434. bfa_mem_dma_setup(minfo, seg_ptr,
  4435. num_ufs * BFA_PER_UF_DMA_SZ);
  4436. }
  4437. /* kva memory */
  4438. bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
  4439. (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
  4440. }
  4441. static void
  4442. bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4443. struct bfa_pcidev_s *pcidev)
  4444. {
  4445. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4446. ufm->bfa = bfa;
  4447. ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
  4448. INIT_LIST_HEAD(&ufm->uf_free_q);
  4449. INIT_LIST_HEAD(&ufm->uf_posted_q);
  4450. INIT_LIST_HEAD(&ufm->uf_unused_q);
  4451. uf_mem_claim(ufm);
  4452. }
  4453. static void
  4454. bfa_uf_detach(struct bfa_s *bfa)
  4455. {
  4456. }
  4457. static struct bfa_uf_s *
  4458. bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
  4459. {
  4460. struct bfa_uf_s *uf;
  4461. bfa_q_deq(&uf_mod->uf_free_q, &uf);
  4462. return uf;
  4463. }
  4464. static void
  4465. bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
  4466. {
  4467. list_add_tail(&uf->qe, &uf_mod->uf_free_q);
  4468. }
  4469. static bfa_status_t
  4470. bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
  4471. {
  4472. struct bfi_uf_buf_post_s *uf_post_msg;
  4473. uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
  4474. if (!uf_post_msg)
  4475. return BFA_STATUS_FAILED;
  4476. memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
  4477. sizeof(struct bfi_uf_buf_post_s));
  4478. bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
  4479. bfa_trc(ufm->bfa, uf->uf_tag);
  4480. list_add_tail(&uf->qe, &ufm->uf_posted_q);
  4481. return BFA_STATUS_OK;
  4482. }
  4483. static void
  4484. bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
  4485. {
  4486. struct bfa_uf_s *uf;
  4487. while ((uf = bfa_uf_get(uf_mod)) != NULL) {
  4488. if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
  4489. break;
  4490. }
  4491. }
  4492. static void
  4493. uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
  4494. {
  4495. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4496. u16 uf_tag = m->buf_tag;
  4497. struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
  4498. struct bfa_uf_buf_s *uf_buf;
  4499. uint8_t *buf;
  4500. struct fchs_s *fchs;
  4501. uf_buf = (struct bfa_uf_buf_s *)
  4502. bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
  4503. buf = &uf_buf->d[0];
  4504. m->frm_len = be16_to_cpu(m->frm_len);
  4505. m->xfr_len = be16_to_cpu(m->xfr_len);
  4506. fchs = (struct fchs_s *)uf_buf;
  4507. list_del(&uf->qe); /* dequeue from posted queue */
  4508. uf->data_ptr = buf;
  4509. uf->data_len = m->xfr_len;
  4510. WARN_ON(uf->data_len < sizeof(struct fchs_s));
  4511. if (uf->data_len == sizeof(struct fchs_s)) {
  4512. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
  4513. uf->data_len, (struct fchs_s *)buf);
  4514. } else {
  4515. u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
  4516. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
  4517. BFA_PL_EID_RX, uf->data_len,
  4518. (struct fchs_s *)buf, pld_w0);
  4519. }
  4520. if (bfa->fcs)
  4521. __bfa_cb_uf_recv(uf, BFA_TRUE);
  4522. else
  4523. bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
  4524. }
  4525. static void
  4526. bfa_uf_stop(struct bfa_s *bfa)
  4527. {
  4528. }
  4529. static void
  4530. bfa_uf_iocdisable(struct bfa_s *bfa)
  4531. {
  4532. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4533. struct bfa_uf_s *uf;
  4534. struct list_head *qe, *qen;
  4535. /* Enqueue unused uf resources to free_q */
  4536. list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
  4537. list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
  4538. uf = (struct bfa_uf_s *) qe;
  4539. list_del(&uf->qe);
  4540. bfa_uf_put(ufm, uf);
  4541. }
  4542. }
  4543. static void
  4544. bfa_uf_start(struct bfa_s *bfa)
  4545. {
  4546. bfa_uf_post_all(BFA_UF_MOD(bfa));
  4547. }
  4548. /*
  4549. * Register handler for all unsolicted receive frames.
  4550. *
  4551. * @param[in] bfa BFA instance
  4552. * @param[in] ufrecv receive handler function
  4553. * @param[in] cbarg receive handler arg
  4554. */
  4555. void
  4556. bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
  4557. {
  4558. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4559. ufm->ufrecv = ufrecv;
  4560. ufm->cbarg = cbarg;
  4561. }
  4562. /*
  4563. * Free an unsolicited frame back to BFA.
  4564. *
  4565. * @param[in] uf unsolicited frame to be freed
  4566. *
  4567. * @return None
  4568. */
  4569. void
  4570. bfa_uf_free(struct bfa_uf_s *uf)
  4571. {
  4572. bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
  4573. bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
  4574. }
  4575. /*
  4576. * uf_pub BFA uf module public functions
  4577. */
  4578. void
  4579. bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4580. {
  4581. bfa_trc(bfa, msg->mhdr.msg_id);
  4582. switch (msg->mhdr.msg_id) {
  4583. case BFI_UF_I2H_FRM_RCVD:
  4584. uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
  4585. break;
  4586. default:
  4587. bfa_trc(bfa, msg->mhdr.msg_id);
  4588. WARN_ON(1);
  4589. }
  4590. }
  4591. void
  4592. bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
  4593. {
  4594. struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
  4595. struct list_head *qe;
  4596. int i;
  4597. for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
  4598. bfa_q_deq_tail(&mod->uf_free_q, &qe);
  4599. list_add_tail(qe, &mod->uf_unused_q);
  4600. }
  4601. }
  4602. /*
  4603. * Dport forward declaration
  4604. */
  4605. /*
  4606. * BFA DPORT state machine events
  4607. */
  4608. enum bfa_dport_sm_event {
  4609. BFA_DPORT_SM_ENABLE = 1, /* dport enable event */
  4610. BFA_DPORT_SM_DISABLE = 2, /* dport disable event */
  4611. BFA_DPORT_SM_FWRSP = 3, /* fw enable/disable rsp */
  4612. BFA_DPORT_SM_QRESUME = 4, /* CQ space available */
  4613. BFA_DPORT_SM_HWFAIL = 5, /* IOC h/w failure */
  4614. };
  4615. static void bfa_dport_sm_disabled(struct bfa_dport_s *dport,
  4616. enum bfa_dport_sm_event event);
  4617. static void bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
  4618. enum bfa_dport_sm_event event);
  4619. static void bfa_dport_sm_enabling(struct bfa_dport_s *dport,
  4620. enum bfa_dport_sm_event event);
  4621. static void bfa_dport_sm_enabled(struct bfa_dport_s *dport,
  4622. enum bfa_dport_sm_event event);
  4623. static void bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
  4624. enum bfa_dport_sm_event event);
  4625. static void bfa_dport_sm_disabling(struct bfa_dport_s *dport,
  4626. enum bfa_dport_sm_event event);
  4627. static void bfa_dport_qresume(void *cbarg);
  4628. static void bfa_dport_req_comp(struct bfa_dport_s *dport,
  4629. bfi_diag_dport_rsp_t *msg);
  4630. /*
  4631. * BFA fcdiag module
  4632. */
  4633. #define BFA_DIAG_QTEST_TOV 1000 /* msec */
  4634. /*
  4635. * Set port status to busy
  4636. */
  4637. static void
  4638. bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
  4639. {
  4640. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
  4641. if (fcdiag->lb.lock)
  4642. fcport->diag_busy = BFA_TRUE;
  4643. else
  4644. fcport->diag_busy = BFA_FALSE;
  4645. }
  4646. static void
  4647. bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  4648. struct bfa_s *bfa)
  4649. {
  4650. }
  4651. static void
  4652. bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4653. struct bfa_pcidev_s *pcidev)
  4654. {
  4655. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4656. struct bfa_dport_s *dport = &fcdiag->dport;
  4657. fcdiag->bfa = bfa;
  4658. fcdiag->trcmod = bfa->trcmod;
  4659. /* The common DIAG attach bfa_diag_attach() will do all memory claim */
  4660. dport->bfa = bfa;
  4661. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  4662. bfa_reqq_winit(&dport->reqq_wait, bfa_dport_qresume, dport);
  4663. dport->cbfn = NULL;
  4664. dport->cbarg = NULL;
  4665. }
  4666. static void
  4667. bfa_fcdiag_iocdisable(struct bfa_s *bfa)
  4668. {
  4669. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4670. struct bfa_dport_s *dport = &fcdiag->dport;
  4671. bfa_trc(fcdiag, fcdiag->lb.lock);
  4672. if (fcdiag->lb.lock) {
  4673. fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
  4674. fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
  4675. fcdiag->lb.lock = 0;
  4676. bfa_fcdiag_set_busy_status(fcdiag);
  4677. }
  4678. bfa_sm_send_event(dport, BFA_DPORT_SM_HWFAIL);
  4679. }
  4680. static void
  4681. bfa_fcdiag_detach(struct bfa_s *bfa)
  4682. {
  4683. }
  4684. static void
  4685. bfa_fcdiag_start(struct bfa_s *bfa)
  4686. {
  4687. }
  4688. static void
  4689. bfa_fcdiag_stop(struct bfa_s *bfa)
  4690. {
  4691. }
  4692. static void
  4693. bfa_fcdiag_queuetest_timeout(void *cbarg)
  4694. {
  4695. struct bfa_fcdiag_s *fcdiag = cbarg;
  4696. struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
  4697. bfa_trc(fcdiag, fcdiag->qtest.all);
  4698. bfa_trc(fcdiag, fcdiag->qtest.count);
  4699. fcdiag->qtest.timer_active = 0;
  4700. res->status = BFA_STATUS_ETIMER;
  4701. res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
  4702. if (fcdiag->qtest.all)
  4703. res->queue = fcdiag->qtest.all;
  4704. bfa_trc(fcdiag, BFA_STATUS_ETIMER);
  4705. fcdiag->qtest.status = BFA_STATUS_ETIMER;
  4706. fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
  4707. fcdiag->qtest.lock = 0;
  4708. }
  4709. static bfa_status_t
  4710. bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
  4711. {
  4712. u32 i;
  4713. struct bfi_diag_qtest_req_s *req;
  4714. req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
  4715. if (!req)
  4716. return BFA_STATUS_DEVBUSY;
  4717. /* build host command */
  4718. bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
  4719. bfa_fn_lpu(fcdiag->bfa));
  4720. for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
  4721. req->data[i] = QTEST_PAT_DEFAULT;
  4722. bfa_trc(fcdiag, fcdiag->qtest.queue);
  4723. /* ring door bell */
  4724. bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
  4725. return BFA_STATUS_OK;
  4726. }
  4727. static void
  4728. bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
  4729. bfi_diag_qtest_rsp_t *rsp)
  4730. {
  4731. struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
  4732. bfa_status_t status = BFA_STATUS_OK;
  4733. int i;
  4734. /* Check timer, should still be active */
  4735. if (!fcdiag->qtest.timer_active) {
  4736. bfa_trc(fcdiag, fcdiag->qtest.timer_active);
  4737. return;
  4738. }
  4739. /* update count */
  4740. fcdiag->qtest.count--;
  4741. /* Check result */
  4742. for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
  4743. if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
  4744. res->status = BFA_STATUS_DATACORRUPTED;
  4745. break;
  4746. }
  4747. }
  4748. if (res->status == BFA_STATUS_OK) {
  4749. if (fcdiag->qtest.count > 0) {
  4750. status = bfa_fcdiag_queuetest_send(fcdiag);
  4751. if (status == BFA_STATUS_OK)
  4752. return;
  4753. else
  4754. res->status = status;
  4755. } else if (fcdiag->qtest.all > 0 &&
  4756. fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
  4757. fcdiag->qtest.count = QTEST_CNT_DEFAULT;
  4758. fcdiag->qtest.queue++;
  4759. status = bfa_fcdiag_queuetest_send(fcdiag);
  4760. if (status == BFA_STATUS_OK)
  4761. return;
  4762. else
  4763. res->status = status;
  4764. }
  4765. }
  4766. /* Stop timer when we comp all queue */
  4767. if (fcdiag->qtest.timer_active) {
  4768. bfa_timer_stop(&fcdiag->qtest.timer);
  4769. fcdiag->qtest.timer_active = 0;
  4770. }
  4771. res->queue = fcdiag->qtest.queue;
  4772. res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
  4773. bfa_trc(fcdiag, res->count);
  4774. bfa_trc(fcdiag, res->status);
  4775. fcdiag->qtest.status = res->status;
  4776. fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
  4777. fcdiag->qtest.lock = 0;
  4778. }
  4779. static void
  4780. bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
  4781. struct bfi_diag_lb_rsp_s *rsp)
  4782. {
  4783. struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
  4784. res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
  4785. res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
  4786. res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
  4787. res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
  4788. res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
  4789. res->status = rsp->res.status;
  4790. fcdiag->lb.status = rsp->res.status;
  4791. bfa_trc(fcdiag, fcdiag->lb.status);
  4792. fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
  4793. fcdiag->lb.lock = 0;
  4794. bfa_fcdiag_set_busy_status(fcdiag);
  4795. }
  4796. static bfa_status_t
  4797. bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
  4798. struct bfa_diag_loopback_s *loopback)
  4799. {
  4800. struct bfi_diag_lb_req_s *lb_req;
  4801. lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
  4802. if (!lb_req)
  4803. return BFA_STATUS_DEVBUSY;
  4804. /* build host command */
  4805. bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
  4806. bfa_fn_lpu(fcdiag->bfa));
  4807. lb_req->lb_mode = loopback->lb_mode;
  4808. lb_req->speed = loopback->speed;
  4809. lb_req->loopcnt = loopback->loopcnt;
  4810. lb_req->pattern = loopback->pattern;
  4811. /* ring door bell */
  4812. bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
  4813. bfa_trc(fcdiag, loopback->lb_mode);
  4814. bfa_trc(fcdiag, loopback->speed);
  4815. bfa_trc(fcdiag, loopback->loopcnt);
  4816. bfa_trc(fcdiag, loopback->pattern);
  4817. return BFA_STATUS_OK;
  4818. }
  4819. /*
  4820. * cpe/rme intr handler
  4821. */
  4822. void
  4823. bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4824. {
  4825. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4826. switch (msg->mhdr.msg_id) {
  4827. case BFI_DIAG_I2H_LOOPBACK:
  4828. bfa_fcdiag_loopback_comp(fcdiag,
  4829. (struct bfi_diag_lb_rsp_s *) msg);
  4830. break;
  4831. case BFI_DIAG_I2H_QTEST:
  4832. bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
  4833. break;
  4834. case BFI_DIAG_I2H_DPORT:
  4835. bfa_dport_req_comp(&fcdiag->dport, (bfi_diag_dport_rsp_t *)msg);
  4836. break;
  4837. default:
  4838. bfa_trc(fcdiag, msg->mhdr.msg_id);
  4839. WARN_ON(1);
  4840. }
  4841. }
  4842. /*
  4843. * Loopback test
  4844. *
  4845. * @param[in] *bfa - bfa data struct
  4846. * @param[in] opmode - port operation mode
  4847. * @param[in] speed - port speed
  4848. * @param[in] lpcnt - loop count
  4849. * @param[in] pat - pattern to build packet
  4850. * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
  4851. * @param[in] cbfn - callback function
  4852. * @param[in] cbarg - callback functioin arg
  4853. *
  4854. * @param[out]
  4855. */
  4856. bfa_status_t
  4857. bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
  4858. enum bfa_port_speed speed, u32 lpcnt, u32 pat,
  4859. struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
  4860. void *cbarg)
  4861. {
  4862. struct bfa_diag_loopback_s loopback;
  4863. struct bfa_port_attr_s attr;
  4864. bfa_status_t status;
  4865. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4866. if (!bfa_iocfc_is_operational(bfa))
  4867. return BFA_STATUS_IOC_NON_OP;
  4868. /* if port is PBC disabled, return error */
  4869. if (bfa_fcport_is_pbcdisabled(bfa)) {
  4870. bfa_trc(fcdiag, BFA_STATUS_PBC);
  4871. return BFA_STATUS_PBC;
  4872. }
  4873. if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
  4874. bfa_trc(fcdiag, opmode);
  4875. return BFA_STATUS_PORT_NOT_DISABLED;
  4876. }
  4877. /*
  4878. * Check if input speed is supported by the port mode
  4879. */
  4880. if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
  4881. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  4882. speed == BFA_PORT_SPEED_2GBPS ||
  4883. speed == BFA_PORT_SPEED_4GBPS ||
  4884. speed == BFA_PORT_SPEED_8GBPS ||
  4885. speed == BFA_PORT_SPEED_16GBPS ||
  4886. speed == BFA_PORT_SPEED_AUTO)) {
  4887. bfa_trc(fcdiag, speed);
  4888. return BFA_STATUS_UNSUPP_SPEED;
  4889. }
  4890. bfa_fcport_get_attr(bfa, &attr);
  4891. bfa_trc(fcdiag, attr.speed_supported);
  4892. if (speed > attr.speed_supported)
  4893. return BFA_STATUS_UNSUPP_SPEED;
  4894. } else {
  4895. if (speed != BFA_PORT_SPEED_10GBPS) {
  4896. bfa_trc(fcdiag, speed);
  4897. return BFA_STATUS_UNSUPP_SPEED;
  4898. }
  4899. }
  4900. /*
  4901. * For CT2, 1G is not supported
  4902. */
  4903. if ((speed == BFA_PORT_SPEED_1GBPS) &&
  4904. (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id))) {
  4905. bfa_trc(fcdiag, speed);
  4906. return BFA_STATUS_UNSUPP_SPEED;
  4907. }
  4908. /* For Mezz card, port speed entered needs to be checked */
  4909. if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
  4910. if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
  4911. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  4912. speed == BFA_PORT_SPEED_2GBPS ||
  4913. speed == BFA_PORT_SPEED_4GBPS ||
  4914. speed == BFA_PORT_SPEED_8GBPS ||
  4915. speed == BFA_PORT_SPEED_16GBPS ||
  4916. speed == BFA_PORT_SPEED_AUTO))
  4917. return BFA_STATUS_UNSUPP_SPEED;
  4918. } else {
  4919. if (speed != BFA_PORT_SPEED_10GBPS)
  4920. return BFA_STATUS_UNSUPP_SPEED;
  4921. }
  4922. }
  4923. /* check to see if there is another destructive diag cmd running */
  4924. if (fcdiag->lb.lock) {
  4925. bfa_trc(fcdiag, fcdiag->lb.lock);
  4926. return BFA_STATUS_DEVBUSY;
  4927. }
  4928. fcdiag->lb.lock = 1;
  4929. loopback.lb_mode = opmode;
  4930. loopback.speed = speed;
  4931. loopback.loopcnt = lpcnt;
  4932. loopback.pattern = pat;
  4933. fcdiag->lb.result = result;
  4934. fcdiag->lb.cbfn = cbfn;
  4935. fcdiag->lb.cbarg = cbarg;
  4936. memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
  4937. bfa_fcdiag_set_busy_status(fcdiag);
  4938. /* Send msg to fw */
  4939. status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
  4940. return status;
  4941. }
  4942. /*
  4943. * DIAG queue test command
  4944. *
  4945. * @param[in] *bfa - bfa data struct
  4946. * @param[in] force - 1: don't do ioc op checking
  4947. * @param[in] queue - queue no. to test
  4948. * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
  4949. * @param[in] cbfn - callback function
  4950. * @param[in] *cbarg - callback functioin arg
  4951. *
  4952. * @param[out]
  4953. */
  4954. bfa_status_t
  4955. bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
  4956. struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
  4957. void *cbarg)
  4958. {
  4959. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4960. bfa_status_t status;
  4961. bfa_trc(fcdiag, force);
  4962. bfa_trc(fcdiag, queue);
  4963. if (!force && !bfa_iocfc_is_operational(bfa))
  4964. return BFA_STATUS_IOC_NON_OP;
  4965. /* check to see if there is another destructive diag cmd running */
  4966. if (fcdiag->qtest.lock) {
  4967. bfa_trc(fcdiag, fcdiag->qtest.lock);
  4968. return BFA_STATUS_DEVBUSY;
  4969. }
  4970. /* Initialization */
  4971. fcdiag->qtest.lock = 1;
  4972. fcdiag->qtest.cbfn = cbfn;
  4973. fcdiag->qtest.cbarg = cbarg;
  4974. fcdiag->qtest.result = result;
  4975. fcdiag->qtest.count = QTEST_CNT_DEFAULT;
  4976. /* Init test results */
  4977. fcdiag->qtest.result->status = BFA_STATUS_OK;
  4978. fcdiag->qtest.result->count = 0;
  4979. /* send */
  4980. if (queue < BFI_IOC_MAX_CQS) {
  4981. fcdiag->qtest.result->queue = (u8)queue;
  4982. fcdiag->qtest.queue = (u8)queue;
  4983. fcdiag->qtest.all = 0;
  4984. } else {
  4985. fcdiag->qtest.result->queue = 0;
  4986. fcdiag->qtest.queue = 0;
  4987. fcdiag->qtest.all = 1;
  4988. }
  4989. status = bfa_fcdiag_queuetest_send(fcdiag);
  4990. /* Start a timer */
  4991. if (status == BFA_STATUS_OK) {
  4992. bfa_timer_start(bfa, &fcdiag->qtest.timer,
  4993. bfa_fcdiag_queuetest_timeout, fcdiag,
  4994. BFA_DIAG_QTEST_TOV);
  4995. fcdiag->qtest.timer_active = 1;
  4996. }
  4997. return status;
  4998. }
  4999. /*
  5000. * DIAG PLB is running
  5001. *
  5002. * @param[in] *bfa - bfa data struct
  5003. *
  5004. * @param[out]
  5005. */
  5006. bfa_status_t
  5007. bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
  5008. {
  5009. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5010. return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
  5011. }
  5012. /*
  5013. * D-port
  5014. */
  5015. static bfa_boolean_t bfa_dport_send_req(struct bfa_dport_s *dport,
  5016. enum bfi_dport_req req);
  5017. static void
  5018. bfa_cb_fcdiag_dport(struct bfa_dport_s *dport, bfa_status_t bfa_status)
  5019. {
  5020. if (dport->cbfn != NULL) {
  5021. dport->cbfn(dport->cbarg, bfa_status);
  5022. dport->cbfn = NULL;
  5023. dport->cbarg = NULL;
  5024. }
  5025. }
  5026. static void
  5027. bfa_dport_sm_disabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5028. {
  5029. bfa_trc(dport->bfa, event);
  5030. switch (event) {
  5031. case BFA_DPORT_SM_ENABLE:
  5032. bfa_fcport_dportenable(dport->bfa);
  5033. if (bfa_dport_send_req(dport, BFI_DPORT_ENABLE))
  5034. bfa_sm_set_state(dport, bfa_dport_sm_enabling);
  5035. else
  5036. bfa_sm_set_state(dport, bfa_dport_sm_enabling_qwait);
  5037. break;
  5038. case BFA_DPORT_SM_DISABLE:
  5039. /* Already disabled */
  5040. break;
  5041. case BFA_DPORT_SM_HWFAIL:
  5042. /* ignore */
  5043. break;
  5044. default:
  5045. bfa_sm_fault(dport->bfa, event);
  5046. }
  5047. }
  5048. static void
  5049. bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
  5050. enum bfa_dport_sm_event event)
  5051. {
  5052. bfa_trc(dport->bfa, event);
  5053. switch (event) {
  5054. case BFA_DPORT_SM_QRESUME:
  5055. bfa_sm_set_state(dport, bfa_dport_sm_enabling);
  5056. bfa_dport_send_req(dport, BFI_DPORT_ENABLE);
  5057. break;
  5058. case BFA_DPORT_SM_HWFAIL:
  5059. bfa_reqq_wcancel(&dport->reqq_wait);
  5060. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5061. bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
  5062. break;
  5063. default:
  5064. bfa_sm_fault(dport->bfa, event);
  5065. }
  5066. }
  5067. static void
  5068. bfa_dport_sm_enabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5069. {
  5070. bfa_trc(dport->bfa, event);
  5071. switch (event) {
  5072. case BFA_DPORT_SM_FWRSP:
  5073. bfa_sm_set_state(dport, bfa_dport_sm_enabled);
  5074. break;
  5075. case BFA_DPORT_SM_HWFAIL:
  5076. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5077. bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
  5078. break;
  5079. default:
  5080. bfa_sm_fault(dport->bfa, event);
  5081. }
  5082. }
  5083. static void
  5084. bfa_dport_sm_enabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5085. {
  5086. bfa_trc(dport->bfa, event);
  5087. switch (event) {
  5088. case BFA_DPORT_SM_ENABLE:
  5089. /* Already enabled */
  5090. break;
  5091. case BFA_DPORT_SM_DISABLE:
  5092. bfa_fcport_dportdisable(dport->bfa);
  5093. if (bfa_dport_send_req(dport, BFI_DPORT_DISABLE))
  5094. bfa_sm_set_state(dport, bfa_dport_sm_disabling);
  5095. else
  5096. bfa_sm_set_state(dport, bfa_dport_sm_disabling_qwait);
  5097. break;
  5098. case BFA_DPORT_SM_HWFAIL:
  5099. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5100. break;
  5101. default:
  5102. bfa_sm_fault(dport->bfa, event);
  5103. }
  5104. }
  5105. static void
  5106. bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
  5107. enum bfa_dport_sm_event event)
  5108. {
  5109. bfa_trc(dport->bfa, event);
  5110. switch (event) {
  5111. case BFA_DPORT_SM_QRESUME:
  5112. bfa_sm_set_state(dport, bfa_dport_sm_disabling);
  5113. bfa_dport_send_req(dport, BFI_DPORT_DISABLE);
  5114. break;
  5115. case BFA_DPORT_SM_HWFAIL:
  5116. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5117. bfa_reqq_wcancel(&dport->reqq_wait);
  5118. bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
  5119. break;
  5120. default:
  5121. bfa_sm_fault(dport->bfa, event);
  5122. }
  5123. }
  5124. static void
  5125. bfa_dport_sm_disabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5126. {
  5127. bfa_trc(dport->bfa, event);
  5128. switch (event) {
  5129. case BFA_DPORT_SM_FWRSP:
  5130. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5131. break;
  5132. case BFA_DPORT_SM_HWFAIL:
  5133. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5134. bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
  5135. break;
  5136. default:
  5137. bfa_sm_fault(dport->bfa, event);
  5138. }
  5139. }
  5140. static bfa_boolean_t
  5141. bfa_dport_send_req(struct bfa_dport_s *dport, enum bfi_dport_req req)
  5142. {
  5143. struct bfi_diag_dport_req_s *m;
  5144. /*
  5145. * Increment message tag before queue check, so that responses to old
  5146. * requests are discarded.
  5147. */
  5148. dport->msgtag++;
  5149. /*
  5150. * check for room in queue to send request now
  5151. */
  5152. m = bfa_reqq_next(dport->bfa, BFA_REQQ_DIAG);
  5153. if (!m) {
  5154. bfa_reqq_wait(dport->bfa, BFA_REQQ_PORT, &dport->reqq_wait);
  5155. return BFA_FALSE;
  5156. }
  5157. bfi_h2i_set(m->mh, BFI_MC_DIAG, BFI_DIAG_H2I_DPORT,
  5158. bfa_fn_lpu(dport->bfa));
  5159. m->req = req;
  5160. m->msgtag = dport->msgtag;
  5161. /*
  5162. * queue I/O message to firmware
  5163. */
  5164. bfa_reqq_produce(dport->bfa, BFA_REQQ_DIAG, m->mh);
  5165. return BFA_TRUE;
  5166. }
  5167. static void
  5168. bfa_dport_qresume(void *cbarg)
  5169. {
  5170. struct bfa_dport_s *dport = cbarg;
  5171. bfa_sm_send_event(dport, BFA_DPORT_SM_QRESUME);
  5172. }
  5173. static void
  5174. bfa_dport_req_comp(struct bfa_dport_s *dport, bfi_diag_dport_rsp_t *msg)
  5175. {
  5176. bfa_sm_send_event(dport, BFA_DPORT_SM_FWRSP);
  5177. bfa_cb_fcdiag_dport(dport, msg->status);
  5178. }
  5179. /*
  5180. * Dport enable
  5181. *
  5182. * @param[in] *bfa - bfa data struct
  5183. */
  5184. bfa_status_t
  5185. bfa_dport_enable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg)
  5186. {
  5187. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5188. struct bfa_dport_s *dport = &fcdiag->dport;
  5189. /*
  5190. * Dport is not support in MEZZ card
  5191. */
  5192. if (bfa_mfg_is_mezz(dport->bfa->ioc.attr->card_type)) {
  5193. bfa_trc(dport->bfa, BFA_STATUS_PBC);
  5194. return BFA_STATUS_CMD_NOTSUPP_MEZZ;
  5195. }
  5196. /*
  5197. * Check to see if IOC is down
  5198. */
  5199. if (!bfa_iocfc_is_operational(bfa))
  5200. return BFA_STATUS_IOC_NON_OP;
  5201. /* if port is PBC disabled, return error */
  5202. if (bfa_fcport_is_pbcdisabled(bfa)) {
  5203. bfa_trc(dport->bfa, BFA_STATUS_PBC);
  5204. return BFA_STATUS_PBC;
  5205. }
  5206. /*
  5207. * Check if port mode is FC port
  5208. */
  5209. if (bfa_ioc_get_type(&bfa->ioc) != BFA_IOC_TYPE_FC) {
  5210. bfa_trc(dport->bfa, bfa_ioc_get_type(&bfa->ioc));
  5211. return BFA_STATUS_CMD_NOTSUPP_CNA;
  5212. }
  5213. /*
  5214. * Check if port is in LOOP mode
  5215. */
  5216. if ((bfa_fcport_get_cfg_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) ||
  5217. (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)) {
  5218. bfa_trc(dport->bfa, 0);
  5219. return BFA_STATUS_TOPOLOGY_LOOP;
  5220. }
  5221. /*
  5222. * Check if port is TRUNK mode
  5223. */
  5224. if (bfa_fcport_is_trunk_enabled(bfa)) {
  5225. bfa_trc(dport->bfa, 0);
  5226. return BFA_STATUS_ERROR_TRUNK_ENABLED;
  5227. }
  5228. /*
  5229. * Check to see if port is disable or in dport state
  5230. */
  5231. if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
  5232. (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
  5233. bfa_trc(dport->bfa, 0);
  5234. return BFA_STATUS_PORT_NOT_DISABLED;
  5235. }
  5236. /*
  5237. * Check if dport is busy
  5238. */
  5239. if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
  5240. bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) ||
  5241. bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
  5242. bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait)) {
  5243. return BFA_STATUS_DEVBUSY;
  5244. }
  5245. /*
  5246. * Check if dport is already enabled
  5247. */
  5248. if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
  5249. bfa_trc(dport->bfa, 0);
  5250. return BFA_STATUS_DPORT_ENABLED;
  5251. }
  5252. dport->cbfn = cbfn;
  5253. dport->cbarg = cbarg;
  5254. bfa_sm_send_event(dport, BFA_DPORT_SM_ENABLE);
  5255. return BFA_STATUS_OK;
  5256. }
  5257. /*
  5258. * Dport disable
  5259. *
  5260. * @param[in] *bfa - bfa data struct
  5261. */
  5262. bfa_status_t
  5263. bfa_dport_disable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg)
  5264. {
  5265. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5266. struct bfa_dport_s *dport = &fcdiag->dport;
  5267. if (bfa_ioc_is_disabled(&bfa->ioc))
  5268. return BFA_STATUS_IOC_DISABLED;
  5269. /* if port is PBC disabled, return error */
  5270. if (bfa_fcport_is_pbcdisabled(bfa)) {
  5271. bfa_trc(dport->bfa, BFA_STATUS_PBC);
  5272. return BFA_STATUS_PBC;
  5273. }
  5274. /*
  5275. * Check to see if port is disable or in dport state
  5276. */
  5277. if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
  5278. (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
  5279. bfa_trc(dport->bfa, 0);
  5280. return BFA_STATUS_PORT_NOT_DISABLED;
  5281. }
  5282. /*
  5283. * Check if dport is busy
  5284. */
  5285. if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
  5286. bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) ||
  5287. bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
  5288. bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait))
  5289. return BFA_STATUS_DEVBUSY;
  5290. /*
  5291. * Check if dport is already disabled
  5292. */
  5293. if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled)) {
  5294. bfa_trc(dport->bfa, 0);
  5295. return BFA_STATUS_DPORT_DISABLED;
  5296. }
  5297. dport->cbfn = cbfn;
  5298. dport->cbarg = cbarg;
  5299. bfa_sm_send_event(dport, BFA_DPORT_SM_DISABLE);
  5300. return BFA_STATUS_OK;
  5301. }
  5302. /*
  5303. * Get D-port state
  5304. *
  5305. * @param[in] *bfa - bfa data struct
  5306. */
  5307. bfa_status_t
  5308. bfa_dport_get_state(struct bfa_s *bfa, enum bfa_dport_state *state)
  5309. {
  5310. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5311. struct bfa_dport_s *dport = &fcdiag->dport;
  5312. if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled))
  5313. *state = BFA_DPORT_ST_ENABLED;
  5314. else if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
  5315. bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait))
  5316. *state = BFA_DPORT_ST_ENABLING;
  5317. else if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled))
  5318. *state = BFA_DPORT_ST_DISABLED;
  5319. else if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
  5320. bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait))
  5321. *state = BFA_DPORT_ST_DISABLING;
  5322. else {
  5323. bfa_trc(dport->bfa, BFA_STATUS_EINVAL);
  5324. return BFA_STATUS_EINVAL;
  5325. }
  5326. return BFA_STATUS_OK;
  5327. }