bfa_svc.c 135 KB

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