ixgb_main.c 63 KB

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