Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * tg3.c: Broadcom Tigon3 ethernet driver. |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com) |
| 5 | * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com) |
| 6 | * Copyright (C) 2004 Sun Microsystems Inc. |
Matt Carlson | 9e056c0 | 2012-02-13 15:20:17 +0000 | [diff] [blame] | 7 | * Copyright (C) 2005-2012 Broadcom Corporation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Firmware is: |
Michael Chan | 49cabf4 | 2005-06-06 15:15:17 -0700 | [diff] [blame] | 10 | * Derived from proprietary unpublished source code, |
| 11 | * Copyright (C) 2000-2003 Broadcom Corporation. |
| 12 | * |
| 13 | * Permission is hereby granted for the distribution of this firmware |
| 14 | * data in hexadecimal or equivalent format, provided this copyright |
| 15 | * notice is accompanying it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/moduleparam.h> |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 21 | #include <linux/stringify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/compiler.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/delay.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 27 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/ioport.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/etherdevice.h> |
| 34 | #include <linux/skbuff.h> |
| 35 | #include <linux/ethtool.h> |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 36 | #include <linux/mdio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/mii.h> |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 38 | #include <linux/phy.h> |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 39 | #include <linux/brcmphy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/if_vlan.h> |
| 41 | #include <linux/ip.h> |
| 42 | #include <linux/tcp.h> |
| 43 | #include <linux/workqueue.h> |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 44 | #include <linux/prefetch.h> |
Tobias Klauser | f9a5f7d | 2005-10-29 15:09:26 +0200 | [diff] [blame] | 45 | #include <linux/dma-mapping.h> |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 46 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 49 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 51 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/byteorder.h> |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 53 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 55 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 57 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #endif |
| 59 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 60 | #define BAR_0 0 |
| 61 | #define BAR_2 2 |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include "tg3.h" |
| 64 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 65 | /* Functions & macros to verify TG3_FLAGS types */ |
| 66 | |
| 67 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) |
| 68 | { |
| 69 | return test_bit(flag, bits); |
| 70 | } |
| 71 | |
| 72 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) |
| 73 | { |
| 74 | set_bit(flag, bits); |
| 75 | } |
| 76 | |
| 77 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) |
| 78 | { |
| 79 | clear_bit(flag, bits); |
| 80 | } |
| 81 | |
| 82 | #define tg3_flag(tp, flag) \ |
| 83 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 84 | #define tg3_flag_set(tp, flag) \ |
| 85 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 86 | #define tg3_flag_clear(tp, flag) \ |
| 87 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 90 | #define TG3_MAJ_NUM 3 |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 91 | #define TG3_MIN_NUM 123 |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 92 | #define DRV_MODULE_VERSION \ |
| 93 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 94 | #define DRV_MODULE_RELDATE "March 21, 2012" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 96 | #define RESET_KIND_SHUTDOWN 0 |
| 97 | #define RESET_KIND_INIT 1 |
| 98 | #define RESET_KIND_SUSPEND 2 |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #define TG3_DEF_RX_MODE 0 |
| 101 | #define TG3_DEF_TX_MODE 0 |
| 102 | #define TG3_DEF_MSG_ENABLE \ |
| 103 | (NETIF_MSG_DRV | \ |
| 104 | NETIF_MSG_PROBE | \ |
| 105 | NETIF_MSG_LINK | \ |
| 106 | NETIF_MSG_TIMER | \ |
| 107 | NETIF_MSG_IFDOWN | \ |
| 108 | NETIF_MSG_IFUP | \ |
| 109 | NETIF_MSG_RX_ERR | \ |
| 110 | NETIF_MSG_TX_ERR) |
| 111 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 112 | #define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* length of time before we decide the hardware is borked, |
| 115 | * and dev->tx_timeout() should be called to fix the problem |
| 116 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 119 | |
| 120 | /* hardware minimum and maximum for a single frame's data payload */ |
| 121 | #define TG3_MIN_MTU 60 |
| 122 | #define TG3_MAX_MTU(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 123 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 126 | * You can't change the ring sizes, but you can change where you place |
| 127 | * them in the NIC onboard memory. |
| 128 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 129 | #define TG3_RX_STD_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 130 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 131 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 133 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 134 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 135 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
| 137 | |
| 138 | /* Do not place this n-ring entries value into the tp struct itself, |
| 139 | * we really want to expose these constants to GCC so that modulo et |
| 140 | * al. operations are done with shifts and masks instead of with |
| 141 | * hw multiply/modulo instructions. Another solution would be to |
| 142 | * replace things like '% foo' with '& (foo - 1)'. |
| 143 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | #define TG3_TX_RING_SIZE 512 |
| 146 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 147 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 148 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 149 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 150 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 151 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 152 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 153 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 155 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 157 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 158 | #define TG3_DMA_BYTE_ENAB 64 |
| 159 | |
| 160 | #define TG3_RX_STD_DMA_SZ 1536 |
| 161 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 162 | |
| 163 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 164 | |
| 165 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 166 | #define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 168 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 169 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 170 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 171 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 172 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 173 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 174 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 175 | * that are at least dword aligned when used in PCIX mode. The driver |
| 176 | * works around this bug by double copying the packet. This workaround |
| 177 | * is built into the normal double copy length check for efficiency. |
| 178 | * |
| 179 | * However, the double copy is only necessary on those architectures |
| 180 | * where unaligned memory accesses are inefficient. For those architectures |
| 181 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 182 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 183 | * dereference by hardcoding the double copy threshold in place. |
| 184 | */ |
| 185 | #define TG3_RX_COPY_THRESHOLD 256 |
| 186 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 187 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 188 | #else |
| 189 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 190 | #endif |
| 191 | |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 192 | #if (NET_IP_ALIGN != 0) |
| 193 | #define TG3_RX_OFFSET(tp) ((tp)->rx_offset) |
| 194 | #else |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 195 | #define TG3_RX_OFFSET(tp) (NET_SKB_PAD) |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 196 | #endif |
| 197 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 198 | /* This driver uses the new build_skb() API providing a frag as skb->head |
| 199 | * This strategy permits better GRO aggregation, better TCP coalescing, and |
| 200 | * better splice() implementation (avoids a copy from head to a page), at |
| 201 | * minimal memory cost. |
| 202 | * In this 2048 bytes block, we have enough room to store the MTU=1500 frame |
| 203 | * and the struct skb_shared_info. |
| 204 | */ |
| 205 | #define TG3_FRAGSIZE 2048 |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 208 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 209 | #define TG3_TX_BD_DMA_MAX_2K 2048 |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 210 | #define TG3_TX_BD_DMA_MAX_4K 4096 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 212 | #define TG3_RAW_IP_ALIGN 2 |
| 213 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 214 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 215 | #define TG3_FW_UPDATE_FREQ_SEC (TG3_FW_UPDATE_TIMEOUT_SEC / 2) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 216 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 217 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 218 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 219 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | static char version[] __devinitdata = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 222 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 225 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 226 | MODULE_LICENSE("GPL"); |
| 227 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 228 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 229 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 230 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 233 | module_param(tg3_debug, int, 0); |
| 234 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 235 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 236 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
| 255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, |
| 256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, |
| 257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
| 258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
| 263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, |
| 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
| 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, |
| 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
| 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 278 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 283 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 286 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 287 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 288 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 289 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 290 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 291 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 292 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 293 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 294 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 295 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 296 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 297 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
| 298 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 299 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 300 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
| 301 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 302 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 303 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 304 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 305 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
| 306 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, |
| 307 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 308 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Matt Carlson | ba1f3c7 | 2011-04-05 14:22:50 +0000 | [diff] [blame] | 309 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 310 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 311 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 312 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 313 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 314 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 315 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 316 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
Meelis Roos | 1dcb14d | 2011-05-25 05:43:47 +0000 | [diff] [blame] | 317 | {PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 318 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 322 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 323 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 325 | } ethtool_stats_keys[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { "rx_octets" }, |
| 327 | { "rx_fragments" }, |
| 328 | { "rx_ucast_packets" }, |
| 329 | { "rx_mcast_packets" }, |
| 330 | { "rx_bcast_packets" }, |
| 331 | { "rx_fcs_errors" }, |
| 332 | { "rx_align_errors" }, |
| 333 | { "rx_xon_pause_rcvd" }, |
| 334 | { "rx_xoff_pause_rcvd" }, |
| 335 | { "rx_mac_ctrl_rcvd" }, |
| 336 | { "rx_xoff_entered" }, |
| 337 | { "rx_frame_too_long_errors" }, |
| 338 | { "rx_jabbers" }, |
| 339 | { "rx_undersize_packets" }, |
| 340 | { "rx_in_length_errors" }, |
| 341 | { "rx_out_length_errors" }, |
| 342 | { "rx_64_or_less_octet_packets" }, |
| 343 | { "rx_65_to_127_octet_packets" }, |
| 344 | { "rx_128_to_255_octet_packets" }, |
| 345 | { "rx_256_to_511_octet_packets" }, |
| 346 | { "rx_512_to_1023_octet_packets" }, |
| 347 | { "rx_1024_to_1522_octet_packets" }, |
| 348 | { "rx_1523_to_2047_octet_packets" }, |
| 349 | { "rx_2048_to_4095_octet_packets" }, |
| 350 | { "rx_4096_to_8191_octet_packets" }, |
| 351 | { "rx_8192_to_9022_octet_packets" }, |
| 352 | |
| 353 | { "tx_octets" }, |
| 354 | { "tx_collisions" }, |
| 355 | |
| 356 | { "tx_xon_sent" }, |
| 357 | { "tx_xoff_sent" }, |
| 358 | { "tx_flow_control" }, |
| 359 | { "tx_mac_errors" }, |
| 360 | { "tx_single_collisions" }, |
| 361 | { "tx_mult_collisions" }, |
| 362 | { "tx_deferred" }, |
| 363 | { "tx_excessive_collisions" }, |
| 364 | { "tx_late_collisions" }, |
| 365 | { "tx_collide_2times" }, |
| 366 | { "tx_collide_3times" }, |
| 367 | { "tx_collide_4times" }, |
| 368 | { "tx_collide_5times" }, |
| 369 | { "tx_collide_6times" }, |
| 370 | { "tx_collide_7times" }, |
| 371 | { "tx_collide_8times" }, |
| 372 | { "tx_collide_9times" }, |
| 373 | { "tx_collide_10times" }, |
| 374 | { "tx_collide_11times" }, |
| 375 | { "tx_collide_12times" }, |
| 376 | { "tx_collide_13times" }, |
| 377 | { "tx_collide_14times" }, |
| 378 | { "tx_collide_15times" }, |
| 379 | { "tx_ucast_packets" }, |
| 380 | { "tx_mcast_packets" }, |
| 381 | { "tx_bcast_packets" }, |
| 382 | { "tx_carrier_sense_errors" }, |
| 383 | { "tx_discards" }, |
| 384 | { "tx_errors" }, |
| 385 | |
| 386 | { "dma_writeq_full" }, |
| 387 | { "dma_write_prioq_full" }, |
| 388 | { "rxbds_empty" }, |
| 389 | { "rx_discards" }, |
| 390 | { "rx_errors" }, |
| 391 | { "rx_threshold_hit" }, |
| 392 | |
| 393 | { "dma_readq_full" }, |
| 394 | { "dma_read_prioq_full" }, |
| 395 | { "tx_comp_queue_full" }, |
| 396 | |
| 397 | { "ring_set_send_prod_index" }, |
| 398 | { "ring_status_update" }, |
| 399 | { "nic_irqs" }, |
| 400 | { "nic_avoided_irqs" }, |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 401 | { "nic_tx_threshold_hit" }, |
| 402 | |
| 403 | { "mbuf_lwm_thresh_hit" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | }; |
| 405 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 406 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
| 407 | |
| 408 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 409 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 410 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 411 | } ethtool_test_keys[] = { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 412 | { "nvram test (online) " }, |
| 413 | { "link test (online) " }, |
| 414 | { "register test (offline)" }, |
| 415 | { "memory test (offline)" }, |
| 416 | { "mac loopback test (offline)" }, |
| 417 | { "phy loopback test (offline)" }, |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 418 | { "ext loopback test (offline)" }, |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 419 | { "interrupt test (offline)" }, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 420 | }; |
| 421 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 422 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
| 423 | |
| 424 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 425 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 426 | { |
| 427 | writel(val, tp->regs + off); |
| 428 | } |
| 429 | |
| 430 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 431 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 432 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 435 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 436 | { |
| 437 | writel(val, tp->aperegs + off); |
| 438 | } |
| 439 | |
| 440 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 441 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 442 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 446 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 447 | unsigned long flags; |
| 448 | |
| 449 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 450 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 451 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 452 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 456 | { |
| 457 | writel(val, tp->regs + off); |
| 458 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 461 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 462 | { |
| 463 | unsigned long flags; |
| 464 | u32 val; |
| 465 | |
| 466 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 467 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 468 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 469 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 470 | return val; |
| 471 | } |
| 472 | |
| 473 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 474 | { |
| 475 | unsigned long flags; |
| 476 | |
| 477 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 478 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 479 | TG3_64BIT_REG_LOW, val); |
| 480 | return; |
| 481 | } |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 482 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 483 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 484 | TG3_64BIT_REG_LOW, val); |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 489 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 490 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 491 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 492 | |
| 493 | /* In indirect mode when disabling interrupts, we also need |
| 494 | * to clear the interrupt bit in the GRC local ctrl register. |
| 495 | */ |
| 496 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 497 | (val == 0x1)) { |
| 498 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 499 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 504 | { |
| 505 | unsigned long flags; |
| 506 | u32 val; |
| 507 | |
| 508 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 509 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 510 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 511 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 512 | return val; |
| 513 | } |
| 514 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 515 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 516 | * where it is unsafe to read back the register without some delay. |
| 517 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 518 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 519 | */ |
| 520 | static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 522 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 523 | /* Non-posted methods */ |
| 524 | tp->write32(tp, off, val); |
| 525 | else { |
| 526 | /* Posted method */ |
| 527 | tg3_write32(tp, off, val); |
| 528 | if (usec_wait) |
| 529 | udelay(usec_wait); |
| 530 | tp->read32(tp, off); |
| 531 | } |
| 532 | /* Wait again after the read for the posted method to guarantee that |
| 533 | * the wait time is met. |
| 534 | */ |
| 535 | if (usec_wait) |
| 536 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 539 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 540 | { |
| 541 | tp->write32_mbox(tp, off, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 542 | if (!tg3_flag(tp, MBOX_WRITE_REORDER) && !tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 543 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 546 | static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
| 548 | void __iomem *mbox = tp->regs + off; |
| 549 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 550 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 552 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | readl(mbox); |
| 554 | } |
| 555 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 556 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 557 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 558 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 562 | { |
| 563 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 564 | } |
| 565 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 566 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 567 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 568 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 569 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 570 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 571 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 572 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 573 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 574 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 575 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 578 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 579 | unsigned long flags; |
| 580 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 581 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 582 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 583 | return; |
| 584 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 585 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 586 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 587 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 588 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 590 | /* Always leave this as zero. */ |
| 591 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 592 | } else { |
| 593 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 594 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 595 | |
| 596 | /* Always leave this as zero. */ |
| 597 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 598 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 599 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 603 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 604 | unsigned long flags; |
| 605 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 606 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 607 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 608 | *val = 0; |
| 609 | return; |
| 610 | } |
| 611 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 612 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 613 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 614 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 615 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 617 | /* Always leave this as zero. */ |
| 618 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 619 | } else { |
| 620 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 621 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 622 | |
| 623 | /* Always leave this as zero. */ |
| 624 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 625 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 626 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 629 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 630 | { |
| 631 | int i; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 632 | u32 regbase, bit; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 633 | |
| 634 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 635 | regbase = TG3_APE_LOCK_GRANT; |
| 636 | else |
| 637 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 638 | |
| 639 | /* Make sure the driver hasn't any stale locks. */ |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 640 | for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) { |
| 641 | switch (i) { |
| 642 | case TG3_APE_LOCK_PHY0: |
| 643 | case TG3_APE_LOCK_PHY1: |
| 644 | case TG3_APE_LOCK_PHY2: |
| 645 | case TG3_APE_LOCK_PHY3: |
| 646 | bit = APE_LOCK_GRANT_DRIVER; |
| 647 | break; |
| 648 | default: |
| 649 | if (!tp->pci_fn) |
| 650 | bit = APE_LOCK_GRANT_DRIVER; |
| 651 | else |
| 652 | bit = 1 << tp->pci_fn; |
| 653 | } |
| 654 | tg3_ape_write32(tp, regbase + 4 * i, bit); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 660 | { |
| 661 | int i, off; |
| 662 | int ret = 0; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 663 | u32 status, req, gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 664 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 665 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 666 | return 0; |
| 667 | |
| 668 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 669 | case TG3_APE_LOCK_GPIO: |
| 670 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 671 | return 0; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 672 | case TG3_APE_LOCK_GRC: |
| 673 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 674 | if (!tp->pci_fn) |
| 675 | bit = APE_LOCK_REQ_DRIVER; |
| 676 | else |
| 677 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 678 | break; |
| 679 | default: |
| 680 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 683 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
| 684 | req = TG3_APE_LOCK_REQ; |
| 685 | gnt = TG3_APE_LOCK_GRANT; |
| 686 | } else { |
| 687 | req = TG3_APE_PER_LOCK_REQ; |
| 688 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 689 | } |
| 690 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 691 | off = 4 * locknum; |
| 692 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 693 | tg3_ape_write32(tp, req + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 694 | |
| 695 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 696 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 697 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 698 | if (status == bit) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 699 | break; |
| 700 | udelay(10); |
| 701 | } |
| 702 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 703 | if (status != bit) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 704 | /* Revoke the lock request. */ |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 705 | tg3_ape_write32(tp, gnt + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 706 | ret = -EBUSY; |
| 707 | } |
| 708 | |
| 709 | return ret; |
| 710 | } |
| 711 | |
| 712 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 713 | { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 714 | u32 gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 715 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 716 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 717 | return; |
| 718 | |
| 719 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 720 | case TG3_APE_LOCK_GPIO: |
| 721 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 722 | return; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 723 | case TG3_APE_LOCK_GRC: |
| 724 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 725 | if (!tp->pci_fn) |
| 726 | bit = APE_LOCK_GRANT_DRIVER; |
| 727 | else |
| 728 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 729 | break; |
| 730 | default: |
| 731 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 734 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 735 | gnt = TG3_APE_LOCK_GRANT; |
| 736 | else |
| 737 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 738 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 739 | tg3_ape_write32(tp, gnt + 4 * locknum, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 742 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 743 | { |
| 744 | int i; |
| 745 | u32 apedata; |
| 746 | |
| 747 | /* NCSI does not support APE events */ |
| 748 | if (tg3_flag(tp, APE_HAS_NCSI)) |
| 749 | return; |
| 750 | |
| 751 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 752 | if (apedata != APE_SEG_SIG_MAGIC) |
| 753 | return; |
| 754 | |
| 755 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 756 | if (!(apedata & APE_FW_STATUS_READY)) |
| 757 | return; |
| 758 | |
| 759 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 760 | for (i = 0; i < 10; i++) { |
| 761 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
| 762 | return; |
| 763 | |
| 764 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 765 | |
| 766 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 767 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 768 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 769 | |
| 770 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 771 | |
| 772 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 773 | break; |
| 774 | |
| 775 | udelay(100); |
| 776 | } |
| 777 | |
| 778 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 779 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 780 | } |
| 781 | |
| 782 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 783 | { |
| 784 | u32 event; |
| 785 | u32 apedata; |
| 786 | |
| 787 | if (!tg3_flag(tp, ENABLE_APE)) |
| 788 | return; |
| 789 | |
| 790 | switch (kind) { |
| 791 | case RESET_KIND_INIT: |
| 792 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 793 | APE_HOST_SEG_SIG_MAGIC); |
| 794 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 795 | APE_HOST_SEG_LEN_MAGIC); |
| 796 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 797 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 798 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
| 799 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
| 800 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 801 | APE_HOST_BEHAV_NO_PHYLOCK); |
| 802 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 803 | TG3_APE_HOST_DRVR_STATE_START); |
| 804 | |
| 805 | event = APE_EVENT_STATUS_STATE_START; |
| 806 | break; |
| 807 | case RESET_KIND_SHUTDOWN: |
| 808 | /* With the interface we are currently using, |
| 809 | * APE does not track driver state. Wiping |
| 810 | * out the HOST SEGMENT SIGNATURE forces |
| 811 | * the APE to assume OS absent status. |
| 812 | */ |
| 813 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
| 814 | |
| 815 | if (device_may_wakeup(&tp->pdev->dev) && |
| 816 | tg3_flag(tp, WOL_ENABLE)) { |
| 817 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 818 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 819 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 820 | } else |
| 821 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 822 | |
| 823 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 824 | |
| 825 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 826 | break; |
| 827 | case RESET_KIND_SUSPEND: |
| 828 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 829 | break; |
| 830 | default: |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 835 | |
| 836 | tg3_ape_send_event(tp, event); |
| 837 | } |
| 838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | static void tg3_disable_ints(struct tg3 *tp) |
| 840 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 841 | int i; |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 844 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 845 | for (i = 0; i < tp->irq_max; i++) |
| 846 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | static void tg3_enable_ints(struct tg3 *tp) |
| 850 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 851 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 852 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 853 | tp->irq_sync = 0; |
| 854 | wmb(); |
| 855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 857 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 858 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 859 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 860 | for (i = 0; i < tp->irq_cnt; i++) { |
| 861 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 862 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 863 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 864 | if (tg3_flag(tp, 1SHOT_MSI)) |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 865 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 866 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 867 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 868 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 869 | |
| 870 | /* Force an initial interrupt */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 871 | if (!tg3_flag(tp, TAGGED_STATUS) && |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 872 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 873 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 874 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 875 | tw32(HOSTCC_MODE, tp->coal_now); |
| 876 | |
| 877 | tp->coal_now &= ~(tp->napi[0].coal_now | tp->napi[1].coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 880 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 881 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 882 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 883 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 884 | unsigned int work_exists = 0; |
| 885 | |
| 886 | /* check for phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 887 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 888 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 889 | work_exists = 1; |
| 890 | } |
| 891 | /* check for RX/TX work to do */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 892 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 893 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 894 | work_exists = 1; |
| 895 | |
| 896 | return work_exists; |
| 897 | } |
| 898 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 899 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 900 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 901 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 902 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 904 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 906 | struct tg3 *tp = tnapi->tp; |
| 907 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 908 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | mmiowb(); |
| 910 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 911 | /* When doing tagged status, this work check is unnecessary. |
| 912 | * The last_tag we write above tells the chip which piece of |
| 913 | * work we've completed. |
| 914 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 915 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 916 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 917 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | static void tg3_switch_clocks(struct tg3 *tp) |
| 921 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 922 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | u32 orig_clock_ctrl; |
| 924 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 925 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 926 | return; |
| 927 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 928 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | orig_clock_ctrl = clock_ctrl; |
| 931 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 932 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 933 | 0x1f); |
| 934 | tp->pci_clock_ctrl = clock_ctrl; |
| 935 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 936 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 938 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 939 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
| 941 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 942 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 943 | clock_ctrl | |
| 944 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 945 | 40); |
| 946 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 947 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 948 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 950 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | #define PHY_BUSY_LOOPS 5000 |
| 954 | |
| 955 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 956 | { |
| 957 | u32 frame_val; |
| 958 | unsigned int loops; |
| 959 | int ret; |
| 960 | |
| 961 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 962 | tw32_f(MAC_MI_MODE, |
| 963 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 964 | udelay(80); |
| 965 | } |
| 966 | |
| 967 | *val = 0x0; |
| 968 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 969 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | MI_COM_PHY_ADDR_MASK); |
| 971 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 972 | MI_COM_REG_ADDR_MASK); |
| 973 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | tw32_f(MAC_MI_COM, frame_val); |
| 976 | |
| 977 | loops = PHY_BUSY_LOOPS; |
| 978 | while (loops != 0) { |
| 979 | udelay(10); |
| 980 | frame_val = tr32(MAC_MI_COM); |
| 981 | |
| 982 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 983 | udelay(5); |
| 984 | frame_val = tr32(MAC_MI_COM); |
| 985 | break; |
| 986 | } |
| 987 | loops -= 1; |
| 988 | } |
| 989 | |
| 990 | ret = -EBUSY; |
| 991 | if (loops != 0) { |
| 992 | *val = frame_val & MI_COM_DATA_MASK; |
| 993 | ret = 0; |
| 994 | } |
| 995 | |
| 996 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 997 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 998 | udelay(80); |
| 999 | } |
| 1000 | |
| 1001 | return ret; |
| 1002 | } |
| 1003 | |
| 1004 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 1005 | { |
| 1006 | u32 frame_val; |
| 1007 | unsigned int loops; |
| 1008 | int ret; |
| 1009 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1010 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 1011 | (reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 1012 | return 0; |
| 1013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1015 | tw32_f(MAC_MI_MODE, |
| 1016 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1017 | udelay(80); |
| 1018 | } |
| 1019 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1020 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | MI_COM_PHY_ADDR_MASK); |
| 1022 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1023 | MI_COM_REG_ADDR_MASK); |
| 1024 | frame_val |= (val & MI_COM_DATA_MASK); |
| 1025 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | tw32_f(MAC_MI_COM, frame_val); |
| 1028 | |
| 1029 | loops = PHY_BUSY_LOOPS; |
| 1030 | while (loops != 0) { |
| 1031 | udelay(10); |
| 1032 | frame_val = tr32(MAC_MI_COM); |
| 1033 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1034 | udelay(5); |
| 1035 | frame_val = tr32(MAC_MI_COM); |
| 1036 | break; |
| 1037 | } |
| 1038 | loops -= 1; |
| 1039 | } |
| 1040 | |
| 1041 | ret = -EBUSY; |
| 1042 | if (loops != 0) |
| 1043 | ret = 0; |
| 1044 | |
| 1045 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1046 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1047 | udelay(80); |
| 1048 | } |
| 1049 | |
| 1050 | return ret; |
| 1051 | } |
| 1052 | |
Matt Carlson | b0988c1 | 2011-04-20 07:57:39 +0000 | [diff] [blame] | 1053 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1054 | { |
| 1055 | int err; |
| 1056 | |
| 1057 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1058 | if (err) |
| 1059 | goto done; |
| 1060 | |
| 1061 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1062 | if (err) |
| 1063 | goto done; |
| 1064 | |
| 1065 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1066 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1067 | if (err) |
| 1068 | goto done; |
| 1069 | |
| 1070 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1071 | |
| 1072 | done: |
| 1073 | return err; |
| 1074 | } |
| 1075 | |
| 1076 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1077 | { |
| 1078 | int err; |
| 1079 | |
| 1080 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1081 | if (err) |
| 1082 | goto done; |
| 1083 | |
| 1084 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1085 | if (err) |
| 1086 | goto done; |
| 1087 | |
| 1088 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1089 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1090 | if (err) |
| 1091 | goto done; |
| 1092 | |
| 1093 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1094 | |
| 1095 | done: |
| 1096 | return err; |
| 1097 | } |
| 1098 | |
| 1099 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1100 | { |
| 1101 | int err; |
| 1102 | |
| 1103 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1104 | if (!err) |
| 1105 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1106 | |
| 1107 | return err; |
| 1108 | } |
| 1109 | |
| 1110 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 1111 | { |
| 1112 | int err; |
| 1113 | |
| 1114 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1115 | if (!err) |
| 1116 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1117 | |
| 1118 | return err; |
| 1119 | } |
| 1120 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1121 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
| 1122 | { |
| 1123 | int err; |
| 1124 | |
| 1125 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1126 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | |
| 1127 | MII_TG3_AUXCTL_SHDWSEL_MISC); |
| 1128 | if (!err) |
| 1129 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); |
| 1130 | |
| 1131 | return err; |
| 1132 | } |
| 1133 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 1134 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
| 1135 | { |
| 1136 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) |
| 1137 | set |= MII_TG3_AUXCTL_MISC_WREN; |
| 1138 | |
| 1139 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); |
| 1140 | } |
| 1141 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1142 | #define TG3_PHY_AUXCTL_SMDSP_ENABLE(tp) \ |
| 1143 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1144 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | \ |
| 1145 | MII_TG3_AUXCTL_ACTL_TX_6DB) |
| 1146 | |
| 1147 | #define TG3_PHY_AUXCTL_SMDSP_DISABLE(tp) \ |
| 1148 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1149 | MII_TG3_AUXCTL_ACTL_TX_6DB); |
| 1150 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1151 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 1152 | { |
| 1153 | u32 phy_control; |
| 1154 | int limit, err; |
| 1155 | |
| 1156 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 1157 | * clears or we time out. |
| 1158 | */ |
| 1159 | phy_control = BMCR_RESET; |
| 1160 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 1161 | if (err != 0) |
| 1162 | return -EBUSY; |
| 1163 | |
| 1164 | limit = 5000; |
| 1165 | while (limit--) { |
| 1166 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 1167 | if (err != 0) |
| 1168 | return -EBUSY; |
| 1169 | |
| 1170 | if ((phy_control & BMCR_RESET) == 0) { |
| 1171 | udelay(40); |
| 1172 | break; |
| 1173 | } |
| 1174 | udelay(10); |
| 1175 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1176 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1177 | return -EBUSY; |
| 1178 | |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1182 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 1183 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1184 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1185 | u32 val; |
| 1186 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1187 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1188 | |
| 1189 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1190 | val = -EIO; |
| 1191 | |
| 1192 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1193 | |
| 1194 | return val; |
| 1195 | } |
| 1196 | |
| 1197 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 1198 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1199 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1200 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1201 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1202 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1203 | |
| 1204 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1205 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1206 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1207 | spin_unlock_bh(&tp->lock); |
| 1208 | |
| 1209 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 1213 | { |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1217 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1218 | { |
| 1219 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1220 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1221 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1222 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1223 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1224 | case PHY_ID_BCM50610: |
| 1225 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1226 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 1227 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1228 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1229 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 1230 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1231 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1232 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 1233 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1234 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1235 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 1236 | break; |
| 1237 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1238 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 1242 | tw32(MAC_PHYCFG2, val); |
| 1243 | |
| 1244 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1245 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 1246 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 1247 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1248 | tw32(MAC_PHYCFG1, val); |
| 1249 | |
| 1250 | return; |
| 1251 | } |
| 1252 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1253 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1254 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 1255 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 1256 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 1257 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 1258 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1259 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1260 | |
| 1261 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1262 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1263 | val = tr32(MAC_PHYCFG1); |
| 1264 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1265 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1266 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1267 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1268 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1269 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1270 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1271 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1272 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1273 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1274 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1275 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1276 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1277 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1278 | MAC_RGMII_MODE_RX_QUALITY | |
| 1279 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1280 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1281 | MAC_RGMII_MODE_TX_ENABLE | |
| 1282 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1283 | MAC_RGMII_MODE_TX_RESET); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1284 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1285 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1286 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1287 | MAC_RGMII_MODE_RX_QUALITY | |
| 1288 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1289 | MAC_RGMII_MODE_RX_ENG_DET; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1290 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1291 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1292 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1293 | MAC_RGMII_MODE_TX_RESET; |
| 1294 | } |
| 1295 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1296 | } |
| 1297 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1298 | static void tg3_mdio_start(struct tg3 *tp) |
| 1299 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1300 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1301 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1302 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1303 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1304 | if (tg3_flag(tp, MDIOBUS_INITED) && |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1305 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1306 | tg3_mdio_config_5785(tp); |
| 1307 | } |
| 1308 | |
| 1309 | static int tg3_mdio_init(struct tg3 *tp) |
| 1310 | { |
| 1311 | int i; |
| 1312 | u32 reg; |
| 1313 | struct phy_device *phydev; |
| 1314 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1315 | if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1316 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1317 | |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 1318 | tp->phy_addr = tp->pci_fn + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1319 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1320 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1321 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1322 | else |
| 1323 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1324 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1325 | if (is_serdes) |
| 1326 | tp->phy_addr += 7; |
| 1327 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1328 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1329 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1330 | tg3_mdio_start(tp); |
| 1331 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1332 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1333 | return 0; |
| 1334 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1335 | tp->mdio_bus = mdiobus_alloc(); |
| 1336 | if (tp->mdio_bus == NULL) |
| 1337 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1338 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1339 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1340 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1341 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1342 | tp->mdio_bus->priv = tp; |
| 1343 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1344 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1345 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1346 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1347 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1348 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1349 | |
| 1350 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1351 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1352 | |
| 1353 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1354 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1355 | * accessing the PHY ID registers. A chip reset is the |
| 1356 | * quickest way to bring the device back to an operational state.. |
| 1357 | */ |
| 1358 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1359 | tg3_bmcr_reset(tp); |
| 1360 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1361 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1362 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1363 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1364 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1365 | return i; |
| 1366 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1367 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1368 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1369 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1370 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1371 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1372 | mdiobus_unregister(tp->mdio_bus); |
| 1373 | mdiobus_free(tp->mdio_bus); |
| 1374 | return -ENODEV; |
| 1375 | } |
| 1376 | |
| 1377 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1378 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1379 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1380 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1381 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1382 | case PHY_ID_BCM50610: |
| 1383 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1384 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1385 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1386 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1387 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1388 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1389 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1390 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1391 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1392 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1393 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1394 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1395 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1396 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1397 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1398 | case PHY_ID_RTL8201E: |
| 1399 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1400 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1401 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1402 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1403 | break; |
| 1404 | } |
| 1405 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1406 | tg3_flag_set(tp, MDIOBUS_INITED); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1407 | |
| 1408 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1409 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1410 | |
| 1411 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1415 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1416 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
| 1417 | tg3_flag_clear(tp, MDIOBUS_INITED); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1418 | mdiobus_unregister(tp->mdio_bus); |
| 1419 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1420 | } |
| 1421 | } |
| 1422 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1423 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1424 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1425 | { |
| 1426 | u32 val; |
| 1427 | |
| 1428 | val = tr32(GRC_RX_CPU_EVENT); |
| 1429 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1430 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1431 | |
| 1432 | tp->last_event_jiffies = jiffies; |
| 1433 | } |
| 1434 | |
| 1435 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1436 | |
| 1437 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1438 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1439 | { |
| 1440 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1441 | unsigned int delay_cnt; |
| 1442 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1443 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1444 | /* If enough time has passed, no wait is necessary. */ |
| 1445 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1446 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1447 | (long)jiffies; |
| 1448 | if (time_remain < 0) |
| 1449 | return; |
| 1450 | |
| 1451 | /* Check if we can shorten the wait time. */ |
| 1452 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1453 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1454 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1455 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1456 | |
| 1457 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1458 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1459 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1460 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | /* tp->lock is held. */ |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1465 | static void tg3_phy_gather_ump_data(struct tg3 *tp, u32 *data) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1466 | { |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1467 | u32 reg, val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1468 | |
| 1469 | val = 0; |
| 1470 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1471 | val = reg << 16; |
| 1472 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1473 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1474 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1475 | |
| 1476 | val = 0; |
| 1477 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1478 | val = reg << 16; |
| 1479 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1480 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1481 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1482 | |
| 1483 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1484 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1485 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1486 | val = reg << 16; |
| 1487 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1488 | val |= (reg & 0xffff); |
| 1489 | } |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1490 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1491 | |
| 1492 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1493 | val = reg << 16; |
| 1494 | else |
| 1495 | val = 0; |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1496 | *data++ = val; |
| 1497 | } |
| 1498 | |
| 1499 | /* tp->lock is held. */ |
| 1500 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1501 | { |
| 1502 | u32 data[4]; |
| 1503 | |
| 1504 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
| 1505 | return; |
| 1506 | |
| 1507 | tg3_phy_gather_ump_data(tp, data); |
| 1508 | |
| 1509 | tg3_wait_for_event_ack(tp); |
| 1510 | |
| 1511 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1512 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1513 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x0, data[0]); |
| 1514 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x4, data[1]); |
| 1515 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x8, data[2]); |
| 1516 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0xc, data[3]); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1517 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1518 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Matt Carlson | 8d5a89b | 2011-08-31 11:44:51 +0000 | [diff] [blame] | 1521 | /* tp->lock is held. */ |
| 1522 | static void tg3_stop_fw(struct tg3 *tp) |
| 1523 | { |
| 1524 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
| 1525 | /* Wait for RX cpu to ACK the previous event. */ |
| 1526 | tg3_wait_for_event_ack(tp); |
| 1527 | |
| 1528 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
| 1529 | |
| 1530 | tg3_generate_fw_event(tp); |
| 1531 | |
| 1532 | /* Wait for RX cpu to ACK this event. */ |
| 1533 | tg3_wait_for_event_ack(tp); |
| 1534 | } |
| 1535 | } |
| 1536 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 1537 | /* tp->lock is held. */ |
| 1538 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 1539 | { |
| 1540 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 1541 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
| 1542 | |
| 1543 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1544 | switch (kind) { |
| 1545 | case RESET_KIND_INIT: |
| 1546 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1547 | DRV_STATE_START); |
| 1548 | break; |
| 1549 | |
| 1550 | case RESET_KIND_SHUTDOWN: |
| 1551 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1552 | DRV_STATE_UNLOAD); |
| 1553 | break; |
| 1554 | |
| 1555 | case RESET_KIND_SUSPEND: |
| 1556 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1557 | DRV_STATE_SUSPEND); |
| 1558 | break; |
| 1559 | |
| 1560 | default: |
| 1561 | break; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | if (kind == RESET_KIND_INIT || |
| 1566 | kind == RESET_KIND_SUSPEND) |
| 1567 | tg3_ape_driver_state_change(tp, kind); |
| 1568 | } |
| 1569 | |
| 1570 | /* tp->lock is held. */ |
| 1571 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 1572 | { |
| 1573 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1574 | switch (kind) { |
| 1575 | case RESET_KIND_INIT: |
| 1576 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1577 | DRV_STATE_START_DONE); |
| 1578 | break; |
| 1579 | |
| 1580 | case RESET_KIND_SHUTDOWN: |
| 1581 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1582 | DRV_STATE_UNLOAD_DONE); |
| 1583 | break; |
| 1584 | |
| 1585 | default: |
| 1586 | break; |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | if (kind == RESET_KIND_SHUTDOWN) |
| 1591 | tg3_ape_driver_state_change(tp, kind); |
| 1592 | } |
| 1593 | |
| 1594 | /* tp->lock is held. */ |
| 1595 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 1596 | { |
| 1597 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 1598 | switch (kind) { |
| 1599 | case RESET_KIND_INIT: |
| 1600 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1601 | DRV_STATE_START); |
| 1602 | break; |
| 1603 | |
| 1604 | case RESET_KIND_SHUTDOWN: |
| 1605 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1606 | DRV_STATE_UNLOAD); |
| 1607 | break; |
| 1608 | |
| 1609 | case RESET_KIND_SUSPEND: |
| 1610 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1611 | DRV_STATE_SUSPEND); |
| 1612 | break; |
| 1613 | |
| 1614 | default: |
| 1615 | break; |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | static int tg3_poll_fw(struct tg3 *tp) |
| 1621 | { |
| 1622 | int i; |
| 1623 | u32 val; |
| 1624 | |
| 1625 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 1626 | /* Wait up to 20ms for init done. */ |
| 1627 | for (i = 0; i < 200; i++) { |
| 1628 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 1629 | return 0; |
| 1630 | udelay(100); |
| 1631 | } |
| 1632 | return -ENODEV; |
| 1633 | } |
| 1634 | |
| 1635 | /* Wait for firmware initialization to complete. */ |
| 1636 | for (i = 0; i < 100000; i++) { |
| 1637 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 1638 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 1639 | break; |
| 1640 | udelay(10); |
| 1641 | } |
| 1642 | |
| 1643 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 1644 | * parts are configured like that. So don't signal the timeout |
| 1645 | * of the above loop as an error, but do report the lack of |
| 1646 | * running firmware once. |
| 1647 | */ |
| 1648 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 1649 | tg3_flag_set(tp, NO_FWARE_REPORTED); |
| 1650 | |
| 1651 | netdev_info(tp->dev, "No firmware running\n"); |
| 1652 | } |
| 1653 | |
| 1654 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 1655 | /* The 57765 A0 needs a little more |
| 1656 | * time to do some important work. |
| 1657 | */ |
| 1658 | mdelay(10); |
| 1659 | } |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1664 | static void tg3_link_report(struct tg3 *tp) |
| 1665 | { |
| 1666 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1667 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1668 | tg3_ump_link_report(tp); |
| 1669 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1670 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1671 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1672 | 1000 : |
| 1673 | (tp->link_config.active_speed == SPEED_100 ? |
| 1674 | 100 : 10)), |
| 1675 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1676 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1677 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1678 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1679 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1680 | "on" : "off", |
| 1681 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1682 | "on" : "off"); |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 1683 | |
| 1684 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 1685 | netdev_info(tp->dev, "EEE is %s\n", |
| 1686 | tp->setlpicnt ? "enabled" : "disabled"); |
| 1687 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1688 | tg3_ump_link_report(tp); |
| 1689 | } |
| 1690 | } |
| 1691 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1692 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1693 | { |
| 1694 | u16 miireg; |
| 1695 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1696 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1697 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1698 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1699 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1700 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1701 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1702 | else |
| 1703 | miireg = 0; |
| 1704 | |
| 1705 | return miireg; |
| 1706 | } |
| 1707 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1708 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1709 | { |
| 1710 | u8 cap = 0; |
| 1711 | |
Matt Carlson | f3791cd | 2011-11-21 15:01:17 +0000 | [diff] [blame] | 1712 | if (lcladv & rmtadv & ADVERTISE_1000XPAUSE) { |
| 1713 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 1714 | } else if (lcladv & rmtadv & ADVERTISE_1000XPSE_ASYM) { |
| 1715 | if (lcladv & ADVERTISE_1000XPAUSE) |
| 1716 | cap = FLOW_CTRL_RX; |
| 1717 | if (rmtadv & ADVERTISE_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1718 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | return cap; |
| 1722 | } |
| 1723 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1724 | static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1725 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1726 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1727 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1728 | u32 old_rx_mode = tp->rx_mode; |
| 1729 | u32 old_tx_mode = tp->tx_mode; |
| 1730 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1731 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1732 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1733 | else |
| 1734 | autoneg = tp->link_config.autoneg; |
| 1735 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1736 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1737 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1738 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1739 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1740 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1741 | } else |
| 1742 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1743 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1744 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1745 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1746 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1747 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1748 | else |
| 1749 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1750 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1751 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1752 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1753 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1754 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1755 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1756 | else |
| 1757 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1758 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1759 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1760 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1763 | static void tg3_adjust_link(struct net_device *dev) |
| 1764 | { |
| 1765 | u8 oldflowctrl, linkmesg = 0; |
| 1766 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1767 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1768 | struct phy_device *phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1769 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1770 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1771 | |
| 1772 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1773 | MAC_MODE_HALF_DUPLEX); |
| 1774 | |
| 1775 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1776 | |
| 1777 | if (phydev->link) { |
| 1778 | lcl_adv = 0; |
| 1779 | rmt_adv = 0; |
| 1780 | |
| 1781 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1782 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1783 | else if (phydev->speed == SPEED_1000 || |
| 1784 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1785 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1786 | else |
| 1787 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1788 | |
| 1789 | if (phydev->duplex == DUPLEX_HALF) |
| 1790 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1791 | else { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 1792 | lcl_adv = mii_advertise_flowctrl( |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1793 | tp->link_config.flowctrl); |
| 1794 | |
| 1795 | if (phydev->pause) |
| 1796 | rmt_adv = LPA_PAUSE_CAP; |
| 1797 | if (phydev->asym_pause) |
| 1798 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1799 | } |
| 1800 | |
| 1801 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1802 | } else |
| 1803 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1804 | |
| 1805 | if (mac_mode != tp->mac_mode) { |
| 1806 | tp->mac_mode = mac_mode; |
| 1807 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1808 | udelay(40); |
| 1809 | } |
| 1810 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1811 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1812 | if (phydev->speed == SPEED_10) |
| 1813 | tw32(MAC_MI_STAT, |
| 1814 | MAC_MI_STAT_10MBPS_MODE | |
| 1815 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1816 | else |
| 1817 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1818 | } |
| 1819 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1820 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1821 | tw32(MAC_TX_LENGTHS, |
| 1822 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1823 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1824 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1825 | else |
| 1826 | tw32(MAC_TX_LENGTHS, |
| 1827 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1828 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1829 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1830 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1831 | if (phydev->link != tp->old_link || |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1832 | phydev->speed != tp->link_config.active_speed || |
| 1833 | phydev->duplex != tp->link_config.active_duplex || |
| 1834 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1835 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1836 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1837 | tp->old_link = phydev->link; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1838 | tp->link_config.active_speed = phydev->speed; |
| 1839 | tp->link_config.active_duplex = phydev->duplex; |
| 1840 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1841 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1842 | |
| 1843 | if (linkmesg) |
| 1844 | tg3_link_report(tp); |
| 1845 | } |
| 1846 | |
| 1847 | static int tg3_phy_init(struct tg3 *tp) |
| 1848 | { |
| 1849 | struct phy_device *phydev; |
| 1850 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1851 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1852 | return 0; |
| 1853 | |
| 1854 | /* Bring the PHY back to a known state. */ |
| 1855 | tg3_bmcr_reset(tp); |
| 1856 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1857 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1858 | |
| 1859 | /* Attach the MAC to the PHY. */ |
Kay Sievers | fb28ad35 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 1860 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1861 | phydev->dev_flags, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1862 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1863 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1864 | return PTR_ERR(phydev); |
| 1865 | } |
| 1866 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1867 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1868 | switch (phydev->interface) { |
| 1869 | case PHY_INTERFACE_MODE_GMII: |
| 1870 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1871 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1872 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 1873 | SUPPORTED_Pause | |
| 1874 | SUPPORTED_Asym_Pause); |
| 1875 | break; |
| 1876 | } |
| 1877 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1878 | case PHY_INTERFACE_MODE_MII: |
| 1879 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 1880 | SUPPORTED_Pause | |
| 1881 | SUPPORTED_Asym_Pause); |
| 1882 | break; |
| 1883 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1884 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1885 | return -EINVAL; |
| 1886 | } |
| 1887 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1888 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1889 | |
| 1890 | phydev->advertising = phydev->supported; |
| 1891 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1892 | return 0; |
| 1893 | } |
| 1894 | |
| 1895 | static void tg3_phy_start(struct tg3 *tp) |
| 1896 | { |
| 1897 | struct phy_device *phydev; |
| 1898 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1899 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1900 | return; |
| 1901 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1902 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1903 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 1904 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 1905 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 1906 | phydev->speed = tp->link_config.speed; |
| 1907 | phydev->duplex = tp->link_config.duplex; |
| 1908 | phydev->autoneg = tp->link_config.autoneg; |
| 1909 | phydev->advertising = tp->link_config.advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | phy_start(phydev); |
| 1913 | |
| 1914 | phy_start_aneg(phydev); |
| 1915 | } |
| 1916 | |
| 1917 | static void tg3_phy_stop(struct tg3 *tp) |
| 1918 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1919 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1920 | return; |
| 1921 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1922 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | static void tg3_phy_fini(struct tg3 *tp) |
| 1926 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1927 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1928 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1929 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 1933 | static int tg3_phy_set_extloopbk(struct tg3 *tp) |
| 1934 | { |
| 1935 | int err; |
| 1936 | u32 val; |
| 1937 | |
| 1938 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 1939 | return 0; |
| 1940 | |
| 1941 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 1942 | /* Cannot do read-modify-write on 5401 */ |
| 1943 | err = tg3_phy_auxctl_write(tp, |
| 1944 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 1945 | MII_TG3_AUXCTL_ACTL_EXTLOOPBK | |
| 1946 | 0x4c20); |
| 1947 | goto done; |
| 1948 | } |
| 1949 | |
| 1950 | err = tg3_phy_auxctl_read(tp, |
| 1951 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 1952 | if (err) |
| 1953 | return err; |
| 1954 | |
| 1955 | val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; |
| 1956 | err = tg3_phy_auxctl_write(tp, |
| 1957 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); |
| 1958 | |
| 1959 | done: |
| 1960 | return err; |
| 1961 | } |
| 1962 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1963 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 1964 | { |
| 1965 | u32 phytest; |
| 1966 | |
| 1967 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 1968 | u32 phy; |
| 1969 | |
| 1970 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1971 | phytest | MII_TG3_FET_SHADOW_EN); |
| 1972 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 1973 | if (enable) |
| 1974 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1975 | else |
| 1976 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1977 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 1978 | } |
| 1979 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 1980 | } |
| 1981 | } |
| 1982 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1983 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 1984 | { |
| 1985 | u32 reg; |
| 1986 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1987 | if (!tg3_flag(tp, 5705_PLUS) || |
| 1988 | (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1989 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1990 | return; |
| 1991 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1992 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1993 | tg3_phy_fet_toggle_apd(tp, enable); |
| 1994 | return; |
| 1995 | } |
| 1996 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1997 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1998 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 1999 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 2000 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 2001 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 2002 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 2003 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 2004 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 2005 | |
| 2006 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2007 | |
| 2008 | |
| 2009 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2010 | MII_TG3_MISC_SHDW_APD_SEL | |
| 2011 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 2012 | if (enable) |
| 2013 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 2014 | |
| 2015 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2016 | } |
| 2017 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2018 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 2019 | { |
| 2020 | u32 phy; |
| 2021 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2022 | if (!tg3_flag(tp, 5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2023 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2024 | return; |
| 2025 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2026 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2027 | u32 ephy; |
| 2028 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2029 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 2030 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 2031 | |
| 2032 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2033 | ephy | MII_TG3_FET_SHADOW_EN); |
| 2034 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2035 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2036 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2037 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2038 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 2039 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2040 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2041 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2042 | } |
| 2043 | } else { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2044 | int ret; |
| 2045 | |
| 2046 | ret = tg3_phy_auxctl_read(tp, |
| 2047 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); |
| 2048 | if (!ret) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2049 | if (enable) |
| 2050 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 2051 | else |
| 2052 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2053 | tg3_phy_auxctl_write(tp, |
| 2054 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2055 | } |
| 2056 | } |
| 2057 | } |
| 2058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 2060 | { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2061 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | u32 val; |
| 2063 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2064 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | return; |
| 2066 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2067 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
| 2068 | if (!ret) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2069 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
| 2070 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2073 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 2074 | { |
| 2075 | u32 otp, phy; |
| 2076 | |
| 2077 | if (!tp->phy_otp) |
| 2078 | return; |
| 2079 | |
| 2080 | otp = tp->phy_otp; |
| 2081 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2082 | if (TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) |
| 2083 | return; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2084 | |
| 2085 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 2086 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 2087 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 2088 | |
| 2089 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 2090 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 2091 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 2092 | |
| 2093 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 2094 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 2095 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 2096 | |
| 2097 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 2098 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 2099 | |
| 2100 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 2101 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 2102 | |
| 2103 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 2104 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 2105 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 2106 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2107 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2110 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
| 2111 | { |
| 2112 | u32 val; |
| 2113 | |
| 2114 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2115 | return; |
| 2116 | |
| 2117 | tp->setlpicnt = 0; |
| 2118 | |
| 2119 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 2120 | current_link_up == 1 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 2121 | tp->link_config.active_duplex == DUPLEX_FULL && |
| 2122 | (tp->link_config.active_speed == SPEED_100 || |
| 2123 | tp->link_config.active_speed == SPEED_1000)) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2124 | u32 eeectl; |
| 2125 | |
| 2126 | if (tp->link_config.active_speed == SPEED_1000) |
| 2127 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 2128 | else |
| 2129 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 2130 | |
| 2131 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 2132 | |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 2133 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
| 2134 | TG3_CL45_D7_EEERES_STAT, &val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2135 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2136 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 2137 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2138 | tp->setlpicnt = 2; |
| 2139 | } |
| 2140 | |
| 2141 | if (!tp->setlpicnt) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2142 | if (current_link_up == 1 && |
| 2143 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2144 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); |
| 2145 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2146 | } |
| 2147 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2148 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2149 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2150 | } |
| 2151 | } |
| 2152 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2153 | static void tg3_phy_eee_enable(struct tg3 *tp) |
| 2154 | { |
| 2155 | u32 val; |
| 2156 | |
| 2157 | if (tp->link_config.active_speed == SPEED_1000 && |
| 2158 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2159 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2160 | tg3_flag(tp, 57765_CLASS)) && |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2161 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2162 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 2163 | MII_TG3_DSP_TAP26_RMRXSTO; |
| 2164 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2165 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2166 | } |
| 2167 | |
| 2168 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2169 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2170 | } |
| 2171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 2173 | { |
| 2174 | int limit = 100; |
| 2175 | |
| 2176 | while (limit--) { |
| 2177 | u32 tmp32; |
| 2178 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2179 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | if ((tmp32 & 0x1000) == 0) |
| 2181 | break; |
| 2182 | } |
| 2183 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 2184 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | return -EBUSY; |
| 2186 | |
| 2187 | return 0; |
| 2188 | } |
| 2189 | |
| 2190 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 2191 | { |
| 2192 | static const u32 test_pat[4][6] = { |
| 2193 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 2194 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 2195 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 2196 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 2197 | }; |
| 2198 | int chan; |
| 2199 | |
| 2200 | for (chan = 0; chan < 4; chan++) { |
| 2201 | int i; |
| 2202 | |
| 2203 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2204 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2205 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | |
| 2207 | for (i = 0; i < 6; i++) |
| 2208 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 2209 | test_pat[chan][i]); |
| 2210 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2211 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | if (tg3_wait_macro_done(tp)) { |
| 2213 | *resetp = 1; |
| 2214 | return -EBUSY; |
| 2215 | } |
| 2216 | |
| 2217 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2218 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2219 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | if (tg3_wait_macro_done(tp)) { |
| 2221 | *resetp = 1; |
| 2222 | return -EBUSY; |
| 2223 | } |
| 2224 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2225 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | if (tg3_wait_macro_done(tp)) { |
| 2227 | *resetp = 1; |
| 2228 | return -EBUSY; |
| 2229 | } |
| 2230 | |
| 2231 | for (i = 0; i < 6; i += 2) { |
| 2232 | u32 low, high; |
| 2233 | |
| 2234 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 2235 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 2236 | tg3_wait_macro_done(tp)) { |
| 2237 | *resetp = 1; |
| 2238 | return -EBUSY; |
| 2239 | } |
| 2240 | low &= 0x7fff; |
| 2241 | high &= 0x000f; |
| 2242 | if (low != test_pat[chan][i] || |
| 2243 | high != test_pat[chan][i+1]) { |
| 2244 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 2245 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 2246 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 2247 | |
| 2248 | return -EBUSY; |
| 2249 | } |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | return 0; |
| 2254 | } |
| 2255 | |
| 2256 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 2257 | { |
| 2258 | int chan; |
| 2259 | |
| 2260 | for (chan = 0; chan < 4; chan++) { |
| 2261 | int i; |
| 2262 | |
| 2263 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2264 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2265 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | for (i = 0; i < 6; i++) |
| 2267 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2268 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | if (tg3_wait_macro_done(tp)) |
| 2270 | return -EBUSY; |
| 2271 | } |
| 2272 | |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
| 2276 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 2277 | { |
| 2278 | u32 reg32, phy9_orig; |
| 2279 | int retries, do_phy_reset, err; |
| 2280 | |
| 2281 | retries = 10; |
| 2282 | do_phy_reset = 1; |
| 2283 | do { |
| 2284 | if (do_phy_reset) { |
| 2285 | err = tg3_bmcr_reset(tp); |
| 2286 | if (err) |
| 2287 | return err; |
| 2288 | do_phy_reset = 0; |
| 2289 | } |
| 2290 | |
| 2291 | /* Disable transmitter and interrupt. */ |
| 2292 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 2293 | continue; |
| 2294 | |
| 2295 | reg32 |= 0x3000; |
| 2296 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2297 | |
| 2298 | /* Set full-duplex, 1000 mbps. */ |
| 2299 | tg3_writephy(tp, MII_BMCR, |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2300 | BMCR_FULLDPLX | BMCR_SPEED1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | |
| 2302 | /* Set to master mode. */ |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2303 | if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | continue; |
| 2305 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2306 | tg3_writephy(tp, MII_CTRL1000, |
| 2307 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2309 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 2310 | if (err) |
| 2311 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
| 2313 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2314 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
| 2316 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 2317 | if (!err) |
| 2318 | break; |
| 2319 | } while (--retries); |
| 2320 | |
| 2321 | err = tg3_phy_reset_chanpat(tp); |
| 2322 | if (err) |
| 2323 | return err; |
| 2324 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2325 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | |
| 2327 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2328 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2330 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2332 | tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | |
| 2334 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 2335 | reg32 &= ~0x3000; |
| 2336 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2337 | } else if (!err) |
| 2338 | err = -EBUSY; |
| 2339 | |
| 2340 | return err; |
| 2341 | } |
| 2342 | |
| 2343 | /* This will reset the tigon3 PHY if there is no valid |
| 2344 | * link unless the FORCE argument is non-zero. |
| 2345 | */ |
| 2346 | static int tg3_phy_reset(struct tg3 *tp) |
| 2347 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2348 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | int err; |
| 2350 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2351 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2352 | val = tr32(GRC_MISC_CFG); |
| 2353 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 2354 | udelay(40); |
| 2355 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2356 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 2357 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | if (err != 0) |
| 2359 | return -EBUSY; |
| 2360 | |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 2361 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
| 2362 | netif_carrier_off(tp->dev); |
| 2363 | tg3_link_report(tp); |
| 2364 | } |
| 2365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2367 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2368 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 2369 | err = tg3_phy_reset_5703_4_5(tp); |
| 2370 | if (err) |
| 2371 | return err; |
| 2372 | goto out; |
| 2373 | } |
| 2374 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2375 | cpmuctrl = 0; |
| 2376 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 2377 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 2378 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2379 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2380 | tw32(TG3_CPMU_CTRL, |
| 2381 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2382 | } |
| 2383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | err = tg3_bmcr_reset(tp); |
| 2385 | if (err) |
| 2386 | return err; |
| 2387 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2388 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2389 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2390 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2391 | |
| 2392 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2393 | } |
| 2394 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2395 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2396 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2397 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2398 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2399 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2400 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2401 | udelay(40); |
| 2402 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2403 | } |
| 2404 | } |
| 2405 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2406 | if (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2407 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2408 | return 0; |
| 2409 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2410 | tg3_phy_apply_otp(tp); |
| 2411 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2412 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2413 | tg3_phy_toggle_apd(tp, true); |
| 2414 | else |
| 2415 | tg3_phy_toggle_apd(tp, false); |
| 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | out: |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2418 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
| 2419 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2420 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2421 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2422 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2424 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2425 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2426 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2427 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2429 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2430 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2431 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2432 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2433 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2434 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
| 2435 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2436 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2437 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2438 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2439 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 2440 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
| 2441 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2442 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2443 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2444 | } else |
| 2445 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
| 2446 | |
| 2447 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2448 | } |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2449 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2452 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2453 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | /* Cannot do read-modify-write on 5401 */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2455 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2456 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | /* Set bit 14 with read-modify-write to preserve other bits */ |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2458 | err = tg3_phy_auxctl_read(tp, |
| 2459 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2460 | if (!err) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2461 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2462 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2466 | * jumbo frames transmission. |
| 2467 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2468 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2469 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2470 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2471 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2474 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2475 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2476 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2479 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | tg3_phy_set_wirespeed(tp); |
| 2481 | return 0; |
| 2482 | } |
| 2483 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2484 | #define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
| 2485 | #define TG3_GPIO_MSG_NEED_VAUX 0x00000002 |
| 2486 | #define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ |
| 2487 | TG3_GPIO_MSG_NEED_VAUX) |
| 2488 | #define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ |
| 2489 | ((TG3_GPIO_MSG_DRVR_PRES << 0) | \ |
| 2490 | (TG3_GPIO_MSG_DRVR_PRES << 4) | \ |
| 2491 | (TG3_GPIO_MSG_DRVR_PRES << 8) | \ |
| 2492 | (TG3_GPIO_MSG_DRVR_PRES << 12)) |
| 2493 | |
| 2494 | #define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ |
| 2495 | ((TG3_GPIO_MSG_NEED_VAUX << 0) | \ |
| 2496 | (TG3_GPIO_MSG_NEED_VAUX << 4) | \ |
| 2497 | (TG3_GPIO_MSG_NEED_VAUX << 8) | \ |
| 2498 | (TG3_GPIO_MSG_NEED_VAUX << 12)) |
| 2499 | |
| 2500 | static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) |
| 2501 | { |
| 2502 | u32 status, shift; |
| 2503 | |
| 2504 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2505 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2506 | status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); |
| 2507 | else |
| 2508 | status = tr32(TG3_CPMU_DRV_STATUS); |
| 2509 | |
| 2510 | shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; |
| 2511 | status &= ~(TG3_GPIO_MSG_MASK << shift); |
| 2512 | status |= (newstat << shift); |
| 2513 | |
| 2514 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2515 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2516 | tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); |
| 2517 | else |
| 2518 | tw32(TG3_CPMU_DRV_STATUS, status); |
| 2519 | |
| 2520 | return status >> TG3_APE_GPIO_MSG_SHIFT; |
| 2521 | } |
| 2522 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2523 | static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
| 2524 | { |
| 2525 | if (!tg3_flag(tp, IS_NIC)) |
| 2526 | return 0; |
| 2527 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2528 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2529 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2530 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 2531 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2532 | return -EIO; |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2533 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2534 | tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
| 2535 | |
| 2536 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2537 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2538 | |
| 2539 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
| 2540 | } else { |
| 2541 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2542 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2543 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2544 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2545 | return 0; |
| 2546 | } |
| 2547 | |
| 2548 | static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) |
| 2549 | { |
| 2550 | u32 grc_local_ctrl; |
| 2551 | |
| 2552 | if (!tg3_flag(tp, IS_NIC) || |
| 2553 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2554 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) |
| 2555 | return; |
| 2556 | |
| 2557 | grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; |
| 2558 | |
| 2559 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2560 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2561 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2562 | |
| 2563 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2564 | grc_local_ctrl, |
| 2565 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2566 | |
| 2567 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2568 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2569 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2570 | } |
| 2571 | |
| 2572 | static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) |
| 2573 | { |
| 2574 | if (!tg3_flag(tp, IS_NIC)) |
| 2575 | return; |
| 2576 | |
| 2577 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2578 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2579 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2580 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2581 | GRC_LCLCTRL_GPIO_OE1 | |
| 2582 | GRC_LCLCTRL_GPIO_OE2 | |
| 2583 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2584 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2585 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2586 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2587 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
| 2588 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2589 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2590 | GRC_LCLCTRL_GPIO_OE1 | |
| 2591 | GRC_LCLCTRL_GPIO_OE2 | |
| 2592 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2593 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2594 | tp->grc_local_ctrl; |
| 2595 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2596 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2597 | |
| 2598 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2599 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2600 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2601 | |
| 2602 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2603 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2604 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2605 | } else { |
| 2606 | u32 no_gpio2; |
| 2607 | u32 grc_local_ctrl = 0; |
| 2608 | |
| 2609 | /* Workaround to prevent overdrawing Amps. */ |
| 2610 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 2611 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
| 2612 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2613 | grc_local_ctrl, |
| 2614 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2615 | } |
| 2616 | |
| 2617 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2618 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2619 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2620 | |
| 2621 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 2622 | GRC_LCLCTRL_GPIO_OE1 | |
| 2623 | GRC_LCLCTRL_GPIO_OE2 | |
| 2624 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2625 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2626 | if (no_gpio2) { |
| 2627 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2628 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2629 | } |
| 2630 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2631 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2632 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2633 | |
| 2634 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2635 | |
| 2636 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2637 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2638 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2639 | |
| 2640 | if (!no_gpio2) { |
| 2641 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2642 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2643 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2644 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2645 | } |
| 2646 | } |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2647 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2648 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2649 | static void tg3_frob_aux_power_5717(struct tg3 *tp, bool wol_enable) |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2650 | { |
| 2651 | u32 msg = 0; |
| 2652 | |
| 2653 | /* Serialize power state transitions */ |
| 2654 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2655 | return; |
| 2656 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2657 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE) || wol_enable) |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2658 | msg = TG3_GPIO_MSG_NEED_VAUX; |
| 2659 | |
| 2660 | msg = tg3_set_function_status(tp, msg); |
| 2661 | |
| 2662 | if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) |
| 2663 | goto done; |
| 2664 | |
| 2665 | if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
| 2666 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2667 | else |
| 2668 | tg3_pwrsrc_die_with_vmain(tp); |
| 2669 | |
| 2670 | done: |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2671 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2674 | static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | { |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2676 | bool need_vaux = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2678 | /* The GPIOs do something completely different on 57765. */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2679 | if (!tg3_flag(tp, IS_NIC) || tg3_flag(tp, 57765_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | return; |
| 2681 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2682 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2683 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2684 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2685 | tg3_frob_aux_power_5717(tp, include_wol ? |
| 2686 | tg3_flag(tp, WOL_ENABLE) != 0 : 0); |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2687 | return; |
| 2688 | } |
| 2689 | |
| 2690 | if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2691 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2693 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2694 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2695 | /* remove_one() may have been run on the peer. */ |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2696 | if (dev_peer) { |
| 2697 | struct tg3 *tp_peer = netdev_priv(dev_peer); |
| 2698 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2699 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2700 | return; |
| 2701 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2702 | if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2703 | tg3_flag(tp_peer, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2704 | need_vaux = true; |
| 2705 | } |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2708 | if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
| 2709 | tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2710 | need_vaux = true; |
| 2711 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2712 | if (need_vaux) |
| 2713 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2714 | else |
| 2715 | tg3_pwrsrc_die_with_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2718 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2719 | { |
| 2720 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2721 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2722 | else if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2723 | if (speed != SPEED_10) |
| 2724 | return 1; |
| 2725 | } else if (speed == SPEED_10) |
| 2726 | return 1; |
| 2727 | |
| 2728 | return 0; |
| 2729 | } |
| 2730 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2731 | static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2732 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2733 | u32 val; |
| 2734 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2735 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2736 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2737 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2738 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2739 | |
| 2740 | sg_dig_ctrl |= |
| 2741 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2742 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2743 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2744 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2745 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2746 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2747 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2748 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2749 | tg3_bmcr_reset(tp); |
| 2750 | val = tr32(GRC_MISC_CFG); |
| 2751 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2752 | udelay(40); |
| 2753 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2754 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2755 | u32 phytest; |
| 2756 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2757 | u32 phy; |
| 2758 | |
| 2759 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2760 | tg3_writephy(tp, MII_BMCR, |
| 2761 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2762 | |
| 2763 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2764 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2765 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2766 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2767 | tg3_writephy(tp, |
| 2768 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2769 | phy); |
| 2770 | } |
| 2771 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2772 | } |
| 2773 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2774 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2775 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2776 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2777 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2778 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2779 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2780 | MII_TG3_AUXCTL_PCTL_VREG_11V; |
| 2781 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2782 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2783 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2784 | /* The PHY should not be powered down on some chips because |
| 2785 | * of bugs. |
| 2786 | */ |
| 2787 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2788 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2789 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
Matt Carlson | 085f1af | 2012-04-02 09:01:40 +0000 | [diff] [blame] | 2790 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) || |
| 2791 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
| 2792 | !tp->pci_fn)) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2793 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2794 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2795 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2796 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2797 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2798 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2799 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2800 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2801 | } |
| 2802 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2803 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2804 | } |
| 2805 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2806 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2807 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2808 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2809 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2810 | int i; |
| 2811 | |
| 2812 | if (tp->nvram_lock_cnt == 0) { |
| 2813 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2814 | for (i = 0; i < 8000; i++) { |
| 2815 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2816 | break; |
| 2817 | udelay(20); |
| 2818 | } |
| 2819 | if (i == 8000) { |
| 2820 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2821 | return -ENODEV; |
| 2822 | } |
| 2823 | } |
| 2824 | tp->nvram_lock_cnt++; |
| 2825 | } |
| 2826 | return 0; |
| 2827 | } |
| 2828 | |
| 2829 | /* tp->lock is held. */ |
| 2830 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2831 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2832 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2833 | if (tp->nvram_lock_cnt > 0) |
| 2834 | tp->nvram_lock_cnt--; |
| 2835 | if (tp->nvram_lock_cnt == 0) |
| 2836 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | /* tp->lock is held. */ |
| 2841 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 2842 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2843 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2844 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2845 | |
| 2846 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | /* tp->lock is held. */ |
| 2851 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 2852 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2853 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2854 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2855 | |
| 2856 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 2861 | u32 offset, u32 *val) |
| 2862 | { |
| 2863 | u32 tmp; |
| 2864 | int i; |
| 2865 | |
| 2866 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 2867 | return -EINVAL; |
| 2868 | |
| 2869 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 2870 | EEPROM_ADDR_DEVID_MASK | |
| 2871 | EEPROM_ADDR_READ); |
| 2872 | tw32(GRC_EEPROM_ADDR, |
| 2873 | tmp | |
| 2874 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 2875 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 2876 | EEPROM_ADDR_ADDR_MASK) | |
| 2877 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 2878 | |
| 2879 | for (i = 0; i < 1000; i++) { |
| 2880 | tmp = tr32(GRC_EEPROM_ADDR); |
| 2881 | |
| 2882 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 2883 | break; |
| 2884 | msleep(1); |
| 2885 | } |
| 2886 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 2887 | return -EBUSY; |
| 2888 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 2889 | tmp = tr32(GRC_EEPROM_DATA); |
| 2890 | |
| 2891 | /* |
| 2892 | * The data will always be opposite the native endian |
| 2893 | * format. Perform a blind byteswap to compensate. |
| 2894 | */ |
| 2895 | *val = swab32(tmp); |
| 2896 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2897 | return 0; |
| 2898 | } |
| 2899 | |
| 2900 | #define NVRAM_CMD_TIMEOUT 10000 |
| 2901 | |
| 2902 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 2903 | { |
| 2904 | int i; |
| 2905 | |
| 2906 | tw32(NVRAM_CMD, nvram_cmd); |
| 2907 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 2908 | udelay(10); |
| 2909 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 2910 | udelay(10); |
| 2911 | break; |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | if (i == NVRAM_CMD_TIMEOUT) |
| 2916 | return -EBUSY; |
| 2917 | |
| 2918 | return 0; |
| 2919 | } |
| 2920 | |
| 2921 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 2922 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2923 | if (tg3_flag(tp, NVRAM) && |
| 2924 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 2925 | tg3_flag(tp, FLASH) && |
| 2926 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2927 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2928 | |
| 2929 | addr = ((addr / tp->nvram_pagesize) << |
| 2930 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 2931 | (addr % tp->nvram_pagesize); |
| 2932 | |
| 2933 | return addr; |
| 2934 | } |
| 2935 | |
| 2936 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 2937 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2938 | if (tg3_flag(tp, NVRAM) && |
| 2939 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 2940 | tg3_flag(tp, FLASH) && |
| 2941 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2942 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2943 | |
| 2944 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 2945 | tp->nvram_pagesize) + |
| 2946 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 2947 | |
| 2948 | return addr; |
| 2949 | } |
| 2950 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2951 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 2952 | * the byteswapping settings for all other register accesses. |
| 2953 | * tg3 devices are BE devices, so on a BE machine, the data |
| 2954 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 2955 | * machine, the 32-bit value will be byteswapped. |
| 2956 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2957 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 2958 | { |
| 2959 | int ret; |
| 2960 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2961 | if (!tg3_flag(tp, NVRAM)) |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2962 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 2963 | |
| 2964 | offset = tg3_nvram_phys_addr(tp, offset); |
| 2965 | |
| 2966 | if (offset > NVRAM_ADDR_MSK) |
| 2967 | return -EINVAL; |
| 2968 | |
| 2969 | ret = tg3_nvram_lock(tp); |
| 2970 | if (ret) |
| 2971 | return ret; |
| 2972 | |
| 2973 | tg3_enable_nvram_access(tp); |
| 2974 | |
| 2975 | tw32(NVRAM_ADDR, offset); |
| 2976 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 2977 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 2978 | |
| 2979 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2980 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2981 | |
| 2982 | tg3_disable_nvram_access(tp); |
| 2983 | |
| 2984 | tg3_nvram_unlock(tp); |
| 2985 | |
| 2986 | return ret; |
| 2987 | } |
| 2988 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2989 | /* Ensures NVRAM data is in bytestream format. */ |
| 2990 | static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2991 | { |
| 2992 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2993 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2994 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2995 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2996 | return res; |
| 2997 | } |
| 2998 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 2999 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 3000 | u32 offset, u32 len, u8 *buf) |
| 3001 | { |
| 3002 | int i, j, rc = 0; |
| 3003 | u32 val; |
| 3004 | |
| 3005 | for (i = 0; i < len; i += 4) { |
| 3006 | u32 addr; |
| 3007 | __be32 data; |
| 3008 | |
| 3009 | addr = offset + i; |
| 3010 | |
| 3011 | memcpy(&data, buf + i, 4); |
| 3012 | |
| 3013 | /* |
| 3014 | * The SEEPROM interface expects the data to always be opposite |
| 3015 | * the native endian format. We accomplish this by reversing |
| 3016 | * all the operations that would have been performed on the |
| 3017 | * data from a call to tg3_nvram_read_be32(). |
| 3018 | */ |
| 3019 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
| 3020 | |
| 3021 | val = tr32(GRC_EEPROM_ADDR); |
| 3022 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 3023 | |
| 3024 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 3025 | EEPROM_ADDR_READ); |
| 3026 | tw32(GRC_EEPROM_ADDR, val | |
| 3027 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3028 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 3029 | EEPROM_ADDR_START | |
| 3030 | EEPROM_ADDR_WRITE); |
| 3031 | |
| 3032 | for (j = 0; j < 1000; j++) { |
| 3033 | val = tr32(GRC_EEPROM_ADDR); |
| 3034 | |
| 3035 | if (val & EEPROM_ADDR_COMPLETE) |
| 3036 | break; |
| 3037 | msleep(1); |
| 3038 | } |
| 3039 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 3040 | rc = -EBUSY; |
| 3041 | break; |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | return rc; |
| 3046 | } |
| 3047 | |
| 3048 | /* offset and length are dword aligned */ |
| 3049 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 3050 | u8 *buf) |
| 3051 | { |
| 3052 | int ret = 0; |
| 3053 | u32 pagesize = tp->nvram_pagesize; |
| 3054 | u32 pagemask = pagesize - 1; |
| 3055 | u32 nvram_cmd; |
| 3056 | u8 *tmp; |
| 3057 | |
| 3058 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 3059 | if (tmp == NULL) |
| 3060 | return -ENOMEM; |
| 3061 | |
| 3062 | while (len) { |
| 3063 | int j; |
| 3064 | u32 phy_addr, page_off, size; |
| 3065 | |
| 3066 | phy_addr = offset & ~pagemask; |
| 3067 | |
| 3068 | for (j = 0; j < pagesize; j += 4) { |
| 3069 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 3070 | (__be32 *) (tmp + j)); |
| 3071 | if (ret) |
| 3072 | break; |
| 3073 | } |
| 3074 | if (ret) |
| 3075 | break; |
| 3076 | |
| 3077 | page_off = offset & pagemask; |
| 3078 | size = pagesize; |
| 3079 | if (len < size) |
| 3080 | size = len; |
| 3081 | |
| 3082 | len -= size; |
| 3083 | |
| 3084 | memcpy(tmp + page_off, buf, size); |
| 3085 | |
| 3086 | offset = offset + (pagesize - page_off); |
| 3087 | |
| 3088 | tg3_enable_nvram_access(tp); |
| 3089 | |
| 3090 | /* |
| 3091 | * Before we can erase the flash page, we need |
| 3092 | * to issue a special "write enable" command. |
| 3093 | */ |
| 3094 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3095 | |
| 3096 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3097 | break; |
| 3098 | |
| 3099 | /* Erase the target page */ |
| 3100 | tw32(NVRAM_ADDR, phy_addr); |
| 3101 | |
| 3102 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 3103 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 3104 | |
| 3105 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3106 | break; |
| 3107 | |
| 3108 | /* Issue another write enable to start the write. */ |
| 3109 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3110 | |
| 3111 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3112 | break; |
| 3113 | |
| 3114 | for (j = 0; j < pagesize; j += 4) { |
| 3115 | __be32 data; |
| 3116 | |
| 3117 | data = *((__be32 *) (tmp + j)); |
| 3118 | |
| 3119 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3120 | |
| 3121 | tw32(NVRAM_ADDR, phy_addr + j); |
| 3122 | |
| 3123 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 3124 | NVRAM_CMD_WR; |
| 3125 | |
| 3126 | if (j == 0) |
| 3127 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3128 | else if (j == (pagesize - 4)) |
| 3129 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3130 | |
| 3131 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3132 | if (ret) |
| 3133 | break; |
| 3134 | } |
| 3135 | if (ret) |
| 3136 | break; |
| 3137 | } |
| 3138 | |
| 3139 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3140 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3141 | |
| 3142 | kfree(tmp); |
| 3143 | |
| 3144 | return ret; |
| 3145 | } |
| 3146 | |
| 3147 | /* offset and length are dword aligned */ |
| 3148 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 3149 | u8 *buf) |
| 3150 | { |
| 3151 | int i, ret = 0; |
| 3152 | |
| 3153 | for (i = 0; i < len; i += 4, offset += 4) { |
| 3154 | u32 page_off, phy_addr, nvram_cmd; |
| 3155 | __be32 data; |
| 3156 | |
| 3157 | memcpy(&data, buf + i, 4); |
| 3158 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3159 | |
| 3160 | page_off = offset % tp->nvram_pagesize; |
| 3161 | |
| 3162 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
| 3163 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3164 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 3165 | |
| 3166 | if (page_off == 0 || i == 0) |
| 3167 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3168 | if (page_off == (tp->nvram_pagesize - 4)) |
| 3169 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3170 | |
| 3171 | if (i == (len - 4)) |
| 3172 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3173 | |
Matt Carlson | 4227822 | 2012-02-13 15:20:11 +0000 | [diff] [blame] | 3174 | if ((nvram_cmd & NVRAM_CMD_FIRST) || |
| 3175 | !tg3_flag(tp, FLASH) || |
| 3176 | !tg3_flag(tp, 57765_PLUS)) |
| 3177 | tw32(NVRAM_ADDR, phy_addr); |
| 3178 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3179 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
| 3180 | !tg3_flag(tp, 5755_PLUS) && |
| 3181 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 3182 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
| 3183 | u32 cmd; |
| 3184 | |
| 3185 | cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3186 | ret = tg3_nvram_exec_cmd(tp, cmd); |
| 3187 | if (ret) |
| 3188 | break; |
| 3189 | } |
| 3190 | if (!tg3_flag(tp, FLASH)) { |
| 3191 | /* We always do complete word writes to eeprom. */ |
| 3192 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 3193 | } |
| 3194 | |
| 3195 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3196 | if (ret) |
| 3197 | break; |
| 3198 | } |
| 3199 | return ret; |
| 3200 | } |
| 3201 | |
| 3202 | /* offset and length are dword aligned */ |
| 3203 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 3204 | { |
| 3205 | int ret; |
| 3206 | |
| 3207 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3208 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 3209 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
| 3210 | udelay(40); |
| 3211 | } |
| 3212 | |
| 3213 | if (!tg3_flag(tp, NVRAM)) { |
| 3214 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
| 3215 | } else { |
| 3216 | u32 grc_mode; |
| 3217 | |
| 3218 | ret = tg3_nvram_lock(tp); |
| 3219 | if (ret) |
| 3220 | return ret; |
| 3221 | |
| 3222 | tg3_enable_nvram_access(tp); |
| 3223 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
| 3224 | tw32(NVRAM_WRITE1, 0x406); |
| 3225 | |
| 3226 | grc_mode = tr32(GRC_MODE); |
| 3227 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 3228 | |
| 3229 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
| 3230 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 3231 | buf); |
| 3232 | } else { |
| 3233 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 3234 | buf); |
| 3235 | } |
| 3236 | |
| 3237 | grc_mode = tr32(GRC_MODE); |
| 3238 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 3239 | |
| 3240 | tg3_disable_nvram_access(tp); |
| 3241 | tg3_nvram_unlock(tp); |
| 3242 | } |
| 3243 | |
| 3244 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3245 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 3246 | udelay(40); |
| 3247 | } |
| 3248 | |
| 3249 | return ret; |
| 3250 | } |
| 3251 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3252 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 3253 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 3254 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 3255 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 3256 | |
| 3257 | /* tp->lock is held. */ |
| 3258 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 3259 | { |
| 3260 | int i; |
| 3261 | |
| 3262 | BUG_ON(offset == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
| 3263 | |
| 3264 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3265 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 3266 | |
| 3267 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 3268 | return 0; |
| 3269 | } |
| 3270 | if (offset == RX_CPU_BASE) { |
| 3271 | for (i = 0; i < 10000; i++) { |
| 3272 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3273 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3274 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3275 | break; |
| 3276 | } |
| 3277 | |
| 3278 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3279 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 3280 | udelay(10); |
| 3281 | } else { |
| 3282 | for (i = 0; i < 10000; i++) { |
| 3283 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3284 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3285 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3286 | break; |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | if (i >= 10000) { |
| 3291 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 3292 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
| 3293 | return -ENODEV; |
| 3294 | } |
| 3295 | |
| 3296 | /* Clear firmware's nvram arbitration. */ |
| 3297 | if (tg3_flag(tp, NVRAM)) |
| 3298 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
| 3299 | return 0; |
| 3300 | } |
| 3301 | |
| 3302 | struct fw_info { |
| 3303 | unsigned int fw_base; |
| 3304 | unsigned int fw_len; |
| 3305 | const __be32 *fw_data; |
| 3306 | }; |
| 3307 | |
| 3308 | /* tp->lock is held. */ |
| 3309 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, |
| 3310 | u32 cpu_scratch_base, int cpu_scratch_size, |
| 3311 | struct fw_info *info) |
| 3312 | { |
| 3313 | int err, lock_err, i; |
| 3314 | void (*write_op)(struct tg3 *, u32, u32); |
| 3315 | |
| 3316 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
| 3317 | netdev_err(tp->dev, |
| 3318 | "%s: Trying to load TX cpu firmware which is 5705\n", |
| 3319 | __func__); |
| 3320 | return -EINVAL; |
| 3321 | } |
| 3322 | |
| 3323 | if (tg3_flag(tp, 5705_PLUS)) |
| 3324 | write_op = tg3_write_mem; |
| 3325 | else |
| 3326 | write_op = tg3_write_indirect_reg32; |
| 3327 | |
| 3328 | /* It is possible that bootcode is still loading at this point. |
| 3329 | * Get the nvram lock first before halting the cpu. |
| 3330 | */ |
| 3331 | lock_err = tg3_nvram_lock(tp); |
| 3332 | err = tg3_halt_cpu(tp, cpu_base); |
| 3333 | if (!lock_err) |
| 3334 | tg3_nvram_unlock(tp); |
| 3335 | if (err) |
| 3336 | goto out; |
| 3337 | |
| 3338 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 3339 | write_op(tp, cpu_scratch_base + i, 0); |
| 3340 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3341 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); |
| 3342 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
| 3343 | write_op(tp, (cpu_scratch_base + |
| 3344 | (info->fw_base & 0xffff) + |
| 3345 | (i * sizeof(u32))), |
| 3346 | be32_to_cpu(info->fw_data[i])); |
| 3347 | |
| 3348 | err = 0; |
| 3349 | |
| 3350 | out: |
| 3351 | return err; |
| 3352 | } |
| 3353 | |
| 3354 | /* tp->lock is held. */ |
| 3355 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 3356 | { |
| 3357 | struct fw_info info; |
| 3358 | const __be32 *fw_data; |
| 3359 | int err, i; |
| 3360 | |
| 3361 | fw_data = (void *)tp->fw->data; |
| 3362 | |
| 3363 | /* Firmware blob starts with version numbers, followed by |
| 3364 | start address and length. We are setting complete length. |
| 3365 | length = end_address_of_bss - start_address_of_text. |
| 3366 | Remainder is the blob to be loaded contiguously |
| 3367 | from start address. */ |
| 3368 | |
| 3369 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3370 | info.fw_len = tp->fw->size - 12; |
| 3371 | info.fw_data = &fw_data[3]; |
| 3372 | |
| 3373 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 3374 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 3375 | &info); |
| 3376 | if (err) |
| 3377 | return err; |
| 3378 | |
| 3379 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 3380 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 3381 | &info); |
| 3382 | if (err) |
| 3383 | return err; |
| 3384 | |
| 3385 | /* Now startup only the RX cpu. */ |
| 3386 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3387 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3388 | |
| 3389 | for (i = 0; i < 5; i++) { |
| 3390 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
| 3391 | break; |
| 3392 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3393 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
| 3394 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3395 | udelay(1000); |
| 3396 | } |
| 3397 | if (i >= 5) { |
| 3398 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 3399 | "should be %08x\n", __func__, |
| 3400 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
| 3401 | return -ENODEV; |
| 3402 | } |
| 3403 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3404 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 3405 | |
| 3406 | return 0; |
| 3407 | } |
| 3408 | |
| 3409 | /* tp->lock is held. */ |
| 3410 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 3411 | { |
| 3412 | struct fw_info info; |
| 3413 | const __be32 *fw_data; |
| 3414 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 3415 | int err, i; |
| 3416 | |
| 3417 | if (tg3_flag(tp, HW_TSO_1) || |
| 3418 | tg3_flag(tp, HW_TSO_2) || |
| 3419 | tg3_flag(tp, HW_TSO_3)) |
| 3420 | return 0; |
| 3421 | |
| 3422 | fw_data = (void *)tp->fw->data; |
| 3423 | |
| 3424 | /* Firmware blob starts with version numbers, followed by |
| 3425 | start address and length. We are setting complete length. |
| 3426 | length = end_address_of_bss - start_address_of_text. |
| 3427 | Remainder is the blob to be loaded contiguously |
| 3428 | from start address. */ |
| 3429 | |
| 3430 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3431 | cpu_scratch_size = tp->fw_len; |
| 3432 | info.fw_len = tp->fw->size - 12; |
| 3433 | info.fw_data = &fw_data[3]; |
| 3434 | |
| 3435 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 3436 | cpu_base = RX_CPU_BASE; |
| 3437 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
| 3438 | } else { |
| 3439 | cpu_base = TX_CPU_BASE; |
| 3440 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 3441 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 3442 | } |
| 3443 | |
| 3444 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 3445 | cpu_scratch_base, cpu_scratch_size, |
| 3446 | &info); |
| 3447 | if (err) |
| 3448 | return err; |
| 3449 | |
| 3450 | /* Now startup the cpu. */ |
| 3451 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3452 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3453 | |
| 3454 | for (i = 0; i < 5; i++) { |
| 3455 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
| 3456 | break; |
| 3457 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3458 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3459 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3460 | udelay(1000); |
| 3461 | } |
| 3462 | if (i >= 5) { |
| 3463 | netdev_err(tp->dev, |
| 3464 | "%s fails to set CPU PC, is %08x should be %08x\n", |
| 3465 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
| 3466 | return -ENODEV; |
| 3467 | } |
| 3468 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3469 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 3470 | return 0; |
| 3471 | } |
| 3472 | |
| 3473 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3474 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 3475 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 3476 | { |
| 3477 | u32 addr_high, addr_low; |
| 3478 | int i; |
| 3479 | |
| 3480 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 3481 | tp->dev->dev_addr[1]); |
| 3482 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 3483 | (tp->dev->dev_addr[3] << 16) | |
| 3484 | (tp->dev->dev_addr[4] << 8) | |
| 3485 | (tp->dev->dev_addr[5] << 0)); |
| 3486 | for (i = 0; i < 4; i++) { |
| 3487 | if (i == 1 && skip_mac_1) |
| 3488 | continue; |
| 3489 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 3490 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 3491 | } |
| 3492 | |
| 3493 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3494 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 3495 | for (i = 0; i < 12; i++) { |
| 3496 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 3497 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | addr_high = (tp->dev->dev_addr[0] + |
| 3502 | tp->dev->dev_addr[1] + |
| 3503 | tp->dev->dev_addr[2] + |
| 3504 | tp->dev->dev_addr[3] + |
| 3505 | tp->dev->dev_addr[4] + |
| 3506 | tp->dev->dev_addr[5]) & |
| 3507 | TX_BACKOFF_SEED_MASK; |
| 3508 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 3509 | } |
| 3510 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3511 | static void tg3_enable_register_access(struct tg3 *tp) |
| 3512 | { |
| 3513 | /* |
| 3514 | * Make sure register accesses (indirect or otherwise) will function |
| 3515 | * correctly. |
| 3516 | */ |
| 3517 | pci_write_config_dword(tp->pdev, |
| 3518 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
| 3519 | } |
| 3520 | |
| 3521 | static int tg3_power_up(struct tg3 *tp) |
| 3522 | { |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3523 | int err; |
| 3524 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3525 | tg3_enable_register_access(tp); |
| 3526 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3527 | err = pci_set_power_state(tp->pdev, PCI_D0); |
| 3528 | if (!err) { |
| 3529 | /* Switch out of Vaux if it is a NIC */ |
| 3530 | tg3_pwrsrc_switch_to_vmain(tp); |
| 3531 | } else { |
| 3532 | netdev_err(tp->dev, "Transition to D0 failed\n"); |
| 3533 | } |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3534 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3535 | return err; |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3536 | } |
| 3537 | |
Matt Carlson | 4b40952 | 2012-02-13 10:20:11 +0000 | [diff] [blame] | 3538 | static int tg3_setup_phy(struct tg3 *, int); |
| 3539 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3540 | static int tg3_power_down_prepare(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | { |
| 3542 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3543 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3545 | tg3_enable_register_access(tp); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3546 | |
| 3547 | /* Restore the CLKREQ setting. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3548 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3549 | u16 lnkctl; |
| 3550 | |
| 3551 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 3552 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3553 | &lnkctl); |
| 3554 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3555 | pci_write_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 3556 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3557 | lnkctl); |
| 3558 | } |
| 3559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 3561 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 3562 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 3563 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3564 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3565 | tg3_flag(tp, WOL_ENABLE); |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3566 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3567 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3568 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3569 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3570 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3571 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3572 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3573 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 3574 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3575 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3576 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3577 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3578 | tp->link_config.speed = phydev->speed; |
| 3579 | tp->link_config.duplex = phydev->duplex; |
| 3580 | tp->link_config.autoneg = phydev->autoneg; |
| 3581 | tp->link_config.advertising = phydev->advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3582 | |
| 3583 | advertising = ADVERTISED_TP | |
| 3584 | ADVERTISED_Pause | |
| 3585 | ADVERTISED_Autoneg | |
| 3586 | ADVERTISED_10baseT_Half; |
| 3587 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3588 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
| 3589 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3590 | advertising |= |
| 3591 | ADVERTISED_100baseT_Half | |
| 3592 | ADVERTISED_100baseT_Full | |
| 3593 | ADVERTISED_10baseT_Full; |
| 3594 | else |
| 3595 | advertising |= ADVERTISED_10baseT_Full; |
| 3596 | } |
| 3597 | |
| 3598 | phydev->advertising = advertising; |
| 3599 | |
| 3600 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3601 | |
| 3602 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 3603 | if (phyid != PHY_ID_BCMAC131) { |
| 3604 | phyid &= PHY_BCM_OUI_MASK; |
| 3605 | if (phyid == PHY_BCM_OUI_1 || |
| 3606 | phyid == PHY_BCM_OUI_2 || |
| 3607 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3608 | do_low_power = true; |
| 3609 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3610 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3611 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 3612 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3613 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3614 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3615 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | |
Matt Carlson | 2855b9f | 2012-02-13 15:20:14 +0000 | [diff] [blame] | 3617 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3618 | tg3_setup_phy(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 3621 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3622 | u32 val; |
| 3623 | |
| 3624 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 3625 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3626 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3627 | int i; |
| 3628 | u32 val; |
| 3629 | |
| 3630 | for (i = 0; i < 200; i++) { |
| 3631 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 3632 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 3633 | break; |
| 3634 | msleep(1); |
| 3635 | } |
| 3636 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3637 | if (tg3_flag(tp, WOL_CAP)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 3638 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 3639 | WOL_DRV_STATE_SHUTDOWN | |
| 3640 | WOL_DRV_WOL | |
| 3641 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3642 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3643 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | u32 mac_mode; |
| 3645 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3646 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3647 | if (do_low_power && |
| 3648 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 3649 | tg3_phy_auxctl_write(tp, |
| 3650 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, |
| 3651 | MII_TG3_AUXCTL_PCTL_WOL_EN | |
| 3652 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 3653 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3654 | udelay(40); |
| 3655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3657 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 3658 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 3659 | else |
| 3660 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3662 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 3663 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 3664 | ASIC_REV_5700) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3665 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3666 | SPEED_100 : SPEED_10; |
| 3667 | if (tg3_5700_link_polarity(tp, speed)) |
| 3668 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 3669 | else |
| 3670 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 3671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | } else { |
| 3673 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 3674 | } |
| 3675 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3676 | if (!tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 3678 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3679 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3680 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
| 3681 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3682 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3684 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 3685 | mac_mode |= MAC_MODE_APE_TX_EN | |
| 3686 | MAC_MODE_APE_RX_EN | |
| 3687 | MAC_MODE_TDE_ENABLE; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 3688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | tw32_f(MAC_MODE, mac_mode); |
| 3690 | udelay(100); |
| 3691 | |
| 3692 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 3693 | udelay(10); |
| 3694 | } |
| 3695 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3696 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3698 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 3699 | u32 base_val; |
| 3700 | |
| 3701 | base_val = tp->pci_clock_ctrl; |
| 3702 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 3703 | CLOCK_CTRL_TXCLK_DISABLE); |
| 3704 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3705 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 3706 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3707 | } else if (tg3_flag(tp, 5780_CLASS) || |
| 3708 | tg3_flag(tp, CPMU_PRESENT) || |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 3709 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 3710 | /* do nothing */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3711 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | u32 newbits1, newbits2; |
| 3713 | |
| 3714 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3715 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3716 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3717 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3718 | CLOCK_CTRL_ALTCLK); |
| 3719 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3720 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | newbits1 = CLOCK_CTRL_625_CORE; |
| 3722 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 3723 | } else { |
| 3724 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 3725 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 3726 | } |
| 3727 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3728 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 3729 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3731 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 3732 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3734 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | u32 newbits3; |
| 3736 | |
| 3737 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3738 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3739 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3740 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3741 | CLOCK_CTRL_44MHZ_CORE); |
| 3742 | } else { |
| 3743 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 3744 | } |
| 3745 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3746 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 3747 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3751 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3752 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3753 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 3754 | tg3_frob_aux_power(tp, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | |
| 3756 | /* Workaround for unstable PLL clock */ |
| 3757 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || |
| 3758 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { |
| 3759 | u32 val = tr32(0x7d00); |
| 3760 | |
| 3761 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 3762 | tw32(0x7d00, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3763 | if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3764 | int err; |
| 3765 | |
| 3766 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3768 | if (!err) |
| 3769 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | } |
| 3772 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 3773 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 3774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | return 0; |
| 3776 | } |
| 3777 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3778 | static void tg3_power_down(struct tg3 *tp) |
| 3779 | { |
| 3780 | tg3_power_down_prepare(tp); |
| 3781 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3782 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3783 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 3784 | } |
| 3785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 3787 | { |
| 3788 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 3789 | case MII_TG3_AUX_STAT_10HALF: |
| 3790 | *speed = SPEED_10; |
| 3791 | *duplex = DUPLEX_HALF; |
| 3792 | break; |
| 3793 | |
| 3794 | case MII_TG3_AUX_STAT_10FULL: |
| 3795 | *speed = SPEED_10; |
| 3796 | *duplex = DUPLEX_FULL; |
| 3797 | break; |
| 3798 | |
| 3799 | case MII_TG3_AUX_STAT_100HALF: |
| 3800 | *speed = SPEED_100; |
| 3801 | *duplex = DUPLEX_HALF; |
| 3802 | break; |
| 3803 | |
| 3804 | case MII_TG3_AUX_STAT_100FULL: |
| 3805 | *speed = SPEED_100; |
| 3806 | *duplex = DUPLEX_FULL; |
| 3807 | break; |
| 3808 | |
| 3809 | case MII_TG3_AUX_STAT_1000HALF: |
| 3810 | *speed = SPEED_1000; |
| 3811 | *duplex = DUPLEX_HALF; |
| 3812 | break; |
| 3813 | |
| 3814 | case MII_TG3_AUX_STAT_1000FULL: |
| 3815 | *speed = SPEED_1000; |
| 3816 | *duplex = DUPLEX_FULL; |
| 3817 | break; |
| 3818 | |
| 3819 | default: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3820 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 3821 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 3822 | SPEED_10; |
| 3823 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 3824 | DUPLEX_HALF; |
| 3825 | break; |
| 3826 | } |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 3827 | *speed = SPEED_UNKNOWN; |
| 3828 | *duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3830 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3833 | static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3835 | int err = 0; |
| 3836 | u32 val, new_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3838 | new_adv = ADVERTISE_CSMA; |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 3839 | new_adv |= ethtool_adv_to_mii_adv_t(advertise) & ADVERTISE_ALL; |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 3840 | new_adv |= mii_advertise_flowctrl(flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3842 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 3843 | if (err) |
| 3844 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3846 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 3847 | new_adv = ethtool_adv_to_mii_ctrl1000_t(advertise); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3848 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3849 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 3850 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 3851 | new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3852 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3853 | err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
| 3854 | if (err) |
| 3855 | goto done; |
| 3856 | } |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3857 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3858 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 3859 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3861 | tw32(TG3_CPMU_EEE_MODE, |
| 3862 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3863 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3864 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 3865 | if (!err) { |
| 3866 | u32 err2; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3867 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 3868 | val = 0; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3869 | /* Advertise 100-BaseTX EEE ability */ |
| 3870 | if (advertise & ADVERTISED_100baseT_Full) |
| 3871 | val |= MDIO_AN_EEE_ADV_100TX; |
| 3872 | /* Advertise 1000-BaseT EEE ability */ |
| 3873 | if (advertise & ADVERTISED_1000baseT_Full) |
| 3874 | val |= MDIO_AN_EEE_ADV_1000T; |
| 3875 | err = tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 3876 | if (err) |
| 3877 | val = 0; |
| 3878 | |
| 3879 | switch (GET_ASIC_REV(tp->pci_chip_rev_id)) { |
| 3880 | case ASIC_REV_5717: |
| 3881 | case ASIC_REV_57765: |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 3882 | case ASIC_REV_57766: |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 3883 | case ASIC_REV_5719: |
| 3884 | /* If we advertised any eee advertisements above... */ |
| 3885 | if (val) |
| 3886 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 3887 | MII_TG3_DSP_TAP26_RMRXSTO | |
| 3888 | MII_TG3_DSP_TAP26_OPCSINPT; |
| 3889 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 3890 | /* Fall through */ |
| 3891 | case ASIC_REV_5720: |
| 3892 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 3893 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | |
| 3894 | MII_TG3_DSP_CH34TP2_HIBW01); |
| 3895 | } |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3896 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3897 | err2 = TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 3898 | if (!err) |
| 3899 | err = err2; |
| 3900 | } |
| 3901 | |
| 3902 | done: |
| 3903 | return err; |
| 3904 | } |
| 3905 | |
| 3906 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 3907 | { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3908 | if (tp->link_config.autoneg == AUTONEG_ENABLE || |
| 3909 | (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 3910 | u32 adv, fc; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3911 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3912 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 3913 | adv = ADVERTISED_10baseT_Half | |
| 3914 | ADVERTISED_10baseT_Full; |
| 3915 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
| 3916 | adv |= ADVERTISED_100baseT_Half | |
| 3917 | ADVERTISED_100baseT_Full; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3918 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3919 | fc = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3920 | } else { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3921 | adv = tp->link_config.advertising; |
| 3922 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 3923 | adv &= ~(ADVERTISED_1000baseT_Half | |
| 3924 | ADVERTISED_1000baseT_Full); |
| 3925 | |
| 3926 | fc = tp->link_config.flowctrl; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3927 | } |
| 3928 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3929 | tg3_phy_autoneg_cfg(tp, adv, fc); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3930 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3931 | tg3_writephy(tp, MII_BMCR, |
| 3932 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 3933 | } else { |
| 3934 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | u32 bmcr, orig_bmcr; |
| 3936 | |
| 3937 | tp->link_config.active_speed = tp->link_config.speed; |
| 3938 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 3939 | |
| 3940 | bmcr = 0; |
| 3941 | switch (tp->link_config.speed) { |
| 3942 | default: |
| 3943 | case SPEED_10: |
| 3944 | break; |
| 3945 | |
| 3946 | case SPEED_100: |
| 3947 | bmcr |= BMCR_SPEED100; |
| 3948 | break; |
| 3949 | |
| 3950 | case SPEED_1000: |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 3951 | bmcr |= BMCR_SPEED1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3953 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | |
| 3955 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3956 | bmcr |= BMCR_FULLDPLX; |
| 3957 | |
| 3958 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 3959 | (bmcr != orig_bmcr)) { |
| 3960 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 3961 | for (i = 0; i < 1500; i++) { |
| 3962 | u32 tmp; |
| 3963 | |
| 3964 | udelay(10); |
| 3965 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 3966 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 3967 | continue; |
| 3968 | if (!(tmp & BMSR_LSTATUS)) { |
| 3969 | udelay(40); |
| 3970 | break; |
| 3971 | } |
| 3972 | } |
| 3973 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 3974 | udelay(40); |
| 3975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 3980 | { |
| 3981 | int err; |
| 3982 | |
| 3983 | /* Turn off tap power management. */ |
| 3984 | /* Set Extended packet length bit */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3985 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 3987 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 3988 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 3989 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 3990 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 3991 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | |
| 3993 | udelay(40); |
| 3994 | |
| 3995 | return err; |
| 3996 | } |
| 3997 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 3998 | static bool tg3_phy_copper_an_config_ok(struct tg3 *tp, u32 *lcladv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4000 | u32 advmsk, tgtadv, advertising; |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4001 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4002 | advertising = tp->link_config.advertising; |
| 4003 | tgtadv = ethtool_adv_to_mii_adv_t(advertising) & ADVERTISE_ALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4005 | advmsk = ADVERTISE_ALL; |
| 4006 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 4007 | tgtadv |= mii_advertise_flowctrl(tp->link_config.flowctrl); |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4008 | advmsk |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4011 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 4012 | return false; |
| 4013 | |
| 4014 | if ((*lcladv & advmsk) != tgtadv) |
| 4015 | return false; |
Matt Carlson | b99d2a5 | 2011-08-31 11:44:47 +0000 | [diff] [blame] | 4016 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4017 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | u32 tg3_ctrl; |
| 4019 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4020 | tgtadv = ethtool_adv_to_mii_ctrl1000_t(advertising); |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4021 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4022 | if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4023 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | |
Matt Carlson | 3198e07 | 2012-02-13 15:20:10 +0000 | [diff] [blame] | 4025 | if (tgtadv && |
| 4026 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4027 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) { |
| 4028 | tgtadv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
| 4029 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL | |
| 4030 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
| 4031 | } else { |
| 4032 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); |
| 4033 | } |
| 4034 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4035 | if (tg3_ctrl != tgtadv) |
| 4036 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | } |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 4038 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4039 | return true; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4042 | static bool tg3_phy_copper_fetch_rmtadv(struct tg3 *tp, u32 *rmtadv) |
| 4043 | { |
| 4044 | u32 lpeth = 0; |
| 4045 | |
| 4046 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4047 | u32 val; |
| 4048 | |
| 4049 | if (tg3_readphy(tp, MII_STAT1000, &val)) |
| 4050 | return false; |
| 4051 | |
| 4052 | lpeth = mii_stat1000_to_ethtool_lpa_t(val); |
| 4053 | } |
| 4054 | |
| 4055 | if (tg3_readphy(tp, MII_LPA, rmtadv)) |
| 4056 | return false; |
| 4057 | |
| 4058 | lpeth |= mii_lpa_to_ethtool_lpa_t(*rmtadv); |
| 4059 | tp->link_config.rmt_adv = lpeth; |
| 4060 | |
| 4061 | return true; |
| 4062 | } |
| 4063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 4065 | { |
| 4066 | int current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4067 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4068 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | u16 current_speed; |
| 4070 | u8 current_duplex; |
| 4071 | int i, err; |
| 4072 | |
| 4073 | tw32(MAC_EVENT, 0); |
| 4074 | |
| 4075 | tw32_f(MAC_STATUS, |
| 4076 | (MAC_STATUS_SYNC_CHANGED | |
| 4077 | MAC_STATUS_CFG_CHANGED | |
| 4078 | MAC_STATUS_MI_COMPLETION | |
| 4079 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4080 | udelay(40); |
| 4081 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 4082 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 4083 | tw32_f(MAC_MI_MODE, |
| 4084 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 4085 | udelay(80); |
| 4086 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4088 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | |
| 4090 | /* Some third-party PHYs need to be reset on link going |
| 4091 | * down. |
| 4092 | */ |
| 4093 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 4094 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 4095 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 4096 | netif_carrier_ok(tp->dev)) { |
| 4097 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4098 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4099 | !(bmsr & BMSR_LSTATUS)) |
| 4100 | force_reset = 1; |
| 4101 | } |
| 4102 | if (force_reset) |
| 4103 | tg3_phy_reset(tp); |
| 4104 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4105 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4107 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4108 | !tg3_flag(tp, INIT_COMPLETE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | bmsr = 0; |
| 4110 | |
| 4111 | if (!(bmsr & BMSR_LSTATUS)) { |
| 4112 | err = tg3_init_5401phy_dsp(tp); |
| 4113 | if (err) |
| 4114 | return err; |
| 4115 | |
| 4116 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4117 | for (i = 0; i < 1000; i++) { |
| 4118 | udelay(10); |
| 4119 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4120 | (bmsr & BMSR_LSTATUS)) { |
| 4121 | udelay(40); |
| 4122 | break; |
| 4123 | } |
| 4124 | } |
| 4125 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4126 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 4127 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | !(bmsr & BMSR_LSTATUS) && |
| 4129 | tp->link_config.active_speed == SPEED_1000) { |
| 4130 | err = tg3_phy_reset(tp); |
| 4131 | if (!err) |
| 4132 | err = tg3_init_5401phy_dsp(tp); |
| 4133 | if (err) |
| 4134 | return err; |
| 4135 | } |
| 4136 | } |
| 4137 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4138 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 4139 | /* 5701 {A0,B0} CRC bug workaround */ |
| 4140 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4141 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 4142 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 4143 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | } |
| 4145 | |
| 4146 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4147 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 4148 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4150 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4152 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 4154 | |
| 4155 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 4156 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 4157 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 4158 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 4159 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 4160 | else |
| 4161 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 4162 | } |
| 4163 | |
| 4164 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 4165 | current_speed = SPEED_UNKNOWN; |
| 4166 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4167 | tp->phy_flags &= ~TG3_PHYFLG_MDIX_STATE; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4168 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4170 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 4171 | err = tg3_phy_auxctl_read(tp, |
| 4172 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4173 | &val); |
| 4174 | if (!err && !(val & (1 << 10))) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4175 | tg3_phy_auxctl_write(tp, |
| 4176 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4177 | val | (1 << 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | goto relink; |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | bmsr = 0; |
| 4183 | for (i = 0; i < 100; i++) { |
| 4184 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4185 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4186 | (bmsr & BMSR_LSTATUS)) |
| 4187 | break; |
| 4188 | udelay(40); |
| 4189 | } |
| 4190 | |
| 4191 | if (bmsr & BMSR_LSTATUS) { |
| 4192 | u32 aux_stat, bmcr; |
| 4193 | |
| 4194 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 4195 | for (i = 0; i < 2000; i++) { |
| 4196 | udelay(10); |
| 4197 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 4198 | aux_stat) |
| 4199 | break; |
| 4200 | } |
| 4201 | |
| 4202 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 4203 | ¤t_speed, |
| 4204 | ¤t_duplex); |
| 4205 | |
| 4206 | bmcr = 0; |
| 4207 | for (i = 0; i < 200; i++) { |
| 4208 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4209 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 4210 | continue; |
| 4211 | if (bmcr && bmcr != 0x7fff) |
| 4212 | break; |
| 4213 | udelay(10); |
| 4214 | } |
| 4215 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4216 | lcl_adv = 0; |
| 4217 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4219 | tp->link_config.active_speed = current_speed; |
| 4220 | tp->link_config.active_duplex = current_duplex; |
| 4221 | |
| 4222 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4223 | if ((bmcr & BMCR_ANENABLE) && |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4224 | tg3_phy_copper_an_config_ok(tp, &lcl_adv) && |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4225 | tg3_phy_copper_fetch_rmtadv(tp, &rmt_adv)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4226 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | } else { |
| 4228 | if (!(bmcr & BMCR_ANENABLE) && |
| 4229 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4230 | tp->link_config.duplex == current_duplex && |
| 4231 | tp->link_config.flowctrl == |
| 4232 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | } |
| 4235 | } |
| 4236 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4237 | if (current_link_up == 1 && |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4238 | tp->link_config.active_duplex == DUPLEX_FULL) { |
| 4239 | u32 reg, bit; |
| 4240 | |
| 4241 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 4242 | reg = MII_TG3_FET_GEN_STAT; |
| 4243 | bit = MII_TG3_FET_GEN_STAT_MDIXSTAT; |
| 4244 | } else { |
| 4245 | reg = MII_TG3_EXT_STAT; |
| 4246 | bit = MII_TG3_EXT_STAT_MDIX; |
| 4247 | } |
| 4248 | |
| 4249 | if (!tg3_readphy(tp, reg, &val) && (val & bit)) |
| 4250 | tp->phy_flags |= TG3_PHYFLG_MDIX_STATE; |
| 4251 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4252 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | relink: |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 4257 | if (current_link_up == 0 || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | tg3_phy_copper_begin(tp); |
| 4259 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4260 | tg3_readphy(tp, MII_BMSR, &bmsr); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 4261 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
| 4262 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | current_link_up = 1; |
| 4264 | } |
| 4265 | |
| 4266 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 4267 | if (current_link_up == 1) { |
| 4268 | if (tp->link_config.active_speed == SPEED_100 || |
| 4269 | tp->link_config.active_speed == SPEED_10) |
| 4270 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4271 | else |
| 4272 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4273 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 4274 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4275 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4277 | |
| 4278 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4279 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4280 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4283 | if (current_link_up == 1 && |
| 4284 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4286 | else |
| 4287 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /* ??? Without this setting Netgear GA302T PHY does not |
| 4291 | * ??? send/receive packets... |
| 4292 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4293 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 4295 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 4296 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 4297 | udelay(80); |
| 4298 | } |
| 4299 | |
| 4300 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4301 | udelay(40); |
| 4302 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4303 | tg3_phy_eee_adjust(tp, current_link_up); |
| 4304 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4305 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | /* Polled via timer. */ |
| 4307 | tw32_f(MAC_EVENT, 0); |
| 4308 | } else { |
| 4309 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4310 | } |
| 4311 | udelay(40); |
| 4312 | |
| 4313 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 4314 | current_link_up == 1 && |
| 4315 | tp->link_config.active_speed == SPEED_1000 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4316 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | udelay(120); |
| 4318 | tw32_f(MAC_STATUS, |
| 4319 | (MAC_STATUS_SYNC_CHANGED | |
| 4320 | MAC_STATUS_CFG_CHANGED)); |
| 4321 | udelay(40); |
| 4322 | tg3_write_mem(tp, |
| 4323 | NIC_SRAM_FIRMWARE_MBOX, |
| 4324 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 4325 | } |
| 4326 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4327 | /* Prevent send BD corruption. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4328 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4329 | u16 oldlnkctl, newlnkctl; |
| 4330 | |
| 4331 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 4332 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4333 | &oldlnkctl); |
| 4334 | if (tp->link_config.active_speed == SPEED_100 || |
| 4335 | tp->link_config.active_speed == SPEED_10) |
| 4336 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4337 | else |
| 4338 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4339 | if (newlnkctl != oldlnkctl) |
| 4340 | pci_write_config_word(tp->pdev, |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 4341 | pci_pcie_cap(tp->pdev) + |
| 4342 | PCI_EXP_LNKCTL, newlnkctl); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4343 | } |
| 4344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4346 | if (current_link_up) |
| 4347 | netif_carrier_on(tp->dev); |
| 4348 | else |
| 4349 | netif_carrier_off(tp->dev); |
| 4350 | tg3_link_report(tp); |
| 4351 | } |
| 4352 | |
| 4353 | return 0; |
| 4354 | } |
| 4355 | |
| 4356 | struct tg3_fiber_aneginfo { |
| 4357 | int state; |
| 4358 | #define ANEG_STATE_UNKNOWN 0 |
| 4359 | #define ANEG_STATE_AN_ENABLE 1 |
| 4360 | #define ANEG_STATE_RESTART_INIT 2 |
| 4361 | #define ANEG_STATE_RESTART 3 |
| 4362 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 4363 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 4364 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 4365 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 4366 | #define ANEG_STATE_ACK_DETECT 8 |
| 4367 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 4368 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 4369 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 4370 | #define ANEG_STATE_IDLE_DETECT 12 |
| 4371 | #define ANEG_STATE_LINK_OK 13 |
| 4372 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 4373 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 4374 | |
| 4375 | u32 flags; |
| 4376 | #define MR_AN_ENABLE 0x00000001 |
| 4377 | #define MR_RESTART_AN 0x00000002 |
| 4378 | #define MR_AN_COMPLETE 0x00000004 |
| 4379 | #define MR_PAGE_RX 0x00000008 |
| 4380 | #define MR_NP_LOADED 0x00000010 |
| 4381 | #define MR_TOGGLE_TX 0x00000020 |
| 4382 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 4383 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 4384 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 4385 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 4386 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 4387 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 4388 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 4389 | #define MR_TOGGLE_RX 0x00002000 |
| 4390 | #define MR_NP_RX 0x00004000 |
| 4391 | |
| 4392 | #define MR_LINK_OK 0x80000000 |
| 4393 | |
| 4394 | unsigned long link_time, cur_time; |
| 4395 | |
| 4396 | u32 ability_match_cfg; |
| 4397 | int ability_match_count; |
| 4398 | |
| 4399 | char ability_match, idle_match, ack_match; |
| 4400 | |
| 4401 | u32 txconfig, rxconfig; |
| 4402 | #define ANEG_CFG_NP 0x00000080 |
| 4403 | #define ANEG_CFG_ACK 0x00000040 |
| 4404 | #define ANEG_CFG_RF2 0x00000020 |
| 4405 | #define ANEG_CFG_RF1 0x00000010 |
| 4406 | #define ANEG_CFG_PS2 0x00000001 |
| 4407 | #define ANEG_CFG_PS1 0x00008000 |
| 4408 | #define ANEG_CFG_HD 0x00004000 |
| 4409 | #define ANEG_CFG_FD 0x00002000 |
| 4410 | #define ANEG_CFG_INVAL 0x00001f06 |
| 4411 | |
| 4412 | }; |
| 4413 | #define ANEG_OK 0 |
| 4414 | #define ANEG_DONE 1 |
| 4415 | #define ANEG_TIMER_ENAB 2 |
| 4416 | #define ANEG_FAILED -1 |
| 4417 | |
| 4418 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 4419 | |
| 4420 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 4421 | struct tg3_fiber_aneginfo *ap) |
| 4422 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4423 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | unsigned long delta; |
| 4425 | u32 rx_cfg_reg; |
| 4426 | int ret; |
| 4427 | |
| 4428 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 4429 | ap->rxconfig = 0; |
| 4430 | ap->link_time = 0; |
| 4431 | ap->cur_time = 0; |
| 4432 | ap->ability_match_cfg = 0; |
| 4433 | ap->ability_match_count = 0; |
| 4434 | ap->ability_match = 0; |
| 4435 | ap->idle_match = 0; |
| 4436 | ap->ack_match = 0; |
| 4437 | } |
| 4438 | ap->cur_time++; |
| 4439 | |
| 4440 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 4441 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 4442 | |
| 4443 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 4444 | ap->ability_match_cfg = rx_cfg_reg; |
| 4445 | ap->ability_match = 0; |
| 4446 | ap->ability_match_count = 0; |
| 4447 | } else { |
| 4448 | if (++ap->ability_match_count > 1) { |
| 4449 | ap->ability_match = 1; |
| 4450 | ap->ability_match_cfg = rx_cfg_reg; |
| 4451 | } |
| 4452 | } |
| 4453 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 4454 | ap->ack_match = 1; |
| 4455 | else |
| 4456 | ap->ack_match = 0; |
| 4457 | |
| 4458 | ap->idle_match = 0; |
| 4459 | } else { |
| 4460 | ap->idle_match = 1; |
| 4461 | ap->ability_match_cfg = 0; |
| 4462 | ap->ability_match_count = 0; |
| 4463 | ap->ability_match = 0; |
| 4464 | ap->ack_match = 0; |
| 4465 | |
| 4466 | rx_cfg_reg = 0; |
| 4467 | } |
| 4468 | |
| 4469 | ap->rxconfig = rx_cfg_reg; |
| 4470 | ret = ANEG_OK; |
| 4471 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 4472 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | case ANEG_STATE_UNKNOWN: |
| 4474 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 4475 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4476 | |
| 4477 | /* fallthru */ |
| 4478 | case ANEG_STATE_AN_ENABLE: |
| 4479 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 4480 | if (ap->flags & MR_AN_ENABLE) { |
| 4481 | ap->link_time = 0; |
| 4482 | ap->cur_time = 0; |
| 4483 | ap->ability_match_cfg = 0; |
| 4484 | ap->ability_match_count = 0; |
| 4485 | ap->ability_match = 0; |
| 4486 | ap->idle_match = 0; |
| 4487 | ap->ack_match = 0; |
| 4488 | |
| 4489 | ap->state = ANEG_STATE_RESTART_INIT; |
| 4490 | } else { |
| 4491 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 4492 | } |
| 4493 | break; |
| 4494 | |
| 4495 | case ANEG_STATE_RESTART_INIT: |
| 4496 | ap->link_time = ap->cur_time; |
| 4497 | ap->flags &= ~(MR_NP_LOADED); |
| 4498 | ap->txconfig = 0; |
| 4499 | tw32(MAC_TX_AUTO_NEG, 0); |
| 4500 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4501 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4502 | udelay(40); |
| 4503 | |
| 4504 | ret = ANEG_TIMER_ENAB; |
| 4505 | ap->state = ANEG_STATE_RESTART; |
| 4506 | |
| 4507 | /* fallthru */ |
| 4508 | case ANEG_STATE_RESTART: |
| 4509 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4510 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4512 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | break; |
| 4515 | |
| 4516 | case ANEG_STATE_DISABLE_LINK_OK: |
| 4517 | ret = ANEG_DONE; |
| 4518 | break; |
| 4519 | |
| 4520 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 4521 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4522 | ap->txconfig = ANEG_CFG_FD; |
| 4523 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4524 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4525 | ap->txconfig |= ANEG_CFG_PS1; |
| 4526 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4527 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4529 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4530 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4531 | udelay(40); |
| 4532 | |
| 4533 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 4534 | break; |
| 4535 | |
| 4536 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4537 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | break; |
| 4540 | |
| 4541 | case ANEG_STATE_ACK_DETECT_INIT: |
| 4542 | ap->txconfig |= ANEG_CFG_ACK; |
| 4543 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4544 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4545 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4546 | udelay(40); |
| 4547 | |
| 4548 | ap->state = ANEG_STATE_ACK_DETECT; |
| 4549 | |
| 4550 | /* fallthru */ |
| 4551 | case ANEG_STATE_ACK_DETECT: |
| 4552 | if (ap->ack_match != 0) { |
| 4553 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 4554 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 4555 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 4556 | } else { |
| 4557 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4558 | } |
| 4559 | } else if (ap->ability_match != 0 && |
| 4560 | ap->rxconfig == 0) { |
| 4561 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4562 | } |
| 4563 | break; |
| 4564 | |
| 4565 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 4566 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 4567 | ret = ANEG_FAILED; |
| 4568 | break; |
| 4569 | } |
| 4570 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 4571 | MR_LP_ADV_HALF_DUPLEX | |
| 4572 | MR_LP_ADV_SYM_PAUSE | |
| 4573 | MR_LP_ADV_ASYM_PAUSE | |
| 4574 | MR_LP_ADV_REMOTE_FAULT1 | |
| 4575 | MR_LP_ADV_REMOTE_FAULT2 | |
| 4576 | MR_LP_ADV_NEXT_PAGE | |
| 4577 | MR_TOGGLE_RX | |
| 4578 | MR_NP_RX); |
| 4579 | if (ap->rxconfig & ANEG_CFG_FD) |
| 4580 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 4581 | if (ap->rxconfig & ANEG_CFG_HD) |
| 4582 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 4583 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 4584 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 4585 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 4586 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 4587 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 4588 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 4589 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 4590 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 4591 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4592 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 4593 | |
| 4594 | ap->link_time = ap->cur_time; |
| 4595 | |
| 4596 | ap->flags ^= (MR_TOGGLE_TX); |
| 4597 | if (ap->rxconfig & 0x0008) |
| 4598 | ap->flags |= MR_TOGGLE_RX; |
| 4599 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4600 | ap->flags |= MR_NP_RX; |
| 4601 | ap->flags |= MR_PAGE_RX; |
| 4602 | |
| 4603 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 4604 | ret = ANEG_TIMER_ENAB; |
| 4605 | break; |
| 4606 | |
| 4607 | case ANEG_STATE_COMPLETE_ACK: |
| 4608 | if (ap->ability_match != 0 && |
| 4609 | ap->rxconfig == 0) { |
| 4610 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4611 | break; |
| 4612 | } |
| 4613 | delta = ap->cur_time - ap->link_time; |
| 4614 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4615 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 4616 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4617 | } else { |
| 4618 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 4619 | !(ap->flags & MR_NP_RX)) { |
| 4620 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4621 | } else { |
| 4622 | ret = ANEG_FAILED; |
| 4623 | } |
| 4624 | } |
| 4625 | } |
| 4626 | break; |
| 4627 | |
| 4628 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 4629 | ap->link_time = ap->cur_time; |
| 4630 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4631 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4632 | udelay(40); |
| 4633 | |
| 4634 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 4635 | ret = ANEG_TIMER_ENAB; |
| 4636 | break; |
| 4637 | |
| 4638 | case ANEG_STATE_IDLE_DETECT: |
| 4639 | if (ap->ability_match != 0 && |
| 4640 | ap->rxconfig == 0) { |
| 4641 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4642 | break; |
| 4643 | } |
| 4644 | delta = ap->cur_time - ap->link_time; |
| 4645 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4646 | /* XXX another gem from the Broadcom driver :( */ |
| 4647 | ap->state = ANEG_STATE_LINK_OK; |
| 4648 | } |
| 4649 | break; |
| 4650 | |
| 4651 | case ANEG_STATE_LINK_OK: |
| 4652 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 4653 | ret = ANEG_DONE; |
| 4654 | break; |
| 4655 | |
| 4656 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 4657 | /* ??? unimplemented */ |
| 4658 | break; |
| 4659 | |
| 4660 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 4661 | /* ??? unimplemented */ |
| 4662 | break; |
| 4663 | |
| 4664 | default: |
| 4665 | ret = ANEG_FAILED; |
| 4666 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | |
| 4669 | return ret; |
| 4670 | } |
| 4671 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4672 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | { |
| 4674 | int res = 0; |
| 4675 | struct tg3_fiber_aneginfo aninfo; |
| 4676 | int status = ANEG_FAILED; |
| 4677 | unsigned int tick; |
| 4678 | u32 tmp; |
| 4679 | |
| 4680 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 4681 | |
| 4682 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 4683 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 4684 | udelay(40); |
| 4685 | |
| 4686 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 4687 | udelay(40); |
| 4688 | |
| 4689 | memset(&aninfo, 0, sizeof(aninfo)); |
| 4690 | aninfo.flags |= MR_AN_ENABLE; |
| 4691 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 4692 | aninfo.cur_time = 0; |
| 4693 | tick = 0; |
| 4694 | while (++tick < 195000) { |
| 4695 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 4696 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 4697 | break; |
| 4698 | |
| 4699 | udelay(1); |
| 4700 | } |
| 4701 | |
| 4702 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4703 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4704 | udelay(40); |
| 4705 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4706 | *txflags = aninfo.txconfig; |
| 4707 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | |
| 4709 | if (status == ANEG_DONE && |
| 4710 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 4711 | MR_LP_ADV_FULL_DUPLEX))) |
| 4712 | res = 1; |
| 4713 | |
| 4714 | return res; |
| 4715 | } |
| 4716 | |
| 4717 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 4718 | { |
| 4719 | u32 mac_status = tr32(MAC_STATUS); |
| 4720 | int i; |
| 4721 | |
| 4722 | /* Reset when initting first time or we have a link. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4723 | if (tg3_flag(tp, INIT_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 4725 | return; |
| 4726 | |
| 4727 | /* Set PLL lock range. */ |
| 4728 | tg3_writephy(tp, 0x16, 0x8007); |
| 4729 | |
| 4730 | /* SW reset */ |
| 4731 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 4732 | |
| 4733 | /* Wait for reset to complete. */ |
| 4734 | /* XXX schedule_timeout() ... */ |
| 4735 | for (i = 0; i < 500; i++) |
| 4736 | udelay(10); |
| 4737 | |
| 4738 | /* Config mode; select PMA/Ch 1 regs. */ |
| 4739 | tg3_writephy(tp, 0x10, 0x8411); |
| 4740 | |
| 4741 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 4742 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4743 | |
| 4744 | tg3_writephy(tp, 0x18, 0x00a0); |
| 4745 | tg3_writephy(tp, 0x16, 0x41ff); |
| 4746 | |
| 4747 | /* Assert and deassert POR. */ |
| 4748 | tg3_writephy(tp, 0x13, 0x0400); |
| 4749 | udelay(40); |
| 4750 | tg3_writephy(tp, 0x13, 0x0000); |
| 4751 | |
| 4752 | tg3_writephy(tp, 0x11, 0x0a50); |
| 4753 | udelay(40); |
| 4754 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4755 | |
| 4756 | /* Wait for signal to stabilize */ |
| 4757 | /* XXX schedule_timeout() ... */ |
| 4758 | for (i = 0; i < 15000; i++) |
| 4759 | udelay(10); |
| 4760 | |
| 4761 | /* Deselect the channel register so we can read the PHYID |
| 4762 | * later. |
| 4763 | */ |
| 4764 | tg3_writephy(tp, 0x10, 0x8011); |
| 4765 | } |
| 4766 | |
| 4767 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 4768 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4769 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | u32 sg_dig_ctrl, sg_dig_status; |
| 4771 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 4772 | int workaround, port_a; |
| 4773 | int current_link_up; |
| 4774 | |
| 4775 | serdes_cfg = 0; |
| 4776 | expected_sg_dig_ctrl = 0; |
| 4777 | workaround = 0; |
| 4778 | port_a = 1; |
| 4779 | current_link_up = 0; |
| 4780 | |
| 4781 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 4782 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 4783 | workaround = 1; |
| 4784 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 4785 | port_a = 0; |
| 4786 | |
| 4787 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 4788 | /* preserve bits 20-23 for voltage regulator */ |
| 4789 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 4790 | } |
| 4791 | |
| 4792 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 4793 | |
| 4794 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4795 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | if (workaround) { |
| 4797 | u32 val = serdes_cfg; |
| 4798 | |
| 4799 | if (port_a) |
| 4800 | val |= 0xc010000; |
| 4801 | else |
| 4802 | val |= 0x4010000; |
| 4803 | tw32_f(MAC_SERDES_CFG, val); |
| 4804 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4805 | |
| 4806 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | } |
| 4808 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 4809 | tg3_setup_flow_control(tp, 0, 0); |
| 4810 | current_link_up = 1; |
| 4811 | } |
| 4812 | goto out; |
| 4813 | } |
| 4814 | |
| 4815 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4816 | expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4818 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4819 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4820 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 4821 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4822 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | |
| 4824 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4825 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4826 | tp->serdes_counter && |
| 4827 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 4828 | MAC_STATUS_RCVD_CFG)) == |
| 4829 | MAC_STATUS_PCS_SYNCED)) { |
| 4830 | tp->serdes_counter--; |
| 4831 | current_link_up = 1; |
| 4832 | goto out; |
| 4833 | } |
| 4834 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | if (workaround) |
| 4836 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4837 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | udelay(5); |
| 4839 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 4840 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4841 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4842 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 4844 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4845 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | mac_status = tr32(MAC_STATUS); |
| 4847 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4848 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4850 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4852 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 4853 | local_adv |= ADVERTISE_1000XPAUSE; |
| 4854 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 4855 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 4856 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4857 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4858 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4859 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4860 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4862 | tp->link_config.rmt_adv = |
| 4863 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 4864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4866 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4867 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4868 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4869 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4870 | if (tp->serdes_counter) |
| 4871 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | else { |
| 4873 | if (workaround) { |
| 4874 | u32 val = serdes_cfg; |
| 4875 | |
| 4876 | if (port_a) |
| 4877 | val |= 0xc010000; |
| 4878 | else |
| 4879 | val |= 0x4010000; |
| 4880 | |
| 4881 | tw32_f(MAC_SERDES_CFG, val); |
| 4882 | } |
| 4883 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4884 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | udelay(40); |
| 4886 | |
| 4887 | /* Link parallel detection - link is up */ |
| 4888 | /* only if we have PCS_SYNC and not */ |
| 4889 | /* receiving config code words */ |
| 4890 | mac_status = tr32(MAC_STATUS); |
| 4891 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4892 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 4893 | tg3_setup_flow_control(tp, 0, 0); |
| 4894 | current_link_up = 1; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4895 | tp->phy_flags |= |
| 4896 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4897 | tp->serdes_counter = |
| 4898 | SERDES_PARALLEL_DET_TIMEOUT; |
| 4899 | } else |
| 4900 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | } |
| 4902 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4903 | } else { |
| 4904 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4905 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | out: |
| 4909 | return current_link_up; |
| 4910 | } |
| 4911 | |
| 4912 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 4913 | { |
| 4914 | int current_link_up = 0; |
| 4915 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 4916 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | |
| 4919 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4920 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 4922 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4923 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 4924 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4926 | if (txflags & ANEG_CFG_PS1) |
| 4927 | local_adv |= ADVERTISE_1000XPAUSE; |
| 4928 | if (txflags & ANEG_CFG_PS2) |
| 4929 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 4930 | |
| 4931 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 4932 | remote_adv |= LPA_1000XPAUSE; |
| 4933 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 4934 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4936 | tp->link_config.rmt_adv = |
| 4937 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 4938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | current_link_up = 1; |
| 4942 | } |
| 4943 | for (i = 0; i < 30; i++) { |
| 4944 | udelay(20); |
| 4945 | tw32_f(MAC_STATUS, |
| 4946 | (MAC_STATUS_SYNC_CHANGED | |
| 4947 | MAC_STATUS_CFG_CHANGED)); |
| 4948 | udelay(40); |
| 4949 | if ((tr32(MAC_STATUS) & |
| 4950 | (MAC_STATUS_SYNC_CHANGED | |
| 4951 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 4952 | break; |
| 4953 | } |
| 4954 | |
| 4955 | mac_status = tr32(MAC_STATUS); |
| 4956 | if (current_link_up == 0 && |
| 4957 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4958 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 4959 | current_link_up = 1; |
| 4960 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4961 | tg3_setup_flow_control(tp, 0, 0); |
| 4962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | /* Forcing 1000FD link up. */ |
| 4964 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | |
| 4966 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 4967 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4968 | |
| 4969 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4970 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | out: |
| 4974 | return current_link_up; |
| 4975 | } |
| 4976 | |
| 4977 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 4978 | { |
| 4979 | u32 orig_pause_cfg; |
| 4980 | u16 orig_active_speed; |
| 4981 | u8 orig_active_duplex; |
| 4982 | u32 mac_status; |
| 4983 | int current_link_up; |
| 4984 | int i; |
| 4985 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4986 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4987 | orig_active_speed = tp->link_config.active_speed; |
| 4988 | orig_active_duplex = tp->link_config.active_duplex; |
| 4989 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4990 | if (!tg3_flag(tp, HW_AUTONEG) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4991 | netif_carrier_ok(tp->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4992 | tg3_flag(tp, INIT_COMPLETE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | mac_status = tr32(MAC_STATUS); |
| 4994 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 4995 | MAC_STATUS_SIGNAL_DET | |
| 4996 | MAC_STATUS_CFG_CHANGED | |
| 4997 | MAC_STATUS_RCVD_CFG); |
| 4998 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 4999 | MAC_STATUS_SIGNAL_DET)) { |
| 5000 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5001 | MAC_STATUS_CFG_CHANGED)); |
| 5002 | return 0; |
| 5003 | } |
| 5004 | } |
| 5005 | |
| 5006 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5007 | |
| 5008 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 5009 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 5010 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5011 | udelay(40); |
| 5012 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 5013 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | tg3_init_bcm8002(tp); |
| 5015 | |
| 5016 | /* Enable link change event even when serdes polling. */ |
| 5017 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5018 | udelay(40); |
| 5019 | |
| 5020 | current_link_up = 0; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5021 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | mac_status = tr32(MAC_STATUS); |
| 5023 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5024 | if (tg3_flag(tp, HW_AUTONEG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 5026 | else |
| 5027 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 5028 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5029 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5031 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | |
| 5033 | for (i = 0; i < 100; i++) { |
| 5034 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5035 | MAC_STATUS_CFG_CHANGED)); |
| 5036 | udelay(5); |
| 5037 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5038 | MAC_STATUS_CFG_CHANGED | |
| 5039 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | break; |
| 5041 | } |
| 5042 | |
| 5043 | mac_status = tr32(MAC_STATUS); |
| 5044 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 5045 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5046 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 5047 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 5049 | MAC_MODE_SEND_CONFIGS)); |
| 5050 | udelay(1); |
| 5051 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5052 | } |
| 5053 | } |
| 5054 | |
| 5055 | if (current_link_up == 1) { |
| 5056 | tp->link_config.active_speed = SPEED_1000; |
| 5057 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 5058 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5059 | LED_CTRL_LNKLED_OVERRIDE | |
| 5060 | LED_CTRL_1000MBPS_ON)); |
| 5061 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5062 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 5063 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5065 | LED_CTRL_LNKLED_OVERRIDE | |
| 5066 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 5067 | } |
| 5068 | |
| 5069 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 5070 | if (current_link_up) |
| 5071 | netif_carrier_on(tp->dev); |
| 5072 | else |
| 5073 | netif_carrier_off(tp->dev); |
| 5074 | tg3_link_report(tp); |
| 5075 | } else { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5076 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | if (orig_pause_cfg != now_pause_cfg || |
| 5078 | orig_active_speed != tp->link_config.active_speed || |
| 5079 | orig_active_duplex != tp->link_config.active_duplex) |
| 5080 | tg3_link_report(tp); |
| 5081 | } |
| 5082 | |
| 5083 | return 0; |
| 5084 | } |
| 5085 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5086 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 5087 | { |
| 5088 | int current_link_up, err = 0; |
| 5089 | u32 bmsr, bmcr; |
| 5090 | u16 current_speed; |
| 5091 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5092 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5093 | |
| 5094 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5095 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5096 | udelay(40); |
| 5097 | |
| 5098 | tw32(MAC_EVENT, 0); |
| 5099 | |
| 5100 | tw32_f(MAC_STATUS, |
| 5101 | (MAC_STATUS_SYNC_CHANGED | |
| 5102 | MAC_STATUS_CFG_CHANGED | |
| 5103 | MAC_STATUS_MI_COMPLETION | |
| 5104 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 5105 | udelay(40); |
| 5106 | |
| 5107 | if (force_reset) |
| 5108 | tg3_phy_reset(tp); |
| 5109 | |
| 5110 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5111 | current_speed = SPEED_UNKNOWN; |
| 5112 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5113 | tp->link_config.rmt_adv = 0; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5114 | |
| 5115 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5116 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5117 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 5118 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5119 | bmsr |= BMSR_LSTATUS; |
| 5120 | else |
| 5121 | bmsr &= ~BMSR_LSTATUS; |
| 5122 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5123 | |
| 5124 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5125 | |
| 5126 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5127 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5128 | /* do nothing, just check for link up at the end */ |
| 5129 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5130 | u32 adv, newadv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5131 | |
| 5132 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5133 | newadv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 5134 | ADVERTISE_1000XPAUSE | |
| 5135 | ADVERTISE_1000XPSE_ASYM | |
| 5136 | ADVERTISE_SLCT); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5137 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5138 | newadv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Matt Carlson | 37f0702 | 2011-11-17 14:30:55 +0000 | [diff] [blame] | 5139 | newadv |= ethtool_adv_to_mii_adv_x(tp->link_config.advertising); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5140 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5141 | if ((newadv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 5142 | tg3_writephy(tp, MII_ADVERTISE, newadv); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5143 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 5144 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 5145 | |
| 5146 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5147 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5148 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5149 | |
| 5150 | return err; |
| 5151 | } |
| 5152 | } else { |
| 5153 | u32 new_bmcr; |
| 5154 | |
| 5155 | bmcr &= ~BMCR_SPEED1000; |
| 5156 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5157 | |
| 5158 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 5159 | new_bmcr |= BMCR_FULLDPLX; |
| 5160 | |
| 5161 | if (new_bmcr != bmcr) { |
| 5162 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 5163 | * to be set on write. |
| 5164 | */ |
| 5165 | new_bmcr |= BMCR_SPEED1000; |
| 5166 | |
| 5167 | /* Force a linkdown */ |
| 5168 | if (netif_carrier_ok(tp->dev)) { |
| 5169 | u32 adv; |
| 5170 | |
| 5171 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 5172 | adv &= ~(ADVERTISE_1000XFULL | |
| 5173 | ADVERTISE_1000XHALF | |
| 5174 | ADVERTISE_SLCT); |
| 5175 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 5176 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 5177 | BMCR_ANRESTART | |
| 5178 | BMCR_ANENABLE); |
| 5179 | udelay(10); |
| 5180 | netif_carrier_off(tp->dev); |
| 5181 | } |
| 5182 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 5183 | bmcr = new_bmcr; |
| 5184 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5185 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5186 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 5187 | ASIC_REV_5714) { |
| 5188 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5189 | bmsr |= BMSR_LSTATUS; |
| 5190 | else |
| 5191 | bmsr &= ~BMSR_LSTATUS; |
| 5192 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5193 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | if (bmsr & BMSR_LSTATUS) { |
| 5198 | current_speed = SPEED_1000; |
| 5199 | current_link_up = 1; |
| 5200 | if (bmcr & BMCR_FULLDPLX) |
| 5201 | current_duplex = DUPLEX_FULL; |
| 5202 | else |
| 5203 | current_duplex = DUPLEX_HALF; |
| 5204 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5205 | local_adv = 0; |
| 5206 | remote_adv = 0; |
| 5207 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5208 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5209 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5210 | |
| 5211 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 5212 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 5213 | common = local_adv & remote_adv; |
| 5214 | if (common & (ADVERTISE_1000XHALF | |
| 5215 | ADVERTISE_1000XFULL)) { |
| 5216 | if (common & ADVERTISE_1000XFULL) |
| 5217 | current_duplex = DUPLEX_FULL; |
| 5218 | else |
| 5219 | current_duplex = DUPLEX_HALF; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5220 | |
| 5221 | tp->link_config.rmt_adv = |
| 5222 | mii_adv_to_ethtool_adv_x(remote_adv); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5223 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 5224 | /* Link is up via parallel detect */ |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5225 | } else { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5226 | current_link_up = 0; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5227 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5228 | } |
| 5229 | } |
| 5230 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5231 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 5232 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5233 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5234 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 5235 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 5236 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 5237 | |
| 5238 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5239 | udelay(40); |
| 5240 | |
| 5241 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5242 | |
| 5243 | tp->link_config.active_speed = current_speed; |
| 5244 | tp->link_config.active_duplex = current_duplex; |
| 5245 | |
| 5246 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 5247 | if (current_link_up) |
| 5248 | netif_carrier_on(tp->dev); |
| 5249 | else { |
| 5250 | netif_carrier_off(tp->dev); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5251 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5252 | } |
| 5253 | tg3_link_report(tp); |
| 5254 | } |
| 5255 | return err; |
| 5256 | } |
| 5257 | |
| 5258 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 5259 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5260 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5261 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5262 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5263 | return; |
| 5264 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5265 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5266 | if (!netif_carrier_ok(tp->dev) && |
| 5267 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 5268 | u32 bmcr; |
| 5269 | |
| 5270 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5271 | if (bmcr & BMCR_ANENABLE) { |
| 5272 | u32 phy1, phy2; |
| 5273 | |
| 5274 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5275 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 5276 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5277 | |
| 5278 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5279 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5280 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5281 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 5282 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5283 | |
| 5284 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 5285 | /* We have signal detect and not receiving |
| 5286 | * config code words, link is up by parallel |
| 5287 | * detection. |
| 5288 | */ |
| 5289 | |
| 5290 | bmcr &= ~BMCR_ANENABLE; |
| 5291 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 5292 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5293 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5294 | } |
| 5295 | } |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5296 | } else if (netif_carrier_ok(tp->dev) && |
| 5297 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5298 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5299 | u32 phy2; |
| 5300 | |
| 5301 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5302 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5303 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5304 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5305 | if (phy2 & 0x20) { |
| 5306 | u32 bmcr; |
| 5307 | |
| 5308 | /* Config code words received, turn on autoneg. */ |
| 5309 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5310 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 5311 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5312 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5313 | |
| 5314 | } |
| 5315 | } |
| 5316 | } |
| 5317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 5319 | { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5320 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | int err; |
| 5322 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5323 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5325 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5326 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5327 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5329 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 5330 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5331 | u32 scale; |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 5332 | |
| 5333 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 5334 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 5335 | scale = 65; |
| 5336 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 5337 | scale = 6; |
| 5338 | else |
| 5339 | scale = 12; |
| 5340 | |
| 5341 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 5342 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 5343 | tw32(GRC_MISC_CFG, val); |
| 5344 | } |
| 5345 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5346 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 5347 | (6 << TX_LENGTHS_IPG_SHIFT); |
| 5348 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 5349 | val |= tr32(MAC_TX_LENGTHS) & |
| 5350 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 5351 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 5352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5353 | if (tp->link_config.active_speed == SPEED_1000 && |
| 5354 | tp->link_config.active_duplex == DUPLEX_HALF) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5355 | tw32(MAC_TX_LENGTHS, val | |
| 5356 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | else |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5358 | tw32(MAC_TX_LENGTHS, val | |
| 5359 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5361 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | if (netif_carrier_ok(tp->dev)) { |
| 5363 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 5364 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | } else { |
| 5366 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 5367 | } |
| 5368 | } |
| 5369 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5370 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5371 | val = tr32(PCIE_PWR_MGMT_THRESH); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 5372 | if (!netif_carrier_ok(tp->dev)) |
| 5373 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 5374 | tp->pwrmgmt_thresh; |
| 5375 | else |
| 5376 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 5377 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 5378 | } |
| 5379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 | return err; |
| 5381 | } |
| 5382 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 5383 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 5384 | { |
| 5385 | return tp->irq_sync; |
| 5386 | } |
| 5387 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5388 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
| 5389 | { |
| 5390 | int i; |
| 5391 | |
| 5392 | dst = (u32 *)((u8 *)dst + off); |
| 5393 | for (i = 0; i < len; i += sizeof(u32)) |
| 5394 | *dst++ = tr32(off + i); |
| 5395 | } |
| 5396 | |
| 5397 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) |
| 5398 | { |
| 5399 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); |
| 5400 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); |
| 5401 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); |
| 5402 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); |
| 5403 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); |
| 5404 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); |
| 5405 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); |
| 5406 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); |
| 5407 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); |
| 5408 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); |
| 5409 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); |
| 5410 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); |
| 5411 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 5412 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); |
| 5413 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); |
| 5414 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); |
| 5415 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); |
| 5416 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); |
| 5417 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); |
| 5418 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5419 | if (tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5420 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
| 5421 | |
| 5422 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); |
| 5423 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); |
| 5424 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); |
| 5425 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); |
| 5426 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); |
| 5427 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); |
| 5428 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); |
| 5429 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); |
| 5430 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5431 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5432 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
| 5433 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); |
| 5434 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); |
| 5435 | } |
| 5436 | |
| 5437 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); |
| 5438 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); |
| 5439 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); |
| 5440 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); |
| 5441 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); |
| 5442 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5443 | if (tg3_flag(tp, NVRAM)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5444 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
| 5445 | } |
| 5446 | |
| 5447 | static void tg3_dump_state(struct tg3 *tp) |
| 5448 | { |
| 5449 | int i; |
| 5450 | u32 *regs; |
| 5451 | |
| 5452 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); |
| 5453 | if (!regs) { |
| 5454 | netdev_err(tp->dev, "Failed allocating register dump buffer\n"); |
| 5455 | return; |
| 5456 | } |
| 5457 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5458 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5459 | /* Read up to but not including private PCI registers */ |
| 5460 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) |
| 5461 | regs[i / sizeof(u32)] = tr32(i); |
| 5462 | } else |
| 5463 | tg3_dump_legacy_regs(tp, regs); |
| 5464 | |
| 5465 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { |
| 5466 | if (!regs[i + 0] && !regs[i + 1] && |
| 5467 | !regs[i + 2] && !regs[i + 3]) |
| 5468 | continue; |
| 5469 | |
| 5470 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", |
| 5471 | i * 4, |
| 5472 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); |
| 5473 | } |
| 5474 | |
| 5475 | kfree(regs); |
| 5476 | |
| 5477 | for (i = 0; i < tp->irq_cnt; i++) { |
| 5478 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 5479 | |
| 5480 | /* SW status block */ |
| 5481 | netdev_err(tp->dev, |
| 5482 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 5483 | i, |
| 5484 | tnapi->hw_status->status, |
| 5485 | tnapi->hw_status->status_tag, |
| 5486 | tnapi->hw_status->rx_jumbo_consumer, |
| 5487 | tnapi->hw_status->rx_consumer, |
| 5488 | tnapi->hw_status->rx_mini_consumer, |
| 5489 | tnapi->hw_status->idx[0].rx_producer, |
| 5490 | tnapi->hw_status->idx[0].tx_consumer); |
| 5491 | |
| 5492 | netdev_err(tp->dev, |
| 5493 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", |
| 5494 | i, |
| 5495 | tnapi->last_tag, tnapi->last_irq_tag, |
| 5496 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, |
| 5497 | tnapi->rx_rcb_ptr, |
| 5498 | tnapi->prodring.rx_std_prod_idx, |
| 5499 | tnapi->prodring.rx_std_cons_idx, |
| 5500 | tnapi->prodring.rx_jmb_prod_idx, |
| 5501 | tnapi->prodring.rx_jmb_cons_idx); |
| 5502 | } |
| 5503 | } |
| 5504 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5505 | /* This is called whenever we suspect that the system chipset is re- |
| 5506 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 5507 | * is bogus tx completions. We try to recover by setting the |
| 5508 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 5509 | * in the workqueue. |
| 5510 | */ |
| 5511 | static void tg3_tx_recover(struct tg3 *tp) |
| 5512 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5513 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5514 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 5515 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5516 | netdev_warn(tp->dev, |
| 5517 | "The system may be re-ordering memory-mapped I/O " |
| 5518 | "cycles to the network device, attempting to recover. " |
| 5519 | "Please report the problem to the driver maintainer " |
| 5520 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5521 | |
| 5522 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5523 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5524 | spin_unlock(&tp->lock); |
| 5525 | } |
| 5526 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5527 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5528 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5529 | /* Tell compiler to fetch tx indices from memory. */ |
| 5530 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5531 | return tnapi->tx_pending - |
| 5532 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5533 | } |
| 5534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | /* Tigon3 never reports partial packet sends. So we do not |
| 5536 | * need special logic to handle SKBs that have not had all |
| 5537 | * of their frags sent yet, like SunGEM does. |
| 5538 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5539 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5541 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5542 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5543 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5544 | struct netdev_queue *txq; |
| 5545 | int index = tnapi - tp->napi; |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5546 | unsigned int pkts_compl = 0, bytes_compl = 0; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5547 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5548 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5549 | index--; |
| 5550 | |
| 5551 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | |
| 5553 | while (sw_idx != hw_idx) { |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 5554 | struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5556 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5557 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5558 | if (unlikely(skb == NULL)) { |
| 5559 | tg3_tx_recover(tp); |
| 5560 | return; |
| 5561 | } |
| 5562 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5563 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5564 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5565 | skb_headlen(skb), |
| 5566 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | |
| 5568 | ri->skb = NULL; |
| 5569 | |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5570 | while (ri->fragmented) { |
| 5571 | ri->fragmented = false; |
| 5572 | sw_idx = NEXT_TX(sw_idx); |
| 5573 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5574 | } |
| 5575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5576 | sw_idx = NEXT_TX(sw_idx); |
| 5577 | |
| 5578 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5579 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5580 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 5581 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5582 | |
| 5583 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5584 | dma_unmap_addr(ri, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5585 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5586 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5587 | |
| 5588 | while (ri->fragmented) { |
| 5589 | ri->fragmented = false; |
| 5590 | sw_idx = NEXT_TX(sw_idx); |
| 5591 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5592 | } |
| 5593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 | sw_idx = NEXT_TX(sw_idx); |
| 5595 | } |
| 5596 | |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5597 | pkts_compl++; |
| 5598 | bytes_compl += skb->len; |
| 5599 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5600 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5601 | |
| 5602 | if (unlikely(tx_bug)) { |
| 5603 | tg3_tx_recover(tp); |
| 5604 | return; |
| 5605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | } |
| 5607 | |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 5608 | netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5609 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5610 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5612 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 5613 | * before checking for netif_queue_stopped(). Without the |
| 5614 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 5615 | * will miss it and cause the queue to be stopped forever. |
| 5616 | */ |
| 5617 | smp_mb(); |
| 5618 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5619 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5620 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5621 | __netif_tx_lock(txq, smp_processor_id()); |
| 5622 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5623 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5624 | netif_tx_wake_queue(txq); |
| 5625 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 5626 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | } |
| 5628 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5629 | static void *tg3_frag_alloc(struct tg3_rx_prodring_set *tpr) |
| 5630 | { |
| 5631 | void *data; |
| 5632 | |
| 5633 | if (tpr->rx_page_size < TG3_FRAGSIZE) { |
| 5634 | struct page *page = alloc_page(GFP_ATOMIC); |
| 5635 | |
| 5636 | if (!page) |
| 5637 | return NULL; |
| 5638 | atomic_add((PAGE_SIZE / TG3_FRAGSIZE) - 1, &page->_count); |
| 5639 | tpr->rx_page_addr = page_address(page); |
| 5640 | tpr->rx_page_size = PAGE_SIZE; |
| 5641 | } |
| 5642 | data = tpr->rx_page_addr; |
| 5643 | tpr->rx_page_addr += TG3_FRAGSIZE; |
| 5644 | tpr->rx_page_size -= TG3_FRAGSIZE; |
| 5645 | return data; |
| 5646 | } |
| 5647 | |
| 5648 | static void tg3_frag_free(bool is_frag, void *data) |
| 5649 | { |
| 5650 | if (is_frag) |
| 5651 | put_page(virt_to_head_page(data)); |
| 5652 | else |
| 5653 | kfree(data); |
| 5654 | } |
| 5655 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5656 | static void tg3_rx_data_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5657 | { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5658 | unsigned int skb_size = SKB_DATA_ALIGN(map_sz + TG3_RX_OFFSET(tp)) + |
| 5659 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 5660 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5661 | if (!ri->data) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5662 | return; |
| 5663 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5664 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5665 | map_sz, PCI_DMA_FROMDEVICE); |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5666 | tg3_frag_free(skb_size <= TG3_FRAGSIZE, ri->data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5667 | ri->data = NULL; |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5668 | } |
| 5669 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | /* Returns size of skb allocated or < 0 on error. |
| 5672 | * |
| 5673 | * We only need to fill in the address because the other members |
| 5674 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 5675 | * |
| 5676 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 5677 | * posting buffers we only dirty the first cache line of the RX |
| 5678 | * descriptor (containing the address). Whereas for the RX status |
| 5679 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 5680 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 5681 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5682 | static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5683 | u32 opaque_key, u32 dest_idx_unmasked, |
| 5684 | unsigned int *frag_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | { |
| 5686 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 5687 | struct ring_info *map; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5688 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | dma_addr_t mapping; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5690 | int skb_size, data_size, dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | switch (opaque_key) { |
| 5693 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5694 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5695 | desc = &tpr->rx_std[dest_idx]; |
| 5696 | map = &tpr->rx_std_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5697 | data_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | break; |
| 5699 | |
| 5700 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5701 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 5702 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5703 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5704 | data_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5705 | break; |
| 5706 | |
| 5707 | default: |
| 5708 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 5709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | |
| 5711 | /* Do not overwrite any of the map or rp information |
| 5712 | * until we are sure we can commit to a new buffer. |
| 5713 | * |
| 5714 | * Callers depend upon this behavior and assume that |
| 5715 | * we leave everything unchanged if we fail. |
| 5716 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5717 | skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) + |
| 5718 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5719 | if (skb_size <= TG3_FRAGSIZE) { |
| 5720 | data = tg3_frag_alloc(tpr); |
| 5721 | *frag_size = TG3_FRAGSIZE; |
| 5722 | } else { |
| 5723 | data = kmalloc(skb_size, GFP_ATOMIC); |
| 5724 | *frag_size = 0; |
| 5725 | } |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5726 | if (!data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | return -ENOMEM; |
| 5728 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5729 | mapping = pci_map_single(tp->pdev, |
| 5730 | data + TG3_RX_OFFSET(tp), |
| 5731 | data_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | PCI_DMA_FROMDEVICE); |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5733 | if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) { |
| 5734 | tg3_frag_free(skb_size <= TG3_FRAGSIZE, data); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 5735 | return -EIO; |
| 5736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5738 | map->data = data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5739 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5741 | desc->addr_hi = ((u64)mapping >> 32); |
| 5742 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 5743 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5744 | return data_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | } |
| 5746 | |
| 5747 | /* We only need to move over in the address because the other |
| 5748 | * members of the RX descriptor are invariant. See notes above |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5749 | * tg3_alloc_rx_data for full details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5750 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5751 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 5752 | struct tg3_rx_prodring_set *dpr, |
| 5753 | u32 opaque_key, int src_idx, |
| 5754 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5756 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 5758 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5759 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5760 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5761 | |
| 5762 | switch (opaque_key) { |
| 5763 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5764 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5765 | dest_desc = &dpr->rx_std[dest_idx]; |
| 5766 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 5767 | src_desc = &spr->rx_std[src_idx]; |
| 5768 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | break; |
| 5770 | |
| 5771 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5772 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5773 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 5774 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 5775 | src_desc = &spr->rx_jmb[src_idx].std; |
| 5776 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5777 | break; |
| 5778 | |
| 5779 | default: |
| 5780 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 5781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5783 | dest_map->data = src_map->data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5784 | dma_unmap_addr_set(dest_map, mapping, |
| 5785 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | dest_desc->addr_hi = src_desc->addr_hi; |
| 5787 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5788 | |
| 5789 | /* Ensure that the update to the skb happens after the physical |
| 5790 | * addresses have been transferred to the new BD location. |
| 5791 | */ |
| 5792 | smp_wmb(); |
| 5793 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5794 | src_map->data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5797 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 5798 | * buffers to the chip, and one special ring the chip uses to report |
| 5799 | * status back to the host. |
| 5800 | * |
| 5801 | * The special ring reports the status of received packets to the |
| 5802 | * host. The chip does not write into the original descriptor the |
| 5803 | * RX buffer was obtained from. The chip simply takes the original |
| 5804 | * descriptor as provided by the host, updates the status and length |
| 5805 | * field, then writes this into the next status ring entry. |
| 5806 | * |
| 5807 | * Each ring the host uses to post buffers to the chip is described |
| 5808 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 5809 | * it is first placed into the on-chip ram. When the packet's length |
| 5810 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 5811 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 5812 | * which is within the range of the new packet's length is chosen. |
| 5813 | * |
| 5814 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 5815 | * sense from a cache coherency perspective. If only the host writes |
| 5816 | * to the buffer post rings, and only the chip writes to the rx status |
| 5817 | * rings, then cache lines never move beyond shared-modified state. |
| 5818 | * If both the host and chip were to write into the same ring, cache line |
| 5819 | * eviction could occur since both entities want it in an exclusive state. |
| 5820 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5821 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5823 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5824 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5825 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5826 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 5827 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5828 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5829 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5830 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5831 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5832 | /* |
| 5833 | * We need to order the read of hw_idx and the read of |
| 5834 | * the opaque cookie. |
| 5835 | */ |
| 5836 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5837 | work_mask = 0; |
| 5838 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5839 | std_prod_idx = tpr->rx_std_prod_idx; |
| 5840 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 5842 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5843 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5844 | unsigned int len; |
| 5845 | struct sk_buff *skb; |
| 5846 | dma_addr_t dma_addr; |
| 5847 | u32 opaque_key, desc_idx, *post_ptr; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5848 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5849 | |
| 5850 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 5851 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 5852 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5853 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5854 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5855 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5856 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5857 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5859 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5860 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5861 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5862 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5863 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5864 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5865 | |
| 5866 | work_mask |= opaque_key; |
| 5867 | |
| 5868 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 5869 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 5870 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5871 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5872 | desc_idx, *post_ptr); |
| 5873 | drop_it_no_recycle: |
| 5874 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 5875 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | goto next_pkt; |
| 5877 | } |
| 5878 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5879 | prefetch(data + TG3_RX_OFFSET(tp)); |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 5880 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 5881 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 5883 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5884 | int skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5885 | unsigned int frag_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5886 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5887 | skb_size = tg3_alloc_rx_data(tp, tpr, opaque_key, |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5888 | *post_ptr, &frag_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5889 | if (skb_size < 0) |
| 5890 | goto drop_it; |
| 5891 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 5892 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | PCI_DMA_FROMDEVICE); |
| 5894 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5895 | skb = build_skb(data, frag_size); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5896 | if (!skb) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 5897 | tg3_frag_free(frag_size != 0, data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5898 | goto drop_it_no_recycle; |
| 5899 | } |
| 5900 | skb_reserve(skb, TG3_RX_OFFSET(tp)); |
| 5901 | /* Ensure that the update to the data happens |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 5902 | * after the usage of the old DMA mapping. |
| 5903 | */ |
| 5904 | smp_wmb(); |
| 5905 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5906 | ri->data = NULL; |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 5907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5908 | } else { |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5909 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5910 | desc_idx, *post_ptr); |
| 5911 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5912 | skb = netdev_alloc_skb(tp->dev, |
| 5913 | len + TG3_RAW_IP_ALIGN); |
| 5914 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5915 | goto drop_it_no_recycle; |
| 5916 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5917 | skb_reserve(skb, TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5918 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5919 | memcpy(skb->data, |
| 5920 | data + TG3_RX_OFFSET(tp), |
| 5921 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5925 | skb_put(skb, len); |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 5926 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5927 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 5928 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 5929 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 5930 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5931 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5932 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5933 | |
| 5934 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 5935 | |
| 5936 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 5937 | skb->protocol != htons(ETH_P_8021Q)) { |
| 5938 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 5939 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 5940 | } |
| 5941 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 5942 | if (desc->type_flags & RXD_FLAG_VLAN && |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 5943 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
| 5944 | __vlan_hwaccel_put_tag(skb, |
| 5945 | desc->err_vlan & RXD_VLAN_MASK); |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 5946 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 5947 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5949 | received++; |
| 5950 | budget--; |
| 5951 | |
| 5952 | next_pkt: |
| 5953 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5954 | |
| 5955 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5956 | tpr->rx_std_prod_idx = std_prod_idx & |
| 5957 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 5958 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5959 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5960 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 5961 | rx_std_posted = 0; |
| 5962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 5964 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 5965 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 5966 | |
| 5967 | /* Refresh hw_idx to see if there is new work */ |
| 5968 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5969 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 5970 | rmb(); |
| 5971 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5972 | } |
| 5973 | |
| 5974 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5975 | tnapi->rx_rcb_ptr = sw_idx; |
| 5976 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | |
| 5978 | /* Refill RX ring(s). */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5979 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 5980 | /* Sync BD data before updating mailbox */ |
| 5981 | wmb(); |
| 5982 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5983 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5984 | tpr->rx_std_prod_idx = std_prod_idx & |
| 5985 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5986 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5987 | tpr->rx_std_prod_idx); |
| 5988 | } |
| 5989 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5990 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 5991 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5992 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 5993 | tpr->rx_jmb_prod_idx); |
| 5994 | } |
| 5995 | mmiowb(); |
| 5996 | } else if (work_mask) { |
| 5997 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 5998 | * updated before the producer indices can be updated. |
| 5999 | */ |
| 6000 | smp_wmb(); |
| 6001 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6002 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 6003 | tpr->rx_jmb_prod_idx = jmb_prod_idx & tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6004 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6005 | if (tnapi != &tp->napi[1]) { |
| 6006 | tp->rx_refill = true; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6007 | napi_schedule(&tp->napi[1].napi); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6008 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | |
| 6011 | return received; |
| 6012 | } |
| 6013 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6014 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6015 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | /* handle link change and other phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6017 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6018 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 6019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 6021 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6022 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6023 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6024 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 6025 | tw32_f(MAC_STATUS, |
| 6026 | (MAC_STATUS_SYNC_CHANGED | |
| 6027 | MAC_STATUS_CFG_CHANGED | |
| 6028 | MAC_STATUS_MI_COMPLETION | |
| 6029 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 6030 | udelay(40); |
| 6031 | } else |
| 6032 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6033 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | } |
| 6035 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6036 | } |
| 6037 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6038 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 6039 | struct tg3_rx_prodring_set *dpr, |
| 6040 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6041 | { |
| 6042 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6043 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6044 | |
| 6045 | while (1) { |
| 6046 | src_prod_idx = spr->rx_std_prod_idx; |
| 6047 | |
| 6048 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 6049 | * standard producer index are seen in the correct order. |
| 6050 | */ |
| 6051 | smp_rmb(); |
| 6052 | |
| 6053 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 6054 | break; |
| 6055 | |
| 6056 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 6057 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 6058 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6059 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 6060 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6061 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6062 | cpycnt = min(cpycnt, |
| 6063 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6064 | |
| 6065 | si = spr->rx_std_cons_idx; |
| 6066 | di = dpr->rx_std_prod_idx; |
| 6067 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6068 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6069 | if (dpr->rx_std_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6070 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6071 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6072 | break; |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | if (!cpycnt) |
| 6077 | break; |
| 6078 | |
| 6079 | /* Ensure that updates to the rx_std_buffers ring and the |
| 6080 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6081 | * ordered correctly WRT the skb check above. |
| 6082 | */ |
| 6083 | smp_rmb(); |
| 6084 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6085 | memcpy(&dpr->rx_std_buffers[di], |
| 6086 | &spr->rx_std_buffers[si], |
| 6087 | cpycnt * sizeof(struct ring_info)); |
| 6088 | |
| 6089 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6090 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6091 | sbd = &spr->rx_std[si]; |
| 6092 | dbd = &dpr->rx_std[di]; |
| 6093 | dbd->addr_hi = sbd->addr_hi; |
| 6094 | dbd->addr_lo = sbd->addr_lo; |
| 6095 | } |
| 6096 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6097 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 6098 | tp->rx_std_ring_mask; |
| 6099 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 6100 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | while (1) { |
| 6104 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 6105 | |
| 6106 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 6107 | * the jumbo producer index are seen in the correct order. |
| 6108 | */ |
| 6109 | smp_rmb(); |
| 6110 | |
| 6111 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 6112 | break; |
| 6113 | |
| 6114 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 6115 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 6116 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6117 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 6118 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6119 | |
| 6120 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6121 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6122 | |
| 6123 | si = spr->rx_jmb_cons_idx; |
| 6124 | di = dpr->rx_jmb_prod_idx; |
| 6125 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6126 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6127 | if (dpr->rx_jmb_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6128 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6129 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6130 | break; |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | if (!cpycnt) |
| 6135 | break; |
| 6136 | |
| 6137 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 6138 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6139 | * ordered correctly WRT the skb check above. |
| 6140 | */ |
| 6141 | smp_rmb(); |
| 6142 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6143 | memcpy(&dpr->rx_jmb_buffers[di], |
| 6144 | &spr->rx_jmb_buffers[si], |
| 6145 | cpycnt * sizeof(struct ring_info)); |
| 6146 | |
| 6147 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6148 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6149 | sbd = &spr->rx_jmb[si].std; |
| 6150 | dbd = &dpr->rx_jmb[di].std; |
| 6151 | dbd->addr_hi = sbd->addr_hi; |
| 6152 | dbd->addr_lo = sbd->addr_lo; |
| 6153 | } |
| 6154 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6155 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 6156 | tp->rx_jmb_ring_mask; |
| 6157 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 6158 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6159 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6160 | |
| 6161 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6164 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 6165 | { |
| 6166 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6167 | |
| 6168 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6169 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6170 | tg3_tx(tnapi); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6171 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6172 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | } |
| 6174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6175 | /* run RX thread, within the bounds set by NAPI. |
| 6176 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6177 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6178 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6179 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6180 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6182 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6183 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6184 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6185 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 6186 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6187 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6188 | tp->rx_refill = false; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6189 | for (i = 1; i < tp->irq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6190 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6191 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6192 | |
| 6193 | wmb(); |
| 6194 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6195 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 6196 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6197 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6198 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6199 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 6200 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 6201 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6202 | |
| 6203 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6204 | |
| 6205 | if (err) |
| 6206 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6207 | } |
| 6208 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6209 | return work_done; |
| 6210 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 6211 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6212 | static inline void tg3_reset_task_schedule(struct tg3 *tp) |
| 6213 | { |
| 6214 | if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) |
| 6215 | schedule_work(&tp->reset_task); |
| 6216 | } |
| 6217 | |
| 6218 | static inline void tg3_reset_task_cancel(struct tg3 *tp) |
| 6219 | { |
| 6220 | cancel_work_sync(&tp->reset_task); |
| 6221 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
Matt Carlson | c710135 | 2012-02-22 12:35:20 +0000 | [diff] [blame] | 6222 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6225 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 6226 | { |
| 6227 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6228 | struct tg3 *tp = tnapi->tp; |
| 6229 | int work_done = 0; |
| 6230 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 6231 | |
| 6232 | while (1) { |
| 6233 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 6234 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6235 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6236 | goto tx_recovery; |
| 6237 | |
| 6238 | if (unlikely(work_done >= budget)) |
| 6239 | break; |
| 6240 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6241 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6242 | * to tell the hw how much work has been processed, |
| 6243 | * so we must read it before checking for more work. |
| 6244 | */ |
| 6245 | tnapi->last_tag = sblk->status_tag; |
| 6246 | tnapi->last_irq_tag = tnapi->last_tag; |
| 6247 | rmb(); |
| 6248 | |
| 6249 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 6250 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 6251 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6252 | |
| 6253 | /* This test here is not race free, but will reduce |
| 6254 | * the number of interrupts by looping again. |
| 6255 | */ |
| 6256 | if (tnapi == &tp->napi[1] && tp->rx_refill) |
| 6257 | continue; |
| 6258 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6259 | napi_complete(napi); |
| 6260 | /* Reenable interrupts. */ |
| 6261 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6262 | |
| 6263 | /* This test here is synchronized by napi_schedule() |
| 6264 | * and napi_complete() to close the race condition. |
| 6265 | */ |
| 6266 | if (unlikely(tnapi == &tp->napi[1] && tp->rx_refill)) { |
| 6267 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 6268 | HOSTCC_MODE_ENABLE | |
| 6269 | tnapi->coal_now); |
| 6270 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6271 | mmiowb(); |
| 6272 | break; |
| 6273 | } |
| 6274 | } |
| 6275 | |
| 6276 | return work_done; |
| 6277 | |
| 6278 | tx_recovery: |
| 6279 | /* work_done is guaranteed to be less than budget. */ |
| 6280 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6281 | tg3_reset_task_schedule(tp); |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6282 | return work_done; |
| 6283 | } |
| 6284 | |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6285 | static void tg3_process_error(struct tg3 *tp) |
| 6286 | { |
| 6287 | u32 val; |
| 6288 | bool real_error = false; |
| 6289 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6290 | if (tg3_flag(tp, ERROR_PROCESSED)) |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6291 | return; |
| 6292 | |
| 6293 | /* Check Flow Attention register */ |
| 6294 | val = tr32(HOSTCC_FLOW_ATTN); |
| 6295 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { |
| 6296 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); |
| 6297 | real_error = true; |
| 6298 | } |
| 6299 | |
| 6300 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { |
| 6301 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); |
| 6302 | real_error = true; |
| 6303 | } |
| 6304 | |
| 6305 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { |
| 6306 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); |
| 6307 | real_error = true; |
| 6308 | } |
| 6309 | |
| 6310 | if (!real_error) |
| 6311 | return; |
| 6312 | |
| 6313 | tg3_dump_state(tp); |
| 6314 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6315 | tg3_flag_set(tp, ERROR_PROCESSED); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6316 | tg3_reset_task_schedule(tp); |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6317 | } |
| 6318 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6319 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 6320 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 6321 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6322 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6323 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6324 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6325 | |
| 6326 | while (1) { |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6327 | if (sblk->status & SD_STATUS_ERROR) |
| 6328 | tg3_process_error(tp); |
| 6329 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6330 | tg3_poll_link(tp); |
| 6331 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6332 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6333 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6334 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6335 | goto tx_recovery; |
| 6336 | |
| 6337 | if (unlikely(work_done >= budget)) |
| 6338 | break; |
| 6339 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6340 | if (tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6341 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6342 | * to tell the hw how much work has been processed, |
| 6343 | * so we must read it before checking for more work. |
| 6344 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6345 | tnapi->last_tag = sblk->status_tag; |
| 6346 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6347 | rmb(); |
| 6348 | } else |
| 6349 | sblk->status &= ~SD_STATUS_UPDATED; |
| 6350 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6351 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6352 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6353 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6354 | break; |
| 6355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6356 | } |
| 6357 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6358 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6359 | |
| 6360 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6361 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6362 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6363 | tg3_reset_task_schedule(tp); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6364 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6365 | } |
| 6366 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6367 | static void tg3_napi_disable(struct tg3 *tp) |
| 6368 | { |
| 6369 | int i; |
| 6370 | |
| 6371 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 6372 | napi_disable(&tp->napi[i].napi); |
| 6373 | } |
| 6374 | |
| 6375 | static void tg3_napi_enable(struct tg3 *tp) |
| 6376 | { |
| 6377 | int i; |
| 6378 | |
| 6379 | for (i = 0; i < tp->irq_cnt; i++) |
| 6380 | napi_enable(&tp->napi[i].napi); |
| 6381 | } |
| 6382 | |
| 6383 | static void tg3_napi_init(struct tg3 *tp) |
| 6384 | { |
| 6385 | int i; |
| 6386 | |
| 6387 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 6388 | for (i = 1; i < tp->irq_cnt; i++) |
| 6389 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 6390 | } |
| 6391 | |
| 6392 | static void tg3_napi_fini(struct tg3 *tp) |
| 6393 | { |
| 6394 | int i; |
| 6395 | |
| 6396 | for (i = 0; i < tp->irq_cnt; i++) |
| 6397 | netif_napi_del(&tp->napi[i].napi); |
| 6398 | } |
| 6399 | |
| 6400 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 6401 | { |
| 6402 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 6403 | tg3_napi_disable(tp); |
| 6404 | netif_tx_disable(tp->dev); |
| 6405 | } |
| 6406 | |
| 6407 | static inline void tg3_netif_start(struct tg3 *tp) |
| 6408 | { |
| 6409 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 6410 | * appropriate so long as all callers are assured to |
| 6411 | * have free tx slots (such as after tg3_init_hw) |
| 6412 | */ |
| 6413 | netif_tx_wake_all_queues(tp->dev); |
| 6414 | |
| 6415 | tg3_napi_enable(tp); |
| 6416 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 6417 | tg3_enable_ints(tp); |
| 6418 | } |
| 6419 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6420 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 6421 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6422 | int i; |
| 6423 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6424 | BUG_ON(tp->irq_sync); |
| 6425 | |
| 6426 | tp->irq_sync = 1; |
| 6427 | smp_mb(); |
| 6428 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6429 | for (i = 0; i < tp->irq_cnt; i++) |
| 6430 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6431 | } |
| 6432 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6433 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 6434 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 6435 | * with as well. Most of the time, this is not necessary except when |
| 6436 | * shutting down the device. |
| 6437 | */ |
| 6438 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 6439 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 6440 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6441 | if (irq_sync) |
| 6442 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 6446 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6447 | spin_unlock_bh(&tp->lock); |
| 6448 | } |
| 6449 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6450 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 6451 | * after sending MSI so driver doesn't have to do it. |
| 6452 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6453 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6454 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6455 | struct tg3_napi *tnapi = dev_id; |
| 6456 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6457 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6458 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6459 | if (tnapi->rx_rcb) |
| 6460 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6461 | |
| 6462 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6463 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6464 | |
| 6465 | return IRQ_HANDLED; |
| 6466 | } |
| 6467 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6468 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 6469 | * flush status block and interrupt mailbox. PCI ordering rules |
| 6470 | * guarantee that MSI will arrive after the status block. |
| 6471 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6472 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6473 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6474 | struct tg3_napi *tnapi = dev_id; |
| 6475 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6476 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6477 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6478 | if (tnapi->rx_rcb) |
| 6479 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6480 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6481 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6482 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6483 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6484 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6485 | * event coalescing. |
| 6486 | */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 6487 | tw32_mailbox(tnapi->int_mbox, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6488 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6489 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6490 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6491 | return IRQ_RETVAL(1); |
| 6492 | } |
| 6493 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6494 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6495 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6496 | struct tg3_napi *tnapi = dev_id; |
| 6497 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6498 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6499 | unsigned int handled = 1; |
| 6500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6501 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6502 | * the CPU before the status block posted prior to the interrupt. |
| 6503 | * Reading the PCI State register will confirm whether the |
| 6504 | * interrupt is ours and will flush the status block. |
| 6505 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6506 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6507 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6508 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6509 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6510 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6511 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6512 | } |
| 6513 | |
| 6514 | /* |
| 6515 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 6516 | * chip-internal interrupt pending events. |
| 6517 | * Writing non-zero to intr-mbox-0 additional tells the |
| 6518 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6519 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6520 | * |
| 6521 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6522 | * spurious interrupts. The flush impacts performance but |
| 6523 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6524 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6525 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6526 | if (tg3_irq_sync(tp)) |
| 6527 | goto out; |
| 6528 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6529 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6530 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6531 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6532 | } else { |
| 6533 | /* No work, shared interrupt perhaps? re-enable |
| 6534 | * interrupts, and flush that PCI write |
| 6535 | */ |
| 6536 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 6537 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6538 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6539 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6540 | return IRQ_RETVAL(handled); |
| 6541 | } |
| 6542 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6543 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6544 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6545 | struct tg3_napi *tnapi = dev_id; |
| 6546 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6547 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6548 | unsigned int handled = 1; |
| 6549 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6550 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6551 | * the CPU before the status block posted prior to the interrupt. |
| 6552 | * Reading the PCI State register will confirm whether the |
| 6553 | * interrupt is ours and will flush the status block. |
| 6554 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6555 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6556 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6557 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6558 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6559 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | /* |
| 6564 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 6565 | * chip-internal interrupt pending events. |
| 6566 | * writing non-zero to intr-mbox-0 additional tells the |
| 6567 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6568 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6569 | * |
| 6570 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6571 | * spurious interrupts. The flush impacts performance but |
| 6572 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6573 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6574 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6575 | |
| 6576 | /* |
| 6577 | * In a shared interrupt configuration, sometimes other devices' |
| 6578 | * interrupts will scream. We record the current status tag here |
| 6579 | * so that the above check can report that the screaming interrupts |
| 6580 | * are unhandled. Eventually they will be silenced. |
| 6581 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6582 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6583 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6584 | if (tg3_irq_sync(tp)) |
| 6585 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6586 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6587 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6588 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6589 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6590 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6591 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6592 | return IRQ_RETVAL(handled); |
| 6593 | } |
| 6594 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6595 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6596 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6597 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6598 | struct tg3_napi *tnapi = dev_id; |
| 6599 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6600 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6601 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 6602 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 6603 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 6604 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6605 | return IRQ_RETVAL(1); |
| 6606 | } |
| 6607 | return IRQ_RETVAL(0); |
| 6608 | } |
| 6609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6610 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6611 | static void tg3_poll_controller(struct net_device *dev) |
| 6612 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6613 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6614 | struct tg3 *tp = netdev_priv(dev); |
| 6615 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6616 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 6617 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6618 | } |
| 6619 | #endif |
| 6620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | static void tg3_tx_timeout(struct net_device *dev) |
| 6622 | { |
| 6623 | struct tg3 *tp = netdev_priv(dev); |
| 6624 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6625 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 6626 | netdev_err(dev, "transmit timed out, resetting\n"); |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6627 | tg3_dump_state(tp); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6629 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6630 | tg3_reset_task_schedule(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6631 | } |
| 6632 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6633 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 6634 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 6635 | { |
| 6636 | u32 base = (u32) mapping & 0xffffffff; |
| 6637 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6638 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6639 | } |
| 6640 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6641 | /* Test for DMA addresses > 40-bit */ |
| 6642 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 6643 | int len) |
| 6644 | { |
| 6645 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6646 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6647 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6648 | return 0; |
| 6649 | #else |
| 6650 | return 0; |
| 6651 | #endif |
| 6652 | } |
| 6653 | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6654 | static inline void tg3_tx_set_bd(struct tg3_tx_buffer_desc *txbd, |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6655 | dma_addr_t mapping, u32 len, u32 flags, |
| 6656 | u32 mss, u32 vlan) |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6657 | { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6658 | txbd->addr_hi = ((u64) mapping >> 32); |
| 6659 | txbd->addr_lo = ((u64) mapping & 0xffffffff); |
| 6660 | txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); |
| 6661 | txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6663 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6664 | static bool tg3_tx_frag_set(struct tg3_napi *tnapi, u32 *entry, u32 *budget, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6665 | dma_addr_t map, u32 len, u32 flags, |
| 6666 | u32 mss, u32 vlan) |
| 6667 | { |
| 6668 | struct tg3 *tp = tnapi->tp; |
| 6669 | bool hwbug = false; |
| 6670 | |
| 6671 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6672 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6673 | |
| 6674 | if (tg3_4g_overflow_test(map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6675 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6676 | |
| 6677 | if (tg3_40bit_overflow_test(tp, map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6678 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6679 | |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6680 | if (tp->dma_limit) { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6681 | u32 prvidx = *entry; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6682 | u32 tmp_flag = flags & ~TXD_FLAG_END; |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6683 | while (len > tp->dma_limit && *budget) { |
| 6684 | u32 frag_len = tp->dma_limit; |
| 6685 | len -= tp->dma_limit; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6686 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6687 | /* Avoid the 8byte DMA problem */ |
| 6688 | if (len <= 8) { |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6689 | len += tp->dma_limit / 2; |
| 6690 | frag_len = tp->dma_limit / 2; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6691 | } |
| 6692 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6693 | tnapi->tx_buffers[*entry].fragmented = true; |
| 6694 | |
| 6695 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6696 | frag_len, tmp_flag, mss, vlan); |
| 6697 | *budget -= 1; |
| 6698 | prvidx = *entry; |
| 6699 | *entry = NEXT_TX(*entry); |
| 6700 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6701 | map += frag_len; |
| 6702 | } |
| 6703 | |
| 6704 | if (len) { |
| 6705 | if (*budget) { |
| 6706 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6707 | len, flags, mss, vlan); |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6708 | *budget -= 1; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6709 | *entry = NEXT_TX(*entry); |
| 6710 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6711 | hwbug = true; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6712 | tnapi->tx_buffers[prvidx].fragmented = false; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6713 | } |
| 6714 | } |
| 6715 | } else { |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6716 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6717 | len, flags, mss, vlan); |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6718 | *entry = NEXT_TX(*entry); |
| 6719 | } |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6720 | |
| 6721 | return hwbug; |
| 6722 | } |
| 6723 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6724 | static void tg3_tx_skb_unmap(struct tg3_napi *tnapi, u32 entry, int last) |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6725 | { |
| 6726 | int i; |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6727 | struct sk_buff *skb; |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 6728 | struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6729 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6730 | skb = txb->skb; |
| 6731 | txb->skb = NULL; |
| 6732 | |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6733 | pci_unmap_single(tnapi->tp->pdev, |
| 6734 | dma_unmap_addr(txb, mapping), |
| 6735 | skb_headlen(skb), |
| 6736 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6737 | |
| 6738 | while (txb->fragmented) { |
| 6739 | txb->fragmented = false; |
| 6740 | entry = NEXT_TX(entry); |
| 6741 | txb = &tnapi->tx_buffers[entry]; |
| 6742 | } |
| 6743 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6744 | for (i = 0; i <= last; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6745 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6746 | |
| 6747 | entry = NEXT_TX(entry); |
| 6748 | txb = &tnapi->tx_buffers[entry]; |
| 6749 | |
| 6750 | pci_unmap_page(tnapi->tp->pdev, |
| 6751 | dma_unmap_addr(txb, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6752 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6753 | |
| 6754 | while (txb->fragmented) { |
| 6755 | txb->fragmented = false; |
| 6756 | entry = NEXT_TX(entry); |
| 6757 | txb = &tnapi->tx_buffers[entry]; |
| 6758 | } |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6759 | } |
| 6760 | } |
| 6761 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6762 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6763 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6764 | struct sk_buff **pskb, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6765 | u32 *entry, u32 *budget, |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6766 | u32 base_flags, u32 mss, u32 vlan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6767 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6768 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6769 | struct sk_buff *new_skb, *skb = *pskb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6770 | dma_addr_t new_addr = 0; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6771 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6772 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 6773 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 6774 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 6775 | else { |
| 6776 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 6777 | |
| 6778 | new_skb = skb_copy_expand(skb, |
| 6779 | skb_headroom(skb) + more_headroom, |
| 6780 | skb_tailroom(skb), GFP_ATOMIC); |
| 6781 | } |
| 6782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6783 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6784 | ret = -1; |
| 6785 | } else { |
| 6786 | /* New SKB is guaranteed to be linear. */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6787 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 6788 | PCI_DMA_TODEVICE); |
| 6789 | /* Make sure the mapping succeeded */ |
| 6790 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6791 | dev_kfree_skb(new_skb); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6792 | ret = -1; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6793 | } else { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6794 | u32 save_entry = *entry; |
| 6795 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6796 | base_flags |= TXD_FLAG_END; |
| 6797 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6798 | tnapi->tx_buffers[*entry].skb = new_skb; |
| 6799 | dma_unmap_addr_set(&tnapi->tx_buffers[*entry], |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6800 | mapping, new_addr); |
| 6801 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6802 | if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6803 | new_skb->len, base_flags, |
| 6804 | mss, vlan)) { |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6805 | tg3_tx_skb_unmap(tnapi, save_entry, -1); |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6806 | dev_kfree_skb(new_skb); |
| 6807 | ret = -1; |
| 6808 | } |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6810 | } |
| 6811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6812 | dev_kfree_skb(skb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6813 | *pskb = new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6814 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6815 | } |
| 6816 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6817 | static netdev_tx_t tg3_start_xmit(struct sk_buff *, struct net_device *); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6818 | |
| 6819 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 6820 | * TSO header is greater than 80 bytes. |
| 6821 | */ |
| 6822 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 6823 | { |
| 6824 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6825 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6826 | |
| 6827 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6828 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6829 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 6830 | |
| 6831 | /* netif_tx_stop_queue() must be done before checking |
| 6832 | * checking tx index in tg3_tx_avail() below, because in |
| 6833 | * tg3_tx(), we update tx index before checking for |
| 6834 | * netif_tx_queue_stopped(). |
| 6835 | */ |
| 6836 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6837 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 6838 | return NETDEV_TX_BUSY; |
| 6839 | |
| 6840 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6841 | } |
| 6842 | |
| 6843 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 6844 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6845 | goto tg3_tso_bug_end; |
| 6846 | |
| 6847 | do { |
| 6848 | nskb = segs; |
| 6849 | segs = segs->next; |
| 6850 | nskb->next = NULL; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6851 | tg3_start_xmit(nskb, tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6852 | } while (segs); |
| 6853 | |
| 6854 | tg3_tso_bug_end: |
| 6855 | dev_kfree_skb(skb); |
| 6856 | |
| 6857 | return NETDEV_TX_OK; |
| 6858 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6859 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 6860 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6861 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 6862 | */ |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6863 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 6864 | { |
| 6865 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6866 | u32 len, entry, base_flags, mss, vlan = 0; |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6867 | u32 budget; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6868 | int i = -1, would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6869 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6870 | struct tg3_napi *tnapi; |
| 6871 | struct netdev_queue *txq; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6872 | unsigned int last; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6873 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6874 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 6875 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6876 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6877 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6878 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6879 | budget = tg3_tx_avail(tnapi); |
| 6880 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 6881 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6882 | * and TX reclaim runs via tp->napi.poll inside of a software |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6883 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 6884 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6885 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6886 | if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6887 | if (!netif_tx_queue_stopped(txq)) { |
| 6888 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 6889 | |
| 6890 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 6891 | netdev_err(dev, |
| 6892 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 6893 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6894 | return NETDEV_TX_BUSY; |
| 6895 | } |
| 6896 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6897 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6898 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 6899 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6900 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6901 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 6902 | mss = skb_shinfo(skb)->gso_size; |
| 6903 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6904 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6905 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6906 | |
| 6907 | if (skb_header_cloned(skb) && |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 6908 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 6909 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6910 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6911 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 6912 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6913 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 6914 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb) - ETH_HLEN; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6915 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 6916 | if (!skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6917 | iph->check = 0; |
| 6918 | iph->tot_len = htons(mss + hdr_len); |
| 6919 | } |
| 6920 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6921 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6922 | tg3_flag(tp, TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 6923 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6925 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 6926 | TXD_FLAG_CPU_POST_DMA); |
| 6927 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6928 | if (tg3_flag(tp, HW_TSO_1) || |
| 6929 | tg3_flag(tp, HW_TSO_2) || |
| 6930 | tg3_flag(tp, HW_TSO_3)) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 6931 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6932 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 6933 | } else |
| 6934 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6935 | iph->daddr, 0, |
| 6936 | IPPROTO_TCP, |
| 6937 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6938 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6939 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 6940 | mss |= (hdr_len & 0xc) << 12; |
| 6941 | if (hdr_len & 0x10) |
| 6942 | base_flags |= 0x00000010; |
| 6943 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6944 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6945 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6946 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6947 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6948 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6949 | int tsflags; |
| 6950 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6951 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6952 | mss |= (tsflags << 11); |
| 6953 | } |
| 6954 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6955 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6956 | int tsflags; |
| 6957 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6958 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6959 | base_flags |= tsflags << 12; |
| 6960 | } |
| 6961 | } |
| 6962 | } |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6963 | |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 6964 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 6965 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
| 6966 | base_flags |= TXD_FLAG_JMB_PKT; |
| 6967 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6968 | if (vlan_tx_tag_present(skb)) { |
| 6969 | base_flags |= TXD_FLAG_VLAN; |
| 6970 | vlan = vlan_tx_tag_get(skb); |
| 6971 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6972 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6973 | len = skb_headlen(skb); |
| 6974 | |
| 6975 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 6976 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 6977 | goto drop; |
| 6978 | |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6979 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6980 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6981 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6982 | |
| 6983 | would_hit_hwbug = 0; |
| 6984 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6985 | if (tg3_flag(tp, 5701_DMA_BUG)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6986 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6987 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6988 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6989 | ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6990 | mss, vlan)) { |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6991 | would_hit_hwbug = 1; |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6992 | } else if (skb_shinfo(skb)->nr_frags > 0) { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6993 | u32 tmp_mss = mss; |
| 6994 | |
| 6995 | if (!tg3_flag(tp, HW_TSO_1) && |
| 6996 | !tg3_flag(tp, HW_TSO_2) && |
| 6997 | !tg3_flag(tp, HW_TSO_3)) |
| 6998 | tmp_mss = 0; |
| 6999 | |
Matt Carlson | c5665a5 | 2012-02-13 10:20:12 +0000 | [diff] [blame] | 7000 | /* Now loop through additional data |
| 7001 | * fragments, and queue them. |
| 7002 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7003 | last = skb_shinfo(skb)->nr_frags - 1; |
| 7004 | for (i = 0; i <= last; i++) { |
| 7005 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 7006 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7007 | len = skb_frag_size(frag); |
Ian Campbell | dc234d0 | 2011-08-24 22:28:11 +0000 | [diff] [blame] | 7008 | mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7009 | len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7010 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7011 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 7012 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7013 | mapping); |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7014 | if (dma_mapping_error(&tp->pdev->dev, mapping)) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7015 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7016 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7017 | if (!budget || |
| 7018 | tg3_tx_frag_set(tnapi, &entry, &budget, mapping, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7019 | len, base_flags | |
| 7020 | ((i == last) ? TXD_FLAG_END : 0), |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7021 | tmp_mss, vlan)) { |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7022 | would_hit_hwbug = 1; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7023 | break; |
| 7024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | if (would_hit_hwbug) { |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7029 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7030 | |
| 7031 | /* If the workaround fails due to memory/mapping |
| 7032 | * failure, silently drop this packet. |
| 7033 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7034 | entry = tnapi->tx_prod; |
| 7035 | budget = tg3_tx_avail(tnapi); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7036 | if (tigon3_dma_hwbug_workaround(tnapi, &skb, &entry, &budget, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7037 | base_flags, mss, vlan)) |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7038 | goto drop_nofree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7039 | } |
| 7040 | |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7041 | skb_tx_timestamp(skb); |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7042 | netdev_tx_sent_queue(txq, skb->len); |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7043 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 7044 | /* Sync BD data before updating mailbox */ |
| 7045 | wmb(); |
| 7046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7047 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7048 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7049 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7050 | tnapi->tx_prod = entry; |
| 7051 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7052 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 7053 | |
| 7054 | /* netif_tx_stop_queue() must be done before checking |
| 7055 | * checking tx index in tg3_tx_avail() below, because in |
| 7056 | * tg3_tx(), we update tx index before checking for |
| 7057 | * netif_tx_queue_stopped(). |
| 7058 | */ |
| 7059 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7060 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7061 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 7062 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7063 | |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 7064 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7065 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7066 | |
| 7067 | dma_error: |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7068 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i); |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7069 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7070 | drop: |
| 7071 | dev_kfree_skb(skb); |
| 7072 | drop_nofree: |
| 7073 | tp->tx_dropped++; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7074 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7075 | } |
| 7076 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7077 | static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
| 7078 | { |
| 7079 | if (enable) { |
| 7080 | tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | |
| 7081 | MAC_MODE_PORT_MODE_MASK); |
| 7082 | |
| 7083 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
| 7084 | |
| 7085 | if (!tg3_flag(tp, 5705_PLUS)) |
| 7086 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7087 | |
| 7088 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 7089 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7090 | else |
| 7091 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7092 | } else { |
| 7093 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; |
| 7094 | |
| 7095 | if (tg3_flag(tp, 5705_PLUS) || |
| 7096 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || |
| 7097 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 7098 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7099 | } |
| 7100 | |
| 7101 | tw32(MAC_MODE, tp->mac_mode); |
| 7102 | udelay(40); |
| 7103 | } |
| 7104 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7105 | static int tg3_phy_lpbk_set(struct tg3 *tp, u32 speed, bool extlpbk) |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7106 | { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7107 | u32 val, bmcr, mac_mode, ptest = 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7108 | |
| 7109 | tg3_phy_toggle_apd(tp, false); |
| 7110 | tg3_phy_toggle_automdix(tp, 0); |
| 7111 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7112 | if (extlpbk && tg3_phy_set_extloopbk(tp)) |
| 7113 | return -EIO; |
| 7114 | |
| 7115 | bmcr = BMCR_FULLDPLX; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7116 | switch (speed) { |
| 7117 | case SPEED_10: |
| 7118 | break; |
| 7119 | case SPEED_100: |
| 7120 | bmcr |= BMCR_SPEED100; |
| 7121 | break; |
| 7122 | case SPEED_1000: |
| 7123 | default: |
| 7124 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 7125 | speed = SPEED_100; |
| 7126 | bmcr |= BMCR_SPEED100; |
| 7127 | } else { |
| 7128 | speed = SPEED_1000; |
| 7129 | bmcr |= BMCR_SPEED1000; |
| 7130 | } |
| 7131 | } |
| 7132 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7133 | if (extlpbk) { |
| 7134 | if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 7135 | tg3_readphy(tp, MII_CTRL1000, &val); |
| 7136 | val |= CTL1000_AS_MASTER | |
| 7137 | CTL1000_ENABLE_MASTER; |
| 7138 | tg3_writephy(tp, MII_CTRL1000, val); |
| 7139 | } else { |
| 7140 | ptest = MII_TG3_FET_PTEST_TRIM_SEL | |
| 7141 | MII_TG3_FET_PTEST_TRIM_2; |
| 7142 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); |
| 7143 | } |
| 7144 | } else |
| 7145 | bmcr |= BMCR_LOOPBACK; |
| 7146 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7147 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 7148 | |
| 7149 | /* The write needs to be flushed for the FETs */ |
| 7150 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 7151 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 7152 | |
| 7153 | udelay(40); |
| 7154 | |
| 7155 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
| 7156 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7157 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7158 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 7159 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 7160 | |
| 7161 | /* The write needs to be flushed for the AC131 */ |
| 7162 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
| 7163 | } |
| 7164 | |
| 7165 | /* Reset to prevent losing 1st rx packet intermittently */ |
| 7166 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 7167 | tg3_flag(tp, 5780_CLASS)) { |
| 7168 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 7169 | udelay(10); |
| 7170 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 7171 | } |
| 7172 | |
| 7173 | mac_mode = tp->mac_mode & |
| 7174 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 7175 | if (speed == SPEED_1000) |
| 7176 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7177 | else |
| 7178 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7179 | |
| 7180 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
| 7181 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 7182 | |
| 7183 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
| 7184 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7185 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
| 7186 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7187 | |
| 7188 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 7189 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 7190 | } |
| 7191 | |
| 7192 | tw32(MAC_MODE, mac_mode); |
| 7193 | udelay(40); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7194 | |
| 7195 | return 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7196 | } |
| 7197 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7198 | static void tg3_set_loopback(struct net_device *dev, netdev_features_t features) |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7199 | { |
| 7200 | struct tg3 *tp = netdev_priv(dev); |
| 7201 | |
| 7202 | if (features & NETIF_F_LOOPBACK) { |
| 7203 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) |
| 7204 | return; |
| 7205 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7206 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7207 | tg3_mac_loopback(tp, true); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7208 | netif_carrier_on(tp->dev); |
| 7209 | spin_unlock_bh(&tp->lock); |
| 7210 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); |
| 7211 | } else { |
| 7212 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 7213 | return; |
| 7214 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7215 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7216 | tg3_mac_loopback(tp, false); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7217 | /* Force link status check */ |
| 7218 | tg3_setup_phy(tp, 1); |
| 7219 | spin_unlock_bh(&tp->lock); |
| 7220 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); |
| 7221 | } |
| 7222 | } |
| 7223 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7224 | static netdev_features_t tg3_fix_features(struct net_device *dev, |
| 7225 | netdev_features_t features) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7226 | { |
| 7227 | struct tg3 *tp = netdev_priv(dev); |
| 7228 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7229 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7230 | features &= ~NETIF_F_ALL_TSO; |
| 7231 | |
| 7232 | return features; |
| 7233 | } |
| 7234 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7235 | static int tg3_set_features(struct net_device *dev, netdev_features_t features) |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7236 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7237 | netdev_features_t changed = dev->features ^ features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7238 | |
| 7239 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) |
| 7240 | tg3_set_loopback(dev, features); |
| 7241 | |
| 7242 | return 0; |
| 7243 | } |
| 7244 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7245 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 7246 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7247 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7248 | int i; |
| 7249 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7250 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7251 | for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7252 | i = (i + 1) & tp->rx_std_ring_mask) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7253 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7254 | tp->rx_pkt_map_sz); |
| 7255 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7256 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7257 | for (i = tpr->rx_jmb_cons_idx; |
| 7258 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7259 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7260 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7261 | TG3_RX_JMB_MAP_SZ); |
| 7262 | } |
| 7263 | } |
| 7264 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7265 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7267 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7268 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7269 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7270 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7271 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7272 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7273 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7274 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7275 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7276 | } |
| 7277 | } |
| 7278 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 7279 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7280 | * |
| 7281 | * The chip has been shut down and the driver detached from |
| 7282 | * the networking, so no interrupts or new tx packets will |
| 7283 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7284 | * we may not sleep. |
| 7285 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7286 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 7287 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7288 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7289 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7290 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7291 | tpr->rx_std_cons_idx = 0; |
| 7292 | tpr->rx_std_prod_idx = 0; |
| 7293 | tpr->rx_jmb_cons_idx = 0; |
| 7294 | tpr->rx_jmb_prod_idx = 0; |
| 7295 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7296 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7297 | memset(&tpr->rx_std_buffers[0], 0, |
| 7298 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 7299 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7300 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7301 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7302 | goto done; |
| 7303 | } |
| 7304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7305 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7306 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7307 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7308 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7309 | if (tg3_flag(tp, 5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7310 | tp->dev->mtu > ETH_DATA_LEN) |
| 7311 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 7312 | tp->rx_pkt_map_sz = TG3_RX_DMA_TO_MAP_SZ(rx_pkt_dma_sz); |
Michael Chan | 7e72aad | 2005-07-25 12:31:17 -0700 | [diff] [blame] | 7313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7314 | /* Initialize invariants of the rings, we only set this |
| 7315 | * stuff once. This works because the card does not |
| 7316 | * write into the rx buffer posting rings. |
| 7317 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7318 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7319 | struct tg3_rx_buffer_desc *rxd; |
| 7320 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7321 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7322 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7323 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 7324 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 7325 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7326 | } |
| 7327 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7328 | /* Now allocate fresh SKBs for each rx ring. */ |
| 7329 | for (i = 0; i < tp->rx_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 7330 | unsigned int frag_size; |
| 7331 | |
| 7332 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_STD, i, |
| 7333 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7334 | netdev_warn(tp->dev, |
| 7335 | "Using a smaller RX standard ring. Only " |
| 7336 | "%d out of %d buffers were allocated " |
| 7337 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7338 | if (i == 0) |
| 7339 | goto initfail; |
| 7340 | tp->rx_pending = i; |
| 7341 | break; |
| 7342 | } |
| 7343 | } |
| 7344 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7345 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7346 | goto done; |
| 7347 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7348 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7349 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7350 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7351 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7352 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7353 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7354 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7355 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7356 | rxd = &tpr->rx_jmb[i].std; |
| 7357 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 7358 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 7359 | RXD_FLAG_JUMBO; |
| 7360 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 7361 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7362 | } |
| 7363 | |
| 7364 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame^] | 7365 | unsigned int frag_size; |
| 7366 | |
| 7367 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_JUMBO, i, |
| 7368 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7369 | netdev_warn(tp->dev, |
| 7370 | "Using a smaller RX jumbo ring. Only %d " |
| 7371 | "out of %d buffers were allocated " |
| 7372 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7373 | if (i == 0) |
| 7374 | goto initfail; |
| 7375 | tp->rx_jumbo_pending = i; |
| 7376 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7377 | } |
| 7378 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7379 | |
| 7380 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 7381 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7382 | |
| 7383 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7384 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7385 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7386 | } |
| 7387 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7388 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 7389 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7390 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7391 | kfree(tpr->rx_std_buffers); |
| 7392 | tpr->rx_std_buffers = NULL; |
| 7393 | kfree(tpr->rx_jmb_buffers); |
| 7394 | tpr->rx_jmb_buffers = NULL; |
| 7395 | if (tpr->rx_std) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7396 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 7397 | tpr->rx_std, tpr->rx_std_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7398 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7399 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7400 | if (tpr->rx_jmb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7401 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 7402 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7403 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7404 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7405 | } |
| 7406 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7407 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 7408 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7409 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7410 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 7411 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7412 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7413 | return -ENOMEM; |
| 7414 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7415 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 7416 | TG3_RX_STD_RING_BYTES(tp), |
| 7417 | &tpr->rx_std_mapping, |
| 7418 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7419 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7420 | goto err_out; |
| 7421 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7422 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7423 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7424 | GFP_KERNEL); |
| 7425 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7426 | goto err_out; |
| 7427 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7428 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 7429 | TG3_RX_JMB_RING_BYTES(tp), |
| 7430 | &tpr->rx_jmb_mapping, |
| 7431 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7432 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7433 | goto err_out; |
| 7434 | } |
| 7435 | |
| 7436 | return 0; |
| 7437 | |
| 7438 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7439 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7440 | return -ENOMEM; |
| 7441 | } |
| 7442 | |
| 7443 | /* Free up pending packets in all rx/tx rings. |
| 7444 | * |
| 7445 | * The chip has been shut down and the driver detached from |
| 7446 | * the networking, so no interrupts or new tx packets will |
| 7447 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 7448 | * in an interrupt context and thus may sleep. |
| 7449 | */ |
| 7450 | static void tg3_free_rings(struct tg3 *tp) |
| 7451 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7452 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7453 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7454 | for (j = 0; j < tp->irq_cnt; j++) { |
| 7455 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7456 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7457 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 7458 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7459 | if (!tnapi->tx_buffers) |
| 7460 | continue; |
| 7461 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7462 | for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
| 7463 | struct sk_buff *skb = tnapi->tx_buffers[i].skb; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7464 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7465 | if (!skb) |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7466 | continue; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7467 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7468 | tg3_tx_skb_unmap(tnapi, i, |
| 7469 | skb_shinfo(skb)->nr_frags - 1); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7470 | |
| 7471 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7472 | } |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7473 | netdev_tx_reset_queue(netdev_get_tx_queue(tp->dev, j)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7474 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | /* Initialize tx/rx rings for packet processing. |
| 7478 | * |
| 7479 | * The chip has been shut down and the driver detached from |
| 7480 | * the networking, so no interrupts or new tx packets will |
| 7481 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7482 | * we may not sleep. |
| 7483 | */ |
| 7484 | static int tg3_init_rings(struct tg3 *tp) |
| 7485 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7486 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7487 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7488 | /* Free up all the SKBs. */ |
| 7489 | tg3_free_rings(tp); |
| 7490 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7491 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7492 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7493 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7494 | tnapi->last_tag = 0; |
| 7495 | tnapi->last_irq_tag = 0; |
| 7496 | tnapi->hw_status->status = 0; |
| 7497 | tnapi->hw_status->status_tag = 0; |
| 7498 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7499 | |
| 7500 | tnapi->tx_prod = 0; |
| 7501 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7502 | if (tnapi->tx_ring) |
| 7503 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7504 | |
| 7505 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7506 | if (tnapi->rx_rcb) |
| 7507 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7508 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7509 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7510 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7511 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7512 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7513 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7514 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7515 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7516 | } |
| 7517 | |
| 7518 | /* |
| 7519 | * Must not be invoked with interrupt sources disabled and |
| 7520 | * the hardware shutdown down. |
| 7521 | */ |
| 7522 | static void tg3_free_consistent(struct tg3 *tp) |
| 7523 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7524 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7525 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7526 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7527 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7528 | |
| 7529 | if (tnapi->tx_ring) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7530 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7531 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 7532 | tnapi->tx_ring = NULL; |
| 7533 | } |
| 7534 | |
| 7535 | kfree(tnapi->tx_buffers); |
| 7536 | tnapi->tx_buffers = NULL; |
| 7537 | |
| 7538 | if (tnapi->rx_rcb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7539 | dma_free_coherent(&tp->pdev->dev, |
| 7540 | TG3_RX_RCB_RING_BYTES(tp), |
| 7541 | tnapi->rx_rcb, |
| 7542 | tnapi->rx_rcb_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7543 | tnapi->rx_rcb = NULL; |
| 7544 | } |
| 7545 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7546 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 7547 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7548 | if (tnapi->hw_status) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7549 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 7550 | tnapi->hw_status, |
| 7551 | tnapi->status_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7552 | tnapi->hw_status = NULL; |
| 7553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7554 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7556 | if (tp->hw_stats) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7557 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 7558 | tp->hw_stats, tp->stats_mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7559 | tp->hw_stats = NULL; |
| 7560 | } |
| 7561 | } |
| 7562 | |
| 7563 | /* |
| 7564 | * Must not be invoked with interrupt sources disabled and |
| 7565 | * the hardware shutdown down. Can sleep. |
| 7566 | */ |
| 7567 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 7568 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7569 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7570 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7571 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 7572 | sizeof(struct tg3_hw_stats), |
| 7573 | &tp->stats_mapping, |
| 7574 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7575 | if (!tp->hw_stats) |
| 7576 | goto err_out; |
| 7577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7578 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 7579 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7580 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7581 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7582 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7583 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7584 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 7585 | TG3_HW_STATUS_SIZE, |
| 7586 | &tnapi->status_mapping, |
| 7587 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7588 | if (!tnapi->hw_status) |
| 7589 | goto err_out; |
| 7590 | |
| 7591 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7592 | sblk = tnapi->hw_status; |
| 7593 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7594 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 7595 | goto err_out; |
| 7596 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7597 | /* If multivector TSS is enabled, vector 0 does not handle |
| 7598 | * tx interrupts. Don't allocate any resources for it. |
| 7599 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7600 | if ((!i && !tg3_flag(tp, ENABLE_TSS)) || |
| 7601 | (i && tg3_flag(tp, ENABLE_TSS))) { |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 7602 | tnapi->tx_buffers = kzalloc( |
| 7603 | sizeof(struct tg3_tx_ring_info) * |
| 7604 | TG3_TX_RING_SIZE, GFP_KERNEL); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7605 | if (!tnapi->tx_buffers) |
| 7606 | goto err_out; |
| 7607 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7608 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 7609 | TG3_TX_RING_BYTES, |
| 7610 | &tnapi->tx_desc_mapping, |
| 7611 | GFP_KERNEL); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7612 | if (!tnapi->tx_ring) |
| 7613 | goto err_out; |
| 7614 | } |
| 7615 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7616 | /* |
| 7617 | * When RSS is enabled, the status block format changes |
| 7618 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 7619 | * and "rx_mini_consumer" members get mapped to the |
| 7620 | * other three rx return ring producer indexes. |
| 7621 | */ |
| 7622 | switch (i) { |
| 7623 | default: |
| 7624 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
| 7625 | break; |
| 7626 | case 2: |
| 7627 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; |
| 7628 | break; |
| 7629 | case 3: |
| 7630 | tnapi->rx_rcb_prod_idx = &sblk->reserved; |
| 7631 | break; |
| 7632 | case 4: |
| 7633 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; |
| 7634 | break; |
| 7635 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7636 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7637 | /* |
| 7638 | * If multivector RSS is enabled, vector 0 does not handle |
| 7639 | * rx or tx interrupts. Don't allocate any resources for it. |
| 7640 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7641 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7642 | continue; |
| 7643 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7644 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 7645 | TG3_RX_RCB_RING_BYTES(tp), |
| 7646 | &tnapi->rx_rcb_mapping, |
| 7647 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7648 | if (!tnapi->rx_rcb) |
| 7649 | goto err_out; |
| 7650 | |
| 7651 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7652 | } |
| 7653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7654 | return 0; |
| 7655 | |
| 7656 | err_out: |
| 7657 | tg3_free_consistent(tp); |
| 7658 | return -ENOMEM; |
| 7659 | } |
| 7660 | |
| 7661 | #define MAX_WAIT_CNT 1000 |
| 7662 | |
| 7663 | /* To stop a block, clear the enable bit and poll till it |
| 7664 | * clears. tp->lock is held. |
| 7665 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7666 | static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7667 | { |
| 7668 | unsigned int i; |
| 7669 | u32 val; |
| 7670 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7671 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7672 | switch (ofs) { |
| 7673 | case RCVLSC_MODE: |
| 7674 | case DMAC_MODE: |
| 7675 | case MBFREE_MODE: |
| 7676 | case BUFMGR_MODE: |
| 7677 | case MEMARB_MODE: |
| 7678 | /* We can't enable/disable these bits of the |
| 7679 | * 5705/5750, just say success. |
| 7680 | */ |
| 7681 | return 0; |
| 7682 | |
| 7683 | default: |
| 7684 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 7685 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7686 | } |
| 7687 | |
| 7688 | val = tr32(ofs); |
| 7689 | val &= ~enable_bit; |
| 7690 | tw32_f(ofs, val); |
| 7691 | |
| 7692 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 7693 | udelay(100); |
| 7694 | val = tr32(ofs); |
| 7695 | if ((val & enable_bit) == 0) |
| 7696 | break; |
| 7697 | } |
| 7698 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7699 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 7700 | dev_err(&tp->pdev->dev, |
| 7701 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 7702 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7703 | return -ENODEV; |
| 7704 | } |
| 7705 | |
| 7706 | return 0; |
| 7707 | } |
| 7708 | |
| 7709 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7710 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7711 | { |
| 7712 | int i, err; |
| 7713 | |
| 7714 | tg3_disable_ints(tp); |
| 7715 | |
| 7716 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 7717 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 7718 | udelay(10); |
| 7719 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7720 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 7721 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 7722 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 7723 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 7724 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 7725 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7726 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7727 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 7728 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 7729 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 7730 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 7731 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 7732 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 7733 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7734 | |
| 7735 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 7736 | tw32_f(MAC_MODE, tp->mac_mode); |
| 7737 | udelay(40); |
| 7738 | |
| 7739 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 7740 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 7741 | |
| 7742 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 7743 | udelay(100); |
| 7744 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 7745 | break; |
| 7746 | } |
| 7747 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 7748 | dev_err(&tp->pdev->dev, |
| 7749 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 7750 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7751 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7752 | } |
| 7753 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7754 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7755 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 7756 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7757 | |
| 7758 | tw32(FTQ_RESET, 0xffffffff); |
| 7759 | tw32(FTQ_RESET, 0x00000000); |
| 7760 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7761 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 7762 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7763 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7764 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7765 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7766 | if (tnapi->hw_status) |
| 7767 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7768 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7770 | return err; |
| 7771 | } |
| 7772 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7773 | /* Save PCI command register before chip reset */ |
| 7774 | static void tg3_save_pci_state(struct tg3 *tp) |
| 7775 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7776 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7777 | } |
| 7778 | |
| 7779 | /* Restore PCI state after chip reset */ |
| 7780 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 7781 | { |
| 7782 | u32 val; |
| 7783 | |
| 7784 | /* Re-enable indirect register accesses. */ |
| 7785 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 7786 | tp->misc_host_ctrl); |
| 7787 | |
| 7788 | /* Set MAX PCI retry to zero. */ |
| 7789 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 7790 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7791 | tg3_flag(tp, PCIX_MODE)) |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7792 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7793 | /* Allow reads and writes to the APE register and memory space. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7794 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7795 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 7796 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 7797 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7798 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 7799 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7800 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7801 | |
Matt Carlson | 2c55a3d | 2011-11-28 09:41:04 +0000 | [diff] [blame] | 7802 | if (!tg3_flag(tp, PCI_EXPRESS)) { |
| 7803 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 7804 | tp->pci_cacheline_sz); |
| 7805 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 7806 | tp->pci_lat_timer); |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 7807 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 7808 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7809 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7810 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 7811 | u16 pcix_cmd; |
| 7812 | |
| 7813 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7814 | &pcix_cmd); |
| 7815 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 7816 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7817 | pcix_cmd); |
| 7818 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7819 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7820 | if (tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7821 | |
| 7822 | /* Chip reset on 5780 will reset MSI enable bit, |
| 7823 | * so need to restore it. |
| 7824 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7825 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7826 | u16 ctrl; |
| 7827 | |
| 7828 | pci_read_config_word(tp->pdev, |
| 7829 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7830 | &ctrl); |
| 7831 | pci_write_config_word(tp->pdev, |
| 7832 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7833 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 7834 | val = tr32(MSGINT_MODE); |
| 7835 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 7836 | } |
| 7837 | } |
| 7838 | } |
| 7839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7840 | /* tp->lock is held. */ |
| 7841 | static int tg3_chip_reset(struct tg3 *tp) |
| 7842 | { |
| 7843 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7844 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7845 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7846 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7847 | tg3_nvram_lock(tp); |
| 7848 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7849 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 7850 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7851 | /* No matching tg3_nvram_unlock() after this because |
| 7852 | * chip reset below will undo the nvram lock. |
| 7853 | */ |
| 7854 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7855 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7856 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 7857 | * enable bit in PCI register 4 and the MSI enable bit |
| 7858 | * on some chips, so we save relevant registers here. |
| 7859 | */ |
| 7860 | tg3_save_pci_state(tp); |
| 7861 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7862 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7863 | tg3_flag(tp, 5755_PLUS)) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7864 | tw32(GRC_FASTBOOT_PC, 0); |
| 7865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7866 | /* |
| 7867 | * We must avoid the readl() that normally takes place. |
| 7868 | * It locks machines, causes machine checks, and other |
| 7869 | * fun things. So, temporarily disable the 5701 |
| 7870 | * hardware workaround, while we do the reset. |
| 7871 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7872 | write_op = tp->write32; |
| 7873 | if (write_op == tg3_write_flush_reg32) |
| 7874 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7875 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7876 | /* Prevent the irq handler from reading or writing PCI registers |
| 7877 | * during chip reset when the memory enable bit in the PCI command |
| 7878 | * register may be cleared. The chip does not generate interrupt |
| 7879 | * at this time, but the irq handler may still be called due to irq |
| 7880 | * sharing or irqpoll. |
| 7881 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7882 | tg3_flag_set(tp, CHIP_RESETTING); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7883 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7884 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7885 | if (tnapi->hw_status) { |
| 7886 | tnapi->hw_status->status = 0; |
| 7887 | tnapi->hw_status->status_tag = 0; |
| 7888 | } |
| 7889 | tnapi->last_tag = 0; |
| 7890 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 7891 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7892 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7893 | |
| 7894 | for (i = 0; i < tp->irq_cnt; i++) |
| 7895 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7896 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7897 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7898 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7899 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 7900 | } |
| 7901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7902 | /* do the reset */ |
| 7903 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 7904 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7905 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7906 | /* Force PCIe 1.0a mode */ |
| 7907 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7908 | !tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7909 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 7910 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 7911 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 7912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7913 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 7914 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 7915 | val |= (1 << 29); |
| 7916 | } |
| 7917 | } |
| 7918 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7919 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7920 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 7921 | tw32(GRC_VCPU_EXT_CTRL, |
| 7922 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7923 | } |
| 7924 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7925 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7926 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7927 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7929 | tw32(GRC_MISC_CFG, val); |
| 7930 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7931 | /* restore 5701 hardware bug workaround write method */ |
| 7932 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7933 | |
| 7934 | /* Unfortunately, we have to delay before the PCI read back. |
| 7935 | * Some 575X chips even will not respond to a PCI cfg access |
| 7936 | * when the reset command is given to the chip. |
| 7937 | * |
| 7938 | * How do these hardware designers expect things to work |
| 7939 | * properly if the PCI write is posted for a long period |
| 7940 | * of time? It is always necessary to have some method by |
| 7941 | * which a register read back can occur to push the write |
| 7942 | * out which does the reset. |
| 7943 | * |
| 7944 | * For most tg3 variants the trick below was working. |
| 7945 | * Ho hum... |
| 7946 | */ |
| 7947 | udelay(120); |
| 7948 | |
| 7949 | /* Flush PCI posted writes. The normal MMIO registers |
| 7950 | * are inaccessible at this time so this is the only |
| 7951 | * way to make this reliably (actually, this is no longer |
| 7952 | * the case, see above). I tried to use indirect |
| 7953 | * register read/write but this upset some 5701 variants. |
| 7954 | */ |
| 7955 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 7956 | |
| 7957 | udelay(120); |
| 7958 | |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7959 | if (tg3_flag(tp, PCI_EXPRESS) && pci_pcie_cap(tp->pdev)) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7960 | u16 val16; |
| 7961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7962 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
| 7963 | int i; |
| 7964 | u32 cfg_val; |
| 7965 | |
| 7966 | /* Wait for link training to complete. */ |
| 7967 | for (i = 0; i < 5000; i++) |
| 7968 | udelay(100); |
| 7969 | |
| 7970 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 7971 | pci_write_config_dword(tp->pdev, 0xc4, |
| 7972 | cfg_val | (1 << 15)); |
| 7973 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7974 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7975 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
| 7976 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7977 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7978 | &val16); |
| 7979 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | |
| 7980 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 7981 | /* |
| 7982 | * Older PCIe devices only support the 128 byte |
| 7983 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7984 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7985 | if (!tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7986 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7987 | pci_write_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7988 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7989 | val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7990 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7991 | /* Clear error status */ |
| 7992 | pci_write_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7993 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVSTA, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7994 | PCI_EXP_DEVSTA_CED | |
| 7995 | PCI_EXP_DEVSTA_NFED | |
| 7996 | PCI_EXP_DEVSTA_FED | |
| 7997 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7998 | } |
| 7999 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8000 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8001 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8002 | tg3_flag_clear(tp, CHIP_RESETTING); |
| 8003 | tg3_flag_clear(tp, ERROR_PROCESSED); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8004 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8005 | val = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8006 | if (tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 8007 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8008 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8009 | |
| 8010 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 8011 | tg3_stop_fw(tp); |
| 8012 | tw32(0x5000, 0x400); |
| 8013 | } |
| 8014 | |
| 8015 | tw32(GRC_MODE, tp->grc_mode); |
| 8016 | |
| 8017 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8018 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8019 | |
| 8020 | tw32(0xc4, val | (1 << 15)); |
| 8021 | } |
| 8022 | |
| 8023 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 8024 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 8025 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 8026 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 8027 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 8028 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8029 | } |
| 8030 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8031 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8032 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8033 | val = tp->mac_mode; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8034 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8035 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8036 | val = tp->mac_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8037 | } else |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8038 | val = 0; |
| 8039 | |
| 8040 | tw32_f(MAC_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8041 | udelay(40); |
| 8042 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8043 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 8044 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 8045 | err = tg3_poll_fw(tp); |
| 8046 | if (err) |
| 8047 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8048 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 8049 | tg3_mdio_start(tp); |
| 8050 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8051 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8052 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 8053 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8054 | !tg3_flag(tp, 57765_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8055 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8056 | |
| 8057 | tw32(0x7c00, val | (1 << 25)); |
| 8058 | } |
| 8059 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8060 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 8061 | val = tr32(TG3_CPMU_CLCK_ORIDE); |
| 8062 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 8063 | } |
| 8064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8065 | /* Reprobe ASF enable state. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8066 | tg3_flag_clear(tp, ENABLE_ASF); |
| 8067 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8068 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 8069 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 8070 | u32 nic_cfg; |
| 8071 | |
| 8072 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 8073 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8074 | tg3_flag_set(tp, ENABLE_ASF); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8075 | tp->last_event_jiffies = jiffies; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8076 | if (tg3_flag(tp, 5750_PLUS)) |
| 8077 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8078 | } |
| 8079 | } |
| 8080 | |
| 8081 | return 0; |
| 8082 | } |
| 8083 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 8084 | static void tg3_get_nstats(struct tg3 *, struct rtnl_link_stats64 *); |
| 8085 | static void tg3_get_estats(struct tg3 *, struct tg3_ethtool_stats *); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8087 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8088 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8089 | { |
| 8090 | int err; |
| 8091 | |
| 8092 | tg3_stop_fw(tp); |
| 8093 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8094 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8095 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8096 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8097 | err = tg3_chip_reset(tp); |
| 8098 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 8099 | __tg3_set_mac_addr(tp, 0); |
| 8100 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8101 | tg3_write_sig_legacy(tp, kind); |
| 8102 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8103 | |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8104 | if (tp->hw_stats) { |
| 8105 | /* Save the stats across chip resets... */ |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 8106 | tg3_get_nstats(tp, &tp->net_stats_prev); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8107 | tg3_get_estats(tp, &tp->estats_prev); |
| 8108 | |
| 8109 | /* And make sure the next sample is new data */ |
| 8110 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 8111 | } |
| 8112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8113 | if (err) |
| 8114 | return err; |
| 8115 | |
| 8116 | return 0; |
| 8117 | } |
| 8118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8119 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 8120 | { |
| 8121 | struct tg3 *tp = netdev_priv(dev); |
| 8122 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8123 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8124 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8125 | if (!is_valid_ether_addr(addr->sa_data)) |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 8126 | return -EADDRNOTAVAIL; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8128 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 8129 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 8130 | if (!netif_running(dev)) |
| 8131 | return 0; |
| 8132 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8133 | if (tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8134 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8135 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8136 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 8137 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 8138 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 8139 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 8140 | |
| 8141 | /* Skip MAC addr 1 if ASF is using it. */ |
| 8142 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 8143 | !(addr1_high == 0 && addr1_low == 0)) |
| 8144 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8145 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8146 | spin_lock_bh(&tp->lock); |
| 8147 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 8148 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8149 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 8150 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8151 | } |
| 8152 | |
| 8153 | /* tp->lock is held. */ |
| 8154 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 8155 | dma_addr_t mapping, u32 maxlen_flags, |
| 8156 | u32 nic_addr) |
| 8157 | { |
| 8158 | tg3_write_mem(tp, |
| 8159 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 8160 | ((u64) mapping >> 32)); |
| 8161 | tg3_write_mem(tp, |
| 8162 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 8163 | ((u64) mapping & 0xffffffff)); |
| 8164 | tg3_write_mem(tp, |
| 8165 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 8166 | maxlen_flags); |
| 8167 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8168 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8169 | tg3_write_mem(tp, |
| 8170 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 8171 | nic_addr); |
| 8172 | } |
| 8173 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 8174 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8175 | { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8176 | int i; |
| 8177 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8178 | if (!tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8179 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 8180 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 8181 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8182 | } else { |
| 8183 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 8184 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 8185 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8186 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8187 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8188 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8189 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 8190 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 8191 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
| 8192 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8193 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 8194 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 8195 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8196 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8197 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8198 | if (!tg3_flag(tp, 5705_PLUS)) { |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8199 | u32 val = ec->stats_block_coalesce_usecs; |
| 8200 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8201 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 8202 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 8203 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8204 | if (!netif_carrier_ok(tp->dev)) |
| 8205 | val = 0; |
| 8206 | |
| 8207 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 8208 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8209 | |
| 8210 | for (i = 0; i < tp->irq_cnt - 1; i++) { |
| 8211 | u32 reg; |
| 8212 | |
| 8213 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 8214 | tw32(reg, ec->rx_coalesce_usecs); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8215 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 8216 | tw32(reg, ec->rx_max_coalesced_frames); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8217 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8218 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8219 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8220 | if (tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8221 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 8222 | tw32(reg, ec->tx_coalesce_usecs); |
| 8223 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 8224 | tw32(reg, ec->tx_max_coalesced_frames); |
| 8225 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8226 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 8227 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8228 | } |
| 8229 | |
| 8230 | for (; i < tp->irq_max - 1; i++) { |
| 8231 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8232 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8233 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8234 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8235 | if (tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8236 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 8237 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 8238 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 8239 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8240 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8242 | |
| 8243 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8244 | static void tg3_rings_reset(struct tg3 *tp) |
| 8245 | { |
| 8246 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8247 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8248 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 8249 | |
| 8250 | /* Disable all transmit rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8251 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8252 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8253 | else if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 8254 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8255 | else if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8256 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8257 | else |
| 8258 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8259 | |
| 8260 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8261 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 8262 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8263 | BDINFO_FLAGS_DISABLED); |
| 8264 | |
| 8265 | |
| 8266 | /* Disable all receive return rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8267 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8268 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8269 | else if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8270 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8271 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8272 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8273 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 8274 | else |
| 8275 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8276 | |
| 8277 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8278 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 8279 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8280 | BDINFO_FLAGS_DISABLED); |
| 8281 | |
| 8282 | /* Disable interrupts */ |
| 8283 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8284 | tp->napi[0].chk_msi_cnt = 0; |
| 8285 | tp->napi[0].last_rx_cons = 0; |
| 8286 | tp->napi[0].last_tx_cons = 0; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8287 | |
| 8288 | /* Zero mailbox registers. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8289 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 8290 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8291 | tp->napi[i].tx_prod = 0; |
| 8292 | tp->napi[i].tx_cons = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8293 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8294 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8295 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 8296 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 8297 | tp->napi[i].chk_msi_cnt = 0; |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8298 | tp->napi[i].last_rx_cons = 0; |
| 8299 | tp->napi[i].last_tx_cons = 0; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8300 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8301 | if (!tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8302 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8303 | } else { |
| 8304 | tp->napi[0].tx_prod = 0; |
| 8305 | tp->napi[0].tx_cons = 0; |
| 8306 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 8307 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 8308 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8309 | |
| 8310 | /* Make sure the NIC-based send BD rings are disabled. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8311 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8312 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 8313 | for (i = 0; i < 16; i++) |
| 8314 | tw32_tx_mbox(mbox + i * 8, 0); |
| 8315 | } |
| 8316 | |
| 8317 | txrcb = NIC_SRAM_SEND_RCB; |
| 8318 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 8319 | |
| 8320 | /* Clear status block in ram. */ |
| 8321 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8322 | |
| 8323 | /* Set status block DMA address */ |
| 8324 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 8325 | ((u64) tnapi->status_mapping >> 32)); |
| 8326 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 8327 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 8328 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8329 | if (tnapi->tx_ring) { |
| 8330 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8331 | (TG3_TX_RING_SIZE << |
| 8332 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8333 | NIC_SRAM_TX_BUFFER_DESC); |
| 8334 | txrcb += TG3_BDINFO_SIZE; |
| 8335 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8336 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8337 | if (tnapi->rx_rcb) { |
| 8338 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8339 | (tp->rx_ret_ring_mask + 1) << |
| 8340 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8341 | rxrcb += TG3_BDINFO_SIZE; |
| 8342 | } |
| 8343 | |
| 8344 | stblk = HOSTCC_STATBLCK_RING1; |
| 8345 | |
| 8346 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 8347 | u64 mapping = (u64)tnapi->status_mapping; |
| 8348 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 8349 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 8350 | |
| 8351 | /* Clear status block in ram. */ |
| 8352 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8353 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8354 | if (tnapi->tx_ring) { |
| 8355 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8356 | (TG3_TX_RING_SIZE << |
| 8357 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8358 | NIC_SRAM_TX_BUFFER_DESC); |
| 8359 | txrcb += TG3_BDINFO_SIZE; |
| 8360 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8361 | |
| 8362 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8363 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8364 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 8365 | |
| 8366 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8367 | rxrcb += TG3_BDINFO_SIZE; |
| 8368 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8369 | } |
| 8370 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8371 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
| 8372 | { |
| 8373 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; |
| 8374 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8375 | if (!tg3_flag(tp, 5750_PLUS) || |
| 8376 | tg3_flag(tp, 5780_CLASS) || |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8377 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8378 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 8379 | tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8380 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
| 8381 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 8382 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) |
| 8383 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
| 8384 | else |
| 8385 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; |
| 8386 | |
| 8387 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); |
| 8388 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); |
| 8389 | |
| 8390 | val = min(nic_rep_thresh, host_rep_thresh); |
| 8391 | tw32(RCVBDI_STD_THRESH, val); |
| 8392 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8393 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8394 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
| 8395 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8396 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8397 | return; |
| 8398 | |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8399 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8400 | |
| 8401 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); |
| 8402 | |
| 8403 | val = min(bdcache_maxcnt / 2, host_rep_thresh); |
| 8404 | tw32(RCVBDI_JUMBO_THRESH, val); |
| 8405 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8406 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8407 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
| 8408 | } |
| 8409 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 8410 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 8411 | { |
| 8412 | u32 reg; |
| 8413 | u32 tmp; |
| 8414 | int j, k; |
| 8415 | |
| 8416 | reg = 0xffffffff; |
| 8417 | |
| 8418 | for (j = 0; j < len; j++) { |
| 8419 | reg ^= buf[j]; |
| 8420 | |
| 8421 | for (k = 0; k < 8; k++) { |
| 8422 | tmp = reg & 0x01; |
| 8423 | |
| 8424 | reg >>= 1; |
| 8425 | |
| 8426 | if (tmp) |
| 8427 | reg ^= 0xedb88320; |
| 8428 | } |
| 8429 | } |
| 8430 | |
| 8431 | return ~reg; |
| 8432 | } |
| 8433 | |
| 8434 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 8435 | { |
| 8436 | /* accept or reject all multicast frames */ |
| 8437 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 8438 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 8439 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 8440 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 8441 | } |
| 8442 | |
| 8443 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 8444 | { |
| 8445 | struct tg3 *tp = netdev_priv(dev); |
| 8446 | u32 rx_mode; |
| 8447 | |
| 8448 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 8449 | RX_MODE_KEEP_VLAN_TAG); |
| 8450 | |
| 8451 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
| 8452 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 8453 | * flag clear. |
| 8454 | */ |
| 8455 | if (!tg3_flag(tp, ENABLE_ASF)) |
| 8456 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 8457 | #endif |
| 8458 | |
| 8459 | if (dev->flags & IFF_PROMISC) { |
| 8460 | /* Promiscuous mode. */ |
| 8461 | rx_mode |= RX_MODE_PROMISC; |
| 8462 | } else if (dev->flags & IFF_ALLMULTI) { |
| 8463 | /* Accept all multicast. */ |
| 8464 | tg3_set_multi(tp, 1); |
| 8465 | } else if (netdev_mc_empty(dev)) { |
| 8466 | /* Reject all multicast. */ |
| 8467 | tg3_set_multi(tp, 0); |
| 8468 | } else { |
| 8469 | /* Accept one or more multicast(s). */ |
| 8470 | struct netdev_hw_addr *ha; |
| 8471 | u32 mc_filter[4] = { 0, }; |
| 8472 | u32 regidx; |
| 8473 | u32 bit; |
| 8474 | u32 crc; |
| 8475 | |
| 8476 | netdev_for_each_mc_addr(ha, dev) { |
| 8477 | crc = calc_crc(ha->addr, ETH_ALEN); |
| 8478 | bit = ~crc & 0x7f; |
| 8479 | regidx = (bit & 0x60) >> 5; |
| 8480 | bit &= 0x1f; |
| 8481 | mc_filter[regidx] |= (1 << bit); |
| 8482 | } |
| 8483 | |
| 8484 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 8485 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 8486 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 8487 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 8488 | } |
| 8489 | |
| 8490 | if (rx_mode != tp->rx_mode) { |
| 8491 | tp->rx_mode = rx_mode; |
| 8492 | tw32_f(MAC_RX_MODE, rx_mode); |
| 8493 | udelay(10); |
| 8494 | } |
| 8495 | } |
| 8496 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8497 | static void tg3_rss_init_dflt_indir_tbl(struct tg3 *tp) |
| 8498 | { |
| 8499 | int i; |
| 8500 | |
| 8501 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 8502 | tp->rss_ind_tbl[i] = |
| 8503 | ethtool_rxfh_indir_default(i, tp->irq_cnt - 1); |
| 8504 | } |
| 8505 | |
| 8506 | static void tg3_rss_check_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8507 | { |
| 8508 | int i; |
| 8509 | |
| 8510 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 8511 | return; |
| 8512 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8513 | if (tp->irq_cnt <= 2) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8514 | memset(&tp->rss_ind_tbl[0], 0, sizeof(tp->rss_ind_tbl)); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8515 | return; |
| 8516 | } |
| 8517 | |
| 8518 | /* Validate table against current IRQ count */ |
| 8519 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
| 8520 | if (tp->rss_ind_tbl[i] >= tp->irq_cnt - 1) |
| 8521 | break; |
| 8522 | } |
| 8523 | |
| 8524 | if (i != TG3_RSS_INDIR_TBL_SIZE) |
| 8525 | tg3_rss_init_dflt_indir_tbl(tp); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8526 | } |
| 8527 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8528 | static void tg3_rss_write_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8529 | { |
| 8530 | int i = 0; |
| 8531 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8532 | |
| 8533 | while (i < TG3_RSS_INDIR_TBL_SIZE) { |
| 8534 | u32 val = tp->rss_ind_tbl[i]; |
| 8535 | i++; |
| 8536 | for (; i % 8; i++) { |
| 8537 | val <<= 4; |
| 8538 | val |= tp->rss_ind_tbl[i]; |
| 8539 | } |
| 8540 | tw32(reg, val); |
| 8541 | reg += 4; |
| 8542 | } |
| 8543 | } |
| 8544 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8545 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8546 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8547 | { |
| 8548 | u32 val, rdmac_mode; |
| 8549 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8550 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8551 | |
| 8552 | tg3_disable_ints(tp); |
| 8553 | |
| 8554 | tg3_stop_fw(tp); |
| 8555 | |
| 8556 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 8557 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8558 | if (tg3_flag(tp, INIT_COMPLETE)) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8559 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8560 | |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8561 | /* Enable MAC control of LPI */ |
| 8562 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
| 8563 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, |
| 8564 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 8565 | TG3_CPMU_EEE_LNKIDL_UART_IDL); |
| 8566 | |
| 8567 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 8568 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 8569 | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8570 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 8571 | TG3_CPMU_EEEMD_LPI_IN_TX | |
| 8572 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 8573 | TG3_CPMU_EEEMD_EEE_ENABLE; |
| 8574 | |
| 8575 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 8576 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
| 8577 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8578 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8579 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
| 8580 | |
| 8581 | tw32_f(TG3_CPMU_EEE_MODE, val); |
| 8582 | |
| 8583 | tw32_f(TG3_CPMU_EEE_DBTMR1, |
| 8584 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | |
| 8585 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); |
| 8586 | |
| 8587 | tw32_f(TG3_CPMU_EEE_DBTMR2, |
Matt Carlson | d7f2ab2 | 2011-01-25 15:58:56 +0000 | [diff] [blame] | 8588 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8589 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8590 | } |
| 8591 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 8592 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 8593 | tg3_phy_reset(tp); |
| 8594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8595 | err = tg3_chip_reset(tp); |
| 8596 | if (err) |
| 8597 | return err; |
| 8598 | |
| 8599 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 8600 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 8601 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8602 | val = tr32(TG3_CPMU_CTRL); |
| 8603 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 8604 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 8605 | |
| 8606 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 8607 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 8608 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 8609 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 8610 | |
| 8611 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 8612 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 8613 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 8614 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 8615 | |
| 8616 | val = tr32(TG3_CPMU_HST_ACC); |
| 8617 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 8618 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 8619 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8620 | } |
| 8621 | |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 8622 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 8623 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 8624 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 8625 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 8626 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 8627 | |
| 8628 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 8629 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 8630 | |
| 8631 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 8632 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 8633 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 8634 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 8635 | } |
| 8636 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8637 | if (tg3_flag(tp, L1PLLPD_EN)) { |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 8638 | u32 grc_mode = tr32(GRC_MODE); |
| 8639 | |
| 8640 | /* Access the lower 1K of PL PCIE block registers. */ |
| 8641 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8642 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 8643 | |
| 8644 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 8645 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 8646 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 8647 | |
| 8648 | tw32(GRC_MODE, grc_mode); |
| 8649 | } |
| 8650 | |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8651 | if (tg3_flag(tp, 57765_CLASS)) { |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8652 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 8653 | u32 grc_mode = tr32(GRC_MODE); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8654 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8655 | /* Access the lower 1K of PL PCIE block registers. */ |
| 8656 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8657 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8658 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8659 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 8660 | TG3_PCIE_PL_LO_PHYCTL5); |
| 8661 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 8662 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8663 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8664 | tw32(GRC_MODE, grc_mode); |
| 8665 | } |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 8666 | |
Matt Carlson | 1ff30a5 | 2011-05-19 12:12:46 +0000 | [diff] [blame] | 8667 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_57765_AX) { |
| 8668 | u32 grc_mode = tr32(GRC_MODE); |
| 8669 | |
| 8670 | /* Access the lower 1K of DL PCIE block registers. */ |
| 8671 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8672 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); |
| 8673 | |
| 8674 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 8675 | TG3_PCIE_DL_LO_FTSMAX); |
| 8676 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; |
| 8677 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, |
| 8678 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); |
| 8679 | |
| 8680 | tw32(GRC_MODE, grc_mode); |
| 8681 | } |
| 8682 | |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 8683 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 8684 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 8685 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 8686 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8687 | } |
| 8688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8689 | /* This works around an issue with Athlon chipsets on |
| 8690 | * B3 tigon3 silicon. This bit has no effect on any |
| 8691 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8692 | * chips and don't even touch the clocks if the CPMU is present. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8693 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8694 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
| 8695 | if (!tg3_flag(tp, PCI_EXPRESS)) |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8696 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 8697 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8698 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8699 | |
| 8700 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8701 | tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8702 | val = tr32(TG3PCI_PCISTATE); |
| 8703 | val |= PCISTATE_RETRY_SAME_DMA; |
| 8704 | tw32(TG3PCI_PCISTATE, val); |
| 8705 | } |
| 8706 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8707 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8708 | /* Allow reads and writes to the |
| 8709 | * APE register and memory space. |
| 8710 | */ |
| 8711 | val = tr32(TG3PCI_PCISTATE); |
| 8712 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 8713 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 8714 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8715 | tw32(TG3PCI_PCISTATE, val); |
| 8716 | } |
| 8717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8718 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 8719 | /* Enable some hw fixes. */ |
| 8720 | val = tr32(TG3PCI_MSI_DATA); |
| 8721 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 8722 | tw32(TG3PCI_MSI_DATA, val); |
| 8723 | } |
| 8724 | |
| 8725 | /* Descriptor ring init may make accesses to the |
| 8726 | * NIC SRAM area to setup the TX descriptors, so we |
| 8727 | * can only do this after the hardware has been |
| 8728 | * successfully reset. |
| 8729 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 8730 | err = tg3_init_rings(tp); |
| 8731 | if (err) |
| 8732 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8733 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8734 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8735 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 8736 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 8737 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 8738 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8739 | if (!tg3_flag(tp, 57765_CLASS) && |
Matt Carlson | 0aebff4 | 2011-04-25 12:42:45 +0000 | [diff] [blame] | 8740 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 8741 | val |= DMA_RWCTRL_TAGGED_STAT_WA; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8742 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 8743 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 8744 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8745 | /* This value is determined during the probe time DMA |
| 8746 | * engine test, tg3_test_dma. |
| 8747 | */ |
| 8748 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 8749 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8750 | |
| 8751 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 8752 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 8753 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 8754 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 8755 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 8756 | |
| 8757 | /* Pseudo-header checksum is done by hardware logic and not |
| 8758 | * the offload processers, so make the chip do the pseudo- |
| 8759 | * header checksums on receive. For transmit it is more |
| 8760 | * convenient to do the pseudo-header checksum in software |
| 8761 | * as Linux does that on transmit for us in all cases. |
| 8762 | */ |
| 8763 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8764 | |
| 8765 | tw32(GRC_MODE, |
| 8766 | tp->grc_mode | |
| 8767 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); |
| 8768 | |
| 8769 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 8770 | val = tr32(GRC_MISC_CFG); |
| 8771 | val &= ~0xff; |
| 8772 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 8773 | tw32(GRC_MISC_CFG, val); |
| 8774 | |
| 8775 | /* Initialize MBUF/DESC pool. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8776 | if (tg3_flag(tp, 5750_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8777 | /* Do nothing. */ |
| 8778 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 8779 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 8780 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 8781 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 8782 | else |
| 8783 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 8784 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 8785 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8786 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8787 | int fw_len; |
| 8788 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 8789 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8790 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 8791 | tw32(BUFMGR_MB_POOL_ADDR, |
| 8792 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 8793 | tw32(BUFMGR_MB_POOL_SIZE, |
| 8794 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 8795 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8796 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8797 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8798 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8799 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 8800 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8801 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 8802 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8803 | tp->bufmgr_config.mbuf_high_water); |
| 8804 | } else { |
| 8805 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8806 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 8807 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8808 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 8809 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8810 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 8811 | } |
| 8812 | tw32(BUFMGR_DMA_LOW_WATER, |
| 8813 | tp->bufmgr_config.dma_low_water); |
| 8814 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 8815 | tp->bufmgr_config.dma_high_water); |
| 8816 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8817 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 8818 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 8819 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 8820 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8821 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 8822 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) |
| 8823 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8824 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8825 | for (i = 0; i < 2000; i++) { |
| 8826 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 8827 | break; |
| 8828 | udelay(10); |
| 8829 | } |
| 8830 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8831 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8832 | return -ENODEV; |
| 8833 | } |
| 8834 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8835 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 8836 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8837 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8838 | tg3_setup_rxbd_thresholds(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8839 | |
| 8840 | /* Initialize TG3_BDINFO's at: |
| 8841 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 8842 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 8843 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 8844 | * |
| 8845 | * like so: |
| 8846 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 8847 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 8848 | * ring attribute flags |
| 8849 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 8850 | * |
| 8851 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 8852 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 8853 | * |
| 8854 | * The size of each ring is fixed in the firmware, but the location is |
| 8855 | * configurable. |
| 8856 | */ |
| 8857 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8858 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8859 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8860 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8861 | if (!tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8862 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 8863 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8864 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8865 | /* Disable the mini ring */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8866 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8867 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8868 | BDINFO_FLAGS_DISABLED); |
| 8869 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8870 | /* Program the jumbo buffer descriptor ring control |
| 8871 | * blocks on those devices that have them. |
| 8872 | */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 8873 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8874 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8875 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8876 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8877 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8878 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8879 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8880 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8881 | val = TG3_RX_JMB_RING_SIZE(tp) << |
| 8882 | BDINFO_FLAGS_MAXLEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8883 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8884 | val | BDINFO_FLAGS_USE_EXT_RECV); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8885 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8886 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8887 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 8888 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8889 | } else { |
| 8890 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8891 | BDINFO_FLAGS_DISABLED); |
| 8892 | } |
| 8893 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8894 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 8895 | val = TG3_RX_STD_RING_SIZE(tp); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8896 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 8897 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 8898 | } else |
Matt Carlson | 04380d4 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 8899 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8900 | } else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8901 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8902 | |
| 8903 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8904 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 8905 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8906 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, tpr->rx_std_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8907 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8908 | tpr->rx_jmb_prod_idx = |
| 8909 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8910 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, tpr->rx_jmb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8911 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8912 | tg3_rings_reset(tp); |
| 8913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8914 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8915 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8916 | |
| 8917 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 8918 | tw32(MAC_RX_MTU_SIZE, |
| 8919 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8920 | |
| 8921 | /* The slot time is changed by tg3_setup_phy if we |
| 8922 | * run at gigabit with half duplex. |
| 8923 | */ |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8924 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 8925 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 8926 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); |
| 8927 | |
| 8928 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 8929 | val |= tr32(MAC_TX_LENGTHS) & |
| 8930 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 8931 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 8932 | |
| 8933 | tw32(MAC_TX_LENGTHS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8934 | |
| 8935 | /* Receive rules. */ |
| 8936 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 8937 | tw32(RCVLPC_CONFIG, 0x0181); |
| 8938 | |
| 8939 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 8940 | * the RCVLPC_STATE_ENABLE mask. |
| 8941 | */ |
| 8942 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 8943 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 8944 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 8945 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 8946 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8947 | |
Matt Carlson | deabaac | 2010-11-24 08:31:50 +0000 | [diff] [blame] | 8948 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 8949 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 8950 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 8951 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8952 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8953 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8954 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 8955 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 8956 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 8957 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 8958 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8959 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8960 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 8961 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8962 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 8963 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8964 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8965 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8966 | } |
| 8967 | } |
| 8968 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8969 | if (tg3_flag(tp, PCI_EXPRESS)) |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8970 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8971 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8972 | if (tg3_flag(tp, HW_TSO_1) || |
| 8973 | tg3_flag(tp, HW_TSO_2) || |
| 8974 | tg3_flag(tp, HW_TSO_3)) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8975 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 8976 | |
Matt Carlson | 108a6c1 | 2011-05-19 12:12:47 +0000 | [diff] [blame] | 8977 | if (tg3_flag(tp, 57765_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 8978 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8979 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 8980 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8981 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8982 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 8983 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
| 8984 | |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8985 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 8986 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 8987 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8988 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8989 | tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8990 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8991 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 8992 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | b4495ed | 2011-01-25 15:58:47 +0000 | [diff] [blame] | 8993 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
| 8994 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | |
| 8995 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); |
| 8996 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | |
| 8997 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | |
| 8998 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; |
Matt Carlson | b75cc0e | 2010-11-24 08:31:46 +0000 | [diff] [blame] | 8999 | } |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 9000 | tw32(TG3_RDMA_RSRVCTRL_REG, |
| 9001 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
| 9002 | } |
| 9003 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 9004 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 9005 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9006 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 9007 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | |
| 9008 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 9009 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 9010 | } |
| 9011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9012 | /* Receive/send statistics. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9013 | if (tg3_flag(tp, 5750_PLUS)) { |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 9014 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9015 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 9016 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9017 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9018 | tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9019 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9020 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 9021 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9022 | } else { |
| 9023 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 9024 | } |
| 9025 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 9026 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 9027 | tw32(SNDDATAI_STATSCTRL, |
| 9028 | (SNDDATAI_SCTRL_ENABLE | |
| 9029 | SNDDATAI_SCTRL_FASTUPD)); |
| 9030 | |
| 9031 | /* Setup host coalescing engine. */ |
| 9032 | tw32(HOSTCC_MODE, 0); |
| 9033 | for (i = 0; i < 2000; i++) { |
| 9034 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 9035 | break; |
| 9036 | udelay(10); |
| 9037 | } |
| 9038 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 9039 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9040 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9041 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9042 | /* Status/statistics block address. See tg3_timer, |
| 9043 | * the tg3_periodic_fetch_stats call there, and |
| 9044 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 9045 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9046 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 9047 | ((u64) tp->stats_mapping >> 32)); |
| 9048 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 9049 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 9050 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9052 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9053 | |
| 9054 | /* Clear statistics and status block memory areas */ |
| 9055 | for (i = NIC_SRAM_STATS_BLK; |
| 9056 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 9057 | i += sizeof(u32)) { |
| 9058 | tg3_write_mem(tp, i, 0); |
| 9059 | udelay(40); |
| 9060 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9061 | } |
| 9062 | |
| 9063 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 9064 | |
| 9065 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 9066 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9067 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9068 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 9069 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9070 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 9071 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 9072 | /* reset to prevent losing 1st rx packet intermittently */ |
| 9073 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9074 | udelay(10); |
| 9075 | } |
| 9076 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 9077 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 9078 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
| 9079 | MAC_MODE_FHDE_ENABLE; |
| 9080 | if (tg3_flag(tp, ENABLE_APE)) |
| 9081 | tp->mac_mode |= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9082 | if (!tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9083 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 9084 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 9085 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9086 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 9087 | udelay(40); |
| 9088 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9089 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9090 | * If TG3_FLAG_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9091 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 9092 | * whether used as inputs or outputs, are set by boot code after |
| 9093 | * reset. |
| 9094 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9095 | if (!tg3_flag(tp, IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9096 | u32 gpio_mask; |
| 9097 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9098 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 9099 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 9100 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 9101 | |
| 9102 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 9103 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 9104 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 9105 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9106 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 9107 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 9108 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 9109 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9110 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 9111 | |
| 9112 | /* GPIO1 must be driven high for eeprom write protect */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9113 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9114 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 9115 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9117 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9118 | udelay(100); |
| 9119 | |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9120 | if (tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9121 | val = tr32(MSGINT_MODE); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9122 | val |= MSGINT_MODE_ENABLE; |
| 9123 | if (tp->irq_cnt > 1) |
| 9124 | val |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9125 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 9126 | val |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9127 | tw32(MSGINT_MODE, val); |
| 9128 | } |
| 9129 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9130 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9131 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 9132 | udelay(40); |
| 9133 | } |
| 9134 | |
| 9135 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 9136 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 9137 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 9138 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 9139 | WDMAC_MODE_LNGREAD_ENAB); |
| 9140 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 9141 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 9142 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9143 | if (tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9144 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 9145 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 9146 | /* nothing */ |
| 9147 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9148 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9149 | val |= WDMAC_MODE_RX_ACCEL; |
| 9150 | } |
| 9151 | } |
| 9152 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9153 | /* Enable host coalescing bug fix */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9154 | if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 9155 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9156 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 9157 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 9158 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 9159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9160 | tw32_f(WDMAC_MODE, val); |
| 9161 | udelay(40); |
| 9162 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9163 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9164 | u16 pcix_cmd; |
| 9165 | |
| 9166 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9167 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9168 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9169 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 9170 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9171 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9172 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 9173 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9174 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9175 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9176 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9177 | } |
| 9178 | |
| 9179 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 9180 | udelay(40); |
| 9181 | |
| 9182 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9183 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9184 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9185 | |
| 9186 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 9187 | tw32(SNDDATAC_MODE, |
| 9188 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 9189 | else |
| 9190 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 9191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9192 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 9193 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9194 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9195 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9196 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 9197 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9198 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9199 | if (tg3_flag(tp, HW_TSO_1) || |
| 9200 | tg3_flag(tp, HW_TSO_2) || |
| 9201 | tg3_flag(tp, HW_TSO_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9202 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9203 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9204 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9205 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 9206 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9207 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 9208 | |
| 9209 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 9210 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 9211 | if (err) |
| 9212 | return err; |
| 9213 | } |
| 9214 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9215 | if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9216 | err = tg3_load_tso_firmware(tp); |
| 9217 | if (err) |
| 9218 | return err; |
| 9219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9220 | |
| 9221 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9222 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9223 | if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 9224 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 9225 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9226 | |
| 9227 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 9228 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
| 9229 | tp->tx_mode &= ~val; |
| 9230 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; |
| 9231 | } |
| 9232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9233 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 9234 | udelay(100); |
| 9235 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9236 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9237 | tg3_rss_write_indir_tbl(tp); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9238 | |
| 9239 | /* Setup the "secret" hash key. */ |
| 9240 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 9241 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 9242 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 9243 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 9244 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 9245 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 9246 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 9247 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 9248 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 9249 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 9250 | } |
| 9251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9252 | tp->rx_mode = RX_MODE_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9253 | if (tg3_flag(tp, 5755_PLUS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9254 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 9255 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9256 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9257 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 9258 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 9259 | RX_MODE_RSS_IPV6_HASH_EN | |
| 9260 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 9261 | RX_MODE_RSS_IPV4_HASH_EN | |
| 9262 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 9263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9264 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9265 | udelay(10); |
| 9266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9267 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 9268 | |
| 9269 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9270 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9271 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9272 | udelay(10); |
| 9273 | } |
| 9274 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9275 | udelay(10); |
| 9276 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9277 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9278 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9279 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9280 | /* Set drive transmission level to 1.2V */ |
| 9281 | /* only if the signal pre-emphasis bit is not set */ |
| 9282 | val = tr32(MAC_SERDES_CFG); |
| 9283 | val &= 0xfffff000; |
| 9284 | val |= 0x880; |
| 9285 | tw32(MAC_SERDES_CFG, val); |
| 9286 | } |
| 9287 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 9288 | tw32(MAC_SERDES_CFG, 0x616000); |
| 9289 | } |
| 9290 | |
| 9291 | /* Prevent chip from dropping frames when flow control |
| 9292 | * is enabled. |
| 9293 | */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9294 | if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 9295 | val = 1; |
| 9296 | else |
| 9297 | val = 2; |
| 9298 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9299 | |
| 9300 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9301 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9302 | /* Use hardware link auto-negotiation */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9303 | tg3_flag_set(tp, HW_AUTONEG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9304 | } |
| 9305 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9306 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 9307 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 9308 | u32 tmp; |
| 9309 | |
| 9310 | tmp = tr32(SERDES_RX_CTRL); |
| 9311 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 9312 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 9313 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 9314 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9315 | } |
| 9316 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9317 | if (!tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 9318 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9319 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9320 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9321 | err = tg3_setup_phy(tp, 0); |
| 9322 | if (err) |
| 9323 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9324 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9325 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 9326 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9327 | u32 tmp; |
| 9328 | |
| 9329 | /* Clear CRC stats. */ |
| 9330 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 9331 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9332 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 9333 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9334 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9335 | } |
| 9336 | } |
| 9337 | |
| 9338 | __tg3_set_rx_mode(tp->dev); |
| 9339 | |
| 9340 | /* Initialize receive rules. */ |
| 9341 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 9342 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9343 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 9344 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9345 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9346 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9347 | limit = 8; |
| 9348 | else |
| 9349 | limit = 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9350 | if (tg3_flag(tp, ENABLE_ASF)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9351 | limit -= 4; |
| 9352 | switch (limit) { |
| 9353 | case 16: |
| 9354 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 9355 | case 15: |
| 9356 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 9357 | case 14: |
| 9358 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 9359 | case 13: |
| 9360 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 9361 | case 12: |
| 9362 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 9363 | case 11: |
| 9364 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 9365 | case 10: |
| 9366 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 9367 | case 9: |
| 9368 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 9369 | case 8: |
| 9370 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 9371 | case 7: |
| 9372 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 9373 | case 6: |
| 9374 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 9375 | case 5: |
| 9376 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 9377 | case 4: |
| 9378 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 9379 | case 3: |
| 9380 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 9381 | case 2: |
| 9382 | case 1: |
| 9383 | |
| 9384 | default: |
| 9385 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 9386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9387 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9388 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 9389 | /* Write our heartbeat update interval to APE. */ |
| 9390 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 9391 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9393 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 9394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9395 | return 0; |
| 9396 | } |
| 9397 | |
| 9398 | /* Called at device open time to get the chip ready for |
| 9399 | * packet processing. Invoked with tp->lock held. |
| 9400 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9401 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9402 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9403 | tg3_switch_clocks(tp); |
| 9404 | |
| 9405 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 9406 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9407 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9408 | } |
| 9409 | |
| 9410 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 9411 | do { u32 __val = tr32(REG); \ |
| 9412 | (PSTAT)->low += __val; \ |
| 9413 | if ((PSTAT)->low < __val) \ |
| 9414 | (PSTAT)->high += 1; \ |
| 9415 | } while (0) |
| 9416 | |
| 9417 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 9418 | { |
| 9419 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 9420 | |
| 9421 | if (!netif_carrier_ok(tp->dev)) |
| 9422 | return; |
| 9423 | |
| 9424 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 9425 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 9426 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 9427 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 9428 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 9429 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 9430 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 9431 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 9432 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 9433 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 9434 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 9435 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 9436 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
| 9437 | |
| 9438 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 9439 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 9440 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 9441 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 9442 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 9443 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 9444 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 9445 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 9446 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 9447 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 9448 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 9449 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 9450 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 9451 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 9452 | |
| 9453 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
Matt Carlson | 310050f | 2011-05-19 12:12:55 +0000 | [diff] [blame] | 9454 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 9455 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0 && |
| 9456 | tp->pci_chip_rev_id != CHIPREV_ID_5720_A0) { |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 9457 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 9458 | } else { |
| 9459 | u32 val = tr32(HOSTCC_FLOW_ATTN); |
| 9460 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; |
| 9461 | if (val) { |
| 9462 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); |
| 9463 | sp->rx_discards.low += val; |
| 9464 | if (sp->rx_discards.low < val) |
| 9465 | sp->rx_discards.high += 1; |
| 9466 | } |
| 9467 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; |
| 9468 | } |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 9469 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9470 | } |
| 9471 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9472 | static void tg3_chk_missed_msi(struct tg3 *tp) |
| 9473 | { |
| 9474 | u32 i; |
| 9475 | |
| 9476 | for (i = 0; i < tp->irq_cnt; i++) { |
| 9477 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9478 | |
| 9479 | if (tg3_has_work(tnapi)) { |
| 9480 | if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && |
| 9481 | tnapi->last_tx_cons == tnapi->tx_cons) { |
| 9482 | if (tnapi->chk_msi_cnt < 1) { |
| 9483 | tnapi->chk_msi_cnt++; |
| 9484 | return; |
| 9485 | } |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 9486 | tg3_msi(0, tnapi); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9487 | } |
| 9488 | } |
| 9489 | tnapi->chk_msi_cnt = 0; |
| 9490 | tnapi->last_rx_cons = tnapi->rx_rcb_ptr; |
| 9491 | tnapi->last_tx_cons = tnapi->tx_cons; |
| 9492 | } |
| 9493 | } |
| 9494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9495 | static void tg3_timer(unsigned long __opaque) |
| 9496 | { |
| 9497 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9498 | |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 9499 | if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 9500 | goto restart_timer; |
| 9501 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9502 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9503 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9504 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9505 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9506 | tg3_chk_missed_msi(tp); |
| 9507 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9508 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9509 | /* All of this garbage is because when using non-tagged |
| 9510 | * IRQ status the mailbox/status_block protocol the chip |
| 9511 | * uses with the cpu is race prone. |
| 9512 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9513 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9514 | tw32(GRC_LOCAL_CTRL, |
| 9515 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 9516 | } else { |
| 9517 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 9518 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9520 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9521 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9522 | spin_unlock(&tp->lock); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 9523 | tg3_reset_task_schedule(tp); |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 9524 | goto restart_timer; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9526 | } |
| 9527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9528 | /* This part only runs once per second. */ |
| 9529 | if (!--tp->timer_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9530 | if (tg3_flag(tp, 5705_PLUS)) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9531 | tg3_periodic_fetch_stats(tp); |
| 9532 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 9533 | if (tp->setlpicnt && !--tp->setlpicnt) |
| 9534 | tg3_phy_eee_enable(tp); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 9535 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9536 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9537 | u32 mac_stat; |
| 9538 | int phy_event; |
| 9539 | |
| 9540 | mac_stat = tr32(MAC_STATUS); |
| 9541 | |
| 9542 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9543 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9544 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 9545 | phy_event = 1; |
| 9546 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 9547 | phy_event = 1; |
| 9548 | |
| 9549 | if (phy_event) |
| 9550 | tg3_setup_phy(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9551 | } else if (tg3_flag(tp, POLL_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9552 | u32 mac_stat = tr32(MAC_STATUS); |
| 9553 | int need_setup = 0; |
| 9554 | |
| 9555 | if (netif_carrier_ok(tp->dev) && |
| 9556 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 9557 | need_setup = 1; |
| 9558 | } |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 9559 | if (!netif_carrier_ok(tp->dev) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9560 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 9561 | MAC_STATUS_SIGNAL_DET))) { |
| 9562 | need_setup = 1; |
| 9563 | } |
| 9564 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 9565 | if (!tp->serdes_counter) { |
| 9566 | tw32_f(MAC_MODE, |
| 9567 | (tp->mac_mode & |
| 9568 | ~MAC_MODE_PORT_MODE_MASK)); |
| 9569 | udelay(40); |
| 9570 | tw32_f(MAC_MODE, tp->mac_mode); |
| 9571 | udelay(40); |
| 9572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9573 | tg3_setup_phy(tp, 0); |
| 9574 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9575 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9576 | tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 9577 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 9578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9579 | |
| 9580 | tp->timer_counter = tp->timer_multiplier; |
| 9581 | } |
| 9582 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 9583 | /* Heartbeat is only sent once every 2 seconds. |
| 9584 | * |
| 9585 | * The heartbeat is to tell the ASF firmware that the host |
| 9586 | * driver is still alive. In the event that the OS crashes, |
| 9587 | * ASF needs to reset the hardware to free up the FIFO space |
| 9588 | * that may be filled with rx packets destined for the host. |
| 9589 | * If the FIFO is full, ASF will no longer function properly. |
| 9590 | * |
| 9591 | * Unintended resets have been reported on real time kernels |
| 9592 | * where the timer doesn't run on time. Netpoll will also have |
| 9593 | * same problem. |
| 9594 | * |
| 9595 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 9596 | * to check the ring condition when the heartbeat is expiring |
| 9597 | * before doing the reset. This will prevent most unintended |
| 9598 | * resets. |
| 9599 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9600 | if (!--tp->asf_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9601 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 9602 | tg3_wait_for_event_ack(tp); |
| 9603 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 9604 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 9605 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 9606 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 9607 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 9608 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 9609 | |
| 9610 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9611 | } |
| 9612 | tp->asf_counter = tp->asf_multiplier; |
| 9613 | } |
| 9614 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9615 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9616 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 9617 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9618 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9619 | add_timer(&tp->timer); |
| 9620 | } |
| 9621 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 9622 | static void __devinit tg3_timer_init(struct tg3 *tp) |
| 9623 | { |
| 9624 | if (tg3_flag(tp, TAGGED_STATUS) && |
| 9625 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 9626 | !tg3_flag(tp, 57765_CLASS)) |
| 9627 | tp->timer_offset = HZ; |
| 9628 | else |
| 9629 | tp->timer_offset = HZ / 10; |
| 9630 | |
| 9631 | BUG_ON(tp->timer_offset > HZ); |
| 9632 | |
| 9633 | tp->timer_multiplier = (HZ / tp->timer_offset); |
| 9634 | tp->asf_multiplier = (HZ / tp->timer_offset) * |
| 9635 | TG3_FW_UPDATE_FREQ_SEC; |
| 9636 | |
| 9637 | init_timer(&tp->timer); |
| 9638 | tp->timer.data = (unsigned long) tp; |
| 9639 | tp->timer.function = tg3_timer; |
| 9640 | } |
| 9641 | |
| 9642 | static void tg3_timer_start(struct tg3 *tp) |
| 9643 | { |
| 9644 | tp->asf_counter = tp->asf_multiplier; |
| 9645 | tp->timer_counter = tp->timer_multiplier; |
| 9646 | |
| 9647 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9648 | add_timer(&tp->timer); |
| 9649 | } |
| 9650 | |
| 9651 | static void tg3_timer_stop(struct tg3 *tp) |
| 9652 | { |
| 9653 | del_timer_sync(&tp->timer); |
| 9654 | } |
| 9655 | |
| 9656 | /* Restart hardware after configuration changes, self-test, etc. |
| 9657 | * Invoked with tp->lock held. |
| 9658 | */ |
| 9659 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
| 9660 | __releases(tp->lock) |
| 9661 | __acquires(tp->lock) |
| 9662 | { |
| 9663 | int err; |
| 9664 | |
| 9665 | err = tg3_init_hw(tp, reset_phy); |
| 9666 | if (err) { |
| 9667 | netdev_err(tp->dev, |
| 9668 | "Failed to re-initialize device, aborting\n"); |
| 9669 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 9670 | tg3_full_unlock(tp); |
| 9671 | tg3_timer_stop(tp); |
| 9672 | tp->irq_sync = 0; |
| 9673 | tg3_napi_enable(tp); |
| 9674 | dev_close(tp->dev); |
| 9675 | tg3_full_lock(tp, 0); |
| 9676 | } |
| 9677 | return err; |
| 9678 | } |
| 9679 | |
| 9680 | static void tg3_reset_task(struct work_struct *work) |
| 9681 | { |
| 9682 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
| 9683 | int err; |
| 9684 | |
| 9685 | tg3_full_lock(tp, 0); |
| 9686 | |
| 9687 | if (!netif_running(tp->dev)) { |
| 9688 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 9689 | tg3_full_unlock(tp); |
| 9690 | return; |
| 9691 | } |
| 9692 | |
| 9693 | tg3_full_unlock(tp); |
| 9694 | |
| 9695 | tg3_phy_stop(tp); |
| 9696 | |
| 9697 | tg3_netif_stop(tp); |
| 9698 | |
| 9699 | tg3_full_lock(tp, 1); |
| 9700 | |
| 9701 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
| 9702 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 9703 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 9704 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 9705 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 9706 | } |
| 9707 | |
| 9708 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 9709 | err = tg3_init_hw(tp, 1); |
| 9710 | if (err) |
| 9711 | goto out; |
| 9712 | |
| 9713 | tg3_netif_start(tp); |
| 9714 | |
| 9715 | out: |
| 9716 | tg3_full_unlock(tp); |
| 9717 | |
| 9718 | if (!err) |
| 9719 | tg3_phy_start(tp); |
| 9720 | |
| 9721 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 9722 | } |
| 9723 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9724 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9725 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 9726 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9727 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9728 | char *name; |
| 9729 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 9730 | |
| 9731 | if (tp->irq_cnt == 1) |
| 9732 | name = tp->dev->name; |
| 9733 | else { |
| 9734 | name = &tnapi->irq_lbl[0]; |
| 9735 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 9736 | name[IFNAMSIZ-1] = 0; |
| 9737 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9738 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9739 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9740 | fn = tg3_msi; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9741 | if (tg3_flag(tp, 1SHOT_MSI)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9742 | fn = tg3_msi_1shot; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 9743 | flags = 0; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9744 | } else { |
| 9745 | fn = tg3_interrupt; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9746 | if (tg3_flag(tp, TAGGED_STATUS)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9747 | fn = tg3_interrupt_tagged; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 9748 | flags = IRQF_SHARED; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9749 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9750 | |
| 9751 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9752 | } |
| 9753 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9754 | static int tg3_test_interrupt(struct tg3 *tp) |
| 9755 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 9756 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9757 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9758 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9759 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9760 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 9761 | if (!netif_running(dev)) |
| 9762 | return -ENODEV; |
| 9763 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9764 | tg3_disable_ints(tp); |
| 9765 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9766 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9767 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9768 | /* |
| 9769 | * Turn off MSI one shot mode. Otherwise this test has no |
| 9770 | * observable way to know whether the interrupt was delivered. |
| 9771 | */ |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 9772 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9773 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 9774 | tw32(MSGINT_MODE, val); |
| 9775 | } |
| 9776 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9777 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Davidlohr Bueso | f274fd9 | 2012-02-22 03:06:54 +0000 | [diff] [blame] | 9778 | IRQF_SHARED, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9779 | if (err) |
| 9780 | return err; |
| 9781 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9782 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9783 | tg3_enable_ints(tp); |
| 9784 | |
| 9785 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 9786 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9787 | |
| 9788 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9789 | u32 int_mbox, misc_host_ctrl; |
| 9790 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9791 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9792 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 9793 | |
| 9794 | if ((int_mbox != 0) || |
| 9795 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 9796 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9797 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9798 | } |
| 9799 | |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 9800 | if (tg3_flag(tp, 57765_PLUS) && |
| 9801 | tnapi->hw_status->status_tag != tnapi->last_tag) |
| 9802 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 9803 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9804 | msleep(10); |
| 9805 | } |
| 9806 | |
| 9807 | tg3_disable_ints(tp); |
| 9808 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9809 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9810 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9811 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9812 | |
| 9813 | if (err) |
| 9814 | return err; |
| 9815 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9816 | if (intr_ok) { |
| 9817 | /* Reenable MSI one shot mode. */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9818 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9819 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 9820 | tw32(MSGINT_MODE, val); |
| 9821 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9822 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9823 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9824 | |
| 9825 | return -EIO; |
| 9826 | } |
| 9827 | |
| 9828 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 9829 | * successfully restored |
| 9830 | */ |
| 9831 | static int tg3_test_msi(struct tg3 *tp) |
| 9832 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9833 | int err; |
| 9834 | u16 pci_cmd; |
| 9835 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9836 | if (!tg3_flag(tp, USING_MSI)) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9837 | return 0; |
| 9838 | |
| 9839 | /* Turn off SERR reporting in case MSI terminates with Master |
| 9840 | * Abort. |
| 9841 | */ |
| 9842 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 9843 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 9844 | pci_cmd & ~PCI_COMMAND_SERR); |
| 9845 | |
| 9846 | err = tg3_test_interrupt(tp); |
| 9847 | |
| 9848 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 9849 | |
| 9850 | if (!err) |
| 9851 | return 0; |
| 9852 | |
| 9853 | /* other failures */ |
| 9854 | if (err != -EIO) |
| 9855 | return err; |
| 9856 | |
| 9857 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9858 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 9859 | "to INTx mode. Please report this failure to the PCI " |
| 9860 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9861 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9862 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 9863 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9864 | pci_disable_msi(tp->pdev); |
| 9865 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9866 | tg3_flag_clear(tp, USING_MSI); |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 9867 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9868 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9869 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9870 | if (err) |
| 9871 | return err; |
| 9872 | |
| 9873 | /* Need to reset the chip because the MSI cycle may have terminated |
| 9874 | * with Master Abort. |
| 9875 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9876 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9877 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9878 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9879 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9880 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9881 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9882 | |
| 9883 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9884 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9885 | |
| 9886 | return err; |
| 9887 | } |
| 9888 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9889 | static int tg3_request_firmware(struct tg3 *tp) |
| 9890 | { |
| 9891 | const __be32 *fw_data; |
| 9892 | |
| 9893 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9894 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 9895 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9896 | return -ENOENT; |
| 9897 | } |
| 9898 | |
| 9899 | fw_data = (void *)tp->fw->data; |
| 9900 | |
| 9901 | /* Firmware blob starts with version numbers, followed by |
| 9902 | * start address and _full_ length including BSS sections |
| 9903 | * (which must be longer than the actual data, of course |
| 9904 | */ |
| 9905 | |
| 9906 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 9907 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9908 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 9909 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9910 | release_firmware(tp->fw); |
| 9911 | tp->fw = NULL; |
| 9912 | return -EINVAL; |
| 9913 | } |
| 9914 | |
| 9915 | /* We no longer need firmware; we have it. */ |
| 9916 | tp->fw_needed = NULL; |
| 9917 | return 0; |
| 9918 | } |
| 9919 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9920 | static bool tg3_enable_msix(struct tg3 *tp) |
| 9921 | { |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9922 | int i, rc; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9923 | struct msix_entry msix_ent[tp->irq_max]; |
| 9924 | |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9925 | tp->irq_cnt = num_online_cpus(); |
| 9926 | if (tp->irq_cnt > 1) { |
| 9927 | /* We want as many rx rings enabled as there are cpus. |
| 9928 | * In multiqueue MSI-X mode, the first MSI-X vector |
| 9929 | * only deals with link interrupts, etc, so we add |
| 9930 | * one to the number of vectors we are requesting. |
| 9931 | */ |
| 9932 | tp->irq_cnt = min_t(unsigned, tp->irq_cnt + 1, tp->irq_max); |
| 9933 | } |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9934 | |
| 9935 | for (i = 0; i < tp->irq_max; i++) { |
| 9936 | msix_ent[i].entry = i; |
| 9937 | msix_ent[i].vector = 0; |
| 9938 | } |
| 9939 | |
| 9940 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9941 | if (rc < 0) { |
| 9942 | return false; |
| 9943 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9944 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 9945 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9946 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 9947 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9948 | tp->irq_cnt = rc; |
| 9949 | } |
| 9950 | |
| 9951 | for (i = 0; i < tp->irq_max; i++) |
| 9952 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 9953 | |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9954 | netif_set_real_num_tx_queues(tp->dev, 1); |
| 9955 | rc = tp->irq_cnt > 1 ? tp->irq_cnt - 1 : 1; |
| 9956 | if (netif_set_real_num_rx_queues(tp->dev, rc)) { |
| 9957 | pci_disable_msix(tp->pdev); |
| 9958 | return false; |
| 9959 | } |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9960 | |
| 9961 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9962 | tg3_flag_set(tp, ENABLE_RSS); |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 9963 | |
| 9964 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 9965 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9966 | tg3_flag_set(tp, ENABLE_TSS); |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9967 | netif_set_real_num_tx_queues(tp->dev, tp->irq_cnt - 1); |
| 9968 | } |
| 9969 | } |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9970 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9971 | return true; |
| 9972 | } |
| 9973 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9974 | static void tg3_ints_init(struct tg3 *tp) |
| 9975 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9976 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
| 9977 | !tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9978 | /* All MSI supporting chips should support tagged |
| 9979 | * status. Assert that this is the case. |
| 9980 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9981 | netdev_warn(tp->dev, |
| 9982 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9983 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9984 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9985 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9986 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 9987 | tg3_flag_set(tp, USING_MSIX); |
| 9988 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) |
| 9989 | tg3_flag_set(tp, USING_MSI); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9990 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9991 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9992 | u32 msi_mode = tr32(MSGINT_MODE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9993 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9994 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9995 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 9996 | msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9997 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 9998 | } |
| 9999 | defcfg: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10000 | if (!tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10001 | tp->irq_cnt = 1; |
| 10002 | tp->napi[0].irq_vec = tp->pdev->irq; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 10003 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 10004 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10005 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10006 | } |
| 10007 | |
| 10008 | static void tg3_ints_fini(struct tg3 *tp) |
| 10009 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10010 | if (tg3_flag(tp, USING_MSIX)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10011 | pci_disable_msix(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10012 | else if (tg3_flag(tp, USING_MSI)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10013 | pci_disable_msi(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10014 | tg3_flag_clear(tp, USING_MSI); |
| 10015 | tg3_flag_clear(tp, USING_MSIX); |
| 10016 | tg3_flag_clear(tp, ENABLE_RSS); |
| 10017 | tg3_flag_clear(tp, ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10018 | } |
| 10019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10020 | static int tg3_open(struct net_device *dev) |
| 10021 | { |
| 10022 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10023 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10024 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10025 | if (tp->fw_needed) { |
| 10026 | err = tg3_request_firmware(tp); |
| 10027 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 10028 | if (err) |
| 10029 | return err; |
| 10030 | } else if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10031 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10032 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 10033 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10034 | netdev_notice(tp->dev, "TSO capability restored\n"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10035 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10036 | } |
| 10037 | } |
| 10038 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 10039 | netif_carrier_off(tp->dev); |
| 10040 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 10041 | err = tg3_power_up(tp); |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 10042 | if (err) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10043 | return err; |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 10044 | |
| 10045 | tg3_full_lock(tp, 0); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10047 | tg3_disable_ints(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10048 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10049 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10050 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10051 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10052 | /* |
| 10053 | * Setup interrupts first so we know how |
| 10054 | * many NAPI resources to allocate |
| 10055 | */ |
| 10056 | tg3_ints_init(tp); |
| 10057 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 10058 | tg3_rss_check_indir_tbl(tp); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 10059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10060 | /* The placement of this call is tied |
| 10061 | * to the setup and use of Host TX descriptors. |
| 10062 | */ |
| 10063 | err = tg3_alloc_consistent(tp); |
| 10064 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10065 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10066 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10067 | tg3_napi_init(tp); |
| 10068 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10069 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 10070 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10071 | for (i = 0; i < tp->irq_cnt; i++) { |
| 10072 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10073 | err = tg3_request_irq(tp, i); |
| 10074 | if (err) { |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10075 | for (i--; i >= 0; i--) { |
| 10076 | tnapi = &tp->napi[i]; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10077 | free_irq(tnapi->irq_vec, tnapi); |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10078 | } |
| 10079 | goto err_out2; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10080 | } |
| 10081 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10082 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10083 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10084 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 10085 | err = tg3_init_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10086 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10087 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10088 | tg3_free_rings(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10089 | } |
| 10090 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10091 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10092 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10093 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10094 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10095 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10096 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10097 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10098 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10099 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10100 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10101 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10102 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10103 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10104 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10105 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10106 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10107 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10108 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10109 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10110 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10111 | tw32(PCIE_TRANSACTION_CFG, |
| 10112 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10113 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10114 | } |
| 10115 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10116 | tg3_phy_start(tp); |
| 10117 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10118 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10119 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10120 | tg3_timer_start(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10121 | tg3_flag_set(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10122 | tg3_enable_ints(tp); |
| 10123 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10124 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10125 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 10126 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10127 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 10128 | /* |
| 10129 | * Reset loopback feature if it was turned on while the device was down |
| 10130 | * make sure that it's installed properly now. |
| 10131 | */ |
| 10132 | if (dev->features & NETIF_F_LOOPBACK) |
| 10133 | tg3_set_loopback(dev, dev->features); |
| 10134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10135 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10136 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10137 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10138 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10139 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10140 | free_irq(tnapi->irq_vec, tnapi); |
| 10141 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10142 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10143 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10144 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10145 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10146 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10147 | |
| 10148 | err_out1: |
| 10149 | tg3_ints_fini(tp); |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 10150 | tg3_frob_aux_power(tp, false); |
| 10151 | pci_set_power_state(tp->pdev, PCI_D3hot); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10152 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10153 | } |
| 10154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10155 | static int tg3_close(struct net_device *dev) |
| 10156 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10157 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10158 | struct tg3 *tp = netdev_priv(dev); |
| 10159 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10160 | tg3_napi_disable(tp); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 10161 | tg3_reset_task_cancel(tp); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 10162 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 10163 | netif_tx_stop_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10164 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10165 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10166 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 10167 | tg3_phy_stop(tp); |
| 10168 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10169 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10170 | |
| 10171 | tg3_disable_ints(tp); |
| 10172 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10173 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10174 | tg3_free_rings(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10175 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10176 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10177 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10178 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10179 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10180 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10181 | free_irq(tnapi->irq_vec, tnapi); |
| 10182 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10183 | |
| 10184 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10185 | |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 10186 | /* Clear stats across close / open calls */ |
| 10187 | memset(&tp->net_stats_prev, 0, sizeof(tp->net_stats_prev)); |
| 10188 | memset(&tp->estats_prev, 0, sizeof(tp->estats_prev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10189 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10190 | tg3_napi_fini(tp); |
| 10191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10192 | tg3_free_consistent(tp); |
| 10193 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 10194 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10195 | |
| 10196 | netif_carrier_off(tp->dev); |
| 10197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10198 | return 0; |
| 10199 | } |
| 10200 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10201 | static inline u64 get_stat64(tg3_stat64_t *val) |
Stefan Buehler | 816f8b8 | 2008-08-15 14:10:54 -0700 | [diff] [blame] | 10202 | { |
| 10203 | return ((u64)val->high << 32) | ((u64)val->low); |
| 10204 | } |
| 10205 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10206 | static u64 tg3_calc_crc_errors(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10207 | { |
| 10208 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10209 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10210 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10211 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 10212 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10213 | u32 val; |
| 10214 | |
Michael Chan | 569a5df | 2007-02-13 12:18:15 -0800 | [diff] [blame] | 10215 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 10216 | tg3_writephy(tp, MII_TG3_TEST1, |
| 10217 | val | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 10218 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10219 | } else |
| 10220 | val = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10221 | |
| 10222 | tp->phy_crc_errors += val; |
| 10223 | |
| 10224 | return tp->phy_crc_errors; |
| 10225 | } |
| 10226 | |
| 10227 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 10228 | } |
| 10229 | |
| 10230 | #define ESTAT_ADD(member) \ |
| 10231 | estats->member = old_estats->member + \ |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10232 | get_stat64(&hw_stats->member) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10233 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10234 | static void tg3_get_estats(struct tg3 *tp, struct tg3_ethtool_stats *estats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10235 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10236 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 10237 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10239 | ESTAT_ADD(rx_octets); |
| 10240 | ESTAT_ADD(rx_fragments); |
| 10241 | ESTAT_ADD(rx_ucast_packets); |
| 10242 | ESTAT_ADD(rx_mcast_packets); |
| 10243 | ESTAT_ADD(rx_bcast_packets); |
| 10244 | ESTAT_ADD(rx_fcs_errors); |
| 10245 | ESTAT_ADD(rx_align_errors); |
| 10246 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 10247 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 10248 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 10249 | ESTAT_ADD(rx_xoff_entered); |
| 10250 | ESTAT_ADD(rx_frame_too_long_errors); |
| 10251 | ESTAT_ADD(rx_jabbers); |
| 10252 | ESTAT_ADD(rx_undersize_packets); |
| 10253 | ESTAT_ADD(rx_in_length_errors); |
| 10254 | ESTAT_ADD(rx_out_length_errors); |
| 10255 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 10256 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 10257 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 10258 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 10259 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 10260 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 10261 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 10262 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 10263 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 10264 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 10265 | |
| 10266 | ESTAT_ADD(tx_octets); |
| 10267 | ESTAT_ADD(tx_collisions); |
| 10268 | ESTAT_ADD(tx_xon_sent); |
| 10269 | ESTAT_ADD(tx_xoff_sent); |
| 10270 | ESTAT_ADD(tx_flow_control); |
| 10271 | ESTAT_ADD(tx_mac_errors); |
| 10272 | ESTAT_ADD(tx_single_collisions); |
| 10273 | ESTAT_ADD(tx_mult_collisions); |
| 10274 | ESTAT_ADD(tx_deferred); |
| 10275 | ESTAT_ADD(tx_excessive_collisions); |
| 10276 | ESTAT_ADD(tx_late_collisions); |
| 10277 | ESTAT_ADD(tx_collide_2times); |
| 10278 | ESTAT_ADD(tx_collide_3times); |
| 10279 | ESTAT_ADD(tx_collide_4times); |
| 10280 | ESTAT_ADD(tx_collide_5times); |
| 10281 | ESTAT_ADD(tx_collide_6times); |
| 10282 | ESTAT_ADD(tx_collide_7times); |
| 10283 | ESTAT_ADD(tx_collide_8times); |
| 10284 | ESTAT_ADD(tx_collide_9times); |
| 10285 | ESTAT_ADD(tx_collide_10times); |
| 10286 | ESTAT_ADD(tx_collide_11times); |
| 10287 | ESTAT_ADD(tx_collide_12times); |
| 10288 | ESTAT_ADD(tx_collide_13times); |
| 10289 | ESTAT_ADD(tx_collide_14times); |
| 10290 | ESTAT_ADD(tx_collide_15times); |
| 10291 | ESTAT_ADD(tx_ucast_packets); |
| 10292 | ESTAT_ADD(tx_mcast_packets); |
| 10293 | ESTAT_ADD(tx_bcast_packets); |
| 10294 | ESTAT_ADD(tx_carrier_sense_errors); |
| 10295 | ESTAT_ADD(tx_discards); |
| 10296 | ESTAT_ADD(tx_errors); |
| 10297 | |
| 10298 | ESTAT_ADD(dma_writeq_full); |
| 10299 | ESTAT_ADD(dma_write_prioq_full); |
| 10300 | ESTAT_ADD(rxbds_empty); |
| 10301 | ESTAT_ADD(rx_discards); |
| 10302 | ESTAT_ADD(rx_errors); |
| 10303 | ESTAT_ADD(rx_threshold_hit); |
| 10304 | |
| 10305 | ESTAT_ADD(dma_readq_full); |
| 10306 | ESTAT_ADD(dma_read_prioq_full); |
| 10307 | ESTAT_ADD(tx_comp_queue_full); |
| 10308 | |
| 10309 | ESTAT_ADD(ring_set_send_prod_index); |
| 10310 | ESTAT_ADD(ring_status_update); |
| 10311 | ESTAT_ADD(nic_irqs); |
| 10312 | ESTAT_ADD(nic_avoided_irqs); |
| 10313 | ESTAT_ADD(nic_tx_threshold_hit); |
| 10314 | |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 10315 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10316 | } |
| 10317 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10318 | static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10319 | { |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10320 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10321 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10323 | stats->rx_packets = old_stats->rx_packets + |
| 10324 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 10325 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 10326 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10328 | stats->tx_packets = old_stats->tx_packets + |
| 10329 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 10330 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 10331 | get_stat64(&hw_stats->tx_bcast_packets); |
| 10332 | |
| 10333 | stats->rx_bytes = old_stats->rx_bytes + |
| 10334 | get_stat64(&hw_stats->rx_octets); |
| 10335 | stats->tx_bytes = old_stats->tx_bytes + |
| 10336 | get_stat64(&hw_stats->tx_octets); |
| 10337 | |
| 10338 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 10339 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10340 | stats->tx_errors = old_stats->tx_errors + |
| 10341 | get_stat64(&hw_stats->tx_errors) + |
| 10342 | get_stat64(&hw_stats->tx_mac_errors) + |
| 10343 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 10344 | get_stat64(&hw_stats->tx_discards); |
| 10345 | |
| 10346 | stats->multicast = old_stats->multicast + |
| 10347 | get_stat64(&hw_stats->rx_mcast_packets); |
| 10348 | stats->collisions = old_stats->collisions + |
| 10349 | get_stat64(&hw_stats->tx_collisions); |
| 10350 | |
| 10351 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 10352 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 10353 | get_stat64(&hw_stats->rx_undersize_packets); |
| 10354 | |
| 10355 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 10356 | get_stat64(&hw_stats->rxbds_empty); |
| 10357 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 10358 | get_stat64(&hw_stats->rx_align_errors); |
| 10359 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 10360 | get_stat64(&hw_stats->tx_discards); |
| 10361 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 10362 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 10363 | |
| 10364 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10365 | tg3_calc_crc_errors(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10366 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 10367 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 10368 | get_stat64(&hw_stats->rx_discards); |
| 10369 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 10370 | stats->rx_dropped = tp->rx_dropped; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 10371 | stats->tx_dropped = tp->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10372 | } |
| 10373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10374 | static int tg3_get_regs_len(struct net_device *dev) |
| 10375 | { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10376 | return TG3_REG_BLK_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10377 | } |
| 10378 | |
| 10379 | static void tg3_get_regs(struct net_device *dev, |
| 10380 | struct ethtool_regs *regs, void *_p) |
| 10381 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10382 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10383 | |
| 10384 | regs->version = 0; |
| 10385 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10386 | memset(_p, 0, TG3_REG_BLK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10387 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10388 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10389 | return; |
| 10390 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10391 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10392 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10393 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10394 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10395 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10396 | } |
| 10397 | |
| 10398 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 10399 | { |
| 10400 | struct tg3 *tp = netdev_priv(dev); |
| 10401 | |
| 10402 | return tp->nvram_size; |
| 10403 | } |
| 10404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10405 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 10406 | { |
| 10407 | struct tg3 *tp = netdev_priv(dev); |
| 10408 | int ret; |
| 10409 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10410 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10411 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10412 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10413 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10414 | return -EINVAL; |
| 10415 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10416 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10417 | return -EAGAIN; |
| 10418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10419 | offset = eeprom->offset; |
| 10420 | len = eeprom->len; |
| 10421 | eeprom->len = 0; |
| 10422 | |
| 10423 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 10424 | |
| 10425 | if (offset & 3) { |
| 10426 | /* adjustments to start on required 4 byte boundary */ |
| 10427 | b_offset = offset & 3; |
| 10428 | b_count = 4 - b_offset; |
| 10429 | if (b_count > len) { |
| 10430 | /* i.e. offset=1 len=2 */ |
| 10431 | b_count = len; |
| 10432 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10433 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10434 | if (ret) |
| 10435 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 10436 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10437 | len -= b_count; |
| 10438 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10439 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10440 | } |
| 10441 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10442 | /* read bytes up to the last 4 byte boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10443 | pd = &data[eeprom->len]; |
| 10444 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10445 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10446 | if (ret) { |
| 10447 | eeprom->len += i; |
| 10448 | return ret; |
| 10449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10450 | memcpy(pd + i, &val, 4); |
| 10451 | } |
| 10452 | eeprom->len += i; |
| 10453 | |
| 10454 | if (len & 3) { |
| 10455 | /* read last bytes not ending on 4 byte boundary */ |
| 10456 | pd = &data[eeprom->len]; |
| 10457 | b_count = len & 3; |
| 10458 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10459 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10460 | if (ret) |
| 10461 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10462 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10463 | eeprom->len += b_count; |
| 10464 | } |
| 10465 | return 0; |
| 10466 | } |
| 10467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10468 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 10469 | { |
| 10470 | struct tg3 *tp = netdev_priv(dev); |
| 10471 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10472 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10473 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10474 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10475 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10476 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10477 | return -EAGAIN; |
| 10478 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10479 | if (tg3_flag(tp, NO_NVRAM) || |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10480 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10481 | return -EINVAL; |
| 10482 | |
| 10483 | offset = eeprom->offset; |
| 10484 | len = eeprom->len; |
| 10485 | |
| 10486 | if ((b_offset = (offset & 3))) { |
| 10487 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10488 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10489 | if (ret) |
| 10490 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10491 | len += b_offset; |
| 10492 | offset &= ~3; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 10493 | if (len < 4) |
| 10494 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10495 | } |
| 10496 | |
| 10497 | odd_len = 0; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 10498 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10499 | /* adjustments to end on required 4 byte boundary */ |
| 10500 | odd_len = 1; |
| 10501 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10502 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10503 | if (ret) |
| 10504 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10505 | } |
| 10506 | |
| 10507 | buf = data; |
| 10508 | if (b_offset || odd_len) { |
| 10509 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 10510 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10511 | return -ENOMEM; |
| 10512 | if (b_offset) |
| 10513 | memcpy(buf, &start, 4); |
| 10514 | if (odd_len) |
| 10515 | memcpy(buf+len-4, &end, 4); |
| 10516 | memcpy(buf + b_offset, data, eeprom->len); |
| 10517 | } |
| 10518 | |
| 10519 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 10520 | |
| 10521 | if (buf != data) |
| 10522 | kfree(buf); |
| 10523 | |
| 10524 | return ret; |
| 10525 | } |
| 10526 | |
| 10527 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 10528 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10529 | struct tg3 *tp = netdev_priv(dev); |
| 10530 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10531 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10532 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10533 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10534 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10535 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 10536 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10537 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10539 | cmd->supported = (SUPPORTED_Autoneg); |
| 10540 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10541 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10542 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 10543 | SUPPORTED_1000baseT_Full); |
| 10544 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10545 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10546 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 10547 | SUPPORTED_100baseT_Full | |
| 10548 | SUPPORTED_10baseT_Half | |
| 10549 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 10550 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 10551 | cmd->port = PORT_TP; |
| 10552 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10553 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 10554 | cmd->port = PORT_FIBRE; |
| 10555 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10557 | cmd->advertising = tp->link_config.advertising; |
Matt Carlson | 5bb0977 | 2011-06-13 13:39:00 +0000 | [diff] [blame] | 10558 | if (tg3_flag(tp, PAUSE_AUTONEG)) { |
| 10559 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) { |
| 10560 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 10561 | cmd->advertising |= ADVERTISED_Pause; |
| 10562 | } else { |
| 10563 | cmd->advertising |= ADVERTISED_Pause | |
| 10564 | ADVERTISED_Asym_Pause; |
| 10565 | } |
| 10566 | } else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 10567 | cmd->advertising |= ADVERTISED_Asym_Pause; |
| 10568 | } |
| 10569 | } |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 10570 | if (netif_running(dev) && netif_carrier_ok(dev)) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 10571 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10572 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 10573 | cmd->lp_advertising = tp->link_config.rmt_adv; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 10574 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 10575 | if (tp->phy_flags & TG3_PHYFLG_MDIX_STATE) |
| 10576 | cmd->eth_tp_mdix = ETH_TP_MDI_X; |
| 10577 | else |
| 10578 | cmd->eth_tp_mdix = ETH_TP_MDI; |
| 10579 | } |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 10580 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 10581 | ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN); |
| 10582 | cmd->duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 10583 | cmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10584 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 10585 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10586 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10587 | cmd->autoneg = tp->link_config.autoneg; |
| 10588 | cmd->maxtxpkt = 0; |
| 10589 | cmd->maxrxpkt = 0; |
| 10590 | return 0; |
| 10591 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10593 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 10594 | { |
| 10595 | struct tg3 *tp = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10596 | u32 speed = ethtool_cmd_speed(cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10597 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10598 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10599 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10600 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10601 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10602 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 10603 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10604 | } |
| 10605 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10606 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 10607 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 10608 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10609 | |
| 10610 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 10611 | cmd->duplex != DUPLEX_FULL && |
| 10612 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 10613 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10614 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10615 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 10616 | u32 mask = ADVERTISED_Autoneg | |
| 10617 | ADVERTISED_Pause | |
| 10618 | ADVERTISED_Asym_Pause; |
| 10619 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10620 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10621 | mask |= ADVERTISED_1000baseT_Half | |
| 10622 | ADVERTISED_1000baseT_Full; |
| 10623 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10624 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10625 | mask |= ADVERTISED_100baseT_Half | |
| 10626 | ADVERTISED_100baseT_Full | |
| 10627 | ADVERTISED_10baseT_Half | |
| 10628 | ADVERTISED_10baseT_Full | |
| 10629 | ADVERTISED_TP; |
| 10630 | else |
| 10631 | mask |= ADVERTISED_FIBRE; |
| 10632 | |
| 10633 | if (cmd->advertising & ~mask) |
| 10634 | return -EINVAL; |
| 10635 | |
| 10636 | mask &= (ADVERTISED_1000baseT_Half | |
| 10637 | ADVERTISED_1000baseT_Full | |
| 10638 | ADVERTISED_100baseT_Half | |
| 10639 | ADVERTISED_100baseT_Full | |
| 10640 | ADVERTISED_10baseT_Half | |
| 10641 | ADVERTISED_10baseT_Full); |
| 10642 | |
| 10643 | cmd->advertising &= mask; |
| 10644 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10645 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10646 | if (speed != SPEED_1000) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10647 | return -EINVAL; |
| 10648 | |
| 10649 | if (cmd->duplex != DUPLEX_FULL) |
| 10650 | return -EINVAL; |
| 10651 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10652 | if (speed != SPEED_100 && |
| 10653 | speed != SPEED_10) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10654 | return -EINVAL; |
| 10655 | } |
| 10656 | } |
| 10657 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10658 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10659 | |
| 10660 | tp->link_config.autoneg = cmd->autoneg; |
| 10661 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 10662 | tp->link_config.advertising = (cmd->advertising | |
| 10663 | ADVERTISED_Autoneg); |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 10664 | tp->link_config.speed = SPEED_UNKNOWN; |
| 10665 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10666 | } else { |
| 10667 | tp->link_config.advertising = 0; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10668 | tp->link_config.speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10669 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10670 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10672 | if (netif_running(dev)) |
| 10673 | tg3_setup_phy(tp, 1); |
| 10674 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10675 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10677 | return 0; |
| 10678 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10680 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 10681 | { |
| 10682 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10683 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 10684 | strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); |
| 10685 | strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); |
| 10686 | strlcpy(info->fw_version, tp->fw_ver, sizeof(info->fw_version)); |
| 10687 | strlcpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10688 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10690 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 10691 | { |
| 10692 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10693 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10694 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 10695 | wol->supported = WAKE_MAGIC; |
| 10696 | else |
| 10697 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10698 | wol->wolopts = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10699 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10700 | wol->wolopts = WAKE_MAGIC; |
| 10701 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 10702 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10704 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 10705 | { |
| 10706 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 10707 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10709 | if (wol->wolopts & ~WAKE_MAGIC) |
| 10710 | return -EINVAL; |
| 10711 | if ((wol->wolopts & WAKE_MAGIC) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10712 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10713 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10714 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10715 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 10716 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10717 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10718 | if (device_may_wakeup(dp)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10719 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10720 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10721 | tg3_flag_clear(tp, WOL_ENABLE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10722 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10724 | return 0; |
| 10725 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10727 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 10728 | { |
| 10729 | struct tg3 *tp = netdev_priv(dev); |
| 10730 | return tp->msg_enable; |
| 10731 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10733 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 10734 | { |
| 10735 | struct tg3 *tp = netdev_priv(dev); |
| 10736 | tp->msg_enable = value; |
| 10737 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10739 | static int tg3_nway_reset(struct net_device *dev) |
| 10740 | { |
| 10741 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10742 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10744 | if (!netif_running(dev)) |
| 10745 | return -EAGAIN; |
| 10746 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10747 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10748 | return -EINVAL; |
| 10749 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10750 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10751 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10752 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10753 | r = phy_start_aneg(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10754 | } else { |
| 10755 | u32 bmcr; |
| 10756 | |
| 10757 | spin_lock_bh(&tp->lock); |
| 10758 | r = -EINVAL; |
| 10759 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 10760 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 10761 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10762 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10763 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 10764 | BMCR_ANENABLE); |
| 10765 | r = 0; |
| 10766 | } |
| 10767 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10768 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10770 | return r; |
| 10771 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10773 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10774 | { |
| 10775 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10776 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10777 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10778 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10779 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10780 | else |
| 10781 | ering->rx_jumbo_max_pending = 0; |
| 10782 | |
| 10783 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10784 | |
| 10785 | ering->rx_pending = tp->rx_pending; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10786 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10787 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 10788 | else |
| 10789 | ering->rx_jumbo_pending = 0; |
| 10790 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10791 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10792 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10794 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10795 | { |
| 10796 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10797 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10798 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10799 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 10800 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10801 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 10802 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10803 | (tg3_flag(tp, TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10804 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10805 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10806 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10807 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10808 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10809 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10810 | irq_sync = 1; |
| 10811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10812 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10813 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10815 | tp->rx_pending = ering->rx_pending; |
| 10816 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10817 | if (tg3_flag(tp, MAX_RXPEND_64) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10818 | tp->rx_pending > 63) |
| 10819 | tp->rx_pending = 63; |
| 10820 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10821 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 10822 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10823 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10824 | |
| 10825 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10826 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10827 | err = tg3_restart_hw(tp, 1); |
| 10828 | if (!err) |
| 10829 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10830 | } |
| 10831 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10832 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10833 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10834 | if (irq_sync && !err) |
| 10835 | tg3_phy_start(tp); |
| 10836 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10837 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10838 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10840 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10841 | { |
| 10842 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10843 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10844 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10845 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 10846 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10847 | epause->rx_pause = 1; |
| 10848 | else |
| 10849 | epause->rx_pause = 0; |
| 10850 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 10851 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10852 | epause->tx_pause = 1; |
| 10853 | else |
| 10854 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10855 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10857 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10858 | { |
| 10859 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10860 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10861 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10862 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10863 | u32 newadv; |
| 10864 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10865 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10866 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10867 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10868 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 10869 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 10870 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10871 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10872 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10873 | tp->link_config.flowctrl = 0; |
| 10874 | if (epause->rx_pause) { |
| 10875 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10876 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10877 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10878 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10879 | newadv = ADVERTISED_Pause; |
| 10880 | } else |
| 10881 | newadv = ADVERTISED_Pause | |
| 10882 | ADVERTISED_Asym_Pause; |
| 10883 | } else if (epause->tx_pause) { |
| 10884 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 10885 | newadv = ADVERTISED_Asym_Pause; |
| 10886 | } else |
| 10887 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10888 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10889 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10890 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10891 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10892 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10893 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10894 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10895 | u32 oldadv = phydev->advertising & |
| 10896 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 10897 | if (oldadv != newadv) { |
| 10898 | phydev->advertising &= |
| 10899 | ~(ADVERTISED_Pause | |
| 10900 | ADVERTISED_Asym_Pause); |
| 10901 | phydev->advertising |= newadv; |
| 10902 | if (phydev->autoneg) { |
| 10903 | /* |
| 10904 | * Always renegotiate the link to |
| 10905 | * inform our link partner of our |
| 10906 | * flow control settings, even if the |
| 10907 | * flow control is forced. Let |
| 10908 | * tg3_adjust_link() do the final |
| 10909 | * flow control setup. |
| 10910 | */ |
| 10911 | return phy_start_aneg(phydev); |
| 10912 | } |
| 10913 | } |
| 10914 | |
| 10915 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10916 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10917 | } else { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 10918 | tp->link_config.advertising &= |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10919 | ~(ADVERTISED_Pause | |
| 10920 | ADVERTISED_Asym_Pause); |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 10921 | tp->link_config.advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10922 | } |
| 10923 | } else { |
| 10924 | int irq_sync = 0; |
| 10925 | |
| 10926 | if (netif_running(dev)) { |
| 10927 | tg3_netif_stop(tp); |
| 10928 | irq_sync = 1; |
| 10929 | } |
| 10930 | |
| 10931 | tg3_full_lock(tp, irq_sync); |
| 10932 | |
| 10933 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10934 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10935 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10936 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10937 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10938 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10939 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10940 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10941 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10942 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10943 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10944 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10945 | |
| 10946 | if (netif_running(dev)) { |
| 10947 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10948 | err = tg3_restart_hw(tp, 1); |
| 10949 | if (!err) |
| 10950 | tg3_netif_start(tp); |
| 10951 | } |
| 10952 | |
| 10953 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10955 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10956 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10957 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10958 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10959 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10960 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 10961 | switch (sset) { |
| 10962 | case ETH_SS_TEST: |
| 10963 | return TG3_NUM_TEST; |
| 10964 | case ETH_SS_STATS: |
| 10965 | return TG3_NUM_STATS; |
| 10966 | default: |
| 10967 | return -EOPNOTSUPP; |
| 10968 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10969 | } |
| 10970 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 10971 | static int tg3_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, |
| 10972 | u32 *rules __always_unused) |
| 10973 | { |
| 10974 | struct tg3 *tp = netdev_priv(dev); |
| 10975 | |
| 10976 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 10977 | return -EOPNOTSUPP; |
| 10978 | |
| 10979 | switch (info->cmd) { |
| 10980 | case ETHTOOL_GRXRINGS: |
| 10981 | if (netif_running(tp->dev)) |
| 10982 | info->data = tp->irq_cnt; |
| 10983 | else { |
| 10984 | info->data = num_online_cpus(); |
| 10985 | if (info->data > TG3_IRQ_MAX_VECS_RSS) |
| 10986 | info->data = TG3_IRQ_MAX_VECS_RSS; |
| 10987 | } |
| 10988 | |
| 10989 | /* The first interrupt vector only |
| 10990 | * handles link interrupts. |
| 10991 | */ |
| 10992 | info->data -= 1; |
| 10993 | return 0; |
| 10994 | |
| 10995 | default: |
| 10996 | return -EOPNOTSUPP; |
| 10997 | } |
| 10998 | } |
| 10999 | |
| 11000 | static u32 tg3_get_rxfh_indir_size(struct net_device *dev) |
| 11001 | { |
| 11002 | u32 size = 0; |
| 11003 | struct tg3 *tp = netdev_priv(dev); |
| 11004 | |
| 11005 | if (tg3_flag(tp, SUPPORT_MSIX)) |
| 11006 | size = TG3_RSS_INDIR_TBL_SIZE; |
| 11007 | |
| 11008 | return size; |
| 11009 | } |
| 11010 | |
| 11011 | static int tg3_get_rxfh_indir(struct net_device *dev, u32 *indir) |
| 11012 | { |
| 11013 | struct tg3 *tp = netdev_priv(dev); |
| 11014 | int i; |
| 11015 | |
| 11016 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11017 | indir[i] = tp->rss_ind_tbl[i]; |
| 11018 | |
| 11019 | return 0; |
| 11020 | } |
| 11021 | |
| 11022 | static int tg3_set_rxfh_indir(struct net_device *dev, const u32 *indir) |
| 11023 | { |
| 11024 | struct tg3 *tp = netdev_priv(dev); |
| 11025 | size_t i; |
| 11026 | |
| 11027 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11028 | tp->rss_ind_tbl[i] = indir[i]; |
| 11029 | |
| 11030 | if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS)) |
| 11031 | return 0; |
| 11032 | |
| 11033 | /* It is legal to write the indirection |
| 11034 | * table while the device is running. |
| 11035 | */ |
| 11036 | tg3_full_lock(tp, 0); |
| 11037 | tg3_rss_write_indir_tbl(tp); |
| 11038 | tg3_full_unlock(tp); |
| 11039 | |
| 11040 | return 0; |
| 11041 | } |
| 11042 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11043 | static void tg3_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11044 | { |
| 11045 | switch (stringset) { |
| 11046 | case ETH_SS_STATS: |
| 11047 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 11048 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11049 | case ETH_SS_TEST: |
| 11050 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 11051 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11052 | default: |
| 11053 | WARN_ON(1); /* we need a WARN() */ |
| 11054 | break; |
| 11055 | } |
| 11056 | } |
| 11057 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11058 | static int tg3_set_phys_id(struct net_device *dev, |
| 11059 | enum ethtool_phys_id_state state) |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11060 | { |
| 11061 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11062 | |
| 11063 | if (!netif_running(tp->dev)) |
| 11064 | return -EAGAIN; |
| 11065 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11066 | switch (state) { |
| 11067 | case ETHTOOL_ID_ACTIVE: |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 11068 | return 1; /* cycle on/off once per second */ |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11069 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11070 | case ETHTOOL_ID_ON: |
| 11071 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11072 | LED_CTRL_1000MBPS_ON | |
| 11073 | LED_CTRL_100MBPS_ON | |
| 11074 | LED_CTRL_10MBPS_ON | |
| 11075 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 11076 | LED_CTRL_TRAFFIC_BLINK | |
| 11077 | LED_CTRL_TRAFFIC_LED); |
| 11078 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11079 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11080 | case ETHTOOL_ID_OFF: |
| 11081 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11082 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 11083 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11084 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11085 | case ETHTOOL_ID_INACTIVE: |
| 11086 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 11087 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11088 | } |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11089 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11090 | return 0; |
| 11091 | } |
| 11092 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11093 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11094 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 11095 | { |
| 11096 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 0e6c9da | 2011-12-08 14:40:13 +0000 | [diff] [blame] | 11097 | |
Matt Carlson | b546e46 | 2012-02-13 15:20:09 +0000 | [diff] [blame] | 11098 | if (tp->hw_stats) |
| 11099 | tg3_get_estats(tp, (struct tg3_ethtool_stats *)tmp_stats); |
| 11100 | else |
| 11101 | memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11102 | } |
| 11103 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11104 | static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11105 | { |
| 11106 | int i; |
| 11107 | __be32 *buf; |
| 11108 | u32 offset = 0, len = 0; |
| 11109 | u32 magic, val; |
| 11110 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11111 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11112 | return NULL; |
| 11113 | |
| 11114 | if (magic == TG3_EEPROM_MAGIC) { |
| 11115 | for (offset = TG3_NVM_DIR_START; |
| 11116 | offset < TG3_NVM_DIR_END; |
| 11117 | offset += TG3_NVM_DIRENT_SIZE) { |
| 11118 | if (tg3_nvram_read(tp, offset, &val)) |
| 11119 | return NULL; |
| 11120 | |
| 11121 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == |
| 11122 | TG3_NVM_DIRTYPE_EXTVPD) |
| 11123 | break; |
| 11124 | } |
| 11125 | |
| 11126 | if (offset != TG3_NVM_DIR_END) { |
| 11127 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; |
| 11128 | if (tg3_nvram_read(tp, offset + 4, &offset)) |
| 11129 | return NULL; |
| 11130 | |
| 11131 | offset = tg3_nvram_logical_addr(tp, offset); |
| 11132 | } |
| 11133 | } |
| 11134 | |
| 11135 | if (!offset || !len) { |
| 11136 | offset = TG3_NVM_VPD_OFF; |
| 11137 | len = TG3_NVM_VPD_LEN; |
| 11138 | } |
| 11139 | |
| 11140 | buf = kmalloc(len, GFP_KERNEL); |
| 11141 | if (buf == NULL) |
| 11142 | return NULL; |
| 11143 | |
| 11144 | if (magic == TG3_EEPROM_MAGIC) { |
| 11145 | for (i = 0; i < len; i += 4) { |
| 11146 | /* The data is in little-endian format in NVRAM. |
| 11147 | * Use the big-endian read routines to preserve |
| 11148 | * the byte order as it exists in NVRAM. |
| 11149 | */ |
| 11150 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) |
| 11151 | goto error; |
| 11152 | } |
| 11153 | } else { |
| 11154 | u8 *ptr; |
| 11155 | ssize_t cnt; |
| 11156 | unsigned int pos = 0; |
| 11157 | |
| 11158 | ptr = (u8 *)&buf[0]; |
| 11159 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { |
| 11160 | cnt = pci_read_vpd(tp->pdev, pos, |
| 11161 | len - pos, ptr); |
| 11162 | if (cnt == -ETIMEDOUT || cnt == -EINTR) |
| 11163 | cnt = 0; |
| 11164 | else if (cnt < 0) |
| 11165 | goto error; |
| 11166 | } |
| 11167 | if (pos != len) |
| 11168 | goto error; |
| 11169 | } |
| 11170 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11171 | *vpdlen = len; |
| 11172 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11173 | return buf; |
| 11174 | |
| 11175 | error: |
| 11176 | kfree(buf); |
| 11177 | return NULL; |
| 11178 | } |
| 11179 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11180 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11181 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 11182 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 11183 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11184 | #define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
| 11185 | #define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 |
Matt Carlson | bda18fa | 2011-07-20 10:20:57 +0000 | [diff] [blame] | 11186 | #define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11187 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 11188 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11189 | |
| 11190 | static int tg3_test_nvram(struct tg3 *tp) |
| 11191 | { |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11192 | u32 csum, magic, len; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11193 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 11194 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11195 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11196 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11197 | return 0; |
| 11198 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11199 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11200 | return -EIO; |
| 11201 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11202 | if (magic == TG3_EEPROM_MAGIC) |
| 11203 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11204 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11205 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 11206 | TG3_EEPROM_SB_FORMAT_1) { |
| 11207 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 11208 | case TG3_EEPROM_SB_REVISION_0: |
| 11209 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 11210 | break; |
| 11211 | case TG3_EEPROM_SB_REVISION_2: |
| 11212 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 11213 | break; |
| 11214 | case TG3_EEPROM_SB_REVISION_3: |
| 11215 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 11216 | break; |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11217 | case TG3_EEPROM_SB_REVISION_4: |
| 11218 | size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; |
| 11219 | break; |
| 11220 | case TG3_EEPROM_SB_REVISION_5: |
| 11221 | size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; |
| 11222 | break; |
| 11223 | case TG3_EEPROM_SB_REVISION_6: |
| 11224 | size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; |
| 11225 | break; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11226 | default: |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11227 | return -EIO; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11228 | } |
| 11229 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11230 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11231 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 11232 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 11233 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11234 | return -EIO; |
| 11235 | |
| 11236 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11237 | if (buf == NULL) |
| 11238 | return -ENOMEM; |
| 11239 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11240 | err = -EIO; |
| 11241 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11242 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 11243 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11244 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11245 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11246 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11247 | goto out; |
| 11248 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11249 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11250 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11251 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11252 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11253 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 11254 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11255 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11256 | TG3_EEPROM_SB_REVISION_2) { |
| 11257 | /* For rev 2, the csum doesn't include the MBA. */ |
| 11258 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 11259 | csum8 += buf8[i]; |
| 11260 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 11261 | csum8 += buf8[i]; |
| 11262 | } else { |
| 11263 | for (i = 0; i < size; i++) |
| 11264 | csum8 += buf8[i]; |
| 11265 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11266 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 11267 | if (csum8 == 0) { |
| 11268 | err = 0; |
| 11269 | goto out; |
| 11270 | } |
| 11271 | |
| 11272 | err = -EIO; |
| 11273 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11274 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11275 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11276 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11277 | TG3_EEPROM_MAGIC_HW) { |
| 11278 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11279 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11280 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11281 | |
| 11282 | /* Separate the parity bits and the data bytes. */ |
| 11283 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 11284 | if ((i == 0) || (i == 8)) { |
| 11285 | int l; |
| 11286 | u8 msk; |
| 11287 | |
| 11288 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 11289 | parity[k++] = buf8[i] & msk; |
| 11290 | i++; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 11291 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11292 | int l; |
| 11293 | u8 msk; |
| 11294 | |
| 11295 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 11296 | parity[k++] = buf8[i] & msk; |
| 11297 | i++; |
| 11298 | |
| 11299 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 11300 | parity[k++] = buf8[i] & msk; |
| 11301 | i++; |
| 11302 | } |
| 11303 | data[j++] = buf8[i]; |
| 11304 | } |
| 11305 | |
| 11306 | err = -EIO; |
| 11307 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 11308 | u8 hw8 = hweight8(data[i]); |
| 11309 | |
| 11310 | if ((hw8 & 0x1) && parity[i]) |
| 11311 | goto out; |
| 11312 | else if (!(hw8 & 0x1) && !parity[i]) |
| 11313 | goto out; |
| 11314 | } |
| 11315 | err = 0; |
| 11316 | goto out; |
| 11317 | } |
| 11318 | |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11319 | err = -EIO; |
| 11320 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11321 | /* Bootstrap checksum at offset 0x10 */ |
| 11322 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11323 | if (csum != le32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11324 | goto out; |
| 11325 | |
| 11326 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 11327 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11328 | if (csum != le32_to_cpu(buf[0xfc/4])) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11329 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11330 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11331 | kfree(buf); |
| 11332 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11333 | buf = tg3_vpd_readblock(tp, &len); |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11334 | if (!buf) |
| 11335 | return -ENOMEM; |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11336 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11337 | i = pci_vpd_find_tag((u8 *)buf, 0, len, PCI_VPD_LRDT_RO_DATA); |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11338 | if (i > 0) { |
| 11339 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); |
| 11340 | if (j < 0) |
| 11341 | goto out; |
| 11342 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11343 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11344 | goto out; |
| 11345 | |
| 11346 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 11347 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, |
| 11348 | PCI_VPD_RO_KEYWORD_CHKSUM); |
| 11349 | if (j > 0) { |
| 11350 | u8 csum8 = 0; |
| 11351 | |
| 11352 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 11353 | |
| 11354 | for (i = 0; i <= j; i++) |
| 11355 | csum8 += ((u8 *)buf)[i]; |
| 11356 | |
| 11357 | if (csum8) |
| 11358 | goto out; |
| 11359 | } |
| 11360 | } |
| 11361 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11362 | err = 0; |
| 11363 | |
| 11364 | out: |
| 11365 | kfree(buf); |
| 11366 | return err; |
| 11367 | } |
| 11368 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11369 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 11370 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 11371 | |
| 11372 | static int tg3_test_link(struct tg3 *tp) |
| 11373 | { |
| 11374 | int i, max; |
| 11375 | |
| 11376 | if (!netif_running(tp->dev)) |
| 11377 | return -ENODEV; |
| 11378 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11379 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11380 | max = TG3_SERDES_TIMEOUT_SEC; |
| 11381 | else |
| 11382 | max = TG3_COPPER_TIMEOUT_SEC; |
| 11383 | |
| 11384 | for (i = 0; i < max; i++) { |
| 11385 | if (netif_carrier_ok(tp->dev)) |
| 11386 | return 0; |
| 11387 | |
| 11388 | if (msleep_interruptible(1000)) |
| 11389 | break; |
| 11390 | } |
| 11391 | |
| 11392 | return -EIO; |
| 11393 | } |
| 11394 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11395 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 11396 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11397 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11398 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11399 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 11400 | static struct { |
| 11401 | u16 offset; |
| 11402 | u16 flags; |
| 11403 | #define TG3_FL_5705 0x1 |
| 11404 | #define TG3_FL_NOT_5705 0x2 |
| 11405 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11406 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11407 | u32 read_mask; |
| 11408 | u32 write_mask; |
| 11409 | } reg_tbl[] = { |
| 11410 | /* MAC Control Registers */ |
| 11411 | { MAC_MODE, TG3_FL_NOT_5705, |
| 11412 | 0x00000000, 0x00ef6f8c }, |
| 11413 | { MAC_MODE, TG3_FL_5705, |
| 11414 | 0x00000000, 0x01ef6b8c }, |
| 11415 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 11416 | 0x03800107, 0x00000000 }, |
| 11417 | { MAC_STATUS, TG3_FL_5705, |
| 11418 | 0x03800100, 0x00000000 }, |
| 11419 | { MAC_ADDR_0_HIGH, 0x0000, |
| 11420 | 0x00000000, 0x0000ffff }, |
| 11421 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11422 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11423 | { MAC_RX_MTU_SIZE, 0x0000, |
| 11424 | 0x00000000, 0x0000ffff }, |
| 11425 | { MAC_TX_MODE, 0x0000, |
| 11426 | 0x00000000, 0x00000070 }, |
| 11427 | { MAC_TX_LENGTHS, 0x0000, |
| 11428 | 0x00000000, 0x00003fff }, |
| 11429 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 11430 | 0x00000000, 0x000007fc }, |
| 11431 | { MAC_RX_MODE, TG3_FL_5705, |
| 11432 | 0x00000000, 0x000007dc }, |
| 11433 | { MAC_HASH_REG_0, 0x0000, |
| 11434 | 0x00000000, 0xffffffff }, |
| 11435 | { MAC_HASH_REG_1, 0x0000, |
| 11436 | 0x00000000, 0xffffffff }, |
| 11437 | { MAC_HASH_REG_2, 0x0000, |
| 11438 | 0x00000000, 0xffffffff }, |
| 11439 | { MAC_HASH_REG_3, 0x0000, |
| 11440 | 0x00000000, 0xffffffff }, |
| 11441 | |
| 11442 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 11443 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 11444 | 0x00000000, 0xffffffff }, |
| 11445 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 11446 | 0x00000000, 0xffffffff }, |
| 11447 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 11448 | 0x00000000, 0x00000003 }, |
| 11449 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 11450 | 0x00000000, 0xffffffff }, |
| 11451 | { RCVDBDI_STD_BD+0, 0x0000, |
| 11452 | 0x00000000, 0xffffffff }, |
| 11453 | { RCVDBDI_STD_BD+4, 0x0000, |
| 11454 | 0x00000000, 0xffffffff }, |
| 11455 | { RCVDBDI_STD_BD+8, 0x0000, |
| 11456 | 0x00000000, 0xffff0002 }, |
| 11457 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 11458 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11459 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11460 | /* Receive BD Initiator Control Registers. */ |
| 11461 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 11462 | 0x00000000, 0xffffffff }, |
| 11463 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 11464 | 0x00000000, 0x000003ff }, |
| 11465 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 11466 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11467 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11468 | /* Host Coalescing Control Registers. */ |
| 11469 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 11470 | 0x00000000, 0x00000004 }, |
| 11471 | { HOSTCC_MODE, TG3_FL_5705, |
| 11472 | 0x00000000, 0x000000f6 }, |
| 11473 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 11474 | 0x00000000, 0xffffffff }, |
| 11475 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 11476 | 0x00000000, 0x000003ff }, |
| 11477 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 11478 | 0x00000000, 0xffffffff }, |
| 11479 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 11480 | 0x00000000, 0x000003ff }, |
| 11481 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 11482 | 0x00000000, 0xffffffff }, |
| 11483 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11484 | 0x00000000, 0x000000ff }, |
| 11485 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 11486 | 0x00000000, 0xffffffff }, |
| 11487 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11488 | 0x00000000, 0x000000ff }, |
| 11489 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 11490 | 0x00000000, 0xffffffff }, |
| 11491 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 11492 | 0x00000000, 0xffffffff }, |
| 11493 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 11494 | 0x00000000, 0xffffffff }, |
| 11495 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11496 | 0x00000000, 0x000000ff }, |
| 11497 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 11498 | 0x00000000, 0xffffffff }, |
| 11499 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11500 | 0x00000000, 0x000000ff }, |
| 11501 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 11502 | 0x00000000, 0xffffffff }, |
| 11503 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 11504 | 0x00000000, 0xffffffff }, |
| 11505 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 11506 | 0x00000000, 0xffffffff }, |
| 11507 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 11508 | 0x00000000, 0xffffffff }, |
| 11509 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 11510 | 0x00000000, 0xffffffff }, |
| 11511 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 11512 | 0xffffffff, 0x00000000 }, |
| 11513 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 11514 | 0xffffffff, 0x00000000 }, |
| 11515 | |
| 11516 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11517 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11518 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11519 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11520 | 0x00000000, 0x007fffff }, |
| 11521 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 11522 | 0x00000000, 0x0000003f }, |
| 11523 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 11524 | 0x00000000, 0x000001ff }, |
| 11525 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 11526 | 0x00000000, 0x000001ff }, |
| 11527 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 11528 | 0xffffffff, 0x00000000 }, |
| 11529 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 11530 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11531 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11532 | /* Mailbox Registers */ |
| 11533 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 11534 | 0x00000000, 0x000001ff }, |
| 11535 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 11536 | 0x00000000, 0x000001ff }, |
| 11537 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 11538 | 0x00000000, 0x000007ff }, |
| 11539 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 11540 | 0x00000000, 0x000001ff }, |
| 11541 | |
| 11542 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 11543 | }; |
| 11544 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11545 | is_5705 = is_5750 = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11546 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11547 | is_5705 = 1; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11548 | if (tg3_flag(tp, 5750_PLUS)) |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11549 | is_5750 = 1; |
| 11550 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11551 | |
| 11552 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 11553 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 11554 | continue; |
| 11555 | |
| 11556 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 11557 | continue; |
| 11558 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11559 | if (tg3_flag(tp, IS_5788) && |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11560 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 11561 | continue; |
| 11562 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11563 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 11564 | continue; |
| 11565 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11566 | offset = (u32) reg_tbl[i].offset; |
| 11567 | read_mask = reg_tbl[i].read_mask; |
| 11568 | write_mask = reg_tbl[i].write_mask; |
| 11569 | |
| 11570 | /* Save the original register content */ |
| 11571 | save_val = tr32(offset); |
| 11572 | |
| 11573 | /* Determine the read-only value. */ |
| 11574 | read_val = save_val & read_mask; |
| 11575 | |
| 11576 | /* Write zero to the register, then make sure the read-only bits |
| 11577 | * are not changed and the read/write bits are all zeros. |
| 11578 | */ |
| 11579 | tw32(offset, 0); |
| 11580 | |
| 11581 | val = tr32(offset); |
| 11582 | |
| 11583 | /* Test the read-only and read/write bits. */ |
| 11584 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 11585 | goto out; |
| 11586 | |
| 11587 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 11588 | * make sure the read-only bits are not changed and the |
| 11589 | * read/write bits are all ones. |
| 11590 | */ |
| 11591 | tw32(offset, read_mask | write_mask); |
| 11592 | |
| 11593 | val = tr32(offset); |
| 11594 | |
| 11595 | /* Test the read-only bits. */ |
| 11596 | if ((val & read_mask) != read_val) |
| 11597 | goto out; |
| 11598 | |
| 11599 | /* Test the read/write bits. */ |
| 11600 | if ((val & write_mask) != write_mask) |
| 11601 | goto out; |
| 11602 | |
| 11603 | tw32(offset, save_val); |
| 11604 | } |
| 11605 | |
| 11606 | return 0; |
| 11607 | |
| 11608 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 11609 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 11610 | netdev_err(tp->dev, |
| 11611 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11612 | tw32(offset, save_val); |
| 11613 | return -EIO; |
| 11614 | } |
| 11615 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11616 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 11617 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 11618 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11619 | int i; |
| 11620 | u32 j; |
| 11621 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 11622 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11623 | for (j = 0; j < len; j += 4) { |
| 11624 | u32 val; |
| 11625 | |
| 11626 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 11627 | tg3_read_mem(tp, offset + j, &val); |
| 11628 | if (val != test_pattern[i]) |
| 11629 | return -EIO; |
| 11630 | } |
| 11631 | } |
| 11632 | return 0; |
| 11633 | } |
| 11634 | |
| 11635 | static int tg3_test_memory(struct tg3 *tp) |
| 11636 | { |
| 11637 | static struct mem_entry { |
| 11638 | u32 offset; |
| 11639 | u32 len; |
| 11640 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 11641 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11642 | { 0x00002000, 0x1c000}, |
| 11643 | { 0xffffffff, 0x00000} |
| 11644 | }, mem_tbl_5705[] = { |
| 11645 | { 0x00000100, 0x0000c}, |
| 11646 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11647 | { 0x00004000, 0x00800}, |
| 11648 | { 0x00006000, 0x01000}, |
| 11649 | { 0x00008000, 0x02000}, |
| 11650 | { 0x00010000, 0x0e000}, |
| 11651 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 11652 | }, mem_tbl_5755[] = { |
| 11653 | { 0x00000200, 0x00008}, |
| 11654 | { 0x00004000, 0x00800}, |
| 11655 | { 0x00006000, 0x00800}, |
| 11656 | { 0x00008000, 0x02000}, |
| 11657 | { 0x00010000, 0x0c000}, |
| 11658 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11659 | }, mem_tbl_5906[] = { |
| 11660 | { 0x00000200, 0x00008}, |
| 11661 | { 0x00004000, 0x00400}, |
| 11662 | { 0x00006000, 0x00400}, |
| 11663 | { 0x00008000, 0x01000}, |
| 11664 | { 0x00010000, 0x01000}, |
| 11665 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 11666 | }, mem_tbl_5717[] = { |
| 11667 | { 0x00000200, 0x00008}, |
| 11668 | { 0x00010000, 0x0a000}, |
| 11669 | { 0x00020000, 0x13c00}, |
| 11670 | { 0xffffffff, 0x00000} |
| 11671 | }, mem_tbl_57765[] = { |
| 11672 | { 0x00000200, 0x00008}, |
| 11673 | { 0x00004000, 0x00800}, |
| 11674 | { 0x00006000, 0x09800}, |
| 11675 | { 0x00010000, 0x0a000}, |
| 11676 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11677 | }; |
| 11678 | struct mem_entry *mem_tbl; |
| 11679 | int err = 0; |
| 11680 | int i; |
| 11681 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11682 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 11683 | mem_tbl = mem_tbl_5717; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 11684 | else if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 11685 | mem_tbl = mem_tbl_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11686 | else if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11687 | mem_tbl = mem_tbl_5755; |
| 11688 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 11689 | mem_tbl = mem_tbl_5906; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11690 | else if (tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11691 | mem_tbl = mem_tbl_5705; |
| 11692 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11693 | mem_tbl = mem_tbl_570x; |
| 11694 | |
| 11695 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 11696 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 11697 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11698 | break; |
| 11699 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11700 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11701 | return err; |
| 11702 | } |
| 11703 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11704 | #define TG3_TSO_MSS 500 |
| 11705 | |
| 11706 | #define TG3_TSO_IP_HDR_LEN 20 |
| 11707 | #define TG3_TSO_TCP_HDR_LEN 20 |
| 11708 | #define TG3_TSO_TCP_OPT_LEN 12 |
| 11709 | |
| 11710 | static const u8 tg3_tso_header[] = { |
| 11711 | 0x08, 0x00, |
| 11712 | 0x45, 0x00, 0x00, 0x00, |
| 11713 | 0x00, 0x00, 0x40, 0x00, |
| 11714 | 0x40, 0x06, 0x00, 0x00, |
| 11715 | 0x0a, 0x00, 0x00, 0x01, |
| 11716 | 0x0a, 0x00, 0x00, 0x02, |
| 11717 | 0x0d, 0x00, 0xe0, 0x00, |
| 11718 | 0x00, 0x00, 0x01, 0x00, |
| 11719 | 0x00, 0x00, 0x02, 0x00, |
| 11720 | 0x80, 0x10, 0x10, 0x00, |
| 11721 | 0x14, 0x09, 0x00, 0x00, |
| 11722 | 0x01, 0x01, 0x08, 0x0a, |
| 11723 | 0x11, 0x11, 0x11, 0x11, |
| 11724 | 0x11, 0x11, 0x11, 0x11, |
| 11725 | }; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11726 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11727 | static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, bool tso_loopback) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11728 | { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 11729 | u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11730 | u32 base_flags = 0, mss = 0, desc_idx, coal_now, data_off, val; |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 11731 | u32 budget; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11732 | struct sk_buff *skb; |
| 11733 | u8 *tx_data, *rx_data; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11734 | dma_addr_t map; |
| 11735 | int num_pkts, tx_len, rx_len, i, err; |
| 11736 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11737 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 11738 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11739 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 11740 | tnapi = &tp->napi[0]; |
| 11741 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 11742 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11743 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 11744 | rnapi = &tp->napi[1]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11745 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 11746 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 11747 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11748 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11749 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11750 | err = -EIO; |
| 11751 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11752 | tx_len = pktsz; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 11753 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 11754 | if (!skb) |
| 11755 | return -ENOMEM; |
| 11756 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11757 | tx_data = skb_put(skb, tx_len); |
| 11758 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 11759 | memset(tx_data + 6, 0x0, 8); |
| 11760 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11761 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11762 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11763 | if (tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11764 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
| 11765 | |
| 11766 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + |
| 11767 | TG3_TSO_TCP_OPT_LEN; |
| 11768 | |
| 11769 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, |
| 11770 | sizeof(tg3_tso_header)); |
| 11771 | mss = TG3_TSO_MSS; |
| 11772 | |
| 11773 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); |
| 11774 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); |
| 11775 | |
| 11776 | /* Set the total length field in the IP header */ |
| 11777 | iph->tot_len = htons((u16)(mss + hdr_len)); |
| 11778 | |
| 11779 | base_flags = (TXD_FLAG_CPU_PRE_DMA | |
| 11780 | TXD_FLAG_CPU_POST_DMA); |
| 11781 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11782 | if (tg3_flag(tp, HW_TSO_1) || |
| 11783 | tg3_flag(tp, HW_TSO_2) || |
| 11784 | tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11785 | struct tcphdr *th; |
| 11786 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; |
| 11787 | th = (struct tcphdr *)&tx_data[val]; |
| 11788 | th->check = 0; |
| 11789 | } else |
| 11790 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 11791 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11792 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11793 | mss |= (hdr_len & 0xc) << 12; |
| 11794 | if (hdr_len & 0x10) |
| 11795 | base_flags |= 0x00000010; |
| 11796 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11797 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11798 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11799 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11800 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 11801 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
| 11802 | } else { |
| 11803 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); |
| 11804 | } |
| 11805 | |
| 11806 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); |
| 11807 | } else { |
| 11808 | num_pkts = 1; |
| 11809 | data_off = ETH_HLEN; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 11810 | |
| 11811 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 11812 | tx_len > VLAN_ETH_FRAME_LEN) |
| 11813 | base_flags |= TXD_FLAG_JMB_PKT; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11814 | } |
| 11815 | |
| 11816 | for (i = data_off; i < tx_len; i++) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11817 | tx_data[i] = (u8) (i & 0xff); |
| 11818 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 11819 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 11820 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 11821 | dev_kfree_skb(skb); |
| 11822 | return -EIO; |
| 11823 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11824 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 11825 | val = tnapi->tx_prod; |
| 11826 | tnapi->tx_buffers[val].skb = skb; |
| 11827 | dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); |
| 11828 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11829 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11830 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11831 | |
| 11832 | udelay(10); |
| 11833 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11834 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11835 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 11836 | budget = tg3_tx_avail(tnapi); |
| 11837 | if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 11838 | base_flags | TXD_FLAG_END, mss, 0)) { |
| 11839 | tnapi->tx_buffers[val].skb = NULL; |
| 11840 | dev_kfree_skb(skb); |
| 11841 | return -EIO; |
| 11842 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11843 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11844 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11845 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 11846 | /* Sync BD data before updating mailbox */ |
| 11847 | wmb(); |
| 11848 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11849 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 11850 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11851 | |
| 11852 | udelay(10); |
| 11853 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 11854 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 11855 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11856 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11857 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11858 | |
| 11859 | udelay(10); |
| 11860 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11861 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 11862 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11863 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11864 | (rx_idx == (rx_start_idx + num_pkts))) |
| 11865 | break; |
| 11866 | } |
| 11867 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 11868 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11869 | dev_kfree_skb(skb); |
| 11870 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11871 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11872 | goto out; |
| 11873 | |
| 11874 | if (rx_idx != rx_start_idx + num_pkts) |
| 11875 | goto out; |
| 11876 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11877 | val = data_off; |
| 11878 | while (rx_idx != rx_start_idx) { |
| 11879 | desc = &rnapi->rx_rcb[rx_start_idx++]; |
| 11880 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 11881 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11882 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11883 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 11884 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11885 | goto out; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11886 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11887 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
| 11888 | - ETH_FCS_LEN; |
| 11889 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11890 | if (!tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11891 | if (rx_len != tx_len) |
| 11892 | goto out; |
| 11893 | |
| 11894 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
| 11895 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 11896 | goto out; |
| 11897 | } else { |
| 11898 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) |
| 11899 | goto out; |
| 11900 | } |
| 11901 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 11902 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
Matt Carlson | 54e0a67 | 2011-05-19 12:12:50 +0000 | [diff] [blame] | 11903 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11904 | goto out; |
| 11905 | } |
| 11906 | |
| 11907 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11908 | rx_data = tpr->rx_std_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11909 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
| 11910 | mapping); |
| 11911 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11912 | rx_data = tpr->rx_jmb_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11913 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
| 11914 | mapping); |
| 11915 | } else |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11916 | goto out; |
| 11917 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11918 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
| 11919 | PCI_DMA_FROMDEVICE); |
| 11920 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11921 | rx_data += TG3_RX_OFFSET(tp); |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11922 | for (i = data_off; i < rx_len; i++, val++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11923 | if (*(rx_data + i) != (u8) (val & 0xff)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11924 | goto out; |
| 11925 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11926 | } |
| 11927 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11928 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11929 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11930 | /* tg3_free_rings will unmap and free the rx_data */ |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11931 | out: |
| 11932 | return err; |
| 11933 | } |
| 11934 | |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11935 | #define TG3_STD_LOOPBACK_FAILED 1 |
| 11936 | #define TG3_JMB_LOOPBACK_FAILED 2 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11937 | #define TG3_TSO_LOOPBACK_FAILED 4 |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11938 | #define TG3_LOOPBACK_FAILED \ |
| 11939 | (TG3_STD_LOOPBACK_FAILED | \ |
| 11940 | TG3_JMB_LOOPBACK_FAILED | \ |
| 11941 | TG3_TSO_LOOPBACK_FAILED) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11942 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 11943 | static int tg3_test_loopback(struct tg3 *tp, u64 *data, bool do_extlpbk) |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11944 | { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11945 | int err = -EIO; |
Matt Carlson | 2215e24 | 2011-08-19 13:58:19 +0000 | [diff] [blame] | 11946 | u32 eee_cap; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 11947 | u32 jmb_pkt_sz = 9000; |
| 11948 | |
| 11949 | if (tp->dma_limit) |
| 11950 | jmb_pkt_sz = tp->dma_limit - ETH_HLEN; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11951 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11952 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
| 11953 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 11954 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11955 | if (!netif_running(tp->dev)) { |
| 11956 | data[0] = TG3_LOOPBACK_FAILED; |
| 11957 | data[1] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 11958 | if (do_extlpbk) |
| 11959 | data[2] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11960 | goto done; |
| 11961 | } |
| 11962 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11963 | err = tg3_reset_hw(tp, 1); |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11964 | if (err) { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11965 | data[0] = TG3_LOOPBACK_FAILED; |
| 11966 | data[1] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 11967 | if (do_extlpbk) |
| 11968 | data[2] = TG3_LOOPBACK_FAILED; |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11969 | goto done; |
| 11970 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11971 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11972 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 4a85f09 | 2011-04-20 07:57:37 +0000 | [diff] [blame] | 11973 | int i; |
| 11974 | |
| 11975 | /* Reroute all rx packets to the 1st queue */ |
| 11976 | for (i = MAC_RSS_INDIR_TBL_0; |
| 11977 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) |
| 11978 | tw32(i, 0x0); |
| 11979 | } |
| 11980 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 11981 | /* HW errata - mac loopback fails in some cases on 5780. |
| 11982 | * Normal traffic and PHY loopback are not affected by |
| 11983 | * errata. Also, the MAC loopback test is deprecated for |
| 11984 | * all newer ASIC revisions. |
| 11985 | */ |
| 11986 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 11987 | !tg3_flag(tp, CPMU_PRESENT)) { |
| 11988 | tg3_mac_loopback(tp, true); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11989 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11990 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 11991 | data[0] |= TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 11992 | |
| 11993 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 11994 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11995 | data[0] |= TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 11996 | |
| 11997 | tg3_mac_loopback(tp, false); |
| 11998 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11999 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12000 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12001 | !tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12002 | int i; |
| 12003 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12004 | tg3_phy_lpbk_set(tp, 0, false); |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12005 | |
| 12006 | /* Wait for link */ |
| 12007 | for (i = 0; i < 100; i++) { |
| 12008 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 12009 | break; |
| 12010 | mdelay(1); |
| 12011 | } |
| 12012 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12013 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 12014 | data[1] |= TG3_STD_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12015 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12016 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
| 12017 | data[1] |= TG3_TSO_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12018 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12019 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12020 | data[1] |= TG3_JMB_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12021 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12022 | if (do_extlpbk) { |
| 12023 | tg3_phy_lpbk_set(tp, 0, true); |
| 12024 | |
| 12025 | /* All link indications report up, but the hardware |
| 12026 | * isn't really ready for about 20 msec. Double it |
| 12027 | * to be sure. |
| 12028 | */ |
| 12029 | mdelay(40); |
| 12030 | |
| 12031 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 12032 | data[2] |= TG3_STD_LOOPBACK_FAILED; |
| 12033 | if (tg3_flag(tp, TSO_CAPABLE) && |
| 12034 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
| 12035 | data[2] |= TG3_TSO_LOOPBACK_FAILED; |
| 12036 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12037 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12038 | data[2] |= TG3_JMB_LOOPBACK_FAILED; |
| 12039 | } |
| 12040 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12041 | /* Re-enable gphy autopowerdown. */ |
| 12042 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
| 12043 | tg3_phy_toggle_apd(tp, true); |
| 12044 | } |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12045 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12046 | err = (data[0] | data[1] | data[2]) ? -EIO : 0; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12047 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12048 | done: |
| 12049 | tp->phy_flags |= eee_cap; |
| 12050 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12051 | return err; |
| 12052 | } |
| 12053 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12054 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 12055 | u64 *data) |
| 12056 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12057 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12058 | bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12059 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 12060 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 12061 | tg3_power_up(tp)) { |
| 12062 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12063 | memset(data, 1, sizeof(u64) * TG3_NUM_TEST); |
| 12064 | return; |
| 12065 | } |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12066 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12067 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 12068 | |
| 12069 | if (tg3_test_nvram(tp) != 0) { |
| 12070 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12071 | data[0] = 1; |
| 12072 | } |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12073 | if (!doextlpbk && tg3_test_link(tp)) { |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12074 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12075 | data[1] = 1; |
| 12076 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12077 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12078 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12079 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12080 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12081 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12082 | tg3_netif_stop(tp); |
| 12083 | irq_sync = 1; |
| 12084 | } |
| 12085 | |
| 12086 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12087 | |
| 12088 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12089 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12090 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12091 | if (!tg3_flag(tp, 5705_PLUS)) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12092 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12093 | if (!err) |
| 12094 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12095 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12096 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 12097 | tg3_phy_reset(tp); |
| 12098 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12099 | if (tg3_test_registers(tp) != 0) { |
| 12100 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12101 | data[2] = 1; |
| 12102 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12103 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12104 | if (tg3_test_memory(tp) != 0) { |
| 12105 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12106 | data[3] = 1; |
| 12107 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12108 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12109 | if (doextlpbk) |
| 12110 | etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; |
| 12111 | |
| 12112 | if (tg3_test_loopback(tp, &data[4], doextlpbk)) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12113 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12114 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12115 | tg3_full_unlock(tp); |
| 12116 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12117 | if (tg3_test_interrupt(tp) != 0) { |
| 12118 | etest->flags |= ETH_TEST_FL_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12119 | data[7] = 1; |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12120 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12121 | |
| 12122 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12123 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12124 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12125 | if (netif_running(dev)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12126 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12127 | err2 = tg3_restart_hw(tp, 1); |
| 12128 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12129 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12130 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12131 | |
| 12132 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12133 | |
| 12134 | if (irq_sync && !err2) |
| 12135 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12136 | } |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 12137 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 12138 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12139 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12140 | } |
| 12141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12142 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 12143 | { |
| 12144 | struct mii_ioctl_data *data = if_mii(ifr); |
| 12145 | struct tg3 *tp = netdev_priv(dev); |
| 12146 | int err; |
| 12147 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12148 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12149 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12150 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12151 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12152 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 12153 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12154 | } |
| 12155 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 12156 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12157 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 12158 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12159 | |
| 12160 | /* fallthru */ |
| 12161 | case SIOCGMIIREG: { |
| 12162 | u32 mii_regval; |
| 12163 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12164 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12165 | break; /* We have no PHY */ |
| 12166 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12167 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12168 | return -EAGAIN; |
| 12169 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12170 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12171 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12172 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12173 | |
| 12174 | data->val_out = mii_regval; |
| 12175 | |
| 12176 | return err; |
| 12177 | } |
| 12178 | |
| 12179 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12180 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12181 | break; /* We have no PHY */ |
| 12182 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12183 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12184 | return -EAGAIN; |
| 12185 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12186 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12187 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12188 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12189 | |
| 12190 | return err; |
| 12191 | |
| 12192 | default: |
| 12193 | /* do nothing */ |
| 12194 | break; |
| 12195 | } |
| 12196 | return -EOPNOTSUPP; |
| 12197 | } |
| 12198 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 12199 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12200 | { |
| 12201 | struct tg3 *tp = netdev_priv(dev); |
| 12202 | |
| 12203 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 12204 | return 0; |
| 12205 | } |
| 12206 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12207 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12208 | { |
| 12209 | struct tg3 *tp = netdev_priv(dev); |
| 12210 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 12211 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 12212 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12213 | if (!tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12214 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 12215 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 12216 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 12217 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 12218 | } |
| 12219 | |
| 12220 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 12221 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 12222 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 12223 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 12224 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 12225 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 12226 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 12227 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 12228 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 12229 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 12230 | return -EINVAL; |
| 12231 | |
| 12232 | /* No rx interrupts will be generated if both are zero */ |
| 12233 | if ((ec->rx_coalesce_usecs == 0) && |
| 12234 | (ec->rx_max_coalesced_frames == 0)) |
| 12235 | return -EINVAL; |
| 12236 | |
| 12237 | /* No tx interrupts will be generated if both are zero */ |
| 12238 | if ((ec->tx_coalesce_usecs == 0) && |
| 12239 | (ec->tx_max_coalesced_frames == 0)) |
| 12240 | return -EINVAL; |
| 12241 | |
| 12242 | /* Only copy relevant parameters, ignore all others. */ |
| 12243 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 12244 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 12245 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 12246 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 12247 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 12248 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 12249 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 12250 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 12251 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 12252 | |
| 12253 | if (netif_running(dev)) { |
| 12254 | tg3_full_lock(tp, 0); |
| 12255 | __tg3_set_coalesce(tp, &tp->coal); |
| 12256 | tg3_full_unlock(tp); |
| 12257 | } |
| 12258 | return 0; |
| 12259 | } |
| 12260 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 12261 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12262 | .get_settings = tg3_get_settings, |
| 12263 | .set_settings = tg3_set_settings, |
| 12264 | .get_drvinfo = tg3_get_drvinfo, |
| 12265 | .get_regs_len = tg3_get_regs_len, |
| 12266 | .get_regs = tg3_get_regs, |
| 12267 | .get_wol = tg3_get_wol, |
| 12268 | .set_wol = tg3_set_wol, |
| 12269 | .get_msglevel = tg3_get_msglevel, |
| 12270 | .set_msglevel = tg3_set_msglevel, |
| 12271 | .nway_reset = tg3_nway_reset, |
| 12272 | .get_link = ethtool_op_get_link, |
| 12273 | .get_eeprom_len = tg3_get_eeprom_len, |
| 12274 | .get_eeprom = tg3_get_eeprom, |
| 12275 | .set_eeprom = tg3_set_eeprom, |
| 12276 | .get_ringparam = tg3_get_ringparam, |
| 12277 | .set_ringparam = tg3_set_ringparam, |
| 12278 | .get_pauseparam = tg3_get_pauseparam, |
| 12279 | .set_pauseparam = tg3_set_pauseparam, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12280 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12281 | .get_strings = tg3_get_strings, |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12282 | .set_phys_id = tg3_set_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12283 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 12284 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12285 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 12286 | .get_sset_count = tg3_get_sset_count, |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 12287 | .get_rxnfc = tg3_get_rxnfc, |
| 12288 | .get_rxfh_indir_size = tg3_get_rxfh_indir_size, |
| 12289 | .get_rxfh_indir = tg3_get_rxfh_indir, |
| 12290 | .set_rxfh_indir = tg3_set_rxfh_indir, |
Richard Cochran | 3f84749 | 2012-04-03 22:59:39 +0000 | [diff] [blame] | 12291 | .get_ts_info = ethtool_op_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12292 | }; |
| 12293 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 12294 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 12295 | struct rtnl_link_stats64 *stats) |
| 12296 | { |
| 12297 | struct tg3 *tp = netdev_priv(dev); |
| 12298 | |
| 12299 | if (!tp->hw_stats) |
| 12300 | return &tp->net_stats_prev; |
| 12301 | |
| 12302 | spin_lock_bh(&tp->lock); |
| 12303 | tg3_get_nstats(tp, stats); |
| 12304 | spin_unlock_bh(&tp->lock); |
| 12305 | |
| 12306 | return stats; |
| 12307 | } |
| 12308 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 12309 | static void tg3_set_rx_mode(struct net_device *dev) |
| 12310 | { |
| 12311 | struct tg3 *tp = netdev_priv(dev); |
| 12312 | |
| 12313 | if (!netif_running(dev)) |
| 12314 | return; |
| 12315 | |
| 12316 | tg3_full_lock(tp, 0); |
| 12317 | __tg3_set_rx_mode(dev); |
| 12318 | tg3_full_unlock(tp); |
| 12319 | } |
| 12320 | |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12321 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 12322 | int new_mtu) |
| 12323 | { |
| 12324 | dev->mtu = new_mtu; |
| 12325 | |
| 12326 | if (new_mtu > ETH_DATA_LEN) { |
| 12327 | if (tg3_flag(tp, 5780_CLASS)) { |
| 12328 | netdev_update_features(dev); |
| 12329 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 12330 | } else { |
| 12331 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
| 12332 | } |
| 12333 | } else { |
| 12334 | if (tg3_flag(tp, 5780_CLASS)) { |
| 12335 | tg3_flag_set(tp, TSO_CAPABLE); |
| 12336 | netdev_update_features(dev); |
| 12337 | } |
| 12338 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
| 12339 | } |
| 12340 | } |
| 12341 | |
| 12342 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 12343 | { |
| 12344 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 12345 | int err, reset_phy = 0; |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12346 | |
| 12347 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 12348 | return -EINVAL; |
| 12349 | |
| 12350 | if (!netif_running(dev)) { |
| 12351 | /* We'll just catch it later when the |
| 12352 | * device is up'd. |
| 12353 | */ |
| 12354 | tg3_set_mtu(dev, tp, new_mtu); |
| 12355 | return 0; |
| 12356 | } |
| 12357 | |
| 12358 | tg3_phy_stop(tp); |
| 12359 | |
| 12360 | tg3_netif_stop(tp); |
| 12361 | |
| 12362 | tg3_full_lock(tp, 1); |
| 12363 | |
| 12364 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12365 | |
| 12366 | tg3_set_mtu(dev, tp, new_mtu); |
| 12367 | |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 12368 | /* Reset PHY, otherwise the read DMA engine will be in a mode that |
| 12369 | * breaks all requests to 256 bytes. |
| 12370 | */ |
| 12371 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 12372 | reset_phy = 1; |
| 12373 | |
| 12374 | err = tg3_restart_hw(tp, reset_phy); |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12375 | |
| 12376 | if (!err) |
| 12377 | tg3_netif_start(tp); |
| 12378 | |
| 12379 | tg3_full_unlock(tp); |
| 12380 | |
| 12381 | if (!err) |
| 12382 | tg3_phy_start(tp); |
| 12383 | |
| 12384 | return err; |
| 12385 | } |
| 12386 | |
| 12387 | static const struct net_device_ops tg3_netdev_ops = { |
| 12388 | .ndo_open = tg3_open, |
| 12389 | .ndo_stop = tg3_close, |
| 12390 | .ndo_start_xmit = tg3_start_xmit, |
| 12391 | .ndo_get_stats64 = tg3_get_stats64, |
| 12392 | .ndo_validate_addr = eth_validate_addr, |
| 12393 | .ndo_set_rx_mode = tg3_set_rx_mode, |
| 12394 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 12395 | .ndo_do_ioctl = tg3_ioctl, |
| 12396 | .ndo_tx_timeout = tg3_tx_timeout, |
| 12397 | .ndo_change_mtu = tg3_change_mtu, |
| 12398 | .ndo_fix_features = tg3_fix_features, |
| 12399 | .ndo_set_features = tg3_set_features, |
| 12400 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 12401 | .ndo_poll_controller = tg3_poll_controller, |
| 12402 | #endif |
| 12403 | }; |
| 12404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12405 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) |
| 12406 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12407 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12408 | |
| 12409 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 12410 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12411 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12412 | return; |
| 12413 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12414 | if ((magic != TG3_EEPROM_MAGIC) && |
| 12415 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 12416 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12417 | return; |
| 12418 | |
| 12419 | /* |
| 12420 | * Size the chip by reading offsets at increasing powers of two. |
| 12421 | * When we encounter our validation signature, we know the addressing |
| 12422 | * has wrapped around, and thus have our chip size. |
| 12423 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12424 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12425 | |
| 12426 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12427 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12428 | return; |
| 12429 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12430 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12431 | break; |
| 12432 | |
| 12433 | cursize <<= 1; |
| 12434 | } |
| 12435 | |
| 12436 | tp->nvram_size = cursize; |
| 12437 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12439 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
| 12440 | { |
| 12441 | u32 val; |
| 12442 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12443 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &val) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12444 | return; |
| 12445 | |
| 12446 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12447 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12448 | tg3_get_eeprom_size(tp); |
| 12449 | return; |
| 12450 | } |
| 12451 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12452 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12453 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12454 | /* This is confusing. We want to operate on the |
| 12455 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 12456 | * call will read from NVRAM and byteswap the data |
| 12457 | * according to the byteswapping settings for all |
| 12458 | * other register accesses. This ensures the data we |
| 12459 | * want will always reside in the lower 16-bits. |
| 12460 | * However, the data in NVRAM is in LE format, which |
| 12461 | * means the data from the NVRAM read will always be |
| 12462 | * opposite the endianness of the CPU. The 16-bit |
| 12463 | * byteswap then brings the data to CPU endianness. |
| 12464 | */ |
| 12465 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12466 | return; |
| 12467 | } |
| 12468 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 12469 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12470 | } |
| 12471 | |
| 12472 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) |
| 12473 | { |
| 12474 | u32 nvcfg1; |
| 12475 | |
| 12476 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12477 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12478 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12479 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12480 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12481 | tw32(NVRAM_CFG1, nvcfg1); |
| 12482 | } |
| 12483 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 12484 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12485 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12486 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12487 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 12488 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12489 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12490 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12491 | break; |
| 12492 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 12493 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12494 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 12495 | break; |
| 12496 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 12497 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12498 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12499 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12500 | break; |
| 12501 | case FLASH_VENDOR_ST: |
| 12502 | tp->nvram_jedecnum = JEDEC_ST; |
| 12503 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12504 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12505 | break; |
| 12506 | case FLASH_VENDOR_SAIFUN: |
| 12507 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 12508 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 12509 | break; |
| 12510 | case FLASH_VENDOR_SST_SMALL: |
| 12511 | case FLASH_VENDOR_SST_LARGE: |
| 12512 | tp->nvram_jedecnum = JEDEC_SST; |
| 12513 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 12514 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12515 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12516 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12517 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12518 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12519 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12520 | } |
| 12521 | } |
| 12522 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12523 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 12524 | { |
| 12525 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 12526 | case FLASH_5752PAGE_SIZE_256: |
| 12527 | tp->nvram_pagesize = 256; |
| 12528 | break; |
| 12529 | case FLASH_5752PAGE_SIZE_512: |
| 12530 | tp->nvram_pagesize = 512; |
| 12531 | break; |
| 12532 | case FLASH_5752PAGE_SIZE_1K: |
| 12533 | tp->nvram_pagesize = 1024; |
| 12534 | break; |
| 12535 | case FLASH_5752PAGE_SIZE_2K: |
| 12536 | tp->nvram_pagesize = 2048; |
| 12537 | break; |
| 12538 | case FLASH_5752PAGE_SIZE_4K: |
| 12539 | tp->nvram_pagesize = 4096; |
| 12540 | break; |
| 12541 | case FLASH_5752PAGE_SIZE_264: |
| 12542 | tp->nvram_pagesize = 264; |
| 12543 | break; |
| 12544 | case FLASH_5752PAGE_SIZE_528: |
| 12545 | tp->nvram_pagesize = 528; |
| 12546 | break; |
| 12547 | } |
| 12548 | } |
| 12549 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12550 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
| 12551 | { |
| 12552 | u32 nvcfg1; |
| 12553 | |
| 12554 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12555 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12556 | /* NVRAM protection for TPM */ |
| 12557 | if (nvcfg1 & (1 << 27)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12558 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12559 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12560 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12561 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 12562 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 12563 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12564 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12565 | break; |
| 12566 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12567 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12568 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12569 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12570 | break; |
| 12571 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12572 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12573 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12574 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12575 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12576 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12577 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12578 | } |
| 12579 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12580 | if (tg3_flag(tp, FLASH)) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12581 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12582 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12583 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 12584 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12585 | |
| 12586 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12587 | tw32(NVRAM_CFG1, nvcfg1); |
| 12588 | } |
| 12589 | } |
| 12590 | |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12591 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
| 12592 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12593 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12594 | |
| 12595 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12596 | |
| 12597 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12598 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12599 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12600 | protect = 1; |
| 12601 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12602 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12603 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 12604 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12605 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 12606 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 12607 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 12608 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 12609 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12610 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12611 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12612 | tp->nvram_pagesize = 264; |
| 12613 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 12614 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 12615 | tp->nvram_size = (protect ? 0x3e200 : |
| 12616 | TG3_NVRAM_SIZE_512KB); |
| 12617 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 12618 | tp->nvram_size = (protect ? 0x1f200 : |
| 12619 | TG3_NVRAM_SIZE_256KB); |
| 12620 | else |
| 12621 | tp->nvram_size = (protect ? 0x1f200 : |
| 12622 | TG3_NVRAM_SIZE_128KB); |
| 12623 | break; |
| 12624 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12625 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12626 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12627 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12628 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12629 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12630 | tp->nvram_pagesize = 256; |
| 12631 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 12632 | tp->nvram_size = (protect ? |
| 12633 | TG3_NVRAM_SIZE_64KB : |
| 12634 | TG3_NVRAM_SIZE_128KB); |
| 12635 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 12636 | tp->nvram_size = (protect ? |
| 12637 | TG3_NVRAM_SIZE_64KB : |
| 12638 | TG3_NVRAM_SIZE_256KB); |
| 12639 | else |
| 12640 | tp->nvram_size = (protect ? |
| 12641 | TG3_NVRAM_SIZE_128KB : |
| 12642 | TG3_NVRAM_SIZE_512KB); |
| 12643 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12644 | } |
| 12645 | } |
| 12646 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12647 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
| 12648 | { |
| 12649 | u32 nvcfg1; |
| 12650 | |
| 12651 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12652 | |
| 12653 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12654 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 12655 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 12656 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 12657 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 12658 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12659 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12660 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12661 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12662 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12663 | tw32(NVRAM_CFG1, nvcfg1); |
| 12664 | break; |
| 12665 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12666 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 12667 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 12668 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 12669 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12670 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12671 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12672 | tp->nvram_pagesize = 264; |
| 12673 | break; |
| 12674 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12675 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12676 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12677 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12678 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12679 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12680 | tp->nvram_pagesize = 256; |
| 12681 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12682 | } |
| 12683 | } |
| 12684 | |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12685 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
| 12686 | { |
| 12687 | u32 nvcfg1, protect = 0; |
| 12688 | |
| 12689 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12690 | |
| 12691 | /* NVRAM protection for TPM */ |
| 12692 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12693 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12694 | protect = 1; |
| 12695 | } |
| 12696 | |
| 12697 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 12698 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12699 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 12700 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 12701 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 12702 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 12703 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 12704 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 12705 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 12706 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 12707 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12708 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12709 | tg3_flag_set(tp, FLASH); |
| 12710 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12711 | tp->nvram_pagesize = 256; |
| 12712 | break; |
| 12713 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 12714 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 12715 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 12716 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 12717 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 12718 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 12719 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 12720 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 12721 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12722 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12723 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12724 | tp->nvram_pagesize = 256; |
| 12725 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12726 | } |
| 12727 | |
| 12728 | if (protect) { |
| 12729 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 12730 | } else { |
| 12731 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12732 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 12733 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 12734 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 12735 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 12736 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 12737 | break; |
| 12738 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 12739 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 12740 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 12741 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 12742 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 12743 | break; |
| 12744 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 12745 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 12746 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 12747 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 12748 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12749 | break; |
| 12750 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 12751 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 12752 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 12753 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 12754 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12755 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12756 | } |
| 12757 | } |
| 12758 | } |
| 12759 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12760 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
| 12761 | { |
| 12762 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12763 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12764 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12765 | } |
| 12766 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12767 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
| 12768 | { |
| 12769 | u32 nvcfg1; |
| 12770 | |
| 12771 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12772 | |
| 12773 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12774 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 12775 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 12776 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12777 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12778 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12779 | |
| 12780 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12781 | tw32(NVRAM_CFG1, nvcfg1); |
| 12782 | return; |
| 12783 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12784 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 12785 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 12786 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 12787 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 12788 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 12789 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 12790 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12791 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12792 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12793 | |
| 12794 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12795 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12796 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 12797 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 12798 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12799 | break; |
| 12800 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 12801 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 12802 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12803 | break; |
| 12804 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 12805 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 12806 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12807 | break; |
| 12808 | } |
| 12809 | break; |
| 12810 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12811 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12812 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12813 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12814 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12815 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12816 | |
| 12817 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12818 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12819 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12820 | break; |
| 12821 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12822 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12823 | break; |
| 12824 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12825 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12826 | break; |
| 12827 | } |
| 12828 | break; |
| 12829 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12830 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12831 | return; |
| 12832 | } |
| 12833 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12834 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 12835 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12836 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12837 | } |
| 12838 | |
| 12839 | |
| 12840 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) |
| 12841 | { |
| 12842 | u32 nvcfg1; |
| 12843 | |
| 12844 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12845 | |
| 12846 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12847 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 12848 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 12849 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12850 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12851 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12852 | |
| 12853 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12854 | tw32(NVRAM_CFG1, nvcfg1); |
| 12855 | return; |
| 12856 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 12857 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 12858 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 12859 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 12860 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 12861 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 12862 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 12863 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12864 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12865 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12866 | |
| 12867 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12868 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 12869 | /* Detect size with tg3_nvram_get_size() */ |
| 12870 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12871 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 12872 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 12873 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12874 | break; |
| 12875 | default: |
| 12876 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12877 | break; |
| 12878 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12879 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12880 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 12881 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 12882 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 12883 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 12884 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 12885 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 12886 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 12887 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 12888 | case FLASH_5717VENDOR_ST_25USPT: |
| 12889 | case FLASH_5717VENDOR_ST_45USPT: |
| 12890 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12891 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12892 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12893 | |
| 12894 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12895 | case FLASH_5717VENDOR_ST_M_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12896 | case FLASH_5717VENDOR_ST_M_M45PE20: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 12897 | /* Detect size with tg3_nvram_get_size() */ |
| 12898 | break; |
| 12899 | case FLASH_5717VENDOR_ST_A_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12900 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 12901 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12902 | break; |
| 12903 | default: |
| 12904 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12905 | break; |
| 12906 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12907 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12908 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12909 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12910 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12911 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12912 | |
| 12913 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 12914 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12915 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12916 | } |
| 12917 | |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12918 | static void __devinit tg3_get_5720_nvram_info(struct tg3 *tp) |
| 12919 | { |
| 12920 | u32 nvcfg1, nvmpinstrp; |
| 12921 | |
| 12922 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12923 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; |
| 12924 | |
| 12925 | switch (nvmpinstrp) { |
| 12926 | case FLASH_5720_EEPROM_HD: |
| 12927 | case FLASH_5720_EEPROM_LD: |
| 12928 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12929 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12930 | |
| 12931 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12932 | tw32(NVRAM_CFG1, nvcfg1); |
| 12933 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) |
| 12934 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12935 | else |
| 12936 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; |
| 12937 | return; |
| 12938 | case FLASH_5720VENDOR_M_ATMEL_DB011D: |
| 12939 | case FLASH_5720VENDOR_A_ATMEL_DB011B: |
| 12940 | case FLASH_5720VENDOR_A_ATMEL_DB011D: |
| 12941 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 12942 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 12943 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 12944 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 12945 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 12946 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 12947 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 12948 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 12949 | case FLASH_5720VENDOR_ATMEL_45USPT: |
| 12950 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12951 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12952 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12953 | |
| 12954 | switch (nvmpinstrp) { |
| 12955 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 12956 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 12957 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 12958 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12959 | break; |
| 12960 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 12961 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 12962 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 12963 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12964 | break; |
| 12965 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 12966 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 12967 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 12968 | break; |
| 12969 | default: |
| 12970 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12971 | break; |
| 12972 | } |
| 12973 | break; |
| 12974 | case FLASH_5720VENDOR_M_ST_M25PE10: |
| 12975 | case FLASH_5720VENDOR_M_ST_M45PE10: |
| 12976 | case FLASH_5720VENDOR_A_ST_M25PE10: |
| 12977 | case FLASH_5720VENDOR_A_ST_M45PE10: |
| 12978 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 12979 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 12980 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 12981 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 12982 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 12983 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 12984 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 12985 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 12986 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 12987 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 12988 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 12989 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 12990 | case FLASH_5720VENDOR_ST_25USPT: |
| 12991 | case FLASH_5720VENDOR_ST_45USPT: |
| 12992 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12993 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12994 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12995 | |
| 12996 | switch (nvmpinstrp) { |
| 12997 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 12998 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 12999 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 13000 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 13001 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13002 | break; |
| 13003 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 13004 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 13005 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 13006 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 13007 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13008 | break; |
| 13009 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 13010 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 13011 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 13012 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 13013 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13014 | break; |
| 13015 | default: |
| 13016 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13017 | break; |
| 13018 | } |
| 13019 | break; |
| 13020 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13021 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13022 | return; |
| 13023 | } |
| 13024 | |
| 13025 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13026 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13027 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13028 | } |
| 13029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13030 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 13031 | static void __devinit tg3_nvram_init(struct tg3 *tp) |
| 13032 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13033 | tw32_f(GRC_EEPROM_ADDR, |
| 13034 | (EEPROM_ADDR_FSM_RESET | |
| 13035 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 13036 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 13037 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 13038 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13039 | |
| 13040 | /* Enable seeprom accesses. */ |
| 13041 | tw32_f(GRC_LOCAL_CTRL, |
| 13042 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 13043 | udelay(100); |
| 13044 | |
| 13045 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13046 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13047 | tg3_flag_set(tp, NVRAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13048 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13049 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 13050 | netdev_warn(tp->dev, |
| 13051 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 13052 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13053 | return; |
| 13054 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13055 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13056 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13057 | tp->nvram_size = 0; |
| 13058 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13059 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13060 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13061 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 13062 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13063 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13064 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13065 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13066 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13067 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 13068 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13069 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13070 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13071 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 13072 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13073 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13074 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13075 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13076 | tg3_get_5717_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13077 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 13078 | tg3_get_5720_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13079 | else |
| 13080 | tg3_get_nvram_info(tp); |
| 13081 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13082 | if (tp->nvram_size == 0) |
| 13083 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13084 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13085 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 13086 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13087 | |
| 13088 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13089 | tg3_flag_clear(tp, NVRAM); |
| 13090 | tg3_flag_clear(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13091 | |
| 13092 | tg3_get_eeprom_size(tp); |
| 13093 | } |
| 13094 | } |
| 13095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13096 | struct subsys_tbl_ent { |
| 13097 | u16 subsys_vendor, subsys_devid; |
| 13098 | u32 phy_id; |
| 13099 | }; |
| 13100 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13101 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13102 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13103 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13104 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13105 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13106 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13107 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13108 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13109 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13110 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 13111 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13112 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13113 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13114 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13115 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13116 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 13117 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13118 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13119 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13120 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13121 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13122 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13123 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13124 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13125 | |
| 13126 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13127 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13128 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13129 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13130 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13131 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 13132 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 13133 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13134 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13135 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13136 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13137 | |
| 13138 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13139 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13140 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13141 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13142 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13143 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13144 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13145 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13146 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13147 | |
| 13148 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13149 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13150 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13151 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13152 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13153 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 13154 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 13155 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13156 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13157 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13158 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13159 | |
| 13160 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13161 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 13162 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13163 | }; |
| 13164 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13165 | static struct subsys_tbl_ent * __devinit tg3_lookup_by_subsys(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13166 | { |
| 13167 | int i; |
| 13168 | |
| 13169 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 13170 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 13171 | tp->pdev->subsystem_vendor) && |
| 13172 | (subsys_id_to_phy_id[i].subsys_devid == |
| 13173 | tp->pdev->subsystem_device)) |
| 13174 | return &subsys_id_to_phy_id[i]; |
| 13175 | } |
| 13176 | return NULL; |
| 13177 | } |
| 13178 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13179 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13180 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13181 | u32 val; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13182 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13183 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13184 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13185 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 13186 | /* Assume an onboard device and WOL capable by default. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13187 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 13188 | tg3_flag_set(tp, WOL_CAP); |
David S. Miller | 72b845e | 2006-03-14 14:11:48 -0800 | [diff] [blame] | 13189 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13190 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13191 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13192 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 13193 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13194 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13195 | val = tr32(VCPU_CFGSHDW); |
| 13196 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13197 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13198 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13199 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13200 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13201 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 13202 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 13203 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13204 | } |
| 13205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13206 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 13207 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 13208 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13209 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13210 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13211 | |
| 13212 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 13213 | tp->nic_sram_data_cfg = nic_cfg; |
| 13214 | |
| 13215 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 13216 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 13217 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13218 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13219 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13220 | (ver > 0) && (ver < 0x100)) |
| 13221 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 13222 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13223 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 13224 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 13225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13226 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 13227 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 13228 | eeprom_phy_serdes = 1; |
| 13229 | |
| 13230 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 13231 | if (nic_phy_id != 0) { |
| 13232 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 13233 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 13234 | |
| 13235 | eeprom_phy_id = (id1 >> 16) << 10; |
| 13236 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 13237 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 13238 | } else |
| 13239 | eeprom_phy_id = 0; |
| 13240 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13241 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13242 | if (eeprom_phy_serdes) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13243 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13244 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13245 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13246 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13247 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13248 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13249 | if (tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13250 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 13251 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 13252 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13253 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 13254 | |
| 13255 | switch (led_cfg) { |
| 13256 | default: |
| 13257 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 13258 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13259 | break; |
| 13260 | |
| 13261 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 13262 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 13263 | break; |
| 13264 | |
| 13265 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 13266 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 13267 | |
| 13268 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 13269 | * read on some older 5700/5701 bootcode. |
| 13270 | */ |
| 13271 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 13272 | ASIC_REV_5700 || |
| 13273 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 13274 | ASIC_REV_5701) |
| 13275 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13277 | break; |
| 13278 | |
| 13279 | case SHASTA_EXT_LED_SHARED: |
| 13280 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 13281 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 13282 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 13283 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 13284 | LED_CTRL_MODE_PHY_2); |
| 13285 | break; |
| 13286 | |
| 13287 | case SHASTA_EXT_LED_MAC: |
| 13288 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 13289 | break; |
| 13290 | |
| 13291 | case SHASTA_EXT_LED_COMBO: |
| 13292 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 13293 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 13294 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 13295 | LED_CTRL_MODE_PHY_2); |
| 13296 | break; |
| 13297 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 13298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13299 | |
| 13300 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 13301 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 13302 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 13303 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 13304 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13305 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 13306 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 13307 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13308 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13309 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13310 | if ((tp->pdev->subsystem_vendor == |
| 13311 | PCI_VENDOR_ID_ARIMA) && |
| 13312 | (tp->pdev->subsystem_device == 0x205a || |
| 13313 | tp->pdev->subsystem_device == 0x2063)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13314 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13315 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13316 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 13317 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13319 | |
| 13320 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13321 | tg3_flag_set(tp, ENABLE_ASF); |
| 13322 | if (tg3_flag(tp, 5750_PLUS)) |
| 13323 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13324 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 13325 | |
| 13326 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13327 | tg3_flag(tp, 5750_PLUS)) |
| 13328 | tg3_flag_set(tp, ENABLE_APE); |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 13329 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13330 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 13331 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13332 | tg3_flag_clear(tp, WOL_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13333 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13334 | if (tg3_flag(tp, WOL_CAP) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13335 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13336 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13337 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 13338 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13340 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13341 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13342 | |
| 13343 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 13344 | /* bootcode if bit 18 is set */ |
| 13345 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13346 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13347 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13348 | if ((tg3_flag(tp, 57765_PLUS) || |
| 13349 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 13350 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 13351 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13352 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 13353 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13354 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 8c69b1e | 2010-08-02 11:26:00 +0000 | [diff] [blame] | 13355 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13356 | !tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13357 | u32 cfg3; |
| 13358 | |
| 13359 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 13360 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13361 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13362 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13363 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 13364 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13365 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13366 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13367 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13368 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13369 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13370 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 13371 | done: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13372 | if (tg3_flag(tp, WOL_CAP)) |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 13373 | device_set_wakeup_enable(&tp->pdev->dev, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13374 | tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 13375 | else |
| 13376 | device_set_wakeup_capable(&tp->pdev->dev, false); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13377 | } |
| 13378 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13379 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 13380 | { |
| 13381 | int i; |
| 13382 | u32 val; |
| 13383 | |
| 13384 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 13385 | tw32(OTP_CTRL, cmd); |
| 13386 | |
| 13387 | /* Wait for up to 1 ms for command to execute. */ |
| 13388 | for (i = 0; i < 100; i++) { |
| 13389 | val = tr32(OTP_STATUS); |
| 13390 | if (val & OTP_STATUS_CMD_DONE) |
| 13391 | break; |
| 13392 | udelay(10); |
| 13393 | } |
| 13394 | |
| 13395 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 13396 | } |
| 13397 | |
| 13398 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 13399 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 13400 | * We do two 32-bit reads and then shift and merge the results. |
| 13401 | */ |
| 13402 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) |
| 13403 | { |
| 13404 | u32 bhalf_otp, thalf_otp; |
| 13405 | |
| 13406 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 13407 | |
| 13408 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 13409 | return 0; |
| 13410 | |
| 13411 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 13412 | |
| 13413 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 13414 | return 0; |
| 13415 | |
| 13416 | thalf_otp = tr32(OTP_READ_DATA); |
| 13417 | |
| 13418 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 13419 | |
| 13420 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 13421 | return 0; |
| 13422 | |
| 13423 | bhalf_otp = tr32(OTP_READ_DATA); |
| 13424 | |
| 13425 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 13426 | } |
| 13427 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13428 | static void __devinit tg3_phy_init_link_config(struct tg3 *tp) |
| 13429 | { |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 13430 | u32 adv = ADVERTISED_Autoneg; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13431 | |
| 13432 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 13433 | adv |= ADVERTISED_1000baseT_Half | |
| 13434 | ADVERTISED_1000baseT_Full; |
| 13435 | |
| 13436 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 13437 | adv |= ADVERTISED_100baseT_Half | |
| 13438 | ADVERTISED_100baseT_Full | |
| 13439 | ADVERTISED_10baseT_Half | |
| 13440 | ADVERTISED_10baseT_Full | |
| 13441 | ADVERTISED_TP; |
| 13442 | else |
| 13443 | adv |= ADVERTISED_FIBRE; |
| 13444 | |
| 13445 | tp->link_config.advertising = adv; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 13446 | tp->link_config.speed = SPEED_UNKNOWN; |
| 13447 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13448 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 13449 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 13450 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 13451 | |
| 13452 | tp->old_link = -1; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13453 | } |
| 13454 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13455 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
| 13456 | { |
| 13457 | u32 hw_phy_id_1, hw_phy_id_2; |
| 13458 | u32 hw_phy_id, hw_phy_id_masked; |
| 13459 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13460 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13461 | /* flow control autonegotiation is default behavior */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13462 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13463 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 13464 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13465 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13466 | return tg3_phy_init(tp); |
| 13467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13468 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 13469 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13470 | */ |
| 13471 | err = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13472 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13473 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13474 | } else { |
| 13475 | /* Now read the physical PHY_ID from the chip and verify |
| 13476 | * that it is sane. If it doesn't look good, we fall back |
| 13477 | * to either the hard-coded table based PHY_ID and failing |
| 13478 | * that the value found in the eeprom area. |
| 13479 | */ |
| 13480 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 13481 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 13482 | |
| 13483 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 13484 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 13485 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 13486 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13487 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13488 | } |
| 13489 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13490 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13491 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13492 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13493 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 13494 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13495 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13496 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13497 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13498 | /* Do nothing, phy ID already set up in |
| 13499 | * tg3_get_eeprom_hw_cfg(). |
| 13500 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13501 | } else { |
| 13502 | struct subsys_tbl_ent *p; |
| 13503 | |
| 13504 | /* No eeprom signature? Try the hardcoded |
| 13505 | * subsys device table. |
| 13506 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13507 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13508 | if (!p) |
| 13509 | return -ENODEV; |
| 13510 | |
| 13511 | tp->phy_id = p->phy_id; |
| 13512 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13513 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13514 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13515 | } |
| 13516 | } |
| 13517 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 13518 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Matt Carlson | 5baa5e9 | 2011-07-20 10:20:53 +0000 | [diff] [blame] | 13519 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 13520 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 13521 | (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 13522 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || |
| 13523 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 13524 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 13525 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 13526 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13527 | tg3_phy_init_link_config(tp); |
| 13528 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13529 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13530 | !tg3_flag(tp, ENABLE_APE) && |
| 13531 | !tg3_flag(tp, ENABLE_ASF)) { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 13532 | u32 bmsr, dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13533 | |
| 13534 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 13535 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 13536 | (bmsr & BMSR_LSTATUS)) |
| 13537 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13539 | err = tg3_phy_reset(tp); |
| 13540 | if (err) |
| 13541 | return err; |
| 13542 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 13543 | tg3_phy_set_wirespeed(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13544 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 13545 | if (!tg3_phy_copper_an_config_ok(tp, &dummy)) { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 13546 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 13547 | tp->link_config.flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13548 | |
| 13549 | tg3_writephy(tp, MII_BMCR, |
| 13550 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 13551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13552 | } |
| 13553 | |
| 13554 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13555 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13556 | err = tg3_init_5401phy_dsp(tp); |
| 13557 | if (err) |
| 13558 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13560 | err = tg3_init_5401phy_dsp(tp); |
| 13561 | } |
| 13562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13563 | return err; |
| 13564 | } |
| 13565 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13566 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13567 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13568 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13569 | unsigned int block_end, rosize, len; |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13570 | u32 vpdlen; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13571 | int j, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13572 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13573 | vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13574 | if (!vpd_data) |
| 13575 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13576 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13577 | i = pci_vpd_find_tag(vpd_data, 0, vpdlen, PCI_VPD_LRDT_RO_DATA); |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13578 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13579 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13580 | |
| 13581 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 13582 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 13583 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 13584 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13585 | if (block_end > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13586 | goto out_not_found; |
| 13587 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13588 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13589 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 13590 | if (j > 0) { |
| 13591 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 13592 | |
| 13593 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13594 | if (j + len > block_end || len != 4 || |
| 13595 | memcmp(&vpd_data[j], "1028", 4)) |
| 13596 | goto partno; |
| 13597 | |
| 13598 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13599 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 13600 | if (j < 0) |
| 13601 | goto partno; |
| 13602 | |
| 13603 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 13604 | |
| 13605 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13606 | if (j + len > block_end) |
| 13607 | goto partno; |
| 13608 | |
| 13609 | memcpy(tp->fw_ver, &vpd_data[j], len); |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13610 | strncat(tp->fw_ver, " bc ", vpdlen - len - 1); |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13611 | } |
| 13612 | |
| 13613 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13614 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13615 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 13616 | if (i < 0) |
| 13617 | goto out_not_found; |
| 13618 | |
| 13619 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 13620 | |
| 13621 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13622 | if (len > TG3_BPN_SIZE || |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13623 | (len + i) > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13624 | goto out_not_found; |
| 13625 | |
| 13626 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 13627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13628 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13629 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13630 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13631 | return; |
| 13632 | |
| 13633 | out_no_vpd: |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13634 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 13635 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717) |
| 13636 | strcpy(tp->board_part_number, "BCM5717"); |
| 13637 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 13638 | strcpy(tp->board_part_number, "BCM5718"); |
| 13639 | else |
| 13640 | goto nomatch; |
| 13641 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 13642 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 13643 | strcpy(tp->board_part_number, "BCM57780"); |
| 13644 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 13645 | strcpy(tp->board_part_number, "BCM57760"); |
| 13646 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 13647 | strcpy(tp->board_part_number, "BCM57790"); |
| 13648 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 13649 | strcpy(tp->board_part_number, "BCM57788"); |
| 13650 | else |
| 13651 | goto nomatch; |
| 13652 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 13653 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 13654 | strcpy(tp->board_part_number, "BCM57761"); |
| 13655 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 13656 | strcpy(tp->board_part_number, "BCM57765"); |
| 13657 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 13658 | strcpy(tp->board_part_number, "BCM57781"); |
| 13659 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 13660 | strcpy(tp->board_part_number, "BCM57785"); |
| 13661 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 13662 | strcpy(tp->board_part_number, "BCM57791"); |
| 13663 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 13664 | strcpy(tp->board_part_number, "BCM57795"); |
| 13665 | else |
| 13666 | goto nomatch; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 13667 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) { |
| 13668 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762) |
| 13669 | strcpy(tp->board_part_number, "BCM57762"); |
| 13670 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766) |
| 13671 | strcpy(tp->board_part_number, "BCM57766"); |
| 13672 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782) |
| 13673 | strcpy(tp->board_part_number, "BCM57782"); |
| 13674 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 13675 | strcpy(tp->board_part_number, "BCM57786"); |
| 13676 | else |
| 13677 | goto nomatch; |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13678 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13679 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13680 | } else { |
| 13681 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13682 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13683 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13684 | } |
| 13685 | |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13686 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 13687 | { |
| 13688 | u32 val; |
| 13689 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13690 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13691 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13692 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13693 | val != 0) |
| 13694 | return 0; |
| 13695 | |
| 13696 | return 1; |
| 13697 | } |
| 13698 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13699 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
| 13700 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13701 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13702 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13703 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13704 | |
| 13705 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 13706 | tg3_nvram_read(tp, 0x4, &start)) |
| 13707 | return; |
| 13708 | |
| 13709 | offset = tg3_nvram_logical_addr(tp, offset); |
| 13710 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13711 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13712 | return; |
| 13713 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13714 | if ((val & 0xfc000000) == 0x0c000000) { |
| 13715 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13716 | return; |
| 13717 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13718 | if (val == 0) |
| 13719 | newver = true; |
| 13720 | } |
| 13721 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13722 | dst_off = strlen(tp->fw_ver); |
| 13723 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13724 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13725 | if (TG3_VER_SIZE - dst_off < 16 || |
| 13726 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13727 | return; |
| 13728 | |
| 13729 | offset = offset + ver_offset - start; |
| 13730 | for (i = 0; i < 16; i += 4) { |
| 13731 | __be32 v; |
| 13732 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 13733 | return; |
| 13734 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13735 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13736 | } |
| 13737 | } else { |
| 13738 | u32 major, minor; |
| 13739 | |
| 13740 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 13741 | return; |
| 13742 | |
| 13743 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 13744 | TG3_NVM_BCVER_MAJSFT; |
| 13745 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13746 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 13747 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13748 | } |
| 13749 | } |
| 13750 | |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13751 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
| 13752 | { |
| 13753 | u32 val, major, minor; |
| 13754 | |
| 13755 | /* Use native endian representation */ |
| 13756 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 13757 | return; |
| 13758 | |
| 13759 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 13760 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 13761 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 13762 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 13763 | |
| 13764 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 13765 | } |
| 13766 | |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13767 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 13768 | { |
| 13769 | u32 offset, major, minor, build; |
| 13770 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13771 | strncat(tp->fw_ver, "sb", TG3_VER_SIZE - strlen(tp->fw_ver) - 1); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13772 | |
| 13773 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 13774 | return; |
| 13775 | |
| 13776 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 13777 | case TG3_EEPROM_SB_REVISION_0: |
| 13778 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 13779 | break; |
| 13780 | case TG3_EEPROM_SB_REVISION_2: |
| 13781 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 13782 | break; |
| 13783 | case TG3_EEPROM_SB_REVISION_3: |
| 13784 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 13785 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 13786 | case TG3_EEPROM_SB_REVISION_4: |
| 13787 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 13788 | break; |
| 13789 | case TG3_EEPROM_SB_REVISION_5: |
| 13790 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 13791 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 13792 | case TG3_EEPROM_SB_REVISION_6: |
| 13793 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 13794 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13795 | default: |
| 13796 | return; |
| 13797 | } |
| 13798 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13799 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13800 | return; |
| 13801 | |
| 13802 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 13803 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 13804 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 13805 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 13806 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 13807 | |
| 13808 | if (minor > 99 || build > 26) |
| 13809 | return; |
| 13810 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13811 | offset = strlen(tp->fw_ver); |
| 13812 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 13813 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13814 | |
| 13815 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13816 | offset = strlen(tp->fw_ver); |
| 13817 | if (offset < TG3_VER_SIZE - 1) |
| 13818 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13819 | } |
| 13820 | } |
| 13821 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13822 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13823 | { |
| 13824 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13825 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13826 | |
| 13827 | for (offset = TG3_NVM_DIR_START; |
| 13828 | offset < TG3_NVM_DIR_END; |
| 13829 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13830 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13831 | return; |
| 13832 | |
| 13833 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 13834 | break; |
| 13835 | } |
| 13836 | |
| 13837 | if (offset == TG3_NVM_DIR_END) |
| 13838 | return; |
| 13839 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13840 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13841 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13842 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13843 | return; |
| 13844 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13845 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13846 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13847 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13848 | return; |
| 13849 | |
| 13850 | offset += val - start; |
| 13851 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13852 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13853 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13854 | tp->fw_ver[vlen++] = ','; |
| 13855 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13856 | |
| 13857 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 13858 | __be32 v; |
| 13859 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13860 | return; |
| 13861 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 13862 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13863 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13864 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 13865 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13866 | break; |
| 13867 | } |
| 13868 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13869 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 13870 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13871 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13872 | } |
| 13873 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13874 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
| 13875 | { |
| 13876 | int vlen; |
| 13877 | u32 apedata; |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13878 | char *fwtype; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13879 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13880 | if (!tg3_flag(tp, ENABLE_APE) || !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13881 | return; |
| 13882 | |
| 13883 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 13884 | if (apedata != APE_SEG_SIG_MAGIC) |
| 13885 | return; |
| 13886 | |
| 13887 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 13888 | if (!(apedata & APE_FW_STATUS_READY)) |
| 13889 | return; |
| 13890 | |
| 13891 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 13892 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13893 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13894 | tg3_flag_set(tp, APE_HAS_NCSI); |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13895 | fwtype = "NCSI"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13896 | } else { |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13897 | fwtype = "DASH"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13898 | } |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13899 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13900 | vlen = strlen(tp->fw_ver); |
| 13901 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13902 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 13903 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13904 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 13905 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 13906 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 13907 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 13908 | } |
| 13909 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13910 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
| 13911 | { |
| 13912 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13913 | bool vpd_vers = false; |
| 13914 | |
| 13915 | if (tp->fw_ver[0] != 0) |
| 13916 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13917 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13918 | if (tg3_flag(tp, NO_NVRAM)) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13919 | strcat(tp->fw_ver, "sb"); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13920 | return; |
| 13921 | } |
| 13922 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13923 | if (tg3_nvram_read(tp, 0, &val)) |
| 13924 | return; |
| 13925 | |
| 13926 | if (val == TG3_EEPROM_MAGIC) |
| 13927 | tg3_read_bc_ver(tp); |
| 13928 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 13929 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13930 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 13931 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13932 | else |
| 13933 | return; |
| 13934 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 13935 | if (vpd_vers) |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13936 | goto done; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13937 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 13938 | if (tg3_flag(tp, ENABLE_APE)) { |
| 13939 | if (tg3_flag(tp, ENABLE_ASF)) |
| 13940 | tg3_read_dash_ver(tp); |
| 13941 | } else if (tg3_flag(tp, ENABLE_ASF)) { |
| 13942 | tg3_read_mgmtfw_ver(tp); |
| 13943 | } |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13944 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13945 | done: |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13946 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13947 | } |
| 13948 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13949 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 13950 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13951 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13952 | return TG3_RX_RET_MAX_SIZE_5717; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13953 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13954 | return TG3_RX_RET_MAX_SIZE_5700; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13955 | else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13956 | return TG3_RX_RET_MAX_SIZE_5705; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13957 | } |
| 13958 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 13959 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 13960 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
| 13961 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
| 13962 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, |
| 13963 | { }, |
| 13964 | }; |
| 13965 | |
Matt Carlson | 16c7fa7 | 2012-02-13 10:20:10 +0000 | [diff] [blame] | 13966 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
| 13967 | { |
| 13968 | struct pci_dev *peer; |
| 13969 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 13970 | |
| 13971 | for (func = 0; func < 8; func++) { |
| 13972 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 13973 | if (peer && peer != tp->pdev) |
| 13974 | break; |
| 13975 | pci_dev_put(peer); |
| 13976 | } |
| 13977 | /* 5704 can be configured in single-port mode, set peer to |
| 13978 | * tp->pdev in that case. |
| 13979 | */ |
| 13980 | if (!peer) { |
| 13981 | peer = tp->pdev; |
| 13982 | return peer; |
| 13983 | } |
| 13984 | |
| 13985 | /* |
| 13986 | * We don't need to keep the refcount elevated; there's no way |
| 13987 | * to remove one half of this device without removing the other |
| 13988 | */ |
| 13989 | pci_dev_put(peer); |
| 13990 | |
| 13991 | return peer; |
| 13992 | } |
| 13993 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 13994 | static void __devinit tg3_detect_asic_rev(struct tg3 *tp, u32 misc_ctrl_reg) |
| 13995 | { |
| 13996 | tp->pci_chip_rev_id = misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT; |
| 13997 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 13998 | u32 reg; |
| 13999 | |
| 14000 | /* All devices that use the alternate |
| 14001 | * ASIC REV location have a CPMU. |
| 14002 | */ |
| 14003 | tg3_flag_set(tp, CPMU_PRESENT); |
| 14004 | |
| 14005 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 14006 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 14007 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 14008 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) |
| 14009 | reg = TG3PCI_GEN2_PRODID_ASICREV; |
| 14010 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 14011 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 14012 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 14013 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 14014 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 14015 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
| 14016 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762 || |
| 14017 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766 || |
| 14018 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782 || |
| 14019 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 14020 | reg = TG3PCI_GEN15_PRODID_ASICREV; |
| 14021 | else |
| 14022 | reg = TG3PCI_PRODID_ASICREV; |
| 14023 | |
| 14024 | pci_read_config_dword(tp->pdev, reg, &tp->pci_chip_rev_id); |
| 14025 | } |
| 14026 | |
| 14027 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 14028 | * as A0 is not in production. |
| 14029 | */ |
| 14030 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 14031 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 14032 | |
| 14033 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14034 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14035 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14036 | tg3_flag_set(tp, 5717_PLUS); |
| 14037 | |
| 14038 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 || |
| 14039 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 14040 | tg3_flag_set(tp, 57765_CLASS); |
| 14041 | |
| 14042 | if (tg3_flag(tp, 57765_CLASS) || tg3_flag(tp, 5717_PLUS)) |
| 14043 | tg3_flag_set(tp, 57765_PLUS); |
| 14044 | |
| 14045 | /* Intentionally exclude ASIC_REV_5906 */ |
| 14046 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 14047 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
| 14048 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 14049 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 14050 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 14051 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 14052 | tg3_flag(tp, 57765_PLUS)) |
| 14053 | tg3_flag_set(tp, 5755_PLUS); |
| 14054 | |
| 14055 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 14056 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
| 14057 | tg3_flag_set(tp, 5780_CLASS); |
| 14058 | |
| 14059 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 14060 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 14061 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
| 14062 | tg3_flag(tp, 5755_PLUS) || |
| 14063 | tg3_flag(tp, 5780_CLASS)) |
| 14064 | tg3_flag_set(tp, 5750_PLUS); |
| 14065 | |
| 14066 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14067 | tg3_flag(tp, 5750_PLUS)) |
| 14068 | tg3_flag_set(tp, 5705_PLUS); |
| 14069 | } |
| 14070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14071 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
| 14072 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14073 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14074 | u32 pci_state_reg, grc_misc_cfg; |
| 14075 | u32 val; |
| 14076 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14077 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14079 | /* Force memory write invalidate off. If we leave it on, |
| 14080 | * then on 5700_BX chips we have to enable a workaround. |
| 14081 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 14082 | * to match the cacheline size. The Broadcom driver have this |
| 14083 | * workaround but turns MWI off all the times so never uses |
| 14084 | * it. This seems to suggest that the workaround is insufficient. |
| 14085 | */ |
| 14086 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14087 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 14088 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14089 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14090 | /* Important! -- Make sure register accesses are byteswapped |
| 14091 | * correctly. Also, for those chips that require it, make |
| 14092 | * sure that indirect register accesses are enabled before |
| 14093 | * the first operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14094 | */ |
| 14095 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14096 | &misc_ctrl_reg); |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14097 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 14098 | MISC_HOST_CTRL_CHIPREV); |
| 14099 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14100 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14101 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14102 | tg3_detect_asic_rev(tp, misc_ctrl_reg); |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 14103 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14104 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 14105 | * we need to disable memory and use config. cycles |
| 14106 | * only to access all registers. The 5702/03 chips |
| 14107 | * can mistakenly decode the special cycles from the |
| 14108 | * ICH chipsets as memory write cycles, causing corruption |
| 14109 | * of register and memory space. Only certain ICH bridges |
| 14110 | * will drive special cycles with non-zero data during the |
| 14111 | * address phase which can fall within the 5703's address |
| 14112 | * range. This is not an ICH bug as the PCI spec allows |
| 14113 | * non-zero address during special cycles. However, only |
| 14114 | * these ICH bridges are known to drive non-zero addresses |
| 14115 | * during special cycles. |
| 14116 | * |
| 14117 | * Since special cycles do not cross PCI bridges, we only |
| 14118 | * enable this workaround if the 5703 is on the secondary |
| 14119 | * bus of these ICH bridges. |
| 14120 | */ |
| 14121 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 14122 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 14123 | static struct tg3_dev_id { |
| 14124 | u32 vendor; |
| 14125 | u32 device; |
| 14126 | u32 rev; |
| 14127 | } ich_chipsets[] = { |
| 14128 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 14129 | PCI_ANY_ID }, |
| 14130 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 14131 | PCI_ANY_ID }, |
| 14132 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 14133 | 0xa }, |
| 14134 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 14135 | PCI_ANY_ID }, |
| 14136 | { }, |
| 14137 | }; |
| 14138 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 14139 | struct pci_dev *bridge = NULL; |
| 14140 | |
| 14141 | while (pci_id->vendor != 0) { |
| 14142 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 14143 | bridge); |
| 14144 | if (!bridge) { |
| 14145 | pci_id++; |
| 14146 | continue; |
| 14147 | } |
| 14148 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 14149 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14150 | continue; |
| 14151 | } |
| 14152 | if (bridge->subordinate && |
| 14153 | (bridge->subordinate->number == |
| 14154 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14155 | tg3_flag_set(tp, ICH_WORKAROUND); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14156 | pci_dev_put(bridge); |
| 14157 | break; |
| 14158 | } |
| 14159 | } |
| 14160 | } |
| 14161 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14162 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 14163 | static struct tg3_dev_id { |
| 14164 | u32 vendor; |
| 14165 | u32 device; |
| 14166 | } bridge_chipsets[] = { |
| 14167 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 14168 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 14169 | { }, |
| 14170 | }; |
| 14171 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 14172 | struct pci_dev *bridge = NULL; |
| 14173 | |
| 14174 | while (pci_id->vendor != 0) { |
| 14175 | bridge = pci_get_device(pci_id->vendor, |
| 14176 | pci_id->device, |
| 14177 | bridge); |
| 14178 | if (!bridge) { |
| 14179 | pci_id++; |
| 14180 | continue; |
| 14181 | } |
| 14182 | if (bridge->subordinate && |
| 14183 | (bridge->subordinate->number <= |
| 14184 | tp->pdev->bus->number) && |
| 14185 | (bridge->subordinate->subordinate >= |
| 14186 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14187 | tg3_flag_set(tp, 5701_DMA_BUG); |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 14188 | pci_dev_put(bridge); |
| 14189 | break; |
| 14190 | } |
| 14191 | } |
| 14192 | } |
| 14193 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14194 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 14195 | * DMA addresses > 40-bit. This bridge may have other additional |
| 14196 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 14197 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 14198 | * DMA workaround. |
| 14199 | */ |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14200 | if (tg3_flag(tp, 5780_CLASS)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14201 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14202 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14203 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14204 | struct pci_dev *bridge = NULL; |
| 14205 | |
| 14206 | do { |
| 14207 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 14208 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 14209 | bridge); |
| 14210 | if (bridge && bridge->subordinate && |
| 14211 | (bridge->subordinate->number <= |
| 14212 | tp->pdev->bus->number) && |
| 14213 | (bridge->subordinate->subordinate >= |
| 14214 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14215 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14216 | pci_dev_put(bridge); |
| 14217 | break; |
| 14218 | } |
| 14219 | } while (bridge); |
| 14220 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14221 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14222 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 14223 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14224 | tp->pdev_peer = tg3_find_peer(tp); |
| 14225 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14226 | /* Determine TSO capabilities */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 14227 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0) |
Matt Carlson | 4d163b7 | 2011-01-25 15:58:48 +0000 | [diff] [blame] | 14228 | ; /* Do nothing. HW bug. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14229 | else if (tg3_flag(tp, 57765_PLUS)) |
| 14230 | tg3_flag_set(tp, HW_TSO_3); |
| 14231 | else if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14232 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14233 | tg3_flag_set(tp, HW_TSO_2); |
| 14234 | else if (tg3_flag(tp, 5750_PLUS)) { |
| 14235 | tg3_flag_set(tp, HW_TSO_1); |
| 14236 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14237 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 14238 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14239 | tg3_flag_clear(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14240 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14241 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 14242 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14243 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14244 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 14245 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 14246 | else |
| 14247 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 14248 | } |
| 14249 | |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14250 | /* Selectively allow TSO based on operating conditions */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14251 | if (tg3_flag(tp, HW_TSO_1) || |
| 14252 | tg3_flag(tp, HW_TSO_2) || |
| 14253 | tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14254 | tp->fw_needed) { |
| 14255 | /* For firmware TSO, assume ASF is disabled. |
| 14256 | * We'll disable TSO later if we discover ASF |
| 14257 | * is enabled in tg3_get_eeprom_hw_cfg(). |
| 14258 | */ |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14259 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14260 | } else { |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14261 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 14262 | tg3_flag_clear(tp, TSO_BUG); |
| 14263 | tp->fw_needed = NULL; |
| 14264 | } |
| 14265 | |
| 14266 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
| 14267 | tp->fw_needed = FIRMWARE_TG3; |
| 14268 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14269 | tp->irq_max = 1; |
| 14270 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14271 | if (tg3_flag(tp, 5750_PLUS)) { |
| 14272 | tg3_flag_set(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14273 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 14274 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 14275 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 14276 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 14277 | tp->pdev_peer == tp->pdev)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14278 | tg3_flag_clear(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14279 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14280 | if (tg3_flag(tp, 5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14281 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14282 | tg3_flag_set(tp, 1SHOT_MSI); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 14283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14284 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14285 | if (tg3_flag(tp, 57765_PLUS)) { |
| 14286 | tg3_flag_set(tp, SUPPORT_MSIX); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14287 | tp->irq_max = TG3_IRQ_MAX_VECS; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 14288 | tg3_rss_init_dflt_indir_tbl(tp); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14289 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14290 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 14291 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 14292 | if (tg3_flag(tp, 5755_PLUS)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14293 | tg3_flag_set(tp, SHORT_DMA_BUG); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14294 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 14295 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 14296 | tp->dma_limit = TG3_TX_BD_DMA_MAX_4K; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 14297 | |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 14298 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14299 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14300 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14301 | tg3_flag_set(tp, LRG_PROD_RING_CAP); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14302 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14303 | if (tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 14304 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14305 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 14306 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14307 | if (!tg3_flag(tp, 5705_PLUS) || |
| 14308 | tg3_flag(tp, 5780_CLASS) || |
| 14309 | tg3_flag(tp, USE_JUMBO_BDFLAG)) |
| 14310 | tg3_flag_set(tp, JUMBO_CAPABLE); |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 14311 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14312 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14313 | &pci_state_reg); |
| 14314 | |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 14315 | if (pci_is_pcie(tp->pdev)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14316 | u16 lnkctl; |
| 14317 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14318 | tg3_flag_set(tp, PCI_EXPRESS); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 14319 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14320 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 14321 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14322 | &lnkctl); |
| 14323 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 14324 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 14325 | ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14326 | tg3_flag_clear(tp, HW_TSO_2); |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14327 | tg3_flag_clear(tp, TSO_CAPABLE); |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 14328 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14329 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14330 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 14331 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 14332 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14333 | tg3_flag_set(tp, CLKREQ_BUG); |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 14334 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14335 | tg3_flag_set(tp, L1PLLPD_EN); |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 14336 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14337 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 14338 | /* BCM5785 devices are effectively PCIe devices, and should |
| 14339 | * follow PCIe codepaths, but do not have a PCIe capabilities |
| 14340 | * section. |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 14341 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14342 | tg3_flag_set(tp, PCI_EXPRESS); |
| 14343 | } else if (!tg3_flag(tp, 5705_PLUS) || |
| 14344 | tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14345 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 14346 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14347 | dev_err(&tp->pdev->dev, |
| 14348 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14349 | return -EIO; |
| 14350 | } |
| 14351 | |
| 14352 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14353 | tg3_flag_set(tp, PCIX_MODE); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14355 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 14356 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 14357 | * reordering to the mailbox registers done by the host |
| 14358 | * controller can cause major troubles. We read back from |
| 14359 | * every mailbox register write to force the writes to be |
| 14360 | * posted to the chip in order. |
| 14361 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 14362 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14363 | !tg3_flag(tp, PCI_EXPRESS)) |
| 14364 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 14365 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 14366 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 14367 | &tp->pci_cacheline_sz); |
| 14368 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 14369 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14370 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14371 | tp->pci_lat_timer < 64) { |
| 14372 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 14373 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 14374 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14375 | } |
| 14376 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14377 | /* Important! -- It is critical that the PCI-X hw workaround |
| 14378 | * situation is decided before the first MMIO register access. |
| 14379 | */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14380 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 14381 | /* 5700 BX chips need to have their TX producer index |
| 14382 | * mailboxes written twice to workaround a bug. |
| 14383 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14384 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14385 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14386 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14387 | * |
| 14388 | * The workaround is to use indirect register accesses |
| 14389 | * for all chip writes not to mailbox registers. |
| 14390 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14391 | if (tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14392 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14393 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14394 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14395 | |
| 14396 | /* The chip can have it's power management PCI config |
| 14397 | * space registers clobbered due to this bug. |
| 14398 | * So explicitly force the chip into D0 here. |
| 14399 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14400 | pci_read_config_dword(tp->pdev, |
| 14401 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14402 | &pm_reg); |
| 14403 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 14404 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14405 | pci_write_config_dword(tp->pdev, |
| 14406 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14407 | pm_reg); |
| 14408 | |
| 14409 | /* Also, force SERR#/PERR# in PCI command. */ |
| 14410 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14411 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 14412 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14413 | } |
| 14414 | } |
| 14415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14416 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14417 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14418 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14419 | tg3_flag_set(tp, PCI_32BIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14420 | |
| 14421 | /* Chip-specific fixup from Broadcom driver */ |
| 14422 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 14423 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 14424 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 14425 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 14426 | } |
| 14427 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14428 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14429 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14430 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 14431 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14432 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14433 | tp->write32_tx_mbox = tg3_write32; |
| 14434 | tp->write32_rx_mbox = tg3_write32; |
| 14435 | |
| 14436 | /* Various workaround register access methods */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14437 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14438 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14439 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14440 | (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14441 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 14442 | /* |
| 14443 | * Back to back register writes can cause problems on these |
| 14444 | * chips, the workaround is to read back all reg writes |
| 14445 | * except those to mailbox regs. |
| 14446 | * |
| 14447 | * See tg3_write_indirect_reg32(). |
| 14448 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14449 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14450 | } |
| 14451 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14452 | if (tg3_flag(tp, TXD_MBOX_HWBUG) || tg3_flag(tp, MBOX_WRITE_REORDER)) { |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14453 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14454 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14455 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 14456 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14457 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14458 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14459 | tp->read32 = tg3_read_indirect_reg32; |
| 14460 | tp->write32 = tg3_write_indirect_reg32; |
| 14461 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 14462 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 14463 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 14464 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 14465 | |
| 14466 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14467 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14468 | |
| 14469 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14470 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 14471 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14472 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14473 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 14474 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 14475 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 14476 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 14477 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 14478 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14479 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14480 | if (tp->write32 == tg3_write_indirect_reg32 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14481 | (tg3_flag(tp, PCIX_MODE) && |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14482 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 14483 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14484 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14485 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14486 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 14487 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 14488 | * sure it is enabled, but other entities such as system netboot |
| 14489 | * code might disable it. |
| 14490 | */ |
| 14491 | val = tr32(MEMARB_MODE); |
| 14492 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 14493 | |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 14494 | tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; |
| 14495 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 14496 | tg3_flag(tp, 5780_CLASS)) { |
| 14497 | if (tg3_flag(tp, PCIX_MODE)) { |
| 14498 | pci_read_config_dword(tp->pdev, |
| 14499 | tp->pcix_cap + PCI_X_STATUS, |
| 14500 | &val); |
| 14501 | tp->pci_fn = val & 0x7; |
| 14502 | } |
| 14503 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 14504 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
| 14505 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) == |
| 14506 | NIC_SRAM_CPMUSTAT_SIG) { |
| 14507 | tp->pci_fn = val & TG3_CPMU_STATUS_FMSK_5717; |
| 14508 | tp->pci_fn = tp->pci_fn ? 1 : 0; |
| 14509 | } |
| 14510 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14511 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 14512 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
| 14513 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) == |
| 14514 | NIC_SRAM_CPMUSTAT_SIG) { |
| 14515 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >> |
| 14516 | TG3_CPMU_STATUS_FSHFT_5719; |
| 14517 | } |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 14518 | } |
| 14519 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14520 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14521 | * In particular, the TG3_FLAG_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14522 | * determined before calling tg3_set_power_state() so that |
| 14523 | * we know whether or not to switch out of Vaux power. |
| 14524 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 14525 | * write protect and also implies that it is a LOM where GPIOs |
| 14526 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 14527 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14528 | tg3_get_eeprom_hw_cfg(tp); |
| 14529 | |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14530 | if (tp->fw_needed && tg3_flag(tp, ENABLE_ASF)) { |
| 14531 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 14532 | tg3_flag_clear(tp, TSO_BUG); |
| 14533 | tp->fw_needed = NULL; |
| 14534 | } |
| 14535 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14536 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14537 | /* Allow reads and writes to the |
| 14538 | * APE register and memory space. |
| 14539 | */ |
| 14540 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 14541 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 14542 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14543 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14544 | pci_state_reg); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 14545 | |
| 14546 | tg3_ape_lock_init(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14547 | } |
| 14548 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14549 | /* Set up tp->grc_local_ctrl before calling |
| 14550 | * tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high |
| 14551 | * will bring 5700's external PHY out of reset. |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 14552 | * It is also used as eeprom write protect on LOMs. |
| 14553 | */ |
| 14554 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14555 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14556 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 14557 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 14558 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 14559 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 14560 | * are no pull-up resistors on unused GPIO pins. |
| 14561 | */ |
| 14562 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 14563 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 14564 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14565 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 14566 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 14567 | tg3_flag(tp, 57765_CLASS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 14568 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 14569 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 14570 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 14571 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 14572 | /* Turn off the debug UART. */ |
| 14573 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14574 | if (tg3_flag(tp, IS_NIC)) |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 14575 | /* Keep VMain power. */ |
| 14576 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 14577 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 14578 | } |
| 14579 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14580 | /* Switch out of Vaux if it is a NIC */ |
| 14581 | tg3_pwrsrc_switch_to_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14583 | /* Derive initial jumbo mode from MTU assigned in |
| 14584 | * ether_setup() via the alloc_etherdev() call |
| 14585 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14586 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
| 14587 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14588 | |
| 14589 | /* Determine WakeOnLan speed to use. */ |
| 14590 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14591 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 14592 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 14593 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14594 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14595 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14596 | tg3_flag_set(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14597 | } |
| 14598 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 14599 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14600 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 14601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14602 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14603 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14604 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14605 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 14606 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14607 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 14608 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 14609 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14610 | |
| 14611 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 14612 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14613 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14614 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14615 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14616 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14617 | if (tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14618 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14619 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14620 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14621 | !tg3_flag(tp, 57765_PLUS)) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 14622 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 14623 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 14624 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 14625 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 14626 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 14627 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14628 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 14629 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14630 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14631 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14632 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 14633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14634 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14635 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 14636 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 14637 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 14638 | if (tp->phy_otp == 0) |
| 14639 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 14640 | } |
| 14641 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14642 | if (tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 14643 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 14644 | else |
| 14645 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 14646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14647 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14648 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 14649 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 14650 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 14651 | |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 14652 | /* Set these bits to enable statistics workaround. */ |
| 14653 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14654 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 14655 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) { |
| 14656 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
| 14657 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; |
| 14658 | } |
| 14659 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14660 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 14661 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14662 | tg3_flag_set(tp, USE_PHYLIB); |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 14663 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14664 | err = tg3_mdio_init(tp); |
| 14665 | if (err) |
| 14666 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14667 | |
| 14668 | /* Initialize data/descriptor byte/word swapping. */ |
| 14669 | val = tr32(GRC_MODE); |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 14670 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14671 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
| 14672 | GRC_MODE_WORD_SWAP_B2HRX_DATA | |
| 14673 | GRC_MODE_B2HRX_ENABLE | |
| 14674 | GRC_MODE_HTX2B_ENABLE | |
| 14675 | GRC_MODE_HOST_STACKUP); |
| 14676 | else |
| 14677 | val &= GRC_MODE_HOST_STACKUP; |
| 14678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14679 | tw32(GRC_MODE, val | tp->grc_mode); |
| 14680 | |
| 14681 | tg3_switch_clocks(tp); |
| 14682 | |
| 14683 | /* Clear this out for sanity. */ |
| 14684 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 14685 | |
| 14686 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14687 | &pci_state_reg); |
| 14688 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14689 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14690 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 14691 | |
| 14692 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 14693 | chiprevid == CHIPREV_ID_5701_B0 || |
| 14694 | chiprevid == CHIPREV_ID_5701_B2 || |
| 14695 | chiprevid == CHIPREV_ID_5701_B5) { |
| 14696 | void __iomem *sram_base; |
| 14697 | |
| 14698 | /* Write some dummy words into the SRAM status block |
| 14699 | * area, see if it reads back correctly. If the return |
| 14700 | * value is bad, force enable the PCIX workaround. |
| 14701 | */ |
| 14702 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 14703 | |
| 14704 | writel(0x00000000, sram_base); |
| 14705 | writel(0x00000000, sram_base + 4); |
| 14706 | writel(0xffffffff, sram_base + 4); |
| 14707 | if (readl(sram_base) != 0x00000000) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14708 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14709 | } |
| 14710 | } |
| 14711 | |
| 14712 | udelay(50); |
| 14713 | tg3_nvram_init(tp); |
| 14714 | |
| 14715 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 14716 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 14717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14718 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 14719 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 14720 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14721 | tg3_flag_set(tp, IS_5788); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14722 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14723 | if (!tg3_flag(tp, IS_5788) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14724 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14725 | tg3_flag_set(tp, TAGGED_STATUS); |
| 14726 | if (tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 14727 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 14728 | HOSTCC_MODE_CLRTICK_TXBD); |
| 14729 | |
| 14730 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 14731 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14732 | tp->misc_host_ctrl); |
| 14733 | } |
| 14734 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 14735 | /* Preserve the APE MAC_MODE bits */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14736 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 14737 | tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 14738 | else |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 14739 | tp->mac_mode = 0; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 14740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14741 | /* these are limited to 10/100 only */ |
| 14742 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14743 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 14744 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 14745 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 14746 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || |
| 14747 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || |
| 14748 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || |
| 14749 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 14750 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 14751 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
| 14752 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14753 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
Matt Carlson | d110114 | 2010-02-17 15:16:55 +0000 | [diff] [blame] | 14754 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 14755 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14756 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 14757 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14758 | |
| 14759 | err = tg3_phy_probe(tp); |
| 14760 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14761 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14762 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14763 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14764 | } |
| 14765 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14766 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 14767 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14768 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14769 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 14770 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14771 | } else { |
| 14772 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14773 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14774 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14775 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14776 | } |
| 14777 | |
| 14778 | /* 5700 {AX,BX} chips have a broken status block link |
| 14779 | * change bit implementation, so we must use the |
| 14780 | * status register in those cases. |
| 14781 | */ |
| 14782 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14783 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14784 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14785 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14786 | |
| 14787 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 14788 | * have to force the link status polling mechanism based |
| 14789 | * upon subsystem IDs. |
| 14790 | */ |
| 14791 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 14792 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14793 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 14794 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14795 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14796 | } |
| 14797 | |
| 14798 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14799 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14800 | tg3_flag_set(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14801 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14802 | tg3_flag_clear(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14803 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 14804 | tp->rx_offset = NET_SKB_PAD + NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14805 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14806 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14807 | tg3_flag(tp, PCIX_MODE)) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 14808 | tp->rx_offset = NET_SKB_PAD; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14809 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 14810 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14811 | #endif |
| 14812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14813 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 14814 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 14815 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14816 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 14817 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 14818 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 14819 | |
| 14820 | /* Increment the rx prod index on the rx std ring by at most |
| 14821 | * 8 for these chips to workaround hw errata. |
| 14822 | */ |
| 14823 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 14824 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 14825 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 14826 | tp->rx_std_max_post = 8; |
| 14827 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14828 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14829 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 14830 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 14831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14832 | return err; |
| 14833 | } |
| 14834 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14835 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14836 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
| 14837 | { |
| 14838 | struct net_device *dev = tp->dev; |
| 14839 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14840 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 14841 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14842 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14843 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14844 | addr = of_get_property(dp, "local-mac-address", &len); |
| 14845 | if (addr && len == 6) { |
| 14846 | memcpy(dev->dev_addr, addr, 6); |
| 14847 | memcpy(dev->perm_addr, dev->dev_addr, 6); |
| 14848 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14849 | } |
| 14850 | return -ENODEV; |
| 14851 | } |
| 14852 | |
| 14853 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) |
| 14854 | { |
| 14855 | struct net_device *dev = tp->dev; |
| 14856 | |
| 14857 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 14858 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14859 | return 0; |
| 14860 | } |
| 14861 | #endif |
| 14862 | |
| 14863 | static int __devinit tg3_get_device_address(struct tg3 *tp) |
| 14864 | { |
| 14865 | struct net_device *dev = tp->dev; |
| 14866 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14867 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14868 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14869 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14870 | if (!tg3_get_macaddr_sparc(tp)) |
| 14871 | return 0; |
| 14872 | #endif |
| 14873 | |
| 14874 | mac_offset = 0x7c; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14875 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14876 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14877 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 14878 | mac_offset = 0xcc; |
| 14879 | if (tg3_nvram_lock(tp)) |
| 14880 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 14881 | else |
| 14882 | tg3_nvram_unlock(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14883 | } else if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 14884 | if (tp->pci_fn & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14885 | mac_offset = 0xcc; |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 14886 | if (tp->pci_fn > 1) |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14887 | mac_offset += 0x18c; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14888 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14889 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14890 | |
| 14891 | /* First try to get it from MAC address mailbox. */ |
| 14892 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 14893 | if ((hi >> 16) == 0x484b) { |
| 14894 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 14895 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 14896 | |
| 14897 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 14898 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 14899 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 14900 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 14901 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14902 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14903 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 14904 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 14905 | } |
| 14906 | if (!addr_ok) { |
| 14907 | /* Next, try NVRAM. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14908 | if (!tg3_flag(tp, NO_NVRAM) && |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 14909 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 14910 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 14911 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 14912 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14913 | } |
| 14914 | /* Finally just fetch it out of the MAC control regs. */ |
| 14915 | else { |
| 14916 | hi = tr32(MAC_ADDR_0_HIGH); |
| 14917 | lo = tr32(MAC_ADDR_0_LOW); |
| 14918 | |
| 14919 | dev->dev_addr[5] = lo & 0xff; |
| 14920 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 14921 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 14922 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 14923 | dev->dev_addr[1] = hi & 0xff; |
| 14924 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 14925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14926 | } |
| 14927 | |
| 14928 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 14929 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14930 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 14931 | return 0; |
| 14932 | #endif |
| 14933 | return -EINVAL; |
| 14934 | } |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 14935 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14936 | return 0; |
| 14937 | } |
| 14938 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14939 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 14940 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 14941 | |
| 14942 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 14943 | { |
| 14944 | int cacheline_size; |
| 14945 | u8 byte; |
| 14946 | int goal; |
| 14947 | |
| 14948 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 14949 | if (byte == 0) |
| 14950 | cacheline_size = 1024; |
| 14951 | else |
| 14952 | cacheline_size = (int) byte * 4; |
| 14953 | |
| 14954 | /* On 5703 and later chips, the boundary bits have no |
| 14955 | * effect. |
| 14956 | */ |
| 14957 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14958 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14959 | !tg3_flag(tp, PCI_EXPRESS)) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14960 | goto out; |
| 14961 | |
| 14962 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 14963 | goal = BOUNDARY_MULTI_CACHELINE; |
| 14964 | #else |
| 14965 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 14966 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 14967 | #else |
| 14968 | goal = 0; |
| 14969 | #endif |
| 14970 | #endif |
| 14971 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14972 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14973 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 14974 | goto out; |
| 14975 | } |
| 14976 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14977 | if (!goal) |
| 14978 | goto out; |
| 14979 | |
| 14980 | /* PCI controllers on most RISC systems tend to disconnect |
| 14981 | * when a device tries to burst across a cache-line boundary. |
| 14982 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 14983 | * |
| 14984 | * Unfortunately, for PCI-E there are only limited |
| 14985 | * write-side controls for this, and thus for reads |
| 14986 | * we will still get the disconnects. We'll also waste |
| 14987 | * these PCI cycles for both read and write for chips |
| 14988 | * other than 5700 and 5701 which do not implement the |
| 14989 | * boundary bits. |
| 14990 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14991 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14992 | switch (cacheline_size) { |
| 14993 | case 16: |
| 14994 | case 32: |
| 14995 | case 64: |
| 14996 | case 128: |
| 14997 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14998 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 14999 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 15000 | } else { |
| 15001 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 15002 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 15003 | } |
| 15004 | break; |
| 15005 | |
| 15006 | case 256: |
| 15007 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 15008 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 15009 | break; |
| 15010 | |
| 15011 | default: |
| 15012 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 15013 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 15014 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15015 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15016 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15017 | switch (cacheline_size) { |
| 15018 | case 16: |
| 15019 | case 32: |
| 15020 | case 64: |
| 15021 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15022 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15023 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 15024 | break; |
| 15025 | } |
| 15026 | /* fallthrough */ |
| 15027 | case 128: |
| 15028 | default: |
| 15029 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15030 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 15031 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15032 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15033 | } else { |
| 15034 | switch (cacheline_size) { |
| 15035 | case 16: |
| 15036 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15037 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 15038 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 15039 | break; |
| 15040 | } |
| 15041 | /* fallthrough */ |
| 15042 | case 32: |
| 15043 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15044 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 15045 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 15046 | break; |
| 15047 | } |
| 15048 | /* fallthrough */ |
| 15049 | case 64: |
| 15050 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15051 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 15052 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 15053 | break; |
| 15054 | } |
| 15055 | /* fallthrough */ |
| 15056 | case 128: |
| 15057 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15058 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 15059 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 15060 | break; |
| 15061 | } |
| 15062 | /* fallthrough */ |
| 15063 | case 256: |
| 15064 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 15065 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 15066 | break; |
| 15067 | case 512: |
| 15068 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 15069 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 15070 | break; |
| 15071 | case 1024: |
| 15072 | default: |
| 15073 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 15074 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 15075 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15076 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15077 | } |
| 15078 | |
| 15079 | out: |
| 15080 | return val; |
| 15081 | } |
| 15082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15083 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
| 15084 | { |
| 15085 | struct tg3_internal_buffer_desc test_desc; |
| 15086 | u32 sram_dma_descs; |
| 15087 | int i, ret; |
| 15088 | |
| 15089 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 15090 | |
| 15091 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 15092 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 15093 | tw32(RDMAC_STATUS, 0); |
| 15094 | tw32(WDMAC_STATUS, 0); |
| 15095 | |
| 15096 | tw32(BUFMGR_MODE, 0); |
| 15097 | tw32(FTQ_RESET, 0); |
| 15098 | |
| 15099 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 15100 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 15101 | test_desc.nic_mbuf = 0x00002100; |
| 15102 | test_desc.len = size; |
| 15103 | |
| 15104 | /* |
| 15105 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 15106 | * the *second* time the tg3 driver was getting loaded after an |
| 15107 | * initial scan. |
| 15108 | * |
| 15109 | * Broadcom tells me: |
| 15110 | * ...the DMA engine is connected to the GRC block and a DMA |
| 15111 | * reset may affect the GRC block in some unpredictable way... |
| 15112 | * The behavior of resets to individual blocks has not been tested. |
| 15113 | * |
| 15114 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 15115 | */ |
| 15116 | if (to_device) { |
| 15117 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 15118 | |
| 15119 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 15120 | udelay(40); |
| 15121 | } else { |
| 15122 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 15123 | |
| 15124 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 15125 | udelay(40); |
| 15126 | } |
| 15127 | test_desc.flags = 0x00000005; |
| 15128 | |
| 15129 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 15130 | u32 val; |
| 15131 | |
| 15132 | val = *(((u32 *)&test_desc) + i); |
| 15133 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 15134 | sram_dma_descs + (i * sizeof(u32))); |
| 15135 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 15136 | } |
| 15137 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 15138 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15139 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15140 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15141 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15142 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15143 | |
| 15144 | ret = -ENODEV; |
| 15145 | for (i = 0; i < 40; i++) { |
| 15146 | u32 val; |
| 15147 | |
| 15148 | if (to_device) |
| 15149 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 15150 | else |
| 15151 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 15152 | if ((val & 0xffff) == sram_dma_descs) { |
| 15153 | ret = 0; |
| 15154 | break; |
| 15155 | } |
| 15156 | |
| 15157 | udelay(100); |
| 15158 | } |
| 15159 | |
| 15160 | return ret; |
| 15161 | } |
| 15162 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 15163 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15164 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15165 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 15166 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 15167 | { }, |
| 15168 | }; |
| 15169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15170 | static int __devinit tg3_test_dma(struct tg3 *tp) |
| 15171 | { |
| 15172 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15173 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15174 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15175 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 15176 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 15177 | &buf_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15178 | if (!buf) { |
| 15179 | ret = -ENOMEM; |
| 15180 | goto out_nofree; |
| 15181 | } |
| 15182 | |
| 15183 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 15184 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 15185 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15186 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15187 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15188 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15189 | goto out; |
| 15190 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15191 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15192 | /* DMA read watermark not used on PCIE */ |
| 15193 | tp->dma_rwctrl |= 0x00180000; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15194 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 15195 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 15196 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15197 | tp->dma_rwctrl |= 0x003f0000; |
| 15198 | else |
| 15199 | tp->dma_rwctrl |= 0x003f000f; |
| 15200 | } else { |
| 15201 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 15202 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 15203 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15204 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15205 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15206 | /* If the 5704 is behind the EPB bridge, we can |
| 15207 | * do the less restrictive ONE_DMA workaround for |
| 15208 | * better performance. |
| 15209 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15210 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15211 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 15212 | tp->dma_rwctrl |= 0x8000; |
| 15213 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15214 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 15215 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15216 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 15217 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15218 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15219 | tp->dma_rwctrl |= |
| 15220 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 15221 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 15222 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 15223 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 15224 | /* 5780 always in PCIX mode */ |
| 15225 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 15226 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 15227 | /* 5714 always in PCIX mode */ |
| 15228 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15229 | } else { |
| 15230 | tp->dma_rwctrl |= 0x001b000f; |
| 15231 | } |
| 15232 | } |
| 15233 | |
| 15234 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 15235 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 15236 | tp->dma_rwctrl &= 0xfffffff0; |
| 15237 | |
| 15238 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 15239 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 15240 | /* Remove this if it causes problems for some boards. */ |
| 15241 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 15242 | |
| 15243 | /* On 5700/5701 chips, we need to set this bit. |
| 15244 | * Otherwise the chip will issue cacheline transactions |
| 15245 | * to streamable DMA memory with not all the byte |
| 15246 | * enables turned on. This is an error on several |
| 15247 | * RISC PCI controllers, in particular sparc64. |
| 15248 | * |
| 15249 | * On 5703/5704 chips, this bit has been reassigned |
| 15250 | * a different meaning. In particular, it is used |
| 15251 | * on those chips to enable a PCI-X workaround. |
| 15252 | */ |
| 15253 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 15254 | } |
| 15255 | |
| 15256 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15257 | |
| 15258 | #if 0 |
| 15259 | /* Unneeded, already done by tg3_get_invariants. */ |
| 15260 | tg3_switch_clocks(tp); |
| 15261 | #endif |
| 15262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15263 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 15264 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 15265 | goto out; |
| 15266 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15267 | /* It is best to perform DMA test with maximum write burst size |
| 15268 | * to expose the 5700/5701 write DMA bug. |
| 15269 | */ |
| 15270 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 15271 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 15272 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15274 | while (1) { |
| 15275 | u32 *p = buf, i; |
| 15276 | |
| 15277 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 15278 | p[i] = i; |
| 15279 | |
| 15280 | /* Send the buffer to the chip. */ |
| 15281 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 15282 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15283 | dev_err(&tp->pdev->dev, |
| 15284 | "%s: Buffer write failed. err = %d\n", |
| 15285 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15286 | break; |
| 15287 | } |
| 15288 | |
| 15289 | #if 0 |
| 15290 | /* validate data reached card RAM correctly. */ |
| 15291 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 15292 | u32 val; |
| 15293 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 15294 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15295 | dev_err(&tp->pdev->dev, |
| 15296 | "%s: Buffer corrupted on device! " |
| 15297 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15298 | /* ret = -ENODEV here? */ |
| 15299 | } |
| 15300 | p[i] = 0; |
| 15301 | } |
| 15302 | #endif |
| 15303 | /* Now read it back. */ |
| 15304 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 15305 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15306 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 15307 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15308 | break; |
| 15309 | } |
| 15310 | |
| 15311 | /* Verify it. */ |
| 15312 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 15313 | if (p[i] == i) |
| 15314 | continue; |
| 15315 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15316 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 15317 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 15318 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15319 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 15320 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15321 | break; |
| 15322 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15323 | dev_err(&tp->pdev->dev, |
| 15324 | "%s: Buffer corrupted on read back! " |
| 15325 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15326 | ret = -ENODEV; |
| 15327 | goto out; |
| 15328 | } |
| 15329 | } |
| 15330 | |
| 15331 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 15332 | /* Success. */ |
| 15333 | ret = 0; |
| 15334 | break; |
| 15335 | } |
| 15336 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15337 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 15338 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 15339 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15340 | * now look for chipsets that are known to expose the |
| 15341 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15342 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15343 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15344 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 15345 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15346 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15347 | /* Safe to use the calculated DMA boundary. */ |
| 15348 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15349 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15350 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15351 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15353 | |
| 15354 | out: |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 15355 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15356 | out_nofree: |
| 15357 | return ret; |
| 15358 | } |
| 15359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15360 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
| 15361 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15362 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 15363 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15364 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15365 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15366 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 15367 | tp->bufmgr_config.mbuf_high_water = |
| 15368 | DEFAULT_MB_HIGH_WATER_57765; |
| 15369 | |
| 15370 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15371 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15372 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15373 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 15374 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15375 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15376 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15377 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15378 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15379 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15380 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 15381 | tp->bufmgr_config.mbuf_high_water = |
| 15382 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 15383 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 15384 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15385 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 15386 | tp->bufmgr_config.mbuf_high_water = |
| 15387 | DEFAULT_MB_HIGH_WATER_5906; |
| 15388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15389 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15390 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15391 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 15392 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15393 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 15394 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15395 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 15396 | } else { |
| 15397 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15398 | DEFAULT_MB_RDMA_LOW_WATER; |
| 15399 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15400 | DEFAULT_MB_MACRX_LOW_WATER; |
| 15401 | tp->bufmgr_config.mbuf_high_water = |
| 15402 | DEFAULT_MB_HIGH_WATER; |
| 15403 | |
| 15404 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15405 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 15406 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15407 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 15408 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15409 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 15410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15411 | |
| 15412 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 15413 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 15414 | } |
| 15415 | |
| 15416 | static char * __devinit tg3_phy_string(struct tg3 *tp) |
| 15417 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15418 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 15419 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 15420 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 15421 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 15422 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 15423 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 15424 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 15425 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 15426 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 15427 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 15428 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 15429 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 15430 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 15431 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 15432 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 15433 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 15434 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 15435 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 15436 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 15437 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 15438 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 15439 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 6418f2c | 2011-04-05 14:22:49 +0000 | [diff] [blame] | 15440 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15441 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15442 | case 0: return "serdes"; |
| 15443 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15445 | } |
| 15446 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15447 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
| 15448 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15449 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15450 | strcpy(str, "PCI Express"); |
| 15451 | return str; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15452 | } else if (tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15453 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 15454 | |
| 15455 | strcpy(str, "PCIX:"); |
| 15456 | |
| 15457 | if ((clock_ctrl == 7) || |
| 15458 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 15459 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 15460 | strcat(str, "133MHz"); |
| 15461 | else if (clock_ctrl == 0) |
| 15462 | strcat(str, "33MHz"); |
| 15463 | else if (clock_ctrl == 2) |
| 15464 | strcat(str, "50MHz"); |
| 15465 | else if (clock_ctrl == 4) |
| 15466 | strcat(str, "66MHz"); |
| 15467 | else if (clock_ctrl == 6) |
| 15468 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15469 | } else { |
| 15470 | strcpy(str, "PCI:"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15471 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15472 | strcat(str, "66MHz"); |
| 15473 | else |
| 15474 | strcat(str, "33MHz"); |
| 15475 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15476 | if (tg3_flag(tp, PCI_32BIT)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15477 | strcat(str, ":32-bit"); |
| 15478 | else |
| 15479 | strcat(str, ":64-bit"); |
| 15480 | return str; |
| 15481 | } |
| 15482 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 15483 | static void __devinit tg3_init_coal(struct tg3 *tp) |
| 15484 | { |
| 15485 | struct ethtool_coalesce *ec = &tp->coal; |
| 15486 | |
| 15487 | memset(ec, 0, sizeof(*ec)); |
| 15488 | ec->cmd = ETHTOOL_GCOALESCE; |
| 15489 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 15490 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 15491 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 15492 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 15493 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 15494 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 15495 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 15496 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 15497 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 15498 | |
| 15499 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 15500 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 15501 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 15502 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 15503 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 15504 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 15505 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 15506 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15507 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 15508 | ec->rx_coalesce_usecs_irq = 0; |
| 15509 | ec->tx_coalesce_usecs_irq = 0; |
| 15510 | ec->stats_block_coalesce_usecs = 0; |
| 15511 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 15512 | } |
| 15513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15514 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
| 15515 | const struct pci_device_id *ent) |
| 15516 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15517 | struct net_device *dev; |
| 15518 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 15519 | int i, err, pm_cap; |
| 15520 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15521 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15522 | u64 dma_mask, persist_dma_mask; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 15523 | netdev_features_t features = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15524 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15525 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15526 | |
| 15527 | err = pci_enable_device(pdev); |
| 15528 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15529 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15530 | return err; |
| 15531 | } |
| 15532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15533 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 15534 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15535 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15536 | goto err_out_disable_pdev; |
| 15537 | } |
| 15538 | |
| 15539 | pci_set_master(pdev); |
| 15540 | |
| 15541 | /* Find power-management capability. */ |
| 15542 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 15543 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15544 | dev_err(&pdev->dev, |
| 15545 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15546 | err = -EIO; |
| 15547 | goto err_out_free_res; |
| 15548 | } |
| 15549 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15550 | err = pci_set_power_state(pdev, PCI_D0); |
| 15551 | if (err) { |
| 15552 | dev_err(&pdev->dev, "Transition to D0 failed, aborting\n"); |
| 15553 | goto err_out_free_res; |
| 15554 | } |
| 15555 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 15556 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15557 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15558 | err = -ENOMEM; |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15559 | goto err_out_power_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15560 | } |
| 15561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15562 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 15563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15564 | tp = netdev_priv(dev); |
| 15565 | tp->pdev = pdev; |
| 15566 | tp->dev = dev; |
| 15567 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15568 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 15569 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 15570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15571 | if (tg3_debug > 0) |
| 15572 | tp->msg_enable = tg3_debug; |
| 15573 | else |
| 15574 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 15575 | |
| 15576 | /* The word/byte swap controls here control register access byte |
| 15577 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 15578 | * setting below. |
| 15579 | */ |
| 15580 | tp->misc_host_ctrl = |
| 15581 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 15582 | MISC_HOST_CTRL_WORD_SWAP | |
| 15583 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 15584 | MISC_HOST_CTRL_PCISTATE_RW; |
| 15585 | |
| 15586 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 15587 | * on descriptor entries, anything which isn't packet data. |
| 15588 | * |
| 15589 | * The StrongARM chips on the board (one for tx, one for rx) |
| 15590 | * are running in big-endian mode. |
| 15591 | */ |
| 15592 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 15593 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 15594 | #ifdef __BIG_ENDIAN |
| 15595 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 15596 | #endif |
| 15597 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15598 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 15599 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15600 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 15601 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 15602 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15603 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15604 | err = -ENOMEM; |
| 15605 | goto err_out_free_dev; |
| 15606 | } |
| 15607 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15608 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 15609 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || |
| 15610 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || |
| 15611 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || |
| 15612 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 15613 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 15614 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 15615 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) { |
| 15616 | tg3_flag_set(tp, ENABLE_APE); |
| 15617 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
| 15618 | if (!tp->aperegs) { |
| 15619 | dev_err(&pdev->dev, |
| 15620 | "Cannot map APE registers, aborting\n"); |
| 15621 | err = -ENOMEM; |
| 15622 | goto err_out_iounmap; |
| 15623 | } |
| 15624 | } |
| 15625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15626 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 15627 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15629 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15630 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 15631 | dev->netdev_ops = &tg3_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15632 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15633 | |
| 15634 | err = tg3_get_invariants(tp); |
| 15635 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15636 | dev_err(&pdev->dev, |
| 15637 | "Problem fetching invariants of chip, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15638 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15639 | } |
| 15640 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15641 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 15642 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15643 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 15644 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 15645 | * do DMA address check in tg3_start_xmit(). |
| 15646 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15647 | if (tg3_flag(tp, IS_5788)) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15648 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15649 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 15650 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15651 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 15652 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15653 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15654 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 15655 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15656 | |
| 15657 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15658 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15659 | err = pci_set_dma_mask(pdev, dma_mask); |
| 15660 | if (!err) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15661 | features |= NETIF_F_HIGHDMA; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15662 | err = pci_set_consistent_dma_mask(pdev, |
| 15663 | persist_dma_mask); |
| 15664 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15665 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 15666 | "DMA for consistent allocations\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15667 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15668 | } |
| 15669 | } |
| 15670 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15671 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 15672 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15673 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15674 | dev_err(&pdev->dev, |
| 15675 | "No usable DMA configuration, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15676 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15677 | } |
| 15678 | } |
| 15679 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15680 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15681 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15682 | features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 15683 | |
| 15684 | /* 5700 B0 chips do not support checksumming correctly due |
| 15685 | * to hardware bugs. |
| 15686 | */ |
| 15687 | if (tp->pci_chip_rev_id != CHIPREV_ID_5700_B0) { |
| 15688 | features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
| 15689 | |
| 15690 | if (tg3_flag(tp, 5755_PLUS)) |
| 15691 | features |= NETIF_F_IPV6_CSUM; |
| 15692 | } |
| 15693 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 15694 | /* TSO is on by default on chips that support hardware TSO. |
| 15695 | * Firmware TSO on older chips gives lower performance, so it |
| 15696 | * is off by default, but can be enabled using ethtool. |
| 15697 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15698 | if ((tg3_flag(tp, HW_TSO_1) || |
| 15699 | tg3_flag(tp, HW_TSO_2) || |
| 15700 | tg3_flag(tp, HW_TSO_3)) && |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15701 | (features & NETIF_F_IP_CSUM)) |
| 15702 | features |= NETIF_F_TSO; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15703 | if (tg3_flag(tp, HW_TSO_2) || tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15704 | if (features & NETIF_F_IPV6_CSUM) |
| 15705 | features |= NETIF_F_TSO6; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15706 | if (tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 15707 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 15708 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 15709 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15710 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 15711 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15712 | features |= NETIF_F_TSO_ECN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 15713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15714 | |
Matt Carlson | d542fe2 | 2011-05-19 16:02:43 +0000 | [diff] [blame] | 15715 | dev->features |= features; |
| 15716 | dev->vlan_features |= features; |
| 15717 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 15718 | /* |
| 15719 | * Add loopback capability only for a subset of devices that support |
| 15720 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY |
| 15721 | * loopback for the remaining devices. |
| 15722 | */ |
| 15723 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 15724 | !tg3_flag(tp, CPMU_PRESENT)) |
| 15725 | /* Add the loopback capability */ |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15726 | features |= NETIF_F_LOOPBACK; |
| 15727 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15728 | dev->hw_features |= features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 15729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15730 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15731 | !tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15732 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15733 | tg3_flag_set(tp, MAX_RXPEND_64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15734 | tp->rx_pending = 63; |
| 15735 | } |
| 15736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15737 | err = tg3_get_device_address(tp); |
| 15738 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15739 | dev_err(&pdev->dev, |
| 15740 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15741 | goto err_out_apeunmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15742 | } |
| 15743 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15744 | /* |
| 15745 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 15746 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 15747 | * pending DMA on the PCI bus at that point. |
| 15748 | */ |
| 15749 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 15750 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 15751 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 15752 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 15753 | } |
| 15754 | |
| 15755 | err = tg3_test_dma(tp); |
| 15756 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15757 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15758 | goto err_out_apeunmap; |
| 15759 | } |
| 15760 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15761 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 15762 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 15763 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 15764 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15765 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 15766 | |
| 15767 | tnapi->tp = tp; |
| 15768 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 15769 | |
| 15770 | tnapi->int_mbox = intmbx; |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 15771 | if (i <= 4) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15772 | intmbx += 0x8; |
| 15773 | else |
| 15774 | intmbx += 0x4; |
| 15775 | |
| 15776 | tnapi->consmbox = rcvmbx; |
| 15777 | tnapi->prodmbox = sndmbx; |
| 15778 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 15779 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15780 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 15781 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15782 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15783 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15784 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15785 | break; |
| 15786 | |
| 15787 | /* |
| 15788 | * If we support MSIX, we'll be using RSS. If we're using |
| 15789 | * RSS, the first vector only handles link interrupts and the |
| 15790 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 15791 | * mailbox values for the next iteration. The values we setup |
| 15792 | * above are still useful for the single vectored mode. |
| 15793 | */ |
| 15794 | if (!i) |
| 15795 | continue; |
| 15796 | |
| 15797 | rcvmbx += 0x8; |
| 15798 | |
| 15799 | if (sndmbx & 0x4) |
| 15800 | sndmbx -= 0x4; |
| 15801 | else |
| 15802 | sndmbx += 0xc; |
| 15803 | } |
| 15804 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15805 | tg3_init_coal(tp); |
| 15806 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 15807 | pci_set_drvdata(pdev, dev); |
| 15808 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 15809 | if (tg3_flag(tp, 5717_PLUS)) { |
| 15810 | /* Resume a low-power mode */ |
| 15811 | tg3_frob_aux_power(tp, false); |
| 15812 | } |
| 15813 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15814 | tg3_timer_init(tp); |
| 15815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15816 | err = register_netdev(dev); |
| 15817 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15818 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15819 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15820 | } |
| 15821 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15822 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 15823 | tp->board_part_number, |
| 15824 | tp->pci_chip_rev_id, |
| 15825 | tg3_bus_string(tp, str), |
| 15826 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15827 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15828 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 15829 | struct phy_device *phydev; |
| 15830 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15831 | netdev_info(dev, |
| 15832 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15833 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15834 | } else { |
| 15835 | char *ethtype; |
| 15836 | |
| 15837 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 15838 | ethtype = "10/100Base-TX"; |
| 15839 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 15840 | ethtype = "1000Base-SX"; |
| 15841 | else |
| 15842 | ethtype = "10/100/1000Base-T"; |
| 15843 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15844 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 15845 | "(WireSpeed[%d], EEE[%d])\n", |
| 15846 | tg3_phy_string(tp), ethtype, |
| 15847 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, |
| 15848 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15849 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 15850 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15851 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 15852 | (dev->features & NETIF_F_RXCSUM) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15853 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15854 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15855 | tg3_flag(tp, ENABLE_ASF) != 0, |
| 15856 | tg3_flag(tp, TSO_CAPABLE) != 0); |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15857 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 15858 | tp->dma_rwctrl, |
| 15859 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 15860 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15861 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15862 | pci_save_state(pdev); |
| 15863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15864 | return 0; |
| 15865 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15866 | err_out_apeunmap: |
| 15867 | if (tp->aperegs) { |
| 15868 | iounmap(tp->aperegs); |
| 15869 | tp->aperegs = NULL; |
| 15870 | } |
| 15871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15872 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15873 | if (tp->regs) { |
| 15874 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15875 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15876 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15877 | |
| 15878 | err_out_free_dev: |
| 15879 | free_netdev(dev); |
| 15880 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15881 | err_out_power_down: |
| 15882 | pci_set_power_state(pdev, PCI_D3hot); |
| 15883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15884 | err_out_free_res: |
| 15885 | pci_release_regions(pdev); |
| 15886 | |
| 15887 | err_out_disable_pdev: |
| 15888 | pci_disable_device(pdev); |
| 15889 | pci_set_drvdata(pdev, NULL); |
| 15890 | return err; |
| 15891 | } |
| 15892 | |
| 15893 | static void __devexit tg3_remove_one(struct pci_dev *pdev) |
| 15894 | { |
| 15895 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15896 | |
| 15897 | if (dev) { |
| 15898 | struct tg3 *tp = netdev_priv(dev); |
| 15899 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 15900 | if (tp->fw) |
| 15901 | release_firmware(tp->fw); |
| 15902 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 15903 | tg3_reset_task_cancel(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15904 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 15905 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15906 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15907 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15908 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15910 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15911 | if (tp->aperegs) { |
| 15912 | iounmap(tp->aperegs); |
| 15913 | tp->aperegs = NULL; |
| 15914 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15915 | if (tp->regs) { |
| 15916 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15917 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15919 | free_netdev(dev); |
| 15920 | pci_release_regions(pdev); |
| 15921 | pci_disable_device(pdev); |
| 15922 | pci_set_drvdata(pdev, NULL); |
| 15923 | } |
| 15924 | } |
| 15925 | |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 15926 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15927 | static int tg3_suspend(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15928 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15929 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15930 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15931 | struct tg3 *tp = netdev_priv(dev); |
| 15932 | int err; |
| 15933 | |
| 15934 | if (!netif_running(dev)) |
| 15935 | return 0; |
| 15936 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 15937 | tg3_reset_task_cancel(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15938 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15939 | tg3_netif_stop(tp); |
| 15940 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15941 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15942 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15943 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15944 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15945 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15946 | |
| 15947 | netif_device_detach(dev); |
| 15948 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15949 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 15950 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15951 | tg3_flag_clear(tp, INIT_COMPLETE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15952 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15953 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15954 | err = tg3_power_down_prepare(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15955 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15956 | int err2; |
| 15957 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15958 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15959 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15960 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15961 | err2 = tg3_restart_hw(tp, 1); |
| 15962 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15963 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15964 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15965 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15966 | |
| 15967 | netif_device_attach(dev); |
| 15968 | tg3_netif_start(tp); |
| 15969 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15970 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15971 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15972 | |
| 15973 | if (!err2) |
| 15974 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15975 | } |
| 15976 | |
| 15977 | return err; |
| 15978 | } |
| 15979 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15980 | static int tg3_resume(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15981 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15982 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15983 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15984 | struct tg3 *tp = netdev_priv(dev); |
| 15985 | int err; |
| 15986 | |
| 15987 | if (!netif_running(dev)) |
| 15988 | return 0; |
| 15989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15990 | netif_device_attach(dev); |
| 15991 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15992 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15993 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15994 | tg3_flag_set(tp, INIT_COMPLETE); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15995 | err = tg3_restart_hw(tp, 1); |
| 15996 | if (err) |
| 15997 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15998 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15999 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16001 | tg3_netif_start(tp); |
| 16002 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16003 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16004 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16005 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16006 | if (!err) |
| 16007 | tg3_phy_start(tp); |
| 16008 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16009 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16010 | } |
| 16011 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16012 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16013 | #define TG3_PM_OPS (&tg3_pm_ops) |
| 16014 | |
| 16015 | #else |
| 16016 | |
| 16017 | #define TG3_PM_OPS NULL |
| 16018 | |
| 16019 | #endif /* CONFIG_PM_SLEEP */ |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16020 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16021 | /** |
| 16022 | * tg3_io_error_detected - called when PCI error is detected |
| 16023 | * @pdev: Pointer to PCI device |
| 16024 | * @state: The current pci connection state |
| 16025 | * |
| 16026 | * This function is called after a PCI bus error affecting |
| 16027 | * this device has been detected. |
| 16028 | */ |
| 16029 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, |
| 16030 | pci_channel_state_t state) |
| 16031 | { |
| 16032 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16033 | struct tg3 *tp = netdev_priv(netdev); |
| 16034 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; |
| 16035 | |
| 16036 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 16037 | |
| 16038 | rtnl_lock(); |
| 16039 | |
| 16040 | if (!netif_running(netdev)) |
| 16041 | goto done; |
| 16042 | |
| 16043 | tg3_phy_stop(tp); |
| 16044 | |
| 16045 | tg3_netif_stop(tp); |
| 16046 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16047 | tg3_timer_stop(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16048 | |
| 16049 | /* Want to make sure that the reset task doesn't run */ |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16050 | tg3_reset_task_cancel(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16051 | |
| 16052 | netif_device_detach(netdev); |
| 16053 | |
| 16054 | /* Clean up software state, even if MMIO is blocked */ |
| 16055 | tg3_full_lock(tp, 0); |
| 16056 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 16057 | tg3_full_unlock(tp); |
| 16058 | |
| 16059 | done: |
| 16060 | if (state == pci_channel_io_perm_failure) |
| 16061 | err = PCI_ERS_RESULT_DISCONNECT; |
| 16062 | else |
| 16063 | pci_disable_device(pdev); |
| 16064 | |
| 16065 | rtnl_unlock(); |
| 16066 | |
| 16067 | return err; |
| 16068 | } |
| 16069 | |
| 16070 | /** |
| 16071 | * tg3_io_slot_reset - called after the pci bus has been reset. |
| 16072 | * @pdev: Pointer to PCI device |
| 16073 | * |
| 16074 | * Restart the card from scratch, as if from a cold-boot. |
| 16075 | * At this point, the card has exprienced a hard reset, |
| 16076 | * followed by fixups by BIOS, and has its config space |
| 16077 | * set up identically to what it was at cold boot. |
| 16078 | */ |
| 16079 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) |
| 16080 | { |
| 16081 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16082 | struct tg3 *tp = netdev_priv(netdev); |
| 16083 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 16084 | int err; |
| 16085 | |
| 16086 | rtnl_lock(); |
| 16087 | |
| 16088 | if (pci_enable_device(pdev)) { |
| 16089 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); |
| 16090 | goto done; |
| 16091 | } |
| 16092 | |
| 16093 | pci_set_master(pdev); |
| 16094 | pci_restore_state(pdev); |
| 16095 | pci_save_state(pdev); |
| 16096 | |
| 16097 | if (!netif_running(netdev)) { |
| 16098 | rc = PCI_ERS_RESULT_RECOVERED; |
| 16099 | goto done; |
| 16100 | } |
| 16101 | |
| 16102 | err = tg3_power_up(tp); |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 16103 | if (err) |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16104 | goto done; |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16105 | |
| 16106 | rc = PCI_ERS_RESULT_RECOVERED; |
| 16107 | |
| 16108 | done: |
| 16109 | rtnl_unlock(); |
| 16110 | |
| 16111 | return rc; |
| 16112 | } |
| 16113 | |
| 16114 | /** |
| 16115 | * tg3_io_resume - called when traffic can start flowing again. |
| 16116 | * @pdev: Pointer to PCI device |
| 16117 | * |
| 16118 | * This callback is called when the error recovery driver tells |
| 16119 | * us that its OK to resume normal operation. |
| 16120 | */ |
| 16121 | static void tg3_io_resume(struct pci_dev *pdev) |
| 16122 | { |
| 16123 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16124 | struct tg3 *tp = netdev_priv(netdev); |
| 16125 | int err; |
| 16126 | |
| 16127 | rtnl_lock(); |
| 16128 | |
| 16129 | if (!netif_running(netdev)) |
| 16130 | goto done; |
| 16131 | |
| 16132 | tg3_full_lock(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16133 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16134 | err = tg3_restart_hw(tp, 1); |
| 16135 | tg3_full_unlock(tp); |
| 16136 | if (err) { |
| 16137 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
| 16138 | goto done; |
| 16139 | } |
| 16140 | |
| 16141 | netif_device_attach(netdev); |
| 16142 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16143 | tg3_timer_start(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16144 | |
| 16145 | tg3_netif_start(tp); |
| 16146 | |
| 16147 | tg3_phy_start(tp); |
| 16148 | |
| 16149 | done: |
| 16150 | rtnl_unlock(); |
| 16151 | } |
| 16152 | |
| 16153 | static struct pci_error_handlers tg3_err_handler = { |
| 16154 | .error_detected = tg3_io_error_detected, |
| 16155 | .slot_reset = tg3_io_slot_reset, |
| 16156 | .resume = tg3_io_resume |
| 16157 | }; |
| 16158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16159 | static struct pci_driver tg3_driver = { |
| 16160 | .name = DRV_MODULE_NAME, |
| 16161 | .id_table = tg3_pci_tbl, |
| 16162 | .probe = tg3_init_one, |
| 16163 | .remove = __devexit_p(tg3_remove_one), |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16164 | .err_handler = &tg3_err_handler, |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16165 | .driver.pm = TG3_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16166 | }; |
| 16167 | |
| 16168 | static int __init tg3_init(void) |
| 16169 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 16170 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16171 | } |
| 16172 | |
| 16173 | static void __exit tg3_cleanup(void) |
| 16174 | { |
| 16175 | pci_unregister_driver(&tg3_driver); |
| 16176 | } |
| 16177 | |
| 16178 | module_init(tg3_init); |
| 16179 | module_exit(tg3_cleanup); |