bnad.c 84 KB

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