bna_ctrl.c 74 KB

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