ixgb_main.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328
  1. /*******************************************************************************
  2. Intel PRO/10GbE Linux driver
  3. Copyright(c) 1999 - 2006 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, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "ixgb.h"
  22. char ixgb_driver_name[] = "ixgb";
  23. static char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
  24. #ifndef CONFIG_IXGB_NAPI
  25. #define DRIVERNAPI
  26. #else
  27. #define DRIVERNAPI "-NAPI"
  28. #endif
  29. #define DRV_VERSION "1.0.126-k4"DRIVERNAPI
  30. const char ixgb_driver_version[] = DRV_VERSION;
  31. static const char ixgb_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
  32. #define IXGB_CB_LENGTH 256
  33. static unsigned int copybreak __read_mostly = IXGB_CB_LENGTH;
  34. module_param(copybreak, uint, 0644);
  35. MODULE_PARM_DESC(copybreak,
  36. "Maximum size of packet that is copied to a new buffer on receive");
  37. /* ixgb_pci_tbl - PCI Device ID Table
  38. *
  39. * Wildcard entries (PCI_ANY_ID) should come last
  40. * Last entry must be all 0s
  41. *
  42. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  43. * Class, Class Mask, private data (not used) }
  44. */
  45. static struct pci_device_id ixgb_pci_tbl[] = {
  46. {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX,
  47. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  48. {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_CX4,
  49. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  50. {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR,
  51. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  52. {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_LR,
  53. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  54. /* required last entry */
  55. {0,}
  56. };
  57. MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl);
  58. /* Local Function Prototypes */
  59. static int ixgb_init_module(void);
  60. static void ixgb_exit_module(void);
  61. static int ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  62. static void __devexit ixgb_remove(struct pci_dev *pdev);
  63. static int ixgb_sw_init(struct ixgb_adapter *adapter);
  64. static int ixgb_open(struct net_device *netdev);
  65. static int ixgb_close(struct net_device *netdev);
  66. static void ixgb_configure_tx(struct ixgb_adapter *adapter);
  67. static void ixgb_configure_rx(struct ixgb_adapter *adapter);
  68. static void ixgb_setup_rctl(struct ixgb_adapter *adapter);
  69. static void ixgb_clean_tx_ring(struct ixgb_adapter *adapter);
  70. static void ixgb_clean_rx_ring(struct ixgb_adapter *adapter);
  71. static void ixgb_set_multi(struct net_device *netdev);
  72. static void ixgb_watchdog(unsigned long data);
  73. static int ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
  74. static struct net_device_stats *ixgb_get_stats(struct net_device *netdev);
  75. static int ixgb_change_mtu(struct net_device *netdev, int new_mtu);
  76. static int ixgb_set_mac(struct net_device *netdev, void *p);
  77. static irqreturn_t ixgb_intr(int irq, void *data);
  78. static bool ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
  79. #ifdef CONFIG_IXGB_NAPI
  80. static int ixgb_clean(struct napi_struct *, int);
  81. static bool ixgb_clean_rx_irq(struct ixgb_adapter *, int *, int);
  82. #else
  83. static bool ixgb_clean_rx_irq(struct ixgb_adapter *);
  84. #endif
  85. static void ixgb_alloc_rx_buffers(struct ixgb_adapter *, int);
  86. static void ixgb_tx_timeout(struct net_device *dev);
  87. static void ixgb_tx_timeout_task(struct work_struct *work);
  88. static void ixgb_vlan_rx_register(struct net_device *netdev,
  89. struct vlan_group *grp);
  90. static void ixgb_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
  91. static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
  92. static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
  93. #ifdef CONFIG_NET_POLL_CONTROLLER
  94. /* for netdump / net console */
  95. static void ixgb_netpoll(struct net_device *dev);
  96. #endif
  97. static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
  98. enum pci_channel_state state);
  99. static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev);
  100. static void ixgb_io_resume (struct pci_dev *pdev);
  101. static struct pci_error_handlers ixgb_err_handler = {
  102. .error_detected = ixgb_io_error_detected,
  103. .slot_reset = ixgb_io_slot_reset,
  104. .resume = ixgb_io_resume,
  105. };
  106. static struct pci_driver ixgb_driver = {
  107. .name = ixgb_driver_name,
  108. .id_table = ixgb_pci_tbl,
  109. .probe = ixgb_probe,
  110. .remove = __devexit_p(ixgb_remove),
  111. .err_handler = &ixgb_err_handler
  112. };
  113. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  114. MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
  115. MODULE_LICENSE("GPL");
  116. MODULE_VERSION(DRV_VERSION);
  117. #define DEFAULT_DEBUG_LEVEL_SHIFT 3
  118. static int debug = DEFAULT_DEBUG_LEVEL_SHIFT;
  119. module_param(debug, int, 0);
  120. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  121. /**
  122. * ixgb_init_module - Driver Registration Routine
  123. *
  124. * ixgb_init_module is the first routine called when the driver is
  125. * loaded. All it does is register with the PCI subsystem.
  126. **/
  127. static int __init
  128. ixgb_init_module(void)
  129. {
  130. printk(KERN_INFO "%s - version %s\n",
  131. ixgb_driver_string, ixgb_driver_version);
  132. printk(KERN_INFO "%s\n", ixgb_copyright);
  133. return pci_register_driver(&ixgb_driver);
  134. }
  135. module_init(ixgb_init_module);
  136. /**
  137. * ixgb_exit_module - Driver Exit Cleanup Routine
  138. *
  139. * ixgb_exit_module is called just before the driver is removed
  140. * from memory.
  141. **/
  142. static void __exit
  143. ixgb_exit_module(void)
  144. {
  145. pci_unregister_driver(&ixgb_driver);
  146. }
  147. module_exit(ixgb_exit_module);
  148. /**
  149. * ixgb_irq_disable - Mask off interrupt generation on the NIC
  150. * @adapter: board private structure
  151. **/
  152. static void
  153. ixgb_irq_disable(struct ixgb_adapter *adapter)
  154. {
  155. IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
  156. IXGB_WRITE_FLUSH(&adapter->hw);
  157. synchronize_irq(adapter->pdev->irq);
  158. }
  159. /**
  160. * ixgb_irq_enable - Enable default interrupt generation settings
  161. * @adapter: board private structure
  162. **/
  163. static void
  164. ixgb_irq_enable(struct ixgb_adapter *adapter)
  165. {
  166. u32 val = IXGB_INT_RXT0 | IXGB_INT_RXDMT0 |
  167. IXGB_INT_TXDW | IXGB_INT_LSC;
  168. if (adapter->hw.subsystem_vendor_id == SUN_SUBVENDOR_ID)
  169. val |= IXGB_INT_GPI0;
  170. IXGB_WRITE_REG(&adapter->hw, IMS, val);
  171. IXGB_WRITE_FLUSH(&adapter->hw);
  172. }
  173. int
  174. ixgb_up(struct ixgb_adapter *adapter)
  175. {
  176. struct net_device *netdev = adapter->netdev;
  177. int err, irq_flags = IRQF_SHARED;
  178. int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
  179. struct ixgb_hw *hw = &adapter->hw;
  180. /* hardware has been reset, we need to reload some things */
  181. ixgb_rar_set(hw, netdev->dev_addr, 0);
  182. ixgb_set_multi(netdev);
  183. ixgb_restore_vlan(adapter);
  184. ixgb_configure_tx(adapter);
  185. ixgb_setup_rctl(adapter);
  186. ixgb_configure_rx(adapter);
  187. ixgb_alloc_rx_buffers(adapter, IXGB_DESC_UNUSED(&adapter->rx_ring));
  188. /* disable interrupts and get the hardware into a known state */
  189. IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
  190. /* only enable MSI if bus is in PCI-X mode */
  191. if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_PCIX_MODE) {
  192. err = pci_enable_msi(adapter->pdev);
  193. if (!err) {
  194. adapter->have_msi = 1;
  195. irq_flags = 0;
  196. }
  197. /* proceed to try to request regular interrupt */
  198. }
  199. err = request_irq(adapter->pdev->irq, &ixgb_intr, irq_flags,
  200. netdev->name, netdev);
  201. if (err) {
  202. if (adapter->have_msi)
  203. pci_disable_msi(adapter->pdev);
  204. DPRINTK(PROBE, ERR,
  205. "Unable to allocate interrupt Error: %d\n", err);
  206. return err;
  207. }
  208. if ((hw->max_frame_size != max_frame) ||
  209. (hw->max_frame_size !=
  210. (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
  211. hw->max_frame_size = max_frame;
  212. IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
  213. if (hw->max_frame_size >
  214. IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
  215. u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
  216. if (!(ctrl0 & IXGB_CTRL0_JFE)) {
  217. ctrl0 |= IXGB_CTRL0_JFE;
  218. IXGB_WRITE_REG(hw, CTRL0, ctrl0);
  219. }
  220. }
  221. }
  222. clear_bit(__IXGB_DOWN, &adapter->flags);
  223. #ifdef CONFIG_IXGB_NAPI
  224. napi_enable(&adapter->napi);
  225. #endif
  226. ixgb_irq_enable(adapter);
  227. mod_timer(&adapter->watchdog_timer, jiffies);
  228. return 0;
  229. }
  230. void
  231. ixgb_down(struct ixgb_adapter *adapter, bool kill_watchdog)
  232. {
  233. struct net_device *netdev = adapter->netdev;
  234. /* prevent the interrupt handler from restarting watchdog */
  235. set_bit(__IXGB_DOWN, &adapter->flags);
  236. #ifdef CONFIG_IXGB_NAPI
  237. napi_disable(&adapter->napi);
  238. #endif
  239. /* waiting for NAPI to complete can re-enable interrupts */
  240. ixgb_irq_disable(adapter);
  241. free_irq(adapter->pdev->irq, netdev);
  242. if (adapter->have_msi)
  243. pci_disable_msi(adapter->pdev);
  244. if (kill_watchdog)
  245. del_timer_sync(&adapter->watchdog_timer);
  246. adapter->link_speed = 0;
  247. adapter->link_duplex = 0;
  248. netif_carrier_off(netdev);
  249. netif_stop_queue(netdev);
  250. ixgb_reset(adapter);
  251. ixgb_clean_tx_ring(adapter);
  252. ixgb_clean_rx_ring(adapter);
  253. }
  254. void
  255. ixgb_reset(struct ixgb_adapter *adapter)
  256. {
  257. struct ixgb_hw *hw = &adapter->hw;
  258. ixgb_adapter_stop(hw);
  259. if (!ixgb_init_hw(hw))
  260. DPRINTK(PROBE, ERR, "ixgb_init_hw failed.\n");
  261. /* restore frame size information */
  262. IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
  263. if (hw->max_frame_size >
  264. IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
  265. u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
  266. if (!(ctrl0 & IXGB_CTRL0_JFE)) {
  267. ctrl0 |= IXGB_CTRL0_JFE;
  268. IXGB_WRITE_REG(hw, CTRL0, ctrl0);
  269. }
  270. }
  271. }
  272. /**
  273. * ixgb_probe - Device Initialization Routine
  274. * @pdev: PCI device information struct
  275. * @ent: entry in ixgb_pci_tbl
  276. *
  277. * Returns 0 on success, negative on failure
  278. *
  279. * ixgb_probe initializes an adapter identified by a pci_dev structure.
  280. * The OS initialization, configuring of the adapter private structure,
  281. * and a hardware reset occur.
  282. **/
  283. static int __devinit
  284. ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  285. {
  286. struct net_device *netdev = NULL;
  287. struct ixgb_adapter *adapter;
  288. static int cards_found = 0;
  289. int pci_using_dac;
  290. int i;
  291. int err;
  292. if ((err = pci_enable_device(pdev)))
  293. return err;
  294. if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
  295. !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
  296. pci_using_dac = 1;
  297. } else {
  298. if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) ||
  299. (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
  300. printk(KERN_ERR
  301. "ixgb: No usable DMA configuration, aborting\n");
  302. goto err_dma_mask;
  303. }
  304. pci_using_dac = 0;
  305. }
  306. if ((err = pci_request_regions(pdev, ixgb_driver_name)))
  307. goto err_request_regions;
  308. pci_set_master(pdev);
  309. netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
  310. if (!netdev) {
  311. err = -ENOMEM;
  312. goto err_alloc_etherdev;
  313. }
  314. SET_NETDEV_DEV(netdev, &pdev->dev);
  315. pci_set_drvdata(pdev, netdev);
  316. adapter = netdev_priv(netdev);
  317. adapter->netdev = netdev;
  318. adapter->pdev = pdev;
  319. adapter->hw.back = adapter;
  320. adapter->msg_enable = netif_msg_init(debug, DEFAULT_DEBUG_LEVEL_SHIFT);
  321. adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
  322. pci_resource_len(pdev, BAR_0));
  323. if (!adapter->hw.hw_addr) {
  324. err = -EIO;
  325. goto err_ioremap;
  326. }
  327. for (i = BAR_1; i <= BAR_5; i++) {
  328. if (pci_resource_len(pdev, i) == 0)
  329. continue;
  330. if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
  331. adapter->hw.io_base = pci_resource_start(pdev, i);
  332. break;
  333. }
  334. }
  335. netdev->open = &ixgb_open;
  336. netdev->stop = &ixgb_close;
  337. netdev->hard_start_xmit = &ixgb_xmit_frame;
  338. netdev->get_stats = &ixgb_get_stats;
  339. netdev->set_multicast_list = &ixgb_set_multi;
  340. netdev->set_mac_address = &ixgb_set_mac;
  341. netdev->change_mtu = &ixgb_change_mtu;
  342. ixgb_set_ethtool_ops(netdev);
  343. netdev->tx_timeout = &ixgb_tx_timeout;
  344. netdev->watchdog_timeo = 5 * HZ;
  345. #ifdef CONFIG_IXGB_NAPI
  346. netif_napi_add(netdev, &adapter->napi, ixgb_clean, 64);
  347. #endif
  348. netdev->vlan_rx_register = ixgb_vlan_rx_register;
  349. netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
  350. netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid;
  351. #ifdef CONFIG_NET_POLL_CONTROLLER
  352. netdev->poll_controller = ixgb_netpoll;
  353. #endif
  354. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  355. adapter->bd_number = cards_found;
  356. adapter->link_speed = 0;
  357. adapter->link_duplex = 0;
  358. /* setup the private structure */
  359. if ((err = ixgb_sw_init(adapter)))
  360. goto err_sw_init;
  361. netdev->features = NETIF_F_SG |
  362. NETIF_F_HW_CSUM |
  363. NETIF_F_HW_VLAN_TX |
  364. NETIF_F_HW_VLAN_RX |
  365. NETIF_F_HW_VLAN_FILTER;
  366. netdev->features |= NETIF_F_TSO;
  367. if (pci_using_dac)
  368. netdev->features |= NETIF_F_HIGHDMA;
  369. /* make sure the EEPROM is good */
  370. if (!ixgb_validate_eeprom_checksum(&adapter->hw)) {
  371. DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
  372. err = -EIO;
  373. goto err_eeprom;
  374. }
  375. ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
  376. memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
  377. if (!is_valid_ether_addr(netdev->perm_addr)) {
  378. DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
  379. err = -EIO;
  380. goto err_eeprom;
  381. }
  382. adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
  383. init_timer(&adapter->watchdog_timer);
  384. adapter->watchdog_timer.function = &ixgb_watchdog;
  385. adapter->watchdog_timer.data = (unsigned long)adapter;
  386. INIT_WORK(&adapter->tx_timeout_task, ixgb_tx_timeout_task);
  387. strcpy(netdev->name, "eth%d");
  388. if ((err = register_netdev(netdev)))
  389. goto err_register;
  390. /* we're going to reset, so assume we have no link for now */
  391. netif_carrier_off(netdev);
  392. netif_stop_queue(netdev);
  393. DPRINTK(PROBE, INFO, "Intel(R) PRO/10GbE Network Connection\n");
  394. ixgb_check_options(adapter);
  395. /* reset the hardware with the new settings */
  396. ixgb_reset(adapter);
  397. cards_found++;
  398. return 0;
  399. err_register:
  400. err_sw_init:
  401. err_eeprom:
  402. iounmap(adapter->hw.hw_addr);
  403. err_ioremap:
  404. free_netdev(netdev);
  405. err_alloc_etherdev:
  406. pci_release_regions(pdev);
  407. err_request_regions:
  408. err_dma_mask:
  409. pci_disable_device(pdev);
  410. return err;
  411. }
  412. /**
  413. * ixgb_remove - Device Removal Routine
  414. * @pdev: PCI device information struct
  415. *
  416. * ixgb_remove is called by the PCI subsystem to alert the driver
  417. * that it should release a PCI device. The could be caused by a
  418. * Hot-Plug event, or because the driver is going to be removed from
  419. * memory.
  420. **/
  421. static void __devexit
  422. ixgb_remove(struct pci_dev *pdev)
  423. {
  424. struct net_device *netdev = pci_get_drvdata(pdev);
  425. struct ixgb_adapter *adapter = netdev_priv(netdev);
  426. flush_scheduled_work();
  427. unregister_netdev(netdev);
  428. iounmap(adapter->hw.hw_addr);
  429. pci_release_regions(pdev);
  430. free_netdev(netdev);
  431. }
  432. /**
  433. * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
  434. * @adapter: board private structure to initialize
  435. *
  436. * ixgb_sw_init initializes the Adapter private data structure.
  437. * Fields are initialized based on PCI device information and
  438. * OS network device settings (MTU size).
  439. **/
  440. static int __devinit
  441. ixgb_sw_init(struct ixgb_adapter *adapter)
  442. {
  443. struct ixgb_hw *hw = &adapter->hw;
  444. struct net_device *netdev = adapter->netdev;
  445. struct pci_dev *pdev = adapter->pdev;
  446. /* PCI config space info */
  447. hw->vendor_id = pdev->vendor;
  448. hw->device_id = pdev->device;
  449. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  450. hw->subsystem_id = pdev->subsystem_device;
  451. hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
  452. adapter->rx_buffer_len = hw->max_frame_size + 8; /* + 8 for errata */
  453. if ((hw->device_id == IXGB_DEVICE_ID_82597EX)
  454. || (hw->device_id == IXGB_DEVICE_ID_82597EX_CX4)
  455. || (hw->device_id == IXGB_DEVICE_ID_82597EX_LR)
  456. || (hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
  457. hw->mac_type = ixgb_82597;
  458. else {
  459. /* should never have loaded on this device */
  460. DPRINTK(PROBE, ERR, "unsupported device id\n");
  461. }
  462. /* enable flow control to be programmed */
  463. hw->fc.send_xon = 1;
  464. set_bit(__IXGB_DOWN, &adapter->flags);
  465. return 0;
  466. }
  467. /**
  468. * ixgb_open - Called when a network interface is made active
  469. * @netdev: network interface device structure
  470. *
  471. * Returns 0 on success, negative value on failure
  472. *
  473. * The open entry point is called when a network interface is made
  474. * active by the system (IFF_UP). At this point all resources needed
  475. * for transmit and receive operations are allocated, the interrupt
  476. * handler is registered with the OS, the watchdog timer is started,
  477. * and the stack is notified that the interface is ready.
  478. **/
  479. static int
  480. ixgb_open(struct net_device *netdev)
  481. {
  482. struct ixgb_adapter *adapter = netdev_priv(netdev);
  483. int err;
  484. /* allocate transmit descriptors */
  485. if ((err = ixgb_setup_tx_resources(adapter)))
  486. goto err_setup_tx;
  487. /* allocate receive descriptors */
  488. if ((err = ixgb_setup_rx_resources(adapter)))
  489. goto err_setup_rx;
  490. if ((err = ixgb_up(adapter)))
  491. goto err_up;
  492. return 0;
  493. err_up:
  494. ixgb_free_rx_resources(adapter);
  495. err_setup_rx:
  496. ixgb_free_tx_resources(adapter);
  497. err_setup_tx:
  498. ixgb_reset(adapter);
  499. return err;
  500. }
  501. /**
  502. * ixgb_close - Disables a network interface
  503. * @netdev: network interface device structure
  504. *
  505. * Returns 0, this is not allowed to fail
  506. *
  507. * The close entry point is called when an interface is de-activated
  508. * by the OS. The hardware is still under the drivers control, but
  509. * needs to be disabled. A global MAC reset is issued to stop the
  510. * hardware, and all transmit and receive resources are freed.
  511. **/
  512. static int
  513. ixgb_close(struct net_device *netdev)
  514. {
  515. struct ixgb_adapter *adapter = netdev_priv(netdev);
  516. ixgb_down(adapter, true);
  517. ixgb_free_tx_resources(adapter);
  518. ixgb_free_rx_resources(adapter);
  519. return 0;
  520. }
  521. /**
  522. * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
  523. * @adapter: board private structure
  524. *
  525. * Return 0 on success, negative on failure
  526. **/
  527. int
  528. ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
  529. {
  530. struct ixgb_desc_ring *txdr = &adapter->tx_ring;
  531. struct pci_dev *pdev = adapter->pdev;
  532. int size;
  533. size = sizeof(struct ixgb_buffer) * txdr->count;
  534. txdr->buffer_info = vmalloc(size);
  535. if (!txdr->buffer_info) {
  536. DPRINTK(PROBE, ERR,
  537. "Unable to allocate transmit descriptor ring memory\n");
  538. return -ENOMEM;
  539. }
  540. memset(txdr->buffer_info, 0, size);
  541. /* round up to nearest 4K */
  542. txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
  543. txdr->size = ALIGN(txdr->size, 4096);
  544. txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  545. if (!txdr->desc) {
  546. vfree(txdr->buffer_info);
  547. DPRINTK(PROBE, ERR,
  548. "Unable to allocate transmit descriptor memory\n");
  549. return -ENOMEM;
  550. }
  551. memset(txdr->desc, 0, txdr->size);
  552. txdr->next_to_use = 0;
  553. txdr->next_to_clean = 0;
  554. return 0;
  555. }
  556. /**
  557. * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
  558. * @adapter: board private structure
  559. *
  560. * Configure the Tx unit of the MAC after a reset.
  561. **/
  562. static void
  563. ixgb_configure_tx(struct ixgb_adapter *adapter)
  564. {
  565. u64 tdba = adapter->tx_ring.dma;
  566. u32 tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
  567. u32 tctl;
  568. struct ixgb_hw *hw = &adapter->hw;
  569. /* Setup the Base and Length of the Tx Descriptor Ring
  570. * tx_ring.dma can be either a 32 or 64 bit value
  571. */
  572. IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
  573. IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
  574. IXGB_WRITE_REG(hw, TDLEN, tdlen);
  575. /* Setup the HW Tx Head and Tail descriptor pointers */
  576. IXGB_WRITE_REG(hw, TDH, 0);
  577. IXGB_WRITE_REG(hw, TDT, 0);
  578. /* don't set up txdctl, it induces performance problems if configured
  579. * incorrectly */
  580. /* Set the Tx Interrupt Delay register */
  581. IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
  582. /* Program the Transmit Control Register */
  583. tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
  584. IXGB_WRITE_REG(hw, TCTL, tctl);
  585. /* Setup Transmit Descriptor Settings for this adapter */
  586. adapter->tx_cmd_type =
  587. IXGB_TX_DESC_TYPE |
  588. (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);
  589. }
  590. /**
  591. * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
  592. * @adapter: board private structure
  593. *
  594. * Returns 0 on success, negative on failure
  595. **/
  596. int
  597. ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
  598. {
  599. struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
  600. struct pci_dev *pdev = adapter->pdev;
  601. int size;
  602. size = sizeof(struct ixgb_buffer) * rxdr->count;
  603. rxdr->buffer_info = vmalloc(size);
  604. if (!rxdr->buffer_info) {
  605. DPRINTK(PROBE, ERR,
  606. "Unable to allocate receive descriptor ring\n");
  607. return -ENOMEM;
  608. }
  609. memset(rxdr->buffer_info, 0, size);
  610. /* Round up to nearest 4K */
  611. rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
  612. rxdr->size = ALIGN(rxdr->size, 4096);
  613. rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  614. if (!rxdr->desc) {
  615. vfree(rxdr->buffer_info);
  616. DPRINTK(PROBE, ERR,
  617. "Unable to allocate receive descriptors\n");
  618. return -ENOMEM;
  619. }
  620. memset(rxdr->desc, 0, rxdr->size);
  621. rxdr->next_to_clean = 0;
  622. rxdr->next_to_use = 0;
  623. return 0;
  624. }
  625. /**
  626. * ixgb_setup_rctl - configure the receive control register
  627. * @adapter: Board private structure
  628. **/
  629. static void
  630. ixgb_setup_rctl(struct ixgb_adapter *adapter)
  631. {
  632. u32 rctl;
  633. rctl = IXGB_READ_REG(&adapter->hw, RCTL);
  634. rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
  635. rctl |=
  636. IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
  637. IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
  638. (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
  639. rctl |= IXGB_RCTL_SECRC;
  640. if (adapter->rx_buffer_len <= IXGB_RXBUFFER_2048)
  641. rctl |= IXGB_RCTL_BSIZE_2048;
  642. else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_4096)
  643. rctl |= IXGB_RCTL_BSIZE_4096;
  644. else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_8192)
  645. rctl |= IXGB_RCTL_BSIZE_8192;
  646. else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_16384)
  647. rctl |= IXGB_RCTL_BSIZE_16384;
  648. IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
  649. }
  650. /**
  651. * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
  652. * @adapter: board private structure
  653. *
  654. * Configure the Rx unit of the MAC after a reset.
  655. **/
  656. static void
  657. ixgb_configure_rx(struct ixgb_adapter *adapter)
  658. {
  659. u64 rdba = adapter->rx_ring.dma;
  660. u32 rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
  661. struct ixgb_hw *hw = &adapter->hw;
  662. u32 rctl;
  663. u32 rxcsum;
  664. /* make sure receives are disabled while setting up the descriptors */
  665. rctl = IXGB_READ_REG(hw, RCTL);
  666. IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
  667. /* set the Receive Delay Timer Register */
  668. IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
  669. /* Setup the Base and Length of the Rx Descriptor Ring */
  670. IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
  671. IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
  672. IXGB_WRITE_REG(hw, RDLEN, rdlen);
  673. /* Setup the HW Rx Head and Tail Descriptor Pointers */
  674. IXGB_WRITE_REG(hw, RDH, 0);
  675. IXGB_WRITE_REG(hw, RDT, 0);
  676. /* due to the hardware errata with RXDCTL, we are unable to use any of
  677. * the performance enhancing features of it without causing other
  678. * subtle bugs, some of the bugs could include receive length
  679. * corruption at high data rates (WTHRESH > 0) and/or receive
  680. * descriptor ring irregularites (particularly in hardware cache) */
  681. IXGB_WRITE_REG(hw, RXDCTL, 0);
  682. /* Enable Receive Checksum Offload for TCP and UDP */
  683. if (adapter->rx_csum) {
  684. rxcsum = IXGB_READ_REG(hw, RXCSUM);
  685. rxcsum |= IXGB_RXCSUM_TUOFL;
  686. IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
  687. }
  688. /* Enable Receives */
  689. IXGB_WRITE_REG(hw, RCTL, rctl);
  690. }
  691. /**
  692. * ixgb_free_tx_resources - Free Tx Resources
  693. * @adapter: board private structure
  694. *
  695. * Free all transmit software resources
  696. **/
  697. void
  698. ixgb_free_tx_resources(struct ixgb_adapter *adapter)
  699. {
  700. struct pci_dev *pdev = adapter->pdev;
  701. ixgb_clean_tx_ring(adapter);
  702. vfree(adapter->tx_ring.buffer_info);
  703. adapter->tx_ring.buffer_info = NULL;
  704. pci_free_consistent(pdev, adapter->tx_ring.size,
  705. adapter->tx_ring.desc, adapter->tx_ring.dma);
  706. adapter->tx_ring.desc = NULL;
  707. }
  708. static void
  709. ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
  710. struct ixgb_buffer *buffer_info)
  711. {
  712. struct pci_dev *pdev = adapter->pdev;
  713. if (buffer_info->dma)
  714. pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
  715. PCI_DMA_TODEVICE);
  716. if (buffer_info->skb)
  717. dev_kfree_skb_any(buffer_info->skb);
  718. buffer_info->skb = NULL;
  719. buffer_info->dma = 0;
  720. buffer_info->time_stamp = 0;
  721. /* these fields must always be initialized in tx
  722. * buffer_info->length = 0;
  723. * buffer_info->next_to_watch = 0; */
  724. }
  725. /**
  726. * ixgb_clean_tx_ring - Free Tx Buffers
  727. * @adapter: board private structure
  728. **/
  729. static void
  730. ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
  731. {
  732. struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
  733. struct ixgb_buffer *buffer_info;
  734. unsigned long size;
  735. unsigned int i;
  736. /* Free all the Tx ring sk_buffs */
  737. for (i = 0; i < tx_ring->count; i++) {
  738. buffer_info = &tx_ring->buffer_info[i];
  739. ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
  740. }
  741. size = sizeof(struct ixgb_buffer) * tx_ring->count;
  742. memset(tx_ring->buffer_info, 0, size);
  743. /* Zero out the descriptor ring */
  744. memset(tx_ring->desc, 0, tx_ring->size);
  745. tx_ring->next_to_use = 0;
  746. tx_ring->next_to_clean = 0;
  747. IXGB_WRITE_REG(&adapter->hw, TDH, 0);
  748. IXGB_WRITE_REG(&adapter->hw, TDT, 0);
  749. }
  750. /**
  751. * ixgb_free_rx_resources - Free Rx Resources
  752. * @adapter: board private structure
  753. *
  754. * Free all receive software resources
  755. **/
  756. void
  757. ixgb_free_rx_resources(struct ixgb_adapter *adapter)
  758. {
  759. struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
  760. struct pci_dev *pdev = adapter->pdev;
  761. ixgb_clean_rx_ring(adapter);
  762. vfree(rx_ring->buffer_info);
  763. rx_ring->buffer_info = NULL;
  764. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  765. rx_ring->desc = NULL;
  766. }
  767. /**
  768. * ixgb_clean_rx_ring - Free Rx Buffers
  769. * @adapter: board private structure
  770. **/
  771. static void
  772. ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
  773. {
  774. struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
  775. struct ixgb_buffer *buffer_info;
  776. struct pci_dev *pdev = adapter->pdev;
  777. unsigned long size;
  778. unsigned int i;
  779. /* Free all the Rx ring sk_buffs */
  780. for (i = 0; i < rx_ring->count; i++) {
  781. buffer_info = &rx_ring->buffer_info[i];
  782. if (buffer_info->skb) {
  783. pci_unmap_single(pdev,
  784. buffer_info->dma,
  785. buffer_info->length,
  786. PCI_DMA_FROMDEVICE);
  787. dev_kfree_skb(buffer_info->skb);
  788. buffer_info->skb = NULL;
  789. }
  790. }
  791. size = sizeof(struct ixgb_buffer) * rx_ring->count;
  792. memset(rx_ring->buffer_info, 0, size);
  793. /* Zero out the descriptor ring */
  794. memset(rx_ring->desc, 0, rx_ring->size);
  795. rx_ring->next_to_clean = 0;
  796. rx_ring->next_to_use = 0;
  797. IXGB_WRITE_REG(&adapter->hw, RDH, 0);
  798. IXGB_WRITE_REG(&adapter->hw, RDT, 0);
  799. }
  800. /**
  801. * ixgb_set_mac - Change the Ethernet Address of the NIC
  802. * @netdev: network interface device structure
  803. * @p: pointer to an address structure
  804. *
  805. * Returns 0 on success, negative on failure
  806. **/
  807. static int
  808. ixgb_set_mac(struct net_device *netdev, void *p)
  809. {
  810. struct ixgb_adapter *adapter = netdev_priv(netdev);
  811. struct sockaddr *addr = p;
  812. if (!is_valid_ether_addr(addr->sa_data))
  813. return -EADDRNOTAVAIL;
  814. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  815. ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
  816. return 0;
  817. }
  818. /**
  819. * ixgb_set_multi - Multicast and Promiscuous mode set
  820. * @netdev: network interface device structure
  821. *
  822. * The set_multi entry point is called whenever the multicast address
  823. * list or the network interface flags are updated. This routine is
  824. * responsible for configuring the hardware for proper multicast,
  825. * promiscuous mode, and all-multi behavior.
  826. **/
  827. static void
  828. ixgb_set_multi(struct net_device *netdev)
  829. {
  830. struct ixgb_adapter *adapter = netdev_priv(netdev);
  831. struct ixgb_hw *hw = &adapter->hw;
  832. struct dev_mc_list *mc_ptr;
  833. u32 rctl;
  834. int i;
  835. /* Check for Promiscuous and All Multicast modes */
  836. rctl = IXGB_READ_REG(hw, RCTL);
  837. if (netdev->flags & IFF_PROMISC) {
  838. rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
  839. } else if (netdev->flags & IFF_ALLMULTI) {
  840. rctl |= IXGB_RCTL_MPE;
  841. rctl &= ~IXGB_RCTL_UPE;
  842. } else {
  843. rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
  844. }
  845. if (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
  846. rctl |= IXGB_RCTL_MPE;
  847. IXGB_WRITE_REG(hw, RCTL, rctl);
  848. } else {
  849. u8 mta[IXGB_MAX_NUM_MULTICAST_ADDRESSES *
  850. IXGB_ETH_LENGTH_OF_ADDRESS];
  851. IXGB_WRITE_REG(hw, RCTL, rctl);
  852. for (i = 0, mc_ptr = netdev->mc_list;
  853. mc_ptr;
  854. i++, mc_ptr = mc_ptr->next)
  855. memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS],
  856. mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS);
  857. ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
  858. }
  859. }
  860. /**
  861. * ixgb_watchdog - Timer Call-back
  862. * @data: pointer to netdev cast into an unsigned long
  863. **/
  864. static void
  865. ixgb_watchdog(unsigned long data)
  866. {
  867. struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
  868. struct net_device *netdev = adapter->netdev;
  869. struct ixgb_desc_ring *txdr = &adapter->tx_ring;
  870. ixgb_check_for_link(&adapter->hw);
  871. if (ixgb_check_for_bad_link(&adapter->hw)) {
  872. /* force the reset path */
  873. netif_stop_queue(netdev);
  874. }
  875. if (adapter->hw.link_up) {
  876. if (!netif_carrier_ok(netdev)) {
  877. DPRINTK(LINK, INFO,
  878. "NIC Link is Up 10000 Mbps Full Duplex\n");
  879. adapter->link_speed = 10000;
  880. adapter->link_duplex = FULL_DUPLEX;
  881. netif_carrier_on(netdev);
  882. netif_wake_queue(netdev);
  883. }
  884. } else {
  885. if (netif_carrier_ok(netdev)) {
  886. adapter->link_speed = 0;
  887. adapter->link_duplex = 0;
  888. DPRINTK(LINK, INFO, "NIC Link is Down\n");
  889. netif_carrier_off(netdev);
  890. netif_stop_queue(netdev);
  891. }
  892. }
  893. ixgb_update_stats(adapter);
  894. if (!netif_carrier_ok(netdev)) {
  895. if (IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
  896. /* We've lost link, so the controller stops DMA,
  897. * but we've got queued Tx work that's never going
  898. * to get done, so reset controller to flush Tx.
  899. * (Do the reset outside of interrupt context). */
  900. schedule_work(&adapter->tx_timeout_task);
  901. }
  902. }
  903. /* Force detection of hung controller every watchdog period */
  904. adapter->detect_tx_hung = true;
  905. /* generate an interrupt to force clean up of any stragglers */
  906. IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
  907. /* Reset the timer */
  908. mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
  909. }
  910. #define IXGB_TX_FLAGS_CSUM 0x00000001
  911. #define IXGB_TX_FLAGS_VLAN 0x00000002
  912. #define IXGB_TX_FLAGS_TSO 0x00000004
  913. static int
  914. ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
  915. {
  916. struct ixgb_context_desc *context_desc;
  917. unsigned int i;
  918. u8 ipcss, ipcso, tucss, tucso, hdr_len;
  919. u16 ipcse, tucse, mss;
  920. int err;
  921. if (likely(skb_is_gso(skb))) {
  922. struct ixgb_buffer *buffer_info;
  923. struct iphdr *iph;
  924. if (skb_header_cloned(skb)) {
  925. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  926. if (err)
  927. return err;
  928. }
  929. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  930. mss = skb_shinfo(skb)->gso_size;
  931. iph = ip_hdr(skb);
  932. iph->tot_len = 0;
  933. iph->check = 0;
  934. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  935. iph->daddr, 0,
  936. IPPROTO_TCP, 0);
  937. ipcss = skb_network_offset(skb);
  938. ipcso = (void *)&(iph->check) - (void *)skb->data;
  939. ipcse = skb_transport_offset(skb) - 1;
  940. tucss = skb_transport_offset(skb);
  941. tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
  942. tucse = 0;
  943. i = adapter->tx_ring.next_to_use;
  944. context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
  945. buffer_info = &adapter->tx_ring.buffer_info[i];
  946. WARN_ON(buffer_info->dma != 0);
  947. context_desc->ipcss = ipcss;
  948. context_desc->ipcso = ipcso;
  949. context_desc->ipcse = cpu_to_le16(ipcse);
  950. context_desc->tucss = tucss;
  951. context_desc->tucso = tucso;
  952. context_desc->tucse = cpu_to_le16(tucse);
  953. context_desc->mss = cpu_to_le16(mss);
  954. context_desc->hdr_len = hdr_len;
  955. context_desc->status = 0;
  956. context_desc->cmd_type_len = cpu_to_le32(
  957. IXGB_CONTEXT_DESC_TYPE
  958. | IXGB_CONTEXT_DESC_CMD_TSE
  959. | IXGB_CONTEXT_DESC_CMD_IP
  960. | IXGB_CONTEXT_DESC_CMD_TCP
  961. | IXGB_CONTEXT_DESC_CMD_IDE
  962. | (skb->len - (hdr_len)));
  963. if (++i == adapter->tx_ring.count) i = 0;
  964. adapter->tx_ring.next_to_use = i;
  965. return 1;
  966. }
  967. return 0;
  968. }
  969. static bool
  970. ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
  971. {
  972. struct ixgb_context_desc *context_desc;
  973. unsigned int i;
  974. u8 css, cso;
  975. if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
  976. struct ixgb_buffer *buffer_info;
  977. css = skb_transport_offset(skb);
  978. cso = css + skb->csum_offset;
  979. i = adapter->tx_ring.next_to_use;
  980. context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
  981. buffer_info = &adapter->tx_ring.buffer_info[i];
  982. WARN_ON(buffer_info->dma != 0);
  983. context_desc->tucss = css;
  984. context_desc->tucso = cso;
  985. context_desc->tucse = 0;
  986. /* zero out any previously existing data in one instruction */
  987. *(u32 *)&(context_desc->ipcss) = 0;
  988. context_desc->status = 0;
  989. context_desc->hdr_len = 0;
  990. context_desc->mss = 0;
  991. context_desc->cmd_type_len =
  992. cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
  993. | IXGB_TX_DESC_CMD_IDE);
  994. if (++i == adapter->tx_ring.count) i = 0;
  995. adapter->tx_ring.next_to_use = i;
  996. return true;
  997. }
  998. return false;
  999. }
  1000. #define IXGB_MAX_TXD_PWR 14
  1001. #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
  1002. static int
  1003. ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
  1004. unsigned int first)
  1005. {
  1006. struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
  1007. struct ixgb_buffer *buffer_info;
  1008. int len = skb->len;
  1009. unsigned int offset = 0, size, count = 0, i;
  1010. unsigned int mss = skb_shinfo(skb)->gso_size;
  1011. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  1012. unsigned int f;
  1013. len -= skb->data_len;
  1014. i = tx_ring->next_to_use;
  1015. while (len) {
  1016. buffer_info = &tx_ring->buffer_info[i];
  1017. size = min(len, IXGB_MAX_DATA_PER_TXD);
  1018. /* Workaround for premature desc write-backs
  1019. * in TSO mode. Append 4-byte sentinel desc */
  1020. if (unlikely(mss && !nr_frags && size == len && size > 8))
  1021. size -= 4;
  1022. buffer_info->length = size;
  1023. WARN_ON(buffer_info->dma != 0);
  1024. buffer_info->time_stamp = jiffies;
  1025. buffer_info->dma =
  1026. pci_map_single(adapter->pdev,
  1027. skb->data + offset,
  1028. size,
  1029. PCI_DMA_TODEVICE);
  1030. buffer_info->next_to_watch = 0;
  1031. len -= size;
  1032. offset += size;
  1033. count++;
  1034. if (++i == tx_ring->count) i = 0;
  1035. }
  1036. for (f = 0; f < nr_frags; f++) {
  1037. struct skb_frag_struct *frag;
  1038. frag = &skb_shinfo(skb)->frags[f];
  1039. len = frag->size;
  1040. offset = 0;
  1041. while (len) {
  1042. buffer_info = &tx_ring->buffer_info[i];
  1043. size = min(len, IXGB_MAX_DATA_PER_TXD);
  1044. /* Workaround for premature desc write-backs
  1045. * in TSO mode. Append 4-byte sentinel desc */
  1046. if (unlikely(mss && (f == (nr_frags - 1))
  1047. && size == len && size > 8))
  1048. size -= 4;
  1049. buffer_info->length = size;
  1050. buffer_info->time_stamp = jiffies;
  1051. buffer_info->dma =
  1052. pci_map_page(adapter->pdev,
  1053. frag->page,
  1054. frag->page_offset + offset,
  1055. size,
  1056. PCI_DMA_TODEVICE);
  1057. buffer_info->next_to_watch = 0;
  1058. len -= size;
  1059. offset += size;
  1060. count++;
  1061. if (++i == tx_ring->count) i = 0;
  1062. }
  1063. }
  1064. i = (i == 0) ? tx_ring->count - 1 : i - 1;
  1065. tx_ring->buffer_info[i].skb = skb;
  1066. tx_ring->buffer_info[first].next_to_watch = i;
  1067. return count;
  1068. }
  1069. static void
  1070. ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
  1071. {
  1072. struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
  1073. struct ixgb_tx_desc *tx_desc = NULL;
  1074. struct ixgb_buffer *buffer_info;
  1075. u32 cmd_type_len = adapter->tx_cmd_type;
  1076. u8 status = 0;
  1077. u8 popts = 0;
  1078. unsigned int i;
  1079. if (tx_flags & IXGB_TX_FLAGS_TSO) {
  1080. cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
  1081. popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
  1082. }
  1083. if (tx_flags & IXGB_TX_FLAGS_CSUM)
  1084. popts |= IXGB_TX_DESC_POPTS_TXSM;
  1085. if (tx_flags & IXGB_TX_FLAGS_VLAN)
  1086. cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
  1087. i = tx_ring->next_to_use;
  1088. while (count--) {
  1089. buffer_info = &tx_ring->buffer_info[i];
  1090. tx_desc = IXGB_TX_DESC(*tx_ring, i);
  1091. tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
  1092. tx_desc->cmd_type_len =
  1093. cpu_to_le32(cmd_type_len | buffer_info->length);
  1094. tx_desc->status = status;
  1095. tx_desc->popts = popts;
  1096. tx_desc->vlan = cpu_to_le16(vlan_id);
  1097. if (++i == tx_ring->count) i = 0;
  1098. }
  1099. tx_desc->cmd_type_len |=
  1100. cpu_to_le32(IXGB_TX_DESC_CMD_EOP | IXGB_TX_DESC_CMD_RS);
  1101. /* Force memory writes to complete before letting h/w
  1102. * know there are new descriptors to fetch. (Only
  1103. * applicable for weak-ordered memory model archs,
  1104. * such as IA-64). */
  1105. wmb();
  1106. tx_ring->next_to_use = i;
  1107. IXGB_WRITE_REG(&adapter->hw, TDT, i);
  1108. }
  1109. static int __ixgb_maybe_stop_tx(struct net_device *netdev, int size)
  1110. {
  1111. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1112. struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
  1113. netif_stop_queue(netdev);
  1114. /* Herbert's original patch had:
  1115. * smp_mb__after_netif_stop_queue();
  1116. * but since that doesn't exist yet, just open code it. */
  1117. smp_mb();
  1118. /* We need to check again in a case another CPU has just
  1119. * made room available. */
  1120. if (likely(IXGB_DESC_UNUSED(tx_ring) < size))
  1121. return -EBUSY;
  1122. /* A reprieve! */
  1123. netif_start_queue(netdev);
  1124. ++adapter->restart_queue;
  1125. return 0;
  1126. }
  1127. static int ixgb_maybe_stop_tx(struct net_device *netdev,
  1128. struct ixgb_desc_ring *tx_ring, int size)
  1129. {
  1130. if (likely(IXGB_DESC_UNUSED(tx_ring) >= size))
  1131. return 0;
  1132. return __ixgb_maybe_stop_tx(netdev, size);
  1133. }
  1134. /* Tx Descriptors needed, worst case */
  1135. #define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
  1136. (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
  1137. #define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) /* skb->date */ + \
  1138. MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1 /* for context */ \
  1139. + 1 /* one more needed for sentinel TSO workaround */
  1140. static int
  1141. ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  1142. {
  1143. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1144. unsigned int first;
  1145. unsigned int tx_flags = 0;
  1146. int vlan_id = 0;
  1147. int tso;
  1148. if (test_bit(__IXGB_DOWN, &adapter->flags)) {
  1149. dev_kfree_skb(skb);
  1150. return NETDEV_TX_OK;
  1151. }
  1152. if (skb->len <= 0) {
  1153. dev_kfree_skb_any(skb);
  1154. return 0;
  1155. }
  1156. if (unlikely(ixgb_maybe_stop_tx(netdev, &adapter->tx_ring,
  1157. DESC_NEEDED)))
  1158. return NETDEV_TX_BUSY;
  1159. if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
  1160. tx_flags |= IXGB_TX_FLAGS_VLAN;
  1161. vlan_id = vlan_tx_tag_get(skb);
  1162. }
  1163. first = adapter->tx_ring.next_to_use;
  1164. tso = ixgb_tso(adapter, skb);
  1165. if (tso < 0) {
  1166. dev_kfree_skb_any(skb);
  1167. return NETDEV_TX_OK;
  1168. }
  1169. if (likely(tso))
  1170. tx_flags |= IXGB_TX_FLAGS_TSO;
  1171. else if (ixgb_tx_csum(adapter, skb))
  1172. tx_flags |= IXGB_TX_FLAGS_CSUM;
  1173. ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
  1174. tx_flags);
  1175. netdev->trans_start = jiffies;
  1176. /* Make sure there is space in the ring for the next send. */
  1177. ixgb_maybe_stop_tx(netdev, &adapter->tx_ring, DESC_NEEDED);
  1178. return NETDEV_TX_OK;
  1179. }
  1180. /**
  1181. * ixgb_tx_timeout - Respond to a Tx Hang
  1182. * @netdev: network interface device structure
  1183. **/
  1184. static void
  1185. ixgb_tx_timeout(struct net_device *netdev)
  1186. {
  1187. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1188. /* Do the reset outside of interrupt context */
  1189. schedule_work(&adapter->tx_timeout_task);
  1190. }
  1191. static void
  1192. ixgb_tx_timeout_task(struct work_struct *work)
  1193. {
  1194. struct ixgb_adapter *adapter =
  1195. container_of(work, struct ixgb_adapter, tx_timeout_task);
  1196. adapter->tx_timeout_count++;
  1197. ixgb_down(adapter, true);
  1198. ixgb_up(adapter);
  1199. }
  1200. /**
  1201. * ixgb_get_stats - Get System Network Statistics
  1202. * @netdev: network interface device structure
  1203. *
  1204. * Returns the address of the device statistics structure.
  1205. * The statistics are actually updated from the timer callback.
  1206. **/
  1207. static struct net_device_stats *
  1208. ixgb_get_stats(struct net_device *netdev)
  1209. {
  1210. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1211. return &adapter->net_stats;
  1212. }
  1213. /**
  1214. * ixgb_change_mtu - Change the Maximum Transfer Unit
  1215. * @netdev: network interface device structure
  1216. * @new_mtu: new value for maximum frame size
  1217. *
  1218. * Returns 0 on success, negative on failure
  1219. **/
  1220. static int
  1221. ixgb_change_mtu(struct net_device *netdev, int new_mtu)
  1222. {
  1223. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1224. int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
  1225. int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
  1226. /* MTU < 68 is an error for IPv4 traffic, just don't allow it */
  1227. if ((new_mtu < 68) ||
  1228. (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) {
  1229. DPRINTK(PROBE, ERR, "Invalid MTU setting %d\n", new_mtu);
  1230. return -EINVAL;
  1231. }
  1232. if (old_max_frame == max_frame)
  1233. return 0;
  1234. if (netif_running(netdev))
  1235. ixgb_down(adapter, true);
  1236. adapter->rx_buffer_len = max_frame + 8; /* + 8 for errata */
  1237. netdev->mtu = new_mtu;
  1238. if (netif_running(netdev))
  1239. ixgb_up(adapter);
  1240. return 0;
  1241. }
  1242. /**
  1243. * ixgb_update_stats - Update the board statistics counters.
  1244. * @adapter: board private structure
  1245. **/
  1246. void
  1247. ixgb_update_stats(struct ixgb_adapter *adapter)
  1248. {
  1249. struct net_device *netdev = adapter->netdev;
  1250. struct pci_dev *pdev = adapter->pdev;
  1251. /* Prevent stats update while adapter is being reset */
  1252. if (pci_channel_offline(pdev))
  1253. return;
  1254. if ((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
  1255. (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) {
  1256. u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL);
  1257. u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL);
  1258. u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH);
  1259. u64 bcast = ((u64)bcast_h << 32) | bcast_l;
  1260. multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
  1261. /* fix up multicast stats by removing broadcasts */
  1262. if (multi >= bcast)
  1263. multi -= bcast;
  1264. adapter->stats.mprcl += (multi & 0xFFFFFFFF);
  1265. adapter->stats.mprch += (multi >> 32);
  1266. adapter->stats.bprcl += bcast_l;
  1267. adapter->stats.bprch += bcast_h;
  1268. } else {
  1269. adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
  1270. adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
  1271. adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
  1272. adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
  1273. }
  1274. adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
  1275. adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
  1276. adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
  1277. adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
  1278. adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
  1279. adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
  1280. adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
  1281. adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
  1282. adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
  1283. adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
  1284. adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
  1285. adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
  1286. adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
  1287. adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
  1288. adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
  1289. adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
  1290. adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
  1291. adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
  1292. adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
  1293. adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
  1294. adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
  1295. adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
  1296. adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
  1297. adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
  1298. adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
  1299. adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
  1300. adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
  1301. adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
  1302. adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
  1303. adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
  1304. adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
  1305. adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
  1306. adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
  1307. adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
  1308. adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
  1309. adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
  1310. adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
  1311. adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
  1312. adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
  1313. adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
  1314. adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
  1315. adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
  1316. adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
  1317. adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
  1318. adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
  1319. adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
  1320. adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
  1321. adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
  1322. adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
  1323. adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
  1324. adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
  1325. adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
  1326. adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
  1327. adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
  1328. adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
  1329. adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
  1330. /* Fill out the OS statistics structure */
  1331. adapter->net_stats.rx_packets = adapter->stats.gprcl;
  1332. adapter->net_stats.tx_packets = adapter->stats.gptcl;
  1333. adapter->net_stats.rx_bytes = adapter->stats.gorcl;
  1334. adapter->net_stats.tx_bytes = adapter->stats.gotcl;
  1335. adapter->net_stats.multicast = adapter->stats.mprcl;
  1336. adapter->net_stats.collisions = 0;
  1337. /* ignore RLEC as it reports errors for padded (<64bytes) frames
  1338. * with a length in the type/len field */
  1339. adapter->net_stats.rx_errors =
  1340. /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
  1341. adapter->stats.ruc +
  1342. adapter->stats.roc /*+ adapter->stats.rlec */ +
  1343. adapter->stats.icbc +
  1344. adapter->stats.ecbc + adapter->stats.mpc;
  1345. /* see above
  1346. * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
  1347. */
  1348. adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
  1349. adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
  1350. adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
  1351. adapter->net_stats.rx_over_errors = adapter->stats.mpc;
  1352. adapter->net_stats.tx_errors = 0;
  1353. adapter->net_stats.rx_frame_errors = 0;
  1354. adapter->net_stats.tx_aborted_errors = 0;
  1355. adapter->net_stats.tx_carrier_errors = 0;
  1356. adapter->net_stats.tx_fifo_errors = 0;
  1357. adapter->net_stats.tx_heartbeat_errors = 0;
  1358. adapter->net_stats.tx_window_errors = 0;
  1359. }
  1360. #define IXGB_MAX_INTR 10
  1361. /**
  1362. * ixgb_intr - Interrupt Handler
  1363. * @irq: interrupt number
  1364. * @data: pointer to a network interface device structure
  1365. **/
  1366. static irqreturn_t
  1367. ixgb_intr(int irq, void *data)
  1368. {
  1369. struct net_device *netdev = data;
  1370. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1371. struct ixgb_hw *hw = &adapter->hw;
  1372. u32 icr = IXGB_READ_REG(hw, ICR);
  1373. #ifndef CONFIG_IXGB_NAPI
  1374. unsigned int i;
  1375. #endif
  1376. if (unlikely(!icr))
  1377. return IRQ_NONE; /* Not our interrupt */
  1378. if (unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)))
  1379. if (!test_bit(__IXGB_DOWN, &adapter->flags))
  1380. mod_timer(&adapter->watchdog_timer, jiffies);
  1381. #ifdef CONFIG_IXGB_NAPI
  1382. if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
  1383. /* Disable interrupts and register for poll. The flush
  1384. of the posted write is intentionally left out.
  1385. */
  1386. IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
  1387. __netif_rx_schedule(netdev, &adapter->napi);
  1388. }
  1389. #else
  1390. /* yes, that is actually a & and it is meant to make sure that
  1391. * every pass through this for loop checks both receive and
  1392. * transmit queues for completed descriptors, intended to
  1393. * avoid starvation issues and assist tx/rx fairness. */
  1394. for (i = 0; i < IXGB_MAX_INTR; i++)
  1395. if (!ixgb_clean_rx_irq(adapter) &
  1396. !ixgb_clean_tx_irq(adapter))
  1397. break;
  1398. #endif
  1399. return IRQ_HANDLED;
  1400. }
  1401. #ifdef CONFIG_IXGB_NAPI
  1402. /**
  1403. * ixgb_clean - NAPI Rx polling callback
  1404. * @adapter: board private structure
  1405. **/
  1406. static int
  1407. ixgb_clean(struct napi_struct *napi, int budget)
  1408. {
  1409. struct ixgb_adapter *adapter = container_of(napi, struct ixgb_adapter, napi);
  1410. struct net_device *netdev = adapter->netdev;
  1411. int work_done = 0;
  1412. ixgb_clean_tx_irq(adapter);
  1413. ixgb_clean_rx_irq(adapter, &work_done, budget);
  1414. /* If budget not fully consumed, exit the polling mode */
  1415. if (work_done < budget) {
  1416. netif_rx_complete(netdev, napi);
  1417. if (!test_bit(__IXGB_DOWN, &adapter->flags))
  1418. ixgb_irq_enable(adapter);
  1419. }
  1420. return work_done;
  1421. }
  1422. #endif
  1423. /**
  1424. * ixgb_clean_tx_irq - Reclaim resources after transmit completes
  1425. * @adapter: board private structure
  1426. **/
  1427. static bool
  1428. ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
  1429. {
  1430. struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
  1431. struct net_device *netdev = adapter->netdev;
  1432. struct ixgb_tx_desc *tx_desc, *eop_desc;
  1433. struct ixgb_buffer *buffer_info;
  1434. unsigned int i, eop;
  1435. bool cleaned = false;
  1436. i = tx_ring->next_to_clean;
  1437. eop = tx_ring->buffer_info[i].next_to_watch;
  1438. eop_desc = IXGB_TX_DESC(*tx_ring, eop);
  1439. while (eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
  1440. for (cleaned = false; !cleaned; ) {
  1441. tx_desc = IXGB_TX_DESC(*tx_ring, i);
  1442. buffer_info = &tx_ring->buffer_info[i];
  1443. if (tx_desc->popts &
  1444. (IXGB_TX_DESC_POPTS_TXSM |
  1445. IXGB_TX_DESC_POPTS_IXSM))
  1446. adapter->hw_csum_tx_good++;
  1447. ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
  1448. *(u32 *)&(tx_desc->status) = 0;
  1449. cleaned = (i == eop);
  1450. if (++i == tx_ring->count) i = 0;
  1451. }
  1452. eop = tx_ring->buffer_info[i].next_to_watch;
  1453. eop_desc = IXGB_TX_DESC(*tx_ring, eop);
  1454. }
  1455. tx_ring->next_to_clean = i;
  1456. if (unlikely(cleaned && netif_carrier_ok(netdev) &&
  1457. IXGB_DESC_UNUSED(tx_ring) >= DESC_NEEDED)) {
  1458. /* Make sure that anybody stopping the queue after this
  1459. * sees the new next_to_clean. */
  1460. smp_mb();
  1461. if (netif_queue_stopped(netdev) &&
  1462. !(test_bit(__IXGB_DOWN, &adapter->flags))) {
  1463. netif_wake_queue(netdev);
  1464. ++adapter->restart_queue;
  1465. }
  1466. }
  1467. if (adapter->detect_tx_hung) {
  1468. /* detect a transmit hang in hardware, this serializes the
  1469. * check with the clearing of time_stamp and movement of i */
  1470. adapter->detect_tx_hung = false;
  1471. if (tx_ring->buffer_info[eop].dma &&
  1472. time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + HZ)
  1473. && !(IXGB_READ_REG(&adapter->hw, STATUS) &
  1474. IXGB_STATUS_TXOFF)) {
  1475. /* detected Tx unit hang */
  1476. DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
  1477. " TDH <%x>\n"
  1478. " TDT <%x>\n"
  1479. " next_to_use <%x>\n"
  1480. " next_to_clean <%x>\n"
  1481. "buffer_info[next_to_clean]\n"
  1482. " time_stamp <%lx>\n"
  1483. " next_to_watch <%x>\n"
  1484. " jiffies <%lx>\n"
  1485. " next_to_watch.status <%x>\n",
  1486. IXGB_READ_REG(&adapter->hw, TDH),
  1487. IXGB_READ_REG(&adapter->hw, TDT),
  1488. tx_ring->next_to_use,
  1489. tx_ring->next_to_clean,
  1490. tx_ring->buffer_info[eop].time_stamp,
  1491. eop,
  1492. jiffies,
  1493. eop_desc->status);
  1494. netif_stop_queue(netdev);
  1495. }
  1496. }
  1497. return cleaned;
  1498. }
  1499. /**
  1500. * ixgb_rx_checksum - Receive Checksum Offload for 82597.
  1501. * @adapter: board private structure
  1502. * @rx_desc: receive descriptor
  1503. * @sk_buff: socket buffer with received data
  1504. **/
  1505. static void
  1506. ixgb_rx_checksum(struct ixgb_adapter *adapter,
  1507. struct ixgb_rx_desc *rx_desc,
  1508. struct sk_buff *skb)
  1509. {
  1510. /* Ignore Checksum bit is set OR
  1511. * TCP Checksum has not been calculated
  1512. */
  1513. if ((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
  1514. (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
  1515. skb->ip_summed = CHECKSUM_NONE;
  1516. return;
  1517. }
  1518. /* At this point we know the hardware did the TCP checksum */
  1519. /* now look at the TCP checksum error bit */
  1520. if (rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
  1521. /* let the stack verify checksum errors */
  1522. skb->ip_summed = CHECKSUM_NONE;
  1523. adapter->hw_csum_rx_error++;
  1524. } else {
  1525. /* TCP checksum is good */
  1526. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1527. adapter->hw_csum_rx_good++;
  1528. }
  1529. }
  1530. /**
  1531. * ixgb_clean_rx_irq - Send received data up the network stack,
  1532. * @adapter: board private structure
  1533. **/
  1534. static bool
  1535. #ifdef CONFIG_IXGB_NAPI
  1536. ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
  1537. #else
  1538. ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
  1539. #endif
  1540. {
  1541. struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
  1542. struct net_device *netdev = adapter->netdev;
  1543. struct pci_dev *pdev = adapter->pdev;
  1544. struct ixgb_rx_desc *rx_desc, *next_rxd;
  1545. struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
  1546. u32 length;
  1547. unsigned int i, j;
  1548. int cleaned_count = 0;
  1549. bool cleaned = false;
  1550. i = rx_ring->next_to_clean;
  1551. rx_desc = IXGB_RX_DESC(*rx_ring, i);
  1552. buffer_info = &rx_ring->buffer_info[i];
  1553. while (rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
  1554. struct sk_buff *skb;
  1555. u8 status;
  1556. #ifdef CONFIG_IXGB_NAPI
  1557. if (*work_done >= work_to_do)
  1558. break;
  1559. (*work_done)++;
  1560. #endif
  1561. status = rx_desc->status;
  1562. skb = buffer_info->skb;
  1563. buffer_info->skb = NULL;
  1564. prefetch(skb->data - NET_IP_ALIGN);
  1565. if (++i == rx_ring->count) i = 0;
  1566. next_rxd = IXGB_RX_DESC(*rx_ring, i);
  1567. prefetch(next_rxd);
  1568. if ((j = i + 1) == rx_ring->count) j = 0;
  1569. next2_buffer = &rx_ring->buffer_info[j];
  1570. prefetch(next2_buffer);
  1571. next_buffer = &rx_ring->buffer_info[i];
  1572. cleaned = true;
  1573. cleaned_count++;
  1574. pci_unmap_single(pdev,
  1575. buffer_info->dma,
  1576. buffer_info->length,
  1577. PCI_DMA_FROMDEVICE);
  1578. buffer_info->dma = 0;
  1579. length = le16_to_cpu(rx_desc->length);
  1580. rx_desc->length = 0;
  1581. if (unlikely(!(status & IXGB_RX_DESC_STATUS_EOP))) {
  1582. /* All receives must fit into a single buffer */
  1583. IXGB_DBG("Receive packet consumed multiple buffers "
  1584. "length<%x>\n", length);
  1585. dev_kfree_skb_irq(skb);
  1586. goto rxdesc_done;
  1587. }
  1588. if (unlikely(rx_desc->errors &
  1589. (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE |
  1590. IXGB_RX_DESC_ERRORS_P | IXGB_RX_DESC_ERRORS_RXE))) {
  1591. dev_kfree_skb_irq(skb);
  1592. goto rxdesc_done;
  1593. }
  1594. /* code added for copybreak, this should improve
  1595. * performance for small packets with large amounts
  1596. * of reassembly being done in the stack */
  1597. if (length < copybreak) {
  1598. struct sk_buff *new_skb =
  1599. netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
  1600. if (new_skb) {
  1601. skb_reserve(new_skb, NET_IP_ALIGN);
  1602. skb_copy_to_linear_data_offset(new_skb,
  1603. -NET_IP_ALIGN,
  1604. (skb->data -
  1605. NET_IP_ALIGN),
  1606. (length +
  1607. NET_IP_ALIGN));
  1608. /* save the skb in buffer_info as good */
  1609. buffer_info->skb = skb;
  1610. skb = new_skb;
  1611. }
  1612. }
  1613. /* end copybreak code */
  1614. /* Good Receive */
  1615. skb_put(skb, length);
  1616. /* Receive Checksum Offload */
  1617. ixgb_rx_checksum(adapter, rx_desc, skb);
  1618. skb->protocol = eth_type_trans(skb, netdev);
  1619. #ifdef CONFIG_IXGB_NAPI
  1620. if (adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
  1621. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  1622. le16_to_cpu(rx_desc->special));
  1623. } else {
  1624. netif_receive_skb(skb);
  1625. }
  1626. #else /* CONFIG_IXGB_NAPI */
  1627. if (adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
  1628. vlan_hwaccel_rx(skb, adapter->vlgrp,
  1629. le16_to_cpu(rx_desc->special));
  1630. } else {
  1631. netif_rx(skb);
  1632. }
  1633. #endif /* CONFIG_IXGB_NAPI */
  1634. netdev->last_rx = jiffies;
  1635. rxdesc_done:
  1636. /* clean up descriptor, might be written over by hw */
  1637. rx_desc->status = 0;
  1638. /* return some buffers to hardware, one at a time is too slow */
  1639. if (unlikely(cleaned_count >= IXGB_RX_BUFFER_WRITE)) {
  1640. ixgb_alloc_rx_buffers(adapter, cleaned_count);
  1641. cleaned_count = 0;
  1642. }
  1643. /* use prefetched values */
  1644. rx_desc = next_rxd;
  1645. buffer_info = next_buffer;
  1646. }
  1647. rx_ring->next_to_clean = i;
  1648. cleaned_count = IXGB_DESC_UNUSED(rx_ring);
  1649. if (cleaned_count)
  1650. ixgb_alloc_rx_buffers(adapter, cleaned_count);
  1651. return cleaned;
  1652. }
  1653. /**
  1654. * ixgb_alloc_rx_buffers - Replace used receive buffers
  1655. * @adapter: address of board private structure
  1656. **/
  1657. static void
  1658. ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter, int cleaned_count)
  1659. {
  1660. struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
  1661. struct net_device *netdev = adapter->netdev;
  1662. struct pci_dev *pdev = adapter->pdev;
  1663. struct ixgb_rx_desc *rx_desc;
  1664. struct ixgb_buffer *buffer_info;
  1665. struct sk_buff *skb;
  1666. unsigned int i;
  1667. long cleancount;
  1668. i = rx_ring->next_to_use;
  1669. buffer_info = &rx_ring->buffer_info[i];
  1670. cleancount = IXGB_DESC_UNUSED(rx_ring);
  1671. /* leave three descriptors unused */
  1672. while (--cleancount > 2 && cleaned_count--) {
  1673. /* recycle! its good for you */
  1674. skb = buffer_info->skb;
  1675. if (skb) {
  1676. skb_trim(skb, 0);
  1677. goto map_skb;
  1678. }
  1679. skb = netdev_alloc_skb(netdev, adapter->rx_buffer_len
  1680. + NET_IP_ALIGN);
  1681. if (unlikely(!skb)) {
  1682. /* Better luck next round */
  1683. adapter->alloc_rx_buff_failed++;
  1684. break;
  1685. }
  1686. /* Make buffer alignment 2 beyond a 16 byte boundary
  1687. * this will result in a 16 byte aligned IP header after
  1688. * the 14 byte MAC header is removed
  1689. */
  1690. skb_reserve(skb, NET_IP_ALIGN);
  1691. buffer_info->skb = skb;
  1692. buffer_info->length = adapter->rx_buffer_len;
  1693. map_skb:
  1694. buffer_info->dma = pci_map_single(pdev,
  1695. skb->data,
  1696. adapter->rx_buffer_len,
  1697. PCI_DMA_FROMDEVICE);
  1698. rx_desc = IXGB_RX_DESC(*rx_ring, i);
  1699. rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
  1700. /* guarantee DD bit not set now before h/w gets descriptor
  1701. * this is the rest of the workaround for h/w double
  1702. * writeback. */
  1703. rx_desc->status = 0;
  1704. if (++i == rx_ring->count) i = 0;
  1705. buffer_info = &rx_ring->buffer_info[i];
  1706. }
  1707. if (likely(rx_ring->next_to_use != i)) {
  1708. rx_ring->next_to_use = i;
  1709. if (unlikely(i-- == 0))
  1710. i = (rx_ring->count - 1);
  1711. /* Force memory writes to complete before letting h/w
  1712. * know there are new descriptors to fetch. (Only
  1713. * applicable for weak-ordered memory model archs, such
  1714. * as IA-64). */
  1715. wmb();
  1716. IXGB_WRITE_REG(&adapter->hw, RDT, i);
  1717. }
  1718. }
  1719. /**
  1720. * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping.
  1721. *
  1722. * @param netdev network interface device structure
  1723. * @param grp indicates to enable or disable tagging/stripping
  1724. **/
  1725. static void
  1726. ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
  1727. {
  1728. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1729. u32 ctrl, rctl;
  1730. ixgb_irq_disable(adapter);
  1731. adapter->vlgrp = grp;
  1732. if (grp) {
  1733. /* enable VLAN tag insert/strip */
  1734. ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
  1735. ctrl |= IXGB_CTRL0_VME;
  1736. IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
  1737. /* enable VLAN receive filtering */
  1738. rctl = IXGB_READ_REG(&adapter->hw, RCTL);
  1739. rctl |= IXGB_RCTL_VFE;
  1740. rctl &= ~IXGB_RCTL_CFIEN;
  1741. IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
  1742. } else {
  1743. /* disable VLAN tag insert/strip */
  1744. ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
  1745. ctrl &= ~IXGB_CTRL0_VME;
  1746. IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
  1747. /* disable VLAN filtering */
  1748. rctl = IXGB_READ_REG(&adapter->hw, RCTL);
  1749. rctl &= ~IXGB_RCTL_VFE;
  1750. IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
  1751. }
  1752. /* don't enable interrupts unless we are UP */
  1753. if (adapter->netdev->flags & IFF_UP)
  1754. ixgb_irq_enable(adapter);
  1755. }
  1756. static void
  1757. ixgb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  1758. {
  1759. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1760. u32 vfta, index;
  1761. /* add VID to filter table */
  1762. index = (vid >> 5) & 0x7F;
  1763. vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  1764. vfta |= (1 << (vid & 0x1F));
  1765. ixgb_write_vfta(&adapter->hw, index, vfta);
  1766. }
  1767. static void
  1768. ixgb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  1769. {
  1770. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1771. u32 vfta, index;
  1772. ixgb_irq_disable(adapter);
  1773. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  1774. /* don't enable interrupts unless we are UP */
  1775. if (adapter->netdev->flags & IFF_UP)
  1776. ixgb_irq_enable(adapter);
  1777. /* remove VID from filter table */
  1778. index = (vid >> 5) & 0x7F;
  1779. vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  1780. vfta &= ~(1 << (vid & 0x1F));
  1781. ixgb_write_vfta(&adapter->hw, index, vfta);
  1782. }
  1783. static void
  1784. ixgb_restore_vlan(struct ixgb_adapter *adapter)
  1785. {
  1786. ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  1787. if (adapter->vlgrp) {
  1788. u16 vid;
  1789. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  1790. if (!vlan_group_get_device(adapter->vlgrp, vid))
  1791. continue;
  1792. ixgb_vlan_rx_add_vid(adapter->netdev, vid);
  1793. }
  1794. }
  1795. }
  1796. #ifdef CONFIG_NET_POLL_CONTROLLER
  1797. /*
  1798. * Polling 'interrupt' - used by things like netconsole to send skbs
  1799. * without having to re-enable interrupts. It's not called while
  1800. * the interrupt routine is executing.
  1801. */
  1802. static void ixgb_netpoll(struct net_device *dev)
  1803. {
  1804. struct ixgb_adapter *adapter = netdev_priv(dev);
  1805. disable_irq(adapter->pdev->irq);
  1806. ixgb_intr(adapter->pdev->irq, dev);
  1807. enable_irq(adapter->pdev->irq);
  1808. }
  1809. #endif
  1810. /**
  1811. * ixgb_io_error_detected() - called when PCI error is detected
  1812. * @pdev pointer to pci device with error
  1813. * @state pci channel state after error
  1814. *
  1815. * This callback is called by the PCI subsystem whenever
  1816. * a PCI bus error is detected.
  1817. */
  1818. static pci_ers_result_t ixgb_io_error_detected(struct pci_dev *pdev,
  1819. enum pci_channel_state state)
  1820. {
  1821. struct net_device *netdev = pci_get_drvdata(pdev);
  1822. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1823. if (netif_running(netdev))
  1824. ixgb_down(adapter, true);
  1825. pci_disable_device(pdev);
  1826. /* Request a slot reset. */
  1827. return PCI_ERS_RESULT_NEED_RESET;
  1828. }
  1829. /**
  1830. * ixgb_io_slot_reset - called after the pci bus has been reset.
  1831. * @pdev pointer to pci device with error
  1832. *
  1833. * This callback is called after the PCI bus has been reset.
  1834. * Basically, this tries to restart the card from scratch.
  1835. * This is a shortened version of the device probe/discovery code,
  1836. * it resembles the first-half of the ixgb_probe() routine.
  1837. */
  1838. static pci_ers_result_t ixgb_io_slot_reset(struct pci_dev *pdev)
  1839. {
  1840. struct net_device *netdev = pci_get_drvdata(pdev);
  1841. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1842. if (pci_enable_device(pdev)) {
  1843. DPRINTK(PROBE, ERR, "Cannot re-enable PCI device after reset.\n");
  1844. return PCI_ERS_RESULT_DISCONNECT;
  1845. }
  1846. /* Perform card reset only on one instance of the card */
  1847. if (0 != PCI_FUNC (pdev->devfn))
  1848. return PCI_ERS_RESULT_RECOVERED;
  1849. pci_set_master(pdev);
  1850. netif_carrier_off(netdev);
  1851. netif_stop_queue(netdev);
  1852. ixgb_reset(adapter);
  1853. /* Make sure the EEPROM is good */
  1854. if (!ixgb_validate_eeprom_checksum(&adapter->hw)) {
  1855. DPRINTK(PROBE, ERR, "After reset, the EEPROM checksum is not valid.\n");
  1856. return PCI_ERS_RESULT_DISCONNECT;
  1857. }
  1858. ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
  1859. memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
  1860. if (!is_valid_ether_addr(netdev->perm_addr)) {
  1861. DPRINTK(PROBE, ERR, "After reset, invalid MAC address.\n");
  1862. return PCI_ERS_RESULT_DISCONNECT;
  1863. }
  1864. return PCI_ERS_RESULT_RECOVERED;
  1865. }
  1866. /**
  1867. * ixgb_io_resume - called when its OK to resume normal operations
  1868. * @pdev pointer to pci device with error
  1869. *
  1870. * The error recovery driver tells us that its OK to resume
  1871. * normal operation. Implementation resembles the second-half
  1872. * of the ixgb_probe() routine.
  1873. */
  1874. static void ixgb_io_resume(struct pci_dev *pdev)
  1875. {
  1876. struct net_device *netdev = pci_get_drvdata(pdev);
  1877. struct ixgb_adapter *adapter = netdev_priv(netdev);
  1878. pci_set_master(pdev);
  1879. if (netif_running(netdev)) {
  1880. if (ixgb_up(adapter)) {
  1881. printk ("ixgb: can't bring device back up after reset\n");
  1882. return;
  1883. }
  1884. }
  1885. netif_device_attach(netdev);
  1886. mod_timer(&adapter->watchdog_timer, jiffies);
  1887. }
  1888. /* ixgb_main.c */