ixgb_main.c 62 KB

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