bnad.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427
  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 <linux/bitops.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/in.h>
  23. #include <linux/ethtool.h>
  24. #include <linux/if_vlan.h>
  25. #include <linux/if_ether.h>
  26. #include <linux/ip.h>
  27. #include <linux/prefetch.h>
  28. #include "bnad.h"
  29. #include "bna.h"
  30. #include "cna.h"
  31. static DEFINE_MUTEX(bnad_fwimg_mutex);
  32. /*
  33. * Module params
  34. */
  35. static uint bnad_msix_disable;
  36. module_param(bnad_msix_disable, uint, 0444);
  37. MODULE_PARM_DESC(bnad_msix_disable, "Disable MSIX mode");
  38. static uint bnad_ioc_auto_recover = 1;
  39. module_param(bnad_ioc_auto_recover, uint, 0444);
  40. MODULE_PARM_DESC(bnad_ioc_auto_recover, "Enable / Disable auto recovery");
  41. /*
  42. * Global variables
  43. */
  44. u32 bnad_rxqs_per_cq = 2;
  45. static const u8 bnad_bcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  46. /*
  47. * Local MACROS
  48. */
  49. #define BNAD_TX_UNMAPQ_DEPTH (bnad->txq_depth * 2)
  50. #define BNAD_RX_UNMAPQ_DEPTH (bnad->rxq_depth)
  51. #define BNAD_GET_MBOX_IRQ(_bnad) \
  52. (((_bnad)->cfg_flags & BNAD_CF_MSIX) ? \
  53. ((_bnad)->msix_table[BNAD_MAILBOX_MSIX_INDEX].vector) : \
  54. ((_bnad)->pcidev->irq))
  55. #define BNAD_FILL_UNMAPQ_MEM_REQ(_res_info, _num, _depth) \
  56. do { \
  57. (_res_info)->res_type = BNA_RES_T_MEM; \
  58. (_res_info)->res_u.mem_info.mem_type = BNA_MEM_T_KVA; \
  59. (_res_info)->res_u.mem_info.num = (_num); \
  60. (_res_info)->res_u.mem_info.len = \
  61. sizeof(struct bnad_unmap_q) + \
  62. (sizeof(struct bnad_skb_unmap) * ((_depth) - 1)); \
  63. } while (0)
  64. #define BNAD_TXRX_SYNC_MDELAY 250 /* 250 msecs */
  65. /*
  66. * Reinitialize completions in CQ, once Rx is taken down
  67. */
  68. static void
  69. bnad_cq_cmpl_init(struct bnad *bnad, struct bna_ccb *ccb)
  70. {
  71. struct bna_cq_entry *cmpl, *next_cmpl;
  72. unsigned int wi_range, wis = 0, ccb_prod = 0;
  73. int i;
  74. BNA_CQ_QPGE_PTR_GET(ccb_prod, ccb->sw_qpt, cmpl,
  75. wi_range);
  76. for (i = 0; i < ccb->q_depth; i++) {
  77. wis++;
  78. if (likely(--wi_range))
  79. next_cmpl = cmpl + 1;
  80. else {
  81. BNA_QE_INDX_ADD(ccb_prod, wis, ccb->q_depth);
  82. wis = 0;
  83. BNA_CQ_QPGE_PTR_GET(ccb_prod, ccb->sw_qpt,
  84. next_cmpl, wi_range);
  85. }
  86. cmpl->valid = 0;
  87. cmpl = next_cmpl;
  88. }
  89. }
  90. /*
  91. * Frees all pending Tx Bufs
  92. * At this point no activity is expected on the Q,
  93. * so DMA unmap & freeing is fine.
  94. */
  95. static void
  96. bnad_free_all_txbufs(struct bnad *bnad,
  97. struct bna_tcb *tcb)
  98. {
  99. u32 unmap_cons;
  100. struct bnad_unmap_q *unmap_q = tcb->unmap_q;
  101. struct bnad_skb_unmap *unmap_array;
  102. struct sk_buff *skb = NULL;
  103. int i;
  104. unmap_array = unmap_q->unmap_array;
  105. unmap_cons = 0;
  106. while (unmap_cons < unmap_q->q_depth) {
  107. skb = unmap_array[unmap_cons].skb;
  108. if (!skb) {
  109. unmap_cons++;
  110. continue;
  111. }
  112. unmap_array[unmap_cons].skb = NULL;
  113. dma_unmap_single(&bnad->pcidev->dev,
  114. dma_unmap_addr(&unmap_array[unmap_cons],
  115. dma_addr), skb_headlen(skb),
  116. DMA_TO_DEVICE);
  117. dma_unmap_addr_set(&unmap_array[unmap_cons], dma_addr, 0);
  118. if (++unmap_cons >= unmap_q->q_depth)
  119. break;
  120. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  121. dma_unmap_page(&bnad->pcidev->dev,
  122. dma_unmap_addr(&unmap_array[unmap_cons],
  123. dma_addr),
  124. skb_shinfo(skb)->frags[i].size,
  125. DMA_TO_DEVICE);
  126. dma_unmap_addr_set(&unmap_array[unmap_cons], dma_addr,
  127. 0);
  128. if (++unmap_cons >= unmap_q->q_depth)
  129. break;
  130. }
  131. dev_kfree_skb_any(skb);
  132. }
  133. }
  134. /* Data Path Handlers */
  135. /*
  136. * bnad_free_txbufs : Frees the Tx bufs on Tx completion
  137. * Can be called in a) Interrupt context
  138. * b) Sending context
  139. * c) Tasklet context
  140. */
  141. static u32
  142. bnad_free_txbufs(struct bnad *bnad,
  143. struct bna_tcb *tcb)
  144. {
  145. u32 sent_packets = 0, sent_bytes = 0;
  146. u16 wis, unmap_cons, updated_hw_cons;
  147. struct bnad_unmap_q *unmap_q = tcb->unmap_q;
  148. struct bnad_skb_unmap *unmap_array;
  149. struct sk_buff *skb;
  150. int i;
  151. /*
  152. * Just return if TX is stopped. This check is useful
  153. * when bnad_free_txbufs() runs out of a tasklet scheduled
  154. * before bnad_cb_tx_cleanup() cleared BNAD_TXQ_TX_STARTED bit
  155. * but this routine runs actually after the cleanup has been
  156. * executed.
  157. */
  158. if (!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))
  159. return 0;
  160. updated_hw_cons = *(tcb->hw_consumer_index);
  161. wis = BNA_Q_INDEX_CHANGE(tcb->consumer_index,
  162. updated_hw_cons, tcb->q_depth);
  163. BUG_ON(!(wis <= BNA_QE_IN_USE_CNT(tcb, tcb->q_depth)));
  164. unmap_array = unmap_q->unmap_array;
  165. unmap_cons = unmap_q->consumer_index;
  166. prefetch(&unmap_array[unmap_cons + 1]);
  167. while (wis) {
  168. skb = unmap_array[unmap_cons].skb;
  169. unmap_array[unmap_cons].skb = NULL;
  170. sent_packets++;
  171. sent_bytes += skb->len;
  172. wis -= BNA_TXQ_WI_NEEDED(1 + skb_shinfo(skb)->nr_frags);
  173. dma_unmap_single(&bnad->pcidev->dev,
  174. dma_unmap_addr(&unmap_array[unmap_cons],
  175. dma_addr), skb_headlen(skb),
  176. DMA_TO_DEVICE);
  177. dma_unmap_addr_set(&unmap_array[unmap_cons], dma_addr, 0);
  178. BNA_QE_INDX_ADD(unmap_cons, 1, unmap_q->q_depth);
  179. prefetch(&unmap_array[unmap_cons + 1]);
  180. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  181. prefetch(&unmap_array[unmap_cons + 1]);
  182. dma_unmap_page(&bnad->pcidev->dev,
  183. dma_unmap_addr(&unmap_array[unmap_cons],
  184. dma_addr),
  185. skb_shinfo(skb)->frags[i].size,
  186. DMA_TO_DEVICE);
  187. dma_unmap_addr_set(&unmap_array[unmap_cons], dma_addr,
  188. 0);
  189. BNA_QE_INDX_ADD(unmap_cons, 1, unmap_q->q_depth);
  190. }
  191. dev_kfree_skb_any(skb);
  192. }
  193. /* Update consumer pointers. */
  194. tcb->consumer_index = updated_hw_cons;
  195. unmap_q->consumer_index = unmap_cons;
  196. tcb->txq->tx_packets += sent_packets;
  197. tcb->txq->tx_bytes += sent_bytes;
  198. return sent_packets;
  199. }
  200. /* Tx Free Tasklet function */
  201. /* Frees for all the tcb's in all the Tx's */
  202. /*
  203. * Scheduled from sending context, so that
  204. * the fat Tx lock is not held for too long
  205. * in the sending context.
  206. */
  207. static void
  208. bnad_tx_free_tasklet(unsigned long bnad_ptr)
  209. {
  210. struct bnad *bnad = (struct bnad *)bnad_ptr;
  211. struct bna_tcb *tcb;
  212. u32 acked = 0;
  213. int i, j;
  214. for (i = 0; i < bnad->num_tx; i++) {
  215. for (j = 0; j < bnad->num_txq_per_tx; j++) {
  216. tcb = bnad->tx_info[i].tcb[j];
  217. if (!tcb)
  218. continue;
  219. if (((u16) (*tcb->hw_consumer_index) !=
  220. tcb->consumer_index) &&
  221. (!test_and_set_bit(BNAD_TXQ_FREE_SENT,
  222. &tcb->flags))) {
  223. acked = bnad_free_txbufs(bnad, tcb);
  224. if (likely(test_bit(BNAD_TXQ_TX_STARTED,
  225. &tcb->flags)))
  226. bna_ib_ack(tcb->i_dbell, acked);
  227. smp_mb__before_clear_bit();
  228. clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags);
  229. }
  230. if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED,
  231. &tcb->flags)))
  232. continue;
  233. if (netif_queue_stopped(bnad->netdev)) {
  234. if (acked && netif_carrier_ok(bnad->netdev) &&
  235. BNA_QE_FREE_CNT(tcb, tcb->q_depth) >=
  236. BNAD_NETIF_WAKE_THRESHOLD) {
  237. netif_wake_queue(bnad->netdev);
  238. /* TODO */
  239. /* Counters for individual TxQs? */
  240. BNAD_UPDATE_CTR(bnad,
  241. netif_queue_wakeup);
  242. }
  243. }
  244. }
  245. }
  246. }
  247. static u32
  248. bnad_tx(struct bnad *bnad, struct bna_tcb *tcb)
  249. {
  250. struct net_device *netdev = bnad->netdev;
  251. u32 sent = 0;
  252. if (test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags))
  253. return 0;
  254. sent = bnad_free_txbufs(bnad, tcb);
  255. if (sent) {
  256. if (netif_queue_stopped(netdev) &&
  257. netif_carrier_ok(netdev) &&
  258. BNA_QE_FREE_CNT(tcb, tcb->q_depth) >=
  259. BNAD_NETIF_WAKE_THRESHOLD) {
  260. if (test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)) {
  261. netif_wake_queue(netdev);
  262. BNAD_UPDATE_CTR(bnad, netif_queue_wakeup);
  263. }
  264. }
  265. }
  266. if (likely(test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)))
  267. bna_ib_ack(tcb->i_dbell, sent);
  268. smp_mb__before_clear_bit();
  269. clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags);
  270. return sent;
  271. }
  272. /* MSIX Tx Completion Handler */
  273. static irqreturn_t
  274. bnad_msix_tx(int irq, void *data)
  275. {
  276. struct bna_tcb *tcb = (struct bna_tcb *)data;
  277. struct bnad *bnad = tcb->bnad;
  278. bnad_tx(bnad, tcb);
  279. return IRQ_HANDLED;
  280. }
  281. static void
  282. bnad_reset_rcb(struct bnad *bnad, struct bna_rcb *rcb)
  283. {
  284. struct bnad_unmap_q *unmap_q = rcb->unmap_q;
  285. rcb->producer_index = 0;
  286. rcb->consumer_index = 0;
  287. unmap_q->producer_index = 0;
  288. unmap_q->consumer_index = 0;
  289. }
  290. static void
  291. bnad_free_all_rxbufs(struct bnad *bnad, struct bna_rcb *rcb)
  292. {
  293. struct bnad_unmap_q *unmap_q;
  294. struct bnad_skb_unmap *unmap_array;
  295. struct sk_buff *skb;
  296. int unmap_cons;
  297. unmap_q = rcb->unmap_q;
  298. unmap_array = unmap_q->unmap_array;
  299. for (unmap_cons = 0; unmap_cons < unmap_q->q_depth; unmap_cons++) {
  300. skb = unmap_array[unmap_cons].skb;
  301. if (!skb)
  302. continue;
  303. unmap_array[unmap_cons].skb = NULL;
  304. dma_unmap_single(&bnad->pcidev->dev,
  305. dma_unmap_addr(&unmap_array[unmap_cons],
  306. dma_addr),
  307. rcb->rxq->buffer_size,
  308. DMA_FROM_DEVICE);
  309. dev_kfree_skb(skb);
  310. }
  311. bnad_reset_rcb(bnad, rcb);
  312. }
  313. static void
  314. bnad_alloc_n_post_rxbufs(struct bnad *bnad, struct bna_rcb *rcb)
  315. {
  316. u16 to_alloc, alloced, unmap_prod, wi_range;
  317. struct bnad_unmap_q *unmap_q = rcb->unmap_q;
  318. struct bnad_skb_unmap *unmap_array;
  319. struct bna_rxq_entry *rxent;
  320. struct sk_buff *skb;
  321. dma_addr_t dma_addr;
  322. alloced = 0;
  323. to_alloc =
  324. BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth);
  325. unmap_array = unmap_q->unmap_array;
  326. unmap_prod = unmap_q->producer_index;
  327. BNA_RXQ_QPGE_PTR_GET(unmap_prod, rcb->sw_qpt, rxent, wi_range);
  328. while (to_alloc--) {
  329. if (!wi_range) {
  330. BNA_RXQ_QPGE_PTR_GET(unmap_prod, rcb->sw_qpt, rxent,
  331. wi_range);
  332. }
  333. skb = netdev_alloc_skb_ip_align(bnad->netdev,
  334. rcb->rxq->buffer_size);
  335. if (unlikely(!skb)) {
  336. BNAD_UPDATE_CTR(bnad, rxbuf_alloc_failed);
  337. goto finishing;
  338. }
  339. unmap_array[unmap_prod].skb = skb;
  340. dma_addr = dma_map_single(&bnad->pcidev->dev, skb->data,
  341. rcb->rxq->buffer_size,
  342. DMA_FROM_DEVICE);
  343. dma_unmap_addr_set(&unmap_array[unmap_prod], dma_addr,
  344. dma_addr);
  345. BNA_SET_DMA_ADDR(dma_addr, &rxent->host_addr);
  346. BNA_QE_INDX_ADD(unmap_prod, 1, unmap_q->q_depth);
  347. rxent++;
  348. wi_range--;
  349. alloced++;
  350. }
  351. finishing:
  352. if (likely(alloced)) {
  353. unmap_q->producer_index = unmap_prod;
  354. rcb->producer_index = unmap_prod;
  355. smp_mb();
  356. if (likely(test_bit(BNAD_RXQ_STARTED, &rcb->flags)))
  357. bna_rxq_prod_indx_doorbell(rcb);
  358. }
  359. }
  360. static inline void
  361. bnad_refill_rxq(struct bnad *bnad, struct bna_rcb *rcb)
  362. {
  363. struct bnad_unmap_q *unmap_q = rcb->unmap_q;
  364. if (!test_and_set_bit(BNAD_RXQ_REFILL, &rcb->flags)) {
  365. if (BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth)
  366. >> BNAD_RXQ_REFILL_THRESHOLD_SHIFT)
  367. bnad_alloc_n_post_rxbufs(bnad, rcb);
  368. smp_mb__before_clear_bit();
  369. clear_bit(BNAD_RXQ_REFILL, &rcb->flags);
  370. }
  371. }
  372. static u32
  373. bnad_poll_cq(struct bnad *bnad, struct bna_ccb *ccb, int budget)
  374. {
  375. struct bna_cq_entry *cmpl, *next_cmpl;
  376. struct bna_rcb *rcb = NULL;
  377. unsigned int wi_range, packets = 0, wis = 0;
  378. struct bnad_unmap_q *unmap_q;
  379. struct bnad_skb_unmap *unmap_array;
  380. struct sk_buff *skb;
  381. u32 flags, unmap_cons;
  382. struct bna_pkt_rate *pkt_rt = &ccb->pkt_rate;
  383. struct bnad_rx_ctrl *rx_ctrl = (struct bnad_rx_ctrl *)(ccb->ctrl);
  384. set_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags);
  385. if (!test_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags)) {
  386. clear_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags);
  387. return 0;
  388. }
  389. prefetch(bnad->netdev);
  390. BNA_CQ_QPGE_PTR_GET(ccb->producer_index, ccb->sw_qpt, cmpl,
  391. wi_range);
  392. BUG_ON(!(wi_range <= ccb->q_depth));
  393. while (cmpl->valid && packets < budget) {
  394. packets++;
  395. BNA_UPDATE_PKT_CNT(pkt_rt, ntohs(cmpl->length));
  396. if (bna_is_small_rxq(cmpl->rxq_id))
  397. rcb = ccb->rcb[1];
  398. else
  399. rcb = ccb->rcb[0];
  400. unmap_q = rcb->unmap_q;
  401. unmap_array = unmap_q->unmap_array;
  402. unmap_cons = unmap_q->consumer_index;
  403. skb = unmap_array[unmap_cons].skb;
  404. BUG_ON(!(skb));
  405. unmap_array[unmap_cons].skb = NULL;
  406. dma_unmap_single(&bnad->pcidev->dev,
  407. dma_unmap_addr(&unmap_array[unmap_cons],
  408. dma_addr),
  409. rcb->rxq->buffer_size,
  410. DMA_FROM_DEVICE);
  411. BNA_QE_INDX_ADD(unmap_q->consumer_index, 1, unmap_q->q_depth);
  412. /* Should be more efficient ? Performance ? */
  413. BNA_QE_INDX_ADD(rcb->consumer_index, 1, rcb->q_depth);
  414. wis++;
  415. if (likely(--wi_range))
  416. next_cmpl = cmpl + 1;
  417. else {
  418. BNA_QE_INDX_ADD(ccb->producer_index, wis, ccb->q_depth);
  419. wis = 0;
  420. BNA_CQ_QPGE_PTR_GET(ccb->producer_index, ccb->sw_qpt,
  421. next_cmpl, wi_range);
  422. BUG_ON(!(wi_range <= ccb->q_depth));
  423. }
  424. prefetch(next_cmpl);
  425. flags = ntohl(cmpl->flags);
  426. if (unlikely
  427. (flags &
  428. (BNA_CQ_EF_MAC_ERROR | BNA_CQ_EF_FCS_ERROR |
  429. BNA_CQ_EF_TOO_LONG))) {
  430. dev_kfree_skb_any(skb);
  431. rcb->rxq->rx_packets_with_error++;
  432. goto next;
  433. }
  434. skb_put(skb, ntohs(cmpl->length));
  435. if (likely
  436. ((bnad->netdev->features & NETIF_F_RXCSUM) &&
  437. (((flags & BNA_CQ_EF_IPV4) &&
  438. (flags & BNA_CQ_EF_L3_CKSUM_OK)) ||
  439. (flags & BNA_CQ_EF_IPV6)) &&
  440. (flags & (BNA_CQ_EF_TCP | BNA_CQ_EF_UDP)) &&
  441. (flags & BNA_CQ_EF_L4_CKSUM_OK)))
  442. skb->ip_summed = CHECKSUM_UNNECESSARY;
  443. else
  444. skb_checksum_none_assert(skb);
  445. rcb->rxq->rx_packets++;
  446. rcb->rxq->rx_bytes += skb->len;
  447. skb->protocol = eth_type_trans(skb, bnad->netdev);
  448. if (flags & BNA_CQ_EF_VLAN)
  449. __vlan_hwaccel_put_tag(skb, ntohs(cmpl->vlan_tag));
  450. if (skb->ip_summed == CHECKSUM_UNNECESSARY)
  451. napi_gro_receive(&rx_ctrl->napi, skb);
  452. else {
  453. netif_receive_skb(skb);
  454. }
  455. next:
  456. cmpl->valid = 0;
  457. cmpl = next_cmpl;
  458. }
  459. BNA_QE_INDX_ADD(ccb->producer_index, wis, ccb->q_depth);
  460. if (likely(test_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags)))
  461. bna_ib_ack(ccb->i_dbell, packets);
  462. bnad_refill_rxq(bnad, ccb->rcb[0]);
  463. if (ccb->rcb[1])
  464. bnad_refill_rxq(bnad, ccb->rcb[1]);
  465. clear_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags);
  466. return packets;
  467. }
  468. static void
  469. bnad_disable_rx_irq(struct bnad *bnad, struct bna_ccb *ccb)
  470. {
  471. if (unlikely(!test_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags)))
  472. return;
  473. bna_ib_coalescing_timer_set(ccb->i_dbell, 0);
  474. bna_ib_ack(ccb->i_dbell, 0);
  475. }
  476. static void
  477. bnad_enable_rx_irq(struct bnad *bnad, struct bna_ccb *ccb)
  478. {
  479. unsigned long flags;
  480. /* Because of polling context */
  481. spin_lock_irqsave(&bnad->bna_lock, flags);
  482. bnad_enable_rx_irq_unsafe(ccb);
  483. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  484. }
  485. static void
  486. bnad_netif_rx_schedule_poll(struct bnad *bnad, struct bna_ccb *ccb)
  487. {
  488. struct bnad_rx_ctrl *rx_ctrl = (struct bnad_rx_ctrl *)(ccb->ctrl);
  489. struct napi_struct *napi = &rx_ctrl->napi;
  490. if (likely(napi_schedule_prep(napi))) {
  491. bnad_disable_rx_irq(bnad, ccb);
  492. __napi_schedule(napi);
  493. }
  494. BNAD_UPDATE_CTR(bnad, netif_rx_schedule);
  495. }
  496. /* MSIX Rx Path Handler */
  497. static irqreturn_t
  498. bnad_msix_rx(int irq, void *data)
  499. {
  500. struct bna_ccb *ccb = (struct bna_ccb *)data;
  501. if (ccb)
  502. bnad_netif_rx_schedule_poll(ccb->bnad, ccb);
  503. return IRQ_HANDLED;
  504. }
  505. /* Interrupt handlers */
  506. /* Mbox Interrupt Handlers */
  507. static irqreturn_t
  508. bnad_msix_mbox_handler(int irq, void *data)
  509. {
  510. u32 intr_status;
  511. unsigned long flags;
  512. struct bnad *bnad = (struct bnad *)data;
  513. if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags)))
  514. return IRQ_HANDLED;
  515. spin_lock_irqsave(&bnad->bna_lock, flags);
  516. bna_intr_status_get(&bnad->bna, intr_status);
  517. if (BNA_IS_MBOX_ERR_INTR(&bnad->bna, intr_status))
  518. bna_mbox_handler(&bnad->bna, intr_status);
  519. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  520. return IRQ_HANDLED;
  521. }
  522. static irqreturn_t
  523. bnad_isr(int irq, void *data)
  524. {
  525. int i, j;
  526. u32 intr_status;
  527. unsigned long flags;
  528. struct bnad *bnad = (struct bnad *)data;
  529. struct bnad_rx_info *rx_info;
  530. struct bnad_rx_ctrl *rx_ctrl;
  531. struct bna_tcb *tcb = NULL;
  532. if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags)))
  533. return IRQ_NONE;
  534. bna_intr_status_get(&bnad->bna, intr_status);
  535. if (unlikely(!intr_status))
  536. return IRQ_NONE;
  537. spin_lock_irqsave(&bnad->bna_lock, flags);
  538. if (BNA_IS_MBOX_ERR_INTR(&bnad->bna, intr_status))
  539. bna_mbox_handler(&bnad->bna, intr_status);
  540. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  541. if (!BNA_IS_INTX_DATA_INTR(intr_status))
  542. return IRQ_HANDLED;
  543. /* Process data interrupts */
  544. /* Tx processing */
  545. for (i = 0; i < bnad->num_tx; i++) {
  546. for (j = 0; j < bnad->num_txq_per_tx; j++) {
  547. tcb = bnad->tx_info[i].tcb[j];
  548. if (tcb && test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))
  549. bnad_tx(bnad, bnad->tx_info[i].tcb[j]);
  550. }
  551. }
  552. /* Rx processing */
  553. for (i = 0; i < bnad->num_rx; i++) {
  554. rx_info = &bnad->rx_info[i];
  555. if (!rx_info->rx)
  556. continue;
  557. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  558. rx_ctrl = &rx_info->rx_ctrl[j];
  559. if (rx_ctrl->ccb)
  560. bnad_netif_rx_schedule_poll(bnad,
  561. rx_ctrl->ccb);
  562. }
  563. }
  564. return IRQ_HANDLED;
  565. }
  566. /*
  567. * Called in interrupt / callback context
  568. * with bna_lock held, so cfg_flags access is OK
  569. */
  570. static void
  571. bnad_enable_mbox_irq(struct bnad *bnad)
  572. {
  573. clear_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags);
  574. BNAD_UPDATE_CTR(bnad, mbox_intr_enabled);
  575. }
  576. /*
  577. * Called with bnad->bna_lock held b'cos of
  578. * bnad->cfg_flags access.
  579. */
  580. static void
  581. bnad_disable_mbox_irq(struct bnad *bnad)
  582. {
  583. set_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags);
  584. BNAD_UPDATE_CTR(bnad, mbox_intr_disabled);
  585. }
  586. static void
  587. bnad_set_netdev_perm_addr(struct bnad *bnad)
  588. {
  589. struct net_device *netdev = bnad->netdev;
  590. memcpy(netdev->perm_addr, &bnad->perm_addr, netdev->addr_len);
  591. if (is_zero_ether_addr(netdev->dev_addr))
  592. memcpy(netdev->dev_addr, &bnad->perm_addr, netdev->addr_len);
  593. }
  594. /* Control Path Handlers */
  595. /* Callbacks */
  596. void
  597. bnad_cb_mbox_intr_enable(struct bnad *bnad)
  598. {
  599. bnad_enable_mbox_irq(bnad);
  600. }
  601. void
  602. bnad_cb_mbox_intr_disable(struct bnad *bnad)
  603. {
  604. bnad_disable_mbox_irq(bnad);
  605. }
  606. void
  607. bnad_cb_ioceth_ready(struct bnad *bnad)
  608. {
  609. bnad->bnad_completions.ioc_comp_status = BNA_CB_SUCCESS;
  610. complete(&bnad->bnad_completions.ioc_comp);
  611. }
  612. void
  613. bnad_cb_ioceth_failed(struct bnad *bnad)
  614. {
  615. bnad->bnad_completions.ioc_comp_status = BNA_CB_FAIL;
  616. complete(&bnad->bnad_completions.ioc_comp);
  617. }
  618. void
  619. bnad_cb_ioceth_disabled(struct bnad *bnad)
  620. {
  621. bnad->bnad_completions.ioc_comp_status = BNA_CB_SUCCESS;
  622. complete(&bnad->bnad_completions.ioc_comp);
  623. }
  624. static void
  625. bnad_cb_enet_disabled(void *arg)
  626. {
  627. struct bnad *bnad = (struct bnad *)arg;
  628. netif_carrier_off(bnad->netdev);
  629. complete(&bnad->bnad_completions.enet_comp);
  630. }
  631. void
  632. bnad_cb_ethport_link_status(struct bnad *bnad,
  633. enum bna_link_status link_status)
  634. {
  635. bool link_up = 0;
  636. link_up = (link_status == BNA_LINK_UP) || (link_status == BNA_CEE_UP);
  637. if (link_status == BNA_CEE_UP) {
  638. if (!test_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags))
  639. BNAD_UPDATE_CTR(bnad, cee_toggle);
  640. set_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags);
  641. } else {
  642. if (test_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags))
  643. BNAD_UPDATE_CTR(bnad, cee_toggle);
  644. clear_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags);
  645. }
  646. if (link_up) {
  647. if (!netif_carrier_ok(bnad->netdev)) {
  648. uint tx_id, tcb_id;
  649. printk(KERN_WARNING "bna: %s link up\n",
  650. bnad->netdev->name);
  651. netif_carrier_on(bnad->netdev);
  652. BNAD_UPDATE_CTR(bnad, link_toggle);
  653. for (tx_id = 0; tx_id < bnad->num_tx; tx_id++) {
  654. for (tcb_id = 0; tcb_id < bnad->num_txq_per_tx;
  655. tcb_id++) {
  656. struct bna_tcb *tcb =
  657. bnad->tx_info[tx_id].tcb[tcb_id];
  658. u32 txq_id;
  659. if (!tcb)
  660. continue;
  661. txq_id = tcb->id;
  662. if (test_bit(BNAD_TXQ_TX_STARTED,
  663. &tcb->flags)) {
  664. /*
  665. * Force an immediate
  666. * Transmit Schedule */
  667. printk(KERN_INFO "bna: %s %d "
  668. "TXQ_STARTED\n",
  669. bnad->netdev->name,
  670. txq_id);
  671. netif_wake_subqueue(
  672. bnad->netdev,
  673. txq_id);
  674. BNAD_UPDATE_CTR(bnad,
  675. netif_queue_wakeup);
  676. } else {
  677. netif_stop_subqueue(
  678. bnad->netdev,
  679. txq_id);
  680. BNAD_UPDATE_CTR(bnad,
  681. netif_queue_stop);
  682. }
  683. }
  684. }
  685. }
  686. } else {
  687. if (netif_carrier_ok(bnad->netdev)) {
  688. printk(KERN_WARNING "bna: %s link down\n",
  689. bnad->netdev->name);
  690. netif_carrier_off(bnad->netdev);
  691. BNAD_UPDATE_CTR(bnad, link_toggle);
  692. }
  693. }
  694. }
  695. static void
  696. bnad_cb_tx_disabled(void *arg, struct bna_tx *tx)
  697. {
  698. struct bnad *bnad = (struct bnad *)arg;
  699. complete(&bnad->bnad_completions.tx_comp);
  700. }
  701. static void
  702. bnad_cb_tcb_setup(struct bnad *bnad, struct bna_tcb *tcb)
  703. {
  704. struct bnad_tx_info *tx_info =
  705. (struct bnad_tx_info *)tcb->txq->tx->priv;
  706. struct bnad_unmap_q *unmap_q = tcb->unmap_q;
  707. tx_info->tcb[tcb->id] = tcb;
  708. unmap_q->producer_index = 0;
  709. unmap_q->consumer_index = 0;
  710. unmap_q->q_depth = BNAD_TX_UNMAPQ_DEPTH;
  711. }
  712. static void
  713. bnad_cb_tcb_destroy(struct bnad *bnad, struct bna_tcb *tcb)
  714. {
  715. struct bnad_tx_info *tx_info =
  716. (struct bnad_tx_info *)tcb->txq->tx->priv;
  717. struct bnad_unmap_q *unmap_q = tcb->unmap_q;
  718. while (test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags))
  719. cpu_relax();
  720. bnad_free_all_txbufs(bnad, tcb);
  721. unmap_q->producer_index = 0;
  722. unmap_q->consumer_index = 0;
  723. smp_mb__before_clear_bit();
  724. clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags);
  725. tx_info->tcb[tcb->id] = NULL;
  726. }
  727. static void
  728. bnad_cb_rcb_setup(struct bnad *bnad, struct bna_rcb *rcb)
  729. {
  730. struct bnad_unmap_q *unmap_q = rcb->unmap_q;
  731. unmap_q->producer_index = 0;
  732. unmap_q->consumer_index = 0;
  733. unmap_q->q_depth = BNAD_RX_UNMAPQ_DEPTH;
  734. }
  735. static void
  736. bnad_cb_rcb_destroy(struct bnad *bnad, struct bna_rcb *rcb)
  737. {
  738. bnad_free_all_rxbufs(bnad, rcb);
  739. }
  740. static void
  741. bnad_cb_ccb_setup(struct bnad *bnad, struct bna_ccb *ccb)
  742. {
  743. struct bnad_rx_info *rx_info =
  744. (struct bnad_rx_info *)ccb->cq->rx->priv;
  745. rx_info->rx_ctrl[ccb->id].ccb = ccb;
  746. ccb->ctrl = &rx_info->rx_ctrl[ccb->id];
  747. }
  748. static void
  749. bnad_cb_ccb_destroy(struct bnad *bnad, struct bna_ccb *ccb)
  750. {
  751. struct bnad_rx_info *rx_info =
  752. (struct bnad_rx_info *)ccb->cq->rx->priv;
  753. rx_info->rx_ctrl[ccb->id].ccb = NULL;
  754. }
  755. static void
  756. bnad_cb_tx_stall(struct bnad *bnad, struct bna_tx *tx)
  757. {
  758. struct bnad_tx_info *tx_info =
  759. (struct bnad_tx_info *)tx->priv;
  760. struct bna_tcb *tcb;
  761. u32 txq_id;
  762. int i;
  763. for (i = 0; i < BNAD_MAX_TXQ_PER_TX; i++) {
  764. tcb = tx_info->tcb[i];
  765. if (!tcb)
  766. continue;
  767. txq_id = tcb->id;
  768. clear_bit(BNAD_TXQ_TX_STARTED, &tcb->flags);
  769. netif_stop_subqueue(bnad->netdev, txq_id);
  770. printk(KERN_INFO "bna: %s %d TXQ_STOPPED\n",
  771. bnad->netdev->name, txq_id);
  772. }
  773. }
  774. static void
  775. bnad_cb_tx_resume(struct bnad *bnad, struct bna_tx *tx)
  776. {
  777. struct bnad_tx_info *tx_info = (struct bnad_tx_info *)tx->priv;
  778. struct bna_tcb *tcb;
  779. struct bnad_unmap_q *unmap_q;
  780. u32 txq_id;
  781. int i;
  782. for (i = 0; i < BNAD_MAX_TXQ_PER_TX; i++) {
  783. tcb = tx_info->tcb[i];
  784. if (!tcb)
  785. continue;
  786. txq_id = tcb->id;
  787. unmap_q = tcb->unmap_q;
  788. if (test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))
  789. continue;
  790. while (test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags))
  791. cpu_relax();
  792. bnad_free_all_txbufs(bnad, tcb);
  793. unmap_q->producer_index = 0;
  794. unmap_q->consumer_index = 0;
  795. smp_mb__before_clear_bit();
  796. clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags);
  797. set_bit(BNAD_TXQ_TX_STARTED, &tcb->flags);
  798. if (netif_carrier_ok(bnad->netdev)) {
  799. printk(KERN_INFO "bna: %s %d TXQ_STARTED\n",
  800. bnad->netdev->name, txq_id);
  801. netif_wake_subqueue(bnad->netdev, txq_id);
  802. BNAD_UPDATE_CTR(bnad, netif_queue_wakeup);
  803. }
  804. }
  805. /*
  806. * Workaround for first ioceth enable failure & we
  807. * get a 0 MAC address. We try to get the MAC address
  808. * again here.
  809. */
  810. if (is_zero_ether_addr(&bnad->perm_addr.mac[0])) {
  811. bna_enet_perm_mac_get(&bnad->bna.enet, &bnad->perm_addr);
  812. bnad_set_netdev_perm_addr(bnad);
  813. }
  814. }
  815. static void
  816. bnad_cb_tx_cleanup(struct bnad *bnad, struct bna_tx *tx)
  817. {
  818. struct bnad_tx_info *tx_info = (struct bnad_tx_info *)tx->priv;
  819. struct bna_tcb *tcb;
  820. int i;
  821. for (i = 0; i < BNAD_MAX_TXQ_PER_TX; i++) {
  822. tcb = tx_info->tcb[i];
  823. if (!tcb)
  824. continue;
  825. }
  826. mdelay(BNAD_TXRX_SYNC_MDELAY);
  827. bna_tx_cleanup_complete(tx);
  828. }
  829. static void
  830. bnad_cb_rx_cleanup(struct bnad *bnad, struct bna_rx *rx)
  831. {
  832. struct bnad_rx_info *rx_info = (struct bnad_rx_info *)rx->priv;
  833. struct bna_ccb *ccb;
  834. struct bnad_rx_ctrl *rx_ctrl;
  835. int i;
  836. mdelay(BNAD_TXRX_SYNC_MDELAY);
  837. for (i = 0; i < BNAD_MAX_RXP_PER_RX; i++) {
  838. rx_ctrl = &rx_info->rx_ctrl[i];
  839. ccb = rx_ctrl->ccb;
  840. if (!ccb)
  841. continue;
  842. clear_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags);
  843. if (ccb->rcb[1])
  844. clear_bit(BNAD_RXQ_STARTED, &ccb->rcb[1]->flags);
  845. while (test_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags))
  846. cpu_relax();
  847. }
  848. bna_rx_cleanup_complete(rx);
  849. }
  850. static void
  851. bnad_cb_rx_post(struct bnad *bnad, struct bna_rx *rx)
  852. {
  853. struct bnad_rx_info *rx_info = (struct bnad_rx_info *)rx->priv;
  854. struct bna_ccb *ccb;
  855. struct bna_rcb *rcb;
  856. struct bnad_rx_ctrl *rx_ctrl;
  857. struct bnad_unmap_q *unmap_q;
  858. int i;
  859. int j;
  860. for (i = 0; i < BNAD_MAX_RXP_PER_RX; i++) {
  861. rx_ctrl = &rx_info->rx_ctrl[i];
  862. ccb = rx_ctrl->ccb;
  863. if (!ccb)
  864. continue;
  865. bnad_cq_cmpl_init(bnad, ccb);
  866. for (j = 0; j < BNAD_MAX_RXQ_PER_RXP; j++) {
  867. rcb = ccb->rcb[j];
  868. if (!rcb)
  869. continue;
  870. bnad_free_all_rxbufs(bnad, rcb);
  871. set_bit(BNAD_RXQ_STARTED, &rcb->flags);
  872. unmap_q = rcb->unmap_q;
  873. /* Now allocate & post buffers for this RCB */
  874. /* !!Allocation in callback context */
  875. if (!test_and_set_bit(BNAD_RXQ_REFILL, &rcb->flags)) {
  876. if (BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth)
  877. >> BNAD_RXQ_REFILL_THRESHOLD_SHIFT)
  878. bnad_alloc_n_post_rxbufs(bnad, rcb);
  879. smp_mb__before_clear_bit();
  880. clear_bit(BNAD_RXQ_REFILL, &rcb->flags);
  881. }
  882. }
  883. }
  884. }
  885. static void
  886. bnad_cb_rx_disabled(void *arg, struct bna_rx *rx)
  887. {
  888. struct bnad *bnad = (struct bnad *)arg;
  889. complete(&bnad->bnad_completions.rx_comp);
  890. }
  891. static void
  892. bnad_cb_rx_mcast_add(struct bnad *bnad, struct bna_rx *rx)
  893. {
  894. bnad->bnad_completions.mcast_comp_status = BNA_CB_SUCCESS;
  895. complete(&bnad->bnad_completions.mcast_comp);
  896. }
  897. void
  898. bnad_cb_stats_get(struct bnad *bnad, enum bna_cb_status status,
  899. struct bna_stats *stats)
  900. {
  901. if (status == BNA_CB_SUCCESS)
  902. BNAD_UPDATE_CTR(bnad, hw_stats_updates);
  903. if (!netif_running(bnad->netdev) ||
  904. !test_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags))
  905. return;
  906. mod_timer(&bnad->stats_timer,
  907. jiffies + msecs_to_jiffies(BNAD_STATS_TIMER_FREQ));
  908. }
  909. static void
  910. bnad_cb_enet_mtu_set(struct bnad *bnad)
  911. {
  912. bnad->bnad_completions.mtu_comp_status = BNA_CB_SUCCESS;
  913. complete(&bnad->bnad_completions.mtu_comp);
  914. }
  915. /* Resource allocation, free functions */
  916. static void
  917. bnad_mem_free(struct bnad *bnad,
  918. struct bna_mem_info *mem_info)
  919. {
  920. int i;
  921. dma_addr_t dma_pa;
  922. if (mem_info->mdl == NULL)
  923. return;
  924. for (i = 0; i < mem_info->num; i++) {
  925. if (mem_info->mdl[i].kva != NULL) {
  926. if (mem_info->mem_type == BNA_MEM_T_DMA) {
  927. BNA_GET_DMA_ADDR(&(mem_info->mdl[i].dma),
  928. dma_pa);
  929. dma_free_coherent(&bnad->pcidev->dev,
  930. mem_info->mdl[i].len,
  931. mem_info->mdl[i].kva, dma_pa);
  932. } else
  933. kfree(mem_info->mdl[i].kva);
  934. }
  935. }
  936. kfree(mem_info->mdl);
  937. mem_info->mdl = NULL;
  938. }
  939. static int
  940. bnad_mem_alloc(struct bnad *bnad,
  941. struct bna_mem_info *mem_info)
  942. {
  943. int i;
  944. dma_addr_t dma_pa;
  945. if ((mem_info->num == 0) || (mem_info->len == 0)) {
  946. mem_info->mdl = NULL;
  947. return 0;
  948. }
  949. mem_info->mdl = kcalloc(mem_info->num, sizeof(struct bna_mem_descr),
  950. GFP_KERNEL);
  951. if (mem_info->mdl == NULL)
  952. return -ENOMEM;
  953. if (mem_info->mem_type == BNA_MEM_T_DMA) {
  954. for (i = 0; i < mem_info->num; i++) {
  955. mem_info->mdl[i].len = mem_info->len;
  956. mem_info->mdl[i].kva =
  957. dma_alloc_coherent(&bnad->pcidev->dev,
  958. mem_info->len, &dma_pa,
  959. GFP_KERNEL);
  960. if (mem_info->mdl[i].kva == NULL)
  961. goto err_return;
  962. BNA_SET_DMA_ADDR(dma_pa,
  963. &(mem_info->mdl[i].dma));
  964. }
  965. } else {
  966. for (i = 0; i < mem_info->num; i++) {
  967. mem_info->mdl[i].len = mem_info->len;
  968. mem_info->mdl[i].kva = kzalloc(mem_info->len,
  969. GFP_KERNEL);
  970. if (mem_info->mdl[i].kva == NULL)
  971. goto err_return;
  972. }
  973. }
  974. return 0;
  975. err_return:
  976. bnad_mem_free(bnad, mem_info);
  977. return -ENOMEM;
  978. }
  979. /* Free IRQ for Mailbox */
  980. static void
  981. bnad_mbox_irq_free(struct bnad *bnad)
  982. {
  983. int irq;
  984. unsigned long flags;
  985. spin_lock_irqsave(&bnad->bna_lock, flags);
  986. bnad_disable_mbox_irq(bnad);
  987. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  988. irq = BNAD_GET_MBOX_IRQ(bnad);
  989. free_irq(irq, bnad);
  990. }
  991. /*
  992. * Allocates IRQ for Mailbox, but keep it disabled
  993. * This will be enabled once we get the mbox enable callback
  994. * from bna
  995. */
  996. static int
  997. bnad_mbox_irq_alloc(struct bnad *bnad)
  998. {
  999. int err = 0;
  1000. unsigned long irq_flags, flags;
  1001. u32 irq;
  1002. irq_handler_t irq_handler;
  1003. spin_lock_irqsave(&bnad->bna_lock, flags);
  1004. if (bnad->cfg_flags & BNAD_CF_MSIX) {
  1005. irq_handler = (irq_handler_t)bnad_msix_mbox_handler;
  1006. irq = bnad->msix_table[BNAD_MAILBOX_MSIX_INDEX].vector;
  1007. irq_flags = 0;
  1008. } else {
  1009. irq_handler = (irq_handler_t)bnad_isr;
  1010. irq = bnad->pcidev->irq;
  1011. irq_flags = IRQF_SHARED;
  1012. }
  1013. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1014. sprintf(bnad->mbox_irq_name, "%s", BNAD_NAME);
  1015. /*
  1016. * Set the Mbox IRQ disable flag, so that the IRQ handler
  1017. * called from request_irq() for SHARED IRQs do not execute
  1018. */
  1019. set_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags);
  1020. BNAD_UPDATE_CTR(bnad, mbox_intr_disabled);
  1021. err = request_irq(irq, irq_handler, irq_flags,
  1022. bnad->mbox_irq_name, bnad);
  1023. return err;
  1024. }
  1025. static void
  1026. bnad_txrx_irq_free(struct bnad *bnad, struct bna_intr_info *intr_info)
  1027. {
  1028. kfree(intr_info->idl);
  1029. intr_info->idl = NULL;
  1030. }
  1031. /* Allocates Interrupt Descriptor List for MSIX/INT-X vectors */
  1032. static int
  1033. bnad_txrx_irq_alloc(struct bnad *bnad, enum bnad_intr_source src,
  1034. u32 txrx_id, struct bna_intr_info *intr_info)
  1035. {
  1036. int i, vector_start = 0;
  1037. u32 cfg_flags;
  1038. unsigned long flags;
  1039. spin_lock_irqsave(&bnad->bna_lock, flags);
  1040. cfg_flags = bnad->cfg_flags;
  1041. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1042. if (cfg_flags & BNAD_CF_MSIX) {
  1043. intr_info->intr_type = BNA_INTR_T_MSIX;
  1044. intr_info->idl = kcalloc(intr_info->num,
  1045. sizeof(struct bna_intr_descr),
  1046. GFP_KERNEL);
  1047. if (!intr_info->idl)
  1048. return -ENOMEM;
  1049. switch (src) {
  1050. case BNAD_INTR_TX:
  1051. vector_start = BNAD_MAILBOX_MSIX_VECTORS + txrx_id;
  1052. break;
  1053. case BNAD_INTR_RX:
  1054. vector_start = BNAD_MAILBOX_MSIX_VECTORS +
  1055. (bnad->num_tx * bnad->num_txq_per_tx) +
  1056. txrx_id;
  1057. break;
  1058. default:
  1059. BUG();
  1060. }
  1061. for (i = 0; i < intr_info->num; i++)
  1062. intr_info->idl[i].vector = vector_start + i;
  1063. } else {
  1064. intr_info->intr_type = BNA_INTR_T_INTX;
  1065. intr_info->num = 1;
  1066. intr_info->idl = kcalloc(intr_info->num,
  1067. sizeof(struct bna_intr_descr),
  1068. GFP_KERNEL);
  1069. if (!intr_info->idl)
  1070. return -ENOMEM;
  1071. switch (src) {
  1072. case BNAD_INTR_TX:
  1073. intr_info->idl[0].vector = BNAD_INTX_TX_IB_BITMASK;
  1074. break;
  1075. case BNAD_INTR_RX:
  1076. intr_info->idl[0].vector = BNAD_INTX_RX_IB_BITMASK;
  1077. break;
  1078. }
  1079. }
  1080. return 0;
  1081. }
  1082. /**
  1083. * NOTE: Should be called for MSIX only
  1084. * Unregisters Tx MSIX vector(s) from the kernel
  1085. */
  1086. static void
  1087. bnad_tx_msix_unregister(struct bnad *bnad, struct bnad_tx_info *tx_info,
  1088. int num_txqs)
  1089. {
  1090. int i;
  1091. int vector_num;
  1092. for (i = 0; i < num_txqs; i++) {
  1093. if (tx_info->tcb[i] == NULL)
  1094. continue;
  1095. vector_num = tx_info->tcb[i]->intr_vector;
  1096. free_irq(bnad->msix_table[vector_num].vector, tx_info->tcb[i]);
  1097. }
  1098. }
  1099. /**
  1100. * NOTE: Should be called for MSIX only
  1101. * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel
  1102. */
  1103. static int
  1104. bnad_tx_msix_register(struct bnad *bnad, struct bnad_tx_info *tx_info,
  1105. u32 tx_id, int num_txqs)
  1106. {
  1107. int i;
  1108. int err;
  1109. int vector_num;
  1110. for (i = 0; i < num_txqs; i++) {
  1111. vector_num = tx_info->tcb[i]->intr_vector;
  1112. sprintf(tx_info->tcb[i]->name, "%s TXQ %d", bnad->netdev->name,
  1113. tx_id + tx_info->tcb[i]->id);
  1114. err = request_irq(bnad->msix_table[vector_num].vector,
  1115. (irq_handler_t)bnad_msix_tx, 0,
  1116. tx_info->tcb[i]->name,
  1117. tx_info->tcb[i]);
  1118. if (err)
  1119. goto err_return;
  1120. }
  1121. return 0;
  1122. err_return:
  1123. if (i > 0)
  1124. bnad_tx_msix_unregister(bnad, tx_info, (i - 1));
  1125. return -1;
  1126. }
  1127. /**
  1128. * NOTE: Should be called for MSIX only
  1129. * Unregisters Rx MSIX vector(s) from the kernel
  1130. */
  1131. static void
  1132. bnad_rx_msix_unregister(struct bnad *bnad, struct bnad_rx_info *rx_info,
  1133. int num_rxps)
  1134. {
  1135. int i;
  1136. int vector_num;
  1137. for (i = 0; i < num_rxps; i++) {
  1138. if (rx_info->rx_ctrl[i].ccb == NULL)
  1139. continue;
  1140. vector_num = rx_info->rx_ctrl[i].ccb->intr_vector;
  1141. free_irq(bnad->msix_table[vector_num].vector,
  1142. rx_info->rx_ctrl[i].ccb);
  1143. }
  1144. }
  1145. /**
  1146. * NOTE: Should be called for MSIX only
  1147. * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel
  1148. */
  1149. static int
  1150. bnad_rx_msix_register(struct bnad *bnad, struct bnad_rx_info *rx_info,
  1151. u32 rx_id, int num_rxps)
  1152. {
  1153. int i;
  1154. int err;
  1155. int vector_num;
  1156. for (i = 0; i < num_rxps; i++) {
  1157. vector_num = rx_info->rx_ctrl[i].ccb->intr_vector;
  1158. sprintf(rx_info->rx_ctrl[i].ccb->name, "%s CQ %d",
  1159. bnad->netdev->name,
  1160. rx_id + rx_info->rx_ctrl[i].ccb->id);
  1161. err = request_irq(bnad->msix_table[vector_num].vector,
  1162. (irq_handler_t)bnad_msix_rx, 0,
  1163. rx_info->rx_ctrl[i].ccb->name,
  1164. rx_info->rx_ctrl[i].ccb);
  1165. if (err)
  1166. goto err_return;
  1167. }
  1168. return 0;
  1169. err_return:
  1170. if (i > 0)
  1171. bnad_rx_msix_unregister(bnad, rx_info, (i - 1));
  1172. return -1;
  1173. }
  1174. /* Free Tx object Resources */
  1175. static void
  1176. bnad_tx_res_free(struct bnad *bnad, struct bna_res_info *res_info)
  1177. {
  1178. int i;
  1179. for (i = 0; i < BNA_TX_RES_T_MAX; i++) {
  1180. if (res_info[i].res_type == BNA_RES_T_MEM)
  1181. bnad_mem_free(bnad, &res_info[i].res_u.mem_info);
  1182. else if (res_info[i].res_type == BNA_RES_T_INTR)
  1183. bnad_txrx_irq_free(bnad, &res_info[i].res_u.intr_info);
  1184. }
  1185. }
  1186. /* Allocates memory and interrupt resources for Tx object */
  1187. static int
  1188. bnad_tx_res_alloc(struct bnad *bnad, struct bna_res_info *res_info,
  1189. u32 tx_id)
  1190. {
  1191. int i, err = 0;
  1192. for (i = 0; i < BNA_TX_RES_T_MAX; i++) {
  1193. if (res_info[i].res_type == BNA_RES_T_MEM)
  1194. err = bnad_mem_alloc(bnad,
  1195. &res_info[i].res_u.mem_info);
  1196. else if (res_info[i].res_type == BNA_RES_T_INTR)
  1197. err = bnad_txrx_irq_alloc(bnad, BNAD_INTR_TX, tx_id,
  1198. &res_info[i].res_u.intr_info);
  1199. if (err)
  1200. goto err_return;
  1201. }
  1202. return 0;
  1203. err_return:
  1204. bnad_tx_res_free(bnad, res_info);
  1205. return err;
  1206. }
  1207. /* Free Rx object Resources */
  1208. static void
  1209. bnad_rx_res_free(struct bnad *bnad, struct bna_res_info *res_info)
  1210. {
  1211. int i;
  1212. for (i = 0; i < BNA_RX_RES_T_MAX; i++) {
  1213. if (res_info[i].res_type == BNA_RES_T_MEM)
  1214. bnad_mem_free(bnad, &res_info[i].res_u.mem_info);
  1215. else if (res_info[i].res_type == BNA_RES_T_INTR)
  1216. bnad_txrx_irq_free(bnad, &res_info[i].res_u.intr_info);
  1217. }
  1218. }
  1219. /* Allocates memory and interrupt resources for Rx object */
  1220. static int
  1221. bnad_rx_res_alloc(struct bnad *bnad, struct bna_res_info *res_info,
  1222. uint rx_id)
  1223. {
  1224. int i, err = 0;
  1225. /* All memory needs to be allocated before setup_ccbs */
  1226. for (i = 0; i < BNA_RX_RES_T_MAX; i++) {
  1227. if (res_info[i].res_type == BNA_RES_T_MEM)
  1228. err = bnad_mem_alloc(bnad,
  1229. &res_info[i].res_u.mem_info);
  1230. else if (res_info[i].res_type == BNA_RES_T_INTR)
  1231. err = bnad_txrx_irq_alloc(bnad, BNAD_INTR_RX, rx_id,
  1232. &res_info[i].res_u.intr_info);
  1233. if (err)
  1234. goto err_return;
  1235. }
  1236. return 0;
  1237. err_return:
  1238. bnad_rx_res_free(bnad, res_info);
  1239. return err;
  1240. }
  1241. /* Timer callbacks */
  1242. /* a) IOC timer */
  1243. static void
  1244. bnad_ioc_timeout(unsigned long data)
  1245. {
  1246. struct bnad *bnad = (struct bnad *)data;
  1247. unsigned long flags;
  1248. spin_lock_irqsave(&bnad->bna_lock, flags);
  1249. bfa_nw_ioc_timeout((void *) &bnad->bna.ioceth.ioc);
  1250. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1251. }
  1252. static void
  1253. bnad_ioc_hb_check(unsigned long data)
  1254. {
  1255. struct bnad *bnad = (struct bnad *)data;
  1256. unsigned long flags;
  1257. spin_lock_irqsave(&bnad->bna_lock, flags);
  1258. bfa_nw_ioc_hb_check((void *) &bnad->bna.ioceth.ioc);
  1259. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1260. }
  1261. static void
  1262. bnad_iocpf_timeout(unsigned long data)
  1263. {
  1264. struct bnad *bnad = (struct bnad *)data;
  1265. unsigned long flags;
  1266. spin_lock_irqsave(&bnad->bna_lock, flags);
  1267. bfa_nw_iocpf_timeout((void *) &bnad->bna.ioceth.ioc);
  1268. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1269. }
  1270. static void
  1271. bnad_iocpf_sem_timeout(unsigned long data)
  1272. {
  1273. struct bnad *bnad = (struct bnad *)data;
  1274. unsigned long flags;
  1275. spin_lock_irqsave(&bnad->bna_lock, flags);
  1276. bfa_nw_iocpf_sem_timeout((void *) &bnad->bna.ioceth.ioc);
  1277. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1278. }
  1279. /*
  1280. * All timer routines use bnad->bna_lock to protect against
  1281. * the following race, which may occur in case of no locking:
  1282. * Time CPU m CPU n
  1283. * 0 1 = test_bit
  1284. * 1 clear_bit
  1285. * 2 del_timer_sync
  1286. * 3 mod_timer
  1287. */
  1288. /* b) Dynamic Interrupt Moderation Timer */
  1289. static void
  1290. bnad_dim_timeout(unsigned long data)
  1291. {
  1292. struct bnad *bnad = (struct bnad *)data;
  1293. struct bnad_rx_info *rx_info;
  1294. struct bnad_rx_ctrl *rx_ctrl;
  1295. int i, j;
  1296. unsigned long flags;
  1297. if (!netif_carrier_ok(bnad->netdev))
  1298. return;
  1299. spin_lock_irqsave(&bnad->bna_lock, flags);
  1300. for (i = 0; i < bnad->num_rx; i++) {
  1301. rx_info = &bnad->rx_info[i];
  1302. if (!rx_info->rx)
  1303. continue;
  1304. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  1305. rx_ctrl = &rx_info->rx_ctrl[j];
  1306. if (!rx_ctrl->ccb)
  1307. continue;
  1308. bna_rx_dim_update(rx_ctrl->ccb);
  1309. }
  1310. }
  1311. /* Check for BNAD_CF_DIM_ENABLED, does not eleminate a race */
  1312. if (test_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags))
  1313. mod_timer(&bnad->dim_timer,
  1314. jiffies + msecs_to_jiffies(BNAD_DIM_TIMER_FREQ));
  1315. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1316. }
  1317. /* c) Statistics Timer */
  1318. static void
  1319. bnad_stats_timeout(unsigned long data)
  1320. {
  1321. struct bnad *bnad = (struct bnad *)data;
  1322. unsigned long flags;
  1323. if (!netif_running(bnad->netdev) ||
  1324. !test_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags))
  1325. return;
  1326. spin_lock_irqsave(&bnad->bna_lock, flags);
  1327. bna_hw_stats_get(&bnad->bna);
  1328. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1329. }
  1330. /*
  1331. * Set up timer for DIM
  1332. * Called with bnad->bna_lock held
  1333. */
  1334. void
  1335. bnad_dim_timer_start(struct bnad *bnad)
  1336. {
  1337. if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
  1338. !test_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags)) {
  1339. setup_timer(&bnad->dim_timer, bnad_dim_timeout,
  1340. (unsigned long)bnad);
  1341. set_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags);
  1342. mod_timer(&bnad->dim_timer,
  1343. jiffies + msecs_to_jiffies(BNAD_DIM_TIMER_FREQ));
  1344. }
  1345. }
  1346. /*
  1347. * Set up timer for statistics
  1348. * Called with mutex_lock(&bnad->conf_mutex) held
  1349. */
  1350. static void
  1351. bnad_stats_timer_start(struct bnad *bnad)
  1352. {
  1353. unsigned long flags;
  1354. spin_lock_irqsave(&bnad->bna_lock, flags);
  1355. if (!test_and_set_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags)) {
  1356. setup_timer(&bnad->stats_timer, bnad_stats_timeout,
  1357. (unsigned long)bnad);
  1358. mod_timer(&bnad->stats_timer,
  1359. jiffies + msecs_to_jiffies(BNAD_STATS_TIMER_FREQ));
  1360. }
  1361. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1362. }
  1363. /*
  1364. * Stops the stats timer
  1365. * Called with mutex_lock(&bnad->conf_mutex) held
  1366. */
  1367. static void
  1368. bnad_stats_timer_stop(struct bnad *bnad)
  1369. {
  1370. int to_del = 0;
  1371. unsigned long flags;
  1372. spin_lock_irqsave(&bnad->bna_lock, flags);
  1373. if (test_and_clear_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags))
  1374. to_del = 1;
  1375. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1376. if (to_del)
  1377. del_timer_sync(&bnad->stats_timer);
  1378. }
  1379. /* Utilities */
  1380. static void
  1381. bnad_netdev_mc_list_get(struct net_device *netdev, u8 *mc_list)
  1382. {
  1383. int i = 1; /* Index 0 has broadcast address */
  1384. struct netdev_hw_addr *mc_addr;
  1385. netdev_for_each_mc_addr(mc_addr, netdev) {
  1386. memcpy(&mc_list[i * ETH_ALEN], &mc_addr->addr[0],
  1387. ETH_ALEN);
  1388. i++;
  1389. }
  1390. }
  1391. static int
  1392. bnad_napi_poll_rx(struct napi_struct *napi, int budget)
  1393. {
  1394. struct bnad_rx_ctrl *rx_ctrl =
  1395. container_of(napi, struct bnad_rx_ctrl, napi);
  1396. struct bnad *bnad = rx_ctrl->bnad;
  1397. int rcvd = 0;
  1398. if (!netif_carrier_ok(bnad->netdev))
  1399. goto poll_exit;
  1400. rcvd = bnad_poll_cq(bnad, rx_ctrl->ccb, budget);
  1401. if (rcvd == budget)
  1402. return rcvd;
  1403. poll_exit:
  1404. napi_complete((napi));
  1405. BNAD_UPDATE_CTR(bnad, netif_rx_complete);
  1406. if (rx_ctrl->ccb)
  1407. bnad_enable_rx_irq(bnad, rx_ctrl->ccb);
  1408. return rcvd;
  1409. }
  1410. #define BNAD_NAPI_POLL_QUOTA 64
  1411. static void
  1412. bnad_napi_init(struct bnad *bnad, u32 rx_id)
  1413. {
  1414. struct bnad_rx_ctrl *rx_ctrl;
  1415. int i;
  1416. /* Initialize & enable NAPI */
  1417. for (i = 0; i < bnad->num_rxp_per_rx; i++) {
  1418. rx_ctrl = &bnad->rx_info[rx_id].rx_ctrl[i];
  1419. netif_napi_add(bnad->netdev, &rx_ctrl->napi,
  1420. bnad_napi_poll_rx, BNAD_NAPI_POLL_QUOTA);
  1421. }
  1422. }
  1423. static void
  1424. bnad_napi_enable(struct bnad *bnad, u32 rx_id)
  1425. {
  1426. struct bnad_rx_ctrl *rx_ctrl;
  1427. int i;
  1428. /* Initialize & enable NAPI */
  1429. for (i = 0; i < bnad->num_rxp_per_rx; i++) {
  1430. rx_ctrl = &bnad->rx_info[rx_id].rx_ctrl[i];
  1431. napi_enable(&rx_ctrl->napi);
  1432. }
  1433. }
  1434. static void
  1435. bnad_napi_disable(struct bnad *bnad, u32 rx_id)
  1436. {
  1437. int i;
  1438. /* First disable and then clean up */
  1439. for (i = 0; i < bnad->num_rxp_per_rx; i++) {
  1440. napi_disable(&bnad->rx_info[rx_id].rx_ctrl[i].napi);
  1441. netif_napi_del(&bnad->rx_info[rx_id].rx_ctrl[i].napi);
  1442. }
  1443. }
  1444. /* Should be held with conf_lock held */
  1445. void
  1446. bnad_cleanup_tx(struct bnad *bnad, u32 tx_id)
  1447. {
  1448. struct bnad_tx_info *tx_info = &bnad->tx_info[tx_id];
  1449. struct bna_res_info *res_info = &bnad->tx_res_info[tx_id].res_info[0];
  1450. unsigned long flags;
  1451. if (!tx_info->tx)
  1452. return;
  1453. init_completion(&bnad->bnad_completions.tx_comp);
  1454. spin_lock_irqsave(&bnad->bna_lock, flags);
  1455. bna_tx_disable(tx_info->tx, BNA_HARD_CLEANUP, bnad_cb_tx_disabled);
  1456. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1457. wait_for_completion(&bnad->bnad_completions.tx_comp);
  1458. if (tx_info->tcb[0]->intr_type == BNA_INTR_T_MSIX)
  1459. bnad_tx_msix_unregister(bnad, tx_info,
  1460. bnad->num_txq_per_tx);
  1461. if (0 == tx_id)
  1462. tasklet_kill(&bnad->tx_free_tasklet);
  1463. spin_lock_irqsave(&bnad->bna_lock, flags);
  1464. bna_tx_destroy(tx_info->tx);
  1465. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1466. tx_info->tx = NULL;
  1467. tx_info->tx_id = 0;
  1468. bnad_tx_res_free(bnad, res_info);
  1469. }
  1470. /* Should be held with conf_lock held */
  1471. int
  1472. bnad_setup_tx(struct bnad *bnad, u32 tx_id)
  1473. {
  1474. int err;
  1475. struct bnad_tx_info *tx_info = &bnad->tx_info[tx_id];
  1476. struct bna_res_info *res_info = &bnad->tx_res_info[tx_id].res_info[0];
  1477. struct bna_intr_info *intr_info =
  1478. &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info;
  1479. struct bna_tx_config *tx_config = &bnad->tx_config[tx_id];
  1480. struct bna_tx_event_cbfn tx_cbfn;
  1481. struct bna_tx *tx;
  1482. unsigned long flags;
  1483. tx_info->tx_id = tx_id;
  1484. /* Initialize the Tx object configuration */
  1485. tx_config->num_txq = bnad->num_txq_per_tx;
  1486. tx_config->txq_depth = bnad->txq_depth;
  1487. tx_config->tx_type = BNA_TX_T_REGULAR;
  1488. tx_config->coalescing_timeo = bnad->tx_coalescing_timeo;
  1489. /* Initialize the tx event handlers */
  1490. tx_cbfn.tcb_setup_cbfn = bnad_cb_tcb_setup;
  1491. tx_cbfn.tcb_destroy_cbfn = bnad_cb_tcb_destroy;
  1492. tx_cbfn.tx_stall_cbfn = bnad_cb_tx_stall;
  1493. tx_cbfn.tx_resume_cbfn = bnad_cb_tx_resume;
  1494. tx_cbfn.tx_cleanup_cbfn = bnad_cb_tx_cleanup;
  1495. /* Get BNA's resource requirement for one tx object */
  1496. spin_lock_irqsave(&bnad->bna_lock, flags);
  1497. bna_tx_res_req(bnad->num_txq_per_tx,
  1498. bnad->txq_depth, res_info);
  1499. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1500. /* Fill Unmap Q memory requirements */
  1501. BNAD_FILL_UNMAPQ_MEM_REQ(
  1502. &res_info[BNA_TX_RES_MEM_T_UNMAPQ],
  1503. bnad->num_txq_per_tx,
  1504. BNAD_TX_UNMAPQ_DEPTH);
  1505. /* Allocate resources */
  1506. err = bnad_tx_res_alloc(bnad, res_info, tx_id);
  1507. if (err)
  1508. return err;
  1509. /* Ask BNA to create one Tx object, supplying required resources */
  1510. spin_lock_irqsave(&bnad->bna_lock, flags);
  1511. tx = bna_tx_create(&bnad->bna, bnad, tx_config, &tx_cbfn, res_info,
  1512. tx_info);
  1513. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1514. if (!tx)
  1515. goto err_return;
  1516. tx_info->tx = tx;
  1517. /* Register ISR for the Tx object */
  1518. if (intr_info->intr_type == BNA_INTR_T_MSIX) {
  1519. err = bnad_tx_msix_register(bnad, tx_info,
  1520. tx_id, bnad->num_txq_per_tx);
  1521. if (err)
  1522. goto err_return;
  1523. }
  1524. spin_lock_irqsave(&bnad->bna_lock, flags);
  1525. bna_tx_enable(tx);
  1526. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1527. return 0;
  1528. err_return:
  1529. bnad_tx_res_free(bnad, res_info);
  1530. return err;
  1531. }
  1532. /* Setup the rx config for bna_rx_create */
  1533. /* bnad decides the configuration */
  1534. static void
  1535. bnad_init_rx_config(struct bnad *bnad, struct bna_rx_config *rx_config)
  1536. {
  1537. rx_config->rx_type = BNA_RX_T_REGULAR;
  1538. rx_config->num_paths = bnad->num_rxp_per_rx;
  1539. rx_config->coalescing_timeo = bnad->rx_coalescing_timeo;
  1540. if (bnad->num_rxp_per_rx > 1) {
  1541. rx_config->rss_status = BNA_STATUS_T_ENABLED;
  1542. rx_config->rss_config.hash_type =
  1543. (BFI_ENET_RSS_IPV6 |
  1544. BFI_ENET_RSS_IPV6_TCP |
  1545. BFI_ENET_RSS_IPV4 |
  1546. BFI_ENET_RSS_IPV4_TCP);
  1547. rx_config->rss_config.hash_mask =
  1548. bnad->num_rxp_per_rx - 1;
  1549. get_random_bytes(rx_config->rss_config.toeplitz_hash_key,
  1550. sizeof(rx_config->rss_config.toeplitz_hash_key));
  1551. } else {
  1552. rx_config->rss_status = BNA_STATUS_T_DISABLED;
  1553. memset(&rx_config->rss_config, 0,
  1554. sizeof(rx_config->rss_config));
  1555. }
  1556. rx_config->rxp_type = BNA_RXP_SLR;
  1557. rx_config->q_depth = bnad->rxq_depth;
  1558. rx_config->small_buff_size = BFI_SMALL_RXBUF_SIZE;
  1559. rx_config->vlan_strip_status = BNA_STATUS_T_ENABLED;
  1560. }
  1561. static void
  1562. bnad_rx_ctrl_init(struct bnad *bnad, u32 rx_id)
  1563. {
  1564. struct bnad_rx_info *rx_info = &bnad->rx_info[rx_id];
  1565. int i;
  1566. for (i = 0; i < bnad->num_rxp_per_rx; i++)
  1567. rx_info->rx_ctrl[i].bnad = bnad;
  1568. }
  1569. /* Called with mutex_lock(&bnad->conf_mutex) held */
  1570. void
  1571. bnad_cleanup_rx(struct bnad *bnad, u32 rx_id)
  1572. {
  1573. struct bnad_rx_info *rx_info = &bnad->rx_info[rx_id];
  1574. struct bna_rx_config *rx_config = &bnad->rx_config[rx_id];
  1575. struct bna_res_info *res_info = &bnad->rx_res_info[rx_id].res_info[0];
  1576. unsigned long flags;
  1577. int dim_timer_del = 0;
  1578. if (!rx_info->rx)
  1579. return;
  1580. if (0 == rx_id) {
  1581. spin_lock_irqsave(&bnad->bna_lock, flags);
  1582. dim_timer_del = bnad_dim_timer_running(bnad);
  1583. if (dim_timer_del)
  1584. clear_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags);
  1585. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1586. if (dim_timer_del)
  1587. del_timer_sync(&bnad->dim_timer);
  1588. }
  1589. init_completion(&bnad->bnad_completions.rx_comp);
  1590. spin_lock_irqsave(&bnad->bna_lock, flags);
  1591. bna_rx_disable(rx_info->rx, BNA_HARD_CLEANUP, bnad_cb_rx_disabled);
  1592. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1593. wait_for_completion(&bnad->bnad_completions.rx_comp);
  1594. if (rx_info->rx_ctrl[0].ccb->intr_type == BNA_INTR_T_MSIX)
  1595. bnad_rx_msix_unregister(bnad, rx_info, rx_config->num_paths);
  1596. bnad_napi_disable(bnad, rx_id);
  1597. spin_lock_irqsave(&bnad->bna_lock, flags);
  1598. bna_rx_destroy(rx_info->rx);
  1599. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1600. rx_info->rx = NULL;
  1601. bnad_rx_res_free(bnad, res_info);
  1602. }
  1603. /* Called with mutex_lock(&bnad->conf_mutex) held */
  1604. int
  1605. bnad_setup_rx(struct bnad *bnad, u32 rx_id)
  1606. {
  1607. int err;
  1608. struct bnad_rx_info *rx_info = &bnad->rx_info[rx_id];
  1609. struct bna_res_info *res_info = &bnad->rx_res_info[rx_id].res_info[0];
  1610. struct bna_intr_info *intr_info =
  1611. &res_info[BNA_RX_RES_T_INTR].res_u.intr_info;
  1612. struct bna_rx_config *rx_config = &bnad->rx_config[rx_id];
  1613. struct bna_rx_event_cbfn rx_cbfn;
  1614. struct bna_rx *rx;
  1615. unsigned long flags;
  1616. rx_info->rx_id = rx_id;
  1617. /* Initialize the Rx object configuration */
  1618. bnad_init_rx_config(bnad, rx_config);
  1619. /* Initialize the Rx event handlers */
  1620. rx_cbfn.rcb_setup_cbfn = bnad_cb_rcb_setup;
  1621. rx_cbfn.rcb_destroy_cbfn = bnad_cb_rcb_destroy;
  1622. rx_cbfn.ccb_setup_cbfn = bnad_cb_ccb_setup;
  1623. rx_cbfn.ccb_destroy_cbfn = bnad_cb_ccb_destroy;
  1624. rx_cbfn.rx_cleanup_cbfn = bnad_cb_rx_cleanup;
  1625. rx_cbfn.rx_post_cbfn = bnad_cb_rx_post;
  1626. /* Get BNA's resource requirement for one Rx object */
  1627. spin_lock_irqsave(&bnad->bna_lock, flags);
  1628. bna_rx_res_req(rx_config, res_info);
  1629. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1630. /* Fill Unmap Q memory requirements */
  1631. BNAD_FILL_UNMAPQ_MEM_REQ(
  1632. &res_info[BNA_RX_RES_MEM_T_UNMAPQ],
  1633. rx_config->num_paths +
  1634. ((rx_config->rxp_type == BNA_RXP_SINGLE) ? 0 :
  1635. rx_config->num_paths), BNAD_RX_UNMAPQ_DEPTH);
  1636. /* Allocate resource */
  1637. err = bnad_rx_res_alloc(bnad, res_info, rx_id);
  1638. if (err)
  1639. return err;
  1640. bnad_rx_ctrl_init(bnad, rx_id);
  1641. /* Ask BNA to create one Rx object, supplying required resources */
  1642. spin_lock_irqsave(&bnad->bna_lock, flags);
  1643. rx = bna_rx_create(&bnad->bna, bnad, rx_config, &rx_cbfn, res_info,
  1644. rx_info);
  1645. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1646. if (!rx)
  1647. goto err_return;
  1648. rx_info->rx = rx;
  1649. /*
  1650. * Init NAPI, so that state is set to NAPI_STATE_SCHED,
  1651. * so that IRQ handler cannot schedule NAPI at this point.
  1652. */
  1653. bnad_napi_init(bnad, rx_id);
  1654. /* Register ISR for the Rx object */
  1655. if (intr_info->intr_type == BNA_INTR_T_MSIX) {
  1656. err = bnad_rx_msix_register(bnad, rx_info, rx_id,
  1657. rx_config->num_paths);
  1658. if (err)
  1659. goto err_return;
  1660. }
  1661. spin_lock_irqsave(&bnad->bna_lock, flags);
  1662. if (0 == rx_id) {
  1663. /* Set up Dynamic Interrupt Moderation Vector */
  1664. if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED)
  1665. bna_rx_dim_reconfig(&bnad->bna, bna_napi_dim_vector);
  1666. /* Enable VLAN filtering only on the default Rx */
  1667. bna_rx_vlanfilter_enable(rx);
  1668. /* Start the DIM timer */
  1669. bnad_dim_timer_start(bnad);
  1670. }
  1671. bna_rx_enable(rx);
  1672. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1673. /* Enable scheduling of NAPI */
  1674. bnad_napi_enable(bnad, rx_id);
  1675. return 0;
  1676. err_return:
  1677. bnad_cleanup_rx(bnad, rx_id);
  1678. return err;
  1679. }
  1680. /* Called with conf_lock & bnad->bna_lock held */
  1681. void
  1682. bnad_tx_coalescing_timeo_set(struct bnad *bnad)
  1683. {
  1684. struct bnad_tx_info *tx_info;
  1685. tx_info = &bnad->tx_info[0];
  1686. if (!tx_info->tx)
  1687. return;
  1688. bna_tx_coalescing_timeo_set(tx_info->tx, bnad->tx_coalescing_timeo);
  1689. }
  1690. /* Called with conf_lock & bnad->bna_lock held */
  1691. void
  1692. bnad_rx_coalescing_timeo_set(struct bnad *bnad)
  1693. {
  1694. struct bnad_rx_info *rx_info;
  1695. int i;
  1696. for (i = 0; i < bnad->num_rx; i++) {
  1697. rx_info = &bnad->rx_info[i];
  1698. if (!rx_info->rx)
  1699. continue;
  1700. bna_rx_coalescing_timeo_set(rx_info->rx,
  1701. bnad->rx_coalescing_timeo);
  1702. }
  1703. }
  1704. /*
  1705. * Called with bnad->bna_lock held
  1706. */
  1707. static int
  1708. bnad_mac_addr_set_locked(struct bnad *bnad, u8 *mac_addr)
  1709. {
  1710. int ret;
  1711. if (!is_valid_ether_addr(mac_addr))
  1712. return -EADDRNOTAVAIL;
  1713. /* If datapath is down, pretend everything went through */
  1714. if (!bnad->rx_info[0].rx)
  1715. return 0;
  1716. ret = bna_rx_ucast_set(bnad->rx_info[0].rx, mac_addr, NULL);
  1717. if (ret != BNA_CB_SUCCESS)
  1718. return -EADDRNOTAVAIL;
  1719. return 0;
  1720. }
  1721. /* Should be called with conf_lock held */
  1722. static int
  1723. bnad_enable_default_bcast(struct bnad *bnad)
  1724. {
  1725. struct bnad_rx_info *rx_info = &bnad->rx_info[0];
  1726. int ret;
  1727. unsigned long flags;
  1728. init_completion(&bnad->bnad_completions.mcast_comp);
  1729. spin_lock_irqsave(&bnad->bna_lock, flags);
  1730. ret = bna_rx_mcast_add(rx_info->rx, (u8 *)bnad_bcast_addr,
  1731. bnad_cb_rx_mcast_add);
  1732. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1733. if (ret == BNA_CB_SUCCESS)
  1734. wait_for_completion(&bnad->bnad_completions.mcast_comp);
  1735. else
  1736. return -ENODEV;
  1737. if (bnad->bnad_completions.mcast_comp_status != BNA_CB_SUCCESS)
  1738. return -ENODEV;
  1739. return 0;
  1740. }
  1741. /* Called with bnad_conf_lock() held */
  1742. static void
  1743. bnad_restore_vlans(struct bnad *bnad, u32 rx_id)
  1744. {
  1745. u16 vid;
  1746. unsigned long flags;
  1747. BUG_ON(!(VLAN_N_VID == BFI_ENET_VLAN_ID_MAX));
  1748. for_each_set_bit(vid, bnad->active_vlans, VLAN_N_VID) {
  1749. spin_lock_irqsave(&bnad->bna_lock, flags);
  1750. bna_rx_vlan_add(bnad->rx_info[rx_id].rx, vid);
  1751. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1752. }
  1753. }
  1754. /* Statistics utilities */
  1755. void
  1756. bnad_netdev_qstats_fill(struct bnad *bnad, struct rtnl_link_stats64 *stats)
  1757. {
  1758. int i, j;
  1759. for (i = 0; i < bnad->num_rx; i++) {
  1760. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  1761. if (bnad->rx_info[i].rx_ctrl[j].ccb) {
  1762. stats->rx_packets += bnad->rx_info[i].
  1763. rx_ctrl[j].ccb->rcb[0]->rxq->rx_packets;
  1764. stats->rx_bytes += bnad->rx_info[i].
  1765. rx_ctrl[j].ccb->rcb[0]->rxq->rx_bytes;
  1766. if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
  1767. bnad->rx_info[i].rx_ctrl[j].ccb->
  1768. rcb[1]->rxq) {
  1769. stats->rx_packets +=
  1770. bnad->rx_info[i].rx_ctrl[j].
  1771. ccb->rcb[1]->rxq->rx_packets;
  1772. stats->rx_bytes +=
  1773. bnad->rx_info[i].rx_ctrl[j].
  1774. ccb->rcb[1]->rxq->rx_bytes;
  1775. }
  1776. }
  1777. }
  1778. }
  1779. for (i = 0; i < bnad->num_tx; i++) {
  1780. for (j = 0; j < bnad->num_txq_per_tx; j++) {
  1781. if (bnad->tx_info[i].tcb[j]) {
  1782. stats->tx_packets +=
  1783. bnad->tx_info[i].tcb[j]->txq->tx_packets;
  1784. stats->tx_bytes +=
  1785. bnad->tx_info[i].tcb[j]->txq->tx_bytes;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. /*
  1791. * Must be called with the bna_lock held.
  1792. */
  1793. void
  1794. bnad_netdev_hwstats_fill(struct bnad *bnad, struct rtnl_link_stats64 *stats)
  1795. {
  1796. struct bfi_enet_stats_mac *mac_stats;
  1797. u32 bmap;
  1798. int i;
  1799. mac_stats = &bnad->stats.bna_stats->hw_stats.mac_stats;
  1800. stats->rx_errors =
  1801. mac_stats->rx_fcs_error + mac_stats->rx_alignment_error +
  1802. mac_stats->rx_frame_length_error + mac_stats->rx_code_error +
  1803. mac_stats->rx_undersize;
  1804. stats->tx_errors = mac_stats->tx_fcs_error +
  1805. mac_stats->tx_undersize;
  1806. stats->rx_dropped = mac_stats->rx_drop;
  1807. stats->tx_dropped = mac_stats->tx_drop;
  1808. stats->multicast = mac_stats->rx_multicast;
  1809. stats->collisions = mac_stats->tx_total_collision;
  1810. stats->rx_length_errors = mac_stats->rx_frame_length_error;
  1811. /* receive ring buffer overflow ?? */
  1812. stats->rx_crc_errors = mac_stats->rx_fcs_error;
  1813. stats->rx_frame_errors = mac_stats->rx_alignment_error;
  1814. /* recv'r fifo overrun */
  1815. bmap = bna_rx_rid_mask(&bnad->bna);
  1816. for (i = 0; bmap; i++) {
  1817. if (bmap & 1) {
  1818. stats->rx_fifo_errors +=
  1819. bnad->stats.bna_stats->
  1820. hw_stats.rxf_stats[i].frame_drops;
  1821. break;
  1822. }
  1823. bmap >>= 1;
  1824. }
  1825. }
  1826. static void
  1827. bnad_mbox_irq_sync(struct bnad *bnad)
  1828. {
  1829. u32 irq;
  1830. unsigned long flags;
  1831. spin_lock_irqsave(&bnad->bna_lock, flags);
  1832. if (bnad->cfg_flags & BNAD_CF_MSIX)
  1833. irq = bnad->msix_table[BNAD_MAILBOX_MSIX_INDEX].vector;
  1834. else
  1835. irq = bnad->pcidev->irq;
  1836. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1837. synchronize_irq(irq);
  1838. }
  1839. /* Utility used by bnad_start_xmit, for doing TSO */
  1840. static int
  1841. bnad_tso_prepare(struct bnad *bnad, struct sk_buff *skb)
  1842. {
  1843. int err;
  1844. /* SKB_GSO_TCPV4 and SKB_GSO_TCPV6 is defined since 2.6.18. */
  1845. BUG_ON(!(skb_shinfo(skb)->gso_type == SKB_GSO_TCPV4 ||
  1846. skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6));
  1847. if (skb_header_cloned(skb)) {
  1848. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  1849. if (err) {
  1850. BNAD_UPDATE_CTR(bnad, tso_err);
  1851. return err;
  1852. }
  1853. }
  1854. /*
  1855. * For TSO, the TCP checksum field is seeded with pseudo-header sum
  1856. * excluding the length field.
  1857. */
  1858. if (skb->protocol == htons(ETH_P_IP)) {
  1859. struct iphdr *iph = ip_hdr(skb);
  1860. /* Do we really need these? */
  1861. iph->tot_len = 0;
  1862. iph->check = 0;
  1863. tcp_hdr(skb)->check =
  1864. ~csum_tcpudp_magic(iph->saddr, iph->daddr, 0,
  1865. IPPROTO_TCP, 0);
  1866. BNAD_UPDATE_CTR(bnad, tso4);
  1867. } else {
  1868. struct ipv6hdr *ipv6h = ipv6_hdr(skb);
  1869. BUG_ON(!(skb->protocol == htons(ETH_P_IPV6)));
  1870. ipv6h->payload_len = 0;
  1871. tcp_hdr(skb)->check =
  1872. ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, 0,
  1873. IPPROTO_TCP, 0);
  1874. BNAD_UPDATE_CTR(bnad, tso6);
  1875. }
  1876. return 0;
  1877. }
  1878. /*
  1879. * Initialize Q numbers depending on Rx Paths
  1880. * Called with bnad->bna_lock held, because of cfg_flags
  1881. * access.
  1882. */
  1883. static void
  1884. bnad_q_num_init(struct bnad *bnad)
  1885. {
  1886. int rxps;
  1887. rxps = min((uint)num_online_cpus(),
  1888. (uint)(BNAD_MAX_RX * BNAD_MAX_RXP_PER_RX));
  1889. if (!(bnad->cfg_flags & BNAD_CF_MSIX))
  1890. rxps = 1; /* INTx */
  1891. bnad->num_rx = 1;
  1892. bnad->num_tx = 1;
  1893. bnad->num_rxp_per_rx = rxps;
  1894. bnad->num_txq_per_tx = BNAD_TXQ_NUM;
  1895. }
  1896. /*
  1897. * Adjusts the Q numbers, given a number of msix vectors
  1898. * Give preference to RSS as opposed to Tx priority Queues,
  1899. * in such a case, just use 1 Tx Q
  1900. * Called with bnad->bna_lock held b'cos of cfg_flags access
  1901. */
  1902. static void
  1903. bnad_q_num_adjust(struct bnad *bnad, int msix_vectors, int temp)
  1904. {
  1905. bnad->num_txq_per_tx = 1;
  1906. if ((msix_vectors >= (bnad->num_tx * bnad->num_txq_per_tx) +
  1907. bnad_rxqs_per_cq + BNAD_MAILBOX_MSIX_VECTORS) &&
  1908. (bnad->cfg_flags & BNAD_CF_MSIX)) {
  1909. bnad->num_rxp_per_rx = msix_vectors -
  1910. (bnad->num_tx * bnad->num_txq_per_tx) -
  1911. BNAD_MAILBOX_MSIX_VECTORS;
  1912. } else
  1913. bnad->num_rxp_per_rx = 1;
  1914. }
  1915. /* Enable / disable ioceth */
  1916. static int
  1917. bnad_ioceth_disable(struct bnad *bnad)
  1918. {
  1919. unsigned long flags;
  1920. int err = 0;
  1921. spin_lock_irqsave(&bnad->bna_lock, flags);
  1922. init_completion(&bnad->bnad_completions.ioc_comp);
  1923. bna_ioceth_disable(&bnad->bna.ioceth, BNA_HARD_CLEANUP);
  1924. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1925. wait_for_completion_timeout(&bnad->bnad_completions.ioc_comp,
  1926. msecs_to_jiffies(BNAD_IOCETH_TIMEOUT));
  1927. err = bnad->bnad_completions.ioc_comp_status;
  1928. return err;
  1929. }
  1930. static int
  1931. bnad_ioceth_enable(struct bnad *bnad)
  1932. {
  1933. int err = 0;
  1934. unsigned long flags;
  1935. spin_lock_irqsave(&bnad->bna_lock, flags);
  1936. init_completion(&bnad->bnad_completions.ioc_comp);
  1937. bnad->bnad_completions.ioc_comp_status = BNA_CB_WAITING;
  1938. bna_ioceth_enable(&bnad->bna.ioceth);
  1939. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1940. wait_for_completion_timeout(&bnad->bnad_completions.ioc_comp,
  1941. msecs_to_jiffies(BNAD_IOCETH_TIMEOUT));
  1942. err = bnad->bnad_completions.ioc_comp_status;
  1943. return err;
  1944. }
  1945. /* Free BNA resources */
  1946. static void
  1947. bnad_res_free(struct bnad *bnad, struct bna_res_info *res_info,
  1948. u32 res_val_max)
  1949. {
  1950. int i;
  1951. for (i = 0; i < res_val_max; i++)
  1952. bnad_mem_free(bnad, &res_info[i].res_u.mem_info);
  1953. }
  1954. /* Allocates memory and interrupt resources for BNA */
  1955. static int
  1956. bnad_res_alloc(struct bnad *bnad, struct bna_res_info *res_info,
  1957. u32 res_val_max)
  1958. {
  1959. int i, err;
  1960. for (i = 0; i < res_val_max; i++) {
  1961. err = bnad_mem_alloc(bnad, &res_info[i].res_u.mem_info);
  1962. if (err)
  1963. goto err_return;
  1964. }
  1965. return 0;
  1966. err_return:
  1967. bnad_res_free(bnad, res_info, res_val_max);
  1968. return err;
  1969. }
  1970. /* Interrupt enable / disable */
  1971. static void
  1972. bnad_enable_msix(struct bnad *bnad)
  1973. {
  1974. int i, ret;
  1975. unsigned long flags;
  1976. spin_lock_irqsave(&bnad->bna_lock, flags);
  1977. if (!(bnad->cfg_flags & BNAD_CF_MSIX)) {
  1978. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1979. return;
  1980. }
  1981. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1982. if (bnad->msix_table)
  1983. return;
  1984. bnad->msix_table =
  1985. kcalloc(bnad->msix_num, sizeof(struct msix_entry), GFP_KERNEL);
  1986. if (!bnad->msix_table)
  1987. goto intx_mode;
  1988. for (i = 0; i < bnad->msix_num; i++)
  1989. bnad->msix_table[i].entry = i;
  1990. ret = pci_enable_msix(bnad->pcidev, bnad->msix_table, bnad->msix_num);
  1991. if (ret > 0) {
  1992. /* Not enough MSI-X vectors. */
  1993. spin_lock_irqsave(&bnad->bna_lock, flags);
  1994. /* ret = #of vectors that we got */
  1995. bnad_q_num_adjust(bnad, ret, 0);
  1996. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  1997. bnad->msix_num = (bnad->num_tx * bnad->num_txq_per_tx)
  1998. + (bnad->num_rx
  1999. * bnad->num_rxp_per_rx) +
  2000. BNAD_MAILBOX_MSIX_VECTORS;
  2001. if (bnad->msix_num > ret)
  2002. goto intx_mode;
  2003. /* Try once more with adjusted numbers */
  2004. /* If this fails, fall back to INTx */
  2005. ret = pci_enable_msix(bnad->pcidev, bnad->msix_table,
  2006. bnad->msix_num);
  2007. if (ret)
  2008. goto intx_mode;
  2009. } else if (ret < 0)
  2010. goto intx_mode;
  2011. pci_intx(bnad->pcidev, 0);
  2012. return;
  2013. intx_mode:
  2014. kfree(bnad->msix_table);
  2015. bnad->msix_table = NULL;
  2016. bnad->msix_num = 0;
  2017. spin_lock_irqsave(&bnad->bna_lock, flags);
  2018. bnad->cfg_flags &= ~BNAD_CF_MSIX;
  2019. bnad_q_num_init(bnad);
  2020. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2021. }
  2022. static void
  2023. bnad_disable_msix(struct bnad *bnad)
  2024. {
  2025. u32 cfg_flags;
  2026. unsigned long flags;
  2027. spin_lock_irqsave(&bnad->bna_lock, flags);
  2028. cfg_flags = bnad->cfg_flags;
  2029. if (bnad->cfg_flags & BNAD_CF_MSIX)
  2030. bnad->cfg_flags &= ~BNAD_CF_MSIX;
  2031. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2032. if (cfg_flags & BNAD_CF_MSIX) {
  2033. pci_disable_msix(bnad->pcidev);
  2034. kfree(bnad->msix_table);
  2035. bnad->msix_table = NULL;
  2036. }
  2037. }
  2038. /* Netdev entry points */
  2039. static int
  2040. bnad_open(struct net_device *netdev)
  2041. {
  2042. int err;
  2043. struct bnad *bnad = netdev_priv(netdev);
  2044. struct bna_pause_config pause_config;
  2045. int mtu;
  2046. unsigned long flags;
  2047. mutex_lock(&bnad->conf_mutex);
  2048. /* Tx */
  2049. err = bnad_setup_tx(bnad, 0);
  2050. if (err)
  2051. goto err_return;
  2052. /* Rx */
  2053. err = bnad_setup_rx(bnad, 0);
  2054. if (err)
  2055. goto cleanup_tx;
  2056. /* Port */
  2057. pause_config.tx_pause = 0;
  2058. pause_config.rx_pause = 0;
  2059. mtu = ETH_HLEN + VLAN_HLEN + bnad->netdev->mtu + ETH_FCS_LEN;
  2060. spin_lock_irqsave(&bnad->bna_lock, flags);
  2061. bna_enet_mtu_set(&bnad->bna.enet, mtu, NULL);
  2062. bna_enet_pause_config(&bnad->bna.enet, &pause_config, NULL);
  2063. bna_enet_enable(&bnad->bna.enet);
  2064. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2065. /* Enable broadcast */
  2066. bnad_enable_default_bcast(bnad);
  2067. /* Restore VLANs, if any */
  2068. bnad_restore_vlans(bnad, 0);
  2069. /* Set the UCAST address */
  2070. spin_lock_irqsave(&bnad->bna_lock, flags);
  2071. bnad_mac_addr_set_locked(bnad, netdev->dev_addr);
  2072. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2073. /* Start the stats timer */
  2074. bnad_stats_timer_start(bnad);
  2075. mutex_unlock(&bnad->conf_mutex);
  2076. return 0;
  2077. cleanup_tx:
  2078. bnad_cleanup_tx(bnad, 0);
  2079. err_return:
  2080. mutex_unlock(&bnad->conf_mutex);
  2081. return err;
  2082. }
  2083. static int
  2084. bnad_stop(struct net_device *netdev)
  2085. {
  2086. struct bnad *bnad = netdev_priv(netdev);
  2087. unsigned long flags;
  2088. mutex_lock(&bnad->conf_mutex);
  2089. /* Stop the stats timer */
  2090. bnad_stats_timer_stop(bnad);
  2091. init_completion(&bnad->bnad_completions.enet_comp);
  2092. spin_lock_irqsave(&bnad->bna_lock, flags);
  2093. bna_enet_disable(&bnad->bna.enet, BNA_HARD_CLEANUP,
  2094. bnad_cb_enet_disabled);
  2095. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2096. wait_for_completion(&bnad->bnad_completions.enet_comp);
  2097. bnad_cleanup_tx(bnad, 0);
  2098. bnad_cleanup_rx(bnad, 0);
  2099. /* Synchronize mailbox IRQ */
  2100. bnad_mbox_irq_sync(bnad);
  2101. mutex_unlock(&bnad->conf_mutex);
  2102. return 0;
  2103. }
  2104. /* TX */
  2105. /*
  2106. * bnad_start_xmit : Netdev entry point for Transmit
  2107. * Called under lock held by net_device
  2108. */
  2109. static netdev_tx_t
  2110. bnad_start_xmit(struct sk_buff *skb, struct net_device *netdev)
  2111. {
  2112. struct bnad *bnad = netdev_priv(netdev);
  2113. u32 txq_id = 0;
  2114. struct bna_tcb *tcb = bnad->tx_info[0].tcb[txq_id];
  2115. u16 txq_prod, vlan_tag = 0;
  2116. u32 unmap_prod, wis, wis_used, wi_range;
  2117. u32 vectors, vect_id, i, acked;
  2118. int err;
  2119. struct bnad_unmap_q *unmap_q = tcb->unmap_q;
  2120. dma_addr_t dma_addr;
  2121. struct bna_txq_entry *txqent;
  2122. u16 flags;
  2123. if (unlikely
  2124. (skb->len <= ETH_HLEN || skb->len > BFI_TX_MAX_DATA_PER_PKT)) {
  2125. dev_kfree_skb(skb);
  2126. return NETDEV_TX_OK;
  2127. }
  2128. /*
  2129. * Takes care of the Tx that is scheduled between clearing the flag
  2130. * and the netif_stop_all_queue() call.
  2131. */
  2132. if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))) {
  2133. dev_kfree_skb(skb);
  2134. return NETDEV_TX_OK;
  2135. }
  2136. vectors = 1 + skb_shinfo(skb)->nr_frags;
  2137. if (vectors > BFI_TX_MAX_VECTORS_PER_PKT) {
  2138. dev_kfree_skb(skb);
  2139. return NETDEV_TX_OK;
  2140. }
  2141. wis = BNA_TXQ_WI_NEEDED(vectors); /* 4 vectors per work item */
  2142. acked = 0;
  2143. if (unlikely(wis > BNA_QE_FREE_CNT(tcb, tcb->q_depth) ||
  2144. vectors > BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth))) {
  2145. if ((u16) (*tcb->hw_consumer_index) !=
  2146. tcb->consumer_index &&
  2147. !test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags)) {
  2148. acked = bnad_free_txbufs(bnad, tcb);
  2149. if (likely(test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)))
  2150. bna_ib_ack(tcb->i_dbell, acked);
  2151. smp_mb__before_clear_bit();
  2152. clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags);
  2153. } else {
  2154. netif_stop_queue(netdev);
  2155. BNAD_UPDATE_CTR(bnad, netif_queue_stop);
  2156. }
  2157. smp_mb();
  2158. /*
  2159. * Check again to deal with race condition between
  2160. * netif_stop_queue here, and netif_wake_queue in
  2161. * interrupt handler which is not inside netif tx lock.
  2162. */
  2163. if (likely
  2164. (wis > BNA_QE_FREE_CNT(tcb, tcb->q_depth) ||
  2165. vectors > BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth))) {
  2166. BNAD_UPDATE_CTR(bnad, netif_queue_stop);
  2167. return NETDEV_TX_BUSY;
  2168. } else {
  2169. netif_wake_queue(netdev);
  2170. BNAD_UPDATE_CTR(bnad, netif_queue_wakeup);
  2171. }
  2172. }
  2173. unmap_prod = unmap_q->producer_index;
  2174. wis_used = 1;
  2175. vect_id = 0;
  2176. flags = 0;
  2177. txq_prod = tcb->producer_index;
  2178. BNA_TXQ_QPGE_PTR_GET(txq_prod, tcb->sw_qpt, txqent, wi_range);
  2179. BUG_ON(!(wi_range <= tcb->q_depth));
  2180. txqent->hdr.wi.reserved = 0;
  2181. txqent->hdr.wi.num_vectors = vectors;
  2182. txqent->hdr.wi.opcode =
  2183. htons((skb_is_gso(skb) ? BNA_TXQ_WI_SEND_LSO :
  2184. BNA_TXQ_WI_SEND));
  2185. if (vlan_tx_tag_present(skb)) {
  2186. vlan_tag = (u16) vlan_tx_tag_get(skb);
  2187. flags |= (BNA_TXQ_WI_CF_INS_PRIO | BNA_TXQ_WI_CF_INS_VLAN);
  2188. }
  2189. if (test_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags)) {
  2190. vlan_tag =
  2191. (tcb->priority & 0x7) << 13 | (vlan_tag & 0x1fff);
  2192. flags |= (BNA_TXQ_WI_CF_INS_PRIO | BNA_TXQ_WI_CF_INS_VLAN);
  2193. }
  2194. txqent->hdr.wi.vlan_tag = htons(vlan_tag);
  2195. if (skb_is_gso(skb)) {
  2196. err = bnad_tso_prepare(bnad, skb);
  2197. if (err) {
  2198. dev_kfree_skb(skb);
  2199. return NETDEV_TX_OK;
  2200. }
  2201. txqent->hdr.wi.lso_mss = htons(skb_is_gso(skb));
  2202. flags |= (BNA_TXQ_WI_CF_IP_CKSUM | BNA_TXQ_WI_CF_TCP_CKSUM);
  2203. txqent->hdr.wi.l4_hdr_size_n_offset =
  2204. htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
  2205. (tcp_hdrlen(skb) >> 2,
  2206. skb_transport_offset(skb)));
  2207. } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2208. u8 proto = 0;
  2209. txqent->hdr.wi.lso_mss = 0;
  2210. if (skb->protocol == htons(ETH_P_IP))
  2211. proto = ip_hdr(skb)->protocol;
  2212. else if (skb->protocol == htons(ETH_P_IPV6)) {
  2213. /* nexthdr may not be TCP immediately. */
  2214. proto = ipv6_hdr(skb)->nexthdr;
  2215. }
  2216. if (proto == IPPROTO_TCP) {
  2217. flags |= BNA_TXQ_WI_CF_TCP_CKSUM;
  2218. txqent->hdr.wi.l4_hdr_size_n_offset =
  2219. htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
  2220. (0, skb_transport_offset(skb)));
  2221. BNAD_UPDATE_CTR(bnad, tcpcsum_offload);
  2222. BUG_ON(!(skb_headlen(skb) >=
  2223. skb_transport_offset(skb) + tcp_hdrlen(skb)));
  2224. } else if (proto == IPPROTO_UDP) {
  2225. flags |= BNA_TXQ_WI_CF_UDP_CKSUM;
  2226. txqent->hdr.wi.l4_hdr_size_n_offset =
  2227. htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
  2228. (0, skb_transport_offset(skb)));
  2229. BNAD_UPDATE_CTR(bnad, udpcsum_offload);
  2230. BUG_ON(!(skb_headlen(skb) >=
  2231. skb_transport_offset(skb) +
  2232. sizeof(struct udphdr)));
  2233. } else {
  2234. err = skb_checksum_help(skb);
  2235. BNAD_UPDATE_CTR(bnad, csum_help);
  2236. if (err) {
  2237. dev_kfree_skb(skb);
  2238. BNAD_UPDATE_CTR(bnad, csum_help_err);
  2239. return NETDEV_TX_OK;
  2240. }
  2241. }
  2242. } else {
  2243. txqent->hdr.wi.lso_mss = 0;
  2244. txqent->hdr.wi.l4_hdr_size_n_offset = 0;
  2245. }
  2246. txqent->hdr.wi.flags = htons(flags);
  2247. txqent->hdr.wi.frame_length = htonl(skb->len);
  2248. unmap_q->unmap_array[unmap_prod].skb = skb;
  2249. BUG_ON(!(skb_headlen(skb) <= BFI_TX_MAX_DATA_PER_VECTOR));
  2250. txqent->vector[vect_id].length = htons(skb_headlen(skb));
  2251. dma_addr = dma_map_single(&bnad->pcidev->dev, skb->data,
  2252. skb_headlen(skb), DMA_TO_DEVICE);
  2253. dma_unmap_addr_set(&unmap_q->unmap_array[unmap_prod], dma_addr,
  2254. dma_addr);
  2255. BNA_SET_DMA_ADDR(dma_addr, &txqent->vector[vect_id].host_addr);
  2256. BNA_QE_INDX_ADD(unmap_prod, 1, unmap_q->q_depth);
  2257. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2258. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i];
  2259. u16 size = frag->size;
  2260. if (++vect_id == BFI_TX_MAX_VECTORS_PER_WI) {
  2261. vect_id = 0;
  2262. if (--wi_range)
  2263. txqent++;
  2264. else {
  2265. BNA_QE_INDX_ADD(txq_prod, wis_used,
  2266. tcb->q_depth);
  2267. wis_used = 0;
  2268. BNA_TXQ_QPGE_PTR_GET(txq_prod, tcb->sw_qpt,
  2269. txqent, wi_range);
  2270. BUG_ON(!(wi_range <= tcb->q_depth));
  2271. }
  2272. wis_used++;
  2273. txqent->hdr.wi_ext.opcode = htons(BNA_TXQ_WI_EXTENSION);
  2274. }
  2275. BUG_ON(!(size <= BFI_TX_MAX_DATA_PER_VECTOR));
  2276. txqent->vector[vect_id].length = htons(size);
  2277. dma_addr = dma_map_page(&bnad->pcidev->dev, frag->page,
  2278. frag->page_offset, size, DMA_TO_DEVICE);
  2279. dma_unmap_addr_set(&unmap_q->unmap_array[unmap_prod], dma_addr,
  2280. dma_addr);
  2281. BNA_SET_DMA_ADDR(dma_addr, &txqent->vector[vect_id].host_addr);
  2282. BNA_QE_INDX_ADD(unmap_prod, 1, unmap_q->q_depth);
  2283. }
  2284. unmap_q->producer_index = unmap_prod;
  2285. BNA_QE_INDX_ADD(txq_prod, wis_used, tcb->q_depth);
  2286. tcb->producer_index = txq_prod;
  2287. smp_mb();
  2288. if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)))
  2289. return NETDEV_TX_OK;
  2290. bna_txq_prod_indx_doorbell(tcb);
  2291. if ((u16) (*tcb->hw_consumer_index) != tcb->consumer_index)
  2292. tasklet_schedule(&bnad->tx_free_tasklet);
  2293. return NETDEV_TX_OK;
  2294. }
  2295. /*
  2296. * Used spin_lock to synchronize reading of stats structures, which
  2297. * is written by BNA under the same lock.
  2298. */
  2299. static struct rtnl_link_stats64 *
  2300. bnad_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
  2301. {
  2302. struct bnad *bnad = netdev_priv(netdev);
  2303. unsigned long flags;
  2304. spin_lock_irqsave(&bnad->bna_lock, flags);
  2305. bnad_netdev_qstats_fill(bnad, stats);
  2306. bnad_netdev_hwstats_fill(bnad, stats);
  2307. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2308. return stats;
  2309. }
  2310. static void
  2311. bnad_set_rx_mode(struct net_device *netdev)
  2312. {
  2313. struct bnad *bnad = netdev_priv(netdev);
  2314. u32 new_mask, valid_mask;
  2315. unsigned long flags;
  2316. spin_lock_irqsave(&bnad->bna_lock, flags);
  2317. new_mask = valid_mask = 0;
  2318. if (netdev->flags & IFF_PROMISC) {
  2319. if (!(bnad->cfg_flags & BNAD_CF_PROMISC)) {
  2320. new_mask = BNAD_RXMODE_PROMISC_DEFAULT;
  2321. valid_mask = BNAD_RXMODE_PROMISC_DEFAULT;
  2322. bnad->cfg_flags |= BNAD_CF_PROMISC;
  2323. }
  2324. } else {
  2325. if (bnad->cfg_flags & BNAD_CF_PROMISC) {
  2326. new_mask = ~BNAD_RXMODE_PROMISC_DEFAULT;
  2327. valid_mask = BNAD_RXMODE_PROMISC_DEFAULT;
  2328. bnad->cfg_flags &= ~BNAD_CF_PROMISC;
  2329. }
  2330. }
  2331. if (netdev->flags & IFF_ALLMULTI) {
  2332. if (!(bnad->cfg_flags & BNAD_CF_ALLMULTI)) {
  2333. new_mask |= BNA_RXMODE_ALLMULTI;
  2334. valid_mask |= BNA_RXMODE_ALLMULTI;
  2335. bnad->cfg_flags |= BNAD_CF_ALLMULTI;
  2336. }
  2337. } else {
  2338. if (bnad->cfg_flags & BNAD_CF_ALLMULTI) {
  2339. new_mask &= ~BNA_RXMODE_ALLMULTI;
  2340. valid_mask |= BNA_RXMODE_ALLMULTI;
  2341. bnad->cfg_flags &= ~BNAD_CF_ALLMULTI;
  2342. }
  2343. }
  2344. bna_rx_mode_set(bnad->rx_info[0].rx, new_mask, valid_mask, NULL);
  2345. if (!netdev_mc_empty(netdev)) {
  2346. u8 *mcaddr_list;
  2347. int mc_count = netdev_mc_count(netdev);
  2348. /* Index 0 holds the broadcast address */
  2349. mcaddr_list =
  2350. kzalloc((mc_count + 1) * ETH_ALEN,
  2351. GFP_ATOMIC);
  2352. if (!mcaddr_list)
  2353. goto unlock;
  2354. memcpy(&mcaddr_list[0], &bnad_bcast_addr[0], ETH_ALEN);
  2355. /* Copy rest of the MC addresses */
  2356. bnad_netdev_mc_list_get(netdev, mcaddr_list);
  2357. bna_rx_mcast_listset(bnad->rx_info[0].rx, mc_count + 1,
  2358. mcaddr_list, NULL);
  2359. /* Should we enable BNAD_CF_ALLMULTI for err != 0 ? */
  2360. kfree(mcaddr_list);
  2361. }
  2362. unlock:
  2363. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2364. }
  2365. /*
  2366. * bna_lock is used to sync writes to netdev->addr
  2367. * conf_lock cannot be used since this call may be made
  2368. * in a non-blocking context.
  2369. */
  2370. static int
  2371. bnad_set_mac_address(struct net_device *netdev, void *mac_addr)
  2372. {
  2373. int err;
  2374. struct bnad *bnad = netdev_priv(netdev);
  2375. struct sockaddr *sa = (struct sockaddr *)mac_addr;
  2376. unsigned long flags;
  2377. spin_lock_irqsave(&bnad->bna_lock, flags);
  2378. err = bnad_mac_addr_set_locked(bnad, sa->sa_data);
  2379. if (!err)
  2380. memcpy(netdev->dev_addr, sa->sa_data, netdev->addr_len);
  2381. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2382. return err;
  2383. }
  2384. static int
  2385. bnad_mtu_set(struct bnad *bnad, int mtu)
  2386. {
  2387. unsigned long flags;
  2388. init_completion(&bnad->bnad_completions.mtu_comp);
  2389. spin_lock_irqsave(&bnad->bna_lock, flags);
  2390. bna_enet_mtu_set(&bnad->bna.enet, mtu, bnad_cb_enet_mtu_set);
  2391. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2392. wait_for_completion(&bnad->bnad_completions.mtu_comp);
  2393. return bnad->bnad_completions.mtu_comp_status;
  2394. }
  2395. static int
  2396. bnad_change_mtu(struct net_device *netdev, int new_mtu)
  2397. {
  2398. int err, mtu = netdev->mtu;
  2399. struct bnad *bnad = netdev_priv(netdev);
  2400. if (new_mtu + ETH_HLEN < ETH_ZLEN || new_mtu > BNAD_JUMBO_MTU)
  2401. return -EINVAL;
  2402. mutex_lock(&bnad->conf_mutex);
  2403. netdev->mtu = new_mtu;
  2404. mtu = ETH_HLEN + VLAN_HLEN + new_mtu + ETH_FCS_LEN;
  2405. err = bnad_mtu_set(bnad, mtu);
  2406. if (err)
  2407. err = -EBUSY;
  2408. mutex_unlock(&bnad->conf_mutex);
  2409. return err;
  2410. }
  2411. static void
  2412. bnad_vlan_rx_add_vid(struct net_device *netdev,
  2413. unsigned short vid)
  2414. {
  2415. struct bnad *bnad = netdev_priv(netdev);
  2416. unsigned long flags;
  2417. if (!bnad->rx_info[0].rx)
  2418. return;
  2419. mutex_lock(&bnad->conf_mutex);
  2420. spin_lock_irqsave(&bnad->bna_lock, flags);
  2421. bna_rx_vlan_add(bnad->rx_info[0].rx, vid);
  2422. set_bit(vid, bnad->active_vlans);
  2423. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2424. mutex_unlock(&bnad->conf_mutex);
  2425. }
  2426. static void
  2427. bnad_vlan_rx_kill_vid(struct net_device *netdev,
  2428. unsigned short vid)
  2429. {
  2430. struct bnad *bnad = netdev_priv(netdev);
  2431. unsigned long flags;
  2432. if (!bnad->rx_info[0].rx)
  2433. return;
  2434. mutex_lock(&bnad->conf_mutex);
  2435. spin_lock_irqsave(&bnad->bna_lock, flags);
  2436. clear_bit(vid, bnad->active_vlans);
  2437. bna_rx_vlan_del(bnad->rx_info[0].rx, vid);
  2438. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2439. mutex_unlock(&bnad->conf_mutex);
  2440. }
  2441. #ifdef CONFIG_NET_POLL_CONTROLLER
  2442. static void
  2443. bnad_netpoll(struct net_device *netdev)
  2444. {
  2445. struct bnad *bnad = netdev_priv(netdev);
  2446. struct bnad_rx_info *rx_info;
  2447. struct bnad_rx_ctrl *rx_ctrl;
  2448. u32 curr_mask;
  2449. int i, j;
  2450. if (!(bnad->cfg_flags & BNAD_CF_MSIX)) {
  2451. bna_intx_disable(&bnad->bna, curr_mask);
  2452. bnad_isr(bnad->pcidev->irq, netdev);
  2453. bna_intx_enable(&bnad->bna, curr_mask);
  2454. } else {
  2455. for (i = 0; i < bnad->num_rx; i++) {
  2456. rx_info = &bnad->rx_info[i];
  2457. if (!rx_info->rx)
  2458. continue;
  2459. for (j = 0; j < bnad->num_rxp_per_rx; j++) {
  2460. rx_ctrl = &rx_info->rx_ctrl[j];
  2461. if (rx_ctrl->ccb) {
  2462. bnad_disable_rx_irq(bnad,
  2463. rx_ctrl->ccb);
  2464. bnad_netif_rx_schedule_poll(bnad,
  2465. rx_ctrl->ccb);
  2466. }
  2467. }
  2468. }
  2469. }
  2470. }
  2471. #endif
  2472. static const struct net_device_ops bnad_netdev_ops = {
  2473. .ndo_open = bnad_open,
  2474. .ndo_stop = bnad_stop,
  2475. .ndo_start_xmit = bnad_start_xmit,
  2476. .ndo_get_stats64 = bnad_get_stats64,
  2477. .ndo_set_rx_mode = bnad_set_rx_mode,
  2478. .ndo_validate_addr = eth_validate_addr,
  2479. .ndo_set_mac_address = bnad_set_mac_address,
  2480. .ndo_change_mtu = bnad_change_mtu,
  2481. .ndo_vlan_rx_add_vid = bnad_vlan_rx_add_vid,
  2482. .ndo_vlan_rx_kill_vid = bnad_vlan_rx_kill_vid,
  2483. #ifdef CONFIG_NET_POLL_CONTROLLER
  2484. .ndo_poll_controller = bnad_netpoll
  2485. #endif
  2486. };
  2487. static void
  2488. bnad_netdev_init(struct bnad *bnad, bool using_dac)
  2489. {
  2490. struct net_device *netdev = bnad->netdev;
  2491. netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM |
  2492. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  2493. NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_HW_VLAN_TX;
  2494. netdev->vlan_features = NETIF_F_SG | NETIF_F_HIGHDMA |
  2495. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  2496. NETIF_F_TSO | NETIF_F_TSO6;
  2497. netdev->features |= netdev->hw_features |
  2498. NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
  2499. if (using_dac)
  2500. netdev->features |= NETIF_F_HIGHDMA;
  2501. netdev->mem_start = bnad->mmio_start;
  2502. netdev->mem_end = bnad->mmio_start + bnad->mmio_len - 1;
  2503. netdev->netdev_ops = &bnad_netdev_ops;
  2504. bnad_set_ethtool_ops(netdev);
  2505. }
  2506. /*
  2507. * 1. Initialize the bnad structure
  2508. * 2. Setup netdev pointer in pci_dev
  2509. * 3. Initialze Tx free tasklet
  2510. * 4. Initialize no. of TxQ & CQs & MSIX vectors
  2511. */
  2512. static int
  2513. bnad_init(struct bnad *bnad,
  2514. struct pci_dev *pdev, struct net_device *netdev)
  2515. {
  2516. unsigned long flags;
  2517. SET_NETDEV_DEV(netdev, &pdev->dev);
  2518. pci_set_drvdata(pdev, netdev);
  2519. bnad->netdev = netdev;
  2520. bnad->pcidev = pdev;
  2521. bnad->mmio_start = pci_resource_start(pdev, 0);
  2522. bnad->mmio_len = pci_resource_len(pdev, 0);
  2523. bnad->bar0 = ioremap_nocache(bnad->mmio_start, bnad->mmio_len);
  2524. if (!bnad->bar0) {
  2525. dev_err(&pdev->dev, "ioremap for bar0 failed\n");
  2526. pci_set_drvdata(pdev, NULL);
  2527. return -ENOMEM;
  2528. }
  2529. pr_info("bar0 mapped to %p, len %llu\n", bnad->bar0,
  2530. (unsigned long long) bnad->mmio_len);
  2531. spin_lock_irqsave(&bnad->bna_lock, flags);
  2532. if (!bnad_msix_disable)
  2533. bnad->cfg_flags = BNAD_CF_MSIX;
  2534. bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
  2535. bnad_q_num_init(bnad);
  2536. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2537. bnad->msix_num = (bnad->num_tx * bnad->num_txq_per_tx) +
  2538. (bnad->num_rx * bnad->num_rxp_per_rx) +
  2539. BNAD_MAILBOX_MSIX_VECTORS;
  2540. bnad->txq_depth = BNAD_TXQ_DEPTH;
  2541. bnad->rxq_depth = BNAD_RXQ_DEPTH;
  2542. bnad->tx_coalescing_timeo = BFI_TX_COALESCING_TIMEO;
  2543. bnad->rx_coalescing_timeo = BFI_RX_COALESCING_TIMEO;
  2544. tasklet_init(&bnad->tx_free_tasklet, bnad_tx_free_tasklet,
  2545. (unsigned long)bnad);
  2546. return 0;
  2547. }
  2548. /*
  2549. * Must be called after bnad_pci_uninit()
  2550. * so that iounmap() and pci_set_drvdata(NULL)
  2551. * happens only after PCI uninitialization.
  2552. */
  2553. static void
  2554. bnad_uninit(struct bnad *bnad)
  2555. {
  2556. if (bnad->bar0)
  2557. iounmap(bnad->bar0);
  2558. pci_set_drvdata(bnad->pcidev, NULL);
  2559. }
  2560. /*
  2561. * Initialize locks
  2562. a) Per ioceth mutes used for serializing configuration
  2563. changes from OS interface
  2564. b) spin lock used to protect bna state machine
  2565. */
  2566. static void
  2567. bnad_lock_init(struct bnad *bnad)
  2568. {
  2569. spin_lock_init(&bnad->bna_lock);
  2570. mutex_init(&bnad->conf_mutex);
  2571. }
  2572. static void
  2573. bnad_lock_uninit(struct bnad *bnad)
  2574. {
  2575. mutex_destroy(&bnad->conf_mutex);
  2576. }
  2577. /* PCI Initialization */
  2578. static int
  2579. bnad_pci_init(struct bnad *bnad,
  2580. struct pci_dev *pdev, bool *using_dac)
  2581. {
  2582. int err;
  2583. err = pci_enable_device(pdev);
  2584. if (err)
  2585. return err;
  2586. err = pci_request_regions(pdev, BNAD_NAME);
  2587. if (err)
  2588. goto disable_device;
  2589. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
  2590. !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  2591. *using_dac = 1;
  2592. } else {
  2593. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  2594. if (err) {
  2595. err = dma_set_coherent_mask(&pdev->dev,
  2596. DMA_BIT_MASK(32));
  2597. if (err)
  2598. goto release_regions;
  2599. }
  2600. *using_dac = 0;
  2601. }
  2602. pci_set_master(pdev);
  2603. return 0;
  2604. release_regions:
  2605. pci_release_regions(pdev);
  2606. disable_device:
  2607. pci_disable_device(pdev);
  2608. return err;
  2609. }
  2610. static void
  2611. bnad_pci_uninit(struct pci_dev *pdev)
  2612. {
  2613. pci_release_regions(pdev);
  2614. pci_disable_device(pdev);
  2615. }
  2616. static int __devinit
  2617. bnad_pci_probe(struct pci_dev *pdev,
  2618. const struct pci_device_id *pcidev_id)
  2619. {
  2620. bool using_dac = false;
  2621. int err;
  2622. struct bnad *bnad;
  2623. struct bna *bna;
  2624. struct net_device *netdev;
  2625. struct bfa_pcidev pcidev_info;
  2626. unsigned long flags;
  2627. pr_info("bnad_pci_probe : (0x%p, 0x%p) PCI Func : (%d)\n",
  2628. pdev, pcidev_id, PCI_FUNC(pdev->devfn));
  2629. mutex_lock(&bnad_fwimg_mutex);
  2630. if (!cna_get_firmware_buf(pdev)) {
  2631. mutex_unlock(&bnad_fwimg_mutex);
  2632. pr_warn("Failed to load Firmware Image!\n");
  2633. return -ENODEV;
  2634. }
  2635. mutex_unlock(&bnad_fwimg_mutex);
  2636. /*
  2637. * Allocates sizeof(struct net_device + struct bnad)
  2638. * bnad = netdev->priv
  2639. */
  2640. netdev = alloc_etherdev(sizeof(struct bnad));
  2641. if (!netdev) {
  2642. dev_err(&pdev->dev, "netdev allocation failed\n");
  2643. err = -ENOMEM;
  2644. return err;
  2645. }
  2646. bnad = netdev_priv(netdev);
  2647. bnad_lock_init(bnad);
  2648. mutex_lock(&bnad->conf_mutex);
  2649. /*
  2650. * PCI initialization
  2651. * Output : using_dac = 1 for 64 bit DMA
  2652. * = 0 for 32 bit DMA
  2653. */
  2654. err = bnad_pci_init(bnad, pdev, &using_dac);
  2655. if (err)
  2656. goto unlock_mutex;
  2657. /*
  2658. * Initialize bnad structure
  2659. * Setup relation between pci_dev & netdev
  2660. * Init Tx free tasklet
  2661. */
  2662. err = bnad_init(bnad, pdev, netdev);
  2663. if (err)
  2664. goto pci_uninit;
  2665. /* Initialize netdev structure, set up ethtool ops */
  2666. bnad_netdev_init(bnad, using_dac);
  2667. /* Set link to down state */
  2668. netif_carrier_off(netdev);
  2669. /* Get resource requirement form bna */
  2670. spin_lock_irqsave(&bnad->bna_lock, flags);
  2671. bna_res_req(&bnad->res_info[0]);
  2672. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2673. /* Allocate resources from bna */
  2674. err = bnad_res_alloc(bnad, &bnad->res_info[0], BNA_RES_T_MAX);
  2675. if (err)
  2676. goto drv_uninit;
  2677. bna = &bnad->bna;
  2678. /* Setup pcidev_info for bna_init() */
  2679. pcidev_info.pci_slot = PCI_SLOT(bnad->pcidev->devfn);
  2680. pcidev_info.pci_func = PCI_FUNC(bnad->pcidev->devfn);
  2681. pcidev_info.device_id = bnad->pcidev->device;
  2682. pcidev_info.pci_bar_kva = bnad->bar0;
  2683. spin_lock_irqsave(&bnad->bna_lock, flags);
  2684. bna_init(bna, bnad, &pcidev_info, &bnad->res_info[0]);
  2685. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2686. bnad->stats.bna_stats = &bna->stats;
  2687. bnad_enable_msix(bnad);
  2688. err = bnad_mbox_irq_alloc(bnad);
  2689. if (err)
  2690. goto res_free;
  2691. /* Set up timers */
  2692. setup_timer(&bnad->bna.ioceth.ioc.ioc_timer, bnad_ioc_timeout,
  2693. ((unsigned long)bnad));
  2694. setup_timer(&bnad->bna.ioceth.ioc.hb_timer, bnad_ioc_hb_check,
  2695. ((unsigned long)bnad));
  2696. setup_timer(&bnad->bna.ioceth.ioc.iocpf_timer, bnad_iocpf_timeout,
  2697. ((unsigned long)bnad));
  2698. setup_timer(&bnad->bna.ioceth.ioc.sem_timer, bnad_iocpf_sem_timeout,
  2699. ((unsigned long)bnad));
  2700. /* Now start the timer before calling IOC */
  2701. mod_timer(&bnad->bna.ioceth.ioc.iocpf_timer,
  2702. jiffies + msecs_to_jiffies(BNA_IOC_TIMER_FREQ));
  2703. /*
  2704. * Start the chip
  2705. * If the call back comes with error, we bail out.
  2706. * This is a catastrophic error.
  2707. */
  2708. err = bnad_ioceth_enable(bnad);
  2709. if (err) {
  2710. pr_err("BNA: Initialization failed err=%d\n",
  2711. err);
  2712. goto probe_success;
  2713. }
  2714. spin_lock_irqsave(&bnad->bna_lock, flags);
  2715. if (bna_num_txq_set(bna, BNAD_NUM_TXQ + 1) ||
  2716. bna_num_rxp_set(bna, BNAD_NUM_RXP + 1)) {
  2717. bnad_q_num_adjust(bnad, bna_attr(bna)->num_txq - 1,
  2718. bna_attr(bna)->num_rxp - 1);
  2719. if (bna_num_txq_set(bna, BNAD_NUM_TXQ + 1) ||
  2720. bna_num_rxp_set(bna, BNAD_NUM_RXP + 1))
  2721. err = -EIO;
  2722. }
  2723. bna_mod_res_req(&bnad->bna, &bnad->mod_res_info[0]);
  2724. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2725. err = bnad_res_alloc(bnad, &bnad->mod_res_info[0], BNA_MOD_RES_T_MAX);
  2726. if (err) {
  2727. err = -EIO;
  2728. goto disable_ioceth;
  2729. }
  2730. spin_lock_irqsave(&bnad->bna_lock, flags);
  2731. bna_mod_init(&bnad->bna, &bnad->mod_res_info[0]);
  2732. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2733. /* Get the burnt-in mac */
  2734. spin_lock_irqsave(&bnad->bna_lock, flags);
  2735. bna_enet_perm_mac_get(&bna->enet, &bnad->perm_addr);
  2736. bnad_set_netdev_perm_addr(bnad);
  2737. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2738. mutex_unlock(&bnad->conf_mutex);
  2739. /* Finally, reguister with net_device layer */
  2740. err = register_netdev(netdev);
  2741. if (err) {
  2742. pr_err("BNA : Registering with netdev failed\n");
  2743. goto probe_uninit;
  2744. }
  2745. set_bit(BNAD_RF_NETDEV_REGISTERED, &bnad->run_flags);
  2746. return 0;
  2747. probe_success:
  2748. mutex_unlock(&bnad->conf_mutex);
  2749. return 0;
  2750. probe_uninit:
  2751. bnad_res_free(bnad, &bnad->mod_res_info[0], BNA_MOD_RES_T_MAX);
  2752. disable_ioceth:
  2753. bnad_ioceth_disable(bnad);
  2754. del_timer_sync(&bnad->bna.ioceth.ioc.ioc_timer);
  2755. del_timer_sync(&bnad->bna.ioceth.ioc.sem_timer);
  2756. del_timer_sync(&bnad->bna.ioceth.ioc.hb_timer);
  2757. spin_lock_irqsave(&bnad->bna_lock, flags);
  2758. bna_uninit(bna);
  2759. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2760. bnad_mbox_irq_free(bnad);
  2761. bnad_disable_msix(bnad);
  2762. res_free:
  2763. bnad_res_free(bnad, &bnad->res_info[0], BNA_RES_T_MAX);
  2764. drv_uninit:
  2765. bnad_uninit(bnad);
  2766. pci_uninit:
  2767. bnad_pci_uninit(pdev);
  2768. unlock_mutex:
  2769. mutex_unlock(&bnad->conf_mutex);
  2770. bnad_lock_uninit(bnad);
  2771. free_netdev(netdev);
  2772. return err;
  2773. }
  2774. static void __devexit
  2775. bnad_pci_remove(struct pci_dev *pdev)
  2776. {
  2777. struct net_device *netdev = pci_get_drvdata(pdev);
  2778. struct bnad *bnad;
  2779. struct bna *bna;
  2780. unsigned long flags;
  2781. if (!netdev)
  2782. return;
  2783. pr_info("%s bnad_pci_remove\n", netdev->name);
  2784. bnad = netdev_priv(netdev);
  2785. bna = &bnad->bna;
  2786. if (test_and_clear_bit(BNAD_RF_NETDEV_REGISTERED, &bnad->run_flags))
  2787. unregister_netdev(netdev);
  2788. mutex_lock(&bnad->conf_mutex);
  2789. bnad_ioceth_disable(bnad);
  2790. del_timer_sync(&bnad->bna.ioceth.ioc.ioc_timer);
  2791. del_timer_sync(&bnad->bna.ioceth.ioc.sem_timer);
  2792. del_timer_sync(&bnad->bna.ioceth.ioc.hb_timer);
  2793. spin_lock_irqsave(&bnad->bna_lock, flags);
  2794. bna_uninit(bna);
  2795. spin_unlock_irqrestore(&bnad->bna_lock, flags);
  2796. bnad_res_free(bnad, &bnad->mod_res_info[0], BNA_MOD_RES_T_MAX);
  2797. bnad_res_free(bnad, &bnad->res_info[0], BNA_RES_T_MAX);
  2798. bnad_mbox_irq_free(bnad);
  2799. bnad_disable_msix(bnad);
  2800. bnad_pci_uninit(pdev);
  2801. mutex_unlock(&bnad->conf_mutex);
  2802. bnad_lock_uninit(bnad);
  2803. bnad_uninit(bnad);
  2804. free_netdev(netdev);
  2805. }
  2806. static DEFINE_PCI_DEVICE_TABLE(bnad_pci_id_table) = {
  2807. {
  2808. PCI_DEVICE(PCI_VENDOR_ID_BROCADE,
  2809. PCI_DEVICE_ID_BROCADE_CT),
  2810. .class = PCI_CLASS_NETWORK_ETHERNET << 8,
  2811. .class_mask = 0xffff00
  2812. }, {0, }
  2813. };
  2814. MODULE_DEVICE_TABLE(pci, bnad_pci_id_table);
  2815. static struct pci_driver bnad_pci_driver = {
  2816. .name = BNAD_NAME,
  2817. .id_table = bnad_pci_id_table,
  2818. .probe = bnad_pci_probe,
  2819. .remove = __devexit_p(bnad_pci_remove),
  2820. };
  2821. static int __init
  2822. bnad_module_init(void)
  2823. {
  2824. int err;
  2825. pr_info("Brocade 10G Ethernet driver - version: %s\n",
  2826. BNAD_VERSION);
  2827. bfa_nw_ioc_auto_recover(bnad_ioc_auto_recover);
  2828. err = pci_register_driver(&bnad_pci_driver);
  2829. if (err < 0) {
  2830. pr_err("bna : PCI registration failed in module init "
  2831. "(%d)\n", err);
  2832. return err;
  2833. }
  2834. return 0;
  2835. }
  2836. static void __exit
  2837. bnad_module_exit(void)
  2838. {
  2839. pci_unregister_driver(&bnad_pci_driver);
  2840. if (bfi_fw)
  2841. release_firmware(bfi_fw);
  2842. }
  2843. module_init(bnad_module_init);
  2844. module_exit(bnad_module_exit);
  2845. MODULE_AUTHOR("Brocade");
  2846. MODULE_LICENSE("GPL");
  2847. MODULE_DESCRIPTION("Brocade 10G PCIe Ethernet driver");
  2848. MODULE_VERSION(BNAD_VERSION);
  2849. MODULE_FIRMWARE(CNA_FW_FILE_CT);