bfa_svc.c 165 KB

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