ixgb_main.c 62 KB

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