netdev.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976
  1. /*******************************************************************************
  2. Intel(R) 82576 Virtual Function Linux driver
  3. Copyright(c) 2009 - 2012 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, see <http://www.gnu.org/licenses/>.
  13. The full GNU General Public License is included in this distribution in
  14. the file called "COPYING".
  15. Contact Information:
  16. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. *******************************************************************************/
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <linux/init.h>
  23. #include <linux/pci.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/pagemap.h>
  26. #include <linux/delay.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/tcp.h>
  29. #include <linux/ipv6.h>
  30. #include <linux/slab.h>
  31. #include <net/checksum.h>
  32. #include <net/ip6_checksum.h>
  33. #include <linux/mii.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if_vlan.h>
  36. #include <linux/prefetch.h>
  37. #include <linux/sctp.h>
  38. #include "igbvf.h"
  39. #define DRV_VERSION "2.4.0-k"
  40. char igbvf_driver_name[] = "igbvf";
  41. const char igbvf_driver_version[] = DRV_VERSION;
  42. static const char igbvf_driver_string[] =
  43. "Intel(R) Gigabit Virtual Function Network Driver";
  44. static const char igbvf_copyright[] =
  45. "Copyright (c) 2009 - 2012 Intel Corporation.";
  46. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  47. static int debug = -1;
  48. module_param(debug, int, 0);
  49. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  50. static int igbvf_poll(struct napi_struct *napi, int budget);
  51. static void igbvf_reset(struct igbvf_adapter *);
  52. static void igbvf_set_interrupt_capability(struct igbvf_adapter *);
  53. static void igbvf_reset_interrupt_capability(struct igbvf_adapter *);
  54. static struct igbvf_info igbvf_vf_info = {
  55. .mac = e1000_vfadapt,
  56. .flags = 0,
  57. .pba = 10,
  58. .init_ops = e1000_init_function_pointers_vf,
  59. };
  60. static struct igbvf_info igbvf_i350_vf_info = {
  61. .mac = e1000_vfadapt_i350,
  62. .flags = 0,
  63. .pba = 10,
  64. .init_ops = e1000_init_function_pointers_vf,
  65. };
  66. static const struct igbvf_info *igbvf_info_tbl[] = {
  67. [board_vf] = &igbvf_vf_info,
  68. [board_i350_vf] = &igbvf_i350_vf_info,
  69. };
  70. /**
  71. * igbvf_desc_unused - calculate if we have unused descriptors
  72. * @rx_ring: address of receive ring structure
  73. **/
  74. static int igbvf_desc_unused(struct igbvf_ring *ring)
  75. {
  76. if (ring->next_to_clean > ring->next_to_use)
  77. return ring->next_to_clean - ring->next_to_use - 1;
  78. return ring->count + ring->next_to_clean - ring->next_to_use - 1;
  79. }
  80. /**
  81. * igbvf_receive_skb - helper function to handle Rx indications
  82. * @adapter: board private structure
  83. * @status: descriptor status field as written by hardware
  84. * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
  85. * @skb: pointer to sk_buff to be indicated to stack
  86. **/
  87. static void igbvf_receive_skb(struct igbvf_adapter *adapter,
  88. struct net_device *netdev,
  89. struct sk_buff *skb,
  90. u32 status, u16 vlan)
  91. {
  92. u16 vid;
  93. if (status & E1000_RXD_STAT_VP) {
  94. if ((adapter->flags & IGBVF_FLAG_RX_LB_VLAN_BSWAP) &&
  95. (status & E1000_RXDEXT_STATERR_LB))
  96. vid = be16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
  97. else
  98. vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
  99. if (test_bit(vid, adapter->active_vlans))
  100. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  101. }
  102. napi_gro_receive(&adapter->rx_ring->napi, skb);
  103. }
  104. static inline void igbvf_rx_checksum_adv(struct igbvf_adapter *adapter,
  105. u32 status_err, struct sk_buff *skb)
  106. {
  107. skb_checksum_none_assert(skb);
  108. /* Ignore Checksum bit is set or checksum is disabled through ethtool */
  109. if ((status_err & E1000_RXD_STAT_IXSM) ||
  110. (adapter->flags & IGBVF_FLAG_RX_CSUM_DISABLED))
  111. return;
  112. /* TCP/UDP checksum error bit is set */
  113. if (status_err &
  114. (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
  115. /* let the stack verify checksum errors */
  116. adapter->hw_csum_err++;
  117. return;
  118. }
  119. /* It must be a TCP or UDP packet with a valid checksum */
  120. if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
  121. skb->ip_summed = CHECKSUM_UNNECESSARY;
  122. adapter->hw_csum_good++;
  123. }
  124. /**
  125. * igbvf_alloc_rx_buffers - Replace used receive buffers; packet split
  126. * @rx_ring: address of ring structure to repopulate
  127. * @cleaned_count: number of buffers to repopulate
  128. **/
  129. static void igbvf_alloc_rx_buffers(struct igbvf_ring *rx_ring,
  130. int cleaned_count)
  131. {
  132. struct igbvf_adapter *adapter = rx_ring->adapter;
  133. struct net_device *netdev = adapter->netdev;
  134. struct pci_dev *pdev = adapter->pdev;
  135. union e1000_adv_rx_desc *rx_desc;
  136. struct igbvf_buffer *buffer_info;
  137. struct sk_buff *skb;
  138. unsigned int i;
  139. int bufsz;
  140. i = rx_ring->next_to_use;
  141. buffer_info = &rx_ring->buffer_info[i];
  142. if (adapter->rx_ps_hdr_size)
  143. bufsz = adapter->rx_ps_hdr_size;
  144. else
  145. bufsz = adapter->rx_buffer_len;
  146. while (cleaned_count--) {
  147. rx_desc = IGBVF_RX_DESC_ADV(*rx_ring, i);
  148. if (adapter->rx_ps_hdr_size && !buffer_info->page_dma) {
  149. if (!buffer_info->page) {
  150. buffer_info->page = alloc_page(GFP_ATOMIC);
  151. if (!buffer_info->page) {
  152. adapter->alloc_rx_buff_failed++;
  153. goto no_buffers;
  154. }
  155. buffer_info->page_offset = 0;
  156. } else {
  157. buffer_info->page_offset ^= PAGE_SIZE / 2;
  158. }
  159. buffer_info->page_dma =
  160. dma_map_page(&pdev->dev, buffer_info->page,
  161. buffer_info->page_offset,
  162. PAGE_SIZE / 2,
  163. DMA_FROM_DEVICE);
  164. if (dma_mapping_error(&pdev->dev,
  165. buffer_info->page_dma)) {
  166. __free_page(buffer_info->page);
  167. buffer_info->page = NULL;
  168. dev_err(&pdev->dev, "RX DMA map failed\n");
  169. break;
  170. }
  171. }
  172. if (!buffer_info->skb) {
  173. skb = netdev_alloc_skb_ip_align(netdev, bufsz);
  174. if (!skb) {
  175. adapter->alloc_rx_buff_failed++;
  176. goto no_buffers;
  177. }
  178. buffer_info->skb = skb;
  179. buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
  180. bufsz,
  181. DMA_FROM_DEVICE);
  182. if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
  183. dev_kfree_skb(buffer_info->skb);
  184. buffer_info->skb = NULL;
  185. dev_err(&pdev->dev, "RX DMA map failed\n");
  186. goto no_buffers;
  187. }
  188. }
  189. /* Refresh the desc even if buffer_addrs didn't change because
  190. * each write-back erases this info.
  191. */
  192. if (adapter->rx_ps_hdr_size) {
  193. rx_desc->read.pkt_addr =
  194. cpu_to_le64(buffer_info->page_dma);
  195. rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
  196. } else {
  197. rx_desc->read.pkt_addr = cpu_to_le64(buffer_info->dma);
  198. rx_desc->read.hdr_addr = 0;
  199. }
  200. i++;
  201. if (i == rx_ring->count)
  202. i = 0;
  203. buffer_info = &rx_ring->buffer_info[i];
  204. }
  205. no_buffers:
  206. if (rx_ring->next_to_use != i) {
  207. rx_ring->next_to_use = i;
  208. if (i == 0)
  209. i = (rx_ring->count - 1);
  210. else
  211. i--;
  212. /* Force memory writes to complete before letting h/w
  213. * know there are new descriptors to fetch. (Only
  214. * applicable for weak-ordered memory model archs,
  215. * such as IA-64).
  216. */
  217. wmb();
  218. writel(i, adapter->hw.hw_addr + rx_ring->tail);
  219. }
  220. }
  221. /**
  222. * igbvf_clean_rx_irq - Send received data up the network stack; legacy
  223. * @adapter: board private structure
  224. *
  225. * the return value indicates whether actual cleaning was done, there
  226. * is no guarantee that everything was cleaned
  227. **/
  228. static bool igbvf_clean_rx_irq(struct igbvf_adapter *adapter,
  229. int *work_done, int work_to_do)
  230. {
  231. struct igbvf_ring *rx_ring = adapter->rx_ring;
  232. struct net_device *netdev = adapter->netdev;
  233. struct pci_dev *pdev = adapter->pdev;
  234. union e1000_adv_rx_desc *rx_desc, *next_rxd;
  235. struct igbvf_buffer *buffer_info, *next_buffer;
  236. struct sk_buff *skb;
  237. bool cleaned = false;
  238. int cleaned_count = 0;
  239. unsigned int total_bytes = 0, total_packets = 0;
  240. unsigned int i;
  241. u32 length, hlen, staterr;
  242. i = rx_ring->next_to_clean;
  243. rx_desc = IGBVF_RX_DESC_ADV(*rx_ring, i);
  244. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  245. while (staterr & E1000_RXD_STAT_DD) {
  246. if (*work_done >= work_to_do)
  247. break;
  248. (*work_done)++;
  249. rmb(); /* read descriptor and rx_buffer_info after status DD */
  250. buffer_info = &rx_ring->buffer_info[i];
  251. /* HW will not DMA in data larger than the given buffer, even
  252. * if it parses the (NFS, of course) header to be larger. In
  253. * that case, it fills the header buffer and spills the rest
  254. * into the page.
  255. */
  256. hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info)
  257. & E1000_RXDADV_HDRBUFLEN_MASK) >>
  258. E1000_RXDADV_HDRBUFLEN_SHIFT;
  259. if (hlen > adapter->rx_ps_hdr_size)
  260. hlen = adapter->rx_ps_hdr_size;
  261. length = le16_to_cpu(rx_desc->wb.upper.length);
  262. cleaned = true;
  263. cleaned_count++;
  264. skb = buffer_info->skb;
  265. prefetch(skb->data - NET_IP_ALIGN);
  266. buffer_info->skb = NULL;
  267. if (!adapter->rx_ps_hdr_size) {
  268. dma_unmap_single(&pdev->dev, buffer_info->dma,
  269. adapter->rx_buffer_len,
  270. DMA_FROM_DEVICE);
  271. buffer_info->dma = 0;
  272. skb_put(skb, length);
  273. goto send_up;
  274. }
  275. if (!skb_shinfo(skb)->nr_frags) {
  276. dma_unmap_single(&pdev->dev, buffer_info->dma,
  277. adapter->rx_ps_hdr_size,
  278. DMA_FROM_DEVICE);
  279. buffer_info->dma = 0;
  280. skb_put(skb, hlen);
  281. }
  282. if (length) {
  283. dma_unmap_page(&pdev->dev, buffer_info->page_dma,
  284. PAGE_SIZE / 2,
  285. DMA_FROM_DEVICE);
  286. buffer_info->page_dma = 0;
  287. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  288. buffer_info->page,
  289. buffer_info->page_offset,
  290. length);
  291. if ((adapter->rx_buffer_len > (PAGE_SIZE / 2)) ||
  292. (page_count(buffer_info->page) != 1))
  293. buffer_info->page = NULL;
  294. else
  295. get_page(buffer_info->page);
  296. skb->len += length;
  297. skb->data_len += length;
  298. skb->truesize += PAGE_SIZE / 2;
  299. }
  300. send_up:
  301. i++;
  302. if (i == rx_ring->count)
  303. i = 0;
  304. next_rxd = IGBVF_RX_DESC_ADV(*rx_ring, i);
  305. prefetch(next_rxd);
  306. next_buffer = &rx_ring->buffer_info[i];
  307. if (!(staterr & E1000_RXD_STAT_EOP)) {
  308. buffer_info->skb = next_buffer->skb;
  309. buffer_info->dma = next_buffer->dma;
  310. next_buffer->skb = skb;
  311. next_buffer->dma = 0;
  312. goto next_desc;
  313. }
  314. if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
  315. dev_kfree_skb_irq(skb);
  316. goto next_desc;
  317. }
  318. total_bytes += skb->len;
  319. total_packets++;
  320. igbvf_rx_checksum_adv(adapter, staterr, skb);
  321. skb->protocol = eth_type_trans(skb, netdev);
  322. igbvf_receive_skb(adapter, netdev, skb, staterr,
  323. rx_desc->wb.upper.vlan);
  324. next_desc:
  325. rx_desc->wb.upper.status_error = 0;
  326. /* return some buffers to hardware, one at a time is too slow */
  327. if (cleaned_count >= IGBVF_RX_BUFFER_WRITE) {
  328. igbvf_alloc_rx_buffers(rx_ring, cleaned_count);
  329. cleaned_count = 0;
  330. }
  331. /* use prefetched values */
  332. rx_desc = next_rxd;
  333. buffer_info = next_buffer;
  334. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  335. }
  336. rx_ring->next_to_clean = i;
  337. cleaned_count = igbvf_desc_unused(rx_ring);
  338. if (cleaned_count)
  339. igbvf_alloc_rx_buffers(rx_ring, cleaned_count);
  340. adapter->total_rx_packets += total_packets;
  341. adapter->total_rx_bytes += total_bytes;
  342. adapter->net_stats.rx_bytes += total_bytes;
  343. adapter->net_stats.rx_packets += total_packets;
  344. return cleaned;
  345. }
  346. static void igbvf_put_txbuf(struct igbvf_adapter *adapter,
  347. struct igbvf_buffer *buffer_info)
  348. {
  349. if (buffer_info->dma) {
  350. if (buffer_info->mapped_as_page)
  351. dma_unmap_page(&adapter->pdev->dev,
  352. buffer_info->dma,
  353. buffer_info->length,
  354. DMA_TO_DEVICE);
  355. else
  356. dma_unmap_single(&adapter->pdev->dev,
  357. buffer_info->dma,
  358. buffer_info->length,
  359. DMA_TO_DEVICE);
  360. buffer_info->dma = 0;
  361. }
  362. if (buffer_info->skb) {
  363. dev_kfree_skb_any(buffer_info->skb);
  364. buffer_info->skb = NULL;
  365. }
  366. buffer_info->time_stamp = 0;
  367. }
  368. /**
  369. * igbvf_setup_tx_resources - allocate Tx resources (Descriptors)
  370. * @adapter: board private structure
  371. *
  372. * Return 0 on success, negative on failure
  373. **/
  374. int igbvf_setup_tx_resources(struct igbvf_adapter *adapter,
  375. struct igbvf_ring *tx_ring)
  376. {
  377. struct pci_dev *pdev = adapter->pdev;
  378. int size;
  379. size = sizeof(struct igbvf_buffer) * tx_ring->count;
  380. tx_ring->buffer_info = vzalloc(size);
  381. if (!tx_ring->buffer_info)
  382. goto err;
  383. /* round up to nearest 4K */
  384. tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
  385. tx_ring->size = ALIGN(tx_ring->size, 4096);
  386. tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
  387. &tx_ring->dma, GFP_KERNEL);
  388. if (!tx_ring->desc)
  389. goto err;
  390. tx_ring->adapter = adapter;
  391. tx_ring->next_to_use = 0;
  392. tx_ring->next_to_clean = 0;
  393. return 0;
  394. err:
  395. vfree(tx_ring->buffer_info);
  396. dev_err(&adapter->pdev->dev,
  397. "Unable to allocate memory for the transmit descriptor ring\n");
  398. return -ENOMEM;
  399. }
  400. /**
  401. * igbvf_setup_rx_resources - allocate Rx resources (Descriptors)
  402. * @adapter: board private structure
  403. *
  404. * Returns 0 on success, negative on failure
  405. **/
  406. int igbvf_setup_rx_resources(struct igbvf_adapter *adapter,
  407. struct igbvf_ring *rx_ring)
  408. {
  409. struct pci_dev *pdev = adapter->pdev;
  410. int size, desc_len;
  411. size = sizeof(struct igbvf_buffer) * rx_ring->count;
  412. rx_ring->buffer_info = vzalloc(size);
  413. if (!rx_ring->buffer_info)
  414. goto err;
  415. desc_len = sizeof(union e1000_adv_rx_desc);
  416. /* Round up to nearest 4K */
  417. rx_ring->size = rx_ring->count * desc_len;
  418. rx_ring->size = ALIGN(rx_ring->size, 4096);
  419. rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
  420. &rx_ring->dma, GFP_KERNEL);
  421. if (!rx_ring->desc)
  422. goto err;
  423. rx_ring->next_to_clean = 0;
  424. rx_ring->next_to_use = 0;
  425. rx_ring->adapter = adapter;
  426. return 0;
  427. err:
  428. vfree(rx_ring->buffer_info);
  429. rx_ring->buffer_info = NULL;
  430. dev_err(&adapter->pdev->dev,
  431. "Unable to allocate memory for the receive descriptor ring\n");
  432. return -ENOMEM;
  433. }
  434. /**
  435. * igbvf_clean_tx_ring - Free Tx Buffers
  436. * @tx_ring: ring to be cleaned
  437. **/
  438. static void igbvf_clean_tx_ring(struct igbvf_ring *tx_ring)
  439. {
  440. struct igbvf_adapter *adapter = tx_ring->adapter;
  441. struct igbvf_buffer *buffer_info;
  442. unsigned long size;
  443. unsigned int i;
  444. if (!tx_ring->buffer_info)
  445. return;
  446. /* Free all the Tx ring sk_buffs */
  447. for (i = 0; i < tx_ring->count; i++) {
  448. buffer_info = &tx_ring->buffer_info[i];
  449. igbvf_put_txbuf(adapter, buffer_info);
  450. }
  451. size = sizeof(struct igbvf_buffer) * tx_ring->count;
  452. memset(tx_ring->buffer_info, 0, size);
  453. /* Zero out the descriptor ring */
  454. memset(tx_ring->desc, 0, tx_ring->size);
  455. tx_ring->next_to_use = 0;
  456. tx_ring->next_to_clean = 0;
  457. writel(0, adapter->hw.hw_addr + tx_ring->head);
  458. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  459. }
  460. /**
  461. * igbvf_free_tx_resources - Free Tx Resources per Queue
  462. * @tx_ring: ring to free resources from
  463. *
  464. * Free all transmit software resources
  465. **/
  466. void igbvf_free_tx_resources(struct igbvf_ring *tx_ring)
  467. {
  468. struct pci_dev *pdev = tx_ring->adapter->pdev;
  469. igbvf_clean_tx_ring(tx_ring);
  470. vfree(tx_ring->buffer_info);
  471. tx_ring->buffer_info = NULL;
  472. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  473. tx_ring->dma);
  474. tx_ring->desc = NULL;
  475. }
  476. /**
  477. * igbvf_clean_rx_ring - Free Rx Buffers per Queue
  478. * @adapter: board private structure
  479. **/
  480. static void igbvf_clean_rx_ring(struct igbvf_ring *rx_ring)
  481. {
  482. struct igbvf_adapter *adapter = rx_ring->adapter;
  483. struct igbvf_buffer *buffer_info;
  484. struct pci_dev *pdev = adapter->pdev;
  485. unsigned long size;
  486. unsigned int i;
  487. if (!rx_ring->buffer_info)
  488. return;
  489. /* Free all the Rx ring sk_buffs */
  490. for (i = 0; i < rx_ring->count; i++) {
  491. buffer_info = &rx_ring->buffer_info[i];
  492. if (buffer_info->dma) {
  493. if (adapter->rx_ps_hdr_size) {
  494. dma_unmap_single(&pdev->dev, buffer_info->dma,
  495. adapter->rx_ps_hdr_size,
  496. DMA_FROM_DEVICE);
  497. } else {
  498. dma_unmap_single(&pdev->dev, buffer_info->dma,
  499. adapter->rx_buffer_len,
  500. DMA_FROM_DEVICE);
  501. }
  502. buffer_info->dma = 0;
  503. }
  504. if (buffer_info->skb) {
  505. dev_kfree_skb(buffer_info->skb);
  506. buffer_info->skb = NULL;
  507. }
  508. if (buffer_info->page) {
  509. if (buffer_info->page_dma)
  510. dma_unmap_page(&pdev->dev,
  511. buffer_info->page_dma,
  512. PAGE_SIZE / 2,
  513. DMA_FROM_DEVICE);
  514. put_page(buffer_info->page);
  515. buffer_info->page = NULL;
  516. buffer_info->page_dma = 0;
  517. buffer_info->page_offset = 0;
  518. }
  519. }
  520. size = sizeof(struct igbvf_buffer) * rx_ring->count;
  521. memset(rx_ring->buffer_info, 0, size);
  522. /* Zero out the descriptor ring */
  523. memset(rx_ring->desc, 0, rx_ring->size);
  524. rx_ring->next_to_clean = 0;
  525. rx_ring->next_to_use = 0;
  526. writel(0, adapter->hw.hw_addr + rx_ring->head);
  527. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  528. }
  529. /**
  530. * igbvf_free_rx_resources - Free Rx Resources
  531. * @rx_ring: ring to clean the resources from
  532. *
  533. * Free all receive software resources
  534. **/
  535. void igbvf_free_rx_resources(struct igbvf_ring *rx_ring)
  536. {
  537. struct pci_dev *pdev = rx_ring->adapter->pdev;
  538. igbvf_clean_rx_ring(rx_ring);
  539. vfree(rx_ring->buffer_info);
  540. rx_ring->buffer_info = NULL;
  541. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  542. rx_ring->dma);
  543. rx_ring->desc = NULL;
  544. }
  545. /**
  546. * igbvf_update_itr - update the dynamic ITR value based on statistics
  547. * @adapter: pointer to adapter
  548. * @itr_setting: current adapter->itr
  549. * @packets: the number of packets during this measurement interval
  550. * @bytes: the number of bytes during this measurement interval
  551. *
  552. * Stores a new ITR value based on packets and byte counts during the last
  553. * interrupt. The advantage of per interrupt computation is faster updates
  554. * and more accurate ITR for the current traffic pattern. Constants in this
  555. * function were computed based on theoretical maximum wire speed and thresholds
  556. * were set based on testing data as well as attempting to minimize response
  557. * time while increasing bulk throughput.
  558. **/
  559. static enum latency_range igbvf_update_itr(struct igbvf_adapter *adapter,
  560. enum latency_range itr_setting,
  561. int packets, int bytes)
  562. {
  563. enum latency_range retval = itr_setting;
  564. if (packets == 0)
  565. goto update_itr_done;
  566. switch (itr_setting) {
  567. case lowest_latency:
  568. /* handle TSO and jumbo frames */
  569. if (bytes/packets > 8000)
  570. retval = bulk_latency;
  571. else if ((packets < 5) && (bytes > 512))
  572. retval = low_latency;
  573. break;
  574. case low_latency: /* 50 usec aka 20000 ints/s */
  575. if (bytes > 10000) {
  576. /* this if handles the TSO accounting */
  577. if (bytes/packets > 8000)
  578. retval = bulk_latency;
  579. else if ((packets < 10) || ((bytes/packets) > 1200))
  580. retval = bulk_latency;
  581. else if ((packets > 35))
  582. retval = lowest_latency;
  583. } else if (bytes/packets > 2000) {
  584. retval = bulk_latency;
  585. } else if (packets <= 2 && bytes < 512) {
  586. retval = lowest_latency;
  587. }
  588. break;
  589. case bulk_latency: /* 250 usec aka 4000 ints/s */
  590. if (bytes > 25000) {
  591. if (packets > 35)
  592. retval = low_latency;
  593. } else if (bytes < 6000) {
  594. retval = low_latency;
  595. }
  596. break;
  597. default:
  598. break;
  599. }
  600. update_itr_done:
  601. return retval;
  602. }
  603. static int igbvf_range_to_itr(enum latency_range current_range)
  604. {
  605. int new_itr;
  606. switch (current_range) {
  607. /* counts and packets in update_itr are dependent on these numbers */
  608. case lowest_latency:
  609. new_itr = IGBVF_70K_ITR;
  610. break;
  611. case low_latency:
  612. new_itr = IGBVF_20K_ITR;
  613. break;
  614. case bulk_latency:
  615. new_itr = IGBVF_4K_ITR;
  616. break;
  617. default:
  618. new_itr = IGBVF_START_ITR;
  619. break;
  620. }
  621. return new_itr;
  622. }
  623. static void igbvf_set_itr(struct igbvf_adapter *adapter)
  624. {
  625. u32 new_itr;
  626. adapter->tx_ring->itr_range =
  627. igbvf_update_itr(adapter,
  628. adapter->tx_ring->itr_val,
  629. adapter->total_tx_packets,
  630. adapter->total_tx_bytes);
  631. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  632. if (adapter->requested_itr == 3 &&
  633. adapter->tx_ring->itr_range == lowest_latency)
  634. adapter->tx_ring->itr_range = low_latency;
  635. new_itr = igbvf_range_to_itr(adapter->tx_ring->itr_range);
  636. if (new_itr != adapter->tx_ring->itr_val) {
  637. u32 current_itr = adapter->tx_ring->itr_val;
  638. /* this attempts to bias the interrupt rate towards Bulk
  639. * by adding intermediate steps when interrupt rate is
  640. * increasing
  641. */
  642. new_itr = new_itr > current_itr ?
  643. min(current_itr + (new_itr >> 2), new_itr) :
  644. new_itr;
  645. adapter->tx_ring->itr_val = new_itr;
  646. adapter->tx_ring->set_itr = 1;
  647. }
  648. adapter->rx_ring->itr_range =
  649. igbvf_update_itr(adapter, adapter->rx_ring->itr_val,
  650. adapter->total_rx_packets,
  651. adapter->total_rx_bytes);
  652. if (adapter->requested_itr == 3 &&
  653. adapter->rx_ring->itr_range == lowest_latency)
  654. adapter->rx_ring->itr_range = low_latency;
  655. new_itr = igbvf_range_to_itr(adapter->rx_ring->itr_range);
  656. if (new_itr != adapter->rx_ring->itr_val) {
  657. u32 current_itr = adapter->rx_ring->itr_val;
  658. new_itr = new_itr > current_itr ?
  659. min(current_itr + (new_itr >> 2), new_itr) :
  660. new_itr;
  661. adapter->rx_ring->itr_val = new_itr;
  662. adapter->rx_ring->set_itr = 1;
  663. }
  664. }
  665. /**
  666. * igbvf_clean_tx_irq - Reclaim resources after transmit completes
  667. * @adapter: board private structure
  668. *
  669. * returns true if ring is completely cleaned
  670. **/
  671. static bool igbvf_clean_tx_irq(struct igbvf_ring *tx_ring)
  672. {
  673. struct igbvf_adapter *adapter = tx_ring->adapter;
  674. struct net_device *netdev = adapter->netdev;
  675. struct igbvf_buffer *buffer_info;
  676. struct sk_buff *skb;
  677. union e1000_adv_tx_desc *tx_desc, *eop_desc;
  678. unsigned int total_bytes = 0, total_packets = 0;
  679. unsigned int i, count = 0;
  680. bool cleaned = false;
  681. i = tx_ring->next_to_clean;
  682. buffer_info = &tx_ring->buffer_info[i];
  683. eop_desc = buffer_info->next_to_watch;
  684. do {
  685. /* if next_to_watch is not set then there is no work pending */
  686. if (!eop_desc)
  687. break;
  688. /* prevent any other reads prior to eop_desc */
  689. smp_rmb();
  690. /* if DD is not set pending work has not been completed */
  691. if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
  692. break;
  693. /* clear next_to_watch to prevent false hangs */
  694. buffer_info->next_to_watch = NULL;
  695. for (cleaned = false; !cleaned; count++) {
  696. tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i);
  697. cleaned = (tx_desc == eop_desc);
  698. skb = buffer_info->skb;
  699. if (skb) {
  700. unsigned int segs, bytecount;
  701. /* gso_segs is currently only valid for tcp */
  702. segs = skb_shinfo(skb)->gso_segs ?: 1;
  703. /* multiply data chunks by size of headers */
  704. bytecount = ((segs - 1) * skb_headlen(skb)) +
  705. skb->len;
  706. total_packets += segs;
  707. total_bytes += bytecount;
  708. }
  709. igbvf_put_txbuf(adapter, buffer_info);
  710. tx_desc->wb.status = 0;
  711. i++;
  712. if (i == tx_ring->count)
  713. i = 0;
  714. buffer_info = &tx_ring->buffer_info[i];
  715. }
  716. eop_desc = buffer_info->next_to_watch;
  717. } while (count < tx_ring->count);
  718. tx_ring->next_to_clean = i;
  719. if (unlikely(count && netif_carrier_ok(netdev) &&
  720. igbvf_desc_unused(tx_ring) >= IGBVF_TX_QUEUE_WAKE)) {
  721. /* Make sure that anybody stopping the queue after this
  722. * sees the new next_to_clean.
  723. */
  724. smp_mb();
  725. if (netif_queue_stopped(netdev) &&
  726. !(test_bit(__IGBVF_DOWN, &adapter->state))) {
  727. netif_wake_queue(netdev);
  728. ++adapter->restart_queue;
  729. }
  730. }
  731. adapter->net_stats.tx_bytes += total_bytes;
  732. adapter->net_stats.tx_packets += total_packets;
  733. return count < tx_ring->count;
  734. }
  735. static irqreturn_t igbvf_msix_other(int irq, void *data)
  736. {
  737. struct net_device *netdev = data;
  738. struct igbvf_adapter *adapter = netdev_priv(netdev);
  739. struct e1000_hw *hw = &adapter->hw;
  740. adapter->int_counter1++;
  741. hw->mac.get_link_status = 1;
  742. if (!test_bit(__IGBVF_DOWN, &adapter->state))
  743. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  744. ew32(EIMS, adapter->eims_other);
  745. return IRQ_HANDLED;
  746. }
  747. static irqreturn_t igbvf_intr_msix_tx(int irq, void *data)
  748. {
  749. struct net_device *netdev = data;
  750. struct igbvf_adapter *adapter = netdev_priv(netdev);
  751. struct e1000_hw *hw = &adapter->hw;
  752. struct igbvf_ring *tx_ring = adapter->tx_ring;
  753. if (tx_ring->set_itr) {
  754. writel(tx_ring->itr_val,
  755. adapter->hw.hw_addr + tx_ring->itr_register);
  756. adapter->tx_ring->set_itr = 0;
  757. }
  758. adapter->total_tx_bytes = 0;
  759. adapter->total_tx_packets = 0;
  760. /* auto mask will automatically re-enable the interrupt when we write
  761. * EICS
  762. */
  763. if (!igbvf_clean_tx_irq(tx_ring))
  764. /* Ring was not completely cleaned, so fire another interrupt */
  765. ew32(EICS, tx_ring->eims_value);
  766. else
  767. ew32(EIMS, tx_ring->eims_value);
  768. return IRQ_HANDLED;
  769. }
  770. static irqreturn_t igbvf_intr_msix_rx(int irq, void *data)
  771. {
  772. struct net_device *netdev = data;
  773. struct igbvf_adapter *adapter = netdev_priv(netdev);
  774. adapter->int_counter0++;
  775. /* Write the ITR value calculated at the end of the
  776. * previous interrupt.
  777. */
  778. if (adapter->rx_ring->set_itr) {
  779. writel(adapter->rx_ring->itr_val,
  780. adapter->hw.hw_addr + adapter->rx_ring->itr_register);
  781. adapter->rx_ring->set_itr = 0;
  782. }
  783. if (napi_schedule_prep(&adapter->rx_ring->napi)) {
  784. adapter->total_rx_bytes = 0;
  785. adapter->total_rx_packets = 0;
  786. __napi_schedule(&adapter->rx_ring->napi);
  787. }
  788. return IRQ_HANDLED;
  789. }
  790. #define IGBVF_NO_QUEUE -1
  791. static void igbvf_assign_vector(struct igbvf_adapter *adapter, int rx_queue,
  792. int tx_queue, int msix_vector)
  793. {
  794. struct e1000_hw *hw = &adapter->hw;
  795. u32 ivar, index;
  796. /* 82576 uses a table-based method for assigning vectors.
  797. * Each queue has a single entry in the table to which we write
  798. * a vector number along with a "valid" bit. Sadly, the layout
  799. * of the table is somewhat counterintuitive.
  800. */
  801. if (rx_queue > IGBVF_NO_QUEUE) {
  802. index = (rx_queue >> 1);
  803. ivar = array_er32(IVAR0, index);
  804. if (rx_queue & 0x1) {
  805. /* vector goes into third byte of register */
  806. ivar = ivar & 0xFF00FFFF;
  807. ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
  808. } else {
  809. /* vector goes into low byte of register */
  810. ivar = ivar & 0xFFFFFF00;
  811. ivar |= msix_vector | E1000_IVAR_VALID;
  812. }
  813. adapter->rx_ring[rx_queue].eims_value = BIT(msix_vector);
  814. array_ew32(IVAR0, index, ivar);
  815. }
  816. if (tx_queue > IGBVF_NO_QUEUE) {
  817. index = (tx_queue >> 1);
  818. ivar = array_er32(IVAR0, index);
  819. if (tx_queue & 0x1) {
  820. /* vector goes into high byte of register */
  821. ivar = ivar & 0x00FFFFFF;
  822. ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
  823. } else {
  824. /* vector goes into second byte of register */
  825. ivar = ivar & 0xFFFF00FF;
  826. ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
  827. }
  828. adapter->tx_ring[tx_queue].eims_value = BIT(msix_vector);
  829. array_ew32(IVAR0, index, ivar);
  830. }
  831. }
  832. /**
  833. * igbvf_configure_msix - Configure MSI-X hardware
  834. * @adapter: board private structure
  835. *
  836. * igbvf_configure_msix sets up the hardware to properly
  837. * generate MSI-X interrupts.
  838. **/
  839. static void igbvf_configure_msix(struct igbvf_adapter *adapter)
  840. {
  841. u32 tmp;
  842. struct e1000_hw *hw = &adapter->hw;
  843. struct igbvf_ring *tx_ring = adapter->tx_ring;
  844. struct igbvf_ring *rx_ring = adapter->rx_ring;
  845. int vector = 0;
  846. adapter->eims_enable_mask = 0;
  847. igbvf_assign_vector(adapter, IGBVF_NO_QUEUE, 0, vector++);
  848. adapter->eims_enable_mask |= tx_ring->eims_value;
  849. writel(tx_ring->itr_val, hw->hw_addr + tx_ring->itr_register);
  850. igbvf_assign_vector(adapter, 0, IGBVF_NO_QUEUE, vector++);
  851. adapter->eims_enable_mask |= rx_ring->eims_value;
  852. writel(rx_ring->itr_val, hw->hw_addr + rx_ring->itr_register);
  853. /* set vector for other causes, i.e. link changes */
  854. tmp = (vector++ | E1000_IVAR_VALID);
  855. ew32(IVAR_MISC, tmp);
  856. adapter->eims_enable_mask = GENMASK(vector - 1, 0);
  857. adapter->eims_other = BIT(vector - 1);
  858. e1e_flush();
  859. }
  860. static void igbvf_reset_interrupt_capability(struct igbvf_adapter *adapter)
  861. {
  862. if (adapter->msix_entries) {
  863. pci_disable_msix(adapter->pdev);
  864. kfree(adapter->msix_entries);
  865. adapter->msix_entries = NULL;
  866. }
  867. }
  868. /**
  869. * igbvf_set_interrupt_capability - set MSI or MSI-X if supported
  870. * @adapter: board private structure
  871. *
  872. * Attempt to configure interrupts using the best available
  873. * capabilities of the hardware and kernel.
  874. **/
  875. static void igbvf_set_interrupt_capability(struct igbvf_adapter *adapter)
  876. {
  877. int err = -ENOMEM;
  878. int i;
  879. /* we allocate 3 vectors, 1 for Tx, 1 for Rx, one for PF messages */
  880. adapter->msix_entries = kcalloc(3, sizeof(struct msix_entry),
  881. GFP_KERNEL);
  882. if (adapter->msix_entries) {
  883. for (i = 0; i < 3; i++)
  884. adapter->msix_entries[i].entry = i;
  885. err = pci_enable_msix_range(adapter->pdev,
  886. adapter->msix_entries, 3, 3);
  887. }
  888. if (err < 0) {
  889. /* MSI-X failed */
  890. dev_err(&adapter->pdev->dev,
  891. "Failed to initialize MSI-X interrupts.\n");
  892. igbvf_reset_interrupt_capability(adapter);
  893. }
  894. }
  895. /**
  896. * igbvf_request_msix - Initialize MSI-X interrupts
  897. * @adapter: board private structure
  898. *
  899. * igbvf_request_msix allocates MSI-X vectors and requests interrupts from the
  900. * kernel.
  901. **/
  902. static int igbvf_request_msix(struct igbvf_adapter *adapter)
  903. {
  904. struct net_device *netdev = adapter->netdev;
  905. int err = 0, vector = 0;
  906. if (strlen(netdev->name) < (IFNAMSIZ - 5)) {
  907. sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
  908. sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
  909. } else {
  910. memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
  911. memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
  912. }
  913. err = request_irq(adapter->msix_entries[vector].vector,
  914. igbvf_intr_msix_tx, 0, adapter->tx_ring->name,
  915. netdev);
  916. if (err)
  917. goto out;
  918. adapter->tx_ring->itr_register = E1000_EITR(vector);
  919. adapter->tx_ring->itr_val = adapter->current_itr;
  920. vector++;
  921. err = request_irq(adapter->msix_entries[vector].vector,
  922. igbvf_intr_msix_rx, 0, adapter->rx_ring->name,
  923. netdev);
  924. if (err)
  925. goto out;
  926. adapter->rx_ring->itr_register = E1000_EITR(vector);
  927. adapter->rx_ring->itr_val = adapter->current_itr;
  928. vector++;
  929. err = request_irq(adapter->msix_entries[vector].vector,
  930. igbvf_msix_other, 0, netdev->name, netdev);
  931. if (err)
  932. goto out;
  933. igbvf_configure_msix(adapter);
  934. return 0;
  935. out:
  936. return err;
  937. }
  938. /**
  939. * igbvf_alloc_queues - Allocate memory for all rings
  940. * @adapter: board private structure to initialize
  941. **/
  942. static int igbvf_alloc_queues(struct igbvf_adapter *adapter)
  943. {
  944. struct net_device *netdev = adapter->netdev;
  945. adapter->tx_ring = kzalloc(sizeof(struct igbvf_ring), GFP_KERNEL);
  946. if (!adapter->tx_ring)
  947. return -ENOMEM;
  948. adapter->rx_ring = kzalloc(sizeof(struct igbvf_ring), GFP_KERNEL);
  949. if (!adapter->rx_ring) {
  950. kfree(adapter->tx_ring);
  951. return -ENOMEM;
  952. }
  953. netif_napi_add(netdev, &adapter->rx_ring->napi, igbvf_poll, 64);
  954. return 0;
  955. }
  956. /**
  957. * igbvf_request_irq - initialize interrupts
  958. * @adapter: board private structure
  959. *
  960. * Attempts to configure interrupts using the best available
  961. * capabilities of the hardware and kernel.
  962. **/
  963. static int igbvf_request_irq(struct igbvf_adapter *adapter)
  964. {
  965. int err = -1;
  966. /* igbvf supports msi-x only */
  967. if (adapter->msix_entries)
  968. err = igbvf_request_msix(adapter);
  969. if (!err)
  970. return err;
  971. dev_err(&adapter->pdev->dev,
  972. "Unable to allocate interrupt, Error: %d\n", err);
  973. return err;
  974. }
  975. static void igbvf_free_irq(struct igbvf_adapter *adapter)
  976. {
  977. struct net_device *netdev = adapter->netdev;
  978. int vector;
  979. if (adapter->msix_entries) {
  980. for (vector = 0; vector < 3; vector++)
  981. free_irq(adapter->msix_entries[vector].vector, netdev);
  982. }
  983. }
  984. /**
  985. * igbvf_irq_disable - Mask off interrupt generation on the NIC
  986. * @adapter: board private structure
  987. **/
  988. static void igbvf_irq_disable(struct igbvf_adapter *adapter)
  989. {
  990. struct e1000_hw *hw = &adapter->hw;
  991. ew32(EIMC, ~0);
  992. if (adapter->msix_entries)
  993. ew32(EIAC, 0);
  994. }
  995. /**
  996. * igbvf_irq_enable - Enable default interrupt generation settings
  997. * @adapter: board private structure
  998. **/
  999. static void igbvf_irq_enable(struct igbvf_adapter *adapter)
  1000. {
  1001. struct e1000_hw *hw = &adapter->hw;
  1002. ew32(EIAC, adapter->eims_enable_mask);
  1003. ew32(EIAM, adapter->eims_enable_mask);
  1004. ew32(EIMS, adapter->eims_enable_mask);
  1005. }
  1006. /**
  1007. * igbvf_poll - NAPI Rx polling callback
  1008. * @napi: struct associated with this polling callback
  1009. * @budget: amount of packets driver is allowed to process this poll
  1010. **/
  1011. static int igbvf_poll(struct napi_struct *napi, int budget)
  1012. {
  1013. struct igbvf_ring *rx_ring = container_of(napi, struct igbvf_ring, napi);
  1014. struct igbvf_adapter *adapter = rx_ring->adapter;
  1015. struct e1000_hw *hw = &adapter->hw;
  1016. int work_done = 0;
  1017. igbvf_clean_rx_irq(adapter, &work_done, budget);
  1018. /* If not enough Rx work done, exit the polling mode */
  1019. if (work_done < budget) {
  1020. napi_complete_done(napi, work_done);
  1021. if (adapter->requested_itr & 3)
  1022. igbvf_set_itr(adapter);
  1023. if (!test_bit(__IGBVF_DOWN, &adapter->state))
  1024. ew32(EIMS, adapter->rx_ring->eims_value);
  1025. }
  1026. return work_done;
  1027. }
  1028. /**
  1029. * igbvf_set_rlpml - set receive large packet maximum length
  1030. * @adapter: board private structure
  1031. *
  1032. * Configure the maximum size of packets that will be received
  1033. */
  1034. static void igbvf_set_rlpml(struct igbvf_adapter *adapter)
  1035. {
  1036. int max_frame_size;
  1037. struct e1000_hw *hw = &adapter->hw;
  1038. max_frame_size = adapter->max_frame_size + VLAN_TAG_SIZE;
  1039. e1000_rlpml_set_vf(hw, max_frame_size);
  1040. }
  1041. static int igbvf_vlan_rx_add_vid(struct net_device *netdev,
  1042. __be16 proto, u16 vid)
  1043. {
  1044. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1045. struct e1000_hw *hw = &adapter->hw;
  1046. if (hw->mac.ops.set_vfta(hw, vid, true)) {
  1047. dev_err(&adapter->pdev->dev, "Failed to add vlan id %d\n", vid);
  1048. return -EINVAL;
  1049. }
  1050. set_bit(vid, adapter->active_vlans);
  1051. return 0;
  1052. }
  1053. static int igbvf_vlan_rx_kill_vid(struct net_device *netdev,
  1054. __be16 proto, u16 vid)
  1055. {
  1056. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1057. struct e1000_hw *hw = &adapter->hw;
  1058. if (hw->mac.ops.set_vfta(hw, vid, false)) {
  1059. dev_err(&adapter->pdev->dev,
  1060. "Failed to remove vlan id %d\n", vid);
  1061. return -EINVAL;
  1062. }
  1063. clear_bit(vid, adapter->active_vlans);
  1064. return 0;
  1065. }
  1066. static void igbvf_restore_vlan(struct igbvf_adapter *adapter)
  1067. {
  1068. u16 vid;
  1069. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  1070. igbvf_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  1071. }
  1072. /**
  1073. * igbvf_configure_tx - Configure Transmit Unit after Reset
  1074. * @adapter: board private structure
  1075. *
  1076. * Configure the Tx unit of the MAC after a reset.
  1077. **/
  1078. static void igbvf_configure_tx(struct igbvf_adapter *adapter)
  1079. {
  1080. struct e1000_hw *hw = &adapter->hw;
  1081. struct igbvf_ring *tx_ring = adapter->tx_ring;
  1082. u64 tdba;
  1083. u32 txdctl, dca_txctrl;
  1084. /* disable transmits */
  1085. txdctl = er32(TXDCTL(0));
  1086. ew32(TXDCTL(0), txdctl & ~E1000_TXDCTL_QUEUE_ENABLE);
  1087. e1e_flush();
  1088. msleep(10);
  1089. /* Setup the HW Tx Head and Tail descriptor pointers */
  1090. ew32(TDLEN(0), tx_ring->count * sizeof(union e1000_adv_tx_desc));
  1091. tdba = tx_ring->dma;
  1092. ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
  1093. ew32(TDBAH(0), (tdba >> 32));
  1094. ew32(TDH(0), 0);
  1095. ew32(TDT(0), 0);
  1096. tx_ring->head = E1000_TDH(0);
  1097. tx_ring->tail = E1000_TDT(0);
  1098. /* Turn off Relaxed Ordering on head write-backs. The writebacks
  1099. * MUST be delivered in order or it will completely screw up
  1100. * our bookkeeping.
  1101. */
  1102. dca_txctrl = er32(DCA_TXCTRL(0));
  1103. dca_txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
  1104. ew32(DCA_TXCTRL(0), dca_txctrl);
  1105. /* enable transmits */
  1106. txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
  1107. ew32(TXDCTL(0), txdctl);
  1108. /* Setup Transmit Descriptor Settings for eop descriptor */
  1109. adapter->txd_cmd = E1000_ADVTXD_DCMD_EOP | E1000_ADVTXD_DCMD_IFCS;
  1110. /* enable Report Status bit */
  1111. adapter->txd_cmd |= E1000_ADVTXD_DCMD_RS;
  1112. }
  1113. /**
  1114. * igbvf_setup_srrctl - configure the receive control registers
  1115. * @adapter: Board private structure
  1116. **/
  1117. static void igbvf_setup_srrctl(struct igbvf_adapter *adapter)
  1118. {
  1119. struct e1000_hw *hw = &adapter->hw;
  1120. u32 srrctl = 0;
  1121. srrctl &= ~(E1000_SRRCTL_DESCTYPE_MASK |
  1122. E1000_SRRCTL_BSIZEHDR_MASK |
  1123. E1000_SRRCTL_BSIZEPKT_MASK);
  1124. /* Enable queue drop to avoid head of line blocking */
  1125. srrctl |= E1000_SRRCTL_DROP_EN;
  1126. /* Setup buffer sizes */
  1127. srrctl |= ALIGN(adapter->rx_buffer_len, 1024) >>
  1128. E1000_SRRCTL_BSIZEPKT_SHIFT;
  1129. if (adapter->rx_buffer_len < 2048) {
  1130. adapter->rx_ps_hdr_size = 0;
  1131. srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
  1132. } else {
  1133. adapter->rx_ps_hdr_size = 128;
  1134. srrctl |= adapter->rx_ps_hdr_size <<
  1135. E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
  1136. srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  1137. }
  1138. ew32(SRRCTL(0), srrctl);
  1139. }
  1140. /**
  1141. * igbvf_configure_rx - Configure Receive Unit after Reset
  1142. * @adapter: board private structure
  1143. *
  1144. * Configure the Rx unit of the MAC after a reset.
  1145. **/
  1146. static void igbvf_configure_rx(struct igbvf_adapter *adapter)
  1147. {
  1148. struct e1000_hw *hw = &adapter->hw;
  1149. struct igbvf_ring *rx_ring = adapter->rx_ring;
  1150. u64 rdba;
  1151. u32 rxdctl;
  1152. /* disable receives */
  1153. rxdctl = er32(RXDCTL(0));
  1154. ew32(RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE);
  1155. e1e_flush();
  1156. msleep(10);
  1157. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  1158. * the Base and Length of the Rx Descriptor Ring
  1159. */
  1160. rdba = rx_ring->dma;
  1161. ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
  1162. ew32(RDBAH(0), (rdba >> 32));
  1163. ew32(RDLEN(0), rx_ring->count * sizeof(union e1000_adv_rx_desc));
  1164. rx_ring->head = E1000_RDH(0);
  1165. rx_ring->tail = E1000_RDT(0);
  1166. ew32(RDH(0), 0);
  1167. ew32(RDT(0), 0);
  1168. rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
  1169. rxdctl &= 0xFFF00000;
  1170. rxdctl |= IGBVF_RX_PTHRESH;
  1171. rxdctl |= IGBVF_RX_HTHRESH << 8;
  1172. rxdctl |= IGBVF_RX_WTHRESH << 16;
  1173. igbvf_set_rlpml(adapter);
  1174. /* enable receives */
  1175. ew32(RXDCTL(0), rxdctl);
  1176. }
  1177. /**
  1178. * igbvf_set_multi - Multicast and Promiscuous mode set
  1179. * @netdev: network interface device structure
  1180. *
  1181. * The set_multi entry point is called whenever the multicast address
  1182. * list or the network interface flags are updated. This routine is
  1183. * responsible for configuring the hardware for proper multicast,
  1184. * promiscuous mode, and all-multi behavior.
  1185. **/
  1186. static void igbvf_set_multi(struct net_device *netdev)
  1187. {
  1188. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1189. struct e1000_hw *hw = &adapter->hw;
  1190. struct netdev_hw_addr *ha;
  1191. u8 *mta_list = NULL;
  1192. int i;
  1193. if (!netdev_mc_empty(netdev)) {
  1194. mta_list = kmalloc_array(netdev_mc_count(netdev), ETH_ALEN,
  1195. GFP_ATOMIC);
  1196. if (!mta_list)
  1197. return;
  1198. }
  1199. /* prepare a packed array of only addresses. */
  1200. i = 0;
  1201. netdev_for_each_mc_addr(ha, netdev)
  1202. memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
  1203. hw->mac.ops.update_mc_addr_list(hw, mta_list, i, 0, 0);
  1204. kfree(mta_list);
  1205. }
  1206. /**
  1207. * igbvf_configure - configure the hardware for Rx and Tx
  1208. * @adapter: private board structure
  1209. **/
  1210. static void igbvf_configure(struct igbvf_adapter *adapter)
  1211. {
  1212. igbvf_set_multi(adapter->netdev);
  1213. igbvf_restore_vlan(adapter);
  1214. igbvf_configure_tx(adapter);
  1215. igbvf_setup_srrctl(adapter);
  1216. igbvf_configure_rx(adapter);
  1217. igbvf_alloc_rx_buffers(adapter->rx_ring,
  1218. igbvf_desc_unused(adapter->rx_ring));
  1219. }
  1220. /* igbvf_reset - bring the hardware into a known good state
  1221. * @adapter: private board structure
  1222. *
  1223. * This function boots the hardware and enables some settings that
  1224. * require a configuration cycle of the hardware - those cannot be
  1225. * set/changed during runtime. After reset the device needs to be
  1226. * properly configured for Rx, Tx etc.
  1227. */
  1228. static void igbvf_reset(struct igbvf_adapter *adapter)
  1229. {
  1230. struct e1000_mac_info *mac = &adapter->hw.mac;
  1231. struct net_device *netdev = adapter->netdev;
  1232. struct e1000_hw *hw = &adapter->hw;
  1233. /* Allow time for pending master requests to run */
  1234. if (mac->ops.reset_hw(hw))
  1235. dev_err(&adapter->pdev->dev, "PF still resetting\n");
  1236. mac->ops.init_hw(hw);
  1237. if (is_valid_ether_addr(adapter->hw.mac.addr)) {
  1238. memcpy(netdev->dev_addr, adapter->hw.mac.addr,
  1239. netdev->addr_len);
  1240. memcpy(netdev->perm_addr, adapter->hw.mac.addr,
  1241. netdev->addr_len);
  1242. }
  1243. adapter->last_reset = jiffies;
  1244. }
  1245. int igbvf_up(struct igbvf_adapter *adapter)
  1246. {
  1247. struct e1000_hw *hw = &adapter->hw;
  1248. /* hardware has been reset, we need to reload some things */
  1249. igbvf_configure(adapter);
  1250. clear_bit(__IGBVF_DOWN, &adapter->state);
  1251. napi_enable(&adapter->rx_ring->napi);
  1252. if (adapter->msix_entries)
  1253. igbvf_configure_msix(adapter);
  1254. /* Clear any pending interrupts. */
  1255. er32(EICR);
  1256. igbvf_irq_enable(adapter);
  1257. /* start the watchdog */
  1258. hw->mac.get_link_status = 1;
  1259. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1260. return 0;
  1261. }
  1262. void igbvf_down(struct igbvf_adapter *adapter)
  1263. {
  1264. struct net_device *netdev = adapter->netdev;
  1265. struct e1000_hw *hw = &adapter->hw;
  1266. u32 rxdctl, txdctl;
  1267. /* signal that we're down so the interrupt handler does not
  1268. * reschedule our watchdog timer
  1269. */
  1270. set_bit(__IGBVF_DOWN, &adapter->state);
  1271. /* disable receives in the hardware */
  1272. rxdctl = er32(RXDCTL(0));
  1273. ew32(RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE);
  1274. netif_carrier_off(netdev);
  1275. netif_stop_queue(netdev);
  1276. /* disable transmits in the hardware */
  1277. txdctl = er32(TXDCTL(0));
  1278. ew32(TXDCTL(0), txdctl & ~E1000_TXDCTL_QUEUE_ENABLE);
  1279. /* flush both disables and wait for them to finish */
  1280. e1e_flush();
  1281. msleep(10);
  1282. napi_disable(&adapter->rx_ring->napi);
  1283. igbvf_irq_disable(adapter);
  1284. del_timer_sync(&adapter->watchdog_timer);
  1285. /* record the stats before reset*/
  1286. igbvf_update_stats(adapter);
  1287. adapter->link_speed = 0;
  1288. adapter->link_duplex = 0;
  1289. igbvf_reset(adapter);
  1290. igbvf_clean_tx_ring(adapter->tx_ring);
  1291. igbvf_clean_rx_ring(adapter->rx_ring);
  1292. }
  1293. void igbvf_reinit_locked(struct igbvf_adapter *adapter)
  1294. {
  1295. might_sleep();
  1296. while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
  1297. usleep_range(1000, 2000);
  1298. igbvf_down(adapter);
  1299. igbvf_up(adapter);
  1300. clear_bit(__IGBVF_RESETTING, &adapter->state);
  1301. }
  1302. /**
  1303. * igbvf_sw_init - Initialize general software structures (struct igbvf_adapter)
  1304. * @adapter: board private structure to initialize
  1305. *
  1306. * igbvf_sw_init initializes the Adapter private data structure.
  1307. * Fields are initialized based on PCI device information and
  1308. * OS network device settings (MTU size).
  1309. **/
  1310. static int igbvf_sw_init(struct igbvf_adapter *adapter)
  1311. {
  1312. struct net_device *netdev = adapter->netdev;
  1313. s32 rc;
  1314. adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
  1315. adapter->rx_ps_hdr_size = 0;
  1316. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  1317. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  1318. adapter->tx_int_delay = 8;
  1319. adapter->tx_abs_int_delay = 32;
  1320. adapter->rx_int_delay = 0;
  1321. adapter->rx_abs_int_delay = 8;
  1322. adapter->requested_itr = 3;
  1323. adapter->current_itr = IGBVF_START_ITR;
  1324. /* Set various function pointers */
  1325. adapter->ei->init_ops(&adapter->hw);
  1326. rc = adapter->hw.mac.ops.init_params(&adapter->hw);
  1327. if (rc)
  1328. return rc;
  1329. rc = adapter->hw.mbx.ops.init_params(&adapter->hw);
  1330. if (rc)
  1331. return rc;
  1332. igbvf_set_interrupt_capability(adapter);
  1333. if (igbvf_alloc_queues(adapter))
  1334. return -ENOMEM;
  1335. spin_lock_init(&adapter->tx_queue_lock);
  1336. /* Explicitly disable IRQ since the NIC can be in any state. */
  1337. igbvf_irq_disable(adapter);
  1338. spin_lock_init(&adapter->stats_lock);
  1339. set_bit(__IGBVF_DOWN, &adapter->state);
  1340. return 0;
  1341. }
  1342. static void igbvf_initialize_last_counter_stats(struct igbvf_adapter *adapter)
  1343. {
  1344. struct e1000_hw *hw = &adapter->hw;
  1345. adapter->stats.last_gprc = er32(VFGPRC);
  1346. adapter->stats.last_gorc = er32(VFGORC);
  1347. adapter->stats.last_gptc = er32(VFGPTC);
  1348. adapter->stats.last_gotc = er32(VFGOTC);
  1349. adapter->stats.last_mprc = er32(VFMPRC);
  1350. adapter->stats.last_gotlbc = er32(VFGOTLBC);
  1351. adapter->stats.last_gptlbc = er32(VFGPTLBC);
  1352. adapter->stats.last_gorlbc = er32(VFGORLBC);
  1353. adapter->stats.last_gprlbc = er32(VFGPRLBC);
  1354. adapter->stats.base_gprc = er32(VFGPRC);
  1355. adapter->stats.base_gorc = er32(VFGORC);
  1356. adapter->stats.base_gptc = er32(VFGPTC);
  1357. adapter->stats.base_gotc = er32(VFGOTC);
  1358. adapter->stats.base_mprc = er32(VFMPRC);
  1359. adapter->stats.base_gotlbc = er32(VFGOTLBC);
  1360. adapter->stats.base_gptlbc = er32(VFGPTLBC);
  1361. adapter->stats.base_gorlbc = er32(VFGORLBC);
  1362. adapter->stats.base_gprlbc = er32(VFGPRLBC);
  1363. }
  1364. /**
  1365. * igbvf_open - Called when a network interface is made active
  1366. * @netdev: network interface device structure
  1367. *
  1368. * Returns 0 on success, negative value on failure
  1369. *
  1370. * The open entry point is called when a network interface is made
  1371. * active by the system (IFF_UP). At this point all resources needed
  1372. * for transmit and receive operations are allocated, the interrupt
  1373. * handler is registered with the OS, the watchdog timer is started,
  1374. * and the stack is notified that the interface is ready.
  1375. **/
  1376. static int igbvf_open(struct net_device *netdev)
  1377. {
  1378. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1379. struct e1000_hw *hw = &adapter->hw;
  1380. int err;
  1381. /* disallow open during test */
  1382. if (test_bit(__IGBVF_TESTING, &adapter->state))
  1383. return -EBUSY;
  1384. /* allocate transmit descriptors */
  1385. err = igbvf_setup_tx_resources(adapter, adapter->tx_ring);
  1386. if (err)
  1387. goto err_setup_tx;
  1388. /* allocate receive descriptors */
  1389. err = igbvf_setup_rx_resources(adapter, adapter->rx_ring);
  1390. if (err)
  1391. goto err_setup_rx;
  1392. /* before we allocate an interrupt, we must be ready to handle it.
  1393. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  1394. * as soon as we call pci_request_irq, so we have to setup our
  1395. * clean_rx handler before we do so.
  1396. */
  1397. igbvf_configure(adapter);
  1398. err = igbvf_request_irq(adapter);
  1399. if (err)
  1400. goto err_req_irq;
  1401. /* From here on the code is the same as igbvf_up() */
  1402. clear_bit(__IGBVF_DOWN, &adapter->state);
  1403. napi_enable(&adapter->rx_ring->napi);
  1404. /* clear any pending interrupts */
  1405. er32(EICR);
  1406. igbvf_irq_enable(adapter);
  1407. /* start the watchdog */
  1408. hw->mac.get_link_status = 1;
  1409. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1410. return 0;
  1411. err_req_irq:
  1412. igbvf_free_rx_resources(adapter->rx_ring);
  1413. err_setup_rx:
  1414. igbvf_free_tx_resources(adapter->tx_ring);
  1415. err_setup_tx:
  1416. igbvf_reset(adapter);
  1417. return err;
  1418. }
  1419. /**
  1420. * igbvf_close - Disables a network interface
  1421. * @netdev: network interface device structure
  1422. *
  1423. * Returns 0, this is not allowed to fail
  1424. *
  1425. * The close entry point is called when an interface is de-activated
  1426. * by the OS. The hardware is still under the drivers control, but
  1427. * needs to be disabled. A global MAC reset is issued to stop the
  1428. * hardware, and all transmit and receive resources are freed.
  1429. **/
  1430. static int igbvf_close(struct net_device *netdev)
  1431. {
  1432. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1433. WARN_ON(test_bit(__IGBVF_RESETTING, &adapter->state));
  1434. igbvf_down(adapter);
  1435. igbvf_free_irq(adapter);
  1436. igbvf_free_tx_resources(adapter->tx_ring);
  1437. igbvf_free_rx_resources(adapter->rx_ring);
  1438. return 0;
  1439. }
  1440. /**
  1441. * igbvf_set_mac - Change the Ethernet Address of the NIC
  1442. * @netdev: network interface device structure
  1443. * @p: pointer to an address structure
  1444. *
  1445. * Returns 0 on success, negative on failure
  1446. **/
  1447. static int igbvf_set_mac(struct net_device *netdev, void *p)
  1448. {
  1449. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1450. struct e1000_hw *hw = &adapter->hw;
  1451. struct sockaddr *addr = p;
  1452. if (!is_valid_ether_addr(addr->sa_data))
  1453. return -EADDRNOTAVAIL;
  1454. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  1455. hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
  1456. if (!ether_addr_equal(addr->sa_data, hw->mac.addr))
  1457. return -EADDRNOTAVAIL;
  1458. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1459. return 0;
  1460. }
  1461. #define UPDATE_VF_COUNTER(reg, name) \
  1462. { \
  1463. u32 current_counter = er32(reg); \
  1464. if (current_counter < adapter->stats.last_##name) \
  1465. adapter->stats.name += 0x100000000LL; \
  1466. adapter->stats.last_##name = current_counter; \
  1467. adapter->stats.name &= 0xFFFFFFFF00000000LL; \
  1468. adapter->stats.name |= current_counter; \
  1469. }
  1470. /**
  1471. * igbvf_update_stats - Update the board statistics counters
  1472. * @adapter: board private structure
  1473. **/
  1474. void igbvf_update_stats(struct igbvf_adapter *adapter)
  1475. {
  1476. struct e1000_hw *hw = &adapter->hw;
  1477. struct pci_dev *pdev = adapter->pdev;
  1478. /* Prevent stats update while adapter is being reset, link is down
  1479. * or if the pci connection is down.
  1480. */
  1481. if (adapter->link_speed == 0)
  1482. return;
  1483. if (test_bit(__IGBVF_RESETTING, &adapter->state))
  1484. return;
  1485. if (pci_channel_offline(pdev))
  1486. return;
  1487. UPDATE_VF_COUNTER(VFGPRC, gprc);
  1488. UPDATE_VF_COUNTER(VFGORC, gorc);
  1489. UPDATE_VF_COUNTER(VFGPTC, gptc);
  1490. UPDATE_VF_COUNTER(VFGOTC, gotc);
  1491. UPDATE_VF_COUNTER(VFMPRC, mprc);
  1492. UPDATE_VF_COUNTER(VFGOTLBC, gotlbc);
  1493. UPDATE_VF_COUNTER(VFGPTLBC, gptlbc);
  1494. UPDATE_VF_COUNTER(VFGORLBC, gorlbc);
  1495. UPDATE_VF_COUNTER(VFGPRLBC, gprlbc);
  1496. /* Fill out the OS statistics structure */
  1497. adapter->net_stats.multicast = adapter->stats.mprc;
  1498. }
  1499. static void igbvf_print_link_info(struct igbvf_adapter *adapter)
  1500. {
  1501. dev_info(&adapter->pdev->dev, "Link is Up %d Mbps %s Duplex\n",
  1502. adapter->link_speed,
  1503. adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half");
  1504. }
  1505. static bool igbvf_has_link(struct igbvf_adapter *adapter)
  1506. {
  1507. struct e1000_hw *hw = &adapter->hw;
  1508. s32 ret_val = E1000_SUCCESS;
  1509. bool link_active;
  1510. /* If interface is down, stay link down */
  1511. if (test_bit(__IGBVF_DOWN, &adapter->state))
  1512. return false;
  1513. ret_val = hw->mac.ops.check_for_link(hw);
  1514. link_active = !hw->mac.get_link_status;
  1515. /* if check for link returns error we will need to reset */
  1516. if (ret_val && time_after(jiffies, adapter->last_reset + (10 * HZ)))
  1517. schedule_work(&adapter->reset_task);
  1518. return link_active;
  1519. }
  1520. /**
  1521. * igbvf_watchdog - Timer Call-back
  1522. * @data: pointer to adapter cast into an unsigned long
  1523. **/
  1524. static void igbvf_watchdog(unsigned long data)
  1525. {
  1526. struct igbvf_adapter *adapter = (struct igbvf_adapter *)data;
  1527. /* Do the rest outside of interrupt context */
  1528. schedule_work(&adapter->watchdog_task);
  1529. }
  1530. static void igbvf_watchdog_task(struct work_struct *work)
  1531. {
  1532. struct igbvf_adapter *adapter = container_of(work,
  1533. struct igbvf_adapter,
  1534. watchdog_task);
  1535. struct net_device *netdev = adapter->netdev;
  1536. struct e1000_mac_info *mac = &adapter->hw.mac;
  1537. struct igbvf_ring *tx_ring = adapter->tx_ring;
  1538. struct e1000_hw *hw = &adapter->hw;
  1539. u32 link;
  1540. int tx_pending = 0;
  1541. link = igbvf_has_link(adapter);
  1542. if (link) {
  1543. if (!netif_carrier_ok(netdev)) {
  1544. mac->ops.get_link_up_info(&adapter->hw,
  1545. &adapter->link_speed,
  1546. &adapter->link_duplex);
  1547. igbvf_print_link_info(adapter);
  1548. netif_carrier_on(netdev);
  1549. netif_wake_queue(netdev);
  1550. }
  1551. } else {
  1552. if (netif_carrier_ok(netdev)) {
  1553. adapter->link_speed = 0;
  1554. adapter->link_duplex = 0;
  1555. dev_info(&adapter->pdev->dev, "Link is Down\n");
  1556. netif_carrier_off(netdev);
  1557. netif_stop_queue(netdev);
  1558. }
  1559. }
  1560. if (netif_carrier_ok(netdev)) {
  1561. igbvf_update_stats(adapter);
  1562. } else {
  1563. tx_pending = (igbvf_desc_unused(tx_ring) + 1 <
  1564. tx_ring->count);
  1565. if (tx_pending) {
  1566. /* We've lost link, so the controller stops DMA,
  1567. * but we've got queued Tx work that's never going
  1568. * to get done, so reset controller to flush Tx.
  1569. * (Do the reset outside of interrupt context).
  1570. */
  1571. adapter->tx_timeout_count++;
  1572. schedule_work(&adapter->reset_task);
  1573. }
  1574. }
  1575. /* Cause software interrupt to ensure Rx ring is cleaned */
  1576. ew32(EICS, adapter->rx_ring->eims_value);
  1577. /* Reset the timer */
  1578. if (!test_bit(__IGBVF_DOWN, &adapter->state))
  1579. mod_timer(&adapter->watchdog_timer,
  1580. round_jiffies(jiffies + (2 * HZ)));
  1581. }
  1582. #define IGBVF_TX_FLAGS_CSUM 0x00000001
  1583. #define IGBVF_TX_FLAGS_VLAN 0x00000002
  1584. #define IGBVF_TX_FLAGS_TSO 0x00000004
  1585. #define IGBVF_TX_FLAGS_IPV4 0x00000008
  1586. #define IGBVF_TX_FLAGS_VLAN_MASK 0xffff0000
  1587. #define IGBVF_TX_FLAGS_VLAN_SHIFT 16
  1588. static void igbvf_tx_ctxtdesc(struct igbvf_ring *tx_ring, u32 vlan_macip_lens,
  1589. u32 type_tucmd, u32 mss_l4len_idx)
  1590. {
  1591. struct e1000_adv_tx_context_desc *context_desc;
  1592. struct igbvf_buffer *buffer_info;
  1593. u16 i = tx_ring->next_to_use;
  1594. context_desc = IGBVF_TX_CTXTDESC_ADV(*tx_ring, i);
  1595. buffer_info = &tx_ring->buffer_info[i];
  1596. i++;
  1597. tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
  1598. /* set bits to identify this as an advanced context descriptor */
  1599. type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
  1600. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  1601. context_desc->seqnum_seed = 0;
  1602. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  1603. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  1604. buffer_info->time_stamp = jiffies;
  1605. buffer_info->dma = 0;
  1606. }
  1607. static int igbvf_tso(struct igbvf_ring *tx_ring,
  1608. struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
  1609. {
  1610. u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
  1611. union {
  1612. struct iphdr *v4;
  1613. struct ipv6hdr *v6;
  1614. unsigned char *hdr;
  1615. } ip;
  1616. union {
  1617. struct tcphdr *tcp;
  1618. unsigned char *hdr;
  1619. } l4;
  1620. u32 paylen, l4_offset;
  1621. int err;
  1622. if (skb->ip_summed != CHECKSUM_PARTIAL)
  1623. return 0;
  1624. if (!skb_is_gso(skb))
  1625. return 0;
  1626. err = skb_cow_head(skb, 0);
  1627. if (err < 0)
  1628. return err;
  1629. ip.hdr = skb_network_header(skb);
  1630. l4.hdr = skb_checksum_start(skb);
  1631. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  1632. type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
  1633. /* initialize outer IP header fields */
  1634. if (ip.v4->version == 4) {
  1635. unsigned char *csum_start = skb_checksum_start(skb);
  1636. unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
  1637. /* IP header will have to cancel out any data that
  1638. * is not a part of the outer IP header
  1639. */
  1640. ip.v4->check = csum_fold(csum_partial(trans_start,
  1641. csum_start - trans_start,
  1642. 0));
  1643. type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
  1644. ip.v4->tot_len = 0;
  1645. } else {
  1646. ip.v6->payload_len = 0;
  1647. }
  1648. /* determine offset of inner transport header */
  1649. l4_offset = l4.hdr - skb->data;
  1650. /* compute length of segmentation header */
  1651. *hdr_len = (l4.tcp->doff * 4) + l4_offset;
  1652. /* remove payload length from inner checksum */
  1653. paylen = skb->len - l4_offset;
  1654. csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
  1655. /* MSS L4LEN IDX */
  1656. mss_l4len_idx = (*hdr_len - l4_offset) << E1000_ADVTXD_L4LEN_SHIFT;
  1657. mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
  1658. /* VLAN MACLEN IPLEN */
  1659. vlan_macip_lens = l4.hdr - ip.hdr;
  1660. vlan_macip_lens |= (ip.hdr - skb->data) << E1000_ADVTXD_MACLEN_SHIFT;
  1661. vlan_macip_lens |= tx_flags & IGBVF_TX_FLAGS_VLAN_MASK;
  1662. igbvf_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
  1663. return 1;
  1664. }
  1665. static inline bool igbvf_ipv6_csum_is_sctp(struct sk_buff *skb)
  1666. {
  1667. unsigned int offset = 0;
  1668. ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
  1669. return offset == skb_checksum_start_offset(skb);
  1670. }
  1671. static bool igbvf_tx_csum(struct igbvf_ring *tx_ring, struct sk_buff *skb,
  1672. u32 tx_flags, __be16 protocol)
  1673. {
  1674. u32 vlan_macip_lens = 0;
  1675. u32 type_tucmd = 0;
  1676. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  1677. csum_failed:
  1678. if (!(tx_flags & IGBVF_TX_FLAGS_VLAN))
  1679. return false;
  1680. goto no_csum;
  1681. }
  1682. switch (skb->csum_offset) {
  1683. case offsetof(struct tcphdr, check):
  1684. type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
  1685. /* fall through */
  1686. case offsetof(struct udphdr, check):
  1687. break;
  1688. case offsetof(struct sctphdr, checksum):
  1689. /* validate that this is actually an SCTP request */
  1690. if (((protocol == htons(ETH_P_IP)) &&
  1691. (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
  1692. ((protocol == htons(ETH_P_IPV6)) &&
  1693. igbvf_ipv6_csum_is_sctp(skb))) {
  1694. type_tucmd = E1000_ADVTXD_TUCMD_L4T_SCTP;
  1695. break;
  1696. }
  1697. default:
  1698. skb_checksum_help(skb);
  1699. goto csum_failed;
  1700. }
  1701. vlan_macip_lens = skb_checksum_start_offset(skb) -
  1702. skb_network_offset(skb);
  1703. no_csum:
  1704. vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
  1705. vlan_macip_lens |= tx_flags & IGBVF_TX_FLAGS_VLAN_MASK;
  1706. igbvf_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, 0);
  1707. return true;
  1708. }
  1709. static int igbvf_maybe_stop_tx(struct net_device *netdev, int size)
  1710. {
  1711. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1712. /* there is enough descriptors then we don't need to worry */
  1713. if (igbvf_desc_unused(adapter->tx_ring) >= size)
  1714. return 0;
  1715. netif_stop_queue(netdev);
  1716. /* Herbert's original patch had:
  1717. * smp_mb__after_netif_stop_queue();
  1718. * but since that doesn't exist yet, just open code it.
  1719. */
  1720. smp_mb();
  1721. /* We need to check again just in case room has been made available */
  1722. if (igbvf_desc_unused(adapter->tx_ring) < size)
  1723. return -EBUSY;
  1724. netif_wake_queue(netdev);
  1725. ++adapter->restart_queue;
  1726. return 0;
  1727. }
  1728. #define IGBVF_MAX_TXD_PWR 16
  1729. #define IGBVF_MAX_DATA_PER_TXD (1u << IGBVF_MAX_TXD_PWR)
  1730. static inline int igbvf_tx_map_adv(struct igbvf_adapter *adapter,
  1731. struct igbvf_ring *tx_ring,
  1732. struct sk_buff *skb)
  1733. {
  1734. struct igbvf_buffer *buffer_info;
  1735. struct pci_dev *pdev = adapter->pdev;
  1736. unsigned int len = skb_headlen(skb);
  1737. unsigned int count = 0, i;
  1738. unsigned int f;
  1739. i = tx_ring->next_to_use;
  1740. buffer_info = &tx_ring->buffer_info[i];
  1741. BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD);
  1742. buffer_info->length = len;
  1743. /* set time_stamp *before* dma to help avoid a possible race */
  1744. buffer_info->time_stamp = jiffies;
  1745. buffer_info->mapped_as_page = false;
  1746. buffer_info->dma = dma_map_single(&pdev->dev, skb->data, len,
  1747. DMA_TO_DEVICE);
  1748. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  1749. goto dma_error;
  1750. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
  1751. const struct skb_frag_struct *frag;
  1752. count++;
  1753. i++;
  1754. if (i == tx_ring->count)
  1755. i = 0;
  1756. frag = &skb_shinfo(skb)->frags[f];
  1757. len = skb_frag_size(frag);
  1758. buffer_info = &tx_ring->buffer_info[i];
  1759. BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD);
  1760. buffer_info->length = len;
  1761. buffer_info->time_stamp = jiffies;
  1762. buffer_info->mapped_as_page = true;
  1763. buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, 0, len,
  1764. DMA_TO_DEVICE);
  1765. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  1766. goto dma_error;
  1767. }
  1768. tx_ring->buffer_info[i].skb = skb;
  1769. return ++count;
  1770. dma_error:
  1771. dev_err(&pdev->dev, "TX DMA map failed\n");
  1772. /* clear timestamp and dma mappings for failed buffer_info mapping */
  1773. buffer_info->dma = 0;
  1774. buffer_info->time_stamp = 0;
  1775. buffer_info->length = 0;
  1776. buffer_info->mapped_as_page = false;
  1777. if (count)
  1778. count--;
  1779. /* clear timestamp and dma mappings for remaining portion of packet */
  1780. while (count--) {
  1781. if (i == 0)
  1782. i += tx_ring->count;
  1783. i--;
  1784. buffer_info = &tx_ring->buffer_info[i];
  1785. igbvf_put_txbuf(adapter, buffer_info);
  1786. }
  1787. return 0;
  1788. }
  1789. static inline void igbvf_tx_queue_adv(struct igbvf_adapter *adapter,
  1790. struct igbvf_ring *tx_ring,
  1791. int tx_flags, int count,
  1792. unsigned int first, u32 paylen,
  1793. u8 hdr_len)
  1794. {
  1795. union e1000_adv_tx_desc *tx_desc = NULL;
  1796. struct igbvf_buffer *buffer_info;
  1797. u32 olinfo_status = 0, cmd_type_len;
  1798. unsigned int i;
  1799. cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
  1800. E1000_ADVTXD_DCMD_DEXT);
  1801. if (tx_flags & IGBVF_TX_FLAGS_VLAN)
  1802. cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
  1803. if (tx_flags & IGBVF_TX_FLAGS_TSO) {
  1804. cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
  1805. /* insert tcp checksum */
  1806. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  1807. /* insert ip checksum */
  1808. if (tx_flags & IGBVF_TX_FLAGS_IPV4)
  1809. olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
  1810. } else if (tx_flags & IGBVF_TX_FLAGS_CSUM) {
  1811. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  1812. }
  1813. olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
  1814. i = tx_ring->next_to_use;
  1815. while (count--) {
  1816. buffer_info = &tx_ring->buffer_info[i];
  1817. tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i);
  1818. tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  1819. tx_desc->read.cmd_type_len =
  1820. cpu_to_le32(cmd_type_len | buffer_info->length);
  1821. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  1822. i++;
  1823. if (i == tx_ring->count)
  1824. i = 0;
  1825. }
  1826. tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd);
  1827. /* Force memory writes to complete before letting h/w
  1828. * know there are new descriptors to fetch. (Only
  1829. * applicable for weak-ordered memory model archs,
  1830. * such as IA-64).
  1831. */
  1832. wmb();
  1833. tx_ring->buffer_info[first].next_to_watch = tx_desc;
  1834. tx_ring->next_to_use = i;
  1835. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  1836. /* we need this if more than one processor can write to our tail
  1837. * at a time, it synchronizes IO on IA64/Altix systems
  1838. */
  1839. mmiowb();
  1840. }
  1841. static netdev_tx_t igbvf_xmit_frame_ring_adv(struct sk_buff *skb,
  1842. struct net_device *netdev,
  1843. struct igbvf_ring *tx_ring)
  1844. {
  1845. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1846. unsigned int first, tx_flags = 0;
  1847. u8 hdr_len = 0;
  1848. int count = 0;
  1849. int tso = 0;
  1850. __be16 protocol = vlan_get_protocol(skb);
  1851. if (test_bit(__IGBVF_DOWN, &adapter->state)) {
  1852. dev_kfree_skb_any(skb);
  1853. return NETDEV_TX_OK;
  1854. }
  1855. if (skb->len <= 0) {
  1856. dev_kfree_skb_any(skb);
  1857. return NETDEV_TX_OK;
  1858. }
  1859. /* need: count + 4 desc gap to keep tail from touching
  1860. * + 2 desc gap to keep tail from touching head,
  1861. * + 1 desc for skb->data,
  1862. * + 1 desc for context descriptor,
  1863. * head, otherwise try next time
  1864. */
  1865. if (igbvf_maybe_stop_tx(netdev, skb_shinfo(skb)->nr_frags + 4)) {
  1866. /* this is a hard error */
  1867. return NETDEV_TX_BUSY;
  1868. }
  1869. if (skb_vlan_tag_present(skb)) {
  1870. tx_flags |= IGBVF_TX_FLAGS_VLAN;
  1871. tx_flags |= (skb_vlan_tag_get(skb) <<
  1872. IGBVF_TX_FLAGS_VLAN_SHIFT);
  1873. }
  1874. if (protocol == htons(ETH_P_IP))
  1875. tx_flags |= IGBVF_TX_FLAGS_IPV4;
  1876. first = tx_ring->next_to_use;
  1877. tso = igbvf_tso(tx_ring, skb, tx_flags, &hdr_len);
  1878. if (unlikely(tso < 0)) {
  1879. dev_kfree_skb_any(skb);
  1880. return NETDEV_TX_OK;
  1881. }
  1882. if (tso)
  1883. tx_flags |= IGBVF_TX_FLAGS_TSO;
  1884. else if (igbvf_tx_csum(tx_ring, skb, tx_flags, protocol) &&
  1885. (skb->ip_summed == CHECKSUM_PARTIAL))
  1886. tx_flags |= IGBVF_TX_FLAGS_CSUM;
  1887. /* count reflects descriptors mapped, if 0 then mapping error
  1888. * has occurred and we need to rewind the descriptor queue
  1889. */
  1890. count = igbvf_tx_map_adv(adapter, tx_ring, skb);
  1891. if (count) {
  1892. igbvf_tx_queue_adv(adapter, tx_ring, tx_flags, count,
  1893. first, skb->len, hdr_len);
  1894. /* Make sure there is space in the ring for the next send. */
  1895. igbvf_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 4);
  1896. } else {
  1897. dev_kfree_skb_any(skb);
  1898. tx_ring->buffer_info[first].time_stamp = 0;
  1899. tx_ring->next_to_use = first;
  1900. }
  1901. return NETDEV_TX_OK;
  1902. }
  1903. static netdev_tx_t igbvf_xmit_frame(struct sk_buff *skb,
  1904. struct net_device *netdev)
  1905. {
  1906. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1907. struct igbvf_ring *tx_ring;
  1908. if (test_bit(__IGBVF_DOWN, &adapter->state)) {
  1909. dev_kfree_skb_any(skb);
  1910. return NETDEV_TX_OK;
  1911. }
  1912. tx_ring = &adapter->tx_ring[0];
  1913. return igbvf_xmit_frame_ring_adv(skb, netdev, tx_ring);
  1914. }
  1915. /**
  1916. * igbvf_tx_timeout - Respond to a Tx Hang
  1917. * @netdev: network interface device structure
  1918. **/
  1919. static void igbvf_tx_timeout(struct net_device *netdev)
  1920. {
  1921. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1922. /* Do the reset outside of interrupt context */
  1923. adapter->tx_timeout_count++;
  1924. schedule_work(&adapter->reset_task);
  1925. }
  1926. static void igbvf_reset_task(struct work_struct *work)
  1927. {
  1928. struct igbvf_adapter *adapter;
  1929. adapter = container_of(work, struct igbvf_adapter, reset_task);
  1930. igbvf_reinit_locked(adapter);
  1931. }
  1932. /**
  1933. * igbvf_get_stats - Get System Network Statistics
  1934. * @netdev: network interface device structure
  1935. *
  1936. * Returns the address of the device statistics structure.
  1937. * The statistics are actually updated from the timer callback.
  1938. **/
  1939. static struct net_device_stats *igbvf_get_stats(struct net_device *netdev)
  1940. {
  1941. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1942. /* only return the current stats */
  1943. return &adapter->net_stats;
  1944. }
  1945. /**
  1946. * igbvf_change_mtu - Change the Maximum Transfer Unit
  1947. * @netdev: network interface device structure
  1948. * @new_mtu: new value for maximum frame size
  1949. *
  1950. * Returns 0 on success, negative on failure
  1951. **/
  1952. static int igbvf_change_mtu(struct net_device *netdev, int new_mtu)
  1953. {
  1954. struct igbvf_adapter *adapter = netdev_priv(netdev);
  1955. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  1956. if (new_mtu < 68 || new_mtu > INT_MAX - ETH_HLEN - ETH_FCS_LEN ||
  1957. max_frame > MAX_JUMBO_FRAME_SIZE)
  1958. return -EINVAL;
  1959. #define MAX_STD_JUMBO_FRAME_SIZE 9234
  1960. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  1961. dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n");
  1962. return -EINVAL;
  1963. }
  1964. while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
  1965. usleep_range(1000, 2000);
  1966. /* igbvf_down has a dependency on max_frame_size */
  1967. adapter->max_frame_size = max_frame;
  1968. if (netif_running(netdev))
  1969. igbvf_down(adapter);
  1970. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  1971. * means we reserve 2 more, this pushes us to allocate from the next
  1972. * larger slab size.
  1973. * i.e. RXBUFFER_2048 --> size-4096 slab
  1974. * However with the new *_jumbo_rx* routines, jumbo receives will use
  1975. * fragmented skbs
  1976. */
  1977. if (max_frame <= 1024)
  1978. adapter->rx_buffer_len = 1024;
  1979. else if (max_frame <= 2048)
  1980. adapter->rx_buffer_len = 2048;
  1981. else
  1982. #if (PAGE_SIZE / 2) > 16384
  1983. adapter->rx_buffer_len = 16384;
  1984. #else
  1985. adapter->rx_buffer_len = PAGE_SIZE / 2;
  1986. #endif
  1987. /* adjust allocation if LPE protects us, and we aren't using SBP */
  1988. if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
  1989. (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
  1990. adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN +
  1991. ETH_FCS_LEN;
  1992. dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n",
  1993. netdev->mtu, new_mtu);
  1994. netdev->mtu = new_mtu;
  1995. if (netif_running(netdev))
  1996. igbvf_up(adapter);
  1997. else
  1998. igbvf_reset(adapter);
  1999. clear_bit(__IGBVF_RESETTING, &adapter->state);
  2000. return 0;
  2001. }
  2002. static int igbvf_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2003. {
  2004. switch (cmd) {
  2005. default:
  2006. return -EOPNOTSUPP;
  2007. }
  2008. }
  2009. static int igbvf_suspend(struct pci_dev *pdev, pm_message_t state)
  2010. {
  2011. struct net_device *netdev = pci_get_drvdata(pdev);
  2012. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2013. #ifdef CONFIG_PM
  2014. int retval = 0;
  2015. #endif
  2016. netif_device_detach(netdev);
  2017. if (netif_running(netdev)) {
  2018. WARN_ON(test_bit(__IGBVF_RESETTING, &adapter->state));
  2019. igbvf_down(adapter);
  2020. igbvf_free_irq(adapter);
  2021. }
  2022. #ifdef CONFIG_PM
  2023. retval = pci_save_state(pdev);
  2024. if (retval)
  2025. return retval;
  2026. #endif
  2027. pci_disable_device(pdev);
  2028. return 0;
  2029. }
  2030. #ifdef CONFIG_PM
  2031. static int igbvf_resume(struct pci_dev *pdev)
  2032. {
  2033. struct net_device *netdev = pci_get_drvdata(pdev);
  2034. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2035. u32 err;
  2036. pci_restore_state(pdev);
  2037. err = pci_enable_device_mem(pdev);
  2038. if (err) {
  2039. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  2040. return err;
  2041. }
  2042. pci_set_master(pdev);
  2043. if (netif_running(netdev)) {
  2044. err = igbvf_request_irq(adapter);
  2045. if (err)
  2046. return err;
  2047. }
  2048. igbvf_reset(adapter);
  2049. if (netif_running(netdev))
  2050. igbvf_up(adapter);
  2051. netif_device_attach(netdev);
  2052. return 0;
  2053. }
  2054. #endif
  2055. static void igbvf_shutdown(struct pci_dev *pdev)
  2056. {
  2057. igbvf_suspend(pdev, PMSG_SUSPEND);
  2058. }
  2059. #ifdef CONFIG_NET_POLL_CONTROLLER
  2060. /* Polling 'interrupt' - used by things like netconsole to send skbs
  2061. * without having to re-enable interrupts. It's not called while
  2062. * the interrupt routine is executing.
  2063. */
  2064. static void igbvf_netpoll(struct net_device *netdev)
  2065. {
  2066. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2067. disable_irq(adapter->pdev->irq);
  2068. igbvf_clean_tx_irq(adapter->tx_ring);
  2069. enable_irq(adapter->pdev->irq);
  2070. }
  2071. #endif
  2072. /**
  2073. * igbvf_io_error_detected - called when PCI error is detected
  2074. * @pdev: Pointer to PCI device
  2075. * @state: The current pci connection state
  2076. *
  2077. * This function is called after a PCI bus error affecting
  2078. * this device has been detected.
  2079. */
  2080. static pci_ers_result_t igbvf_io_error_detected(struct pci_dev *pdev,
  2081. pci_channel_state_t state)
  2082. {
  2083. struct net_device *netdev = pci_get_drvdata(pdev);
  2084. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2085. netif_device_detach(netdev);
  2086. if (state == pci_channel_io_perm_failure)
  2087. return PCI_ERS_RESULT_DISCONNECT;
  2088. if (netif_running(netdev))
  2089. igbvf_down(adapter);
  2090. pci_disable_device(pdev);
  2091. /* Request a slot slot reset. */
  2092. return PCI_ERS_RESULT_NEED_RESET;
  2093. }
  2094. /**
  2095. * igbvf_io_slot_reset - called after the pci bus has been reset.
  2096. * @pdev: Pointer to PCI device
  2097. *
  2098. * Restart the card from scratch, as if from a cold-boot. Implementation
  2099. * resembles the first-half of the igbvf_resume routine.
  2100. */
  2101. static pci_ers_result_t igbvf_io_slot_reset(struct pci_dev *pdev)
  2102. {
  2103. struct net_device *netdev = pci_get_drvdata(pdev);
  2104. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2105. if (pci_enable_device_mem(pdev)) {
  2106. dev_err(&pdev->dev,
  2107. "Cannot re-enable PCI device after reset.\n");
  2108. return PCI_ERS_RESULT_DISCONNECT;
  2109. }
  2110. pci_set_master(pdev);
  2111. igbvf_reset(adapter);
  2112. return PCI_ERS_RESULT_RECOVERED;
  2113. }
  2114. /**
  2115. * igbvf_io_resume - called when traffic can start flowing again.
  2116. * @pdev: Pointer to PCI device
  2117. *
  2118. * This callback is called when the error recovery driver tells us that
  2119. * its OK to resume normal operation. Implementation resembles the
  2120. * second-half of the igbvf_resume routine.
  2121. */
  2122. static void igbvf_io_resume(struct pci_dev *pdev)
  2123. {
  2124. struct net_device *netdev = pci_get_drvdata(pdev);
  2125. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2126. if (netif_running(netdev)) {
  2127. if (igbvf_up(adapter)) {
  2128. dev_err(&pdev->dev,
  2129. "can't bring device back up after reset\n");
  2130. return;
  2131. }
  2132. }
  2133. netif_device_attach(netdev);
  2134. }
  2135. static void igbvf_print_device_info(struct igbvf_adapter *adapter)
  2136. {
  2137. struct e1000_hw *hw = &adapter->hw;
  2138. struct net_device *netdev = adapter->netdev;
  2139. struct pci_dev *pdev = adapter->pdev;
  2140. if (hw->mac.type == e1000_vfadapt_i350)
  2141. dev_info(&pdev->dev, "Intel(R) I350 Virtual Function\n");
  2142. else
  2143. dev_info(&pdev->dev, "Intel(R) 82576 Virtual Function\n");
  2144. dev_info(&pdev->dev, "Address: %pM\n", netdev->dev_addr);
  2145. }
  2146. static int igbvf_set_features(struct net_device *netdev,
  2147. netdev_features_t features)
  2148. {
  2149. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2150. if (features & NETIF_F_RXCSUM)
  2151. adapter->flags &= ~IGBVF_FLAG_RX_CSUM_DISABLED;
  2152. else
  2153. adapter->flags |= IGBVF_FLAG_RX_CSUM_DISABLED;
  2154. return 0;
  2155. }
  2156. #define IGBVF_MAX_MAC_HDR_LEN 127
  2157. #define IGBVF_MAX_NETWORK_HDR_LEN 511
  2158. static netdev_features_t
  2159. igbvf_features_check(struct sk_buff *skb, struct net_device *dev,
  2160. netdev_features_t features)
  2161. {
  2162. unsigned int network_hdr_len, mac_hdr_len;
  2163. /* Make certain the headers can be described by a context descriptor */
  2164. mac_hdr_len = skb_network_header(skb) - skb->data;
  2165. if (unlikely(mac_hdr_len > IGBVF_MAX_MAC_HDR_LEN))
  2166. return features & ~(NETIF_F_HW_CSUM |
  2167. NETIF_F_SCTP_CRC |
  2168. NETIF_F_HW_VLAN_CTAG_TX |
  2169. NETIF_F_TSO |
  2170. NETIF_F_TSO6);
  2171. network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
  2172. if (unlikely(network_hdr_len > IGBVF_MAX_NETWORK_HDR_LEN))
  2173. return features & ~(NETIF_F_HW_CSUM |
  2174. NETIF_F_SCTP_CRC |
  2175. NETIF_F_TSO |
  2176. NETIF_F_TSO6);
  2177. /* We can only support IPV4 TSO in tunnels if we can mangle the
  2178. * inner IP ID field, so strip TSO if MANGLEID is not supported.
  2179. */
  2180. if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
  2181. features &= ~NETIF_F_TSO;
  2182. return features;
  2183. }
  2184. static const struct net_device_ops igbvf_netdev_ops = {
  2185. .ndo_open = igbvf_open,
  2186. .ndo_stop = igbvf_close,
  2187. .ndo_start_xmit = igbvf_xmit_frame,
  2188. .ndo_get_stats = igbvf_get_stats,
  2189. .ndo_set_rx_mode = igbvf_set_multi,
  2190. .ndo_set_mac_address = igbvf_set_mac,
  2191. .ndo_change_mtu = igbvf_change_mtu,
  2192. .ndo_do_ioctl = igbvf_ioctl,
  2193. .ndo_tx_timeout = igbvf_tx_timeout,
  2194. .ndo_vlan_rx_add_vid = igbvf_vlan_rx_add_vid,
  2195. .ndo_vlan_rx_kill_vid = igbvf_vlan_rx_kill_vid,
  2196. #ifdef CONFIG_NET_POLL_CONTROLLER
  2197. .ndo_poll_controller = igbvf_netpoll,
  2198. #endif
  2199. .ndo_set_features = igbvf_set_features,
  2200. .ndo_features_check = igbvf_features_check,
  2201. };
  2202. /**
  2203. * igbvf_probe - Device Initialization Routine
  2204. * @pdev: PCI device information struct
  2205. * @ent: entry in igbvf_pci_tbl
  2206. *
  2207. * Returns 0 on success, negative on failure
  2208. *
  2209. * igbvf_probe initializes an adapter identified by a pci_dev structure.
  2210. * The OS initialization, configuring of the adapter private structure,
  2211. * and a hardware reset occur.
  2212. **/
  2213. static int igbvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2214. {
  2215. struct net_device *netdev;
  2216. struct igbvf_adapter *adapter;
  2217. struct e1000_hw *hw;
  2218. const struct igbvf_info *ei = igbvf_info_tbl[ent->driver_data];
  2219. static int cards_found;
  2220. int err, pci_using_dac;
  2221. err = pci_enable_device_mem(pdev);
  2222. if (err)
  2223. return err;
  2224. pci_using_dac = 0;
  2225. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  2226. if (!err) {
  2227. pci_using_dac = 1;
  2228. } else {
  2229. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  2230. if (err) {
  2231. dev_err(&pdev->dev,
  2232. "No usable DMA configuration, aborting\n");
  2233. goto err_dma;
  2234. }
  2235. }
  2236. err = pci_request_regions(pdev, igbvf_driver_name);
  2237. if (err)
  2238. goto err_pci_reg;
  2239. pci_set_master(pdev);
  2240. err = -ENOMEM;
  2241. netdev = alloc_etherdev(sizeof(struct igbvf_adapter));
  2242. if (!netdev)
  2243. goto err_alloc_etherdev;
  2244. SET_NETDEV_DEV(netdev, &pdev->dev);
  2245. pci_set_drvdata(pdev, netdev);
  2246. adapter = netdev_priv(netdev);
  2247. hw = &adapter->hw;
  2248. adapter->netdev = netdev;
  2249. adapter->pdev = pdev;
  2250. adapter->ei = ei;
  2251. adapter->pba = ei->pba;
  2252. adapter->flags = ei->flags;
  2253. adapter->hw.back = adapter;
  2254. adapter->hw.mac.type = ei->mac;
  2255. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  2256. /* PCI config space info */
  2257. hw->vendor_id = pdev->vendor;
  2258. hw->device_id = pdev->device;
  2259. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  2260. hw->subsystem_device_id = pdev->subsystem_device;
  2261. hw->revision_id = pdev->revision;
  2262. err = -EIO;
  2263. adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, 0),
  2264. pci_resource_len(pdev, 0));
  2265. if (!adapter->hw.hw_addr)
  2266. goto err_ioremap;
  2267. if (ei->get_variants) {
  2268. err = ei->get_variants(adapter);
  2269. if (err)
  2270. goto err_get_variants;
  2271. }
  2272. /* setup adapter struct */
  2273. err = igbvf_sw_init(adapter);
  2274. if (err)
  2275. goto err_sw_init;
  2276. /* construct the net_device struct */
  2277. netdev->netdev_ops = &igbvf_netdev_ops;
  2278. igbvf_set_ethtool_ops(netdev);
  2279. netdev->watchdog_timeo = 5 * HZ;
  2280. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  2281. adapter->bd_number = cards_found++;
  2282. netdev->hw_features = NETIF_F_SG |
  2283. NETIF_F_TSO |
  2284. NETIF_F_TSO6 |
  2285. NETIF_F_RXCSUM |
  2286. NETIF_F_HW_CSUM |
  2287. NETIF_F_SCTP_CRC;
  2288. #define IGBVF_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
  2289. NETIF_F_GSO_GRE_CSUM | \
  2290. NETIF_F_GSO_IPXIP4 | \
  2291. NETIF_F_GSO_IPXIP6 | \
  2292. NETIF_F_GSO_UDP_TUNNEL | \
  2293. NETIF_F_GSO_UDP_TUNNEL_CSUM)
  2294. netdev->gso_partial_features = IGBVF_GSO_PARTIAL_FEATURES;
  2295. netdev->hw_features |= NETIF_F_GSO_PARTIAL |
  2296. IGBVF_GSO_PARTIAL_FEATURES;
  2297. netdev->features = netdev->hw_features;
  2298. if (pci_using_dac)
  2299. netdev->features |= NETIF_F_HIGHDMA;
  2300. netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
  2301. netdev->mpls_features |= NETIF_F_HW_CSUM;
  2302. netdev->hw_enc_features |= netdev->vlan_features;
  2303. /* set this bit last since it cannot be part of vlan_features */
  2304. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
  2305. NETIF_F_HW_VLAN_CTAG_RX |
  2306. NETIF_F_HW_VLAN_CTAG_TX;
  2307. /*reset the controller to put the device in a known good state */
  2308. err = hw->mac.ops.reset_hw(hw);
  2309. if (err) {
  2310. dev_info(&pdev->dev,
  2311. "PF still in reset state. Is the PF interface up?\n");
  2312. } else {
  2313. err = hw->mac.ops.read_mac_addr(hw);
  2314. if (err)
  2315. dev_info(&pdev->dev, "Error reading MAC address.\n");
  2316. else if (is_zero_ether_addr(adapter->hw.mac.addr))
  2317. dev_info(&pdev->dev,
  2318. "MAC address not assigned by administrator.\n");
  2319. memcpy(netdev->dev_addr, adapter->hw.mac.addr,
  2320. netdev->addr_len);
  2321. }
  2322. if (!is_valid_ether_addr(netdev->dev_addr)) {
  2323. dev_info(&pdev->dev, "Assigning random MAC address.\n");
  2324. eth_hw_addr_random(netdev);
  2325. memcpy(adapter->hw.mac.addr, netdev->dev_addr,
  2326. netdev->addr_len);
  2327. }
  2328. setup_timer(&adapter->watchdog_timer, &igbvf_watchdog,
  2329. (unsigned long)adapter);
  2330. INIT_WORK(&adapter->reset_task, igbvf_reset_task);
  2331. INIT_WORK(&adapter->watchdog_task, igbvf_watchdog_task);
  2332. /* ring size defaults */
  2333. adapter->rx_ring->count = 1024;
  2334. adapter->tx_ring->count = 1024;
  2335. /* reset the hardware with the new settings */
  2336. igbvf_reset(adapter);
  2337. /* set hardware-specific flags */
  2338. if (adapter->hw.mac.type == e1000_vfadapt_i350)
  2339. adapter->flags |= IGBVF_FLAG_RX_LB_VLAN_BSWAP;
  2340. strcpy(netdev->name, "eth%d");
  2341. err = register_netdev(netdev);
  2342. if (err)
  2343. goto err_hw_init;
  2344. /* tell the stack to leave us alone until igbvf_open() is called */
  2345. netif_carrier_off(netdev);
  2346. netif_stop_queue(netdev);
  2347. igbvf_print_device_info(adapter);
  2348. igbvf_initialize_last_counter_stats(adapter);
  2349. return 0;
  2350. err_hw_init:
  2351. kfree(adapter->tx_ring);
  2352. kfree(adapter->rx_ring);
  2353. err_sw_init:
  2354. igbvf_reset_interrupt_capability(adapter);
  2355. err_get_variants:
  2356. iounmap(adapter->hw.hw_addr);
  2357. err_ioremap:
  2358. free_netdev(netdev);
  2359. err_alloc_etherdev:
  2360. pci_release_regions(pdev);
  2361. err_pci_reg:
  2362. err_dma:
  2363. pci_disable_device(pdev);
  2364. return err;
  2365. }
  2366. /**
  2367. * igbvf_remove - Device Removal Routine
  2368. * @pdev: PCI device information struct
  2369. *
  2370. * igbvf_remove is called by the PCI subsystem to alert the driver
  2371. * that it should release a PCI device. The could be caused by a
  2372. * Hot-Plug event, or because the driver is going to be removed from
  2373. * memory.
  2374. **/
  2375. static void igbvf_remove(struct pci_dev *pdev)
  2376. {
  2377. struct net_device *netdev = pci_get_drvdata(pdev);
  2378. struct igbvf_adapter *adapter = netdev_priv(netdev);
  2379. struct e1000_hw *hw = &adapter->hw;
  2380. /* The watchdog timer may be rescheduled, so explicitly
  2381. * disable it from being rescheduled.
  2382. */
  2383. set_bit(__IGBVF_DOWN, &adapter->state);
  2384. del_timer_sync(&adapter->watchdog_timer);
  2385. cancel_work_sync(&adapter->reset_task);
  2386. cancel_work_sync(&adapter->watchdog_task);
  2387. unregister_netdev(netdev);
  2388. igbvf_reset_interrupt_capability(adapter);
  2389. /* it is important to delete the NAPI struct prior to freeing the
  2390. * Rx ring so that you do not end up with null pointer refs
  2391. */
  2392. netif_napi_del(&adapter->rx_ring->napi);
  2393. kfree(adapter->tx_ring);
  2394. kfree(adapter->rx_ring);
  2395. iounmap(hw->hw_addr);
  2396. if (hw->flash_address)
  2397. iounmap(hw->flash_address);
  2398. pci_release_regions(pdev);
  2399. free_netdev(netdev);
  2400. pci_disable_device(pdev);
  2401. }
  2402. /* PCI Error Recovery (ERS) */
  2403. static const struct pci_error_handlers igbvf_err_handler = {
  2404. .error_detected = igbvf_io_error_detected,
  2405. .slot_reset = igbvf_io_slot_reset,
  2406. .resume = igbvf_io_resume,
  2407. };
  2408. static const struct pci_device_id igbvf_pci_tbl[] = {
  2409. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_VF), board_vf },
  2410. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_VF), board_i350_vf },
  2411. { } /* terminate list */
  2412. };
  2413. MODULE_DEVICE_TABLE(pci, igbvf_pci_tbl);
  2414. /* PCI Device API Driver */
  2415. static struct pci_driver igbvf_driver = {
  2416. .name = igbvf_driver_name,
  2417. .id_table = igbvf_pci_tbl,
  2418. .probe = igbvf_probe,
  2419. .remove = igbvf_remove,
  2420. #ifdef CONFIG_PM
  2421. /* Power Management Hooks */
  2422. .suspend = igbvf_suspend,
  2423. .resume = igbvf_resume,
  2424. #endif
  2425. .shutdown = igbvf_shutdown,
  2426. .err_handler = &igbvf_err_handler
  2427. };
  2428. /**
  2429. * igbvf_init_module - Driver Registration Routine
  2430. *
  2431. * igbvf_init_module is the first routine called when the driver is
  2432. * loaded. All it does is register with the PCI subsystem.
  2433. **/
  2434. static int __init igbvf_init_module(void)
  2435. {
  2436. int ret;
  2437. pr_info("%s - version %s\n", igbvf_driver_string, igbvf_driver_version);
  2438. pr_info("%s\n", igbvf_copyright);
  2439. ret = pci_register_driver(&igbvf_driver);
  2440. return ret;
  2441. }
  2442. module_init(igbvf_init_module);
  2443. /**
  2444. * igbvf_exit_module - Driver Exit Cleanup Routine
  2445. *
  2446. * igbvf_exit_module is called just before the driver is removed
  2447. * from memory.
  2448. **/
  2449. static void __exit igbvf_exit_module(void)
  2450. {
  2451. pci_unregister_driver(&igbvf_driver);
  2452. }
  2453. module_exit(igbvf_exit_module);
  2454. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  2455. MODULE_DESCRIPTION("Intel(R) Gigabit Virtual Function Network Driver");
  2456. MODULE_LICENSE("GPL");
  2457. MODULE_VERSION(DRV_VERSION);
  2458. /* netdev.c */