bfa_svc.c 163 KB

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