ixgb_main.c 63 KB

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