bna_ctrl.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261
  1. /*
  2. * Linux network driver for Brocade Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #include "bna.h"
  19. #include "bfa_sm.h"
  20. #include "bfa_wc.h"
  21. static void bna_device_cb_port_stopped(void *arg, enum bna_cb_status status);
  22. static void
  23. bna_port_cb_link_up(struct bna_port *port, struct bfi_ll_aen *aen,
  24. int status)
  25. {
  26. int i;
  27. u8 prio_map;
  28. port->llport.link_status = BNA_LINK_UP;
  29. if (aen->cee_linkup)
  30. port->llport.link_status = BNA_CEE_UP;
  31. /* Compute the priority */
  32. prio_map = aen->prio_map;
  33. if (prio_map) {
  34. for (i = 0; i < 8; i++) {
  35. if ((prio_map >> i) & 0x1)
  36. break;
  37. }
  38. port->priority = i;
  39. } else
  40. port->priority = 0;
  41. /* Dispatch events */
  42. bna_tx_mod_cee_link_status(&port->bna->tx_mod, aen->cee_linkup);
  43. bna_tx_mod_prio_changed(&port->bna->tx_mod, port->priority);
  44. port->link_cbfn(port->bna->bnad, port->llport.link_status);
  45. }
  46. static void
  47. bna_port_cb_link_down(struct bna_port *port, int status)
  48. {
  49. port->llport.link_status = BNA_LINK_DOWN;
  50. /* Dispatch events */
  51. bna_tx_mod_cee_link_status(&port->bna->tx_mod, BNA_LINK_DOWN);
  52. port->link_cbfn(port->bna->bnad, BNA_LINK_DOWN);
  53. }
  54. /**
  55. * MBOX
  56. */
  57. static int
  58. bna_is_aen(u8 msg_id)
  59. {
  60. return msg_id == BFI_LL_I2H_LINK_DOWN_AEN ||
  61. msg_id == BFI_LL_I2H_LINK_UP_AEN;
  62. }
  63. static void
  64. bna_mbox_aen_callback(struct bna *bna, struct bfi_mbmsg *msg)
  65. {
  66. struct bfi_ll_aen *aen = (struct bfi_ll_aen *)(msg);
  67. switch (aen->mh.msg_id) {
  68. case BFI_LL_I2H_LINK_UP_AEN:
  69. bna_port_cb_link_up(&bna->port, aen, aen->reason);
  70. break;
  71. case BFI_LL_I2H_LINK_DOWN_AEN:
  72. bna_port_cb_link_down(&bna->port, aen->reason);
  73. break;
  74. default:
  75. break;
  76. }
  77. }
  78. static void
  79. bna_ll_isr(void *llarg, struct bfi_mbmsg *msg)
  80. {
  81. struct bna *bna = (struct bna *)(llarg);
  82. struct bfi_ll_rsp *mb_rsp = (struct bfi_ll_rsp *)(msg);
  83. struct bfi_mhdr *cmd_h, *rsp_h;
  84. struct bna_mbox_qe *mb_qe = NULL;
  85. int to_post = 0;
  86. u8 aen = 0;
  87. char message[BNA_MESSAGE_SIZE];
  88. aen = bna_is_aen(mb_rsp->mh.msg_id);
  89. if (!aen) {
  90. mb_qe = bfa_q_first(&bna->mbox_mod.posted_q);
  91. cmd_h = (struct bfi_mhdr *)(&mb_qe->cmd.msg[0]);
  92. rsp_h = (struct bfi_mhdr *)(&mb_rsp->mh);
  93. if ((BFA_I2HM(cmd_h->msg_id) == rsp_h->msg_id) &&
  94. (cmd_h->mtag.i2htok == rsp_h->mtag.i2htok)) {
  95. /* Remove the request from posted_q, update state */
  96. list_del(&mb_qe->qe);
  97. bna->mbox_mod.msg_pending--;
  98. if (list_empty(&bna->mbox_mod.posted_q))
  99. bna->mbox_mod.state = BNA_MBOX_FREE;
  100. else
  101. to_post = 1;
  102. /* Dispatch the cbfn */
  103. if (mb_qe->cbfn)
  104. mb_qe->cbfn(mb_qe->cbarg, mb_rsp->error);
  105. /* Post the next entry, if needed */
  106. if (to_post) {
  107. mb_qe = bfa_q_first(&bna->mbox_mod.posted_q);
  108. bfa_nw_ioc_mbox_queue(&bna->device.ioc,
  109. &mb_qe->cmd);
  110. }
  111. } else {
  112. snprintf(message, BNA_MESSAGE_SIZE,
  113. "No matching rsp for [%d:%d:%d]\n",
  114. mb_rsp->mh.msg_class, mb_rsp->mh.msg_id,
  115. mb_rsp->mh.mtag.i2htok);
  116. pr_info("%s", message);
  117. }
  118. } else
  119. bna_mbox_aen_callback(bna, msg);
  120. }
  121. static void
  122. bna_err_handler(struct bna *bna, u32 intr_status)
  123. {
  124. u32 init_halt;
  125. if (intr_status & __HALT_STATUS_BITS) {
  126. init_halt = readl(bna->device.ioc.ioc_regs.ll_halt);
  127. init_halt &= ~__FW_INIT_HALT_P;
  128. writel(init_halt, bna->device.ioc.ioc_regs.ll_halt);
  129. }
  130. bfa_nw_ioc_error_isr(&bna->device.ioc);
  131. }
  132. void
  133. bna_mbox_handler(struct bna *bna, u32 intr_status)
  134. {
  135. if (BNA_IS_ERR_INTR(intr_status)) {
  136. bna_err_handler(bna, intr_status);
  137. return;
  138. }
  139. if (BNA_IS_MBOX_INTR(intr_status))
  140. bfa_nw_ioc_mbox_isr(&bna->device.ioc);
  141. }
  142. void
  143. bna_mbox_send(struct bna *bna, struct bna_mbox_qe *mbox_qe)
  144. {
  145. struct bfi_mhdr *mh;
  146. mh = (struct bfi_mhdr *)(&mbox_qe->cmd.msg[0]);
  147. mh->mtag.i2htok = htons(bna->mbox_mod.msg_ctr);
  148. bna->mbox_mod.msg_ctr++;
  149. bna->mbox_mod.msg_pending++;
  150. if (bna->mbox_mod.state == BNA_MBOX_FREE) {
  151. list_add_tail(&mbox_qe->qe, &bna->mbox_mod.posted_q);
  152. bfa_nw_ioc_mbox_queue(&bna->device.ioc, &mbox_qe->cmd);
  153. bna->mbox_mod.state = BNA_MBOX_POSTED;
  154. } else {
  155. list_add_tail(&mbox_qe->qe, &bna->mbox_mod.posted_q);
  156. }
  157. }
  158. static void
  159. bna_mbox_flush_q(struct bna *bna, struct list_head *q)
  160. {
  161. struct bna_mbox_qe *mb_qe = NULL;
  162. struct bfi_mhdr *cmd_h;
  163. struct list_head *mb_q;
  164. void (*cbfn)(void *arg, int status);
  165. void *cbarg;
  166. mb_q = &bna->mbox_mod.posted_q;
  167. while (!list_empty(mb_q)) {
  168. bfa_q_deq(mb_q, &mb_qe);
  169. cbfn = mb_qe->cbfn;
  170. cbarg = mb_qe->cbarg;
  171. bfa_q_qe_init(mb_qe);
  172. bna->mbox_mod.msg_pending--;
  173. cmd_h = (struct bfi_mhdr *)(&mb_qe->cmd.msg[0]);
  174. if (cbfn)
  175. cbfn(cbarg, BNA_CB_NOT_EXEC);
  176. }
  177. bna->mbox_mod.state = BNA_MBOX_FREE;
  178. }
  179. static void
  180. bna_mbox_mod_start(struct bna_mbox_mod *mbox_mod)
  181. {
  182. }
  183. static void
  184. bna_mbox_mod_stop(struct bna_mbox_mod *mbox_mod)
  185. {
  186. bna_mbox_flush_q(mbox_mod->bna, &mbox_mod->posted_q);
  187. }
  188. static void
  189. bna_mbox_mod_init(struct bna_mbox_mod *mbox_mod, struct bna *bna)
  190. {
  191. bfa_nw_ioc_mbox_regisr(&bna->device.ioc, BFI_MC_LL, bna_ll_isr, bna);
  192. mbox_mod->state = BNA_MBOX_FREE;
  193. mbox_mod->msg_ctr = mbox_mod->msg_pending = 0;
  194. INIT_LIST_HEAD(&mbox_mod->posted_q);
  195. mbox_mod->bna = bna;
  196. }
  197. static void
  198. bna_mbox_mod_uninit(struct bna_mbox_mod *mbox_mod)
  199. {
  200. mbox_mod->bna = NULL;
  201. }
  202. /**
  203. * LLPORT
  204. */
  205. #define call_llport_stop_cbfn(llport, status)\
  206. do {\
  207. if ((llport)->stop_cbfn)\
  208. (llport)->stop_cbfn(&(llport)->bna->port, status);\
  209. (llport)->stop_cbfn = NULL;\
  210. } while (0)
  211. static void bna_fw_llport_up(struct bna_llport *llport);
  212. static void bna_fw_cb_llport_up(void *arg, int status);
  213. static void bna_fw_llport_down(struct bna_llport *llport);
  214. static void bna_fw_cb_llport_down(void *arg, int status);
  215. static void bna_llport_start(struct bna_llport *llport);
  216. static void bna_llport_stop(struct bna_llport *llport);
  217. static void bna_llport_fail(struct bna_llport *llport);
  218. enum bna_llport_event {
  219. LLPORT_E_START = 1,
  220. LLPORT_E_STOP = 2,
  221. LLPORT_E_FAIL = 3,
  222. LLPORT_E_UP = 4,
  223. LLPORT_E_DOWN = 5,
  224. LLPORT_E_FWRESP_UP = 6,
  225. LLPORT_E_FWRESP_DOWN = 7
  226. };
  227. enum bna_llport_state {
  228. BNA_LLPORT_STOPPED = 1,
  229. BNA_LLPORT_DOWN = 2,
  230. BNA_LLPORT_UP_RESP_WAIT = 3,
  231. BNA_LLPORT_DOWN_RESP_WAIT = 4,
  232. BNA_LLPORT_UP = 5,
  233. BNA_LLPORT_LAST_RESP_WAIT = 6
  234. };
  235. bfa_fsm_state_decl(bna_llport, stopped, struct bna_llport,
  236. enum bna_llport_event);
  237. bfa_fsm_state_decl(bna_llport, down, struct bna_llport,
  238. enum bna_llport_event);
  239. bfa_fsm_state_decl(bna_llport, up_resp_wait, struct bna_llport,
  240. enum bna_llport_event);
  241. bfa_fsm_state_decl(bna_llport, down_resp_wait, struct bna_llport,
  242. enum bna_llport_event);
  243. bfa_fsm_state_decl(bna_llport, up, struct bna_llport,
  244. enum bna_llport_event);
  245. bfa_fsm_state_decl(bna_llport, last_resp_wait, struct bna_llport,
  246. enum bna_llport_event);
  247. static struct bfa_sm_table llport_sm_table[] = {
  248. {BFA_SM(bna_llport_sm_stopped), BNA_LLPORT_STOPPED},
  249. {BFA_SM(bna_llport_sm_down), BNA_LLPORT_DOWN},
  250. {BFA_SM(bna_llport_sm_up_resp_wait), BNA_LLPORT_UP_RESP_WAIT},
  251. {BFA_SM(bna_llport_sm_down_resp_wait), BNA_LLPORT_DOWN_RESP_WAIT},
  252. {BFA_SM(bna_llport_sm_up), BNA_LLPORT_UP},
  253. {BFA_SM(bna_llport_sm_last_resp_wait), BNA_LLPORT_LAST_RESP_WAIT}
  254. };
  255. static void
  256. bna_llport_sm_stopped_entry(struct bna_llport *llport)
  257. {
  258. llport->bna->port.link_cbfn((llport)->bna->bnad, BNA_LINK_DOWN);
  259. call_llport_stop_cbfn(llport, BNA_CB_SUCCESS);
  260. }
  261. static void
  262. bna_llport_sm_stopped(struct bna_llport *llport,
  263. enum bna_llport_event event)
  264. {
  265. switch (event) {
  266. case LLPORT_E_START:
  267. bfa_fsm_set_state(llport, bna_llport_sm_down);
  268. break;
  269. case LLPORT_E_STOP:
  270. call_llport_stop_cbfn(llport, BNA_CB_SUCCESS);
  271. break;
  272. case LLPORT_E_FAIL:
  273. break;
  274. case LLPORT_E_DOWN:
  275. /* This event is received due to Rx objects failing */
  276. /* No-op */
  277. break;
  278. case LLPORT_E_FWRESP_UP:
  279. case LLPORT_E_FWRESP_DOWN:
  280. /**
  281. * These events are received due to flushing of mbox when
  282. * device fails
  283. */
  284. /* No-op */
  285. break;
  286. default:
  287. bfa_sm_fault(llport->bna, event);
  288. }
  289. }
  290. static void
  291. bna_llport_sm_down_entry(struct bna_llport *llport)
  292. {
  293. bnad_cb_port_link_status((llport)->bna->bnad, BNA_LINK_DOWN);
  294. }
  295. static void
  296. bna_llport_sm_down(struct bna_llport *llport,
  297. enum bna_llport_event event)
  298. {
  299. switch (event) {
  300. case LLPORT_E_STOP:
  301. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  302. break;
  303. case LLPORT_E_FAIL:
  304. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  305. break;
  306. case LLPORT_E_UP:
  307. bfa_fsm_set_state(llport, bna_llport_sm_up_resp_wait);
  308. bna_fw_llport_up(llport);
  309. break;
  310. default:
  311. bfa_sm_fault(llport->bna, event);
  312. }
  313. }
  314. static void
  315. bna_llport_sm_up_resp_wait_entry(struct bna_llport *llport)
  316. {
  317. /**
  318. * NOTE: Do not call bna_fw_llport_up() here. That will over step
  319. * mbox due to down_resp_wait -> up_resp_wait transition on event
  320. * LLPORT_E_UP
  321. */
  322. }
  323. static void
  324. bna_llport_sm_up_resp_wait(struct bna_llport *llport,
  325. enum bna_llport_event event)
  326. {
  327. switch (event) {
  328. case LLPORT_E_STOP:
  329. bfa_fsm_set_state(llport, bna_llport_sm_last_resp_wait);
  330. break;
  331. case LLPORT_E_FAIL:
  332. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  333. break;
  334. case LLPORT_E_DOWN:
  335. bfa_fsm_set_state(llport, bna_llport_sm_down_resp_wait);
  336. break;
  337. case LLPORT_E_FWRESP_UP:
  338. bfa_fsm_set_state(llport, bna_llport_sm_up);
  339. break;
  340. case LLPORT_E_FWRESP_DOWN:
  341. /* down_resp_wait -> up_resp_wait transition on LLPORT_E_UP */
  342. bna_fw_llport_up(llport);
  343. break;
  344. default:
  345. bfa_sm_fault(llport->bna, event);
  346. }
  347. }
  348. static void
  349. bna_llport_sm_down_resp_wait_entry(struct bna_llport *llport)
  350. {
  351. /**
  352. * NOTE: Do not call bna_fw_llport_down() here. That will over step
  353. * mbox due to up_resp_wait -> down_resp_wait transition on event
  354. * LLPORT_E_DOWN
  355. */
  356. }
  357. static void
  358. bna_llport_sm_down_resp_wait(struct bna_llport *llport,
  359. enum bna_llport_event event)
  360. {
  361. switch (event) {
  362. case LLPORT_E_STOP:
  363. bfa_fsm_set_state(llport, bna_llport_sm_last_resp_wait);
  364. break;
  365. case LLPORT_E_FAIL:
  366. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  367. break;
  368. case LLPORT_E_UP:
  369. bfa_fsm_set_state(llport, bna_llport_sm_up_resp_wait);
  370. break;
  371. case LLPORT_E_FWRESP_UP:
  372. /* up_resp_wait->down_resp_wait transition on LLPORT_E_DOWN */
  373. bna_fw_llport_down(llport);
  374. break;
  375. case LLPORT_E_FWRESP_DOWN:
  376. bfa_fsm_set_state(llport, bna_llport_sm_down);
  377. break;
  378. default:
  379. bfa_sm_fault(llport->bna, event);
  380. }
  381. }
  382. static void
  383. bna_llport_sm_up_entry(struct bna_llport *llport)
  384. {
  385. }
  386. static void
  387. bna_llport_sm_up(struct bna_llport *llport,
  388. enum bna_llport_event event)
  389. {
  390. switch (event) {
  391. case LLPORT_E_STOP:
  392. bfa_fsm_set_state(llport, bna_llport_sm_last_resp_wait);
  393. bna_fw_llport_down(llport);
  394. break;
  395. case LLPORT_E_FAIL:
  396. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  397. break;
  398. case LLPORT_E_DOWN:
  399. bfa_fsm_set_state(llport, bna_llport_sm_down_resp_wait);
  400. bna_fw_llport_down(llport);
  401. break;
  402. default:
  403. bfa_sm_fault(llport->bna, event);
  404. }
  405. }
  406. static void
  407. bna_llport_sm_last_resp_wait_entry(struct bna_llport *llport)
  408. {
  409. }
  410. static void
  411. bna_llport_sm_last_resp_wait(struct bna_llport *llport,
  412. enum bna_llport_event event)
  413. {
  414. switch (event) {
  415. case LLPORT_E_FAIL:
  416. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  417. break;
  418. case LLPORT_E_DOWN:
  419. /**
  420. * This event is received due to Rx objects stopping in
  421. * parallel to llport
  422. */
  423. /* No-op */
  424. break;
  425. case LLPORT_E_FWRESP_UP:
  426. /* up_resp_wait->last_resp_wait transition on LLPORT_T_STOP */
  427. bna_fw_llport_down(llport);
  428. break;
  429. case LLPORT_E_FWRESP_DOWN:
  430. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  431. break;
  432. default:
  433. bfa_sm_fault(llport->bna, event);
  434. }
  435. }
  436. static void
  437. bna_fw_llport_admin_up(struct bna_llport *llport)
  438. {
  439. struct bfi_ll_port_admin_req ll_req;
  440. memset(&ll_req, 0, sizeof(ll_req));
  441. ll_req.mh.msg_class = BFI_MC_LL;
  442. ll_req.mh.msg_id = BFI_LL_H2I_PORT_ADMIN_REQ;
  443. ll_req.mh.mtag.h2i.lpu_id = 0;
  444. ll_req.up = BNA_STATUS_T_ENABLED;
  445. bna_mbox_qe_fill(&llport->mbox_qe, &ll_req, sizeof(ll_req),
  446. bna_fw_cb_llport_up, llport);
  447. bna_mbox_send(llport->bna, &llport->mbox_qe);
  448. }
  449. static void
  450. bna_fw_llport_up(struct bna_llport *llport)
  451. {
  452. if (llport->type == BNA_PORT_T_REGULAR)
  453. bna_fw_llport_admin_up(llport);
  454. }
  455. static void
  456. bna_fw_cb_llport_up(void *arg, int status)
  457. {
  458. struct bna_llport *llport = (struct bna_llport *)arg;
  459. bfa_q_qe_init(&llport->mbox_qe.qe);
  460. bfa_fsm_send_event(llport, LLPORT_E_FWRESP_UP);
  461. }
  462. static void
  463. bna_fw_llport_admin_down(struct bna_llport *llport)
  464. {
  465. struct bfi_ll_port_admin_req ll_req;
  466. memset(&ll_req, 0, sizeof(ll_req));
  467. ll_req.mh.msg_class = BFI_MC_LL;
  468. ll_req.mh.msg_id = BFI_LL_H2I_PORT_ADMIN_REQ;
  469. ll_req.mh.mtag.h2i.lpu_id = 0;
  470. ll_req.up = BNA_STATUS_T_DISABLED;
  471. bna_mbox_qe_fill(&llport->mbox_qe, &ll_req, sizeof(ll_req),
  472. bna_fw_cb_llport_down, llport);
  473. bna_mbox_send(llport->bna, &llport->mbox_qe);
  474. }
  475. static void
  476. bna_fw_llport_down(struct bna_llport *llport)
  477. {
  478. if (llport->type == BNA_PORT_T_REGULAR)
  479. bna_fw_llport_admin_down(llport);
  480. }
  481. static void
  482. bna_fw_cb_llport_down(void *arg, int status)
  483. {
  484. struct bna_llport *llport = (struct bna_llport *)arg;
  485. bfa_q_qe_init(&llport->mbox_qe.qe);
  486. bfa_fsm_send_event(llport, LLPORT_E_FWRESP_DOWN);
  487. }
  488. static void
  489. bna_port_cb_llport_stopped(struct bna_port *port,
  490. enum bna_cb_status status)
  491. {
  492. bfa_wc_down(&port->chld_stop_wc);
  493. }
  494. static void
  495. bna_llport_init(struct bna_llport *llport, struct bna *bna)
  496. {
  497. llport->flags |= BNA_LLPORT_F_ENABLED;
  498. llport->type = BNA_PORT_T_REGULAR;
  499. llport->bna = bna;
  500. llport->link_status = BNA_LINK_DOWN;
  501. llport->admin_up_count = 0;
  502. llport->stop_cbfn = NULL;
  503. bfa_q_qe_init(&llport->mbox_qe.qe);
  504. bfa_fsm_set_state(llport, bna_llport_sm_stopped);
  505. }
  506. static void
  507. bna_llport_uninit(struct bna_llport *llport)
  508. {
  509. llport->flags &= ~BNA_LLPORT_F_ENABLED;
  510. llport->bna = NULL;
  511. }
  512. static void
  513. bna_llport_start(struct bna_llport *llport)
  514. {
  515. bfa_fsm_send_event(llport, LLPORT_E_START);
  516. }
  517. static void
  518. bna_llport_stop(struct bna_llport *llport)
  519. {
  520. llport->stop_cbfn = bna_port_cb_llport_stopped;
  521. bfa_fsm_send_event(llport, LLPORT_E_STOP);
  522. }
  523. static void
  524. bna_llport_fail(struct bna_llport *llport)
  525. {
  526. bfa_fsm_send_event(llport, LLPORT_E_FAIL);
  527. }
  528. static int
  529. bna_llport_state_get(struct bna_llport *llport)
  530. {
  531. return bfa_sm_to_state(llport_sm_table, llport->fsm);
  532. }
  533. void
  534. bna_llport_admin_up(struct bna_llport *llport)
  535. {
  536. llport->admin_up_count++;
  537. if (llport->admin_up_count == 1) {
  538. llport->flags |= BNA_LLPORT_F_RX_ENABLED;
  539. if (llport->flags & BNA_LLPORT_F_ENABLED)
  540. bfa_fsm_send_event(llport, LLPORT_E_UP);
  541. }
  542. }
  543. void
  544. bna_llport_admin_down(struct bna_llport *llport)
  545. {
  546. llport->admin_up_count--;
  547. if (llport->admin_up_count == 0) {
  548. llport->flags &= ~BNA_LLPORT_F_RX_ENABLED;
  549. if (llport->flags & BNA_LLPORT_F_ENABLED)
  550. bfa_fsm_send_event(llport, LLPORT_E_DOWN);
  551. }
  552. }
  553. /**
  554. * PORT
  555. */
  556. #define bna_port_chld_start(port)\
  557. do {\
  558. enum bna_tx_type tx_type = ((port)->type == BNA_PORT_T_REGULAR) ?\
  559. BNA_TX_T_REGULAR : BNA_TX_T_LOOPBACK;\
  560. enum bna_rx_type rx_type = ((port)->type == BNA_PORT_T_REGULAR) ?\
  561. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK;\
  562. bna_llport_start(&(port)->llport);\
  563. bna_tx_mod_start(&(port)->bna->tx_mod, tx_type);\
  564. bna_rx_mod_start(&(port)->bna->rx_mod, rx_type);\
  565. } while (0)
  566. #define bna_port_chld_stop(port)\
  567. do {\
  568. enum bna_tx_type tx_type = ((port)->type == BNA_PORT_T_REGULAR) ?\
  569. BNA_TX_T_REGULAR : BNA_TX_T_LOOPBACK;\
  570. enum bna_rx_type rx_type = ((port)->type == BNA_PORT_T_REGULAR) ?\
  571. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK;\
  572. bfa_wc_up(&(port)->chld_stop_wc);\
  573. bfa_wc_up(&(port)->chld_stop_wc);\
  574. bfa_wc_up(&(port)->chld_stop_wc);\
  575. bna_llport_stop(&(port)->llport);\
  576. bna_tx_mod_stop(&(port)->bna->tx_mod, tx_type);\
  577. bna_rx_mod_stop(&(port)->bna->rx_mod, rx_type);\
  578. } while (0)
  579. #define bna_port_chld_fail(port)\
  580. do {\
  581. bna_llport_fail(&(port)->llport);\
  582. bna_tx_mod_fail(&(port)->bna->tx_mod);\
  583. bna_rx_mod_fail(&(port)->bna->rx_mod);\
  584. } while (0)
  585. #define bna_port_rx_start(port)\
  586. do {\
  587. enum bna_rx_type rx_type = ((port)->type == BNA_PORT_T_REGULAR) ?\
  588. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK;\
  589. bna_rx_mod_start(&(port)->bna->rx_mod, rx_type);\
  590. } while (0)
  591. #define bna_port_rx_stop(port)\
  592. do {\
  593. enum bna_rx_type rx_type = ((port)->type == BNA_PORT_T_REGULAR) ?\
  594. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK;\
  595. bfa_wc_up(&(port)->chld_stop_wc);\
  596. bna_rx_mod_stop(&(port)->bna->rx_mod, rx_type);\
  597. } while (0)
  598. #define call_port_stop_cbfn(port, status)\
  599. do {\
  600. if ((port)->stop_cbfn)\
  601. (port)->stop_cbfn((port)->stop_cbarg, status);\
  602. (port)->stop_cbfn = NULL;\
  603. (port)->stop_cbarg = NULL;\
  604. } while (0)
  605. #define call_port_pause_cbfn(port, status)\
  606. do {\
  607. if ((port)->pause_cbfn)\
  608. (port)->pause_cbfn((port)->bna->bnad, status);\
  609. (port)->pause_cbfn = NULL;\
  610. } while (0)
  611. #define call_port_mtu_cbfn(port, status)\
  612. do {\
  613. if ((port)->mtu_cbfn)\
  614. (port)->mtu_cbfn((port)->bna->bnad, status);\
  615. (port)->mtu_cbfn = NULL;\
  616. } while (0)
  617. static void bna_fw_pause_set(struct bna_port *port);
  618. static void bna_fw_cb_pause_set(void *arg, int status);
  619. static void bna_fw_mtu_set(struct bna_port *port);
  620. static void bna_fw_cb_mtu_set(void *arg, int status);
  621. enum bna_port_event {
  622. PORT_E_START = 1,
  623. PORT_E_STOP = 2,
  624. PORT_E_FAIL = 3,
  625. PORT_E_PAUSE_CFG = 4,
  626. PORT_E_MTU_CFG = 5,
  627. PORT_E_CHLD_STOPPED = 6,
  628. PORT_E_FWRESP_PAUSE = 7,
  629. PORT_E_FWRESP_MTU = 8
  630. };
  631. enum bna_port_state {
  632. BNA_PORT_STOPPED = 1,
  633. BNA_PORT_MTU_INIT_WAIT = 2,
  634. BNA_PORT_PAUSE_INIT_WAIT = 3,
  635. BNA_PORT_LAST_RESP_WAIT = 4,
  636. BNA_PORT_STARTED = 5,
  637. BNA_PORT_PAUSE_CFG_WAIT = 6,
  638. BNA_PORT_RX_STOP_WAIT = 7,
  639. BNA_PORT_MTU_CFG_WAIT = 8,
  640. BNA_PORT_CHLD_STOP_WAIT = 9
  641. };
  642. bfa_fsm_state_decl(bna_port, stopped, struct bna_port,
  643. enum bna_port_event);
  644. bfa_fsm_state_decl(bna_port, mtu_init_wait, struct bna_port,
  645. enum bna_port_event);
  646. bfa_fsm_state_decl(bna_port, pause_init_wait, struct bna_port,
  647. enum bna_port_event);
  648. bfa_fsm_state_decl(bna_port, last_resp_wait, struct bna_port,
  649. enum bna_port_event);
  650. bfa_fsm_state_decl(bna_port, started, struct bna_port,
  651. enum bna_port_event);
  652. bfa_fsm_state_decl(bna_port, pause_cfg_wait, struct bna_port,
  653. enum bna_port_event);
  654. bfa_fsm_state_decl(bna_port, rx_stop_wait, struct bna_port,
  655. enum bna_port_event);
  656. bfa_fsm_state_decl(bna_port, mtu_cfg_wait, struct bna_port,
  657. enum bna_port_event);
  658. bfa_fsm_state_decl(bna_port, chld_stop_wait, struct bna_port,
  659. enum bna_port_event);
  660. static struct bfa_sm_table port_sm_table[] = {
  661. {BFA_SM(bna_port_sm_stopped), BNA_PORT_STOPPED},
  662. {BFA_SM(bna_port_sm_mtu_init_wait), BNA_PORT_MTU_INIT_WAIT},
  663. {BFA_SM(bna_port_sm_pause_init_wait), BNA_PORT_PAUSE_INIT_WAIT},
  664. {BFA_SM(bna_port_sm_last_resp_wait), BNA_PORT_LAST_RESP_WAIT},
  665. {BFA_SM(bna_port_sm_started), BNA_PORT_STARTED},
  666. {BFA_SM(bna_port_sm_pause_cfg_wait), BNA_PORT_PAUSE_CFG_WAIT},
  667. {BFA_SM(bna_port_sm_rx_stop_wait), BNA_PORT_RX_STOP_WAIT},
  668. {BFA_SM(bna_port_sm_mtu_cfg_wait), BNA_PORT_MTU_CFG_WAIT},
  669. {BFA_SM(bna_port_sm_chld_stop_wait), BNA_PORT_CHLD_STOP_WAIT}
  670. };
  671. static void
  672. bna_port_sm_stopped_entry(struct bna_port *port)
  673. {
  674. call_port_pause_cbfn(port, BNA_CB_SUCCESS);
  675. call_port_mtu_cbfn(port, BNA_CB_SUCCESS);
  676. call_port_stop_cbfn(port, BNA_CB_SUCCESS);
  677. }
  678. static void
  679. bna_port_sm_stopped(struct bna_port *port, enum bna_port_event event)
  680. {
  681. switch (event) {
  682. case PORT_E_START:
  683. bfa_fsm_set_state(port, bna_port_sm_mtu_init_wait);
  684. break;
  685. case PORT_E_STOP:
  686. call_port_stop_cbfn(port, BNA_CB_SUCCESS);
  687. break;
  688. case PORT_E_FAIL:
  689. /* No-op */
  690. break;
  691. case PORT_E_PAUSE_CFG:
  692. call_port_pause_cbfn(port, BNA_CB_SUCCESS);
  693. break;
  694. case PORT_E_MTU_CFG:
  695. call_port_mtu_cbfn(port, BNA_CB_SUCCESS);
  696. break;
  697. case PORT_E_CHLD_STOPPED:
  698. /**
  699. * This event is received due to LLPort, Tx and Rx objects
  700. * failing
  701. */
  702. /* No-op */
  703. break;
  704. case PORT_E_FWRESP_PAUSE:
  705. case PORT_E_FWRESP_MTU:
  706. /**
  707. * These events are received due to flushing of mbox when
  708. * device fails
  709. */
  710. /* No-op */
  711. break;
  712. default:
  713. bfa_sm_fault(port->bna, event);
  714. }
  715. }
  716. static void
  717. bna_port_sm_mtu_init_wait_entry(struct bna_port *port)
  718. {
  719. bna_fw_mtu_set(port);
  720. }
  721. static void
  722. bna_port_sm_mtu_init_wait(struct bna_port *port, enum bna_port_event event)
  723. {
  724. switch (event) {
  725. case PORT_E_STOP:
  726. bfa_fsm_set_state(port, bna_port_sm_last_resp_wait);
  727. break;
  728. case PORT_E_FAIL:
  729. bfa_fsm_set_state(port, bna_port_sm_stopped);
  730. break;
  731. case PORT_E_PAUSE_CFG:
  732. /* No-op */
  733. break;
  734. case PORT_E_MTU_CFG:
  735. port->flags |= BNA_PORT_F_MTU_CHANGED;
  736. break;
  737. case PORT_E_FWRESP_MTU:
  738. if (port->flags & BNA_PORT_F_MTU_CHANGED) {
  739. port->flags &= ~BNA_PORT_F_MTU_CHANGED;
  740. bna_fw_mtu_set(port);
  741. } else {
  742. bfa_fsm_set_state(port, bna_port_sm_pause_init_wait);
  743. }
  744. break;
  745. default:
  746. bfa_sm_fault(port->bna, event);
  747. }
  748. }
  749. static void
  750. bna_port_sm_pause_init_wait_entry(struct bna_port *port)
  751. {
  752. bna_fw_pause_set(port);
  753. }
  754. static void
  755. bna_port_sm_pause_init_wait(struct bna_port *port,
  756. enum bna_port_event event)
  757. {
  758. switch (event) {
  759. case PORT_E_STOP:
  760. bfa_fsm_set_state(port, bna_port_sm_last_resp_wait);
  761. break;
  762. case PORT_E_FAIL:
  763. bfa_fsm_set_state(port, bna_port_sm_stopped);
  764. break;
  765. case PORT_E_PAUSE_CFG:
  766. port->flags |= BNA_PORT_F_PAUSE_CHANGED;
  767. break;
  768. case PORT_E_MTU_CFG:
  769. port->flags |= BNA_PORT_F_MTU_CHANGED;
  770. break;
  771. case PORT_E_FWRESP_PAUSE:
  772. if (port->flags & BNA_PORT_F_PAUSE_CHANGED) {
  773. port->flags &= ~BNA_PORT_F_PAUSE_CHANGED;
  774. bna_fw_pause_set(port);
  775. } else if (port->flags & BNA_PORT_F_MTU_CHANGED) {
  776. port->flags &= ~BNA_PORT_F_MTU_CHANGED;
  777. bfa_fsm_set_state(port, bna_port_sm_mtu_init_wait);
  778. } else {
  779. bfa_fsm_set_state(port, bna_port_sm_started);
  780. bna_port_chld_start(port);
  781. }
  782. break;
  783. default:
  784. bfa_sm_fault(port->bna, event);
  785. }
  786. }
  787. static void
  788. bna_port_sm_last_resp_wait_entry(struct bna_port *port)
  789. {
  790. }
  791. static void
  792. bna_port_sm_last_resp_wait(struct bna_port *port,
  793. enum bna_port_event event)
  794. {
  795. switch (event) {
  796. case PORT_E_FAIL:
  797. case PORT_E_FWRESP_PAUSE:
  798. case PORT_E_FWRESP_MTU:
  799. bfa_fsm_set_state(port, bna_port_sm_stopped);
  800. break;
  801. default:
  802. bfa_sm_fault(port->bna, event);
  803. }
  804. }
  805. static void
  806. bna_port_sm_started_entry(struct bna_port *port)
  807. {
  808. /**
  809. * NOTE: Do not call bna_port_chld_start() here, since it will be
  810. * inadvertently called during pause_cfg_wait->started transition
  811. * as well
  812. */
  813. call_port_pause_cbfn(port, BNA_CB_SUCCESS);
  814. call_port_mtu_cbfn(port, BNA_CB_SUCCESS);
  815. }
  816. static void
  817. bna_port_sm_started(struct bna_port *port,
  818. enum bna_port_event event)
  819. {
  820. switch (event) {
  821. case PORT_E_STOP:
  822. bfa_fsm_set_state(port, bna_port_sm_chld_stop_wait);
  823. break;
  824. case PORT_E_FAIL:
  825. bfa_fsm_set_state(port, bna_port_sm_stopped);
  826. bna_port_chld_fail(port);
  827. break;
  828. case PORT_E_PAUSE_CFG:
  829. bfa_fsm_set_state(port, bna_port_sm_pause_cfg_wait);
  830. break;
  831. case PORT_E_MTU_CFG:
  832. bfa_fsm_set_state(port, bna_port_sm_rx_stop_wait);
  833. break;
  834. default:
  835. bfa_sm_fault(port->bna, event);
  836. }
  837. }
  838. static void
  839. bna_port_sm_pause_cfg_wait_entry(struct bna_port *port)
  840. {
  841. bna_fw_pause_set(port);
  842. }
  843. static void
  844. bna_port_sm_pause_cfg_wait(struct bna_port *port,
  845. enum bna_port_event event)
  846. {
  847. switch (event) {
  848. case PORT_E_FAIL:
  849. bfa_fsm_set_state(port, bna_port_sm_stopped);
  850. bna_port_chld_fail(port);
  851. break;
  852. case PORT_E_FWRESP_PAUSE:
  853. bfa_fsm_set_state(port, bna_port_sm_started);
  854. break;
  855. default:
  856. bfa_sm_fault(port->bna, event);
  857. }
  858. }
  859. static void
  860. bna_port_sm_rx_stop_wait_entry(struct bna_port *port)
  861. {
  862. bna_port_rx_stop(port);
  863. }
  864. static void
  865. bna_port_sm_rx_stop_wait(struct bna_port *port,
  866. enum bna_port_event event)
  867. {
  868. switch (event) {
  869. case PORT_E_FAIL:
  870. bfa_fsm_set_state(port, bna_port_sm_stopped);
  871. bna_port_chld_fail(port);
  872. break;
  873. case PORT_E_CHLD_STOPPED:
  874. bfa_fsm_set_state(port, bna_port_sm_mtu_cfg_wait);
  875. break;
  876. default:
  877. bfa_sm_fault(port->bna, event);
  878. }
  879. }
  880. static void
  881. bna_port_sm_mtu_cfg_wait_entry(struct bna_port *port)
  882. {
  883. bna_fw_mtu_set(port);
  884. }
  885. static void
  886. bna_port_sm_mtu_cfg_wait(struct bna_port *port, enum bna_port_event event)
  887. {
  888. switch (event) {
  889. case PORT_E_FAIL:
  890. bfa_fsm_set_state(port, bna_port_sm_stopped);
  891. bna_port_chld_fail(port);
  892. break;
  893. case PORT_E_FWRESP_MTU:
  894. bfa_fsm_set_state(port, bna_port_sm_started);
  895. bna_port_rx_start(port);
  896. break;
  897. default:
  898. bfa_sm_fault(port->bna, event);
  899. }
  900. }
  901. static void
  902. bna_port_sm_chld_stop_wait_entry(struct bna_port *port)
  903. {
  904. bna_port_chld_stop(port);
  905. }
  906. static void
  907. bna_port_sm_chld_stop_wait(struct bna_port *port,
  908. enum bna_port_event event)
  909. {
  910. switch (event) {
  911. case PORT_E_FAIL:
  912. bfa_fsm_set_state(port, bna_port_sm_stopped);
  913. bna_port_chld_fail(port);
  914. break;
  915. case PORT_E_CHLD_STOPPED:
  916. bfa_fsm_set_state(port, bna_port_sm_stopped);
  917. break;
  918. default:
  919. bfa_sm_fault(port->bna, event);
  920. }
  921. }
  922. static void
  923. bna_fw_pause_set(struct bna_port *port)
  924. {
  925. struct bfi_ll_set_pause_req ll_req;
  926. memset(&ll_req, 0, sizeof(ll_req));
  927. ll_req.mh.msg_class = BFI_MC_LL;
  928. ll_req.mh.msg_id = BFI_LL_H2I_SET_PAUSE_REQ;
  929. ll_req.mh.mtag.h2i.lpu_id = 0;
  930. ll_req.tx_pause = port->pause_config.tx_pause;
  931. ll_req.rx_pause = port->pause_config.rx_pause;
  932. bna_mbox_qe_fill(&port->mbox_qe, &ll_req, sizeof(ll_req),
  933. bna_fw_cb_pause_set, port);
  934. bna_mbox_send(port->bna, &port->mbox_qe);
  935. }
  936. static void
  937. bna_fw_cb_pause_set(void *arg, int status)
  938. {
  939. struct bna_port *port = (struct bna_port *)arg;
  940. bfa_q_qe_init(&port->mbox_qe.qe);
  941. bfa_fsm_send_event(port, PORT_E_FWRESP_PAUSE);
  942. }
  943. void
  944. bna_fw_mtu_set(struct bna_port *port)
  945. {
  946. struct bfi_ll_mtu_info_req ll_req;
  947. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_MTU_INFO_REQ, 0);
  948. ll_req.mtu = htons((u16)port->mtu);
  949. bna_mbox_qe_fill(&port->mbox_qe, &ll_req, sizeof(ll_req),
  950. bna_fw_cb_mtu_set, port);
  951. bna_mbox_send(port->bna, &port->mbox_qe);
  952. }
  953. void
  954. bna_fw_cb_mtu_set(void *arg, int status)
  955. {
  956. struct bna_port *port = (struct bna_port *)arg;
  957. bfa_q_qe_init(&port->mbox_qe.qe);
  958. bfa_fsm_send_event(port, PORT_E_FWRESP_MTU);
  959. }
  960. static void
  961. bna_port_cb_chld_stopped(void *arg)
  962. {
  963. struct bna_port *port = (struct bna_port *)arg;
  964. bfa_fsm_send_event(port, PORT_E_CHLD_STOPPED);
  965. }
  966. static void
  967. bna_port_init(struct bna_port *port, struct bna *bna)
  968. {
  969. port->bna = bna;
  970. port->flags = 0;
  971. port->mtu = 0;
  972. port->type = BNA_PORT_T_REGULAR;
  973. port->link_cbfn = bnad_cb_port_link_status;
  974. port->chld_stop_wc.wc_resume = bna_port_cb_chld_stopped;
  975. port->chld_stop_wc.wc_cbarg = port;
  976. port->chld_stop_wc.wc_count = 0;
  977. port->stop_cbfn = NULL;
  978. port->stop_cbarg = NULL;
  979. port->pause_cbfn = NULL;
  980. port->mtu_cbfn = NULL;
  981. bfa_q_qe_init(&port->mbox_qe.qe);
  982. bfa_fsm_set_state(port, bna_port_sm_stopped);
  983. bna_llport_init(&port->llport, bna);
  984. }
  985. static void
  986. bna_port_uninit(struct bna_port *port)
  987. {
  988. bna_llport_uninit(&port->llport);
  989. port->flags = 0;
  990. port->bna = NULL;
  991. }
  992. static int
  993. bna_port_state_get(struct bna_port *port)
  994. {
  995. return bfa_sm_to_state(port_sm_table, port->fsm);
  996. }
  997. static void
  998. bna_port_start(struct bna_port *port)
  999. {
  1000. port->flags |= BNA_PORT_F_DEVICE_READY;
  1001. if (port->flags & BNA_PORT_F_ENABLED)
  1002. bfa_fsm_send_event(port, PORT_E_START);
  1003. }
  1004. static void
  1005. bna_port_stop(struct bna_port *port)
  1006. {
  1007. port->stop_cbfn = bna_device_cb_port_stopped;
  1008. port->stop_cbarg = &port->bna->device;
  1009. port->flags &= ~BNA_PORT_F_DEVICE_READY;
  1010. bfa_fsm_send_event(port, PORT_E_STOP);
  1011. }
  1012. static void
  1013. bna_port_fail(struct bna_port *port)
  1014. {
  1015. port->flags &= ~BNA_PORT_F_DEVICE_READY;
  1016. bfa_fsm_send_event(port, PORT_E_FAIL);
  1017. }
  1018. void
  1019. bna_port_cb_tx_stopped(struct bna_port *port, enum bna_cb_status status)
  1020. {
  1021. bfa_wc_down(&port->chld_stop_wc);
  1022. }
  1023. void
  1024. bna_port_cb_rx_stopped(struct bna_port *port, enum bna_cb_status status)
  1025. {
  1026. bfa_wc_down(&port->chld_stop_wc);
  1027. }
  1028. int
  1029. bna_port_mtu_get(struct bna_port *port)
  1030. {
  1031. return port->mtu;
  1032. }
  1033. void
  1034. bna_port_enable(struct bna_port *port)
  1035. {
  1036. if (port->fsm != (bfa_sm_t)bna_port_sm_stopped)
  1037. return;
  1038. port->flags |= BNA_PORT_F_ENABLED;
  1039. if (port->flags & BNA_PORT_F_DEVICE_READY)
  1040. bfa_fsm_send_event(port, PORT_E_START);
  1041. }
  1042. void
  1043. bna_port_disable(struct bna_port *port, enum bna_cleanup_type type,
  1044. void (*cbfn)(void *, enum bna_cb_status))
  1045. {
  1046. if (type == BNA_SOFT_CLEANUP) {
  1047. (*cbfn)(port->bna->bnad, BNA_CB_SUCCESS);
  1048. return;
  1049. }
  1050. port->stop_cbfn = cbfn;
  1051. port->stop_cbarg = port->bna->bnad;
  1052. port->flags &= ~BNA_PORT_F_ENABLED;
  1053. bfa_fsm_send_event(port, PORT_E_STOP);
  1054. }
  1055. void
  1056. bna_port_pause_config(struct bna_port *port,
  1057. struct bna_pause_config *pause_config,
  1058. void (*cbfn)(struct bnad *, enum bna_cb_status))
  1059. {
  1060. port->pause_config = *pause_config;
  1061. port->pause_cbfn = cbfn;
  1062. bfa_fsm_send_event(port, PORT_E_PAUSE_CFG);
  1063. }
  1064. void
  1065. bna_port_mtu_set(struct bna_port *port, int mtu,
  1066. void (*cbfn)(struct bnad *, enum bna_cb_status))
  1067. {
  1068. port->mtu = mtu;
  1069. port->mtu_cbfn = cbfn;
  1070. bfa_fsm_send_event(port, PORT_E_MTU_CFG);
  1071. }
  1072. void
  1073. bna_port_mac_get(struct bna_port *port, mac_t *mac)
  1074. {
  1075. *mac = bfa_nw_ioc_get_mac(&port->bna->device.ioc);
  1076. }
  1077. /**
  1078. * DEVICE
  1079. */
  1080. #define enable_mbox_intr(_device)\
  1081. do {\
  1082. u32 intr_status;\
  1083. bna_intr_status_get((_device)->bna, intr_status);\
  1084. bnad_cb_device_enable_mbox_intr((_device)->bna->bnad);\
  1085. bna_mbox_intr_enable((_device)->bna);\
  1086. } while (0)
  1087. #define disable_mbox_intr(_device)\
  1088. do {\
  1089. bna_mbox_intr_disable((_device)->bna);\
  1090. bnad_cb_device_disable_mbox_intr((_device)->bna->bnad);\
  1091. } while (0)
  1092. static const struct bna_chip_regs_offset reg_offset[] =
  1093. {{HOST_PAGE_NUM_FN0, HOSTFN0_INT_STATUS,
  1094. HOSTFN0_INT_MASK, HOST_MSIX_ERR_INDEX_FN0},
  1095. {HOST_PAGE_NUM_FN1, HOSTFN1_INT_STATUS,
  1096. HOSTFN1_INT_MASK, HOST_MSIX_ERR_INDEX_FN1},
  1097. {HOST_PAGE_NUM_FN2, HOSTFN2_INT_STATUS,
  1098. HOSTFN2_INT_MASK, HOST_MSIX_ERR_INDEX_FN2},
  1099. {HOST_PAGE_NUM_FN3, HOSTFN3_INT_STATUS,
  1100. HOSTFN3_INT_MASK, HOST_MSIX_ERR_INDEX_FN3},
  1101. };
  1102. enum bna_device_event {
  1103. DEVICE_E_ENABLE = 1,
  1104. DEVICE_E_DISABLE = 2,
  1105. DEVICE_E_IOC_READY = 3,
  1106. DEVICE_E_IOC_FAILED = 4,
  1107. DEVICE_E_IOC_DISABLED = 5,
  1108. DEVICE_E_IOC_RESET = 6,
  1109. DEVICE_E_PORT_STOPPED = 7,
  1110. };
  1111. enum bna_device_state {
  1112. BNA_DEVICE_STOPPED = 1,
  1113. BNA_DEVICE_IOC_READY_WAIT = 2,
  1114. BNA_DEVICE_READY = 3,
  1115. BNA_DEVICE_PORT_STOP_WAIT = 4,
  1116. BNA_DEVICE_IOC_DISABLE_WAIT = 5,
  1117. BNA_DEVICE_FAILED = 6
  1118. };
  1119. bfa_fsm_state_decl(bna_device, stopped, struct bna_device,
  1120. enum bna_device_event);
  1121. bfa_fsm_state_decl(bna_device, ioc_ready_wait, struct bna_device,
  1122. enum bna_device_event);
  1123. bfa_fsm_state_decl(bna_device, ready, struct bna_device,
  1124. enum bna_device_event);
  1125. bfa_fsm_state_decl(bna_device, port_stop_wait, struct bna_device,
  1126. enum bna_device_event);
  1127. bfa_fsm_state_decl(bna_device, ioc_disable_wait, struct bna_device,
  1128. enum bna_device_event);
  1129. bfa_fsm_state_decl(bna_device, failed, struct bna_device,
  1130. enum bna_device_event);
  1131. static struct bfa_sm_table device_sm_table[] = {
  1132. {BFA_SM(bna_device_sm_stopped), BNA_DEVICE_STOPPED},
  1133. {BFA_SM(bna_device_sm_ioc_ready_wait), BNA_DEVICE_IOC_READY_WAIT},
  1134. {BFA_SM(bna_device_sm_ready), BNA_DEVICE_READY},
  1135. {BFA_SM(bna_device_sm_port_stop_wait), BNA_DEVICE_PORT_STOP_WAIT},
  1136. {BFA_SM(bna_device_sm_ioc_disable_wait), BNA_DEVICE_IOC_DISABLE_WAIT},
  1137. {BFA_SM(bna_device_sm_failed), BNA_DEVICE_FAILED},
  1138. };
  1139. static void
  1140. bna_device_sm_stopped_entry(struct bna_device *device)
  1141. {
  1142. if (device->stop_cbfn)
  1143. device->stop_cbfn(device->stop_cbarg, BNA_CB_SUCCESS);
  1144. device->stop_cbfn = NULL;
  1145. device->stop_cbarg = NULL;
  1146. }
  1147. static void
  1148. bna_device_sm_stopped(struct bna_device *device,
  1149. enum bna_device_event event)
  1150. {
  1151. switch (event) {
  1152. case DEVICE_E_ENABLE:
  1153. if (device->intr_type == BNA_INTR_T_MSIX)
  1154. bna_mbox_msix_idx_set(device);
  1155. bfa_nw_ioc_enable(&device->ioc);
  1156. bfa_fsm_set_state(device, bna_device_sm_ioc_ready_wait);
  1157. break;
  1158. case DEVICE_E_DISABLE:
  1159. bfa_fsm_set_state(device, bna_device_sm_stopped);
  1160. break;
  1161. case DEVICE_E_IOC_RESET:
  1162. enable_mbox_intr(device);
  1163. break;
  1164. case DEVICE_E_IOC_FAILED:
  1165. bfa_fsm_set_state(device, bna_device_sm_failed);
  1166. break;
  1167. default:
  1168. bfa_sm_fault(device->bna, event);
  1169. }
  1170. }
  1171. static void
  1172. bna_device_sm_ioc_ready_wait_entry(struct bna_device *device)
  1173. {
  1174. /**
  1175. * Do not call bfa_ioc_enable() here. It must be called in the
  1176. * previous state due to failed -> ioc_ready_wait transition.
  1177. */
  1178. }
  1179. static void
  1180. bna_device_sm_ioc_ready_wait(struct bna_device *device,
  1181. enum bna_device_event event)
  1182. {
  1183. switch (event) {
  1184. case DEVICE_E_DISABLE:
  1185. if (device->ready_cbfn)
  1186. device->ready_cbfn(device->ready_cbarg,
  1187. BNA_CB_INTERRUPT);
  1188. device->ready_cbfn = NULL;
  1189. device->ready_cbarg = NULL;
  1190. bfa_fsm_set_state(device, bna_device_sm_ioc_disable_wait);
  1191. break;
  1192. case DEVICE_E_IOC_READY:
  1193. bfa_fsm_set_state(device, bna_device_sm_ready);
  1194. break;
  1195. case DEVICE_E_IOC_FAILED:
  1196. bfa_fsm_set_state(device, bna_device_sm_failed);
  1197. break;
  1198. case DEVICE_E_IOC_RESET:
  1199. enable_mbox_intr(device);
  1200. break;
  1201. default:
  1202. bfa_sm_fault(device->bna, event);
  1203. }
  1204. }
  1205. static void
  1206. bna_device_sm_ready_entry(struct bna_device *device)
  1207. {
  1208. bna_mbox_mod_start(&device->bna->mbox_mod);
  1209. bna_port_start(&device->bna->port);
  1210. if (device->ready_cbfn)
  1211. device->ready_cbfn(device->ready_cbarg,
  1212. BNA_CB_SUCCESS);
  1213. device->ready_cbfn = NULL;
  1214. device->ready_cbarg = NULL;
  1215. }
  1216. static void
  1217. bna_device_sm_ready(struct bna_device *device, enum bna_device_event event)
  1218. {
  1219. switch (event) {
  1220. case DEVICE_E_DISABLE:
  1221. bfa_fsm_set_state(device, bna_device_sm_port_stop_wait);
  1222. break;
  1223. case DEVICE_E_IOC_FAILED:
  1224. bfa_fsm_set_state(device, bna_device_sm_failed);
  1225. break;
  1226. default:
  1227. bfa_sm_fault(device->bna, event);
  1228. }
  1229. }
  1230. static void
  1231. bna_device_sm_port_stop_wait_entry(struct bna_device *device)
  1232. {
  1233. bna_port_stop(&device->bna->port);
  1234. }
  1235. static void
  1236. bna_device_sm_port_stop_wait(struct bna_device *device,
  1237. enum bna_device_event event)
  1238. {
  1239. switch (event) {
  1240. case DEVICE_E_PORT_STOPPED:
  1241. bna_mbox_mod_stop(&device->bna->mbox_mod);
  1242. bfa_fsm_set_state(device, bna_device_sm_ioc_disable_wait);
  1243. break;
  1244. case DEVICE_E_IOC_FAILED:
  1245. disable_mbox_intr(device);
  1246. bna_port_fail(&device->bna->port);
  1247. break;
  1248. default:
  1249. bfa_sm_fault(device->bna, event);
  1250. }
  1251. }
  1252. static void
  1253. bna_device_sm_ioc_disable_wait_entry(struct bna_device *device)
  1254. {
  1255. bfa_nw_ioc_disable(&device->ioc);
  1256. }
  1257. static void
  1258. bna_device_sm_ioc_disable_wait(struct bna_device *device,
  1259. enum bna_device_event event)
  1260. {
  1261. switch (event) {
  1262. case DEVICE_E_IOC_DISABLED:
  1263. disable_mbox_intr(device);
  1264. bfa_fsm_set_state(device, bna_device_sm_stopped);
  1265. break;
  1266. default:
  1267. bfa_sm_fault(device->bna, event);
  1268. }
  1269. }
  1270. static void
  1271. bna_device_sm_failed_entry(struct bna_device *device)
  1272. {
  1273. disable_mbox_intr(device);
  1274. bna_port_fail(&device->bna->port);
  1275. bna_mbox_mod_stop(&device->bna->mbox_mod);
  1276. if (device->ready_cbfn)
  1277. device->ready_cbfn(device->ready_cbarg,
  1278. BNA_CB_FAIL);
  1279. device->ready_cbfn = NULL;
  1280. device->ready_cbarg = NULL;
  1281. }
  1282. static void
  1283. bna_device_sm_failed(struct bna_device *device,
  1284. enum bna_device_event event)
  1285. {
  1286. switch (event) {
  1287. case DEVICE_E_DISABLE:
  1288. bfa_fsm_set_state(device, bna_device_sm_ioc_disable_wait);
  1289. break;
  1290. case DEVICE_E_IOC_RESET:
  1291. enable_mbox_intr(device);
  1292. bfa_fsm_set_state(device, bna_device_sm_ioc_ready_wait);
  1293. break;
  1294. default:
  1295. bfa_sm_fault(device->bna, event);
  1296. }
  1297. }
  1298. /* IOC callback functions */
  1299. static void
  1300. bna_device_cb_iocll_ready(void *dev, enum bfa_status error)
  1301. {
  1302. struct bna_device *device = (struct bna_device *)dev;
  1303. if (error)
  1304. bfa_fsm_send_event(device, DEVICE_E_IOC_FAILED);
  1305. else
  1306. bfa_fsm_send_event(device, DEVICE_E_IOC_READY);
  1307. }
  1308. static void
  1309. bna_device_cb_iocll_disabled(void *dev)
  1310. {
  1311. struct bna_device *device = (struct bna_device *)dev;
  1312. bfa_fsm_send_event(device, DEVICE_E_IOC_DISABLED);
  1313. }
  1314. static void
  1315. bna_device_cb_iocll_failed(void *dev)
  1316. {
  1317. struct bna_device *device = (struct bna_device *)dev;
  1318. bfa_fsm_send_event(device, DEVICE_E_IOC_FAILED);
  1319. }
  1320. static void
  1321. bna_device_cb_iocll_reset(void *dev)
  1322. {
  1323. struct bna_device *device = (struct bna_device *)dev;
  1324. bfa_fsm_send_event(device, DEVICE_E_IOC_RESET);
  1325. }
  1326. static struct bfa_ioc_cbfn bfa_iocll_cbfn = {
  1327. bna_device_cb_iocll_ready,
  1328. bna_device_cb_iocll_disabled,
  1329. bna_device_cb_iocll_failed,
  1330. bna_device_cb_iocll_reset
  1331. };
  1332. /* device */
  1333. static void
  1334. bna_adv_device_init(struct bna_device *device, struct bna *bna,
  1335. struct bna_res_info *res_info)
  1336. {
  1337. u8 *kva;
  1338. u64 dma;
  1339. device->bna = bna;
  1340. kva = res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.mdl[0].kva;
  1341. /**
  1342. * Attach common modules (Diag, SFP, CEE, Port) and claim respective
  1343. * DMA memory.
  1344. */
  1345. BNA_GET_DMA_ADDR(
  1346. &res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mdl[0].dma, dma);
  1347. kva = res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mdl[0].kva;
  1348. bfa_nw_cee_attach(&bna->cee, &device->ioc, bna);
  1349. bfa_nw_cee_mem_claim(&bna->cee, kva, dma);
  1350. kva += bfa_nw_cee_meminfo();
  1351. dma += bfa_nw_cee_meminfo();
  1352. }
  1353. static void
  1354. bna_device_init(struct bna_device *device, struct bna *bna,
  1355. struct bna_res_info *res_info)
  1356. {
  1357. u64 dma;
  1358. device->bna = bna;
  1359. /**
  1360. * Attach IOC and claim:
  1361. * 1. DMA memory for IOC attributes
  1362. * 2. Kernel memory for FW trace
  1363. */
  1364. bfa_nw_ioc_attach(&device->ioc, device, &bfa_iocll_cbfn);
  1365. bfa_nw_ioc_pci_init(&device->ioc, &bna->pcidev, BFI_MC_LL);
  1366. BNA_GET_DMA_ADDR(
  1367. &res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mdl[0].dma, dma);
  1368. bfa_nw_ioc_mem_claim(&device->ioc,
  1369. res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mdl[0].kva,
  1370. dma);
  1371. bna_adv_device_init(device, bna, res_info);
  1372. /*
  1373. * Initialize mbox_mod only after IOC, so that mbox handler
  1374. * registration goes through
  1375. */
  1376. device->intr_type =
  1377. res_info[BNA_RES_INTR_T_MBOX].res_u.intr_info.intr_type;
  1378. device->vector =
  1379. res_info[BNA_RES_INTR_T_MBOX].res_u.intr_info.idl[0].vector;
  1380. bna_mbox_mod_init(&bna->mbox_mod, bna);
  1381. device->ready_cbfn = device->stop_cbfn = NULL;
  1382. device->ready_cbarg = device->stop_cbarg = NULL;
  1383. bfa_fsm_set_state(device, bna_device_sm_stopped);
  1384. }
  1385. static void
  1386. bna_device_uninit(struct bna_device *device)
  1387. {
  1388. bna_mbox_mod_uninit(&device->bna->mbox_mod);
  1389. bfa_nw_ioc_detach(&device->ioc);
  1390. device->bna = NULL;
  1391. }
  1392. static void
  1393. bna_device_cb_port_stopped(void *arg, enum bna_cb_status status)
  1394. {
  1395. struct bna_device *device = (struct bna_device *)arg;
  1396. bfa_fsm_send_event(device, DEVICE_E_PORT_STOPPED);
  1397. }
  1398. static int
  1399. bna_device_status_get(struct bna_device *device)
  1400. {
  1401. return device->fsm == (bfa_fsm_t)bna_device_sm_ready;
  1402. }
  1403. void
  1404. bna_device_enable(struct bna_device *device)
  1405. {
  1406. if (device->fsm != (bfa_fsm_t)bna_device_sm_stopped) {
  1407. bnad_cb_device_enabled(device->bna->bnad, BNA_CB_BUSY);
  1408. return;
  1409. }
  1410. device->ready_cbfn = bnad_cb_device_enabled;
  1411. device->ready_cbarg = device->bna->bnad;
  1412. bfa_fsm_send_event(device, DEVICE_E_ENABLE);
  1413. }
  1414. void
  1415. bna_device_disable(struct bna_device *device, enum bna_cleanup_type type)
  1416. {
  1417. if (type == BNA_SOFT_CLEANUP) {
  1418. bnad_cb_device_disabled(device->bna->bnad, BNA_CB_SUCCESS);
  1419. return;
  1420. }
  1421. device->stop_cbfn = bnad_cb_device_disabled;
  1422. device->stop_cbarg = device->bna->bnad;
  1423. bfa_fsm_send_event(device, DEVICE_E_DISABLE);
  1424. }
  1425. static int
  1426. bna_device_state_get(struct bna_device *device)
  1427. {
  1428. return bfa_sm_to_state(device_sm_table, device->fsm);
  1429. }
  1430. const u32 bna_napi_dim_vector[BNA_LOAD_T_MAX][BNA_BIAS_T_MAX] = {
  1431. {12, 12},
  1432. {6, 10},
  1433. {5, 10},
  1434. {4, 8},
  1435. {3, 6},
  1436. {3, 6},
  1437. {2, 4},
  1438. {1, 2},
  1439. };
  1440. /* utils */
  1441. static void
  1442. bna_adv_res_req(struct bna_res_info *res_info)
  1443. {
  1444. /* DMA memory for COMMON_MODULE */
  1445. res_info[BNA_RES_MEM_T_COM].res_type = BNA_RES_T_MEM;
  1446. res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
  1447. res_info[BNA_RES_MEM_T_COM].res_u.mem_info.num = 1;
  1448. res_info[BNA_RES_MEM_T_COM].res_u.mem_info.len = ALIGN(
  1449. bfa_nw_cee_meminfo(), PAGE_SIZE);
  1450. /* Virtual memory for retreiving fw_trc */
  1451. res_info[BNA_RES_MEM_T_FWTRC].res_type = BNA_RES_T_MEM;
  1452. res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.mem_type = BNA_MEM_T_KVA;
  1453. res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.num = 0;
  1454. res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.len = 0;
  1455. /* DMA memory for retreiving stats */
  1456. res_info[BNA_RES_MEM_T_STATS].res_type = BNA_RES_T_MEM;
  1457. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
  1458. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.num = 1;
  1459. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.len =
  1460. ALIGN(BFI_HW_STATS_SIZE, PAGE_SIZE);
  1461. /* Virtual memory for soft stats */
  1462. res_info[BNA_RES_MEM_T_SWSTATS].res_type = BNA_RES_T_MEM;
  1463. res_info[BNA_RES_MEM_T_SWSTATS].res_u.mem_info.mem_type = BNA_MEM_T_KVA;
  1464. res_info[BNA_RES_MEM_T_SWSTATS].res_u.mem_info.num = 1;
  1465. res_info[BNA_RES_MEM_T_SWSTATS].res_u.mem_info.len =
  1466. sizeof(struct bna_sw_stats);
  1467. }
  1468. static void
  1469. bna_sw_stats_get(struct bna *bna, struct bna_sw_stats *sw_stats)
  1470. {
  1471. struct bna_tx *tx;
  1472. struct bna_txq *txq;
  1473. struct bna_rx *rx;
  1474. struct bna_rxp *rxp;
  1475. struct list_head *qe;
  1476. struct list_head *txq_qe;
  1477. struct list_head *rxp_qe;
  1478. struct list_head *mac_qe;
  1479. int i;
  1480. sw_stats->device_state = bna_device_state_get(&bna->device);
  1481. sw_stats->port_state = bna_port_state_get(&bna->port);
  1482. sw_stats->port_flags = bna->port.flags;
  1483. sw_stats->llport_state = bna_llport_state_get(&bna->port.llport);
  1484. sw_stats->priority = bna->port.priority;
  1485. i = 0;
  1486. list_for_each(qe, &bna->tx_mod.tx_active_q) {
  1487. tx = (struct bna_tx *)qe;
  1488. sw_stats->tx_stats[i].tx_state = bna_tx_state_get(tx);
  1489. sw_stats->tx_stats[i].tx_flags = tx->flags;
  1490. sw_stats->tx_stats[i].num_txqs = 0;
  1491. sw_stats->tx_stats[i].txq_bmap[0] = 0;
  1492. sw_stats->tx_stats[i].txq_bmap[1] = 0;
  1493. list_for_each(txq_qe, &tx->txq_q) {
  1494. txq = (struct bna_txq *)txq_qe;
  1495. if (txq->txq_id < 32)
  1496. sw_stats->tx_stats[i].txq_bmap[0] |=
  1497. ((u32)1 << txq->txq_id);
  1498. else
  1499. sw_stats->tx_stats[i].txq_bmap[1] |=
  1500. ((u32)
  1501. 1 << (txq->txq_id - 32));
  1502. sw_stats->tx_stats[i].num_txqs++;
  1503. }
  1504. sw_stats->tx_stats[i].txf_id = tx->txf.txf_id;
  1505. i++;
  1506. }
  1507. sw_stats->num_active_tx = i;
  1508. i = 0;
  1509. list_for_each(qe, &bna->rx_mod.rx_active_q) {
  1510. rx = (struct bna_rx *)qe;
  1511. sw_stats->rx_stats[i].rx_state = bna_rx_state_get(rx);
  1512. sw_stats->rx_stats[i].rx_flags = rx->rx_flags;
  1513. sw_stats->rx_stats[i].num_rxps = 0;
  1514. sw_stats->rx_stats[i].num_rxqs = 0;
  1515. sw_stats->rx_stats[i].rxq_bmap[0] = 0;
  1516. sw_stats->rx_stats[i].rxq_bmap[1] = 0;
  1517. sw_stats->rx_stats[i].cq_bmap[0] = 0;
  1518. sw_stats->rx_stats[i].cq_bmap[1] = 0;
  1519. list_for_each(rxp_qe, &rx->rxp_q) {
  1520. rxp = (struct bna_rxp *)rxp_qe;
  1521. sw_stats->rx_stats[i].num_rxqs += 1;
  1522. if (rxp->type == BNA_RXP_SINGLE) {
  1523. if (rxp->rxq.single.only->rxq_id < 32) {
  1524. sw_stats->rx_stats[i].rxq_bmap[0] |=
  1525. ((u32)1 <<
  1526. rxp->rxq.single.only->rxq_id);
  1527. } else {
  1528. sw_stats->rx_stats[i].rxq_bmap[1] |=
  1529. ((u32)1 <<
  1530. (rxp->rxq.single.only->rxq_id - 32));
  1531. }
  1532. } else {
  1533. if (rxp->rxq.slr.large->rxq_id < 32) {
  1534. sw_stats->rx_stats[i].rxq_bmap[0] |=
  1535. ((u32)1 <<
  1536. rxp->rxq.slr.large->rxq_id);
  1537. } else {
  1538. sw_stats->rx_stats[i].rxq_bmap[1] |=
  1539. ((u32)1 <<
  1540. (rxp->rxq.slr.large->rxq_id - 32));
  1541. }
  1542. if (rxp->rxq.slr.small->rxq_id < 32) {
  1543. sw_stats->rx_stats[i].rxq_bmap[0] |=
  1544. ((u32)1 <<
  1545. rxp->rxq.slr.small->rxq_id);
  1546. } else {
  1547. sw_stats->rx_stats[i].rxq_bmap[1] |=
  1548. ((u32)1 <<
  1549. (rxp->rxq.slr.small->rxq_id - 32));
  1550. }
  1551. sw_stats->rx_stats[i].num_rxqs += 1;
  1552. }
  1553. if (rxp->cq.cq_id < 32)
  1554. sw_stats->rx_stats[i].cq_bmap[0] |=
  1555. (1 << rxp->cq.cq_id);
  1556. else
  1557. sw_stats->rx_stats[i].cq_bmap[1] |=
  1558. (1 << (rxp->cq.cq_id - 32));
  1559. sw_stats->rx_stats[i].num_rxps++;
  1560. }
  1561. sw_stats->rx_stats[i].rxf_id = rx->rxf.rxf_id;
  1562. sw_stats->rx_stats[i].rxf_state = bna_rxf_state_get(&rx->rxf);
  1563. sw_stats->rx_stats[i].rxf_oper_state = rx->rxf.rxf_oper_state;
  1564. sw_stats->rx_stats[i].num_active_ucast = 0;
  1565. if (rx->rxf.ucast_active_mac)
  1566. sw_stats->rx_stats[i].num_active_ucast++;
  1567. list_for_each(mac_qe, &rx->rxf.ucast_active_q)
  1568. sw_stats->rx_stats[i].num_active_ucast++;
  1569. sw_stats->rx_stats[i].num_active_mcast = 0;
  1570. list_for_each(mac_qe, &rx->rxf.mcast_active_q)
  1571. sw_stats->rx_stats[i].num_active_mcast++;
  1572. sw_stats->rx_stats[i].rxmode_active = rx->rxf.rxmode_active;
  1573. sw_stats->rx_stats[i].vlan_filter_status =
  1574. rx->rxf.vlan_filter_status;
  1575. memcpy(sw_stats->rx_stats[i].vlan_filter_table,
  1576. rx->rxf.vlan_filter_table,
  1577. sizeof(u32) * ((BFI_MAX_VLAN + 1) / 32));
  1578. sw_stats->rx_stats[i].rss_status = rx->rxf.rss_status;
  1579. sw_stats->rx_stats[i].hds_status = rx->rxf.hds_status;
  1580. i++;
  1581. }
  1582. sw_stats->num_active_rx = i;
  1583. }
  1584. static void
  1585. bna_fw_cb_stats_get(void *arg, int status)
  1586. {
  1587. struct bna *bna = (struct bna *)arg;
  1588. u64 *p_stats;
  1589. int i, count;
  1590. int rxf_count, txf_count;
  1591. u64 rxf_bmap, txf_bmap;
  1592. bfa_q_qe_init(&bna->mbox_qe.qe);
  1593. if (status == 0) {
  1594. p_stats = (u64 *)bna->stats.hw_stats;
  1595. count = sizeof(struct bfi_ll_stats) / sizeof(u64);
  1596. for (i = 0; i < count; i++)
  1597. p_stats[i] = cpu_to_be64(p_stats[i]);
  1598. rxf_count = 0;
  1599. rxf_bmap = (u64)bna->stats.rxf_bmap[0] |
  1600. ((u64)bna->stats.rxf_bmap[1] << 32);
  1601. for (i = 0; i < BFI_LL_RXF_ID_MAX; i++)
  1602. if (rxf_bmap & ((u64)1 << i))
  1603. rxf_count++;
  1604. txf_count = 0;
  1605. txf_bmap = (u64)bna->stats.txf_bmap[0] |
  1606. ((u64)bna->stats.txf_bmap[1] << 32);
  1607. for (i = 0; i < BFI_LL_TXF_ID_MAX; i++)
  1608. if (txf_bmap & ((u64)1 << i))
  1609. txf_count++;
  1610. p_stats = (u64 *)&bna->stats.hw_stats->rxf_stats[0] +
  1611. ((rxf_count * sizeof(struct bfi_ll_stats_rxf) +
  1612. txf_count * sizeof(struct bfi_ll_stats_txf))/
  1613. sizeof(u64));
  1614. /* Populate the TXF stats from the firmware DMAed copy */
  1615. for (i = (BFI_LL_TXF_ID_MAX - 1); i >= 0; i--)
  1616. if (txf_bmap & ((u64)1 << i)) {
  1617. p_stats -= sizeof(struct bfi_ll_stats_txf)/
  1618. sizeof(u64);
  1619. memcpy(&bna->stats.hw_stats->txf_stats[i],
  1620. p_stats,
  1621. sizeof(struct bfi_ll_stats_txf));
  1622. }
  1623. /* Populate the RXF stats from the firmware DMAed copy */
  1624. for (i = (BFI_LL_RXF_ID_MAX - 1); i >= 0; i--)
  1625. if (rxf_bmap & ((u64)1 << i)) {
  1626. p_stats -= sizeof(struct bfi_ll_stats_rxf)/
  1627. sizeof(u64);
  1628. memcpy(&bna->stats.hw_stats->rxf_stats[i],
  1629. p_stats,
  1630. sizeof(struct bfi_ll_stats_rxf));
  1631. }
  1632. bna_sw_stats_get(bna, bna->stats.sw_stats);
  1633. bnad_cb_stats_get(bna->bnad, BNA_CB_SUCCESS, &bna->stats);
  1634. } else
  1635. bnad_cb_stats_get(bna->bnad, BNA_CB_FAIL, &bna->stats);
  1636. }
  1637. static void
  1638. bna_fw_stats_get(struct bna *bna)
  1639. {
  1640. struct bfi_ll_stats_req ll_req;
  1641. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_STATS_GET_REQ, 0);
  1642. ll_req.stats_mask = htons(BFI_LL_STATS_ALL);
  1643. ll_req.rxf_id_mask[0] = htonl(bna->rx_mod.rxf_bmap[0]);
  1644. ll_req.rxf_id_mask[1] = htonl(bna->rx_mod.rxf_bmap[1]);
  1645. ll_req.txf_id_mask[0] = htonl(bna->tx_mod.txf_bmap[0]);
  1646. ll_req.txf_id_mask[1] = htonl(bna->tx_mod.txf_bmap[1]);
  1647. ll_req.host_buffer.a32.addr_hi = bna->hw_stats_dma.msb;
  1648. ll_req.host_buffer.a32.addr_lo = bna->hw_stats_dma.lsb;
  1649. bna_mbox_qe_fill(&bna->mbox_qe, &ll_req, sizeof(ll_req),
  1650. bna_fw_cb_stats_get, bna);
  1651. bna_mbox_send(bna, &bna->mbox_qe);
  1652. bna->stats.rxf_bmap[0] = bna->rx_mod.rxf_bmap[0];
  1653. bna->stats.rxf_bmap[1] = bna->rx_mod.rxf_bmap[1];
  1654. bna->stats.txf_bmap[0] = bna->tx_mod.txf_bmap[0];
  1655. bna->stats.txf_bmap[1] = bna->tx_mod.txf_bmap[1];
  1656. }
  1657. void
  1658. bna_stats_get(struct bna *bna)
  1659. {
  1660. if (bna_device_status_get(&bna->device))
  1661. bna_fw_stats_get(bna);
  1662. else
  1663. bnad_cb_stats_get(bna->bnad, BNA_CB_FAIL, &bna->stats);
  1664. }
  1665. /* IB */
  1666. static void
  1667. bna_ib_coalescing_timeo_set(struct bna_ib *ib, u8 coalescing_timeo)
  1668. {
  1669. ib->ib_config.coalescing_timeo = coalescing_timeo;
  1670. if (ib->start_count)
  1671. ib->door_bell.doorbell_ack = BNA_DOORBELL_IB_INT_ACK(
  1672. (u32)ib->ib_config.coalescing_timeo, 0);
  1673. }
  1674. /* RxF */
  1675. void
  1676. bna_rxf_adv_init(struct bna_rxf *rxf,
  1677. struct bna_rx *rx,
  1678. struct bna_rx_config *q_config)
  1679. {
  1680. switch (q_config->rxp_type) {
  1681. case BNA_RXP_SINGLE:
  1682. /* No-op */
  1683. break;
  1684. case BNA_RXP_SLR:
  1685. rxf->ctrl_flags |= BNA_RXF_CF_SM_LG_RXQ;
  1686. break;
  1687. case BNA_RXP_HDS:
  1688. rxf->hds_cfg.hdr_type = q_config->hds_config.hdr_type;
  1689. rxf->hds_cfg.header_size =
  1690. q_config->hds_config.header_size;
  1691. rxf->forced_offset = 0;
  1692. break;
  1693. default:
  1694. break;
  1695. }
  1696. if (q_config->rss_status == BNA_STATUS_T_ENABLED) {
  1697. rxf->ctrl_flags |= BNA_RXF_CF_RSS_ENABLE;
  1698. rxf->rss_cfg.hash_type = q_config->rss_config.hash_type;
  1699. rxf->rss_cfg.hash_mask = q_config->rss_config.hash_mask;
  1700. memcpy(&rxf->rss_cfg.toeplitz_hash_key[0],
  1701. &q_config->rss_config.toeplitz_hash_key[0],
  1702. sizeof(rxf->rss_cfg.toeplitz_hash_key));
  1703. }
  1704. }
  1705. static void
  1706. rxf_fltr_mbox_cmd(struct bna_rxf *rxf, u8 cmd, enum bna_status status)
  1707. {
  1708. struct bfi_ll_rxf_req req;
  1709. bfi_h2i_set(req.mh, BFI_MC_LL, cmd, 0);
  1710. req.rxf_id = rxf->rxf_id;
  1711. req.enable = status;
  1712. bna_mbox_qe_fill(&rxf->mbox_qe, &req, sizeof(req),
  1713. rxf_cb_cam_fltr_mbox_cmd, rxf);
  1714. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  1715. }
  1716. static void
  1717. __rxf_default_function_config(struct bna_rxf *rxf, enum bna_status status)
  1718. {
  1719. struct bna_rx_fndb_ram *rx_fndb_ram;
  1720. u32 ctrl_flags;
  1721. int i;
  1722. rx_fndb_ram = (struct bna_rx_fndb_ram *)
  1723. BNA_GET_MEM_BASE_ADDR(rxf->rx->bna->pcidev.pci_bar_kva,
  1724. RX_FNDB_RAM_BASE_OFFSET);
  1725. for (i = 0; i < BFI_MAX_RXF; i++) {
  1726. if (status == BNA_STATUS_T_ENABLED) {
  1727. if (i == rxf->rxf_id)
  1728. continue;
  1729. ctrl_flags =
  1730. readl(&rx_fndb_ram[i].control_flags);
  1731. ctrl_flags |= BNA_RXF_CF_DEFAULT_FUNCTION_ENABLE;
  1732. writel(ctrl_flags,
  1733. &rx_fndb_ram[i].control_flags);
  1734. } else {
  1735. ctrl_flags =
  1736. readl(&rx_fndb_ram[i].control_flags);
  1737. ctrl_flags &= ~BNA_RXF_CF_DEFAULT_FUNCTION_ENABLE;
  1738. writel(ctrl_flags,
  1739. &rx_fndb_ram[i].control_flags);
  1740. }
  1741. }
  1742. }
  1743. int
  1744. rxf_process_packet_filter_ucast(struct bna_rxf *rxf)
  1745. {
  1746. struct bna_mac *mac = NULL;
  1747. struct list_head *qe;
  1748. /* Add additional MAC entries */
  1749. if (!list_empty(&rxf->ucast_pending_add_q)) {
  1750. bfa_q_deq(&rxf->ucast_pending_add_q, &qe);
  1751. bfa_q_qe_init(qe);
  1752. mac = (struct bna_mac *)qe;
  1753. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_UCAST_ADD_REQ, mac);
  1754. list_add_tail(&mac->qe, &rxf->ucast_active_q);
  1755. return 1;
  1756. }
  1757. /* Delete MAC addresses previousely added */
  1758. if (!list_empty(&rxf->ucast_pending_del_q)) {
  1759. bfa_q_deq(&rxf->ucast_pending_del_q, &qe);
  1760. bfa_q_qe_init(qe);
  1761. mac = (struct bna_mac *)qe;
  1762. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_UCAST_DEL_REQ, mac);
  1763. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod, mac);
  1764. return 1;
  1765. }
  1766. return 0;
  1767. }
  1768. int
  1769. rxf_process_packet_filter_promisc(struct bna_rxf *rxf)
  1770. {
  1771. struct bna *bna = rxf->rx->bna;
  1772. /* Enable/disable promiscuous mode */
  1773. if (is_promisc_enable(rxf->rxmode_pending,
  1774. rxf->rxmode_pending_bitmask)) {
  1775. /* move promisc configuration from pending -> active */
  1776. promisc_inactive(rxf->rxmode_pending,
  1777. rxf->rxmode_pending_bitmask);
  1778. rxf->rxmode_active |= BNA_RXMODE_PROMISC;
  1779. /* Disable VLAN filter to allow all VLANs */
  1780. __rxf_vlan_filter_set(rxf, BNA_STATUS_T_DISABLED);
  1781. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_PROMISCUOUS_SET_REQ,
  1782. BNA_STATUS_T_ENABLED);
  1783. return 1;
  1784. } else if (is_promisc_disable(rxf->rxmode_pending,
  1785. rxf->rxmode_pending_bitmask)) {
  1786. /* move promisc configuration from pending -> active */
  1787. promisc_inactive(rxf->rxmode_pending,
  1788. rxf->rxmode_pending_bitmask);
  1789. rxf->rxmode_active &= ~BNA_RXMODE_PROMISC;
  1790. bna->rxf_promisc_id = BFI_MAX_RXF;
  1791. /* Revert VLAN filter */
  1792. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1793. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_PROMISCUOUS_SET_REQ,
  1794. BNA_STATUS_T_DISABLED);
  1795. return 1;
  1796. }
  1797. return 0;
  1798. }
  1799. int
  1800. rxf_process_packet_filter_default(struct bna_rxf *rxf)
  1801. {
  1802. struct bna *bna = rxf->rx->bna;
  1803. /* Enable/disable default mode */
  1804. if (is_default_enable(rxf->rxmode_pending,
  1805. rxf->rxmode_pending_bitmask)) {
  1806. /* move default configuration from pending -> active */
  1807. default_inactive(rxf->rxmode_pending,
  1808. rxf->rxmode_pending_bitmask);
  1809. rxf->rxmode_active |= BNA_RXMODE_DEFAULT;
  1810. /* Disable VLAN filter to allow all VLANs */
  1811. __rxf_vlan_filter_set(rxf, BNA_STATUS_T_DISABLED);
  1812. /* Redirect all other RxF vlan filtering to this one */
  1813. __rxf_default_function_config(rxf, BNA_STATUS_T_ENABLED);
  1814. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_DEFAULT_SET_REQ,
  1815. BNA_STATUS_T_ENABLED);
  1816. return 1;
  1817. } else if (is_default_disable(rxf->rxmode_pending,
  1818. rxf->rxmode_pending_bitmask)) {
  1819. /* move default configuration from pending -> active */
  1820. default_inactive(rxf->rxmode_pending,
  1821. rxf->rxmode_pending_bitmask);
  1822. rxf->rxmode_active &= ~BNA_RXMODE_DEFAULT;
  1823. bna->rxf_default_id = BFI_MAX_RXF;
  1824. /* Revert VLAN filter */
  1825. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1826. /* Stop RxF vlan filter table redirection */
  1827. __rxf_default_function_config(rxf, BNA_STATUS_T_DISABLED);
  1828. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_DEFAULT_SET_REQ,
  1829. BNA_STATUS_T_DISABLED);
  1830. return 1;
  1831. }
  1832. return 0;
  1833. }
  1834. int
  1835. rxf_process_packet_filter_allmulti(struct bna_rxf *rxf)
  1836. {
  1837. /* Enable/disable allmulti mode */
  1838. if (is_allmulti_enable(rxf->rxmode_pending,
  1839. rxf->rxmode_pending_bitmask)) {
  1840. /* move allmulti configuration from pending -> active */
  1841. allmulti_inactive(rxf->rxmode_pending,
  1842. rxf->rxmode_pending_bitmask);
  1843. rxf->rxmode_active |= BNA_RXMODE_ALLMULTI;
  1844. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_FILTER_REQ,
  1845. BNA_STATUS_T_ENABLED);
  1846. return 1;
  1847. } else if (is_allmulti_disable(rxf->rxmode_pending,
  1848. rxf->rxmode_pending_bitmask)) {
  1849. /* move allmulti configuration from pending -> active */
  1850. allmulti_inactive(rxf->rxmode_pending,
  1851. rxf->rxmode_pending_bitmask);
  1852. rxf->rxmode_active &= ~BNA_RXMODE_ALLMULTI;
  1853. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_FILTER_REQ,
  1854. BNA_STATUS_T_DISABLED);
  1855. return 1;
  1856. }
  1857. return 0;
  1858. }
  1859. int
  1860. rxf_clear_packet_filter_ucast(struct bna_rxf *rxf)
  1861. {
  1862. struct bna_mac *mac = NULL;
  1863. struct list_head *qe;
  1864. /* 1. delete pending ucast entries */
  1865. if (!list_empty(&rxf->ucast_pending_del_q)) {
  1866. bfa_q_deq(&rxf->ucast_pending_del_q, &qe);
  1867. bfa_q_qe_init(qe);
  1868. mac = (struct bna_mac *)qe;
  1869. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_UCAST_DEL_REQ, mac);
  1870. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod, mac);
  1871. return 1;
  1872. }
  1873. /* 2. clear active ucast entries; move them to pending_add_q */
  1874. if (!list_empty(&rxf->ucast_active_q)) {
  1875. bfa_q_deq(&rxf->ucast_active_q, &qe);
  1876. bfa_q_qe_init(qe);
  1877. mac = (struct bna_mac *)qe;
  1878. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_UCAST_DEL_REQ, mac);
  1879. list_add_tail(&mac->qe, &rxf->ucast_pending_add_q);
  1880. return 1;
  1881. }
  1882. return 0;
  1883. }
  1884. int
  1885. rxf_clear_packet_filter_promisc(struct bna_rxf *rxf)
  1886. {
  1887. struct bna *bna = rxf->rx->bna;
  1888. /* 6. Execute pending promisc mode disable command */
  1889. if (is_promisc_disable(rxf->rxmode_pending,
  1890. rxf->rxmode_pending_bitmask)) {
  1891. /* move promisc configuration from pending -> active */
  1892. promisc_inactive(rxf->rxmode_pending,
  1893. rxf->rxmode_pending_bitmask);
  1894. rxf->rxmode_active &= ~BNA_RXMODE_PROMISC;
  1895. bna->rxf_promisc_id = BFI_MAX_RXF;
  1896. /* Revert VLAN filter */
  1897. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1898. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_PROMISCUOUS_SET_REQ,
  1899. BNA_STATUS_T_DISABLED);
  1900. return 1;
  1901. }
  1902. /* 7. Clear active promisc mode; move it to pending enable */
  1903. if (rxf->rxmode_active & BNA_RXMODE_PROMISC) {
  1904. /* move promisc configuration from active -> pending */
  1905. promisc_enable(rxf->rxmode_pending,
  1906. rxf->rxmode_pending_bitmask);
  1907. rxf->rxmode_active &= ~BNA_RXMODE_PROMISC;
  1908. /* Revert VLAN filter */
  1909. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1910. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_PROMISCUOUS_SET_REQ,
  1911. BNA_STATUS_T_DISABLED);
  1912. return 1;
  1913. }
  1914. return 0;
  1915. }
  1916. int
  1917. rxf_clear_packet_filter_default(struct bna_rxf *rxf)
  1918. {
  1919. struct bna *bna = rxf->rx->bna;
  1920. /* 8. Execute pending default mode disable command */
  1921. if (is_default_disable(rxf->rxmode_pending,
  1922. rxf->rxmode_pending_bitmask)) {
  1923. /* move default configuration from pending -> active */
  1924. default_inactive(rxf->rxmode_pending,
  1925. rxf->rxmode_pending_bitmask);
  1926. rxf->rxmode_active &= ~BNA_RXMODE_DEFAULT;
  1927. bna->rxf_default_id = BFI_MAX_RXF;
  1928. /* Revert VLAN filter */
  1929. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1930. /* Stop RxF vlan filter table redirection */
  1931. __rxf_default_function_config(rxf, BNA_STATUS_T_DISABLED);
  1932. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_DEFAULT_SET_REQ,
  1933. BNA_STATUS_T_DISABLED);
  1934. return 1;
  1935. }
  1936. /* 9. Clear active default mode; move it to pending enable */
  1937. if (rxf->rxmode_active & BNA_RXMODE_DEFAULT) {
  1938. /* move default configuration from active -> pending */
  1939. default_enable(rxf->rxmode_pending,
  1940. rxf->rxmode_pending_bitmask);
  1941. rxf->rxmode_active &= ~BNA_RXMODE_DEFAULT;
  1942. /* Revert VLAN filter */
  1943. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1944. /* Stop RxF vlan filter table redirection */
  1945. __rxf_default_function_config(rxf, BNA_STATUS_T_DISABLED);
  1946. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_RXF_DEFAULT_SET_REQ,
  1947. BNA_STATUS_T_DISABLED);
  1948. return 1;
  1949. }
  1950. return 0;
  1951. }
  1952. int
  1953. rxf_clear_packet_filter_allmulti(struct bna_rxf *rxf)
  1954. {
  1955. /* 10. Execute pending allmulti mode disable command */
  1956. if (is_allmulti_disable(rxf->rxmode_pending,
  1957. rxf->rxmode_pending_bitmask)) {
  1958. /* move allmulti configuration from pending -> active */
  1959. allmulti_inactive(rxf->rxmode_pending,
  1960. rxf->rxmode_pending_bitmask);
  1961. rxf->rxmode_active &= ~BNA_RXMODE_ALLMULTI;
  1962. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_FILTER_REQ,
  1963. BNA_STATUS_T_DISABLED);
  1964. return 1;
  1965. }
  1966. /* 11. Clear active allmulti mode; move it to pending enable */
  1967. if (rxf->rxmode_active & BNA_RXMODE_ALLMULTI) {
  1968. /* move allmulti configuration from active -> pending */
  1969. allmulti_enable(rxf->rxmode_pending,
  1970. rxf->rxmode_pending_bitmask);
  1971. rxf->rxmode_active &= ~BNA_RXMODE_ALLMULTI;
  1972. rxf_fltr_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_FILTER_REQ,
  1973. BNA_STATUS_T_DISABLED);
  1974. return 1;
  1975. }
  1976. return 0;
  1977. }
  1978. void
  1979. rxf_reset_packet_filter_ucast(struct bna_rxf *rxf)
  1980. {
  1981. struct list_head *qe;
  1982. struct bna_mac *mac;
  1983. /* 1. Move active ucast entries to pending_add_q */
  1984. while (!list_empty(&rxf->ucast_active_q)) {
  1985. bfa_q_deq(&rxf->ucast_active_q, &qe);
  1986. bfa_q_qe_init(qe);
  1987. list_add_tail(qe, &rxf->ucast_pending_add_q);
  1988. }
  1989. /* 2. Throw away delete pending ucast entries */
  1990. while (!list_empty(&rxf->ucast_pending_del_q)) {
  1991. bfa_q_deq(&rxf->ucast_pending_del_q, &qe);
  1992. bfa_q_qe_init(qe);
  1993. mac = (struct bna_mac *)qe;
  1994. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod, mac);
  1995. }
  1996. }
  1997. void
  1998. rxf_reset_packet_filter_promisc(struct bna_rxf *rxf)
  1999. {
  2000. struct bna *bna = rxf->rx->bna;
  2001. /* 6. Clear pending promisc mode disable */
  2002. if (is_promisc_disable(rxf->rxmode_pending,
  2003. rxf->rxmode_pending_bitmask)) {
  2004. promisc_inactive(rxf->rxmode_pending,
  2005. rxf->rxmode_pending_bitmask);
  2006. rxf->rxmode_active &= ~BNA_RXMODE_PROMISC;
  2007. bna->rxf_promisc_id = BFI_MAX_RXF;
  2008. }
  2009. /* 7. Move promisc mode config from active -> pending */
  2010. if (rxf->rxmode_active & BNA_RXMODE_PROMISC) {
  2011. promisc_enable(rxf->rxmode_pending,
  2012. rxf->rxmode_pending_bitmask);
  2013. rxf->rxmode_active &= ~BNA_RXMODE_PROMISC;
  2014. }
  2015. }
  2016. void
  2017. rxf_reset_packet_filter_default(struct bna_rxf *rxf)
  2018. {
  2019. struct bna *bna = rxf->rx->bna;
  2020. /* 8. Clear pending default mode disable */
  2021. if (is_default_disable(rxf->rxmode_pending,
  2022. rxf->rxmode_pending_bitmask)) {
  2023. default_inactive(rxf->rxmode_pending,
  2024. rxf->rxmode_pending_bitmask);
  2025. rxf->rxmode_active &= ~BNA_RXMODE_DEFAULT;
  2026. bna->rxf_default_id = BFI_MAX_RXF;
  2027. }
  2028. /* 9. Move default mode config from active -> pending */
  2029. if (rxf->rxmode_active & BNA_RXMODE_DEFAULT) {
  2030. default_enable(rxf->rxmode_pending,
  2031. rxf->rxmode_pending_bitmask);
  2032. rxf->rxmode_active &= ~BNA_RXMODE_DEFAULT;
  2033. }
  2034. }
  2035. void
  2036. rxf_reset_packet_filter_allmulti(struct bna_rxf *rxf)
  2037. {
  2038. /* 10. Clear pending allmulti mode disable */
  2039. if (is_allmulti_disable(rxf->rxmode_pending,
  2040. rxf->rxmode_pending_bitmask)) {
  2041. allmulti_inactive(rxf->rxmode_pending,
  2042. rxf->rxmode_pending_bitmask);
  2043. rxf->rxmode_active &= ~BNA_RXMODE_ALLMULTI;
  2044. }
  2045. /* 11. Move allmulti mode config from active -> pending */
  2046. if (rxf->rxmode_active & BNA_RXMODE_ALLMULTI) {
  2047. allmulti_enable(rxf->rxmode_pending,
  2048. rxf->rxmode_pending_bitmask);
  2049. rxf->rxmode_active &= ~BNA_RXMODE_ALLMULTI;
  2050. }
  2051. }
  2052. /**
  2053. * Should only be called by bna_rxf_mode_set.
  2054. * Helps deciding if h/w configuration is needed or not.
  2055. * Returns:
  2056. * 0 = no h/w change
  2057. * 1 = need h/w change
  2058. */
  2059. static int
  2060. rxf_promisc_enable(struct bna_rxf *rxf)
  2061. {
  2062. struct bna *bna = rxf->rx->bna;
  2063. int ret = 0;
  2064. /* There can not be any pending disable command */
  2065. /* Do nothing if pending enable or already enabled */
  2066. if (is_promisc_enable(rxf->rxmode_pending,
  2067. rxf->rxmode_pending_bitmask) ||
  2068. (rxf->rxmode_active & BNA_RXMODE_PROMISC)) {
  2069. /* Schedule enable */
  2070. } else {
  2071. /* Promisc mode should not be active in the system */
  2072. promisc_enable(rxf->rxmode_pending,
  2073. rxf->rxmode_pending_bitmask);
  2074. bna->rxf_promisc_id = rxf->rxf_id;
  2075. ret = 1;
  2076. }
  2077. return ret;
  2078. }
  2079. /**
  2080. * Should only be called by bna_rxf_mode_set.
  2081. * Helps deciding if h/w configuration is needed or not.
  2082. * Returns:
  2083. * 0 = no h/w change
  2084. * 1 = need h/w change
  2085. */
  2086. static int
  2087. rxf_promisc_disable(struct bna_rxf *rxf)
  2088. {
  2089. struct bna *bna = rxf->rx->bna;
  2090. int ret = 0;
  2091. /* There can not be any pending disable */
  2092. /* Turn off pending enable command , if any */
  2093. if (is_promisc_enable(rxf->rxmode_pending,
  2094. rxf->rxmode_pending_bitmask)) {
  2095. /* Promisc mode should not be active */
  2096. /* system promisc state should be pending */
  2097. promisc_inactive(rxf->rxmode_pending,
  2098. rxf->rxmode_pending_bitmask);
  2099. /* Remove the promisc state from the system */
  2100. bna->rxf_promisc_id = BFI_MAX_RXF;
  2101. /* Schedule disable */
  2102. } else if (rxf->rxmode_active & BNA_RXMODE_PROMISC) {
  2103. /* Promisc mode should be active in the system */
  2104. promisc_disable(rxf->rxmode_pending,
  2105. rxf->rxmode_pending_bitmask);
  2106. ret = 1;
  2107. /* Do nothing if already disabled */
  2108. } else {
  2109. }
  2110. return ret;
  2111. }
  2112. /**
  2113. * Should only be called by bna_rxf_mode_set.
  2114. * Helps deciding if h/w configuration is needed or not.
  2115. * Returns:
  2116. * 0 = no h/w change
  2117. * 1 = need h/w change
  2118. */
  2119. static int
  2120. rxf_default_enable(struct bna_rxf *rxf)
  2121. {
  2122. struct bna *bna = rxf->rx->bna;
  2123. int ret = 0;
  2124. /* There can not be any pending disable command */
  2125. /* Do nothing if pending enable or already enabled */
  2126. if (is_default_enable(rxf->rxmode_pending,
  2127. rxf->rxmode_pending_bitmask) ||
  2128. (rxf->rxmode_active & BNA_RXMODE_DEFAULT)) {
  2129. /* Schedule enable */
  2130. } else {
  2131. /* Default mode should not be active in the system */
  2132. default_enable(rxf->rxmode_pending,
  2133. rxf->rxmode_pending_bitmask);
  2134. bna->rxf_default_id = rxf->rxf_id;
  2135. ret = 1;
  2136. }
  2137. return ret;
  2138. }
  2139. /**
  2140. * Should only be called by bna_rxf_mode_set.
  2141. * Helps deciding if h/w configuration is needed or not.
  2142. * Returns:
  2143. * 0 = no h/w change
  2144. * 1 = need h/w change
  2145. */
  2146. static int
  2147. rxf_default_disable(struct bna_rxf *rxf)
  2148. {
  2149. struct bna *bna = rxf->rx->bna;
  2150. int ret = 0;
  2151. /* There can not be any pending disable */
  2152. /* Turn off pending enable command , if any */
  2153. if (is_default_enable(rxf->rxmode_pending,
  2154. rxf->rxmode_pending_bitmask)) {
  2155. /* Promisc mode should not be active */
  2156. /* system default state should be pending */
  2157. default_inactive(rxf->rxmode_pending,
  2158. rxf->rxmode_pending_bitmask);
  2159. /* Remove the default state from the system */
  2160. bna->rxf_default_id = BFI_MAX_RXF;
  2161. /* Schedule disable */
  2162. } else if (rxf->rxmode_active & BNA_RXMODE_DEFAULT) {
  2163. /* Default mode should be active in the system */
  2164. default_disable(rxf->rxmode_pending,
  2165. rxf->rxmode_pending_bitmask);
  2166. ret = 1;
  2167. /* Do nothing if already disabled */
  2168. } else {
  2169. }
  2170. return ret;
  2171. }
  2172. /**
  2173. * Should only be called by bna_rxf_mode_set.
  2174. * Helps deciding if h/w configuration is needed or not.
  2175. * Returns:
  2176. * 0 = no h/w change
  2177. * 1 = need h/w change
  2178. */
  2179. static int
  2180. rxf_allmulti_enable(struct bna_rxf *rxf)
  2181. {
  2182. int ret = 0;
  2183. /* There can not be any pending disable command */
  2184. /* Do nothing if pending enable or already enabled */
  2185. if (is_allmulti_enable(rxf->rxmode_pending,
  2186. rxf->rxmode_pending_bitmask) ||
  2187. (rxf->rxmode_active & BNA_RXMODE_ALLMULTI)) {
  2188. /* Schedule enable */
  2189. } else {
  2190. allmulti_enable(rxf->rxmode_pending,
  2191. rxf->rxmode_pending_bitmask);
  2192. ret = 1;
  2193. }
  2194. return ret;
  2195. }
  2196. /**
  2197. * Should only be called by bna_rxf_mode_set.
  2198. * Helps deciding if h/w configuration is needed or not.
  2199. * Returns:
  2200. * 0 = no h/w change
  2201. * 1 = need h/w change
  2202. */
  2203. static int
  2204. rxf_allmulti_disable(struct bna_rxf *rxf)
  2205. {
  2206. int ret = 0;
  2207. /* There can not be any pending disable */
  2208. /* Turn off pending enable command , if any */
  2209. if (is_allmulti_enable(rxf->rxmode_pending,
  2210. rxf->rxmode_pending_bitmask)) {
  2211. /* Allmulti mode should not be active */
  2212. allmulti_inactive(rxf->rxmode_pending,
  2213. rxf->rxmode_pending_bitmask);
  2214. /* Schedule disable */
  2215. } else if (rxf->rxmode_active & BNA_RXMODE_ALLMULTI) {
  2216. allmulti_disable(rxf->rxmode_pending,
  2217. rxf->rxmode_pending_bitmask);
  2218. ret = 1;
  2219. }
  2220. return ret;
  2221. }
  2222. /* RxF <- bnad */
  2223. enum bna_cb_status
  2224. bna_rx_mode_set(struct bna_rx *rx, enum bna_rxmode new_mode,
  2225. enum bna_rxmode bitmask,
  2226. void (*cbfn)(struct bnad *, struct bna_rx *,
  2227. enum bna_cb_status))
  2228. {
  2229. struct bna_rxf *rxf = &rx->rxf;
  2230. int need_hw_config = 0;
  2231. /* Error checks */
  2232. if (is_promisc_enable(new_mode, bitmask)) {
  2233. /* If promisc mode is already enabled elsewhere in the system */
  2234. if ((rx->bna->rxf_promisc_id != BFI_MAX_RXF) &&
  2235. (rx->bna->rxf_promisc_id != rxf->rxf_id))
  2236. goto err_return;
  2237. /* If default mode is already enabled in the system */
  2238. if (rx->bna->rxf_default_id != BFI_MAX_RXF)
  2239. goto err_return;
  2240. /* Trying to enable promiscuous and default mode together */
  2241. if (is_default_enable(new_mode, bitmask))
  2242. goto err_return;
  2243. }
  2244. if (is_default_enable(new_mode, bitmask)) {
  2245. /* If default mode is already enabled elsewhere in the system */
  2246. if ((rx->bna->rxf_default_id != BFI_MAX_RXF) &&
  2247. (rx->bna->rxf_default_id != rxf->rxf_id)) {
  2248. goto err_return;
  2249. }
  2250. /* If promiscuous mode is already enabled in the system */
  2251. if (rx->bna->rxf_promisc_id != BFI_MAX_RXF)
  2252. goto err_return;
  2253. }
  2254. /* Process the commands */
  2255. if (is_promisc_enable(new_mode, bitmask)) {
  2256. if (rxf_promisc_enable(rxf))
  2257. need_hw_config = 1;
  2258. } else if (is_promisc_disable(new_mode, bitmask)) {
  2259. if (rxf_promisc_disable(rxf))
  2260. need_hw_config = 1;
  2261. }
  2262. if (is_default_enable(new_mode, bitmask)) {
  2263. if (rxf_default_enable(rxf))
  2264. need_hw_config = 1;
  2265. } else if (is_default_disable(new_mode, bitmask)) {
  2266. if (rxf_default_disable(rxf))
  2267. need_hw_config = 1;
  2268. }
  2269. if (is_allmulti_enable(new_mode, bitmask)) {
  2270. if (rxf_allmulti_enable(rxf))
  2271. need_hw_config = 1;
  2272. } else if (is_allmulti_disable(new_mode, bitmask)) {
  2273. if (rxf_allmulti_disable(rxf))
  2274. need_hw_config = 1;
  2275. }
  2276. /* Trigger h/w if needed */
  2277. if (need_hw_config) {
  2278. rxf->cam_fltr_cbfn = cbfn;
  2279. rxf->cam_fltr_cbarg = rx->bna->bnad;
  2280. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  2281. } else if (cbfn)
  2282. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  2283. return BNA_CB_SUCCESS;
  2284. err_return:
  2285. return BNA_CB_FAIL;
  2286. }
  2287. void
  2288. /* RxF <- bnad */
  2289. bna_rx_vlanfilter_enable(struct bna_rx *rx)
  2290. {
  2291. struct bna_rxf *rxf = &rx->rxf;
  2292. if (rxf->vlan_filter_status == BNA_STATUS_T_DISABLED) {
  2293. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  2294. rxf->vlan_filter_status = BNA_STATUS_T_ENABLED;
  2295. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  2296. }
  2297. }
  2298. /* Rx */
  2299. /* Rx <- bnad */
  2300. void
  2301. bna_rx_coalescing_timeo_set(struct bna_rx *rx, int coalescing_timeo)
  2302. {
  2303. struct bna_rxp *rxp;
  2304. struct list_head *qe;
  2305. list_for_each(qe, &rx->rxp_q) {
  2306. rxp = (struct bna_rxp *)qe;
  2307. rxp->cq.ccb->rx_coalescing_timeo = coalescing_timeo;
  2308. bna_ib_coalescing_timeo_set(rxp->cq.ib, coalescing_timeo);
  2309. }
  2310. }
  2311. /* Rx <- bnad */
  2312. void
  2313. bna_rx_dim_reconfig(struct bna *bna, const u32 vector[][BNA_BIAS_T_MAX])
  2314. {
  2315. int i, j;
  2316. for (i = 0; i < BNA_LOAD_T_MAX; i++)
  2317. for (j = 0; j < BNA_BIAS_T_MAX; j++)
  2318. bna->rx_mod.dim_vector[i][j] = vector[i][j];
  2319. }
  2320. /* Rx <- bnad */
  2321. void
  2322. bna_rx_dim_update(struct bna_ccb *ccb)
  2323. {
  2324. struct bna *bna = ccb->cq->rx->bna;
  2325. u32 load, bias;
  2326. u32 pkt_rt, small_rt, large_rt;
  2327. u8 coalescing_timeo;
  2328. if ((ccb->pkt_rate.small_pkt_cnt == 0) &&
  2329. (ccb->pkt_rate.large_pkt_cnt == 0))
  2330. return;
  2331. /* Arrive at preconfigured coalescing timeo value based on pkt rate */
  2332. small_rt = ccb->pkt_rate.small_pkt_cnt;
  2333. large_rt = ccb->pkt_rate.large_pkt_cnt;
  2334. pkt_rt = small_rt + large_rt;
  2335. if (pkt_rt < BNA_PKT_RATE_10K)
  2336. load = BNA_LOAD_T_LOW_4;
  2337. else if (pkt_rt < BNA_PKT_RATE_20K)
  2338. load = BNA_LOAD_T_LOW_3;
  2339. else if (pkt_rt < BNA_PKT_RATE_30K)
  2340. load = BNA_LOAD_T_LOW_2;
  2341. else if (pkt_rt < BNA_PKT_RATE_40K)
  2342. load = BNA_LOAD_T_LOW_1;
  2343. else if (pkt_rt < BNA_PKT_RATE_50K)
  2344. load = BNA_LOAD_T_HIGH_1;
  2345. else if (pkt_rt < BNA_PKT_RATE_60K)
  2346. load = BNA_LOAD_T_HIGH_2;
  2347. else if (pkt_rt < BNA_PKT_RATE_80K)
  2348. load = BNA_LOAD_T_HIGH_3;
  2349. else
  2350. load = BNA_LOAD_T_HIGH_4;
  2351. if (small_rt > (large_rt << 1))
  2352. bias = 0;
  2353. else
  2354. bias = 1;
  2355. ccb->pkt_rate.small_pkt_cnt = 0;
  2356. ccb->pkt_rate.large_pkt_cnt = 0;
  2357. coalescing_timeo = bna->rx_mod.dim_vector[load][bias];
  2358. ccb->rx_coalescing_timeo = coalescing_timeo;
  2359. /* Set it to IB */
  2360. bna_ib_coalescing_timeo_set(ccb->cq->ib, coalescing_timeo);
  2361. }
  2362. /* Tx */
  2363. /* TX <- bnad */
  2364. void
  2365. bna_tx_coalescing_timeo_set(struct bna_tx *tx, int coalescing_timeo)
  2366. {
  2367. struct bna_txq *txq;
  2368. struct list_head *qe;
  2369. list_for_each(qe, &tx->txq_q) {
  2370. txq = (struct bna_txq *)qe;
  2371. bna_ib_coalescing_timeo_set(txq->ib, coalescing_timeo);
  2372. }
  2373. }
  2374. /*
  2375. * Private data
  2376. */
  2377. struct bna_ritseg_pool_cfg {
  2378. u32 pool_size;
  2379. u32 pool_entry_size;
  2380. };
  2381. init_ritseg_pool(ritseg_pool_cfg);
  2382. /*
  2383. * Private functions
  2384. */
  2385. static void
  2386. bna_ucam_mod_init(struct bna_ucam_mod *ucam_mod, struct bna *bna,
  2387. struct bna_res_info *res_info)
  2388. {
  2389. int i;
  2390. ucam_mod->ucmac = (struct bna_mac *)
  2391. res_info[BNA_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.mdl[0].kva;
  2392. INIT_LIST_HEAD(&ucam_mod->free_q);
  2393. for (i = 0; i < BFI_MAX_UCMAC; i++) {
  2394. bfa_q_qe_init(&ucam_mod->ucmac[i].qe);
  2395. list_add_tail(&ucam_mod->ucmac[i].qe, &ucam_mod->free_q);
  2396. }
  2397. ucam_mod->bna = bna;
  2398. }
  2399. static void
  2400. bna_ucam_mod_uninit(struct bna_ucam_mod *ucam_mod)
  2401. {
  2402. struct list_head *qe;
  2403. int i = 0;
  2404. list_for_each(qe, &ucam_mod->free_q)
  2405. i++;
  2406. ucam_mod->bna = NULL;
  2407. }
  2408. static void
  2409. bna_mcam_mod_init(struct bna_mcam_mod *mcam_mod, struct bna *bna,
  2410. struct bna_res_info *res_info)
  2411. {
  2412. int i;
  2413. mcam_mod->mcmac = (struct bna_mac *)
  2414. res_info[BNA_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.mdl[0].kva;
  2415. INIT_LIST_HEAD(&mcam_mod->free_q);
  2416. for (i = 0; i < BFI_MAX_MCMAC; i++) {
  2417. bfa_q_qe_init(&mcam_mod->mcmac[i].qe);
  2418. list_add_tail(&mcam_mod->mcmac[i].qe, &mcam_mod->free_q);
  2419. }
  2420. mcam_mod->bna = bna;
  2421. }
  2422. static void
  2423. bna_mcam_mod_uninit(struct bna_mcam_mod *mcam_mod)
  2424. {
  2425. struct list_head *qe;
  2426. int i = 0;
  2427. list_for_each(qe, &mcam_mod->free_q)
  2428. i++;
  2429. mcam_mod->bna = NULL;
  2430. }
  2431. static void
  2432. bna_rit_mod_init(struct bna_rit_mod *rit_mod,
  2433. struct bna_res_info *res_info)
  2434. {
  2435. int i;
  2436. int j;
  2437. int count;
  2438. int offset;
  2439. rit_mod->rit = (struct bna_rit_entry *)
  2440. res_info[BNA_RES_MEM_T_RIT_ENTRY].res_u.mem_info.mdl[0].kva;
  2441. rit_mod->rit_segment = (struct bna_rit_segment *)
  2442. res_info[BNA_RES_MEM_T_RIT_SEGMENT].res_u.mem_info.mdl[0].kva;
  2443. count = 0;
  2444. offset = 0;
  2445. for (i = 0; i < BFI_RIT_SEG_TOTAL_POOLS; i++) {
  2446. INIT_LIST_HEAD(&rit_mod->rit_seg_pool[i]);
  2447. for (j = 0; j < ritseg_pool_cfg[i].pool_size; j++) {
  2448. bfa_q_qe_init(&rit_mod->rit_segment[count].qe);
  2449. rit_mod->rit_segment[count].max_rit_size =
  2450. ritseg_pool_cfg[i].pool_entry_size;
  2451. rit_mod->rit_segment[count].rit_offset = offset;
  2452. rit_mod->rit_segment[count].rit =
  2453. &rit_mod->rit[offset];
  2454. list_add_tail(&rit_mod->rit_segment[count].qe,
  2455. &rit_mod->rit_seg_pool[i]);
  2456. count++;
  2457. offset += ritseg_pool_cfg[i].pool_entry_size;
  2458. }
  2459. }
  2460. }
  2461. static void
  2462. bna_rit_mod_uninit(struct bna_rit_mod *rit_mod)
  2463. {
  2464. struct bna_rit_segment *rit_segment;
  2465. struct list_head *qe;
  2466. int i;
  2467. int j;
  2468. for (i = 0; i < BFI_RIT_SEG_TOTAL_POOLS; i++) {
  2469. j = 0;
  2470. list_for_each(qe, &rit_mod->rit_seg_pool[i]) {
  2471. rit_segment = (struct bna_rit_segment *)qe;
  2472. j++;
  2473. }
  2474. }
  2475. }
  2476. /*
  2477. * Public functions
  2478. */
  2479. /* Called during probe(), before calling bna_init() */
  2480. void
  2481. bna_res_req(struct bna_res_info *res_info)
  2482. {
  2483. bna_adv_res_req(res_info);
  2484. /* DMA memory for retrieving IOC attributes */
  2485. res_info[BNA_RES_MEM_T_ATTR].res_type = BNA_RES_T_MEM;
  2486. res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
  2487. res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.num = 1;
  2488. res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.len =
  2489. ALIGN(bfa_nw_ioc_meminfo(), PAGE_SIZE);
  2490. /* DMA memory for index segment of an IB */
  2491. res_info[BNA_RES_MEM_T_IBIDX].res_type = BNA_RES_T_MEM;
  2492. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
  2493. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.len =
  2494. BFI_IBIDX_SIZE * BFI_IBIDX_MAX_SEGSIZE;
  2495. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.num = BFI_MAX_IB;
  2496. /* Virtual memory for IB objects - stored by IB module */
  2497. res_info[BNA_RES_MEM_T_IB_ARRAY].res_type = BNA_RES_T_MEM;
  2498. res_info[BNA_RES_MEM_T_IB_ARRAY].res_u.mem_info.mem_type =
  2499. BNA_MEM_T_KVA;
  2500. res_info[BNA_RES_MEM_T_IB_ARRAY].res_u.mem_info.num = 1;
  2501. res_info[BNA_RES_MEM_T_IB_ARRAY].res_u.mem_info.len =
  2502. BFI_MAX_IB * sizeof(struct bna_ib);
  2503. /* Virtual memory for intr objects - stored by IB module */
  2504. res_info[BNA_RES_MEM_T_INTR_ARRAY].res_type = BNA_RES_T_MEM;
  2505. res_info[BNA_RES_MEM_T_INTR_ARRAY].res_u.mem_info.mem_type =
  2506. BNA_MEM_T_KVA;
  2507. res_info[BNA_RES_MEM_T_INTR_ARRAY].res_u.mem_info.num = 1;
  2508. res_info[BNA_RES_MEM_T_INTR_ARRAY].res_u.mem_info.len =
  2509. BFI_MAX_IB * sizeof(struct bna_intr);
  2510. /* Virtual memory for idx_seg objects - stored by IB module */
  2511. res_info[BNA_RES_MEM_T_IDXSEG_ARRAY].res_type = BNA_RES_T_MEM;
  2512. res_info[BNA_RES_MEM_T_IDXSEG_ARRAY].res_u.mem_info.mem_type =
  2513. BNA_MEM_T_KVA;
  2514. res_info[BNA_RES_MEM_T_IDXSEG_ARRAY].res_u.mem_info.num = 1;
  2515. res_info[BNA_RES_MEM_T_IDXSEG_ARRAY].res_u.mem_info.len =
  2516. BFI_IBIDX_TOTAL_SEGS * sizeof(struct bna_ibidx_seg);
  2517. /* Virtual memory for Tx objects - stored by Tx module */
  2518. res_info[BNA_RES_MEM_T_TX_ARRAY].res_type = BNA_RES_T_MEM;
  2519. res_info[BNA_RES_MEM_T_TX_ARRAY].res_u.mem_info.mem_type =
  2520. BNA_MEM_T_KVA;
  2521. res_info[BNA_RES_MEM_T_TX_ARRAY].res_u.mem_info.num = 1;
  2522. res_info[BNA_RES_MEM_T_TX_ARRAY].res_u.mem_info.len =
  2523. BFI_MAX_TXQ * sizeof(struct bna_tx);
  2524. /* Virtual memory for TxQ - stored by Tx module */
  2525. res_info[BNA_RES_MEM_T_TXQ_ARRAY].res_type = BNA_RES_T_MEM;
  2526. res_info[BNA_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.mem_type =
  2527. BNA_MEM_T_KVA;
  2528. res_info[BNA_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.num = 1;
  2529. res_info[BNA_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.len =
  2530. BFI_MAX_TXQ * sizeof(struct bna_txq);
  2531. /* Virtual memory for Rx objects - stored by Rx module */
  2532. res_info[BNA_RES_MEM_T_RX_ARRAY].res_type = BNA_RES_T_MEM;
  2533. res_info[BNA_RES_MEM_T_RX_ARRAY].res_u.mem_info.mem_type =
  2534. BNA_MEM_T_KVA;
  2535. res_info[BNA_RES_MEM_T_RX_ARRAY].res_u.mem_info.num = 1;
  2536. res_info[BNA_RES_MEM_T_RX_ARRAY].res_u.mem_info.len =
  2537. BFI_MAX_RXQ * sizeof(struct bna_rx);
  2538. /* Virtual memory for RxPath - stored by Rx module */
  2539. res_info[BNA_RES_MEM_T_RXP_ARRAY].res_type = BNA_RES_T_MEM;
  2540. res_info[BNA_RES_MEM_T_RXP_ARRAY].res_u.mem_info.mem_type =
  2541. BNA_MEM_T_KVA;
  2542. res_info[BNA_RES_MEM_T_RXP_ARRAY].res_u.mem_info.num = 1;
  2543. res_info[BNA_RES_MEM_T_RXP_ARRAY].res_u.mem_info.len =
  2544. BFI_MAX_RXQ * sizeof(struct bna_rxp);
  2545. /* Virtual memory for RxQ - stored by Rx module */
  2546. res_info[BNA_RES_MEM_T_RXQ_ARRAY].res_type = BNA_RES_T_MEM;
  2547. res_info[BNA_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.mem_type =
  2548. BNA_MEM_T_KVA;
  2549. res_info[BNA_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.num = 1;
  2550. res_info[BNA_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.len =
  2551. BFI_MAX_RXQ * sizeof(struct bna_rxq);
  2552. /* Virtual memory for Unicast MAC address - stored by ucam module */
  2553. res_info[BNA_RES_MEM_T_UCMAC_ARRAY].res_type = BNA_RES_T_MEM;
  2554. res_info[BNA_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.mem_type =
  2555. BNA_MEM_T_KVA;
  2556. res_info[BNA_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.num = 1;
  2557. res_info[BNA_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.len =
  2558. BFI_MAX_UCMAC * sizeof(struct bna_mac);
  2559. /* Virtual memory for Multicast MAC address - stored by mcam module */
  2560. res_info[BNA_RES_MEM_T_MCMAC_ARRAY].res_type = BNA_RES_T_MEM;
  2561. res_info[BNA_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.mem_type =
  2562. BNA_MEM_T_KVA;
  2563. res_info[BNA_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.num = 1;
  2564. res_info[BNA_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.len =
  2565. BFI_MAX_MCMAC * sizeof(struct bna_mac);
  2566. /* Virtual memory for RIT entries */
  2567. res_info[BNA_RES_MEM_T_RIT_ENTRY].res_type = BNA_RES_T_MEM;
  2568. res_info[BNA_RES_MEM_T_RIT_ENTRY].res_u.mem_info.mem_type =
  2569. BNA_MEM_T_KVA;
  2570. res_info[BNA_RES_MEM_T_RIT_ENTRY].res_u.mem_info.num = 1;
  2571. res_info[BNA_RES_MEM_T_RIT_ENTRY].res_u.mem_info.len =
  2572. BFI_MAX_RIT_SIZE * sizeof(struct bna_rit_entry);
  2573. /* Virtual memory for RIT segment table */
  2574. res_info[BNA_RES_MEM_T_RIT_SEGMENT].res_type = BNA_RES_T_MEM;
  2575. res_info[BNA_RES_MEM_T_RIT_SEGMENT].res_u.mem_info.mem_type =
  2576. BNA_MEM_T_KVA;
  2577. res_info[BNA_RES_MEM_T_RIT_SEGMENT].res_u.mem_info.num = 1;
  2578. res_info[BNA_RES_MEM_T_RIT_SEGMENT].res_u.mem_info.len =
  2579. BFI_RIT_TOTAL_SEGS * sizeof(struct bna_rit_segment);
  2580. /* Interrupt resource for mailbox interrupt */
  2581. res_info[BNA_RES_INTR_T_MBOX].res_type = BNA_RES_T_INTR;
  2582. res_info[BNA_RES_INTR_T_MBOX].res_u.intr_info.intr_type =
  2583. BNA_INTR_T_MSIX;
  2584. res_info[BNA_RES_INTR_T_MBOX].res_u.intr_info.num = 1;
  2585. }
  2586. /* Called during probe() */
  2587. void
  2588. bna_init(struct bna *bna, struct bnad *bnad, struct bfa_pcidev *pcidev,
  2589. struct bna_res_info *res_info)
  2590. {
  2591. bna->bnad = bnad;
  2592. bna->pcidev = *pcidev;
  2593. bna->stats.hw_stats = (struct bfi_ll_stats *)
  2594. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].kva;
  2595. bna->hw_stats_dma.msb =
  2596. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].dma.msb;
  2597. bna->hw_stats_dma.lsb =
  2598. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].dma.lsb;
  2599. bna->stats.sw_stats = (struct bna_sw_stats *)
  2600. res_info[BNA_RES_MEM_T_SWSTATS].res_u.mem_info.mdl[0].kva;
  2601. bna->regs.page_addr = bna->pcidev.pci_bar_kva +
  2602. reg_offset[bna->pcidev.pci_func].page_addr;
  2603. bna->regs.fn_int_status = bna->pcidev.pci_bar_kva +
  2604. reg_offset[bna->pcidev.pci_func].fn_int_status;
  2605. bna->regs.fn_int_mask = bna->pcidev.pci_bar_kva +
  2606. reg_offset[bna->pcidev.pci_func].fn_int_mask;
  2607. if (bna->pcidev.pci_func < 3)
  2608. bna->port_num = 0;
  2609. else
  2610. bna->port_num = 1;
  2611. /* Also initializes diag, cee, sfp, phy_port and mbox_mod */
  2612. bna_device_init(&bna->device, bna, res_info);
  2613. bna_port_init(&bna->port, bna);
  2614. bna_tx_mod_init(&bna->tx_mod, bna, res_info);
  2615. bna_rx_mod_init(&bna->rx_mod, bna, res_info);
  2616. bna_ib_mod_init(&bna->ib_mod, bna, res_info);
  2617. bna_rit_mod_init(&bna->rit_mod, res_info);
  2618. bna_ucam_mod_init(&bna->ucam_mod, bna, res_info);
  2619. bna_mcam_mod_init(&bna->mcam_mod, bna, res_info);
  2620. bna->rxf_default_id = BFI_MAX_RXF;
  2621. bna->rxf_promisc_id = BFI_MAX_RXF;
  2622. /* Mbox q element for posting stat request to f/w */
  2623. bfa_q_qe_init(&bna->mbox_qe.qe);
  2624. }
  2625. void
  2626. bna_uninit(struct bna *bna)
  2627. {
  2628. bna_mcam_mod_uninit(&bna->mcam_mod);
  2629. bna_ucam_mod_uninit(&bna->ucam_mod);
  2630. bna_rit_mod_uninit(&bna->rit_mod);
  2631. bna_ib_mod_uninit(&bna->ib_mod);
  2632. bna_rx_mod_uninit(&bna->rx_mod);
  2633. bna_tx_mod_uninit(&bna->tx_mod);
  2634. bna_port_uninit(&bna->port);
  2635. bna_device_uninit(&bna->device);
  2636. bna->bnad = NULL;
  2637. }
  2638. struct bna_mac *
  2639. bna_ucam_mod_mac_get(struct bna_ucam_mod *ucam_mod)
  2640. {
  2641. struct list_head *qe;
  2642. if (list_empty(&ucam_mod->free_q))
  2643. return NULL;
  2644. bfa_q_deq(&ucam_mod->free_q, &qe);
  2645. return (struct bna_mac *)qe;
  2646. }
  2647. void
  2648. bna_ucam_mod_mac_put(struct bna_ucam_mod *ucam_mod, struct bna_mac *mac)
  2649. {
  2650. list_add_tail(&mac->qe, &ucam_mod->free_q);
  2651. }
  2652. struct bna_mac *
  2653. bna_mcam_mod_mac_get(struct bna_mcam_mod *mcam_mod)
  2654. {
  2655. struct list_head *qe;
  2656. if (list_empty(&mcam_mod->free_q))
  2657. return NULL;
  2658. bfa_q_deq(&mcam_mod->free_q, &qe);
  2659. return (struct bna_mac *)qe;
  2660. }
  2661. void
  2662. bna_mcam_mod_mac_put(struct bna_mcam_mod *mcam_mod, struct bna_mac *mac)
  2663. {
  2664. list_add_tail(&mac->qe, &mcam_mod->free_q);
  2665. }
  2666. /**
  2667. * Note: This should be called in the same locking context as the call to
  2668. * bna_rit_mod_seg_get()
  2669. */
  2670. int
  2671. bna_rit_mod_can_satisfy(struct bna_rit_mod *rit_mod, int seg_size)
  2672. {
  2673. int i;
  2674. /* Select the pool for seg_size */
  2675. for (i = 0; i < BFI_RIT_SEG_TOTAL_POOLS; i++) {
  2676. if (seg_size <= ritseg_pool_cfg[i].pool_entry_size)
  2677. break;
  2678. }
  2679. if (i == BFI_RIT_SEG_TOTAL_POOLS)
  2680. return 0;
  2681. if (list_empty(&rit_mod->rit_seg_pool[i]))
  2682. return 0;
  2683. return 1;
  2684. }
  2685. struct bna_rit_segment *
  2686. bna_rit_mod_seg_get(struct bna_rit_mod *rit_mod, int seg_size)
  2687. {
  2688. struct bna_rit_segment *seg;
  2689. struct list_head *qe;
  2690. int i;
  2691. /* Select the pool for seg_size */
  2692. for (i = 0; i < BFI_RIT_SEG_TOTAL_POOLS; i++) {
  2693. if (seg_size <= ritseg_pool_cfg[i].pool_entry_size)
  2694. break;
  2695. }
  2696. if (i == BFI_RIT_SEG_TOTAL_POOLS)
  2697. return NULL;
  2698. if (list_empty(&rit_mod->rit_seg_pool[i]))
  2699. return NULL;
  2700. bfa_q_deq(&rit_mod->rit_seg_pool[i], &qe);
  2701. seg = (struct bna_rit_segment *)qe;
  2702. bfa_q_qe_init(&seg->qe);
  2703. seg->rit_size = seg_size;
  2704. return seg;
  2705. }
  2706. void
  2707. bna_rit_mod_seg_put(struct bna_rit_mod *rit_mod,
  2708. struct bna_rit_segment *seg)
  2709. {
  2710. int i;
  2711. /* Select the pool for seg->max_rit_size */
  2712. for (i = 0; i < BFI_RIT_SEG_TOTAL_POOLS; i++) {
  2713. if (seg->max_rit_size == ritseg_pool_cfg[i].pool_entry_size)
  2714. break;
  2715. }
  2716. seg->rit_size = 0;
  2717. list_add_tail(&seg->qe, &rit_mod->rit_seg_pool[i]);
  2718. }