bfa_svc.c 152 KB

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