ixgb_main.c 62 KB

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