PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/kernel/2.6.32_froyo_photon_nightly/drivers/net/e1000e/netdev.c

http://photon-android.googlecode.com/
C | 5445 lines | 3562 code | 798 blank | 1085 comment | 594 complexity | 74d68e1ac47466efebe5b32d7a930a09 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2008 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/module.h>
  22. #include <linux/types.h>
  23. #include <linux/init.h>
  24. #include <linux/pci.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/pagemap.h>
  27. #include <linux/delay.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/tcp.h>
  30. #include <linux/ipv6.h>
  31. #include <net/checksum.h>
  32. #include <net/ip6_checksum.h>
  33. #include <linux/mii.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if_vlan.h>
  36. #include <linux/cpu.h>
  37. #include <linux/smp.h>
  38. #include <linux/pm_qos_params.h>
  39. #include <linux/aer.h>
  40. #include "e1000.h"
  41. #define DRV_VERSION "1.0.2-k2"
  42. char e1000e_driver_name[] = "e1000e";
  43. const char e1000e_driver_version[] = DRV_VERSION;
  44. static const struct e1000_info *e1000_info_tbl[] = {
  45. [board_82571] = &e1000_82571_info,
  46. [board_82572] = &e1000_82572_info,
  47. [board_82573] = &e1000_82573_info,
  48. [board_82574] = &e1000_82574_info,
  49. [board_82583] = &e1000_82583_info,
  50. [board_80003es2lan] = &e1000_es2_info,
  51. [board_ich8lan] = &e1000_ich8_info,
  52. [board_ich9lan] = &e1000_ich9_info,
  53. [board_ich10lan] = &e1000_ich10_info,
  54. [board_pchlan] = &e1000_pch_info,
  55. };
  56. #ifdef DEBUG
  57. /**
  58. * e1000_get_hw_dev_name - return device name string
  59. * used by hardware layer to print debugging information
  60. **/
  61. char *e1000e_get_hw_dev_name(struct e1000_hw *hw)
  62. {
  63. return hw->adapter->netdev->name;
  64. }
  65. #endif
  66. /**
  67. * e1000_desc_unused - calculate if we have unused descriptors
  68. **/
  69. static int e1000_desc_unused(struct e1000_ring *ring)
  70. {
  71. if (ring->next_to_clean > ring->next_to_use)
  72. return ring->next_to_clean - ring->next_to_use - 1;
  73. return ring->count + ring->next_to_clean - ring->next_to_use - 1;
  74. }
  75. /**
  76. * e1000_receive_skb - helper function to handle Rx indications
  77. * @adapter: board private structure
  78. * @status: descriptor status field as written by hardware
  79. * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
  80. * @skb: pointer to sk_buff to be indicated to stack
  81. **/
  82. static void e1000_receive_skb(struct e1000_adapter *adapter,
  83. struct net_device *netdev,
  84. struct sk_buff *skb,
  85. u8 status, __le16 vlan)
  86. {
  87. skb->protocol = eth_type_trans(skb, netdev);
  88. if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
  89. vlan_gro_receive(&adapter->napi, adapter->vlgrp,
  90. le16_to_cpu(vlan), skb);
  91. else
  92. napi_gro_receive(&adapter->napi, skb);
  93. }
  94. /**
  95. * e1000_rx_checksum - Receive Checksum Offload for 82543
  96. * @adapter: board private structure
  97. * @status_err: receive descriptor status and error fields
  98. * @csum: receive descriptor csum field
  99. * @sk_buff: socket buffer with received data
  100. **/
  101. static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
  102. u32 csum, struct sk_buff *skb)
  103. {
  104. u16 status = (u16)status_err;
  105. u8 errors = (u8)(status_err >> 24);
  106. skb->ip_summed = CHECKSUM_NONE;
  107. /* Ignore Checksum bit is set */
  108. if (status & E1000_RXD_STAT_IXSM)
  109. return;
  110. /* TCP/UDP checksum error bit is set */
  111. if (errors & E1000_RXD_ERR_TCPE) {
  112. /* let the stack verify checksum errors */
  113. adapter->hw_csum_err++;
  114. return;
  115. }
  116. /* TCP/UDP Checksum has not been calculated */
  117. if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
  118. return;
  119. /* It must be a TCP or UDP packet with a valid checksum */
  120. if (status & E1000_RXD_STAT_TCPCS) {
  121. /* TCP checksum is good */
  122. skb->ip_summed = CHECKSUM_UNNECESSARY;
  123. } else {
  124. /*
  125. * IP fragment with UDP payload
  126. * Hardware complements the payload checksum, so we undo it
  127. * and then put the value in host order for further stack use.
  128. */
  129. __sum16 sum = (__force __sum16)htons(csum);
  130. skb->csum = csum_unfold(~sum);
  131. skb->ip_summed = CHECKSUM_COMPLETE;
  132. }
  133. adapter->hw_csum_good++;
  134. }
  135. /**
  136. * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
  137. * @adapter: address of board private structure
  138. **/
  139. static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
  140. int cleaned_count)
  141. {
  142. struct net_device *netdev = adapter->netdev;
  143. struct pci_dev *pdev = adapter->pdev;
  144. struct e1000_ring *rx_ring = adapter->rx_ring;
  145. struct e1000_rx_desc *rx_desc;
  146. struct e1000_buffer *buffer_info;
  147. struct sk_buff *skb;
  148. unsigned int i;
  149. unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
  150. i = rx_ring->next_to_use;
  151. buffer_info = &rx_ring->buffer_info[i];
  152. while (cleaned_count--) {
  153. skb = buffer_info->skb;
  154. if (skb) {
  155. skb_trim(skb, 0);
  156. goto map_skb;
  157. }
  158. skb = netdev_alloc_skb(netdev, bufsz);
  159. if (!skb) {
  160. /* Better luck next round */
  161. adapter->alloc_rx_buff_failed++;
  162. break;
  163. }
  164. /*
  165. * Make buffer alignment 2 beyond a 16 byte boundary
  166. * this will result in a 16 byte aligned IP header after
  167. * the 14 byte MAC header is removed
  168. */
  169. skb_reserve(skb, NET_IP_ALIGN);
  170. buffer_info->skb = skb;
  171. map_skb:
  172. buffer_info->dma = pci_map_single(pdev, skb->data,
  173. adapter->rx_buffer_len,
  174. PCI_DMA_FROMDEVICE);
  175. if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
  176. dev_err(&pdev->dev, "RX DMA map failed\n");
  177. adapter->rx_dma_failed++;
  178. break;
  179. }
  180. rx_desc = E1000_RX_DESC(*rx_ring, i);
  181. rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  182. i++;
  183. if (i == rx_ring->count)
  184. i = 0;
  185. buffer_info = &rx_ring->buffer_info[i];
  186. }
  187. if (rx_ring->next_to_use != i) {
  188. rx_ring->next_to_use = i;
  189. if (i-- == 0)
  190. i = (rx_ring->count - 1);
  191. /*
  192. * Force memory writes to complete before letting h/w
  193. * know there are new descriptors to fetch. (Only
  194. * applicable for weak-ordered memory model archs,
  195. * such as IA-64).
  196. */
  197. wmb();
  198. writel(i, adapter->hw.hw_addr + rx_ring->tail);
  199. }
  200. }
  201. /**
  202. * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
  203. * @adapter: address of board private structure
  204. **/
  205. static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
  206. int cleaned_count)
  207. {
  208. struct net_device *netdev = adapter->netdev;
  209. struct pci_dev *pdev = adapter->pdev;
  210. union e1000_rx_desc_packet_split *rx_desc;
  211. struct e1000_ring *rx_ring = adapter->rx_ring;
  212. struct e1000_buffer *buffer_info;
  213. struct e1000_ps_page *ps_page;
  214. struct sk_buff *skb;
  215. unsigned int i, j;
  216. i = rx_ring->next_to_use;
  217. buffer_info = &rx_ring->buffer_info[i];
  218. while (cleaned_count--) {
  219. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  220. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  221. ps_page = &buffer_info->ps_pages[j];
  222. if (j >= adapter->rx_ps_pages) {
  223. /* all unused desc entries get hw null ptr */
  224. rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
  225. continue;
  226. }
  227. if (!ps_page->page) {
  228. ps_page->page = alloc_page(GFP_ATOMIC);
  229. if (!ps_page->page) {
  230. adapter->alloc_rx_buff_failed++;
  231. goto no_buffers;
  232. }
  233. ps_page->dma = pci_map_page(pdev,
  234. ps_page->page,
  235. 0, PAGE_SIZE,
  236. PCI_DMA_FROMDEVICE);
  237. if (pci_dma_mapping_error(pdev, ps_page->dma)) {
  238. dev_err(&adapter->pdev->dev,
  239. "RX DMA page map failed\n");
  240. adapter->rx_dma_failed++;
  241. goto no_buffers;
  242. }
  243. }
  244. /*
  245. * Refresh the desc even if buffer_addrs
  246. * didn't change because each write-back
  247. * erases this info.
  248. */
  249. rx_desc->read.buffer_addr[j+1] =
  250. cpu_to_le64(ps_page->dma);
  251. }
  252. skb = netdev_alloc_skb(netdev,
  253. adapter->rx_ps_bsize0 + NET_IP_ALIGN);
  254. if (!skb) {
  255. adapter->alloc_rx_buff_failed++;
  256. break;
  257. }
  258. /*
  259. * Make buffer alignment 2 beyond a 16 byte boundary
  260. * this will result in a 16 byte aligned IP header after
  261. * the 14 byte MAC header is removed
  262. */
  263. skb_reserve(skb, NET_IP_ALIGN);
  264. buffer_info->skb = skb;
  265. buffer_info->dma = pci_map_single(pdev, skb->data,
  266. adapter->rx_ps_bsize0,
  267. PCI_DMA_FROMDEVICE);
  268. if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
  269. dev_err(&pdev->dev, "RX DMA map failed\n");
  270. adapter->rx_dma_failed++;
  271. /* cleanup skb */
  272. dev_kfree_skb_any(skb);
  273. buffer_info->skb = NULL;
  274. break;
  275. }
  276. rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
  277. i++;
  278. if (i == rx_ring->count)
  279. i = 0;
  280. buffer_info = &rx_ring->buffer_info[i];
  281. }
  282. no_buffers:
  283. if (rx_ring->next_to_use != i) {
  284. rx_ring->next_to_use = i;
  285. if (!(i--))
  286. i = (rx_ring->count - 1);
  287. /*
  288. * Force memory writes to complete before letting h/w
  289. * know there are new descriptors to fetch. (Only
  290. * applicable for weak-ordered memory model archs,
  291. * such as IA-64).
  292. */
  293. wmb();
  294. /*
  295. * Hardware increments by 16 bytes, but packet split
  296. * descriptors are 32 bytes...so we increment tail
  297. * twice as much.
  298. */
  299. writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
  300. }
  301. }
  302. /**
  303. * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
  304. * @adapter: address of board private structure
  305. * @cleaned_count: number of buffers to allocate this pass
  306. **/
  307. static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
  308. int cleaned_count)
  309. {
  310. struct net_device *netdev = adapter->netdev;
  311. struct pci_dev *pdev = adapter->pdev;
  312. struct e1000_rx_desc *rx_desc;
  313. struct e1000_ring *rx_ring = adapter->rx_ring;
  314. struct e1000_buffer *buffer_info;
  315. struct sk_buff *skb;
  316. unsigned int i;
  317. unsigned int bufsz = 256 -
  318. 16 /* for skb_reserve */ -
  319. NET_IP_ALIGN;
  320. i = rx_ring->next_to_use;
  321. buffer_info = &rx_ring->buffer_info[i];
  322. while (cleaned_count--) {
  323. skb = buffer_info->skb;
  324. if (skb) {
  325. skb_trim(skb, 0);
  326. goto check_page;
  327. }
  328. skb = netdev_alloc_skb(netdev, bufsz);
  329. if (unlikely(!skb)) {
  330. /* Better luck next round */
  331. adapter->alloc_rx_buff_failed++;
  332. break;
  333. }
  334. /* Make buffer alignment 2 beyond a 16 byte boundary
  335. * this will result in a 16 byte aligned IP header after
  336. * the 14 byte MAC header is removed
  337. */
  338. skb_reserve(skb, NET_IP_ALIGN);
  339. buffer_info->skb = skb;
  340. check_page:
  341. /* allocate a new page if necessary */
  342. if (!buffer_info->page) {
  343. buffer_info->page = alloc_page(GFP_ATOMIC);
  344. if (unlikely(!buffer_info->page)) {
  345. adapter->alloc_rx_buff_failed++;
  346. break;
  347. }
  348. }
  349. if (!buffer_info->dma)
  350. buffer_info->dma = pci_map_page(pdev,
  351. buffer_info->page, 0,
  352. PAGE_SIZE,
  353. PCI_DMA_FROMDEVICE);
  354. rx_desc = E1000_RX_DESC(*rx_ring, i);
  355. rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  356. if (unlikely(++i == rx_ring->count))
  357. i = 0;
  358. buffer_info = &rx_ring->buffer_info[i];
  359. }
  360. if (likely(rx_ring->next_to_use != i)) {
  361. rx_ring->next_to_use = i;
  362. if (unlikely(i-- == 0))
  363. i = (rx_ring->count - 1);
  364. /* Force memory writes to complete before letting h/w
  365. * know there are new descriptors to fetch. (Only
  366. * applicable for weak-ordered memory model archs,
  367. * such as IA-64). */
  368. wmb();
  369. writel(i, adapter->hw.hw_addr + rx_ring->tail);
  370. }
  371. }
  372. /**
  373. * e1000_clean_rx_irq - Send received data up the network stack; legacy
  374. * @adapter: board private structure
  375. *
  376. * the return value indicates whether actual cleaning was done, there
  377. * is no guarantee that everything was cleaned
  378. **/
  379. static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
  380. int *work_done, int work_to_do)
  381. {
  382. struct net_device *netdev = adapter->netdev;
  383. struct pci_dev *pdev = adapter->pdev;
  384. struct e1000_ring *rx_ring = adapter->rx_ring;
  385. struct e1000_rx_desc *rx_desc, *next_rxd;
  386. struct e1000_buffer *buffer_info, *next_buffer;
  387. u32 length;
  388. unsigned int i;
  389. int cleaned_count = 0;
  390. bool cleaned = 0;
  391. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  392. i = rx_ring->next_to_clean;
  393. rx_desc = E1000_RX_DESC(*rx_ring, i);
  394. buffer_info = &rx_ring->buffer_info[i];
  395. while (rx_desc->status & E1000_RXD_STAT_DD) {
  396. struct sk_buff *skb;
  397. u8 status;
  398. if (*work_done >= work_to_do)
  399. break;
  400. (*work_done)++;
  401. status = rx_desc->status;
  402. skb = buffer_info->skb;
  403. buffer_info->skb = NULL;
  404. prefetch(skb->data - NET_IP_ALIGN);
  405. i++;
  406. if (i == rx_ring->count)
  407. i = 0;
  408. next_rxd = E1000_RX_DESC(*rx_ring, i);
  409. prefetch(next_rxd);
  410. next_buffer = &rx_ring->buffer_info[i];
  411. cleaned = 1;
  412. cleaned_count++;
  413. pci_unmap_single(pdev,
  414. buffer_info->dma,
  415. adapter->rx_buffer_len,
  416. PCI_DMA_FROMDEVICE);
  417. buffer_info->dma = 0;
  418. length = le16_to_cpu(rx_desc->length);
  419. /*
  420. * !EOP means multiple descriptors were used to store a single
  421. * packet, if that's the case we need to toss it. In fact, we
  422. * need to toss every packet with the EOP bit clear and the
  423. * next frame that _does_ have the EOP bit set, as it is by
  424. * definition only a frame fragment
  425. */
  426. if (unlikely(!(status & E1000_RXD_STAT_EOP)))
  427. adapter->flags2 |= FLAG2_IS_DISCARDING;
  428. if (adapter->flags2 & FLAG2_IS_DISCARDING) {
  429. /* All receives must fit into a single buffer */
  430. e_dbg("%s: Receive packet consumed multiple buffers\n",
  431. netdev->name);
  432. /* recycle */
  433. buffer_info->skb = skb;
  434. if (status & E1000_RXD_STAT_EOP)
  435. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  436. goto next_desc;
  437. }
  438. if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
  439. /* recycle */
  440. buffer_info->skb = skb;
  441. goto next_desc;
  442. }
  443. /* adjust length to remove Ethernet CRC */
  444. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
  445. length -= 4;
  446. total_rx_bytes += length;
  447. total_rx_packets++;
  448. /*
  449. * code added for copybreak, this should improve
  450. * performance for small packets with large amounts
  451. * of reassembly being done in the stack
  452. */
  453. if (length < copybreak) {
  454. struct sk_buff *new_skb =
  455. netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
  456. if (new_skb) {
  457. skb_reserve(new_skb, NET_IP_ALIGN);
  458. skb_copy_to_linear_data_offset(new_skb,
  459. -NET_IP_ALIGN,
  460. (skb->data -
  461. NET_IP_ALIGN),
  462. (length +
  463. NET_IP_ALIGN));
  464. /* save the skb in buffer_info as good */
  465. buffer_info->skb = skb;
  466. skb = new_skb;
  467. }
  468. /* else just continue with the old one */
  469. }
  470. /* end copybreak code */
  471. skb_put(skb, length);
  472. /* Receive Checksum Offload */
  473. e1000_rx_checksum(adapter,
  474. (u32)(status) |
  475. ((u32)(rx_desc->errors) << 24),
  476. le16_to_cpu(rx_desc->csum), skb);
  477. e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
  478. next_desc:
  479. rx_desc->status = 0;
  480. /* return some buffers to hardware, one at a time is too slow */
  481. if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
  482. adapter->alloc_rx_buf(adapter, cleaned_count);
  483. cleaned_count = 0;
  484. }
  485. /* use prefetched values */
  486. rx_desc = next_rxd;
  487. buffer_info = next_buffer;
  488. }
  489. rx_ring->next_to_clean = i;
  490. cleaned_count = e1000_desc_unused(rx_ring);
  491. if (cleaned_count)
  492. adapter->alloc_rx_buf(adapter, cleaned_count);
  493. adapter->total_rx_bytes += total_rx_bytes;
  494. adapter->total_rx_packets += total_rx_packets;
  495. adapter->net_stats.rx_bytes += total_rx_bytes;
  496. adapter->net_stats.rx_packets += total_rx_packets;
  497. return cleaned;
  498. }
  499. static void e1000_put_txbuf(struct e1000_adapter *adapter,
  500. struct e1000_buffer *buffer_info)
  501. {
  502. buffer_info->dma = 0;
  503. if (buffer_info->skb) {
  504. skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
  505. DMA_TO_DEVICE);
  506. dev_kfree_skb_any(buffer_info->skb);
  507. buffer_info->skb = NULL;
  508. }
  509. buffer_info->time_stamp = 0;
  510. }
  511. static void e1000_print_tx_hang(struct e1000_adapter *adapter)
  512. {
  513. struct e1000_ring *tx_ring = adapter->tx_ring;
  514. unsigned int i = tx_ring->next_to_clean;
  515. unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
  516. struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
  517. /* detected Tx unit hang */
  518. e_err("Detected Tx Unit Hang:\n"
  519. " TDH <%x>\n"
  520. " TDT <%x>\n"
  521. " next_to_use <%x>\n"
  522. " next_to_clean <%x>\n"
  523. "buffer_info[next_to_clean]:\n"
  524. " time_stamp <%lx>\n"
  525. " next_to_watch <%x>\n"
  526. " jiffies <%lx>\n"
  527. " next_to_watch.status <%x>\n",
  528. readl(adapter->hw.hw_addr + tx_ring->head),
  529. readl(adapter->hw.hw_addr + tx_ring->tail),
  530. tx_ring->next_to_use,
  531. tx_ring->next_to_clean,
  532. tx_ring->buffer_info[eop].time_stamp,
  533. eop,
  534. jiffies,
  535. eop_desc->upper.fields.status);
  536. }
  537. /**
  538. * e1000_clean_tx_irq - Reclaim resources after transmit completes
  539. * @adapter: board private structure
  540. *
  541. * the return value indicates whether actual cleaning was done, there
  542. * is no guarantee that everything was cleaned
  543. **/
  544. static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
  545. {
  546. struct net_device *netdev = adapter->netdev;
  547. struct e1000_hw *hw = &adapter->hw;
  548. struct e1000_ring *tx_ring = adapter->tx_ring;
  549. struct e1000_tx_desc *tx_desc, *eop_desc;
  550. struct e1000_buffer *buffer_info;
  551. unsigned int i, eop;
  552. unsigned int count = 0;
  553. unsigned int total_tx_bytes = 0, total_tx_packets = 0;
  554. i = tx_ring->next_to_clean;
  555. eop = tx_ring->buffer_info[i].next_to_watch;
  556. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  557. while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
  558. (count < tx_ring->count)) {
  559. bool cleaned = false;
  560. for (; !cleaned; count++) {
  561. tx_desc = E1000_TX_DESC(*tx_ring, i);
  562. buffer_info = &tx_ring->buffer_info[i];
  563. cleaned = (i == eop);
  564. if (cleaned) {
  565. struct sk_buff *skb = buffer_info->skb;
  566. unsigned int segs, bytecount;
  567. segs = skb_shinfo(skb)->gso_segs ?: 1;
  568. /* multiply data chunks by size of headers */
  569. bytecount = ((segs - 1) * skb_headlen(skb)) +
  570. skb->len;
  571. total_tx_packets += segs;
  572. total_tx_bytes += bytecount;
  573. }
  574. e1000_put_txbuf(adapter, buffer_info);
  575. tx_desc->upper.data = 0;
  576. i++;
  577. if (i == tx_ring->count)
  578. i = 0;
  579. }
  580. eop = tx_ring->buffer_info[i].next_to_watch;
  581. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  582. }
  583. tx_ring->next_to_clean = i;
  584. #define TX_WAKE_THRESHOLD 32
  585. if (count && netif_carrier_ok(netdev) &&
  586. e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
  587. /* Make sure that anybody stopping the queue after this
  588. * sees the new next_to_clean.
  589. */
  590. smp_mb();
  591. if (netif_queue_stopped(netdev) &&
  592. !(test_bit(__E1000_DOWN, &adapter->state))) {
  593. netif_wake_queue(netdev);
  594. ++adapter->restart_queue;
  595. }
  596. }
  597. if (adapter->detect_tx_hung) {
  598. /* Detect a transmit hang in hardware, this serializes the
  599. * check with the clearing of time_stamp and movement of i */
  600. adapter->detect_tx_hung = 0;
  601. if (tx_ring->buffer_info[i].time_stamp &&
  602. time_after(jiffies, tx_ring->buffer_info[i].time_stamp
  603. + (adapter->tx_timeout_factor * HZ))
  604. && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
  605. e1000_print_tx_hang(adapter);
  606. netif_stop_queue(netdev);
  607. }
  608. }
  609. adapter->total_tx_bytes += total_tx_bytes;
  610. adapter->total_tx_packets += total_tx_packets;
  611. adapter->net_stats.tx_bytes += total_tx_bytes;
  612. adapter->net_stats.tx_packets += total_tx_packets;
  613. return (count < tx_ring->count);
  614. }
  615. /**
  616. * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
  617. * @adapter: board private structure
  618. *
  619. * the return value indicates whether actual cleaning was done, there
  620. * is no guarantee that everything was cleaned
  621. **/
  622. static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  623. int *work_done, int work_to_do)
  624. {
  625. union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
  626. struct net_device *netdev = adapter->netdev;
  627. struct pci_dev *pdev = adapter->pdev;
  628. struct e1000_ring *rx_ring = adapter->rx_ring;
  629. struct e1000_buffer *buffer_info, *next_buffer;
  630. struct e1000_ps_page *ps_page;
  631. struct sk_buff *skb;
  632. unsigned int i, j;
  633. u32 length, staterr;
  634. int cleaned_count = 0;
  635. bool cleaned = 0;
  636. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  637. i = rx_ring->next_to_clean;
  638. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  639. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  640. buffer_info = &rx_ring->buffer_info[i];
  641. while (staterr & E1000_RXD_STAT_DD) {
  642. if (*work_done >= work_to_do)
  643. break;
  644. (*work_done)++;
  645. skb = buffer_info->skb;
  646. /* in the packet split case this is header only */
  647. prefetch(skb->data - NET_IP_ALIGN);
  648. i++;
  649. if (i == rx_ring->count)
  650. i = 0;
  651. next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
  652. prefetch(next_rxd);
  653. next_buffer = &rx_ring->buffer_info[i];
  654. cleaned = 1;
  655. cleaned_count++;
  656. pci_unmap_single(pdev, buffer_info->dma,
  657. adapter->rx_ps_bsize0,
  658. PCI_DMA_FROMDEVICE);
  659. buffer_info->dma = 0;
  660. /* see !EOP comment in other rx routine */
  661. if (!(staterr & E1000_RXD_STAT_EOP))
  662. adapter->flags2 |= FLAG2_IS_DISCARDING;
  663. if (adapter->flags2 & FLAG2_IS_DISCARDING) {
  664. e_dbg("%s: Packet Split buffers didn't pick up the "
  665. "full packet\n", netdev->name);
  666. dev_kfree_skb_irq(skb);
  667. if (staterr & E1000_RXD_STAT_EOP)
  668. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  669. goto next_desc;
  670. }
  671. if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
  672. dev_kfree_skb_irq(skb);
  673. goto next_desc;
  674. }
  675. length = le16_to_cpu(rx_desc->wb.middle.length0);
  676. if (!length) {
  677. e_dbg("%s: Last part of the packet spanning multiple "
  678. "descriptors\n", netdev->name);
  679. dev_kfree_skb_irq(skb);
  680. goto next_desc;
  681. }
  682. /* Good Receive */
  683. skb_put(skb, length);
  684. {
  685. /*
  686. * this looks ugly, but it seems compiler issues make it
  687. * more efficient than reusing j
  688. */
  689. int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
  690. /*
  691. * page alloc/put takes too long and effects small packet
  692. * throughput, so unsplit small packets and save the alloc/put
  693. * only valid in softirq (napi) context to call kmap_*
  694. */
  695. if (l1 && (l1 <= copybreak) &&
  696. ((length + l1) <= adapter->rx_ps_bsize0)) {
  697. u8 *vaddr;
  698. ps_page = &buffer_info->ps_pages[0];
  699. /*
  700. * there is no documentation about how to call
  701. * kmap_atomic, so we can't hold the mapping
  702. * very long
  703. */
  704. pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
  705. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  706. vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
  707. memcpy(skb_tail_pointer(skb), vaddr, l1);
  708. kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
  709. pci_dma_sync_single_for_device(pdev, ps_page->dma,
  710. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  711. /* remove the CRC */
  712. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
  713. l1 -= 4;
  714. skb_put(skb, l1);
  715. goto copydone;
  716. } /* if */
  717. }
  718. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  719. length = le16_to_cpu(rx_desc->wb.upper.length[j]);
  720. if (!length)
  721. break;
  722. ps_page = &buffer_info->ps_pages[j];
  723. pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
  724. PCI_DMA_FROMDEVICE);
  725. ps_page->dma = 0;
  726. skb_fill_page_desc(skb, j, ps_page->page, 0, length);
  727. ps_page->page = NULL;
  728. skb->len += length;
  729. skb->data_len += length;
  730. skb->truesize += length;
  731. }
  732. /* strip the ethernet crc, problem is we're using pages now so
  733. * this whole operation can get a little cpu intensive
  734. */
  735. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
  736. pskb_trim(skb, skb->len - 4);
  737. copydone:
  738. total_rx_bytes += skb->len;
  739. total_rx_packets++;
  740. e1000_rx_checksum(adapter, staterr, le16_to_cpu(
  741. rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
  742. if (rx_desc->wb.upper.header_status &
  743. cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
  744. adapter->rx_hdr_split++;
  745. e1000_receive_skb(adapter, netdev, skb,
  746. staterr, rx_desc->wb.middle.vlan);
  747. next_desc:
  748. rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
  749. buffer_info->skb = NULL;
  750. /* return some buffers to hardware, one at a time is too slow */
  751. if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
  752. adapter->alloc_rx_buf(adapter, cleaned_count);
  753. cleaned_count = 0;
  754. }
  755. /* use prefetched values */
  756. rx_desc = next_rxd;
  757. buffer_info = next_buffer;
  758. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  759. }
  760. rx_ring->next_to_clean = i;
  761. cleaned_count = e1000_desc_unused(rx_ring);
  762. if (cleaned_count)
  763. adapter->alloc_rx_buf(adapter, cleaned_count);
  764. adapter->total_rx_bytes += total_rx_bytes;
  765. adapter->total_rx_packets += total_rx_packets;
  766. adapter->net_stats.rx_bytes += total_rx_bytes;
  767. adapter->net_stats.rx_packets += total_rx_packets;
  768. return cleaned;
  769. }
  770. /**
  771. * e1000_consume_page - helper function
  772. **/
  773. static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
  774. u16 length)
  775. {
  776. bi->page = NULL;
  777. skb->len += length;
  778. skb->data_len += length;
  779. skb->truesize += length;
  780. }
  781. /**
  782. * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
  783. * @adapter: board private structure
  784. *
  785. * the return value indicates whether actual cleaning was done, there
  786. * is no guarantee that everything was cleaned
  787. **/
  788. static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
  789. int *work_done, int work_to_do)
  790. {
  791. struct net_device *netdev = adapter->netdev;
  792. struct pci_dev *pdev = adapter->pdev;
  793. struct e1000_ring *rx_ring = adapter->rx_ring;
  794. struct e1000_rx_desc *rx_desc, *next_rxd;
  795. struct e1000_buffer *buffer_info, *next_buffer;
  796. u32 length;
  797. unsigned int i;
  798. int cleaned_count = 0;
  799. bool cleaned = false;
  800. unsigned int total_rx_bytes=0, total_rx_packets=0;
  801. i = rx_ring->next_to_clean;
  802. rx_desc = E1000_RX_DESC(*rx_ring, i);
  803. buffer_info = &rx_ring->buffer_info[i];
  804. while (rx_desc->status & E1000_RXD_STAT_DD) {
  805. struct sk_buff *skb;
  806. u8 status;
  807. if (*work_done >= work_to_do)
  808. break;
  809. (*work_done)++;
  810. status = rx_desc->status;
  811. skb = buffer_info->skb;
  812. buffer_info->skb = NULL;
  813. ++i;
  814. if (i == rx_ring->count)
  815. i = 0;
  816. next_rxd = E1000_RX_DESC(*rx_ring, i);
  817. prefetch(next_rxd);
  818. next_buffer = &rx_ring->buffer_info[i];
  819. cleaned = true;
  820. cleaned_count++;
  821. pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE,
  822. PCI_DMA_FROMDEVICE);
  823. buffer_info->dma = 0;
  824. length = le16_to_cpu(rx_desc->length);
  825. /* errors is only valid for DD + EOP descriptors */
  826. if (unlikely((status & E1000_RXD_STAT_EOP) &&
  827. (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
  828. /* recycle both page and skb */
  829. buffer_info->skb = skb;
  830. /* an error means any chain goes out the window
  831. * too */
  832. if (rx_ring->rx_skb_top)
  833. dev_kfree_skb(rx_ring->rx_skb_top);
  834. rx_ring->rx_skb_top = NULL;
  835. goto next_desc;
  836. }
  837. #define rxtop rx_ring->rx_skb_top
  838. if (!(status & E1000_RXD_STAT_EOP)) {
  839. /* this descriptor is only the beginning (or middle) */
  840. if (!rxtop) {
  841. /* this is the beginning of a chain */
  842. rxtop = skb;
  843. skb_fill_page_desc(rxtop, 0, buffer_info->page,
  844. 0, length);
  845. } else {
  846. /* this is the middle of a chain */
  847. skb_fill_page_desc(rxtop,
  848. skb_shinfo(rxtop)->nr_frags,
  849. buffer_info->page, 0, length);
  850. /* re-use the skb, only consumed the page */
  851. buffer_info->skb = skb;
  852. }
  853. e1000_consume_page(buffer_info, rxtop, length);
  854. goto next_desc;
  855. } else {
  856. if (rxtop) {
  857. /* end of the chain */
  858. skb_fill_page_desc(rxtop,
  859. skb_shinfo(rxtop)->nr_frags,
  860. buffer_info->page, 0, length);
  861. /* re-use the current skb, we only consumed the
  862. * page */
  863. buffer_info->skb = skb;
  864. skb = rxtop;
  865. rxtop = NULL;
  866. e1000_consume_page(buffer_info, skb, length);
  867. } else {
  868. /* no chain, got EOP, this buf is the packet
  869. * copybreak to save the put_page/alloc_page */
  870. if (length <= copybreak &&
  871. skb_tailroom(skb) >= length) {
  872. u8 *vaddr;
  873. vaddr = kmap_atomic(buffer_info->page,
  874. KM_SKB_DATA_SOFTIRQ);
  875. memcpy(skb_tail_pointer(skb), vaddr,
  876. length);
  877. kunmap_atomic(vaddr,
  878. KM_SKB_DATA_SOFTIRQ);
  879. /* re-use the page, so don't erase
  880. * buffer_info->page */
  881. skb_put(skb, length);
  882. } else {
  883. skb_fill_page_desc(skb, 0,
  884. buffer_info->page, 0,
  885. length);
  886. e1000_consume_page(buffer_info, skb,
  887. length);
  888. }
  889. }
  890. }
  891. /* Receive Checksum Offload XXX recompute due to CRC strip? */
  892. e1000_rx_checksum(adapter,
  893. (u32)(status) |
  894. ((u32)(rx_desc->errors) << 24),
  895. le16_to_cpu(rx_desc->csum), skb);
  896. /* probably a little skewed due to removing CRC */
  897. total_rx_bytes += skb->len;
  898. total_rx_packets++;
  899. /* eth type trans needs skb->data to point to something */
  900. if (!pskb_may_pull(skb, ETH_HLEN)) {
  901. e_err("pskb_may_pull failed.\n");
  902. dev_kfree_skb(skb);
  903. goto next_desc;
  904. }
  905. e1000_receive_skb(adapter, netdev, skb, status,
  906. rx_desc->special);
  907. next_desc:
  908. rx_desc->status = 0;
  909. /* return some buffers to hardware, one at a time is too slow */
  910. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  911. adapter->alloc_rx_buf(adapter, cleaned_count);
  912. cleaned_count = 0;
  913. }
  914. /* use prefetched values */
  915. rx_desc = next_rxd;
  916. buffer_info = next_buffer;
  917. }
  918. rx_ring->next_to_clean = i;
  919. cleaned_count = e1000_desc_unused(rx_ring);
  920. if (cleaned_count)
  921. adapter->alloc_rx_buf(adapter, cleaned_count);
  922. adapter->total_rx_bytes += total_rx_bytes;
  923. adapter->total_rx_packets += total_rx_packets;
  924. adapter->net_stats.rx_bytes += total_rx_bytes;
  925. adapter->net_stats.rx_packets += total_rx_packets;
  926. return cleaned;
  927. }
  928. /**
  929. * e1000_clean_rx_ring - Free Rx Buffers per Queue
  930. * @adapter: board private structure
  931. **/
  932. static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
  933. {
  934. struct e1000_ring *rx_ring = adapter->rx_ring;
  935. struct e1000_buffer *buffer_info;
  936. struct e1000_ps_page *ps_page;
  937. struct pci_dev *pdev = adapter->pdev;
  938. unsigned int i, j;
  939. /* Free all the Rx ring sk_buffs */
  940. for (i = 0; i < rx_ring->count; i++) {
  941. buffer_info = &rx_ring->buffer_info[i];
  942. if (buffer_info->dma) {
  943. if (adapter->clean_rx == e1000_clean_rx_irq)
  944. pci_unmap_single(pdev, buffer_info->dma,
  945. adapter->rx_buffer_len,
  946. PCI_DMA_FROMDEVICE);
  947. else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
  948. pci_unmap_page(pdev, buffer_info->dma,
  949. PAGE_SIZE,
  950. PCI_DMA_FROMDEVICE);
  951. else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
  952. pci_unmap_single(pdev, buffer_info->dma,
  953. adapter->rx_ps_bsize0,
  954. PCI_DMA_FROMDEVICE);
  955. buffer_info->dma = 0;
  956. }
  957. if (buffer_info->page) {
  958. put_page(buffer_info->page);
  959. buffer_info->page = NULL;
  960. }
  961. if (buffer_info->skb) {
  962. dev_kfree_skb(buffer_info->skb);
  963. buffer_info->skb = NULL;
  964. }
  965. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  966. ps_page = &buffer_info->ps_pages[j];
  967. if (!ps_page->page)
  968. break;
  969. pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
  970. PCI_DMA_FROMDEVICE);
  971. ps_page->dma = 0;
  972. put_page(ps_page->page);
  973. ps_page->page = NULL;
  974. }
  975. }
  976. /* there also may be some cached data from a chained receive */
  977. if (rx_ring->rx_skb_top) {
  978. dev_kfree_skb(rx_ring->rx_skb_top);
  979. rx_ring->rx_skb_top = NULL;
  980. }
  981. /* Zero out the descriptor ring */
  982. memset(rx_ring->desc, 0, rx_ring->size);
  983. rx_ring->next_to_clean = 0;
  984. rx_ring->next_to_use = 0;
  985. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  986. writel(0, adapter->hw.hw_addr + rx_ring->head);
  987. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  988. }
  989. static void e1000e_downshift_workaround(struct work_struct *work)
  990. {
  991. struct e1000_adapter *adapter = container_of(work,
  992. struct e1000_adapter, downshift_task);
  993. e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
  994. }
  995. /**
  996. * e1000_intr_msi - Interrupt Handler
  997. * @irq: interrupt number
  998. * @data: pointer to a network interface device structure
  999. **/
  1000. static irqreturn_t e1000_intr_msi(int irq, void *data)
  1001. {
  1002. struct net_device *netdev = data;
  1003. struct e1000_adapter *adapter = netdev_priv(netdev);
  1004. struct e1000_hw *hw = &adapter->hw;
  1005. u32 icr = er32(ICR);
  1006. /*
  1007. * read ICR disables interrupts using IAM
  1008. */
  1009. if (icr & E1000_ICR_LSC) {
  1010. hw->mac.get_link_status = 1;
  1011. /*
  1012. * ICH8 workaround-- Call gig speed drop workaround on cable
  1013. * disconnect (LSC) before accessing any PHY registers
  1014. */
  1015. if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
  1016. (!(er32(STATUS) & E1000_STATUS_LU)))
  1017. schedule_work(&adapter->downshift_task);
  1018. /*
  1019. * 80003ES2LAN workaround-- For packet buffer work-around on
  1020. * link down event; disable receives here in the ISR and reset
  1021. * adapter in watchdog
  1022. */
  1023. if (netif_carrier_ok(netdev) &&
  1024. adapter->flags & FLAG_RX_NEEDS_RESTART) {
  1025. /* disable receives */
  1026. u32 rctl = er32(RCTL);
  1027. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  1028. adapter->flags |= FLAG_RX_RESTART_NOW;
  1029. }
  1030. /* guard against interrupt when we're going down */
  1031. if (!test_bit(__E1000_DOWN, &adapter->state))
  1032. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1033. }
  1034. if (napi_schedule_prep(&adapter->napi)) {
  1035. adapter->total_tx_bytes = 0;
  1036. adapter->total_tx_packets = 0;
  1037. adapter->total_rx_bytes = 0;
  1038. adapter->total_rx_packets = 0;
  1039. __napi_schedule(&adapter->napi);
  1040. }
  1041. return IRQ_HANDLED;
  1042. }
  1043. /**
  1044. * e1000_intr - Interrupt Handler
  1045. * @irq: interrupt number
  1046. * @data: pointer to a network interface device structure
  1047. **/
  1048. static irqreturn_t e1000_intr(int irq, void *data)
  1049. {
  1050. struct net_device *netdev = data;
  1051. struct e1000_adapter *adapter = netdev_priv(netdev);
  1052. struct e1000_hw *hw = &adapter->hw;
  1053. u32 rctl, icr = er32(ICR);
  1054. if (!icr)
  1055. return IRQ_NONE; /* Not our interrupt */
  1056. /*
  1057. * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  1058. * not set, then the adapter didn't send an interrupt
  1059. */
  1060. if (!(icr & E1000_ICR_INT_ASSERTED))
  1061. return IRQ_NONE;
  1062. /*
  1063. * Interrupt Auto-Mask...upon reading ICR,
  1064. * interrupts are masked. No need for the
  1065. * IMC write
  1066. */
  1067. if (icr & E1000_ICR_LSC) {
  1068. hw->mac.get_link_status = 1;
  1069. /*
  1070. * ICH8 workaround-- Call gig speed drop workaround on cable
  1071. * disconnect (LSC) before accessing any PHY registers
  1072. */
  1073. if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
  1074. (!(er32(STATUS) & E1000_STATUS_LU)))
  1075. schedule_work(&adapter->downshift_task);
  1076. /*
  1077. * 80003ES2LAN workaround--
  1078. * For packet buffer work-around on link down event;
  1079. * disable receives here in the ISR and
  1080. * reset adapter in watchdog
  1081. */
  1082. if (netif_carrier_ok(netdev) &&
  1083. (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
  1084. /* disable receives */
  1085. rctl = er32(RCTL);
  1086. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  1087. adapter->flags |= FLAG_RX_RESTART_NOW;
  1088. }
  1089. /* guard against interrupt when we're going down */
  1090. if (!test_bit(__E1000_DOWN, &adapter->state))
  1091. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1092. }
  1093. if (napi_schedule_prep(&adapter->napi)) {
  1094. adapter->total_tx_bytes = 0;
  1095. adapter->total_tx_packets = 0;
  1096. adapter->total_rx_bytes = 0;
  1097. adapter->total_rx_packets = 0;
  1098. __napi_schedule(&adapter->napi);
  1099. }
  1100. return IRQ_HANDLED;
  1101. }
  1102. static irqreturn_t e1000_msix_other(int irq, void *data)
  1103. {
  1104. struct net_device *netdev = data;
  1105. struct e1000_adapter *adapter = netdev_priv(netdev);
  1106. struct e1000_hw *hw = &adapter->hw;
  1107. u32 icr = er32(ICR);
  1108. if (!(icr & E1000_ICR_INT_ASSERTED)) {
  1109. if (!test_bit(__E1000_DOWN, &adapter->state))
  1110. ew32(IMS, E1000_IMS_OTHER);
  1111. return IRQ_NONE;
  1112. }
  1113. if (icr & adapter->eiac_mask)
  1114. ew32(ICS, (icr & adapter->eiac_mask));
  1115. if (icr & E1000_ICR_OTHER) {
  1116. if (!(icr & E1000_ICR_LSC))
  1117. goto no_link_interrupt;
  1118. hw->mac.get_link_status = 1;
  1119. /* guard against interrupt when we're going down */
  1120. if (!test_bit(__E1000_DOWN, &adapter->state))
  1121. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1122. }
  1123. no_link_interrupt:
  1124. if (!test_bit(__E1000_DOWN, &adapter->state))
  1125. ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
  1126. return IRQ_HANDLED;
  1127. }
  1128. static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
  1129. {
  1130. struct net_device *netdev = data;
  1131. struct e1000_adapter *adapter = netdev_priv(netdev);
  1132. struct e1000_hw *hw = &adapter->hw;
  1133. struct e1000_ring *tx_ring = adapter->tx_ring;
  1134. adapter->total_tx_bytes = 0;
  1135. adapter->total_tx_packets = 0;
  1136. if (!e1000_clean_tx_irq(adapter))
  1137. /* Ring was not completely cleaned, so fire another interrupt */
  1138. ew32(ICS, tx_ring->ims_val);
  1139. return IRQ_HANDLED;
  1140. }
  1141. static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
  1142. {
  1143. struct net_device *netdev = data;
  1144. struct e1000_adapter *adapter = netdev_priv(netdev);
  1145. /* Write the ITR value calculated at the end of the
  1146. * previous interrupt.
  1147. */
  1148. if (adapter->rx_ring->set_itr) {
  1149. writel(1000000000 / (adapter->rx_ring->itr_val * 256),
  1150. adapter->hw.hw_addr + adapter->rx_ring->itr_register);
  1151. adapter->rx_ring->set_itr = 0;
  1152. }
  1153. if (napi_schedule_prep(&adapter->napi)) {
  1154. adapter->total_rx_bytes = 0;
  1155. adapter->total_rx_packets = 0;
  1156. __napi_schedule(&adapter->napi);
  1157. }
  1158. return IRQ_HANDLED;
  1159. }
  1160. /**
  1161. * e1000_configure_msix - Configure MSI-X hardware
  1162. *
  1163. * e1000_configure_msix sets up the hardware to properly
  1164. * generate MSI-X interrupts.
  1165. **/
  1166. static void e1000_configure_msix(struct e1000_adapter *adapter)
  1167. {
  1168. struct e1000_hw *hw = &adapter->hw;
  1169. struct e1000_ring *rx_ring = adapter->rx_ring;
  1170. struct e1000_ring *tx_ring = adapter->tx_ring;
  1171. int vector = 0;
  1172. u32 ctrl_ext, ivar = 0;
  1173. adapter->eiac_mask = 0;
  1174. /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
  1175. if (hw->mac.type == e1000_82574) {
  1176. u32 rfctl = er32(RFCTL);
  1177. rfctl |= E1000_RFCTL_ACK_DIS;
  1178. ew32(RFCTL, rfctl);
  1179. }
  1180. #define E1000_IVAR_INT_ALLOC_VALID 0x8
  1181. /* Configure Rx vector */
  1182. rx_ring->ims_val = E1000_IMS_RXQ0;
  1183. adapter->eiac_mask |= rx_ring->ims_val;
  1184. if (rx_ring->itr_val)
  1185. writel(1000000000 / (rx_ring->itr_val * 256),
  1186. hw->hw_addr + rx_ring->itr_register);
  1187. else
  1188. writel(1, hw->hw_addr + rx_ring->itr_register);
  1189. ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
  1190. /* Configure Tx vector */
  1191. tx_ring->ims_val = E1000_IMS_TXQ0;
  1192. vector++;
  1193. if (tx_ring->itr_val)
  1194. writel(1000000000 / (tx_ring->itr_val * 256),
  1195. hw->hw_addr + tx_ring->itr_register);
  1196. else
  1197. writel(1, hw->hw_addr + tx_ring->itr_register);
  1198. adapter->eiac_mask |= tx_ring->ims_val;
  1199. ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
  1200. /* set vector for Other Causes, e.g. link changes */
  1201. vector++;
  1202. ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
  1203. if (rx_ring->itr_val)
  1204. writel(1000000000 / (rx_ring->itr_val * 256),
  1205. hw->hw_addr + E1000_EITR_82574(vector));
  1206. else
  1207. writel(1, hw->hw_addr + E1000_EITR_82574(vector));
  1208. /* Cause Tx interrupts on every write back */
  1209. ivar |= (1 << 31);
  1210. ew32(IVAR, ivar);
  1211. /* enable MSI-X PBA support */
  1212. ctrl_ext = er32(CTRL_EXT);
  1213. ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
  1214. /* Auto-Mask Other interrupts upon ICR read */
  1215. #define E1000_EIAC_MASK_82574 0x01F00000
  1216. ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
  1217. ctrl_ext |= E1000_CTRL_EXT_EIAME;
  1218. ew32(CTRL_EXT, ctrl_ext);
  1219. e1e_flush();
  1220. }
  1221. void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
  1222. {
  1223. if (adapter->msix_entries) {
  1224. pci_disable_msix(adapter->pdev);
  1225. kfree(adapter->msix_entries);
  1226. adapter->msix_entries = NULL;
  1227. } else if (adapter->flags & FLAG_MSI_ENABLED) {
  1228. pci_disable_msi(adapter->pdev);
  1229. adapter->flags &= ~FLAG_MSI_ENABLED;
  1230. }
  1231. return;
  1232. }
  1233. /**
  1234. * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
  1235. *
  1236. * Attempt to configure interrupts using the best available
  1237. * capabilities of the hardware and kernel.
  1238. **/
  1239. void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
  1240. {
  1241. int err;
  1242. int numvecs, i;
  1243. switch (adapter->int_mode) {
  1244. case E1000E_INT_MODE_MSIX:
  1245. if (adapter->flags & FLAG_HAS_MSIX) {
  1246. numvecs = 3; /* RxQ0, TxQ0 and other */
  1247. adapter->msix_entries = kcalloc(numvecs,
  1248. sizeof(struct msix_entry),
  1249. GFP_KERNEL);
  1250. if (adapter->msix_entries) {
  1251. for (i = 0; i < numvecs; i++)
  1252. adapter->msix_entries[i].entry = i;
  1253. err = pci_enable_msix(adapter->pdev,
  1254. adapter->msix_entries,
  1255. numvecs);
  1256. if (err == 0)
  1257. return;
  1258. }
  1259. /* MSI-X failed, so fall through and try MSI */
  1260. e_err("Failed to initialize MSI-X interrupts. "
  1261. "Falling back to MSI interrupts.\n");
  1262. e1000e_reset_interrupt_capability(adapter);
  1263. }
  1264. adapter->int_mode = E1000E_INT_MODE_MSI;
  1265. /* Fall through */
  1266. case E1000E_INT_MODE_MSI:
  1267. if (!pci_enable_msi(adapter->pdev)) {
  1268. adapter->flags |= FLAG_MSI_ENABLED;
  1269. } else {
  1270. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  1271. e_err("Failed to initialize MSI interrupts. Falling "
  1272. "back to legacy interrupts.\n");
  1273. }
  1274. /* Fall through */
  1275. case E1000E_INT_MODE_LEGACY:
  1276. /* Don't do anything; this is the system default */
  1277. break;
  1278. }
  1279. return;
  1280. }
  1281. /**
  1282. * e1000_request_msix - Initialize MSI-X interrupts
  1283. *
  1284. * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
  1285. * kernel.
  1286. **/
  1287. static int e1000_request_msix(struct e1000_adapter *adapter)
  1288. {
  1289. struct net_device *netdev = adapter->netdev;
  1290. int err = 0, vector = 0;
  1291. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  1292. sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
  1293. else
  1294. memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
  1295. err = request_irq(adapter->msix_entries[vector].vector,
  1296. &e1000_intr_msix_rx, 0, adapter->rx_ring->name,
  1297. netdev);
  1298. if (err)
  1299. goto out;
  1300. adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
  1301. adapter->rx_ring->itr_val = adapter->itr;
  1302. vector++;
  1303. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  1304. sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
  1305. else
  1306. memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
  1307. err = request_irq(adapter->msix_entries[vector].vector,
  1308. &e1000_intr_msix_tx, 0, adapter->tx_ring->name,
  1309. netdev);
  1310. if (err)
  1311. goto out;
  1312. adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
  1313. adapter->tx_ring->itr_val = adapter->itr;
  1314. vector++;
  1315. err = request_irq(adapter->msix_entries[vector].vector,
  1316. &e1000_msix_other, 0, netdev->name, netdev);
  1317. if (err)
  1318. goto out;
  1319. e1000_configure_msix(adapter);
  1320. return 0;
  1321. out:
  1322. return err;
  1323. }
  1324. /**
  1325. * e1000_request_irq - initialize interrupts
  1326. *
  1327. * Attempts to configure interrupts using the best available
  1328. * capabilities of the hardware and kernel.
  1329. **/
  1330. static int e1000_request_irq(struct e1000_adapter *adapter)
  1331. {
  1332. struct net_device *netdev = adapter->netdev;
  1333. int err;
  1334. if (adapter->msix_entries) {
  1335. err = e1000_request_msix(adapter);
  1336. if (!err)
  1337. return err;
  1338. /* fall back to MSI */
  1339. e1000e_reset_interrupt_capability(adapter);
  1340. adapter->int_mode = E1000E_INT_MODE_MSI;
  1341. e1000e_set_interrupt_capability(adapter);
  1342. }
  1343. if (adapter->flags & FLAG_MSI_ENABLED) {
  1344. err = request_irq(adapter->pdev->irq, &e1000_intr_msi, 0,
  1345. netdev->name, netdev);
  1346. if (!err)
  1347. return err;
  1348. /* fall back to legacy interrupt */
  1349. e1000e_reset_interrupt_capability(adapter);
  1350. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  1351. }
  1352. err = request_irq(adapter->pdev->irq, &e1000_intr, IRQF_SHARED,
  1353. netdev->name, netdev);
  1354. if (err)
  1355. e_err("Unable to allocate interrupt, Error: %d\n", err);
  1356. return err;
  1357. }
  1358. static void e1000_free_irq(struct e1000_adapter *adapter)
  1359. {
  1360. struct net_device *netdev = adapter->netdev;
  1361. if (adapter->msix_entries) {
  1362. int vector = 0;
  1363. free_irq(adapter->msix_entries[vector].vector, netdev);
  1364. vector++;
  1365. free_irq(adapter->msix_entries[vector].vector, netdev);
  1366. vector++;
  1367. /* Other Causes interrupt vector */
  1368. free_irq(adapter->msix_entries[vector].vector, netdev);
  1369. return;
  1370. }
  1371. free_irq(adapter->pdev->irq, netdev);
  1372. }
  1373. /**
  1374. * e1000_irq_disable - Mask off interrupt generation on the NIC
  1375. **/
  1376. static void e1000_irq_disable(struct e1000_adapter *adapter)
  1377. {
  1378. struct e1000_hw *hw = &adapter->hw;
  1379. ew32(IMC, ~0);
  1380. if (adapter->msix_entries)
  1381. ew32(EIAC_82574, 0);
  1382. e1e_flush();
  1383. synchronize_irq(adapter->pdev->irq);
  1384. }
  1385. /**
  1386. * e1000_irq_enable - Enable default interrupt generation settings
  1387. **/
  1388. static void e1000_irq_enable(struct e1000_adapter *adapter)
  1389. {
  1390. struct e1000_hw *hw = &adapter->hw;
  1391. if (adapter->msix_entries) {
  1392. ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
  1393. ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
  1394. } else {
  1395. ew32(IMS, IMS_ENABLE_MASK);
  1396. }
  1397. e1e_flush();
  1398. }
  1399. /**
  1400. * e1000_get_hw_control - get control of the h/w from f/w
  1401. * @adapter: address of board private structure
  1402. *
  1403. * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
  1404. * For ASF and Pass Through versions of f/w this means that
  1405. * the driver is loaded. For AMT version (only with 82573)
  1406. * of the f/w this means that the network i/f is open.
  1407. **/
  1408. static void e1000_get_hw_control(struct e1000_adapter *adapter)
  1409. {
  1410. struct e1000_hw *hw = &adapter->hw;
  1411. u32 ctrl_ext;
  1412. u32 swsm;
  1413. /* Let firmware know the driver has taken over */
  1414. if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
  1415. swsm = er32(SWSM);
  1416. ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
  1417. } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
  1418. ctrl_ext = er32(CTRL_EXT);
  1419. ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  1420. }
  1421. }
  1422. /**
  1423. * e1000_release_hw_control - release control of the h/w to f/w
  1424. * @adapter: address of board private structure
  1425. *
  1426. * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
  1427. * For ASF and Pass Through versions of f/w this means that the
  1428. * driver is no longer loaded. For AMT version (only with 82573) i
  1429. * of the f/w this means that the network i/f is closed.
  1430. *
  1431. **/
  1432. static void e1000_release_hw_control(struct e1000_adapter *adapter)
  1433. {
  1434. struct e1000_hw *hw = &adapter->hw;
  1435. u32 ctrl_ext;
  1436. u32 swsm;
  1437. /* Let firmware taken over control of h/w */
  1438. if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
  1439. swsm = er32(SWSM);
  1440. ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
  1441. } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
  1442. ctrl_ext = er32(CTRL_EXT);
  1443. ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  1444. }
  1445. }
  1446. /**
  1447. * @e1000_alloc_ring - allocate memory for a ring structure
  1448. **/
  1449. static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
  1450. struct e1000_ring *ring)
  1451. {
  1452. struct pci_dev *pdev = adapter->pdev;
  1453. ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
  1454. GFP_KERNEL);
  1455. if (!ring->desc)
  1456. return -ENOMEM;
  1457. return 0;
  1458. }
  1459. /**
  1460. * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
  1461. * @adapter: board private structure
  1462. *
  1463. * Return 0 on success, negative on failure
  1464. **/
  1465. int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
  1466. {
  1467. struct e1000_ring *tx_ring = adapter->tx_ring;
  1468. int err = -ENOMEM, size;
  1469. size = sizeof(struct e1000_buffer) * tx_ring->count;
  1470. tx_ring->buffer_info = vmalloc(size);
  1471. if (!tx_ring->buffer_info)
  1472. goto err;
  1473. memset(tx_ring->buffer_info, 0, size);
  1474. /* round up to nearest 4K */
  1475. tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
  1476. tx_ring->size = ALIGN(tx_ring->size, 4096);
  1477. err = e1000_alloc_ring_dma(adapter, tx_ring);
  1478. if (err)
  1479. goto err;
  1480. tx_ring->next_to_use = 0;
  1481. tx_ring->next_to_clean = 0;
  1482. return 0;
  1483. err:
  1484. vfree(tx_ring->buffer_info);
  1485. e_err("Unable to allocate memory for the transmit descriptor ring\n");
  1486. return err;
  1487. }
  1488. /**
  1489. * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
  1490. * @adapter: board private structure
  1491. *
  1492. * Returns 0 on success, negative on failure
  1493. **/
  1494. int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
  1495. {
  1496. struct e1000_ring *rx_ring = adapter->rx_ring;
  1497. struct e1000_buffer *buffer_info;
  1498. int i, size, desc_len, err = -ENOMEM;
  1499. size = sizeof(struct e1000_buffer) * rx_ring->count;
  1500. rx_ring->buffer_info = vmalloc(size);
  1501. if (!rx_ring->buffer_info)
  1502. goto err;
  1503. memset(rx_ring->buffer_info, 0, size);
  1504. for (i = 0; i < rx_ring->count; i++) {
  1505. buffer_info = &rx_ring->buffer_info[i];
  1506. buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
  1507. sizeof(struct e1000_ps_page),
  1508. GFP_KERNEL);
  1509. if (!buffer_info->ps_pages)
  1510. goto err_pages;
  1511. }
  1512. desc_len = sizeof(union e1000_rx_desc_packet_split);
  1513. /* Round up to nearest 4K */
  1514. rx_ring->size = rx_ring->count * desc_len;
  1515. rx_ring->size = ALIGN(rx_ring->size, 4096);
  1516. err = e1000_alloc_ring_dma(adapter, rx_ring);
  1517. if (err)
  1518. goto err_pages;
  1519. rx_ring->next_to_clean = 0;
  1520. rx_ring->next_to_use = 0;
  1521. rx_ring->rx_skb_top = NULL;
  1522. return 0;
  1523. err_pages:
  1524. for (i = 0; i < rx_ring->count; i++) {
  1525. buffer_info = &rx_ring->buffer_info[i];
  1526. kfree(buffer_info->ps_pages);
  1527. }
  1528. err:
  1529. vfree(rx_ring->buffer_info);
  1530. e_err("Unable to allocate memory for the transmit descriptor ring\n");
  1531. return err;
  1532. }
  1533. /**
  1534. * e1000_clean_tx_ring - Free Tx Buffers
  1535. * @adapter: board private structure
  1536. **/
  1537. static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
  1538. {
  1539. struct e1000_ring *tx_ring = adapter->tx_ring;
  1540. struct e1000_buffer *buffer_info;
  1541. unsigned long size;
  1542. unsigned int i;
  1543. for (i = 0; i < tx_ring->count; i++) {
  1544. buffer_info = &tx_ring->buffer_info[i];
  1545. e1000_put_txbuf(adapter, buffer_info);
  1546. }
  1547. size = sizeof(struct e1000_buffer) * tx_ring->count;
  1548. memset(tx_ring->buffer_info, 0, size);
  1549. memset(tx_ring->desc, 0, tx_ring->size);
  1550. tx_ring->next_to_use = 0;
  1551. tx_ring->next_to_clean = 0;
  1552. writel(0, adapter->hw.hw_addr + tx_ring->head);
  1553. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  1554. }
  1555. /**
  1556. * e1000e_free_tx_resources - Free Tx Resources per Queue
  1557. * @adapter: board private structure
  1558. *
  1559. * Free all transmit software resources
  1560. **/
  1561. void e1000e_free_tx_resources(struct e1000_adapter *adapter)
  1562. {
  1563. struct pci_dev *pdev = adapter->pdev;
  1564. struct e1000_ring *tx_ring = adapter->tx_ring;
  1565. e1000_clean_tx_ring(adapter);
  1566. vfree(tx_ring->buffer_info);
  1567. tx_ring->buffer_info = NULL;
  1568. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  1569. tx_ring->dma);
  1570. tx_ring->desc = NULL;
  1571. }
  1572. /**
  1573. * e1000e_free_rx_resources - Free Rx Resources
  1574. * @adapter: board private structure
  1575. *
  1576. * Free all receive software resources
  1577. **/
  1578. void e1000e_free_rx_resources(struct e1000_adapter *adapter)
  1579. {
  1580. struct pci_dev *pdev = adapter->pdev;
  1581. struct e1000_ring *rx_ring = adapter->rx_ring;
  1582. int i;
  1583. e1000_clean_rx_ring(adapter);
  1584. for (i = 0; i < rx_ring->count; i++) {
  1585. kfree(rx_ring->buffer_info[i].ps_pages);
  1586. }
  1587. vfree(rx_ring->buffer_info);
  1588. rx_ring->buffer_info = NULL;
  1589. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  1590. rx_ring->dma);
  1591. rx_ring->desc = NULL;
  1592. }
  1593. /**
  1594. * e1000_update_itr - update the dynamic ITR value based on statistics
  1595. * @adapter: pointer to adapter
  1596. * @itr_setting: current adapter->itr
  1597. * @packets: the number of packets during this measurement interval
  1598. * @bytes: the number of bytes during this measurement interval
  1599. *
  1600. * Stores a new ITR value based on packets and byte
  1601. * counts during the last interrupt. The advantage of per interrupt
  1602. * computation is faster updates and more accurate ITR for the current
  1603. * traffic pattern. Constants in this function were computed
  1604. * based on theoretical maximum wire speed and thresholds were set based
  1605. * on testing data as well as attempting to minimize response time
  1606. * while increasing bulk throughput. This functionality is controlled
  1607. * by the InterruptThrottleRate module parameter.
  1608. **/
  1609. static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
  1610. u16 itr_setting, int packets,
  1611. int bytes)
  1612. {
  1613. unsigned int retval = itr_setting;
  1614. if (packets == 0)
  1615. goto update_itr_done;
  1616. switch (itr_setting) {
  1617. case lowest_latency:
  1618. /* handle TSO and jumbo frames */
  1619. if (bytes/packets > 8000)
  1620. retval = bulk_latency;
  1621. else if ((packets < 5) && (bytes > 512)) {
  1622. retval = low_latency;
  1623. }
  1624. break;
  1625. case low_latency: /* 50 usec aka 20000 ints/s */
  1626. if (bytes > 10000) {
  1627. /* this if handles the TSO accounting */
  1628. if (bytes/packets > 8000) {
  1629. retval = bulk_latency;
  1630. } else if ((packets < 10) || ((bytes/packets) > 1200)) {
  1631. retval = bulk_latency;
  1632. } else if ((packets > 35)) {
  1633. retval = lowest_latency;
  1634. }
  1635. } else if (bytes/packets > 2000) {
  1636. retval = bulk_latency;
  1637. } else if (packets <= 2 && bytes < 512) {
  1638. retval = lowest_latency;
  1639. }
  1640. break;
  1641. case bulk_latency: /* 250 usec aka 4000 ints/s */
  1642. if (bytes > 25000) {
  1643. if (packets > 35) {
  1644. retval = low_latency;
  1645. }
  1646. } else if (bytes < 6000) {
  1647. retval = low_latency;
  1648. }
  1649. break;
  1650. }
  1651. update_itr_done:
  1652. return retval;
  1653. }
  1654. static void e1000_set_itr(struct e1000_adapter *adapter)
  1655. {
  1656. struct e1000_hw *hw = &adapter->hw;
  1657. u16 current_itr;
  1658. u32 new_itr = adapter->itr;
  1659. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  1660. if (adapter->link_speed != SPEED_1000) {
  1661. current_itr = 0;
  1662. new_itr = 4000;
  1663. goto set_itr_now;
  1664. }
  1665. adapter->tx_itr = e1000_update_itr(adapter,
  1666. adapter->tx_itr,
  1667. adapter->total_tx_packets,
  1668. adapter->total_tx_bytes);
  1669. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  1670. if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
  1671. adapter->tx_itr = low_latency;
  1672. adapter->rx_itr = e1000_update_itr(adapter,
  1673. adapter->rx_itr,
  1674. adapter->total_rx_packets,
  1675. adapter->total_rx_bytes);
  1676. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  1677. if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
  1678. adapter->rx_itr = low_latency;
  1679. current_itr = max(adapter->rx_itr, adapter->tx_itr);
  1680. switch (current_itr) {
  1681. /* counts and packets in update_itr are dependent on these numbers */
  1682. case lowest_latency:
  1683. new_itr = 70000;
  1684. break;
  1685. case low_latency:
  1686. new_itr = 20000; /* aka hwitr = ~200 */
  1687. break;
  1688. case bulk_latency:
  1689. new_itr = 4000;
  1690. break;
  1691. default:
  1692. break;
  1693. }
  1694. set_itr_now:
  1695. if (new_itr != adapter->itr) {
  1696. /*
  1697. * this attempts to bias the interrupt rate towards Bulk
  1698. * by adding intermediate steps when interrupt rate is
  1699. * increasing
  1700. */
  1701. new_itr = new_itr > adapter->itr ?
  1702. min(adapter->itr + (new_itr >> 2), new_itr) :
  1703. new_itr;
  1704. adapter->itr = new_itr;
  1705. adapter->rx_ring->itr_val = new_itr;
  1706. if (adapter->msix_entries)
  1707. adapter->rx_ring->set_itr = 1;
  1708. else
  1709. ew32(ITR, 1000000000 / (new_itr * 256));
  1710. }
  1711. }
  1712. /**
  1713. * e1000_alloc_queues - Allocate memory for all rings
  1714. * @adapter: board private structure to initialize
  1715. **/
  1716. static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
  1717. {
  1718. adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
  1719. if (!adapter->tx_ring)
  1720. goto err;
  1721. adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
  1722. if (!adapter->rx_ring)
  1723. goto err;
  1724. return 0;
  1725. err:
  1726. e_err("Unable to allocate memory for queues\n");
  1727. kfree(adapter->rx_ring);
  1728. kfree(adapter->tx_ring);
  1729. return -ENOMEM;
  1730. }
  1731. /**
  1732. * e1000_clean - NAPI Rx polling callback
  1733. * @napi: struct associated with this polling callback
  1734. * @budget: amount of packets driver is allowed to process this poll
  1735. **/
  1736. static int e1000_clean(struct napi_struct *napi, int budget)
  1737. {
  1738. struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
  1739. struct e1000_hw *hw = &adapter->hw;
  1740. struct net_device *poll_dev = adapter->netdev;
  1741. int tx_cleaned = 1, work_done = 0;
  1742. adapter = netdev_priv(poll_dev);
  1743. if (adapter->msix_entries &&
  1744. !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
  1745. goto clean_rx;
  1746. tx_cleaned = e1000_clean_tx_irq(adapter);
  1747. clean_rx:
  1748. adapter->clean_rx(adapter, &work_done, budget);
  1749. if (!tx_cleaned)
  1750. work_done = budget;
  1751. /* If budget not fully consumed, exit the polling mode */
  1752. if (work_done < budget) {
  1753. if (adapter->itr_setting & 3)
  1754. e1000_set_itr(adapter);
  1755. napi_complete(napi);
  1756. if (!test_bit(__E1000_DOWN, &adapter->state)) {
  1757. if (adapter->msix_entries)
  1758. ew32(IMS, adapter->rx_ring->ims_val);
  1759. else
  1760. e1000_irq_enable(adapter);
  1761. }
  1762. }
  1763. return work_done;
  1764. }
  1765. static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  1766. {
  1767. struct e1000_adapter *adapter = netdev_priv(netdev);
  1768. struct e1000_hw *hw = &adapter->hw;
  1769. u32 vfta, index;
  1770. /* don't update vlan cookie if already programmed */
  1771. if ((adapter->hw.mng_cookie.status &
  1772. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  1773. (vid == adapter->mng_vlan_id))
  1774. return;
  1775. /* add VID to filter table */
  1776. index = (vid >> 5) & 0x7F;
  1777. vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
  1778. vfta |= (1 << (vid & 0x1F));
  1779. e1000e_write_vfta(hw, index, vfta);
  1780. }
  1781. static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  1782. {
  1783. struct e1000_adapter *adapter = netdev_priv(netdev);
  1784. struct e1000_hw *hw = &adapter->hw;
  1785. u32 vfta, index;
  1786. if (!test_bit(__E1000_DOWN, &adapter->state))
  1787. e1000_irq_disable(adapter);
  1788. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  1789. if (!test_bit(__E1000_DOWN, &adapter->state))
  1790. e1000_irq_enable(adapter);
  1791. if ((adapter->hw.mng_cookie.status &
  1792. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  1793. (vid == adapter->mng_vlan_id)) {
  1794. /* release control to f/w */
  1795. e1000_release_hw_control(adapter);
  1796. return;
  1797. }
  1798. /* remove VID from filter table */
  1799. index = (vid >> 5) & 0x7F;
  1800. vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
  1801. vfta &= ~(1 << (vid & 0x1F));
  1802. e1000e_write_vfta(hw, index, vfta);
  1803. }
  1804. static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
  1805. {
  1806. struct net_device *netdev = adapter->netdev;
  1807. u16 vid = adapter->hw.mng_cookie.vlan_id;
  1808. u16 old_vid = adapter->mng_vlan_id;
  1809. if (!adapter->vlgrp)
  1810. return;
  1811. if (!vlan_group_get_device(adapter->vlgrp, vid)) {
  1812. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  1813. if (adapter->hw.mng_cookie.status &
  1814. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  1815. e1000_vlan_rx_add_vid(netdev, vid);
  1816. adapter->mng_vlan_id = vid;
  1817. }
  1818. if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
  1819. (vid != old_vid) &&
  1820. !vlan_group_get_device(adapter->vlgrp, old_vid))
  1821. e1000_vlan_rx_kill_vid(netdev, old_vid);
  1822. } else {
  1823. adapter->mng_vlan_id = vid;
  1824. }
  1825. }
  1826. static void e1000_vlan_rx_register(struct net_device *netdev,
  1827. struct vlan_group *grp)
  1828. {
  1829. struct e1000_adapter *adapter = netdev_priv(netdev);
  1830. struct e1000_hw *hw = &adapter->hw;
  1831. u32 ctrl, rctl;
  1832. if (!test_bit(__E1000_DOWN, &adapter->state))
  1833. e1000_irq_disable(adapter);
  1834. adapter->vlgrp = grp;
  1835. if (grp) {
  1836. /* enable VLAN tag insert/strip */
  1837. ctrl = er32(CTRL);
  1838. ctrl |= E1000_CTRL_VME;
  1839. ew32(CTRL, ctrl);
  1840. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  1841. /* enable VLAN receive filtering */
  1842. rctl = er32(RCTL);
  1843. rctl &= ~E1000_RCTL_CFIEN;
  1844. ew32(RCTL, rctl);
  1845. e1000_update_mng_vlan(adapter);
  1846. }
  1847. } else {
  1848. /* disable VLAN tag insert/strip */
  1849. ctrl = er32(CTRL);
  1850. ctrl &= ~E1000_CTRL_VME;
  1851. ew32(CTRL, ctrl);
  1852. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  1853. if (adapter->mng_vlan_id !=
  1854. (u16)E1000_MNG_VLAN_NONE) {
  1855. e1000_vlan_rx_kill_vid(netdev,
  1856. adapter->mng_vlan_id);
  1857. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  1858. }
  1859. }
  1860. }
  1861. if (!test_bit(__E1000_DOWN, &adapter->state))
  1862. e1000_irq_enable(adapter);
  1863. }
  1864. static void e1000_restore_vlan(struct e1000_adapter *adapter)
  1865. {
  1866. u16 vid;
  1867. e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  1868. if (!adapter->vlgrp)
  1869. return;
  1870. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  1871. if (!vlan_group_get_device(adapter->vlgrp, vid))
  1872. continue;
  1873. e1000_vlan_rx_add_vid(adapter->netdev, vid);
  1874. }
  1875. }
  1876. static void e1000_init_manageability(struct e1000_adapter *adapter)
  1877. {
  1878. struct e1000_hw *hw = &adapter->hw;
  1879. u32 manc, manc2h;
  1880. if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
  1881. return;
  1882. manc = er32(MANC);
  1883. /*
  1884. * enable receiving management packets to the host. this will probably
  1885. * generate destination unreachable messages from the host OS, but
  1886. * the packets will be handled on SMBUS
  1887. */
  1888. manc |= E1000_MANC_EN_MNG2HOST;
  1889. manc2h = er32(MANC2H);
  1890. #define E1000_MNG2HOST_PORT_623 (1 << 5)
  1891. #define E1000_MNG2HOST_PORT_664 (1 << 6)
  1892. manc2h |= E1000_MNG2HOST_PORT_623;
  1893. manc2h |= E1000_MNG2HOST_PORT_664;
  1894. ew32(MANC2H, manc2h);
  1895. ew32(MANC, manc);
  1896. }
  1897. /**
  1898. * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  1899. * @adapter: board private structure
  1900. *
  1901. * Configure the Tx unit of the MAC after a reset.
  1902. **/
  1903. static void e1000_configure_tx(struct e1000_adapter *adapter)
  1904. {
  1905. struct e1000_hw *hw = &adapter->hw;
  1906. struct e1000_ring *tx_ring = adapter->tx_ring;
  1907. u64 tdba;
  1908. u32 tdlen, tctl, tipg, tarc;
  1909. u32 ipgr1, ipgr2;
  1910. /* Setup the HW Tx Head and Tail descriptor pointers */
  1911. tdba = tx_ring->dma;
  1912. tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
  1913. ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
  1914. ew32(TDBAH, (tdba >> 32));
  1915. ew32(TDLEN, tdlen);
  1916. ew32(TDH, 0);
  1917. ew32(TDT, 0);
  1918. tx_ring->head = E1000_TDH;
  1919. tx_ring->tail = E1000_TDT;
  1920. /* Set the default values for the Tx Inter Packet Gap timer */
  1921. tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
  1922. ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
  1923. ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
  1924. if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
  1925. ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
  1926. tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
  1927. tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
  1928. ew32(TIPG, tipg);
  1929. /* Set the Tx Interrupt Delay register */
  1930. ew32(TIDV, adapter->tx_int_delay);
  1931. /* Tx irq moderation */
  1932. ew32(TADV, adapter->tx_abs_int_delay);
  1933. /* Program the Transmit Control Register */
  1934. tctl = er32(TCTL);
  1935. tctl &= ~E1000_TCTL_CT;
  1936. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  1937. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  1938. if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
  1939. tarc = er32(TARC(0));
  1940. /*
  1941. * set the speed mode bit, we'll clear it if we're not at
  1942. * gigabit link later
  1943. */
  1944. #define SPEED_MODE_BIT (1 << 21)
  1945. tarc |= SPEED_MODE_BIT;
  1946. ew32(TARC(0), tarc);
  1947. }
  1948. /* errata: program both queues to unweighted RR */
  1949. if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
  1950. tarc = er32(TARC(0));
  1951. tarc |= 1;
  1952. ew32(TARC(0), tarc);
  1953. tarc = er32(TARC(1));
  1954. tarc |= 1;
  1955. ew32(TARC(1), tarc);
  1956. }
  1957. /* Setup Transmit Descriptor Settings for eop descriptor */
  1958. adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
  1959. /* only set IDE if we are delaying interrupts using the timers */
  1960. if (adapter->tx_int_delay)
  1961. adapter->txd_cmd |= E1000_TXD_CMD_IDE;
  1962. /* enable Report Status bit */
  1963. adapter->txd_cmd |= E1000_TXD_CMD_RS;
  1964. ew32(TCTL, tctl);
  1965. e1000e_config_collision_dist(hw);
  1966. adapter->tx_queue_len = adapter->netdev->tx_queue_len;
  1967. }
  1968. /**
  1969. * e1000_setup_rctl - configure the receive control registers
  1970. * @adapter: Board private structure
  1971. **/
  1972. #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
  1973. (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
  1974. static void e1000_setup_rctl(struct e1000_adapter *adapter)
  1975. {
  1976. struct e1000_hw *hw = &adapter->hw;
  1977. u32 rctl, rfctl;
  1978. u32 psrctl = 0;
  1979. u32 pages = 0;
  1980. /* Program MC offset vector base */
  1981. rctl = er32(RCTL);
  1982. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  1983. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  1984. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  1985. (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  1986. /* Do not Store bad packets */
  1987. rctl &= ~E1000_RCTL_SBP;
  1988. /* Enable Long Packet receive */
  1989. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  1990. rctl &= ~E1000_RCTL_LPE;
  1991. else
  1992. rctl |= E1000_RCTL_LPE;
  1993. /* Some systems expect that the CRC is included in SMBUS traffic. The
  1994. * hardware strips the CRC before sending to both SMBUS (BMC) and to
  1995. * host memory when this is enabled
  1996. */
  1997. if (adapter->flags2 & FLAG2_CRC_STRIPPING)
  1998. rctl |= E1000_RCTL_SECRC;
  1999. /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
  2000. if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
  2001. u16 phy_data;
  2002. e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
  2003. phy_data &= 0xfff8;
  2004. phy_data |= (1 << 2);
  2005. e1e_wphy(hw, PHY_REG(770, 26), phy_data);
  2006. e1e_rphy(hw, 22, &phy_data);
  2007. phy_data &= 0x0fff;
  2008. phy_data |= (1 << 14);
  2009. e1e_wphy(hw, 0x10, 0x2823);
  2010. e1e_wphy(hw, 0x11, 0x0003);
  2011. e1e_wphy(hw, 22, phy_data);
  2012. }
  2013. /* Setup buffer sizes */
  2014. rctl &= ~E1000_RCTL_SZ_4096;
  2015. rctl |= E1000_RCTL_BSEX;
  2016. switch (adapter->rx_buffer_len) {
  2017. case 2048:
  2018. default:
  2019. rctl |= E1000_RCTL_SZ_2048;
  2020. rctl &= ~E1000_RCTL_BSEX;
  2021. break;
  2022. case 4096:
  2023. rctl |= E1000_RCTL_SZ_4096;
  2024. break;
  2025. case 8192:
  2026. rctl |= E1000_RCTL_SZ_8192;
  2027. break;
  2028. case 16384:
  2029. rctl |= E1000_RCTL_SZ_16384;
  2030. break;
  2031. }
  2032. /*
  2033. * 82571 and greater support packet-split where the protocol
  2034. * header is placed in skb->data and the packet data is
  2035. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  2036. * In the case of a non-split, skb->data is linearly filled,
  2037. * followed by the page buffers. Therefore, skb->data is
  2038. * sized to hold the largest protocol header.
  2039. *
  2040. * allocations using alloc_page take too long for regular MTU
  2041. * so only enable packet split for jumbo frames
  2042. *
  2043. * Using pages when the page size is greater than 16k wastes
  2044. * a lot of memory, since we allocate 3 pages at all times
  2045. * per packet.
  2046. */
  2047. pages = PAGE_USE_COUNT(adapter->netdev->mtu);
  2048. if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&
  2049. (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
  2050. adapter->rx_ps_pages = pages;
  2051. else
  2052. adapter->rx_ps_pages = 0;
  2053. if (adapter->rx_ps_pages) {
  2054. /* Configure extra packet-split registers */
  2055. rfctl = er32(RFCTL);
  2056. rfctl |= E1000_RFCTL_EXTEN;
  2057. /*
  2058. * disable packet split support for IPv6 extension headers,
  2059. * because some malformed IPv6 headers can hang the Rx
  2060. */
  2061. rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
  2062. E1000_RFCTL_NEW_IPV6_EXT_DIS);
  2063. ew32(RFCTL, rfctl);
  2064. /* Enable Packet split descriptors */
  2065. rctl |= E1000_RCTL_DTYP_PS;
  2066. psrctl |= adapter->rx_ps_bsize0 >>
  2067. E1000_PSRCTL_BSIZE0_SHIFT;
  2068. switch (adapter->rx_ps_pages) {
  2069. case 3:
  2070. psrctl |= PAGE_SIZE <<
  2071. E1000_PSRCTL_BSIZE3_SHIFT;
  2072. case 2:
  2073. psrctl |= PAGE_SIZE <<
  2074. E1000_PSRCTL_BSIZE2_SHIFT;
  2075. case 1:
  2076. psrctl |= PAGE_SIZE >>
  2077. E1000_PSRCTL_BSIZE1_SHIFT;
  2078. break;
  2079. }
  2080. ew32(PSRCTL, psrctl);
  2081. }
  2082. ew32(RCTL, rctl);
  2083. /* just started the receive unit, no need to restart */
  2084. adapter->flags &= ~FLAG_RX_RESTART_NOW;
  2085. }
  2086. /**
  2087. * e1000_configure_rx - Configure Receive Unit after Reset
  2088. * @adapter: board private structure
  2089. *
  2090. * Configure the Rx unit of the MAC after a reset.
  2091. **/
  2092. static void e1000_configure_rx(struct e1000_adapter *adapter)
  2093. {
  2094. struct e1000_hw *hw = &adapter->hw;
  2095. struct e1000_ring *rx_ring = adapter->rx_ring;
  2096. u64 rdba;
  2097. u32 rdlen, rctl, rxcsum, ctrl_ext;
  2098. if (adapter->rx_ps_pages) {
  2099. /* this is a 32 byte descriptor */
  2100. rdlen = rx_ring->count *
  2101. sizeof(union e1000_rx_desc_packet_split);
  2102. adapter->clean_rx = e1000_clean_rx_irq_ps;
  2103. adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
  2104. } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
  2105. rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
  2106. adapter->clean_rx = e1000_clean_jumbo_rx_irq;
  2107. adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
  2108. } else {
  2109. rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
  2110. adapter->clean_rx = e1000_clean_rx_irq;
  2111. adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
  2112. }
  2113. /* disable receives while setting up the descriptors */
  2114. rctl = er32(RCTL);
  2115. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  2116. e1e_flush();
  2117. msleep(10);
  2118. /* set the Receive Delay Timer Register */
  2119. ew32(RDTR, adapter->rx_int_delay);
  2120. /* irq moderation */
  2121. ew32(RADV, adapter->rx_abs_int_delay);
  2122. if (adapter->itr_setting != 0)
  2123. ew32(ITR, 1000000000 / (adapter->itr * 256));
  2124. ctrl_ext = er32(CTRL_EXT);
  2125. /* Reset delay timers after every interrupt */
  2126. ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
  2127. /* Auto-Mask interrupts upon ICR access */
  2128. ctrl_ext |= E1000_CTRL_EXT_IAME;
  2129. ew32(IAM, 0xffffffff);
  2130. ew32(CTRL_EXT, ctrl_ext);
  2131. e1e_flush();
  2132. /*
  2133. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2134. * the Base and Length of the Rx Descriptor Ring
  2135. */
  2136. rdba = rx_ring->dma;
  2137. ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
  2138. ew32(RDBAH, (rdba >> 32));
  2139. ew32(RDLEN, rdlen);
  2140. ew32(RDH, 0);
  2141. ew32(RDT, 0);
  2142. rx_ring->head = E1000_RDH;
  2143. rx_ring->tail = E1000_RDT;
  2144. /* Enable Receive Checksum Offload for TCP and UDP */
  2145. rxcsum = er32(RXCSUM);
  2146. if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
  2147. rxcsum |= E1000_RXCSUM_TUOFL;
  2148. /*
  2149. * IPv4 payload checksum for UDP fragments must be
  2150. * used in conjunction with packet-split.
  2151. */
  2152. if (adapter->rx_ps_pages)
  2153. rxcsum |= E1000_RXCSUM_IPPCSE;
  2154. } else {
  2155. rxcsum &= ~E1000_RXCSUM_TUOFL;
  2156. /* no need to clear IPPCSE as it defaults to 0 */
  2157. }
  2158. ew32(RXCSUM, rxcsum);
  2159. /*
  2160. * Enable early receives on supported devices, only takes effect when
  2161. * packet size is equal or larger than the specified value (in 8 byte
  2162. * units), e.g. using jumbo frames when setting to E1000_ERT_2048
  2163. */
  2164. if ((adapter->flags & FLAG_HAS_ERT) &&
  2165. (adapter->netdev->mtu > ETH_DATA_LEN)) {
  2166. u32 rxdctl = er32(RXDCTL(0));
  2167. ew32(RXDCTL(0), rxdctl | 0x3);
  2168. ew32(ERT, E1000_ERT_2048 | (1 << 13));
  2169. /*
  2170. * With jumbo frames and early-receive enabled, excessive
  2171. * C4->C2 latencies result in dropped transactions.
  2172. */
  2173. pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
  2174. e1000e_driver_name, 55);
  2175. } else {
  2176. pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
  2177. e1000e_driver_name,
  2178. PM_QOS_DEFAULT_VALUE);
  2179. }
  2180. /* Enable Receives */
  2181. ew32(RCTL, rctl);
  2182. }
  2183. /**
  2184. * e1000_update_mc_addr_list - Update Multicast addresses
  2185. * @hw: pointer to the HW structure
  2186. * @mc_addr_list: array of multicast addresses to program
  2187. * @mc_addr_count: number of multicast addresses to program
  2188. * @rar_used_count: the first RAR register free to program
  2189. * @rar_count: total number of supported Receive Address Registers
  2190. *
  2191. * Updates the Receive Address Registers and Multicast Table Array.
  2192. * The caller must have a packed mc_addr_list of multicast addresses.
  2193. * The parameter rar_count will usually be hw->mac.rar_entry_count
  2194. * unless there are workarounds that change this. Currently no func pointer
  2195. * exists and all implementations are handled in the generic version of this
  2196. * function.
  2197. **/
  2198. static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
  2199. u32 mc_addr_count, u32 rar_used_count,
  2200. u32 rar_count)
  2201. {
  2202. hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
  2203. rar_used_count, rar_count);
  2204. }
  2205. /**
  2206. * e1000_set_multi - Multicast and Promiscuous mode set
  2207. * @netdev: network interface device structure
  2208. *
  2209. * The set_multi entry point is called whenever the multicast address
  2210. * list or the network interface flags are updated. This routine is
  2211. * responsible for configuring the hardware for proper multicast,
  2212. * promiscuous mode, and all-multi behavior.
  2213. **/
  2214. static void e1000_set_multi(struct net_device *netdev)
  2215. {
  2216. struct e1000_adapter *adapter = netdev_priv(netdev);
  2217. struct e1000_hw *hw = &adapter->hw;
  2218. struct e1000_mac_info *mac = &hw->mac;
  2219. struct dev_mc_list *mc_ptr;
  2220. u8 *mta_list;
  2221. u32 rctl;
  2222. int i;
  2223. /* Check for Promiscuous and All Multicast modes */
  2224. rctl = er32(RCTL);
  2225. if (netdev->flags & IFF_PROMISC) {
  2226. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  2227. rctl &= ~E1000_RCTL_VFE;
  2228. } else {
  2229. if (netdev->flags & IFF_ALLMULTI) {
  2230. rctl |= E1000_RCTL_MPE;
  2231. rctl &= ~E1000_RCTL_UPE;
  2232. } else {
  2233. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
  2234. }
  2235. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
  2236. rctl |= E1000_RCTL_VFE;
  2237. }
  2238. ew32(RCTL, rctl);
  2239. if (netdev->mc_count) {
  2240. mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
  2241. if (!mta_list)
  2242. return;
  2243. /* prepare a packed array of only addresses. */
  2244. mc_ptr = netdev->mc_list;
  2245. for (i = 0; i < netdev->mc_count; i++) {
  2246. if (!mc_ptr)
  2247. break;
  2248. memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
  2249. ETH_ALEN);
  2250. mc_ptr = mc_ptr->next;
  2251. }
  2252. e1000_update_mc_addr_list(hw, mta_list, i, 1,
  2253. mac->rar_entry_count);
  2254. kfree(mta_list);
  2255. } else {
  2256. /*
  2257. * if we're called from probe, we might not have
  2258. * anything to do here, so clear out the list
  2259. */
  2260. e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count);
  2261. }
  2262. }
  2263. /**
  2264. * e1000_configure - configure the hardware for Rx and Tx
  2265. * @adapter: private board structure
  2266. **/
  2267. static void e1000_configure(struct e1000_adapter *adapter)
  2268. {
  2269. e1000_set_multi(adapter->netdev);
  2270. e1000_restore_vlan(adapter);
  2271. e1000_init_manageability(adapter);
  2272. e1000_configure_tx(adapter);
  2273. e1000_setup_rctl(adapter);
  2274. e1000_configure_rx(adapter);
  2275. adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
  2276. }
  2277. /**
  2278. * e1000e_power_up_phy - restore link in case the phy was powered down
  2279. * @adapter: address of board private structure
  2280. *
  2281. * The phy may be powered down to save power and turn off link when the
  2282. * driver is unloaded and wake on lan is not enabled (among others)
  2283. * *** this routine MUST be followed by a call to e1000e_reset ***
  2284. **/
  2285. void e1000e_power_up_phy(struct e1000_adapter *adapter)
  2286. {
  2287. u16 mii_reg = 0;
  2288. /* Just clear the power down bit to wake the phy back up */
  2289. if (adapter->hw.phy.media_type == e1000_media_type_copper) {
  2290. /*
  2291. * According to the manual, the phy will retain its
  2292. * settings across a power-down/up cycle
  2293. */
  2294. e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
  2295. mii_reg &= ~MII_CR_POWER_DOWN;
  2296. e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
  2297. }
  2298. adapter->hw.mac.ops.setup_link(&adapter->hw);
  2299. }
  2300. /**
  2301. * e1000_power_down_phy - Power down the PHY
  2302. *
  2303. * Power down the PHY so no link is implied when interface is down
  2304. * The PHY cannot be powered down is management or WoL is active
  2305. */
  2306. static void e1000_power_down_phy(struct e1000_adapter *adapter)
  2307. {
  2308. struct e1000_hw *hw = &adapter->hw;
  2309. u16 mii_reg;
  2310. /* WoL is enabled */
  2311. if (adapter->wol)
  2312. return;
  2313. /* non-copper PHY? */
  2314. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  2315. return;
  2316. /* reset is blocked because of a SoL/IDER session */
  2317. if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw))
  2318. return;
  2319. /* manageability (AMT) is enabled */
  2320. if (er32(MANC) & E1000_MANC_SMBUS_EN)
  2321. return;
  2322. /* power down the PHY */
  2323. e1e_rphy(hw, PHY_CONTROL, &mii_reg);
  2324. mii_reg |= MII_CR_POWER_DOWN;
  2325. e1e_wphy(hw, PHY_CONTROL, mii_reg);
  2326. mdelay(1);
  2327. }
  2328. /**
  2329. * e1000e_reset - bring the hardware into a known good state
  2330. *
  2331. * This function boots the hardware and enables some settings that
  2332. * require a configuration cycle of the hardware - those cannot be
  2333. * set/changed during runtime. After reset the device needs to be
  2334. * properly configured for Rx, Tx etc.
  2335. */
  2336. void e1000e_reset(struct e1000_adapter *adapter)
  2337. {
  2338. struct e1000_mac_info *mac = &adapter->hw.mac;
  2339. struct e1000_fc_info *fc = &adapter->hw.fc;
  2340. struct e1000_hw *hw = &adapter->hw;
  2341. u32 tx_space, min_tx_space, min_rx_space;
  2342. u32 pba = adapter->pba;
  2343. u16 hwm;
  2344. /* reset Packet Buffer Allocation to default */
  2345. ew32(PBA, pba);
  2346. if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
  2347. /*
  2348. * To maintain wire speed transmits, the Tx FIFO should be
  2349. * large enough to accommodate two full transmit packets,
  2350. * rounded up to the next 1KB and expressed in KB. Likewise,
  2351. * the Rx FIFO should be large enough to accommodate at least
  2352. * one full receive packet and is similarly rounded up and
  2353. * expressed in KB.
  2354. */
  2355. pba = er32(PBA);
  2356. /* upper 16 bits has Tx packet buffer allocation size in KB */
  2357. tx_space = pba >> 16;
  2358. /* lower 16 bits has Rx packet buffer allocation size in KB */
  2359. pba &= 0xffff;
  2360. /*
  2361. * the Tx fifo also stores 16 bytes of information about the tx
  2362. * but don't include ethernet FCS because hardware appends it
  2363. */
  2364. min_tx_space = (adapter->max_frame_size +
  2365. sizeof(struct e1000_tx_desc) -
  2366. ETH_FCS_LEN) * 2;
  2367. min_tx_space = ALIGN(min_tx_space, 1024);
  2368. min_tx_space >>= 10;
  2369. /* software strips receive CRC, so leave room for it */
  2370. min_rx_space = adapter->max_frame_size;
  2371. min_rx_space = ALIGN(min_rx_space, 1024);
  2372. min_rx_space >>= 10;
  2373. /*
  2374. * If current Tx allocation is less than the min Tx FIFO size,
  2375. * and the min Tx FIFO size is less than the current Rx FIFO
  2376. * allocation, take space away from current Rx allocation
  2377. */
  2378. if ((tx_space < min_tx_space) &&
  2379. ((min_tx_space - tx_space) < pba)) {
  2380. pba -= min_tx_space - tx_space;
  2381. /*
  2382. * if short on Rx space, Rx wins and must trump tx
  2383. * adjustment or use Early Receive if available
  2384. */
  2385. if ((pba < min_rx_space) &&
  2386. (!(adapter->flags & FLAG_HAS_ERT)))
  2387. /* ERT enabled in e1000_configure_rx */
  2388. pba = min_rx_space;
  2389. }
  2390. ew32(PBA, pba);
  2391. }
  2392. /*
  2393. * flow control settings
  2394. *
  2395. * The high water mark must be low enough to fit one full frame
  2396. * (or the size used for early receive) above it in the Rx FIFO.
  2397. * Set it to the lower of:
  2398. * - 90% of the Rx FIFO size, and
  2399. * - the full Rx FIFO size minus the early receive size (for parts
  2400. * with ERT support assuming ERT set to E1000_ERT_2048), or
  2401. * - the full Rx FIFO size minus one full frame
  2402. */
  2403. if (hw->mac.type == e1000_pchlan) {
  2404. /*
  2405. * Workaround PCH LOM adapter hangs with certain network
  2406. * loads. If hangs persist, try disabling Tx flow control.
  2407. */
  2408. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  2409. fc->high_water = 0x3500;
  2410. fc->low_water = 0x1500;
  2411. } else {
  2412. fc->high_water = 0x5000;
  2413. fc->low_water = 0x3000;
  2414. }
  2415. } else {
  2416. if ((adapter->flags & FLAG_HAS_ERT) &&
  2417. (adapter->netdev->mtu > ETH_DATA_LEN))
  2418. hwm = min(((pba << 10) * 9 / 10),
  2419. ((pba << 10) - (E1000_ERT_2048 << 3)));
  2420. else
  2421. hwm = min(((pba << 10) * 9 / 10),
  2422. ((pba << 10) - adapter->max_frame_size));
  2423. fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
  2424. fc->low_water = fc->high_water - 8;
  2425. }
  2426. if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
  2427. fc->pause_time = 0xFFFF;
  2428. else
  2429. fc->pause_time = E1000_FC_PAUSE_TIME;
  2430. fc->send_xon = 1;
  2431. fc->current_mode = fc->requested_mode;
  2432. /* Allow time for pending master requests to run */
  2433. mac->ops.reset_hw(hw);
  2434. /*
  2435. * For parts with AMT enabled, let the firmware know
  2436. * that the network interface is in control
  2437. */
  2438. if (adapter->flags & FLAG_HAS_AMT)
  2439. e1000_get_hw_control(adapter);
  2440. ew32(WUC, 0);
  2441. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)
  2442. e1e_wphy(&adapter->hw, BM_WUC, 0);
  2443. if (mac->ops.init_hw(hw))
  2444. e_err("Hardware Error\n");
  2445. /* additional part of the flow-control workaround above */
  2446. if (hw->mac.type == e1000_pchlan)
  2447. ew32(FCRTV_PCH, 0x1000);
  2448. e1000_update_mng_vlan(adapter);
  2449. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  2450. ew32(VET, ETH_P_8021Q);
  2451. e1000e_reset_adaptive(hw);
  2452. e1000_get_phy_info(hw);
  2453. if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
  2454. !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
  2455. u16 phy_data = 0;
  2456. /*
  2457. * speed up time to link by disabling smart power down, ignore
  2458. * the return value of this function because there is nothing
  2459. * different we would do if it failed
  2460. */
  2461. e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  2462. phy_data &= ~IGP02E1000_PM_SPD;
  2463. e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  2464. }
  2465. }
  2466. int e1000e_up(struct e1000_adapter *adapter)
  2467. {
  2468. struct e1000_hw *hw = &adapter->hw;
  2469. /* hardware has been reset, we need to reload some things */
  2470. e1000_configure(adapter);
  2471. clear_bit(__E1000_DOWN, &adapter->state);
  2472. napi_enable(&adapter->napi);
  2473. if (adapter->msix_entries)
  2474. e1000_configure_msix(adapter);
  2475. e1000_irq_enable(adapter);
  2476. netif_wake_queue(adapter->netdev);
  2477. /* fire a link change interrupt to start the watchdog */
  2478. ew32(ICS, E1000_ICS_LSC);
  2479. return 0;
  2480. }
  2481. void e1000e_down(struct e1000_adapter *adapter)
  2482. {
  2483. struct net_device *netdev = adapter->netdev;
  2484. struct e1000_hw *hw = &adapter->hw;
  2485. u32 tctl, rctl;
  2486. /*
  2487. * signal that we're down so the interrupt handler does not
  2488. * reschedule our watchdog timer
  2489. */
  2490. set_bit(__E1000_DOWN, &adapter->state);
  2491. /* disable receives in the hardware */
  2492. rctl = er32(RCTL);
  2493. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  2494. /* flush and sleep below */
  2495. netif_stop_queue(netdev);
  2496. /* disable transmits in the hardware */
  2497. tctl = er32(TCTL);
  2498. tctl &= ~E1000_TCTL_EN;
  2499. ew32(TCTL, tctl);
  2500. /* flush both disables and wait for them to finish */
  2501. e1e_flush();
  2502. msleep(10);
  2503. napi_disable(&adapter->napi);
  2504. e1000_irq_disable(adapter);
  2505. del_timer_sync(&adapter->watchdog_timer);
  2506. del_timer_sync(&adapter->phy_info_timer);
  2507. netdev->tx_queue_len = adapter->tx_queue_len;
  2508. netif_carrier_off(netdev);
  2509. adapter->link_speed = 0;
  2510. adapter->link_duplex = 0;
  2511. if (!pci_channel_offline(adapter->pdev))
  2512. e1000e_reset(adapter);
  2513. e1000_clean_tx_ring(adapter);
  2514. e1000_clean_rx_ring(adapter);
  2515. /*
  2516. * TODO: for power management, we could drop the link and
  2517. * pci_disable_device here.
  2518. */
  2519. }
  2520. void e1000e_reinit_locked(struct e1000_adapter *adapter)
  2521. {
  2522. might_sleep();
  2523. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  2524. msleep(1);
  2525. e1000e_down(adapter);
  2526. e1000e_up(adapter);
  2527. clear_bit(__E1000_RESETTING, &adapter->state);
  2528. }
  2529. /**
  2530. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  2531. * @adapter: board private structure to initialize
  2532. *
  2533. * e1000_sw_init initializes the Adapter private data structure.
  2534. * Fields are initialized based on PCI device information and
  2535. * OS network device settings (MTU size).
  2536. **/
  2537. static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
  2538. {
  2539. struct net_device *netdev = adapter->netdev;
  2540. adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
  2541. adapter->rx_ps_bsize0 = 128;
  2542. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2543. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  2544. e1000e_set_interrupt_capability(adapter);
  2545. if (e1000_alloc_queues(adapter))
  2546. return -ENOMEM;
  2547. /* Explicitly disable IRQ since the NIC can be in any state. */
  2548. e1000_irq_disable(adapter);
  2549. set_bit(__E1000_DOWN, &adapter->state);
  2550. return 0;
  2551. }
  2552. /**
  2553. * e1000_intr_msi_test - Interrupt Handler
  2554. * @irq: interrupt number
  2555. * @data: pointer to a network interface device structure
  2556. **/
  2557. static irqreturn_t e1000_intr_msi_test(int irq, void *data)
  2558. {
  2559. struct net_device *netdev = data;
  2560. struct e1000_adapter *adapter = netdev_priv(netdev);
  2561. struct e1000_hw *hw = &adapter->hw;
  2562. u32 icr = er32(ICR);
  2563. e_dbg("%s: icr is %08X\n", netdev->name, icr);
  2564. if (icr & E1000_ICR_RXSEQ) {
  2565. adapter->flags &= ~FLAG_MSI_TEST_FAILED;
  2566. wmb();
  2567. }
  2568. return IRQ_HANDLED;
  2569. }
  2570. /**
  2571. * e1000_test_msi_interrupt - Returns 0 for successful test
  2572. * @adapter: board private struct
  2573. *
  2574. * code flow taken from tg3.c
  2575. **/
  2576. static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
  2577. {
  2578. struct net_device *netdev = adapter->netdev;
  2579. struct e1000_hw *hw = &adapter->hw;
  2580. int err;
  2581. /* poll_enable hasn't been called yet, so don't need disable */
  2582. /* clear any pending events */
  2583. er32(ICR);
  2584. /* free the real vector and request a test handler */
  2585. e1000_free_irq(adapter);
  2586. e1000e_reset_interrupt_capability(adapter);
  2587. /* Assume that the test fails, if it succeeds then the test
  2588. * MSI irq handler will unset this flag */
  2589. adapter->flags |= FLAG_MSI_TEST_FAILED;
  2590. err = pci_enable_msi(adapter->pdev);
  2591. if (err)
  2592. goto msi_test_failed;
  2593. err = request_irq(adapter->pdev->irq, &e1000_intr_msi_test, 0,
  2594. netdev->name, netdev);
  2595. if (err) {
  2596. pci_disable_msi(adapter->pdev);
  2597. goto msi_test_failed;
  2598. }
  2599. wmb();
  2600. e1000_irq_enable(adapter);
  2601. /* fire an unusual interrupt on the test handler */
  2602. ew32(ICS, E1000_ICS_RXSEQ);
  2603. e1e_flush();
  2604. msleep(50);
  2605. e1000_irq_disable(adapter);
  2606. rmb();
  2607. if (adapter->flags & FLAG_MSI_TEST_FAILED) {
  2608. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  2609. err = -EIO;
  2610. e_info("MSI interrupt test failed!\n");
  2611. }
  2612. free_irq(adapter->pdev->irq, netdev);
  2613. pci_disable_msi(adapter->pdev);
  2614. if (err == -EIO)
  2615. goto msi_test_failed;
  2616. /* okay so the test worked, restore settings */
  2617. e_dbg("%s: MSI interrupt test succeeded!\n", netdev->name);
  2618. msi_test_failed:
  2619. e1000e_set_interrupt_capability(adapter);
  2620. e1000_request_irq(adapter);
  2621. return err;
  2622. }
  2623. /**
  2624. * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
  2625. * @adapter: board private struct
  2626. *
  2627. * code flow taken from tg3.c, called with e1000 interrupts disabled.
  2628. **/
  2629. static int e1000_test_msi(struct e1000_adapter *adapter)
  2630. {
  2631. int err;
  2632. u16 pci_cmd;
  2633. if (!(adapter->flags & FLAG_MSI_ENABLED))
  2634. return 0;
  2635. /* disable SERR in case the MSI write causes a master abort */
  2636. pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
  2637. pci_write_config_word(adapter->pdev, PCI_COMMAND,
  2638. pci_cmd & ~PCI_COMMAND_SERR);
  2639. err = e1000_test_msi_interrupt(adapter);
  2640. /* restore previous setting of command word */
  2641. pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
  2642. /* success ! */
  2643. if (!err)
  2644. return 0;
  2645. /* EIO means MSI test failed */
  2646. if (err != -EIO)
  2647. return err;
  2648. /* back to INTx mode */
  2649. e_warn("MSI interrupt test failed, using legacy interrupt.\n");
  2650. e1000_free_irq(adapter);
  2651. err = e1000_request_irq(adapter);
  2652. return err;
  2653. }
  2654. /**
  2655. * e1000_open - Called when a network interface is made active
  2656. * @netdev: network interface device structure
  2657. *
  2658. * Returns 0 on success, negative value on failure
  2659. *
  2660. * The open entry point is called when a network interface is made
  2661. * active by the system (IFF_UP). At this point all resources needed
  2662. * for transmit and receive operations are allocated, the interrupt
  2663. * handler is registered with the OS, the watchdog timer is started,
  2664. * and the stack is notified that the interface is ready.
  2665. **/
  2666. static int e1000_open(struct net_device *netdev)
  2667. {
  2668. struct e1000_adapter *adapter = netdev_priv(netdev);
  2669. struct e1000_hw *hw = &adapter->hw;
  2670. int err;
  2671. /* disallow open during test */
  2672. if (test_bit(__E1000_TESTING, &adapter->state))
  2673. return -EBUSY;
  2674. netif_carrier_off(netdev);
  2675. /* allocate transmit descriptors */
  2676. err = e1000e_setup_tx_resources(adapter);
  2677. if (err)
  2678. goto err_setup_tx;
  2679. /* allocate receive descriptors */
  2680. err = e1000e_setup_rx_resources(adapter);
  2681. if (err)
  2682. goto err_setup_rx;
  2683. e1000e_power_up_phy(adapter);
  2684. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  2685. if ((adapter->hw.mng_cookie.status &
  2686. E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
  2687. e1000_update_mng_vlan(adapter);
  2688. /*
  2689. * If AMT is enabled, let the firmware know that the network
  2690. * interface is now open
  2691. */
  2692. if (adapter->flags & FLAG_HAS_AMT)
  2693. e1000_get_hw_control(adapter);
  2694. /*
  2695. * before we allocate an interrupt, we must be ready to handle it.
  2696. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  2697. * as soon as we call pci_request_irq, so we have to setup our
  2698. * clean_rx handler before we do so.
  2699. */
  2700. e1000_configure(adapter);
  2701. err = e1000_request_irq(adapter);
  2702. if (err)
  2703. goto err_req_irq;
  2704. /*
  2705. * Work around PCIe errata with MSI interrupts causing some chipsets to
  2706. * ignore e1000e MSI messages, which means we need to test our MSI
  2707. * interrupt now
  2708. */
  2709. if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
  2710. err = e1000_test_msi(adapter);
  2711. if (err) {
  2712. e_err("Interrupt allocation failed\n");
  2713. goto err_req_irq;
  2714. }
  2715. }
  2716. /* From here on the code is the same as e1000e_up() */
  2717. clear_bit(__E1000_DOWN, &adapter->state);
  2718. napi_enable(&adapter->napi);
  2719. e1000_irq_enable(adapter);
  2720. netif_start_queue(netdev);
  2721. /* fire a link status change interrupt to start the watchdog */
  2722. ew32(ICS, E1000_ICS_LSC);
  2723. return 0;
  2724. err_req_irq:
  2725. e1000_release_hw_control(adapter);
  2726. e1000_power_down_phy(adapter);
  2727. e1000e_free_rx_resources(adapter);
  2728. err_setup_rx:
  2729. e1000e_free_tx_resources(adapter);
  2730. err_setup_tx:
  2731. e1000e_reset(adapter);
  2732. return err;
  2733. }
  2734. /**
  2735. * e1000_close - Disables a network interface
  2736. * @netdev: network interface device structure
  2737. *
  2738. * Returns 0, this is not allowed to fail
  2739. *
  2740. * The close entry point is called when an interface is de-activated
  2741. * by the OS. The hardware is still under the drivers control, but
  2742. * needs to be disabled. A global MAC reset is issued to stop the
  2743. * hardware, and all transmit and receive resources are freed.
  2744. **/
  2745. static int e1000_close(struct net_device *netdev)
  2746. {
  2747. struct e1000_adapter *adapter = netdev_priv(netdev);
  2748. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  2749. e1000e_down(adapter);
  2750. e1000_power_down_phy(adapter);
  2751. e1000_free_irq(adapter);
  2752. e1000e_free_tx_resources(adapter);
  2753. e1000e_free_rx_resources(adapter);
  2754. /*
  2755. * kill manageability vlan ID if supported, but not if a vlan with
  2756. * the same ID is registered on the host OS (let 8021q kill it)
  2757. */
  2758. if ((adapter->hw.mng_cookie.status &
  2759. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  2760. !(adapter->vlgrp &&
  2761. vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
  2762. e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  2763. /*
  2764. * If AMT is enabled, let the firmware know that the network
  2765. * interface is now closed
  2766. */
  2767. if (adapter->flags & FLAG_HAS_AMT)
  2768. e1000_release_hw_control(adapter);
  2769. return 0;
  2770. }
  2771. /**
  2772. * e1000_set_mac - Change the Ethernet Address of the NIC
  2773. * @netdev: network interface device structure
  2774. * @p: pointer to an address structure
  2775. *
  2776. * Returns 0 on success, negative on failure
  2777. **/
  2778. static int e1000_set_mac(struct net_device *netdev, void *p)
  2779. {
  2780. struct e1000_adapter *adapter = netdev_priv(netdev);
  2781. struct sockaddr *addr = p;
  2782. if (!is_valid_ether_addr(addr->sa_data))
  2783. return -EADDRNOTAVAIL;
  2784. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2785. memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
  2786. e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
  2787. if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
  2788. /* activate the work around */
  2789. e1000e_set_laa_state_82571(&adapter->hw, 1);
  2790. /*
  2791. * Hold a copy of the LAA in RAR[14] This is done so that
  2792. * between the time RAR[0] gets clobbered and the time it
  2793. * gets fixed (in e1000_watchdog), the actual LAA is in one
  2794. * of the RARs and no incoming packets directed to this port
  2795. * are dropped. Eventually the LAA will be in RAR[0] and
  2796. * RAR[14]
  2797. */
  2798. e1000e_rar_set(&adapter->hw,
  2799. adapter->hw.mac.addr,
  2800. adapter->hw.mac.rar_entry_count - 1);
  2801. }
  2802. return 0;
  2803. }
  2804. /**
  2805. * e1000e_update_phy_task - work thread to update phy
  2806. * @work: pointer to our work struct
  2807. *
  2808. * this worker thread exists because we must acquire a
  2809. * semaphore to read the phy, which we could msleep while
  2810. * waiting for it, and we can't msleep in a timer.
  2811. **/
  2812. static void e1000e_update_phy_task(struct work_struct *work)
  2813. {
  2814. struct e1000_adapter *adapter = container_of(work,
  2815. struct e1000_adapter, update_phy_task);
  2816. e1000_get_phy_info(&adapter->hw);
  2817. }
  2818. /*
  2819. * Need to wait a few seconds after link up to get diagnostic information from
  2820. * the phy
  2821. */
  2822. static void e1000_update_phy_info(unsigned long data)
  2823. {
  2824. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  2825. schedule_work(&adapter->update_phy_task);
  2826. }
  2827. /**
  2828. * e1000e_update_stats - Update the board statistics counters
  2829. * @adapter: board private structure
  2830. **/
  2831. void e1000e_update_stats(struct e1000_adapter *adapter)
  2832. {
  2833. struct e1000_hw *hw = &adapter->hw;
  2834. struct pci_dev *pdev = adapter->pdev;
  2835. u16 phy_data;
  2836. /*
  2837. * Prevent stats update while adapter is being reset, or if the pci
  2838. * connection is down.
  2839. */
  2840. if (adapter->link_speed == 0)
  2841. return;
  2842. if (pci_channel_offline(pdev))
  2843. return;
  2844. adapter->stats.crcerrs += er32(CRCERRS);
  2845. adapter->stats.gprc += er32(GPRC);
  2846. adapter->stats.gorc += er32(GORCL);
  2847. er32(GORCH); /* Clear gorc */
  2848. adapter->stats.bprc += er32(BPRC);
  2849. adapter->stats.mprc += er32(MPRC);
  2850. adapter->stats.roc += er32(ROC);
  2851. adapter->stats.mpc += er32(MPC);
  2852. if ((hw->phy.type == e1000_phy_82578) ||
  2853. (hw->phy.type == e1000_phy_82577)) {
  2854. e1e_rphy(hw, HV_SCC_UPPER, &phy_data);
  2855. e1e_rphy(hw, HV_SCC_LOWER, &phy_data);
  2856. adapter->stats.scc += phy_data;
  2857. e1e_rphy(hw, HV_ECOL_UPPER, &phy_data);
  2858. e1e_rphy(hw, HV_ECOL_LOWER, &phy_data);
  2859. adapter->stats.ecol += phy_data;
  2860. e1e_rphy(hw, HV_MCC_UPPER, &phy_data);
  2861. e1e_rphy(hw, HV_MCC_LOWER, &phy_data);
  2862. adapter->stats.mcc += phy_data;
  2863. e1e_rphy(hw, HV_LATECOL_UPPER, &phy_data);
  2864. e1e_rphy(hw, HV_LATECOL_LOWER, &phy_data);
  2865. adapter->stats.latecol += phy_data;
  2866. e1e_rphy(hw, HV_DC_UPPER, &phy_data);
  2867. e1e_rphy(hw, HV_DC_LOWER, &phy_data);
  2868. adapter->stats.dc += phy_data;
  2869. } else {
  2870. adapter->stats.scc += er32(SCC);
  2871. adapter->stats.ecol += er32(ECOL);
  2872. adapter->stats.mcc += er32(MCC);
  2873. adapter->stats.latecol += er32(LATECOL);
  2874. adapter->stats.dc += er32(DC);
  2875. }
  2876. adapter->stats.xonrxc += er32(XONRXC);
  2877. adapter->stats.xontxc += er32(XONTXC);
  2878. adapter->stats.xoffrxc += er32(XOFFRXC);
  2879. adapter->stats.xofftxc += er32(XOFFTXC);
  2880. adapter->stats.gptc += er32(GPTC);
  2881. adapter->stats.gotc += er32(GOTCL);
  2882. er32(GOTCH); /* Clear gotc */
  2883. adapter->stats.rnbc += er32(RNBC);
  2884. adapter->stats.ruc += er32(RUC);
  2885. adapter->stats.mptc += er32(MPTC);
  2886. adapter->stats.bptc += er32(BPTC);
  2887. /* used for adaptive IFS */
  2888. hw->mac.tx_packet_delta = er32(TPT);
  2889. adapter->stats.tpt += hw->mac.tx_packet_delta;
  2890. if ((hw->phy.type == e1000_phy_82578) ||
  2891. (hw->phy.type == e1000_phy_82577)) {
  2892. e1e_rphy(hw, HV_COLC_UPPER, &phy_data);
  2893. e1e_rphy(hw, HV_COLC_LOWER, &phy_data);
  2894. hw->mac.collision_delta = phy_data;
  2895. } else {
  2896. hw->mac.collision_delta = er32(COLC);
  2897. }
  2898. adapter->stats.colc += hw->mac.collision_delta;
  2899. adapter->stats.algnerrc += er32(ALGNERRC);
  2900. adapter->stats.rxerrc += er32(RXERRC);
  2901. if ((hw->phy.type == e1000_phy_82578) ||
  2902. (hw->phy.type == e1000_phy_82577)) {
  2903. e1e_rphy(hw, HV_TNCRS_UPPER, &phy_data);
  2904. e1e_rphy(hw, HV_TNCRS_LOWER, &phy_data);
  2905. adapter->stats.tncrs += phy_data;
  2906. } else {
  2907. if ((hw->mac.type != e1000_82574) &&
  2908. (hw->mac.type != e1000_82583))
  2909. adapter->stats.tncrs += er32(TNCRS);
  2910. }
  2911. adapter->stats.cexterr += er32(CEXTERR);
  2912. adapter->stats.tsctc += er32(TSCTC);
  2913. adapter->stats.tsctfc += er32(TSCTFC);
  2914. /* Fill out the OS statistics structure */
  2915. adapter->net_stats.multicast = adapter->stats.mprc;
  2916. adapter->net_stats.collisions = adapter->stats.colc;
  2917. /* Rx Errors */
  2918. /*
  2919. * RLEC on some newer hardware can be incorrect so build
  2920. * our own version based on RUC and ROC
  2921. */
  2922. adapter->net_stats.rx_errors = adapter->stats.rxerrc +
  2923. adapter->stats.crcerrs + adapter->stats.algnerrc +
  2924. adapter->stats.ruc + adapter->stats.roc +
  2925. adapter->stats.cexterr;
  2926. adapter->net_stats.rx_length_errors = adapter->stats.ruc +
  2927. adapter->stats.roc;
  2928. adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
  2929. adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
  2930. adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
  2931. /* Tx Errors */
  2932. adapter->net_stats.tx_errors = adapter->stats.ecol +
  2933. adapter->stats.latecol;
  2934. adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
  2935. adapter->net_stats.tx_window_errors = adapter->stats.latecol;
  2936. adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
  2937. /* Tx Dropped needs to be maintained elsewhere */
  2938. /* Management Stats */
  2939. adapter->stats.mgptc += er32(MGTPTC);
  2940. adapter->stats.mgprc += er32(MGTPRC);
  2941. adapter->stats.mgpdc += er32(MGTPDC);
  2942. }
  2943. /**
  2944. * e1000_phy_read_status - Update the PHY register status snapshot
  2945. * @adapter: board private structure
  2946. **/
  2947. static void e1000_phy_read_status(struct e1000_adapter *adapter)
  2948. {
  2949. struct e1000_hw *hw = &adapter->hw;
  2950. struct e1000_phy_regs *phy = &adapter->phy_regs;
  2951. int ret_val;
  2952. if ((er32(STATUS) & E1000_STATUS_LU) &&
  2953. (adapter->hw.phy.media_type == e1000_media_type_copper)) {
  2954. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
  2955. ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
  2956. ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
  2957. ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
  2958. ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
  2959. ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
  2960. ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
  2961. ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
  2962. if (ret_val)
  2963. e_warn("Error reading PHY register\n");
  2964. } else {
  2965. /*
  2966. * Do not read PHY registers if link is not up
  2967. * Set values to typical power-on defaults
  2968. */
  2969. phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
  2970. phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
  2971. BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
  2972. BMSR_ERCAP);
  2973. phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
  2974. ADVERTISE_ALL | ADVERTISE_CSMA);
  2975. phy->lpa = 0;
  2976. phy->expansion = EXPANSION_ENABLENPAGE;
  2977. phy->ctrl1000 = ADVERTISE_1000FULL;
  2978. phy->stat1000 = 0;
  2979. phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
  2980. }
  2981. }
  2982. static void e1000_print_link_info(struct e1000_adapter *adapter)
  2983. {
  2984. struct e1000_hw *hw = &adapter->hw;
  2985. u32 ctrl = er32(CTRL);
  2986. /* Link status message must follow this format for user tools */
  2987. printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
  2988. "Flow Control: %s\n",
  2989. adapter->netdev->name,
  2990. adapter->link_speed,
  2991. (adapter->link_duplex == FULL_DUPLEX) ?
  2992. "Full Duplex" : "Half Duplex",
  2993. ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
  2994. "RX/TX" :
  2995. ((ctrl & E1000_CTRL_RFCE) ? "RX" :
  2996. ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
  2997. }
  2998. bool e1000_has_link(struct e1000_adapter *adapter)
  2999. {
  3000. struct e1000_hw *hw = &adapter->hw;
  3001. bool link_active = 0;
  3002. s32 ret_val = 0;
  3003. /*
  3004. * get_link_status is set on LSC (link status) interrupt or
  3005. * Rx sequence error interrupt. get_link_status will stay
  3006. * false until the check_for_link establishes link
  3007. * for copper adapters ONLY
  3008. */
  3009. switch (hw->phy.media_type) {
  3010. case e1000_media_type_copper:
  3011. if (hw->mac.get_link_status) {
  3012. ret_val = hw->mac.ops.check_for_link(hw);
  3013. link_active = !hw->mac.get_link_status;
  3014. } else {
  3015. link_active = 1;
  3016. }
  3017. break;
  3018. case e1000_media_type_fiber:
  3019. ret_val = hw->mac.ops.check_for_link(hw);
  3020. link_active = !!(er32(STATUS) & E1000_STATUS_LU);
  3021. break;
  3022. case e1000_media_type_internal_serdes:
  3023. ret_val = hw->mac.ops.check_for_link(hw);
  3024. link_active = adapter->hw.mac.serdes_has_link;
  3025. break;
  3026. default:
  3027. case e1000_media_type_unknown:
  3028. break;
  3029. }
  3030. if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
  3031. (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
  3032. /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
  3033. e_info("Gigabit has been disabled, downgrading speed\n");
  3034. }
  3035. return link_active;
  3036. }
  3037. static void e1000e_enable_receives(struct e1000_adapter *adapter)
  3038. {
  3039. /* make sure the receive unit is started */
  3040. if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
  3041. (adapter->flags & FLAG_RX_RESTART_NOW)) {
  3042. struct e1000_hw *hw = &adapter->hw;
  3043. u32 rctl = er32(RCTL);
  3044. ew32(RCTL, rctl | E1000_RCTL_EN);
  3045. adapter->flags &= ~FLAG_RX_RESTART_NOW;
  3046. }
  3047. }
  3048. /**
  3049. * e1000_watchdog - Timer Call-back
  3050. * @data: pointer to adapter cast into an unsigned long
  3051. **/
  3052. static void e1000_watchdog(unsigned long data)
  3053. {
  3054. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  3055. /* Do the rest outside of interrupt context */
  3056. schedule_work(&adapter->watchdog_task);
  3057. /* TODO: make this use queue_delayed_work() */
  3058. }
  3059. static void e1000_watchdog_task(struct work_struct *work)
  3060. {
  3061. struct e1000_adapter *adapter = container_of(work,
  3062. struct e1000_adapter, watchdog_task);
  3063. struct net_device *netdev = adapter->netdev;
  3064. struct e1000_mac_info *mac = &adapter->hw.mac;
  3065. struct e1000_phy_info *phy = &adapter->hw.phy;
  3066. struct e1000_ring *tx_ring = adapter->tx_ring;
  3067. struct e1000_hw *hw = &adapter->hw;
  3068. u32 link, tctl;
  3069. int tx_pending = 0;
  3070. link = e1000_has_link(adapter);
  3071. if ((netif_carrier_ok(netdev)) && link) {
  3072. e1000e_enable_receives(adapter);
  3073. goto link_up;
  3074. }
  3075. if ((e1000e_enable_tx_pkt_filtering(hw)) &&
  3076. (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
  3077. e1000_update_mng_vlan(adapter);
  3078. if (link) {
  3079. if (!netif_carrier_ok(netdev)) {
  3080. bool txb2b = 1;
  3081. /* update snapshot of PHY registers on LSC */
  3082. e1000_phy_read_status(adapter);
  3083. mac->ops.get_link_up_info(&adapter->hw,
  3084. &adapter->link_speed,
  3085. &adapter->link_duplex);
  3086. e1000_print_link_info(adapter);
  3087. /*
  3088. * On supported PHYs, check for duplex mismatch only
  3089. * if link has autonegotiated at 10/100 half
  3090. */
  3091. if ((hw->phy.type == e1000_phy_igp_3 ||
  3092. hw->phy.type == e1000_phy_bm) &&
  3093. (hw->mac.autoneg == true) &&
  3094. (adapter->link_speed == SPEED_10 ||
  3095. adapter->link_speed == SPEED_100) &&
  3096. (adapter->link_duplex == HALF_DUPLEX)) {
  3097. u16 autoneg_exp;
  3098. e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
  3099. if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
  3100. e_info("Autonegotiated half duplex but"
  3101. " link partner cannot autoneg. "
  3102. " Try forcing full duplex if "
  3103. "link gets many collisions.\n");
  3104. }
  3105. /*
  3106. * tweak tx_queue_len according to speed/duplex
  3107. * and adjust the timeout factor
  3108. */
  3109. netdev->tx_queue_len = adapter->tx_queue_len;
  3110. adapter->tx_timeout_factor = 1;
  3111. switch (adapter->link_speed) {
  3112. case SPEED_10:
  3113. txb2b = 0;
  3114. netdev->tx_queue_len = 10;
  3115. adapter->tx_timeout_factor = 16;
  3116. break;
  3117. case SPEED_100:
  3118. txb2b = 0;
  3119. netdev->tx_queue_len = 100;
  3120. adapter->tx_timeout_factor = 10;
  3121. break;
  3122. }
  3123. /*
  3124. * workaround: re-program speed mode bit after
  3125. * link-up event
  3126. */
  3127. if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
  3128. !txb2b) {
  3129. u32 tarc0;
  3130. tarc0 = er32(TARC(0));
  3131. tarc0 &= ~SPEED_MODE_BIT;
  3132. ew32(TARC(0), tarc0);
  3133. }
  3134. /*
  3135. * disable TSO for pcie and 10/100 speeds, to avoid
  3136. * some hardware issues
  3137. */
  3138. if (!(adapter->flags & FLAG_TSO_FORCE)) {
  3139. switch (adapter->link_speed) {
  3140. case SPEED_10:
  3141. case SPEED_100:
  3142. e_info("10/100 speed: disabling TSO\n");
  3143. netdev->features &= ~NETIF_F_TSO;
  3144. netdev->features &= ~NETIF_F_TSO6;
  3145. break;
  3146. case SPEED_1000:
  3147. netdev->features |= NETIF_F_TSO;
  3148. netdev->features |= NETIF_F_TSO6;
  3149. break;
  3150. default:
  3151. /* oops */
  3152. break;
  3153. }
  3154. }
  3155. /*
  3156. * enable transmits in the hardware, need to do this
  3157. * after setting TARC(0)
  3158. */
  3159. tctl = er32(TCTL);
  3160. tctl |= E1000_TCTL_EN;
  3161. ew32(TCTL, tctl);
  3162. /*
  3163. * Perform any post-link-up configuration before
  3164. * reporting link up.
  3165. */
  3166. if (phy->ops.cfg_on_link_up)
  3167. phy->ops.cfg_on_link_up(hw);
  3168. netif_carrier_on(netdev);
  3169. if (!test_bit(__E1000_DOWN, &adapter->state))
  3170. mod_timer(&adapter->phy_info_timer,
  3171. round_jiffies(jiffies + 2 * HZ));
  3172. }
  3173. } else {
  3174. if (netif_carrier_ok(netdev)) {
  3175. adapter->link_speed = 0;
  3176. adapter->link_duplex = 0;
  3177. /* Link status message must follow this format */
  3178. printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
  3179. adapter->netdev->name);
  3180. netif_carrier_off(netdev);
  3181. if (!test_bit(__E1000_DOWN, &adapter->state))
  3182. mod_timer(&adapter->phy_info_timer,
  3183. round_jiffies(jiffies + 2 * HZ));
  3184. if (adapter->flags & FLAG_RX_NEEDS_RESTART)
  3185. schedule_work(&adapter->reset_task);
  3186. }
  3187. }
  3188. link_up:
  3189. e1000e_update_stats(adapter);
  3190. mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  3191. adapter->tpt_old = adapter->stats.tpt;
  3192. mac->collision_delta = adapter->stats.colc - adapter->colc_old;
  3193. adapter->colc_old = adapter->stats.colc;
  3194. adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
  3195. adapter->gorc_old = adapter->stats.gorc;
  3196. adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
  3197. adapter->gotc_old = adapter->stats.gotc;
  3198. e1000e_update_adaptive(&adapter->hw);
  3199. if (!netif_carrier_ok(netdev)) {
  3200. tx_pending = (e1000_desc_unused(tx_ring) + 1 <
  3201. tx_ring->count);
  3202. if (tx_pending) {
  3203. /*
  3204. * We've lost link, so the controller stops DMA,
  3205. * but we've got queued Tx work that's never going
  3206. * to get done, so reset controller to flush Tx.
  3207. * (Do the reset outside of interrupt context).
  3208. */
  3209. adapter->tx_timeout_count++;
  3210. schedule_work(&adapter->reset_task);
  3211. /* return immediately since reset is imminent */
  3212. return;
  3213. }
  3214. }
  3215. /* Cause software interrupt to ensure Rx ring is cleaned */
  3216. if (adapter->msix_entries)
  3217. ew32(ICS, adapter->rx_ring->ims_val);
  3218. else
  3219. ew32(ICS, E1000_ICS_RXDMT0);
  3220. /* Force detection of hung controller every watchdog period */
  3221. adapter->detect_tx_hung = 1;
  3222. /*
  3223. * With 82571 controllers, LAA may be overwritten due to controller
  3224. * reset from the other port. Set the appropriate LAA in RAR[0]
  3225. */
  3226. if (e1000e_get_laa_state_82571(hw))
  3227. e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
  3228. /* Reset the timer */
  3229. if (!test_bit(__E1000_DOWN, &adapter->state))
  3230. mod_timer(&adapter->watchdog_timer,
  3231. round_jiffies(jiffies + 2 * HZ));
  3232. }
  3233. #define E1000_TX_FLAGS_CSUM 0x00000001
  3234. #define E1000_TX_FLAGS_VLAN 0x00000002
  3235. #define E1000_TX_FLAGS_TSO 0x00000004
  3236. #define E1000_TX_FLAGS_IPV4 0x00000008
  3237. #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
  3238. #define E1000_TX_FLAGS_VLAN_SHIFT 16
  3239. static int e1000_tso(struct e1000_adapter *adapter,
  3240. struct sk_buff *skb)
  3241. {
  3242. struct e1000_ring *tx_ring = adapter->tx_ring;
  3243. struct e1000_context_desc *context_desc;
  3244. struct e1000_buffer *buffer_info;
  3245. unsigned int i;
  3246. u32 cmd_length = 0;
  3247. u16 ipcse = 0, tucse, mss;
  3248. u8 ipcss, ipcso, tucss, tucso, hdr_len;
  3249. int err;
  3250. if (skb_is_gso(skb)) {
  3251. if (skb_header_cloned(skb)) {
  3252. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  3253. if (err)
  3254. return err;
  3255. }
  3256. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  3257. mss = skb_shinfo(skb)->gso_size;
  3258. if (skb->protocol == htons(ETH_P_IP)) {
  3259. struct iphdr *iph = ip_hdr(skb);
  3260. iph->tot_len = 0;
  3261. iph->check = 0;
  3262. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3263. iph->daddr, 0,
  3264. IPPROTO_TCP,
  3265. 0);
  3266. cmd_length = E1000_TXD_CMD_IP;
  3267. ipcse = skb_transport_offset(skb) - 1;
  3268. } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
  3269. ipv6_hdr(skb)->payload_len = 0;
  3270. tcp_hdr(skb)->check =
  3271. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  3272. &ipv6_hdr(skb)->daddr,
  3273. 0, IPPROTO_TCP, 0);
  3274. ipcse = 0;
  3275. }
  3276. ipcss = skb_network_offset(skb);
  3277. ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
  3278. tucss = skb_transport_offset(skb);
  3279. tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
  3280. tucse = 0;
  3281. cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
  3282. E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
  3283. i = tx_ring->next_to_use;
  3284. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  3285. buffer_info = &tx_ring->buffer_info[i];
  3286. context_desc->lower_setup.ip_fields.ipcss = ipcss;
  3287. context_desc->lower_setup.ip_fields.ipcso = ipcso;
  3288. context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
  3289. context_desc->upper_setup.tcp_fields.tucss = tucss;
  3290. context_desc->upper_setup.tcp_fields.tucso = tucso;
  3291. context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
  3292. context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
  3293. context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
  3294. context_desc->cmd_and_length = cpu_to_le32(cmd_length);
  3295. buffer_info->time_stamp = jiffies;
  3296. buffer_info->next_to_watch = i;
  3297. i++;
  3298. if (i == tx_ring->count)
  3299. i = 0;
  3300. tx_ring->next_to_use = i;
  3301. return 1;
  3302. }
  3303. return 0;
  3304. }
  3305. static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
  3306. {
  3307. struct e1000_ring *tx_ring = adapter->tx_ring;
  3308. struct e1000_context_desc *context_desc;
  3309. struct e1000_buffer *buffer_info;
  3310. unsigned int i;
  3311. u8 css;
  3312. u32 cmd_len = E1000_TXD_CMD_DEXT;
  3313. __be16 protocol;
  3314. if (skb->ip_summed != CHECKSUM_PARTIAL)
  3315. return 0;
  3316. if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
  3317. protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
  3318. else
  3319. protocol = skb->protocol;
  3320. switch (protocol) {
  3321. case cpu_to_be16(ETH_P_IP):
  3322. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  3323. cmd_len |= E1000_TXD_CMD_TCP;
  3324. break;
  3325. case cpu_to_be16(ETH_P_IPV6):
  3326. /* XXX not handling all IPV6 headers */
  3327. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  3328. cmd_len |= E1000_TXD_CMD_TCP;
  3329. break;
  3330. default:
  3331. if (unlikely(net_ratelimit()))
  3332. e_warn("checksum_partial proto=%x!\n",
  3333. be16_to_cpu(protocol));
  3334. break;
  3335. }
  3336. css = skb_transport_offset(skb);
  3337. i = tx_ring->next_to_use;
  3338. buffer_info = &tx_ring->buffer_info[i];
  3339. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  3340. context_desc->lower_setup.ip_config = 0;
  3341. context_desc->upper_setup.tcp_fields.tucss = css;
  3342. context_desc->upper_setup.tcp_fields.tucso =
  3343. css + skb->csum_offset;
  3344. context_desc->upper_setup.tcp_fields.tucse = 0;
  3345. context_desc->tcp_seg_setup.data = 0;
  3346. context_desc->cmd_and_length = cpu_to_le32(cmd_len);
  3347. buffer_info->time_stamp = jiffies;
  3348. buffer_info->next_to_watch = i;
  3349. i++;
  3350. if (i == tx_ring->count)
  3351. i = 0;
  3352. tx_ring->next_to_use = i;
  3353. return 1;
  3354. }
  3355. #define E1000_MAX_PER_TXD 8192
  3356. #define E1000_MAX_TXD_PWR 12
  3357. static int e1000_tx_map(struct e1000_adapter *adapter,
  3358. struct sk_buff *skb, unsigned int first,
  3359. unsigned int max_per_txd, unsigned int nr_frags,
  3360. unsigned int mss)
  3361. {
  3362. struct e1000_ring *tx_ring = adapter->tx_ring;
  3363. struct e1000_buffer *buffer_info;
  3364. unsigned int len = skb_headlen(skb);
  3365. unsigned int offset, size, count = 0, i;
  3366. unsigned int f;
  3367. dma_addr_t *map;
  3368. i = tx_ring->next_to_use;
  3369. if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
  3370. dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
  3371. adapter->tx_dma_failed++;
  3372. return 0;
  3373. }
  3374. map = skb_shinfo(skb)->dma_maps;
  3375. offset = 0;
  3376. while (len) {
  3377. buffer_info = &tx_ring->buffer_info[i];
  3378. size = min(len, max_per_txd);
  3379. buffer_info->length = size;
  3380. buffer_info->time_stamp = jiffies;
  3381. buffer_info->next_to_watch = i;
  3382. buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
  3383. count++;
  3384. len -= size;
  3385. offset += size;
  3386. if (len) {
  3387. i++;
  3388. if (i == tx_ring->count)
  3389. i = 0;
  3390. }
  3391. }
  3392. for (f = 0; f < nr_frags; f++) {
  3393. struct skb_frag_struct *frag;
  3394. frag = &skb_shinfo(skb)->frags[f];
  3395. len = frag->size;
  3396. offset = 0;
  3397. while (len) {
  3398. i++;
  3399. if (i == tx_ring->count)
  3400. i = 0;
  3401. buffer_info = &tx_ring->buffer_info[i];
  3402. size = min(len, max_per_txd);
  3403. buffer_info->length = size;
  3404. buffer_info->time_stamp = jiffies;
  3405. buffer_info->next_to_watch = i;
  3406. buffer_info->dma = map[f] + offset;
  3407. len -= size;
  3408. offset += size;
  3409. count++;
  3410. }
  3411. }
  3412. tx_ring->buffer_info[i].skb = skb;
  3413. tx_ring->buffer_info[first].next_to_watch = i;
  3414. return count;
  3415. }
  3416. static void e1000_tx_queue(struct e1000_adapter *adapter,
  3417. int tx_flags, int count)
  3418. {
  3419. struct e1000_ring *tx_ring = adapter->tx_ring;
  3420. struct e1000_tx_desc *tx_desc = NULL;
  3421. struct e1000_buffer *buffer_info;
  3422. u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
  3423. unsigned int i;
  3424. if (tx_flags & E1000_TX_FLAGS_TSO) {
  3425. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
  3426. E1000_TXD_CMD_TSE;
  3427. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  3428. if (tx_flags & E1000_TX_FLAGS_IPV4)
  3429. txd_upper |= E1000_TXD_POPTS_IXSM << 8;
  3430. }
  3431. if (tx_flags & E1000_TX_FLAGS_CSUM) {
  3432. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  3433. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  3434. }
  3435. if (tx_flags & E1000_TX_FLAGS_VLAN) {
  3436. txd_lower |= E1000_TXD_CMD_VLE;
  3437. txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
  3438. }
  3439. i = tx_ring->next_to_use;
  3440. while (count--) {
  3441. buffer_info = &tx_ring->buffer_info[i];
  3442. tx_desc = E1000_TX_DESC(*tx_ring, i);
  3443. tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  3444. tx_desc->lower.data =
  3445. cpu_to_le32(txd_lower | buffer_info->length);
  3446. tx_desc->upper.data = cpu_to_le32(txd_upper);
  3447. i++;
  3448. if (i == tx_ring->count)
  3449. i = 0;
  3450. }
  3451. tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
  3452. /*
  3453. * Force memory writes to complete before letting h/w
  3454. * know there are new descriptors to fetch. (Only
  3455. * applicable for weak-ordered memory model archs,
  3456. * such as IA-64).
  3457. */
  3458. wmb();
  3459. tx_ring->next_to_use = i;
  3460. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  3461. /*
  3462. * we need this if more than one processor can write to our tail
  3463. * at a time, it synchronizes IO on IA64/Altix systems
  3464. */
  3465. mmiowb();
  3466. }
  3467. #define MINIMUM_DHCP_PACKET_SIZE 282
  3468. static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
  3469. struct sk_buff *skb)
  3470. {
  3471. struct e1000_hw *hw = &adapter->hw;
  3472. u16 length, offset;
  3473. if (vlan_tx_tag_present(skb)) {
  3474. if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
  3475. && (adapter->hw.mng_cookie.status &
  3476. E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
  3477. return 0;
  3478. }
  3479. if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
  3480. return 0;
  3481. if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
  3482. return 0;
  3483. {
  3484. const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
  3485. struct udphdr *udp;
  3486. if (ip->protocol != IPPROTO_UDP)
  3487. return 0;
  3488. udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
  3489. if (ntohs(udp->dest) != 67)
  3490. return 0;
  3491. offset = (u8 *)udp + 8 - skb->data;
  3492. length = skb->len - offset;
  3493. return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
  3494. }
  3495. return 0;
  3496. }
  3497. static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
  3498. {
  3499. struct e1000_adapter *adapter = netdev_priv(netdev);
  3500. netif_stop_queue(netdev);
  3501. /*
  3502. * Herbert's original patch had:
  3503. * smp_mb__after_netif_stop_queue();
  3504. * but since that doesn't exist yet, just open code it.
  3505. */
  3506. smp_mb();
  3507. /*
  3508. * We need to check again in a case another CPU has just
  3509. * made room available.
  3510. */
  3511. if (e1000_desc_unused(adapter->tx_ring) < size)
  3512. return -EBUSY;
  3513. /* A reprieve! */
  3514. netif_start_queue(netdev);
  3515. ++adapter->restart_queue;
  3516. return 0;
  3517. }
  3518. static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
  3519. {
  3520. struct e1000_adapter *adapter = netdev_priv(netdev);
  3521. if (e1000_desc_unused(adapter->tx_ring) >= size)
  3522. return 0;
  3523. return __e1000_maybe_stop_tx(netdev, size);
  3524. }
  3525. #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
  3526. static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
  3527. struct net_device *netdev)
  3528. {
  3529. struct e1000_adapter *adapter = netdev_priv(netdev);
  3530. struct e1000_ring *tx_ring = adapter->tx_ring;
  3531. unsigned int first;
  3532. unsigned int max_per_txd = E1000_MAX_PER_TXD;
  3533. unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
  3534. unsigned int tx_flags = 0;
  3535. unsigned int len = skb->len - skb->data_len;
  3536. unsigned int nr_frags;
  3537. unsigned int mss;
  3538. int count = 0;
  3539. int tso;
  3540. unsigned int f;
  3541. if (test_bit(__E1000_DOWN, &adapter->state)) {
  3542. dev_kfree_skb_any(skb);
  3543. return NETDEV_TX_OK;
  3544. }
  3545. if (skb->len <= 0) {
  3546. dev_kfree_skb_any(skb);
  3547. return NETDEV_TX_OK;
  3548. }
  3549. mss = skb_shinfo(skb)->gso_size;
  3550. /*
  3551. * The controller does a simple calculation to
  3552. * make sure there is enough room in the FIFO before
  3553. * initiating the DMA for each buffer. The calc is:
  3554. * 4 = ceil(buffer len/mss). To make sure we don't
  3555. * overrun the FIFO, adjust the max buffer len if mss
  3556. * drops.
  3557. */
  3558. if (mss) {
  3559. u8 hdr_len;
  3560. max_per_txd = min(mss << 2, max_per_txd);
  3561. max_txd_pwr = fls(max_per_txd) - 1;
  3562. /*
  3563. * TSO Workaround for 82571/2/3 Controllers -- if skb->data
  3564. * points to just header, pull a few bytes of payload from
  3565. * frags into skb->data
  3566. */
  3567. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  3568. /*
  3569. * we do this workaround for ES2LAN, but it is un-necessary,
  3570. * avoiding it could save a lot of cycles
  3571. */
  3572. if (skb->data_len && (hdr_len == len)) {
  3573. unsigned int pull_size;
  3574. pull_size = min((unsigned int)4, skb->data_len);
  3575. if (!__pskb_pull_tail(skb, pull_size)) {
  3576. e_err("__pskb_pull_tail failed.\n");
  3577. dev_kfree_skb_any(skb);
  3578. return NETDEV_TX_OK;
  3579. }
  3580. len = skb->len - skb->data_len;
  3581. }
  3582. }
  3583. /* reserve a descriptor for the offload context */
  3584. if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
  3585. count++;
  3586. count++;
  3587. count += TXD_USE_COUNT(len, max_txd_pwr);
  3588. nr_frags = skb_shinfo(skb)->nr_frags;
  3589. for (f = 0; f < nr_frags; f++)
  3590. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
  3591. max_txd_pwr);
  3592. if (adapter->hw.mac.tx_pkt_filtering)
  3593. e1000_transfer_dhcp_info(adapter, skb);
  3594. /*
  3595. * need: count + 2 desc gap to keep tail from touching
  3596. * head, otherwise try next time
  3597. */
  3598. if (e1000_maybe_stop_tx(netdev, count + 2))
  3599. return NETDEV_TX_BUSY;
  3600. if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
  3601. tx_flags |= E1000_TX_FLAGS_VLAN;
  3602. tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
  3603. }
  3604. first = tx_ring->next_to_use;
  3605. tso = e1000_tso(adapter, skb);
  3606. if (tso < 0) {
  3607. dev_kfree_skb_any(skb);
  3608. return NETDEV_TX_OK;
  3609. }
  3610. if (tso)
  3611. tx_flags |= E1000_TX_FLAGS_TSO;
  3612. else if (e1000_tx_csum(adapter, skb))
  3613. tx_flags |= E1000_TX_FLAGS_CSUM;
  3614. /*
  3615. * Old method was to assume IPv4 packet by default if TSO was enabled.
  3616. * 82571 hardware supports TSO capabilities for IPv6 as well...
  3617. * no longer assume, we must.
  3618. */
  3619. if (skb->protocol == htons(ETH_P_IP))
  3620. tx_flags |= E1000_TX_FLAGS_IPV4;
  3621. /* if count is 0 then mapping error has occured */
  3622. count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
  3623. if (count) {
  3624. e1000_tx_queue(adapter, tx_flags, count);
  3625. /* Make sure there is space in the ring for the next send. */
  3626. e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
  3627. } else {
  3628. dev_kfree_skb_any(skb);
  3629. tx_ring->buffer_info[first].time_stamp = 0;
  3630. tx_ring->next_to_use = first;
  3631. }
  3632. return NETDEV_TX_OK;
  3633. }
  3634. /**
  3635. * e1000_tx_timeout - Respond to a Tx Hang
  3636. * @netdev: network interface device structure
  3637. **/
  3638. static void e1000_tx_timeout(struct net_device *netdev)
  3639. {
  3640. struct e1000_adapter *adapter = netdev_priv(netdev);
  3641. /* Do the reset outside of interrupt context */
  3642. adapter->tx_timeout_count++;
  3643. schedule_work(&adapter->reset_task);
  3644. }
  3645. static void e1000_reset_task(struct work_struct *work)
  3646. {
  3647. struct e1000_adapter *adapter;
  3648. adapter = container_of(work, struct e1000_adapter, reset_task);
  3649. e1000e_reinit_locked(adapter);
  3650. }
  3651. /**
  3652. * e1000_get_stats - Get System Network Statistics
  3653. * @netdev: network interface device structure
  3654. *
  3655. * Returns the address of the device statistics structure.
  3656. * The statistics are actually updated from the timer callback.
  3657. **/
  3658. static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
  3659. {
  3660. struct e1000_adapter *adapter = netdev_priv(netdev);
  3661. /* only return the current stats */
  3662. return &adapter->net_stats;
  3663. }
  3664. /**
  3665. * e1000_change_mtu - Change the Maximum Transfer Unit
  3666. * @netdev: network interface device structure
  3667. * @new_mtu: new value for maximum frame size
  3668. *
  3669. * Returns 0 on success, negative on failure
  3670. **/
  3671. static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
  3672. {
  3673. struct e1000_adapter *adapter = netdev_priv(netdev);
  3674. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  3675. /* Jumbo frame support */
  3676. if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
  3677. !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
  3678. e_err("Jumbo Frames not supported.\n");
  3679. return -EINVAL;
  3680. }
  3681. /* Supported frame sizes */
  3682. if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
  3683. (max_frame > adapter->max_hw_frame_size)) {
  3684. e_err("Unsupported MTU setting\n");
  3685. return -EINVAL;
  3686. }
  3687. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  3688. msleep(1);
  3689. /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
  3690. adapter->max_frame_size = max_frame;
  3691. e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  3692. netdev->mtu = new_mtu;
  3693. if (netif_running(netdev))
  3694. e1000e_down(adapter);
  3695. /*
  3696. * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  3697. * means we reserve 2 more, this pushes us to allocate from the next
  3698. * larger slab size.
  3699. * i.e. RXBUFFER_2048 --> size-4096 slab
  3700. * However with the new *_jumbo_rx* routines, jumbo receives will use
  3701. * fragmented skbs
  3702. */
  3703. if (max_frame <= 2048)
  3704. adapter->rx_buffer_len = 2048;
  3705. else
  3706. adapter->rx_buffer_len = 4096;
  3707. /* adjust allocation if LPE protects us, and we aren't using SBP */
  3708. if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
  3709. (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
  3710. adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
  3711. + ETH_FCS_LEN;
  3712. if (netif_running(netdev))
  3713. e1000e_up(adapter);
  3714. else
  3715. e1000e_reset(adapter);
  3716. clear_bit(__E1000_RESETTING, &adapter->state);
  3717. return 0;
  3718. }
  3719. static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  3720. int cmd)
  3721. {
  3722. struct e1000_adapter *adapter = netdev_priv(netdev);
  3723. struct mii_ioctl_data *data = if_mii(ifr);
  3724. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  3725. return -EOPNOTSUPP;
  3726. switch (cmd) {
  3727. case SIOCGMIIPHY:
  3728. data->phy_id = adapter->hw.phy.addr;
  3729. break;
  3730. case SIOCGMIIREG:
  3731. switch (data->reg_num & 0x1F) {
  3732. case MII_BMCR:
  3733. data->val_out = adapter->phy_regs.bmcr;
  3734. break;
  3735. case MII_BMSR:
  3736. data->val_out = adapter->phy_regs.bmsr;
  3737. break;
  3738. case MII_PHYSID1:
  3739. data->val_out = (adapter->hw.phy.id >> 16);
  3740. break;
  3741. case MII_PHYSID2:
  3742. data->val_out = (adapter->hw.phy.id & 0xFFFF);
  3743. break;
  3744. case MII_ADVERTISE:
  3745. data->val_out = adapter->phy_regs.advertise;
  3746. break;
  3747. case MII_LPA:
  3748. data->val_out = adapter->phy_regs.lpa;
  3749. break;
  3750. case MII_EXPANSION:
  3751. data->val_out = adapter->phy_regs.expansion;
  3752. break;
  3753. case MII_CTRL1000:
  3754. data->val_out = adapter->phy_regs.ctrl1000;
  3755. break;
  3756. case MII_STAT1000:
  3757. data->val_out = adapter->phy_regs.stat1000;
  3758. break;
  3759. case MII_ESTATUS:
  3760. data->val_out = adapter->phy_regs.estatus;
  3761. break;
  3762. default:
  3763. return -EIO;
  3764. }
  3765. break;
  3766. case SIOCSMIIREG:
  3767. default:
  3768. return -EOPNOTSUPP;
  3769. }
  3770. return 0;
  3771. }
  3772. static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  3773. {
  3774. switch (cmd) {
  3775. case SIOCGMIIPHY:
  3776. case SIOCGMIIREG:
  3777. case SIOCSMIIREG:
  3778. return e1000_mii_ioctl(netdev, ifr, cmd);
  3779. default:
  3780. return -EOPNOTSUPP;
  3781. }
  3782. }
  3783. static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
  3784. {
  3785. struct e1000_hw *hw = &adapter->hw;
  3786. u32 i, mac_reg;
  3787. u16 phy_reg;
  3788. int retval = 0;
  3789. /* copy MAC RARs to PHY RARs */
  3790. for (i = 0; i < adapter->hw.mac.rar_entry_count; i++) {
  3791. mac_reg = er32(RAL(i));
  3792. e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF));
  3793. e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF));
  3794. mac_reg = er32(RAH(i));
  3795. e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF));
  3796. e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0xFFFF));
  3797. }
  3798. /* copy MAC MTA to PHY MTA */
  3799. for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
  3800. mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
  3801. e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
  3802. e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
  3803. }
  3804. /* configure PHY Rx Control register */
  3805. e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
  3806. mac_reg = er32(RCTL);
  3807. if (mac_reg & E1000_RCTL_UPE)
  3808. phy_reg |= BM_RCTL_UPE;
  3809. if (mac_reg & E1000_RCTL_MPE)
  3810. phy_reg |= BM_RCTL_MPE;
  3811. phy_reg &= ~(BM_RCTL_MO_MASK);
  3812. if (mac_reg & E1000_RCTL_MO_3)
  3813. phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
  3814. << BM_RCTL_MO_SHIFT);
  3815. if (mac_reg & E1000_RCTL_BAM)
  3816. phy_reg |= BM_RCTL_BAM;
  3817. if (mac_reg & E1000_RCTL_PMCF)
  3818. phy_reg |= BM_RCTL_PMCF;
  3819. mac_reg = er32(CTRL);
  3820. if (mac_reg & E1000_CTRL_RFCE)
  3821. phy_reg |= BM_RCTL_RFCE;
  3822. e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
  3823. /* enable PHY wakeup in MAC register */
  3824. ew32(WUFC, wufc);
  3825. ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
  3826. /* configure and enable PHY wakeup in PHY registers */
  3827. e1e_wphy(&adapter->hw, BM_WUFC, wufc);
  3828. e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
  3829. /* activate PHY wakeup */
  3830. retval = hw->phy.ops.acquire_phy(hw);
  3831. if (retval) {
  3832. e_err("Could not acquire PHY\n");
  3833. return retval;
  3834. }
  3835. e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  3836. (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
  3837. retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
  3838. if (retval) {
  3839. e_err("Could not read PHY page 769\n");
  3840. goto out;
  3841. }
  3842. phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
  3843. retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
  3844. if (retval)
  3845. e_err("Could not set PHY Host Wakeup bit\n");
  3846. out:
  3847. hw->phy.ops.release_phy(hw);
  3848. return retval;
  3849. }
  3850. static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
  3851. {
  3852. struct net_device *netdev = pci_get_drvdata(pdev);
  3853. struct e1000_adapter *adapter = netdev_priv(netdev);
  3854. struct e1000_hw *hw = &adapter->hw;
  3855. u32 ctrl, ctrl_ext, rctl, status;
  3856. u32 wufc = adapter->wol;
  3857. int retval = 0;
  3858. netif_device_detach(netdev);
  3859. if (netif_running(netdev)) {
  3860. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  3861. e1000e_down(adapter);
  3862. e1000_free_irq(adapter);
  3863. }
  3864. e1000e_reset_interrupt_capability(adapter);
  3865. retval = pci_save_state(pdev);
  3866. if (retval)
  3867. return retval;
  3868. status = er32(STATUS);
  3869. if (status & E1000_STATUS_LU)
  3870. wufc &= ~E1000_WUFC_LNKC;
  3871. if (wufc) {
  3872. e1000_setup_rctl(adapter);
  3873. e1000_set_multi(netdev);
  3874. /* turn on all-multi mode if wake on multicast is enabled */
  3875. if (wufc & E1000_WUFC_MC) {
  3876. rctl = er32(RCTL);
  3877. rctl |= E1000_RCTL_MPE;
  3878. ew32(RCTL, rctl);
  3879. }
  3880. ctrl = er32(CTRL);
  3881. /* advertise wake from D3Cold */
  3882. #define E1000_CTRL_ADVD3WUC 0x00100000
  3883. /* phy power management enable */
  3884. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  3885. ctrl |= E1000_CTRL_ADVD3WUC;
  3886. if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
  3887. ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
  3888. ew32(CTRL, ctrl);
  3889. if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
  3890. adapter->hw.phy.media_type ==
  3891. e1000_media_type_internal_serdes) {
  3892. /* keep the laser running in D3 */
  3893. ctrl_ext = er32(CTRL_EXT);
  3894. ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
  3895. ew32(CTRL_EXT, ctrl_ext);
  3896. }
  3897. if (adapter->flags & FLAG_IS_ICH)
  3898. e1000e_disable_gig_wol_ich8lan(&adapter->hw);
  3899. /* Allow time for pending master requests to run */
  3900. e1000e_disable_pcie_master(&adapter->hw);
  3901. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  3902. /* enable wakeup by the PHY */
  3903. retval = e1000_init_phy_wakeup(adapter, wufc);
  3904. if (retval)
  3905. return retval;
  3906. } else {
  3907. /* enable wakeup by the MAC */
  3908. ew32(WUFC, wufc);
  3909. ew32(WUC, E1000_WUC_PME_EN);
  3910. }
  3911. } else {
  3912. ew32(WUC, 0);
  3913. ew32(WUFC, 0);
  3914. }
  3915. *enable_wake = !!wufc;
  3916. /* make sure adapter isn't asleep if manageability is enabled */
  3917. if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
  3918. (hw->mac.ops.check_mng_mode(hw)))
  3919. *enable_wake = true;
  3920. if (adapter->hw.phy.type == e1000_phy_igp_3)
  3921. e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
  3922. /*
  3923. * Release control of h/w to f/w. If f/w is AMT enabled, this
  3924. * would have already happened in close and is redundant.
  3925. */
  3926. e1000_release_hw_control(adapter);
  3927. pci_disable_device(pdev);
  3928. return 0;
  3929. }
  3930. static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
  3931. {
  3932. if (sleep && wake) {
  3933. pci_prepare_to_sleep(pdev);
  3934. return;
  3935. }
  3936. pci_wake_from_d3(pdev, wake);
  3937. pci_set_power_state(pdev, PCI_D3hot);
  3938. }
  3939. static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
  3940. bool wake)
  3941. {
  3942. struct net_device *netdev = pci_get_drvdata(pdev);
  3943. struct e1000_adapter *adapter = netdev_priv(netdev);
  3944. /*
  3945. * The pci-e switch on some quad port adapters will report a
  3946. * correctable error when the MAC transitions from D0 to D3. To
  3947. * prevent this we need to mask off the correctable errors on the
  3948. * downstream port of the pci-e switch.
  3949. */
  3950. if (adapter->flags & FLAG_IS_QUAD_PORT) {
  3951. struct pci_dev *us_dev = pdev->bus->self;
  3952. int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
  3953. u16 devctl;
  3954. pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
  3955. pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
  3956. (devctl & ~PCI_EXP_DEVCTL_CERE));
  3957. e1000_power_off(pdev, sleep, wake);
  3958. pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
  3959. } else {
  3960. e1000_power_off(pdev, sleep, wake);
  3961. }
  3962. }
  3963. static void e1000e_disable_l1aspm(struct pci_dev *pdev)
  3964. {
  3965. int pos;
  3966. u16 val;
  3967. /*
  3968. * 82573 workaround - disable L1 ASPM on mobile chipsets
  3969. *
  3970. * L1 ASPM on various mobile (ich7) chipsets do not behave properly
  3971. * resulting in lost data or garbage information on the pci-e link
  3972. * level. This could result in (false) bad EEPROM checksum errors,
  3973. * long ping times (up to 2s) or even a system freeze/hang.
  3974. *
  3975. * Unfortunately this feature saves about 1W power consumption when
  3976. * active.
  3977. */
  3978. pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  3979. pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
  3980. if (val & 0x2) {
  3981. dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
  3982. val &= ~0x2;
  3983. pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
  3984. }
  3985. }
  3986. #ifdef CONFIG_PM
  3987. static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
  3988. {
  3989. int retval;
  3990. bool wake;
  3991. retval = __e1000_shutdown(pdev, &wake);
  3992. if (!retval)
  3993. e1000_complete_shutdown(pdev, true, wake);
  3994. return retval;
  3995. }
  3996. static int e1000_resume(struct pci_dev *pdev)
  3997. {
  3998. struct net_device *netdev = pci_get_drvdata(pdev);
  3999. struct e1000_adapter *adapter = netdev_priv(netdev);
  4000. struct e1000_hw *hw = &adapter->hw;
  4001. u32 err;
  4002. pci_set_power_state(pdev, PCI_D0);
  4003. pci_restore_state(pdev);
  4004. e1000e_disable_l1aspm(pdev);
  4005. err = pci_enable_device_mem(pdev);
  4006. if (err) {
  4007. dev_err(&pdev->dev,
  4008. "Cannot enable PCI device from suspend\n");
  4009. return err;
  4010. }
  4011. pci_set_master(pdev);
  4012. pci_enable_wake(pdev, PCI_D3hot, 0);
  4013. pci_enable_wake(pdev, PCI_D3cold, 0);
  4014. e1000e_set_interrupt_capability(adapter);
  4015. if (netif_running(netdev)) {
  4016. err = e1000_request_irq(adapter);
  4017. if (err)
  4018. return err;
  4019. }
  4020. e1000e_power_up_phy(adapter);
  4021. /* report the system wakeup cause from S3/S4 */
  4022. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  4023. u16 phy_data;
  4024. e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
  4025. if (phy_data) {
  4026. e_info("PHY Wakeup cause - %s\n",
  4027. phy_data & E1000_WUS_EX ? "Unicast Packet" :
  4028. phy_data & E1000_WUS_MC ? "Multicast Packet" :
  4029. phy_data & E1000_WUS_BC ? "Broadcast Packet" :
  4030. phy_data & E1000_WUS_MAG ? "Magic Packet" :
  4031. phy_data & E1000_WUS_LNKC ? "Link Status "
  4032. " Change" : "other");
  4033. }
  4034. e1e_wphy(&adapter->hw, BM_WUS, ~0);
  4035. } else {
  4036. u32 wus = er32(WUS);
  4037. if (wus) {
  4038. e_info("MAC Wakeup cause - %s\n",
  4039. wus & E1000_WUS_EX ? "Unicast Packet" :
  4040. wus & E1000_WUS_MC ? "Multicast Packet" :
  4041. wus & E1000_WUS_BC ? "Broadcast Packet" :
  4042. wus & E1000_WUS_MAG ? "Magic Packet" :
  4043. wus & E1000_WUS_LNKC ? "Link Status Change" :
  4044. "other");
  4045. }
  4046. ew32(WUS, ~0);
  4047. }
  4048. e1000e_reset(adapter);
  4049. e1000_init_manageability(adapter);
  4050. if (netif_running(netdev))
  4051. e1000e_up(adapter);
  4052. netif_device_attach(netdev);
  4053. /*
  4054. * If the controller has AMT, do not set DRV_LOAD until the interface
  4055. * is up. For all other cases, let the f/w know that the h/w is now
  4056. * under the control of the driver.
  4057. */
  4058. if (!(adapter->flags & FLAG_HAS_AMT))
  4059. e1000_get_hw_control(adapter);
  4060. return 0;
  4061. }
  4062. #endif
  4063. static void e1000_shutdown(struct pci_dev *pdev)
  4064. {
  4065. bool wake = false;
  4066. __e1000_shutdown(pdev, &wake);
  4067. if (system_state == SYSTEM_POWER_OFF)
  4068. e1000_complete_shutdown(pdev, false, wake);
  4069. }
  4070. #ifdef CONFIG_NET_POLL_CONTROLLER
  4071. /*
  4072. * Polling 'interrupt' - used by things like netconsole to send skbs
  4073. * without having to re-enable interrupts. It's not called while
  4074. * the interrupt routine is executing.
  4075. */
  4076. static void e1000_netpoll(struct net_device *netdev)
  4077. {
  4078. struct e1000_adapter *adapter = netdev_priv(netdev);
  4079. disable_irq(adapter->pdev->irq);
  4080. e1000_intr(adapter->pdev->irq, netdev);
  4081. enable_irq(adapter->pdev->irq);
  4082. }
  4083. #endif
  4084. /**
  4085. * e1000_io_error_detected - called when PCI error is detected
  4086. * @pdev: Pointer to PCI device
  4087. * @state: The current pci connection state
  4088. *
  4089. * This function is called after a PCI bus error affecting
  4090. * this device has been detected.
  4091. */
  4092. static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
  4093. pci_channel_state_t state)
  4094. {
  4095. struct net_device *netdev = pci_get_drvdata(pdev);
  4096. struct e1000_adapter *adapter = netdev_priv(netdev);
  4097. netif_device_detach(netdev);
  4098. if (state == pci_channel_io_perm_failure)
  4099. return PCI_ERS_RESULT_DISCONNECT;
  4100. if (netif_running(netdev))
  4101. e1000e_down(adapter);
  4102. pci_disable_device(pdev);
  4103. /* Request a slot slot reset. */
  4104. return PCI_ERS_RESULT_NEED_RESET;
  4105. }
  4106. /**
  4107. * e1000_io_slot_reset - called after the pci bus has been reset.
  4108. * @pdev: Pointer to PCI device
  4109. *
  4110. * Restart the card from scratch, as if from a cold-boot. Implementation
  4111. * resembles the first-half of the e1000_resume routine.
  4112. */
  4113. static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
  4114. {
  4115. struct net_device *netdev = pci_get_drvdata(pdev);
  4116. struct e1000_adapter *adapter = netdev_priv(netdev);
  4117. struct e1000_hw *hw = &adapter->hw;
  4118. int err;
  4119. pci_ers_result_t result;
  4120. e1000e_disable_l1aspm(pdev);
  4121. err = pci_enable_device_mem(pdev);
  4122. if (err) {
  4123. dev_err(&pdev->dev,
  4124. "Cannot re-enable PCI device after reset.\n");
  4125. result = PCI_ERS_RESULT_DISCONNECT;
  4126. } else {
  4127. pci_set_master(pdev);
  4128. pci_restore_state(pdev);
  4129. pci_enable_wake(pdev, PCI_D3hot, 0);
  4130. pci_enable_wake(pdev, PCI_D3cold, 0);
  4131. e1000e_reset(adapter);
  4132. ew32(WUS, ~0);
  4133. result = PCI_ERS_RESULT_RECOVERED;
  4134. }
  4135. pci_cleanup_aer_uncorrect_error_status(pdev);
  4136. return result;
  4137. }
  4138. /**
  4139. * e1000_io_resume - called when traffic can start flowing again.
  4140. * @pdev: Pointer to PCI device
  4141. *
  4142. * This callback is called when the error recovery driver tells us that
  4143. * its OK to resume normal operation. Implementation resembles the
  4144. * second-half of the e1000_resume routine.
  4145. */
  4146. static void e1000_io_resume(struct pci_dev *pdev)
  4147. {
  4148. struct net_device *netdev = pci_get_drvdata(pdev);
  4149. struct e1000_adapter *adapter = netdev_priv(netdev);
  4150. e1000_init_manageability(adapter);
  4151. if (netif_running(netdev)) {
  4152. if (e1000e_up(adapter)) {
  4153. dev_err(&pdev->dev,
  4154. "can't bring device back up after reset\n");
  4155. return;
  4156. }
  4157. }
  4158. netif_device_attach(netdev);
  4159. /*
  4160. * If the controller has AMT, do not set DRV_LOAD until the interface
  4161. * is up. For all other cases, let the f/w know that the h/w is now
  4162. * under the control of the driver.
  4163. */
  4164. if (!(adapter->flags & FLAG_HAS_AMT))
  4165. e1000_get_hw_control(adapter);
  4166. }
  4167. static void e1000_print_device_info(struct e1000_adapter *adapter)
  4168. {
  4169. struct e1000_hw *hw = &adapter->hw;
  4170. struct net_device *netdev = adapter->netdev;
  4171. u32 pba_num;
  4172. /* print bus type/speed/width info */
  4173. e_info("(PCI Express:2.5GB/s:%s) %pM\n",
  4174. /* bus width */
  4175. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  4176. "Width x1"),
  4177. /* MAC address */
  4178. netdev->dev_addr);
  4179. e_info("Intel(R) PRO/%s Network Connection\n",
  4180. (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
  4181. e1000e_read_pba_num(hw, &pba_num);
  4182. e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
  4183. hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff));
  4184. }
  4185. static void e1000_eeprom_checks(struct e1000_adapter *adapter)
  4186. {
  4187. struct e1000_hw *hw = &adapter->hw;
  4188. int ret_val;
  4189. u16 buf = 0;
  4190. if (hw->mac.type != e1000_82573)
  4191. return;
  4192. ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
  4193. if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
  4194. /* Deep Smart Power Down (DSPD) */
  4195. dev_warn(&adapter->pdev->dev,
  4196. "Warning: detected DSPD enabled in EEPROM\n");
  4197. }
  4198. ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
  4199. if (!ret_val && (le16_to_cpu(buf) & (3 << 2))) {
  4200. /* ASPM enable */
  4201. dev_warn(&adapter->pdev->dev,
  4202. "Warning: detected ASPM enabled in EEPROM\n");
  4203. }
  4204. }
  4205. static const struct net_device_ops e1000e_netdev_ops = {
  4206. .ndo_open = e1000_open,
  4207. .ndo_stop = e1000_close,
  4208. .ndo_start_xmit = e1000_xmit_frame,
  4209. .ndo_get_stats = e1000_get_stats,
  4210. .ndo_set_multicast_list = e1000_set_multi,
  4211. .ndo_set_mac_address = e1000_set_mac,
  4212. .ndo_change_mtu = e1000_change_mtu,
  4213. .ndo_do_ioctl = e1000_ioctl,
  4214. .ndo_tx_timeout = e1000_tx_timeout,
  4215. .ndo_validate_addr = eth_validate_addr,
  4216. .ndo_vlan_rx_register = e1000_vlan_rx_register,
  4217. .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
  4218. .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
  4219. #ifdef CONFIG_NET_POLL_CONTROLLER
  4220. .ndo_poll_controller = e1000_netpoll,
  4221. #endif
  4222. };
  4223. /**
  4224. * e1000_probe - Device Initialization Routine
  4225. * @pdev: PCI device information struct
  4226. * @ent: entry in e1000_pci_tbl
  4227. *
  4228. * Returns 0 on success, negative on failure
  4229. *
  4230. * e1000_probe initializes an adapter identified by a pci_dev structure.
  4231. * The OS initialization, configuring of the adapter private structure,
  4232. * and a hardware reset occur.
  4233. **/
  4234. static int __devinit e1000_probe(struct pci_dev *pdev,
  4235. const struct pci_device_id *ent)
  4236. {
  4237. struct net_device *netdev;
  4238. struct e1000_adapter *adapter;
  4239. struct e1000_hw *hw;
  4240. const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
  4241. resource_size_t mmio_start, mmio_len;
  4242. resource_size_t flash_start, flash_len;
  4243. static int cards_found;
  4244. int i, err, pci_using_dac;
  4245. u16 eeprom_data = 0;
  4246. u16 eeprom_apme_mask = E1000_EEPROM_APME;
  4247. e1000e_disable_l1aspm(pdev);
  4248. err = pci_enable_device_mem(pdev);
  4249. if (err)
  4250. return err;
  4251. pci_using_dac = 0;
  4252. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  4253. if (!err) {
  4254. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  4255. if (!err)
  4256. pci_using_dac = 1;
  4257. } else {
  4258. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4259. if (err) {
  4260. err = pci_set_consistent_dma_mask(pdev,
  4261. DMA_BIT_MASK(32));
  4262. if (err) {
  4263. dev_err(&pdev->dev, "No usable DMA "
  4264. "configuration, aborting\n");
  4265. goto err_dma;
  4266. }
  4267. }
  4268. }
  4269. err = pci_request_selected_regions_exclusive(pdev,
  4270. pci_select_bars(pdev, IORESOURCE_MEM),
  4271. e1000e_driver_name);
  4272. if (err)
  4273. goto err_pci_reg;
  4274. /* AER (Advanced Error Reporting) hooks */
  4275. pci_enable_pcie_error_reporting(pdev);
  4276. pci_set_master(pdev);
  4277. /* PCI config space info */
  4278. err = pci_save_state(pdev);
  4279. if (err)
  4280. goto err_alloc_etherdev;
  4281. err = -ENOMEM;
  4282. netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  4283. if (!netdev)
  4284. goto err_alloc_etherdev;
  4285. SET_NETDEV_DEV(netdev, &pdev->dev);
  4286. pci_set_drvdata(pdev, netdev);
  4287. adapter = netdev_priv(netdev);
  4288. hw = &adapter->hw;
  4289. adapter->netdev = netdev;
  4290. adapter->pdev = pdev;
  4291. adapter->ei = ei;
  4292. adapter->pba = ei->pba;
  4293. adapter->flags = ei->flags;
  4294. adapter->flags2 = ei->flags2;
  4295. adapter->hw.adapter = adapter;
  4296. adapter->hw.mac.type = ei->mac;
  4297. adapter->max_hw_frame_size = ei->max_hw_frame_size;
  4298. adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
  4299. mmio_start = pci_resource_start(pdev, 0);
  4300. mmio_len = pci_resource_len(pdev, 0);
  4301. err = -EIO;
  4302. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  4303. if (!adapter->hw.hw_addr)
  4304. goto err_ioremap;
  4305. if ((adapter->flags & FLAG_HAS_FLASH) &&
  4306. (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
  4307. flash_start = pci_resource_start(pdev, 1);
  4308. flash_len = pci_resource_len(pdev, 1);
  4309. adapter->hw.flash_address = ioremap(flash_start, flash_len);
  4310. if (!adapter->hw.flash_address)
  4311. goto err_flashmap;
  4312. }
  4313. /* construct the net_device struct */
  4314. netdev->netdev_ops = &e1000e_netdev_ops;
  4315. e1000e_set_ethtool_ops(netdev);
  4316. netdev->watchdog_timeo = 5 * HZ;
  4317. netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
  4318. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  4319. netdev->mem_start = mmio_start;
  4320. netdev->mem_end = mmio_start + mmio_len;
  4321. adapter->bd_number = cards_found++;
  4322. e1000e_check_options(adapter);
  4323. /* setup adapter struct */
  4324. err = e1000_sw_init(adapter);
  4325. if (err)
  4326. goto err_sw_init;
  4327. err = -EIO;
  4328. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  4329. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  4330. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  4331. err = ei->get_variants(adapter);
  4332. if (err)
  4333. goto err_hw_init;
  4334. if ((adapter->flags & FLAG_IS_ICH) &&
  4335. (adapter->flags & FLAG_READ_ONLY_NVM))
  4336. e1000e_write_protect_nvm_ich8lan(&adapter->hw);
  4337. hw->mac.ops.get_bus_info(&adapter->hw);
  4338. adapter->hw.phy.autoneg_wait_to_complete = 0;
  4339. /* Copper options */
  4340. if (adapter->hw.phy.media_type == e1000_media_type_copper) {
  4341. adapter->hw.phy.mdix = AUTO_ALL_MODES;
  4342. adapter->hw.phy.disable_polarity_correction = 0;
  4343. adapter->hw.phy.ms_type = e1000_ms_hw_default;
  4344. }
  4345. if (e1000_check_reset_block(&adapter->hw))
  4346. e_info("PHY reset is blocked due to SOL/IDER session.\n");
  4347. netdev->features = NETIF_F_SG |
  4348. NETIF_F_HW_CSUM |
  4349. NETIF_F_HW_VLAN_TX |
  4350. NETIF_F_HW_VLAN_RX;
  4351. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
  4352. netdev->features |= NETIF_F_HW_VLAN_FILTER;
  4353. netdev->features |= NETIF_F_TSO;
  4354. netdev->features |= NETIF_F_TSO6;
  4355. netdev->vlan_features |= NETIF_F_TSO;
  4356. netdev->vlan_features |= NETIF_F_TSO6;
  4357. netdev->vlan_features |= NETIF_F_HW_CSUM;
  4358. netdev->vlan_features |= NETIF_F_SG;
  4359. if (pci_using_dac)
  4360. netdev->features |= NETIF_F_HIGHDMA;
  4361. if (e1000e_enable_mng_pass_thru(&adapter->hw))
  4362. adapter->flags |= FLAG_MNG_PT_ENABLED;
  4363. /*
  4364. * before reading the NVM, reset the controller to
  4365. * put the device in a known good starting state
  4366. */
  4367. adapter->hw.mac.ops.reset_hw(&adapter->hw);
  4368. /*
  4369. * systems with ASPM and others may see the checksum fail on the first
  4370. * attempt. Let's give it a few tries
  4371. */
  4372. for (i = 0;; i++) {
  4373. if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
  4374. break;
  4375. if (i == 2) {
  4376. e_err("The NVM Checksum Is Not Valid\n");
  4377. err = -EIO;
  4378. goto err_eeprom;
  4379. }
  4380. }
  4381. e1000_eeprom_checks(adapter);
  4382. /* copy the MAC address out of the NVM */
  4383. if (e1000e_read_mac_addr(&adapter->hw))
  4384. e_err("NVM Read Error while reading MAC address\n");
  4385. memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
  4386. memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
  4387. if (!is_valid_ether_addr(netdev->perm_addr)) {
  4388. e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
  4389. err = -EIO;
  4390. goto err_eeprom;
  4391. }
  4392. init_timer(&adapter->watchdog_timer);
  4393. adapter->watchdog_timer.function = &e1000_watchdog;
  4394. adapter->watchdog_timer.data = (unsigned long) adapter;
  4395. init_timer(&adapter->phy_info_timer);
  4396. adapter->phy_info_timer.function = &e1000_update_phy_info;
  4397. adapter->phy_info_timer.data = (unsigned long) adapter;
  4398. INIT_WORK(&adapter->reset_task, e1000_reset_task);
  4399. INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
  4400. INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
  4401. INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
  4402. /* Initialize link parameters. User can change them with ethtool */
  4403. adapter->hw.mac.autoneg = 1;
  4404. adapter->fc_autoneg = 1;
  4405. adapter->hw.fc.requested_mode = e1000_fc_default;
  4406. adapter->hw.fc.current_mode = e1000_fc_default;
  4407. adapter->hw.phy.autoneg_advertised = 0x2f;
  4408. /* ring size defaults */
  4409. adapter->rx_ring->count = 256;
  4410. adapter->tx_ring->count = 256;
  4411. /*
  4412. * Initial Wake on LAN setting - If APM wake is enabled in
  4413. * the EEPROM, enable the ACPI Magic Packet filter
  4414. */
  4415. if (adapter->flags & FLAG_APME_IN_WUC) {
  4416. /* APME bit in EEPROM is mapped to WUC.APME */
  4417. eeprom_data = er32(WUC);
  4418. eeprom_apme_mask = E1000_WUC_APME;
  4419. if (eeprom_data & E1000_WUC_PHY_WAKE)
  4420. adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
  4421. } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
  4422. if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
  4423. (adapter->hw.bus.func == 1))
  4424. e1000_read_nvm(&adapter->hw,
  4425. NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  4426. else
  4427. e1000_read_nvm(&adapter->hw,
  4428. NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  4429. }
  4430. /* fetch WoL from EEPROM */
  4431. if (eeprom_data & eeprom_apme_mask)
  4432. adapter->eeprom_wol |= E1000_WUFC_MAG;
  4433. /*
  4434. * now that we have the eeprom settings, apply the special cases
  4435. * where the eeprom may be wrong or the board simply won't support
  4436. * wake on lan on a particular port
  4437. */
  4438. if (!(adapter->flags & FLAG_HAS_WOL))
  4439. adapter->eeprom_wol = 0;
  4440. /* initialize the wol settings based on the eeprom settings */
  4441. adapter->wol = adapter->eeprom_wol;
  4442. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  4443. /* save off EEPROM version number */
  4444. e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
  4445. /* reset the hardware with the new settings */
  4446. e1000e_reset(adapter);
  4447. /*
  4448. * If the controller has AMT, do not set DRV_LOAD until the interface
  4449. * is up. For all other cases, let the f/w know that the h/w is now
  4450. * under the control of the driver.
  4451. */
  4452. if (!(adapter->flags & FLAG_HAS_AMT))
  4453. e1000_get_hw_control(adapter);
  4454. strcpy(netdev->name, "eth%d");
  4455. err = register_netdev(netdev);
  4456. if (err)
  4457. goto err_register;
  4458. /* carrier off reporting is important to ethtool even BEFORE open */
  4459. netif_carrier_off(netdev);
  4460. e1000_print_device_info(adapter);
  4461. return 0;
  4462. err_register:
  4463. if (!(adapter->flags & FLAG_HAS_AMT))
  4464. e1000_release_hw_control(adapter);
  4465. err_eeprom:
  4466. if (!e1000_check_reset_block(&adapter->hw))
  4467. e1000_phy_hw_reset(&adapter->hw);
  4468. err_hw_init:
  4469. kfree(adapter->tx_ring);
  4470. kfree(adapter->rx_ring);
  4471. err_sw_init:
  4472. if (adapter->hw.flash_address)
  4473. iounmap(adapter->hw.flash_address);
  4474. e1000e_reset_interrupt_capability(adapter);
  4475. err_flashmap:
  4476. iounmap(adapter->hw.hw_addr);
  4477. err_ioremap:
  4478. free_netdev(netdev);
  4479. err_alloc_etherdev:
  4480. pci_release_selected_regions(pdev,
  4481. pci_select_bars(pdev, IORESOURCE_MEM));
  4482. err_pci_reg:
  4483. err_dma:
  4484. pci_disable_device(pdev);
  4485. return err;
  4486. }
  4487. /**
  4488. * e1000_remove - Device Removal Routine
  4489. * @pdev: PCI device information struct
  4490. *
  4491. * e1000_remove is called by the PCI subsystem to alert the driver
  4492. * that it should release a PCI device. The could be caused by a
  4493. * Hot-Plug event, or because the driver is going to be removed from
  4494. * memory.
  4495. **/
  4496. static void __devexit e1000_remove(struct pci_dev *pdev)
  4497. {
  4498. struct net_device *netdev = pci_get_drvdata(pdev);
  4499. struct e1000_adapter *adapter = netdev_priv(netdev);
  4500. /*
  4501. * flush_scheduled work may reschedule our watchdog task, so
  4502. * explicitly disable watchdog tasks from being rescheduled
  4503. */
  4504. set_bit(__E1000_DOWN, &adapter->state);
  4505. del_timer_sync(&adapter->watchdog_timer);
  4506. del_timer_sync(&adapter->phy_info_timer);
  4507. flush_scheduled_work();
  4508. /*
  4509. * Release control of h/w to f/w. If f/w is AMT enabled, this
  4510. * would have already happened in close and is redundant.
  4511. */
  4512. e1000_release_hw_control(adapter);
  4513. unregister_netdev(netdev);
  4514. if (!e1000_check_reset_block(&adapter->hw))
  4515. e1000_phy_hw_reset(&adapter->hw);
  4516. e1000e_reset_interrupt_capability(adapter);
  4517. kfree(adapter->tx_ring);
  4518. kfree(adapter->rx_ring);
  4519. iounmap(adapter->hw.hw_addr);
  4520. if (adapter->hw.flash_address)
  4521. iounmap(adapter->hw.flash_address);
  4522. pci_release_selected_regions(pdev,
  4523. pci_select_bars(pdev, IORESOURCE_MEM));
  4524. free_netdev(netdev);
  4525. /* AER disable */
  4526. pci_disable_pcie_error_reporting(pdev);
  4527. pci_disable_device(pdev);
  4528. }
  4529. /* PCI Error Recovery (ERS) */
  4530. static struct pci_error_handlers e1000_err_handler = {
  4531. .error_detected = e1000_io_error_detected,
  4532. .slot_reset = e1000_io_slot_reset,
  4533. .resume = e1000_io_resume,
  4534. };
  4535. static struct pci_device_id e1000_pci_tbl[] = {
  4536. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
  4537. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
  4538. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
  4539. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
  4540. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
  4541. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
  4542. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
  4543. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
  4544. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
  4545. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
  4546. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
  4547. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
  4548. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
  4549. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
  4550. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
  4551. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
  4552. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
  4553. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
  4554. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
  4555. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
  4556. board_80003es2lan },
  4557. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
  4558. board_80003es2lan },
  4559. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
  4560. board_80003es2lan },
  4561. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
  4562. board_80003es2lan },
  4563. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
  4564. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
  4565. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
  4566. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
  4567. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
  4568. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
  4569. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
  4570. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
  4571. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
  4572. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
  4573. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
  4574. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
  4575. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
  4576. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
  4577. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
  4578. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
  4579. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
  4580. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
  4581. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
  4582. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
  4583. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
  4584. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
  4585. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
  4586. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
  4587. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
  4588. { } /* terminate list */
  4589. };
  4590. MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  4591. /* PCI Device API Driver */
  4592. static struct pci_driver e1000_driver = {
  4593. .name = e1000e_driver_name,
  4594. .id_table = e1000_pci_tbl,
  4595. .probe = e1000_probe,
  4596. .remove = __devexit_p(e1000_remove),
  4597. #ifdef CONFIG_PM
  4598. /* Power Management Hooks */
  4599. .suspend = e1000_suspend,
  4600. .resume = e1000_resume,
  4601. #endif
  4602. .shutdown = e1000_shutdown,
  4603. .err_handler = &e1000_err_handler
  4604. };
  4605. /**
  4606. * e1000_init_module - Driver Registration Routine
  4607. *
  4608. * e1000_init_module is the first routine called when the driver is
  4609. * loaded. All it does is register with the PCI subsystem.
  4610. **/
  4611. static int __init e1000_init_module(void)
  4612. {
  4613. int ret;
  4614. printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
  4615. e1000e_driver_name, e1000e_driver_version);
  4616. printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n",
  4617. e1000e_driver_name);
  4618. ret = pci_register_driver(&e1000_driver);
  4619. pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name,
  4620. PM_QOS_DEFAULT_VALUE);
  4621. return ret;
  4622. }
  4623. module_init(e1000_init_module);
  4624. /**
  4625. * e1000_exit_module - Driver Exit Cleanup Routine
  4626. *
  4627. * e1000_exit_module is called just before the driver is removed
  4628. * from memory.
  4629. **/
  4630. static void __exit e1000_exit_module(void)
  4631. {
  4632. pci_unregister_driver(&e1000_driver);
  4633. pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name);
  4634. }
  4635. module_exit(e1000_exit_module);
  4636. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  4637. MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  4638. MODULE_LICENSE("GPL");
  4639. MODULE_VERSION(DRV_VERSION);
  4640. /* e1000_main.c */