bnad.c 84 KB

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