ixgb_main.c 61 KB

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