bfa_svc.c 116 KB

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