bnad.c 84 KB

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