igc_main.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018 Intel Corporation */
  3. #include <linux/module.h>
  4. #include <linux/types.h>
  5. #include <linux/if_vlan.h>
  6. #include <linux/aer.h>
  7. #include "igc.h"
  8. #include "igc_hw.h"
  9. #define DRV_VERSION "0.0.1-k"
  10. #define DRV_SUMMARY "Intel(R) 2.5G Ethernet Linux Driver"
  11. static int debug = -1;
  12. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  13. MODULE_DESCRIPTION(DRV_SUMMARY);
  14. MODULE_LICENSE("GPL v2");
  15. MODULE_VERSION(DRV_VERSION);
  16. module_param(debug, int, 0);
  17. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  18. char igc_driver_name[] = "igc";
  19. char igc_driver_version[] = DRV_VERSION;
  20. static const char igc_driver_string[] = DRV_SUMMARY;
  21. static const char igc_copyright[] =
  22. "Copyright(c) 2018 Intel Corporation.";
  23. static const struct pci_device_id igc_pci_tbl[] = {
  24. { PCI_VDEVICE(INTEL, IGC_DEV_ID_I225_LM) },
  25. { PCI_VDEVICE(INTEL, IGC_DEV_ID_I225_V) },
  26. /* required last entry */
  27. {0, }
  28. };
  29. MODULE_DEVICE_TABLE(pci, igc_pci_tbl);
  30. /* forward declaration */
  31. static void igc_clean_tx_ring(struct igc_ring *tx_ring);
  32. static int igc_sw_init(struct igc_adapter *);
  33. static void igc_configure(struct igc_adapter *adapter);
  34. static void igc_power_down_link(struct igc_adapter *adapter);
  35. static void igc_set_default_mac_filter(struct igc_adapter *adapter);
  36. static void igc_set_rx_mode(struct net_device *netdev);
  37. static void igc_write_itr(struct igc_q_vector *q_vector);
  38. static void igc_assign_vector(struct igc_q_vector *q_vector, int msix_vector);
  39. static void igc_free_q_vector(struct igc_adapter *adapter, int v_idx);
  40. static void igc_set_interrupt_capability(struct igc_adapter *adapter,
  41. bool msix);
  42. static void igc_free_q_vectors(struct igc_adapter *adapter);
  43. static void igc_irq_disable(struct igc_adapter *adapter);
  44. static void igc_irq_enable(struct igc_adapter *adapter);
  45. static void igc_configure_msix(struct igc_adapter *adapter);
  46. enum latency_range {
  47. lowest_latency = 0,
  48. low_latency = 1,
  49. bulk_latency = 2,
  50. latency_invalid = 255
  51. };
  52. static void igc_reset(struct igc_adapter *adapter)
  53. {
  54. if (!netif_running(adapter->netdev))
  55. igc_power_down_link(adapter);
  56. }
  57. /**
  58. * igc_power_up_link - Power up the phy/serdes link
  59. * @adapter: address of board private structure
  60. */
  61. static void igc_power_up_link(struct igc_adapter *adapter)
  62. {
  63. }
  64. /**
  65. * igc_power_down_link - Power down the phy/serdes link
  66. * @adapter: address of board private structure
  67. */
  68. static void igc_power_down_link(struct igc_adapter *adapter)
  69. {
  70. }
  71. /**
  72. * igc_release_hw_control - release control of the h/w to f/w
  73. * @adapter: address of board private structure
  74. *
  75. * igc_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
  76. * For ASF and Pass Through versions of f/w this means that the
  77. * driver is no longer loaded.
  78. */
  79. static void igc_release_hw_control(struct igc_adapter *adapter)
  80. {
  81. struct igc_hw *hw = &adapter->hw;
  82. u32 ctrl_ext;
  83. /* Let firmware take over control of h/w */
  84. ctrl_ext = rd32(IGC_CTRL_EXT);
  85. wr32(IGC_CTRL_EXT,
  86. ctrl_ext & ~IGC_CTRL_EXT_DRV_LOAD);
  87. }
  88. /**
  89. * igc_get_hw_control - get control of the h/w from f/w
  90. * @adapter: address of board private structure
  91. *
  92. * igc_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
  93. * For ASF and Pass Through versions of f/w this means that
  94. * the driver is loaded.
  95. */
  96. static void igc_get_hw_control(struct igc_adapter *adapter)
  97. {
  98. struct igc_hw *hw = &adapter->hw;
  99. u32 ctrl_ext;
  100. /* Let firmware know the driver has taken over */
  101. ctrl_ext = rd32(IGC_CTRL_EXT);
  102. wr32(IGC_CTRL_EXT,
  103. ctrl_ext | IGC_CTRL_EXT_DRV_LOAD);
  104. }
  105. /**
  106. * igc_free_tx_resources - Free Tx Resources per Queue
  107. * @tx_ring: Tx descriptor ring for a specific queue
  108. *
  109. * Free all transmit software resources
  110. */
  111. static void igc_free_tx_resources(struct igc_ring *tx_ring)
  112. {
  113. igc_clean_tx_ring(tx_ring);
  114. vfree(tx_ring->tx_buffer_info);
  115. tx_ring->tx_buffer_info = NULL;
  116. /* if not set, then don't free */
  117. if (!tx_ring->desc)
  118. return;
  119. dma_free_coherent(tx_ring->dev, tx_ring->size,
  120. tx_ring->desc, tx_ring->dma);
  121. tx_ring->desc = NULL;
  122. }
  123. /**
  124. * igc_free_all_tx_resources - Free Tx Resources for All Queues
  125. * @adapter: board private structure
  126. *
  127. * Free all transmit software resources
  128. */
  129. static void igc_free_all_tx_resources(struct igc_adapter *adapter)
  130. {
  131. int i;
  132. for (i = 0; i < adapter->num_tx_queues; i++)
  133. igc_free_tx_resources(adapter->tx_ring[i]);
  134. }
  135. /**
  136. * igc_clean_tx_ring - Free Tx Buffers
  137. * @tx_ring: ring to be cleaned
  138. */
  139. static void igc_clean_tx_ring(struct igc_ring *tx_ring)
  140. {
  141. u16 i = tx_ring->next_to_clean;
  142. struct igc_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
  143. while (i != tx_ring->next_to_use) {
  144. union igc_adv_tx_desc *eop_desc, *tx_desc;
  145. /* Free all the Tx ring sk_buffs */
  146. dev_kfree_skb_any(tx_buffer->skb);
  147. /* unmap skb header data */
  148. dma_unmap_single(tx_ring->dev,
  149. dma_unmap_addr(tx_buffer, dma),
  150. dma_unmap_len(tx_buffer, len),
  151. DMA_TO_DEVICE);
  152. /* check for eop_desc to determine the end of the packet */
  153. eop_desc = tx_buffer->next_to_watch;
  154. tx_desc = IGC_TX_DESC(tx_ring, i);
  155. /* unmap remaining buffers */
  156. while (tx_desc != eop_desc) {
  157. tx_buffer++;
  158. tx_desc++;
  159. i++;
  160. if (unlikely(i == tx_ring->count)) {
  161. i = 0;
  162. tx_buffer = tx_ring->tx_buffer_info;
  163. tx_desc = IGC_TX_DESC(tx_ring, 0);
  164. }
  165. /* unmap any remaining paged data */
  166. if (dma_unmap_len(tx_buffer, len))
  167. dma_unmap_page(tx_ring->dev,
  168. dma_unmap_addr(tx_buffer, dma),
  169. dma_unmap_len(tx_buffer, len),
  170. DMA_TO_DEVICE);
  171. }
  172. /* move us one more past the eop_desc for start of next pkt */
  173. tx_buffer++;
  174. i++;
  175. if (unlikely(i == tx_ring->count)) {
  176. i = 0;
  177. tx_buffer = tx_ring->tx_buffer_info;
  178. }
  179. }
  180. /* reset BQL for queue */
  181. netdev_tx_reset_queue(txring_txq(tx_ring));
  182. /* reset next_to_use and next_to_clean */
  183. tx_ring->next_to_use = 0;
  184. tx_ring->next_to_clean = 0;
  185. }
  186. /**
  187. * igc_setup_tx_resources - allocate Tx resources (Descriptors)
  188. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  189. *
  190. * Return 0 on success, negative on failure
  191. */
  192. static int igc_setup_tx_resources(struct igc_ring *tx_ring)
  193. {
  194. struct device *dev = tx_ring->dev;
  195. int size = 0;
  196. size = sizeof(struct igc_tx_buffer) * tx_ring->count;
  197. tx_ring->tx_buffer_info = vzalloc(size);
  198. if (!tx_ring->tx_buffer_info)
  199. goto err;
  200. /* round up to nearest 4K */
  201. tx_ring->size = tx_ring->count * sizeof(union igc_adv_tx_desc);
  202. tx_ring->size = ALIGN(tx_ring->size, 4096);
  203. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  204. &tx_ring->dma, GFP_KERNEL);
  205. if (!tx_ring->desc)
  206. goto err;
  207. tx_ring->next_to_use = 0;
  208. tx_ring->next_to_clean = 0;
  209. return 0;
  210. err:
  211. vfree(tx_ring->tx_buffer_info);
  212. dev_err(dev,
  213. "Unable to allocate memory for the transmit descriptor ring\n");
  214. return -ENOMEM;
  215. }
  216. /**
  217. * igc_setup_all_tx_resources - wrapper to allocate Tx resources for all queues
  218. * @adapter: board private structure
  219. *
  220. * Return 0 on success, negative on failure
  221. */
  222. static int igc_setup_all_tx_resources(struct igc_adapter *adapter)
  223. {
  224. struct pci_dev *pdev = adapter->pdev;
  225. int i, err = 0;
  226. for (i = 0; i < adapter->num_tx_queues; i++) {
  227. err = igc_setup_tx_resources(adapter->tx_ring[i]);
  228. if (err) {
  229. dev_err(&pdev->dev,
  230. "Allocation for Tx Queue %u failed\n", i);
  231. for (i--; i >= 0; i--)
  232. igc_free_tx_resources(adapter->tx_ring[i]);
  233. break;
  234. }
  235. }
  236. return err;
  237. }
  238. /**
  239. * igc_clean_rx_ring - Free Rx Buffers per Queue
  240. * @rx_ring: ring to free buffers from
  241. */
  242. static void igc_clean_rx_ring(struct igc_ring *rx_ring)
  243. {
  244. u16 i = rx_ring->next_to_clean;
  245. if (rx_ring->skb)
  246. dev_kfree_skb(rx_ring->skb);
  247. rx_ring->skb = NULL;
  248. /* Free all the Rx ring sk_buffs */
  249. while (i != rx_ring->next_to_alloc) {
  250. struct igc_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
  251. /* Invalidate cache lines that may have been written to by
  252. * device so that we avoid corrupting memory.
  253. */
  254. dma_sync_single_range_for_cpu(rx_ring->dev,
  255. buffer_info->dma,
  256. buffer_info->page_offset,
  257. igc_rx_bufsz(rx_ring),
  258. DMA_FROM_DEVICE);
  259. /* free resources associated with mapping */
  260. dma_unmap_page_attrs(rx_ring->dev,
  261. buffer_info->dma,
  262. igc_rx_pg_size(rx_ring),
  263. DMA_FROM_DEVICE,
  264. IGC_RX_DMA_ATTR);
  265. __page_frag_cache_drain(buffer_info->page,
  266. buffer_info->pagecnt_bias);
  267. i++;
  268. if (i == rx_ring->count)
  269. i = 0;
  270. }
  271. rx_ring->next_to_alloc = 0;
  272. rx_ring->next_to_clean = 0;
  273. rx_ring->next_to_use = 0;
  274. }
  275. /**
  276. * igc_free_rx_resources - Free Rx Resources
  277. * @rx_ring: ring to clean the resources from
  278. *
  279. * Free all receive software resources
  280. */
  281. static void igc_free_rx_resources(struct igc_ring *rx_ring)
  282. {
  283. igc_clean_rx_ring(rx_ring);
  284. vfree(rx_ring->rx_buffer_info);
  285. rx_ring->rx_buffer_info = NULL;
  286. /* if not set, then don't free */
  287. if (!rx_ring->desc)
  288. return;
  289. dma_free_coherent(rx_ring->dev, rx_ring->size,
  290. rx_ring->desc, rx_ring->dma);
  291. rx_ring->desc = NULL;
  292. }
  293. /**
  294. * igc_free_all_rx_resources - Free Rx Resources for All Queues
  295. * @adapter: board private structure
  296. *
  297. * Free all receive software resources
  298. */
  299. static void igc_free_all_rx_resources(struct igc_adapter *adapter)
  300. {
  301. int i;
  302. for (i = 0; i < adapter->num_rx_queues; i++)
  303. igc_free_rx_resources(adapter->rx_ring[i]);
  304. }
  305. /**
  306. * igc_setup_rx_resources - allocate Rx resources (Descriptors)
  307. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  308. *
  309. * Returns 0 on success, negative on failure
  310. */
  311. static int igc_setup_rx_resources(struct igc_ring *rx_ring)
  312. {
  313. struct device *dev = rx_ring->dev;
  314. int size, desc_len;
  315. size = sizeof(struct igc_rx_buffer) * rx_ring->count;
  316. rx_ring->rx_buffer_info = vzalloc(size);
  317. if (!rx_ring->rx_buffer_info)
  318. goto err;
  319. desc_len = sizeof(union igc_adv_rx_desc);
  320. /* Round up to nearest 4K */
  321. rx_ring->size = rx_ring->count * desc_len;
  322. rx_ring->size = ALIGN(rx_ring->size, 4096);
  323. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  324. &rx_ring->dma, GFP_KERNEL);
  325. if (!rx_ring->desc)
  326. goto err;
  327. rx_ring->next_to_alloc = 0;
  328. rx_ring->next_to_clean = 0;
  329. rx_ring->next_to_use = 0;
  330. return 0;
  331. err:
  332. vfree(rx_ring->rx_buffer_info);
  333. rx_ring->rx_buffer_info = NULL;
  334. dev_err(dev,
  335. "Unable to allocate memory for the receive descriptor ring\n");
  336. return -ENOMEM;
  337. }
  338. /**
  339. * igc_setup_all_rx_resources - wrapper to allocate Rx resources
  340. * (Descriptors) for all queues
  341. * @adapter: board private structure
  342. *
  343. * Return 0 on success, negative on failure
  344. */
  345. static int igc_setup_all_rx_resources(struct igc_adapter *adapter)
  346. {
  347. struct pci_dev *pdev = adapter->pdev;
  348. int i, err = 0;
  349. for (i = 0; i < adapter->num_rx_queues; i++) {
  350. err = igc_setup_rx_resources(adapter->rx_ring[i]);
  351. if (err) {
  352. dev_err(&pdev->dev,
  353. "Allocation for Rx Queue %u failed\n", i);
  354. for (i--; i >= 0; i--)
  355. igc_free_rx_resources(adapter->rx_ring[i]);
  356. break;
  357. }
  358. }
  359. return err;
  360. }
  361. /**
  362. * igc_configure_rx_ring - Configure a receive ring after Reset
  363. * @adapter: board private structure
  364. * @ring: receive ring to be configured
  365. *
  366. * Configure the Rx unit of the MAC after a reset.
  367. */
  368. static void igc_configure_rx_ring(struct igc_adapter *adapter,
  369. struct igc_ring *ring)
  370. {
  371. struct igc_hw *hw = &adapter->hw;
  372. union igc_adv_rx_desc *rx_desc;
  373. int reg_idx = ring->reg_idx;
  374. u32 srrctl = 0, rxdctl = 0;
  375. u64 rdba = ring->dma;
  376. /* disable the queue */
  377. wr32(IGC_RXDCTL(reg_idx), 0);
  378. /* Set DMA base address registers */
  379. wr32(IGC_RDBAL(reg_idx),
  380. rdba & 0x00000000ffffffffULL);
  381. wr32(IGC_RDBAH(reg_idx), rdba >> 32);
  382. wr32(IGC_RDLEN(reg_idx),
  383. ring->count * sizeof(union igc_adv_rx_desc));
  384. /* initialize head and tail */
  385. ring->tail = adapter->io_addr + IGC_RDT(reg_idx);
  386. wr32(IGC_RDH(reg_idx), 0);
  387. writel(0, ring->tail);
  388. /* reset next-to- use/clean to place SW in sync with hardware */
  389. ring->next_to_clean = 0;
  390. ring->next_to_use = 0;
  391. /* set descriptor configuration */
  392. srrctl = IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT;
  393. if (ring_uses_large_buffer(ring))
  394. srrctl |= IGC_RXBUFFER_3072 >> IGC_SRRCTL_BSIZEPKT_SHIFT;
  395. else
  396. srrctl |= IGC_RXBUFFER_2048 >> IGC_SRRCTL_BSIZEPKT_SHIFT;
  397. srrctl |= IGC_SRRCTL_DESCTYPE_ADV_ONEBUF;
  398. wr32(IGC_SRRCTL(reg_idx), srrctl);
  399. rxdctl |= IGC_RX_PTHRESH;
  400. rxdctl |= IGC_RX_HTHRESH << 8;
  401. rxdctl |= IGC_RX_WTHRESH << 16;
  402. /* initialize rx_buffer_info */
  403. memset(ring->rx_buffer_info, 0,
  404. sizeof(struct igc_rx_buffer) * ring->count);
  405. /* initialize Rx descriptor 0 */
  406. rx_desc = IGC_RX_DESC(ring, 0);
  407. rx_desc->wb.upper.length = 0;
  408. /* enable receive descriptor fetching */
  409. rxdctl |= IGC_RXDCTL_QUEUE_ENABLE;
  410. wr32(IGC_RXDCTL(reg_idx), rxdctl);
  411. }
  412. /**
  413. * igc_configure_rx - Configure receive Unit after Reset
  414. * @adapter: board private structure
  415. *
  416. * Configure the Rx unit of the MAC after a reset.
  417. */
  418. static void igc_configure_rx(struct igc_adapter *adapter)
  419. {
  420. int i;
  421. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  422. * the Base and Length of the Rx Descriptor Ring
  423. */
  424. for (i = 0; i < adapter->num_rx_queues; i++)
  425. igc_configure_rx_ring(adapter, adapter->rx_ring[i]);
  426. }
  427. /**
  428. * igc_configure_tx_ring - Configure transmit ring after Reset
  429. * @adapter: board private structure
  430. * @ring: tx ring to configure
  431. *
  432. * Configure a transmit ring after a reset.
  433. */
  434. static void igc_configure_tx_ring(struct igc_adapter *adapter,
  435. struct igc_ring *ring)
  436. {
  437. struct igc_hw *hw = &adapter->hw;
  438. int reg_idx = ring->reg_idx;
  439. u64 tdba = ring->dma;
  440. u32 txdctl = 0;
  441. /* disable the queue */
  442. wr32(IGC_TXDCTL(reg_idx), 0);
  443. wrfl();
  444. mdelay(10);
  445. wr32(IGC_TDLEN(reg_idx),
  446. ring->count * sizeof(union igc_adv_tx_desc));
  447. wr32(IGC_TDBAL(reg_idx),
  448. tdba & 0x00000000ffffffffULL);
  449. wr32(IGC_TDBAH(reg_idx), tdba >> 32);
  450. ring->tail = adapter->io_addr + IGC_TDT(reg_idx);
  451. wr32(IGC_TDH(reg_idx), 0);
  452. writel(0, ring->tail);
  453. txdctl |= IGC_TX_PTHRESH;
  454. txdctl |= IGC_TX_HTHRESH << 8;
  455. txdctl |= IGC_TX_WTHRESH << 16;
  456. txdctl |= IGC_TXDCTL_QUEUE_ENABLE;
  457. wr32(IGC_TXDCTL(reg_idx), txdctl);
  458. }
  459. /**
  460. * igc_configure_tx - Configure transmit Unit after Reset
  461. * @adapter: board private structure
  462. *
  463. * Configure the Tx unit of the MAC after a reset.
  464. */
  465. static void igc_configure_tx(struct igc_adapter *adapter)
  466. {
  467. int i;
  468. for (i = 0; i < adapter->num_tx_queues; i++)
  469. igc_configure_tx_ring(adapter, adapter->tx_ring[i]);
  470. }
  471. /**
  472. * igc_setup_mrqc - configure the multiple receive queue control registers
  473. * @adapter: Board private structure
  474. */
  475. static void igc_setup_mrqc(struct igc_adapter *adapter)
  476. {
  477. }
  478. /**
  479. * igc_setup_rctl - configure the receive control registers
  480. * @adapter: Board private structure
  481. */
  482. static void igc_setup_rctl(struct igc_adapter *adapter)
  483. {
  484. struct igc_hw *hw = &adapter->hw;
  485. u32 rctl;
  486. rctl = rd32(IGC_RCTL);
  487. rctl &= ~(3 << IGC_RCTL_MO_SHIFT);
  488. rctl &= ~(IGC_RCTL_LBM_TCVR | IGC_RCTL_LBM_MAC);
  489. rctl |= IGC_RCTL_EN | IGC_RCTL_BAM | IGC_RCTL_RDMTS_HALF |
  490. (hw->mac.mc_filter_type << IGC_RCTL_MO_SHIFT);
  491. /* enable stripping of CRC. Newer features require
  492. * that the HW strips the CRC.
  493. */
  494. rctl |= IGC_RCTL_SECRC;
  495. /* disable store bad packets and clear size bits. */
  496. rctl &= ~(IGC_RCTL_SBP | IGC_RCTL_SZ_256);
  497. /* enable LPE to allow for reception of jumbo frames */
  498. rctl |= IGC_RCTL_LPE;
  499. /* disable queue 0 to prevent tail write w/o re-config */
  500. wr32(IGC_RXDCTL(0), 0);
  501. /* This is useful for sniffing bad packets. */
  502. if (adapter->netdev->features & NETIF_F_RXALL) {
  503. /* UPE and MPE will be handled by normal PROMISC logic
  504. * in set_rx_mode
  505. */
  506. rctl |= (IGC_RCTL_SBP | /* Receive bad packets */
  507. IGC_RCTL_BAM | /* RX All Bcast Pkts */
  508. IGC_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
  509. rctl &= ~(IGC_RCTL_DPF | /* Allow filtered pause */
  510. IGC_RCTL_CFIEN); /* Disable VLAN CFIEN Filter */
  511. }
  512. wr32(IGC_RCTL, rctl);
  513. }
  514. /**
  515. * igc_setup_tctl - configure the transmit control registers
  516. * @adapter: Board private structure
  517. */
  518. static void igc_setup_tctl(struct igc_adapter *adapter)
  519. {
  520. struct igc_hw *hw = &adapter->hw;
  521. u32 tctl;
  522. /* disable queue 0 which icould be enabled by default */
  523. wr32(IGC_TXDCTL(0), 0);
  524. /* Program the Transmit Control Register */
  525. tctl = rd32(IGC_TCTL);
  526. tctl &= ~IGC_TCTL_CT;
  527. tctl |= IGC_TCTL_PSP | IGC_TCTL_RTLC |
  528. (IGC_COLLISION_THRESHOLD << IGC_CT_SHIFT);
  529. /* Enable transmits */
  530. tctl |= IGC_TCTL_EN;
  531. wr32(IGC_TCTL, tctl);
  532. }
  533. /**
  534. * igc_set_mac - Change the Ethernet Address of the NIC
  535. * @netdev: network interface device structure
  536. * @p: pointer to an address structure
  537. *
  538. * Returns 0 on success, negative on failure
  539. */
  540. static int igc_set_mac(struct net_device *netdev, void *p)
  541. {
  542. struct igc_adapter *adapter = netdev_priv(netdev);
  543. struct igc_hw *hw = &adapter->hw;
  544. struct sockaddr *addr = p;
  545. if (!is_valid_ether_addr(addr->sa_data))
  546. return -EADDRNOTAVAIL;
  547. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  548. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  549. /* set the correct pool for the new PF MAC address in entry 0 */
  550. igc_set_default_mac_filter(adapter);
  551. return 0;
  552. }
  553. static netdev_tx_t igc_xmit_frame(struct sk_buff *skb,
  554. struct net_device *netdev)
  555. {
  556. dev_kfree_skb_any(skb);
  557. return NETDEV_TX_OK;
  558. }
  559. static inline unsigned int igc_rx_offset(struct igc_ring *rx_ring)
  560. {
  561. return ring_uses_build_skb(rx_ring) ? IGC_SKB_PAD : 0;
  562. }
  563. static bool igc_alloc_mapped_page(struct igc_ring *rx_ring,
  564. struct igc_rx_buffer *bi)
  565. {
  566. struct page *page = bi->page;
  567. dma_addr_t dma;
  568. /* since we are recycling buffers we should seldom need to alloc */
  569. if (likely(page))
  570. return true;
  571. /* alloc new page for storage */
  572. page = dev_alloc_pages(igc_rx_pg_order(rx_ring));
  573. if (unlikely(!page)) {
  574. rx_ring->rx_stats.alloc_failed++;
  575. return false;
  576. }
  577. /* map page for use */
  578. dma = dma_map_page_attrs(rx_ring->dev, page, 0,
  579. igc_rx_pg_size(rx_ring),
  580. DMA_FROM_DEVICE,
  581. IGC_RX_DMA_ATTR);
  582. /* if mapping failed free memory back to system since
  583. * there isn't much point in holding memory we can't use
  584. */
  585. if (dma_mapping_error(rx_ring->dev, dma)) {
  586. __free_page(page);
  587. rx_ring->rx_stats.alloc_failed++;
  588. return false;
  589. }
  590. bi->dma = dma;
  591. bi->page = page;
  592. bi->page_offset = igc_rx_offset(rx_ring);
  593. bi->pagecnt_bias = 1;
  594. return true;
  595. }
  596. /**
  597. * igc_alloc_rx_buffers - Replace used receive buffers; packet split
  598. * @adapter: address of board private structure
  599. */
  600. static void igc_alloc_rx_buffers(struct igc_ring *rx_ring, u16 cleaned_count)
  601. {
  602. union igc_adv_rx_desc *rx_desc;
  603. u16 i = rx_ring->next_to_use;
  604. struct igc_rx_buffer *bi;
  605. u16 bufsz;
  606. /* nothing to do */
  607. if (!cleaned_count)
  608. return;
  609. rx_desc = IGC_RX_DESC(rx_ring, i);
  610. bi = &rx_ring->rx_buffer_info[i];
  611. i -= rx_ring->count;
  612. bufsz = igc_rx_bufsz(rx_ring);
  613. do {
  614. if (!igc_alloc_mapped_page(rx_ring, bi))
  615. break;
  616. /* sync the buffer for use by the device */
  617. dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
  618. bi->page_offset, bufsz,
  619. DMA_FROM_DEVICE);
  620. /* Refresh the desc even if buffer_addrs didn't change
  621. * because each write-back erases this info.
  622. */
  623. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  624. rx_desc++;
  625. bi++;
  626. i++;
  627. if (unlikely(!i)) {
  628. rx_desc = IGC_RX_DESC(rx_ring, 0);
  629. bi = rx_ring->rx_buffer_info;
  630. i -= rx_ring->count;
  631. }
  632. /* clear the length for the next_to_use descriptor */
  633. rx_desc->wb.upper.length = 0;
  634. cleaned_count--;
  635. } while (cleaned_count);
  636. i += rx_ring->count;
  637. if (rx_ring->next_to_use != i) {
  638. /* record the next descriptor to use */
  639. rx_ring->next_to_use = i;
  640. /* update next to alloc since we have filled the ring */
  641. rx_ring->next_to_alloc = i;
  642. /* Force memory writes to complete before letting h/w
  643. * know there are new descriptors to fetch. (Only
  644. * applicable for weak-ordered memory model archs,
  645. * such as IA-64).
  646. */
  647. wmb();
  648. writel(i, rx_ring->tail);
  649. }
  650. }
  651. /**
  652. * igc_ioctl - I/O control method
  653. * @netdev: network interface device structure
  654. * @ifreq: frequency
  655. * @cmd: command
  656. */
  657. static int igc_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  658. {
  659. switch (cmd) {
  660. default:
  661. return -EOPNOTSUPP;
  662. }
  663. }
  664. /**
  665. * igc_up - Open the interface and prepare it to handle traffic
  666. * @adapter: board private structure
  667. */
  668. static void igc_up(struct igc_adapter *adapter)
  669. {
  670. struct igc_hw *hw = &adapter->hw;
  671. int i = 0;
  672. /* hardware has been reset, we need to reload some things */
  673. igc_configure(adapter);
  674. clear_bit(__IGC_DOWN, &adapter->state);
  675. for (i = 0; i < adapter->num_q_vectors; i++)
  676. napi_enable(&adapter->q_vector[i]->napi);
  677. if (adapter->msix_entries)
  678. igc_configure_msix(adapter);
  679. else
  680. igc_assign_vector(adapter->q_vector[0], 0);
  681. /* Clear any pending interrupts. */
  682. rd32(IGC_ICR);
  683. igc_irq_enable(adapter);
  684. netif_tx_start_all_queues(adapter->netdev);
  685. /* start the watchdog. */
  686. hw->mac.get_link_status = 1;
  687. }
  688. /**
  689. * igc_update_stats - Update the board statistics counters
  690. * @adapter: board private structure
  691. */
  692. static void igc_update_stats(struct igc_adapter *adapter)
  693. {
  694. }
  695. /**
  696. * igc_down - Close the interface
  697. * @adapter: board private structure
  698. */
  699. static void igc_down(struct igc_adapter *adapter)
  700. {
  701. struct net_device *netdev = adapter->netdev;
  702. int i = 0;
  703. set_bit(__IGC_DOWN, &adapter->state);
  704. /* set trans_start so we don't get spurious watchdogs during reset */
  705. netif_trans_update(netdev);
  706. netif_carrier_off(netdev);
  707. netif_tx_stop_all_queues(netdev);
  708. for (i = 0; i < adapter->num_q_vectors; i++)
  709. napi_disable(&adapter->q_vector[i]->napi);
  710. adapter->link_speed = 0;
  711. adapter->link_duplex = 0;
  712. }
  713. /**
  714. * igc_change_mtu - Change the Maximum Transfer Unit
  715. * @netdev: network interface device structure
  716. * @new_mtu: new value for maximum frame size
  717. *
  718. * Returns 0 on success, negative on failure
  719. */
  720. static int igc_change_mtu(struct net_device *netdev, int new_mtu)
  721. {
  722. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  723. struct igc_adapter *adapter = netdev_priv(netdev);
  724. struct pci_dev *pdev = adapter->pdev;
  725. /* adjust max frame to be at least the size of a standard frame */
  726. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  727. max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
  728. while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
  729. usleep_range(1000, 2000);
  730. /* igc_down has a dependency on max_frame_size */
  731. adapter->max_frame_size = max_frame;
  732. if (netif_running(netdev))
  733. igc_down(adapter);
  734. dev_info(&pdev->dev, "changing MTU from %d to %d\n",
  735. netdev->mtu, new_mtu);
  736. netdev->mtu = new_mtu;
  737. if (netif_running(netdev))
  738. igc_up(adapter);
  739. else
  740. igc_reset(adapter);
  741. clear_bit(__IGC_RESETTING, &adapter->state);
  742. return 0;
  743. }
  744. /**
  745. * igc_get_stats - Get System Network Statistics
  746. * @netdev: network interface device structure
  747. *
  748. * Returns the address of the device statistics structure.
  749. * The statistics are updated here and also from the timer callback.
  750. */
  751. static struct net_device_stats *igc_get_stats(struct net_device *netdev)
  752. {
  753. struct igc_adapter *adapter = netdev_priv(netdev);
  754. if (!test_bit(__IGC_RESETTING, &adapter->state))
  755. igc_update_stats(adapter);
  756. /* only return the current stats */
  757. return &netdev->stats;
  758. }
  759. /**
  760. * igc_configure - configure the hardware for RX and TX
  761. * @adapter: private board structure
  762. */
  763. static void igc_configure(struct igc_adapter *adapter)
  764. {
  765. struct net_device *netdev = adapter->netdev;
  766. int i = 0;
  767. igc_get_hw_control(adapter);
  768. igc_set_rx_mode(netdev);
  769. igc_setup_tctl(adapter);
  770. igc_setup_mrqc(adapter);
  771. igc_setup_rctl(adapter);
  772. igc_configure_tx(adapter);
  773. igc_configure_rx(adapter);
  774. igc_rx_fifo_flush_base(&adapter->hw);
  775. /* call igc_desc_unused which always leaves
  776. * at least 1 descriptor unused to make sure
  777. * next_to_use != next_to_clean
  778. */
  779. for (i = 0; i < adapter->num_rx_queues; i++) {
  780. struct igc_ring *ring = adapter->rx_ring[i];
  781. igc_alloc_rx_buffers(ring, igc_desc_unused(ring));
  782. }
  783. }
  784. /**
  785. * igc_rar_set_index - Sync RAL[index] and RAH[index] registers with MAC table
  786. * @adapter: Pointer to adapter structure
  787. * @index: Index of the RAR entry which need to be synced with MAC table
  788. */
  789. static void igc_rar_set_index(struct igc_adapter *adapter, u32 index)
  790. {
  791. u8 *addr = adapter->mac_table[index].addr;
  792. struct igc_hw *hw = &adapter->hw;
  793. u32 rar_low, rar_high;
  794. /* HW expects these to be in network order when they are plugged
  795. * into the registers which are little endian. In order to guarantee
  796. * that ordering we need to do an leXX_to_cpup here in order to be
  797. * ready for the byteswap that occurs with writel
  798. */
  799. rar_low = le32_to_cpup((__le32 *)(addr));
  800. rar_high = le16_to_cpup((__le16 *)(addr + 4));
  801. /* Indicate to hardware the Address is Valid. */
  802. if (adapter->mac_table[index].state & IGC_MAC_STATE_IN_USE) {
  803. if (is_valid_ether_addr(addr))
  804. rar_high |= IGC_RAH_AV;
  805. rar_high |= IGC_RAH_POOL_1 <<
  806. adapter->mac_table[index].queue;
  807. }
  808. wr32(IGC_RAL(index), rar_low);
  809. wrfl();
  810. wr32(IGC_RAH(index), rar_high);
  811. wrfl();
  812. }
  813. /* Set default MAC address for the PF in the first RAR entry */
  814. static void igc_set_default_mac_filter(struct igc_adapter *adapter)
  815. {
  816. struct igc_mac_addr *mac_table = &adapter->mac_table[0];
  817. ether_addr_copy(mac_table->addr, adapter->hw.mac.addr);
  818. mac_table->state = IGC_MAC_STATE_DEFAULT | IGC_MAC_STATE_IN_USE;
  819. igc_rar_set_index(adapter, 0);
  820. }
  821. /**
  822. * igc_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
  823. * @netdev: network interface device structure
  824. *
  825. * The set_rx_mode entry point is called whenever the unicast or multicast
  826. * address lists or the network interface flags are updated. This routine is
  827. * responsible for configuring the hardware for proper unicast, multicast,
  828. * promiscuous mode, and all-multi behavior.
  829. */
  830. static void igc_set_rx_mode(struct net_device *netdev)
  831. {
  832. }
  833. /**
  834. * igc_msix_other - msix other interrupt handler
  835. * @irq: interrupt number
  836. * @data: pointer to a q_vector
  837. */
  838. static irqreturn_t igc_msix_other(int irq, void *data)
  839. {
  840. struct igc_adapter *adapter = data;
  841. struct igc_hw *hw = &adapter->hw;
  842. u32 icr = rd32(IGC_ICR);
  843. /* reading ICR causes bit 31 of EICR to be cleared */
  844. if (icr & IGC_ICR_DRSTA)
  845. schedule_work(&adapter->reset_task);
  846. if (icr & IGC_ICR_DOUTSYNC) {
  847. /* HW is reporting DMA is out of sync */
  848. adapter->stats.doosync++;
  849. }
  850. if (icr & IGC_ICR_LSC) {
  851. hw->mac.get_link_status = 1;
  852. /* guard against interrupt when we're going down */
  853. if (!test_bit(__IGC_DOWN, &adapter->state))
  854. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  855. }
  856. wr32(IGC_EIMS, adapter->eims_other);
  857. return IRQ_HANDLED;
  858. }
  859. /**
  860. * igc_write_ivar - configure ivar for given MSI-X vector
  861. * @hw: pointer to the HW structure
  862. * @msix_vector: vector number we are allocating to a given ring
  863. * @index: row index of IVAR register to write within IVAR table
  864. * @offset: column offset of in IVAR, should be multiple of 8
  865. *
  866. * The IVAR table consists of 2 columns,
  867. * each containing an cause allocation for an Rx and Tx ring, and a
  868. * variable number of rows depending on the number of queues supported.
  869. */
  870. static void igc_write_ivar(struct igc_hw *hw, int msix_vector,
  871. int index, int offset)
  872. {
  873. u32 ivar = array_rd32(IGC_IVAR0, index);
  874. /* clear any bits that are currently set */
  875. ivar &= ~((u32)0xFF << offset);
  876. /* write vector and valid bit */
  877. ivar |= (msix_vector | IGC_IVAR_VALID) << offset;
  878. array_wr32(IGC_IVAR0, index, ivar);
  879. }
  880. static void igc_assign_vector(struct igc_q_vector *q_vector, int msix_vector)
  881. {
  882. struct igc_adapter *adapter = q_vector->adapter;
  883. struct igc_hw *hw = &adapter->hw;
  884. int rx_queue = IGC_N0_QUEUE;
  885. int tx_queue = IGC_N0_QUEUE;
  886. if (q_vector->rx.ring)
  887. rx_queue = q_vector->rx.ring->reg_idx;
  888. if (q_vector->tx.ring)
  889. tx_queue = q_vector->tx.ring->reg_idx;
  890. switch (hw->mac.type) {
  891. case igc_i225:
  892. if (rx_queue > IGC_N0_QUEUE)
  893. igc_write_ivar(hw, msix_vector,
  894. rx_queue >> 1,
  895. (rx_queue & 0x1) << 4);
  896. if (tx_queue > IGC_N0_QUEUE)
  897. igc_write_ivar(hw, msix_vector,
  898. tx_queue >> 1,
  899. ((tx_queue & 0x1) << 4) + 8);
  900. q_vector->eims_value = BIT(msix_vector);
  901. break;
  902. default:
  903. WARN_ONCE(hw->mac.type != igc_i225, "Wrong MAC type\n");
  904. break;
  905. }
  906. /* add q_vector eims value to global eims_enable_mask */
  907. adapter->eims_enable_mask |= q_vector->eims_value;
  908. /* configure q_vector to set itr on first interrupt */
  909. q_vector->set_itr = 1;
  910. }
  911. /**
  912. * igc_configure_msix - Configure MSI-X hardware
  913. * @adapter: Pointer to adapter structure
  914. *
  915. * igc_configure_msix sets up the hardware to properly
  916. * generate MSI-X interrupts.
  917. */
  918. static void igc_configure_msix(struct igc_adapter *adapter)
  919. {
  920. struct igc_hw *hw = &adapter->hw;
  921. int i, vector = 0;
  922. u32 tmp;
  923. adapter->eims_enable_mask = 0;
  924. /* set vector for other causes, i.e. link changes */
  925. switch (hw->mac.type) {
  926. case igc_i225:
  927. /* Turn on MSI-X capability first, or our settings
  928. * won't stick. And it will take days to debug.
  929. */
  930. wr32(IGC_GPIE, IGC_GPIE_MSIX_MODE |
  931. IGC_GPIE_PBA | IGC_GPIE_EIAME |
  932. IGC_GPIE_NSICR);
  933. /* enable msix_other interrupt */
  934. adapter->eims_other = BIT(vector);
  935. tmp = (vector++ | IGC_IVAR_VALID) << 8;
  936. wr32(IGC_IVAR_MISC, tmp);
  937. break;
  938. default:
  939. /* do nothing, since nothing else supports MSI-X */
  940. break;
  941. } /* switch (hw->mac.type) */
  942. adapter->eims_enable_mask |= adapter->eims_other;
  943. for (i = 0; i < adapter->num_q_vectors; i++)
  944. igc_assign_vector(adapter->q_vector[i], vector++);
  945. wrfl();
  946. }
  947. static irqreturn_t igc_msix_ring(int irq, void *data)
  948. {
  949. struct igc_q_vector *q_vector = data;
  950. /* Write the ITR value calculated from the previous interrupt. */
  951. igc_write_itr(q_vector);
  952. napi_schedule(&q_vector->napi);
  953. return IRQ_HANDLED;
  954. }
  955. /**
  956. * igc_request_msix - Initialize MSI-X interrupts
  957. * @adapter: Pointer to adapter structure
  958. *
  959. * igc_request_msix allocates MSI-X vectors and requests interrupts from the
  960. * kernel.
  961. */
  962. static int igc_request_msix(struct igc_adapter *adapter)
  963. {
  964. int i = 0, err = 0, vector = 0, free_vector = 0;
  965. struct net_device *netdev = adapter->netdev;
  966. err = request_irq(adapter->msix_entries[vector].vector,
  967. &igc_msix_other, 0, netdev->name, adapter);
  968. if (err)
  969. goto err_out;
  970. for (i = 0; i < adapter->num_q_vectors; i++) {
  971. struct igc_q_vector *q_vector = adapter->q_vector[i];
  972. vector++;
  973. q_vector->itr_register = adapter->io_addr + IGC_EITR(vector);
  974. if (q_vector->rx.ring && q_vector->tx.ring)
  975. sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
  976. q_vector->rx.ring->queue_index);
  977. else if (q_vector->tx.ring)
  978. sprintf(q_vector->name, "%s-tx-%u", netdev->name,
  979. q_vector->tx.ring->queue_index);
  980. else if (q_vector->rx.ring)
  981. sprintf(q_vector->name, "%s-rx-%u", netdev->name,
  982. q_vector->rx.ring->queue_index);
  983. else
  984. sprintf(q_vector->name, "%s-unused", netdev->name);
  985. err = request_irq(adapter->msix_entries[vector].vector,
  986. igc_msix_ring, 0, q_vector->name,
  987. q_vector);
  988. if (err)
  989. goto err_free;
  990. }
  991. igc_configure_msix(adapter);
  992. return 0;
  993. err_free:
  994. /* free already assigned IRQs */
  995. free_irq(adapter->msix_entries[free_vector++].vector, adapter);
  996. vector--;
  997. for (i = 0; i < vector; i++) {
  998. free_irq(adapter->msix_entries[free_vector++].vector,
  999. adapter->q_vector[i]);
  1000. }
  1001. err_out:
  1002. return err;
  1003. }
  1004. /**
  1005. * igc_reset_q_vector - Reset config for interrupt vector
  1006. * @adapter: board private structure to initialize
  1007. * @v_idx: Index of vector to be reset
  1008. *
  1009. * If NAPI is enabled it will delete any references to the
  1010. * NAPI struct. This is preparation for igc_free_q_vector.
  1011. */
  1012. static void igc_reset_q_vector(struct igc_adapter *adapter, int v_idx)
  1013. {
  1014. struct igc_q_vector *q_vector = adapter->q_vector[v_idx];
  1015. /* if we're coming from igc_set_interrupt_capability, the vectors are
  1016. * not yet allocated
  1017. */
  1018. if (!q_vector)
  1019. return;
  1020. if (q_vector->tx.ring)
  1021. adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
  1022. if (q_vector->rx.ring)
  1023. adapter->rx_ring[q_vector->rx.ring->queue_index] = NULL;
  1024. netif_napi_del(&q_vector->napi);
  1025. }
  1026. static void igc_reset_interrupt_capability(struct igc_adapter *adapter)
  1027. {
  1028. int v_idx = adapter->num_q_vectors;
  1029. if (adapter->msix_entries) {
  1030. pci_disable_msix(adapter->pdev);
  1031. kfree(adapter->msix_entries);
  1032. adapter->msix_entries = NULL;
  1033. } else if (adapter->flags & IGC_FLAG_HAS_MSI) {
  1034. pci_disable_msi(adapter->pdev);
  1035. }
  1036. while (v_idx--)
  1037. igc_reset_q_vector(adapter, v_idx);
  1038. }
  1039. /**
  1040. * igc_clear_interrupt_scheme - reset the device to a state of no interrupts
  1041. * @adapter: Pointer to adapter structure
  1042. *
  1043. * This function resets the device so that it has 0 rx queues, tx queues, and
  1044. * MSI-X interrupts allocated.
  1045. */
  1046. static void igc_clear_interrupt_scheme(struct igc_adapter *adapter)
  1047. {
  1048. igc_free_q_vectors(adapter);
  1049. igc_reset_interrupt_capability(adapter);
  1050. }
  1051. /**
  1052. * igc_free_q_vectors - Free memory allocated for interrupt vectors
  1053. * @adapter: board private structure to initialize
  1054. *
  1055. * This function frees the memory allocated to the q_vectors. In addition if
  1056. * NAPI is enabled it will delete any references to the NAPI struct prior
  1057. * to freeing the q_vector.
  1058. */
  1059. static void igc_free_q_vectors(struct igc_adapter *adapter)
  1060. {
  1061. int v_idx = adapter->num_q_vectors;
  1062. adapter->num_tx_queues = 0;
  1063. adapter->num_rx_queues = 0;
  1064. adapter->num_q_vectors = 0;
  1065. while (v_idx--) {
  1066. igc_reset_q_vector(adapter, v_idx);
  1067. igc_free_q_vector(adapter, v_idx);
  1068. }
  1069. }
  1070. /**
  1071. * igc_free_q_vector - Free memory allocated for specific interrupt vector
  1072. * @adapter: board private structure to initialize
  1073. * @v_idx: Index of vector to be freed
  1074. *
  1075. * This function frees the memory allocated to the q_vector.
  1076. */
  1077. static void igc_free_q_vector(struct igc_adapter *adapter, int v_idx)
  1078. {
  1079. struct igc_q_vector *q_vector = adapter->q_vector[v_idx];
  1080. adapter->q_vector[v_idx] = NULL;
  1081. /* igc_get_stats64() might access the rings on this vector,
  1082. * we must wait a grace period before freeing it.
  1083. */
  1084. if (q_vector)
  1085. kfree_rcu(q_vector, rcu);
  1086. }
  1087. /**
  1088. * igc_update_ring_itr - update the dynamic ITR value based on packet size
  1089. * @q_vector: pointer to q_vector
  1090. *
  1091. * Stores a new ITR value based on strictly on packet size. This
  1092. * algorithm is less sophisticated than that used in igc_update_itr,
  1093. * due to the difficulty of synchronizing statistics across multiple
  1094. * receive rings. The divisors and thresholds used by this function
  1095. * were determined based on theoretical maximum wire speed and testing
  1096. * data, in order to minimize response time while increasing bulk
  1097. * throughput.
  1098. * NOTE: This function is called only when operating in a multiqueue
  1099. * receive environment.
  1100. */
  1101. static void igc_update_ring_itr(struct igc_q_vector *q_vector)
  1102. {
  1103. struct igc_adapter *adapter = q_vector->adapter;
  1104. int new_val = q_vector->itr_val;
  1105. int avg_wire_size = 0;
  1106. unsigned int packets;
  1107. /* For non-gigabit speeds, just fix the interrupt rate at 4000
  1108. * ints/sec - ITR timer value of 120 ticks.
  1109. */
  1110. switch (adapter->link_speed) {
  1111. case SPEED_10:
  1112. case SPEED_100:
  1113. new_val = IGC_4K_ITR;
  1114. goto set_itr_val;
  1115. default:
  1116. break;
  1117. }
  1118. packets = q_vector->rx.total_packets;
  1119. if (packets)
  1120. avg_wire_size = q_vector->rx.total_bytes / packets;
  1121. packets = q_vector->tx.total_packets;
  1122. if (packets)
  1123. avg_wire_size = max_t(u32, avg_wire_size,
  1124. q_vector->tx.total_bytes / packets);
  1125. /* if avg_wire_size isn't set no work was done */
  1126. if (!avg_wire_size)
  1127. goto clear_counts;
  1128. /* Add 24 bytes to size to account for CRC, preamble, and gap */
  1129. avg_wire_size += 24;
  1130. /* Don't starve jumbo frames */
  1131. avg_wire_size = min(avg_wire_size, 3000);
  1132. /* Give a little boost to mid-size frames */
  1133. if (avg_wire_size > 300 && avg_wire_size < 1200)
  1134. new_val = avg_wire_size / 3;
  1135. else
  1136. new_val = avg_wire_size / 2;
  1137. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  1138. if (new_val < IGC_20K_ITR &&
  1139. ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
  1140. (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
  1141. new_val = IGC_20K_ITR;
  1142. set_itr_val:
  1143. if (new_val != q_vector->itr_val) {
  1144. q_vector->itr_val = new_val;
  1145. q_vector->set_itr = 1;
  1146. }
  1147. clear_counts:
  1148. q_vector->rx.total_bytes = 0;
  1149. q_vector->rx.total_packets = 0;
  1150. q_vector->tx.total_bytes = 0;
  1151. q_vector->tx.total_packets = 0;
  1152. }
  1153. /**
  1154. * igc_update_itr - update the dynamic ITR value based on statistics
  1155. * @q_vector: pointer to q_vector
  1156. * @ring_container: ring info to update the itr for
  1157. *
  1158. * Stores a new ITR value based on packets and byte
  1159. * counts during the last interrupt. The advantage of per interrupt
  1160. * computation is faster updates and more accurate ITR for the current
  1161. * traffic pattern. Constants in this function were computed
  1162. * based on theoretical maximum wire speed and thresholds were set based
  1163. * on testing data as well as attempting to minimize response time
  1164. * while increasing bulk throughput.
  1165. * NOTE: These calculations are only valid when operating in a single-
  1166. * queue environment.
  1167. */
  1168. static void igc_update_itr(struct igc_q_vector *q_vector,
  1169. struct igc_ring_container *ring_container)
  1170. {
  1171. unsigned int packets = ring_container->total_packets;
  1172. unsigned int bytes = ring_container->total_bytes;
  1173. u8 itrval = ring_container->itr;
  1174. /* no packets, exit with status unchanged */
  1175. if (packets == 0)
  1176. return;
  1177. switch (itrval) {
  1178. case lowest_latency:
  1179. /* handle TSO and jumbo frames */
  1180. if (bytes / packets > 8000)
  1181. itrval = bulk_latency;
  1182. else if ((packets < 5) && (bytes > 512))
  1183. itrval = low_latency;
  1184. break;
  1185. case low_latency: /* 50 usec aka 20000 ints/s */
  1186. if (bytes > 10000) {
  1187. /* this if handles the TSO accounting */
  1188. if (bytes / packets > 8000)
  1189. itrval = bulk_latency;
  1190. else if ((packets < 10) || ((bytes / packets) > 1200))
  1191. itrval = bulk_latency;
  1192. else if ((packets > 35))
  1193. itrval = lowest_latency;
  1194. } else if (bytes / packets > 2000) {
  1195. itrval = bulk_latency;
  1196. } else if (packets <= 2 && bytes < 512) {
  1197. itrval = lowest_latency;
  1198. }
  1199. break;
  1200. case bulk_latency: /* 250 usec aka 4000 ints/s */
  1201. if (bytes > 25000) {
  1202. if (packets > 35)
  1203. itrval = low_latency;
  1204. } else if (bytes < 1500) {
  1205. itrval = low_latency;
  1206. }
  1207. break;
  1208. }
  1209. /* clear work counters since we have the values we need */
  1210. ring_container->total_bytes = 0;
  1211. ring_container->total_packets = 0;
  1212. /* write updated itr to ring container */
  1213. ring_container->itr = itrval;
  1214. }
  1215. /**
  1216. * igc_intr_msi - Interrupt Handler
  1217. * @irq: interrupt number
  1218. * @data: pointer to a network interface device structure
  1219. */
  1220. static irqreturn_t igc_intr_msi(int irq, void *data)
  1221. {
  1222. struct igc_adapter *adapter = data;
  1223. struct igc_q_vector *q_vector = adapter->q_vector[0];
  1224. struct igc_hw *hw = &adapter->hw;
  1225. /* read ICR disables interrupts using IAM */
  1226. u32 icr = rd32(IGC_ICR);
  1227. igc_write_itr(q_vector);
  1228. if (icr & IGC_ICR_DRSTA)
  1229. schedule_work(&adapter->reset_task);
  1230. if (icr & IGC_ICR_DOUTSYNC) {
  1231. /* HW is reporting DMA is out of sync */
  1232. adapter->stats.doosync++;
  1233. }
  1234. if (icr & (IGC_ICR_RXSEQ | IGC_ICR_LSC)) {
  1235. hw->mac.get_link_status = 1;
  1236. if (!test_bit(__IGC_DOWN, &adapter->state))
  1237. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1238. }
  1239. napi_schedule(&q_vector->napi);
  1240. return IRQ_HANDLED;
  1241. }
  1242. /**
  1243. * igc_intr - Legacy Interrupt Handler
  1244. * @irq: interrupt number
  1245. * @data: pointer to a network interface device structure
  1246. */
  1247. static irqreturn_t igc_intr(int irq, void *data)
  1248. {
  1249. struct igc_adapter *adapter = data;
  1250. struct igc_q_vector *q_vector = adapter->q_vector[0];
  1251. struct igc_hw *hw = &adapter->hw;
  1252. /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
  1253. * need for the IMC write
  1254. */
  1255. u32 icr = rd32(IGC_ICR);
  1256. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  1257. * not set, then the adapter didn't send an interrupt
  1258. */
  1259. if (!(icr & IGC_ICR_INT_ASSERTED))
  1260. return IRQ_NONE;
  1261. igc_write_itr(q_vector);
  1262. if (icr & IGC_ICR_DRSTA)
  1263. schedule_work(&adapter->reset_task);
  1264. if (icr & IGC_ICR_DOUTSYNC) {
  1265. /* HW is reporting DMA is out of sync */
  1266. adapter->stats.doosync++;
  1267. }
  1268. if (icr & (IGC_ICR_RXSEQ | IGC_ICR_LSC)) {
  1269. hw->mac.get_link_status = 1;
  1270. /* guard against interrupt when we're going down */
  1271. if (!test_bit(__IGC_DOWN, &adapter->state))
  1272. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1273. }
  1274. napi_schedule(&q_vector->napi);
  1275. return IRQ_HANDLED;
  1276. }
  1277. static void igc_set_itr(struct igc_q_vector *q_vector)
  1278. {
  1279. struct igc_adapter *adapter = q_vector->adapter;
  1280. u32 new_itr = q_vector->itr_val;
  1281. u8 current_itr = 0;
  1282. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  1283. switch (adapter->link_speed) {
  1284. case SPEED_10:
  1285. case SPEED_100:
  1286. current_itr = 0;
  1287. new_itr = IGC_4K_ITR;
  1288. goto set_itr_now;
  1289. default:
  1290. break;
  1291. }
  1292. igc_update_itr(q_vector, &q_vector->tx);
  1293. igc_update_itr(q_vector, &q_vector->rx);
  1294. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  1295. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  1296. if (current_itr == lowest_latency &&
  1297. ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
  1298. (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
  1299. current_itr = low_latency;
  1300. switch (current_itr) {
  1301. /* counts and packets in update_itr are dependent on these numbers */
  1302. case lowest_latency:
  1303. new_itr = IGC_70K_ITR; /* 70,000 ints/sec */
  1304. break;
  1305. case low_latency:
  1306. new_itr = IGC_20K_ITR; /* 20,000 ints/sec */
  1307. break;
  1308. case bulk_latency:
  1309. new_itr = IGC_4K_ITR; /* 4,000 ints/sec */
  1310. break;
  1311. default:
  1312. break;
  1313. }
  1314. set_itr_now:
  1315. if (new_itr != q_vector->itr_val) {
  1316. /* this attempts to bias the interrupt rate towards Bulk
  1317. * by adding intermediate steps when interrupt rate is
  1318. * increasing
  1319. */
  1320. new_itr = new_itr > q_vector->itr_val ?
  1321. max((new_itr * q_vector->itr_val) /
  1322. (new_itr + (q_vector->itr_val >> 2)),
  1323. new_itr) : new_itr;
  1324. /* Don't write the value here; it resets the adapter's
  1325. * internal timer, and causes us to delay far longer than
  1326. * we should between interrupts. Instead, we write the ITR
  1327. * value at the beginning of the next interrupt so the timing
  1328. * ends up being correct.
  1329. */
  1330. q_vector->itr_val = new_itr;
  1331. q_vector->set_itr = 1;
  1332. }
  1333. }
  1334. static void igc_ring_irq_enable(struct igc_q_vector *q_vector)
  1335. {
  1336. struct igc_adapter *adapter = q_vector->adapter;
  1337. struct igc_hw *hw = &adapter->hw;
  1338. if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
  1339. (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
  1340. if (adapter->num_q_vectors == 1)
  1341. igc_set_itr(q_vector);
  1342. else
  1343. igc_update_ring_itr(q_vector);
  1344. }
  1345. if (!test_bit(__IGC_DOWN, &adapter->state)) {
  1346. if (adapter->msix_entries)
  1347. wr32(IGC_EIMS, q_vector->eims_value);
  1348. else
  1349. igc_irq_enable(adapter);
  1350. }
  1351. }
  1352. /**
  1353. * igc_poll - NAPI Rx polling callback
  1354. * @napi: napi polling structure
  1355. * @budget: count of how many packets we should handle
  1356. */
  1357. static int igc_poll(struct napi_struct *napi, int budget)
  1358. {
  1359. struct igc_q_vector *q_vector = container_of(napi,
  1360. struct igc_q_vector,
  1361. napi);
  1362. bool clean_complete = true;
  1363. int work_done = 0;
  1364. int cleaned = 0;
  1365. if (q_vector->rx.ring) {
  1366. work_done += cleaned;
  1367. if (cleaned >= budget)
  1368. clean_complete = false;
  1369. }
  1370. /* If all work not completed, return budget and keep polling */
  1371. if (!clean_complete)
  1372. return budget;
  1373. /* If not enough Rx work done, exit the polling mode */
  1374. napi_complete_done(napi, work_done);
  1375. igc_ring_irq_enable(q_vector);
  1376. return 0;
  1377. }
  1378. /**
  1379. * igc_set_interrupt_capability - set MSI or MSI-X if supported
  1380. * @adapter: Pointer to adapter structure
  1381. *
  1382. * Attempt to configure interrupts using the best available
  1383. * capabilities of the hardware and kernel.
  1384. */
  1385. static void igc_set_interrupt_capability(struct igc_adapter *adapter,
  1386. bool msix)
  1387. {
  1388. int numvecs, i;
  1389. int err;
  1390. if (!msix)
  1391. goto msi_only;
  1392. adapter->flags |= IGC_FLAG_HAS_MSIX;
  1393. /* Number of supported queues. */
  1394. adapter->num_rx_queues = adapter->rss_queues;
  1395. adapter->num_tx_queues = adapter->rss_queues;
  1396. /* start with one vector for every Rx queue */
  1397. numvecs = adapter->num_rx_queues;
  1398. /* if Tx handler is separate add 1 for every Tx queue */
  1399. if (!(adapter->flags & IGC_FLAG_QUEUE_PAIRS))
  1400. numvecs += adapter->num_tx_queues;
  1401. /* store the number of vectors reserved for queues */
  1402. adapter->num_q_vectors = numvecs;
  1403. /* add 1 vector for link status interrupts */
  1404. numvecs++;
  1405. adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
  1406. GFP_KERNEL);
  1407. if (!adapter->msix_entries)
  1408. return;
  1409. /* populate entry values */
  1410. for (i = 0; i < numvecs; i++)
  1411. adapter->msix_entries[i].entry = i;
  1412. err = pci_enable_msix_range(adapter->pdev,
  1413. adapter->msix_entries,
  1414. numvecs,
  1415. numvecs);
  1416. if (err > 0)
  1417. return;
  1418. kfree(adapter->msix_entries);
  1419. adapter->msix_entries = NULL;
  1420. igc_reset_interrupt_capability(adapter);
  1421. msi_only:
  1422. adapter->flags &= ~IGC_FLAG_HAS_MSIX;
  1423. adapter->rss_queues = 1;
  1424. adapter->flags |= IGC_FLAG_QUEUE_PAIRS;
  1425. adapter->num_rx_queues = 1;
  1426. adapter->num_tx_queues = 1;
  1427. adapter->num_q_vectors = 1;
  1428. if (!pci_enable_msi(adapter->pdev))
  1429. adapter->flags |= IGC_FLAG_HAS_MSI;
  1430. }
  1431. static void igc_add_ring(struct igc_ring *ring,
  1432. struct igc_ring_container *head)
  1433. {
  1434. head->ring = ring;
  1435. head->count++;
  1436. }
  1437. /**
  1438. * igc_alloc_q_vector - Allocate memory for a single interrupt vector
  1439. * @adapter: board private structure to initialize
  1440. * @v_count: q_vectors allocated on adapter, used for ring interleaving
  1441. * @v_idx: index of vector in adapter struct
  1442. * @txr_count: total number of Tx rings to allocate
  1443. * @txr_idx: index of first Tx ring to allocate
  1444. * @rxr_count: total number of Rx rings to allocate
  1445. * @rxr_idx: index of first Rx ring to allocate
  1446. *
  1447. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  1448. */
  1449. static int igc_alloc_q_vector(struct igc_adapter *adapter,
  1450. unsigned int v_count, unsigned int v_idx,
  1451. unsigned int txr_count, unsigned int txr_idx,
  1452. unsigned int rxr_count, unsigned int rxr_idx)
  1453. {
  1454. struct igc_q_vector *q_vector;
  1455. struct igc_ring *ring;
  1456. int ring_count, size;
  1457. /* igc only supports 1 Tx and/or 1 Rx queue per vector */
  1458. if (txr_count > 1 || rxr_count > 1)
  1459. return -ENOMEM;
  1460. ring_count = txr_count + rxr_count;
  1461. size = sizeof(struct igc_q_vector) +
  1462. (sizeof(struct igc_ring) * ring_count);
  1463. /* allocate q_vector and rings */
  1464. q_vector = adapter->q_vector[v_idx];
  1465. if (!q_vector)
  1466. q_vector = kzalloc(size, GFP_KERNEL);
  1467. else
  1468. memset(q_vector, 0, size);
  1469. if (!q_vector)
  1470. return -ENOMEM;
  1471. /* initialize NAPI */
  1472. netif_napi_add(adapter->netdev, &q_vector->napi,
  1473. igc_poll, 64);
  1474. /* tie q_vector and adapter together */
  1475. adapter->q_vector[v_idx] = q_vector;
  1476. q_vector->adapter = adapter;
  1477. /* initialize work limits */
  1478. q_vector->tx.work_limit = adapter->tx_work_limit;
  1479. /* initialize ITR configuration */
  1480. q_vector->itr_register = adapter->io_addr + IGC_EITR(0);
  1481. q_vector->itr_val = IGC_START_ITR;
  1482. /* initialize pointer to rings */
  1483. ring = q_vector->ring;
  1484. /* initialize ITR */
  1485. if (rxr_count) {
  1486. /* rx or rx/tx vector */
  1487. if (!adapter->rx_itr_setting || adapter->rx_itr_setting > 3)
  1488. q_vector->itr_val = adapter->rx_itr_setting;
  1489. } else {
  1490. /* tx only vector */
  1491. if (!adapter->tx_itr_setting || adapter->tx_itr_setting > 3)
  1492. q_vector->itr_val = adapter->tx_itr_setting;
  1493. }
  1494. if (txr_count) {
  1495. /* assign generic ring traits */
  1496. ring->dev = &adapter->pdev->dev;
  1497. ring->netdev = adapter->netdev;
  1498. /* configure backlink on ring */
  1499. ring->q_vector = q_vector;
  1500. /* update q_vector Tx values */
  1501. igc_add_ring(ring, &q_vector->tx);
  1502. /* apply Tx specific ring traits */
  1503. ring->count = adapter->tx_ring_count;
  1504. ring->queue_index = txr_idx;
  1505. /* assign ring to adapter */
  1506. adapter->tx_ring[txr_idx] = ring;
  1507. /* push pointer to next ring */
  1508. ring++;
  1509. }
  1510. if (rxr_count) {
  1511. /* assign generic ring traits */
  1512. ring->dev = &adapter->pdev->dev;
  1513. ring->netdev = adapter->netdev;
  1514. /* configure backlink on ring */
  1515. ring->q_vector = q_vector;
  1516. /* update q_vector Rx values */
  1517. igc_add_ring(ring, &q_vector->rx);
  1518. /* apply Rx specific ring traits */
  1519. ring->count = adapter->rx_ring_count;
  1520. ring->queue_index = rxr_idx;
  1521. /* assign ring to adapter */
  1522. adapter->rx_ring[rxr_idx] = ring;
  1523. }
  1524. return 0;
  1525. }
  1526. /**
  1527. * igc_alloc_q_vectors - Allocate memory for interrupt vectors
  1528. * @adapter: board private structure to initialize
  1529. *
  1530. * We allocate one q_vector per queue interrupt. If allocation fails we
  1531. * return -ENOMEM.
  1532. */
  1533. static int igc_alloc_q_vectors(struct igc_adapter *adapter)
  1534. {
  1535. int rxr_remaining = adapter->num_rx_queues;
  1536. int txr_remaining = adapter->num_tx_queues;
  1537. int rxr_idx = 0, txr_idx = 0, v_idx = 0;
  1538. int q_vectors = adapter->num_q_vectors;
  1539. int err;
  1540. if (q_vectors >= (rxr_remaining + txr_remaining)) {
  1541. for (; rxr_remaining; v_idx++) {
  1542. err = igc_alloc_q_vector(adapter, q_vectors, v_idx,
  1543. 0, 0, 1, rxr_idx);
  1544. if (err)
  1545. goto err_out;
  1546. /* update counts and index */
  1547. rxr_remaining--;
  1548. rxr_idx++;
  1549. }
  1550. }
  1551. for (; v_idx < q_vectors; v_idx++) {
  1552. int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
  1553. int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
  1554. err = igc_alloc_q_vector(adapter, q_vectors, v_idx,
  1555. tqpv, txr_idx, rqpv, rxr_idx);
  1556. if (err)
  1557. goto err_out;
  1558. /* update counts and index */
  1559. rxr_remaining -= rqpv;
  1560. txr_remaining -= tqpv;
  1561. rxr_idx++;
  1562. txr_idx++;
  1563. }
  1564. return 0;
  1565. err_out:
  1566. adapter->num_tx_queues = 0;
  1567. adapter->num_rx_queues = 0;
  1568. adapter->num_q_vectors = 0;
  1569. while (v_idx--)
  1570. igc_free_q_vector(adapter, v_idx);
  1571. return -ENOMEM;
  1572. }
  1573. /**
  1574. * igc_cache_ring_register - Descriptor ring to register mapping
  1575. * @adapter: board private structure to initialize
  1576. *
  1577. * Once we know the feature-set enabled for the device, we'll cache
  1578. * the register offset the descriptor ring is assigned to.
  1579. */
  1580. static void igc_cache_ring_register(struct igc_adapter *adapter)
  1581. {
  1582. int i = 0, j = 0;
  1583. switch (adapter->hw.mac.type) {
  1584. case igc_i225:
  1585. /* Fall through */
  1586. default:
  1587. for (; i < adapter->num_rx_queues; i++)
  1588. adapter->rx_ring[i]->reg_idx = i;
  1589. for (; j < adapter->num_tx_queues; j++)
  1590. adapter->tx_ring[j]->reg_idx = j;
  1591. break;
  1592. }
  1593. }
  1594. /**
  1595. * igc_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
  1596. * @adapter: Pointer to adapter structure
  1597. *
  1598. * This function initializes the interrupts and allocates all of the queues.
  1599. */
  1600. static int igc_init_interrupt_scheme(struct igc_adapter *adapter, bool msix)
  1601. {
  1602. struct pci_dev *pdev = adapter->pdev;
  1603. int err = 0;
  1604. igc_set_interrupt_capability(adapter, msix);
  1605. err = igc_alloc_q_vectors(adapter);
  1606. if (err) {
  1607. dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
  1608. goto err_alloc_q_vectors;
  1609. }
  1610. igc_cache_ring_register(adapter);
  1611. return 0;
  1612. err_alloc_q_vectors:
  1613. igc_reset_interrupt_capability(adapter);
  1614. return err;
  1615. }
  1616. static void igc_free_irq(struct igc_adapter *adapter)
  1617. {
  1618. if (adapter->msix_entries) {
  1619. int vector = 0, i;
  1620. free_irq(adapter->msix_entries[vector++].vector, adapter);
  1621. for (i = 0; i < adapter->num_q_vectors; i++)
  1622. free_irq(adapter->msix_entries[vector++].vector,
  1623. adapter->q_vector[i]);
  1624. } else {
  1625. free_irq(adapter->pdev->irq, adapter);
  1626. }
  1627. }
  1628. /**
  1629. * igc_irq_disable - Mask off interrupt generation on the NIC
  1630. * @adapter: board private structure
  1631. */
  1632. static void igc_irq_disable(struct igc_adapter *adapter)
  1633. {
  1634. struct igc_hw *hw = &adapter->hw;
  1635. if (adapter->msix_entries) {
  1636. u32 regval = rd32(IGC_EIAM);
  1637. wr32(IGC_EIAM, regval & ~adapter->eims_enable_mask);
  1638. wr32(IGC_EIMC, adapter->eims_enable_mask);
  1639. regval = rd32(IGC_EIAC);
  1640. wr32(IGC_EIAC, regval & ~adapter->eims_enable_mask);
  1641. }
  1642. wr32(IGC_IAM, 0);
  1643. wr32(IGC_IMC, ~0);
  1644. wrfl();
  1645. if (adapter->msix_entries) {
  1646. int vector = 0, i;
  1647. synchronize_irq(adapter->msix_entries[vector++].vector);
  1648. for (i = 0; i < adapter->num_q_vectors; i++)
  1649. synchronize_irq(adapter->msix_entries[vector++].vector);
  1650. } else {
  1651. synchronize_irq(adapter->pdev->irq);
  1652. }
  1653. }
  1654. /**
  1655. * igc_irq_enable - Enable default interrupt generation settings
  1656. * @adapter: board private structure
  1657. */
  1658. static void igc_irq_enable(struct igc_adapter *adapter)
  1659. {
  1660. struct igc_hw *hw = &adapter->hw;
  1661. if (adapter->msix_entries) {
  1662. u32 ims = IGC_IMS_LSC | IGC_IMS_DOUTSYNC | IGC_IMS_DRSTA;
  1663. u32 regval = rd32(IGC_EIAC);
  1664. wr32(IGC_EIAC, regval | adapter->eims_enable_mask);
  1665. regval = rd32(IGC_EIAM);
  1666. wr32(IGC_EIAM, regval | adapter->eims_enable_mask);
  1667. wr32(IGC_EIMS, adapter->eims_enable_mask);
  1668. wr32(IGC_IMS, ims);
  1669. } else {
  1670. wr32(IGC_IMS, IMS_ENABLE_MASK | IGC_IMS_DRSTA);
  1671. wr32(IGC_IAM, IMS_ENABLE_MASK | IGC_IMS_DRSTA);
  1672. }
  1673. }
  1674. /**
  1675. * igc_request_irq - initialize interrupts
  1676. * @adapter: Pointer to adapter structure
  1677. *
  1678. * Attempts to configure interrupts using the best available
  1679. * capabilities of the hardware and kernel.
  1680. */
  1681. static int igc_request_irq(struct igc_adapter *adapter)
  1682. {
  1683. struct net_device *netdev = adapter->netdev;
  1684. struct pci_dev *pdev = adapter->pdev;
  1685. int err = 0;
  1686. if (adapter->flags & IGC_FLAG_HAS_MSIX) {
  1687. err = igc_request_msix(adapter);
  1688. if (!err)
  1689. goto request_done;
  1690. /* fall back to MSI */
  1691. igc_free_all_tx_resources(adapter);
  1692. igc_free_all_rx_resources(adapter);
  1693. igc_clear_interrupt_scheme(adapter);
  1694. err = igc_init_interrupt_scheme(adapter, false);
  1695. if (err)
  1696. goto request_done;
  1697. igc_setup_all_tx_resources(adapter);
  1698. igc_setup_all_rx_resources(adapter);
  1699. igc_configure(adapter);
  1700. }
  1701. igc_assign_vector(adapter->q_vector[0], 0);
  1702. if (adapter->flags & IGC_FLAG_HAS_MSI) {
  1703. err = request_irq(pdev->irq, &igc_intr_msi, 0,
  1704. netdev->name, adapter);
  1705. if (!err)
  1706. goto request_done;
  1707. /* fall back to legacy interrupts */
  1708. igc_reset_interrupt_capability(adapter);
  1709. adapter->flags &= ~IGC_FLAG_HAS_MSI;
  1710. }
  1711. err = request_irq(pdev->irq, &igc_intr, IRQF_SHARED,
  1712. netdev->name, adapter);
  1713. if (err)
  1714. dev_err(&pdev->dev, "Error %d getting interrupt\n",
  1715. err);
  1716. request_done:
  1717. return err;
  1718. }
  1719. static void igc_write_itr(struct igc_q_vector *q_vector)
  1720. {
  1721. u32 itr_val = q_vector->itr_val & IGC_QVECTOR_MASK;
  1722. if (!q_vector->set_itr)
  1723. return;
  1724. if (!itr_val)
  1725. itr_val = IGC_ITR_VAL_MASK;
  1726. itr_val |= IGC_EITR_CNT_IGNR;
  1727. writel(itr_val, q_vector->itr_register);
  1728. q_vector->set_itr = 0;
  1729. }
  1730. /**
  1731. * igc_open - Called when a network interface is made active
  1732. * @netdev: network interface device structure
  1733. *
  1734. * Returns 0 on success, negative value on failure
  1735. *
  1736. * The open entry point is called when a network interface is made
  1737. * active by the system (IFF_UP). At this point all resources needed
  1738. * for transmit and receive operations are allocated, the interrupt
  1739. * handler is registered with the OS, the watchdog timer is started,
  1740. * and the stack is notified that the interface is ready.
  1741. */
  1742. static int __igc_open(struct net_device *netdev, bool resuming)
  1743. {
  1744. struct igc_adapter *adapter = netdev_priv(netdev);
  1745. struct igc_hw *hw = &adapter->hw;
  1746. int err = 0;
  1747. int i = 0;
  1748. /* disallow open during test */
  1749. if (test_bit(__IGC_TESTING, &adapter->state)) {
  1750. WARN_ON(resuming);
  1751. return -EBUSY;
  1752. }
  1753. netif_carrier_off(netdev);
  1754. /* allocate transmit descriptors */
  1755. err = igc_setup_all_tx_resources(adapter);
  1756. if (err)
  1757. goto err_setup_tx;
  1758. /* allocate receive descriptors */
  1759. err = igc_setup_all_rx_resources(adapter);
  1760. if (err)
  1761. goto err_setup_rx;
  1762. igc_power_up_link(adapter);
  1763. igc_configure(adapter);
  1764. err = igc_request_irq(adapter);
  1765. if (err)
  1766. goto err_req_irq;
  1767. /* Notify the stack of the actual queue counts. */
  1768. netif_set_real_num_tx_queues(netdev, adapter->num_tx_queues);
  1769. if (err)
  1770. goto err_set_queues;
  1771. err = netif_set_real_num_rx_queues(netdev, adapter->num_rx_queues);
  1772. if (err)
  1773. goto err_set_queues;
  1774. clear_bit(__IGC_DOWN, &adapter->state);
  1775. for (i = 0; i < adapter->num_q_vectors; i++)
  1776. napi_enable(&adapter->q_vector[i]->napi);
  1777. /* Clear any pending interrupts. */
  1778. rd32(IGC_ICR);
  1779. igc_irq_enable(adapter);
  1780. netif_tx_start_all_queues(netdev);
  1781. /* start the watchdog. */
  1782. hw->mac.get_link_status = 1;
  1783. return IGC_SUCCESS;
  1784. err_set_queues:
  1785. igc_free_irq(adapter);
  1786. err_req_irq:
  1787. igc_release_hw_control(adapter);
  1788. igc_power_down_link(adapter);
  1789. igc_free_all_rx_resources(adapter);
  1790. err_setup_rx:
  1791. igc_free_all_tx_resources(adapter);
  1792. err_setup_tx:
  1793. igc_reset(adapter);
  1794. return err;
  1795. }
  1796. static int igc_open(struct net_device *netdev)
  1797. {
  1798. return __igc_open(netdev, false);
  1799. }
  1800. /**
  1801. * igc_close - Disables a network interface
  1802. * @netdev: network interface device structure
  1803. *
  1804. * Returns 0, this is not allowed to fail
  1805. *
  1806. * The close entry point is called when an interface is de-activated
  1807. * by the OS. The hardware is still under the driver's control, but
  1808. * needs to be disabled. A global MAC reset is issued to stop the
  1809. * hardware, and all transmit and receive resources are freed.
  1810. */
  1811. static int __igc_close(struct net_device *netdev, bool suspending)
  1812. {
  1813. struct igc_adapter *adapter = netdev_priv(netdev);
  1814. WARN_ON(test_bit(__IGC_RESETTING, &adapter->state));
  1815. igc_down(adapter);
  1816. igc_release_hw_control(adapter);
  1817. igc_free_irq(adapter);
  1818. igc_free_all_tx_resources(adapter);
  1819. igc_free_all_rx_resources(adapter);
  1820. return 0;
  1821. }
  1822. static int igc_close(struct net_device *netdev)
  1823. {
  1824. if (netif_device_present(netdev) || netdev->dismantle)
  1825. return __igc_close(netdev, false);
  1826. return 0;
  1827. }
  1828. static const struct net_device_ops igc_netdev_ops = {
  1829. .ndo_open = igc_open,
  1830. .ndo_stop = igc_close,
  1831. .ndo_start_xmit = igc_xmit_frame,
  1832. .ndo_set_mac_address = igc_set_mac,
  1833. .ndo_change_mtu = igc_change_mtu,
  1834. .ndo_get_stats = igc_get_stats,
  1835. .ndo_do_ioctl = igc_ioctl,
  1836. };
  1837. /* PCIe configuration access */
  1838. void igc_read_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value)
  1839. {
  1840. struct igc_adapter *adapter = hw->back;
  1841. pci_read_config_word(adapter->pdev, reg, value);
  1842. }
  1843. void igc_write_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value)
  1844. {
  1845. struct igc_adapter *adapter = hw->back;
  1846. pci_write_config_word(adapter->pdev, reg, *value);
  1847. }
  1848. s32 igc_read_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value)
  1849. {
  1850. struct igc_adapter *adapter = hw->back;
  1851. u16 cap_offset;
  1852. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  1853. if (!cap_offset)
  1854. return -IGC_ERR_CONFIG;
  1855. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  1856. return IGC_SUCCESS;
  1857. }
  1858. s32 igc_write_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value)
  1859. {
  1860. struct igc_adapter *adapter = hw->back;
  1861. u16 cap_offset;
  1862. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  1863. if (!cap_offset)
  1864. return -IGC_ERR_CONFIG;
  1865. pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
  1866. return IGC_SUCCESS;
  1867. }
  1868. u32 igc_rd32(struct igc_hw *hw, u32 reg)
  1869. {
  1870. struct igc_adapter *igc = container_of(hw, struct igc_adapter, hw);
  1871. u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr);
  1872. u32 value = 0;
  1873. if (IGC_REMOVED(hw_addr))
  1874. return ~value;
  1875. value = readl(&hw_addr[reg]);
  1876. /* reads should not return all F's */
  1877. if (!(~value) && (!reg || !(~readl(hw_addr)))) {
  1878. struct net_device *netdev = igc->netdev;
  1879. hw->hw_addr = NULL;
  1880. netif_device_detach(netdev);
  1881. netdev_err(netdev, "PCIe link lost, device now detached\n");
  1882. }
  1883. return value;
  1884. }
  1885. /**
  1886. * igc_probe - Device Initialization Routine
  1887. * @pdev: PCI device information struct
  1888. * @ent: entry in igc_pci_tbl
  1889. *
  1890. * Returns 0 on success, negative on failure
  1891. *
  1892. * igc_probe initializes an adapter identified by a pci_dev structure.
  1893. * The OS initialization, configuring the adapter private structure,
  1894. * and a hardware reset occur.
  1895. */
  1896. static int igc_probe(struct pci_dev *pdev,
  1897. const struct pci_device_id *ent)
  1898. {
  1899. struct igc_adapter *adapter;
  1900. struct net_device *netdev;
  1901. struct igc_hw *hw;
  1902. int err, pci_using_dac;
  1903. err = pci_enable_device_mem(pdev);
  1904. if (err)
  1905. return err;
  1906. pci_using_dac = 0;
  1907. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
  1908. if (!err) {
  1909. err = dma_set_coherent_mask(&pdev->dev,
  1910. DMA_BIT_MASK(64));
  1911. if (!err)
  1912. pci_using_dac = 1;
  1913. } else {
  1914. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  1915. if (err) {
  1916. err = dma_set_coherent_mask(&pdev->dev,
  1917. DMA_BIT_MASK(32));
  1918. if (err) {
  1919. IGC_ERR("Wrong DMA configuration, aborting\n");
  1920. goto err_dma;
  1921. }
  1922. }
  1923. }
  1924. err = pci_request_selected_regions(pdev,
  1925. pci_select_bars(pdev,
  1926. IORESOURCE_MEM),
  1927. igc_driver_name);
  1928. if (err)
  1929. goto err_pci_reg;
  1930. pci_enable_pcie_error_reporting(pdev);
  1931. pci_set_master(pdev);
  1932. err = -ENOMEM;
  1933. netdev = alloc_etherdev_mq(sizeof(struct igc_adapter),
  1934. IGC_MAX_TX_QUEUES);
  1935. if (!netdev)
  1936. goto err_alloc_etherdev;
  1937. SET_NETDEV_DEV(netdev, &pdev->dev);
  1938. pci_set_drvdata(pdev, netdev);
  1939. adapter = netdev_priv(netdev);
  1940. adapter->netdev = netdev;
  1941. adapter->pdev = pdev;
  1942. hw = &adapter->hw;
  1943. hw->back = adapter;
  1944. adapter->port_num = hw->bus.func;
  1945. adapter->msg_enable = GENMASK(debug - 1, 0);
  1946. err = pci_save_state(pdev);
  1947. if (err)
  1948. goto err_ioremap;
  1949. err = -EIO;
  1950. adapter->io_addr = ioremap(pci_resource_start(pdev, 0),
  1951. pci_resource_len(pdev, 0));
  1952. if (!adapter->io_addr)
  1953. goto err_ioremap;
  1954. /* hw->hw_addr can be zeroed, so use adapter->io_addr for unmap */
  1955. hw->hw_addr = adapter->io_addr;
  1956. netdev->netdev_ops = &igc_netdev_ops;
  1957. netdev->watchdog_timeo = 5 * HZ;
  1958. netdev->mem_start = pci_resource_start(pdev, 0);
  1959. netdev->mem_end = pci_resource_end(pdev, 0);
  1960. /* PCI config space info */
  1961. hw->vendor_id = pdev->vendor;
  1962. hw->device_id = pdev->device;
  1963. hw->revision_id = pdev->revision;
  1964. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1965. hw->subsystem_device_id = pdev->subsystem_device;
  1966. /* setup the private structure */
  1967. err = igc_sw_init(adapter);
  1968. if (err)
  1969. goto err_sw_init;
  1970. /* MTU range: 68 - 9216 */
  1971. netdev->min_mtu = ETH_MIN_MTU;
  1972. netdev->max_mtu = MAX_STD_JUMBO_FRAME_SIZE;
  1973. /* reset the hardware with the new settings */
  1974. igc_reset(adapter);
  1975. /* let the f/w know that the h/w is now under the control of the
  1976. * driver.
  1977. */
  1978. igc_get_hw_control(adapter);
  1979. strncpy(netdev->name, "eth%d", IFNAMSIZ);
  1980. err = register_netdev(netdev);
  1981. if (err)
  1982. goto err_register;
  1983. /* carrier off reporting is important to ethtool even BEFORE open */
  1984. netif_carrier_off(netdev);
  1985. /* print pcie link status and MAC address */
  1986. pcie_print_link_status(pdev);
  1987. netdev_info(netdev, "MAC: %pM\n", netdev->dev_addr);
  1988. return 0;
  1989. err_register:
  1990. igc_release_hw_control(adapter);
  1991. err_sw_init:
  1992. igc_clear_interrupt_scheme(adapter);
  1993. iounmap(adapter->io_addr);
  1994. err_ioremap:
  1995. free_netdev(netdev);
  1996. err_alloc_etherdev:
  1997. pci_release_selected_regions(pdev,
  1998. pci_select_bars(pdev, IORESOURCE_MEM));
  1999. err_pci_reg:
  2000. err_dma:
  2001. pci_disable_device(pdev);
  2002. return err;
  2003. }
  2004. /**
  2005. * igc_remove - Device Removal Routine
  2006. * @pdev: PCI device information struct
  2007. *
  2008. * igc_remove is called by the PCI subsystem to alert the driver
  2009. * that it should release a PCI device. This could be caused by a
  2010. * Hot-Plug event, or because the driver is going to be removed from
  2011. * memory.
  2012. */
  2013. static void igc_remove(struct pci_dev *pdev)
  2014. {
  2015. struct net_device *netdev = pci_get_drvdata(pdev);
  2016. struct igc_adapter *adapter = netdev_priv(netdev);
  2017. set_bit(__IGC_DOWN, &adapter->state);
  2018. flush_scheduled_work();
  2019. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  2020. * would have already happened in close and is redundant.
  2021. */
  2022. igc_release_hw_control(adapter);
  2023. unregister_netdev(netdev);
  2024. pci_release_selected_regions(pdev,
  2025. pci_select_bars(pdev, IORESOURCE_MEM));
  2026. free_netdev(netdev);
  2027. pci_disable_device(pdev);
  2028. }
  2029. static struct pci_driver igc_driver = {
  2030. .name = igc_driver_name,
  2031. .id_table = igc_pci_tbl,
  2032. .probe = igc_probe,
  2033. .remove = igc_remove,
  2034. };
  2035. /**
  2036. * igc_sw_init - Initialize general software structures (struct igc_adapter)
  2037. * @adapter: board private structure to initialize
  2038. *
  2039. * igc_sw_init initializes the Adapter private data structure.
  2040. * Fields are initialized based on PCI device information and
  2041. * OS network device settings (MTU size).
  2042. */
  2043. static int igc_sw_init(struct igc_adapter *adapter)
  2044. {
  2045. struct net_device *netdev = adapter->netdev;
  2046. struct pci_dev *pdev = adapter->pdev;
  2047. struct igc_hw *hw = &adapter->hw;
  2048. /* PCI config space info */
  2049. hw->vendor_id = pdev->vendor;
  2050. hw->device_id = pdev->device;
  2051. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  2052. hw->subsystem_device_id = pdev->subsystem_device;
  2053. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  2054. pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
  2055. /* adjust max frame to be at least the size of a standard frame */
  2056. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
  2057. VLAN_HLEN;
  2058. if (igc_init_interrupt_scheme(adapter, true)) {
  2059. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  2060. return -ENOMEM;
  2061. }
  2062. /* Explicitly disable IRQ since the NIC can be in any state. */
  2063. igc_irq_disable(adapter);
  2064. set_bit(__IGC_DOWN, &adapter->state);
  2065. return 0;
  2066. }
  2067. /**
  2068. * igc_init_module - Driver Registration Routine
  2069. *
  2070. * igc_init_module is the first routine called when the driver is
  2071. * loaded. All it does is register with the PCI subsystem.
  2072. */
  2073. static int __init igc_init_module(void)
  2074. {
  2075. int ret;
  2076. pr_info("%s - version %s\n",
  2077. igc_driver_string, igc_driver_version);
  2078. pr_info("%s\n", igc_copyright);
  2079. ret = pci_register_driver(&igc_driver);
  2080. return ret;
  2081. }
  2082. module_init(igc_init_module);
  2083. /**
  2084. * igc_exit_module - Driver Exit Cleanup Routine
  2085. *
  2086. * igc_exit_module is called just before the driver is removed
  2087. * from memory.
  2088. */
  2089. static void __exit igc_exit_module(void)
  2090. {
  2091. pci_unregister_driver(&igc_driver);
  2092. }
  2093. module_exit(igc_exit_module);
  2094. /* igc_main.c */