bna_ctrl.c 75 KB

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