bfa_svc.c 162 KB

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