bfa_svc.c 167 KB

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