PageRenderTime 102ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/e1000e/netdev.c

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